blob: 02c926fe85686b4159a868a167b3a62c64d6cd56 [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;
567
paul718e3742002-12-13 20:15:29 +0000568 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
569
570 if (ret == 1)
571 return 0;
572 if (ret == -1)
573 return 1;
574
575 return 1;
576}
577
paul94f2b392005-06-28 12:44:16 +0000578static enum filter_type
paul718e3742002-12-13 20:15:29 +0000579bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
580 afi_t afi, safi_t safi)
581{
582 struct bgp_filter *filter;
583
584 filter = &peer->filter[afi][safi];
585
Paul Jakma650f76c2009-06-25 18:06:31 +0100586#define FILTER_EXIST_WARN(F,f,filter) \
587 if (BGP_DEBUG (update, UPDATE_IN) \
588 && !(F ## _IN (filter))) \
589 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
590 peer->host, #f, F ## _IN_NAME(filter));
591
592 if (DISTRIBUTE_IN_NAME (filter)) {
593 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
594
paul718e3742002-12-13 20:15:29 +0000595 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
596 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 }
paul718e3742002-12-13 20:15:29 +0000598
Paul Jakma650f76c2009-06-25 18:06:31 +0100599 if (PREFIX_LIST_IN_NAME (filter)) {
600 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
601
paul718e3742002-12-13 20:15:29 +0000602 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
603 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100604 }
paul718e3742002-12-13 20:15:29 +0000605
Paul Jakma650f76c2009-06-25 18:06:31 +0100606 if (FILTER_LIST_IN_NAME (filter)) {
607 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
608
paul718e3742002-12-13 20:15:29 +0000609 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
610 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 }
612
paul718e3742002-12-13 20:15:29 +0000613 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100614#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000615}
616
paul94f2b392005-06-28 12:44:16 +0000617static enum filter_type
paul718e3742002-12-13 20:15:29 +0000618bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
619 afi_t afi, safi_t safi)
620{
621 struct bgp_filter *filter;
622
623 filter = &peer->filter[afi][safi];
624
Paul Jakma650f76c2009-06-25 18:06:31 +0100625#define FILTER_EXIST_WARN(F,f,filter) \
626 if (BGP_DEBUG (update, UPDATE_OUT) \
627 && !(F ## _OUT (filter))) \
628 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
629 peer->host, #f, F ## _OUT_NAME(filter));
630
631 if (DISTRIBUTE_OUT_NAME (filter)) {
632 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
633
paul718e3742002-12-13 20:15:29 +0000634 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
635 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100636 }
paul718e3742002-12-13 20:15:29 +0000637
Paul Jakma650f76c2009-06-25 18:06:31 +0100638 if (PREFIX_LIST_OUT_NAME (filter)) {
639 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
640
paul718e3742002-12-13 20:15:29 +0000641 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
642 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100643 }
paul718e3742002-12-13 20:15:29 +0000644
Paul Jakma650f76c2009-06-25 18:06:31 +0100645 if (FILTER_LIST_OUT_NAME (filter)) {
646 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
647
paul718e3742002-12-13 20:15:29 +0000648 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
649 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100650 }
paul718e3742002-12-13 20:15:29 +0000651
652 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100653#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000654}
655
656/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000657static int
paul718e3742002-12-13 20:15:29 +0000658bgp_community_filter (struct peer *peer, struct attr *attr)
659{
660 if (attr->community)
661 {
662 /* NO_ADVERTISE check. */
663 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
664 return 1;
665
666 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000667 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000668 community_include (attr->community, COMMUNITY_NO_EXPORT))
669 return 1;
670
671 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000672 if (peer->sort == BGP_PEER_EBGP
673 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000674 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
675 return 1;
676 }
677 return 0;
678}
679
680/* Route reflection loop check. */
681static int
682bgp_cluster_filter (struct peer *peer, struct attr *attr)
683{
684 struct in_addr cluster_id;
685
Paul Jakmafb982c22007-05-04 20:15:47 +0000686 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000687 {
688 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
689 cluster_id = peer->bgp->cluster_id;
690 else
691 cluster_id = peer->bgp->router_id;
692
Paul Jakmafb982c22007-05-04 20:15:47 +0000693 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000694 return 1;
695 }
696 return 0;
697}
David Lamparter6b0655a2014-06-04 06:53:35 +0200698
paul94f2b392005-06-28 12:44:16 +0000699static int
paul718e3742002-12-13 20:15:29 +0000700bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
701 afi_t afi, safi_t safi)
702{
703 struct bgp_filter *filter;
704 struct bgp_info info;
705 route_map_result_t ret;
706
707 filter = &peer->filter[afi][safi];
708
709 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000710 if (peer->weight)
711 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000712
713 /* Route map apply. */
714 if (ROUTE_MAP_IN_NAME (filter))
715 {
716 /* Duplicate current value to new strucutre for modification. */
717 info.peer = peer;
718 info.attr = attr;
719
paulac41b2a2003-08-12 05:32:27 +0000720 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
721
paul718e3742002-12-13 20:15:29 +0000722 /* Apply BGP route map to the attribute. */
723 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000724
725 peer->rmap_type = 0;
726
paul718e3742002-12-13 20:15:29 +0000727 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200728 /* caller has multiple error paths with bgp_attr_flush() */
729 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000730 }
731 return RMAP_PERMIT;
732}
David Lamparter6b0655a2014-06-04 06:53:35 +0200733
paul94f2b392005-06-28 12:44:16 +0000734static int
paulfee0f4c2004-09-13 05:12:46 +0000735bgp_export_modifier (struct peer *rsclient, struct peer *peer,
736 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
737{
738 struct bgp_filter *filter;
739 struct bgp_info info;
740 route_map_result_t ret;
741
742 filter = &peer->filter[afi][safi];
743
744 /* Route map apply. */
745 if (ROUTE_MAP_EXPORT_NAME (filter))
746 {
747 /* Duplicate current value to new strucutre for modification. */
748 info.peer = rsclient;
749 info.attr = attr;
750
751 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
752
753 /* Apply BGP route map to the attribute. */
754 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
755
756 rsclient->rmap_type = 0;
757
758 if (ret == RMAP_DENYMATCH)
759 {
760 /* Free newly generated AS path and community by route-map. */
761 bgp_attr_flush (attr);
762 return RMAP_DENY;
763 }
764 }
765 return RMAP_PERMIT;
766}
767
paul94f2b392005-06-28 12:44:16 +0000768static int
paulfee0f4c2004-09-13 05:12:46 +0000769bgp_import_modifier (struct peer *rsclient, struct peer *peer,
770 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
771{
772 struct bgp_filter *filter;
773 struct bgp_info info;
774 route_map_result_t ret;
775
776 filter = &rsclient->filter[afi][safi];
777
778 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000779 if (peer->weight)
780 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000781
782 /* Route map apply. */
783 if (ROUTE_MAP_IMPORT_NAME (filter))
784 {
785 /* Duplicate current value to new strucutre for modification. */
786 info.peer = peer;
787 info.attr = attr;
788
789 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
790
791 /* Apply BGP route map to the attribute. */
792 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
793
794 peer->rmap_type = 0;
795
796 if (ret == RMAP_DENYMATCH)
797 {
798 /* Free newly generated AS path and community by route-map. */
799 bgp_attr_flush (attr);
800 return RMAP_DENY;
801 }
802 }
803 return RMAP_PERMIT;
804}
David Lamparter6b0655a2014-06-04 06:53:35 +0200805
paul94f2b392005-06-28 12:44:16 +0000806static int
paul718e3742002-12-13 20:15:29 +0000807bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
808 struct attr *attr, afi_t afi, safi_t safi)
809{
810 int ret;
811 char buf[SU_ADDRSTRLEN];
812 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000813 struct peer *from;
814 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000815 int transparent;
816 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700817 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000818
819 from = ri->peer;
820 filter = &peer->filter[afi][safi];
821 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700822 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000823
Paul Jakma750e8142008-07-22 21:11:48 +0000824 if (DISABLE_BGP_ANNOUNCE)
825 return 0;
paul718e3742002-12-13 20:15:29 +0000826
paulfee0f4c2004-09-13 05:12:46 +0000827 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
828 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
829 return 0;
830
paul718e3742002-12-13 20:15:29 +0000831 /* Do not send back route to sender. */
832 if (from == peer)
833 return 0;
834
835 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000836 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000837 if (! UNSUPPRESS_MAP_NAME (filter))
838 return 0;
839
840 /* Default route check. */
841 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
842 {
843 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
844 return 0;
845#ifdef HAVE_IPV6
846 else if (p->family == AF_INET6 && p->prefixlen == 0)
847 return 0;
848#endif /* HAVE_IPV6 */
849 }
850
paul286e1e72003-08-08 00:24:31 +0000851 /* Transparency check. */
852 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
853 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
854 transparent = 1;
855 else
856 transparent = 0;
857
paul718e3742002-12-13 20:15:29 +0000858 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700859 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000860 return 0;
861
862 /* If the attribute has originator-id and it is same as remote
863 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700864 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000865 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700866 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000867 {
868 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000869 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000870 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
871 peer->host,
872 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
873 p->prefixlen);
874 return 0;
875 }
876 }
877
878 /* ORF prefix-list filter check */
879 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
880 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
881 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
882 if (peer->orf_plist[afi][safi])
883 {
884 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
885 return 0;
886 }
887
888 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700889 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000890 {
891 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000892 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000893 "%s [Update:SEND] %s/%d is filtered",
894 peer->host,
895 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
896 p->prefixlen);
897 return 0;
898 }
899
900#ifdef BGP_SEND_ASPATH_CHECK
901 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700902 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000903 {
904 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000905 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400906 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000907 peer->host, peer->as);
908 return 0;
909 }
910#endif /* BGP_SEND_ASPATH_CHECK */
911
912 /* If we're a CONFED we need to loop check the CONFED ID too */
913 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
914 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700915 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000916 {
917 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000918 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400919 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000920 peer->host,
921 bgp->confed_id);
922 return 0;
923 }
924 }
925
926 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000927 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000928 reflect = 1;
929 else
930 reflect = 0;
931
932 /* IBGP reflection check. */
933 if (reflect)
934 {
935 /* A route from a Client peer. */
936 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
937 {
938 /* Reflect to all the Non-Client peers and also to the
939 Client peers other than the originator. Originator check
940 is already done. So there is noting to do. */
941 /* no bgp client-to-client reflection check. */
942 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
943 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
944 return 0;
945 }
946 else
947 {
948 /* A route from a Non-client peer. Reflect to all other
949 clients. */
950 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
951 return 0;
952 }
953 }
Paul Jakma41367172007-08-06 15:24:51 +0000954
paul718e3742002-12-13 20:15:29 +0000955 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700956 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000957
paul718e3742002-12-13 20:15:29 +0000958 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000959 if ((peer->sort == BGP_PEER_IBGP
960 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000961 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
962 {
963 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
964 attr->local_pref = bgp->default_local_pref;
965 }
966
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000967 /* If originator-id is not set and the route is to be reflected,
968 set the originator id */
969 if (peer && from && peer->sort == BGP_PEER_IBGP &&
970 from->sort == BGP_PEER_IBGP &&
971 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
972 {
973 attr->extra = bgp_attr_extra_get(attr);
974 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
975 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
976 }
977
paul718e3742002-12-13 20:15:29 +0000978 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000979 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000980 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
981 {
982 if (ri->peer != bgp->peer_self && ! transparent
983 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
984 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
985 }
986
987 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300988 if (transparent
989 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000990 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
991 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000992#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000993 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000994 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000995#endif /* HAVE_IPV6 */
996 )))
paul718e3742002-12-13 20:15:29 +0000997 {
998 /* NEXT-HOP Unchanged. */
999 }
1000 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
1001 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
1002#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +00001003 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001004 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001005#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001006 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001007 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1008 {
1009 /* Set IPv4 nexthop. */
1010 if (p->family == AF_INET)
1011 {
1012 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001013 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1014 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001015 else
1016 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1017 }
1018#ifdef HAVE_IPV6
1019 /* Set IPv6 nexthop. */
1020 if (p->family == AF_INET6)
1021 {
1022 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001023 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001024 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001025 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001026 }
1027#endif /* HAVE_IPV6 */
1028 }
1029
1030#ifdef HAVE_IPV6
1031 if (p->family == AF_INET6)
1032 {
paulfee0f4c2004-09-13 05:12:46 +00001033 /* Left nexthop_local unchanged if so configured. */
1034 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1035 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1036 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001037 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1038 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001039 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001040 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001041 }
1042
1043 /* Default nexthop_local treatment for non-RS-Clients */
1044 else
1045 {
paul718e3742002-12-13 20:15:29 +00001046 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001047 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001048
1049 /* Set link-local address for shared network peer. */
1050 if (peer->shared_network
1051 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1052 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001053 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001054 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001055 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001056 }
1057
1058 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1059 address.*/
1060 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001061 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001062
1063 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1064 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001065 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001066 }
paulfee0f4c2004-09-13 05:12:46 +00001067
1068 }
paul718e3742002-12-13 20:15:29 +00001069#endif /* HAVE_IPV6 */
1070
1071 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001072 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001073 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1074 && aspath_private_as_check (attr->aspath))
1075 attr->aspath = aspath_empty_get ();
1076
1077 /* Route map & unsuppress-map apply. */
1078 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001079 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001080 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001081 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001082 struct attr dummy_attr;
1083 struct attr_extra dummy_extra;
1084
1085 dummy_attr.extra = &dummy_extra;
1086
paul718e3742002-12-13 20:15:29 +00001087 info.peer = peer;
1088 info.attr = attr;
1089
1090 /* The route reflector is not allowed to modify the attributes
1091 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001092 if (from->sort == BGP_PEER_IBGP
1093 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001094 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001095 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001096 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001097 }
paulac41b2a2003-08-12 05:32:27 +00001098
1099 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1100
Paul Jakmafb982c22007-05-04 20:15:47 +00001101 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001102 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1103 else
1104 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1105
paulac41b2a2003-08-12 05:32:27 +00001106 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001107
paul718e3742002-12-13 20:15:29 +00001108 if (ret == RMAP_DENYMATCH)
1109 {
1110 bgp_attr_flush (attr);
1111 return 0;
1112 }
1113 }
1114 return 1;
1115}
1116
paul94f2b392005-06-28 12:44:16 +00001117static int
paulfee0f4c2004-09-13 05:12:46 +00001118bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1119 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001120{
paulfee0f4c2004-09-13 05:12:46 +00001121 int ret;
1122 char buf[SU_ADDRSTRLEN];
1123 struct bgp_filter *filter;
1124 struct bgp_info info;
1125 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001126 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001127
1128 from = ri->peer;
1129 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001130 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001131
Paul Jakma750e8142008-07-22 21:11:48 +00001132 if (DISABLE_BGP_ANNOUNCE)
1133 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001134
1135 /* Do not send back route to sender. */
1136 if (from == rsclient)
1137 return 0;
1138
1139 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001140 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001141 if (! UNSUPPRESS_MAP_NAME (filter))
1142 return 0;
1143
1144 /* Default route check. */
1145 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1146 PEER_STATUS_DEFAULT_ORIGINATE))
1147 {
1148 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1149 return 0;
1150#ifdef HAVE_IPV6
1151 else if (p->family == AF_INET6 && p->prefixlen == 0)
1152 return 0;
1153#endif /* HAVE_IPV6 */
1154 }
1155
1156 /* If the attribute has originator-id and it is same as remote
1157 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001158 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001159 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001160 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001161 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001162 {
1163 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001164 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001165 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1166 rsclient->host,
1167 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1168 p->prefixlen);
1169 return 0;
1170 }
1171 }
1172
1173 /* ORF prefix-list filter check */
1174 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1175 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1176 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1177 if (rsclient->orf_plist[afi][safi])
1178 {
1179 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1180 return 0;
1181 }
1182
1183 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001184 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001185 {
1186 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001187 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001188 "%s [Update:SEND] %s/%d is filtered",
1189 rsclient->host,
1190 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1191 p->prefixlen);
1192 return 0;
1193 }
1194
1195#ifdef BGP_SEND_ASPATH_CHECK
1196 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001197 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001198 {
1199 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001200 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001201 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001202 rsclient->host, rsclient->as);
1203 return 0;
1204 }
1205#endif /* BGP_SEND_ASPATH_CHECK */
1206
1207 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001208 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001209
1210 /* next-hop-set */
1211 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1212#ifdef HAVE_IPV6
1213 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001214 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001215#endif /* HAVE_IPV6 */
1216 )
1217 {
1218 /* Set IPv4 nexthop. */
1219 if (p->family == AF_INET)
1220 {
1221 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001222 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001223 IPV4_MAX_BYTELEN);
1224 else
1225 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1226 }
1227#ifdef HAVE_IPV6
1228 /* Set IPv6 nexthop. */
1229 if (p->family == AF_INET6)
1230 {
1231 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001232 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001233 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001235 }
1236#endif /* HAVE_IPV6 */
1237 }
1238
1239#ifdef HAVE_IPV6
1240 if (p->family == AF_INET6)
1241 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001242 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001243
paulfee0f4c2004-09-13 05:12:46 +00001244 /* Left nexthop_local unchanged if so configured. */
1245 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1246 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1247 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001248 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1249 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001250 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001251 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001252 }
1253
1254 /* Default nexthop_local treatment for RS-Clients */
1255 else
1256 {
1257 /* Announcer and RS-Client are both in the same network */
1258 if (rsclient->shared_network && from->shared_network &&
1259 (rsclient->ifindex == from->ifindex))
1260 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001261 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1262 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001263 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001264 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001265 }
1266
1267 /* Set link-local address for shared network peer. */
1268 else if (rsclient->shared_network
1269 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1270 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001271 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001272 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001273 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001274 }
1275
1276 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001277 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001278 }
1279
1280 }
1281#endif /* HAVE_IPV6 */
1282
1283
1284 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001285 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001286 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1287 && aspath_private_as_check (attr->aspath))
1288 attr->aspath = aspath_empty_get ();
1289
1290 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001291 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001292 {
1293 info.peer = rsclient;
1294 info.attr = attr;
1295
1296 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1297
Paul Jakmafb982c22007-05-04 20:15:47 +00001298 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001299 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1300 else
1301 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1302
1303 rsclient->rmap_type = 0;
1304
1305 if (ret == RMAP_DENYMATCH)
1306 {
1307 bgp_attr_flush (attr);
1308 return 0;
1309 }
1310 }
1311
1312 return 1;
1313}
1314
1315struct bgp_info_pair
1316{
1317 struct bgp_info *old;
1318 struct bgp_info *new;
1319};
1320
paul94f2b392005-06-28 12:44:16 +00001321static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001322bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1323 struct bgp_maxpaths_cfg *mpath_cfg,
1324 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001325{
paul718e3742002-12-13 20:15:29 +00001326 struct bgp_info *new_select;
1327 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001328 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001329 struct bgp_info *ri1;
1330 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001331 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001332 int paths_eq, do_mpath;
1333 struct list mp_list;
1334
1335 bgp_mp_list_init (&mp_list);
1336 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1337 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1338
paul718e3742002-12-13 20:15:29 +00001339 /* bgp deterministic-med */
1340 new_select = NULL;
1341 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1342 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1343 {
1344 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1345 continue;
1346 if (BGP_INFO_HOLDDOWN (ri1))
1347 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001348 if (ri1->peer && ri1->peer != bgp->peer_self)
1349 if (ri1->peer->status != Established)
1350 continue;
paul718e3742002-12-13 20:15:29 +00001351
1352 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001353 if (do_mpath)
1354 bgp_mp_list_add (&mp_list, ri1);
1355 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001356 if (ri1->next)
1357 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1358 {
1359 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1360 continue;
1361 if (BGP_INFO_HOLDDOWN (ri2))
1362 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001363 if (ri2->peer &&
1364 ri2->peer != bgp->peer_self &&
1365 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1366 if (ri2->peer->status != Established)
1367 continue;
paul718e3742002-12-13 20:15:29 +00001368
1369 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1370 || aspath_cmp_left_confed (ri1->attr->aspath,
1371 ri2->attr->aspath))
1372 {
Josh Bailey6918e742011-07-20 20:48:20 -07001373 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1374 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001375 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001376 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001377 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001378 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001379 if (do_mpath && !paths_eq)
1380 {
1381 bgp_mp_list_clear (&mp_list);
1382 bgp_mp_list_add (&mp_list, ri2);
1383 }
paul718e3742002-12-13 20:15:29 +00001384 }
1385
Josh Bailey6918e742011-07-20 20:48:20 -07001386 if (do_mpath && paths_eq)
1387 bgp_mp_list_add (&mp_list, ri2);
1388
Paul Jakma1a392d42006-09-07 00:24:49 +00001389 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001390 }
1391 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001392 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1393 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001394
1395 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1396 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001397 }
1398
1399 /* Check old selected route and new selected route. */
1400 old_select = NULL;
1401 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001402 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001403 {
1404 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1405 old_select = ri;
1406
1407 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001408 {
1409 /* reap REMOVED routes, if needs be
1410 * selected route must stay for a while longer though
1411 */
1412 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1413 && (ri != old_select))
1414 bgp_info_reap (rn, ri);
1415
1416 continue;
1417 }
paul718e3742002-12-13 20:15:29 +00001418
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001419 if (ri->peer &&
1420 ri->peer != bgp->peer_self &&
1421 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1422 if (ri->peer->status != Established)
1423 continue;
1424
paul718e3742002-12-13 20:15:29 +00001425 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1426 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1427 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001428 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001429 continue;
1430 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001431 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1432 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001433
Josh Bailey96450fa2011-07-20 20:45:12 -07001434 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1435 {
Josh Bailey6918e742011-07-20 20:48:20 -07001436 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1437 bgp_mp_dmed_deselect (new_select);
1438
Josh Bailey96450fa2011-07-20 20:45:12 -07001439 new_select = ri;
1440
1441 if (do_mpath && !paths_eq)
1442 {
1443 bgp_mp_list_clear (&mp_list);
1444 bgp_mp_list_add (&mp_list, ri);
1445 }
1446 }
Josh Bailey6918e742011-07-20 20:48:20 -07001447 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1448 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001449
1450 if (do_mpath && paths_eq)
1451 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001452 }
paulb40d9392005-08-22 22:34:41 +00001453
paulfee0f4c2004-09-13 05:12:46 +00001454
Josh Bailey6918e742011-07-20 20:48:20 -07001455 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1456 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001457
Josh Bailey0b597ef2011-07-20 20:49:11 -07001458 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001459 bgp_mp_list_clear (&mp_list);
1460
1461 result->old = old_select;
1462 result->new = new_select;
1463
1464 return;
paulfee0f4c2004-09-13 05:12:46 +00001465}
1466
paul94f2b392005-06-28 12:44:16 +00001467static int
paulfee0f4c2004-09-13 05:12:46 +00001468bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001469 struct bgp_node *rn, afi_t afi, safi_t safi)
1470{
paulfee0f4c2004-09-13 05:12:46 +00001471 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001472 struct attr attr;
1473 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001474
1475 p = &rn->p;
1476
Paul Jakma9eda90c2007-08-30 13:36:17 +00001477 /* Announce route to Established peer. */
1478 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001479 return 0;
1480
Paul Jakma9eda90c2007-08-30 13:36:17 +00001481 /* Address family configuration check. */
1482 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001483 return 0;
1484
Paul Jakma9eda90c2007-08-30 13:36:17 +00001485 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001486 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1487 PEER_STATUS_ORF_WAIT_REFRESH))
1488 return 0;
1489
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001490 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1491 attr.extra = &extra;
1492
Avneesh Sachdev67174042012-08-17 08:19:49 -07001493 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001494 {
1495 case BGP_TABLE_MAIN:
1496 /* Announcement to peer->conf. If the route is filtered,
1497 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001498 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1499 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001500 else
1501 bgp_adj_out_unset (rn, peer, p, afi, safi);
1502 break;
1503 case BGP_TABLE_RSCLIENT:
1504 /* Announcement to peer->conf. If the route is filtered,
1505 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001506 if (selected &&
1507 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1508 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1509 else
1510 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001511 break;
1512 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001513
paulfee0f4c2004-09-13 05:12:46 +00001514 return 0;
paul200df112005-06-01 11:17:05 +00001515}
paulfee0f4c2004-09-13 05:12:46 +00001516
paul200df112005-06-01 11:17:05 +00001517struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001518{
paul200df112005-06-01 11:17:05 +00001519 struct bgp *bgp;
1520 struct bgp_node *rn;
1521 afi_t afi;
1522 safi_t safi;
1523};
1524
1525static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001526bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001527{
paul0fb58d52005-11-14 14:31:49 +00001528 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001529 struct bgp *bgp = pq->bgp;
1530 struct bgp_node *rn = pq->rn;
1531 afi_t afi = pq->afi;
1532 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001533 struct bgp_info *new_select;
1534 struct bgp_info *old_select;
1535 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001536 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001537 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001538
paulfee0f4c2004-09-13 05:12:46 +00001539 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001540 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001541 new_select = old_and_new.new;
1542 old_select = old_and_new.old;
1543
paul200df112005-06-01 11:17:05 +00001544 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1545 {
Chris Caputo228da422009-07-18 05:44:03 +00001546 if (rsclient->group)
1547 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1548 {
1549 /* Nothing to do. */
1550 if (old_select && old_select == new_select)
1551 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1552 continue;
paulfee0f4c2004-09-13 05:12:46 +00001553
Chris Caputo228da422009-07-18 05:44:03 +00001554 if (old_select)
1555 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1556 if (new_select)
1557 {
1558 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1559 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001560 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1561 }
paulfee0f4c2004-09-13 05:12:46 +00001562
Chris Caputo228da422009-07-18 05:44:03 +00001563 bgp_process_announce_selected (rsclient, new_select, rn,
1564 afi, safi);
1565 }
paul200df112005-06-01 11:17:05 +00001566 }
1567 else
1568 {
hassob7395792005-08-26 12:58:38 +00001569 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001570 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001571 if (new_select)
1572 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001573 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1574 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001575 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001576 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001577 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001578 }
paulfee0f4c2004-09-13 05:12:46 +00001579
paulb40d9392005-08-22 22:34:41 +00001580 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1581 bgp_info_reap (rn, old_select);
1582
paul200df112005-06-01 11:17:05 +00001583 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1584 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001585}
1586
paul200df112005-06-01 11:17:05 +00001587static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001588bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001589{
paul0fb58d52005-11-14 14:31:49 +00001590 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001591 struct bgp *bgp = pq->bgp;
1592 struct bgp_node *rn = pq->rn;
1593 afi_t afi = pq->afi;
1594 safi_t safi = pq->safi;
1595 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001596 struct bgp_info *new_select;
1597 struct bgp_info *old_select;
1598 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001599 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001600 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001601
paulfee0f4c2004-09-13 05:12:46 +00001602 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001603 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001604 old_select = old_and_new.old;
1605 new_select = old_and_new.new;
1606
1607 /* Nothing to do. */
1608 if (old_select && old_select == new_select)
1609 {
1610 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001611 {
Josh Bailey8196f132011-07-20 20:47:07 -07001612 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1613 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001614 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001615
Josh Bailey8196f132011-07-20 20:47:07 -07001616 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001617 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1618 return WQ_SUCCESS;
1619 }
paulfee0f4c2004-09-13 05:12:46 +00001620 }
paul718e3742002-12-13 20:15:29 +00001621
hasso338b3422005-02-23 14:27:24 +00001622 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001623 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001624 if (new_select)
1625 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001626 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1627 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001628 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001629 }
1630
1631
paul718e3742002-12-13 20:15:29 +00001632 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001633 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001634 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001635 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001636 }
1637
1638 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001639 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1640 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001641 {
1642 if (new_select
1643 && new_select->type == ZEBRA_ROUTE_BGP
1644 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001645 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001646 else
1647 {
1648 /* Withdraw the route from the kernel. */
1649 if (old_select
1650 && old_select->type == ZEBRA_ROUTE_BGP
1651 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001652 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001653 }
1654 }
paulb40d9392005-08-22 22:34:41 +00001655
1656 /* Reap old select bgp_info, it it has been removed */
1657 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1658 bgp_info_reap (rn, old_select);
1659
paul200df112005-06-01 11:17:05 +00001660 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1661 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001662}
1663
paul200df112005-06-01 11:17:05 +00001664static void
paul0fb58d52005-11-14 14:31:49 +00001665bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001666{
paul0fb58d52005-11-14 14:31:49 +00001667 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001668 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001669
Chris Caputo228da422009-07-18 05:44:03 +00001670 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001671 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001672 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001673 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1674}
1675
1676static void
1677bgp_process_queue_init (void)
1678{
1679 bm->process_main_queue
1680 = work_queue_new (bm->master, "process_main_queue");
1681 bm->process_rsclient_queue
1682 = work_queue_new (bm->master, "process_rsclient_queue");
1683
1684 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1685 {
1686 zlog_err ("%s: Failed to allocate work queue", __func__);
1687 exit (1);
1688 }
1689
1690 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001691 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001692 bm->process_main_queue->spec.max_retries = 0;
1693 bm->process_main_queue->spec.hold = 50;
1694
Paul Jakma838bbde2010-01-08 14:05:32 +00001695 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001696 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1697 bm->process_rsclient_queue->spec.max_retries = 0;
1698 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001699}
1700
1701void
paulfee0f4c2004-09-13 05:12:46 +00001702bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1703{
paul200df112005-06-01 11:17:05 +00001704 struct bgp_process_queue *pqnode;
1705
1706 /* already scheduled for processing? */
1707 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1708 return;
1709
1710 if ( (bm->process_main_queue == NULL) ||
1711 (bm->process_rsclient_queue == NULL) )
1712 bgp_process_queue_init ();
1713
1714 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1715 sizeof (struct bgp_process_queue));
1716 if (!pqnode)
1717 return;
Chris Caputo228da422009-07-18 05:44:03 +00001718
1719 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001720 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001721 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001722 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001723 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001724 pqnode->afi = afi;
1725 pqnode->safi = safi;
1726
Avneesh Sachdev67174042012-08-17 08:19:49 -07001727 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001728 {
paul200df112005-06-01 11:17:05 +00001729 case BGP_TABLE_MAIN:
1730 work_queue_add (bm->process_main_queue, pqnode);
1731 break;
1732 case BGP_TABLE_RSCLIENT:
1733 work_queue_add (bm->process_rsclient_queue, pqnode);
1734 break;
paulfee0f4c2004-09-13 05:12:46 +00001735 }
paul200df112005-06-01 11:17:05 +00001736
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001737 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001738 return;
paulfee0f4c2004-09-13 05:12:46 +00001739}
hasso0a486e52005-02-01 20:57:17 +00001740
paul94f2b392005-06-28 12:44:16 +00001741static int
hasso0a486e52005-02-01 20:57:17 +00001742bgp_maximum_prefix_restart_timer (struct thread *thread)
1743{
1744 struct peer *peer;
1745
1746 peer = THREAD_ARG (thread);
1747 peer->t_pmax_restart = NULL;
1748
1749 if (BGP_DEBUG (events, EVENTS))
1750 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1751 peer->host);
1752
1753 peer_clear (peer);
1754
1755 return 0;
1756}
1757
paulfee0f4c2004-09-13 05:12:46 +00001758int
paul5228ad22004-06-04 17:58:18 +00001759bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1760 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001761{
hassoe0701b72004-05-20 09:19:34 +00001762 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1763 return 0;
1764
1765 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001766 {
hassoe0701b72004-05-20 09:19:34 +00001767 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1768 && ! always)
1769 return 0;
paul718e3742002-12-13 20:15:29 +00001770
hassoe0701b72004-05-20 09:19:34 +00001771 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001772 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1773 "limit %ld", afi_safi_print (afi, safi), peer->host,
1774 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001775 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001776
hassoe0701b72004-05-20 09:19:34 +00001777 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1778 return 0;
paul718e3742002-12-13 20:15:29 +00001779
hassoe0701b72004-05-20 09:19:34 +00001780 {
paul5228ad22004-06-04 17:58:18 +00001781 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001782
1783 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001784 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001785
1786 ndata[0] = (afi >> 8);
1787 ndata[1] = afi;
1788 ndata[2] = safi;
1789 ndata[3] = (peer->pmax[afi][safi] >> 24);
1790 ndata[4] = (peer->pmax[afi][safi] >> 16);
1791 ndata[5] = (peer->pmax[afi][safi] >> 8);
1792 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001793
1794 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1795 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1796 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1797 }
hasso0a486e52005-02-01 20:57:17 +00001798
1799 /* restart timer start */
1800 if (peer->pmax_restart[afi][safi])
1801 {
1802 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1803
1804 if (BGP_DEBUG (events, EVENTS))
1805 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1806 peer->host, peer->v_pmax_restart);
1807
1808 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1809 peer->v_pmax_restart);
1810 }
1811
hassoe0701b72004-05-20 09:19:34 +00001812 return 1;
paul718e3742002-12-13 20:15:29 +00001813 }
hassoe0701b72004-05-20 09:19:34 +00001814 else
1815 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1816
1817 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1818 {
1819 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1820 && ! always)
1821 return 0;
1822
1823 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001824 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1825 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1826 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001827 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1828 }
1829 else
1830 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001831 return 0;
1832}
1833
paulb40d9392005-08-22 22:34:41 +00001834/* Unconditionally remove the route from the RIB, without taking
1835 * damping into consideration (eg, because the session went down)
1836 */
paul94f2b392005-06-28 12:44:16 +00001837static void
paul718e3742002-12-13 20:15:29 +00001838bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1839 afi_t afi, safi_t safi)
1840{
paul902212c2006-02-05 17:51:19 +00001841 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1842
1843 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1844 bgp_info_delete (rn, ri); /* keep historical info */
1845
paulb40d9392005-08-22 22:34:41 +00001846 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001847}
1848
paul94f2b392005-06-28 12:44:16 +00001849static void
paul718e3742002-12-13 20:15:29 +00001850bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001851 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001852{
paul718e3742002-12-13 20:15:29 +00001853 int status = BGP_DAMP_NONE;
1854
paulb40d9392005-08-22 22:34:41 +00001855 /* apply dampening, if result is suppressed, we'll be retaining
1856 * the bgp_info in the RIB for historical reference.
1857 */
1858 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001859 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001860 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1861 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001862 {
paul902212c2006-02-05 17:51:19 +00001863 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1864 return;
1865 }
1866
1867 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001868}
1869
paul94f2b392005-06-28 12:44:16 +00001870static void
paulfee0f4c2004-09-13 05:12:46 +00001871bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1872 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1873 int sub_type, struct prefix_rd *prd, u_char *tag)
1874{
1875 struct bgp_node *rn;
1876 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001877 struct attr new_attr;
1878 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001879 struct attr *attr_new;
1880 struct attr *attr_new2;
1881 struct bgp_info *ri;
1882 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001883 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001884 char buf[SU_ADDRSTRLEN];
1885
1886 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1887 if (peer == rsclient)
1888 return;
1889
1890 bgp = peer->bgp;
1891 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1892
1893 /* Check previously received route. */
1894 for (ri = rn->info; ri; ri = ri->next)
1895 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1896 break;
1897
1898 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001899 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001900 {
1901 reason = "as-path contains our own AS;";
1902 goto filtered;
1903 }
1904
1905 /* Route reflector originator ID check. */
1906 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001907 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001908 {
1909 reason = "originator is us;";
1910 goto filtered;
1911 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001912
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001913 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001914 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001915
1916 /* Apply export policy. */
1917 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1918 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1919 {
1920 reason = "export-policy;";
1921 goto filtered;
1922 }
1923
1924 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001925
paulfee0f4c2004-09-13 05:12:46 +00001926 /* Apply import policy. */
1927 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1928 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001929 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001930
1931 reason = "import-policy;";
1932 goto filtered;
1933 }
1934
1935 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001936 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001937
1938 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001939 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001940 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001941 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001942 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001943 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001944 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001945 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001946
1947 reason = "martian next-hop;";
1948 goto filtered;
1949 }
1950 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001951
paulfee0f4c2004-09-13 05:12:46 +00001952 /* If the update is implicit withdraw. */
1953 if (ri)
1954 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001955 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001956
1957 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001958 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1959 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001960 {
1961
Paul Jakma1a392d42006-09-07 00:24:49 +00001962 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001963
1964 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001965 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001966 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1967 peer->host,
1968 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1969 p->prefixlen, rsclient->host);
1970
Chris Caputo228da422009-07-18 05:44:03 +00001971 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001972 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001973
Chris Caputo228da422009-07-18 05:44:03 +00001974 return;
paulfee0f4c2004-09-13 05:12:46 +00001975 }
1976
Paul Jakma16d2e242007-04-10 19:32:10 +00001977 /* Withdraw/Announce before we fully processed the withdraw */
1978 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1979 bgp_info_restore (rn, ri);
1980
paulfee0f4c2004-09-13 05:12:46 +00001981 /* Received Logging. */
1982 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001983 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001984 peer->host,
1985 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1986 p->prefixlen, rsclient->host);
1987
1988 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001989 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001990
1991 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001992 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001993 ri->attr = attr_new;
1994
1995 /* Update MPLS tag. */
1996 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001997 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001998
Paul Jakma1a392d42006-09-07 00:24:49 +00001999 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002000
2001 /* Process change. */
2002 bgp_process (bgp, rn, afi, safi);
2003 bgp_unlock_node (rn);
2004
2005 return;
2006 }
2007
2008 /* Received Logging. */
2009 if (BGP_DEBUG (update, UPDATE_IN))
2010 {
ajsd2c1f162004-12-08 21:10:20 +00002011 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002012 peer->host,
2013 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2014 p->prefixlen, rsclient->host);
2015 }
2016
2017 /* Make new BGP info. */
2018 new = bgp_info_new ();
2019 new->type = type;
2020 new->sub_type = sub_type;
2021 new->peer = peer;
2022 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002023 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002024
2025 /* Update MPLS tag. */
2026 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002027 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002028
Paul Jakma1a392d42006-09-07 00:24:49 +00002029 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002030
2031 /* Register new BGP information. */
2032 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002033
2034 /* route_node_get lock */
2035 bgp_unlock_node (rn);
2036
paulfee0f4c2004-09-13 05:12:46 +00002037 /* Process change. */
2038 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002039
paulfee0f4c2004-09-13 05:12:46 +00002040 return;
2041
2042 filtered:
2043
2044 /* This BGP update is filtered. Log the reason then update BGP entry. */
2045 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002046 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002047 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2048 peer->host,
2049 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2050 p->prefixlen, rsclient->host, reason);
2051
2052 if (ri)
paulb40d9392005-08-22 22:34:41 +00002053 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002054
2055 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002056
paulfee0f4c2004-09-13 05:12:46 +00002057 return;
2058}
2059
paul94f2b392005-06-28 12:44:16 +00002060static void
paulfee0f4c2004-09-13 05:12:46 +00002061bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2062 struct peer *peer, struct prefix *p, int type, int sub_type,
2063 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002064{
paulfee0f4c2004-09-13 05:12:46 +00002065 struct bgp_node *rn;
2066 struct bgp_info *ri;
2067 char buf[SU_ADDRSTRLEN];
2068
2069 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002070 return;
paulfee0f4c2004-09-13 05:12:46 +00002071
2072 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2073
2074 /* Lookup withdrawn route. */
2075 for (ri = rn->info; ri; ri = ri->next)
2076 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2077 break;
2078
2079 /* Withdraw specified route from routing table. */
2080 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002081 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002082 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002083 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002084 "%s Can't find the route %s/%d", peer->host,
2085 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2086 p->prefixlen);
2087
2088 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002089 bgp_unlock_node (rn);
2090}
paulfee0f4c2004-09-13 05:12:46 +00002091
paul94f2b392005-06-28 12:44:16 +00002092static int
paulfee0f4c2004-09-13 05:12:46 +00002093bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002094 afi_t afi, safi_t safi, int type, int sub_type,
2095 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2096{
2097 int ret;
2098 int aspath_loop_count = 0;
2099 struct bgp_node *rn;
2100 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002101 struct attr new_attr;
2102 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002103 struct attr *attr_new;
2104 struct bgp_info *ri;
2105 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002106 const char *reason;
paul718e3742002-12-13 20:15:29 +00002107 char buf[SU_ADDRSTRLEN];
2108
2109 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002110 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002111
paul718e3742002-12-13 20:15:29 +00002112 /* When peer's soft reconfiguration enabled. Record input packet in
2113 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002114 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2115 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002116 bgp_adj_in_set (rn, peer, attr);
2117
2118 /* Check previously received route. */
2119 for (ri = rn->info; ri; ri = ri->next)
2120 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2121 break;
2122
2123 /* AS path local-as loop check. */
2124 if (peer->change_local_as)
2125 {
2126 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2127 aspath_loop_count = 1;
2128
2129 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2130 {
2131 reason = "as-path contains our own AS;";
2132 goto filtered;
2133 }
2134 }
2135
2136 /* AS path loop check. */
2137 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2138 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2139 && aspath_loop_check(attr->aspath, bgp->confed_id)
2140 > peer->allowas_in[afi][safi]))
2141 {
2142 reason = "as-path contains our own AS;";
2143 goto filtered;
2144 }
2145
2146 /* Route reflector originator ID check. */
2147 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002148 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002149 {
2150 reason = "originator is us;";
2151 goto filtered;
2152 }
2153
2154 /* Route reflector cluster ID check. */
2155 if (bgp_cluster_filter (peer, attr))
2156 {
2157 reason = "reflected from the same cluster;";
2158 goto filtered;
2159 }
2160
2161 /* Apply incoming filter. */
2162 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2163 {
2164 reason = "filter;";
2165 goto filtered;
2166 }
2167
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002168 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002169 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002170
David Lamparterc460e572014-06-04 00:54:58 +02002171 /* Apply incoming route-map.
2172 * NB: new_attr may now contain newly allocated values from route-map "set"
2173 * commands, so we need bgp_attr_flush in the error paths, until we intern
2174 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002175 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2176 {
2177 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002178 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002179 goto filtered;
2180 }
2181
2182 /* IPv4 unicast next hop check. */
2183 if (afi == AFI_IP && safi == SAFI_UNICAST)
2184 {
2185 /* If the peer is EBGP and nexthop is not on connected route,
2186 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002187 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002188 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002189 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002190 {
2191 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002192 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002193 goto filtered;
2194 }
2195
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002196 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002197 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002198 if (new_attr.nexthop.s_addr == 0
2199 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2200 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002201 {
2202 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002203 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002204 goto filtered;
2205 }
2206 }
2207
2208 attr_new = bgp_attr_intern (&new_attr);
2209
2210 /* If the update is implicit withdraw. */
2211 if (ri)
2212 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002213 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002214
2215 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002216 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2217 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002218 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002219 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002220
2221 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002222 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002223 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2224 {
2225 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002226 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002227 peer->host,
2228 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2229 p->prefixlen);
2230
paul902212c2006-02-05 17:51:19 +00002231 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2232 {
2233 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2234 bgp_process (bgp, rn, afi, safi);
2235 }
paul718e3742002-12-13 20:15:29 +00002236 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002237 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002238 {
2239 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002240 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002241 "%s rcvd %s/%d...duplicate ignored",
2242 peer->host,
2243 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2244 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002245
2246 /* graceful restart STALE flag unset. */
2247 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2248 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002249 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002250 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002251 }
paul718e3742002-12-13 20:15:29 +00002252 }
2253
2254 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002255 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002256
paul718e3742002-12-13 20:15:29 +00002257 return 0;
2258 }
2259
Paul Jakma16d2e242007-04-10 19:32:10 +00002260 /* Withdraw/Announce before we fully processed the withdraw */
2261 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2262 {
2263 if (BGP_DEBUG (update, UPDATE_IN))
2264 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2265 peer->host,
2266 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2267 p->prefixlen);
2268 bgp_info_restore (rn, ri);
2269 }
2270
paul718e3742002-12-13 20:15:29 +00002271 /* Received Logging. */
2272 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002273 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002274 peer->host,
2275 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2276 p->prefixlen);
2277
hasso93406d82005-02-02 14:40:33 +00002278 /* graceful restart STALE flag unset. */
2279 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002280 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002281
paul718e3742002-12-13 20:15:29 +00002282 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002283 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002284
2285 /* implicit withdraw, decrement aggregate and pcount here.
2286 * only if update is accepted, they'll increment below.
2287 */
paul902212c2006-02-05 17:51:19 +00002288 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2289
paul718e3742002-12-13 20:15:29 +00002290 /* Update bgp route dampening information. */
2291 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002292 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002293 {
2294 /* This is implicit withdraw so we should update dampening
2295 information. */
2296 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2297 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002298 }
2299
paul718e3742002-12-13 20:15:29 +00002300 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002301 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002302 ri->attr = attr_new;
2303
2304 /* Update MPLS tag. */
2305 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002306 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002307
2308 /* Update bgp route dampening information. */
2309 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002310 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002311 {
2312 /* Now we do normal update dampening. */
2313 ret = bgp_damp_update (ri, rn, afi, safi);
2314 if (ret == BGP_DAMP_SUPPRESSED)
2315 {
2316 bgp_unlock_node (rn);
2317 return 0;
2318 }
2319 }
2320
2321 /* Nexthop reachability check. */
2322 if ((afi == AFI_IP || afi == AFI_IP6)
2323 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002324 && (peer->sort == BGP_PEER_IBGP
2325 || peer->sort == BGP_PEER_CONFED
2326 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002327 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002328 {
2329 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002330 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002331 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002332 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002333 }
2334 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002335 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002336
2337 /* Process change. */
2338 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2339
2340 bgp_process (bgp, rn, afi, safi);
2341 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002342
paul718e3742002-12-13 20:15:29 +00002343 return 0;
2344 }
2345
2346 /* Received Logging. */
2347 if (BGP_DEBUG (update, UPDATE_IN))
2348 {
ajsd2c1f162004-12-08 21:10:20 +00002349 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002350 peer->host,
2351 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2352 p->prefixlen);
2353 }
2354
paul718e3742002-12-13 20:15:29 +00002355 /* Make new BGP info. */
2356 new = bgp_info_new ();
2357 new->type = type;
2358 new->sub_type = sub_type;
2359 new->peer = peer;
2360 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002361 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002362
2363 /* Update MPLS tag. */
2364 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002365 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002366
2367 /* Nexthop reachability check. */
2368 if ((afi == AFI_IP || afi == AFI_IP6)
2369 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002370 && (peer->sort == BGP_PEER_IBGP
2371 || peer->sort == BGP_PEER_CONFED
2372 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002373 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002374 {
2375 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002376 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002377 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002378 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002379 }
2380 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002381 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002382
paul902212c2006-02-05 17:51:19 +00002383 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002384 bgp_aggregate_increment (bgp, p, new, afi, safi);
2385
2386 /* Register new BGP information. */
2387 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002388
2389 /* route_node_get lock */
2390 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002391
paul718e3742002-12-13 20:15:29 +00002392 /* If maximum prefix count is configured and current prefix
2393 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002394 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2395 return -1;
paul718e3742002-12-13 20:15:29 +00002396
2397 /* Process change. */
2398 bgp_process (bgp, rn, afi, safi);
2399
2400 return 0;
2401
2402 /* This BGP update is filtered. Log the reason then update BGP
2403 entry. */
2404 filtered:
2405 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002406 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002407 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2408 peer->host,
2409 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2410 p->prefixlen, reason);
2411
2412 if (ri)
paulb40d9392005-08-22 22:34:41 +00002413 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002414
2415 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002416
paul718e3742002-12-13 20:15:29 +00002417 return 0;
2418}
2419
2420int
paulfee0f4c2004-09-13 05:12:46 +00002421bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2422 afi_t afi, safi_t safi, int type, int sub_type,
2423 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2424{
2425 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002426 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002427 struct bgp *bgp;
2428 int ret;
2429
2430 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2431 soft_reconfig);
2432
2433 bgp = peer->bgp;
2434
2435 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002436 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002437 {
2438 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2439 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2440 sub_type, prd, tag);
2441 }
2442
2443 return ret;
2444}
2445
2446int
paul718e3742002-12-13 20:15:29 +00002447bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002448 afi_t afi, safi_t safi, int type, int sub_type,
2449 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002450{
2451 struct bgp *bgp;
2452 char buf[SU_ADDRSTRLEN];
2453 struct bgp_node *rn;
2454 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002455 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002456 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002457
2458 bgp = peer->bgp;
2459
David Lamparter4584c232015-04-13 09:50:00 +02002460 /* Lookup node. */
2461 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2462
2463 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2464 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2465 * the iteration over all RS clients.
2466 * Since we need to remove the entry from adj_in anyway, do that first and
2467 * if there was no entry, we don't need to do anything more. */
2468 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2469 && peer != bgp->peer_self)
2470 if (!bgp_adj_in_unset (rn, peer))
2471 {
2472 if (BGP_DEBUG (update, UPDATE_IN))
2473 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2474 "not in adj-in", peer->host,
2475 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2476 p->prefixlen);
2477 bgp_unlock_node (rn);
2478 return 0;
2479 }
2480
paulfee0f4c2004-09-13 05:12:46 +00002481 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002482 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002483 {
2484 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2485 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2486 }
2487
paul718e3742002-12-13 20:15:29 +00002488 /* Logging. */
2489 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002490 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002491 peer->host,
2492 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2493 p->prefixlen);
2494
paul718e3742002-12-13 20:15:29 +00002495 /* Lookup withdrawn route. */
2496 for (ri = rn->info; ri; ri = ri->next)
2497 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2498 break;
2499
2500 /* Withdraw specified route from routing table. */
2501 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002502 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002503 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002504 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002505 "%s Can't find the route %s/%d", peer->host,
2506 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2507 p->prefixlen);
2508
2509 /* Unlock bgp_node_get() lock. */
2510 bgp_unlock_node (rn);
2511
2512 return 0;
2513}
David Lamparter6b0655a2014-06-04 06:53:35 +02002514
paul718e3742002-12-13 20:15:29 +00002515void
2516bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2517{
2518 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002519 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002520 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002521 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002522 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002523 struct bgp_node *rn;
2524 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002525 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002526
Paul Jakmab2497022007-06-14 11:17:58 +00002527 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002528 return;
2529
paul718e3742002-12-13 20:15:29 +00002530 bgp = peer->bgp;
2531 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002532
paul718e3742002-12-13 20:15:29 +00002533 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2534 aspath = attr.aspath;
2535 attr.local_pref = bgp->default_local_pref;
2536 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2537
2538 if (afi == AFI_IP)
2539 str2prefix ("0.0.0.0/0", &p);
2540#ifdef HAVE_IPV6
2541 else if (afi == AFI_IP6)
2542 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002543 struct attr_extra *ae = attr.extra;
2544
paul718e3742002-12-13 20:15:29 +00002545 str2prefix ("::/0", &p);
2546
2547 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002548 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002549 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002550 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002551
2552 /* If the peer is on shared nextwork and we have link-local
2553 nexthop set it. */
2554 if (peer->shared_network
2555 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2556 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002557 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002558 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002559 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002560 }
2561 }
2562#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002563
2564 if (peer->default_rmap[afi][safi].name)
2565 {
paulfee0f4c2004-09-13 05:12:46 +00002566 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002567 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2568 {
2569 for (ri = rn->info; ri; ri = ri->next)
2570 {
2571 struct attr dummy_attr;
2572 struct attr_extra dummy_extra;
2573 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002574
Christian Frankedcab1bb2012-12-07 16:45:52 +00002575 /* Provide dummy so the route-map can't modify the attributes */
2576 dummy_attr.extra = &dummy_extra;
2577 bgp_attr_dup(&dummy_attr, ri->attr);
2578 info.peer = ri->peer;
2579 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002580
Christian Frankedcab1bb2012-12-07 16:45:52 +00002581 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2582 RMAP_BGP, &info);
2583
2584 /* The route map might have set attributes. If we don't flush them
2585 * here, they will be leaked. */
2586 bgp_attr_flush(&dummy_attr);
2587 if (ret != RMAP_DENYMATCH)
2588 break;
2589 }
2590 if (ret != RMAP_DENYMATCH)
2591 break;
2592 }
paulfee0f4c2004-09-13 05:12:46 +00002593 bgp->peer_self->rmap_type = 0;
2594
paul718e3742002-12-13 20:15:29 +00002595 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002596 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002597 }
2598
2599 if (withdraw)
2600 {
2601 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2602 bgp_default_withdraw_send (peer, afi, safi);
2603 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2604 }
2605 else
2606 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002607 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2608 {
2609 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2610 bgp_default_update_send (peer, &attr, afi, safi, from);
2611 }
paul718e3742002-12-13 20:15:29 +00002612 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002613
2614 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002615 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002616}
David Lamparter6b0655a2014-06-04 06:53:35 +02002617
paul718e3742002-12-13 20:15:29 +00002618static void
2619bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002620 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002621{
2622 struct bgp_node *rn;
2623 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002624 struct attr attr;
2625 struct attr_extra extra;
2626
paul718e3742002-12-13 20:15:29 +00002627 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002628 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002629
2630 if (safi != SAFI_MPLS_VPN
2631 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2632 bgp_default_originate (peer, afi, safi, 0);
2633
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002634 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2635 attr.extra = &extra;
2636
paul718e3742002-12-13 20:15:29 +00002637 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2638 for (ri = rn->info; ri; ri = ri->next)
2639 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2640 {
paulfee0f4c2004-09-13 05:12:46 +00002641 if ( (rsclient) ?
2642 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2643 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002644 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2645 else
2646 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2647 }
2648}
2649
2650void
2651bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2652{
2653 struct bgp_node *rn;
2654 struct bgp_table *table;
2655
2656 if (peer->status != Established)
2657 return;
2658
2659 if (! peer->afc_nego[afi][safi])
2660 return;
2661
2662 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2663 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2664 return;
2665
2666 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002667 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002668 else
2669 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2670 rn = bgp_route_next(rn))
2671 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002672 bgp_announce_table (peer, afi, safi, table, 0);
2673
2674 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2675 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002676}
2677
2678void
2679bgp_announce_route_all (struct peer *peer)
2680{
2681 afi_t afi;
2682 safi_t safi;
2683
2684 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2685 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2686 bgp_announce_route (peer, afi, safi);
2687}
David Lamparter6b0655a2014-06-04 06:53:35 +02002688
paul718e3742002-12-13 20:15:29 +00002689static void
paulfee0f4c2004-09-13 05:12:46 +00002690bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002691 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002692{
2693 struct bgp_node *rn;
2694 struct bgp_adj_in *ain;
2695
2696 if (! table)
2697 table = rsclient->bgp->rib[afi][safi];
2698
2699 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2700 for (ain = rn->adj_in; ain; ain = ain->next)
2701 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002702 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002703 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002704
paulfee0f4c2004-09-13 05:12:46 +00002705 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002706 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002707 }
2708}
2709
2710void
2711bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2712{
2713 struct bgp_table *table;
2714 struct bgp_node *rn;
2715
2716 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002717 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002718
2719 else
2720 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2721 rn = bgp_route_next (rn))
2722 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002723 {
2724 struct prefix_rd prd;
2725 prd.family = AF_UNSPEC;
2726 prd.prefixlen = 64;
2727 memcpy(&prd.val, rn->p.u.val, 8);
2728
2729 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2730 }
paulfee0f4c2004-09-13 05:12:46 +00002731}
David Lamparter6b0655a2014-06-04 06:53:35 +02002732
paulfee0f4c2004-09-13 05:12:46 +00002733static void
paul718e3742002-12-13 20:15:29 +00002734bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002735 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002736{
2737 int ret;
2738 struct bgp_node *rn;
2739 struct bgp_adj_in *ain;
2740
2741 if (! table)
2742 table = peer->bgp->rib[afi][safi];
2743
2744 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2745 for (ain = rn->adj_in; ain; ain = ain->next)
2746 {
2747 if (ain->peer == peer)
2748 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002749 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002750 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002751
paul718e3742002-12-13 20:15:29 +00002752 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2753 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002754 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002755
paul718e3742002-12-13 20:15:29 +00002756 if (ret < 0)
2757 {
2758 bgp_unlock_node (rn);
2759 return;
2760 }
2761 continue;
2762 }
2763 }
2764}
2765
2766void
2767bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2768{
2769 struct bgp_node *rn;
2770 struct bgp_table *table;
2771
2772 if (peer->status != Established)
2773 return;
2774
2775 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002776 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002777 else
2778 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2779 rn = bgp_route_next (rn))
2780 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002781 {
2782 struct prefix_rd prd;
2783 prd.family = AF_UNSPEC;
2784 prd.prefixlen = 64;
2785 memcpy(&prd.val, rn->p.u.val, 8);
2786
2787 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2788 }
paul718e3742002-12-13 20:15:29 +00002789}
David Lamparter6b0655a2014-06-04 06:53:35 +02002790
Chris Caputo228da422009-07-18 05:44:03 +00002791
2792struct bgp_clear_node_queue
2793{
2794 struct bgp_node *rn;
2795 enum bgp_clear_route_type purpose;
2796};
2797
paul200df112005-06-01 11:17:05 +00002798static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002799bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002800{
Chris Caputo228da422009-07-18 05:44:03 +00002801 struct bgp_clear_node_queue *cnq = data;
2802 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002803 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002804 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002805 afi_t afi = bgp_node_table (rn)->afi;
2806 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002807
Paul Jakma64e580a2006-02-21 01:09:01 +00002808 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002809
Paul Jakma64e580a2006-02-21 01:09:01 +00002810 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002811 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002812 {
2813 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002814 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2815 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002816 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002817 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2818 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002819 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002820 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002821 break;
2822 }
paul200df112005-06-01 11:17:05 +00002823 return WQ_SUCCESS;
2824}
2825
2826static void
paul0fb58d52005-11-14 14:31:49 +00002827bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002828{
Chris Caputo228da422009-07-18 05:44:03 +00002829 struct bgp_clear_node_queue *cnq = data;
2830 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002831 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002832
2833 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002834 bgp_table_unlock (table);
2835 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002836}
2837
2838static void
paul94f2b392005-06-28 12:44:16 +00002839bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002840{
Paul Jakma64e580a2006-02-21 01:09:01 +00002841 struct peer *peer = wq->spec.data;
2842
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002843 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002844 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002845
2846 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002847}
2848
2849static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002850bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002851{
Paul Jakmaa2943652009-07-21 14:02:04 +01002852 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002853
Paul Jakmaa2943652009-07-21 14:02:04 +01002854 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002855#undef CLEAR_QUEUE_NAME_LEN
2856
2857 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002858 {
2859 zlog_err ("%s: Failed to allocate work queue", __func__);
2860 exit (1);
2861 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002862 peer->clear_node_queue->spec.hold = 10;
2863 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2864 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2865 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2866 peer->clear_node_queue->spec.max_retries = 0;
2867
2868 /* we only 'lock' this peer reference when the queue is actually active */
2869 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002870}
2871
paul718e3742002-12-13 20:15:29 +00002872static void
2873bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002874 struct bgp_table *table, struct peer *rsclient,
2875 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002876{
2877 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002878
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002879
paul718e3742002-12-13 20:15:29 +00002880 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002881 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002882
hasso6cf159b2005-03-21 10:28:14 +00002883 /* If still no table => afi/safi isn't configured at all or smth. */
2884 if (! table)
2885 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002886
2887 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2888 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002889 struct bgp_info *ri;
2890 struct bgp_adj_in *ain;
2891 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002892
2893 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2894 * queued for every clearing peer, regardless of whether it is
2895 * relevant to the peer at hand.
2896 *
2897 * Overview: There are 3 different indices which need to be
2898 * scrubbed, potentially, when a peer is removed:
2899 *
2900 * 1 peer's routes visible via the RIB (ie accepted routes)
2901 * 2 peer's routes visible by the (optional) peer's adj-in index
2902 * 3 other routes visible by the peer's adj-out index
2903 *
2904 * 3 there is no hurry in scrubbing, once the struct peer is
2905 * removed from bgp->peer, we could just GC such deleted peer's
2906 * adj-outs at our leisure.
2907 *
2908 * 1 and 2 must be 'scrubbed' in some way, at least made
2909 * invisible via RIB index before peer session is allowed to be
2910 * brought back up. So one needs to know when such a 'search' is
2911 * complete.
2912 *
2913 * Ideally:
2914 *
2915 * - there'd be a single global queue or a single RIB walker
2916 * - rather than tracking which route_nodes still need to be
2917 * examined on a peer basis, we'd track which peers still
2918 * aren't cleared
2919 *
2920 * Given that our per-peer prefix-counts now should be reliable,
2921 * this may actually be achievable. It doesn't seem to be a huge
2922 * problem at this time,
2923 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002924 for (ain = rn->adj_in; ain; ain = ain->next)
2925 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2926 {
2927 bgp_adj_in_remove (rn, ain);
2928 bgp_unlock_node (rn);
2929 break;
2930 }
2931 for (aout = rn->adj_out; aout; aout = aout->next)
2932 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2933 {
2934 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2935 bgp_unlock_node (rn);
2936 break;
2937 }
2938
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002939 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002940 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002941 {
Chris Caputo228da422009-07-18 05:44:03 +00002942 struct bgp_clear_node_queue *cnq;
2943
2944 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002945 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002946 bgp_lock_node (rn);
2947 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2948 sizeof (struct bgp_clear_node_queue));
2949 cnq->rn = rn;
2950 cnq->purpose = purpose;
2951 work_queue_add (peer->clear_node_queue, cnq);
2952 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002953 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002954 }
2955 return;
2956}
2957
2958void
Chris Caputo228da422009-07-18 05:44:03 +00002959bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2960 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002961{
2962 struct bgp_node *rn;
2963 struct bgp_table *table;
2964 struct peer *rsclient;
2965 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002966
Paul Jakma64e580a2006-02-21 01:09:01 +00002967 if (peer->clear_node_queue == NULL)
2968 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002969
Paul Jakmaca058a32006-09-14 02:58:49 +00002970 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2971 * Idle until it receives a Clearing_Completed event. This protects
2972 * against peers which flap faster than we can we clear, which could
2973 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002974 *
2975 * a) race with routes from the new session being installed before
2976 * clear_route_node visits the node (to delete the route of that
2977 * peer)
2978 * b) resource exhaustion, clear_route_node likely leads to an entry
2979 * on the process_main queue. Fast-flapping could cause that queue
2980 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002981 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002982 if (!peer->clear_node_queue->thread)
2983 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002984
Chris Caputo228da422009-07-18 05:44:03 +00002985 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002986 {
Chris Caputo228da422009-07-18 05:44:03 +00002987 case BGP_CLEAR_ROUTE_NORMAL:
2988 if (safi != SAFI_MPLS_VPN)
2989 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2990 else
2991 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2992 rn = bgp_route_next (rn))
2993 if ((table = rn->info) != NULL)
2994 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2995
2996 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2997 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2998 PEER_FLAG_RSERVER_CLIENT))
2999 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3000 break;
3001
3002 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3003 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3004 break;
3005
3006 default:
3007 assert (0);
3008 break;
paulfee0f4c2004-09-13 05:12:46 +00003009 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00003010
Paul Jakmaca058a32006-09-14 02:58:49 +00003011 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00003012 * completion function won't be run by workqueue code - call it here.
3013 * XXX: Actually, this assumption doesn't hold, see
3014 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00003015 *
3016 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00003017 * really needed if peer state is Established - peers in
3018 * pre-Established states shouldn't have any route-update state
3019 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00003020 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00003021 * We still can get here in pre-Established though, through
3022 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
3023 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00003024 *
3025 * At some future point, this check could be move to the top of the
3026 * function, and do a quick early-return when state is
3027 * pre-Established, avoiding above list and table scans. Once we're
3028 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00003029 */
3030 if (!peer->clear_node_queue->thread)
3031 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00003032}
3033
3034void
3035bgp_clear_route_all (struct peer *peer)
3036{
3037 afi_t afi;
3038 safi_t safi;
3039
3040 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3041 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003042 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003043}
3044
3045void
3046bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3047{
3048 struct bgp_table *table;
3049 struct bgp_node *rn;
3050 struct bgp_adj_in *ain;
3051
3052 table = peer->bgp->rib[afi][safi];
3053
3054 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3055 for (ain = rn->adj_in; ain ; ain = ain->next)
3056 if (ain->peer == peer)
3057 {
3058 bgp_adj_in_remove (rn, ain);
3059 bgp_unlock_node (rn);
3060 break;
3061 }
3062}
hasso93406d82005-02-02 14:40:33 +00003063
3064void
3065bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3066{
3067 struct bgp_node *rn;
3068 struct bgp_info *ri;
3069 struct bgp_table *table;
3070
3071 table = peer->bgp->rib[afi][safi];
3072
3073 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3074 {
3075 for (ri = rn->info; ri; ri = ri->next)
3076 if (ri->peer == peer)
3077 {
3078 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3079 bgp_rib_remove (rn, ri, peer, afi, safi);
3080 break;
3081 }
3082 }
3083}
David Lamparter6b0655a2014-06-04 06:53:35 +02003084
paul718e3742002-12-13 20:15:29 +00003085/* Delete all kernel routes. */
3086void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003087bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003088{
3089 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003090 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003091 struct bgp_node *rn;
3092 struct bgp_table *table;
3093 struct bgp_info *ri;
3094
paul1eb8ef22005-04-07 07:30:20 +00003095 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003096 {
3097 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3098
3099 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3100 for (ri = rn->info; ri; ri = ri->next)
3101 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3102 && ri->type == ZEBRA_ROUTE_BGP
3103 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003104 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003105
3106 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3107
3108 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3109 for (ri = rn->info; ri; ri = ri->next)
3110 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3111 && ri->type == ZEBRA_ROUTE_BGP
3112 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003113 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003114 }
3115}
3116
3117void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003118bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003119{
3120 vty_reset ();
3121 bgp_zclient_reset ();
3122 access_list_reset ();
3123 prefix_list_reset ();
3124}
David Lamparter6b0655a2014-06-04 06:53:35 +02003125
paul718e3742002-12-13 20:15:29 +00003126/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3127 value. */
3128int
3129bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3130{
3131 u_char *pnt;
3132 u_char *lim;
3133 struct prefix p;
3134 int psize;
3135 int ret;
3136
3137 /* Check peer status. */
3138 if (peer->status != Established)
3139 return 0;
3140
3141 pnt = packet->nlri;
3142 lim = pnt + packet->length;
3143
3144 for (; pnt < lim; pnt += psize)
3145 {
3146 /* Clear prefix structure. */
3147 memset (&p, 0, sizeof (struct prefix));
3148
3149 /* Fetch prefix length. */
3150 p.prefixlen = *pnt++;
3151 p.family = afi2family (packet->afi);
3152
3153 /* Already checked in nlri_sanity_check(). We do double check
3154 here. */
3155 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3156 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3157 return -1;
3158
3159 /* Packet size overflow check. */
3160 psize = PSIZE (p.prefixlen);
3161
3162 /* When packet overflow occur return immediately. */
3163 if (pnt + psize > lim)
3164 return -1;
3165
3166 /* Fetch prefix from NLRI packet. */
3167 memcpy (&p.u.prefix, pnt, psize);
3168
3169 /* Check address. */
3170 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3171 {
3172 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3173 {
paulf5ba3872004-07-09 12:11:31 +00003174 /*
3175 * From draft-ietf-idr-bgp4-22, Section 6.3:
3176 * If a BGP router receives an UPDATE message with a
3177 * semantically incorrect NLRI field, in which a prefix is
3178 * semantically incorrect (eg. an unexpected multicast IP
3179 * address), it should ignore the prefix.
3180 */
paul718e3742002-12-13 20:15:29 +00003181 zlog (peer->log, LOG_ERR,
3182 "IPv4 unicast NLRI is multicast address %s",
3183 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003184
paul718e3742002-12-13 20:15:29 +00003185 return -1;
3186 }
3187 }
3188
3189#ifdef HAVE_IPV6
3190 /* Check address. */
3191 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3192 {
3193 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3194 {
3195 char buf[BUFSIZ];
3196
3197 zlog (peer->log, LOG_WARNING,
3198 "IPv6 link-local NLRI received %s ignore this NLRI",
3199 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3200
3201 continue;
3202 }
3203 }
3204#endif /* HAVE_IPV6 */
3205
3206 /* Normal process. */
3207 if (attr)
3208 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3209 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3210 else
3211 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3212 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3213
3214 /* Address family configuration mismatch or maximum-prefix count
3215 overflow. */
3216 if (ret < 0)
3217 return -1;
3218 }
3219
3220 /* Packet length consistency check. */
3221 if (pnt != lim)
3222 return -1;
3223
3224 return 0;
3225}
3226
3227/* NLRI encode syntax check routine. */
3228int
3229bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3230 bgp_size_t length)
3231{
3232 u_char *end;
3233 u_char prefixlen;
3234 int psize;
3235
3236 end = pnt + length;
3237
3238 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3239 syntactic validity. If the field is syntactically incorrect,
3240 then the Error Subcode is set to Invalid Network Field. */
3241
3242 while (pnt < end)
3243 {
3244 prefixlen = *pnt++;
3245
3246 /* Prefix length check. */
3247 if ((afi == AFI_IP && prefixlen > 32)
3248 || (afi == AFI_IP6 && prefixlen > 128))
3249 {
3250 plog_err (peer->log,
3251 "%s [Error] Update packet error (wrong prefix length %d)",
3252 peer->host, prefixlen);
3253 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3254 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3255 return -1;
3256 }
3257
3258 /* Packet size overflow check. */
3259 psize = PSIZE (prefixlen);
3260
3261 if (pnt + psize > end)
3262 {
3263 plog_err (peer->log,
3264 "%s [Error] Update packet error"
3265 " (prefix data overflow prefix size is %d)",
3266 peer->host, psize);
3267 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3268 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3269 return -1;
3270 }
3271
3272 pnt += psize;
3273 }
3274
3275 /* Packet length consistency check. */
3276 if (pnt != end)
3277 {
3278 plog_err (peer->log,
3279 "%s [Error] Update packet error"
3280 " (prefix length mismatch with total length)",
3281 peer->host);
3282 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3283 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3284 return -1;
3285 }
3286 return 0;
3287}
David Lamparter6b0655a2014-06-04 06:53:35 +02003288
paul94f2b392005-06-28 12:44:16 +00003289static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003290bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003291{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003292 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003293}
3294
paul94f2b392005-06-28 12:44:16 +00003295static void
paul718e3742002-12-13 20:15:29 +00003296bgp_static_free (struct bgp_static *bgp_static)
3297{
3298 if (bgp_static->rmap.name)
3299 free (bgp_static->rmap.name);
3300 XFREE (MTYPE_BGP_STATIC, bgp_static);
3301}
3302
paul94f2b392005-06-28 12:44:16 +00003303static void
paulfee0f4c2004-09-13 05:12:46 +00003304bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3305 struct prefix *p, afi_t afi, safi_t safi)
3306{
3307 struct bgp_node *rn;
3308 struct bgp_info *ri;
3309
3310 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3311
3312 /* Check selected route and self inserted route. */
3313 for (ri = rn->info; ri; ri = ri->next)
3314 if (ri->peer == bgp->peer_self
3315 && ri->type == ZEBRA_ROUTE_BGP
3316 && ri->sub_type == BGP_ROUTE_STATIC)
3317 break;
3318
3319 /* Withdraw static BGP route from routing table. */
3320 if (ri)
3321 {
paulfee0f4c2004-09-13 05:12:46 +00003322 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003323 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003324 }
3325
3326 /* Unlock bgp_node_lookup. */
3327 bgp_unlock_node (rn);
3328}
3329
paul94f2b392005-06-28 12:44:16 +00003330static void
paulfee0f4c2004-09-13 05:12:46 +00003331bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003332 struct bgp_static *bgp_static,
3333 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003334{
3335 struct bgp_node *rn;
3336 struct bgp_info *ri;
3337 struct bgp_info *new;
3338 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003339 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003340 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003341 struct attr new_attr;
3342 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003343 struct bgp *bgp;
3344 int ret;
3345 char buf[SU_ADDRSTRLEN];
3346
3347 bgp = rsclient->bgp;
3348
Paul Jakma06e110f2006-05-12 23:29:22 +00003349 assert (bgp_static);
3350 if (!bgp_static)
3351 return;
3352
paulfee0f4c2004-09-13 05:12:46 +00003353 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3354
3355 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003356
3357 attr.nexthop = bgp_static->igpnexthop;
3358 attr.med = bgp_static->igpmetric;
3359 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003360
Paul Jakma41367172007-08-06 15:24:51 +00003361 if (bgp_static->atomic)
3362 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3363
paulfee0f4c2004-09-13 05:12:46 +00003364 /* Apply network route-map for export to this rsclient. */
3365 if (bgp_static->rmap.name)
3366 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003367 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003368 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003369 info.attr = &attr_tmp;
3370
paulfee0f4c2004-09-13 05:12:46 +00003371 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3372 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3373
3374 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3375
3376 rsclient->rmap_type = 0;
3377
3378 if (ret == RMAP_DENYMATCH)
3379 {
3380 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003381 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003382
3383 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003384 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003385 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003386 bgp_attr_extra_free (&attr);
3387
paulfee0f4c2004-09-13 05:12:46 +00003388 return;
3389 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003390 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003391 }
3392 else
3393 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003394
3395 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003396 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003397
paulfee0f4c2004-09-13 05:12:46 +00003398 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3399
Paul Jakmafb982c22007-05-04 20:15:47 +00003400 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3401 == RMAP_DENY)
3402 {
paulfee0f4c2004-09-13 05:12:46 +00003403 /* This BGP update is filtered. Log the reason then update BGP entry. */
3404 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003405 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003406 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3407 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3408 p->prefixlen, rsclient->host);
3409
3410 bgp->peer_self->rmap_type = 0;
3411
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003412 bgp_attr_unintern (&attr_new);
3413 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003414 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003415
3416 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3417
3418 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003419 }
paulfee0f4c2004-09-13 05:12:46 +00003420
3421 bgp->peer_self->rmap_type = 0;
3422
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003423 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003424 attr_new = bgp_attr_intern (&new_attr);
3425
3426 for (ri = rn->info; ri; ri = ri->next)
3427 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3428 && ri->sub_type == BGP_ROUTE_STATIC)
3429 break;
3430
3431 if (ri)
3432 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003433 if (attrhash_cmp (ri->attr, attr_new) &&
3434 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003435 {
3436 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003437 bgp_attr_unintern (&attr_new);
3438 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003439 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003440 return;
3441 }
3442 else
3443 {
3444 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003445 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003446
3447 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003448 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3449 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003450 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003451 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003452 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003453
3454 /* Process change. */
3455 bgp_process (bgp, rn, afi, safi);
3456 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003457 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003458 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003459 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003460 }
paulfee0f4c2004-09-13 05:12:46 +00003461 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003462
paulfee0f4c2004-09-13 05:12:46 +00003463 /* Make new BGP info. */
3464 new = bgp_info_new ();
3465 new->type = ZEBRA_ROUTE_BGP;
3466 new->sub_type = BGP_ROUTE_STATIC;
3467 new->peer = bgp->peer_self;
3468 SET_FLAG (new->flags, BGP_INFO_VALID);
3469 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003470 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003471
3472 /* Register new BGP information. */
3473 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003474
3475 /* route_node_get lock */
3476 bgp_unlock_node (rn);
3477
paulfee0f4c2004-09-13 05:12:46 +00003478 /* Process change. */
3479 bgp_process (bgp, rn, afi, safi);
3480
3481 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003482 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003483 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003484}
3485
paul94f2b392005-06-28 12:44:16 +00003486static void
paulfee0f4c2004-09-13 05:12:46 +00003487bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003488 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3489{
3490 struct bgp_node *rn;
3491 struct bgp_info *ri;
3492 struct bgp_info *new;
3493 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003494 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003495 struct attr *attr_new;
3496 int ret;
3497
Paul Jakmadd8103a2006-05-12 23:27:30 +00003498 assert (bgp_static);
3499 if (!bgp_static)
3500 return;
3501
paulfee0f4c2004-09-13 05:12:46 +00003502 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003503
3504 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003505
3506 attr.nexthop = bgp_static->igpnexthop;
3507 attr.med = bgp_static->igpmetric;
3508 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003509
Paul Jakma41367172007-08-06 15:24:51 +00003510 if (bgp_static->atomic)
3511 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3512
paul718e3742002-12-13 20:15:29 +00003513 /* Apply route-map. */
3514 if (bgp_static->rmap.name)
3515 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003516 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003517 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003518 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003519
paulfee0f4c2004-09-13 05:12:46 +00003520 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3521
paul718e3742002-12-13 20:15:29 +00003522 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003523
paulfee0f4c2004-09-13 05:12:46 +00003524 bgp->peer_self->rmap_type = 0;
3525
paul718e3742002-12-13 20:15:29 +00003526 if (ret == RMAP_DENYMATCH)
3527 {
3528 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003529 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003530
3531 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003532 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003533 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003534 bgp_static_withdraw (bgp, p, afi, safi);
3535 return;
3536 }
paul286e1e72003-08-08 00:24:31 +00003537 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003538 }
paul286e1e72003-08-08 00:24:31 +00003539 else
3540 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003541
3542 for (ri = rn->info; ri; ri = ri->next)
3543 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3544 && ri->sub_type == BGP_ROUTE_STATIC)
3545 break;
3546
3547 if (ri)
3548 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003549 if (attrhash_cmp (ri->attr, attr_new) &&
3550 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003551 {
3552 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003553 bgp_attr_unintern (&attr_new);
3554 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003555 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003556 return;
3557 }
3558 else
3559 {
3560 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003561 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003562
3563 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003564 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3565 bgp_info_restore(rn, ri);
3566 else
3567 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003568 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003569 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003570 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003571
3572 /* Process change. */
3573 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3574 bgp_process (bgp, rn, afi, safi);
3575 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003576 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003577 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003578 return;
3579 }
3580 }
3581
3582 /* Make new BGP info. */
3583 new = bgp_info_new ();
3584 new->type = ZEBRA_ROUTE_BGP;
3585 new->sub_type = BGP_ROUTE_STATIC;
3586 new->peer = bgp->peer_self;
3587 SET_FLAG (new->flags, BGP_INFO_VALID);
3588 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003589 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003590
3591 /* Aggregate address increment. */
3592 bgp_aggregate_increment (bgp, p, new, afi, safi);
3593
3594 /* Register new BGP information. */
3595 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003596
3597 /* route_node_get lock */
3598 bgp_unlock_node (rn);
3599
paul718e3742002-12-13 20:15:29 +00003600 /* Process change. */
3601 bgp_process (bgp, rn, afi, safi);
3602
3603 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003604 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003605 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003606}
3607
3608void
paulfee0f4c2004-09-13 05:12:46 +00003609bgp_static_update (struct bgp *bgp, struct prefix *p,
3610 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3611{
3612 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003613 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003614
3615 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3616
paul1eb8ef22005-04-07 07:30:20 +00003617 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003618 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003619 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3620 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003621 }
3622}
3623
paul94f2b392005-06-28 12:44:16 +00003624static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003625bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3626 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003627{
3628 struct bgp_node *rn;
3629 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003630
paulfee0f4c2004-09-13 05:12:46 +00003631 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003632
3633 /* Make new BGP info. */
3634 new = bgp_info_new ();
3635 new->type = ZEBRA_ROUTE_BGP;
3636 new->sub_type = BGP_ROUTE_STATIC;
3637 new->peer = bgp->peer_self;
3638 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3639 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003640 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003641 new->extra = bgp_info_extra_new();
3642 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003643
3644 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003645 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003646
3647 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003648 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003649
paul200df112005-06-01 11:17:05 +00003650 /* route_node_get lock */
3651 bgp_unlock_node (rn);
3652
paul718e3742002-12-13 20:15:29 +00003653 /* Process change. */
3654 bgp_process (bgp, rn, afi, safi);
3655}
3656
3657void
3658bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3659 safi_t safi)
3660{
3661 struct bgp_node *rn;
3662 struct bgp_info *ri;
3663
paulfee0f4c2004-09-13 05:12:46 +00003664 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003665
3666 /* Check selected route and self inserted route. */
3667 for (ri = rn->info; ri; ri = ri->next)
3668 if (ri->peer == bgp->peer_self
3669 && ri->type == ZEBRA_ROUTE_BGP
3670 && ri->sub_type == BGP_ROUTE_STATIC)
3671 break;
3672
3673 /* Withdraw static BGP route from routing table. */
3674 if (ri)
3675 {
3676 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003677 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003678 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003679 }
3680
3681 /* Unlock bgp_node_lookup. */
3682 bgp_unlock_node (rn);
3683}
3684
3685void
paulfee0f4c2004-09-13 05:12:46 +00003686bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3687{
3688 struct bgp_static *bgp_static;
3689 struct bgp *bgp;
3690 struct bgp_node *rn;
3691 struct prefix *p;
3692
3693 bgp = rsclient->bgp;
3694
3695 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3696 if ((bgp_static = rn->info) != NULL)
3697 {
3698 p = &rn->p;
3699
3700 bgp_static_update_rsclient (rsclient, p, bgp_static,
3701 afi, safi);
3702 }
3703}
3704
paul94f2b392005-06-28 12:44:16 +00003705static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003706bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3707 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003708{
3709 struct bgp_node *rn;
3710 struct bgp_info *ri;
3711
paulfee0f4c2004-09-13 05:12:46 +00003712 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003713
3714 /* Check selected route and self inserted route. */
3715 for (ri = rn->info; ri; ri = ri->next)
3716 if (ri->peer == bgp->peer_self
3717 && ri->type == ZEBRA_ROUTE_BGP
3718 && ri->sub_type == BGP_ROUTE_STATIC)
3719 break;
3720
3721 /* Withdraw static BGP route from routing table. */
3722 if (ri)
3723 {
3724 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003725 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003726 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003727 }
3728
3729 /* Unlock bgp_node_lookup. */
3730 bgp_unlock_node (rn);
3731}
3732
3733/* Configure static BGP network. When user don't run zebra, static
3734 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003735static int
paulfd79ac92004-10-13 05:06:08 +00003736bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003737 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003738{
3739 int ret;
3740 struct prefix p;
3741 struct bgp_static *bgp_static;
3742 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003743 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003744
3745 /* Convert IP prefix string to struct prefix. */
3746 ret = str2prefix (ip_str, &p);
3747 if (! ret)
3748 {
3749 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3750 return CMD_WARNING;
3751 }
3752#ifdef HAVE_IPV6
3753 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3754 {
3755 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3756 VTY_NEWLINE);
3757 return CMD_WARNING;
3758 }
3759#endif /* HAVE_IPV6 */
3760
3761 apply_mask (&p);
3762
3763 /* Set BGP static route configuration. */
3764 rn = bgp_node_get (bgp->route[afi][safi], &p);
3765
3766 if (rn->info)
3767 {
3768 /* Configuration change. */
3769 bgp_static = rn->info;
3770
3771 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003772 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3773 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003774
paul718e3742002-12-13 20:15:29 +00003775 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003776
paul718e3742002-12-13 20:15:29 +00003777 if (rmap)
3778 {
3779 if (bgp_static->rmap.name)
3780 free (bgp_static->rmap.name);
3781 bgp_static->rmap.name = strdup (rmap);
3782 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3783 }
3784 else
3785 {
3786 if (bgp_static->rmap.name)
3787 free (bgp_static->rmap.name);
3788 bgp_static->rmap.name = NULL;
3789 bgp_static->rmap.map = NULL;
3790 bgp_static->valid = 0;
3791 }
3792 bgp_unlock_node (rn);
3793 }
3794 else
3795 {
3796 /* New configuration. */
3797 bgp_static = bgp_static_new ();
3798 bgp_static->backdoor = backdoor;
3799 bgp_static->valid = 0;
3800 bgp_static->igpmetric = 0;
3801 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003802
paul718e3742002-12-13 20:15:29 +00003803 if (rmap)
3804 {
3805 if (bgp_static->rmap.name)
3806 free (bgp_static->rmap.name);
3807 bgp_static->rmap.name = strdup (rmap);
3808 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3809 }
3810 rn->info = bgp_static;
3811 }
3812
3813 /* If BGP scan is not enabled, we should install this route here. */
3814 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3815 {
3816 bgp_static->valid = 1;
3817
3818 if (need_update)
3819 bgp_static_withdraw (bgp, &p, afi, safi);
3820
3821 if (! bgp_static->backdoor)
3822 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3823 }
3824
3825 return CMD_SUCCESS;
3826}
3827
3828/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003829static int
paulfd79ac92004-10-13 05:06:08 +00003830bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003831 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003832{
3833 int ret;
3834 struct prefix p;
3835 struct bgp_static *bgp_static;
3836 struct bgp_node *rn;
3837
3838 /* Convert IP prefix string to struct prefix. */
3839 ret = str2prefix (ip_str, &p);
3840 if (! ret)
3841 {
3842 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3843 return CMD_WARNING;
3844 }
3845#ifdef HAVE_IPV6
3846 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3847 {
3848 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3849 VTY_NEWLINE);
3850 return CMD_WARNING;
3851 }
3852#endif /* HAVE_IPV6 */
3853
3854 apply_mask (&p);
3855
3856 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3857 if (! rn)
3858 {
3859 vty_out (vty, "%% Can't find specified static route configuration.%s",
3860 VTY_NEWLINE);
3861 return CMD_WARNING;
3862 }
3863
3864 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003865
paul718e3742002-12-13 20:15:29 +00003866 /* Update BGP RIB. */
3867 if (! bgp_static->backdoor)
3868 bgp_static_withdraw (bgp, &p, afi, safi);
3869
3870 /* Clear configuration. */
3871 bgp_static_free (bgp_static);
3872 rn->info = NULL;
3873 bgp_unlock_node (rn);
3874 bgp_unlock_node (rn);
3875
3876 return CMD_SUCCESS;
3877}
3878
3879/* Called from bgp_delete(). Delete all static routes from the BGP
3880 instance. */
3881void
3882bgp_static_delete (struct bgp *bgp)
3883{
3884 afi_t afi;
3885 safi_t safi;
3886 struct bgp_node *rn;
3887 struct bgp_node *rm;
3888 struct bgp_table *table;
3889 struct bgp_static *bgp_static;
3890
3891 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3892 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3893 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3894 if (rn->info != NULL)
3895 {
3896 if (safi == SAFI_MPLS_VPN)
3897 {
3898 table = rn->info;
3899
3900 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3901 {
3902 bgp_static = rn->info;
3903 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3904 AFI_IP, SAFI_MPLS_VPN,
3905 (struct prefix_rd *)&rn->p,
3906 bgp_static->tag);
3907 bgp_static_free (bgp_static);
3908 rn->info = NULL;
3909 bgp_unlock_node (rn);
3910 }
3911 }
3912 else
3913 {
3914 bgp_static = rn->info;
3915 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3916 bgp_static_free (bgp_static);
3917 rn->info = NULL;
3918 bgp_unlock_node (rn);
3919 }
3920 }
3921}
3922
3923int
paulfd79ac92004-10-13 05:06:08 +00003924bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3925 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003926{
3927 int ret;
3928 struct prefix p;
3929 struct prefix_rd prd;
3930 struct bgp *bgp;
3931 struct bgp_node *prn;
3932 struct bgp_node *rn;
3933 struct bgp_table *table;
3934 struct bgp_static *bgp_static;
3935 u_char tag[3];
3936
3937 bgp = vty->index;
3938
3939 ret = str2prefix (ip_str, &p);
3940 if (! ret)
3941 {
3942 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3943 return CMD_WARNING;
3944 }
3945 apply_mask (&p);
3946
3947 ret = str2prefix_rd (rd_str, &prd);
3948 if (! ret)
3949 {
3950 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3951 return CMD_WARNING;
3952 }
3953
3954 ret = str2tag (tag_str, tag);
3955 if (! ret)
3956 {
3957 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3958 return CMD_WARNING;
3959 }
3960
3961 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3962 (struct prefix *)&prd);
3963 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003964 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003965 else
3966 bgp_unlock_node (prn);
3967 table = prn->info;
3968
3969 rn = bgp_node_get (table, &p);
3970
3971 if (rn->info)
3972 {
3973 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3974 bgp_unlock_node (rn);
3975 }
3976 else
3977 {
3978 /* New configuration. */
3979 bgp_static = bgp_static_new ();
3980 bgp_static->valid = 1;
3981 memcpy (bgp_static->tag, tag, 3);
3982 rn->info = bgp_static;
3983
3984 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3985 }
3986
3987 return CMD_SUCCESS;
3988}
3989
3990/* Configure static BGP network. */
3991int
paulfd79ac92004-10-13 05:06:08 +00003992bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3993 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003994{
3995 int ret;
3996 struct bgp *bgp;
3997 struct prefix p;
3998 struct prefix_rd prd;
3999 struct bgp_node *prn;
4000 struct bgp_node *rn;
4001 struct bgp_table *table;
4002 struct bgp_static *bgp_static;
4003 u_char tag[3];
4004
4005 bgp = vty->index;
4006
4007 /* Convert IP prefix string to struct prefix. */
4008 ret = str2prefix (ip_str, &p);
4009 if (! ret)
4010 {
4011 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4012 return CMD_WARNING;
4013 }
4014 apply_mask (&p);
4015
4016 ret = str2prefix_rd (rd_str, &prd);
4017 if (! ret)
4018 {
4019 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4020 return CMD_WARNING;
4021 }
4022
4023 ret = str2tag (tag_str, tag);
4024 if (! ret)
4025 {
4026 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4027 return CMD_WARNING;
4028 }
4029
4030 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4031 (struct prefix *)&prd);
4032 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004033 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004034 else
4035 bgp_unlock_node (prn);
4036 table = prn->info;
4037
4038 rn = bgp_node_lookup (table, &p);
4039
4040 if (rn)
4041 {
4042 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4043
4044 bgp_static = rn->info;
4045 bgp_static_free (bgp_static);
4046 rn->info = NULL;
4047 bgp_unlock_node (rn);
4048 bgp_unlock_node (rn);
4049 }
4050 else
4051 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4052
4053 return CMD_SUCCESS;
4054}
David Lamparter6b0655a2014-06-04 06:53:35 +02004055
paul718e3742002-12-13 20:15:29 +00004056DEFUN (bgp_network,
4057 bgp_network_cmd,
4058 "network A.B.C.D/M",
4059 "Specify a network to announce via BGP\n"
4060 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4061{
4062 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004063 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004064}
4065
4066DEFUN (bgp_network_route_map,
4067 bgp_network_route_map_cmd,
4068 "network A.B.C.D/M route-map WORD",
4069 "Specify a network to announce via BGP\n"
4070 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4071 "Route-map to modify the attributes\n"
4072 "Name of the route map\n")
4073{
4074 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004075 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004076}
4077
4078DEFUN (bgp_network_backdoor,
4079 bgp_network_backdoor_cmd,
4080 "network A.B.C.D/M backdoor",
4081 "Specify a network to announce via BGP\n"
4082 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4083 "Specify a BGP backdoor route\n")
4084{
Paul Jakma41367172007-08-06 15:24:51 +00004085 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004086 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004087}
4088
4089DEFUN (bgp_network_mask,
4090 bgp_network_mask_cmd,
4091 "network A.B.C.D mask A.B.C.D",
4092 "Specify a network to announce via BGP\n"
4093 "Network number\n"
4094 "Network mask\n"
4095 "Network mask\n")
4096{
4097 int ret;
4098 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004099
paul718e3742002-12-13 20:15:29 +00004100 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4101 if (! ret)
4102 {
4103 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4104 return CMD_WARNING;
4105 }
4106
4107 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004108 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004109}
4110
4111DEFUN (bgp_network_mask_route_map,
4112 bgp_network_mask_route_map_cmd,
4113 "network A.B.C.D mask A.B.C.D route-map WORD",
4114 "Specify a network to announce via BGP\n"
4115 "Network number\n"
4116 "Network mask\n"
4117 "Network mask\n"
4118 "Route-map to modify the attributes\n"
4119 "Name of the route map\n")
4120{
4121 int ret;
4122 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004123
paul718e3742002-12-13 20:15:29 +00004124 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4125 if (! ret)
4126 {
4127 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4128 return CMD_WARNING;
4129 }
4130
4131 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004132 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004133}
4134
4135DEFUN (bgp_network_mask_backdoor,
4136 bgp_network_mask_backdoor_cmd,
4137 "network A.B.C.D mask A.B.C.D backdoor",
4138 "Specify a network to announce via BGP\n"
4139 "Network number\n"
4140 "Network mask\n"
4141 "Network mask\n"
4142 "Specify a BGP backdoor route\n")
4143{
4144 int ret;
4145 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004146
paul718e3742002-12-13 20:15:29 +00004147 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4148 if (! ret)
4149 {
4150 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4151 return CMD_WARNING;
4152 }
4153
Paul Jakma41367172007-08-06 15:24:51 +00004154 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004155 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004156}
4157
4158DEFUN (bgp_network_mask_natural,
4159 bgp_network_mask_natural_cmd,
4160 "network A.B.C.D",
4161 "Specify a network to announce via BGP\n"
4162 "Network number\n")
4163{
4164 int ret;
4165 char prefix_str[BUFSIZ];
4166
4167 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4168 if (! ret)
4169 {
4170 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4171 return CMD_WARNING;
4172 }
4173
4174 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004175 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004176}
4177
4178DEFUN (bgp_network_mask_natural_route_map,
4179 bgp_network_mask_natural_route_map_cmd,
4180 "network A.B.C.D route-map WORD",
4181 "Specify a network to announce via BGP\n"
4182 "Network number\n"
4183 "Route-map to modify the attributes\n"
4184 "Name of the route map\n")
4185{
4186 int ret;
4187 char prefix_str[BUFSIZ];
4188
4189 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4190 if (! ret)
4191 {
4192 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4193 return CMD_WARNING;
4194 }
4195
4196 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004197 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004198}
4199
4200DEFUN (bgp_network_mask_natural_backdoor,
4201 bgp_network_mask_natural_backdoor_cmd,
4202 "network A.B.C.D backdoor",
4203 "Specify a network to announce via BGP\n"
4204 "Network number\n"
4205 "Specify a BGP backdoor route\n")
4206{
4207 int ret;
4208 char prefix_str[BUFSIZ];
4209
4210 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4211 if (! ret)
4212 {
4213 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4214 return CMD_WARNING;
4215 }
4216
Paul Jakma41367172007-08-06 15:24:51 +00004217 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004218 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004219}
4220
4221DEFUN (no_bgp_network,
4222 no_bgp_network_cmd,
4223 "no network A.B.C.D/M",
4224 NO_STR
4225 "Specify a network to announce via BGP\n"
4226 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4227{
4228 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4229 bgp_node_safi (vty));
4230}
4231
4232ALIAS (no_bgp_network,
4233 no_bgp_network_route_map_cmd,
4234 "no network A.B.C.D/M route-map WORD",
4235 NO_STR
4236 "Specify a network to announce via BGP\n"
4237 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4238 "Route-map to modify the attributes\n"
4239 "Name of the route map\n")
4240
4241ALIAS (no_bgp_network,
4242 no_bgp_network_backdoor_cmd,
4243 "no network A.B.C.D/M backdoor",
4244 NO_STR
4245 "Specify a network to announce via BGP\n"
4246 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4247 "Specify a BGP backdoor route\n")
4248
4249DEFUN (no_bgp_network_mask,
4250 no_bgp_network_mask_cmd,
4251 "no network A.B.C.D mask A.B.C.D",
4252 NO_STR
4253 "Specify a network to announce via BGP\n"
4254 "Network number\n"
4255 "Network mask\n"
4256 "Network mask\n")
4257{
4258 int ret;
4259 char prefix_str[BUFSIZ];
4260
4261 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4262 if (! ret)
4263 {
4264 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4265 return CMD_WARNING;
4266 }
4267
4268 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4269 bgp_node_safi (vty));
4270}
4271
4272ALIAS (no_bgp_network_mask,
4273 no_bgp_network_mask_route_map_cmd,
4274 "no network A.B.C.D mask A.B.C.D route-map WORD",
4275 NO_STR
4276 "Specify a network to announce via BGP\n"
4277 "Network number\n"
4278 "Network mask\n"
4279 "Network mask\n"
4280 "Route-map to modify the attributes\n"
4281 "Name of the route map\n")
4282
4283ALIAS (no_bgp_network_mask,
4284 no_bgp_network_mask_backdoor_cmd,
4285 "no network A.B.C.D mask A.B.C.D backdoor",
4286 NO_STR
4287 "Specify a network to announce via BGP\n"
4288 "Network number\n"
4289 "Network mask\n"
4290 "Network mask\n"
4291 "Specify a BGP backdoor route\n")
4292
4293DEFUN (no_bgp_network_mask_natural,
4294 no_bgp_network_mask_natural_cmd,
4295 "no network A.B.C.D",
4296 NO_STR
4297 "Specify a network to announce via BGP\n"
4298 "Network number\n")
4299{
4300 int ret;
4301 char prefix_str[BUFSIZ];
4302
4303 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4304 if (! ret)
4305 {
4306 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4307 return CMD_WARNING;
4308 }
4309
4310 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4311 bgp_node_safi (vty));
4312}
4313
4314ALIAS (no_bgp_network_mask_natural,
4315 no_bgp_network_mask_natural_route_map_cmd,
4316 "no network A.B.C.D route-map WORD",
4317 NO_STR
4318 "Specify a network to announce via BGP\n"
4319 "Network number\n"
4320 "Route-map to modify the attributes\n"
4321 "Name of the route map\n")
4322
4323ALIAS (no_bgp_network_mask_natural,
4324 no_bgp_network_mask_natural_backdoor_cmd,
4325 "no network A.B.C.D backdoor",
4326 NO_STR
4327 "Specify a network to announce via BGP\n"
4328 "Network number\n"
4329 "Specify a BGP backdoor route\n")
4330
4331#ifdef HAVE_IPV6
4332DEFUN (ipv6_bgp_network,
4333 ipv6_bgp_network_cmd,
4334 "network X:X::X:X/M",
4335 "Specify a network to announce via BGP\n"
4336 "IPv6 prefix <network>/<length>\n")
4337{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304338 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004339 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004340}
4341
4342DEFUN (ipv6_bgp_network_route_map,
4343 ipv6_bgp_network_route_map_cmd,
4344 "network X:X::X:X/M route-map WORD",
4345 "Specify a network to announce via BGP\n"
4346 "IPv6 prefix <network>/<length>\n"
4347 "Route-map to modify the attributes\n"
4348 "Name of the route map\n")
4349{
4350 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004351 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004352}
4353
4354DEFUN (no_ipv6_bgp_network,
4355 no_ipv6_bgp_network_cmd,
4356 "no network X:X::X:X/M",
4357 NO_STR
4358 "Specify a network to announce via BGP\n"
4359 "IPv6 prefix <network>/<length>\n")
4360{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304361 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004362}
4363
4364ALIAS (no_ipv6_bgp_network,
4365 no_ipv6_bgp_network_route_map_cmd,
4366 "no network X:X::X:X/M route-map WORD",
4367 NO_STR
4368 "Specify a network to announce via BGP\n"
4369 "IPv6 prefix <network>/<length>\n"
4370 "Route-map to modify the attributes\n"
4371 "Name of the route map\n")
4372
4373ALIAS (ipv6_bgp_network,
4374 old_ipv6_bgp_network_cmd,
4375 "ipv6 bgp network X:X::X:X/M",
4376 IPV6_STR
4377 BGP_STR
4378 "Specify a network to announce via BGP\n"
4379 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4380
4381ALIAS (no_ipv6_bgp_network,
4382 old_no_ipv6_bgp_network_cmd,
4383 "no ipv6 bgp network X:X::X:X/M",
4384 NO_STR
4385 IPV6_STR
4386 BGP_STR
4387 "Specify a network to announce via BGP\n"
4388 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4389#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004390
4391/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4392ALIAS_DEPRECATED (bgp_network,
4393 bgp_network_ttl_cmd,
4394 "network A.B.C.D/M 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 "AS-Path hopcount limit attribute\n"
4398 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4399ALIAS_DEPRECATED (bgp_network_backdoor,
4400 bgp_network_backdoor_ttl_cmd,
4401 "network A.B.C.D/M backdoor pathlimit <0-255>",
4402 "Specify a network to announce via BGP\n"
4403 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4404 "Specify a BGP backdoor route\n"
4405 "AS-Path hopcount limit attribute\n"
4406 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4407ALIAS_DEPRECATED (bgp_network_mask,
4408 bgp_network_mask_ttl_cmd,
4409 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4410 "Specify a network to announce via BGP\n"
4411 "Network number\n"
4412 "Network mask\n"
4413 "Network mask\n"
4414 "AS-Path hopcount limit attribute\n"
4415 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4416ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4417 bgp_network_mask_backdoor_ttl_cmd,
4418 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4419 "Specify a network to announce via BGP\n"
4420 "Network number\n"
4421 "Network mask\n"
4422 "Network mask\n"
4423 "Specify a BGP backdoor route\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,
4427 bgp_network_mask_natural_ttl_cmd,
4428 "network A.B.C.D pathlimit <0-255>",
4429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "AS-Path hopcount limit attribute\n"
4432 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4433ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4434 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004435 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004436 "Specify a network to announce via BGP\n"
4437 "Network number\n"
4438 "Specify a BGP backdoor route\n"
4439 "AS-Path hopcount limit attribute\n"
4440 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4441ALIAS_DEPRECATED (no_bgp_network,
4442 no_bgp_network_ttl_cmd,
4443 "no network A.B.C.D/M pathlimit <0-255>",
4444 NO_STR
4445 "Specify a network to announce via BGP\n"
4446 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4447 "AS-Path hopcount limit attribute\n"
4448 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4449ALIAS_DEPRECATED (no_bgp_network,
4450 no_bgp_network_backdoor_ttl_cmd,
4451 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4452 NO_STR
4453 "Specify a network to announce via BGP\n"
4454 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4455 "Specify a BGP backdoor route\n"
4456 "AS-Path hopcount limit attribute\n"
4457 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4458ALIAS_DEPRECATED (no_bgp_network,
4459 no_bgp_network_mask_ttl_cmd,
4460 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4461 NO_STR
4462 "Specify a network to announce via BGP\n"
4463 "Network number\n"
4464 "Network mask\n"
4465 "Network mask\n"
4466 "AS-Path hopcount limit attribute\n"
4467 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4468ALIAS_DEPRECATED (no_bgp_network_mask,
4469 no_bgp_network_mask_backdoor_ttl_cmd,
4470 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4471 NO_STR
4472 "Specify a network to announce via BGP\n"
4473 "Network number\n"
4474 "Network mask\n"
4475 "Network mask\n"
4476 "Specify a BGP backdoor route\n"
4477 "AS-Path hopcount limit attribute\n"
4478 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4479ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4480 no_bgp_network_mask_natural_ttl_cmd,
4481 "no network A.B.C.D pathlimit <0-255>",
4482 NO_STR
4483 "Specify a network to announce via BGP\n"
4484 "Network number\n"
4485 "AS-Path hopcount limit attribute\n"
4486 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4487ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4488 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4489 "no network A.B.C.D backdoor pathlimit <0-255>",
4490 NO_STR
4491 "Specify a network to announce via BGP\n"
4492 "Network number\n"
4493 "Specify a BGP backdoor route\n"
4494 "AS-Path hopcount limit attribute\n"
4495 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004496#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004497ALIAS_DEPRECATED (ipv6_bgp_network,
4498 ipv6_bgp_network_ttl_cmd,
4499 "network X:X::X:X/M pathlimit <0-255>",
4500 "Specify a network to announce via BGP\n"
4501 "IPv6 prefix <network>/<length>\n"
4502 "AS-Path hopcount limit attribute\n"
4503 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4504ALIAS_DEPRECATED (no_ipv6_bgp_network,
4505 no_ipv6_bgp_network_ttl_cmd,
4506 "no network X:X::X:X/M pathlimit <0-255>",
4507 NO_STR
4508 "Specify a network to announce via BGP\n"
4509 "IPv6 prefix <network>/<length>\n"
4510 "AS-Path hopcount limit attribute\n"
4511 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004512#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004513
paul718e3742002-12-13 20:15:29 +00004514/* Aggreagete address:
4515
4516 advertise-map Set condition to advertise attribute
4517 as-set Generate AS set path information
4518 attribute-map Set attributes of aggregate
4519 route-map Set parameters of aggregate
4520 summary-only Filter more specific routes from updates
4521 suppress-map Conditionally filter more specific routes from updates
4522 <cr>
4523 */
4524struct bgp_aggregate
4525{
4526 /* Summary-only flag. */
4527 u_char summary_only;
4528
4529 /* AS set generation. */
4530 u_char as_set;
4531
4532 /* Route-map for aggregated route. */
4533 struct route_map *map;
4534
4535 /* Suppress-count. */
4536 unsigned long count;
4537
4538 /* SAFI configuration. */
4539 safi_t safi;
4540};
4541
paul94f2b392005-06-28 12:44:16 +00004542static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004543bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004544{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004545 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004546}
4547
paul94f2b392005-06-28 12:44:16 +00004548static void
paul718e3742002-12-13 20:15:29 +00004549bgp_aggregate_free (struct bgp_aggregate *aggregate)
4550{
4551 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4552}
4553
paul94f2b392005-06-28 12:44:16 +00004554static void
paul718e3742002-12-13 20:15:29 +00004555bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4556 afi_t afi, safi_t safi, struct bgp_info *del,
4557 struct bgp_aggregate *aggregate)
4558{
4559 struct bgp_table *table;
4560 struct bgp_node *top;
4561 struct bgp_node *rn;
4562 u_char origin;
4563 struct aspath *aspath = NULL;
4564 struct aspath *asmerge = NULL;
4565 struct community *community = NULL;
4566 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004567 struct bgp_info *ri;
4568 struct bgp_info *new;
4569 int first = 1;
4570 unsigned long match = 0;
4571
paul718e3742002-12-13 20:15:29 +00004572 /* ORIGIN attribute: If at least one route among routes that are
4573 aggregated has ORIGIN with the value INCOMPLETE, then the
4574 aggregated route must have the ORIGIN attribute with the value
4575 INCOMPLETE. Otherwise, if at least one route among routes that
4576 are aggregated has ORIGIN with the value EGP, then the aggregated
4577 route must have the origin attribute with the value EGP. In all
4578 other case the value of the ORIGIN attribute of the aggregated
4579 route is INTERNAL. */
4580 origin = BGP_ORIGIN_IGP;
4581
4582 table = bgp->rib[afi][safi];
4583
4584 top = bgp_node_get (table, p);
4585 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4586 if (rn->p.prefixlen > p->prefixlen)
4587 {
4588 match = 0;
4589
4590 for (ri = rn->info; ri; ri = ri->next)
4591 {
4592 if (BGP_INFO_HOLDDOWN (ri))
4593 continue;
4594
4595 if (del && ri == del)
4596 continue;
4597
4598 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004599 first = 0;
paul718e3742002-12-13 20:15:29 +00004600
4601#ifdef AGGREGATE_NEXTHOP_CHECK
4602 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4603 || ri->attr->med != med)
4604 {
4605 if (aspath)
4606 aspath_free (aspath);
4607 if (community)
4608 community_free (community);
4609 bgp_unlock_node (rn);
4610 bgp_unlock_node (top);
4611 return;
4612 }
4613#endif /* AGGREGATE_NEXTHOP_CHECK */
4614
4615 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4616 {
4617 if (aggregate->summary_only)
4618 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004619 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004620 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004621 match++;
4622 }
4623
4624 aggregate->count++;
4625
4626 if (aggregate->as_set)
4627 {
4628 if (origin < ri->attr->origin)
4629 origin = ri->attr->origin;
4630
4631 if (aspath)
4632 {
4633 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4634 aspath_free (aspath);
4635 aspath = asmerge;
4636 }
4637 else
4638 aspath = aspath_dup (ri->attr->aspath);
4639
4640 if (ri->attr->community)
4641 {
4642 if (community)
4643 {
4644 commerge = community_merge (community,
4645 ri->attr->community);
4646 community = community_uniq_sort (commerge);
4647 community_free (commerge);
4648 }
4649 else
4650 community = community_dup (ri->attr->community);
4651 }
4652 }
4653 }
4654 }
4655 if (match)
4656 bgp_process (bgp, rn, afi, safi);
4657 }
4658 bgp_unlock_node (top);
4659
4660 if (rinew)
4661 {
4662 aggregate->count++;
4663
4664 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004665 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004666
4667 if (aggregate->as_set)
4668 {
4669 if (origin < rinew->attr->origin)
4670 origin = rinew->attr->origin;
4671
4672 if (aspath)
4673 {
4674 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4675 aspath_free (aspath);
4676 aspath = asmerge;
4677 }
4678 else
4679 aspath = aspath_dup (rinew->attr->aspath);
4680
4681 if (rinew->attr->community)
4682 {
4683 if (community)
4684 {
4685 commerge = community_merge (community,
4686 rinew->attr->community);
4687 community = community_uniq_sort (commerge);
4688 community_free (commerge);
4689 }
4690 else
4691 community = community_dup (rinew->attr->community);
4692 }
4693 }
4694 }
4695
4696 if (aggregate->count > 0)
4697 {
4698 rn = bgp_node_get (table, p);
4699 new = bgp_info_new ();
4700 new->type = ZEBRA_ROUTE_BGP;
4701 new->sub_type = BGP_ROUTE_AGGREGATE;
4702 new->peer = bgp->peer_self;
4703 SET_FLAG (new->flags, BGP_INFO_VALID);
4704 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004705 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004706
4707 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004708 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004709 bgp_process (bgp, rn, afi, safi);
4710 }
4711 else
4712 {
4713 if (aspath)
4714 aspath_free (aspath);
4715 if (community)
4716 community_free (community);
4717 }
4718}
4719
4720void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4721 struct bgp_aggregate *);
4722
4723void
4724bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4725 struct bgp_info *ri, afi_t afi, safi_t safi)
4726{
4727 struct bgp_node *child;
4728 struct bgp_node *rn;
4729 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004730 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004731
4732 /* MPLS-VPN aggregation is not yet supported. */
4733 if (safi == SAFI_MPLS_VPN)
4734 return;
4735
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004736 table = bgp->aggregate[afi][safi];
4737
4738 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004739 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004740 return;
4741
paul718e3742002-12-13 20:15:29 +00004742 if (p->prefixlen == 0)
4743 return;
4744
4745 if (BGP_INFO_HOLDDOWN (ri))
4746 return;
4747
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004748 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004749
4750 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004751 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004752 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4753 {
4754 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004755 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004756 }
4757 bgp_unlock_node (child);
4758}
4759
4760void
4761bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4762 struct bgp_info *del, afi_t afi, safi_t safi)
4763{
4764 struct bgp_node *child;
4765 struct bgp_node *rn;
4766 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004767 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004768
4769 /* MPLS-VPN aggregation is not yet supported. */
4770 if (safi == SAFI_MPLS_VPN)
4771 return;
4772
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004773 table = bgp->aggregate[afi][safi];
4774
4775 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004776 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004777 return;
4778
paul718e3742002-12-13 20:15:29 +00004779 if (p->prefixlen == 0)
4780 return;
4781
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004782 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004783
4784 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004785 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004786 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4787 {
4788 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004789 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004790 }
4791 bgp_unlock_node (child);
4792}
4793
paul94f2b392005-06-28 12:44:16 +00004794static void
paul718e3742002-12-13 20:15:29 +00004795bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4796 struct bgp_aggregate *aggregate)
4797{
4798 struct bgp_table *table;
4799 struct bgp_node *top;
4800 struct bgp_node *rn;
4801 struct bgp_info *new;
4802 struct bgp_info *ri;
4803 unsigned long match;
4804 u_char origin = BGP_ORIGIN_IGP;
4805 struct aspath *aspath = NULL;
4806 struct aspath *asmerge = NULL;
4807 struct community *community = NULL;
4808 struct community *commerge = NULL;
4809
4810 table = bgp->rib[afi][safi];
4811
4812 /* Sanity check. */
4813 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4814 return;
4815 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4816 return;
4817
4818 /* If routes exists below this node, generate aggregate routes. */
4819 top = bgp_node_get (table, p);
4820 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4821 if (rn->p.prefixlen > p->prefixlen)
4822 {
4823 match = 0;
4824
4825 for (ri = rn->info; ri; ri = ri->next)
4826 {
4827 if (BGP_INFO_HOLDDOWN (ri))
4828 continue;
4829
4830 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4831 {
4832 /* summary-only aggregate route suppress aggregated
4833 route announcement. */
4834 if (aggregate->summary_only)
4835 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004836 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004837 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004838 match++;
4839 }
4840 /* as-set aggregate route generate origin, as path,
4841 community aggregation. */
4842 if (aggregate->as_set)
4843 {
4844 if (origin < ri->attr->origin)
4845 origin = ri->attr->origin;
4846
4847 if (aspath)
4848 {
4849 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4850 aspath_free (aspath);
4851 aspath = asmerge;
4852 }
4853 else
4854 aspath = aspath_dup (ri->attr->aspath);
4855
4856 if (ri->attr->community)
4857 {
4858 if (community)
4859 {
4860 commerge = community_merge (community,
4861 ri->attr->community);
4862 community = community_uniq_sort (commerge);
4863 community_free (commerge);
4864 }
4865 else
4866 community = community_dup (ri->attr->community);
4867 }
4868 }
4869 aggregate->count++;
4870 }
4871 }
4872
4873 /* If this node is suppressed, process the change. */
4874 if (match)
4875 bgp_process (bgp, rn, afi, safi);
4876 }
4877 bgp_unlock_node (top);
4878
4879 /* Add aggregate route to BGP table. */
4880 if (aggregate->count)
4881 {
4882 rn = bgp_node_get (table, p);
4883
4884 new = bgp_info_new ();
4885 new->type = ZEBRA_ROUTE_BGP;
4886 new->sub_type = BGP_ROUTE_AGGREGATE;
4887 new->peer = bgp->peer_self;
4888 SET_FLAG (new->flags, BGP_INFO_VALID);
4889 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004890 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004891
4892 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004893 bgp_unlock_node (rn);
4894
paul718e3742002-12-13 20:15:29 +00004895 /* Process change. */
4896 bgp_process (bgp, rn, afi, safi);
4897 }
4898}
4899
4900void
4901bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4902 safi_t safi, struct bgp_aggregate *aggregate)
4903{
4904 struct bgp_table *table;
4905 struct bgp_node *top;
4906 struct bgp_node *rn;
4907 struct bgp_info *ri;
4908 unsigned long match;
4909
4910 table = bgp->rib[afi][safi];
4911
4912 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4913 return;
4914 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4915 return;
4916
4917 /* If routes exists below this node, generate aggregate routes. */
4918 top = bgp_node_get (table, p);
4919 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4920 if (rn->p.prefixlen > p->prefixlen)
4921 {
4922 match = 0;
4923
4924 for (ri = rn->info; ri; ri = ri->next)
4925 {
4926 if (BGP_INFO_HOLDDOWN (ri))
4927 continue;
4928
4929 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4930 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004931 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004932 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004933 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004934
Paul Jakmafb982c22007-05-04 20:15:47 +00004935 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004936 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004937 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004938 match++;
4939 }
4940 }
4941 aggregate->count--;
4942 }
4943 }
4944
Paul Jakmafb982c22007-05-04 20:15:47 +00004945 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004946 if (match)
4947 bgp_process (bgp, rn, afi, safi);
4948 }
4949 bgp_unlock_node (top);
4950
4951 /* Delete aggregate route from BGP table. */
4952 rn = bgp_node_get (table, p);
4953
4954 for (ri = rn->info; ri; ri = ri->next)
4955 if (ri->peer == bgp->peer_self
4956 && ri->type == ZEBRA_ROUTE_BGP
4957 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4958 break;
4959
4960 /* Withdraw static BGP route from routing table. */
4961 if (ri)
4962 {
paul718e3742002-12-13 20:15:29 +00004963 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004964 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004965 }
4966
4967 /* Unlock bgp_node_lookup. */
4968 bgp_unlock_node (rn);
4969}
4970
4971/* Aggregate route attribute. */
4972#define AGGREGATE_SUMMARY_ONLY 1
4973#define AGGREGATE_AS_SET 1
4974
paul94f2b392005-06-28 12:44:16 +00004975static int
Robert Baysf6269b42010-08-05 10:26:28 -07004976bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4977 afi_t afi, safi_t safi)
4978{
4979 int ret;
4980 struct prefix p;
4981 struct bgp_node *rn;
4982 struct bgp *bgp;
4983 struct bgp_aggregate *aggregate;
4984
4985 /* Convert string to prefix structure. */
4986 ret = str2prefix (prefix_str, &p);
4987 if (!ret)
4988 {
4989 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4990 return CMD_WARNING;
4991 }
4992 apply_mask (&p);
4993
4994 /* Get BGP structure. */
4995 bgp = vty->index;
4996
4997 /* Old configuration check. */
4998 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4999 if (! rn)
5000 {
5001 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5002 VTY_NEWLINE);
5003 return CMD_WARNING;
5004 }
5005
5006 aggregate = rn->info;
5007 if (aggregate->safi & SAFI_UNICAST)
5008 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5009 if (aggregate->safi & SAFI_MULTICAST)
5010 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5011
5012 /* Unlock aggregate address configuration. */
5013 rn->info = NULL;
5014 bgp_aggregate_free (aggregate);
5015 bgp_unlock_node (rn);
5016 bgp_unlock_node (rn);
5017
5018 return CMD_SUCCESS;
5019}
5020
5021static int
5022bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005023 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005024 u_char summary_only, u_char as_set)
5025{
5026 int ret;
5027 struct prefix p;
5028 struct bgp_node *rn;
5029 struct bgp *bgp;
5030 struct bgp_aggregate *aggregate;
5031
5032 /* Convert string to prefix structure. */
5033 ret = str2prefix (prefix_str, &p);
5034 if (!ret)
5035 {
5036 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5037 return CMD_WARNING;
5038 }
5039 apply_mask (&p);
5040
5041 /* Get BGP structure. */
5042 bgp = vty->index;
5043
5044 /* Old configuration check. */
5045 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5046
5047 if (rn->info)
5048 {
5049 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005050 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005051 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5052 if (ret)
5053 {
Robert Bays368473f2010-08-05 10:26:29 -07005054 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5055 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005056 return CMD_WARNING;
5057 }
paul718e3742002-12-13 20:15:29 +00005058 }
5059
5060 /* Make aggregate address structure. */
5061 aggregate = bgp_aggregate_new ();
5062 aggregate->summary_only = summary_only;
5063 aggregate->as_set = as_set;
5064 aggregate->safi = safi;
5065 rn->info = aggregate;
5066
5067 /* Aggregate address insert into BGP routing table. */
5068 if (safi & SAFI_UNICAST)
5069 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5070 if (safi & SAFI_MULTICAST)
5071 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5072
5073 return CMD_SUCCESS;
5074}
5075
paul718e3742002-12-13 20:15:29 +00005076DEFUN (aggregate_address,
5077 aggregate_address_cmd,
5078 "aggregate-address A.B.C.D/M",
5079 "Configure BGP aggregate entries\n"
5080 "Aggregate prefix\n")
5081{
5082 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5083}
5084
5085DEFUN (aggregate_address_mask,
5086 aggregate_address_mask_cmd,
5087 "aggregate-address A.B.C.D A.B.C.D",
5088 "Configure BGP aggregate entries\n"
5089 "Aggregate address\n"
5090 "Aggregate mask\n")
5091{
5092 int ret;
5093 char prefix_str[BUFSIZ];
5094
5095 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5096
5097 if (! ret)
5098 {
5099 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5100 return CMD_WARNING;
5101 }
5102
5103 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5104 0, 0);
5105}
5106
5107DEFUN (aggregate_address_summary_only,
5108 aggregate_address_summary_only_cmd,
5109 "aggregate-address A.B.C.D/M summary-only",
5110 "Configure BGP aggregate entries\n"
5111 "Aggregate prefix\n"
5112 "Filter more specific routes from updates\n")
5113{
5114 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5115 AGGREGATE_SUMMARY_ONLY, 0);
5116}
5117
5118DEFUN (aggregate_address_mask_summary_only,
5119 aggregate_address_mask_summary_only_cmd,
5120 "aggregate-address A.B.C.D A.B.C.D summary-only",
5121 "Configure BGP aggregate entries\n"
5122 "Aggregate address\n"
5123 "Aggregate mask\n"
5124 "Filter more specific routes from updates\n")
5125{
5126 int ret;
5127 char prefix_str[BUFSIZ];
5128
5129 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5130
5131 if (! ret)
5132 {
5133 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5134 return CMD_WARNING;
5135 }
5136
5137 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5138 AGGREGATE_SUMMARY_ONLY, 0);
5139}
5140
5141DEFUN (aggregate_address_as_set,
5142 aggregate_address_as_set_cmd,
5143 "aggregate-address A.B.C.D/M as-set",
5144 "Configure BGP aggregate entries\n"
5145 "Aggregate prefix\n"
5146 "Generate AS set path information\n")
5147{
5148 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5149 0, AGGREGATE_AS_SET);
5150}
5151
5152DEFUN (aggregate_address_mask_as_set,
5153 aggregate_address_mask_as_set_cmd,
5154 "aggregate-address A.B.C.D A.B.C.D as-set",
5155 "Configure BGP aggregate entries\n"
5156 "Aggregate address\n"
5157 "Aggregate mask\n"
5158 "Generate AS set path information\n")
5159{
5160 int ret;
5161 char prefix_str[BUFSIZ];
5162
5163 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5164
5165 if (! ret)
5166 {
5167 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5168 return CMD_WARNING;
5169 }
5170
5171 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5172 0, AGGREGATE_AS_SET);
5173}
5174
5175
5176DEFUN (aggregate_address_as_set_summary,
5177 aggregate_address_as_set_summary_cmd,
5178 "aggregate-address A.B.C.D/M as-set summary-only",
5179 "Configure BGP aggregate entries\n"
5180 "Aggregate prefix\n"
5181 "Generate AS set path information\n"
5182 "Filter more specific routes from updates\n")
5183{
5184 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5185 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5186}
5187
5188ALIAS (aggregate_address_as_set_summary,
5189 aggregate_address_summary_as_set_cmd,
5190 "aggregate-address A.B.C.D/M summary-only as-set",
5191 "Configure BGP aggregate entries\n"
5192 "Aggregate prefix\n"
5193 "Filter more specific routes from updates\n"
5194 "Generate AS set path information\n")
5195
5196DEFUN (aggregate_address_mask_as_set_summary,
5197 aggregate_address_mask_as_set_summary_cmd,
5198 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5199 "Configure BGP aggregate entries\n"
5200 "Aggregate address\n"
5201 "Aggregate mask\n"
5202 "Generate AS set path information\n"
5203 "Filter more specific routes from updates\n")
5204{
5205 int ret;
5206 char prefix_str[BUFSIZ];
5207
5208 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5209
5210 if (! ret)
5211 {
5212 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5213 return CMD_WARNING;
5214 }
5215
5216 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5217 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5218}
5219
5220ALIAS (aggregate_address_mask_as_set_summary,
5221 aggregate_address_mask_summary_as_set_cmd,
5222 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5223 "Configure BGP aggregate entries\n"
5224 "Aggregate address\n"
5225 "Aggregate mask\n"
5226 "Filter more specific routes from updates\n"
5227 "Generate AS set path information\n")
5228
5229DEFUN (no_aggregate_address,
5230 no_aggregate_address_cmd,
5231 "no aggregate-address A.B.C.D/M",
5232 NO_STR
5233 "Configure BGP aggregate entries\n"
5234 "Aggregate prefix\n")
5235{
5236 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5237}
5238
5239ALIAS (no_aggregate_address,
5240 no_aggregate_address_summary_only_cmd,
5241 "no aggregate-address A.B.C.D/M summary-only",
5242 NO_STR
5243 "Configure BGP aggregate entries\n"
5244 "Aggregate prefix\n"
5245 "Filter more specific routes from updates\n")
5246
5247ALIAS (no_aggregate_address,
5248 no_aggregate_address_as_set_cmd,
5249 "no aggregate-address A.B.C.D/M as-set",
5250 NO_STR
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate prefix\n"
5253 "Generate AS set path information\n")
5254
5255ALIAS (no_aggregate_address,
5256 no_aggregate_address_as_set_summary_cmd,
5257 "no aggregate-address A.B.C.D/M as-set summary-only",
5258 NO_STR
5259 "Configure BGP aggregate entries\n"
5260 "Aggregate prefix\n"
5261 "Generate AS set path information\n"
5262 "Filter more specific routes from updates\n")
5263
5264ALIAS (no_aggregate_address,
5265 no_aggregate_address_summary_as_set_cmd,
5266 "no aggregate-address A.B.C.D/M summary-only as-set",
5267 NO_STR
5268 "Configure BGP aggregate entries\n"
5269 "Aggregate prefix\n"
5270 "Filter more specific routes from updates\n"
5271 "Generate AS set path information\n")
5272
5273DEFUN (no_aggregate_address_mask,
5274 no_aggregate_address_mask_cmd,
5275 "no aggregate-address A.B.C.D A.B.C.D",
5276 NO_STR
5277 "Configure BGP aggregate entries\n"
5278 "Aggregate address\n"
5279 "Aggregate mask\n")
5280{
5281 int ret;
5282 char prefix_str[BUFSIZ];
5283
5284 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5285
5286 if (! ret)
5287 {
5288 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5289 return CMD_WARNING;
5290 }
5291
5292 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5293}
5294
5295ALIAS (no_aggregate_address_mask,
5296 no_aggregate_address_mask_summary_only_cmd,
5297 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5298 NO_STR
5299 "Configure BGP aggregate entries\n"
5300 "Aggregate address\n"
5301 "Aggregate mask\n"
5302 "Filter more specific routes from updates\n")
5303
5304ALIAS (no_aggregate_address_mask,
5305 no_aggregate_address_mask_as_set_cmd,
5306 "no aggregate-address A.B.C.D A.B.C.D as-set",
5307 NO_STR
5308 "Configure BGP aggregate entries\n"
5309 "Aggregate address\n"
5310 "Aggregate mask\n"
5311 "Generate AS set path information\n")
5312
5313ALIAS (no_aggregate_address_mask,
5314 no_aggregate_address_mask_as_set_summary_cmd,
5315 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5316 NO_STR
5317 "Configure BGP aggregate entries\n"
5318 "Aggregate address\n"
5319 "Aggregate mask\n"
5320 "Generate AS set path information\n"
5321 "Filter more specific routes from updates\n")
5322
5323ALIAS (no_aggregate_address_mask,
5324 no_aggregate_address_mask_summary_as_set_cmd,
5325 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5326 NO_STR
5327 "Configure BGP aggregate entries\n"
5328 "Aggregate address\n"
5329 "Aggregate mask\n"
5330 "Filter more specific routes from updates\n"
5331 "Generate AS set path information\n")
5332
5333#ifdef HAVE_IPV6
5334DEFUN (ipv6_aggregate_address,
5335 ipv6_aggregate_address_cmd,
5336 "aggregate-address X:X::X:X/M",
5337 "Configure BGP aggregate entries\n"
5338 "Aggregate prefix\n")
5339{
5340 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5341}
5342
5343DEFUN (ipv6_aggregate_address_summary_only,
5344 ipv6_aggregate_address_summary_only_cmd,
5345 "aggregate-address X:X::X:X/M summary-only",
5346 "Configure BGP aggregate entries\n"
5347 "Aggregate prefix\n"
5348 "Filter more specific routes from updates\n")
5349{
5350 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5351 AGGREGATE_SUMMARY_ONLY, 0);
5352}
5353
5354DEFUN (no_ipv6_aggregate_address,
5355 no_ipv6_aggregate_address_cmd,
5356 "no aggregate-address X:X::X:X/M",
5357 NO_STR
5358 "Configure BGP aggregate entries\n"
5359 "Aggregate prefix\n")
5360{
5361 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5362}
5363
5364DEFUN (no_ipv6_aggregate_address_summary_only,
5365 no_ipv6_aggregate_address_summary_only_cmd,
5366 "no aggregate-address X:X::X:X/M summary-only",
5367 NO_STR
5368 "Configure BGP aggregate entries\n"
5369 "Aggregate prefix\n"
5370 "Filter more specific routes from updates\n")
5371{
5372 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5373}
5374
5375ALIAS (ipv6_aggregate_address,
5376 old_ipv6_aggregate_address_cmd,
5377 "ipv6 bgp aggregate-address X:X::X:X/M",
5378 IPV6_STR
5379 BGP_STR
5380 "Configure BGP aggregate entries\n"
5381 "Aggregate prefix\n")
5382
5383ALIAS (ipv6_aggregate_address_summary_only,
5384 old_ipv6_aggregate_address_summary_only_cmd,
5385 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5386 IPV6_STR
5387 BGP_STR
5388 "Configure BGP aggregate entries\n"
5389 "Aggregate prefix\n"
5390 "Filter more specific routes from updates\n")
5391
5392ALIAS (no_ipv6_aggregate_address,
5393 old_no_ipv6_aggregate_address_cmd,
5394 "no ipv6 bgp aggregate-address X:X::X:X/M",
5395 NO_STR
5396 IPV6_STR
5397 BGP_STR
5398 "Configure BGP aggregate entries\n"
5399 "Aggregate prefix\n")
5400
5401ALIAS (no_ipv6_aggregate_address_summary_only,
5402 old_no_ipv6_aggregate_address_summary_only_cmd,
5403 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5404 NO_STR
5405 IPV6_STR
5406 BGP_STR
5407 "Configure BGP aggregate entries\n"
5408 "Aggregate prefix\n"
5409 "Filter more specific routes from updates\n")
5410#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005411
paul718e3742002-12-13 20:15:29 +00005412/* Redistribute route treatment. */
5413void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005414bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5415 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005416 u_int32_t metric, u_char type)
5417{
5418 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005419 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005420 struct bgp_info *new;
5421 struct bgp_info *bi;
5422 struct bgp_info info;
5423 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005424 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005425 struct attr *new_attr;
5426 afi_t afi;
5427 int ret;
5428
5429 /* Make default attribute. */
5430 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5431 if (nexthop)
5432 attr.nexthop = *nexthop;
5433
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005434#ifdef HAVE_IPV6
5435 if (nexthop6)
5436 {
5437 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5438 extra->mp_nexthop_global = *nexthop6;
5439 extra->mp_nexthop_len = 16;
5440 }
5441#endif
5442
paul718e3742002-12-13 20:15:29 +00005443 attr.med = metric;
5444 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5445
paul1eb8ef22005-04-07 07:30:20 +00005446 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005447 {
5448 afi = family2afi (p->family);
5449
5450 if (bgp->redist[afi][type])
5451 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005452 struct attr attr_new;
5453 struct attr_extra extra_new;
5454
paul718e3742002-12-13 20:15:29 +00005455 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005456 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005457 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005458
5459 if (bgp->redist_metric_flag[afi][type])
5460 attr_new.med = bgp->redist_metric[afi][type];
5461
5462 /* Apply route-map. */
5463 if (bgp->rmap[afi][type].map)
5464 {
5465 info.peer = bgp->peer_self;
5466 info.attr = &attr_new;
5467
paulfee0f4c2004-09-13 05:12:46 +00005468 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5469
paul718e3742002-12-13 20:15:29 +00005470 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5471 &info);
paulfee0f4c2004-09-13 05:12:46 +00005472
5473 bgp->peer_self->rmap_type = 0;
5474
paul718e3742002-12-13 20:15:29 +00005475 if (ret == RMAP_DENYMATCH)
5476 {
5477 /* Free uninterned attribute. */
5478 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005479
paul718e3742002-12-13 20:15:29 +00005480 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005481 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005482 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005483 bgp_redistribute_delete (p, type);
5484 return;
5485 }
5486 }
5487
Paul Jakmafb982c22007-05-04 20:15:47 +00005488 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5489 afi, SAFI_UNICAST, p, NULL);
5490
paul718e3742002-12-13 20:15:29 +00005491 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005492
paul718e3742002-12-13 20:15:29 +00005493 for (bi = bn->info; bi; bi = bi->next)
5494 if (bi->peer == bgp->peer_self
5495 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5496 break;
5497
5498 if (bi)
5499 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005500 if (attrhash_cmp (bi->attr, new_attr) &&
5501 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005502 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005503 bgp_attr_unintern (&new_attr);
5504 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005505 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005506 bgp_unlock_node (bn);
5507 return;
5508 }
5509 else
5510 {
5511 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005512 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005513
5514 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005515 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5516 bgp_info_restore(bn, bi);
5517 else
5518 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005519 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005520 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005521 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005522
5523 /* Process change. */
5524 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5525 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5526 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005527 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005528 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005529 return;
5530 }
5531 }
5532
5533 new = bgp_info_new ();
5534 new->type = type;
5535 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5536 new->peer = bgp->peer_self;
5537 SET_FLAG (new->flags, BGP_INFO_VALID);
5538 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005539 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005540
5541 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5542 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005543 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005544 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5545 }
5546 }
5547
5548 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005549 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005550 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005551}
5552
5553void
5554bgp_redistribute_delete (struct prefix *p, u_char type)
5555{
5556 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005557 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005558 afi_t afi;
5559 struct bgp_node *rn;
5560 struct bgp_info *ri;
5561
paul1eb8ef22005-04-07 07:30:20 +00005562 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005563 {
5564 afi = family2afi (p->family);
5565
5566 if (bgp->redist[afi][type])
5567 {
paulfee0f4c2004-09-13 05:12:46 +00005568 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005569
5570 for (ri = rn->info; ri; ri = ri->next)
5571 if (ri->peer == bgp->peer_self
5572 && ri->type == type)
5573 break;
5574
5575 if (ri)
5576 {
5577 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005578 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005579 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005580 }
5581 bgp_unlock_node (rn);
5582 }
5583 }
5584}
5585
5586/* Withdraw specified route type's route. */
5587void
5588bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5589{
5590 struct bgp_node *rn;
5591 struct bgp_info *ri;
5592 struct bgp_table *table;
5593
5594 table = bgp->rib[afi][SAFI_UNICAST];
5595
5596 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5597 {
5598 for (ri = rn->info; ri; ri = ri->next)
5599 if (ri->peer == bgp->peer_self
5600 && ri->type == type)
5601 break;
5602
5603 if (ri)
5604 {
5605 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005606 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005607 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005608 }
5609 }
5610}
David Lamparter6b0655a2014-06-04 06:53:35 +02005611
paul718e3742002-12-13 20:15:29 +00005612/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005613static void
paul718e3742002-12-13 20:15:29 +00005614route_vty_out_route (struct prefix *p, struct vty *vty)
5615{
5616 int len;
5617 u_int32_t destination;
5618 char buf[BUFSIZ];
5619
5620 if (p->family == AF_INET)
5621 {
5622 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5623 destination = ntohl (p->u.prefix4.s_addr);
5624
5625 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5626 || (IN_CLASSB (destination) && p->prefixlen == 16)
5627 || (IN_CLASSA (destination) && p->prefixlen == 8)
5628 || p->u.prefix4.s_addr == 0)
5629 {
5630 /* When mask is natural, mask is not displayed. */
5631 }
5632 else
5633 len += vty_out (vty, "/%d", p->prefixlen);
5634 }
5635 else
5636 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5637 p->prefixlen);
5638
5639 len = 17 - len;
5640 if (len < 1)
5641 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5642 else
5643 vty_out (vty, "%*s", len, " ");
5644}
5645
paul718e3742002-12-13 20:15:29 +00005646enum bgp_display_type
5647{
5648 normal_list,
5649};
5650
paulb40d9392005-08-22 22:34:41 +00005651/* Print the short form route status for a bgp_info */
5652static void
5653route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005654{
paulb40d9392005-08-22 22:34:41 +00005655 /* Route status display. */
5656 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5657 vty_out (vty, "R");
5658 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005659 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005660 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005661 vty_out (vty, "s");
5662 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5663 vty_out (vty, "*");
5664 else
5665 vty_out (vty, " ");
5666
5667 /* Selected */
5668 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5669 vty_out (vty, "h");
5670 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5671 vty_out (vty, "d");
5672 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5673 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005674 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5675 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005676 else
5677 vty_out (vty, " ");
5678
5679 /* Internal route. */
5680 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5681 vty_out (vty, "i");
5682 else
paulb40d9392005-08-22 22:34:41 +00005683 vty_out (vty, " ");
5684}
5685
5686/* called from terminal list command */
5687void
5688route_vty_out (struct vty *vty, struct prefix *p,
5689 struct bgp_info *binfo, int display, safi_t safi)
5690{
5691 struct attr *attr;
5692
5693 /* short status lead text */
5694 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005695
5696 /* print prefix and mask */
5697 if (! display)
5698 route_vty_out_route (p, vty);
5699 else
5700 vty_out (vty, "%*s", 17, " ");
5701
5702 /* Print attribute */
5703 attr = binfo->attr;
5704 if (attr)
5705 {
5706 if (p->family == AF_INET)
5707 {
5708 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005709 vty_out (vty, "%-16s",
5710 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005711 else
5712 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5713 }
5714#ifdef HAVE_IPV6
5715 else if (p->family == AF_INET6)
5716 {
5717 int len;
5718 char buf[BUFSIZ];
5719
5720 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005721 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5722 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005723 len = 16 - len;
5724 if (len < 1)
5725 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5726 else
5727 vty_out (vty, "%*s", len, " ");
5728 }
5729#endif /* HAVE_IPV6 */
5730
5731 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005732 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005733 else
5734 vty_out (vty, " ");
5735
5736 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005737 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005738 else
5739 vty_out (vty, " ");
5740
Paul Jakmafb982c22007-05-04 20:15:47 +00005741 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005742
Paul Jakmab2518c12006-05-12 23:48:40 +00005743 /* Print aspath */
5744 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005745 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005746
Paul Jakmab2518c12006-05-12 23:48:40 +00005747 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005748 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005749 }
paul718e3742002-12-13 20:15:29 +00005750 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005751}
5752
5753/* called from terminal list command */
5754void
5755route_vty_out_tmp (struct vty *vty, struct prefix *p,
5756 struct attr *attr, safi_t safi)
5757{
5758 /* Route status display. */
5759 vty_out (vty, "*");
5760 vty_out (vty, ">");
5761 vty_out (vty, " ");
5762
5763 /* print prefix and mask */
5764 route_vty_out_route (p, vty);
5765
5766 /* Print attribute */
5767 if (attr)
5768 {
5769 if (p->family == AF_INET)
5770 {
5771 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005772 vty_out (vty, "%-16s",
5773 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005774 else
5775 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5776 }
5777#ifdef HAVE_IPV6
5778 else if (p->family == AF_INET6)
5779 {
5780 int len;
5781 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005782
5783 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005784
5785 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005786 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5787 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005788 len = 16 - len;
5789 if (len < 1)
5790 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5791 else
5792 vty_out (vty, "%*s", len, " ");
5793 }
5794#endif /* HAVE_IPV6 */
5795
5796 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005797 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005798 else
5799 vty_out (vty, " ");
5800
5801 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005802 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005803 else
5804 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005805
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005806 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005807
Paul Jakmab2518c12006-05-12 23:48:40 +00005808 /* Print aspath */
5809 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005810 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005811
Paul Jakmab2518c12006-05-12 23:48:40 +00005812 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005813 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005814 }
paul718e3742002-12-13 20:15:29 +00005815
5816 vty_out (vty, "%s", VTY_NEWLINE);
5817}
5818
ajs5a646652004-11-05 01:25:55 +00005819void
paul718e3742002-12-13 20:15:29 +00005820route_vty_out_tag (struct vty *vty, struct prefix *p,
5821 struct bgp_info *binfo, int display, safi_t safi)
5822{
5823 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005824 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005825
5826 if (!binfo->extra)
5827 return;
5828
paulb40d9392005-08-22 22:34:41 +00005829 /* short status lead text */
5830 route_vty_short_status_out (vty, binfo);
5831
paul718e3742002-12-13 20:15:29 +00005832 /* print prefix and mask */
5833 if (! display)
5834 route_vty_out_route (p, vty);
5835 else
5836 vty_out (vty, "%*s", 17, " ");
5837
5838 /* Print attribute */
5839 attr = binfo->attr;
5840 if (attr)
5841 {
5842 if (p->family == AF_INET)
5843 {
5844 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005845 vty_out (vty, "%-16s",
5846 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005847 else
5848 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5849 }
5850#ifdef HAVE_IPV6
5851 else if (p->family == AF_INET6)
5852 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005853 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005854 char buf[BUFSIZ];
5855 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005856 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005857 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005858 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5859 buf, BUFSIZ));
5860 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005861 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005862 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5863 buf, BUFSIZ),
5864 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5865 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005866
5867 }
5868#endif /* HAVE_IPV6 */
5869 }
5870
Paul Jakmafb982c22007-05-04 20:15:47 +00005871 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005872
5873 vty_out (vty, "notag/%d", label);
5874
5875 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005876}
5877
5878/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005879static void
paul718e3742002-12-13 20:15:29 +00005880damp_route_vty_out (struct vty *vty, struct prefix *p,
5881 struct bgp_info *binfo, int display, safi_t safi)
5882{
5883 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005884 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005885 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005886
paulb40d9392005-08-22 22:34:41 +00005887 /* short status lead text */
5888 route_vty_short_status_out (vty, binfo);
5889
paul718e3742002-12-13 20:15:29 +00005890 /* print prefix and mask */
5891 if (! display)
5892 route_vty_out_route (p, vty);
5893 else
5894 vty_out (vty, "%*s", 17, " ");
5895
5896 len = vty_out (vty, "%s", binfo->peer->host);
5897 len = 17 - len;
5898 if (len < 1)
5899 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5900 else
5901 vty_out (vty, "%*s", len, " ");
5902
Chris Caputo50aef6f2009-06-23 06:06:49 +00005903 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005904
5905 /* Print attribute */
5906 attr = binfo->attr;
5907 if (attr)
5908 {
5909 /* Print aspath */
5910 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005911 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005912
5913 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005914 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005915 }
5916 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005917}
5918
paul718e3742002-12-13 20:15:29 +00005919/* flap route */
ajs5a646652004-11-05 01:25:55 +00005920static void
paul718e3742002-12-13 20:15:29 +00005921flap_route_vty_out (struct vty *vty, struct prefix *p,
5922 struct bgp_info *binfo, int display, safi_t safi)
5923{
5924 struct attr *attr;
5925 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005926 char timebuf[BGP_UPTIME_LEN];
5927 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005928
5929 if (!binfo->extra)
5930 return;
5931
5932 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005933
paulb40d9392005-08-22 22:34:41 +00005934 /* short status lead text */
5935 route_vty_short_status_out (vty, binfo);
5936
paul718e3742002-12-13 20:15:29 +00005937 /* print prefix and mask */
5938 if (! display)
5939 route_vty_out_route (p, vty);
5940 else
5941 vty_out (vty, "%*s", 17, " ");
5942
5943 len = vty_out (vty, "%s", binfo->peer->host);
5944 len = 16 - len;
5945 if (len < 1)
5946 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5947 else
5948 vty_out (vty, "%*s", len, " ");
5949
5950 len = vty_out (vty, "%d", bdi->flap);
5951 len = 5 - len;
5952 if (len < 1)
5953 vty_out (vty, " ");
5954 else
5955 vty_out (vty, "%*s ", len, " ");
5956
5957 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5958 timebuf, BGP_UPTIME_LEN));
5959
5960 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5961 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005962 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005963 else
5964 vty_out (vty, "%*s ", 8, " ");
5965
5966 /* Print attribute */
5967 attr = binfo->attr;
5968 if (attr)
5969 {
5970 /* Print aspath */
5971 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005972 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005973
5974 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005975 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005976 }
5977 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005978}
5979
paul94f2b392005-06-28 12:44:16 +00005980static void
paul718e3742002-12-13 20:15:29 +00005981route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5982 struct bgp_info *binfo, afi_t afi, safi_t safi)
5983{
5984 char buf[INET6_ADDRSTRLEN];
5985 char buf1[BUFSIZ];
5986 struct attr *attr;
5987 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005988#ifdef HAVE_CLOCK_MONOTONIC
5989 time_t tbuf;
5990#endif
paul718e3742002-12-13 20:15:29 +00005991
5992 attr = binfo->attr;
5993
5994 if (attr)
5995 {
5996 /* Line1 display AS-path, Aggregator */
5997 if (attr->aspath)
5998 {
5999 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006000 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006001 vty_out (vty, "Local");
6002 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006003 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006004 }
6005
paulb40d9392005-08-22 22:34:41 +00006006 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6007 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006008 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6009 vty_out (vty, ", (stale)");
6010 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006011 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006012 attr->extra->aggregator_as,
6013 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006014 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6015 vty_out (vty, ", (Received from a RR-client)");
6016 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6017 vty_out (vty, ", (Received from a RS-client)");
6018 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6019 vty_out (vty, ", (history entry)");
6020 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6021 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006022 vty_out (vty, "%s", VTY_NEWLINE);
6023
6024 /* Line2 display Next-hop, Neighbor, Router-id */
6025 if (p->family == AF_INET)
6026 {
6027 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006028 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006029 inet_ntoa (attr->nexthop));
6030 }
6031#ifdef HAVE_IPV6
6032 else
6033 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006034 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006035 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006036 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006037 buf, INET6_ADDRSTRLEN));
6038 }
6039#endif /* HAVE_IPV6 */
6040
6041 if (binfo->peer == bgp->peer_self)
6042 {
6043 vty_out (vty, " from %s ",
6044 p->family == AF_INET ? "0.0.0.0" : "::");
6045 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6046 }
6047 else
6048 {
6049 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6050 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006051 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006052 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006053 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006054 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006055 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006056 else
6057 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6058 }
6059 vty_out (vty, "%s", VTY_NEWLINE);
6060
6061#ifdef HAVE_IPV6
6062 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006063 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006064 {
6065 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006066 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006067 buf, INET6_ADDRSTRLEN),
6068 VTY_NEWLINE);
6069 }
6070#endif /* HAVE_IPV6 */
6071
6072 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6073 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6074
6075 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006076 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006077
6078 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006079 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006080 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006081 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006082
Paul Jakmafb982c22007-05-04 20:15:47 +00006083 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006084 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006085
6086 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6087 vty_out (vty, ", valid");
6088
6089 if (binfo->peer != bgp->peer_self)
6090 {
6091 if (binfo->peer->as == binfo->peer->local_as)
6092 vty_out (vty, ", internal");
6093 else
6094 vty_out (vty, ", %s",
6095 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6096 }
6097 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6098 vty_out (vty, ", aggregated, local");
6099 else if (binfo->type != ZEBRA_ROUTE_BGP)
6100 vty_out (vty, ", sourced");
6101 else
6102 vty_out (vty, ", sourced, local");
6103
6104 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6105 vty_out (vty, ", atomic-aggregate");
6106
Josh Baileyde8d5df2011-07-20 20:46:01 -07006107 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6108 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6109 bgp_info_mpath_count (binfo)))
6110 vty_out (vty, ", multipath");
6111
paul718e3742002-12-13 20:15:29 +00006112 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6113 vty_out (vty, ", best");
6114
6115 vty_out (vty, "%s", VTY_NEWLINE);
6116
6117 /* Line 4 display Community */
6118 if (attr->community)
6119 vty_out (vty, " Community: %s%s", attr->community->str,
6120 VTY_NEWLINE);
6121
6122 /* Line 5 display Extended-community */
6123 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006124 vty_out (vty, " Extended Community: %s%s",
6125 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006126
6127 /* Line 6 display Originator, Cluster-id */
6128 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6129 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6130 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006131 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006132 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006133 vty_out (vty, " Originator: %s",
6134 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006135
6136 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6137 {
6138 int i;
6139 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006140 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6141 vty_out (vty, "%s ",
6142 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006143 }
6144 vty_out (vty, "%s", VTY_NEWLINE);
6145 }
Paul Jakma41367172007-08-06 15:24:51 +00006146
Paul Jakmafb982c22007-05-04 20:15:47 +00006147 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006148 bgp_damp_info_vty (vty, binfo);
6149
6150 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006151#ifdef HAVE_CLOCK_MONOTONIC
6152 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006153 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006154#else
6155 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6156#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006157 }
6158 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006159}
6160
6161#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6162 "h history, * valid, > best, = multipath,%s"\
6163 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006164#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006165#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6166#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6167#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6168
6169enum bgp_show_type
6170{
6171 bgp_show_type_normal,
6172 bgp_show_type_regexp,
6173 bgp_show_type_prefix_list,
6174 bgp_show_type_filter_list,
6175 bgp_show_type_route_map,
6176 bgp_show_type_neighbor,
6177 bgp_show_type_cidr_only,
6178 bgp_show_type_prefix_longer,
6179 bgp_show_type_community_all,
6180 bgp_show_type_community,
6181 bgp_show_type_community_exact,
6182 bgp_show_type_community_list,
6183 bgp_show_type_community_list_exact,
6184 bgp_show_type_flap_statistics,
6185 bgp_show_type_flap_address,
6186 bgp_show_type_flap_prefix,
6187 bgp_show_type_flap_cidr_only,
6188 bgp_show_type_flap_regexp,
6189 bgp_show_type_flap_filter_list,
6190 bgp_show_type_flap_prefix_list,
6191 bgp_show_type_flap_prefix_longer,
6192 bgp_show_type_flap_route_map,
6193 bgp_show_type_flap_neighbor,
6194 bgp_show_type_dampend_paths,
6195 bgp_show_type_damp_neighbor
6196};
6197
ajs5a646652004-11-05 01:25:55 +00006198static int
paulfee0f4c2004-09-13 05:12:46 +00006199bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006200 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006201{
paul718e3742002-12-13 20:15:29 +00006202 struct bgp_info *ri;
6203 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006204 int header = 1;
paul718e3742002-12-13 20:15:29 +00006205 int display;
ajs5a646652004-11-05 01:25:55 +00006206 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006207
6208 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006209 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006210
paul718e3742002-12-13 20:15:29 +00006211 /* Start processing of routes. */
6212 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6213 if (rn->info != NULL)
6214 {
6215 display = 0;
6216
6217 for (ri = rn->info; ri; ri = ri->next)
6218 {
ajs5a646652004-11-05 01:25:55 +00006219 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006220 || type == bgp_show_type_flap_address
6221 || type == bgp_show_type_flap_prefix
6222 || type == bgp_show_type_flap_cidr_only
6223 || type == bgp_show_type_flap_regexp
6224 || type == bgp_show_type_flap_filter_list
6225 || type == bgp_show_type_flap_prefix_list
6226 || type == bgp_show_type_flap_prefix_longer
6227 || type == bgp_show_type_flap_route_map
6228 || type == bgp_show_type_flap_neighbor
6229 || type == bgp_show_type_dampend_paths
6230 || type == bgp_show_type_damp_neighbor)
6231 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006232 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006233 continue;
6234 }
6235 if (type == bgp_show_type_regexp
6236 || type == bgp_show_type_flap_regexp)
6237 {
ajs5a646652004-11-05 01:25:55 +00006238 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006239
6240 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6241 continue;
6242 }
6243 if (type == bgp_show_type_prefix_list
6244 || type == bgp_show_type_flap_prefix_list)
6245 {
ajs5a646652004-11-05 01:25:55 +00006246 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006247
6248 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6249 continue;
6250 }
6251 if (type == bgp_show_type_filter_list
6252 || type == bgp_show_type_flap_filter_list)
6253 {
ajs5a646652004-11-05 01:25:55 +00006254 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006255
6256 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6257 continue;
6258 }
6259 if (type == bgp_show_type_route_map
6260 || type == bgp_show_type_flap_route_map)
6261 {
ajs5a646652004-11-05 01:25:55 +00006262 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006263 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006264 struct attr dummy_attr;
6265 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006266 int ret;
6267
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006268 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006269 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006270
paul718e3742002-12-13 20:15:29 +00006271 binfo.peer = ri->peer;
6272 binfo.attr = &dummy_attr;
6273
6274 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006275 if (ret == RMAP_DENYMATCH)
6276 continue;
6277 }
6278 if (type == bgp_show_type_neighbor
6279 || type == bgp_show_type_flap_neighbor
6280 || type == bgp_show_type_damp_neighbor)
6281 {
ajs5a646652004-11-05 01:25:55 +00006282 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006283
6284 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6285 continue;
6286 }
6287 if (type == bgp_show_type_cidr_only
6288 || type == bgp_show_type_flap_cidr_only)
6289 {
6290 u_int32_t destination;
6291
6292 destination = ntohl (rn->p.u.prefix4.s_addr);
6293 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6294 continue;
6295 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6296 continue;
6297 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6298 continue;
6299 }
6300 if (type == bgp_show_type_prefix_longer
6301 || type == bgp_show_type_flap_prefix_longer)
6302 {
ajs5a646652004-11-05 01:25:55 +00006303 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006304
6305 if (! prefix_match (p, &rn->p))
6306 continue;
6307 }
6308 if (type == bgp_show_type_community_all)
6309 {
6310 if (! ri->attr->community)
6311 continue;
6312 }
6313 if (type == bgp_show_type_community)
6314 {
ajs5a646652004-11-05 01:25:55 +00006315 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006316
6317 if (! ri->attr->community ||
6318 ! community_match (ri->attr->community, com))
6319 continue;
6320 }
6321 if (type == bgp_show_type_community_exact)
6322 {
ajs5a646652004-11-05 01:25:55 +00006323 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006324
6325 if (! ri->attr->community ||
6326 ! community_cmp (ri->attr->community, com))
6327 continue;
6328 }
6329 if (type == bgp_show_type_community_list)
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_match (ri->attr->community, list))
6334 continue;
6335 }
6336 if (type == bgp_show_type_community_list_exact)
6337 {
ajs5a646652004-11-05 01:25:55 +00006338 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006339
6340 if (! community_list_exact_match (ri->attr->community, list))
6341 continue;
6342 }
6343 if (type == bgp_show_type_flap_address
6344 || type == bgp_show_type_flap_prefix)
6345 {
ajs5a646652004-11-05 01:25:55 +00006346 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006347
6348 if (! prefix_match (&rn->p, p))
6349 continue;
6350
6351 if (type == bgp_show_type_flap_prefix)
6352 if (p->prefixlen != rn->p.prefixlen)
6353 continue;
6354 }
6355 if (type == bgp_show_type_dampend_paths
6356 || type == bgp_show_type_damp_neighbor)
6357 {
6358 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6359 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6360 continue;
6361 }
6362
6363 if (header)
6364 {
hasso93406d82005-02-02 14:40:33 +00006365 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6366 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6367 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006368 if (type == bgp_show_type_dampend_paths
6369 || type == bgp_show_type_damp_neighbor)
6370 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6371 else if (type == bgp_show_type_flap_statistics
6372 || type == bgp_show_type_flap_address
6373 || type == bgp_show_type_flap_prefix
6374 || type == bgp_show_type_flap_cidr_only
6375 || type == bgp_show_type_flap_regexp
6376 || type == bgp_show_type_flap_filter_list
6377 || type == bgp_show_type_flap_prefix_list
6378 || type == bgp_show_type_flap_prefix_longer
6379 || type == bgp_show_type_flap_route_map
6380 || type == bgp_show_type_flap_neighbor)
6381 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6382 else
6383 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006384 header = 0;
6385 }
6386
6387 if (type == bgp_show_type_dampend_paths
6388 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006389 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006390 else if (type == bgp_show_type_flap_statistics
6391 || type == bgp_show_type_flap_address
6392 || type == bgp_show_type_flap_prefix
6393 || type == bgp_show_type_flap_cidr_only
6394 || type == bgp_show_type_flap_regexp
6395 || type == bgp_show_type_flap_filter_list
6396 || type == bgp_show_type_flap_prefix_list
6397 || type == bgp_show_type_flap_prefix_longer
6398 || type == bgp_show_type_flap_route_map
6399 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006400 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006401 else
ajs5a646652004-11-05 01:25:55 +00006402 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006403 display++;
6404 }
6405 if (display)
ajs5a646652004-11-05 01:25:55 +00006406 output_count++;
paul718e3742002-12-13 20:15:29 +00006407 }
6408
6409 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006410 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006411 {
6412 if (type == bgp_show_type_normal)
6413 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6414 }
6415 else
6416 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006417 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006418
6419 return CMD_SUCCESS;
6420}
6421
ajs5a646652004-11-05 01:25:55 +00006422static int
paulfee0f4c2004-09-13 05:12:46 +00006423bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006424 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006425{
6426 struct bgp_table *table;
6427
6428 if (bgp == NULL) {
6429 bgp = bgp_get_default ();
6430 }
6431
6432 if (bgp == NULL)
6433 {
6434 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6435 return CMD_WARNING;
6436 }
6437
6438
6439 table = bgp->rib[afi][safi];
6440
ajs5a646652004-11-05 01:25:55 +00006441 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006442}
6443
paul718e3742002-12-13 20:15:29 +00006444/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006445static void
paul718e3742002-12-13 20:15:29 +00006446route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6447 struct bgp_node *rn,
6448 struct prefix_rd *prd, afi_t afi, safi_t safi)
6449{
6450 struct bgp_info *ri;
6451 struct prefix *p;
6452 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006453 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006454 char buf1[INET6_ADDRSTRLEN];
6455 char buf2[INET6_ADDRSTRLEN];
6456 int count = 0;
6457 int best = 0;
6458 int suppress = 0;
6459 int no_export = 0;
6460 int no_advertise = 0;
6461 int local_as = 0;
6462 int first = 0;
6463
6464 p = &rn->p;
6465 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6466 (safi == SAFI_MPLS_VPN ?
6467 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6468 safi == SAFI_MPLS_VPN ? ":" : "",
6469 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6470 p->prefixlen, VTY_NEWLINE);
6471
6472 for (ri = rn->info; ri; ri = ri->next)
6473 {
6474 count++;
6475 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6476 {
6477 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006478 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006479 suppress = 1;
6480 if (ri->attr->community != NULL)
6481 {
6482 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6483 no_advertise = 1;
6484 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6485 no_export = 1;
6486 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6487 local_as = 1;
6488 }
6489 }
6490 }
6491
6492 vty_out (vty, "Paths: (%d available", count);
6493 if (best)
6494 {
6495 vty_out (vty, ", best #%d", best);
6496 if (safi == SAFI_UNICAST)
6497 vty_out (vty, ", table Default-IP-Routing-Table");
6498 }
6499 else
6500 vty_out (vty, ", no best path");
6501 if (no_advertise)
6502 vty_out (vty, ", not advertised to any peer");
6503 else if (no_export)
6504 vty_out (vty, ", not advertised to EBGP peer");
6505 else if (local_as)
6506 vty_out (vty, ", not advertised outside local AS");
6507 if (suppress)
6508 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6509 vty_out (vty, ")%s", VTY_NEWLINE);
6510
6511 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006512 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006513 {
6514 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6515 {
6516 if (! first)
6517 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6518 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6519 first = 1;
6520 }
6521 }
6522 if (! first)
6523 vty_out (vty, " Not advertised to any peer");
6524 vty_out (vty, "%s", VTY_NEWLINE);
6525}
6526
6527/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006528static int
paulfee0f4c2004-09-13 05:12:46 +00006529bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006530 struct bgp_table *rib, const char *ip_str,
6531 afi_t afi, safi_t safi, struct prefix_rd *prd,
6532 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006533{
6534 int ret;
6535 int header;
6536 int display = 0;
6537 struct prefix match;
6538 struct bgp_node *rn;
6539 struct bgp_node *rm;
6540 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006541 struct bgp_table *table;
6542
paul718e3742002-12-13 20:15:29 +00006543 /* Check IP address argument. */
6544 ret = str2prefix (ip_str, &match);
6545 if (! ret)
6546 {
6547 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6548 return CMD_WARNING;
6549 }
6550
6551 match.family = afi2family (afi);
6552
6553 if (safi == SAFI_MPLS_VPN)
6554 {
paulfee0f4c2004-09-13 05:12:46 +00006555 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006556 {
6557 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6558 continue;
6559
6560 if ((table = rn->info) != NULL)
6561 {
6562 header = 1;
6563
6564 if ((rm = bgp_node_match (table, &match)) != NULL)
6565 {
6566 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006567 {
6568 bgp_unlock_node (rm);
6569 continue;
6570 }
paul718e3742002-12-13 20:15:29 +00006571
6572 for (ri = rm->info; ri; ri = ri->next)
6573 {
6574 if (header)
6575 {
6576 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6577 AFI_IP, SAFI_MPLS_VPN);
6578
6579 header = 0;
6580 }
6581 display++;
6582 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6583 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006584
6585 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006586 }
6587 }
6588 }
6589 }
6590 else
6591 {
6592 header = 1;
6593
paulfee0f4c2004-09-13 05:12:46 +00006594 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006595 {
6596 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6597 {
6598 for (ri = rn->info; ri; ri = ri->next)
6599 {
6600 if (header)
6601 {
6602 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6603 header = 0;
6604 }
6605 display++;
6606 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6607 }
6608 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006609
6610 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006611 }
6612 }
6613
6614 if (! display)
6615 {
6616 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6617 return CMD_WARNING;
6618 }
6619
6620 return CMD_SUCCESS;
6621}
6622
paulfee0f4c2004-09-13 05:12:46 +00006623/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006624static int
paulfd79ac92004-10-13 05:06:08 +00006625bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006626 afi_t afi, safi_t safi, struct prefix_rd *prd,
6627 int prefix_check)
6628{
6629 struct bgp *bgp;
6630
6631 /* BGP structure lookup. */
6632 if (view_name)
6633 {
6634 bgp = bgp_lookup_by_name (view_name);
6635 if (bgp == NULL)
6636 {
6637 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6638 return CMD_WARNING;
6639 }
6640 }
6641 else
6642 {
6643 bgp = bgp_get_default ();
6644 if (bgp == NULL)
6645 {
6646 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6647 return CMD_WARNING;
6648 }
6649 }
6650
6651 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6652 afi, safi, prd, prefix_check);
6653}
6654
paul718e3742002-12-13 20:15:29 +00006655/* BGP route print out function. */
6656DEFUN (show_ip_bgp,
6657 show_ip_bgp_cmd,
6658 "show ip bgp",
6659 SHOW_STR
6660 IP_STR
6661 BGP_STR)
6662{
ajs5a646652004-11-05 01:25:55 +00006663 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006664}
6665
6666DEFUN (show_ip_bgp_ipv4,
6667 show_ip_bgp_ipv4_cmd,
6668 "show ip bgp ipv4 (unicast|multicast)",
6669 SHOW_STR
6670 IP_STR
6671 BGP_STR
6672 "Address family\n"
6673 "Address Family modifier\n"
6674 "Address Family modifier\n")
6675{
6676 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006677 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6678 NULL);
paul718e3742002-12-13 20:15:29 +00006679
ajs5a646652004-11-05 01:25:55 +00006680 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006681}
6682
Michael Lambert95cbbd22010-07-23 14:43:04 -04006683ALIAS (show_ip_bgp_ipv4,
6684 show_bgp_ipv4_safi_cmd,
6685 "show bgp ipv4 (unicast|multicast)",
6686 SHOW_STR
6687 BGP_STR
6688 "Address family\n"
6689 "Address Family modifier\n"
6690 "Address Family modifier\n")
6691
paul718e3742002-12-13 20:15:29 +00006692DEFUN (show_ip_bgp_route,
6693 show_ip_bgp_route_cmd,
6694 "show ip bgp A.B.C.D",
6695 SHOW_STR
6696 IP_STR
6697 BGP_STR
6698 "Network in the BGP routing table to display\n")
6699{
6700 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6701}
6702
6703DEFUN (show_ip_bgp_ipv4_route,
6704 show_ip_bgp_ipv4_route_cmd,
6705 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6706 SHOW_STR
6707 IP_STR
6708 BGP_STR
6709 "Address family\n"
6710 "Address Family modifier\n"
6711 "Address Family modifier\n"
6712 "Network in the BGP routing table to display\n")
6713{
6714 if (strncmp (argv[0], "m", 1) == 0)
6715 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6716
6717 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6718}
6719
Michael Lambert95cbbd22010-07-23 14:43:04 -04006720ALIAS (show_ip_bgp_ipv4_route,
6721 show_bgp_ipv4_safi_route_cmd,
6722 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6723 SHOW_STR
6724 BGP_STR
6725 "Address family\n"
6726 "Address Family modifier\n"
6727 "Address Family modifier\n"
6728 "Network in the BGP routing table to display\n")
6729
paul718e3742002-12-13 20:15:29 +00006730DEFUN (show_ip_bgp_vpnv4_all_route,
6731 show_ip_bgp_vpnv4_all_route_cmd,
6732 "show ip bgp vpnv4 all A.B.C.D",
6733 SHOW_STR
6734 IP_STR
6735 BGP_STR
6736 "Display VPNv4 NLRI specific information\n"
6737 "Display information about all VPNv4 NLRIs\n"
6738 "Network in the BGP routing table to display\n")
6739{
6740 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6741}
6742
6743DEFUN (show_ip_bgp_vpnv4_rd_route,
6744 show_ip_bgp_vpnv4_rd_route_cmd,
6745 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6746 SHOW_STR
6747 IP_STR
6748 BGP_STR
6749 "Display VPNv4 NLRI specific information\n"
6750 "Display information for a route distinguisher\n"
6751 "VPN Route Distinguisher\n"
6752 "Network in the BGP routing table to display\n")
6753{
6754 int ret;
6755 struct prefix_rd prd;
6756
6757 ret = str2prefix_rd (argv[0], &prd);
6758 if (! ret)
6759 {
6760 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6761 return CMD_WARNING;
6762 }
6763 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6764}
6765
6766DEFUN (show_ip_bgp_prefix,
6767 show_ip_bgp_prefix_cmd,
6768 "show ip bgp A.B.C.D/M",
6769 SHOW_STR
6770 IP_STR
6771 BGP_STR
6772 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6773{
6774 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6775}
6776
6777DEFUN (show_ip_bgp_ipv4_prefix,
6778 show_ip_bgp_ipv4_prefix_cmd,
6779 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6780 SHOW_STR
6781 IP_STR
6782 BGP_STR
6783 "Address family\n"
6784 "Address Family modifier\n"
6785 "Address Family modifier\n"
6786 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6787{
6788 if (strncmp (argv[0], "m", 1) == 0)
6789 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6790
6791 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6792}
6793
Michael Lambert95cbbd22010-07-23 14:43:04 -04006794ALIAS (show_ip_bgp_ipv4_prefix,
6795 show_bgp_ipv4_safi_prefix_cmd,
6796 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6797 SHOW_STR
6798 BGP_STR
6799 "Address family\n"
6800 "Address Family modifier\n"
6801 "Address Family modifier\n"
6802 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6803
paul718e3742002-12-13 20:15:29 +00006804DEFUN (show_ip_bgp_vpnv4_all_prefix,
6805 show_ip_bgp_vpnv4_all_prefix_cmd,
6806 "show ip bgp vpnv4 all A.B.C.D/M",
6807 SHOW_STR
6808 IP_STR
6809 BGP_STR
6810 "Display VPNv4 NLRI specific information\n"
6811 "Display information about all VPNv4 NLRIs\n"
6812 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6813{
6814 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6815}
6816
6817DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6818 show_ip_bgp_vpnv4_rd_prefix_cmd,
6819 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6820 SHOW_STR
6821 IP_STR
6822 BGP_STR
6823 "Display VPNv4 NLRI specific information\n"
6824 "Display information for a route distinguisher\n"
6825 "VPN Route Distinguisher\n"
6826 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6827{
6828 int ret;
6829 struct prefix_rd prd;
6830
6831 ret = str2prefix_rd (argv[0], &prd);
6832 if (! ret)
6833 {
6834 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6835 return CMD_WARNING;
6836 }
6837 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6838}
6839
6840DEFUN (show_ip_bgp_view,
6841 show_ip_bgp_view_cmd,
6842 "show ip bgp view WORD",
6843 SHOW_STR
6844 IP_STR
6845 BGP_STR
6846 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006847 "View name\n")
paul718e3742002-12-13 20:15:29 +00006848{
paulbb46e942003-10-24 19:02:03 +00006849 struct bgp *bgp;
6850
6851 /* BGP structure lookup. */
6852 bgp = bgp_lookup_by_name (argv[0]);
6853 if (bgp == NULL)
6854 {
6855 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6856 return CMD_WARNING;
6857 }
6858
ajs5a646652004-11-05 01:25:55 +00006859 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006860}
6861
6862DEFUN (show_ip_bgp_view_route,
6863 show_ip_bgp_view_route_cmd,
6864 "show ip bgp view WORD A.B.C.D",
6865 SHOW_STR
6866 IP_STR
6867 BGP_STR
6868 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006869 "View name\n"
paul718e3742002-12-13 20:15:29 +00006870 "Network in the BGP routing table to display\n")
6871{
6872 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6873}
6874
6875DEFUN (show_ip_bgp_view_prefix,
6876 show_ip_bgp_view_prefix_cmd,
6877 "show ip bgp view WORD A.B.C.D/M",
6878 SHOW_STR
6879 IP_STR
6880 BGP_STR
6881 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006882 "View name\n"
paul718e3742002-12-13 20:15:29 +00006883 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6884{
6885 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6886}
6887
6888#ifdef HAVE_IPV6
6889DEFUN (show_bgp,
6890 show_bgp_cmd,
6891 "show bgp",
6892 SHOW_STR
6893 BGP_STR)
6894{
ajs5a646652004-11-05 01:25:55 +00006895 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6896 NULL);
paul718e3742002-12-13 20:15:29 +00006897}
6898
6899ALIAS (show_bgp,
6900 show_bgp_ipv6_cmd,
6901 "show bgp ipv6",
6902 SHOW_STR
6903 BGP_STR
6904 "Address family\n")
6905
Michael Lambert95cbbd22010-07-23 14:43:04 -04006906DEFUN (show_bgp_ipv6_safi,
6907 show_bgp_ipv6_safi_cmd,
6908 "show bgp ipv6 (unicast|multicast)",
6909 SHOW_STR
6910 BGP_STR
6911 "Address family\n"
6912 "Address Family modifier\n"
6913 "Address Family modifier\n")
6914{
6915 if (strncmp (argv[0], "m", 1) == 0)
6916 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6917 NULL);
6918
6919 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6920}
6921
paul718e3742002-12-13 20:15:29 +00006922/* old command */
6923DEFUN (show_ipv6_bgp,
6924 show_ipv6_bgp_cmd,
6925 "show ipv6 bgp",
6926 SHOW_STR
6927 IP_STR
6928 BGP_STR)
6929{
ajs5a646652004-11-05 01:25:55 +00006930 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6931 NULL);
paul718e3742002-12-13 20:15:29 +00006932}
6933
6934DEFUN (show_bgp_route,
6935 show_bgp_route_cmd,
6936 "show bgp X:X::X:X",
6937 SHOW_STR
6938 BGP_STR
6939 "Network in the BGP routing table to display\n")
6940{
6941 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6942}
6943
6944ALIAS (show_bgp_route,
6945 show_bgp_ipv6_route_cmd,
6946 "show bgp ipv6 X:X::X:X",
6947 SHOW_STR
6948 BGP_STR
6949 "Address family\n"
6950 "Network in the BGP routing table to display\n")
6951
Michael Lambert95cbbd22010-07-23 14:43:04 -04006952DEFUN (show_bgp_ipv6_safi_route,
6953 show_bgp_ipv6_safi_route_cmd,
6954 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6955 SHOW_STR
6956 BGP_STR
6957 "Address family\n"
6958 "Address Family modifier\n"
6959 "Address Family modifier\n"
6960 "Network in the BGP routing table to display\n")
6961{
6962 if (strncmp (argv[0], "m", 1) == 0)
6963 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6964
6965 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6966}
6967
paul718e3742002-12-13 20:15:29 +00006968/* old command */
6969DEFUN (show_ipv6_bgp_route,
6970 show_ipv6_bgp_route_cmd,
6971 "show ipv6 bgp X:X::X:X",
6972 SHOW_STR
6973 IP_STR
6974 BGP_STR
6975 "Network in the BGP routing table to display\n")
6976{
6977 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6978}
6979
6980DEFUN (show_bgp_prefix,
6981 show_bgp_prefix_cmd,
6982 "show bgp X:X::X:X/M",
6983 SHOW_STR
6984 BGP_STR
6985 "IPv6 prefix <network>/<length>\n")
6986{
6987 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6988}
6989
6990ALIAS (show_bgp_prefix,
6991 show_bgp_ipv6_prefix_cmd,
6992 "show bgp ipv6 X:X::X:X/M",
6993 SHOW_STR
6994 BGP_STR
6995 "Address family\n"
6996 "IPv6 prefix <network>/<length>\n")
6997
Michael Lambert95cbbd22010-07-23 14:43:04 -04006998DEFUN (show_bgp_ipv6_safi_prefix,
6999 show_bgp_ipv6_safi_prefix_cmd,
7000 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7001 SHOW_STR
7002 BGP_STR
7003 "Address family\n"
7004 "Address Family modifier\n"
7005 "Address Family modifier\n"
7006 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7007{
7008 if (strncmp (argv[0], "m", 1) == 0)
7009 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7010
7011 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7012}
7013
paul718e3742002-12-13 20:15:29 +00007014/* old command */
7015DEFUN (show_ipv6_bgp_prefix,
7016 show_ipv6_bgp_prefix_cmd,
7017 "show ipv6 bgp X:X::X:X/M",
7018 SHOW_STR
7019 IP_STR
7020 BGP_STR
7021 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7022{
7023 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7024}
7025
paulbb46e942003-10-24 19:02:03 +00007026DEFUN (show_bgp_view,
7027 show_bgp_view_cmd,
7028 "show bgp view WORD",
7029 SHOW_STR
7030 BGP_STR
7031 "BGP view\n"
7032 "View name\n")
7033{
7034 struct bgp *bgp;
7035
7036 /* BGP structure lookup. */
7037 bgp = bgp_lookup_by_name (argv[0]);
7038 if (bgp == NULL)
7039 {
7040 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7041 return CMD_WARNING;
7042 }
7043
ajs5a646652004-11-05 01:25:55 +00007044 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007045}
7046
7047ALIAS (show_bgp_view,
7048 show_bgp_view_ipv6_cmd,
7049 "show bgp view WORD ipv6",
7050 SHOW_STR
7051 BGP_STR
7052 "BGP view\n"
7053 "View name\n"
7054 "Address family\n")
7055
7056DEFUN (show_bgp_view_route,
7057 show_bgp_view_route_cmd,
7058 "show bgp view WORD X:X::X:X",
7059 SHOW_STR
7060 BGP_STR
7061 "BGP view\n"
7062 "View name\n"
7063 "Network in the BGP routing table to display\n")
7064{
7065 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7066}
7067
7068ALIAS (show_bgp_view_route,
7069 show_bgp_view_ipv6_route_cmd,
7070 "show bgp view WORD ipv6 X:X::X:X",
7071 SHOW_STR
7072 BGP_STR
7073 "BGP view\n"
7074 "View name\n"
7075 "Address family\n"
7076 "Network in the BGP routing table to display\n")
7077
7078DEFUN (show_bgp_view_prefix,
7079 show_bgp_view_prefix_cmd,
7080 "show bgp view WORD X:X::X:X/M",
7081 SHOW_STR
7082 BGP_STR
7083 "BGP view\n"
7084 "View name\n"
7085 "IPv6 prefix <network>/<length>\n")
7086{
7087 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7088}
7089
7090ALIAS (show_bgp_view_prefix,
7091 show_bgp_view_ipv6_prefix_cmd,
7092 "show bgp view WORD ipv6 X:X::X:X/M",
7093 SHOW_STR
7094 BGP_STR
7095 "BGP view\n"
7096 "View name\n"
7097 "Address family\n"
7098 "IPv6 prefix <network>/<length>\n")
7099
paul718e3742002-12-13 20:15:29 +00007100/* old command */
7101DEFUN (show_ipv6_mbgp,
7102 show_ipv6_mbgp_cmd,
7103 "show ipv6 mbgp",
7104 SHOW_STR
7105 IP_STR
7106 MBGP_STR)
7107{
ajs5a646652004-11-05 01:25:55 +00007108 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7109 NULL);
paul718e3742002-12-13 20:15:29 +00007110}
7111
7112/* old command */
7113DEFUN (show_ipv6_mbgp_route,
7114 show_ipv6_mbgp_route_cmd,
7115 "show ipv6 mbgp X:X::X:X",
7116 SHOW_STR
7117 IP_STR
7118 MBGP_STR
7119 "Network in the MBGP routing table to display\n")
7120{
7121 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7122}
7123
7124/* old command */
7125DEFUN (show_ipv6_mbgp_prefix,
7126 show_ipv6_mbgp_prefix_cmd,
7127 "show ipv6 mbgp X:X::X:X/M",
7128 SHOW_STR
7129 IP_STR
7130 MBGP_STR
7131 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7132{
7133 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7134}
7135#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007136
paul718e3742002-12-13 20:15:29 +00007137
paul94f2b392005-06-28 12:44:16 +00007138static int
paulfd79ac92004-10-13 05:06:08 +00007139bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007140 safi_t safi, enum bgp_show_type type)
7141{
7142 int i;
7143 struct buffer *b;
7144 char *regstr;
7145 int first;
7146 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007147 int rc;
paul718e3742002-12-13 20:15:29 +00007148
7149 first = 0;
7150 b = buffer_new (1024);
7151 for (i = 0; i < argc; i++)
7152 {
7153 if (first)
7154 buffer_putc (b, ' ');
7155 else
7156 {
7157 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7158 continue;
7159 first = 1;
7160 }
7161
7162 buffer_putstr (b, argv[i]);
7163 }
7164 buffer_putc (b, '\0');
7165
7166 regstr = buffer_getstr (b);
7167 buffer_free (b);
7168
7169 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007170 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007171 if (! regex)
7172 {
7173 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7174 VTY_NEWLINE);
7175 return CMD_WARNING;
7176 }
7177
ajs5a646652004-11-05 01:25:55 +00007178 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7179 bgp_regex_free (regex);
7180 return rc;
paul718e3742002-12-13 20:15:29 +00007181}
7182
7183DEFUN (show_ip_bgp_regexp,
7184 show_ip_bgp_regexp_cmd,
7185 "show ip bgp regexp .LINE",
7186 SHOW_STR
7187 IP_STR
7188 BGP_STR
7189 "Display routes matching the AS path regular expression\n"
7190 "A regular-expression to match the BGP AS paths\n")
7191{
7192 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7193 bgp_show_type_regexp);
7194}
7195
7196DEFUN (show_ip_bgp_flap_regexp,
7197 show_ip_bgp_flap_regexp_cmd,
7198 "show ip bgp flap-statistics regexp .LINE",
7199 SHOW_STR
7200 IP_STR
7201 BGP_STR
7202 "Display flap statistics of routes\n"
7203 "Display routes matching the AS path regular expression\n"
7204 "A regular-expression to match the BGP AS paths\n")
7205{
7206 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7207 bgp_show_type_flap_regexp);
7208}
7209
7210DEFUN (show_ip_bgp_ipv4_regexp,
7211 show_ip_bgp_ipv4_regexp_cmd,
7212 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7213 SHOW_STR
7214 IP_STR
7215 BGP_STR
7216 "Address family\n"
7217 "Address Family modifier\n"
7218 "Address Family modifier\n"
7219 "Display routes matching the AS path regular expression\n"
7220 "A regular-expression to match the BGP AS paths\n")
7221{
7222 if (strncmp (argv[0], "m", 1) == 0)
7223 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7224 bgp_show_type_regexp);
7225
7226 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7227 bgp_show_type_regexp);
7228}
7229
7230#ifdef HAVE_IPV6
7231DEFUN (show_bgp_regexp,
7232 show_bgp_regexp_cmd,
7233 "show bgp regexp .LINE",
7234 SHOW_STR
7235 BGP_STR
7236 "Display routes matching the AS path regular expression\n"
7237 "A regular-expression to match the BGP AS paths\n")
7238{
7239 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7240 bgp_show_type_regexp);
7241}
7242
7243ALIAS (show_bgp_regexp,
7244 show_bgp_ipv6_regexp_cmd,
7245 "show bgp ipv6 regexp .LINE",
7246 SHOW_STR
7247 BGP_STR
7248 "Address family\n"
7249 "Display routes matching the AS path regular expression\n"
7250 "A regular-expression to match the BGP AS paths\n")
7251
7252/* old command */
7253DEFUN (show_ipv6_bgp_regexp,
7254 show_ipv6_bgp_regexp_cmd,
7255 "show ipv6 bgp regexp .LINE",
7256 SHOW_STR
7257 IP_STR
7258 BGP_STR
7259 "Display routes matching the AS path regular expression\n"
7260 "A regular-expression to match the BGP AS paths\n")
7261{
7262 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7263 bgp_show_type_regexp);
7264}
7265
7266/* old command */
7267DEFUN (show_ipv6_mbgp_regexp,
7268 show_ipv6_mbgp_regexp_cmd,
7269 "show ipv6 mbgp regexp .LINE",
7270 SHOW_STR
7271 IP_STR
7272 BGP_STR
7273 "Display routes matching the AS path regular expression\n"
7274 "A regular-expression to match the MBGP AS paths\n")
7275{
7276 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7277 bgp_show_type_regexp);
7278}
7279#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007280
paul94f2b392005-06-28 12:44:16 +00007281static int
paulfd79ac92004-10-13 05:06:08 +00007282bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007283 safi_t safi, enum bgp_show_type type)
7284{
7285 struct prefix_list *plist;
7286
7287 plist = prefix_list_lookup (afi, prefix_list_str);
7288 if (plist == NULL)
7289 {
7290 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7291 prefix_list_str, VTY_NEWLINE);
7292 return CMD_WARNING;
7293 }
7294
ajs5a646652004-11-05 01:25:55 +00007295 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007296}
7297
7298DEFUN (show_ip_bgp_prefix_list,
7299 show_ip_bgp_prefix_list_cmd,
7300 "show ip bgp prefix-list WORD",
7301 SHOW_STR
7302 IP_STR
7303 BGP_STR
7304 "Display routes conforming to the prefix-list\n"
7305 "IP prefix-list name\n")
7306{
7307 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7308 bgp_show_type_prefix_list);
7309}
7310
7311DEFUN (show_ip_bgp_flap_prefix_list,
7312 show_ip_bgp_flap_prefix_list_cmd,
7313 "show ip bgp flap-statistics prefix-list WORD",
7314 SHOW_STR
7315 IP_STR
7316 BGP_STR
7317 "Display flap statistics of routes\n"
7318 "Display routes conforming to the prefix-list\n"
7319 "IP prefix-list name\n")
7320{
7321 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7322 bgp_show_type_flap_prefix_list);
7323}
7324
7325DEFUN (show_ip_bgp_ipv4_prefix_list,
7326 show_ip_bgp_ipv4_prefix_list_cmd,
7327 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7328 SHOW_STR
7329 IP_STR
7330 BGP_STR
7331 "Address family\n"
7332 "Address Family modifier\n"
7333 "Address Family modifier\n"
7334 "Display routes conforming to the prefix-list\n"
7335 "IP prefix-list name\n")
7336{
7337 if (strncmp (argv[0], "m", 1) == 0)
7338 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7339 bgp_show_type_prefix_list);
7340
7341 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7342 bgp_show_type_prefix_list);
7343}
7344
7345#ifdef HAVE_IPV6
7346DEFUN (show_bgp_prefix_list,
7347 show_bgp_prefix_list_cmd,
7348 "show bgp prefix-list WORD",
7349 SHOW_STR
7350 BGP_STR
7351 "Display routes conforming to the prefix-list\n"
7352 "IPv6 prefix-list name\n")
7353{
7354 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7355 bgp_show_type_prefix_list);
7356}
7357
7358ALIAS (show_bgp_prefix_list,
7359 show_bgp_ipv6_prefix_list_cmd,
7360 "show bgp ipv6 prefix-list WORD",
7361 SHOW_STR
7362 BGP_STR
7363 "Address family\n"
7364 "Display routes conforming to the prefix-list\n"
7365 "IPv6 prefix-list name\n")
7366
7367/* old command */
7368DEFUN (show_ipv6_bgp_prefix_list,
7369 show_ipv6_bgp_prefix_list_cmd,
7370 "show ipv6 bgp prefix-list WORD",
7371 SHOW_STR
7372 IPV6_STR
7373 BGP_STR
7374 "Display routes matching the prefix-list\n"
7375 "IPv6 prefix-list name\n")
7376{
7377 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7378 bgp_show_type_prefix_list);
7379}
7380
7381/* old command */
7382DEFUN (show_ipv6_mbgp_prefix_list,
7383 show_ipv6_mbgp_prefix_list_cmd,
7384 "show ipv6 mbgp prefix-list WORD",
7385 SHOW_STR
7386 IPV6_STR
7387 MBGP_STR
7388 "Display routes matching the prefix-list\n"
7389 "IPv6 prefix-list name\n")
7390{
7391 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7392 bgp_show_type_prefix_list);
7393}
7394#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007395
paul94f2b392005-06-28 12:44:16 +00007396static int
paulfd79ac92004-10-13 05:06:08 +00007397bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007398 safi_t safi, enum bgp_show_type type)
7399{
7400 struct as_list *as_list;
7401
7402 as_list = as_list_lookup (filter);
7403 if (as_list == NULL)
7404 {
7405 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7406 return CMD_WARNING;
7407 }
7408
ajs5a646652004-11-05 01:25:55 +00007409 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007410}
7411
7412DEFUN (show_ip_bgp_filter_list,
7413 show_ip_bgp_filter_list_cmd,
7414 "show ip bgp filter-list WORD",
7415 SHOW_STR
7416 IP_STR
7417 BGP_STR
7418 "Display routes conforming to the filter-list\n"
7419 "Regular expression access list name\n")
7420{
7421 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7422 bgp_show_type_filter_list);
7423}
7424
7425DEFUN (show_ip_bgp_flap_filter_list,
7426 show_ip_bgp_flap_filter_list_cmd,
7427 "show ip bgp flap-statistics filter-list WORD",
7428 SHOW_STR
7429 IP_STR
7430 BGP_STR
7431 "Display flap statistics of routes\n"
7432 "Display routes conforming to the filter-list\n"
7433 "Regular expression access list name\n")
7434{
7435 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7436 bgp_show_type_flap_filter_list);
7437}
7438
7439DEFUN (show_ip_bgp_ipv4_filter_list,
7440 show_ip_bgp_ipv4_filter_list_cmd,
7441 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7442 SHOW_STR
7443 IP_STR
7444 BGP_STR
7445 "Address family\n"
7446 "Address Family modifier\n"
7447 "Address Family modifier\n"
7448 "Display routes conforming to the filter-list\n"
7449 "Regular expression access list name\n")
7450{
7451 if (strncmp (argv[0], "m", 1) == 0)
7452 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7453 bgp_show_type_filter_list);
7454
7455 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7456 bgp_show_type_filter_list);
7457}
7458
7459#ifdef HAVE_IPV6
7460DEFUN (show_bgp_filter_list,
7461 show_bgp_filter_list_cmd,
7462 "show bgp filter-list WORD",
7463 SHOW_STR
7464 BGP_STR
7465 "Display routes conforming to the filter-list\n"
7466 "Regular expression access list name\n")
7467{
7468 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7469 bgp_show_type_filter_list);
7470}
7471
7472ALIAS (show_bgp_filter_list,
7473 show_bgp_ipv6_filter_list_cmd,
7474 "show bgp ipv6 filter-list WORD",
7475 SHOW_STR
7476 BGP_STR
7477 "Address family\n"
7478 "Display routes conforming to the filter-list\n"
7479 "Regular expression access list name\n")
7480
7481/* old command */
7482DEFUN (show_ipv6_bgp_filter_list,
7483 show_ipv6_bgp_filter_list_cmd,
7484 "show ipv6 bgp filter-list WORD",
7485 SHOW_STR
7486 IPV6_STR
7487 BGP_STR
7488 "Display routes conforming to the filter-list\n"
7489 "Regular expression access list name\n")
7490{
7491 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7492 bgp_show_type_filter_list);
7493}
7494
7495/* old command */
7496DEFUN (show_ipv6_mbgp_filter_list,
7497 show_ipv6_mbgp_filter_list_cmd,
7498 "show ipv6 mbgp filter-list WORD",
7499 SHOW_STR
7500 IPV6_STR
7501 MBGP_STR
7502 "Display routes conforming to the filter-list\n"
7503 "Regular expression access list name\n")
7504{
7505 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7506 bgp_show_type_filter_list);
7507}
7508#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007509
paul94f2b392005-06-28 12:44:16 +00007510static int
paulfd79ac92004-10-13 05:06:08 +00007511bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007512 safi_t safi, enum bgp_show_type type)
7513{
7514 struct route_map *rmap;
7515
7516 rmap = route_map_lookup_by_name (rmap_str);
7517 if (! rmap)
7518 {
7519 vty_out (vty, "%% %s is not a valid route-map name%s",
7520 rmap_str, VTY_NEWLINE);
7521 return CMD_WARNING;
7522 }
7523
ajs5a646652004-11-05 01:25:55 +00007524 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007525}
7526
7527DEFUN (show_ip_bgp_route_map,
7528 show_ip_bgp_route_map_cmd,
7529 "show ip bgp route-map WORD",
7530 SHOW_STR
7531 IP_STR
7532 BGP_STR
7533 "Display routes matching the route-map\n"
7534 "A route-map to match on\n")
7535{
7536 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7537 bgp_show_type_route_map);
7538}
7539
7540DEFUN (show_ip_bgp_flap_route_map,
7541 show_ip_bgp_flap_route_map_cmd,
7542 "show ip bgp flap-statistics route-map WORD",
7543 SHOW_STR
7544 IP_STR
7545 BGP_STR
7546 "Display flap statistics of routes\n"
7547 "Display routes matching the route-map\n"
7548 "A route-map to match on\n")
7549{
7550 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7551 bgp_show_type_flap_route_map);
7552}
7553
7554DEFUN (show_ip_bgp_ipv4_route_map,
7555 show_ip_bgp_ipv4_route_map_cmd,
7556 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7557 SHOW_STR
7558 IP_STR
7559 BGP_STR
7560 "Address family\n"
7561 "Address Family modifier\n"
7562 "Address Family modifier\n"
7563 "Display routes matching the route-map\n"
7564 "A route-map to match on\n")
7565{
7566 if (strncmp (argv[0], "m", 1) == 0)
7567 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7568 bgp_show_type_route_map);
7569
7570 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7571 bgp_show_type_route_map);
7572}
7573
7574DEFUN (show_bgp_route_map,
7575 show_bgp_route_map_cmd,
7576 "show bgp route-map WORD",
7577 SHOW_STR
7578 BGP_STR
7579 "Display routes matching the route-map\n"
7580 "A route-map to match on\n")
7581{
7582 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7583 bgp_show_type_route_map);
7584}
7585
7586ALIAS (show_bgp_route_map,
7587 show_bgp_ipv6_route_map_cmd,
7588 "show bgp ipv6 route-map WORD",
7589 SHOW_STR
7590 BGP_STR
7591 "Address family\n"
7592 "Display routes matching the route-map\n"
7593 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007594
paul718e3742002-12-13 20:15:29 +00007595DEFUN (show_ip_bgp_cidr_only,
7596 show_ip_bgp_cidr_only_cmd,
7597 "show ip bgp cidr-only",
7598 SHOW_STR
7599 IP_STR
7600 BGP_STR
7601 "Display only routes with non-natural netmasks\n")
7602{
7603 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007604 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007605}
7606
7607DEFUN (show_ip_bgp_flap_cidr_only,
7608 show_ip_bgp_flap_cidr_only_cmd,
7609 "show ip bgp flap-statistics cidr-only",
7610 SHOW_STR
7611 IP_STR
7612 BGP_STR
7613 "Display flap statistics of routes\n"
7614 "Display only routes with non-natural netmasks\n")
7615{
7616 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007617 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007618}
7619
7620DEFUN (show_ip_bgp_ipv4_cidr_only,
7621 show_ip_bgp_ipv4_cidr_only_cmd,
7622 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7623 SHOW_STR
7624 IP_STR
7625 BGP_STR
7626 "Address family\n"
7627 "Address Family modifier\n"
7628 "Address Family modifier\n"
7629 "Display only routes with non-natural netmasks\n")
7630{
7631 if (strncmp (argv[0], "m", 1) == 0)
7632 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007633 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007634
7635 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007636 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007637}
David Lamparter6b0655a2014-06-04 06:53:35 +02007638
paul718e3742002-12-13 20:15:29 +00007639DEFUN (show_ip_bgp_community_all,
7640 show_ip_bgp_community_all_cmd,
7641 "show ip bgp community",
7642 SHOW_STR
7643 IP_STR
7644 BGP_STR
7645 "Display routes matching the communities\n")
7646{
7647 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007648 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007649}
7650
7651DEFUN (show_ip_bgp_ipv4_community_all,
7652 show_ip_bgp_ipv4_community_all_cmd,
7653 "show ip bgp ipv4 (unicast|multicast) community",
7654 SHOW_STR
7655 IP_STR
7656 BGP_STR
7657 "Address family\n"
7658 "Address Family modifier\n"
7659 "Address Family modifier\n"
7660 "Display routes matching the communities\n")
7661{
7662 if (strncmp (argv[0], "m", 1) == 0)
7663 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007664 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007665
7666 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007667 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007668}
7669
7670#ifdef HAVE_IPV6
7671DEFUN (show_bgp_community_all,
7672 show_bgp_community_all_cmd,
7673 "show bgp community",
7674 SHOW_STR
7675 BGP_STR
7676 "Display routes matching the communities\n")
7677{
7678 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007679 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007680}
7681
7682ALIAS (show_bgp_community_all,
7683 show_bgp_ipv6_community_all_cmd,
7684 "show bgp ipv6 community",
7685 SHOW_STR
7686 BGP_STR
7687 "Address family\n"
7688 "Display routes matching the communities\n")
7689
7690/* old command */
7691DEFUN (show_ipv6_bgp_community_all,
7692 show_ipv6_bgp_community_all_cmd,
7693 "show ipv6 bgp community",
7694 SHOW_STR
7695 IPV6_STR
7696 BGP_STR
7697 "Display routes matching the communities\n")
7698{
7699 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007700 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007701}
7702
7703/* old command */
7704DEFUN (show_ipv6_mbgp_community_all,
7705 show_ipv6_mbgp_community_all_cmd,
7706 "show ipv6 mbgp community",
7707 SHOW_STR
7708 IPV6_STR
7709 MBGP_STR
7710 "Display routes matching the communities\n")
7711{
7712 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007713 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007714}
7715#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007716
paul94f2b392005-06-28 12:44:16 +00007717static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007718bgp_show_community (struct vty *vty, const char *view_name, int argc,
7719 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007720{
7721 struct community *com;
7722 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007723 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007724 int i;
7725 char *str;
7726 int first = 0;
7727
Michael Lambert95cbbd22010-07-23 14:43:04 -04007728 /* BGP structure lookup */
7729 if (view_name)
7730 {
7731 bgp = bgp_lookup_by_name (view_name);
7732 if (bgp == NULL)
7733 {
7734 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7735 return CMD_WARNING;
7736 }
7737 }
7738 else
7739 {
7740 bgp = bgp_get_default ();
7741 if (bgp == NULL)
7742 {
7743 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7744 return CMD_WARNING;
7745 }
7746 }
7747
paul718e3742002-12-13 20:15:29 +00007748 b = buffer_new (1024);
7749 for (i = 0; i < argc; i++)
7750 {
7751 if (first)
7752 buffer_putc (b, ' ');
7753 else
7754 {
7755 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7756 continue;
7757 first = 1;
7758 }
7759
7760 buffer_putstr (b, argv[i]);
7761 }
7762 buffer_putc (b, '\0');
7763
7764 str = buffer_getstr (b);
7765 buffer_free (b);
7766
7767 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007768 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007769 if (! com)
7770 {
7771 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7772 return CMD_WARNING;
7773 }
7774
Michael Lambert95cbbd22010-07-23 14:43:04 -04007775 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007776 (exact ? bgp_show_type_community_exact :
7777 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007778}
7779
7780DEFUN (show_ip_bgp_community,
7781 show_ip_bgp_community_cmd,
7782 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7783 SHOW_STR
7784 IP_STR
7785 BGP_STR
7786 "Display routes matching the communities\n"
7787 "community number\n"
7788 "Do not send outside local AS (well-known community)\n"
7789 "Do not advertise to any peer (well-known community)\n"
7790 "Do not export to next AS (well-known community)\n")
7791{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007792 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007793}
7794
7795ALIAS (show_ip_bgp_community,
7796 show_ip_bgp_community2_cmd,
7797 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7798 SHOW_STR
7799 IP_STR
7800 BGP_STR
7801 "Display routes matching the communities\n"
7802 "community number\n"
7803 "Do not send outside local AS (well-known community)\n"
7804 "Do not advertise to any peer (well-known community)\n"
7805 "Do not export to next AS (well-known community)\n"
7806 "community number\n"
7807 "Do not send outside local AS (well-known community)\n"
7808 "Do not advertise to any peer (well-known community)\n"
7809 "Do not export to next AS (well-known community)\n")
7810
7811ALIAS (show_ip_bgp_community,
7812 show_ip_bgp_community3_cmd,
7813 "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)",
7814 SHOW_STR
7815 IP_STR
7816 BGP_STR
7817 "Display routes matching the communities\n"
7818 "community number\n"
7819 "Do not send outside local AS (well-known community)\n"
7820 "Do not advertise to any peer (well-known community)\n"
7821 "Do not export to next AS (well-known community)\n"
7822 "community number\n"
7823 "Do not send outside local AS (well-known community)\n"
7824 "Do not advertise to any peer (well-known community)\n"
7825 "Do not export to next AS (well-known community)\n"
7826 "community number\n"
7827 "Do not send outside local AS (well-known community)\n"
7828 "Do not advertise to any peer (well-known community)\n"
7829 "Do not export to next AS (well-known community)\n")
7830
7831ALIAS (show_ip_bgp_community,
7832 show_ip_bgp_community4_cmd,
7833 "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)",
7834 SHOW_STR
7835 IP_STR
7836 BGP_STR
7837 "Display routes matching the communities\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n"
7842 "community number\n"
7843 "Do not send outside local AS (well-known community)\n"
7844 "Do not advertise to any peer (well-known community)\n"
7845 "Do not export to next AS (well-known community)\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 "community number\n"
7851 "Do not send outside local AS (well-known community)\n"
7852 "Do not advertise to any peer (well-known community)\n"
7853 "Do not export to next AS (well-known community)\n")
7854
7855DEFUN (show_ip_bgp_ipv4_community,
7856 show_ip_bgp_ipv4_community_cmd,
7857 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7858 SHOW_STR
7859 IP_STR
7860 BGP_STR
7861 "Address family\n"
7862 "Address Family modifier\n"
7863 "Address Family modifier\n"
7864 "Display routes matching the communities\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{
7870 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007871 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007872
Michael Lambert95cbbd22010-07-23 14:43:04 -04007873 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007874}
7875
7876ALIAS (show_ip_bgp_ipv4_community,
7877 show_ip_bgp_ipv4_community2_cmd,
7878 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7879 SHOW_STR
7880 IP_STR
7881 BGP_STR
7882 "Address family\n"
7883 "Address Family modifier\n"
7884 "Address Family modifier\n"
7885 "Display routes matching the communities\n"
7886 "community number\n"
7887 "Do not send outside local AS (well-known community)\n"
7888 "Do not advertise to any peer (well-known community)\n"
7889 "Do not export to next AS (well-known community)\n"
7890 "community number\n"
7891 "Do not send outside local AS (well-known community)\n"
7892 "Do not advertise to any peer (well-known community)\n"
7893 "Do not export to next AS (well-known community)\n")
7894
7895ALIAS (show_ip_bgp_ipv4_community,
7896 show_ip_bgp_ipv4_community3_cmd,
7897 "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)",
7898 SHOW_STR
7899 IP_STR
7900 BGP_STR
7901 "Address family\n"
7902 "Address Family modifier\n"
7903 "Address Family modifier\n"
7904 "Display routes matching the communities\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 "community number\n"
7914 "Do not send outside local AS (well-known community)\n"
7915 "Do not advertise to any peer (well-known community)\n"
7916 "Do not export to next AS (well-known community)\n")
7917
7918ALIAS (show_ip_bgp_ipv4_community,
7919 show_ip_bgp_ipv4_community4_cmd,
7920 "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)",
7921 SHOW_STR
7922 IP_STR
7923 BGP_STR
7924 "Address family\n"
7925 "Address Family modifier\n"
7926 "Address Family modifier\n"
7927 "Display routes matching the communities\n"
7928 "community number\n"
7929 "Do not send outside local AS (well-known community)\n"
7930 "Do not advertise to any peer (well-known community)\n"
7931 "Do not export to next AS (well-known community)\n"
7932 "community number\n"
7933 "Do not send outside local AS (well-known community)\n"
7934 "Do not advertise to any peer (well-known community)\n"
7935 "Do not export to next AS (well-known community)\n"
7936 "community number\n"
7937 "Do not send outside local AS (well-known community)\n"
7938 "Do not advertise to any peer (well-known community)\n"
7939 "Do not export to next AS (well-known community)\n"
7940 "community number\n"
7941 "Do not send outside local AS (well-known community)\n"
7942 "Do not advertise to any peer (well-known community)\n"
7943 "Do not export to next AS (well-known community)\n")
7944
Michael Lambert95cbbd22010-07-23 14:43:04 -04007945DEFUN (show_bgp_view_afi_safi_community_all,
7946 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007947 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007948 SHOW_STR
7949 BGP_STR
7950 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007951 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007952 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007953 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007954 "Address Family modifier\n"
7955 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007956 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007957{
7958 int afi;
7959 int safi;
7960 struct bgp *bgp;
7961
7962 /* BGP structure lookup. */
7963 bgp = bgp_lookup_by_name (argv[0]);
7964 if (bgp == NULL)
7965 {
7966 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7967 return CMD_WARNING;
7968 }
7969
Michael Lambert95cbbd22010-07-23 14:43:04 -04007970 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7971 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007972 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7973}
7974
7975DEFUN (show_bgp_view_afi_safi_community,
7976 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007977 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007978 SHOW_STR
7979 BGP_STR
7980 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007981 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007982 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007983 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007984 "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{
7992 int afi;
7993 int safi;
7994
Michael Lambert95cbbd22010-07-23 14:43:04 -04007995 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7996 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7997 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007998}
7999
8000ALIAS (show_bgp_view_afi_safi_community,
8001 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008002 "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 -04008003 SHOW_STR
8004 BGP_STR
8005 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008006 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008007 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008008 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008009 "Address family modifier\n"
8010 "Address family modifier\n"
8011 "Display routes matching the communities\n"
8012 "community number\n"
8013 "Do not send outside local AS (well-known community)\n"
8014 "Do not advertise to any peer (well-known community)\n"
8015 "Do not export to next AS (well-known community)\n"
8016 "community number\n"
8017 "Do not send outside local AS (well-known community)\n"
8018 "Do not advertise to any peer (well-known community)\n"
8019 "Do not export to next AS (well-known community)\n")
8020
8021ALIAS (show_bgp_view_afi_safi_community,
8022 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008023 "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 -04008024 SHOW_STR
8025 BGP_STR
8026 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008027 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008028 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008029 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008030 "Address family modifier\n"
8031 "Address family modifier\n"
8032 "Display routes matching the communities\n"
8033 "community number\n"
8034 "Do not send outside local AS (well-known community)\n"
8035 "Do not advertise to any peer (well-known community)\n"
8036 "Do not export to next AS (well-known community)\n"
8037 "community number\n"
8038 "Do not send outside local AS (well-known community)\n"
8039 "Do not advertise to any peer (well-known community)\n"
8040 "Do not export to next AS (well-known community)\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n")
8045
8046ALIAS (show_bgp_view_afi_safi_community,
8047 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008048 "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 -04008049 SHOW_STR
8050 BGP_STR
8051 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008052 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008053 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008054 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008055 "Address family modifier\n"
8056 "Address family modifier\n"
8057 "Display routes matching the communities\n"
8058 "community number\n"
8059 "Do not send outside local AS (well-known community)\n"
8060 "Do not advertise to any peer (well-known community)\n"
8061 "Do not export to next AS (well-known community)\n"
8062 "community number\n"
8063 "Do not send outside local AS (well-known community)\n"
8064 "Do not advertise to any peer (well-known community)\n"
8065 "Do not export to next AS (well-known community)\n"
8066 "community number\n"
8067 "Do not send outside local AS (well-known community)\n"
8068 "Do not advertise to any peer (well-known community)\n"
8069 "Do not export to next AS (well-known community)\n"
8070 "community number\n"
8071 "Do not send outside local AS (well-known community)\n"
8072 "Do not advertise to any peer (well-known community)\n"
8073 "Do not export to next AS (well-known community)\n")
8074
paul718e3742002-12-13 20:15:29 +00008075DEFUN (show_ip_bgp_community_exact,
8076 show_ip_bgp_community_exact_cmd,
8077 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8078 SHOW_STR
8079 IP_STR
8080 BGP_STR
8081 "Display routes matching the communities\n"
8082 "community number\n"
8083 "Do not send outside local AS (well-known community)\n"
8084 "Do not advertise to any peer (well-known community)\n"
8085 "Do not export to next AS (well-known community)\n"
8086 "Exact match of the communities")
8087{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008088 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008089}
8090
8091ALIAS (show_ip_bgp_community_exact,
8092 show_ip_bgp_community2_exact_cmd,
8093 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8094 SHOW_STR
8095 IP_STR
8096 BGP_STR
8097 "Display routes matching the communities\n"
8098 "community number\n"
8099 "Do not send outside local AS (well-known community)\n"
8100 "Do not advertise to any peer (well-known community)\n"
8101 "Do not export to next AS (well-known community)\n"
8102 "community number\n"
8103 "Do not send outside local AS (well-known community)\n"
8104 "Do not advertise to any peer (well-known community)\n"
8105 "Do not export to next AS (well-known community)\n"
8106 "Exact match of the communities")
8107
8108ALIAS (show_ip_bgp_community_exact,
8109 show_ip_bgp_community3_exact_cmd,
8110 "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",
8111 SHOW_STR
8112 IP_STR
8113 BGP_STR
8114 "Display routes matching the communities\n"
8115 "community number\n"
8116 "Do not send outside local AS (well-known community)\n"
8117 "Do not advertise to any peer (well-known community)\n"
8118 "Do not export to next AS (well-known community)\n"
8119 "community number\n"
8120 "Do not send outside local AS (well-known community)\n"
8121 "Do not advertise to any peer (well-known community)\n"
8122 "Do not export to next AS (well-known community)\n"
8123 "community number\n"
8124 "Do not send outside local AS (well-known community)\n"
8125 "Do not advertise to any peer (well-known community)\n"
8126 "Do not export to next AS (well-known community)\n"
8127 "Exact match of the communities")
8128
8129ALIAS (show_ip_bgp_community_exact,
8130 show_ip_bgp_community4_exact_cmd,
8131 "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",
8132 SHOW_STR
8133 IP_STR
8134 BGP_STR
8135 "Display routes matching the communities\n"
8136 "community number\n"
8137 "Do not send outside local AS (well-known community)\n"
8138 "Do not advertise to any peer (well-known community)\n"
8139 "Do not export to next AS (well-known community)\n"
8140 "community number\n"
8141 "Do not send outside local AS (well-known community)\n"
8142 "Do not advertise to any peer (well-known community)\n"
8143 "Do not export to next AS (well-known community)\n"
8144 "community number\n"
8145 "Do not send outside local AS (well-known community)\n"
8146 "Do not advertise to any peer (well-known community)\n"
8147 "Do not export to next AS (well-known community)\n"
8148 "community number\n"
8149 "Do not send outside local AS (well-known community)\n"
8150 "Do not advertise to any peer (well-known community)\n"
8151 "Do not export to next AS (well-known community)\n"
8152 "Exact match of the communities")
8153
8154DEFUN (show_ip_bgp_ipv4_community_exact,
8155 show_ip_bgp_ipv4_community_exact_cmd,
8156 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8157 SHOW_STR
8158 IP_STR
8159 BGP_STR
8160 "Address family\n"
8161 "Address Family modifier\n"
8162 "Address Family modifier\n"
8163 "Display routes matching the communities\n"
8164 "community number\n"
8165 "Do not send outside local AS (well-known community)\n"
8166 "Do not advertise to any peer (well-known community)\n"
8167 "Do not export to next AS (well-known community)\n"
8168 "Exact match of the communities")
8169{
8170 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008171 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008172
Michael Lambert95cbbd22010-07-23 14:43:04 -04008173 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008174}
8175
8176ALIAS (show_ip_bgp_ipv4_community_exact,
8177 show_ip_bgp_ipv4_community2_exact_cmd,
8178 "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",
8179 SHOW_STR
8180 IP_STR
8181 BGP_STR
8182 "Address family\n"
8183 "Address Family modifier\n"
8184 "Address Family modifier\n"
8185 "Display routes matching the communities\n"
8186 "community number\n"
8187 "Do not send outside local AS (well-known community)\n"
8188 "Do not advertise to any peer (well-known community)\n"
8189 "Do not export to next AS (well-known community)\n"
8190 "community number\n"
8191 "Do not send outside local AS (well-known community)\n"
8192 "Do not advertise to any peer (well-known community)\n"
8193 "Do not export to next AS (well-known community)\n"
8194 "Exact match of the communities")
8195
8196ALIAS (show_ip_bgp_ipv4_community_exact,
8197 show_ip_bgp_ipv4_community3_exact_cmd,
8198 "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",
8199 SHOW_STR
8200 IP_STR
8201 BGP_STR
8202 "Address family\n"
8203 "Address Family modifier\n"
8204 "Address Family modifier\n"
8205 "Display routes matching the communities\n"
8206 "community number\n"
8207 "Do not send outside local AS (well-known community)\n"
8208 "Do not advertise to any peer (well-known community)\n"
8209 "Do not export to next AS (well-known community)\n"
8210 "community number\n"
8211 "Do not send outside local AS (well-known community)\n"
8212 "Do not advertise to any peer (well-known community)\n"
8213 "Do not export to next AS (well-known community)\n"
8214 "community number\n"
8215 "Do not send outside local AS (well-known community)\n"
8216 "Do not advertise to any peer (well-known community)\n"
8217 "Do not export to next AS (well-known community)\n"
8218 "Exact match of the communities")
8219
8220ALIAS (show_ip_bgp_ipv4_community_exact,
8221 show_ip_bgp_ipv4_community4_exact_cmd,
8222 "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",
8223 SHOW_STR
8224 IP_STR
8225 BGP_STR
8226 "Address family\n"
8227 "Address Family modifier\n"
8228 "Address Family modifier\n"
8229 "Display routes matching the communities\n"
8230 "community number\n"
8231 "Do not send outside local AS (well-known community)\n"
8232 "Do not advertise to any peer (well-known community)\n"
8233 "Do not export to next AS (well-known community)\n"
8234 "community number\n"
8235 "Do not send outside local AS (well-known community)\n"
8236 "Do not advertise to any peer (well-known community)\n"
8237 "Do not export to next AS (well-known community)\n"
8238 "community number\n"
8239 "Do not send outside local AS (well-known community)\n"
8240 "Do not advertise to any peer (well-known community)\n"
8241 "Do not export to next AS (well-known community)\n"
8242 "community number\n"
8243 "Do not send outside local AS (well-known community)\n"
8244 "Do not advertise to any peer (well-known community)\n"
8245 "Do not export to next AS (well-known community)\n"
8246 "Exact match of the communities")
8247
8248#ifdef HAVE_IPV6
8249DEFUN (show_bgp_community,
8250 show_bgp_community_cmd,
8251 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8252 SHOW_STR
8253 BGP_STR
8254 "Display routes matching the communities\n"
8255 "community number\n"
8256 "Do not send outside local AS (well-known community)\n"
8257 "Do not advertise to any peer (well-known community)\n"
8258 "Do not export to next AS (well-known community)\n")
8259{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008260 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008261}
8262
8263ALIAS (show_bgp_community,
8264 show_bgp_ipv6_community_cmd,
8265 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8266 SHOW_STR
8267 BGP_STR
8268 "Address family\n"
8269 "Display routes matching the communities\n"
8270 "community number\n"
8271 "Do not send outside local AS (well-known community)\n"
8272 "Do not advertise to any peer (well-known community)\n"
8273 "Do not export to next AS (well-known community)\n")
8274
8275ALIAS (show_bgp_community,
8276 show_bgp_community2_cmd,
8277 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8278 SHOW_STR
8279 BGP_STR
8280 "Display routes matching the communities\n"
8281 "community number\n"
8282 "Do not send outside local AS (well-known community)\n"
8283 "Do not advertise to any peer (well-known community)\n"
8284 "Do not export to next AS (well-known community)\n"
8285 "community number\n"
8286 "Do not send outside local AS (well-known community)\n"
8287 "Do not advertise to any peer (well-known community)\n"
8288 "Do not export to next AS (well-known community)\n")
8289
8290ALIAS (show_bgp_community,
8291 show_bgp_ipv6_community2_cmd,
8292 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8293 SHOW_STR
8294 BGP_STR
8295 "Address family\n"
8296 "Display routes matching the communities\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
8306ALIAS (show_bgp_community,
8307 show_bgp_community3_cmd,
8308 "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)",
8309 SHOW_STR
8310 BGP_STR
8311 "Display routes matching the communities\n"
8312 "community number\n"
8313 "Do not send outside local AS (well-known community)\n"
8314 "Do not advertise to any peer (well-known community)\n"
8315 "Do not export to next AS (well-known community)\n"
8316 "community number\n"
8317 "Do not send outside local AS (well-known community)\n"
8318 "Do not advertise to any peer (well-known community)\n"
8319 "Do not export to next AS (well-known community)\n"
8320 "community number\n"
8321 "Do not send outside local AS (well-known community)\n"
8322 "Do not advertise to any peer (well-known community)\n"
8323 "Do not export to next AS (well-known community)\n")
8324
8325ALIAS (show_bgp_community,
8326 show_bgp_ipv6_community3_cmd,
8327 "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)",
8328 SHOW_STR
8329 BGP_STR
8330 "Address family\n"
8331 "Display routes matching the communities\n"
8332 "community number\n"
8333 "Do not send outside local AS (well-known community)\n"
8334 "Do not advertise to any peer (well-known community)\n"
8335 "Do not export to next AS (well-known community)\n"
8336 "community number\n"
8337 "Do not send outside local AS (well-known community)\n"
8338 "Do not advertise to any peer (well-known community)\n"
8339 "Do not export to next AS (well-known community)\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
8345ALIAS (show_bgp_community,
8346 show_bgp_community4_cmd,
8347 "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)",
8348 SHOW_STR
8349 BGP_STR
8350 "Display routes matching the communities\n"
8351 "community number\n"
8352 "Do not send outside local AS (well-known community)\n"
8353 "Do not advertise to any peer (well-known community)\n"
8354 "Do not export to next AS (well-known community)\n"
8355 "community number\n"
8356 "Do not send outside local AS (well-known community)\n"
8357 "Do not advertise to any peer (well-known community)\n"
8358 "Do not export to next AS (well-known community)\n"
8359 "community number\n"
8360 "Do not send outside local AS (well-known community)\n"
8361 "Do not advertise to any peer (well-known community)\n"
8362 "Do not export to next AS (well-known community)\n"
8363 "community number\n"
8364 "Do not send outside local AS (well-known community)\n"
8365 "Do not advertise to any peer (well-known community)\n"
8366 "Do not export to next AS (well-known community)\n")
8367
8368ALIAS (show_bgp_community,
8369 show_bgp_ipv6_community4_cmd,
8370 "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)",
8371 SHOW_STR
8372 BGP_STR
8373 "Address family\n"
8374 "Display routes matching the communities\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 "community number\n"
8384 "Do not send outside local AS (well-known community)\n"
8385 "Do not advertise to any peer (well-known community)\n"
8386 "Do not export to next AS (well-known community)\n"
8387 "community number\n"
8388 "Do not send outside local AS (well-known community)\n"
8389 "Do not advertise to any peer (well-known community)\n"
8390 "Do not export to next AS (well-known community)\n")
8391
8392/* old command */
8393DEFUN (show_ipv6_bgp_community,
8394 show_ipv6_bgp_community_cmd,
8395 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8396 SHOW_STR
8397 IPV6_STR
8398 BGP_STR
8399 "Display routes matching the communities\n"
8400 "community number\n"
8401 "Do not send outside local AS (well-known community)\n"
8402 "Do not advertise to any peer (well-known community)\n"
8403 "Do not export to next AS (well-known community)\n")
8404{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008405 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008406}
8407
8408/* old command */
8409ALIAS (show_ipv6_bgp_community,
8410 show_ipv6_bgp_community2_cmd,
8411 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8412 SHOW_STR
8413 IPV6_STR
8414 BGP_STR
8415 "Display routes matching the communities\n"
8416 "community number\n"
8417 "Do not send outside local AS (well-known community)\n"
8418 "Do not advertise to any peer (well-known community)\n"
8419 "Do not export to next AS (well-known community)\n"
8420 "community number\n"
8421 "Do not send outside local AS (well-known community)\n"
8422 "Do not advertise to any peer (well-known community)\n"
8423 "Do not export to next AS (well-known community)\n")
8424
8425/* old command */
8426ALIAS (show_ipv6_bgp_community,
8427 show_ipv6_bgp_community3_cmd,
8428 "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)",
8429 SHOW_STR
8430 IPV6_STR
8431 BGP_STR
8432 "Display routes matching the communities\n"
8433 "community number\n"
8434 "Do not send outside local AS (well-known community)\n"
8435 "Do not advertise to any peer (well-known community)\n"
8436 "Do not export to next AS (well-known community)\n"
8437 "community number\n"
8438 "Do not send outside local AS (well-known community)\n"
8439 "Do not advertise to any peer (well-known community)\n"
8440 "Do not export to next AS (well-known community)\n"
8441 "community number\n"
8442 "Do not send outside local AS (well-known community)\n"
8443 "Do not advertise to any peer (well-known community)\n"
8444 "Do not export to next AS (well-known community)\n")
8445
8446/* old command */
8447ALIAS (show_ipv6_bgp_community,
8448 show_ipv6_bgp_community4_cmd,
8449 "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)",
8450 SHOW_STR
8451 IPV6_STR
8452 BGP_STR
8453 "Display routes matching the communities\n"
8454 "community number\n"
8455 "Do not send outside local AS (well-known community)\n"
8456 "Do not advertise to any peer (well-known community)\n"
8457 "Do not export to next AS (well-known community)\n"
8458 "community number\n"
8459 "Do not send outside local AS (well-known community)\n"
8460 "Do not advertise to any peer (well-known community)\n"
8461 "Do not export to next AS (well-known community)\n"
8462 "community number\n"
8463 "Do not send outside local AS (well-known community)\n"
8464 "Do not advertise to any peer (well-known community)\n"
8465 "Do not export to next AS (well-known community)\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n")
8470
8471DEFUN (show_bgp_community_exact,
8472 show_bgp_community_exact_cmd,
8473 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8474 SHOW_STR
8475 BGP_STR
8476 "Display routes matching the communities\n"
8477 "community number\n"
8478 "Do not send outside local AS (well-known community)\n"
8479 "Do not advertise to any peer (well-known community)\n"
8480 "Do not export to next AS (well-known community)\n"
8481 "Exact match of the communities")
8482{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008483 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008484}
8485
8486ALIAS (show_bgp_community_exact,
8487 show_bgp_ipv6_community_exact_cmd,
8488 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8489 SHOW_STR
8490 BGP_STR
8491 "Address family\n"
8492 "Display routes matching the communities\n"
8493 "community number\n"
8494 "Do not send outside local AS (well-known community)\n"
8495 "Do not advertise to any peer (well-known community)\n"
8496 "Do not export to next AS (well-known community)\n"
8497 "Exact match of the communities")
8498
8499ALIAS (show_bgp_community_exact,
8500 show_bgp_community2_exact_cmd,
8501 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8502 SHOW_STR
8503 BGP_STR
8504 "Display routes matching the communities\n"
8505 "community number\n"
8506 "Do not send outside local AS (well-known community)\n"
8507 "Do not advertise to any peer (well-known community)\n"
8508 "Do not export to next AS (well-known community)\n"
8509 "community number\n"
8510 "Do not send outside local AS (well-known community)\n"
8511 "Do not advertise to any peer (well-known community)\n"
8512 "Do not export to next AS (well-known community)\n"
8513 "Exact match of the communities")
8514
8515ALIAS (show_bgp_community_exact,
8516 show_bgp_ipv6_community2_exact_cmd,
8517 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8518 SHOW_STR
8519 BGP_STR
8520 "Address family\n"
8521 "Display routes matching the communities\n"
8522 "community number\n"
8523 "Do not send outside local AS (well-known community)\n"
8524 "Do not advertise to any peer (well-known community)\n"
8525 "Do not export to next AS (well-known community)\n"
8526 "community number\n"
8527 "Do not send outside local AS (well-known community)\n"
8528 "Do not advertise to any peer (well-known community)\n"
8529 "Do not export to next AS (well-known community)\n"
8530 "Exact match of the communities")
8531
8532ALIAS (show_bgp_community_exact,
8533 show_bgp_community3_exact_cmd,
8534 "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",
8535 SHOW_STR
8536 BGP_STR
8537 "Display routes matching the communities\n"
8538 "community number\n"
8539 "Do not send outside local AS (well-known community)\n"
8540 "Do not advertise to any peer (well-known community)\n"
8541 "Do not export to next AS (well-known community)\n"
8542 "community number\n"
8543 "Do not send outside local AS (well-known community)\n"
8544 "Do not advertise to any peer (well-known community)\n"
8545 "Do not export to next AS (well-known community)\n"
8546 "community number\n"
8547 "Do not send outside local AS (well-known community)\n"
8548 "Do not advertise to any peer (well-known community)\n"
8549 "Do not export to next AS (well-known community)\n"
8550 "Exact match of the communities")
8551
8552ALIAS (show_bgp_community_exact,
8553 show_bgp_ipv6_community3_exact_cmd,
8554 "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",
8555 SHOW_STR
8556 BGP_STR
8557 "Address family\n"
8558 "Display routes matching the communities\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n"
8563 "community number\n"
8564 "Do not send outside local AS (well-known community)\n"
8565 "Do not advertise to any peer (well-known community)\n"
8566 "Do not export to next AS (well-known community)\n"
8567 "community number\n"
8568 "Do not send outside local AS (well-known community)\n"
8569 "Do not advertise to any peer (well-known community)\n"
8570 "Do not export to next AS (well-known community)\n"
8571 "Exact match of the communities")
8572
8573ALIAS (show_bgp_community_exact,
8574 show_bgp_community4_exact_cmd,
8575 "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",
8576 SHOW_STR
8577 BGP_STR
8578 "Display routes matching the communities\n"
8579 "community number\n"
8580 "Do not send outside local AS (well-known community)\n"
8581 "Do not advertise to any peer (well-known community)\n"
8582 "Do not export to next AS (well-known community)\n"
8583 "community number\n"
8584 "Do not send outside local AS (well-known community)\n"
8585 "Do not advertise to any peer (well-known community)\n"
8586 "Do not export to next AS (well-known community)\n"
8587 "community number\n"
8588 "Do not send outside local AS (well-known community)\n"
8589 "Do not advertise to any peer (well-known community)\n"
8590 "Do not export to next AS (well-known community)\n"
8591 "community number\n"
8592 "Do not send outside local AS (well-known community)\n"
8593 "Do not advertise to any peer (well-known community)\n"
8594 "Do not export to next AS (well-known community)\n"
8595 "Exact match of the communities")
8596
8597ALIAS (show_bgp_community_exact,
8598 show_bgp_ipv6_community4_exact_cmd,
8599 "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",
8600 SHOW_STR
8601 BGP_STR
8602 "Address family\n"
8603 "Display routes matching the communities\n"
8604 "community number\n"
8605 "Do not send outside local AS (well-known community)\n"
8606 "Do not advertise to any peer (well-known community)\n"
8607 "Do not export to next AS (well-known community)\n"
8608 "community number\n"
8609 "Do not send outside local AS (well-known community)\n"
8610 "Do not advertise to any peer (well-known community)\n"
8611 "Do not export to next AS (well-known community)\n"
8612 "community number\n"
8613 "Do not send outside local AS (well-known community)\n"
8614 "Do not advertise to any peer (well-known community)\n"
8615 "Do not export to next AS (well-known community)\n"
8616 "community number\n"
8617 "Do not send outside local AS (well-known community)\n"
8618 "Do not advertise to any peer (well-known community)\n"
8619 "Do not export to next AS (well-known community)\n"
8620 "Exact match of the communities")
8621
8622/* old command */
8623DEFUN (show_ipv6_bgp_community_exact,
8624 show_ipv6_bgp_community_exact_cmd,
8625 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8626 SHOW_STR
8627 IPV6_STR
8628 BGP_STR
8629 "Display routes matching the communities\n"
8630 "community number\n"
8631 "Do not send outside local AS (well-known community)\n"
8632 "Do not advertise to any peer (well-known community)\n"
8633 "Do not export to next AS (well-known community)\n"
8634 "Exact match of the communities")
8635{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008636 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008637}
8638
8639/* old command */
8640ALIAS (show_ipv6_bgp_community_exact,
8641 show_ipv6_bgp_community2_exact_cmd,
8642 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8643 SHOW_STR
8644 IPV6_STR
8645 BGP_STR
8646 "Display routes matching the communities\n"
8647 "community number\n"
8648 "Do not send outside local AS (well-known community)\n"
8649 "Do not advertise to any peer (well-known community)\n"
8650 "Do not export to next AS (well-known community)\n"
8651 "community number\n"
8652 "Do not send outside local AS (well-known community)\n"
8653 "Do not advertise to any peer (well-known community)\n"
8654 "Do not export to next AS (well-known community)\n"
8655 "Exact match of the communities")
8656
8657/* old command */
8658ALIAS (show_ipv6_bgp_community_exact,
8659 show_ipv6_bgp_community3_exact_cmd,
8660 "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",
8661 SHOW_STR
8662 IPV6_STR
8663 BGP_STR
8664 "Display routes matching the communities\n"
8665 "community number\n"
8666 "Do not send outside local AS (well-known community)\n"
8667 "Do not advertise to any peer (well-known community)\n"
8668 "Do not export to next AS (well-known community)\n"
8669 "community number\n"
8670 "Do not send outside local AS (well-known community)\n"
8671 "Do not advertise to any peer (well-known community)\n"
8672 "Do not export to next AS (well-known community)\n"
8673 "community number\n"
8674 "Do not send outside local AS (well-known community)\n"
8675 "Do not advertise to any peer (well-known community)\n"
8676 "Do not export to next AS (well-known community)\n"
8677 "Exact match of the communities")
8678
8679/* old command */
8680ALIAS (show_ipv6_bgp_community_exact,
8681 show_ipv6_bgp_community4_exact_cmd,
8682 "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",
8683 SHOW_STR
8684 IPV6_STR
8685 BGP_STR
8686 "Display routes matching the communities\n"
8687 "community number\n"
8688 "Do not send outside local AS (well-known community)\n"
8689 "Do not advertise to any peer (well-known community)\n"
8690 "Do not export to next AS (well-known community)\n"
8691 "community number\n"
8692 "Do not send outside local AS (well-known community)\n"
8693 "Do not advertise to any peer (well-known community)\n"
8694 "Do not export to next AS (well-known community)\n"
8695 "community number\n"
8696 "Do not send outside local AS (well-known community)\n"
8697 "Do not advertise to any peer (well-known community)\n"
8698 "Do not export to next AS (well-known community)\n"
8699 "community number\n"
8700 "Do not send outside local AS (well-known community)\n"
8701 "Do not advertise to any peer (well-known community)\n"
8702 "Do not export to next AS (well-known community)\n"
8703 "Exact match of the communities")
8704
8705/* old command */
8706DEFUN (show_ipv6_mbgp_community,
8707 show_ipv6_mbgp_community_cmd,
8708 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8709 SHOW_STR
8710 IPV6_STR
8711 MBGP_STR
8712 "Display routes matching the communities\n"
8713 "community number\n"
8714 "Do not send outside local AS (well-known community)\n"
8715 "Do not advertise to any peer (well-known community)\n"
8716 "Do not export to next AS (well-known community)\n")
8717{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008718 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008719}
8720
8721/* old command */
8722ALIAS (show_ipv6_mbgp_community,
8723 show_ipv6_mbgp_community2_cmd,
8724 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8725 SHOW_STR
8726 IPV6_STR
8727 MBGP_STR
8728 "Display routes matching the communities\n"
8729 "community number\n"
8730 "Do not send outside local AS (well-known community)\n"
8731 "Do not advertise to any peer (well-known community)\n"
8732 "Do not export to next AS (well-known community)\n"
8733 "community number\n"
8734 "Do not send outside local AS (well-known community)\n"
8735 "Do not advertise to any peer (well-known community)\n"
8736 "Do not export to next AS (well-known community)\n")
8737
8738/* old command */
8739ALIAS (show_ipv6_mbgp_community,
8740 show_ipv6_mbgp_community3_cmd,
8741 "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)",
8742 SHOW_STR
8743 IPV6_STR
8744 MBGP_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
8759/* old command */
8760ALIAS (show_ipv6_mbgp_community,
8761 show_ipv6_mbgp_community4_cmd,
8762 "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)",
8763 SHOW_STR
8764 IPV6_STR
8765 MBGP_STR
8766 "Display routes matching the communities\n"
8767 "community number\n"
8768 "Do not send outside local AS (well-known community)\n"
8769 "Do not advertise to any peer (well-known community)\n"
8770 "Do not export to next AS (well-known community)\n"
8771 "community number\n"
8772 "Do not send outside local AS (well-known community)\n"
8773 "Do not advertise to any peer (well-known community)\n"
8774 "Do not export to next AS (well-known community)\n"
8775 "community number\n"
8776 "Do not send outside local AS (well-known community)\n"
8777 "Do not advertise to any peer (well-known community)\n"
8778 "Do not export to next AS (well-known community)\n"
8779 "community number\n"
8780 "Do not send outside local AS (well-known community)\n"
8781 "Do not advertise to any peer (well-known community)\n"
8782 "Do not export to next AS (well-known community)\n")
8783
8784/* old command */
8785DEFUN (show_ipv6_mbgp_community_exact,
8786 show_ipv6_mbgp_community_exact_cmd,
8787 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8788 SHOW_STR
8789 IPV6_STR
8790 MBGP_STR
8791 "Display routes matching the communities\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 "Exact match of the communities")
8797{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008798 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008799}
8800
8801/* old command */
8802ALIAS (show_ipv6_mbgp_community_exact,
8803 show_ipv6_mbgp_community2_exact_cmd,
8804 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8805 SHOW_STR
8806 IPV6_STR
8807 MBGP_STR
8808 "Display routes matching the communities\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 "Exact match of the communities")
8818
8819/* old command */
8820ALIAS (show_ipv6_mbgp_community_exact,
8821 show_ipv6_mbgp_community3_exact_cmd,
8822 "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",
8823 SHOW_STR
8824 IPV6_STR
8825 MBGP_STR
8826 "Display routes matching the communities\n"
8827 "community number\n"
8828 "Do not send outside local AS (well-known community)\n"
8829 "Do not advertise to any peer (well-known community)\n"
8830 "Do not export to next AS (well-known community)\n"
8831 "community number\n"
8832 "Do not send outside local AS (well-known community)\n"
8833 "Do not advertise to any peer (well-known community)\n"
8834 "Do not export to next AS (well-known community)\n"
8835 "community number\n"
8836 "Do not send outside local AS (well-known community)\n"
8837 "Do not advertise to any peer (well-known community)\n"
8838 "Do not export to next AS (well-known community)\n"
8839 "Exact match of the communities")
8840
8841/* old command */
8842ALIAS (show_ipv6_mbgp_community_exact,
8843 show_ipv6_mbgp_community4_exact_cmd,
8844 "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",
8845 SHOW_STR
8846 IPV6_STR
8847 MBGP_STR
8848 "Display routes matching the communities\n"
8849 "community number\n"
8850 "Do not send outside local AS (well-known community)\n"
8851 "Do not advertise to any peer (well-known community)\n"
8852 "Do not export to next AS (well-known community)\n"
8853 "community number\n"
8854 "Do not send outside local AS (well-known community)\n"
8855 "Do not advertise to any peer (well-known community)\n"
8856 "Do not export to next AS (well-known community)\n"
8857 "community number\n"
8858 "Do not send outside local AS (well-known community)\n"
8859 "Do not advertise to any peer (well-known community)\n"
8860 "Do not export to next AS (well-known community)\n"
8861 "community number\n"
8862 "Do not send outside local AS (well-known community)\n"
8863 "Do not advertise to any peer (well-known community)\n"
8864 "Do not export to next AS (well-known community)\n"
8865 "Exact match of the communities")
8866#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008867
paul94f2b392005-06-28 12:44:16 +00008868static int
paulfd79ac92004-10-13 05:06:08 +00008869bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008870 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008871{
8872 struct community_list *list;
8873
hassofee6e4e2005-02-02 16:29:31 +00008874 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008875 if (list == NULL)
8876 {
8877 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8878 VTY_NEWLINE);
8879 return CMD_WARNING;
8880 }
8881
ajs5a646652004-11-05 01:25:55 +00008882 return bgp_show (vty, NULL, afi, safi,
8883 (exact ? bgp_show_type_community_list_exact :
8884 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008885}
8886
8887DEFUN (show_ip_bgp_community_list,
8888 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008889 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008890 SHOW_STR
8891 IP_STR
8892 BGP_STR
8893 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008894 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008895 "community-list name\n")
8896{
8897 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8898}
8899
8900DEFUN (show_ip_bgp_ipv4_community_list,
8901 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008902 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008903 SHOW_STR
8904 IP_STR
8905 BGP_STR
8906 "Address family\n"
8907 "Address Family modifier\n"
8908 "Address Family modifier\n"
8909 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008910 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008911 "community-list name\n")
8912{
8913 if (strncmp (argv[0], "m", 1) == 0)
8914 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8915
8916 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8917}
8918
8919DEFUN (show_ip_bgp_community_list_exact,
8920 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008921 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008922 SHOW_STR
8923 IP_STR
8924 BGP_STR
8925 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008926 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008927 "community-list name\n"
8928 "Exact match of the communities\n")
8929{
8930 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8931}
8932
8933DEFUN (show_ip_bgp_ipv4_community_list_exact,
8934 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008935 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008936 SHOW_STR
8937 IP_STR
8938 BGP_STR
8939 "Address family\n"
8940 "Address Family modifier\n"
8941 "Address Family modifier\n"
8942 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008943 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008944 "community-list name\n"
8945 "Exact match of the communities\n")
8946{
8947 if (strncmp (argv[0], "m", 1) == 0)
8948 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8949
8950 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8951}
8952
8953#ifdef HAVE_IPV6
8954DEFUN (show_bgp_community_list,
8955 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008956 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008957 SHOW_STR
8958 BGP_STR
8959 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008960 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008961 "community-list name\n")
8962{
8963 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8964}
8965
8966ALIAS (show_bgp_community_list,
8967 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008968 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008969 SHOW_STR
8970 BGP_STR
8971 "Address family\n"
8972 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008973 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008974 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008975
8976/* old command */
8977DEFUN (show_ipv6_bgp_community_list,
8978 show_ipv6_bgp_community_list_cmd,
8979 "show ipv6 bgp community-list WORD",
8980 SHOW_STR
8981 IPV6_STR
8982 BGP_STR
8983 "Display routes matching the community-list\n"
8984 "community-list name\n")
8985{
8986 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8987}
8988
8989/* old command */
8990DEFUN (show_ipv6_mbgp_community_list,
8991 show_ipv6_mbgp_community_list_cmd,
8992 "show ipv6 mbgp community-list WORD",
8993 SHOW_STR
8994 IPV6_STR
8995 MBGP_STR
8996 "Display routes matching the community-list\n"
8997 "community-list name\n")
8998{
8999 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9000}
9001
9002DEFUN (show_bgp_community_list_exact,
9003 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009004 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009005 SHOW_STR
9006 BGP_STR
9007 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009008 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009009 "community-list name\n"
9010 "Exact match of the communities\n")
9011{
9012 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9013}
9014
9015ALIAS (show_bgp_community_list_exact,
9016 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009017 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009018 SHOW_STR
9019 BGP_STR
9020 "Address family\n"
9021 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009022 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009023 "community-list name\n"
9024 "Exact match of the communities\n")
9025
9026/* old command */
9027DEFUN (show_ipv6_bgp_community_list_exact,
9028 show_ipv6_bgp_community_list_exact_cmd,
9029 "show ipv6 bgp community-list WORD exact-match",
9030 SHOW_STR
9031 IPV6_STR
9032 BGP_STR
9033 "Display routes matching the community-list\n"
9034 "community-list name\n"
9035 "Exact match of the communities\n")
9036{
9037 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9038}
9039
9040/* old command */
9041DEFUN (show_ipv6_mbgp_community_list_exact,
9042 show_ipv6_mbgp_community_list_exact_cmd,
9043 "show ipv6 mbgp community-list WORD exact-match",
9044 SHOW_STR
9045 IPV6_STR
9046 MBGP_STR
9047 "Display routes matching the community-list\n"
9048 "community-list name\n"
9049 "Exact match of the communities\n")
9050{
9051 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9052}
9053#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009054
paul94f2b392005-06-28 12:44:16 +00009055static int
paulfd79ac92004-10-13 05:06:08 +00009056bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009057 safi_t safi, enum bgp_show_type type)
9058{
9059 int ret;
9060 struct prefix *p;
9061
9062 p = prefix_new();
9063
9064 ret = str2prefix (prefix, p);
9065 if (! ret)
9066 {
9067 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9068 return CMD_WARNING;
9069 }
9070
ajs5a646652004-11-05 01:25:55 +00009071 ret = bgp_show (vty, NULL, afi, safi, type, p);
9072 prefix_free(p);
9073 return ret;
paul718e3742002-12-13 20:15:29 +00009074}
9075
9076DEFUN (show_ip_bgp_prefix_longer,
9077 show_ip_bgp_prefix_longer_cmd,
9078 "show ip bgp A.B.C.D/M longer-prefixes",
9079 SHOW_STR
9080 IP_STR
9081 BGP_STR
9082 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9083 "Display route and more specific routes\n")
9084{
9085 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9086 bgp_show_type_prefix_longer);
9087}
9088
9089DEFUN (show_ip_bgp_flap_prefix_longer,
9090 show_ip_bgp_flap_prefix_longer_cmd,
9091 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9092 SHOW_STR
9093 IP_STR
9094 BGP_STR
9095 "Display flap statistics of routes\n"
9096 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9097 "Display route and more specific routes\n")
9098{
9099 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9100 bgp_show_type_flap_prefix_longer);
9101}
9102
9103DEFUN (show_ip_bgp_ipv4_prefix_longer,
9104 show_ip_bgp_ipv4_prefix_longer_cmd,
9105 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9106 SHOW_STR
9107 IP_STR
9108 BGP_STR
9109 "Address family\n"
9110 "Address Family modifier\n"
9111 "Address Family modifier\n"
9112 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9113 "Display route and more specific routes\n")
9114{
9115 if (strncmp (argv[0], "m", 1) == 0)
9116 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9117 bgp_show_type_prefix_longer);
9118
9119 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9120 bgp_show_type_prefix_longer);
9121}
9122
9123DEFUN (show_ip_bgp_flap_address,
9124 show_ip_bgp_flap_address_cmd,
9125 "show ip bgp flap-statistics A.B.C.D",
9126 SHOW_STR
9127 IP_STR
9128 BGP_STR
9129 "Display flap statistics of routes\n"
9130 "Network in the BGP routing table to display\n")
9131{
9132 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9133 bgp_show_type_flap_address);
9134}
9135
9136DEFUN (show_ip_bgp_flap_prefix,
9137 show_ip_bgp_flap_prefix_cmd,
9138 "show ip bgp flap-statistics A.B.C.D/M",
9139 SHOW_STR
9140 IP_STR
9141 BGP_STR
9142 "Display flap statistics of routes\n"
9143 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9144{
9145 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9146 bgp_show_type_flap_prefix);
9147}
9148#ifdef HAVE_IPV6
9149DEFUN (show_bgp_prefix_longer,
9150 show_bgp_prefix_longer_cmd,
9151 "show bgp X:X::X:X/M longer-prefixes",
9152 SHOW_STR
9153 BGP_STR
9154 "IPv6 prefix <network>/<length>\n"
9155 "Display route and more specific routes\n")
9156{
9157 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9158 bgp_show_type_prefix_longer);
9159}
9160
9161ALIAS (show_bgp_prefix_longer,
9162 show_bgp_ipv6_prefix_longer_cmd,
9163 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9164 SHOW_STR
9165 BGP_STR
9166 "Address family\n"
9167 "IPv6 prefix <network>/<length>\n"
9168 "Display route and more specific routes\n")
9169
9170/* old command */
9171DEFUN (show_ipv6_bgp_prefix_longer,
9172 show_ipv6_bgp_prefix_longer_cmd,
9173 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9174 SHOW_STR
9175 IPV6_STR
9176 BGP_STR
9177 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9178 "Display route and more specific routes\n")
9179{
9180 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9181 bgp_show_type_prefix_longer);
9182}
9183
9184/* old command */
9185DEFUN (show_ipv6_mbgp_prefix_longer,
9186 show_ipv6_mbgp_prefix_longer_cmd,
9187 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9188 SHOW_STR
9189 IPV6_STR
9190 MBGP_STR
9191 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9192 "Display route and more specific routes\n")
9193{
9194 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9195 bgp_show_type_prefix_longer);
9196}
9197#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009198
paul94f2b392005-06-28 12:44:16 +00009199static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009200peer_lookup_in_view (struct vty *vty, const char *view_name,
9201 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009202{
9203 int ret;
9204 struct bgp *bgp;
9205 struct peer *peer;
9206 union sockunion su;
9207
9208 /* BGP structure lookup. */
9209 if (view_name)
9210 {
9211 bgp = bgp_lookup_by_name (view_name);
9212 if (! bgp)
9213 {
9214 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9215 return NULL;
9216 }
9217 }
paul5228ad22004-06-04 17:58:18 +00009218 else
paulbb46e942003-10-24 19:02:03 +00009219 {
9220 bgp = bgp_get_default ();
9221 if (! bgp)
9222 {
9223 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9224 return NULL;
9225 }
9226 }
9227
9228 /* Get peer sockunion. */
9229 ret = str2sockunion (ip_str, &su);
9230 if (ret < 0)
9231 {
9232 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9233 return NULL;
9234 }
9235
9236 /* Peer structure lookup. */
9237 peer = peer_lookup (bgp, &su);
9238 if (! peer)
9239 {
9240 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9241 return NULL;
9242 }
9243
9244 return peer;
9245}
David Lamparter6b0655a2014-06-04 06:53:35 +02009246
Paul Jakma2815e612006-09-14 02:56:07 +00009247enum bgp_stats
9248{
9249 BGP_STATS_MAXBITLEN = 0,
9250 BGP_STATS_RIB,
9251 BGP_STATS_PREFIXES,
9252 BGP_STATS_TOTPLEN,
9253 BGP_STATS_UNAGGREGATEABLE,
9254 BGP_STATS_MAX_AGGREGATEABLE,
9255 BGP_STATS_AGGREGATES,
9256 BGP_STATS_SPACE,
9257 BGP_STATS_ASPATH_COUNT,
9258 BGP_STATS_ASPATH_MAXHOPS,
9259 BGP_STATS_ASPATH_TOTHOPS,
9260 BGP_STATS_ASPATH_MAXSIZE,
9261 BGP_STATS_ASPATH_TOTSIZE,
9262 BGP_STATS_ASN_HIGHEST,
9263 BGP_STATS_MAX,
9264};
paulbb46e942003-10-24 19:02:03 +00009265
Paul Jakma2815e612006-09-14 02:56:07 +00009266static const char *table_stats_strs[] =
9267{
9268 [BGP_STATS_PREFIXES] = "Total Prefixes",
9269 [BGP_STATS_TOTPLEN] = "Average prefix length",
9270 [BGP_STATS_RIB] = "Total Advertisements",
9271 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9272 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9273 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9274 [BGP_STATS_SPACE] = "Address space advertised",
9275 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9276 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9277 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9278 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9279 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9280 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9281 [BGP_STATS_MAX] = NULL,
9282};
9283
9284struct bgp_table_stats
9285{
9286 struct bgp_table *table;
9287 unsigned long long counts[BGP_STATS_MAX];
9288};
9289
9290#if 0
9291#define TALLY_SIGFIG 100000
9292static unsigned long
9293ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9294{
9295 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9296 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9297 unsigned long ret = newtot / count;
9298
9299 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9300 return ret + 1;
9301 else
9302 return ret;
9303}
9304#endif
9305
9306static int
9307bgp_table_stats_walker (struct thread *t)
9308{
9309 struct bgp_node *rn;
9310 struct bgp_node *top;
9311 struct bgp_table_stats *ts = THREAD_ARG (t);
9312 unsigned int space = 0;
9313
Paul Jakma53d9f672006-10-15 23:41:16 +00009314 if (!(top = bgp_table_top (ts->table)))
9315 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009316
9317 switch (top->p.family)
9318 {
9319 case AF_INET:
9320 space = IPV4_MAX_BITLEN;
9321 break;
9322 case AF_INET6:
9323 space = IPV6_MAX_BITLEN;
9324 break;
9325 }
9326
9327 ts->counts[BGP_STATS_MAXBITLEN] = space;
9328
9329 for (rn = top; rn; rn = bgp_route_next (rn))
9330 {
9331 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009332 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009333 unsigned int rinum = 0;
9334
9335 if (rn == top)
9336 continue;
9337
9338 if (!rn->info)
9339 continue;
9340
9341 ts->counts[BGP_STATS_PREFIXES]++;
9342 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9343
9344#if 0
9345 ts->counts[BGP_STATS_AVGPLEN]
9346 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9347 ts->counts[BGP_STATS_AVGPLEN],
9348 rn->p.prefixlen);
9349#endif
9350
9351 /* check if the prefix is included by any other announcements */
9352 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009353 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009354
9355 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009356 {
9357 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9358 /* announced address space */
9359 if (space)
9360 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9361 }
Paul Jakma2815e612006-09-14 02:56:07 +00009362 else if (prn->info)
9363 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9364
Paul Jakma2815e612006-09-14 02:56:07 +00009365 for (ri = rn->info; ri; ri = ri->next)
9366 {
9367 rinum++;
9368 ts->counts[BGP_STATS_RIB]++;
9369
9370 if (ri->attr &&
9371 (CHECK_FLAG (ri->attr->flag,
9372 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9373 ts->counts[BGP_STATS_AGGREGATES]++;
9374
9375 /* as-path stats */
9376 if (ri->attr && ri->attr->aspath)
9377 {
9378 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9379 unsigned int size = aspath_size (ri->attr->aspath);
9380 as_t highest = aspath_highest (ri->attr->aspath);
9381
9382 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9383
9384 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9385 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9386
9387 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9388 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9389
9390 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9391 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9392#if 0
9393 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9394 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9395 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9396 hops);
9397 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9398 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9399 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9400 size);
9401#endif
9402 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9403 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9404 }
9405 }
9406 }
9407 return 0;
9408}
9409
9410static int
9411bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9412{
9413 struct bgp_table_stats ts;
9414 unsigned int i;
9415
9416 if (!bgp->rib[afi][safi])
9417 {
9418 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9419 return CMD_WARNING;
9420 }
9421
9422 memset (&ts, 0, sizeof (ts));
9423 ts.table = bgp->rib[afi][safi];
9424 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9425
9426 vty_out (vty, "BGP %s RIB statistics%s%s",
9427 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9428
9429 for (i = 0; i < BGP_STATS_MAX; i++)
9430 {
9431 if (!table_stats_strs[i])
9432 continue;
9433
9434 switch (i)
9435 {
9436#if 0
9437 case BGP_STATS_ASPATH_AVGHOPS:
9438 case BGP_STATS_ASPATH_AVGSIZE:
9439 case BGP_STATS_AVGPLEN:
9440 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9441 vty_out (vty, "%12.2f",
9442 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9443 break;
9444#endif
9445 case BGP_STATS_ASPATH_TOTHOPS:
9446 case BGP_STATS_ASPATH_TOTSIZE:
9447 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9448 vty_out (vty, "%12.2f",
9449 ts.counts[i] ?
9450 (float)ts.counts[i] /
9451 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9452 : 0);
9453 break;
9454 case BGP_STATS_TOTPLEN:
9455 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9456 vty_out (vty, "%12.2f",
9457 ts.counts[i] ?
9458 (float)ts.counts[i] /
9459 (float)ts.counts[BGP_STATS_PREFIXES]
9460 : 0);
9461 break;
9462 case BGP_STATS_SPACE:
9463 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9464 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9465 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9466 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009467 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009468 vty_out (vty, "%12.2f%s",
9469 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009470 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009471 VTY_NEWLINE);
9472 vty_out (vty, "%30s: ", "/8 equivalent ");
9473 vty_out (vty, "%12.2f%s",
9474 (float)ts.counts[BGP_STATS_SPACE] /
9475 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9476 VTY_NEWLINE);
9477 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9478 break;
9479 vty_out (vty, "%30s: ", "/24 equivalent ");
9480 vty_out (vty, "%12.2f",
9481 (float)ts.counts[BGP_STATS_SPACE] /
9482 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9483 break;
9484 default:
9485 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9486 vty_out (vty, "%12llu", ts.counts[i]);
9487 }
9488
9489 vty_out (vty, "%s", VTY_NEWLINE);
9490 }
9491 return CMD_SUCCESS;
9492}
9493
9494static int
9495bgp_table_stats_vty (struct vty *vty, const char *name,
9496 const char *afi_str, const char *safi_str)
9497{
9498 struct bgp *bgp;
9499 afi_t afi;
9500 safi_t safi;
9501
9502 if (name)
9503 bgp = bgp_lookup_by_name (name);
9504 else
9505 bgp = bgp_get_default ();
9506
9507 if (!bgp)
9508 {
9509 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9510 return CMD_WARNING;
9511 }
9512 if (strncmp (afi_str, "ipv", 3) == 0)
9513 {
9514 if (strncmp (afi_str, "ipv4", 4) == 0)
9515 afi = AFI_IP;
9516 else if (strncmp (afi_str, "ipv6", 4) == 0)
9517 afi = AFI_IP6;
9518 else
9519 {
9520 vty_out (vty, "%% Invalid address family %s%s",
9521 afi_str, VTY_NEWLINE);
9522 return CMD_WARNING;
9523 }
9524 if (strncmp (safi_str, "m", 1) == 0)
9525 safi = SAFI_MULTICAST;
9526 else if (strncmp (safi_str, "u", 1) == 0)
9527 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009528 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9529 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009530 else
9531 {
9532 vty_out (vty, "%% Invalid subsequent address family %s%s",
9533 safi_str, VTY_NEWLINE);
9534 return CMD_WARNING;
9535 }
9536 }
9537 else
9538 {
9539 vty_out (vty, "%% Invalid address family %s%s",
9540 afi_str, VTY_NEWLINE);
9541 return CMD_WARNING;
9542 }
9543
Paul Jakma2815e612006-09-14 02:56:07 +00009544 return bgp_table_stats (vty, bgp, afi, safi);
9545}
9546
9547DEFUN (show_bgp_statistics,
9548 show_bgp_statistics_cmd,
9549 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9550 SHOW_STR
9551 BGP_STR
9552 "Address family\n"
9553 "Address family\n"
9554 "Address Family modifier\n"
9555 "Address Family modifier\n"
9556 "BGP RIB advertisement statistics\n")
9557{
9558 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9559}
9560
9561ALIAS (show_bgp_statistics,
9562 show_bgp_statistics_vpnv4_cmd,
9563 "show bgp (ipv4) (vpnv4) statistics",
9564 SHOW_STR
9565 BGP_STR
9566 "Address family\n"
9567 "Address Family modifier\n"
9568 "BGP RIB advertisement statistics\n")
9569
9570DEFUN (show_bgp_statistics_view,
9571 show_bgp_statistics_view_cmd,
9572 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9573 SHOW_STR
9574 BGP_STR
9575 "BGP view\n"
9576 "Address family\n"
9577 "Address family\n"
9578 "Address Family modifier\n"
9579 "Address Family modifier\n"
9580 "BGP RIB advertisement statistics\n")
9581{
9582 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9583}
9584
9585ALIAS (show_bgp_statistics_view,
9586 show_bgp_statistics_view_vpnv4_cmd,
9587 "show bgp view WORD (ipv4) (vpnv4) statistics",
9588 SHOW_STR
9589 BGP_STR
9590 "BGP view\n"
9591 "Address family\n"
9592 "Address Family modifier\n"
9593 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009594
Paul Jakmaff7924f2006-09-04 01:10:36 +00009595enum bgp_pcounts
9596{
9597 PCOUNT_ADJ_IN = 0,
9598 PCOUNT_DAMPED,
9599 PCOUNT_REMOVED,
9600 PCOUNT_HISTORY,
9601 PCOUNT_STALE,
9602 PCOUNT_VALID,
9603 PCOUNT_ALL,
9604 PCOUNT_COUNTED,
9605 PCOUNT_PFCNT, /* the figure we display to users */
9606 PCOUNT_MAX,
9607};
9608
9609static const char *pcount_strs[] =
9610{
9611 [PCOUNT_ADJ_IN] = "Adj-in",
9612 [PCOUNT_DAMPED] = "Damped",
9613 [PCOUNT_REMOVED] = "Removed",
9614 [PCOUNT_HISTORY] = "History",
9615 [PCOUNT_STALE] = "Stale",
9616 [PCOUNT_VALID] = "Valid",
9617 [PCOUNT_ALL] = "All RIB",
9618 [PCOUNT_COUNTED] = "PfxCt counted",
9619 [PCOUNT_PFCNT] = "Useable",
9620 [PCOUNT_MAX] = NULL,
9621};
9622
Paul Jakma2815e612006-09-14 02:56:07 +00009623struct peer_pcounts
9624{
9625 unsigned int count[PCOUNT_MAX];
9626 const struct peer *peer;
9627 const struct bgp_table *table;
9628};
9629
Paul Jakmaff7924f2006-09-04 01:10:36 +00009630static int
Paul Jakma2815e612006-09-14 02:56:07 +00009631bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009632{
9633 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009634 struct peer_pcounts *pc = THREAD_ARG (t);
9635 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009636
Paul Jakma2815e612006-09-14 02:56:07 +00009637 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009638 {
9639 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009640 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009641
9642 for (ain = rn->adj_in; ain; ain = ain->next)
9643 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009644 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009645
Paul Jakmaff7924f2006-09-04 01:10:36 +00009646 for (ri = rn->info; ri; ri = ri->next)
9647 {
9648 char buf[SU_ADDRSTRLEN];
9649
9650 if (ri->peer != peer)
9651 continue;
9652
Paul Jakma2815e612006-09-14 02:56:07 +00009653 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009654
9655 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009656 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009657 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009658 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009659 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009660 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009661 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009662 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009663 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009664 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009665 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009666 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009667
9668 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9669 {
Paul Jakma2815e612006-09-14 02:56:07 +00009670 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009671 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009672 plog_warn (peer->log,
9673 "%s [pcount] %s/%d is counted but flags 0x%x",
9674 peer->host,
9675 inet_ntop(rn->p.family, &rn->p.u.prefix,
9676 buf, SU_ADDRSTRLEN),
9677 rn->p.prefixlen,
9678 ri->flags);
9679 }
9680 else
9681 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009682 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009683 plog_warn (peer->log,
9684 "%s [pcount] %s/%d not counted but flags 0x%x",
9685 peer->host,
9686 inet_ntop(rn->p.family, &rn->p.u.prefix,
9687 buf, SU_ADDRSTRLEN),
9688 rn->p.prefixlen,
9689 ri->flags);
9690 }
9691 }
9692 }
Paul Jakma2815e612006-09-14 02:56:07 +00009693 return 0;
9694}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009695
Paul Jakma2815e612006-09-14 02:56:07 +00009696static int
9697bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9698{
9699 struct peer_pcounts pcounts = { .peer = peer };
9700 unsigned int i;
9701
9702 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9703 || !peer->bgp->rib[afi][safi])
9704 {
9705 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9706 return CMD_WARNING;
9707 }
9708
9709 memset (&pcounts, 0, sizeof(pcounts));
9710 pcounts.peer = peer;
9711 pcounts.table = peer->bgp->rib[afi][safi];
9712
9713 /* in-place call via thread subsystem so as to record execution time
9714 * stats for the thread-walk (i.e. ensure this can't be blamed on
9715 * on just vty_read()).
9716 */
9717 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9718
Paul Jakmaff7924f2006-09-04 01:10:36 +00009719 vty_out (vty, "Prefix counts for %s, %s%s",
9720 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9721 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9722 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9723 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9724
9725 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009726 vty_out (vty, "%20s: %-10d%s",
9727 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009728
Paul Jakma2815e612006-09-14 02:56:07 +00009729 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009730 {
9731 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9732 peer->host, VTY_NEWLINE);
9733 vty_out (vty, "Please report this bug, with the above command output%s",
9734 VTY_NEWLINE);
9735 }
9736
9737 return CMD_SUCCESS;
9738}
9739
9740DEFUN (show_ip_bgp_neighbor_prefix_counts,
9741 show_ip_bgp_neighbor_prefix_counts_cmd,
9742 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9743 SHOW_STR
9744 IP_STR
9745 BGP_STR
9746 "Detailed information on TCP and BGP neighbor connections\n"
9747 "Neighbor to display information about\n"
9748 "Neighbor to display information about\n"
9749 "Display detailed prefix count information\n")
9750{
9751 struct peer *peer;
9752
9753 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9754 if (! peer)
9755 return CMD_WARNING;
9756
9757 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9758}
9759
9760DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9761 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9762 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9763 SHOW_STR
9764 BGP_STR
9765 "Address family\n"
9766 "Detailed information on TCP and BGP neighbor connections\n"
9767 "Neighbor to display information about\n"
9768 "Neighbor to display information about\n"
9769 "Display detailed prefix count information\n")
9770{
9771 struct peer *peer;
9772
9773 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9774 if (! peer)
9775 return CMD_WARNING;
9776
9777 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9778}
9779
9780DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9781 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9782 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9783 SHOW_STR
9784 IP_STR
9785 BGP_STR
9786 "Address family\n"
9787 "Address Family modifier\n"
9788 "Address Family modifier\n"
9789 "Detailed information on TCP and BGP neighbor connections\n"
9790 "Neighbor to display information about\n"
9791 "Neighbor to display information about\n"
9792 "Display detailed prefix count information\n")
9793{
9794 struct peer *peer;
9795
9796 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9797 if (! peer)
9798 return CMD_WARNING;
9799
9800 if (strncmp (argv[0], "m", 1) == 0)
9801 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9802
9803 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9804}
9805
9806DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9807 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9808 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9809 SHOW_STR
9810 IP_STR
9811 BGP_STR
9812 "Address family\n"
9813 "Address Family modifier\n"
9814 "Address Family modifier\n"
9815 "Detailed information on TCP and BGP neighbor connections\n"
9816 "Neighbor to display information about\n"
9817 "Neighbor to display information about\n"
9818 "Display detailed prefix count information\n")
9819{
9820 struct peer *peer;
9821
9822 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9823 if (! peer)
9824 return CMD_WARNING;
9825
9826 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9827}
9828
9829
paul94f2b392005-06-28 12:44:16 +00009830static void
paul718e3742002-12-13 20:15:29 +00009831show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9832 int in)
9833{
9834 struct bgp_table *table;
9835 struct bgp_adj_in *ain;
9836 struct bgp_adj_out *adj;
9837 unsigned long output_count;
9838 struct bgp_node *rn;
9839 int header1 = 1;
9840 struct bgp *bgp;
9841 int header2 = 1;
9842
paulbb46e942003-10-24 19:02:03 +00009843 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009844
9845 if (! bgp)
9846 return;
9847
9848 table = bgp->rib[afi][safi];
9849
9850 output_count = 0;
9851
9852 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9853 PEER_STATUS_DEFAULT_ORIGINATE))
9854 {
9855 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 +00009856 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9857 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009858
9859 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9860 VTY_NEWLINE, VTY_NEWLINE);
9861 header1 = 0;
9862 }
9863
9864 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9865 if (in)
9866 {
9867 for (ain = rn->adj_in; ain; ain = ain->next)
9868 if (ain->peer == peer)
9869 {
9870 if (header1)
9871 {
9872 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 +00009873 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9874 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009875 header1 = 0;
9876 }
9877 if (header2)
9878 {
9879 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9880 header2 = 0;
9881 }
9882 if (ain->attr)
9883 {
9884 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9885 output_count++;
9886 }
9887 }
9888 }
9889 else
9890 {
9891 for (adj = rn->adj_out; adj; adj = adj->next)
9892 if (adj->peer == peer)
9893 {
9894 if (header1)
9895 {
9896 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 +00009897 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9898 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009899 header1 = 0;
9900 }
9901 if (header2)
9902 {
9903 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9904 header2 = 0;
9905 }
9906 if (adj->attr)
9907 {
9908 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9909 output_count++;
9910 }
9911 }
9912 }
9913
9914 if (output_count != 0)
9915 vty_out (vty, "%sTotal number of prefixes %ld%s",
9916 VTY_NEWLINE, output_count, VTY_NEWLINE);
9917}
9918
paul94f2b392005-06-28 12:44:16 +00009919static int
paulbb46e942003-10-24 19:02:03 +00009920peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9921{
paul718e3742002-12-13 20:15:29 +00009922 if (! peer || ! peer->afc[afi][safi])
9923 {
9924 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9925 return CMD_WARNING;
9926 }
9927
9928 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9929 {
9930 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9931 VTY_NEWLINE);
9932 return CMD_WARNING;
9933 }
9934
9935 show_adj_route (vty, peer, afi, safi, in);
9936
9937 return CMD_SUCCESS;
9938}
9939
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009940DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9941 show_ip_bgp_view_neighbor_advertised_route_cmd,
9942 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9943 SHOW_STR
9944 IP_STR
9945 BGP_STR
9946 "BGP view\n"
9947 "View name\n"
9948 "Detailed information on TCP and BGP neighbor connections\n"
9949 "Neighbor to display information about\n"
9950 "Neighbor to display information about\n"
9951 "Display the routes advertised to a BGP neighbor\n")
9952{
9953 struct peer *peer;
9954
9955 if (argc == 2)
9956 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9957 else
9958 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9959
9960 if (! peer)
9961 return CMD_WARNING;
9962
9963 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9964}
9965
9966ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009967 show_ip_bgp_neighbor_advertised_route_cmd,
9968 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9969 SHOW_STR
9970 IP_STR
9971 BGP_STR
9972 "Detailed information on TCP and BGP neighbor connections\n"
9973 "Neighbor to display information about\n"
9974 "Neighbor to display information about\n"
9975 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009976
9977DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9978 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9979 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9980 SHOW_STR
9981 IP_STR
9982 BGP_STR
9983 "Address family\n"
9984 "Address Family modifier\n"
9985 "Address Family modifier\n"
9986 "Detailed information on TCP and BGP neighbor connections\n"
9987 "Neighbor to display information about\n"
9988 "Neighbor to display information about\n"
9989 "Display the routes advertised to a BGP neighbor\n")
9990{
paulbb46e942003-10-24 19:02:03 +00009991 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009992
paulbb46e942003-10-24 19:02:03 +00009993 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9994 if (! peer)
9995 return CMD_WARNING;
9996
9997 if (strncmp (argv[0], "m", 1) == 0)
9998 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9999
10000 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010001}
10002
10003#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010004DEFUN (show_bgp_view_neighbor_advertised_route,
10005 show_bgp_view_neighbor_advertised_route_cmd,
10006 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10007 SHOW_STR
10008 BGP_STR
10009 "BGP view\n"
10010 "View name\n"
10011 "Detailed information on TCP and BGP neighbor connections\n"
10012 "Neighbor to display information about\n"
10013 "Neighbor to display information about\n"
10014 "Display the routes advertised to a BGP neighbor\n")
10015{
10016 struct peer *peer;
10017
10018 if (argc == 2)
10019 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10020 else
10021 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10022
10023 if (! peer)
10024 return CMD_WARNING;
10025
10026 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10027}
10028
10029ALIAS (show_bgp_view_neighbor_advertised_route,
10030 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10031 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10032 SHOW_STR
10033 BGP_STR
10034 "BGP view\n"
10035 "View name\n"
10036 "Address family\n"
10037 "Detailed information on TCP and BGP neighbor connections\n"
10038 "Neighbor to display information about\n"
10039 "Neighbor to display information about\n"
10040 "Display the routes advertised to a BGP neighbor\n")
10041
10042DEFUN (show_bgp_view_neighbor_received_routes,
10043 show_bgp_view_neighbor_received_routes_cmd,
10044 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10045 SHOW_STR
10046 BGP_STR
10047 "BGP view\n"
10048 "View name\n"
10049 "Detailed information on TCP and BGP neighbor connections\n"
10050 "Neighbor to display information about\n"
10051 "Neighbor to display information about\n"
10052 "Display the received routes from neighbor\n")
10053{
10054 struct peer *peer;
10055
10056 if (argc == 2)
10057 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10058 else
10059 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10060
10061 if (! peer)
10062 return CMD_WARNING;
10063
10064 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10065}
10066
10067ALIAS (show_bgp_view_neighbor_received_routes,
10068 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10069 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10070 SHOW_STR
10071 BGP_STR
10072 "BGP view\n"
10073 "View name\n"
10074 "Address family\n"
10075 "Detailed information on TCP and BGP neighbor connections\n"
10076 "Neighbor to display information about\n"
10077 "Neighbor to display information about\n"
10078 "Display the received routes from neighbor\n")
10079
10080ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010081 show_bgp_neighbor_advertised_route_cmd,
10082 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10083 SHOW_STR
10084 BGP_STR
10085 "Detailed information on TCP and BGP neighbor connections\n"
10086 "Neighbor to display information about\n"
10087 "Neighbor to display information about\n"
10088 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010089
10090ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010091 show_bgp_ipv6_neighbor_advertised_route_cmd,
10092 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10093 SHOW_STR
10094 BGP_STR
10095 "Address family\n"
10096 "Detailed information on TCP and BGP neighbor connections\n"
10097 "Neighbor to display information about\n"
10098 "Neighbor to display information about\n"
10099 "Display the routes advertised to a BGP neighbor\n")
10100
10101/* old command */
paulbb46e942003-10-24 19:02:03 +000010102ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010103 ipv6_bgp_neighbor_advertised_route_cmd,
10104 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10105 SHOW_STR
10106 IPV6_STR
10107 BGP_STR
10108 "Detailed information on TCP and BGP neighbor connections\n"
10109 "Neighbor to display information about\n"
10110 "Neighbor to display information about\n"
10111 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010112
paul718e3742002-12-13 20:15:29 +000010113/* old command */
10114DEFUN (ipv6_mbgp_neighbor_advertised_route,
10115 ipv6_mbgp_neighbor_advertised_route_cmd,
10116 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10117 SHOW_STR
10118 IPV6_STR
10119 MBGP_STR
10120 "Detailed information on TCP and BGP neighbor connections\n"
10121 "Neighbor to display information about\n"
10122 "Neighbor to display information about\n"
10123 "Display the routes advertised to a BGP neighbor\n")
10124{
paulbb46e942003-10-24 19:02:03 +000010125 struct peer *peer;
10126
10127 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10128 if (! peer)
10129 return CMD_WARNING;
10130
10131 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010132}
10133#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010134
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010135DEFUN (show_ip_bgp_view_neighbor_received_routes,
10136 show_ip_bgp_view_neighbor_received_routes_cmd,
10137 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10138 SHOW_STR
10139 IP_STR
10140 BGP_STR
10141 "BGP view\n"
10142 "View name\n"
10143 "Detailed information on TCP and BGP neighbor connections\n"
10144 "Neighbor to display information about\n"
10145 "Neighbor to display information about\n"
10146 "Display the received routes from neighbor\n")
10147{
10148 struct peer *peer;
10149
10150 if (argc == 2)
10151 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10152 else
10153 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10154
10155 if (! peer)
10156 return CMD_WARNING;
10157
10158 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10159}
10160
10161ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010162 show_ip_bgp_neighbor_received_routes_cmd,
10163 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10164 SHOW_STR
10165 IP_STR
10166 BGP_STR
10167 "Detailed information on TCP and BGP neighbor connections\n"
10168 "Neighbor to display information about\n"
10169 "Neighbor to display information about\n"
10170 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010171
10172DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10173 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10174 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10175 SHOW_STR
10176 IP_STR
10177 BGP_STR
10178 "Address family\n"
10179 "Address Family modifier\n"
10180 "Address Family modifier\n"
10181 "Detailed information on TCP and BGP neighbor connections\n"
10182 "Neighbor to display information about\n"
10183 "Neighbor to display information about\n"
10184 "Display the received routes from neighbor\n")
10185{
paulbb46e942003-10-24 19:02:03 +000010186 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010187
paulbb46e942003-10-24 19:02:03 +000010188 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10189 if (! peer)
10190 return CMD_WARNING;
10191
10192 if (strncmp (argv[0], "m", 1) == 0)
10193 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10194
10195 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010196}
10197
Michael Lambert95cbbd22010-07-23 14:43:04 -040010198DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10199 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010200 "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 -040010201 SHOW_STR
10202 BGP_STR
10203 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010204 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010205 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010206 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010207 "Address family modifier\n"
10208 "Address family modifier\n"
10209 "Detailed information on TCP and BGP neighbor connections\n"
10210 "Neighbor to display information about\n"
10211 "Neighbor to display information about\n"
10212 "Display the advertised routes to neighbor\n"
10213 "Display the received routes from neighbor\n")
10214{
10215 int afi;
10216 int safi;
10217 int in;
10218 struct peer *peer;
10219
David Lamparter94bad672015-03-03 08:52:22 +010010220 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010221
10222 if (! peer)
10223 return CMD_WARNING;
10224
Michael Lambert95cbbd22010-07-23 14:43:04 -040010225 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10226 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10227 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010228
10229 return peer_adj_routes (vty, peer, afi, safi, in);
10230}
10231
paul718e3742002-12-13 20:15:29 +000010232DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10233 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10234 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10235 SHOW_STR
10236 IP_STR
10237 BGP_STR
10238 "Detailed information on TCP and BGP neighbor connections\n"
10239 "Neighbor to display information about\n"
10240 "Neighbor to display information about\n"
10241 "Display information received from a BGP neighbor\n"
10242 "Display the prefixlist filter\n")
10243{
10244 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010245 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010246 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010247 int count, ret;
paul718e3742002-12-13 20:15:29 +000010248
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010249 ret = str2sockunion (argv[0], &su);
10250 if (ret < 0)
10251 {
10252 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10253 return CMD_WARNING;
10254 }
paul718e3742002-12-13 20:15:29 +000010255
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010256 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010257 if (! peer)
10258 return CMD_WARNING;
10259
10260 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10261 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10262 if (count)
10263 {
10264 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10265 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10266 }
10267
10268 return CMD_SUCCESS;
10269}
10270
10271DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10272 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10273 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10274 SHOW_STR
10275 IP_STR
10276 BGP_STR
10277 "Address family\n"
10278 "Address Family modifier\n"
10279 "Address Family modifier\n"
10280 "Detailed information on TCP and BGP neighbor connections\n"
10281 "Neighbor to display information about\n"
10282 "Neighbor to display information about\n"
10283 "Display information received from a BGP neighbor\n"
10284 "Display the prefixlist filter\n")
10285{
10286 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010287 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010288 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010289 int count, ret;
paul718e3742002-12-13 20:15:29 +000010290
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010291 ret = str2sockunion (argv[1], &su);
10292 if (ret < 0)
10293 {
10294 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10295 return CMD_WARNING;
10296 }
paul718e3742002-12-13 20:15:29 +000010297
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010298 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010299 if (! peer)
10300 return CMD_WARNING;
10301
10302 if (strncmp (argv[0], "m", 1) == 0)
10303 {
10304 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10305 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10306 if (count)
10307 {
10308 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10309 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10310 }
10311 }
10312 else
10313 {
10314 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10315 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10316 if (count)
10317 {
10318 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10319 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10320 }
10321 }
10322
10323 return CMD_SUCCESS;
10324}
10325
10326
10327#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010328ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010329 show_bgp_neighbor_received_routes_cmd,
10330 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10331 SHOW_STR
10332 BGP_STR
10333 "Detailed information on TCP and BGP neighbor connections\n"
10334 "Neighbor to display information about\n"
10335 "Neighbor to display information about\n"
10336 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010337
paulbb46e942003-10-24 19:02:03 +000010338ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010339 show_bgp_ipv6_neighbor_received_routes_cmd,
10340 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10341 SHOW_STR
10342 BGP_STR
10343 "Address family\n"
10344 "Detailed information on TCP and BGP neighbor connections\n"
10345 "Neighbor to display information about\n"
10346 "Neighbor to display information about\n"
10347 "Display the received routes from neighbor\n")
10348
10349DEFUN (show_bgp_neighbor_received_prefix_filter,
10350 show_bgp_neighbor_received_prefix_filter_cmd,
10351 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10352 SHOW_STR
10353 BGP_STR
10354 "Detailed information on TCP and BGP neighbor connections\n"
10355 "Neighbor to display information about\n"
10356 "Neighbor to display information about\n"
10357 "Display information received from a BGP neighbor\n"
10358 "Display the prefixlist filter\n")
10359{
10360 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010361 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010362 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010363 int count, ret;
paul718e3742002-12-13 20:15:29 +000010364
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010365 ret = str2sockunion (argv[0], &su);
10366 if (ret < 0)
10367 {
10368 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10369 return CMD_WARNING;
10370 }
paul718e3742002-12-13 20:15:29 +000010371
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010372 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010373 if (! peer)
10374 return CMD_WARNING;
10375
10376 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10377 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10378 if (count)
10379 {
10380 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10381 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10382 }
10383
10384 return CMD_SUCCESS;
10385}
10386
10387ALIAS (show_bgp_neighbor_received_prefix_filter,
10388 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10389 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10390 SHOW_STR
10391 BGP_STR
10392 "Address family\n"
10393 "Detailed information on TCP and BGP neighbor connections\n"
10394 "Neighbor to display information about\n"
10395 "Neighbor to display information about\n"
10396 "Display information received from a BGP neighbor\n"
10397 "Display the prefixlist filter\n")
10398
10399/* old command */
paulbb46e942003-10-24 19:02:03 +000010400ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010401 ipv6_bgp_neighbor_received_routes_cmd,
10402 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10403 SHOW_STR
10404 IPV6_STR
10405 BGP_STR
10406 "Detailed information on TCP and BGP neighbor connections\n"
10407 "Neighbor to display information about\n"
10408 "Neighbor to display information about\n"
10409 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010410
10411/* old command */
10412DEFUN (ipv6_mbgp_neighbor_received_routes,
10413 ipv6_mbgp_neighbor_received_routes_cmd,
10414 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10415 SHOW_STR
10416 IPV6_STR
10417 MBGP_STR
10418 "Detailed information on TCP and BGP neighbor connections\n"
10419 "Neighbor to display information about\n"
10420 "Neighbor to display information about\n"
10421 "Display the received routes from neighbor\n")
10422{
paulbb46e942003-10-24 19:02:03 +000010423 struct peer *peer;
10424
10425 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10426 if (! peer)
10427 return CMD_WARNING;
10428
10429 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010430}
paulbb46e942003-10-24 19:02:03 +000010431
10432DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10433 show_bgp_view_neighbor_received_prefix_filter_cmd,
10434 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10435 SHOW_STR
10436 BGP_STR
10437 "BGP view\n"
10438 "View name\n"
10439 "Detailed information on TCP and BGP neighbor connections\n"
10440 "Neighbor to display information about\n"
10441 "Neighbor to display information about\n"
10442 "Display information received from a BGP neighbor\n"
10443 "Display the prefixlist filter\n")
10444{
10445 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010446 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010447 struct peer *peer;
10448 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010449 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010450
10451 /* BGP structure lookup. */
10452 bgp = bgp_lookup_by_name (argv[0]);
10453 if (bgp == NULL)
10454 {
10455 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10456 return CMD_WARNING;
10457 }
10458
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010459 ret = str2sockunion (argv[1], &su);
10460 if (ret < 0)
10461 {
10462 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10463 return CMD_WARNING;
10464 }
paulbb46e942003-10-24 19:02:03 +000010465
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010466 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010467 if (! peer)
10468 return CMD_WARNING;
10469
10470 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10471 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10472 if (count)
10473 {
10474 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10475 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10476 }
10477
10478 return CMD_SUCCESS;
10479}
10480
10481ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10482 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10483 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10484 SHOW_STR
10485 BGP_STR
10486 "BGP view\n"
10487 "View name\n"
10488 "Address family\n"
10489 "Detailed information on TCP and BGP neighbor connections\n"
10490 "Neighbor to display information about\n"
10491 "Neighbor to display information about\n"
10492 "Display information received from a BGP neighbor\n"
10493 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010494#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010495
paul94f2b392005-06-28 12:44:16 +000010496static int
paulbb46e942003-10-24 19:02:03 +000010497bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010498 safi_t safi, enum bgp_show_type type)
10499{
paul718e3742002-12-13 20:15:29 +000010500 if (! peer || ! peer->afc[afi][safi])
10501 {
10502 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010503 return CMD_WARNING;
10504 }
10505
ajs5a646652004-11-05 01:25:55 +000010506 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010507}
10508
10509DEFUN (show_ip_bgp_neighbor_routes,
10510 show_ip_bgp_neighbor_routes_cmd,
10511 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10512 SHOW_STR
10513 IP_STR
10514 BGP_STR
10515 "Detailed information on TCP and BGP neighbor connections\n"
10516 "Neighbor to display information about\n"
10517 "Neighbor to display information about\n"
10518 "Display routes learned from neighbor\n")
10519{
paulbb46e942003-10-24 19:02:03 +000010520 struct peer *peer;
10521
10522 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10523 if (! peer)
10524 return CMD_WARNING;
10525
10526 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010527 bgp_show_type_neighbor);
10528}
10529
10530DEFUN (show_ip_bgp_neighbor_flap,
10531 show_ip_bgp_neighbor_flap_cmd,
10532 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10533 SHOW_STR
10534 IP_STR
10535 BGP_STR
10536 "Detailed information on TCP and BGP neighbor connections\n"
10537 "Neighbor to display information about\n"
10538 "Neighbor to display information about\n"
10539 "Display flap statistics of the routes learned from neighbor\n")
10540{
paulbb46e942003-10-24 19:02:03 +000010541 struct peer *peer;
10542
10543 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10544 if (! peer)
10545 return CMD_WARNING;
10546
10547 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010548 bgp_show_type_flap_neighbor);
10549}
10550
10551DEFUN (show_ip_bgp_neighbor_damp,
10552 show_ip_bgp_neighbor_damp_cmd,
10553 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10554 SHOW_STR
10555 IP_STR
10556 BGP_STR
10557 "Detailed information on TCP and BGP neighbor connections\n"
10558 "Neighbor to display information about\n"
10559 "Neighbor to display information about\n"
10560 "Display the dampened routes received from neighbor\n")
10561{
paulbb46e942003-10-24 19:02:03 +000010562 struct peer *peer;
10563
10564 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10565 if (! peer)
10566 return CMD_WARNING;
10567
10568 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010569 bgp_show_type_damp_neighbor);
10570}
10571
10572DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10573 show_ip_bgp_ipv4_neighbor_routes_cmd,
10574 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10575 SHOW_STR
10576 IP_STR
10577 BGP_STR
10578 "Address family\n"
10579 "Address Family modifier\n"
10580 "Address Family modifier\n"
10581 "Detailed information on TCP and BGP neighbor connections\n"
10582 "Neighbor to display information about\n"
10583 "Neighbor to display information about\n"
10584 "Display routes learned from neighbor\n")
10585{
paulbb46e942003-10-24 19:02:03 +000010586 struct peer *peer;
10587
10588 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10589 if (! peer)
10590 return CMD_WARNING;
10591
paul718e3742002-12-13 20:15:29 +000010592 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010593 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010594 bgp_show_type_neighbor);
10595
paulbb46e942003-10-24 19:02:03 +000010596 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010597 bgp_show_type_neighbor);
10598}
paulbb46e942003-10-24 19:02:03 +000010599
paulfee0f4c2004-09-13 05:12:46 +000010600DEFUN (show_ip_bgp_view_rsclient,
10601 show_ip_bgp_view_rsclient_cmd,
10602 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10603 SHOW_STR
10604 IP_STR
10605 BGP_STR
10606 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010607 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010608 "Information about Route Server Client\n"
10609 NEIGHBOR_ADDR_STR)
10610{
10611 struct bgp_table *table;
10612 struct peer *peer;
10613
10614 if (argc == 2)
10615 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10616 else
10617 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10618
10619 if (! peer)
10620 return CMD_WARNING;
10621
10622 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10623 {
10624 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10625 VTY_NEWLINE);
10626 return CMD_WARNING;
10627 }
10628
10629 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10630 PEER_FLAG_RSERVER_CLIENT))
10631 {
10632 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10633 VTY_NEWLINE);
10634 return CMD_WARNING;
10635 }
10636
10637 table = peer->rib[AFI_IP][SAFI_UNICAST];
10638
ajs5a646652004-11-05 01:25:55 +000010639 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010640}
10641
10642ALIAS (show_ip_bgp_view_rsclient,
10643 show_ip_bgp_rsclient_cmd,
10644 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10645 SHOW_STR
10646 IP_STR
10647 BGP_STR
10648 "Information about Route Server Client\n"
10649 NEIGHBOR_ADDR_STR)
10650
Michael Lambert95cbbd22010-07-23 14:43:04 -040010651DEFUN (show_bgp_view_ipv4_safi_rsclient,
10652 show_bgp_view_ipv4_safi_rsclient_cmd,
10653 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10654 SHOW_STR
10655 BGP_STR
10656 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010657 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010658 "Address family\n"
10659 "Address Family modifier\n"
10660 "Address Family modifier\n"
10661 "Information about Route Server Client\n"
10662 NEIGHBOR_ADDR_STR)
10663{
10664 struct bgp_table *table;
10665 struct peer *peer;
10666 safi_t safi;
10667
10668 if (argc == 3) {
10669 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10670 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10671 } else {
10672 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10673 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10674 }
10675
10676 if (! peer)
10677 return CMD_WARNING;
10678
10679 if (! peer->afc[AFI_IP][safi])
10680 {
10681 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10682 VTY_NEWLINE);
10683 return CMD_WARNING;
10684 }
10685
10686 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10687 PEER_FLAG_RSERVER_CLIENT))
10688 {
10689 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10690 VTY_NEWLINE);
10691 return CMD_WARNING;
10692 }
10693
10694 table = peer->rib[AFI_IP][safi];
10695
10696 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10697}
10698
10699ALIAS (show_bgp_view_ipv4_safi_rsclient,
10700 show_bgp_ipv4_safi_rsclient_cmd,
10701 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10702 SHOW_STR
10703 BGP_STR
10704 "Address family\n"
10705 "Address Family modifier\n"
10706 "Address Family modifier\n"
10707 "Information about Route Server Client\n"
10708 NEIGHBOR_ADDR_STR)
10709
paulfee0f4c2004-09-13 05:12:46 +000010710DEFUN (show_ip_bgp_view_rsclient_route,
10711 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010712 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010713 SHOW_STR
10714 IP_STR
10715 BGP_STR
10716 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010717 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010718 "Information about Route Server Client\n"
10719 NEIGHBOR_ADDR_STR
10720 "Network in the BGP routing table to display\n")
10721{
10722 struct bgp *bgp;
10723 struct peer *peer;
10724
10725 /* BGP structure lookup. */
10726 if (argc == 3)
10727 {
10728 bgp = bgp_lookup_by_name (argv[0]);
10729 if (bgp == NULL)
10730 {
10731 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10732 return CMD_WARNING;
10733 }
10734 }
10735 else
10736 {
10737 bgp = bgp_get_default ();
10738 if (bgp == NULL)
10739 {
10740 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10741 return CMD_WARNING;
10742 }
10743 }
10744
10745 if (argc == 3)
10746 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10747 else
10748 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10749
10750 if (! peer)
10751 return CMD_WARNING;
10752
10753 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10754 {
10755 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10756 VTY_NEWLINE);
10757 return CMD_WARNING;
10758}
10759
10760 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10761 PEER_FLAG_RSERVER_CLIENT))
10762 {
10763 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10764 VTY_NEWLINE);
10765 return CMD_WARNING;
10766 }
10767
10768 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10769 (argc == 3) ? argv[2] : argv[1],
10770 AFI_IP, SAFI_UNICAST, NULL, 0);
10771}
10772
10773ALIAS (show_ip_bgp_view_rsclient_route,
10774 show_ip_bgp_rsclient_route_cmd,
10775 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10776 SHOW_STR
10777 IP_STR
10778 BGP_STR
10779 "Information about Route Server Client\n"
10780 NEIGHBOR_ADDR_STR
10781 "Network in the BGP routing table to display\n")
10782
Michael Lambert95cbbd22010-07-23 14:43:04 -040010783DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10784 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10785 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10786 SHOW_STR
10787 BGP_STR
10788 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010789 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010790 "Address family\n"
10791 "Address Family modifier\n"
10792 "Address Family modifier\n"
10793 "Information about Route Server Client\n"
10794 NEIGHBOR_ADDR_STR
10795 "Network in the BGP routing table to display\n")
10796{
10797 struct bgp *bgp;
10798 struct peer *peer;
10799 safi_t safi;
10800
10801 /* BGP structure lookup. */
10802 if (argc == 4)
10803 {
10804 bgp = bgp_lookup_by_name (argv[0]);
10805 if (bgp == NULL)
10806 {
10807 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10808 return CMD_WARNING;
10809 }
10810 }
10811 else
10812 {
10813 bgp = bgp_get_default ();
10814 if (bgp == NULL)
10815 {
10816 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10817 return CMD_WARNING;
10818 }
10819 }
10820
10821 if (argc == 4) {
10822 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10823 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10824 } else {
10825 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10826 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10827 }
10828
10829 if (! peer)
10830 return CMD_WARNING;
10831
10832 if (! peer->afc[AFI_IP][safi])
10833 {
10834 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10835 VTY_NEWLINE);
10836 return CMD_WARNING;
10837}
10838
10839 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10840 PEER_FLAG_RSERVER_CLIENT))
10841 {
10842 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10843 VTY_NEWLINE);
10844 return CMD_WARNING;
10845 }
10846
10847 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10848 (argc == 4) ? argv[3] : argv[2],
10849 AFI_IP, safi, NULL, 0);
10850}
10851
10852ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10853 show_bgp_ipv4_safi_rsclient_route_cmd,
10854 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10855 SHOW_STR
10856 BGP_STR
10857 "Address family\n"
10858 "Address Family modifier\n"
10859 "Address Family modifier\n"
10860 "Information about Route Server Client\n"
10861 NEIGHBOR_ADDR_STR
10862 "Network in the BGP routing table to display\n")
10863
paulfee0f4c2004-09-13 05:12:46 +000010864DEFUN (show_ip_bgp_view_rsclient_prefix,
10865 show_ip_bgp_view_rsclient_prefix_cmd,
10866 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10867 SHOW_STR
10868 IP_STR
10869 BGP_STR
10870 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010871 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010872 "Information about Route Server Client\n"
10873 NEIGHBOR_ADDR_STR
10874 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10875{
10876 struct bgp *bgp;
10877 struct peer *peer;
10878
10879 /* BGP structure lookup. */
10880 if (argc == 3)
10881 {
10882 bgp = bgp_lookup_by_name (argv[0]);
10883 if (bgp == NULL)
10884 {
10885 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10886 return CMD_WARNING;
10887 }
10888 }
10889 else
10890 {
10891 bgp = bgp_get_default ();
10892 if (bgp == NULL)
10893 {
10894 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10895 return CMD_WARNING;
10896 }
10897 }
10898
10899 if (argc == 3)
10900 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10901 else
10902 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10903
10904 if (! peer)
10905 return CMD_WARNING;
10906
10907 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10908 {
10909 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10910 VTY_NEWLINE);
10911 return CMD_WARNING;
10912}
10913
10914 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10915 PEER_FLAG_RSERVER_CLIENT))
10916{
10917 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10918 VTY_NEWLINE);
10919 return CMD_WARNING;
10920 }
10921
10922 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10923 (argc == 3) ? argv[2] : argv[1],
10924 AFI_IP, SAFI_UNICAST, NULL, 1);
10925}
10926
10927ALIAS (show_ip_bgp_view_rsclient_prefix,
10928 show_ip_bgp_rsclient_prefix_cmd,
10929 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10930 SHOW_STR
10931 IP_STR
10932 BGP_STR
10933 "Information about Route Server Client\n"
10934 NEIGHBOR_ADDR_STR
10935 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10936
Michael Lambert95cbbd22010-07-23 14:43:04 -040010937DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10938 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10939 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10940 SHOW_STR
10941 BGP_STR
10942 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010943 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010944 "Address family\n"
10945 "Address Family modifier\n"
10946 "Address Family modifier\n"
10947 "Information about Route Server Client\n"
10948 NEIGHBOR_ADDR_STR
10949 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10950{
10951 struct bgp *bgp;
10952 struct peer *peer;
10953 safi_t safi;
10954
10955 /* BGP structure lookup. */
10956 if (argc == 4)
10957 {
10958 bgp = bgp_lookup_by_name (argv[0]);
10959 if (bgp == NULL)
10960 {
10961 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10962 return CMD_WARNING;
10963 }
10964 }
10965 else
10966 {
10967 bgp = bgp_get_default ();
10968 if (bgp == NULL)
10969 {
10970 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10971 return CMD_WARNING;
10972 }
10973 }
10974
10975 if (argc == 4) {
10976 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10977 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10978 } else {
10979 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10980 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10981 }
10982
10983 if (! peer)
10984 return CMD_WARNING;
10985
10986 if (! peer->afc[AFI_IP][safi])
10987 {
10988 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10989 VTY_NEWLINE);
10990 return CMD_WARNING;
10991}
10992
10993 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10994 PEER_FLAG_RSERVER_CLIENT))
10995{
10996 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10997 VTY_NEWLINE);
10998 return CMD_WARNING;
10999 }
11000
11001 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11002 (argc == 4) ? argv[3] : argv[2],
11003 AFI_IP, safi, NULL, 1);
11004}
11005
11006ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11007 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11008 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11009 SHOW_STR
11010 BGP_STR
11011 "Address family\n"
11012 "Address Family modifier\n"
11013 "Address Family modifier\n"
11014 "Information about Route Server Client\n"
11015 NEIGHBOR_ADDR_STR
11016 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011017
paul718e3742002-12-13 20:15:29 +000011018#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011019DEFUN (show_bgp_view_neighbor_routes,
11020 show_bgp_view_neighbor_routes_cmd,
11021 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11022 SHOW_STR
11023 BGP_STR
11024 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011025 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011026 "Detailed information on TCP and BGP neighbor connections\n"
11027 "Neighbor to display information about\n"
11028 "Neighbor to display information about\n"
11029 "Display routes learned from neighbor\n")
11030{
11031 struct peer *peer;
11032
11033 if (argc == 2)
11034 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11035 else
11036 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11037
11038 if (! peer)
11039 return CMD_WARNING;
11040
11041 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11042 bgp_show_type_neighbor);
11043}
11044
11045ALIAS (show_bgp_view_neighbor_routes,
11046 show_bgp_view_ipv6_neighbor_routes_cmd,
11047 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11048 SHOW_STR
11049 BGP_STR
11050 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011051 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011052 "Address family\n"
11053 "Detailed information on TCP and BGP neighbor connections\n"
11054 "Neighbor to display information about\n"
11055 "Neighbor to display information about\n"
11056 "Display routes learned from neighbor\n")
11057
11058DEFUN (show_bgp_view_neighbor_damp,
11059 show_bgp_view_neighbor_damp_cmd,
11060 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11061 SHOW_STR
11062 BGP_STR
11063 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011064 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011065 "Detailed information on TCP and BGP neighbor connections\n"
11066 "Neighbor to display information about\n"
11067 "Neighbor to display information about\n"
11068 "Display the dampened routes received from neighbor\n")
11069{
11070 struct peer *peer;
11071
11072 if (argc == 2)
11073 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11074 else
11075 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11076
11077 if (! peer)
11078 return CMD_WARNING;
11079
11080 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11081 bgp_show_type_damp_neighbor);
11082}
11083
11084ALIAS (show_bgp_view_neighbor_damp,
11085 show_bgp_view_ipv6_neighbor_damp_cmd,
11086 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11087 SHOW_STR
11088 BGP_STR
11089 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011090 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011091 "Address family\n"
11092 "Detailed information on TCP and BGP neighbor connections\n"
11093 "Neighbor to display information about\n"
11094 "Neighbor to display information about\n"
11095 "Display the dampened routes received from neighbor\n")
11096
11097DEFUN (show_bgp_view_neighbor_flap,
11098 show_bgp_view_neighbor_flap_cmd,
11099 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11100 SHOW_STR
11101 BGP_STR
11102 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011103 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011104 "Detailed information on TCP and BGP neighbor connections\n"
11105 "Neighbor to display information about\n"
11106 "Neighbor to display information about\n"
11107 "Display flap statistics of the routes learned from neighbor\n")
11108{
11109 struct peer *peer;
11110
11111 if (argc == 2)
11112 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11113 else
11114 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11115
11116 if (! peer)
11117 return CMD_WARNING;
11118
11119 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11120 bgp_show_type_flap_neighbor);
11121}
11122
11123ALIAS (show_bgp_view_neighbor_flap,
11124 show_bgp_view_ipv6_neighbor_flap_cmd,
11125 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11126 SHOW_STR
11127 BGP_STR
11128 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011129 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011130 "Address family\n"
11131 "Detailed information on TCP and BGP neighbor connections\n"
11132 "Neighbor to display information about\n"
11133 "Neighbor to display information about\n"
11134 "Display flap statistics of the routes learned from neighbor\n")
11135
11136ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011137 show_bgp_neighbor_routes_cmd,
11138 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11139 SHOW_STR
11140 BGP_STR
11141 "Detailed information on TCP and BGP neighbor connections\n"
11142 "Neighbor to display information about\n"
11143 "Neighbor to display information about\n"
11144 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011145
paulbb46e942003-10-24 19:02:03 +000011146
11147ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011148 show_bgp_ipv6_neighbor_routes_cmd,
11149 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11150 SHOW_STR
11151 BGP_STR
11152 "Address family\n"
11153 "Detailed information on TCP and BGP neighbor connections\n"
11154 "Neighbor to display information about\n"
11155 "Neighbor to display information about\n"
11156 "Display routes learned from neighbor\n")
11157
11158/* old command */
paulbb46e942003-10-24 19:02:03 +000011159ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011160 ipv6_bgp_neighbor_routes_cmd,
11161 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11162 SHOW_STR
11163 IPV6_STR
11164 BGP_STR
11165 "Detailed information on TCP and BGP neighbor connections\n"
11166 "Neighbor to display information about\n"
11167 "Neighbor to display information about\n"
11168 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011169
11170/* old command */
11171DEFUN (ipv6_mbgp_neighbor_routes,
11172 ipv6_mbgp_neighbor_routes_cmd,
11173 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11174 SHOW_STR
11175 IPV6_STR
11176 MBGP_STR
11177 "Detailed information on TCP and BGP neighbor connections\n"
11178 "Neighbor to display information about\n"
11179 "Neighbor to display information about\n"
11180 "Display routes learned from neighbor\n")
11181{
paulbb46e942003-10-24 19:02:03 +000011182 struct peer *peer;
11183
11184 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11185 if (! peer)
11186 return CMD_WARNING;
11187
11188 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011189 bgp_show_type_neighbor);
11190}
paulbb46e942003-10-24 19:02:03 +000011191
11192ALIAS (show_bgp_view_neighbor_flap,
11193 show_bgp_neighbor_flap_cmd,
11194 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11195 SHOW_STR
11196 BGP_STR
11197 "Detailed information on TCP and BGP neighbor connections\n"
11198 "Neighbor to display information about\n"
11199 "Neighbor to display information about\n"
11200 "Display flap statistics of the routes learned from neighbor\n")
11201
11202ALIAS (show_bgp_view_neighbor_flap,
11203 show_bgp_ipv6_neighbor_flap_cmd,
11204 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11205 SHOW_STR
11206 BGP_STR
11207 "Address family\n"
11208 "Detailed information on TCP and BGP neighbor connections\n"
11209 "Neighbor to display information about\n"
11210 "Neighbor to display information about\n"
11211 "Display flap statistics of the routes learned from neighbor\n")
11212
11213ALIAS (show_bgp_view_neighbor_damp,
11214 show_bgp_neighbor_damp_cmd,
11215 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11216 SHOW_STR
11217 BGP_STR
11218 "Detailed information on TCP and BGP neighbor connections\n"
11219 "Neighbor to display information about\n"
11220 "Neighbor to display information about\n"
11221 "Display the dampened routes received from neighbor\n")
11222
11223ALIAS (show_bgp_view_neighbor_damp,
11224 show_bgp_ipv6_neighbor_damp_cmd,
11225 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11226 SHOW_STR
11227 BGP_STR
11228 "Address family\n"
11229 "Detailed information on TCP and BGP neighbor connections\n"
11230 "Neighbor to display information about\n"
11231 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011232 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011233
11234DEFUN (show_bgp_view_rsclient,
11235 show_bgp_view_rsclient_cmd,
11236 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11237 SHOW_STR
11238 BGP_STR
11239 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011240 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011241 "Information about Route Server Client\n"
11242 NEIGHBOR_ADDR_STR)
11243{
11244 struct bgp_table *table;
11245 struct peer *peer;
11246
11247 if (argc == 2)
11248 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11249 else
11250 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11251
11252 if (! peer)
11253 return CMD_WARNING;
11254
11255 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11256 {
11257 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11258 VTY_NEWLINE);
11259 return CMD_WARNING;
11260 }
11261
11262 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11263 PEER_FLAG_RSERVER_CLIENT))
11264 {
11265 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11266 VTY_NEWLINE);
11267 return CMD_WARNING;
11268 }
11269
11270 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11271
ajs5a646652004-11-05 01:25:55 +000011272 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011273}
11274
11275ALIAS (show_bgp_view_rsclient,
11276 show_bgp_rsclient_cmd,
11277 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11278 SHOW_STR
11279 BGP_STR
11280 "Information about Route Server Client\n"
11281 NEIGHBOR_ADDR_STR)
11282
Michael Lambert95cbbd22010-07-23 14:43:04 -040011283DEFUN (show_bgp_view_ipv6_safi_rsclient,
11284 show_bgp_view_ipv6_safi_rsclient_cmd,
11285 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11286 SHOW_STR
11287 BGP_STR
11288 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011289 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011290 "Address family\n"
11291 "Address Family modifier\n"
11292 "Address Family modifier\n"
11293 "Information about Route Server Client\n"
11294 NEIGHBOR_ADDR_STR)
11295{
11296 struct bgp_table *table;
11297 struct peer *peer;
11298 safi_t safi;
11299
11300 if (argc == 3) {
11301 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11302 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11303 } else {
11304 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11305 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11306 }
11307
11308 if (! peer)
11309 return CMD_WARNING;
11310
11311 if (! peer->afc[AFI_IP6][safi])
11312 {
11313 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11314 VTY_NEWLINE);
11315 return CMD_WARNING;
11316 }
11317
11318 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11319 PEER_FLAG_RSERVER_CLIENT))
11320 {
11321 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11322 VTY_NEWLINE);
11323 return CMD_WARNING;
11324 }
11325
11326 table = peer->rib[AFI_IP6][safi];
11327
11328 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11329}
11330
11331ALIAS (show_bgp_view_ipv6_safi_rsclient,
11332 show_bgp_ipv6_safi_rsclient_cmd,
11333 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11334 SHOW_STR
11335 BGP_STR
11336 "Address family\n"
11337 "Address Family modifier\n"
11338 "Address Family modifier\n"
11339 "Information about Route Server Client\n"
11340 NEIGHBOR_ADDR_STR)
11341
paulfee0f4c2004-09-13 05:12:46 +000011342DEFUN (show_bgp_view_rsclient_route,
11343 show_bgp_view_rsclient_route_cmd,
11344 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11345 SHOW_STR
11346 BGP_STR
11347 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011348 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011349 "Information about Route Server Client\n"
11350 NEIGHBOR_ADDR_STR
11351 "Network in the BGP routing table to display\n")
11352{
11353 struct bgp *bgp;
11354 struct peer *peer;
11355
11356 /* BGP structure lookup. */
11357 if (argc == 3)
11358 {
11359 bgp = bgp_lookup_by_name (argv[0]);
11360 if (bgp == NULL)
11361 {
11362 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11363 return CMD_WARNING;
11364 }
11365 }
11366 else
11367 {
11368 bgp = bgp_get_default ();
11369 if (bgp == NULL)
11370 {
11371 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11372 return CMD_WARNING;
11373 }
11374 }
11375
11376 if (argc == 3)
11377 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11378 else
11379 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11380
11381 if (! peer)
11382 return CMD_WARNING;
11383
11384 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11385 {
11386 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11387 VTY_NEWLINE);
11388 return CMD_WARNING;
11389 }
11390
11391 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11392 PEER_FLAG_RSERVER_CLIENT))
11393 {
11394 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11395 VTY_NEWLINE);
11396 return CMD_WARNING;
11397 }
11398
11399 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11400 (argc == 3) ? argv[2] : argv[1],
11401 AFI_IP6, SAFI_UNICAST, NULL, 0);
11402}
11403
11404ALIAS (show_bgp_view_rsclient_route,
11405 show_bgp_rsclient_route_cmd,
11406 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11407 SHOW_STR
11408 BGP_STR
11409 "Information about Route Server Client\n"
11410 NEIGHBOR_ADDR_STR
11411 "Network in the BGP routing table to display\n")
11412
Michael Lambert95cbbd22010-07-23 14:43:04 -040011413DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11414 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11415 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11416 SHOW_STR
11417 BGP_STR
11418 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011419 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011420 "Address family\n"
11421 "Address Family modifier\n"
11422 "Address Family modifier\n"
11423 "Information about Route Server Client\n"
11424 NEIGHBOR_ADDR_STR
11425 "Network in the BGP routing table to display\n")
11426{
11427 struct bgp *bgp;
11428 struct peer *peer;
11429 safi_t safi;
11430
11431 /* BGP structure lookup. */
11432 if (argc == 4)
11433 {
11434 bgp = bgp_lookup_by_name (argv[0]);
11435 if (bgp == NULL)
11436 {
11437 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11438 return CMD_WARNING;
11439 }
11440 }
11441 else
11442 {
11443 bgp = bgp_get_default ();
11444 if (bgp == NULL)
11445 {
11446 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11447 return CMD_WARNING;
11448 }
11449 }
11450
11451 if (argc == 4) {
11452 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11453 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11454 } else {
11455 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11456 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11457 }
11458
11459 if (! peer)
11460 return CMD_WARNING;
11461
11462 if (! peer->afc[AFI_IP6][safi])
11463 {
11464 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11465 VTY_NEWLINE);
11466 return CMD_WARNING;
11467}
11468
11469 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11470 PEER_FLAG_RSERVER_CLIENT))
11471 {
11472 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11473 VTY_NEWLINE);
11474 return CMD_WARNING;
11475 }
11476
11477 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11478 (argc == 4) ? argv[3] : argv[2],
11479 AFI_IP6, safi, NULL, 0);
11480}
11481
11482ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11483 show_bgp_ipv6_safi_rsclient_route_cmd,
11484 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11485 SHOW_STR
11486 BGP_STR
11487 "Address family\n"
11488 "Address Family modifier\n"
11489 "Address Family modifier\n"
11490 "Information about Route Server Client\n"
11491 NEIGHBOR_ADDR_STR
11492 "Network in the BGP routing table to display\n")
11493
paulfee0f4c2004-09-13 05:12:46 +000011494DEFUN (show_bgp_view_rsclient_prefix,
11495 show_bgp_view_rsclient_prefix_cmd,
11496 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11497 SHOW_STR
11498 BGP_STR
11499 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011500 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011501 "Information about Route Server Client\n"
11502 NEIGHBOR_ADDR_STR
11503 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11504{
11505 struct bgp *bgp;
11506 struct peer *peer;
11507
11508 /* BGP structure lookup. */
11509 if (argc == 3)
11510 {
11511 bgp = bgp_lookup_by_name (argv[0]);
11512 if (bgp == NULL)
11513 {
11514 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11515 return CMD_WARNING;
11516 }
11517 }
11518 else
11519 {
11520 bgp = bgp_get_default ();
11521 if (bgp == NULL)
11522 {
11523 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11524 return CMD_WARNING;
11525 }
11526 }
11527
11528 if (argc == 3)
11529 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11530 else
11531 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11532
11533 if (! peer)
11534 return CMD_WARNING;
11535
11536 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11537 {
11538 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11539 VTY_NEWLINE);
11540 return CMD_WARNING;
11541 }
11542
11543 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11544 PEER_FLAG_RSERVER_CLIENT))
11545 {
11546 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11547 VTY_NEWLINE);
11548 return CMD_WARNING;
11549 }
11550
11551 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11552 (argc == 3) ? argv[2] : argv[1],
11553 AFI_IP6, SAFI_UNICAST, NULL, 1);
11554}
11555
11556ALIAS (show_bgp_view_rsclient_prefix,
11557 show_bgp_rsclient_prefix_cmd,
11558 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11559 SHOW_STR
11560 BGP_STR
11561 "Information about Route Server Client\n"
11562 NEIGHBOR_ADDR_STR
11563 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11564
Michael Lambert95cbbd22010-07-23 14:43:04 -040011565DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11566 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11567 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11568 SHOW_STR
11569 BGP_STR
11570 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011571 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011572 "Address family\n"
11573 "Address Family modifier\n"
11574 "Address Family modifier\n"
11575 "Information about Route Server Client\n"
11576 NEIGHBOR_ADDR_STR
11577 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11578{
11579 struct bgp *bgp;
11580 struct peer *peer;
11581 safi_t safi;
11582
11583 /* BGP structure lookup. */
11584 if (argc == 4)
11585 {
11586 bgp = bgp_lookup_by_name (argv[0]);
11587 if (bgp == NULL)
11588 {
11589 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11590 return CMD_WARNING;
11591 }
11592 }
11593 else
11594 {
11595 bgp = bgp_get_default ();
11596 if (bgp == NULL)
11597 {
11598 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11599 return CMD_WARNING;
11600 }
11601 }
11602
11603 if (argc == 4) {
11604 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11605 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11606 } else {
11607 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11608 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11609 }
11610
11611 if (! peer)
11612 return CMD_WARNING;
11613
11614 if (! peer->afc[AFI_IP6][safi])
11615 {
11616 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11617 VTY_NEWLINE);
11618 return CMD_WARNING;
11619}
11620
11621 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11622 PEER_FLAG_RSERVER_CLIENT))
11623{
11624 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11625 VTY_NEWLINE);
11626 return CMD_WARNING;
11627 }
11628
11629 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11630 (argc == 4) ? argv[3] : argv[2],
11631 AFI_IP6, safi, NULL, 1);
11632}
11633
11634ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11635 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11636 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11637 SHOW_STR
11638 BGP_STR
11639 "Address family\n"
11640 "Address Family modifier\n"
11641 "Address Family modifier\n"
11642 "Information about Route Server Client\n"
11643 NEIGHBOR_ADDR_STR
11644 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11645
paul718e3742002-12-13 20:15:29 +000011646#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011647
paul718e3742002-12-13 20:15:29 +000011648struct bgp_table *bgp_distance_table;
11649
11650struct bgp_distance
11651{
11652 /* Distance value for the IP source prefix. */
11653 u_char distance;
11654
11655 /* Name of the access-list to be matched. */
11656 char *access_list;
11657};
11658
paul94f2b392005-06-28 12:44:16 +000011659static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011660bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011661{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011662 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011663}
11664
paul94f2b392005-06-28 12:44:16 +000011665static void
paul718e3742002-12-13 20:15:29 +000011666bgp_distance_free (struct bgp_distance *bdistance)
11667{
11668 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11669}
11670
paul94f2b392005-06-28 12:44:16 +000011671static int
paulfd79ac92004-10-13 05:06:08 +000011672bgp_distance_set (struct vty *vty, const char *distance_str,
11673 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011674{
11675 int ret;
11676 struct prefix_ipv4 p;
11677 u_char distance;
11678 struct bgp_node *rn;
11679 struct bgp_distance *bdistance;
11680
11681 ret = str2prefix_ipv4 (ip_str, &p);
11682 if (ret == 0)
11683 {
11684 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11685 return CMD_WARNING;
11686 }
11687
11688 distance = atoi (distance_str);
11689
11690 /* Get BGP distance node. */
11691 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11692 if (rn->info)
11693 {
11694 bdistance = rn->info;
11695 bgp_unlock_node (rn);
11696 }
11697 else
11698 {
11699 bdistance = bgp_distance_new ();
11700 rn->info = bdistance;
11701 }
11702
11703 /* Set distance value. */
11704 bdistance->distance = distance;
11705
11706 /* Reset access-list configuration. */
11707 if (bdistance->access_list)
11708 {
11709 free (bdistance->access_list);
11710 bdistance->access_list = NULL;
11711 }
11712 if (access_list_str)
11713 bdistance->access_list = strdup (access_list_str);
11714
11715 return CMD_SUCCESS;
11716}
11717
paul94f2b392005-06-28 12:44:16 +000011718static int
paulfd79ac92004-10-13 05:06:08 +000011719bgp_distance_unset (struct vty *vty, const char *distance_str,
11720 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011721{
11722 int ret;
11723 struct prefix_ipv4 p;
11724 u_char distance;
11725 struct bgp_node *rn;
11726 struct bgp_distance *bdistance;
11727
11728 ret = str2prefix_ipv4 (ip_str, &p);
11729 if (ret == 0)
11730 {
11731 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11732 return CMD_WARNING;
11733 }
11734
11735 distance = atoi (distance_str);
11736
11737 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11738 if (! rn)
11739 {
11740 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11741 return CMD_WARNING;
11742 }
11743
11744 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011745
11746 if (bdistance->distance != distance)
11747 {
11748 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11749 return CMD_WARNING;
11750 }
11751
paul718e3742002-12-13 20:15:29 +000011752 if (bdistance->access_list)
11753 free (bdistance->access_list);
11754 bgp_distance_free (bdistance);
11755
11756 rn->info = NULL;
11757 bgp_unlock_node (rn);
11758 bgp_unlock_node (rn);
11759
11760 return CMD_SUCCESS;
11761}
11762
paul718e3742002-12-13 20:15:29 +000011763/* Apply BGP information to distance method. */
11764u_char
11765bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11766{
11767 struct bgp_node *rn;
11768 struct prefix_ipv4 q;
11769 struct peer *peer;
11770 struct bgp_distance *bdistance;
11771 struct access_list *alist;
11772 struct bgp_static *bgp_static;
11773
11774 if (! bgp)
11775 return 0;
11776
11777 if (p->family != AF_INET)
11778 return 0;
11779
11780 peer = rinfo->peer;
11781
11782 if (peer->su.sa.sa_family != AF_INET)
11783 return 0;
11784
11785 memset (&q, 0, sizeof (struct prefix_ipv4));
11786 q.family = AF_INET;
11787 q.prefix = peer->su.sin.sin_addr;
11788 q.prefixlen = IPV4_MAX_BITLEN;
11789
11790 /* Check source address. */
11791 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11792 if (rn)
11793 {
11794 bdistance = rn->info;
11795 bgp_unlock_node (rn);
11796
11797 if (bdistance->access_list)
11798 {
11799 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11800 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11801 return bdistance->distance;
11802 }
11803 else
11804 return bdistance->distance;
11805 }
11806
11807 /* Backdoor check. */
11808 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11809 if (rn)
11810 {
11811 bgp_static = rn->info;
11812 bgp_unlock_node (rn);
11813
11814 if (bgp_static->backdoor)
11815 {
11816 if (bgp->distance_local)
11817 return bgp->distance_local;
11818 else
11819 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11820 }
11821 }
11822
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011823 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011824 {
11825 if (bgp->distance_ebgp)
11826 return bgp->distance_ebgp;
11827 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11828 }
11829 else
11830 {
11831 if (bgp->distance_ibgp)
11832 return bgp->distance_ibgp;
11833 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11834 }
11835}
11836
11837DEFUN (bgp_distance,
11838 bgp_distance_cmd,
11839 "distance bgp <1-255> <1-255> <1-255>",
11840 "Define an administrative distance\n"
11841 "BGP distance\n"
11842 "Distance for routes external to the AS\n"
11843 "Distance for routes internal to the AS\n"
11844 "Distance for local routes\n")
11845{
11846 struct bgp *bgp;
11847
11848 bgp = vty->index;
11849
11850 bgp->distance_ebgp = atoi (argv[0]);
11851 bgp->distance_ibgp = atoi (argv[1]);
11852 bgp->distance_local = atoi (argv[2]);
11853 return CMD_SUCCESS;
11854}
11855
11856DEFUN (no_bgp_distance,
11857 no_bgp_distance_cmd,
11858 "no distance bgp <1-255> <1-255> <1-255>",
11859 NO_STR
11860 "Define an administrative distance\n"
11861 "BGP distance\n"
11862 "Distance for routes external to the AS\n"
11863 "Distance for routes internal to the AS\n"
11864 "Distance for local routes\n")
11865{
11866 struct bgp *bgp;
11867
11868 bgp = vty->index;
11869
11870 bgp->distance_ebgp= 0;
11871 bgp->distance_ibgp = 0;
11872 bgp->distance_local = 0;
11873 return CMD_SUCCESS;
11874}
11875
11876ALIAS (no_bgp_distance,
11877 no_bgp_distance2_cmd,
11878 "no distance bgp",
11879 NO_STR
11880 "Define an administrative distance\n"
11881 "BGP distance\n")
11882
11883DEFUN (bgp_distance_source,
11884 bgp_distance_source_cmd,
11885 "distance <1-255> A.B.C.D/M",
11886 "Define an administrative distance\n"
11887 "Administrative distance\n"
11888 "IP source prefix\n")
11889{
11890 bgp_distance_set (vty, argv[0], argv[1], NULL);
11891 return CMD_SUCCESS;
11892}
11893
11894DEFUN (no_bgp_distance_source,
11895 no_bgp_distance_source_cmd,
11896 "no distance <1-255> A.B.C.D/M",
11897 NO_STR
11898 "Define an administrative distance\n"
11899 "Administrative distance\n"
11900 "IP source prefix\n")
11901{
11902 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11903 return CMD_SUCCESS;
11904}
11905
11906DEFUN (bgp_distance_source_access_list,
11907 bgp_distance_source_access_list_cmd,
11908 "distance <1-255> A.B.C.D/M WORD",
11909 "Define an administrative distance\n"
11910 "Administrative distance\n"
11911 "IP source prefix\n"
11912 "Access list name\n")
11913{
11914 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11915 return CMD_SUCCESS;
11916}
11917
11918DEFUN (no_bgp_distance_source_access_list,
11919 no_bgp_distance_source_access_list_cmd,
11920 "no distance <1-255> A.B.C.D/M WORD",
11921 NO_STR
11922 "Define an administrative distance\n"
11923 "Administrative distance\n"
11924 "IP source prefix\n"
11925 "Access list name\n")
11926{
11927 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11928 return CMD_SUCCESS;
11929}
David Lamparter6b0655a2014-06-04 06:53:35 +020011930
paul718e3742002-12-13 20:15:29 +000011931DEFUN (bgp_damp_set,
11932 bgp_damp_set_cmd,
11933 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11934 "BGP Specific commands\n"
11935 "Enable route-flap dampening\n"
11936 "Half-life time for the penalty\n"
11937 "Value to start reusing a route\n"
11938 "Value to start suppressing a route\n"
11939 "Maximum duration to suppress a stable route\n")
11940{
11941 struct bgp *bgp;
11942 int half = DEFAULT_HALF_LIFE * 60;
11943 int reuse = DEFAULT_REUSE;
11944 int suppress = DEFAULT_SUPPRESS;
11945 int max = 4 * half;
11946
11947 if (argc == 4)
11948 {
11949 half = atoi (argv[0]) * 60;
11950 reuse = atoi (argv[1]);
11951 suppress = atoi (argv[2]);
11952 max = atoi (argv[3]) * 60;
11953 }
11954 else if (argc == 1)
11955 {
11956 half = atoi (argv[0]) * 60;
11957 max = 4 * half;
11958 }
11959
11960 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000011961
11962 if (suppress < reuse)
11963 {
11964 vty_out (vty, "Suppress value cannot be less than reuse value %s",
11965 VTY_NEWLINE);
11966 return 0;
11967 }
11968
paul718e3742002-12-13 20:15:29 +000011969 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11970 half, reuse, suppress, max);
11971}
11972
11973ALIAS (bgp_damp_set,
11974 bgp_damp_set2_cmd,
11975 "bgp dampening <1-45>",
11976 "BGP Specific commands\n"
11977 "Enable route-flap dampening\n"
11978 "Half-life time for the penalty\n")
11979
11980ALIAS (bgp_damp_set,
11981 bgp_damp_set3_cmd,
11982 "bgp dampening",
11983 "BGP Specific commands\n"
11984 "Enable route-flap dampening\n")
11985
11986DEFUN (bgp_damp_unset,
11987 bgp_damp_unset_cmd,
11988 "no bgp dampening",
11989 NO_STR
11990 "BGP Specific commands\n"
11991 "Enable route-flap dampening\n")
11992{
11993 struct bgp *bgp;
11994
11995 bgp = vty->index;
11996 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11997}
11998
11999ALIAS (bgp_damp_unset,
12000 bgp_damp_unset2_cmd,
12001 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12002 NO_STR
12003 "BGP Specific commands\n"
12004 "Enable route-flap dampening\n"
12005 "Half-life time for the penalty\n"
12006 "Value to start reusing a route\n"
12007 "Value to start suppressing a route\n"
12008 "Maximum duration to suppress a stable route\n")
12009
12010DEFUN (show_ip_bgp_dampened_paths,
12011 show_ip_bgp_dampened_paths_cmd,
12012 "show ip bgp dampened-paths",
12013 SHOW_STR
12014 IP_STR
12015 BGP_STR
12016 "Display paths suppressed due to dampening\n")
12017{
ajs5a646652004-11-05 01:25:55 +000012018 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12019 NULL);
paul718e3742002-12-13 20:15:29 +000012020}
12021
12022DEFUN (show_ip_bgp_flap_statistics,
12023 show_ip_bgp_flap_statistics_cmd,
12024 "show ip bgp flap-statistics",
12025 SHOW_STR
12026 IP_STR
12027 BGP_STR
12028 "Display flap statistics of routes\n")
12029{
ajs5a646652004-11-05 01:25:55 +000012030 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12031 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012032}
David Lamparter6b0655a2014-06-04 06:53:35 +020012033
paul718e3742002-12-13 20:15:29 +000012034/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012035static int
paulfd79ac92004-10-13 05:06:08 +000012036bgp_clear_damp_route (struct vty *vty, const char *view_name,
12037 const char *ip_str, afi_t afi, safi_t safi,
12038 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012039{
12040 int ret;
12041 struct prefix match;
12042 struct bgp_node *rn;
12043 struct bgp_node *rm;
12044 struct bgp_info *ri;
12045 struct bgp_info *ri_temp;
12046 struct bgp *bgp;
12047 struct bgp_table *table;
12048
12049 /* BGP structure lookup. */
12050 if (view_name)
12051 {
12052 bgp = bgp_lookup_by_name (view_name);
12053 if (bgp == NULL)
12054 {
12055 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12056 return CMD_WARNING;
12057 }
12058 }
12059 else
12060 {
12061 bgp = bgp_get_default ();
12062 if (bgp == NULL)
12063 {
12064 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12065 return CMD_WARNING;
12066 }
12067 }
12068
12069 /* Check IP address argument. */
12070 ret = str2prefix (ip_str, &match);
12071 if (! ret)
12072 {
12073 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12074 return CMD_WARNING;
12075 }
12076
12077 match.family = afi2family (afi);
12078
12079 if (safi == SAFI_MPLS_VPN)
12080 {
12081 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12082 {
12083 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12084 continue;
12085
12086 if ((table = rn->info) != NULL)
12087 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012088 {
12089 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12090 {
12091 ri = rm->info;
12092 while (ri)
12093 {
12094 if (ri->extra && ri->extra->damp_info)
12095 {
12096 ri_temp = ri->next;
12097 bgp_damp_info_free (ri->extra->damp_info, 1);
12098 ri = ri_temp;
12099 }
12100 else
12101 ri = ri->next;
12102 }
12103 }
12104
12105 bgp_unlock_node (rm);
12106 }
paul718e3742002-12-13 20:15:29 +000012107 }
12108 }
12109 else
12110 {
12111 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012112 {
12113 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12114 {
12115 ri = rn->info;
12116 while (ri)
12117 {
12118 if (ri->extra && ri->extra->damp_info)
12119 {
12120 ri_temp = ri->next;
12121 bgp_damp_info_free (ri->extra->damp_info, 1);
12122 ri = ri_temp;
12123 }
12124 else
12125 ri = ri->next;
12126 }
12127 }
12128
12129 bgp_unlock_node (rn);
12130 }
paul718e3742002-12-13 20:15:29 +000012131 }
12132
12133 return CMD_SUCCESS;
12134}
12135
12136DEFUN (clear_ip_bgp_dampening,
12137 clear_ip_bgp_dampening_cmd,
12138 "clear ip bgp dampening",
12139 CLEAR_STR
12140 IP_STR
12141 BGP_STR
12142 "Clear route flap dampening information\n")
12143{
12144 bgp_damp_info_clean ();
12145 return CMD_SUCCESS;
12146}
12147
12148DEFUN (clear_ip_bgp_dampening_prefix,
12149 clear_ip_bgp_dampening_prefix_cmd,
12150 "clear ip bgp dampening A.B.C.D/M",
12151 CLEAR_STR
12152 IP_STR
12153 BGP_STR
12154 "Clear route flap dampening information\n"
12155 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12156{
12157 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12158 SAFI_UNICAST, NULL, 1);
12159}
12160
12161DEFUN (clear_ip_bgp_dampening_address,
12162 clear_ip_bgp_dampening_address_cmd,
12163 "clear ip bgp dampening A.B.C.D",
12164 CLEAR_STR
12165 IP_STR
12166 BGP_STR
12167 "Clear route flap dampening information\n"
12168 "Network to clear damping information\n")
12169{
12170 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12171 SAFI_UNICAST, NULL, 0);
12172}
12173
12174DEFUN (clear_ip_bgp_dampening_address_mask,
12175 clear_ip_bgp_dampening_address_mask_cmd,
12176 "clear ip bgp dampening A.B.C.D A.B.C.D",
12177 CLEAR_STR
12178 IP_STR
12179 BGP_STR
12180 "Clear route flap dampening information\n"
12181 "Network to clear damping information\n"
12182 "Network mask\n")
12183{
12184 int ret;
12185 char prefix_str[BUFSIZ];
12186
12187 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12188 if (! ret)
12189 {
12190 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12191 return CMD_WARNING;
12192 }
12193
12194 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12195 SAFI_UNICAST, NULL, 0);
12196}
David Lamparter6b0655a2014-06-04 06:53:35 +020012197
paul94f2b392005-06-28 12:44:16 +000012198static int
paul718e3742002-12-13 20:15:29 +000012199bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12200 afi_t afi, safi_t safi, int *write)
12201{
12202 struct bgp_node *prn;
12203 struct bgp_node *rn;
12204 struct bgp_table *table;
12205 struct prefix *p;
12206 struct prefix_rd *prd;
12207 struct bgp_static *bgp_static;
12208 u_int32_t label;
12209 char buf[SU_ADDRSTRLEN];
12210 char rdbuf[RD_ADDRSTRLEN];
12211
12212 /* Network configuration. */
12213 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12214 if ((table = prn->info) != NULL)
12215 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12216 if ((bgp_static = rn->info) != NULL)
12217 {
12218 p = &rn->p;
12219 prd = (struct prefix_rd *) &prn->p;
12220
12221 /* "address-family" display. */
12222 bgp_config_write_family_header (vty, afi, safi, write);
12223
12224 /* "network" configuration display. */
12225 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12226 label = decode_label (bgp_static->tag);
12227
12228 vty_out (vty, " network %s/%d rd %s tag %d",
12229 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12230 p->prefixlen,
12231 rdbuf, label);
12232 vty_out (vty, "%s", VTY_NEWLINE);
12233 }
12234 return 0;
12235}
12236
12237/* Configuration of static route announcement and aggregate
12238 information. */
12239int
12240bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12241 afi_t afi, safi_t safi, int *write)
12242{
12243 struct bgp_node *rn;
12244 struct prefix *p;
12245 struct bgp_static *bgp_static;
12246 struct bgp_aggregate *bgp_aggregate;
12247 char buf[SU_ADDRSTRLEN];
12248
12249 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12250 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12251
12252 /* Network configuration. */
12253 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12254 if ((bgp_static = rn->info) != NULL)
12255 {
12256 p = &rn->p;
12257
12258 /* "address-family" display. */
12259 bgp_config_write_family_header (vty, afi, safi, write);
12260
12261 /* "network" configuration display. */
12262 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12263 {
12264 u_int32_t destination;
12265 struct in_addr netmask;
12266
12267 destination = ntohl (p->u.prefix4.s_addr);
12268 masklen2ip (p->prefixlen, &netmask);
12269 vty_out (vty, " network %s",
12270 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12271
12272 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12273 || (IN_CLASSB (destination) && p->prefixlen == 16)
12274 || (IN_CLASSA (destination) && p->prefixlen == 8)
12275 || p->u.prefix4.s_addr == 0)
12276 {
12277 /* Natural mask is not display. */
12278 }
12279 else
12280 vty_out (vty, " mask %s", inet_ntoa (netmask));
12281 }
12282 else
12283 {
12284 vty_out (vty, " network %s/%d",
12285 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12286 p->prefixlen);
12287 }
12288
12289 if (bgp_static->rmap.name)
12290 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012291 else
12292 {
12293 if (bgp_static->backdoor)
12294 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012295 }
paul718e3742002-12-13 20:15:29 +000012296
12297 vty_out (vty, "%s", VTY_NEWLINE);
12298 }
12299
12300 /* Aggregate-address configuration. */
12301 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12302 if ((bgp_aggregate = rn->info) != NULL)
12303 {
12304 p = &rn->p;
12305
12306 /* "address-family" display. */
12307 bgp_config_write_family_header (vty, afi, safi, write);
12308
12309 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12310 {
12311 struct in_addr netmask;
12312
12313 masklen2ip (p->prefixlen, &netmask);
12314 vty_out (vty, " aggregate-address %s %s",
12315 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12316 inet_ntoa (netmask));
12317 }
12318 else
12319 {
12320 vty_out (vty, " aggregate-address %s/%d",
12321 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12322 p->prefixlen);
12323 }
12324
12325 if (bgp_aggregate->as_set)
12326 vty_out (vty, " as-set");
12327
12328 if (bgp_aggregate->summary_only)
12329 vty_out (vty, " summary-only");
12330
12331 vty_out (vty, "%s", VTY_NEWLINE);
12332 }
12333
12334 return 0;
12335}
12336
12337int
12338bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12339{
12340 struct bgp_node *rn;
12341 struct bgp_distance *bdistance;
12342
12343 /* Distance configuration. */
12344 if (bgp->distance_ebgp
12345 && bgp->distance_ibgp
12346 && bgp->distance_local
12347 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12348 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12349 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12350 vty_out (vty, " distance bgp %d %d %d%s",
12351 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12352 VTY_NEWLINE);
12353
12354 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12355 if ((bdistance = rn->info) != NULL)
12356 {
12357 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12358 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12359 bdistance->access_list ? bdistance->access_list : "",
12360 VTY_NEWLINE);
12361 }
12362
12363 return 0;
12364}
12365
12366/* Allocate routing table structure and install commands. */
12367void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012368bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012369{
12370 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012371 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012372
12373 /* IPv4 BGP commands. */
12374 install_element (BGP_NODE, &bgp_network_cmd);
12375 install_element (BGP_NODE, &bgp_network_mask_cmd);
12376 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12377 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12378 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12379 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12380 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12381 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12382 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12383 install_element (BGP_NODE, &no_bgp_network_cmd);
12384 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12385 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12386 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12387 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12388 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12389 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12390 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12391 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12392
12393 install_element (BGP_NODE, &aggregate_address_cmd);
12394 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12395 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12396 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12397 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12398 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12399 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12400 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12401 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12402 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12403 install_element (BGP_NODE, &no_aggregate_address_cmd);
12404 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12405 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12406 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12407 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12408 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12409 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12410 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12411 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12412 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12413
12414 /* IPv4 unicast configuration. */
12415 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12416 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12417 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12418 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12419 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12420 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012421 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012422 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12423 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12424 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12425 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12426 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012427
paul718e3742002-12-13 20:15:29 +000012428 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12429 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12430 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12431 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12432 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12433 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12434 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12435 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12436 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12437 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12438 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12439 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12440 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12441 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12442 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12443 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12444 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12445 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12446 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12447 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12448
12449 /* IPv4 multicast configuration. */
12450 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12451 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12452 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12453 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12454 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12455 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12456 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12457 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12458 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12459 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12460 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12461 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12462 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12463 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12464 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12465 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12466 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12467 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12468 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12469 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12470 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12471 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12472 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12473 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12474 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12475 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12476 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12477 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12478 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12479 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12480 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12481 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12482
12483 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012485 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012486 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012488 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012489 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012493 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012494 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012519 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12520 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12521 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12522 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12523 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012524 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12536 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12537 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012542 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012543 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12545 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12546 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12547 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12548 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12549 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12550 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12551 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12553 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12554 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12555 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12556 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12557 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12558 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012559 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012560 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012561 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012562 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012563 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012564 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012565 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12566 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012567 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012568 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012569 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012570 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012571 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012572 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012573
12574 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12575 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12576 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012577 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012578 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12580 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012581 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012582 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12583 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12584 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12585 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12586 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12587 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12588 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12589 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12590 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12591 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12592 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12593 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012594 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12595 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12596 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12597 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12598 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012599 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12600 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12601 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12602 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12603 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12604 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12605 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12606 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12607 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012608 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012609 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012610 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012611 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012612 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012613 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012614 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012615
12616 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012618 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012619 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012621 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012622 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012626 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012627 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012652 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12653 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12654 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12655 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12656 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012657 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12669 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12670 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012675 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012676 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12678 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12679 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12683 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12686 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12689 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12690 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12691 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012692 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012693 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012694 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012695 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012696 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012697 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012698 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12699 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012700 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012701 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012702 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012703 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012704 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012705 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012706
12707 /* BGP dampening clear commands */
12708 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12709 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12710 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12711 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12712
Paul Jakmaff7924f2006-09-04 01:10:36 +000012713 /* prefix count */
12714 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12715 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12716 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012717#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012718 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12719
paul718e3742002-12-13 20:15:29 +000012720 /* New config IPv6 BGP commands. */
12721 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12722 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12723 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12724 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12725
12726 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12727 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12728 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12729 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12730
G.Balaji73bfe0b2011-09-23 22:36:20 +053012731 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12732 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12733
paul718e3742002-12-13 20:15:29 +000012734 /* Old config IPv6 BGP commands. */
12735 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12736 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12737
12738 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12739 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12740 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12741 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12742
12743 install_element (VIEW_NODE, &show_bgp_cmd);
12744 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012745 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012746 install_element (VIEW_NODE, &show_bgp_route_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012748 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012749 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12750 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012751 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012752 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12754 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12756 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12758 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12760 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12762 install_element (VIEW_NODE, &show_bgp_community_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12764 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12766 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12768 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12770 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12771 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12772 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12773 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12774 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12775 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12776 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12777 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12778 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12779 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12780 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12781 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12782 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12783 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12784 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12785 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12786 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12787 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12788 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12789 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12790 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12791 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012792 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12793 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12794 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12795 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012796 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012797 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012798 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012799 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012800 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012801 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012802 install_element (VIEW_NODE, &show_bgp_view_cmd);
12803 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12804 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12805 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12806 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12807 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12808 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12809 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12810 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12811 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12812 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12813 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12814 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12815 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12816 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12817 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12818 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12819 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012820 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012821 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012822 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012823 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012824 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012825 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012826
12827 /* Restricted:
12828 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12829 */
12830 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012832 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012833 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012835 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012836 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12837 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12838 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12839 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12840 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12841 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12842 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12843 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12844 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12845 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12846 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12847 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12848 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12849 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12850 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12851 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12852 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012853 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012854 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012855 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012856 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12857 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12858 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12859 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12860 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12861 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12862 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012863 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012864 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012865 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012866
12867 install_element (ENABLE_NODE, &show_bgp_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012869 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012870 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012872 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012873 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012875 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012876 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012916 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012920 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012921 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012922 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012923 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012924 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012925 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012926 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12930 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12931 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12932 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12933 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12934 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12935 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12936 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12937 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12938 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12939 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12940 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12942 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12943 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012944 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012945 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012946 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012947 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012948 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012949 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012950
12951 /* Statistics */
12952 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12953 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12954 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12955 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12956
paul718e3742002-12-13 20:15:29 +000012957 /* old command */
12958 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12966 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12967 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12968 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12969 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12970 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12971 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12980 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12981 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12982 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12983 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12984 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12985 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12986 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12987 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12988 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12989 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12990 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12991 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12992 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12993 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012994
paul718e3742002-12-13 20:15:29 +000012995 /* old command */
12996 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13004 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13005 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13006 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13007 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13008 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13009 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13018 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13019 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13020 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13021 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13022 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13023 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13024 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13025 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13026 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13027 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13028 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13029 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13030 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13031 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13032
13033 /* old command */
13034 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13035 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13036 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13037 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13038
13039 /* old command */
13040 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13041 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13042 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13043 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13044
13045 /* old command */
13046 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13047 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13048 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13049 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13050#endif /* HAVE_IPV6 */
13051
13052 install_element (BGP_NODE, &bgp_distance_cmd);
13053 install_element (BGP_NODE, &no_bgp_distance_cmd);
13054 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13055 install_element (BGP_NODE, &bgp_distance_source_cmd);
13056 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13057 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13058 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13059
13060 install_element (BGP_NODE, &bgp_damp_set_cmd);
13061 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13062 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13063 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13064 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13065 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13066 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13067 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13068 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13069 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013070
13071 /* Deprecated AS-Pathlimit commands */
13072 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13073 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13074 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13075 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13076 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13077 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13078
13079 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13080 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13081 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13082 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13083 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13084 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13085
13086 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13087 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13088 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13089 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13090 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13091 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13092
13093 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13094 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13095 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13096 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13097 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13098 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13099
13100 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13101 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13102 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13103 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13104 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13105 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13106
13107 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13108 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13109 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13110 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13111 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13112 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013113
13114#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013115 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13116 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013117#endif
paul718e3742002-12-13 20:15:29 +000013118}
Chris Caputo228da422009-07-18 05:44:03 +000013119
13120void
13121bgp_route_finish (void)
13122{
13123 bgp_table_unlock (bgp_distance_table);
13124 bgp_distance_table = NULL;
13125}