blob: 648dc9c857debee4efcf4386ea086410a60b15fd [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;
1348
1349 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001350 if (do_mpath)
1351 bgp_mp_list_add (&mp_list, ri1);
1352 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001353 if (ri1->next)
1354 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1355 {
1356 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1357 continue;
1358 if (BGP_INFO_HOLDDOWN (ri2))
1359 continue;
1360
1361 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1362 || aspath_cmp_left_confed (ri1->attr->aspath,
1363 ri2->attr->aspath))
1364 {
Josh Bailey6918e742011-07-20 20:48:20 -07001365 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1366 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001367 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001368 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001369 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001370 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001371 if (do_mpath && !paths_eq)
1372 {
1373 bgp_mp_list_clear (&mp_list);
1374 bgp_mp_list_add (&mp_list, ri2);
1375 }
paul718e3742002-12-13 20:15:29 +00001376 }
1377
Josh Bailey6918e742011-07-20 20:48:20 -07001378 if (do_mpath && paths_eq)
1379 bgp_mp_list_add (&mp_list, ri2);
1380
Paul Jakma1a392d42006-09-07 00:24:49 +00001381 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001382 }
1383 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001384 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1385 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001386
1387 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1388 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001389 }
1390
1391 /* Check old selected route and new selected route. */
1392 old_select = NULL;
1393 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001394 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001395 {
1396 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1397 old_select = ri;
1398
1399 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001400 {
1401 /* reap REMOVED routes, if needs be
1402 * selected route must stay for a while longer though
1403 */
1404 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1405 && (ri != old_select))
1406 bgp_info_reap (rn, ri);
1407
1408 continue;
1409 }
paul718e3742002-12-13 20:15:29 +00001410
1411 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1412 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1413 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001414 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001415 continue;
1416 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001417 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1418 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001419
Josh Bailey96450fa2011-07-20 20:45:12 -07001420 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1421 {
Josh Bailey6918e742011-07-20 20:48:20 -07001422 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1423 bgp_mp_dmed_deselect (new_select);
1424
Josh Bailey96450fa2011-07-20 20:45:12 -07001425 new_select = ri;
1426
1427 if (do_mpath && !paths_eq)
1428 {
1429 bgp_mp_list_clear (&mp_list);
1430 bgp_mp_list_add (&mp_list, ri);
1431 }
1432 }
Josh Bailey6918e742011-07-20 20:48:20 -07001433 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1434 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001435
1436 if (do_mpath && paths_eq)
1437 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001438 }
paulb40d9392005-08-22 22:34:41 +00001439
paulfee0f4c2004-09-13 05:12:46 +00001440
Josh Bailey6918e742011-07-20 20:48:20 -07001441 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1442 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001443
Josh Bailey0b597ef2011-07-20 20:49:11 -07001444 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001445 bgp_mp_list_clear (&mp_list);
1446
1447 result->old = old_select;
1448 result->new = new_select;
1449
1450 return;
paulfee0f4c2004-09-13 05:12:46 +00001451}
1452
paul94f2b392005-06-28 12:44:16 +00001453static int
paulfee0f4c2004-09-13 05:12:46 +00001454bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001455 struct bgp_node *rn, afi_t afi, safi_t safi)
1456{
paulfee0f4c2004-09-13 05:12:46 +00001457 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001458 struct attr attr;
1459 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001460
1461 p = &rn->p;
1462
Paul Jakma9eda90c2007-08-30 13:36:17 +00001463 /* Announce route to Established peer. */
1464 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001465 return 0;
1466
Paul Jakma9eda90c2007-08-30 13:36:17 +00001467 /* Address family configuration check. */
1468 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001469 return 0;
1470
Paul Jakma9eda90c2007-08-30 13:36:17 +00001471 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001472 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1473 PEER_STATUS_ORF_WAIT_REFRESH))
1474 return 0;
1475
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001476 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1477 attr.extra = &extra;
1478
Avneesh Sachdev67174042012-08-17 08:19:49 -07001479 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001480 {
1481 case BGP_TABLE_MAIN:
1482 /* Announcement to peer->conf. If the route is filtered,
1483 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001484 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1485 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001486 else
1487 bgp_adj_out_unset (rn, peer, p, afi, safi);
1488 break;
1489 case BGP_TABLE_RSCLIENT:
1490 /* Announcement to peer->conf. If the route is filtered,
1491 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001492 if (selected &&
1493 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1494 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1495 else
1496 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001497 break;
1498 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001499
paulfee0f4c2004-09-13 05:12:46 +00001500 return 0;
paul200df112005-06-01 11:17:05 +00001501}
paulfee0f4c2004-09-13 05:12:46 +00001502
paul200df112005-06-01 11:17:05 +00001503struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001504{
paul200df112005-06-01 11:17:05 +00001505 struct bgp *bgp;
1506 struct bgp_node *rn;
1507 afi_t afi;
1508 safi_t safi;
1509};
1510
1511static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001512bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001513{
paul0fb58d52005-11-14 14:31:49 +00001514 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001515 struct bgp *bgp = pq->bgp;
1516 struct bgp_node *rn = pq->rn;
1517 afi_t afi = pq->afi;
1518 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001519 struct bgp_info *new_select;
1520 struct bgp_info *old_select;
1521 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001522 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001523 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001524
paulfee0f4c2004-09-13 05:12:46 +00001525 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001526 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001527 new_select = old_and_new.new;
1528 old_select = old_and_new.old;
1529
paul200df112005-06-01 11:17:05 +00001530 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1531 {
Chris Caputo228da422009-07-18 05:44:03 +00001532 if (rsclient->group)
1533 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1534 {
1535 /* Nothing to do. */
1536 if (old_select && old_select == new_select)
1537 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1538 continue;
paulfee0f4c2004-09-13 05:12:46 +00001539
Chris Caputo228da422009-07-18 05:44:03 +00001540 if (old_select)
1541 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1542 if (new_select)
1543 {
1544 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1545 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001546 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1547 }
paulfee0f4c2004-09-13 05:12:46 +00001548
Chris Caputo228da422009-07-18 05:44:03 +00001549 bgp_process_announce_selected (rsclient, new_select, rn,
1550 afi, safi);
1551 }
paul200df112005-06-01 11:17:05 +00001552 }
1553 else
1554 {
hassob7395792005-08-26 12:58:38 +00001555 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001556 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001557 if (new_select)
1558 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001559 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1560 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001561 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001562 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001563 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001564 }
paulfee0f4c2004-09-13 05:12:46 +00001565
paulb40d9392005-08-22 22:34:41 +00001566 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1567 bgp_info_reap (rn, old_select);
1568
paul200df112005-06-01 11:17:05 +00001569 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1570 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001571}
1572
paul200df112005-06-01 11:17:05 +00001573static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001574bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001575{
paul0fb58d52005-11-14 14:31:49 +00001576 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001577 struct bgp *bgp = pq->bgp;
1578 struct bgp_node *rn = pq->rn;
1579 afi_t afi = pq->afi;
1580 safi_t safi = pq->safi;
1581 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001582 struct bgp_info *new_select;
1583 struct bgp_info *old_select;
1584 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001585 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001586 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001587
paulfee0f4c2004-09-13 05:12:46 +00001588 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001589 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001590 old_select = old_and_new.old;
1591 new_select = old_and_new.new;
1592
1593 /* Nothing to do. */
1594 if (old_select && old_select == new_select)
1595 {
1596 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001597 {
Josh Bailey8196f132011-07-20 20:47:07 -07001598 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1599 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001600 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001601
Josh Bailey8196f132011-07-20 20:47:07 -07001602 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001603 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1604 return WQ_SUCCESS;
1605 }
paulfee0f4c2004-09-13 05:12:46 +00001606 }
paul718e3742002-12-13 20:15:29 +00001607
hasso338b3422005-02-23 14:27:24 +00001608 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001609 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001610 if (new_select)
1611 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001612 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1613 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001614 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001615 }
1616
1617
paul718e3742002-12-13 20:15:29 +00001618 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001619 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001620 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001621 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001622 }
1623
1624 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001625 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1626 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001627 {
1628 if (new_select
1629 && new_select->type == ZEBRA_ROUTE_BGP
1630 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001631 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001632 else
1633 {
1634 /* Withdraw the route from the kernel. */
1635 if (old_select
1636 && old_select->type == ZEBRA_ROUTE_BGP
1637 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001638 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001639 }
1640 }
paulb40d9392005-08-22 22:34:41 +00001641
1642 /* Reap old select bgp_info, it it has been removed */
1643 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1644 bgp_info_reap (rn, old_select);
1645
paul200df112005-06-01 11:17:05 +00001646 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1647 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001648}
1649
paul200df112005-06-01 11:17:05 +00001650static void
paul0fb58d52005-11-14 14:31:49 +00001651bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001652{
paul0fb58d52005-11-14 14:31:49 +00001653 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001654 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001655
Chris Caputo228da422009-07-18 05:44:03 +00001656 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001657 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001658 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001659 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1660}
1661
1662static void
1663bgp_process_queue_init (void)
1664{
1665 bm->process_main_queue
1666 = work_queue_new (bm->master, "process_main_queue");
1667 bm->process_rsclient_queue
1668 = work_queue_new (bm->master, "process_rsclient_queue");
1669
1670 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1671 {
1672 zlog_err ("%s: Failed to allocate work queue", __func__);
1673 exit (1);
1674 }
1675
1676 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001677 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001678 bm->process_main_queue->spec.max_retries = 0;
1679 bm->process_main_queue->spec.hold = 50;
1680
Paul Jakma838bbde2010-01-08 14:05:32 +00001681 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001682 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1683 bm->process_rsclient_queue->spec.max_retries = 0;
1684 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001685}
1686
1687void
paulfee0f4c2004-09-13 05:12:46 +00001688bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1689{
paul200df112005-06-01 11:17:05 +00001690 struct bgp_process_queue *pqnode;
1691
1692 /* already scheduled for processing? */
1693 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1694 return;
1695
1696 if ( (bm->process_main_queue == NULL) ||
1697 (bm->process_rsclient_queue == NULL) )
1698 bgp_process_queue_init ();
1699
1700 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1701 sizeof (struct bgp_process_queue));
1702 if (!pqnode)
1703 return;
Chris Caputo228da422009-07-18 05:44:03 +00001704
1705 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001706 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001707 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001708 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001709 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001710 pqnode->afi = afi;
1711 pqnode->safi = safi;
1712
Avneesh Sachdev67174042012-08-17 08:19:49 -07001713 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001714 {
paul200df112005-06-01 11:17:05 +00001715 case BGP_TABLE_MAIN:
1716 work_queue_add (bm->process_main_queue, pqnode);
1717 break;
1718 case BGP_TABLE_RSCLIENT:
1719 work_queue_add (bm->process_rsclient_queue, pqnode);
1720 break;
paulfee0f4c2004-09-13 05:12:46 +00001721 }
paul200df112005-06-01 11:17:05 +00001722
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001723 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001724 return;
paulfee0f4c2004-09-13 05:12:46 +00001725}
hasso0a486e52005-02-01 20:57:17 +00001726
paul94f2b392005-06-28 12:44:16 +00001727static int
hasso0a486e52005-02-01 20:57:17 +00001728bgp_maximum_prefix_restart_timer (struct thread *thread)
1729{
1730 struct peer *peer;
1731
1732 peer = THREAD_ARG (thread);
1733 peer->t_pmax_restart = NULL;
1734
1735 if (BGP_DEBUG (events, EVENTS))
1736 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1737 peer->host);
1738
1739 peer_clear (peer);
1740
1741 return 0;
1742}
1743
paulfee0f4c2004-09-13 05:12:46 +00001744int
paul5228ad22004-06-04 17:58:18 +00001745bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1746 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001747{
hassoe0701b72004-05-20 09:19:34 +00001748 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1749 return 0;
1750
1751 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001752 {
hassoe0701b72004-05-20 09:19:34 +00001753 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1754 && ! always)
1755 return 0;
paul718e3742002-12-13 20:15:29 +00001756
hassoe0701b72004-05-20 09:19:34 +00001757 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001758 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1759 "limit %ld", afi_safi_print (afi, safi), peer->host,
1760 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001761 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001762
hassoe0701b72004-05-20 09:19:34 +00001763 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1764 return 0;
paul718e3742002-12-13 20:15:29 +00001765
hassoe0701b72004-05-20 09:19:34 +00001766 {
paul5228ad22004-06-04 17:58:18 +00001767 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001768
1769 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001770 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001771
1772 ndata[0] = (afi >> 8);
1773 ndata[1] = afi;
1774 ndata[2] = safi;
1775 ndata[3] = (peer->pmax[afi][safi] >> 24);
1776 ndata[4] = (peer->pmax[afi][safi] >> 16);
1777 ndata[5] = (peer->pmax[afi][safi] >> 8);
1778 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001779
1780 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1781 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1782 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1783 }
hasso0a486e52005-02-01 20:57:17 +00001784
1785 /* restart timer start */
1786 if (peer->pmax_restart[afi][safi])
1787 {
1788 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1789
1790 if (BGP_DEBUG (events, EVENTS))
1791 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1792 peer->host, peer->v_pmax_restart);
1793
1794 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1795 peer->v_pmax_restart);
1796 }
1797
hassoe0701b72004-05-20 09:19:34 +00001798 return 1;
paul718e3742002-12-13 20:15:29 +00001799 }
hassoe0701b72004-05-20 09:19:34 +00001800 else
1801 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1802
1803 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1804 {
1805 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1806 && ! always)
1807 return 0;
1808
1809 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001810 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1811 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1812 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001813 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1814 }
1815 else
1816 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001817 return 0;
1818}
1819
paulb40d9392005-08-22 22:34:41 +00001820/* Unconditionally remove the route from the RIB, without taking
1821 * damping into consideration (eg, because the session went down)
1822 */
paul94f2b392005-06-28 12:44:16 +00001823static void
paul718e3742002-12-13 20:15:29 +00001824bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1825 afi_t afi, safi_t safi)
1826{
paul902212c2006-02-05 17:51:19 +00001827 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1828
1829 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1830 bgp_info_delete (rn, ri); /* keep historical info */
1831
paulb40d9392005-08-22 22:34:41 +00001832 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001833}
1834
paul94f2b392005-06-28 12:44:16 +00001835static void
paul718e3742002-12-13 20:15:29 +00001836bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001837 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001838{
paul718e3742002-12-13 20:15:29 +00001839 int status = BGP_DAMP_NONE;
1840
paulb40d9392005-08-22 22:34:41 +00001841 /* apply dampening, if result is suppressed, we'll be retaining
1842 * the bgp_info in the RIB for historical reference.
1843 */
1844 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001845 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001846 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1847 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001848 {
paul902212c2006-02-05 17:51:19 +00001849 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1850 return;
1851 }
1852
1853 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001854}
1855
paul94f2b392005-06-28 12:44:16 +00001856static void
paulfee0f4c2004-09-13 05:12:46 +00001857bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1858 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1859 int sub_type, struct prefix_rd *prd, u_char *tag)
1860{
1861 struct bgp_node *rn;
1862 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001863 struct attr new_attr;
1864 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001865 struct attr *attr_new;
1866 struct attr *attr_new2;
1867 struct bgp_info *ri;
1868 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001869 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001870 char buf[SU_ADDRSTRLEN];
1871
1872 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1873 if (peer == rsclient)
1874 return;
1875
1876 bgp = peer->bgp;
1877 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1878
1879 /* Check previously received route. */
1880 for (ri = rn->info; ri; ri = ri->next)
1881 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1882 break;
1883
1884 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001885 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001886 {
1887 reason = "as-path contains our own AS;";
1888 goto filtered;
1889 }
1890
1891 /* Route reflector originator ID check. */
1892 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001893 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001894 {
1895 reason = "originator is us;";
1896 goto filtered;
1897 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001898
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001899 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001900 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001901
1902 /* Apply export policy. */
1903 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1904 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1905 {
1906 reason = "export-policy;";
1907 goto filtered;
1908 }
1909
1910 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001911
paulfee0f4c2004-09-13 05:12:46 +00001912 /* Apply import policy. */
1913 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1914 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001915 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001916
1917 reason = "import-policy;";
1918 goto filtered;
1919 }
1920
1921 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001922 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001923
1924 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001925 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001926 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001927 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001928 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001929 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001930 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001931 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001932
1933 reason = "martian next-hop;";
1934 goto filtered;
1935 }
1936 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001937
paulfee0f4c2004-09-13 05:12:46 +00001938 /* If the update is implicit withdraw. */
1939 if (ri)
1940 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001941 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001942
1943 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001944 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1945 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001946 {
1947
Paul Jakma1a392d42006-09-07 00:24:49 +00001948 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001949
1950 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001951 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001952 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1953 peer->host,
1954 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1955 p->prefixlen, rsclient->host);
1956
Chris Caputo228da422009-07-18 05:44:03 +00001957 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001958 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001959
Chris Caputo228da422009-07-18 05:44:03 +00001960 return;
paulfee0f4c2004-09-13 05:12:46 +00001961 }
1962
Paul Jakma16d2e242007-04-10 19:32:10 +00001963 /* Withdraw/Announce before we fully processed the withdraw */
1964 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1965 bgp_info_restore (rn, ri);
1966
paulfee0f4c2004-09-13 05:12:46 +00001967 /* Received Logging. */
1968 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001969 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001970 peer->host,
1971 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1972 p->prefixlen, rsclient->host);
1973
1974 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001975 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001976
1977 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001978 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001979 ri->attr = attr_new;
1980
1981 /* Update MPLS tag. */
1982 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001983 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001984
Paul Jakma1a392d42006-09-07 00:24:49 +00001985 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001986
1987 /* Process change. */
1988 bgp_process (bgp, rn, afi, safi);
1989 bgp_unlock_node (rn);
1990
1991 return;
1992 }
1993
1994 /* Received Logging. */
1995 if (BGP_DEBUG (update, UPDATE_IN))
1996 {
ajsd2c1f162004-12-08 21:10:20 +00001997 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001998 peer->host,
1999 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2000 p->prefixlen, rsclient->host);
2001 }
2002
2003 /* Make new BGP info. */
2004 new = bgp_info_new ();
2005 new->type = type;
2006 new->sub_type = sub_type;
2007 new->peer = peer;
2008 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002009 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002010
2011 /* Update MPLS tag. */
2012 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002013 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002014
Paul Jakma1a392d42006-09-07 00:24:49 +00002015 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002016
2017 /* Register new BGP information. */
2018 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002019
2020 /* route_node_get lock */
2021 bgp_unlock_node (rn);
2022
paulfee0f4c2004-09-13 05:12:46 +00002023 /* Process change. */
2024 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002025
paulfee0f4c2004-09-13 05:12:46 +00002026 return;
2027
2028 filtered:
2029
2030 /* This BGP update is filtered. Log the reason then update BGP entry. */
2031 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002032 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002033 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2034 peer->host,
2035 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2036 p->prefixlen, rsclient->host, reason);
2037
2038 if (ri)
paulb40d9392005-08-22 22:34:41 +00002039 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002040
2041 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002042
paulfee0f4c2004-09-13 05:12:46 +00002043 return;
2044}
2045
paul94f2b392005-06-28 12:44:16 +00002046static void
paulfee0f4c2004-09-13 05:12:46 +00002047bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2048 struct peer *peer, struct prefix *p, int type, int sub_type,
2049 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002050{
paulfee0f4c2004-09-13 05:12:46 +00002051 struct bgp_node *rn;
2052 struct bgp_info *ri;
2053 char buf[SU_ADDRSTRLEN];
2054
2055 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002056 return;
paulfee0f4c2004-09-13 05:12:46 +00002057
2058 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2059
2060 /* Lookup withdrawn route. */
2061 for (ri = rn->info; ri; ri = ri->next)
2062 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2063 break;
2064
2065 /* Withdraw specified route from routing table. */
2066 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002067 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002068 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002069 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002070 "%s Can't find the route %s/%d", peer->host,
2071 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2072 p->prefixlen);
2073
2074 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002075 bgp_unlock_node (rn);
2076}
paulfee0f4c2004-09-13 05:12:46 +00002077
paul94f2b392005-06-28 12:44:16 +00002078static int
paulfee0f4c2004-09-13 05:12:46 +00002079bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002080 afi_t afi, safi_t safi, int type, int sub_type,
2081 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2082{
2083 int ret;
2084 int aspath_loop_count = 0;
2085 struct bgp_node *rn;
2086 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002087 struct attr new_attr;
2088 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002089 struct attr *attr_new;
2090 struct bgp_info *ri;
2091 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002092 const char *reason;
paul718e3742002-12-13 20:15:29 +00002093 char buf[SU_ADDRSTRLEN];
2094
2095 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002096 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002097
paul718e3742002-12-13 20:15:29 +00002098 /* When peer's soft reconfiguration enabled. Record input packet in
2099 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002100 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2101 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002102 bgp_adj_in_set (rn, peer, attr);
2103
2104 /* Check previously received route. */
2105 for (ri = rn->info; ri; ri = ri->next)
2106 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2107 break;
2108
2109 /* AS path local-as loop check. */
2110 if (peer->change_local_as)
2111 {
2112 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2113 aspath_loop_count = 1;
2114
2115 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2116 {
2117 reason = "as-path contains our own AS;";
2118 goto filtered;
2119 }
2120 }
2121
2122 /* AS path loop check. */
2123 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2124 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2125 && aspath_loop_check(attr->aspath, bgp->confed_id)
2126 > peer->allowas_in[afi][safi]))
2127 {
2128 reason = "as-path contains our own AS;";
2129 goto filtered;
2130 }
2131
2132 /* Route reflector originator ID check. */
2133 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002134 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002135 {
2136 reason = "originator is us;";
2137 goto filtered;
2138 }
2139
2140 /* Route reflector cluster ID check. */
2141 if (bgp_cluster_filter (peer, attr))
2142 {
2143 reason = "reflected from the same cluster;";
2144 goto filtered;
2145 }
2146
2147 /* Apply incoming filter. */
2148 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2149 {
2150 reason = "filter;";
2151 goto filtered;
2152 }
2153
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002154 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002155 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002156
David Lamparterc460e572014-06-04 00:54:58 +02002157 /* Apply incoming route-map.
2158 * NB: new_attr may now contain newly allocated values from route-map "set"
2159 * commands, so we need bgp_attr_flush in the error paths, until we intern
2160 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002161 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2162 {
2163 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002164 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002165 goto filtered;
2166 }
2167
2168 /* IPv4 unicast next hop check. */
2169 if (afi == AFI_IP && safi == SAFI_UNICAST)
2170 {
2171 /* If the peer is EBGP and nexthop is not on connected route,
2172 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002173 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002174 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002175 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002176 {
2177 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002178 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002179 goto filtered;
2180 }
2181
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002182 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002183 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002184 if (new_attr.nexthop.s_addr == 0
2185 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2186 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002187 {
2188 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002189 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002190 goto filtered;
2191 }
2192 }
2193
2194 attr_new = bgp_attr_intern (&new_attr);
2195
2196 /* If the update is implicit withdraw. */
2197 if (ri)
2198 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002199 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002200
2201 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002202 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2203 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002204 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002205 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002206
2207 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002208 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002209 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2210 {
2211 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002212 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002213 peer->host,
2214 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2215 p->prefixlen);
2216
paul902212c2006-02-05 17:51:19 +00002217 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2218 {
2219 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2220 bgp_process (bgp, rn, afi, safi);
2221 }
paul718e3742002-12-13 20:15:29 +00002222 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002223 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002224 {
2225 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002226 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002227 "%s rcvd %s/%d...duplicate ignored",
2228 peer->host,
2229 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2230 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002231
2232 /* graceful restart STALE flag unset. */
2233 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2234 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002235 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002236 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002237 }
paul718e3742002-12-13 20:15:29 +00002238 }
2239
2240 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002241 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002242
paul718e3742002-12-13 20:15:29 +00002243 return 0;
2244 }
2245
Paul Jakma16d2e242007-04-10 19:32:10 +00002246 /* Withdraw/Announce before we fully processed the withdraw */
2247 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2248 {
2249 if (BGP_DEBUG (update, UPDATE_IN))
2250 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2251 peer->host,
2252 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2253 p->prefixlen);
2254 bgp_info_restore (rn, ri);
2255 }
2256
paul718e3742002-12-13 20:15:29 +00002257 /* Received Logging. */
2258 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002259 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002260 peer->host,
2261 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2262 p->prefixlen);
2263
hasso93406d82005-02-02 14:40:33 +00002264 /* graceful restart STALE flag unset. */
2265 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002266 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002267
paul718e3742002-12-13 20:15:29 +00002268 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002269 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002270
2271 /* implicit withdraw, decrement aggregate and pcount here.
2272 * only if update is accepted, they'll increment below.
2273 */
paul902212c2006-02-05 17:51:19 +00002274 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2275
paul718e3742002-12-13 20:15:29 +00002276 /* Update bgp route dampening information. */
2277 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002278 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002279 {
2280 /* This is implicit withdraw so we should update dampening
2281 information. */
2282 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2283 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002284 }
2285
paul718e3742002-12-13 20:15:29 +00002286 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002287 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002288 ri->attr = attr_new;
2289
2290 /* Update MPLS tag. */
2291 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002292 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002293
2294 /* Update bgp route dampening information. */
2295 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002296 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002297 {
2298 /* Now we do normal update dampening. */
2299 ret = bgp_damp_update (ri, rn, afi, safi);
2300 if (ret == BGP_DAMP_SUPPRESSED)
2301 {
2302 bgp_unlock_node (rn);
2303 return 0;
2304 }
2305 }
2306
2307 /* Nexthop reachability check. */
2308 if ((afi == AFI_IP || afi == AFI_IP6)
2309 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002310 && (peer->sort == BGP_PEER_IBGP
2311 || peer->sort == BGP_PEER_CONFED
2312 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002313 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002314 {
2315 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002316 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002317 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002318 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002319 }
2320 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002321 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002322
2323 /* Process change. */
2324 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2325
2326 bgp_process (bgp, rn, afi, safi);
2327 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002328
paul718e3742002-12-13 20:15:29 +00002329 return 0;
2330 }
2331
2332 /* Received Logging. */
2333 if (BGP_DEBUG (update, UPDATE_IN))
2334 {
ajsd2c1f162004-12-08 21:10:20 +00002335 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002336 peer->host,
2337 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2338 p->prefixlen);
2339 }
2340
paul718e3742002-12-13 20:15:29 +00002341 /* Make new BGP info. */
2342 new = bgp_info_new ();
2343 new->type = type;
2344 new->sub_type = sub_type;
2345 new->peer = peer;
2346 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002347 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002348
2349 /* Update MPLS tag. */
2350 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002351 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002352
2353 /* Nexthop reachability check. */
2354 if ((afi == AFI_IP || afi == AFI_IP6)
2355 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002356 && (peer->sort == BGP_PEER_IBGP
2357 || peer->sort == BGP_PEER_CONFED
2358 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002359 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002360 {
2361 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002362 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002363 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002364 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002365 }
2366 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002367 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002368
paul902212c2006-02-05 17:51:19 +00002369 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002370 bgp_aggregate_increment (bgp, p, new, afi, safi);
2371
2372 /* Register new BGP information. */
2373 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002374
2375 /* route_node_get lock */
2376 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002377
paul718e3742002-12-13 20:15:29 +00002378 /* If maximum prefix count is configured and current prefix
2379 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002380 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2381 return -1;
paul718e3742002-12-13 20:15:29 +00002382
2383 /* Process change. */
2384 bgp_process (bgp, rn, afi, safi);
2385
2386 return 0;
2387
2388 /* This BGP update is filtered. Log the reason then update BGP
2389 entry. */
2390 filtered:
2391 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002392 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002393 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2394 peer->host,
2395 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2396 p->prefixlen, reason);
2397
2398 if (ri)
paulb40d9392005-08-22 22:34:41 +00002399 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002400
2401 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002402
paul718e3742002-12-13 20:15:29 +00002403 return 0;
2404}
2405
2406int
paulfee0f4c2004-09-13 05:12:46 +00002407bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2408 afi_t afi, safi_t safi, int type, int sub_type,
2409 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2410{
2411 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002412 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002413 struct bgp *bgp;
2414 int ret;
2415
2416 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2417 soft_reconfig);
2418
2419 bgp = peer->bgp;
2420
2421 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002422 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002423 {
2424 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2425 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2426 sub_type, prd, tag);
2427 }
2428
2429 return ret;
2430}
2431
2432int
paul718e3742002-12-13 20:15:29 +00002433bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002434 afi_t afi, safi_t safi, int type, int sub_type,
2435 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002436{
2437 struct bgp *bgp;
2438 char buf[SU_ADDRSTRLEN];
2439 struct bgp_node *rn;
2440 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002441 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002442 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002443
2444 bgp = peer->bgp;
2445
David Lamparter4584c232015-04-13 09:50:00 +02002446 /* Lookup node. */
2447 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2448
2449 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2450 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2451 * the iteration over all RS clients.
2452 * Since we need to remove the entry from adj_in anyway, do that first and
2453 * if there was no entry, we don't need to do anything more. */
2454 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2455 && peer != bgp->peer_self)
2456 if (!bgp_adj_in_unset (rn, peer))
2457 {
2458 if (BGP_DEBUG (update, UPDATE_IN))
2459 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2460 "not in adj-in", peer->host,
2461 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2462 p->prefixlen);
2463 bgp_unlock_node (rn);
2464 return 0;
2465 }
2466
paulfee0f4c2004-09-13 05:12:46 +00002467 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002468 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002469 {
2470 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2471 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2472 }
2473
paul718e3742002-12-13 20:15:29 +00002474 /* Logging. */
2475 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002476 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002477 peer->host,
2478 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2479 p->prefixlen);
2480
paul718e3742002-12-13 20:15:29 +00002481 /* Lookup withdrawn route. */
2482 for (ri = rn->info; ri; ri = ri->next)
2483 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2484 break;
2485
2486 /* Withdraw specified route from routing table. */
2487 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002488 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002489 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002490 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002491 "%s Can't find the route %s/%d", peer->host,
2492 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2493 p->prefixlen);
2494
2495 /* Unlock bgp_node_get() lock. */
2496 bgp_unlock_node (rn);
2497
2498 return 0;
2499}
David Lamparter6b0655a2014-06-04 06:53:35 +02002500
paul718e3742002-12-13 20:15:29 +00002501void
2502bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2503{
2504 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002505 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002506 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002507 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002508 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002509 struct bgp_node *rn;
2510 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002511 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002512
Paul Jakmab2497022007-06-14 11:17:58 +00002513 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002514 return;
2515
paul718e3742002-12-13 20:15:29 +00002516 bgp = peer->bgp;
2517 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002518
paul718e3742002-12-13 20:15:29 +00002519 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2520 aspath = attr.aspath;
2521 attr.local_pref = bgp->default_local_pref;
2522 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2523
2524 if (afi == AFI_IP)
2525 str2prefix ("0.0.0.0/0", &p);
2526#ifdef HAVE_IPV6
2527 else if (afi == AFI_IP6)
2528 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002529 struct attr_extra *ae = attr.extra;
2530
paul718e3742002-12-13 20:15:29 +00002531 str2prefix ("::/0", &p);
2532
2533 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002534 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002535 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002536 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002537
2538 /* If the peer is on shared nextwork and we have link-local
2539 nexthop set it. */
2540 if (peer->shared_network
2541 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2542 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002543 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002544 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002545 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002546 }
2547 }
2548#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002549
2550 if (peer->default_rmap[afi][safi].name)
2551 {
paulfee0f4c2004-09-13 05:12:46 +00002552 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002553 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2554 {
2555 for (ri = rn->info; ri; ri = ri->next)
2556 {
2557 struct attr dummy_attr;
2558 struct attr_extra dummy_extra;
2559 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002560
Christian Frankedcab1bb2012-12-07 16:45:52 +00002561 /* Provide dummy so the route-map can't modify the attributes */
2562 dummy_attr.extra = &dummy_extra;
2563 bgp_attr_dup(&dummy_attr, ri->attr);
2564 info.peer = ri->peer;
2565 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002566
Christian Frankedcab1bb2012-12-07 16:45:52 +00002567 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2568 RMAP_BGP, &info);
2569
2570 /* The route map might have set attributes. If we don't flush them
2571 * here, they will be leaked. */
2572 bgp_attr_flush(&dummy_attr);
2573 if (ret != RMAP_DENYMATCH)
2574 break;
2575 }
2576 if (ret != RMAP_DENYMATCH)
2577 break;
2578 }
paulfee0f4c2004-09-13 05:12:46 +00002579 bgp->peer_self->rmap_type = 0;
2580
paul718e3742002-12-13 20:15:29 +00002581 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002582 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002583 }
2584
2585 if (withdraw)
2586 {
2587 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2588 bgp_default_withdraw_send (peer, afi, safi);
2589 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2590 }
2591 else
2592 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002593 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2594 {
2595 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2596 bgp_default_update_send (peer, &attr, afi, safi, from);
2597 }
paul718e3742002-12-13 20:15:29 +00002598 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002599
2600 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002601 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002602}
David Lamparter6b0655a2014-06-04 06:53:35 +02002603
paul718e3742002-12-13 20:15:29 +00002604static void
2605bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002606 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002607{
2608 struct bgp_node *rn;
2609 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002610 struct attr attr;
2611 struct attr_extra extra;
2612
paul718e3742002-12-13 20:15:29 +00002613 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002614 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002615
2616 if (safi != SAFI_MPLS_VPN
2617 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2618 bgp_default_originate (peer, afi, safi, 0);
2619
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002620 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2621 attr.extra = &extra;
2622
paul718e3742002-12-13 20:15:29 +00002623 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2624 for (ri = rn->info; ri; ri = ri->next)
2625 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2626 {
paulfee0f4c2004-09-13 05:12:46 +00002627 if ( (rsclient) ?
2628 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2629 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002630 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2631 else
2632 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2633 }
2634}
2635
2636void
2637bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2638{
2639 struct bgp_node *rn;
2640 struct bgp_table *table;
2641
2642 if (peer->status != Established)
2643 return;
2644
2645 if (! peer->afc_nego[afi][safi])
2646 return;
2647
2648 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2649 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2650 return;
2651
2652 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002653 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002654 else
2655 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2656 rn = bgp_route_next(rn))
2657 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002658 bgp_announce_table (peer, afi, safi, table, 0);
2659
2660 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2661 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002662}
2663
2664void
2665bgp_announce_route_all (struct peer *peer)
2666{
2667 afi_t afi;
2668 safi_t safi;
2669
2670 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2671 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2672 bgp_announce_route (peer, afi, safi);
2673}
David Lamparter6b0655a2014-06-04 06:53:35 +02002674
paul718e3742002-12-13 20:15:29 +00002675static void
paulfee0f4c2004-09-13 05:12:46 +00002676bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002677 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002678{
2679 struct bgp_node *rn;
2680 struct bgp_adj_in *ain;
2681
2682 if (! table)
2683 table = rsclient->bgp->rib[afi][safi];
2684
2685 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2686 for (ain = rn->adj_in; ain; ain = ain->next)
2687 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002688 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002689 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002690
paulfee0f4c2004-09-13 05:12:46 +00002691 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002692 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002693 }
2694}
2695
2696void
2697bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2698{
2699 struct bgp_table *table;
2700 struct bgp_node *rn;
2701
2702 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002703 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002704
2705 else
2706 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2707 rn = bgp_route_next (rn))
2708 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002709 {
2710 struct prefix_rd prd;
2711 prd.family = AF_UNSPEC;
2712 prd.prefixlen = 64;
2713 memcpy(&prd.val, rn->p.u.val, 8);
2714
2715 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2716 }
paulfee0f4c2004-09-13 05:12:46 +00002717}
David Lamparter6b0655a2014-06-04 06:53:35 +02002718
paulfee0f4c2004-09-13 05:12:46 +00002719static void
paul718e3742002-12-13 20:15:29 +00002720bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002721 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002722{
2723 int ret;
2724 struct bgp_node *rn;
2725 struct bgp_adj_in *ain;
2726
2727 if (! table)
2728 table = peer->bgp->rib[afi][safi];
2729
2730 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2731 for (ain = rn->adj_in; ain; ain = ain->next)
2732 {
2733 if (ain->peer == peer)
2734 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002735 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002736 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002737
paul718e3742002-12-13 20:15:29 +00002738 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2739 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002740 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002741
paul718e3742002-12-13 20:15:29 +00002742 if (ret < 0)
2743 {
2744 bgp_unlock_node (rn);
2745 return;
2746 }
2747 continue;
2748 }
2749 }
2750}
2751
2752void
2753bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2754{
2755 struct bgp_node *rn;
2756 struct bgp_table *table;
2757
2758 if (peer->status != Established)
2759 return;
2760
2761 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002762 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002763 else
2764 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2765 rn = bgp_route_next (rn))
2766 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002767 {
2768 struct prefix_rd prd;
2769 prd.family = AF_UNSPEC;
2770 prd.prefixlen = 64;
2771 memcpy(&prd.val, rn->p.u.val, 8);
2772
2773 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2774 }
paul718e3742002-12-13 20:15:29 +00002775}
David Lamparter6b0655a2014-06-04 06:53:35 +02002776
Chris Caputo228da422009-07-18 05:44:03 +00002777
2778struct bgp_clear_node_queue
2779{
2780 struct bgp_node *rn;
2781 enum bgp_clear_route_type purpose;
2782};
2783
paul200df112005-06-01 11:17:05 +00002784static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002785bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002786{
Chris Caputo228da422009-07-18 05:44:03 +00002787 struct bgp_clear_node_queue *cnq = data;
2788 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002789 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002790 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002791 afi_t afi = bgp_node_table (rn)->afi;
2792 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002793
Paul Jakma64e580a2006-02-21 01:09:01 +00002794 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002795
Paul Jakma64e580a2006-02-21 01:09:01 +00002796 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002797 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002798 {
2799 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002800 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2801 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002802 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002803 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2804 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002805 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002806 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002807 break;
2808 }
paul200df112005-06-01 11:17:05 +00002809 return WQ_SUCCESS;
2810}
2811
2812static void
paul0fb58d52005-11-14 14:31:49 +00002813bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002814{
Chris Caputo228da422009-07-18 05:44:03 +00002815 struct bgp_clear_node_queue *cnq = data;
2816 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002817 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002818
2819 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002820 bgp_table_unlock (table);
2821 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002822}
2823
2824static void
paul94f2b392005-06-28 12:44:16 +00002825bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002826{
Paul Jakma64e580a2006-02-21 01:09:01 +00002827 struct peer *peer = wq->spec.data;
2828
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002829 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002830 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002831
2832 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002833}
2834
2835static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002836bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002837{
Paul Jakmaa2943652009-07-21 14:02:04 +01002838 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002839
Paul Jakmaa2943652009-07-21 14:02:04 +01002840 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002841#undef CLEAR_QUEUE_NAME_LEN
2842
2843 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002844 {
2845 zlog_err ("%s: Failed to allocate work queue", __func__);
2846 exit (1);
2847 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002848 peer->clear_node_queue->spec.hold = 10;
2849 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2850 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2851 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2852 peer->clear_node_queue->spec.max_retries = 0;
2853
2854 /* we only 'lock' this peer reference when the queue is actually active */
2855 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002856}
2857
paul718e3742002-12-13 20:15:29 +00002858static void
2859bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002860 struct bgp_table *table, struct peer *rsclient,
2861 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002862{
2863 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002864
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002865
paul718e3742002-12-13 20:15:29 +00002866 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002867 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002868
hasso6cf159b2005-03-21 10:28:14 +00002869 /* If still no table => afi/safi isn't configured at all or smth. */
2870 if (! table)
2871 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002872
2873 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2874 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002875 struct bgp_info *ri;
2876 struct bgp_adj_in *ain;
2877 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002878
2879 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2880 * queued for every clearing peer, regardless of whether it is
2881 * relevant to the peer at hand.
2882 *
2883 * Overview: There are 3 different indices which need to be
2884 * scrubbed, potentially, when a peer is removed:
2885 *
2886 * 1 peer's routes visible via the RIB (ie accepted routes)
2887 * 2 peer's routes visible by the (optional) peer's adj-in index
2888 * 3 other routes visible by the peer's adj-out index
2889 *
2890 * 3 there is no hurry in scrubbing, once the struct peer is
2891 * removed from bgp->peer, we could just GC such deleted peer's
2892 * adj-outs at our leisure.
2893 *
2894 * 1 and 2 must be 'scrubbed' in some way, at least made
2895 * invisible via RIB index before peer session is allowed to be
2896 * brought back up. So one needs to know when such a 'search' is
2897 * complete.
2898 *
2899 * Ideally:
2900 *
2901 * - there'd be a single global queue or a single RIB walker
2902 * - rather than tracking which route_nodes still need to be
2903 * examined on a peer basis, we'd track which peers still
2904 * aren't cleared
2905 *
2906 * Given that our per-peer prefix-counts now should be reliable,
2907 * this may actually be achievable. It doesn't seem to be a huge
2908 * problem at this time,
2909 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002910 for (ain = rn->adj_in; ain; ain = ain->next)
2911 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2912 {
2913 bgp_adj_in_remove (rn, ain);
2914 bgp_unlock_node (rn);
2915 break;
2916 }
2917 for (aout = rn->adj_out; aout; aout = aout->next)
2918 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2919 {
2920 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2921 bgp_unlock_node (rn);
2922 break;
2923 }
2924
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002925 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002926 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002927 {
Chris Caputo228da422009-07-18 05:44:03 +00002928 struct bgp_clear_node_queue *cnq;
2929
2930 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002931 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002932 bgp_lock_node (rn);
2933 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2934 sizeof (struct bgp_clear_node_queue));
2935 cnq->rn = rn;
2936 cnq->purpose = purpose;
2937 work_queue_add (peer->clear_node_queue, cnq);
2938 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002939 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002940 }
2941 return;
2942}
2943
2944void
Chris Caputo228da422009-07-18 05:44:03 +00002945bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2946 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002947{
2948 struct bgp_node *rn;
2949 struct bgp_table *table;
2950 struct peer *rsclient;
2951 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002952
Paul Jakma64e580a2006-02-21 01:09:01 +00002953 if (peer->clear_node_queue == NULL)
2954 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002955
Paul Jakmaca058a32006-09-14 02:58:49 +00002956 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2957 * Idle until it receives a Clearing_Completed event. This protects
2958 * against peers which flap faster than we can we clear, which could
2959 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002960 *
2961 * a) race with routes from the new session being installed before
2962 * clear_route_node visits the node (to delete the route of that
2963 * peer)
2964 * b) resource exhaustion, clear_route_node likely leads to an entry
2965 * on the process_main queue. Fast-flapping could cause that queue
2966 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002967 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002968 if (!peer->clear_node_queue->thread)
2969 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002970
Chris Caputo228da422009-07-18 05:44:03 +00002971 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002972 {
Chris Caputo228da422009-07-18 05:44:03 +00002973 case BGP_CLEAR_ROUTE_NORMAL:
2974 if (safi != SAFI_MPLS_VPN)
2975 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2976 else
2977 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2978 rn = bgp_route_next (rn))
2979 if ((table = rn->info) != NULL)
2980 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2981
2982 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2983 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2984 PEER_FLAG_RSERVER_CLIENT))
2985 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2986 break;
2987
2988 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2989 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2990 break;
2991
2992 default:
2993 assert (0);
2994 break;
paulfee0f4c2004-09-13 05:12:46 +00002995 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002996
Paul Jakmaca058a32006-09-14 02:58:49 +00002997 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002998 * completion function won't be run by workqueue code - call it here.
2999 * XXX: Actually, this assumption doesn't hold, see
3000 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00003001 *
3002 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00003003 * really needed if peer state is Established - peers in
3004 * pre-Established states shouldn't have any route-update state
3005 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00003006 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00003007 * We still can get here in pre-Established though, through
3008 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
3009 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00003010 *
3011 * At some future point, this check could be move to the top of the
3012 * function, and do a quick early-return when state is
3013 * pre-Established, avoiding above list and table scans. Once we're
3014 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00003015 */
3016 if (!peer->clear_node_queue->thread)
3017 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00003018}
3019
3020void
3021bgp_clear_route_all (struct peer *peer)
3022{
3023 afi_t afi;
3024 safi_t safi;
3025
3026 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3027 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003028 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003029}
3030
3031void
3032bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3033{
3034 struct bgp_table *table;
3035 struct bgp_node *rn;
3036 struct bgp_adj_in *ain;
3037
3038 table = peer->bgp->rib[afi][safi];
3039
3040 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3041 for (ain = rn->adj_in; ain ; ain = ain->next)
3042 if (ain->peer == peer)
3043 {
3044 bgp_adj_in_remove (rn, ain);
3045 bgp_unlock_node (rn);
3046 break;
3047 }
3048}
hasso93406d82005-02-02 14:40:33 +00003049
3050void
3051bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3052{
3053 struct bgp_node *rn;
3054 struct bgp_info *ri;
3055 struct bgp_table *table;
3056
3057 table = peer->bgp->rib[afi][safi];
3058
3059 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3060 {
3061 for (ri = rn->info; ri; ri = ri->next)
3062 if (ri->peer == peer)
3063 {
3064 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3065 bgp_rib_remove (rn, ri, peer, afi, safi);
3066 break;
3067 }
3068 }
3069}
David Lamparter6b0655a2014-06-04 06:53:35 +02003070
paul718e3742002-12-13 20:15:29 +00003071/* Delete all kernel routes. */
3072void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003073bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003074{
3075 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003076 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003077 struct bgp_node *rn;
3078 struct bgp_table *table;
3079 struct bgp_info *ri;
3080
paul1eb8ef22005-04-07 07:30:20 +00003081 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003082 {
3083 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3084
3085 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3086 for (ri = rn->info; ri; ri = ri->next)
3087 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3088 && ri->type == ZEBRA_ROUTE_BGP
3089 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003090 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003091
3092 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3093
3094 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3095 for (ri = rn->info; ri; ri = ri->next)
3096 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3097 && ri->type == ZEBRA_ROUTE_BGP
3098 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003099 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003100 }
3101}
3102
3103void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003104bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003105{
3106 vty_reset ();
3107 bgp_zclient_reset ();
3108 access_list_reset ();
3109 prefix_list_reset ();
3110}
David Lamparter6b0655a2014-06-04 06:53:35 +02003111
paul718e3742002-12-13 20:15:29 +00003112/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3113 value. */
3114int
3115bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3116{
3117 u_char *pnt;
3118 u_char *lim;
3119 struct prefix p;
3120 int psize;
3121 int ret;
3122
3123 /* Check peer status. */
3124 if (peer->status != Established)
3125 return 0;
3126
3127 pnt = packet->nlri;
3128 lim = pnt + packet->length;
3129
3130 for (; pnt < lim; pnt += psize)
3131 {
3132 /* Clear prefix structure. */
3133 memset (&p, 0, sizeof (struct prefix));
3134
3135 /* Fetch prefix length. */
3136 p.prefixlen = *pnt++;
3137 p.family = afi2family (packet->afi);
3138
3139 /* Already checked in nlri_sanity_check(). We do double check
3140 here. */
3141 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3142 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3143 return -1;
3144
3145 /* Packet size overflow check. */
3146 psize = PSIZE (p.prefixlen);
3147
3148 /* When packet overflow occur return immediately. */
3149 if (pnt + psize > lim)
3150 return -1;
3151
3152 /* Fetch prefix from NLRI packet. */
3153 memcpy (&p.u.prefix, pnt, psize);
3154
3155 /* Check address. */
3156 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3157 {
3158 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3159 {
paulf5ba3872004-07-09 12:11:31 +00003160 /*
3161 * From draft-ietf-idr-bgp4-22, Section 6.3:
3162 * If a BGP router receives an UPDATE message with a
3163 * semantically incorrect NLRI field, in which a prefix is
3164 * semantically incorrect (eg. an unexpected multicast IP
3165 * address), it should ignore the prefix.
3166 */
paul718e3742002-12-13 20:15:29 +00003167 zlog (peer->log, LOG_ERR,
3168 "IPv4 unicast NLRI is multicast address %s",
3169 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003170
paul718e3742002-12-13 20:15:29 +00003171 return -1;
3172 }
3173 }
3174
3175#ifdef HAVE_IPV6
3176 /* Check address. */
3177 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3178 {
3179 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3180 {
3181 char buf[BUFSIZ];
3182
3183 zlog (peer->log, LOG_WARNING,
3184 "IPv6 link-local NLRI received %s ignore this NLRI",
3185 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3186
3187 continue;
3188 }
3189 }
3190#endif /* HAVE_IPV6 */
3191
3192 /* Normal process. */
3193 if (attr)
3194 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3195 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3196 else
3197 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3198 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3199
3200 /* Address family configuration mismatch or maximum-prefix count
3201 overflow. */
3202 if (ret < 0)
3203 return -1;
3204 }
3205
3206 /* Packet length consistency check. */
3207 if (pnt != lim)
3208 return -1;
3209
3210 return 0;
3211}
3212
3213/* NLRI encode syntax check routine. */
3214int
3215bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3216 bgp_size_t length)
3217{
3218 u_char *end;
3219 u_char prefixlen;
3220 int psize;
3221
3222 end = pnt + length;
3223
3224 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3225 syntactic validity. If the field is syntactically incorrect,
3226 then the Error Subcode is set to Invalid Network Field. */
3227
3228 while (pnt < end)
3229 {
3230 prefixlen = *pnt++;
3231
3232 /* Prefix length check. */
3233 if ((afi == AFI_IP && prefixlen > 32)
3234 || (afi == AFI_IP6 && prefixlen > 128))
3235 {
3236 plog_err (peer->log,
3237 "%s [Error] Update packet error (wrong prefix length %d)",
3238 peer->host, prefixlen);
3239 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3240 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3241 return -1;
3242 }
3243
3244 /* Packet size overflow check. */
3245 psize = PSIZE (prefixlen);
3246
3247 if (pnt + psize > end)
3248 {
3249 plog_err (peer->log,
3250 "%s [Error] Update packet error"
3251 " (prefix data overflow prefix size is %d)",
3252 peer->host, psize);
3253 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3254 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3255 return -1;
3256 }
3257
3258 pnt += psize;
3259 }
3260
3261 /* Packet length consistency check. */
3262 if (pnt != end)
3263 {
3264 plog_err (peer->log,
3265 "%s [Error] Update packet error"
3266 " (prefix length mismatch with total length)",
3267 peer->host);
3268 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3269 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3270 return -1;
3271 }
3272 return 0;
3273}
David Lamparter6b0655a2014-06-04 06:53:35 +02003274
paul94f2b392005-06-28 12:44:16 +00003275static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003276bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003277{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003278 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003279}
3280
paul94f2b392005-06-28 12:44:16 +00003281static void
paul718e3742002-12-13 20:15:29 +00003282bgp_static_free (struct bgp_static *bgp_static)
3283{
3284 if (bgp_static->rmap.name)
3285 free (bgp_static->rmap.name);
3286 XFREE (MTYPE_BGP_STATIC, bgp_static);
3287}
3288
paul94f2b392005-06-28 12:44:16 +00003289static void
paulfee0f4c2004-09-13 05:12:46 +00003290bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3291 struct prefix *p, afi_t afi, safi_t safi)
3292{
3293 struct bgp_node *rn;
3294 struct bgp_info *ri;
3295
3296 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3297
3298 /* Check selected route and self inserted route. */
3299 for (ri = rn->info; ri; ri = ri->next)
3300 if (ri->peer == bgp->peer_self
3301 && ri->type == ZEBRA_ROUTE_BGP
3302 && ri->sub_type == BGP_ROUTE_STATIC)
3303 break;
3304
3305 /* Withdraw static BGP route from routing table. */
3306 if (ri)
3307 {
paulfee0f4c2004-09-13 05:12:46 +00003308 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003309 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003310 }
3311
3312 /* Unlock bgp_node_lookup. */
3313 bgp_unlock_node (rn);
3314}
3315
paul94f2b392005-06-28 12:44:16 +00003316static void
paulfee0f4c2004-09-13 05:12:46 +00003317bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003318 struct bgp_static *bgp_static,
3319 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003320{
3321 struct bgp_node *rn;
3322 struct bgp_info *ri;
3323 struct bgp_info *new;
3324 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003325 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003326 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003327 struct attr new_attr;
3328 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003329 struct bgp *bgp;
3330 int ret;
3331 char buf[SU_ADDRSTRLEN];
3332
3333 bgp = rsclient->bgp;
3334
Paul Jakma06e110f2006-05-12 23:29:22 +00003335 assert (bgp_static);
3336 if (!bgp_static)
3337 return;
3338
paulfee0f4c2004-09-13 05:12:46 +00003339 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3340
3341 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003342
3343 attr.nexthop = bgp_static->igpnexthop;
3344 attr.med = bgp_static->igpmetric;
3345 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003346
Paul Jakma41367172007-08-06 15:24:51 +00003347 if (bgp_static->atomic)
3348 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3349
paulfee0f4c2004-09-13 05:12:46 +00003350 /* Apply network route-map for export to this rsclient. */
3351 if (bgp_static->rmap.name)
3352 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003353 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003354 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003355 info.attr = &attr_tmp;
3356
paulfee0f4c2004-09-13 05:12:46 +00003357 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3358 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3359
3360 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3361
3362 rsclient->rmap_type = 0;
3363
3364 if (ret == RMAP_DENYMATCH)
3365 {
3366 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003367 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003368
3369 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003370 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003371 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003372 bgp_attr_extra_free (&attr);
3373
paulfee0f4c2004-09-13 05:12:46 +00003374 return;
3375 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003376 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003377 }
3378 else
3379 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003380
3381 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003382 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003383
paulfee0f4c2004-09-13 05:12:46 +00003384 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3385
Paul Jakmafb982c22007-05-04 20:15:47 +00003386 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3387 == RMAP_DENY)
3388 {
paulfee0f4c2004-09-13 05:12:46 +00003389 /* This BGP update is filtered. Log the reason then update BGP entry. */
3390 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003391 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003392 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3393 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3394 p->prefixlen, rsclient->host);
3395
3396 bgp->peer_self->rmap_type = 0;
3397
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003398 bgp_attr_unintern (&attr_new);
3399 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003400 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003401
3402 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3403
3404 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003405 }
paulfee0f4c2004-09-13 05:12:46 +00003406
3407 bgp->peer_self->rmap_type = 0;
3408
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003409 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003410 attr_new = bgp_attr_intern (&new_attr);
3411
3412 for (ri = rn->info; ri; ri = ri->next)
3413 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3414 && ri->sub_type == BGP_ROUTE_STATIC)
3415 break;
3416
3417 if (ri)
3418 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003419 if (attrhash_cmp (ri->attr, attr_new) &&
3420 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003421 {
3422 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003423 bgp_attr_unintern (&attr_new);
3424 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003425 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003426 return;
3427 }
3428 else
3429 {
3430 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003431 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003432
3433 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003434 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3435 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003436 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003437 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003438 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003439
3440 /* Process change. */
3441 bgp_process (bgp, rn, afi, safi);
3442 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003443 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003444 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003445 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003446 }
paulfee0f4c2004-09-13 05:12:46 +00003447 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003448
paulfee0f4c2004-09-13 05:12:46 +00003449 /* Make new BGP info. */
3450 new = bgp_info_new ();
3451 new->type = ZEBRA_ROUTE_BGP;
3452 new->sub_type = BGP_ROUTE_STATIC;
3453 new->peer = bgp->peer_self;
3454 SET_FLAG (new->flags, BGP_INFO_VALID);
3455 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003456 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003457
3458 /* Register new BGP information. */
3459 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003460
3461 /* route_node_get lock */
3462 bgp_unlock_node (rn);
3463
paulfee0f4c2004-09-13 05:12:46 +00003464 /* Process change. */
3465 bgp_process (bgp, rn, afi, safi);
3466
3467 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003468 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003469 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003470}
3471
paul94f2b392005-06-28 12:44:16 +00003472static void
paulfee0f4c2004-09-13 05:12:46 +00003473bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003474 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3475{
3476 struct bgp_node *rn;
3477 struct bgp_info *ri;
3478 struct bgp_info *new;
3479 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003480 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003481 struct attr *attr_new;
3482 int ret;
3483
Paul Jakmadd8103a2006-05-12 23:27:30 +00003484 assert (bgp_static);
3485 if (!bgp_static)
3486 return;
3487
paulfee0f4c2004-09-13 05:12:46 +00003488 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003489
3490 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003491
3492 attr.nexthop = bgp_static->igpnexthop;
3493 attr.med = bgp_static->igpmetric;
3494 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003495
Paul Jakma41367172007-08-06 15:24:51 +00003496 if (bgp_static->atomic)
3497 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3498
paul718e3742002-12-13 20:15:29 +00003499 /* Apply route-map. */
3500 if (bgp_static->rmap.name)
3501 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003502 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003503 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003504 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003505
paulfee0f4c2004-09-13 05:12:46 +00003506 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3507
paul718e3742002-12-13 20:15:29 +00003508 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003509
paulfee0f4c2004-09-13 05:12:46 +00003510 bgp->peer_self->rmap_type = 0;
3511
paul718e3742002-12-13 20:15:29 +00003512 if (ret == RMAP_DENYMATCH)
3513 {
3514 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003515 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003516
3517 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003518 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003519 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003520 bgp_static_withdraw (bgp, p, afi, safi);
3521 return;
3522 }
paul286e1e72003-08-08 00:24:31 +00003523 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003524 }
paul286e1e72003-08-08 00:24:31 +00003525 else
3526 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003527
3528 for (ri = rn->info; ri; ri = ri->next)
3529 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3530 && ri->sub_type == BGP_ROUTE_STATIC)
3531 break;
3532
3533 if (ri)
3534 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003535 if (attrhash_cmp (ri->attr, attr_new) &&
3536 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003537 {
3538 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003539 bgp_attr_unintern (&attr_new);
3540 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003541 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003542 return;
3543 }
3544 else
3545 {
3546 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003547 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003548
3549 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003550 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3551 bgp_info_restore(rn, ri);
3552 else
3553 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003554 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003555 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003556 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003557
3558 /* Process change. */
3559 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3560 bgp_process (bgp, rn, afi, safi);
3561 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003562 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003563 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003564 return;
3565 }
3566 }
3567
3568 /* Make new BGP info. */
3569 new = bgp_info_new ();
3570 new->type = ZEBRA_ROUTE_BGP;
3571 new->sub_type = BGP_ROUTE_STATIC;
3572 new->peer = bgp->peer_self;
3573 SET_FLAG (new->flags, BGP_INFO_VALID);
3574 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003575 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003576
3577 /* Aggregate address increment. */
3578 bgp_aggregate_increment (bgp, p, new, afi, safi);
3579
3580 /* Register new BGP information. */
3581 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003582
3583 /* route_node_get lock */
3584 bgp_unlock_node (rn);
3585
paul718e3742002-12-13 20:15:29 +00003586 /* Process change. */
3587 bgp_process (bgp, rn, afi, safi);
3588
3589 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003590 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003591 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003592}
3593
3594void
paulfee0f4c2004-09-13 05:12:46 +00003595bgp_static_update (struct bgp *bgp, struct prefix *p,
3596 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3597{
3598 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003599 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003600
3601 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3602
paul1eb8ef22005-04-07 07:30:20 +00003603 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003604 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003605 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3606 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003607 }
3608}
3609
paul94f2b392005-06-28 12:44:16 +00003610static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003611bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3612 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003613{
3614 struct bgp_node *rn;
3615 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003616
paulfee0f4c2004-09-13 05:12:46 +00003617 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003618
3619 /* Make new BGP info. */
3620 new = bgp_info_new ();
3621 new->type = ZEBRA_ROUTE_BGP;
3622 new->sub_type = BGP_ROUTE_STATIC;
3623 new->peer = bgp->peer_self;
3624 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3625 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003626 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003627 new->extra = bgp_info_extra_new();
3628 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003629
3630 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003631 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003632
3633 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003634 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003635
paul200df112005-06-01 11:17:05 +00003636 /* route_node_get lock */
3637 bgp_unlock_node (rn);
3638
paul718e3742002-12-13 20:15:29 +00003639 /* Process change. */
3640 bgp_process (bgp, rn, afi, safi);
3641}
3642
3643void
3644bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3645 safi_t safi)
3646{
3647 struct bgp_node *rn;
3648 struct bgp_info *ri;
3649
paulfee0f4c2004-09-13 05:12:46 +00003650 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003651
3652 /* Check selected route and self inserted route. */
3653 for (ri = rn->info; ri; ri = ri->next)
3654 if (ri->peer == bgp->peer_self
3655 && ri->type == ZEBRA_ROUTE_BGP
3656 && ri->sub_type == BGP_ROUTE_STATIC)
3657 break;
3658
3659 /* Withdraw static BGP route from routing table. */
3660 if (ri)
3661 {
3662 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003663 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003664 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003665 }
3666
3667 /* Unlock bgp_node_lookup. */
3668 bgp_unlock_node (rn);
3669}
3670
3671void
paulfee0f4c2004-09-13 05:12:46 +00003672bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3673{
3674 struct bgp_static *bgp_static;
3675 struct bgp *bgp;
3676 struct bgp_node *rn;
3677 struct prefix *p;
3678
3679 bgp = rsclient->bgp;
3680
3681 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3682 if ((bgp_static = rn->info) != NULL)
3683 {
3684 p = &rn->p;
3685
3686 bgp_static_update_rsclient (rsclient, p, bgp_static,
3687 afi, safi);
3688 }
3689}
3690
paul94f2b392005-06-28 12:44:16 +00003691static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003692bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3693 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003694{
3695 struct bgp_node *rn;
3696 struct bgp_info *ri;
3697
paulfee0f4c2004-09-13 05:12:46 +00003698 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003699
3700 /* Check selected route and self inserted route. */
3701 for (ri = rn->info; ri; ri = ri->next)
3702 if (ri->peer == bgp->peer_self
3703 && ri->type == ZEBRA_ROUTE_BGP
3704 && ri->sub_type == BGP_ROUTE_STATIC)
3705 break;
3706
3707 /* Withdraw static BGP route from routing table. */
3708 if (ri)
3709 {
3710 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003711 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003712 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003713 }
3714
3715 /* Unlock bgp_node_lookup. */
3716 bgp_unlock_node (rn);
3717}
3718
3719/* Configure static BGP network. When user don't run zebra, static
3720 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003721static int
paulfd79ac92004-10-13 05:06:08 +00003722bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003723 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003724{
3725 int ret;
3726 struct prefix p;
3727 struct bgp_static *bgp_static;
3728 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003729 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003730
3731 /* Convert IP prefix string to struct prefix. */
3732 ret = str2prefix (ip_str, &p);
3733 if (! ret)
3734 {
3735 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3736 return CMD_WARNING;
3737 }
3738#ifdef HAVE_IPV6
3739 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3740 {
3741 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3742 VTY_NEWLINE);
3743 return CMD_WARNING;
3744 }
3745#endif /* HAVE_IPV6 */
3746
3747 apply_mask (&p);
3748
3749 /* Set BGP static route configuration. */
3750 rn = bgp_node_get (bgp->route[afi][safi], &p);
3751
3752 if (rn->info)
3753 {
3754 /* Configuration change. */
3755 bgp_static = rn->info;
3756
3757 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003758 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3759 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003760
paul718e3742002-12-13 20:15:29 +00003761 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003762
paul718e3742002-12-13 20:15:29 +00003763 if (rmap)
3764 {
3765 if (bgp_static->rmap.name)
3766 free (bgp_static->rmap.name);
3767 bgp_static->rmap.name = strdup (rmap);
3768 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3769 }
3770 else
3771 {
3772 if (bgp_static->rmap.name)
3773 free (bgp_static->rmap.name);
3774 bgp_static->rmap.name = NULL;
3775 bgp_static->rmap.map = NULL;
3776 bgp_static->valid = 0;
3777 }
3778 bgp_unlock_node (rn);
3779 }
3780 else
3781 {
3782 /* New configuration. */
3783 bgp_static = bgp_static_new ();
3784 bgp_static->backdoor = backdoor;
3785 bgp_static->valid = 0;
3786 bgp_static->igpmetric = 0;
3787 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003788
paul718e3742002-12-13 20:15:29 +00003789 if (rmap)
3790 {
3791 if (bgp_static->rmap.name)
3792 free (bgp_static->rmap.name);
3793 bgp_static->rmap.name = strdup (rmap);
3794 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3795 }
3796 rn->info = bgp_static;
3797 }
3798
3799 /* If BGP scan is not enabled, we should install this route here. */
3800 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3801 {
3802 bgp_static->valid = 1;
3803
3804 if (need_update)
3805 bgp_static_withdraw (bgp, &p, afi, safi);
3806
3807 if (! bgp_static->backdoor)
3808 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3809 }
3810
3811 return CMD_SUCCESS;
3812}
3813
3814/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003815static int
paulfd79ac92004-10-13 05:06:08 +00003816bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003817 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003818{
3819 int ret;
3820 struct prefix p;
3821 struct bgp_static *bgp_static;
3822 struct bgp_node *rn;
3823
3824 /* Convert IP prefix string to struct prefix. */
3825 ret = str2prefix (ip_str, &p);
3826 if (! ret)
3827 {
3828 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3829 return CMD_WARNING;
3830 }
3831#ifdef HAVE_IPV6
3832 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3833 {
3834 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3835 VTY_NEWLINE);
3836 return CMD_WARNING;
3837 }
3838#endif /* HAVE_IPV6 */
3839
3840 apply_mask (&p);
3841
3842 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3843 if (! rn)
3844 {
3845 vty_out (vty, "%% Can't find specified static route configuration.%s",
3846 VTY_NEWLINE);
3847 return CMD_WARNING;
3848 }
3849
3850 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003851
paul718e3742002-12-13 20:15:29 +00003852 /* Update BGP RIB. */
3853 if (! bgp_static->backdoor)
3854 bgp_static_withdraw (bgp, &p, afi, safi);
3855
3856 /* Clear configuration. */
3857 bgp_static_free (bgp_static);
3858 rn->info = NULL;
3859 bgp_unlock_node (rn);
3860 bgp_unlock_node (rn);
3861
3862 return CMD_SUCCESS;
3863}
3864
3865/* Called from bgp_delete(). Delete all static routes from the BGP
3866 instance. */
3867void
3868bgp_static_delete (struct bgp *bgp)
3869{
3870 afi_t afi;
3871 safi_t safi;
3872 struct bgp_node *rn;
3873 struct bgp_node *rm;
3874 struct bgp_table *table;
3875 struct bgp_static *bgp_static;
3876
3877 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3878 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3879 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3880 if (rn->info != NULL)
3881 {
3882 if (safi == SAFI_MPLS_VPN)
3883 {
3884 table = rn->info;
3885
3886 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3887 {
3888 bgp_static = rn->info;
3889 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3890 AFI_IP, SAFI_MPLS_VPN,
3891 (struct prefix_rd *)&rn->p,
3892 bgp_static->tag);
3893 bgp_static_free (bgp_static);
3894 rn->info = NULL;
3895 bgp_unlock_node (rn);
3896 }
3897 }
3898 else
3899 {
3900 bgp_static = rn->info;
3901 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3902 bgp_static_free (bgp_static);
3903 rn->info = NULL;
3904 bgp_unlock_node (rn);
3905 }
3906 }
3907}
3908
3909int
paulfd79ac92004-10-13 05:06:08 +00003910bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3911 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003912{
3913 int ret;
3914 struct prefix p;
3915 struct prefix_rd prd;
3916 struct bgp *bgp;
3917 struct bgp_node *prn;
3918 struct bgp_node *rn;
3919 struct bgp_table *table;
3920 struct bgp_static *bgp_static;
3921 u_char tag[3];
3922
3923 bgp = vty->index;
3924
3925 ret = str2prefix (ip_str, &p);
3926 if (! ret)
3927 {
3928 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3929 return CMD_WARNING;
3930 }
3931 apply_mask (&p);
3932
3933 ret = str2prefix_rd (rd_str, &prd);
3934 if (! ret)
3935 {
3936 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3937 return CMD_WARNING;
3938 }
3939
3940 ret = str2tag (tag_str, tag);
3941 if (! ret)
3942 {
3943 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3944 return CMD_WARNING;
3945 }
3946
3947 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3948 (struct prefix *)&prd);
3949 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003950 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003951 else
3952 bgp_unlock_node (prn);
3953 table = prn->info;
3954
3955 rn = bgp_node_get (table, &p);
3956
3957 if (rn->info)
3958 {
3959 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3960 bgp_unlock_node (rn);
3961 }
3962 else
3963 {
3964 /* New configuration. */
3965 bgp_static = bgp_static_new ();
3966 bgp_static->valid = 1;
3967 memcpy (bgp_static->tag, tag, 3);
3968 rn->info = bgp_static;
3969
3970 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3971 }
3972
3973 return CMD_SUCCESS;
3974}
3975
3976/* Configure static BGP network. */
3977int
paulfd79ac92004-10-13 05:06:08 +00003978bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3979 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003980{
3981 int ret;
3982 struct bgp *bgp;
3983 struct prefix p;
3984 struct prefix_rd prd;
3985 struct bgp_node *prn;
3986 struct bgp_node *rn;
3987 struct bgp_table *table;
3988 struct bgp_static *bgp_static;
3989 u_char tag[3];
3990
3991 bgp = vty->index;
3992
3993 /* Convert IP prefix string to struct prefix. */
3994 ret = str2prefix (ip_str, &p);
3995 if (! ret)
3996 {
3997 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3998 return CMD_WARNING;
3999 }
4000 apply_mask (&p);
4001
4002 ret = str2prefix_rd (rd_str, &prd);
4003 if (! ret)
4004 {
4005 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4006 return CMD_WARNING;
4007 }
4008
4009 ret = str2tag (tag_str, tag);
4010 if (! ret)
4011 {
4012 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4013 return CMD_WARNING;
4014 }
4015
4016 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4017 (struct prefix *)&prd);
4018 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004019 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004020 else
4021 bgp_unlock_node (prn);
4022 table = prn->info;
4023
4024 rn = bgp_node_lookup (table, &p);
4025
4026 if (rn)
4027 {
4028 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4029
4030 bgp_static = rn->info;
4031 bgp_static_free (bgp_static);
4032 rn->info = NULL;
4033 bgp_unlock_node (rn);
4034 bgp_unlock_node (rn);
4035 }
4036 else
4037 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4038
4039 return CMD_SUCCESS;
4040}
David Lamparter6b0655a2014-06-04 06:53:35 +02004041
paul718e3742002-12-13 20:15:29 +00004042DEFUN (bgp_network,
4043 bgp_network_cmd,
4044 "network A.B.C.D/M",
4045 "Specify a network to announce via BGP\n"
4046 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4047{
4048 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004049 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004050}
4051
4052DEFUN (bgp_network_route_map,
4053 bgp_network_route_map_cmd,
4054 "network A.B.C.D/M route-map WORD",
4055 "Specify a network to announce via BGP\n"
4056 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4057 "Route-map to modify the attributes\n"
4058 "Name of the route map\n")
4059{
4060 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004061 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004062}
4063
4064DEFUN (bgp_network_backdoor,
4065 bgp_network_backdoor_cmd,
4066 "network A.B.C.D/M backdoor",
4067 "Specify a network to announce via BGP\n"
4068 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4069 "Specify a BGP backdoor route\n")
4070{
Paul Jakma41367172007-08-06 15:24:51 +00004071 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004072 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004073}
4074
4075DEFUN (bgp_network_mask,
4076 bgp_network_mask_cmd,
4077 "network A.B.C.D mask A.B.C.D",
4078 "Specify a network to announce via BGP\n"
4079 "Network number\n"
4080 "Network mask\n"
4081 "Network mask\n")
4082{
4083 int ret;
4084 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004085
paul718e3742002-12-13 20:15:29 +00004086 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4087 if (! ret)
4088 {
4089 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4090 return CMD_WARNING;
4091 }
4092
4093 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004094 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004095}
4096
4097DEFUN (bgp_network_mask_route_map,
4098 bgp_network_mask_route_map_cmd,
4099 "network A.B.C.D mask A.B.C.D route-map WORD",
4100 "Specify a network to announce via BGP\n"
4101 "Network number\n"
4102 "Network mask\n"
4103 "Network mask\n"
4104 "Route-map to modify the attributes\n"
4105 "Name of the route map\n")
4106{
4107 int ret;
4108 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004109
paul718e3742002-12-13 20:15:29 +00004110 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4111 if (! ret)
4112 {
4113 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4114 return CMD_WARNING;
4115 }
4116
4117 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004118 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004119}
4120
4121DEFUN (bgp_network_mask_backdoor,
4122 bgp_network_mask_backdoor_cmd,
4123 "network A.B.C.D mask A.B.C.D backdoor",
4124 "Specify a network to announce via BGP\n"
4125 "Network number\n"
4126 "Network mask\n"
4127 "Network mask\n"
4128 "Specify a BGP backdoor route\n")
4129{
4130 int ret;
4131 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004132
paul718e3742002-12-13 20:15:29 +00004133 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4134 if (! ret)
4135 {
4136 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4137 return CMD_WARNING;
4138 }
4139
Paul Jakma41367172007-08-06 15:24:51 +00004140 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004141 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004142}
4143
4144DEFUN (bgp_network_mask_natural,
4145 bgp_network_mask_natural_cmd,
4146 "network A.B.C.D",
4147 "Specify a network to announce via BGP\n"
4148 "Network number\n")
4149{
4150 int ret;
4151 char prefix_str[BUFSIZ];
4152
4153 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4154 if (! ret)
4155 {
4156 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4157 return CMD_WARNING;
4158 }
4159
4160 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004161 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004162}
4163
4164DEFUN (bgp_network_mask_natural_route_map,
4165 bgp_network_mask_natural_route_map_cmd,
4166 "network A.B.C.D route-map WORD",
4167 "Specify a network to announce via BGP\n"
4168 "Network number\n"
4169 "Route-map to modify the attributes\n"
4170 "Name of the route map\n")
4171{
4172 int ret;
4173 char prefix_str[BUFSIZ];
4174
4175 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4176 if (! ret)
4177 {
4178 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4179 return CMD_WARNING;
4180 }
4181
4182 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004183 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004184}
4185
4186DEFUN (bgp_network_mask_natural_backdoor,
4187 bgp_network_mask_natural_backdoor_cmd,
4188 "network A.B.C.D backdoor",
4189 "Specify a network to announce via BGP\n"
4190 "Network number\n"
4191 "Specify a BGP backdoor route\n")
4192{
4193 int ret;
4194 char prefix_str[BUFSIZ];
4195
4196 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4197 if (! ret)
4198 {
4199 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4200 return CMD_WARNING;
4201 }
4202
Paul Jakma41367172007-08-06 15:24:51 +00004203 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004204 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004205}
4206
4207DEFUN (no_bgp_network,
4208 no_bgp_network_cmd,
4209 "no network A.B.C.D/M",
4210 NO_STR
4211 "Specify a network to announce via BGP\n"
4212 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4213{
4214 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4215 bgp_node_safi (vty));
4216}
4217
4218ALIAS (no_bgp_network,
4219 no_bgp_network_route_map_cmd,
4220 "no network A.B.C.D/M route-map WORD",
4221 NO_STR
4222 "Specify a network to announce via BGP\n"
4223 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4224 "Route-map to modify the attributes\n"
4225 "Name of the route map\n")
4226
4227ALIAS (no_bgp_network,
4228 no_bgp_network_backdoor_cmd,
4229 "no network A.B.C.D/M backdoor",
4230 NO_STR
4231 "Specify a network to announce via BGP\n"
4232 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4233 "Specify a BGP backdoor route\n")
4234
4235DEFUN (no_bgp_network_mask,
4236 no_bgp_network_mask_cmd,
4237 "no network A.B.C.D mask A.B.C.D",
4238 NO_STR
4239 "Specify a network to announce via BGP\n"
4240 "Network number\n"
4241 "Network mask\n"
4242 "Network mask\n")
4243{
4244 int ret;
4245 char prefix_str[BUFSIZ];
4246
4247 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4248 if (! ret)
4249 {
4250 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4251 return CMD_WARNING;
4252 }
4253
4254 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4255 bgp_node_safi (vty));
4256}
4257
4258ALIAS (no_bgp_network_mask,
4259 no_bgp_network_mask_route_map_cmd,
4260 "no network A.B.C.D mask A.B.C.D route-map WORD",
4261 NO_STR
4262 "Specify a network to announce via BGP\n"
4263 "Network number\n"
4264 "Network mask\n"
4265 "Network mask\n"
4266 "Route-map to modify the attributes\n"
4267 "Name of the route map\n")
4268
4269ALIAS (no_bgp_network_mask,
4270 no_bgp_network_mask_backdoor_cmd,
4271 "no network A.B.C.D mask A.B.C.D backdoor",
4272 NO_STR
4273 "Specify a network to announce via BGP\n"
4274 "Network number\n"
4275 "Network mask\n"
4276 "Network mask\n"
4277 "Specify a BGP backdoor route\n")
4278
4279DEFUN (no_bgp_network_mask_natural,
4280 no_bgp_network_mask_natural_cmd,
4281 "no network A.B.C.D",
4282 NO_STR
4283 "Specify a network to announce via BGP\n"
4284 "Network number\n")
4285{
4286 int ret;
4287 char prefix_str[BUFSIZ];
4288
4289 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4290 if (! ret)
4291 {
4292 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4293 return CMD_WARNING;
4294 }
4295
4296 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4297 bgp_node_safi (vty));
4298}
4299
4300ALIAS (no_bgp_network_mask_natural,
4301 no_bgp_network_mask_natural_route_map_cmd,
4302 "no network A.B.C.D route-map WORD",
4303 NO_STR
4304 "Specify a network to announce via BGP\n"
4305 "Network number\n"
4306 "Route-map to modify the attributes\n"
4307 "Name of the route map\n")
4308
4309ALIAS (no_bgp_network_mask_natural,
4310 no_bgp_network_mask_natural_backdoor_cmd,
4311 "no network A.B.C.D backdoor",
4312 NO_STR
4313 "Specify a network to announce via BGP\n"
4314 "Network number\n"
4315 "Specify a BGP backdoor route\n")
4316
4317#ifdef HAVE_IPV6
4318DEFUN (ipv6_bgp_network,
4319 ipv6_bgp_network_cmd,
4320 "network X:X::X:X/M",
4321 "Specify a network to announce via BGP\n"
4322 "IPv6 prefix <network>/<length>\n")
4323{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304324 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004325 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004326}
4327
4328DEFUN (ipv6_bgp_network_route_map,
4329 ipv6_bgp_network_route_map_cmd,
4330 "network X:X::X:X/M route-map WORD",
4331 "Specify a network to announce via BGP\n"
4332 "IPv6 prefix <network>/<length>\n"
4333 "Route-map to modify the attributes\n"
4334 "Name of the route map\n")
4335{
4336 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004337 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004338}
4339
4340DEFUN (no_ipv6_bgp_network,
4341 no_ipv6_bgp_network_cmd,
4342 "no network X:X::X:X/M",
4343 NO_STR
4344 "Specify a network to announce via BGP\n"
4345 "IPv6 prefix <network>/<length>\n")
4346{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304347 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004348}
4349
4350ALIAS (no_ipv6_bgp_network,
4351 no_ipv6_bgp_network_route_map_cmd,
4352 "no network X:X::X:X/M route-map WORD",
4353 NO_STR
4354 "Specify a network to announce via BGP\n"
4355 "IPv6 prefix <network>/<length>\n"
4356 "Route-map to modify the attributes\n"
4357 "Name of the route map\n")
4358
4359ALIAS (ipv6_bgp_network,
4360 old_ipv6_bgp_network_cmd,
4361 "ipv6 bgp network X:X::X:X/M",
4362 IPV6_STR
4363 BGP_STR
4364 "Specify a network to announce via BGP\n"
4365 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4366
4367ALIAS (no_ipv6_bgp_network,
4368 old_no_ipv6_bgp_network_cmd,
4369 "no ipv6 bgp network X:X::X:X/M",
4370 NO_STR
4371 IPV6_STR
4372 BGP_STR
4373 "Specify a network to announce via BGP\n"
4374 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4375#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004376
4377/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4378ALIAS_DEPRECATED (bgp_network,
4379 bgp_network_ttl_cmd,
4380 "network A.B.C.D/M pathlimit <0-255>",
4381 "Specify a network to announce via BGP\n"
4382 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4383 "AS-Path hopcount limit attribute\n"
4384 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4385ALIAS_DEPRECATED (bgp_network_backdoor,
4386 bgp_network_backdoor_ttl_cmd,
4387 "network A.B.C.D/M backdoor pathlimit <0-255>",
4388 "Specify a network to announce via BGP\n"
4389 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4390 "Specify a BGP backdoor route\n"
4391 "AS-Path hopcount limit attribute\n"
4392 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4393ALIAS_DEPRECATED (bgp_network_mask,
4394 bgp_network_mask_ttl_cmd,
4395 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4396 "Specify a network to announce via BGP\n"
4397 "Network number\n"
4398 "Network mask\n"
4399 "Network mask\n"
4400 "AS-Path hopcount limit attribute\n"
4401 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4402ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4403 bgp_network_mask_backdoor_ttl_cmd,
4404 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4405 "Specify a network to announce via BGP\n"
4406 "Network number\n"
4407 "Network mask\n"
4408 "Network mask\n"
4409 "Specify a BGP backdoor route\n"
4410 "AS-Path hopcount limit attribute\n"
4411 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4412ALIAS_DEPRECATED (bgp_network_mask_natural,
4413 bgp_network_mask_natural_ttl_cmd,
4414 "network A.B.C.D pathlimit <0-255>",
4415 "Specify a network to announce via BGP\n"
4416 "Network number\n"
4417 "AS-Path hopcount limit attribute\n"
4418 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4419ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4420 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004421 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004422 "Specify a network to announce via BGP\n"
4423 "Network number\n"
4424 "Specify a BGP backdoor route\n"
4425 "AS-Path hopcount limit attribute\n"
4426 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4427ALIAS_DEPRECATED (no_bgp_network,
4428 no_bgp_network_ttl_cmd,
4429 "no network A.B.C.D/M pathlimit <0-255>",
4430 NO_STR
4431 "Specify a network to announce via BGP\n"
4432 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4433 "AS-Path hopcount limit attribute\n"
4434 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4435ALIAS_DEPRECATED (no_bgp_network,
4436 no_bgp_network_backdoor_ttl_cmd,
4437 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4438 NO_STR
4439 "Specify a network to announce via BGP\n"
4440 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4441 "Specify a BGP backdoor route\n"
4442 "AS-Path hopcount limit attribute\n"
4443 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4444ALIAS_DEPRECATED (no_bgp_network,
4445 no_bgp_network_mask_ttl_cmd,
4446 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4447 NO_STR
4448 "Specify a network to announce via BGP\n"
4449 "Network number\n"
4450 "Network mask\n"
4451 "Network mask\n"
4452 "AS-Path hopcount limit attribute\n"
4453 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4454ALIAS_DEPRECATED (no_bgp_network_mask,
4455 no_bgp_network_mask_backdoor_ttl_cmd,
4456 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4457 NO_STR
4458 "Specify a network to announce via BGP\n"
4459 "Network number\n"
4460 "Network mask\n"
4461 "Network mask\n"
4462 "Specify a BGP backdoor route\n"
4463 "AS-Path hopcount limit attribute\n"
4464 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4465ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4466 no_bgp_network_mask_natural_ttl_cmd,
4467 "no network A.B.C.D pathlimit <0-255>",
4468 NO_STR
4469 "Specify a network to announce via BGP\n"
4470 "Network number\n"
4471 "AS-Path hopcount limit attribute\n"
4472 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4473ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4474 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4475 "no network A.B.C.D backdoor pathlimit <0-255>",
4476 NO_STR
4477 "Specify a network to announce via BGP\n"
4478 "Network number\n"
4479 "Specify a BGP backdoor route\n"
4480 "AS-Path hopcount limit attribute\n"
4481 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004482#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004483ALIAS_DEPRECATED (ipv6_bgp_network,
4484 ipv6_bgp_network_ttl_cmd,
4485 "network X:X::X:X/M pathlimit <0-255>",
4486 "Specify a network to announce via BGP\n"
4487 "IPv6 prefix <network>/<length>\n"
4488 "AS-Path hopcount limit attribute\n"
4489 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4490ALIAS_DEPRECATED (no_ipv6_bgp_network,
4491 no_ipv6_bgp_network_ttl_cmd,
4492 "no network X:X::X:X/M pathlimit <0-255>",
4493 NO_STR
4494 "Specify a network to announce via BGP\n"
4495 "IPv6 prefix <network>/<length>\n"
4496 "AS-Path hopcount limit attribute\n"
4497 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004498#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004499
paul718e3742002-12-13 20:15:29 +00004500/* Aggreagete address:
4501
4502 advertise-map Set condition to advertise attribute
4503 as-set Generate AS set path information
4504 attribute-map Set attributes of aggregate
4505 route-map Set parameters of aggregate
4506 summary-only Filter more specific routes from updates
4507 suppress-map Conditionally filter more specific routes from updates
4508 <cr>
4509 */
4510struct bgp_aggregate
4511{
4512 /* Summary-only flag. */
4513 u_char summary_only;
4514
4515 /* AS set generation. */
4516 u_char as_set;
4517
4518 /* Route-map for aggregated route. */
4519 struct route_map *map;
4520
4521 /* Suppress-count. */
4522 unsigned long count;
4523
4524 /* SAFI configuration. */
4525 safi_t safi;
4526};
4527
paul94f2b392005-06-28 12:44:16 +00004528static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004529bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004530{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004531 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004532}
4533
paul94f2b392005-06-28 12:44:16 +00004534static void
paul718e3742002-12-13 20:15:29 +00004535bgp_aggregate_free (struct bgp_aggregate *aggregate)
4536{
4537 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4538}
4539
paul94f2b392005-06-28 12:44:16 +00004540static void
paul718e3742002-12-13 20:15:29 +00004541bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4542 afi_t afi, safi_t safi, struct bgp_info *del,
4543 struct bgp_aggregate *aggregate)
4544{
4545 struct bgp_table *table;
4546 struct bgp_node *top;
4547 struct bgp_node *rn;
4548 u_char origin;
4549 struct aspath *aspath = NULL;
4550 struct aspath *asmerge = NULL;
4551 struct community *community = NULL;
4552 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004553 struct bgp_info *ri;
4554 struct bgp_info *new;
4555 int first = 1;
4556 unsigned long match = 0;
4557
paul718e3742002-12-13 20:15:29 +00004558 /* ORIGIN attribute: If at least one route among routes that are
4559 aggregated has ORIGIN with the value INCOMPLETE, then the
4560 aggregated route must have the ORIGIN attribute with the value
4561 INCOMPLETE. Otherwise, if at least one route among routes that
4562 are aggregated has ORIGIN with the value EGP, then the aggregated
4563 route must have the origin attribute with the value EGP. In all
4564 other case the value of the ORIGIN attribute of the aggregated
4565 route is INTERNAL. */
4566 origin = BGP_ORIGIN_IGP;
4567
4568 table = bgp->rib[afi][safi];
4569
4570 top = bgp_node_get (table, p);
4571 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4572 if (rn->p.prefixlen > p->prefixlen)
4573 {
4574 match = 0;
4575
4576 for (ri = rn->info; ri; ri = ri->next)
4577 {
4578 if (BGP_INFO_HOLDDOWN (ri))
4579 continue;
4580
4581 if (del && ri == del)
4582 continue;
4583
4584 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004585 first = 0;
paul718e3742002-12-13 20:15:29 +00004586
4587#ifdef AGGREGATE_NEXTHOP_CHECK
4588 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4589 || ri->attr->med != med)
4590 {
4591 if (aspath)
4592 aspath_free (aspath);
4593 if (community)
4594 community_free (community);
4595 bgp_unlock_node (rn);
4596 bgp_unlock_node (top);
4597 return;
4598 }
4599#endif /* AGGREGATE_NEXTHOP_CHECK */
4600
4601 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4602 {
4603 if (aggregate->summary_only)
4604 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004605 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004606 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004607 match++;
4608 }
4609
4610 aggregate->count++;
4611
4612 if (aggregate->as_set)
4613 {
4614 if (origin < ri->attr->origin)
4615 origin = ri->attr->origin;
4616
4617 if (aspath)
4618 {
4619 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4620 aspath_free (aspath);
4621 aspath = asmerge;
4622 }
4623 else
4624 aspath = aspath_dup (ri->attr->aspath);
4625
4626 if (ri->attr->community)
4627 {
4628 if (community)
4629 {
4630 commerge = community_merge (community,
4631 ri->attr->community);
4632 community = community_uniq_sort (commerge);
4633 community_free (commerge);
4634 }
4635 else
4636 community = community_dup (ri->attr->community);
4637 }
4638 }
4639 }
4640 }
4641 if (match)
4642 bgp_process (bgp, rn, afi, safi);
4643 }
4644 bgp_unlock_node (top);
4645
4646 if (rinew)
4647 {
4648 aggregate->count++;
4649
4650 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004651 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004652
4653 if (aggregate->as_set)
4654 {
4655 if (origin < rinew->attr->origin)
4656 origin = rinew->attr->origin;
4657
4658 if (aspath)
4659 {
4660 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4661 aspath_free (aspath);
4662 aspath = asmerge;
4663 }
4664 else
4665 aspath = aspath_dup (rinew->attr->aspath);
4666
4667 if (rinew->attr->community)
4668 {
4669 if (community)
4670 {
4671 commerge = community_merge (community,
4672 rinew->attr->community);
4673 community = community_uniq_sort (commerge);
4674 community_free (commerge);
4675 }
4676 else
4677 community = community_dup (rinew->attr->community);
4678 }
4679 }
4680 }
4681
4682 if (aggregate->count > 0)
4683 {
4684 rn = bgp_node_get (table, p);
4685 new = bgp_info_new ();
4686 new->type = ZEBRA_ROUTE_BGP;
4687 new->sub_type = BGP_ROUTE_AGGREGATE;
4688 new->peer = bgp->peer_self;
4689 SET_FLAG (new->flags, BGP_INFO_VALID);
4690 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004691 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004692
4693 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004694 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004695 bgp_process (bgp, rn, afi, safi);
4696 }
4697 else
4698 {
4699 if (aspath)
4700 aspath_free (aspath);
4701 if (community)
4702 community_free (community);
4703 }
4704}
4705
4706void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4707 struct bgp_aggregate *);
4708
4709void
4710bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4711 struct bgp_info *ri, afi_t afi, safi_t safi)
4712{
4713 struct bgp_node *child;
4714 struct bgp_node *rn;
4715 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004716 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004717
4718 /* MPLS-VPN aggregation is not yet supported. */
4719 if (safi == SAFI_MPLS_VPN)
4720 return;
4721
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004722 table = bgp->aggregate[afi][safi];
4723
4724 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004725 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004726 return;
4727
paul718e3742002-12-13 20:15:29 +00004728 if (p->prefixlen == 0)
4729 return;
4730
4731 if (BGP_INFO_HOLDDOWN (ri))
4732 return;
4733
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004734 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004735
4736 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004737 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004738 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4739 {
4740 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004741 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004742 }
4743 bgp_unlock_node (child);
4744}
4745
4746void
4747bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4748 struct bgp_info *del, afi_t afi, safi_t safi)
4749{
4750 struct bgp_node *child;
4751 struct bgp_node *rn;
4752 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004753 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004754
4755 /* MPLS-VPN aggregation is not yet supported. */
4756 if (safi == SAFI_MPLS_VPN)
4757 return;
4758
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004759 table = bgp->aggregate[afi][safi];
4760
4761 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004762 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004763 return;
4764
paul718e3742002-12-13 20:15:29 +00004765 if (p->prefixlen == 0)
4766 return;
4767
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004768 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004769
4770 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004771 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004772 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4773 {
4774 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004775 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004776 }
4777 bgp_unlock_node (child);
4778}
4779
paul94f2b392005-06-28 12:44:16 +00004780static void
paul718e3742002-12-13 20:15:29 +00004781bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4782 struct bgp_aggregate *aggregate)
4783{
4784 struct bgp_table *table;
4785 struct bgp_node *top;
4786 struct bgp_node *rn;
4787 struct bgp_info *new;
4788 struct bgp_info *ri;
4789 unsigned long match;
4790 u_char origin = BGP_ORIGIN_IGP;
4791 struct aspath *aspath = NULL;
4792 struct aspath *asmerge = NULL;
4793 struct community *community = NULL;
4794 struct community *commerge = NULL;
4795
4796 table = bgp->rib[afi][safi];
4797
4798 /* Sanity check. */
4799 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4800 return;
4801 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4802 return;
4803
4804 /* If routes exists below this node, generate aggregate routes. */
4805 top = bgp_node_get (table, p);
4806 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4807 if (rn->p.prefixlen > p->prefixlen)
4808 {
4809 match = 0;
4810
4811 for (ri = rn->info; ri; ri = ri->next)
4812 {
4813 if (BGP_INFO_HOLDDOWN (ri))
4814 continue;
4815
4816 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4817 {
4818 /* summary-only aggregate route suppress aggregated
4819 route announcement. */
4820 if (aggregate->summary_only)
4821 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004822 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004823 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004824 match++;
4825 }
4826 /* as-set aggregate route generate origin, as path,
4827 community aggregation. */
4828 if (aggregate->as_set)
4829 {
4830 if (origin < ri->attr->origin)
4831 origin = ri->attr->origin;
4832
4833 if (aspath)
4834 {
4835 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4836 aspath_free (aspath);
4837 aspath = asmerge;
4838 }
4839 else
4840 aspath = aspath_dup (ri->attr->aspath);
4841
4842 if (ri->attr->community)
4843 {
4844 if (community)
4845 {
4846 commerge = community_merge (community,
4847 ri->attr->community);
4848 community = community_uniq_sort (commerge);
4849 community_free (commerge);
4850 }
4851 else
4852 community = community_dup (ri->attr->community);
4853 }
4854 }
4855 aggregate->count++;
4856 }
4857 }
4858
4859 /* If this node is suppressed, process the change. */
4860 if (match)
4861 bgp_process (bgp, rn, afi, safi);
4862 }
4863 bgp_unlock_node (top);
4864
4865 /* Add aggregate route to BGP table. */
4866 if (aggregate->count)
4867 {
4868 rn = bgp_node_get (table, p);
4869
4870 new = bgp_info_new ();
4871 new->type = ZEBRA_ROUTE_BGP;
4872 new->sub_type = BGP_ROUTE_AGGREGATE;
4873 new->peer = bgp->peer_self;
4874 SET_FLAG (new->flags, BGP_INFO_VALID);
4875 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004876 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004877
4878 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004879 bgp_unlock_node (rn);
4880
paul718e3742002-12-13 20:15:29 +00004881 /* Process change. */
4882 bgp_process (bgp, rn, afi, safi);
4883 }
4884}
4885
4886void
4887bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4888 safi_t safi, struct bgp_aggregate *aggregate)
4889{
4890 struct bgp_table *table;
4891 struct bgp_node *top;
4892 struct bgp_node *rn;
4893 struct bgp_info *ri;
4894 unsigned long match;
4895
4896 table = bgp->rib[afi][safi];
4897
4898 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4899 return;
4900 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4901 return;
4902
4903 /* If routes exists below this node, generate aggregate routes. */
4904 top = bgp_node_get (table, p);
4905 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4906 if (rn->p.prefixlen > p->prefixlen)
4907 {
4908 match = 0;
4909
4910 for (ri = rn->info; ri; ri = ri->next)
4911 {
4912 if (BGP_INFO_HOLDDOWN (ri))
4913 continue;
4914
4915 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4916 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004917 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004918 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004919 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004920
Paul Jakmafb982c22007-05-04 20:15:47 +00004921 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004922 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004923 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004924 match++;
4925 }
4926 }
4927 aggregate->count--;
4928 }
4929 }
4930
Paul Jakmafb982c22007-05-04 20:15:47 +00004931 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004932 if (match)
4933 bgp_process (bgp, rn, afi, safi);
4934 }
4935 bgp_unlock_node (top);
4936
4937 /* Delete aggregate route from BGP table. */
4938 rn = bgp_node_get (table, p);
4939
4940 for (ri = rn->info; ri; ri = ri->next)
4941 if (ri->peer == bgp->peer_self
4942 && ri->type == ZEBRA_ROUTE_BGP
4943 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4944 break;
4945
4946 /* Withdraw static BGP route from routing table. */
4947 if (ri)
4948 {
paul718e3742002-12-13 20:15:29 +00004949 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004950 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004951 }
4952
4953 /* Unlock bgp_node_lookup. */
4954 bgp_unlock_node (rn);
4955}
4956
4957/* Aggregate route attribute. */
4958#define AGGREGATE_SUMMARY_ONLY 1
4959#define AGGREGATE_AS_SET 1
4960
paul94f2b392005-06-28 12:44:16 +00004961static int
Robert Baysf6269b42010-08-05 10:26:28 -07004962bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4963 afi_t afi, safi_t safi)
4964{
4965 int ret;
4966 struct prefix p;
4967 struct bgp_node *rn;
4968 struct bgp *bgp;
4969 struct bgp_aggregate *aggregate;
4970
4971 /* Convert string to prefix structure. */
4972 ret = str2prefix (prefix_str, &p);
4973 if (!ret)
4974 {
4975 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4976 return CMD_WARNING;
4977 }
4978 apply_mask (&p);
4979
4980 /* Get BGP structure. */
4981 bgp = vty->index;
4982
4983 /* Old configuration check. */
4984 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4985 if (! rn)
4986 {
4987 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4988 VTY_NEWLINE);
4989 return CMD_WARNING;
4990 }
4991
4992 aggregate = rn->info;
4993 if (aggregate->safi & SAFI_UNICAST)
4994 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4995 if (aggregate->safi & SAFI_MULTICAST)
4996 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4997
4998 /* Unlock aggregate address configuration. */
4999 rn->info = NULL;
5000 bgp_aggregate_free (aggregate);
5001 bgp_unlock_node (rn);
5002 bgp_unlock_node (rn);
5003
5004 return CMD_SUCCESS;
5005}
5006
5007static int
5008bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005009 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005010 u_char summary_only, u_char as_set)
5011{
5012 int ret;
5013 struct prefix p;
5014 struct bgp_node *rn;
5015 struct bgp *bgp;
5016 struct bgp_aggregate *aggregate;
5017
5018 /* Convert string to prefix structure. */
5019 ret = str2prefix (prefix_str, &p);
5020 if (!ret)
5021 {
5022 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5023 return CMD_WARNING;
5024 }
5025 apply_mask (&p);
5026
5027 /* Get BGP structure. */
5028 bgp = vty->index;
5029
5030 /* Old configuration check. */
5031 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5032
5033 if (rn->info)
5034 {
5035 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005036 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005037 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5038 if (ret)
5039 {
Robert Bays368473f2010-08-05 10:26:29 -07005040 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5041 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005042 return CMD_WARNING;
5043 }
paul718e3742002-12-13 20:15:29 +00005044 }
5045
5046 /* Make aggregate address structure. */
5047 aggregate = bgp_aggregate_new ();
5048 aggregate->summary_only = summary_only;
5049 aggregate->as_set = as_set;
5050 aggregate->safi = safi;
5051 rn->info = aggregate;
5052
5053 /* Aggregate address insert into BGP routing table. */
5054 if (safi & SAFI_UNICAST)
5055 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5056 if (safi & SAFI_MULTICAST)
5057 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5058
5059 return CMD_SUCCESS;
5060}
5061
paul718e3742002-12-13 20:15:29 +00005062DEFUN (aggregate_address,
5063 aggregate_address_cmd,
5064 "aggregate-address A.B.C.D/M",
5065 "Configure BGP aggregate entries\n"
5066 "Aggregate prefix\n")
5067{
5068 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5069}
5070
5071DEFUN (aggregate_address_mask,
5072 aggregate_address_mask_cmd,
5073 "aggregate-address A.B.C.D A.B.C.D",
5074 "Configure BGP aggregate entries\n"
5075 "Aggregate address\n"
5076 "Aggregate mask\n")
5077{
5078 int ret;
5079 char prefix_str[BUFSIZ];
5080
5081 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5082
5083 if (! ret)
5084 {
5085 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5086 return CMD_WARNING;
5087 }
5088
5089 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5090 0, 0);
5091}
5092
5093DEFUN (aggregate_address_summary_only,
5094 aggregate_address_summary_only_cmd,
5095 "aggregate-address A.B.C.D/M summary-only",
5096 "Configure BGP aggregate entries\n"
5097 "Aggregate prefix\n"
5098 "Filter more specific routes from updates\n")
5099{
5100 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5101 AGGREGATE_SUMMARY_ONLY, 0);
5102}
5103
5104DEFUN (aggregate_address_mask_summary_only,
5105 aggregate_address_mask_summary_only_cmd,
5106 "aggregate-address A.B.C.D A.B.C.D summary-only",
5107 "Configure BGP aggregate entries\n"
5108 "Aggregate address\n"
5109 "Aggregate mask\n"
5110 "Filter more specific routes from updates\n")
5111{
5112 int ret;
5113 char prefix_str[BUFSIZ];
5114
5115 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5116
5117 if (! ret)
5118 {
5119 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5120 return CMD_WARNING;
5121 }
5122
5123 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5124 AGGREGATE_SUMMARY_ONLY, 0);
5125}
5126
5127DEFUN (aggregate_address_as_set,
5128 aggregate_address_as_set_cmd,
5129 "aggregate-address A.B.C.D/M as-set",
5130 "Configure BGP aggregate entries\n"
5131 "Aggregate prefix\n"
5132 "Generate AS set path information\n")
5133{
5134 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5135 0, AGGREGATE_AS_SET);
5136}
5137
5138DEFUN (aggregate_address_mask_as_set,
5139 aggregate_address_mask_as_set_cmd,
5140 "aggregate-address A.B.C.D A.B.C.D as-set",
5141 "Configure BGP aggregate entries\n"
5142 "Aggregate address\n"
5143 "Aggregate mask\n"
5144 "Generate AS set path information\n")
5145{
5146 int ret;
5147 char prefix_str[BUFSIZ];
5148
5149 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5150
5151 if (! ret)
5152 {
5153 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5154 return CMD_WARNING;
5155 }
5156
5157 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5158 0, AGGREGATE_AS_SET);
5159}
5160
5161
5162DEFUN (aggregate_address_as_set_summary,
5163 aggregate_address_as_set_summary_cmd,
5164 "aggregate-address A.B.C.D/M as-set summary-only",
5165 "Configure BGP aggregate entries\n"
5166 "Aggregate prefix\n"
5167 "Generate AS set path information\n"
5168 "Filter more specific routes from updates\n")
5169{
5170 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5171 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5172}
5173
5174ALIAS (aggregate_address_as_set_summary,
5175 aggregate_address_summary_as_set_cmd,
5176 "aggregate-address A.B.C.D/M summary-only as-set",
5177 "Configure BGP aggregate entries\n"
5178 "Aggregate prefix\n"
5179 "Filter more specific routes from updates\n"
5180 "Generate AS set path information\n")
5181
5182DEFUN (aggregate_address_mask_as_set_summary,
5183 aggregate_address_mask_as_set_summary_cmd,
5184 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5185 "Configure BGP aggregate entries\n"
5186 "Aggregate address\n"
5187 "Aggregate mask\n"
5188 "Generate AS set path information\n"
5189 "Filter more specific routes from updates\n")
5190{
5191 int ret;
5192 char prefix_str[BUFSIZ];
5193
5194 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5195
5196 if (! ret)
5197 {
5198 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5199 return CMD_WARNING;
5200 }
5201
5202 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5203 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5204}
5205
5206ALIAS (aggregate_address_mask_as_set_summary,
5207 aggregate_address_mask_summary_as_set_cmd,
5208 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5209 "Configure BGP aggregate entries\n"
5210 "Aggregate address\n"
5211 "Aggregate mask\n"
5212 "Filter more specific routes from updates\n"
5213 "Generate AS set path information\n")
5214
5215DEFUN (no_aggregate_address,
5216 no_aggregate_address_cmd,
5217 "no aggregate-address A.B.C.D/M",
5218 NO_STR
5219 "Configure BGP aggregate entries\n"
5220 "Aggregate prefix\n")
5221{
5222 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5223}
5224
5225ALIAS (no_aggregate_address,
5226 no_aggregate_address_summary_only_cmd,
5227 "no aggregate-address A.B.C.D/M summary-only",
5228 NO_STR
5229 "Configure BGP aggregate entries\n"
5230 "Aggregate prefix\n"
5231 "Filter more specific routes from updates\n")
5232
5233ALIAS (no_aggregate_address,
5234 no_aggregate_address_as_set_cmd,
5235 "no aggregate-address A.B.C.D/M as-set",
5236 NO_STR
5237 "Configure BGP aggregate entries\n"
5238 "Aggregate prefix\n"
5239 "Generate AS set path information\n")
5240
5241ALIAS (no_aggregate_address,
5242 no_aggregate_address_as_set_summary_cmd,
5243 "no aggregate-address A.B.C.D/M as-set summary-only",
5244 NO_STR
5245 "Configure BGP aggregate entries\n"
5246 "Aggregate prefix\n"
5247 "Generate AS set path information\n"
5248 "Filter more specific routes from updates\n")
5249
5250ALIAS (no_aggregate_address,
5251 no_aggregate_address_summary_as_set_cmd,
5252 "no aggregate-address A.B.C.D/M summary-only as-set",
5253 NO_STR
5254 "Configure BGP aggregate entries\n"
5255 "Aggregate prefix\n"
5256 "Filter more specific routes from updates\n"
5257 "Generate AS set path information\n")
5258
5259DEFUN (no_aggregate_address_mask,
5260 no_aggregate_address_mask_cmd,
5261 "no aggregate-address A.B.C.D A.B.C.D",
5262 NO_STR
5263 "Configure BGP aggregate entries\n"
5264 "Aggregate address\n"
5265 "Aggregate mask\n")
5266{
5267 int ret;
5268 char prefix_str[BUFSIZ];
5269
5270 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5271
5272 if (! ret)
5273 {
5274 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5275 return CMD_WARNING;
5276 }
5277
5278 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5279}
5280
5281ALIAS (no_aggregate_address_mask,
5282 no_aggregate_address_mask_summary_only_cmd,
5283 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5284 NO_STR
5285 "Configure BGP aggregate entries\n"
5286 "Aggregate address\n"
5287 "Aggregate mask\n"
5288 "Filter more specific routes from updates\n")
5289
5290ALIAS (no_aggregate_address_mask,
5291 no_aggregate_address_mask_as_set_cmd,
5292 "no aggregate-address A.B.C.D A.B.C.D as-set",
5293 NO_STR
5294 "Configure BGP aggregate entries\n"
5295 "Aggregate address\n"
5296 "Aggregate mask\n"
5297 "Generate AS set path information\n")
5298
5299ALIAS (no_aggregate_address_mask,
5300 no_aggregate_address_mask_as_set_summary_cmd,
5301 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5302 NO_STR
5303 "Configure BGP aggregate entries\n"
5304 "Aggregate address\n"
5305 "Aggregate mask\n"
5306 "Generate AS set path information\n"
5307 "Filter more specific routes from updates\n")
5308
5309ALIAS (no_aggregate_address_mask,
5310 no_aggregate_address_mask_summary_as_set_cmd,
5311 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5312 NO_STR
5313 "Configure BGP aggregate entries\n"
5314 "Aggregate address\n"
5315 "Aggregate mask\n"
5316 "Filter more specific routes from updates\n"
5317 "Generate AS set path information\n")
5318
5319#ifdef HAVE_IPV6
5320DEFUN (ipv6_aggregate_address,
5321 ipv6_aggregate_address_cmd,
5322 "aggregate-address X:X::X:X/M",
5323 "Configure BGP aggregate entries\n"
5324 "Aggregate prefix\n")
5325{
5326 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5327}
5328
5329DEFUN (ipv6_aggregate_address_summary_only,
5330 ipv6_aggregate_address_summary_only_cmd,
5331 "aggregate-address X:X::X:X/M summary-only",
5332 "Configure BGP aggregate entries\n"
5333 "Aggregate prefix\n"
5334 "Filter more specific routes from updates\n")
5335{
5336 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5337 AGGREGATE_SUMMARY_ONLY, 0);
5338}
5339
5340DEFUN (no_ipv6_aggregate_address,
5341 no_ipv6_aggregate_address_cmd,
5342 "no aggregate-address X:X::X:X/M",
5343 NO_STR
5344 "Configure BGP aggregate entries\n"
5345 "Aggregate prefix\n")
5346{
5347 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5348}
5349
5350DEFUN (no_ipv6_aggregate_address_summary_only,
5351 no_ipv6_aggregate_address_summary_only_cmd,
5352 "no aggregate-address X:X::X:X/M summary-only",
5353 NO_STR
5354 "Configure BGP aggregate entries\n"
5355 "Aggregate prefix\n"
5356 "Filter more specific routes from updates\n")
5357{
5358 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5359}
5360
5361ALIAS (ipv6_aggregate_address,
5362 old_ipv6_aggregate_address_cmd,
5363 "ipv6 bgp aggregate-address X:X::X:X/M",
5364 IPV6_STR
5365 BGP_STR
5366 "Configure BGP aggregate entries\n"
5367 "Aggregate prefix\n")
5368
5369ALIAS (ipv6_aggregate_address_summary_only,
5370 old_ipv6_aggregate_address_summary_only_cmd,
5371 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5372 IPV6_STR
5373 BGP_STR
5374 "Configure BGP aggregate entries\n"
5375 "Aggregate prefix\n"
5376 "Filter more specific routes from updates\n")
5377
5378ALIAS (no_ipv6_aggregate_address,
5379 old_no_ipv6_aggregate_address_cmd,
5380 "no ipv6 bgp aggregate-address X:X::X:X/M",
5381 NO_STR
5382 IPV6_STR
5383 BGP_STR
5384 "Configure BGP aggregate entries\n"
5385 "Aggregate prefix\n")
5386
5387ALIAS (no_ipv6_aggregate_address_summary_only,
5388 old_no_ipv6_aggregate_address_summary_only_cmd,
5389 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5390 NO_STR
5391 IPV6_STR
5392 BGP_STR
5393 "Configure BGP aggregate entries\n"
5394 "Aggregate prefix\n"
5395 "Filter more specific routes from updates\n")
5396#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005397
paul718e3742002-12-13 20:15:29 +00005398/* Redistribute route treatment. */
5399void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005400bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5401 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005402 u_int32_t metric, u_char type)
5403{
5404 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005405 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005406 struct bgp_info *new;
5407 struct bgp_info *bi;
5408 struct bgp_info info;
5409 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005410 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005411 struct attr *new_attr;
5412 afi_t afi;
5413 int ret;
5414
5415 /* Make default attribute. */
5416 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5417 if (nexthop)
5418 attr.nexthop = *nexthop;
5419
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005420#ifdef HAVE_IPV6
5421 if (nexthop6)
5422 {
5423 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5424 extra->mp_nexthop_global = *nexthop6;
5425 extra->mp_nexthop_len = 16;
5426 }
5427#endif
5428
paul718e3742002-12-13 20:15:29 +00005429 attr.med = metric;
5430 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5431
paul1eb8ef22005-04-07 07:30:20 +00005432 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005433 {
5434 afi = family2afi (p->family);
5435
5436 if (bgp->redist[afi][type])
5437 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005438 struct attr attr_new;
5439 struct attr_extra extra_new;
5440
paul718e3742002-12-13 20:15:29 +00005441 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005442 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005443 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005444
5445 if (bgp->redist_metric_flag[afi][type])
5446 attr_new.med = bgp->redist_metric[afi][type];
5447
5448 /* Apply route-map. */
5449 if (bgp->rmap[afi][type].map)
5450 {
5451 info.peer = bgp->peer_self;
5452 info.attr = &attr_new;
5453
paulfee0f4c2004-09-13 05:12:46 +00005454 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5455
paul718e3742002-12-13 20:15:29 +00005456 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5457 &info);
paulfee0f4c2004-09-13 05:12:46 +00005458
5459 bgp->peer_self->rmap_type = 0;
5460
paul718e3742002-12-13 20:15:29 +00005461 if (ret == RMAP_DENYMATCH)
5462 {
5463 /* Free uninterned attribute. */
5464 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005465
paul718e3742002-12-13 20:15:29 +00005466 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005467 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005468 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005469 bgp_redistribute_delete (p, type);
5470 return;
5471 }
5472 }
5473
Paul Jakmafb982c22007-05-04 20:15:47 +00005474 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5475 afi, SAFI_UNICAST, p, NULL);
5476
paul718e3742002-12-13 20:15:29 +00005477 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005478
paul718e3742002-12-13 20:15:29 +00005479 for (bi = bn->info; bi; bi = bi->next)
5480 if (bi->peer == bgp->peer_self
5481 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5482 break;
5483
5484 if (bi)
5485 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005486 if (attrhash_cmp (bi->attr, new_attr) &&
5487 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005488 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005489 bgp_attr_unintern (&new_attr);
5490 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005491 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005492 bgp_unlock_node (bn);
5493 return;
5494 }
5495 else
5496 {
5497 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005498 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005499
5500 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005501 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5502 bgp_info_restore(bn, bi);
5503 else
5504 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005505 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005506 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005507 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005508
5509 /* Process change. */
5510 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5511 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5512 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005513 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005514 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005515 return;
5516 }
5517 }
5518
5519 new = bgp_info_new ();
5520 new->type = type;
5521 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5522 new->peer = bgp->peer_self;
5523 SET_FLAG (new->flags, BGP_INFO_VALID);
5524 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005525 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005526
5527 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5528 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005529 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005530 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5531 }
5532 }
5533
5534 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005535 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005536 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005537}
5538
5539void
5540bgp_redistribute_delete (struct prefix *p, u_char type)
5541{
5542 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005543 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005544 afi_t afi;
5545 struct bgp_node *rn;
5546 struct bgp_info *ri;
5547
paul1eb8ef22005-04-07 07:30:20 +00005548 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005549 {
5550 afi = family2afi (p->family);
5551
5552 if (bgp->redist[afi][type])
5553 {
paulfee0f4c2004-09-13 05:12:46 +00005554 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005555
5556 for (ri = rn->info; ri; ri = ri->next)
5557 if (ri->peer == bgp->peer_self
5558 && ri->type == type)
5559 break;
5560
5561 if (ri)
5562 {
5563 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005564 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005565 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005566 }
5567 bgp_unlock_node (rn);
5568 }
5569 }
5570}
5571
5572/* Withdraw specified route type's route. */
5573void
5574bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5575{
5576 struct bgp_node *rn;
5577 struct bgp_info *ri;
5578 struct bgp_table *table;
5579
5580 table = bgp->rib[afi][SAFI_UNICAST];
5581
5582 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5583 {
5584 for (ri = rn->info; ri; ri = ri->next)
5585 if (ri->peer == bgp->peer_self
5586 && ri->type == type)
5587 break;
5588
5589 if (ri)
5590 {
5591 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005592 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005593 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005594 }
5595 }
5596}
David Lamparter6b0655a2014-06-04 06:53:35 +02005597
paul718e3742002-12-13 20:15:29 +00005598/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005599static void
paul718e3742002-12-13 20:15:29 +00005600route_vty_out_route (struct prefix *p, struct vty *vty)
5601{
5602 int len;
5603 u_int32_t destination;
5604 char buf[BUFSIZ];
5605
5606 if (p->family == AF_INET)
5607 {
5608 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5609 destination = ntohl (p->u.prefix4.s_addr);
5610
5611 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5612 || (IN_CLASSB (destination) && p->prefixlen == 16)
5613 || (IN_CLASSA (destination) && p->prefixlen == 8)
5614 || p->u.prefix4.s_addr == 0)
5615 {
5616 /* When mask is natural, mask is not displayed. */
5617 }
5618 else
5619 len += vty_out (vty, "/%d", p->prefixlen);
5620 }
5621 else
5622 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5623 p->prefixlen);
5624
5625 len = 17 - len;
5626 if (len < 1)
5627 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5628 else
5629 vty_out (vty, "%*s", len, " ");
5630}
5631
paul718e3742002-12-13 20:15:29 +00005632enum bgp_display_type
5633{
5634 normal_list,
5635};
5636
paulb40d9392005-08-22 22:34:41 +00005637/* Print the short form route status for a bgp_info */
5638static void
5639route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005640{
paulb40d9392005-08-22 22:34:41 +00005641 /* Route status display. */
5642 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5643 vty_out (vty, "R");
5644 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005645 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005646 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005647 vty_out (vty, "s");
5648 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5649 vty_out (vty, "*");
5650 else
5651 vty_out (vty, " ");
5652
5653 /* Selected */
5654 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5655 vty_out (vty, "h");
5656 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5657 vty_out (vty, "d");
5658 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5659 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005660 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5661 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005662 else
5663 vty_out (vty, " ");
5664
5665 /* Internal route. */
5666 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5667 vty_out (vty, "i");
5668 else
paulb40d9392005-08-22 22:34:41 +00005669 vty_out (vty, " ");
5670}
5671
5672/* called from terminal list command */
5673void
5674route_vty_out (struct vty *vty, struct prefix *p,
5675 struct bgp_info *binfo, int display, safi_t safi)
5676{
5677 struct attr *attr;
5678
5679 /* short status lead text */
5680 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005681
5682 /* print prefix and mask */
5683 if (! display)
5684 route_vty_out_route (p, vty);
5685 else
5686 vty_out (vty, "%*s", 17, " ");
5687
5688 /* Print attribute */
5689 attr = binfo->attr;
5690 if (attr)
5691 {
5692 if (p->family == AF_INET)
5693 {
5694 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005695 vty_out (vty, "%-16s",
5696 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005697 else
5698 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5699 }
5700#ifdef HAVE_IPV6
5701 else if (p->family == AF_INET6)
5702 {
5703 int len;
5704 char buf[BUFSIZ];
5705
5706 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005707 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5708 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005709 len = 16 - len;
5710 if (len < 1)
5711 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5712 else
5713 vty_out (vty, "%*s", len, " ");
5714 }
5715#endif /* HAVE_IPV6 */
5716
5717 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005718 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005719 else
5720 vty_out (vty, " ");
5721
5722 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005723 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005724 else
5725 vty_out (vty, " ");
5726
Paul Jakmafb982c22007-05-04 20:15:47 +00005727 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005728
Paul Jakmab2518c12006-05-12 23:48:40 +00005729 /* Print aspath */
5730 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005731 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005732
Paul Jakmab2518c12006-05-12 23:48:40 +00005733 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005734 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005735 }
paul718e3742002-12-13 20:15:29 +00005736 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005737}
5738
5739/* called from terminal list command */
5740void
5741route_vty_out_tmp (struct vty *vty, struct prefix *p,
5742 struct attr *attr, safi_t safi)
5743{
5744 /* Route status display. */
5745 vty_out (vty, "*");
5746 vty_out (vty, ">");
5747 vty_out (vty, " ");
5748
5749 /* print prefix and mask */
5750 route_vty_out_route (p, vty);
5751
5752 /* Print attribute */
5753 if (attr)
5754 {
5755 if (p->family == AF_INET)
5756 {
5757 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005758 vty_out (vty, "%-16s",
5759 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005760 else
5761 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5762 }
5763#ifdef HAVE_IPV6
5764 else if (p->family == AF_INET6)
5765 {
5766 int len;
5767 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005768
5769 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005770
5771 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005772 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5773 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005774 len = 16 - len;
5775 if (len < 1)
5776 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5777 else
5778 vty_out (vty, "%*s", len, " ");
5779 }
5780#endif /* HAVE_IPV6 */
5781
5782 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005783 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005784 else
5785 vty_out (vty, " ");
5786
5787 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005788 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005789 else
5790 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005791
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005792 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005793
Paul Jakmab2518c12006-05-12 23:48:40 +00005794 /* Print aspath */
5795 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005796 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005797
Paul Jakmab2518c12006-05-12 23:48:40 +00005798 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005799 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005800 }
paul718e3742002-12-13 20:15:29 +00005801
5802 vty_out (vty, "%s", VTY_NEWLINE);
5803}
5804
ajs5a646652004-11-05 01:25:55 +00005805void
paul718e3742002-12-13 20:15:29 +00005806route_vty_out_tag (struct vty *vty, struct prefix *p,
5807 struct bgp_info *binfo, int display, safi_t safi)
5808{
5809 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005810 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005811
5812 if (!binfo->extra)
5813 return;
5814
paulb40d9392005-08-22 22:34:41 +00005815 /* short status lead text */
5816 route_vty_short_status_out (vty, binfo);
5817
paul718e3742002-12-13 20:15:29 +00005818 /* print prefix and mask */
5819 if (! display)
5820 route_vty_out_route (p, vty);
5821 else
5822 vty_out (vty, "%*s", 17, " ");
5823
5824 /* Print attribute */
5825 attr = binfo->attr;
5826 if (attr)
5827 {
5828 if (p->family == AF_INET)
5829 {
5830 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005831 vty_out (vty, "%-16s",
5832 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005833 else
5834 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5835 }
5836#ifdef HAVE_IPV6
5837 else if (p->family == AF_INET6)
5838 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005839 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005840 char buf[BUFSIZ];
5841 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005842 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005843 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005844 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5845 buf, BUFSIZ));
5846 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005847 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005848 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5849 buf, BUFSIZ),
5850 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5851 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005852
5853 }
5854#endif /* HAVE_IPV6 */
5855 }
5856
Paul Jakmafb982c22007-05-04 20:15:47 +00005857 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005858
5859 vty_out (vty, "notag/%d", label);
5860
5861 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005862}
5863
5864/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005865static void
paul718e3742002-12-13 20:15:29 +00005866damp_route_vty_out (struct vty *vty, struct prefix *p,
5867 struct bgp_info *binfo, int display, safi_t safi)
5868{
5869 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005870 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005871 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005872
paulb40d9392005-08-22 22:34:41 +00005873 /* short status lead text */
5874 route_vty_short_status_out (vty, binfo);
5875
paul718e3742002-12-13 20:15:29 +00005876 /* print prefix and mask */
5877 if (! display)
5878 route_vty_out_route (p, vty);
5879 else
5880 vty_out (vty, "%*s", 17, " ");
5881
5882 len = vty_out (vty, "%s", binfo->peer->host);
5883 len = 17 - len;
5884 if (len < 1)
5885 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5886 else
5887 vty_out (vty, "%*s", len, " ");
5888
Chris Caputo50aef6f2009-06-23 06:06:49 +00005889 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005890
5891 /* Print attribute */
5892 attr = binfo->attr;
5893 if (attr)
5894 {
5895 /* Print aspath */
5896 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005897 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005898
5899 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005900 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005901 }
5902 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005903}
5904
paul718e3742002-12-13 20:15:29 +00005905/* flap route */
ajs5a646652004-11-05 01:25:55 +00005906static void
paul718e3742002-12-13 20:15:29 +00005907flap_route_vty_out (struct vty *vty, struct prefix *p,
5908 struct bgp_info *binfo, int display, safi_t safi)
5909{
5910 struct attr *attr;
5911 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005912 char timebuf[BGP_UPTIME_LEN];
5913 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005914
5915 if (!binfo->extra)
5916 return;
5917
5918 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005919
paulb40d9392005-08-22 22:34:41 +00005920 /* short status lead text */
5921 route_vty_short_status_out (vty, binfo);
5922
paul718e3742002-12-13 20:15:29 +00005923 /* print prefix and mask */
5924 if (! display)
5925 route_vty_out_route (p, vty);
5926 else
5927 vty_out (vty, "%*s", 17, " ");
5928
5929 len = vty_out (vty, "%s", binfo->peer->host);
5930 len = 16 - len;
5931 if (len < 1)
5932 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5933 else
5934 vty_out (vty, "%*s", len, " ");
5935
5936 len = vty_out (vty, "%d", bdi->flap);
5937 len = 5 - len;
5938 if (len < 1)
5939 vty_out (vty, " ");
5940 else
5941 vty_out (vty, "%*s ", len, " ");
5942
5943 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5944 timebuf, BGP_UPTIME_LEN));
5945
5946 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5947 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005948 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005949 else
5950 vty_out (vty, "%*s ", 8, " ");
5951
5952 /* Print attribute */
5953 attr = binfo->attr;
5954 if (attr)
5955 {
5956 /* Print aspath */
5957 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005958 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005959
5960 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005961 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005962 }
5963 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005964}
5965
paul94f2b392005-06-28 12:44:16 +00005966static void
paul718e3742002-12-13 20:15:29 +00005967route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5968 struct bgp_info *binfo, afi_t afi, safi_t safi)
5969{
5970 char buf[INET6_ADDRSTRLEN];
5971 char buf1[BUFSIZ];
5972 struct attr *attr;
5973 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005974#ifdef HAVE_CLOCK_MONOTONIC
5975 time_t tbuf;
5976#endif
paul718e3742002-12-13 20:15:29 +00005977
5978 attr = binfo->attr;
5979
5980 if (attr)
5981 {
5982 /* Line1 display AS-path, Aggregator */
5983 if (attr->aspath)
5984 {
5985 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005986 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005987 vty_out (vty, "Local");
5988 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005989 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005990 }
5991
paulb40d9392005-08-22 22:34:41 +00005992 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5993 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005994 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5995 vty_out (vty, ", (stale)");
5996 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005997 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005998 attr->extra->aggregator_as,
5999 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006000 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6001 vty_out (vty, ", (Received from a RR-client)");
6002 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6003 vty_out (vty, ", (Received from a RS-client)");
6004 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6005 vty_out (vty, ", (history entry)");
6006 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6007 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006008 vty_out (vty, "%s", VTY_NEWLINE);
6009
6010 /* Line2 display Next-hop, Neighbor, Router-id */
6011 if (p->family == AF_INET)
6012 {
6013 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006014 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006015 inet_ntoa (attr->nexthop));
6016 }
6017#ifdef HAVE_IPV6
6018 else
6019 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006020 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006021 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006022 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006023 buf, INET6_ADDRSTRLEN));
6024 }
6025#endif /* HAVE_IPV6 */
6026
6027 if (binfo->peer == bgp->peer_self)
6028 {
6029 vty_out (vty, " from %s ",
6030 p->family == AF_INET ? "0.0.0.0" : "::");
6031 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6032 }
6033 else
6034 {
6035 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6036 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006037 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006038 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006039 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006040 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006041 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006042 else
6043 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6044 }
6045 vty_out (vty, "%s", VTY_NEWLINE);
6046
6047#ifdef HAVE_IPV6
6048 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006049 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006050 {
6051 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006052 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006053 buf, INET6_ADDRSTRLEN),
6054 VTY_NEWLINE);
6055 }
6056#endif /* HAVE_IPV6 */
6057
6058 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6059 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6060
6061 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006062 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006063
6064 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006065 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006066 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006067 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006068
Paul Jakmafb982c22007-05-04 20:15:47 +00006069 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006070 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006071
6072 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6073 vty_out (vty, ", valid");
6074
6075 if (binfo->peer != bgp->peer_self)
6076 {
6077 if (binfo->peer->as == binfo->peer->local_as)
6078 vty_out (vty, ", internal");
6079 else
6080 vty_out (vty, ", %s",
6081 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6082 }
6083 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6084 vty_out (vty, ", aggregated, local");
6085 else if (binfo->type != ZEBRA_ROUTE_BGP)
6086 vty_out (vty, ", sourced");
6087 else
6088 vty_out (vty, ", sourced, local");
6089
6090 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6091 vty_out (vty, ", atomic-aggregate");
6092
Josh Baileyde8d5df2011-07-20 20:46:01 -07006093 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6094 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6095 bgp_info_mpath_count (binfo)))
6096 vty_out (vty, ", multipath");
6097
paul718e3742002-12-13 20:15:29 +00006098 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6099 vty_out (vty, ", best");
6100
6101 vty_out (vty, "%s", VTY_NEWLINE);
6102
6103 /* Line 4 display Community */
6104 if (attr->community)
6105 vty_out (vty, " Community: %s%s", attr->community->str,
6106 VTY_NEWLINE);
6107
6108 /* Line 5 display Extended-community */
6109 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006110 vty_out (vty, " Extended Community: %s%s",
6111 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006112
6113 /* Line 6 display Originator, Cluster-id */
6114 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6115 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6116 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006117 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006118 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006119 vty_out (vty, " Originator: %s",
6120 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006121
6122 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6123 {
6124 int i;
6125 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006126 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6127 vty_out (vty, "%s ",
6128 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006129 }
6130 vty_out (vty, "%s", VTY_NEWLINE);
6131 }
Paul Jakma41367172007-08-06 15:24:51 +00006132
Paul Jakmafb982c22007-05-04 20:15:47 +00006133 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006134 bgp_damp_info_vty (vty, binfo);
6135
6136 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006137#ifdef HAVE_CLOCK_MONOTONIC
6138 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006139 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006140#else
6141 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6142#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006143 }
6144 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006145}
6146
6147#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6148 "h history, * valid, > best, = multipath,%s"\
6149 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006150#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006151#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6152#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6153#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6154
6155enum bgp_show_type
6156{
6157 bgp_show_type_normal,
6158 bgp_show_type_regexp,
6159 bgp_show_type_prefix_list,
6160 bgp_show_type_filter_list,
6161 bgp_show_type_route_map,
6162 bgp_show_type_neighbor,
6163 bgp_show_type_cidr_only,
6164 bgp_show_type_prefix_longer,
6165 bgp_show_type_community_all,
6166 bgp_show_type_community,
6167 bgp_show_type_community_exact,
6168 bgp_show_type_community_list,
6169 bgp_show_type_community_list_exact,
6170 bgp_show_type_flap_statistics,
6171 bgp_show_type_flap_address,
6172 bgp_show_type_flap_prefix,
6173 bgp_show_type_flap_cidr_only,
6174 bgp_show_type_flap_regexp,
6175 bgp_show_type_flap_filter_list,
6176 bgp_show_type_flap_prefix_list,
6177 bgp_show_type_flap_prefix_longer,
6178 bgp_show_type_flap_route_map,
6179 bgp_show_type_flap_neighbor,
6180 bgp_show_type_dampend_paths,
6181 bgp_show_type_damp_neighbor
6182};
6183
ajs5a646652004-11-05 01:25:55 +00006184static int
paulfee0f4c2004-09-13 05:12:46 +00006185bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006186 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006187{
paul718e3742002-12-13 20:15:29 +00006188 struct bgp_info *ri;
6189 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006190 int header = 1;
paul718e3742002-12-13 20:15:29 +00006191 int display;
ajs5a646652004-11-05 01:25:55 +00006192 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006193
6194 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006195 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006196
paul718e3742002-12-13 20:15:29 +00006197 /* Start processing of routes. */
6198 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6199 if (rn->info != NULL)
6200 {
6201 display = 0;
6202
6203 for (ri = rn->info; ri; ri = ri->next)
6204 {
ajs5a646652004-11-05 01:25:55 +00006205 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006206 || type == bgp_show_type_flap_address
6207 || type == bgp_show_type_flap_prefix
6208 || type == bgp_show_type_flap_cidr_only
6209 || type == bgp_show_type_flap_regexp
6210 || type == bgp_show_type_flap_filter_list
6211 || type == bgp_show_type_flap_prefix_list
6212 || type == bgp_show_type_flap_prefix_longer
6213 || type == bgp_show_type_flap_route_map
6214 || type == bgp_show_type_flap_neighbor
6215 || type == bgp_show_type_dampend_paths
6216 || type == bgp_show_type_damp_neighbor)
6217 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006218 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006219 continue;
6220 }
6221 if (type == bgp_show_type_regexp
6222 || type == bgp_show_type_flap_regexp)
6223 {
ajs5a646652004-11-05 01:25:55 +00006224 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006225
6226 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6227 continue;
6228 }
6229 if (type == bgp_show_type_prefix_list
6230 || type == bgp_show_type_flap_prefix_list)
6231 {
ajs5a646652004-11-05 01:25:55 +00006232 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006233
6234 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6235 continue;
6236 }
6237 if (type == bgp_show_type_filter_list
6238 || type == bgp_show_type_flap_filter_list)
6239 {
ajs5a646652004-11-05 01:25:55 +00006240 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006241
6242 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6243 continue;
6244 }
6245 if (type == bgp_show_type_route_map
6246 || type == bgp_show_type_flap_route_map)
6247 {
ajs5a646652004-11-05 01:25:55 +00006248 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006249 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006250 struct attr dummy_attr;
6251 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006252 int ret;
6253
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006254 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006255 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006256
paul718e3742002-12-13 20:15:29 +00006257 binfo.peer = ri->peer;
6258 binfo.attr = &dummy_attr;
6259
6260 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006261 if (ret == RMAP_DENYMATCH)
6262 continue;
6263 }
6264 if (type == bgp_show_type_neighbor
6265 || type == bgp_show_type_flap_neighbor
6266 || type == bgp_show_type_damp_neighbor)
6267 {
ajs5a646652004-11-05 01:25:55 +00006268 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006269
6270 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6271 continue;
6272 }
6273 if (type == bgp_show_type_cidr_only
6274 || type == bgp_show_type_flap_cidr_only)
6275 {
6276 u_int32_t destination;
6277
6278 destination = ntohl (rn->p.u.prefix4.s_addr);
6279 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6280 continue;
6281 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6282 continue;
6283 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6284 continue;
6285 }
6286 if (type == bgp_show_type_prefix_longer
6287 || type == bgp_show_type_flap_prefix_longer)
6288 {
ajs5a646652004-11-05 01:25:55 +00006289 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006290
6291 if (! prefix_match (p, &rn->p))
6292 continue;
6293 }
6294 if (type == bgp_show_type_community_all)
6295 {
6296 if (! ri->attr->community)
6297 continue;
6298 }
6299 if (type == bgp_show_type_community)
6300 {
ajs5a646652004-11-05 01:25:55 +00006301 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006302
6303 if (! ri->attr->community ||
6304 ! community_match (ri->attr->community, com))
6305 continue;
6306 }
6307 if (type == bgp_show_type_community_exact)
6308 {
ajs5a646652004-11-05 01:25:55 +00006309 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006310
6311 if (! ri->attr->community ||
6312 ! community_cmp (ri->attr->community, com))
6313 continue;
6314 }
6315 if (type == bgp_show_type_community_list)
6316 {
ajs5a646652004-11-05 01:25:55 +00006317 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006318
6319 if (! community_list_match (ri->attr->community, list))
6320 continue;
6321 }
6322 if (type == bgp_show_type_community_list_exact)
6323 {
ajs5a646652004-11-05 01:25:55 +00006324 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006325
6326 if (! community_list_exact_match (ri->attr->community, list))
6327 continue;
6328 }
6329 if (type == bgp_show_type_flap_address
6330 || type == bgp_show_type_flap_prefix)
6331 {
ajs5a646652004-11-05 01:25:55 +00006332 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006333
6334 if (! prefix_match (&rn->p, p))
6335 continue;
6336
6337 if (type == bgp_show_type_flap_prefix)
6338 if (p->prefixlen != rn->p.prefixlen)
6339 continue;
6340 }
6341 if (type == bgp_show_type_dampend_paths
6342 || type == bgp_show_type_damp_neighbor)
6343 {
6344 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6345 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6346 continue;
6347 }
6348
6349 if (header)
6350 {
hasso93406d82005-02-02 14:40:33 +00006351 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6352 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6353 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006354 if (type == bgp_show_type_dampend_paths
6355 || type == bgp_show_type_damp_neighbor)
6356 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6357 else if (type == bgp_show_type_flap_statistics
6358 || type == bgp_show_type_flap_address
6359 || type == bgp_show_type_flap_prefix
6360 || type == bgp_show_type_flap_cidr_only
6361 || type == bgp_show_type_flap_regexp
6362 || type == bgp_show_type_flap_filter_list
6363 || type == bgp_show_type_flap_prefix_list
6364 || type == bgp_show_type_flap_prefix_longer
6365 || type == bgp_show_type_flap_route_map
6366 || type == bgp_show_type_flap_neighbor)
6367 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6368 else
6369 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006370 header = 0;
6371 }
6372
6373 if (type == bgp_show_type_dampend_paths
6374 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006375 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006376 else if (type == bgp_show_type_flap_statistics
6377 || type == bgp_show_type_flap_address
6378 || type == bgp_show_type_flap_prefix
6379 || type == bgp_show_type_flap_cidr_only
6380 || type == bgp_show_type_flap_regexp
6381 || type == bgp_show_type_flap_filter_list
6382 || type == bgp_show_type_flap_prefix_list
6383 || type == bgp_show_type_flap_prefix_longer
6384 || type == bgp_show_type_flap_route_map
6385 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006386 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006387 else
ajs5a646652004-11-05 01:25:55 +00006388 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006389 display++;
6390 }
6391 if (display)
ajs5a646652004-11-05 01:25:55 +00006392 output_count++;
paul718e3742002-12-13 20:15:29 +00006393 }
6394
6395 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006396 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006397 {
6398 if (type == bgp_show_type_normal)
6399 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6400 }
6401 else
6402 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006403 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006404
6405 return CMD_SUCCESS;
6406}
6407
ajs5a646652004-11-05 01:25:55 +00006408static int
paulfee0f4c2004-09-13 05:12:46 +00006409bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006410 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006411{
6412 struct bgp_table *table;
6413
6414 if (bgp == NULL) {
6415 bgp = bgp_get_default ();
6416 }
6417
6418 if (bgp == NULL)
6419 {
6420 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6421 return CMD_WARNING;
6422 }
6423
6424
6425 table = bgp->rib[afi][safi];
6426
ajs5a646652004-11-05 01:25:55 +00006427 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006428}
6429
paul718e3742002-12-13 20:15:29 +00006430/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006431static void
paul718e3742002-12-13 20:15:29 +00006432route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6433 struct bgp_node *rn,
6434 struct prefix_rd *prd, afi_t afi, safi_t safi)
6435{
6436 struct bgp_info *ri;
6437 struct prefix *p;
6438 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006439 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006440 char buf1[INET6_ADDRSTRLEN];
6441 char buf2[INET6_ADDRSTRLEN];
6442 int count = 0;
6443 int best = 0;
6444 int suppress = 0;
6445 int no_export = 0;
6446 int no_advertise = 0;
6447 int local_as = 0;
6448 int first = 0;
6449
6450 p = &rn->p;
6451 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6452 (safi == SAFI_MPLS_VPN ?
6453 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6454 safi == SAFI_MPLS_VPN ? ":" : "",
6455 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6456 p->prefixlen, VTY_NEWLINE);
6457
6458 for (ri = rn->info; ri; ri = ri->next)
6459 {
6460 count++;
6461 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6462 {
6463 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006464 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006465 suppress = 1;
6466 if (ri->attr->community != NULL)
6467 {
6468 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6469 no_advertise = 1;
6470 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6471 no_export = 1;
6472 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6473 local_as = 1;
6474 }
6475 }
6476 }
6477
6478 vty_out (vty, "Paths: (%d available", count);
6479 if (best)
6480 {
6481 vty_out (vty, ", best #%d", best);
6482 if (safi == SAFI_UNICAST)
6483 vty_out (vty, ", table Default-IP-Routing-Table");
6484 }
6485 else
6486 vty_out (vty, ", no best path");
6487 if (no_advertise)
6488 vty_out (vty, ", not advertised to any peer");
6489 else if (no_export)
6490 vty_out (vty, ", not advertised to EBGP peer");
6491 else if (local_as)
6492 vty_out (vty, ", not advertised outside local AS");
6493 if (suppress)
6494 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6495 vty_out (vty, ")%s", VTY_NEWLINE);
6496
6497 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006498 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006499 {
6500 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6501 {
6502 if (! first)
6503 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6504 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6505 first = 1;
6506 }
6507 }
6508 if (! first)
6509 vty_out (vty, " Not advertised to any peer");
6510 vty_out (vty, "%s", VTY_NEWLINE);
6511}
6512
6513/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006514static int
paulfee0f4c2004-09-13 05:12:46 +00006515bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006516 struct bgp_table *rib, const char *ip_str,
6517 afi_t afi, safi_t safi, struct prefix_rd *prd,
6518 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006519{
6520 int ret;
6521 int header;
6522 int display = 0;
6523 struct prefix match;
6524 struct bgp_node *rn;
6525 struct bgp_node *rm;
6526 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006527 struct bgp_table *table;
6528
paul718e3742002-12-13 20:15:29 +00006529 /* Check IP address argument. */
6530 ret = str2prefix (ip_str, &match);
6531 if (! ret)
6532 {
6533 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6534 return CMD_WARNING;
6535 }
6536
6537 match.family = afi2family (afi);
6538
6539 if (safi == SAFI_MPLS_VPN)
6540 {
paulfee0f4c2004-09-13 05:12:46 +00006541 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006542 {
6543 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6544 continue;
6545
6546 if ((table = rn->info) != NULL)
6547 {
6548 header = 1;
6549
6550 if ((rm = bgp_node_match (table, &match)) != NULL)
6551 {
6552 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006553 {
6554 bgp_unlock_node (rm);
6555 continue;
6556 }
paul718e3742002-12-13 20:15:29 +00006557
6558 for (ri = rm->info; ri; ri = ri->next)
6559 {
6560 if (header)
6561 {
6562 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6563 AFI_IP, SAFI_MPLS_VPN);
6564
6565 header = 0;
6566 }
6567 display++;
6568 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6569 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006570
6571 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006572 }
6573 }
6574 }
6575 }
6576 else
6577 {
6578 header = 1;
6579
paulfee0f4c2004-09-13 05:12:46 +00006580 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006581 {
6582 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6583 {
6584 for (ri = rn->info; ri; ri = ri->next)
6585 {
6586 if (header)
6587 {
6588 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6589 header = 0;
6590 }
6591 display++;
6592 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6593 }
6594 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006595
6596 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006597 }
6598 }
6599
6600 if (! display)
6601 {
6602 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6603 return CMD_WARNING;
6604 }
6605
6606 return CMD_SUCCESS;
6607}
6608
paulfee0f4c2004-09-13 05:12:46 +00006609/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006610static int
paulfd79ac92004-10-13 05:06:08 +00006611bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006612 afi_t afi, safi_t safi, struct prefix_rd *prd,
6613 int prefix_check)
6614{
6615 struct bgp *bgp;
6616
6617 /* BGP structure lookup. */
6618 if (view_name)
6619 {
6620 bgp = bgp_lookup_by_name (view_name);
6621 if (bgp == NULL)
6622 {
6623 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6624 return CMD_WARNING;
6625 }
6626 }
6627 else
6628 {
6629 bgp = bgp_get_default ();
6630 if (bgp == NULL)
6631 {
6632 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6633 return CMD_WARNING;
6634 }
6635 }
6636
6637 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6638 afi, safi, prd, prefix_check);
6639}
6640
paul718e3742002-12-13 20:15:29 +00006641/* BGP route print out function. */
6642DEFUN (show_ip_bgp,
6643 show_ip_bgp_cmd,
6644 "show ip bgp",
6645 SHOW_STR
6646 IP_STR
6647 BGP_STR)
6648{
ajs5a646652004-11-05 01:25:55 +00006649 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006650}
6651
6652DEFUN (show_ip_bgp_ipv4,
6653 show_ip_bgp_ipv4_cmd,
6654 "show ip bgp ipv4 (unicast|multicast)",
6655 SHOW_STR
6656 IP_STR
6657 BGP_STR
6658 "Address family\n"
6659 "Address Family modifier\n"
6660 "Address Family modifier\n")
6661{
6662 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006663 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6664 NULL);
paul718e3742002-12-13 20:15:29 +00006665
ajs5a646652004-11-05 01:25:55 +00006666 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006667}
6668
Michael Lambert95cbbd22010-07-23 14:43:04 -04006669ALIAS (show_ip_bgp_ipv4,
6670 show_bgp_ipv4_safi_cmd,
6671 "show bgp ipv4 (unicast|multicast)",
6672 SHOW_STR
6673 BGP_STR
6674 "Address family\n"
6675 "Address Family modifier\n"
6676 "Address Family modifier\n")
6677
paul718e3742002-12-13 20:15:29 +00006678DEFUN (show_ip_bgp_route,
6679 show_ip_bgp_route_cmd,
6680 "show ip bgp A.B.C.D",
6681 SHOW_STR
6682 IP_STR
6683 BGP_STR
6684 "Network in the BGP routing table to display\n")
6685{
6686 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6687}
6688
6689DEFUN (show_ip_bgp_ipv4_route,
6690 show_ip_bgp_ipv4_route_cmd,
6691 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6692 SHOW_STR
6693 IP_STR
6694 BGP_STR
6695 "Address family\n"
6696 "Address Family modifier\n"
6697 "Address Family modifier\n"
6698 "Network in the BGP routing table to display\n")
6699{
6700 if (strncmp (argv[0], "m", 1) == 0)
6701 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6702
6703 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6704}
6705
Michael Lambert95cbbd22010-07-23 14:43:04 -04006706ALIAS (show_ip_bgp_ipv4_route,
6707 show_bgp_ipv4_safi_route_cmd,
6708 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6709 SHOW_STR
6710 BGP_STR
6711 "Address family\n"
6712 "Address Family modifier\n"
6713 "Address Family modifier\n"
6714 "Network in the BGP routing table to display\n")
6715
paul718e3742002-12-13 20:15:29 +00006716DEFUN (show_ip_bgp_vpnv4_all_route,
6717 show_ip_bgp_vpnv4_all_route_cmd,
6718 "show ip bgp vpnv4 all A.B.C.D",
6719 SHOW_STR
6720 IP_STR
6721 BGP_STR
6722 "Display VPNv4 NLRI specific information\n"
6723 "Display information about all VPNv4 NLRIs\n"
6724 "Network in the BGP routing table to display\n")
6725{
6726 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6727}
6728
6729DEFUN (show_ip_bgp_vpnv4_rd_route,
6730 show_ip_bgp_vpnv4_rd_route_cmd,
6731 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6732 SHOW_STR
6733 IP_STR
6734 BGP_STR
6735 "Display VPNv4 NLRI specific information\n"
6736 "Display information for a route distinguisher\n"
6737 "VPN Route Distinguisher\n"
6738 "Network in the BGP routing table to display\n")
6739{
6740 int ret;
6741 struct prefix_rd prd;
6742
6743 ret = str2prefix_rd (argv[0], &prd);
6744 if (! ret)
6745 {
6746 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6747 return CMD_WARNING;
6748 }
6749 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6750}
6751
6752DEFUN (show_ip_bgp_prefix,
6753 show_ip_bgp_prefix_cmd,
6754 "show ip bgp A.B.C.D/M",
6755 SHOW_STR
6756 IP_STR
6757 BGP_STR
6758 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6759{
6760 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6761}
6762
6763DEFUN (show_ip_bgp_ipv4_prefix,
6764 show_ip_bgp_ipv4_prefix_cmd,
6765 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6766 SHOW_STR
6767 IP_STR
6768 BGP_STR
6769 "Address family\n"
6770 "Address Family modifier\n"
6771 "Address Family modifier\n"
6772 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6773{
6774 if (strncmp (argv[0], "m", 1) == 0)
6775 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6776
6777 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6778}
6779
Michael Lambert95cbbd22010-07-23 14:43:04 -04006780ALIAS (show_ip_bgp_ipv4_prefix,
6781 show_bgp_ipv4_safi_prefix_cmd,
6782 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6783 SHOW_STR
6784 BGP_STR
6785 "Address family\n"
6786 "Address Family modifier\n"
6787 "Address Family modifier\n"
6788 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6789
paul718e3742002-12-13 20:15:29 +00006790DEFUN (show_ip_bgp_vpnv4_all_prefix,
6791 show_ip_bgp_vpnv4_all_prefix_cmd,
6792 "show ip bgp vpnv4 all A.B.C.D/M",
6793 SHOW_STR
6794 IP_STR
6795 BGP_STR
6796 "Display VPNv4 NLRI specific information\n"
6797 "Display information about all VPNv4 NLRIs\n"
6798 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6799{
6800 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6801}
6802
6803DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6804 show_ip_bgp_vpnv4_rd_prefix_cmd,
6805 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6806 SHOW_STR
6807 IP_STR
6808 BGP_STR
6809 "Display VPNv4 NLRI specific information\n"
6810 "Display information for a route distinguisher\n"
6811 "VPN Route Distinguisher\n"
6812 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6813{
6814 int ret;
6815 struct prefix_rd prd;
6816
6817 ret = str2prefix_rd (argv[0], &prd);
6818 if (! ret)
6819 {
6820 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6821 return CMD_WARNING;
6822 }
6823 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6824}
6825
6826DEFUN (show_ip_bgp_view,
6827 show_ip_bgp_view_cmd,
6828 "show ip bgp view WORD",
6829 SHOW_STR
6830 IP_STR
6831 BGP_STR
6832 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006833 "View name\n")
paul718e3742002-12-13 20:15:29 +00006834{
paulbb46e942003-10-24 19:02:03 +00006835 struct bgp *bgp;
6836
6837 /* BGP structure lookup. */
6838 bgp = bgp_lookup_by_name (argv[0]);
6839 if (bgp == NULL)
6840 {
6841 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6842 return CMD_WARNING;
6843 }
6844
ajs5a646652004-11-05 01:25:55 +00006845 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006846}
6847
6848DEFUN (show_ip_bgp_view_route,
6849 show_ip_bgp_view_route_cmd,
6850 "show ip bgp view WORD A.B.C.D",
6851 SHOW_STR
6852 IP_STR
6853 BGP_STR
6854 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006855 "View name\n"
paul718e3742002-12-13 20:15:29 +00006856 "Network in the BGP routing table to display\n")
6857{
6858 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6859}
6860
6861DEFUN (show_ip_bgp_view_prefix,
6862 show_ip_bgp_view_prefix_cmd,
6863 "show ip bgp view WORD A.B.C.D/M",
6864 SHOW_STR
6865 IP_STR
6866 BGP_STR
6867 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006868 "View name\n"
paul718e3742002-12-13 20:15:29 +00006869 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6870{
6871 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6872}
6873
6874#ifdef HAVE_IPV6
6875DEFUN (show_bgp,
6876 show_bgp_cmd,
6877 "show bgp",
6878 SHOW_STR
6879 BGP_STR)
6880{
ajs5a646652004-11-05 01:25:55 +00006881 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6882 NULL);
paul718e3742002-12-13 20:15:29 +00006883}
6884
6885ALIAS (show_bgp,
6886 show_bgp_ipv6_cmd,
6887 "show bgp ipv6",
6888 SHOW_STR
6889 BGP_STR
6890 "Address family\n")
6891
Michael Lambert95cbbd22010-07-23 14:43:04 -04006892DEFUN (show_bgp_ipv6_safi,
6893 show_bgp_ipv6_safi_cmd,
6894 "show bgp ipv6 (unicast|multicast)",
6895 SHOW_STR
6896 BGP_STR
6897 "Address family\n"
6898 "Address Family modifier\n"
6899 "Address Family modifier\n")
6900{
6901 if (strncmp (argv[0], "m", 1) == 0)
6902 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6903 NULL);
6904
6905 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6906}
6907
paul718e3742002-12-13 20:15:29 +00006908/* old command */
6909DEFUN (show_ipv6_bgp,
6910 show_ipv6_bgp_cmd,
6911 "show ipv6 bgp",
6912 SHOW_STR
6913 IP_STR
6914 BGP_STR)
6915{
ajs5a646652004-11-05 01:25:55 +00006916 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6917 NULL);
paul718e3742002-12-13 20:15:29 +00006918}
6919
6920DEFUN (show_bgp_route,
6921 show_bgp_route_cmd,
6922 "show bgp X:X::X:X",
6923 SHOW_STR
6924 BGP_STR
6925 "Network in the BGP routing table to display\n")
6926{
6927 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6928}
6929
6930ALIAS (show_bgp_route,
6931 show_bgp_ipv6_route_cmd,
6932 "show bgp ipv6 X:X::X:X",
6933 SHOW_STR
6934 BGP_STR
6935 "Address family\n"
6936 "Network in the BGP routing table to display\n")
6937
Michael Lambert95cbbd22010-07-23 14:43:04 -04006938DEFUN (show_bgp_ipv6_safi_route,
6939 show_bgp_ipv6_safi_route_cmd,
6940 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6941 SHOW_STR
6942 BGP_STR
6943 "Address family\n"
6944 "Address Family modifier\n"
6945 "Address Family modifier\n"
6946 "Network in the BGP routing table to display\n")
6947{
6948 if (strncmp (argv[0], "m", 1) == 0)
6949 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6950
6951 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6952}
6953
paul718e3742002-12-13 20:15:29 +00006954/* old command */
6955DEFUN (show_ipv6_bgp_route,
6956 show_ipv6_bgp_route_cmd,
6957 "show ipv6 bgp X:X::X:X",
6958 SHOW_STR
6959 IP_STR
6960 BGP_STR
6961 "Network in the BGP routing table to display\n")
6962{
6963 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6964}
6965
6966DEFUN (show_bgp_prefix,
6967 show_bgp_prefix_cmd,
6968 "show bgp X:X::X:X/M",
6969 SHOW_STR
6970 BGP_STR
6971 "IPv6 prefix <network>/<length>\n")
6972{
6973 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6974}
6975
6976ALIAS (show_bgp_prefix,
6977 show_bgp_ipv6_prefix_cmd,
6978 "show bgp ipv6 X:X::X:X/M",
6979 SHOW_STR
6980 BGP_STR
6981 "Address family\n"
6982 "IPv6 prefix <network>/<length>\n")
6983
Michael Lambert95cbbd22010-07-23 14:43:04 -04006984DEFUN (show_bgp_ipv6_safi_prefix,
6985 show_bgp_ipv6_safi_prefix_cmd,
6986 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6987 SHOW_STR
6988 BGP_STR
6989 "Address family\n"
6990 "Address Family modifier\n"
6991 "Address Family modifier\n"
6992 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6993{
6994 if (strncmp (argv[0], "m", 1) == 0)
6995 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6996
6997 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6998}
6999
paul718e3742002-12-13 20:15:29 +00007000/* old command */
7001DEFUN (show_ipv6_bgp_prefix,
7002 show_ipv6_bgp_prefix_cmd,
7003 "show ipv6 bgp X:X::X:X/M",
7004 SHOW_STR
7005 IP_STR
7006 BGP_STR
7007 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7008{
7009 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7010}
7011
paulbb46e942003-10-24 19:02:03 +00007012DEFUN (show_bgp_view,
7013 show_bgp_view_cmd,
7014 "show bgp view WORD",
7015 SHOW_STR
7016 BGP_STR
7017 "BGP view\n"
7018 "View name\n")
7019{
7020 struct bgp *bgp;
7021
7022 /* BGP structure lookup. */
7023 bgp = bgp_lookup_by_name (argv[0]);
7024 if (bgp == NULL)
7025 {
7026 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7027 return CMD_WARNING;
7028 }
7029
ajs5a646652004-11-05 01:25:55 +00007030 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007031}
7032
7033ALIAS (show_bgp_view,
7034 show_bgp_view_ipv6_cmd,
7035 "show bgp view WORD ipv6",
7036 SHOW_STR
7037 BGP_STR
7038 "BGP view\n"
7039 "View name\n"
7040 "Address family\n")
7041
7042DEFUN (show_bgp_view_route,
7043 show_bgp_view_route_cmd,
7044 "show bgp view WORD X:X::X:X",
7045 SHOW_STR
7046 BGP_STR
7047 "BGP view\n"
7048 "View name\n"
7049 "Network in the BGP routing table to display\n")
7050{
7051 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7052}
7053
7054ALIAS (show_bgp_view_route,
7055 show_bgp_view_ipv6_route_cmd,
7056 "show bgp view WORD ipv6 X:X::X:X",
7057 SHOW_STR
7058 BGP_STR
7059 "BGP view\n"
7060 "View name\n"
7061 "Address family\n"
7062 "Network in the BGP routing table to display\n")
7063
7064DEFUN (show_bgp_view_prefix,
7065 show_bgp_view_prefix_cmd,
7066 "show bgp view WORD X:X::X:X/M",
7067 SHOW_STR
7068 BGP_STR
7069 "BGP view\n"
7070 "View name\n"
7071 "IPv6 prefix <network>/<length>\n")
7072{
7073 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7074}
7075
7076ALIAS (show_bgp_view_prefix,
7077 show_bgp_view_ipv6_prefix_cmd,
7078 "show bgp view WORD ipv6 X:X::X:X/M",
7079 SHOW_STR
7080 BGP_STR
7081 "BGP view\n"
7082 "View name\n"
7083 "Address family\n"
7084 "IPv6 prefix <network>/<length>\n")
7085
paul718e3742002-12-13 20:15:29 +00007086/* old command */
7087DEFUN (show_ipv6_mbgp,
7088 show_ipv6_mbgp_cmd,
7089 "show ipv6 mbgp",
7090 SHOW_STR
7091 IP_STR
7092 MBGP_STR)
7093{
ajs5a646652004-11-05 01:25:55 +00007094 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7095 NULL);
paul718e3742002-12-13 20:15:29 +00007096}
7097
7098/* old command */
7099DEFUN (show_ipv6_mbgp_route,
7100 show_ipv6_mbgp_route_cmd,
7101 "show ipv6 mbgp X:X::X:X",
7102 SHOW_STR
7103 IP_STR
7104 MBGP_STR
7105 "Network in the MBGP routing table to display\n")
7106{
7107 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7108}
7109
7110/* old command */
7111DEFUN (show_ipv6_mbgp_prefix,
7112 show_ipv6_mbgp_prefix_cmd,
7113 "show ipv6 mbgp X:X::X:X/M",
7114 SHOW_STR
7115 IP_STR
7116 MBGP_STR
7117 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7118{
7119 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7120}
7121#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007122
paul718e3742002-12-13 20:15:29 +00007123
paul94f2b392005-06-28 12:44:16 +00007124static int
paulfd79ac92004-10-13 05:06:08 +00007125bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007126 safi_t safi, enum bgp_show_type type)
7127{
7128 int i;
7129 struct buffer *b;
7130 char *regstr;
7131 int first;
7132 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007133 int rc;
paul718e3742002-12-13 20:15:29 +00007134
7135 first = 0;
7136 b = buffer_new (1024);
7137 for (i = 0; i < argc; i++)
7138 {
7139 if (first)
7140 buffer_putc (b, ' ');
7141 else
7142 {
7143 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7144 continue;
7145 first = 1;
7146 }
7147
7148 buffer_putstr (b, argv[i]);
7149 }
7150 buffer_putc (b, '\0');
7151
7152 regstr = buffer_getstr (b);
7153 buffer_free (b);
7154
7155 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007156 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007157 if (! regex)
7158 {
7159 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7160 VTY_NEWLINE);
7161 return CMD_WARNING;
7162 }
7163
ajs5a646652004-11-05 01:25:55 +00007164 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7165 bgp_regex_free (regex);
7166 return rc;
paul718e3742002-12-13 20:15:29 +00007167}
7168
7169DEFUN (show_ip_bgp_regexp,
7170 show_ip_bgp_regexp_cmd,
7171 "show ip bgp regexp .LINE",
7172 SHOW_STR
7173 IP_STR
7174 BGP_STR
7175 "Display routes matching the AS path regular expression\n"
7176 "A regular-expression to match the BGP AS paths\n")
7177{
7178 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7179 bgp_show_type_regexp);
7180}
7181
7182DEFUN (show_ip_bgp_flap_regexp,
7183 show_ip_bgp_flap_regexp_cmd,
7184 "show ip bgp flap-statistics regexp .LINE",
7185 SHOW_STR
7186 IP_STR
7187 BGP_STR
7188 "Display flap statistics of routes\n"
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_flap_regexp);
7194}
7195
7196DEFUN (show_ip_bgp_ipv4_regexp,
7197 show_ip_bgp_ipv4_regexp_cmd,
7198 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7199 SHOW_STR
7200 IP_STR
7201 BGP_STR
7202 "Address family\n"
7203 "Address Family modifier\n"
7204 "Address Family modifier\n"
7205 "Display routes matching the AS path regular expression\n"
7206 "A regular-expression to match the BGP AS paths\n")
7207{
7208 if (strncmp (argv[0], "m", 1) == 0)
7209 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7210 bgp_show_type_regexp);
7211
7212 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7213 bgp_show_type_regexp);
7214}
7215
7216#ifdef HAVE_IPV6
7217DEFUN (show_bgp_regexp,
7218 show_bgp_regexp_cmd,
7219 "show bgp regexp .LINE",
7220 SHOW_STR
7221 BGP_STR
7222 "Display routes matching the AS path regular expression\n"
7223 "A regular-expression to match the BGP AS paths\n")
7224{
7225 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7226 bgp_show_type_regexp);
7227}
7228
7229ALIAS (show_bgp_regexp,
7230 show_bgp_ipv6_regexp_cmd,
7231 "show bgp ipv6 regexp .LINE",
7232 SHOW_STR
7233 BGP_STR
7234 "Address family\n"
7235 "Display routes matching the AS path regular expression\n"
7236 "A regular-expression to match the BGP AS paths\n")
7237
7238/* old command */
7239DEFUN (show_ipv6_bgp_regexp,
7240 show_ipv6_bgp_regexp_cmd,
7241 "show ipv6 bgp regexp .LINE",
7242 SHOW_STR
7243 IP_STR
7244 BGP_STR
7245 "Display routes matching the AS path regular expression\n"
7246 "A regular-expression to match the BGP AS paths\n")
7247{
7248 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7249 bgp_show_type_regexp);
7250}
7251
7252/* old command */
7253DEFUN (show_ipv6_mbgp_regexp,
7254 show_ipv6_mbgp_regexp_cmd,
7255 "show ipv6 mbgp 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 MBGP AS paths\n")
7261{
7262 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7263 bgp_show_type_regexp);
7264}
7265#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007266
paul94f2b392005-06-28 12:44:16 +00007267static int
paulfd79ac92004-10-13 05:06:08 +00007268bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007269 safi_t safi, enum bgp_show_type type)
7270{
7271 struct prefix_list *plist;
7272
7273 plist = prefix_list_lookup (afi, prefix_list_str);
7274 if (plist == NULL)
7275 {
7276 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7277 prefix_list_str, VTY_NEWLINE);
7278 return CMD_WARNING;
7279 }
7280
ajs5a646652004-11-05 01:25:55 +00007281 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007282}
7283
7284DEFUN (show_ip_bgp_prefix_list,
7285 show_ip_bgp_prefix_list_cmd,
7286 "show ip bgp prefix-list WORD",
7287 SHOW_STR
7288 IP_STR
7289 BGP_STR
7290 "Display routes conforming to the prefix-list\n"
7291 "IP prefix-list name\n")
7292{
7293 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7294 bgp_show_type_prefix_list);
7295}
7296
7297DEFUN (show_ip_bgp_flap_prefix_list,
7298 show_ip_bgp_flap_prefix_list_cmd,
7299 "show ip bgp flap-statistics prefix-list WORD",
7300 SHOW_STR
7301 IP_STR
7302 BGP_STR
7303 "Display flap statistics of routes\n"
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_flap_prefix_list);
7309}
7310
7311DEFUN (show_ip_bgp_ipv4_prefix_list,
7312 show_ip_bgp_ipv4_prefix_list_cmd,
7313 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7314 SHOW_STR
7315 IP_STR
7316 BGP_STR
7317 "Address family\n"
7318 "Address Family modifier\n"
7319 "Address Family modifier\n"
7320 "Display routes conforming to the prefix-list\n"
7321 "IP prefix-list name\n")
7322{
7323 if (strncmp (argv[0], "m", 1) == 0)
7324 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7325 bgp_show_type_prefix_list);
7326
7327 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7328 bgp_show_type_prefix_list);
7329}
7330
7331#ifdef HAVE_IPV6
7332DEFUN (show_bgp_prefix_list,
7333 show_bgp_prefix_list_cmd,
7334 "show bgp prefix-list WORD",
7335 SHOW_STR
7336 BGP_STR
7337 "Display routes conforming to the prefix-list\n"
7338 "IPv6 prefix-list name\n")
7339{
7340 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7341 bgp_show_type_prefix_list);
7342}
7343
7344ALIAS (show_bgp_prefix_list,
7345 show_bgp_ipv6_prefix_list_cmd,
7346 "show bgp ipv6 prefix-list WORD",
7347 SHOW_STR
7348 BGP_STR
7349 "Address family\n"
7350 "Display routes conforming to the prefix-list\n"
7351 "IPv6 prefix-list name\n")
7352
7353/* old command */
7354DEFUN (show_ipv6_bgp_prefix_list,
7355 show_ipv6_bgp_prefix_list_cmd,
7356 "show ipv6 bgp prefix-list WORD",
7357 SHOW_STR
7358 IPV6_STR
7359 BGP_STR
7360 "Display routes matching the prefix-list\n"
7361 "IPv6 prefix-list name\n")
7362{
7363 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7364 bgp_show_type_prefix_list);
7365}
7366
7367/* old command */
7368DEFUN (show_ipv6_mbgp_prefix_list,
7369 show_ipv6_mbgp_prefix_list_cmd,
7370 "show ipv6 mbgp prefix-list WORD",
7371 SHOW_STR
7372 IPV6_STR
7373 MBGP_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_MULTICAST,
7378 bgp_show_type_prefix_list);
7379}
7380#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007381
paul94f2b392005-06-28 12:44:16 +00007382static int
paulfd79ac92004-10-13 05:06:08 +00007383bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007384 safi_t safi, enum bgp_show_type type)
7385{
7386 struct as_list *as_list;
7387
7388 as_list = as_list_lookup (filter);
7389 if (as_list == NULL)
7390 {
7391 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7392 return CMD_WARNING;
7393 }
7394
ajs5a646652004-11-05 01:25:55 +00007395 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007396}
7397
7398DEFUN (show_ip_bgp_filter_list,
7399 show_ip_bgp_filter_list_cmd,
7400 "show ip bgp filter-list WORD",
7401 SHOW_STR
7402 IP_STR
7403 BGP_STR
7404 "Display routes conforming to the filter-list\n"
7405 "Regular expression access list name\n")
7406{
7407 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7408 bgp_show_type_filter_list);
7409}
7410
7411DEFUN (show_ip_bgp_flap_filter_list,
7412 show_ip_bgp_flap_filter_list_cmd,
7413 "show ip bgp flap-statistics filter-list WORD",
7414 SHOW_STR
7415 IP_STR
7416 BGP_STR
7417 "Display flap statistics of routes\n"
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_flap_filter_list);
7423}
7424
7425DEFUN (show_ip_bgp_ipv4_filter_list,
7426 show_ip_bgp_ipv4_filter_list_cmd,
7427 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7428 SHOW_STR
7429 IP_STR
7430 BGP_STR
7431 "Address family\n"
7432 "Address Family modifier\n"
7433 "Address Family modifier\n"
7434 "Display routes conforming to the filter-list\n"
7435 "Regular expression access list name\n")
7436{
7437 if (strncmp (argv[0], "m", 1) == 0)
7438 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7439 bgp_show_type_filter_list);
7440
7441 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7442 bgp_show_type_filter_list);
7443}
7444
7445#ifdef HAVE_IPV6
7446DEFUN (show_bgp_filter_list,
7447 show_bgp_filter_list_cmd,
7448 "show bgp filter-list WORD",
7449 SHOW_STR
7450 BGP_STR
7451 "Display routes conforming to the filter-list\n"
7452 "Regular expression access list name\n")
7453{
7454 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7455 bgp_show_type_filter_list);
7456}
7457
7458ALIAS (show_bgp_filter_list,
7459 show_bgp_ipv6_filter_list_cmd,
7460 "show bgp ipv6 filter-list WORD",
7461 SHOW_STR
7462 BGP_STR
7463 "Address family\n"
7464 "Display routes conforming to the filter-list\n"
7465 "Regular expression access list name\n")
7466
7467/* old command */
7468DEFUN (show_ipv6_bgp_filter_list,
7469 show_ipv6_bgp_filter_list_cmd,
7470 "show ipv6 bgp filter-list WORD",
7471 SHOW_STR
7472 IPV6_STR
7473 BGP_STR
7474 "Display routes conforming to the filter-list\n"
7475 "Regular expression access list name\n")
7476{
7477 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7478 bgp_show_type_filter_list);
7479}
7480
7481/* old command */
7482DEFUN (show_ipv6_mbgp_filter_list,
7483 show_ipv6_mbgp_filter_list_cmd,
7484 "show ipv6 mbgp filter-list WORD",
7485 SHOW_STR
7486 IPV6_STR
7487 MBGP_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_MULTICAST,
7492 bgp_show_type_filter_list);
7493}
7494#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007495
paul94f2b392005-06-28 12:44:16 +00007496static int
paulfd79ac92004-10-13 05:06:08 +00007497bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007498 safi_t safi, enum bgp_show_type type)
7499{
7500 struct route_map *rmap;
7501
7502 rmap = route_map_lookup_by_name (rmap_str);
7503 if (! rmap)
7504 {
7505 vty_out (vty, "%% %s is not a valid route-map name%s",
7506 rmap_str, VTY_NEWLINE);
7507 return CMD_WARNING;
7508 }
7509
ajs5a646652004-11-05 01:25:55 +00007510 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007511}
7512
7513DEFUN (show_ip_bgp_route_map,
7514 show_ip_bgp_route_map_cmd,
7515 "show ip bgp route-map WORD",
7516 SHOW_STR
7517 IP_STR
7518 BGP_STR
7519 "Display routes matching the route-map\n"
7520 "A route-map to match on\n")
7521{
7522 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7523 bgp_show_type_route_map);
7524}
7525
7526DEFUN (show_ip_bgp_flap_route_map,
7527 show_ip_bgp_flap_route_map_cmd,
7528 "show ip bgp flap-statistics route-map WORD",
7529 SHOW_STR
7530 IP_STR
7531 BGP_STR
7532 "Display flap statistics of routes\n"
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_flap_route_map);
7538}
7539
7540DEFUN (show_ip_bgp_ipv4_route_map,
7541 show_ip_bgp_ipv4_route_map_cmd,
7542 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7543 SHOW_STR
7544 IP_STR
7545 BGP_STR
7546 "Address family\n"
7547 "Address Family modifier\n"
7548 "Address Family modifier\n"
7549 "Display routes matching the route-map\n"
7550 "A route-map to match on\n")
7551{
7552 if (strncmp (argv[0], "m", 1) == 0)
7553 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7554 bgp_show_type_route_map);
7555
7556 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7557 bgp_show_type_route_map);
7558}
7559
7560DEFUN (show_bgp_route_map,
7561 show_bgp_route_map_cmd,
7562 "show bgp route-map WORD",
7563 SHOW_STR
7564 BGP_STR
7565 "Display routes matching the route-map\n"
7566 "A route-map to match on\n")
7567{
7568 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7569 bgp_show_type_route_map);
7570}
7571
7572ALIAS (show_bgp_route_map,
7573 show_bgp_ipv6_route_map_cmd,
7574 "show bgp ipv6 route-map WORD",
7575 SHOW_STR
7576 BGP_STR
7577 "Address family\n"
7578 "Display routes matching the route-map\n"
7579 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007580
paul718e3742002-12-13 20:15:29 +00007581DEFUN (show_ip_bgp_cidr_only,
7582 show_ip_bgp_cidr_only_cmd,
7583 "show ip bgp cidr-only",
7584 SHOW_STR
7585 IP_STR
7586 BGP_STR
7587 "Display only routes with non-natural netmasks\n")
7588{
7589 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007590 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007591}
7592
7593DEFUN (show_ip_bgp_flap_cidr_only,
7594 show_ip_bgp_flap_cidr_only_cmd,
7595 "show ip bgp flap-statistics cidr-only",
7596 SHOW_STR
7597 IP_STR
7598 BGP_STR
7599 "Display flap statistics of routes\n"
7600 "Display only routes with non-natural netmasks\n")
7601{
7602 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007603 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007604}
7605
7606DEFUN (show_ip_bgp_ipv4_cidr_only,
7607 show_ip_bgp_ipv4_cidr_only_cmd,
7608 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7609 SHOW_STR
7610 IP_STR
7611 BGP_STR
7612 "Address family\n"
7613 "Address Family modifier\n"
7614 "Address Family modifier\n"
7615 "Display only routes with non-natural netmasks\n")
7616{
7617 if (strncmp (argv[0], "m", 1) == 0)
7618 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007619 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007620
7621 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007622 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007623}
David Lamparter6b0655a2014-06-04 06:53:35 +02007624
paul718e3742002-12-13 20:15:29 +00007625DEFUN (show_ip_bgp_community_all,
7626 show_ip_bgp_community_all_cmd,
7627 "show ip bgp community",
7628 SHOW_STR
7629 IP_STR
7630 BGP_STR
7631 "Display routes matching the communities\n")
7632{
7633 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007634 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007635}
7636
7637DEFUN (show_ip_bgp_ipv4_community_all,
7638 show_ip_bgp_ipv4_community_all_cmd,
7639 "show ip bgp ipv4 (unicast|multicast) community",
7640 SHOW_STR
7641 IP_STR
7642 BGP_STR
7643 "Address family\n"
7644 "Address Family modifier\n"
7645 "Address Family modifier\n"
7646 "Display routes matching the communities\n")
7647{
7648 if (strncmp (argv[0], "m", 1) == 0)
7649 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007650 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007651
7652 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007653 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007654}
7655
7656#ifdef HAVE_IPV6
7657DEFUN (show_bgp_community_all,
7658 show_bgp_community_all_cmd,
7659 "show bgp community",
7660 SHOW_STR
7661 BGP_STR
7662 "Display routes matching the communities\n")
7663{
7664 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007665 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007666}
7667
7668ALIAS (show_bgp_community_all,
7669 show_bgp_ipv6_community_all_cmd,
7670 "show bgp ipv6 community",
7671 SHOW_STR
7672 BGP_STR
7673 "Address family\n"
7674 "Display routes matching the communities\n")
7675
7676/* old command */
7677DEFUN (show_ipv6_bgp_community_all,
7678 show_ipv6_bgp_community_all_cmd,
7679 "show ipv6 bgp community",
7680 SHOW_STR
7681 IPV6_STR
7682 BGP_STR
7683 "Display routes matching the communities\n")
7684{
7685 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007686 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007687}
7688
7689/* old command */
7690DEFUN (show_ipv6_mbgp_community_all,
7691 show_ipv6_mbgp_community_all_cmd,
7692 "show ipv6 mbgp community",
7693 SHOW_STR
7694 IPV6_STR
7695 MBGP_STR
7696 "Display routes matching the communities\n")
7697{
7698 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007699 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007700}
7701#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007702
paul94f2b392005-06-28 12:44:16 +00007703static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007704bgp_show_community (struct vty *vty, const char *view_name, int argc,
7705 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007706{
7707 struct community *com;
7708 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007709 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007710 int i;
7711 char *str;
7712 int first = 0;
7713
Michael Lambert95cbbd22010-07-23 14:43:04 -04007714 /* BGP structure lookup */
7715 if (view_name)
7716 {
7717 bgp = bgp_lookup_by_name (view_name);
7718 if (bgp == NULL)
7719 {
7720 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7721 return CMD_WARNING;
7722 }
7723 }
7724 else
7725 {
7726 bgp = bgp_get_default ();
7727 if (bgp == NULL)
7728 {
7729 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7730 return CMD_WARNING;
7731 }
7732 }
7733
paul718e3742002-12-13 20:15:29 +00007734 b = buffer_new (1024);
7735 for (i = 0; i < argc; i++)
7736 {
7737 if (first)
7738 buffer_putc (b, ' ');
7739 else
7740 {
7741 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7742 continue;
7743 first = 1;
7744 }
7745
7746 buffer_putstr (b, argv[i]);
7747 }
7748 buffer_putc (b, '\0');
7749
7750 str = buffer_getstr (b);
7751 buffer_free (b);
7752
7753 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007754 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007755 if (! com)
7756 {
7757 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7758 return CMD_WARNING;
7759 }
7760
Michael Lambert95cbbd22010-07-23 14:43:04 -04007761 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007762 (exact ? bgp_show_type_community_exact :
7763 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007764}
7765
7766DEFUN (show_ip_bgp_community,
7767 show_ip_bgp_community_cmd,
7768 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7769 SHOW_STR
7770 IP_STR
7771 BGP_STR
7772 "Display routes matching the communities\n"
7773 "community number\n"
7774 "Do not send outside local AS (well-known community)\n"
7775 "Do not advertise to any peer (well-known community)\n"
7776 "Do not export to next AS (well-known community)\n")
7777{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007778 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007779}
7780
7781ALIAS (show_ip_bgp_community,
7782 show_ip_bgp_community2_cmd,
7783 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7784 SHOW_STR
7785 IP_STR
7786 BGP_STR
7787 "Display routes matching the communities\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n")
7796
7797ALIAS (show_ip_bgp_community,
7798 show_ip_bgp_community3_cmd,
7799 "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)",
7800 SHOW_STR
7801 IP_STR
7802 BGP_STR
7803 "Display routes matching the communities\n"
7804 "community number\n"
7805 "Do not send outside local AS (well-known community)\n"
7806 "Do not advertise to any peer (well-known community)\n"
7807 "Do not export to next AS (well-known community)\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n")
7816
7817ALIAS (show_ip_bgp_community,
7818 show_ip_bgp_community4_cmd,
7819 "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)",
7820 SHOW_STR
7821 IP_STR
7822 BGP_STR
7823 "Display routes matching the communities\n"
7824 "community number\n"
7825 "Do not send outside local AS (well-known community)\n"
7826 "Do not advertise to any peer (well-known community)\n"
7827 "Do not export to next AS (well-known community)\n"
7828 "community number\n"
7829 "Do not send outside local AS (well-known community)\n"
7830 "Do not advertise to any peer (well-known community)\n"
7831 "Do not export to next AS (well-known community)\n"
7832 "community number\n"
7833 "Do not send outside local AS (well-known community)\n"
7834 "Do not advertise to any peer (well-known community)\n"
7835 "Do not export to next AS (well-known community)\n"
7836 "community number\n"
7837 "Do not send outside local AS (well-known community)\n"
7838 "Do not advertise to any peer (well-known community)\n"
7839 "Do not export to next AS (well-known community)\n")
7840
7841DEFUN (show_ip_bgp_ipv4_community,
7842 show_ip_bgp_ipv4_community_cmd,
7843 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7844 SHOW_STR
7845 IP_STR
7846 BGP_STR
7847 "Address family\n"
7848 "Address Family modifier\n"
7849 "Address Family modifier\n"
7850 "Display routes matching the communities\n"
7851 "community number\n"
7852 "Do not send outside local AS (well-known community)\n"
7853 "Do not advertise to any peer (well-known community)\n"
7854 "Do not export to next AS (well-known community)\n")
7855{
7856 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007857 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007858
Michael Lambert95cbbd22010-07-23 14:43:04 -04007859 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007860}
7861
7862ALIAS (show_ip_bgp_ipv4_community,
7863 show_ip_bgp_ipv4_community2_cmd,
7864 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7865 SHOW_STR
7866 IP_STR
7867 BGP_STR
7868 "Address family\n"
7869 "Address Family modifier\n"
7870 "Address Family modifier\n"
7871 "Display routes matching the communities\n"
7872 "community number\n"
7873 "Do not send outside local AS (well-known community)\n"
7874 "Do not advertise to any peer (well-known community)\n"
7875 "Do not export to next AS (well-known community)\n"
7876 "community number\n"
7877 "Do not send outside local AS (well-known community)\n"
7878 "Do not advertise to any peer (well-known community)\n"
7879 "Do not export to next AS (well-known community)\n")
7880
7881ALIAS (show_ip_bgp_ipv4_community,
7882 show_ip_bgp_ipv4_community3_cmd,
7883 "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)",
7884 SHOW_STR
7885 IP_STR
7886 BGP_STR
7887 "Address family\n"
7888 "Address Family modifier\n"
7889 "Address Family modifier\n"
7890 "Display routes matching the communities\n"
7891 "community number\n"
7892 "Do not send outside local AS (well-known community)\n"
7893 "Do not advertise to any peer (well-known community)\n"
7894 "Do not export to next AS (well-known community)\n"
7895 "community number\n"
7896 "Do not send outside local AS (well-known community)\n"
7897 "Do not advertise to any peer (well-known community)\n"
7898 "Do not export to next AS (well-known community)\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n")
7903
7904ALIAS (show_ip_bgp_ipv4_community,
7905 show_ip_bgp_ipv4_community4_cmd,
7906 "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)",
7907 SHOW_STR
7908 IP_STR
7909 BGP_STR
7910 "Address family\n"
7911 "Address Family modifier\n"
7912 "Address Family modifier\n"
7913 "Display routes matching the communities\n"
7914 "community number\n"
7915 "Do not send outside local AS (well-known community)\n"
7916 "Do not advertise to any peer (well-known community)\n"
7917 "Do not export to next AS (well-known community)\n"
7918 "community number\n"
7919 "Do not send outside local AS (well-known community)\n"
7920 "Do not advertise to any peer (well-known community)\n"
7921 "Do not export to next AS (well-known community)\n"
7922 "community number\n"
7923 "Do not send outside local AS (well-known community)\n"
7924 "Do not advertise to any peer (well-known community)\n"
7925 "Do not export to next AS (well-known community)\n"
7926 "community number\n"
7927 "Do not send outside local AS (well-known community)\n"
7928 "Do not advertise to any peer (well-known community)\n"
7929 "Do not export to next AS (well-known community)\n")
7930
Michael Lambert95cbbd22010-07-23 14:43:04 -04007931DEFUN (show_bgp_view_afi_safi_community_all,
7932 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007933 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007934 SHOW_STR
7935 BGP_STR
7936 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007937 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007938 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007939 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007940 "Address Family modifier\n"
7941 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00007942 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007943{
7944 int afi;
7945 int safi;
7946 struct bgp *bgp;
7947
7948 /* BGP structure lookup. */
7949 bgp = bgp_lookup_by_name (argv[0]);
7950 if (bgp == NULL)
7951 {
7952 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7953 return CMD_WARNING;
7954 }
7955
Michael Lambert95cbbd22010-07-23 14:43:04 -04007956 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7957 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007958 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7959}
7960
7961DEFUN (show_bgp_view_afi_safi_community,
7962 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007963 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007964 SHOW_STR
7965 BGP_STR
7966 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007967 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007968 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007969 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007970 "Address family modifier\n"
7971 "Address family modifier\n"
7972 "Display routes matching the communities\n"
7973 "community number\n"
7974 "Do not send outside local AS (well-known community)\n"
7975 "Do not advertise to any peer (well-known community)\n"
7976 "Do not export to next AS (well-known community)\n")
7977{
7978 int afi;
7979 int safi;
7980
Michael Lambert95cbbd22010-07-23 14:43:04 -04007981 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7982 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7983 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007984}
7985
7986ALIAS (show_bgp_view_afi_safi_community,
7987 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04007988 "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 -04007989 SHOW_STR
7990 BGP_STR
7991 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007992 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007993 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007994 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04007995 "Address family modifier\n"
7996 "Address family modifier\n"
7997 "Display routes matching the communities\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n")
8006
8007ALIAS (show_bgp_view_afi_safi_community,
8008 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008009 "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 -04008010 SHOW_STR
8011 BGP_STR
8012 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008013 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008014 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008015 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008016 "Address family modifier\n"
8017 "Address family modifier\n"
8018 "Display routes matching the communities\n"
8019 "community number\n"
8020 "Do not send outside local AS (well-known community)\n"
8021 "Do not advertise to any peer (well-known community)\n"
8022 "Do not export to next AS (well-known community)\n"
8023 "community number\n"
8024 "Do not send outside local AS (well-known community)\n"
8025 "Do not advertise to any peer (well-known community)\n"
8026 "Do not export to next AS (well-known community)\n"
8027 "community number\n"
8028 "Do not send outside local AS (well-known community)\n"
8029 "Do not advertise to any peer (well-known community)\n"
8030 "Do not export to next AS (well-known community)\n")
8031
8032ALIAS (show_bgp_view_afi_safi_community,
8033 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008034 "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 -04008035 SHOW_STR
8036 BGP_STR
8037 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008038 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008039 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008040 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008041 "Address family modifier\n"
8042 "Address family modifier\n"
8043 "Display routes matching the communities\n"
8044 "community number\n"
8045 "Do not send outside local AS (well-known community)\n"
8046 "Do not advertise to any peer (well-known community)\n"
8047 "Do not export to next AS (well-known community)\n"
8048 "community number\n"
8049 "Do not send outside local AS (well-known community)\n"
8050 "Do not advertise to any peer (well-known community)\n"
8051 "Do not export to next AS (well-known community)\n"
8052 "community number\n"
8053 "Do not send outside local AS (well-known community)\n"
8054 "Do not advertise to any peer (well-known community)\n"
8055 "Do not export to next AS (well-known community)\n"
8056 "community number\n"
8057 "Do not send outside local AS (well-known community)\n"
8058 "Do not advertise to any peer (well-known community)\n"
8059 "Do not export to next AS (well-known community)\n")
8060
paul718e3742002-12-13 20:15:29 +00008061DEFUN (show_ip_bgp_community_exact,
8062 show_ip_bgp_community_exact_cmd,
8063 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8064 SHOW_STR
8065 IP_STR
8066 BGP_STR
8067 "Display routes matching the communities\n"
8068 "community number\n"
8069 "Do not send outside local AS (well-known community)\n"
8070 "Do not advertise to any peer (well-known community)\n"
8071 "Do not export to next AS (well-known community)\n"
8072 "Exact match of the communities")
8073{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008074 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008075}
8076
8077ALIAS (show_ip_bgp_community_exact,
8078 show_ip_bgp_community2_exact_cmd,
8079 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8080 SHOW_STR
8081 IP_STR
8082 BGP_STR
8083 "Display routes matching the communities\n"
8084 "community number\n"
8085 "Do not send outside local AS (well-known community)\n"
8086 "Do not advertise to any peer (well-known community)\n"
8087 "Do not export to next AS (well-known community)\n"
8088 "community number\n"
8089 "Do not send outside local AS (well-known community)\n"
8090 "Do not advertise to any peer (well-known community)\n"
8091 "Do not export to next AS (well-known community)\n"
8092 "Exact match of the communities")
8093
8094ALIAS (show_ip_bgp_community_exact,
8095 show_ip_bgp_community3_exact_cmd,
8096 "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",
8097 SHOW_STR
8098 IP_STR
8099 BGP_STR
8100 "Display routes matching the communities\n"
8101 "community number\n"
8102 "Do not send outside local AS (well-known community)\n"
8103 "Do not advertise to any peer (well-known community)\n"
8104 "Do not export to next AS (well-known community)\n"
8105 "community number\n"
8106 "Do not send outside local AS (well-known community)\n"
8107 "Do not advertise to any peer (well-known community)\n"
8108 "Do not export to next AS (well-known community)\n"
8109 "community number\n"
8110 "Do not send outside local AS (well-known community)\n"
8111 "Do not advertise to any peer (well-known community)\n"
8112 "Do not export to next AS (well-known community)\n"
8113 "Exact match of the communities")
8114
8115ALIAS (show_ip_bgp_community_exact,
8116 show_ip_bgp_community4_exact_cmd,
8117 "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",
8118 SHOW_STR
8119 IP_STR
8120 BGP_STR
8121 "Display routes matching the communities\n"
8122 "community number\n"
8123 "Do not send outside local AS (well-known community)\n"
8124 "Do not advertise to any peer (well-known community)\n"
8125 "Do not export to next AS (well-known community)\n"
8126 "community number\n"
8127 "Do not send outside local AS (well-known community)\n"
8128 "Do not advertise to any peer (well-known community)\n"
8129 "Do not export to next AS (well-known community)\n"
8130 "community number\n"
8131 "Do not send outside local AS (well-known community)\n"
8132 "Do not advertise to any peer (well-known community)\n"
8133 "Do not export to next AS (well-known community)\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n"
8138 "Exact match of the communities")
8139
8140DEFUN (show_ip_bgp_ipv4_community_exact,
8141 show_ip_bgp_ipv4_community_exact_cmd,
8142 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8143 SHOW_STR
8144 IP_STR
8145 BGP_STR
8146 "Address family\n"
8147 "Address Family modifier\n"
8148 "Address Family modifier\n"
8149 "Display routes matching the communities\n"
8150 "community number\n"
8151 "Do not send outside local AS (well-known community)\n"
8152 "Do not advertise to any peer (well-known community)\n"
8153 "Do not export to next AS (well-known community)\n"
8154 "Exact match of the communities")
8155{
8156 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008157 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008158
Michael Lambert95cbbd22010-07-23 14:43:04 -04008159 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008160}
8161
8162ALIAS (show_ip_bgp_ipv4_community_exact,
8163 show_ip_bgp_ipv4_community2_exact_cmd,
8164 "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",
8165 SHOW_STR
8166 IP_STR
8167 BGP_STR
8168 "Address family\n"
8169 "Address Family modifier\n"
8170 "Address Family modifier\n"
8171 "Display routes matching the communities\n"
8172 "community number\n"
8173 "Do not send outside local AS (well-known community)\n"
8174 "Do not advertise to any peer (well-known community)\n"
8175 "Do not export to next AS (well-known community)\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n"
8180 "Exact match of the communities")
8181
8182ALIAS (show_ip_bgp_ipv4_community_exact,
8183 show_ip_bgp_ipv4_community3_exact_cmd,
8184 "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",
8185 SHOW_STR
8186 IP_STR
8187 BGP_STR
8188 "Address family\n"
8189 "Address Family modifier\n"
8190 "Address Family modifier\n"
8191 "Display routes matching the communities\n"
8192 "community number\n"
8193 "Do not send outside local AS (well-known community)\n"
8194 "Do not advertise to any peer (well-known community)\n"
8195 "Do not export to next AS (well-known community)\n"
8196 "community number\n"
8197 "Do not send outside local AS (well-known community)\n"
8198 "Do not advertise to any peer (well-known community)\n"
8199 "Do not export to next AS (well-known community)\n"
8200 "community number\n"
8201 "Do not send outside local AS (well-known community)\n"
8202 "Do not advertise to any peer (well-known community)\n"
8203 "Do not export to next AS (well-known community)\n"
8204 "Exact match of the communities")
8205
8206ALIAS (show_ip_bgp_ipv4_community_exact,
8207 show_ip_bgp_ipv4_community4_exact_cmd,
8208 "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",
8209 SHOW_STR
8210 IP_STR
8211 BGP_STR
8212 "Address family\n"
8213 "Address Family modifier\n"
8214 "Address Family modifier\n"
8215 "Display routes matching the communities\n"
8216 "community number\n"
8217 "Do not send outside local AS (well-known community)\n"
8218 "Do not advertise to any peer (well-known community)\n"
8219 "Do not export to next AS (well-known community)\n"
8220 "community number\n"
8221 "Do not send outside local AS (well-known community)\n"
8222 "Do not advertise to any peer (well-known community)\n"
8223 "Do not export to next AS (well-known community)\n"
8224 "community number\n"
8225 "Do not send outside local AS (well-known community)\n"
8226 "Do not advertise to any peer (well-known community)\n"
8227 "Do not export to next AS (well-known community)\n"
8228 "community number\n"
8229 "Do not send outside local AS (well-known community)\n"
8230 "Do not advertise to any peer (well-known community)\n"
8231 "Do not export to next AS (well-known community)\n"
8232 "Exact match of the communities")
8233
8234#ifdef HAVE_IPV6
8235DEFUN (show_bgp_community,
8236 show_bgp_community_cmd,
8237 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8238 SHOW_STR
8239 BGP_STR
8240 "Display routes matching the communities\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n")
8245{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008246 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008247}
8248
8249ALIAS (show_bgp_community,
8250 show_bgp_ipv6_community_cmd,
8251 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8252 SHOW_STR
8253 BGP_STR
8254 "Address family\n"
8255 "Display routes matching the communities\n"
8256 "community number\n"
8257 "Do not send outside local AS (well-known community)\n"
8258 "Do not advertise to any peer (well-known community)\n"
8259 "Do not export to next AS (well-known community)\n")
8260
8261ALIAS (show_bgp_community,
8262 show_bgp_community2_cmd,
8263 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8264 SHOW_STR
8265 BGP_STR
8266 "Display routes matching the communities\n"
8267 "community number\n"
8268 "Do not send outside local AS (well-known community)\n"
8269 "Do not advertise to any peer (well-known community)\n"
8270 "Do not export to next AS (well-known community)\n"
8271 "community number\n"
8272 "Do not send outside local AS (well-known community)\n"
8273 "Do not advertise to any peer (well-known community)\n"
8274 "Do not export to next AS (well-known community)\n")
8275
8276ALIAS (show_bgp_community,
8277 show_bgp_ipv6_community2_cmd,
8278 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8279 SHOW_STR
8280 BGP_STR
8281 "Address family\n"
8282 "Display routes matching the communities\n"
8283 "community number\n"
8284 "Do not send outside local AS (well-known community)\n"
8285 "Do not advertise to any peer (well-known community)\n"
8286 "Do not export to next AS (well-known community)\n"
8287 "community number\n"
8288 "Do not send outside local AS (well-known community)\n"
8289 "Do not advertise to any peer (well-known community)\n"
8290 "Do not export to next AS (well-known community)\n")
8291
8292ALIAS (show_bgp_community,
8293 show_bgp_community3_cmd,
8294 "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)",
8295 SHOW_STR
8296 BGP_STR
8297 "Display routes matching the communities\n"
8298 "community number\n"
8299 "Do not send outside local AS (well-known community)\n"
8300 "Do not advertise to any peer (well-known community)\n"
8301 "Do not export to next AS (well-known community)\n"
8302 "community number\n"
8303 "Do not send outside local AS (well-known community)\n"
8304 "Do not advertise to any peer (well-known community)\n"
8305 "Do not export to next AS (well-known community)\n"
8306 "community number\n"
8307 "Do not send outside local AS (well-known community)\n"
8308 "Do not advertise to any peer (well-known community)\n"
8309 "Do not export to next AS (well-known community)\n")
8310
8311ALIAS (show_bgp_community,
8312 show_bgp_ipv6_community3_cmd,
8313 "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)",
8314 SHOW_STR
8315 BGP_STR
8316 "Address family\n"
8317 "Display routes matching the communities\n"
8318 "community number\n"
8319 "Do not send outside local AS (well-known community)\n"
8320 "Do not advertise to any peer (well-known community)\n"
8321 "Do not export to next AS (well-known community)\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n"
8326 "community number\n"
8327 "Do not send outside local AS (well-known community)\n"
8328 "Do not advertise to any peer (well-known community)\n"
8329 "Do not export to next AS (well-known community)\n")
8330
8331ALIAS (show_bgp_community,
8332 show_bgp_community4_cmd,
8333 "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)",
8334 SHOW_STR
8335 BGP_STR
8336 "Display routes matching the communities\n"
8337 "community number\n"
8338 "Do not send outside local AS (well-known community)\n"
8339 "Do not advertise to any peer (well-known community)\n"
8340 "Do not export to next AS (well-known community)\n"
8341 "community number\n"
8342 "Do not send outside local AS (well-known community)\n"
8343 "Do not advertise to any peer (well-known community)\n"
8344 "Do not export to next AS (well-known community)\n"
8345 "community number\n"
8346 "Do not send outside local AS (well-known community)\n"
8347 "Do not advertise to any peer (well-known community)\n"
8348 "Do not export to next AS (well-known community)\n"
8349 "community number\n"
8350 "Do not send outside local AS (well-known community)\n"
8351 "Do not advertise to any peer (well-known community)\n"
8352 "Do not export to next AS (well-known community)\n")
8353
8354ALIAS (show_bgp_community,
8355 show_bgp_ipv6_community4_cmd,
8356 "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)",
8357 SHOW_STR
8358 BGP_STR
8359 "Address family\n"
8360 "Display routes matching the communities\n"
8361 "community number\n"
8362 "Do not send outside local AS (well-known community)\n"
8363 "Do not advertise to any peer (well-known community)\n"
8364 "Do not export to next AS (well-known community)\n"
8365 "community number\n"
8366 "Do not send outside local AS (well-known community)\n"
8367 "Do not advertise to any peer (well-known community)\n"
8368 "Do not export to next AS (well-known community)\n"
8369 "community number\n"
8370 "Do not send outside local AS (well-known community)\n"
8371 "Do not advertise to any peer (well-known community)\n"
8372 "Do not export to next AS (well-known community)\n"
8373 "community number\n"
8374 "Do not send outside local AS (well-known community)\n"
8375 "Do not advertise to any peer (well-known community)\n"
8376 "Do not export to next AS (well-known community)\n")
8377
8378/* old command */
8379DEFUN (show_ipv6_bgp_community,
8380 show_ipv6_bgp_community_cmd,
8381 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8382 SHOW_STR
8383 IPV6_STR
8384 BGP_STR
8385 "Display routes matching the communities\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n")
8390{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008391 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008392}
8393
8394/* old command */
8395ALIAS (show_ipv6_bgp_community,
8396 show_ipv6_bgp_community2_cmd,
8397 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8398 SHOW_STR
8399 IPV6_STR
8400 BGP_STR
8401 "Display routes matching the communities\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n"
8406 "community number\n"
8407 "Do not send outside local AS (well-known community)\n"
8408 "Do not advertise to any peer (well-known community)\n"
8409 "Do not export to next AS (well-known community)\n")
8410
8411/* old command */
8412ALIAS (show_ipv6_bgp_community,
8413 show_ipv6_bgp_community3_cmd,
8414 "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)",
8415 SHOW_STR
8416 IPV6_STR
8417 BGP_STR
8418 "Display routes matching the communities\n"
8419 "community number\n"
8420 "Do not send outside local AS (well-known community)\n"
8421 "Do not advertise to any peer (well-known community)\n"
8422 "Do not export to next AS (well-known community)\n"
8423 "community number\n"
8424 "Do not send outside local AS (well-known community)\n"
8425 "Do not advertise to any peer (well-known community)\n"
8426 "Do not export to next AS (well-known community)\n"
8427 "community number\n"
8428 "Do not send outside local AS (well-known community)\n"
8429 "Do not advertise to any peer (well-known community)\n"
8430 "Do not export to next AS (well-known community)\n")
8431
8432/* old command */
8433ALIAS (show_ipv6_bgp_community,
8434 show_ipv6_bgp_community4_cmd,
8435 "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)",
8436 SHOW_STR
8437 IPV6_STR
8438 BGP_STR
8439 "Display routes matching the communities\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n"
8448 "community number\n"
8449 "Do not send outside local AS (well-known community)\n"
8450 "Do not advertise to any peer (well-known community)\n"
8451 "Do not export to next AS (well-known community)\n"
8452 "community number\n"
8453 "Do not send outside local AS (well-known community)\n"
8454 "Do not advertise to any peer (well-known community)\n"
8455 "Do not export to next AS (well-known community)\n")
8456
8457DEFUN (show_bgp_community_exact,
8458 show_bgp_community_exact_cmd,
8459 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8460 SHOW_STR
8461 BGP_STR
8462 "Display routes matching the communities\n"
8463 "community number\n"
8464 "Do not send outside local AS (well-known community)\n"
8465 "Do not advertise to any peer (well-known community)\n"
8466 "Do not export to next AS (well-known community)\n"
8467 "Exact match of the communities")
8468{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008469 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008470}
8471
8472ALIAS (show_bgp_community_exact,
8473 show_bgp_ipv6_community_exact_cmd,
8474 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8475 SHOW_STR
8476 BGP_STR
8477 "Address family\n"
8478 "Display routes matching the communities\n"
8479 "community number\n"
8480 "Do not send outside local AS (well-known community)\n"
8481 "Do not advertise to any peer (well-known community)\n"
8482 "Do not export to next AS (well-known community)\n"
8483 "Exact match of the communities")
8484
8485ALIAS (show_bgp_community_exact,
8486 show_bgp_community2_exact_cmd,
8487 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8488 SHOW_STR
8489 BGP_STR
8490 "Display routes matching the communities\n"
8491 "community number\n"
8492 "Do not send outside local AS (well-known community)\n"
8493 "Do not advertise to any peer (well-known community)\n"
8494 "Do not export to next AS (well-known community)\n"
8495 "community number\n"
8496 "Do not send outside local AS (well-known community)\n"
8497 "Do not advertise to any peer (well-known community)\n"
8498 "Do not export to next AS (well-known community)\n"
8499 "Exact match of the communities")
8500
8501ALIAS (show_bgp_community_exact,
8502 show_bgp_ipv6_community2_exact_cmd,
8503 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8504 SHOW_STR
8505 BGP_STR
8506 "Address family\n"
8507 "Display routes matching the communities\n"
8508 "community number\n"
8509 "Do not send outside local AS (well-known community)\n"
8510 "Do not advertise to any peer (well-known community)\n"
8511 "Do not export to next AS (well-known community)\n"
8512 "community number\n"
8513 "Do not send outside local AS (well-known community)\n"
8514 "Do not advertise to any peer (well-known community)\n"
8515 "Do not export to next AS (well-known community)\n"
8516 "Exact match of the communities")
8517
8518ALIAS (show_bgp_community_exact,
8519 show_bgp_community3_exact_cmd,
8520 "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",
8521 SHOW_STR
8522 BGP_STR
8523 "Display routes matching the communities\n"
8524 "community number\n"
8525 "Do not send outside local AS (well-known community)\n"
8526 "Do not advertise to any peer (well-known community)\n"
8527 "Do not export to next AS (well-known community)\n"
8528 "community number\n"
8529 "Do not send outside local AS (well-known community)\n"
8530 "Do not advertise to any peer (well-known community)\n"
8531 "Do not export to next AS (well-known community)\n"
8532 "community number\n"
8533 "Do not send outside local AS (well-known community)\n"
8534 "Do not advertise to any peer (well-known community)\n"
8535 "Do not export to next AS (well-known community)\n"
8536 "Exact match of the communities")
8537
8538ALIAS (show_bgp_community_exact,
8539 show_bgp_ipv6_community3_exact_cmd,
8540 "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",
8541 SHOW_STR
8542 BGP_STR
8543 "Address family\n"
8544 "Display routes matching the communities\n"
8545 "community number\n"
8546 "Do not send outside local AS (well-known community)\n"
8547 "Do not advertise to any peer (well-known community)\n"
8548 "Do not export to next AS (well-known community)\n"
8549 "community number\n"
8550 "Do not send outside local AS (well-known community)\n"
8551 "Do not advertise to any peer (well-known community)\n"
8552 "Do not export to next AS (well-known community)\n"
8553 "community number\n"
8554 "Do not send outside local AS (well-known community)\n"
8555 "Do not advertise to any peer (well-known community)\n"
8556 "Do not export to next AS (well-known community)\n"
8557 "Exact match of the communities")
8558
8559ALIAS (show_bgp_community_exact,
8560 show_bgp_community4_exact_cmd,
8561 "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",
8562 SHOW_STR
8563 BGP_STR
8564 "Display routes matching the communities\n"
8565 "community number\n"
8566 "Do not send outside local AS (well-known community)\n"
8567 "Do not advertise to any peer (well-known community)\n"
8568 "Do not export to next AS (well-known community)\n"
8569 "community number\n"
8570 "Do not send outside local AS (well-known community)\n"
8571 "Do not advertise to any peer (well-known community)\n"
8572 "Do not export to next AS (well-known community)\n"
8573 "community number\n"
8574 "Do not send outside local AS (well-known community)\n"
8575 "Do not advertise to any peer (well-known community)\n"
8576 "Do not export to next AS (well-known community)\n"
8577 "community number\n"
8578 "Do not send outside local AS (well-known community)\n"
8579 "Do not advertise to any peer (well-known community)\n"
8580 "Do not export to next AS (well-known community)\n"
8581 "Exact match of the communities")
8582
8583ALIAS (show_bgp_community_exact,
8584 show_bgp_ipv6_community4_exact_cmd,
8585 "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",
8586 SHOW_STR
8587 BGP_STR
8588 "Address family\n"
8589 "Display routes matching the communities\n"
8590 "community number\n"
8591 "Do not send outside local AS (well-known community)\n"
8592 "Do not advertise to any peer (well-known community)\n"
8593 "Do not export to next AS (well-known community)\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "community number\n"
8599 "Do not send outside local AS (well-known community)\n"
8600 "Do not advertise to any peer (well-known community)\n"
8601 "Do not export to next AS (well-known community)\n"
8602 "community number\n"
8603 "Do not send outside local AS (well-known community)\n"
8604 "Do not advertise to any peer (well-known community)\n"
8605 "Do not export to next AS (well-known community)\n"
8606 "Exact match of the communities")
8607
8608/* old command */
8609DEFUN (show_ipv6_bgp_community_exact,
8610 show_ipv6_bgp_community_exact_cmd,
8611 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8612 SHOW_STR
8613 IPV6_STR
8614 BGP_STR
8615 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008622 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008623}
8624
8625/* old command */
8626ALIAS (show_ipv6_bgp_community_exact,
8627 show_ipv6_bgp_community2_exact_cmd,
8628 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8629 SHOW_STR
8630 IPV6_STR
8631 BGP_STR
8632 "Display routes matching the communities\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\n"
8641 "Exact match of the communities")
8642
8643/* old command */
8644ALIAS (show_ipv6_bgp_community_exact,
8645 show_ipv6_bgp_community3_exact_cmd,
8646 "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",
8647 SHOW_STR
8648 IPV6_STR
8649 BGP_STR
8650 "Display routes matching the communities\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 "community number\n"
8656 "Do not send outside local AS (well-known community)\n"
8657 "Do not advertise to any peer (well-known community)\n"
8658 "Do not export to next AS (well-known community)\n"
8659 "community number\n"
8660 "Do not send outside local AS (well-known community)\n"
8661 "Do not advertise to any peer (well-known community)\n"
8662 "Do not export to next AS (well-known community)\n"
8663 "Exact match of the communities")
8664
8665/* old command */
8666ALIAS (show_ipv6_bgp_community_exact,
8667 show_ipv6_bgp_community4_exact_cmd,
8668 "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",
8669 SHOW_STR
8670 IPV6_STR
8671 BGP_STR
8672 "Display routes matching the communities\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 "community number\n"
8678 "Do not send outside local AS (well-known community)\n"
8679 "Do not advertise to any peer (well-known community)\n"
8680 "Do not export to next AS (well-known community)\n"
8681 "community number\n"
8682 "Do not send outside local AS (well-known community)\n"
8683 "Do not advertise to any peer (well-known community)\n"
8684 "Do not export to next AS (well-known community)\n"
8685 "community number\n"
8686 "Do not send outside local AS (well-known community)\n"
8687 "Do not advertise to any peer (well-known community)\n"
8688 "Do not export to next AS (well-known community)\n"
8689 "Exact match of the communities")
8690
8691/* old command */
8692DEFUN (show_ipv6_mbgp_community,
8693 show_ipv6_mbgp_community_cmd,
8694 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8695 SHOW_STR
8696 IPV6_STR
8697 MBGP_STR
8698 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008704 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008705}
8706
8707/* old command */
8708ALIAS (show_ipv6_mbgp_community,
8709 show_ipv6_mbgp_community2_cmd,
8710 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8711 SHOW_STR
8712 IPV6_STR
8713 MBGP_STR
8714 "Display routes matching the communities\n"
8715 "community number\n"
8716 "Do not send outside local AS (well-known community)\n"
8717 "Do not advertise to any peer (well-known community)\n"
8718 "Do not export to next AS (well-known community)\n"
8719 "community number\n"
8720 "Do not send outside local AS (well-known community)\n"
8721 "Do not advertise to any peer (well-known community)\n"
8722 "Do not export to next AS (well-known community)\n")
8723
8724/* old command */
8725ALIAS (show_ipv6_mbgp_community,
8726 show_ipv6_mbgp_community3_cmd,
8727 "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)",
8728 SHOW_STR
8729 IPV6_STR
8730 MBGP_STR
8731 "Display routes matching the communities\n"
8732 "community number\n"
8733 "Do not send outside local AS (well-known community)\n"
8734 "Do not advertise to any peer (well-known community)\n"
8735 "Do not export to next AS (well-known community)\n"
8736 "community number\n"
8737 "Do not send outside local AS (well-known community)\n"
8738 "Do not advertise to any peer (well-known community)\n"
8739 "Do not export to next AS (well-known community)\n"
8740 "community number\n"
8741 "Do not send outside local AS (well-known community)\n"
8742 "Do not advertise to any peer (well-known community)\n"
8743 "Do not export to next AS (well-known community)\n")
8744
8745/* old command */
8746ALIAS (show_ipv6_mbgp_community,
8747 show_ipv6_mbgp_community4_cmd,
8748 "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)",
8749 SHOW_STR
8750 IPV6_STR
8751 MBGP_STR
8752 "Display routes matching the communities\n"
8753 "community number\n"
8754 "Do not send outside local AS (well-known community)\n"
8755 "Do not advertise to any peer (well-known community)\n"
8756 "Do not export to next AS (well-known community)\n"
8757 "community number\n"
8758 "Do not send outside local AS (well-known community)\n"
8759 "Do not advertise to any peer (well-known community)\n"
8760 "Do not export to next AS (well-known community)\n"
8761 "community number\n"
8762 "Do not send outside local AS (well-known community)\n"
8763 "Do not advertise to any peer (well-known community)\n"
8764 "Do not export to next AS (well-known community)\n"
8765 "community number\n"
8766 "Do not send outside local AS (well-known community)\n"
8767 "Do not advertise to any peer (well-known community)\n"
8768 "Do not export to next AS (well-known community)\n")
8769
8770/* old command */
8771DEFUN (show_ipv6_mbgp_community_exact,
8772 show_ipv6_mbgp_community_exact_cmd,
8773 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8774 SHOW_STR
8775 IPV6_STR
8776 MBGP_STR
8777 "Display routes matching the communities\n"
8778 "community number\n"
8779 "Do not send outside local AS (well-known community)\n"
8780 "Do not advertise to any peer (well-known community)\n"
8781 "Do not export to next AS (well-known community)\n"
8782 "Exact match of the communities")
8783{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008784 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008785}
8786
8787/* old command */
8788ALIAS (show_ipv6_mbgp_community_exact,
8789 show_ipv6_mbgp_community2_exact_cmd,
8790 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8791 SHOW_STR
8792 IPV6_STR
8793 MBGP_STR
8794 "Display routes matching the communities\n"
8795 "community number\n"
8796 "Do not send outside local AS (well-known community)\n"
8797 "Do not advertise to any peer (well-known community)\n"
8798 "Do not export to next AS (well-known community)\n"
8799 "community number\n"
8800 "Do not send outside local AS (well-known community)\n"
8801 "Do not advertise to any peer (well-known community)\n"
8802 "Do not export to next AS (well-known community)\n"
8803 "Exact match of the communities")
8804
8805/* old command */
8806ALIAS (show_ipv6_mbgp_community_exact,
8807 show_ipv6_mbgp_community3_exact_cmd,
8808 "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",
8809 SHOW_STR
8810 IPV6_STR
8811 MBGP_STR
8812 "Display routes matching the communities\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 "community number\n"
8818 "Do not send outside local AS (well-known community)\n"
8819 "Do not advertise to any peer (well-known community)\n"
8820 "Do not export to next AS (well-known community)\n"
8821 "community number\n"
8822 "Do not send outside local AS (well-known community)\n"
8823 "Do not advertise to any peer (well-known community)\n"
8824 "Do not export to next AS (well-known community)\n"
8825 "Exact match of the communities")
8826
8827/* old command */
8828ALIAS (show_ipv6_mbgp_community_exact,
8829 show_ipv6_mbgp_community4_exact_cmd,
8830 "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",
8831 SHOW_STR
8832 IPV6_STR
8833 MBGP_STR
8834 "Display routes matching the communities\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 "community number\n"
8840 "Do not send outside local AS (well-known community)\n"
8841 "Do not advertise to any peer (well-known community)\n"
8842 "Do not export to next AS (well-known community)\n"
8843 "community number\n"
8844 "Do not send outside local AS (well-known community)\n"
8845 "Do not advertise to any peer (well-known community)\n"
8846 "Do not export to next AS (well-known community)\n"
8847 "community number\n"
8848 "Do not send outside local AS (well-known community)\n"
8849 "Do not advertise to any peer (well-known community)\n"
8850 "Do not export to next AS (well-known community)\n"
8851 "Exact match of the communities")
8852#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008853
paul94f2b392005-06-28 12:44:16 +00008854static int
paulfd79ac92004-10-13 05:06:08 +00008855bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008856 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008857{
8858 struct community_list *list;
8859
hassofee6e4e2005-02-02 16:29:31 +00008860 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008861 if (list == NULL)
8862 {
8863 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8864 VTY_NEWLINE);
8865 return CMD_WARNING;
8866 }
8867
ajs5a646652004-11-05 01:25:55 +00008868 return bgp_show (vty, NULL, afi, safi,
8869 (exact ? bgp_show_type_community_list_exact :
8870 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008871}
8872
8873DEFUN (show_ip_bgp_community_list,
8874 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008875 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008876 SHOW_STR
8877 IP_STR
8878 BGP_STR
8879 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008880 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008881 "community-list name\n")
8882{
8883 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8884}
8885
8886DEFUN (show_ip_bgp_ipv4_community_list,
8887 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008888 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008889 SHOW_STR
8890 IP_STR
8891 BGP_STR
8892 "Address family\n"
8893 "Address Family modifier\n"
8894 "Address Family modifier\n"
8895 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008896 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008897 "community-list name\n")
8898{
8899 if (strncmp (argv[0], "m", 1) == 0)
8900 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8901
8902 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8903}
8904
8905DEFUN (show_ip_bgp_community_list_exact,
8906 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008907 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008908 SHOW_STR
8909 IP_STR
8910 BGP_STR
8911 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008912 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008913 "community-list name\n"
8914 "Exact match of the communities\n")
8915{
8916 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8917}
8918
8919DEFUN (show_ip_bgp_ipv4_community_list_exact,
8920 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008921 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008922 SHOW_STR
8923 IP_STR
8924 BGP_STR
8925 "Address family\n"
8926 "Address Family modifier\n"
8927 "Address Family modifier\n"
8928 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008929 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008930 "community-list name\n"
8931 "Exact match of the communities\n")
8932{
8933 if (strncmp (argv[0], "m", 1) == 0)
8934 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8935
8936 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8937}
8938
8939#ifdef HAVE_IPV6
8940DEFUN (show_bgp_community_list,
8941 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008942 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008943 SHOW_STR
8944 BGP_STR
8945 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008946 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008947 "community-list name\n")
8948{
8949 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8950}
8951
8952ALIAS (show_bgp_community_list,
8953 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008954 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008955 SHOW_STR
8956 BGP_STR
8957 "Address family\n"
8958 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008959 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008960 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008961
8962/* old command */
8963DEFUN (show_ipv6_bgp_community_list,
8964 show_ipv6_bgp_community_list_cmd,
8965 "show ipv6 bgp community-list WORD",
8966 SHOW_STR
8967 IPV6_STR
8968 BGP_STR
8969 "Display routes matching the community-list\n"
8970 "community-list name\n")
8971{
8972 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8973}
8974
8975/* old command */
8976DEFUN (show_ipv6_mbgp_community_list,
8977 show_ipv6_mbgp_community_list_cmd,
8978 "show ipv6 mbgp community-list WORD",
8979 SHOW_STR
8980 IPV6_STR
8981 MBGP_STR
8982 "Display routes matching the community-list\n"
8983 "community-list name\n")
8984{
8985 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8986}
8987
8988DEFUN (show_bgp_community_list_exact,
8989 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008990 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008991 SHOW_STR
8992 BGP_STR
8993 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008994 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008995 "community-list name\n"
8996 "Exact match of the communities\n")
8997{
8998 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8999}
9000
9001ALIAS (show_bgp_community_list_exact,
9002 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009003 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009004 SHOW_STR
9005 BGP_STR
9006 "Address family\n"
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/* old command */
9013DEFUN (show_ipv6_bgp_community_list_exact,
9014 show_ipv6_bgp_community_list_exact_cmd,
9015 "show ipv6 bgp community-list WORD exact-match",
9016 SHOW_STR
9017 IPV6_STR
9018 BGP_STR
9019 "Display routes matching the community-list\n"
9020 "community-list name\n"
9021 "Exact match of the communities\n")
9022{
9023 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9024}
9025
9026/* old command */
9027DEFUN (show_ipv6_mbgp_community_list_exact,
9028 show_ipv6_mbgp_community_list_exact_cmd,
9029 "show ipv6 mbgp community-list WORD exact-match",
9030 SHOW_STR
9031 IPV6_STR
9032 MBGP_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_MULTICAST);
9038}
9039#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009040
paul94f2b392005-06-28 12:44:16 +00009041static int
paulfd79ac92004-10-13 05:06:08 +00009042bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009043 safi_t safi, enum bgp_show_type type)
9044{
9045 int ret;
9046 struct prefix *p;
9047
9048 p = prefix_new();
9049
9050 ret = str2prefix (prefix, p);
9051 if (! ret)
9052 {
9053 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9054 return CMD_WARNING;
9055 }
9056
ajs5a646652004-11-05 01:25:55 +00009057 ret = bgp_show (vty, NULL, afi, safi, type, p);
9058 prefix_free(p);
9059 return ret;
paul718e3742002-12-13 20:15:29 +00009060}
9061
9062DEFUN (show_ip_bgp_prefix_longer,
9063 show_ip_bgp_prefix_longer_cmd,
9064 "show ip bgp A.B.C.D/M longer-prefixes",
9065 SHOW_STR
9066 IP_STR
9067 BGP_STR
9068 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9069 "Display route and more specific routes\n")
9070{
9071 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9072 bgp_show_type_prefix_longer);
9073}
9074
9075DEFUN (show_ip_bgp_flap_prefix_longer,
9076 show_ip_bgp_flap_prefix_longer_cmd,
9077 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9078 SHOW_STR
9079 IP_STR
9080 BGP_STR
9081 "Display flap statistics of routes\n"
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_flap_prefix_longer);
9087}
9088
9089DEFUN (show_ip_bgp_ipv4_prefix_longer,
9090 show_ip_bgp_ipv4_prefix_longer_cmd,
9091 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9092 SHOW_STR
9093 IP_STR
9094 BGP_STR
9095 "Address family\n"
9096 "Address Family modifier\n"
9097 "Address Family modifier\n"
9098 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9099 "Display route and more specific routes\n")
9100{
9101 if (strncmp (argv[0], "m", 1) == 0)
9102 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9103 bgp_show_type_prefix_longer);
9104
9105 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9106 bgp_show_type_prefix_longer);
9107}
9108
9109DEFUN (show_ip_bgp_flap_address,
9110 show_ip_bgp_flap_address_cmd,
9111 "show ip bgp flap-statistics A.B.C.D",
9112 SHOW_STR
9113 IP_STR
9114 BGP_STR
9115 "Display flap statistics of routes\n"
9116 "Network in the BGP routing table to display\n")
9117{
9118 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9119 bgp_show_type_flap_address);
9120}
9121
9122DEFUN (show_ip_bgp_flap_prefix,
9123 show_ip_bgp_flap_prefix_cmd,
9124 "show ip bgp flap-statistics A.B.C.D/M",
9125 SHOW_STR
9126 IP_STR
9127 BGP_STR
9128 "Display flap statistics of routes\n"
9129 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9130{
9131 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9132 bgp_show_type_flap_prefix);
9133}
9134#ifdef HAVE_IPV6
9135DEFUN (show_bgp_prefix_longer,
9136 show_bgp_prefix_longer_cmd,
9137 "show bgp X:X::X:X/M longer-prefixes",
9138 SHOW_STR
9139 BGP_STR
9140 "IPv6 prefix <network>/<length>\n"
9141 "Display route and more specific routes\n")
9142{
9143 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9144 bgp_show_type_prefix_longer);
9145}
9146
9147ALIAS (show_bgp_prefix_longer,
9148 show_bgp_ipv6_prefix_longer_cmd,
9149 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9150 SHOW_STR
9151 BGP_STR
9152 "Address family\n"
9153 "IPv6 prefix <network>/<length>\n"
9154 "Display route and more specific routes\n")
9155
9156/* old command */
9157DEFUN (show_ipv6_bgp_prefix_longer,
9158 show_ipv6_bgp_prefix_longer_cmd,
9159 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9160 SHOW_STR
9161 IPV6_STR
9162 BGP_STR
9163 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9164 "Display route and more specific routes\n")
9165{
9166 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9167 bgp_show_type_prefix_longer);
9168}
9169
9170/* old command */
9171DEFUN (show_ipv6_mbgp_prefix_longer,
9172 show_ipv6_mbgp_prefix_longer_cmd,
9173 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9174 SHOW_STR
9175 IPV6_STR
9176 MBGP_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_MULTICAST,
9181 bgp_show_type_prefix_longer);
9182}
9183#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009184
paul94f2b392005-06-28 12:44:16 +00009185static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009186peer_lookup_in_view (struct vty *vty, const char *view_name,
9187 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009188{
9189 int ret;
9190 struct bgp *bgp;
9191 struct peer *peer;
9192 union sockunion su;
9193
9194 /* BGP structure lookup. */
9195 if (view_name)
9196 {
9197 bgp = bgp_lookup_by_name (view_name);
9198 if (! bgp)
9199 {
9200 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9201 return NULL;
9202 }
9203 }
paul5228ad22004-06-04 17:58:18 +00009204 else
paulbb46e942003-10-24 19:02:03 +00009205 {
9206 bgp = bgp_get_default ();
9207 if (! bgp)
9208 {
9209 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9210 return NULL;
9211 }
9212 }
9213
9214 /* Get peer sockunion. */
9215 ret = str2sockunion (ip_str, &su);
9216 if (ret < 0)
9217 {
9218 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9219 return NULL;
9220 }
9221
9222 /* Peer structure lookup. */
9223 peer = peer_lookup (bgp, &su);
9224 if (! peer)
9225 {
9226 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9227 return NULL;
9228 }
9229
9230 return peer;
9231}
David Lamparter6b0655a2014-06-04 06:53:35 +02009232
Paul Jakma2815e612006-09-14 02:56:07 +00009233enum bgp_stats
9234{
9235 BGP_STATS_MAXBITLEN = 0,
9236 BGP_STATS_RIB,
9237 BGP_STATS_PREFIXES,
9238 BGP_STATS_TOTPLEN,
9239 BGP_STATS_UNAGGREGATEABLE,
9240 BGP_STATS_MAX_AGGREGATEABLE,
9241 BGP_STATS_AGGREGATES,
9242 BGP_STATS_SPACE,
9243 BGP_STATS_ASPATH_COUNT,
9244 BGP_STATS_ASPATH_MAXHOPS,
9245 BGP_STATS_ASPATH_TOTHOPS,
9246 BGP_STATS_ASPATH_MAXSIZE,
9247 BGP_STATS_ASPATH_TOTSIZE,
9248 BGP_STATS_ASN_HIGHEST,
9249 BGP_STATS_MAX,
9250};
paulbb46e942003-10-24 19:02:03 +00009251
Paul Jakma2815e612006-09-14 02:56:07 +00009252static const char *table_stats_strs[] =
9253{
9254 [BGP_STATS_PREFIXES] = "Total Prefixes",
9255 [BGP_STATS_TOTPLEN] = "Average prefix length",
9256 [BGP_STATS_RIB] = "Total Advertisements",
9257 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9258 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9259 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9260 [BGP_STATS_SPACE] = "Address space advertised",
9261 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9262 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9263 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9264 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9265 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9266 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9267 [BGP_STATS_MAX] = NULL,
9268};
9269
9270struct bgp_table_stats
9271{
9272 struct bgp_table *table;
9273 unsigned long long counts[BGP_STATS_MAX];
9274};
9275
9276#if 0
9277#define TALLY_SIGFIG 100000
9278static unsigned long
9279ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9280{
9281 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9282 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9283 unsigned long ret = newtot / count;
9284
9285 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9286 return ret + 1;
9287 else
9288 return ret;
9289}
9290#endif
9291
9292static int
9293bgp_table_stats_walker (struct thread *t)
9294{
9295 struct bgp_node *rn;
9296 struct bgp_node *top;
9297 struct bgp_table_stats *ts = THREAD_ARG (t);
9298 unsigned int space = 0;
9299
Paul Jakma53d9f672006-10-15 23:41:16 +00009300 if (!(top = bgp_table_top (ts->table)))
9301 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009302
9303 switch (top->p.family)
9304 {
9305 case AF_INET:
9306 space = IPV4_MAX_BITLEN;
9307 break;
9308 case AF_INET6:
9309 space = IPV6_MAX_BITLEN;
9310 break;
9311 }
9312
9313 ts->counts[BGP_STATS_MAXBITLEN] = space;
9314
9315 for (rn = top; rn; rn = bgp_route_next (rn))
9316 {
9317 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009318 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009319 unsigned int rinum = 0;
9320
9321 if (rn == top)
9322 continue;
9323
9324 if (!rn->info)
9325 continue;
9326
9327 ts->counts[BGP_STATS_PREFIXES]++;
9328 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9329
9330#if 0
9331 ts->counts[BGP_STATS_AVGPLEN]
9332 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9333 ts->counts[BGP_STATS_AVGPLEN],
9334 rn->p.prefixlen);
9335#endif
9336
9337 /* check if the prefix is included by any other announcements */
9338 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009339 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009340
9341 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009342 {
9343 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9344 /* announced address space */
9345 if (space)
9346 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9347 }
Paul Jakma2815e612006-09-14 02:56:07 +00009348 else if (prn->info)
9349 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9350
Paul Jakma2815e612006-09-14 02:56:07 +00009351 for (ri = rn->info; ri; ri = ri->next)
9352 {
9353 rinum++;
9354 ts->counts[BGP_STATS_RIB]++;
9355
9356 if (ri->attr &&
9357 (CHECK_FLAG (ri->attr->flag,
9358 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9359 ts->counts[BGP_STATS_AGGREGATES]++;
9360
9361 /* as-path stats */
9362 if (ri->attr && ri->attr->aspath)
9363 {
9364 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9365 unsigned int size = aspath_size (ri->attr->aspath);
9366 as_t highest = aspath_highest (ri->attr->aspath);
9367
9368 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9369
9370 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9371 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9372
9373 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9374 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9375
9376 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9377 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9378#if 0
9379 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9380 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9381 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9382 hops);
9383 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9384 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9385 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9386 size);
9387#endif
9388 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9389 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9390 }
9391 }
9392 }
9393 return 0;
9394}
9395
9396static int
9397bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9398{
9399 struct bgp_table_stats ts;
9400 unsigned int i;
9401
9402 if (!bgp->rib[afi][safi])
9403 {
9404 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9405 return CMD_WARNING;
9406 }
9407
9408 memset (&ts, 0, sizeof (ts));
9409 ts.table = bgp->rib[afi][safi];
9410 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9411
9412 vty_out (vty, "BGP %s RIB statistics%s%s",
9413 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9414
9415 for (i = 0; i < BGP_STATS_MAX; i++)
9416 {
9417 if (!table_stats_strs[i])
9418 continue;
9419
9420 switch (i)
9421 {
9422#if 0
9423 case BGP_STATS_ASPATH_AVGHOPS:
9424 case BGP_STATS_ASPATH_AVGSIZE:
9425 case BGP_STATS_AVGPLEN:
9426 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9427 vty_out (vty, "%12.2f",
9428 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9429 break;
9430#endif
9431 case BGP_STATS_ASPATH_TOTHOPS:
9432 case BGP_STATS_ASPATH_TOTSIZE:
9433 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9434 vty_out (vty, "%12.2f",
9435 ts.counts[i] ?
9436 (float)ts.counts[i] /
9437 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9438 : 0);
9439 break;
9440 case BGP_STATS_TOTPLEN:
9441 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9442 vty_out (vty, "%12.2f",
9443 ts.counts[i] ?
9444 (float)ts.counts[i] /
9445 (float)ts.counts[BGP_STATS_PREFIXES]
9446 : 0);
9447 break;
9448 case BGP_STATS_SPACE:
9449 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9450 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9451 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9452 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009453 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009454 vty_out (vty, "%12.2f%s",
9455 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009456 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009457 VTY_NEWLINE);
9458 vty_out (vty, "%30s: ", "/8 equivalent ");
9459 vty_out (vty, "%12.2f%s",
9460 (float)ts.counts[BGP_STATS_SPACE] /
9461 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9462 VTY_NEWLINE);
9463 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9464 break;
9465 vty_out (vty, "%30s: ", "/24 equivalent ");
9466 vty_out (vty, "%12.2f",
9467 (float)ts.counts[BGP_STATS_SPACE] /
9468 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9469 break;
9470 default:
9471 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9472 vty_out (vty, "%12llu", ts.counts[i]);
9473 }
9474
9475 vty_out (vty, "%s", VTY_NEWLINE);
9476 }
9477 return CMD_SUCCESS;
9478}
9479
9480static int
9481bgp_table_stats_vty (struct vty *vty, const char *name,
9482 const char *afi_str, const char *safi_str)
9483{
9484 struct bgp *bgp;
9485 afi_t afi;
9486 safi_t safi;
9487
9488 if (name)
9489 bgp = bgp_lookup_by_name (name);
9490 else
9491 bgp = bgp_get_default ();
9492
9493 if (!bgp)
9494 {
9495 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9496 return CMD_WARNING;
9497 }
9498 if (strncmp (afi_str, "ipv", 3) == 0)
9499 {
9500 if (strncmp (afi_str, "ipv4", 4) == 0)
9501 afi = AFI_IP;
9502 else if (strncmp (afi_str, "ipv6", 4) == 0)
9503 afi = AFI_IP6;
9504 else
9505 {
9506 vty_out (vty, "%% Invalid address family %s%s",
9507 afi_str, VTY_NEWLINE);
9508 return CMD_WARNING;
9509 }
9510 if (strncmp (safi_str, "m", 1) == 0)
9511 safi = SAFI_MULTICAST;
9512 else if (strncmp (safi_str, "u", 1) == 0)
9513 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009514 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9515 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009516 else
9517 {
9518 vty_out (vty, "%% Invalid subsequent address family %s%s",
9519 safi_str, VTY_NEWLINE);
9520 return CMD_WARNING;
9521 }
9522 }
9523 else
9524 {
9525 vty_out (vty, "%% Invalid address family %s%s",
9526 afi_str, VTY_NEWLINE);
9527 return CMD_WARNING;
9528 }
9529
Paul Jakma2815e612006-09-14 02:56:07 +00009530 return bgp_table_stats (vty, bgp, afi, safi);
9531}
9532
9533DEFUN (show_bgp_statistics,
9534 show_bgp_statistics_cmd,
9535 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9536 SHOW_STR
9537 BGP_STR
9538 "Address family\n"
9539 "Address family\n"
9540 "Address Family modifier\n"
9541 "Address Family modifier\n"
9542 "BGP RIB advertisement statistics\n")
9543{
9544 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9545}
9546
9547ALIAS (show_bgp_statistics,
9548 show_bgp_statistics_vpnv4_cmd,
9549 "show bgp (ipv4) (vpnv4) statistics",
9550 SHOW_STR
9551 BGP_STR
9552 "Address family\n"
9553 "Address Family modifier\n"
9554 "BGP RIB advertisement statistics\n")
9555
9556DEFUN (show_bgp_statistics_view,
9557 show_bgp_statistics_view_cmd,
9558 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9559 SHOW_STR
9560 BGP_STR
9561 "BGP view\n"
9562 "Address family\n"
9563 "Address family\n"
9564 "Address Family modifier\n"
9565 "Address Family modifier\n"
9566 "BGP RIB advertisement statistics\n")
9567{
9568 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9569}
9570
9571ALIAS (show_bgp_statistics_view,
9572 show_bgp_statistics_view_vpnv4_cmd,
9573 "show bgp view WORD (ipv4) (vpnv4) statistics",
9574 SHOW_STR
9575 BGP_STR
9576 "BGP view\n"
9577 "Address family\n"
9578 "Address Family modifier\n"
9579 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009580
Paul Jakmaff7924f2006-09-04 01:10:36 +00009581enum bgp_pcounts
9582{
9583 PCOUNT_ADJ_IN = 0,
9584 PCOUNT_DAMPED,
9585 PCOUNT_REMOVED,
9586 PCOUNT_HISTORY,
9587 PCOUNT_STALE,
9588 PCOUNT_VALID,
9589 PCOUNT_ALL,
9590 PCOUNT_COUNTED,
9591 PCOUNT_PFCNT, /* the figure we display to users */
9592 PCOUNT_MAX,
9593};
9594
9595static const char *pcount_strs[] =
9596{
9597 [PCOUNT_ADJ_IN] = "Adj-in",
9598 [PCOUNT_DAMPED] = "Damped",
9599 [PCOUNT_REMOVED] = "Removed",
9600 [PCOUNT_HISTORY] = "History",
9601 [PCOUNT_STALE] = "Stale",
9602 [PCOUNT_VALID] = "Valid",
9603 [PCOUNT_ALL] = "All RIB",
9604 [PCOUNT_COUNTED] = "PfxCt counted",
9605 [PCOUNT_PFCNT] = "Useable",
9606 [PCOUNT_MAX] = NULL,
9607};
9608
Paul Jakma2815e612006-09-14 02:56:07 +00009609struct peer_pcounts
9610{
9611 unsigned int count[PCOUNT_MAX];
9612 const struct peer *peer;
9613 const struct bgp_table *table;
9614};
9615
Paul Jakmaff7924f2006-09-04 01:10:36 +00009616static int
Paul Jakma2815e612006-09-14 02:56:07 +00009617bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009618{
9619 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009620 struct peer_pcounts *pc = THREAD_ARG (t);
9621 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009622
Paul Jakma2815e612006-09-14 02:56:07 +00009623 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009624 {
9625 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009626 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009627
9628 for (ain = rn->adj_in; ain; ain = ain->next)
9629 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009630 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009631
Paul Jakmaff7924f2006-09-04 01:10:36 +00009632 for (ri = rn->info; ri; ri = ri->next)
9633 {
9634 char buf[SU_ADDRSTRLEN];
9635
9636 if (ri->peer != peer)
9637 continue;
9638
Paul Jakma2815e612006-09-14 02:56:07 +00009639 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009640
9641 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009642 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009643 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009644 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009645 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009646 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009647 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009648 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009649 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009650 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009651 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009652 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009653
9654 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9655 {
Paul Jakma2815e612006-09-14 02:56:07 +00009656 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009657 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009658 plog_warn (peer->log,
9659 "%s [pcount] %s/%d is counted but flags 0x%x",
9660 peer->host,
9661 inet_ntop(rn->p.family, &rn->p.u.prefix,
9662 buf, SU_ADDRSTRLEN),
9663 rn->p.prefixlen,
9664 ri->flags);
9665 }
9666 else
9667 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009668 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009669 plog_warn (peer->log,
9670 "%s [pcount] %s/%d not counted but flags 0x%x",
9671 peer->host,
9672 inet_ntop(rn->p.family, &rn->p.u.prefix,
9673 buf, SU_ADDRSTRLEN),
9674 rn->p.prefixlen,
9675 ri->flags);
9676 }
9677 }
9678 }
Paul Jakma2815e612006-09-14 02:56:07 +00009679 return 0;
9680}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009681
Paul Jakma2815e612006-09-14 02:56:07 +00009682static int
9683bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9684{
9685 struct peer_pcounts pcounts = { .peer = peer };
9686 unsigned int i;
9687
9688 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9689 || !peer->bgp->rib[afi][safi])
9690 {
9691 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9692 return CMD_WARNING;
9693 }
9694
9695 memset (&pcounts, 0, sizeof(pcounts));
9696 pcounts.peer = peer;
9697 pcounts.table = peer->bgp->rib[afi][safi];
9698
9699 /* in-place call via thread subsystem so as to record execution time
9700 * stats for the thread-walk (i.e. ensure this can't be blamed on
9701 * on just vty_read()).
9702 */
9703 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9704
Paul Jakmaff7924f2006-09-04 01:10:36 +00009705 vty_out (vty, "Prefix counts for %s, %s%s",
9706 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9707 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9708 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9709 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9710
9711 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009712 vty_out (vty, "%20s: %-10d%s",
9713 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009714
Paul Jakma2815e612006-09-14 02:56:07 +00009715 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009716 {
9717 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9718 peer->host, VTY_NEWLINE);
9719 vty_out (vty, "Please report this bug, with the above command output%s",
9720 VTY_NEWLINE);
9721 }
9722
9723 return CMD_SUCCESS;
9724}
9725
9726DEFUN (show_ip_bgp_neighbor_prefix_counts,
9727 show_ip_bgp_neighbor_prefix_counts_cmd,
9728 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9729 SHOW_STR
9730 IP_STR
9731 BGP_STR
9732 "Detailed information on TCP and BGP neighbor connections\n"
9733 "Neighbor to display information about\n"
9734 "Neighbor to display information about\n"
9735 "Display detailed prefix count information\n")
9736{
9737 struct peer *peer;
9738
9739 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9740 if (! peer)
9741 return CMD_WARNING;
9742
9743 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9744}
9745
9746DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9747 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9748 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9749 SHOW_STR
9750 BGP_STR
9751 "Address family\n"
9752 "Detailed information on TCP and BGP neighbor connections\n"
9753 "Neighbor to display information about\n"
9754 "Neighbor to display information about\n"
9755 "Display detailed prefix count information\n")
9756{
9757 struct peer *peer;
9758
9759 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9760 if (! peer)
9761 return CMD_WARNING;
9762
9763 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9764}
9765
9766DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9767 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9768 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9769 SHOW_STR
9770 IP_STR
9771 BGP_STR
9772 "Address family\n"
9773 "Address Family modifier\n"
9774 "Address Family modifier\n"
9775 "Detailed information on TCP and BGP neighbor connections\n"
9776 "Neighbor to display information about\n"
9777 "Neighbor to display information about\n"
9778 "Display detailed prefix count information\n")
9779{
9780 struct peer *peer;
9781
9782 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9783 if (! peer)
9784 return CMD_WARNING;
9785
9786 if (strncmp (argv[0], "m", 1) == 0)
9787 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9788
9789 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9790}
9791
9792DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9793 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9794 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9795 SHOW_STR
9796 IP_STR
9797 BGP_STR
9798 "Address family\n"
9799 "Address Family modifier\n"
9800 "Address Family modifier\n"
9801 "Detailed information on TCP and BGP neighbor connections\n"
9802 "Neighbor to display information about\n"
9803 "Neighbor to display information about\n"
9804 "Display detailed prefix count information\n")
9805{
9806 struct peer *peer;
9807
9808 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9809 if (! peer)
9810 return CMD_WARNING;
9811
9812 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9813}
9814
9815
paul94f2b392005-06-28 12:44:16 +00009816static void
paul718e3742002-12-13 20:15:29 +00009817show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9818 int in)
9819{
9820 struct bgp_table *table;
9821 struct bgp_adj_in *ain;
9822 struct bgp_adj_out *adj;
9823 unsigned long output_count;
9824 struct bgp_node *rn;
9825 int header1 = 1;
9826 struct bgp *bgp;
9827 int header2 = 1;
9828
paulbb46e942003-10-24 19:02:03 +00009829 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009830
9831 if (! bgp)
9832 return;
9833
9834 table = bgp->rib[afi][safi];
9835
9836 output_count = 0;
9837
9838 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9839 PEER_STATUS_DEFAULT_ORIGINATE))
9840 {
9841 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 +00009842 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9843 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009844
9845 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9846 VTY_NEWLINE, VTY_NEWLINE);
9847 header1 = 0;
9848 }
9849
9850 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9851 if (in)
9852 {
9853 for (ain = rn->adj_in; ain; ain = ain->next)
9854 if (ain->peer == peer)
9855 {
9856 if (header1)
9857 {
9858 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 +00009859 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9860 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009861 header1 = 0;
9862 }
9863 if (header2)
9864 {
9865 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9866 header2 = 0;
9867 }
9868 if (ain->attr)
9869 {
9870 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9871 output_count++;
9872 }
9873 }
9874 }
9875 else
9876 {
9877 for (adj = rn->adj_out; adj; adj = adj->next)
9878 if (adj->peer == peer)
9879 {
9880 if (header1)
9881 {
9882 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 +00009883 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9884 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009885 header1 = 0;
9886 }
9887 if (header2)
9888 {
9889 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9890 header2 = 0;
9891 }
9892 if (adj->attr)
9893 {
9894 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9895 output_count++;
9896 }
9897 }
9898 }
9899
9900 if (output_count != 0)
9901 vty_out (vty, "%sTotal number of prefixes %ld%s",
9902 VTY_NEWLINE, output_count, VTY_NEWLINE);
9903}
9904
paul94f2b392005-06-28 12:44:16 +00009905static int
paulbb46e942003-10-24 19:02:03 +00009906peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9907{
paul718e3742002-12-13 20:15:29 +00009908 if (! peer || ! peer->afc[afi][safi])
9909 {
9910 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9911 return CMD_WARNING;
9912 }
9913
9914 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9915 {
9916 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9917 VTY_NEWLINE);
9918 return CMD_WARNING;
9919 }
9920
9921 show_adj_route (vty, peer, afi, safi, in);
9922
9923 return CMD_SUCCESS;
9924}
9925
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009926DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9927 show_ip_bgp_view_neighbor_advertised_route_cmd,
9928 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9929 SHOW_STR
9930 IP_STR
9931 BGP_STR
9932 "BGP view\n"
9933 "View name\n"
9934 "Detailed information on TCP and BGP neighbor connections\n"
9935 "Neighbor to display information about\n"
9936 "Neighbor to display information about\n"
9937 "Display the routes advertised to a BGP neighbor\n")
9938{
9939 struct peer *peer;
9940
9941 if (argc == 2)
9942 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9943 else
9944 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9945
9946 if (! peer)
9947 return CMD_WARNING;
9948
9949 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9950}
9951
9952ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009953 show_ip_bgp_neighbor_advertised_route_cmd,
9954 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9955 SHOW_STR
9956 IP_STR
9957 BGP_STR
9958 "Detailed information on TCP and BGP neighbor connections\n"
9959 "Neighbor to display information about\n"
9960 "Neighbor to display information about\n"
9961 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009962
9963DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9964 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9965 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9966 SHOW_STR
9967 IP_STR
9968 BGP_STR
9969 "Address family\n"
9970 "Address Family modifier\n"
9971 "Address Family modifier\n"
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")
9976{
paulbb46e942003-10-24 19:02:03 +00009977 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009978
paulbb46e942003-10-24 19:02:03 +00009979 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9980 if (! peer)
9981 return CMD_WARNING;
9982
9983 if (strncmp (argv[0], "m", 1) == 0)
9984 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9985
9986 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009987}
9988
9989#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009990DEFUN (show_bgp_view_neighbor_advertised_route,
9991 show_bgp_view_neighbor_advertised_route_cmd,
9992 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9993 SHOW_STR
9994 BGP_STR
9995 "BGP view\n"
9996 "View name\n"
9997 "Detailed information on TCP and BGP neighbor connections\n"
9998 "Neighbor to display information about\n"
9999 "Neighbor to display information about\n"
10000 "Display the routes advertised to a BGP neighbor\n")
10001{
10002 struct peer *peer;
10003
10004 if (argc == 2)
10005 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10006 else
10007 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10008
10009 if (! peer)
10010 return CMD_WARNING;
10011
10012 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10013}
10014
10015ALIAS (show_bgp_view_neighbor_advertised_route,
10016 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10017 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10018 SHOW_STR
10019 BGP_STR
10020 "BGP view\n"
10021 "View name\n"
10022 "Address family\n"
10023 "Detailed information on TCP and BGP neighbor connections\n"
10024 "Neighbor to display information about\n"
10025 "Neighbor to display information about\n"
10026 "Display the routes advertised to a BGP neighbor\n")
10027
10028DEFUN (show_bgp_view_neighbor_received_routes,
10029 show_bgp_view_neighbor_received_routes_cmd,
10030 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10031 SHOW_STR
10032 BGP_STR
10033 "BGP view\n"
10034 "View name\n"
10035 "Detailed information on TCP and BGP neighbor connections\n"
10036 "Neighbor to display information about\n"
10037 "Neighbor to display information about\n"
10038 "Display the received routes from neighbor\n")
10039{
10040 struct peer *peer;
10041
10042 if (argc == 2)
10043 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10044 else
10045 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10046
10047 if (! peer)
10048 return CMD_WARNING;
10049
10050 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10051}
10052
10053ALIAS (show_bgp_view_neighbor_received_routes,
10054 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10055 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10056 SHOW_STR
10057 BGP_STR
10058 "BGP view\n"
10059 "View name\n"
10060 "Address family\n"
10061 "Detailed information on TCP and BGP neighbor connections\n"
10062 "Neighbor to display information about\n"
10063 "Neighbor to display information about\n"
10064 "Display the received routes from neighbor\n")
10065
10066ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010067 show_bgp_neighbor_advertised_route_cmd,
10068 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10069 SHOW_STR
10070 BGP_STR
10071 "Detailed information on TCP and BGP neighbor connections\n"
10072 "Neighbor to display information about\n"
10073 "Neighbor to display information about\n"
10074 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010075
10076ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010077 show_bgp_ipv6_neighbor_advertised_route_cmd,
10078 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10079 SHOW_STR
10080 BGP_STR
10081 "Address family\n"
10082 "Detailed information on TCP and BGP neighbor connections\n"
10083 "Neighbor to display information about\n"
10084 "Neighbor to display information about\n"
10085 "Display the routes advertised to a BGP neighbor\n")
10086
10087/* old command */
paulbb46e942003-10-24 19:02:03 +000010088ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010089 ipv6_bgp_neighbor_advertised_route_cmd,
10090 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10091 SHOW_STR
10092 IPV6_STR
10093 BGP_STR
10094 "Detailed information on TCP and BGP neighbor connections\n"
10095 "Neighbor to display information about\n"
10096 "Neighbor to display information about\n"
10097 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010098
paul718e3742002-12-13 20:15:29 +000010099/* old command */
10100DEFUN (ipv6_mbgp_neighbor_advertised_route,
10101 ipv6_mbgp_neighbor_advertised_route_cmd,
10102 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10103 SHOW_STR
10104 IPV6_STR
10105 MBGP_STR
10106 "Detailed information on TCP and BGP neighbor connections\n"
10107 "Neighbor to display information about\n"
10108 "Neighbor to display information about\n"
10109 "Display the routes advertised to a BGP neighbor\n")
10110{
paulbb46e942003-10-24 19:02:03 +000010111 struct peer *peer;
10112
10113 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10114 if (! peer)
10115 return CMD_WARNING;
10116
10117 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010118}
10119#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010120
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010121DEFUN (show_ip_bgp_view_neighbor_received_routes,
10122 show_ip_bgp_view_neighbor_received_routes_cmd,
10123 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10124 SHOW_STR
10125 IP_STR
10126 BGP_STR
10127 "BGP view\n"
10128 "View name\n"
10129 "Detailed information on TCP and BGP neighbor connections\n"
10130 "Neighbor to display information about\n"
10131 "Neighbor to display information about\n"
10132 "Display the received routes from neighbor\n")
10133{
10134 struct peer *peer;
10135
10136 if (argc == 2)
10137 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10138 else
10139 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10140
10141 if (! peer)
10142 return CMD_WARNING;
10143
10144 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10145}
10146
10147ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010148 show_ip_bgp_neighbor_received_routes_cmd,
10149 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10150 SHOW_STR
10151 IP_STR
10152 BGP_STR
10153 "Detailed information on TCP and BGP neighbor connections\n"
10154 "Neighbor to display information about\n"
10155 "Neighbor to display information about\n"
10156 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010157
10158DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10159 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10160 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10161 SHOW_STR
10162 IP_STR
10163 BGP_STR
10164 "Address family\n"
10165 "Address Family modifier\n"
10166 "Address Family modifier\n"
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")
10171{
paulbb46e942003-10-24 19:02:03 +000010172 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010173
paulbb46e942003-10-24 19:02:03 +000010174 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10175 if (! peer)
10176 return CMD_WARNING;
10177
10178 if (strncmp (argv[0], "m", 1) == 0)
10179 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10180
10181 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010182}
10183
Michael Lambert95cbbd22010-07-23 14:43:04 -040010184DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10185 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010186 "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 -040010187 SHOW_STR
10188 BGP_STR
10189 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010190 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010191 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010192 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010193 "Address family modifier\n"
10194 "Address family modifier\n"
10195 "Detailed information on TCP and BGP neighbor connections\n"
10196 "Neighbor to display information about\n"
10197 "Neighbor to display information about\n"
10198 "Display the advertised routes to neighbor\n"
10199 "Display the received routes from neighbor\n")
10200{
10201 int afi;
10202 int safi;
10203 int in;
10204 struct peer *peer;
10205
David Lamparter94bad672015-03-03 08:52:22 +010010206 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010207
10208 if (! peer)
10209 return CMD_WARNING;
10210
Michael Lambert95cbbd22010-07-23 14:43:04 -040010211 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10212 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10213 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010214
10215 return peer_adj_routes (vty, peer, afi, safi, in);
10216}
10217
paul718e3742002-12-13 20:15:29 +000010218DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10219 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10220 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10221 SHOW_STR
10222 IP_STR
10223 BGP_STR
10224 "Detailed information on TCP and BGP neighbor connections\n"
10225 "Neighbor to display information about\n"
10226 "Neighbor to display information about\n"
10227 "Display information received from a BGP neighbor\n"
10228 "Display the prefixlist filter\n")
10229{
10230 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010231 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010232 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010233 int count, ret;
paul718e3742002-12-13 20:15:29 +000010234
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010235 ret = str2sockunion (argv[0], &su);
10236 if (ret < 0)
10237 {
10238 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10239 return CMD_WARNING;
10240 }
paul718e3742002-12-13 20:15:29 +000010241
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010242 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010243 if (! peer)
10244 return CMD_WARNING;
10245
10246 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10247 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10248 if (count)
10249 {
10250 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10251 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10252 }
10253
10254 return CMD_SUCCESS;
10255}
10256
10257DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10258 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10259 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10260 SHOW_STR
10261 IP_STR
10262 BGP_STR
10263 "Address family\n"
10264 "Address Family modifier\n"
10265 "Address Family modifier\n"
10266 "Detailed information on TCP and BGP neighbor connections\n"
10267 "Neighbor to display information about\n"
10268 "Neighbor to display information about\n"
10269 "Display information received from a BGP neighbor\n"
10270 "Display the prefixlist filter\n")
10271{
10272 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010273 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010274 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010275 int count, ret;
paul718e3742002-12-13 20:15:29 +000010276
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010277 ret = str2sockunion (argv[1], &su);
10278 if (ret < 0)
10279 {
10280 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10281 return CMD_WARNING;
10282 }
paul718e3742002-12-13 20:15:29 +000010283
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010284 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010285 if (! peer)
10286 return CMD_WARNING;
10287
10288 if (strncmp (argv[0], "m", 1) == 0)
10289 {
10290 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10291 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10292 if (count)
10293 {
10294 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10295 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10296 }
10297 }
10298 else
10299 {
10300 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10301 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10302 if (count)
10303 {
10304 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10305 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10306 }
10307 }
10308
10309 return CMD_SUCCESS;
10310}
10311
10312
10313#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010314ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010315 show_bgp_neighbor_received_routes_cmd,
10316 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10317 SHOW_STR
10318 BGP_STR
10319 "Detailed information on TCP and BGP neighbor connections\n"
10320 "Neighbor to display information about\n"
10321 "Neighbor to display information about\n"
10322 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010323
paulbb46e942003-10-24 19:02:03 +000010324ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010325 show_bgp_ipv6_neighbor_received_routes_cmd,
10326 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10327 SHOW_STR
10328 BGP_STR
10329 "Address family\n"
10330 "Detailed information on TCP and BGP neighbor connections\n"
10331 "Neighbor to display information about\n"
10332 "Neighbor to display information about\n"
10333 "Display the received routes from neighbor\n")
10334
10335DEFUN (show_bgp_neighbor_received_prefix_filter,
10336 show_bgp_neighbor_received_prefix_filter_cmd,
10337 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10338 SHOW_STR
10339 BGP_STR
10340 "Detailed information on TCP and BGP neighbor connections\n"
10341 "Neighbor to display information about\n"
10342 "Neighbor to display information about\n"
10343 "Display information received from a BGP neighbor\n"
10344 "Display the prefixlist filter\n")
10345{
10346 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010347 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010348 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010349 int count, ret;
paul718e3742002-12-13 20:15:29 +000010350
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010351 ret = str2sockunion (argv[0], &su);
10352 if (ret < 0)
10353 {
10354 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10355 return CMD_WARNING;
10356 }
paul718e3742002-12-13 20:15:29 +000010357
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010358 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010359 if (! peer)
10360 return CMD_WARNING;
10361
10362 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10363 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10364 if (count)
10365 {
10366 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10367 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10368 }
10369
10370 return CMD_SUCCESS;
10371}
10372
10373ALIAS (show_bgp_neighbor_received_prefix_filter,
10374 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10375 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10376 SHOW_STR
10377 BGP_STR
10378 "Address family\n"
10379 "Detailed information on TCP and BGP neighbor connections\n"
10380 "Neighbor to display information about\n"
10381 "Neighbor to display information about\n"
10382 "Display information received from a BGP neighbor\n"
10383 "Display the prefixlist filter\n")
10384
10385/* old command */
paulbb46e942003-10-24 19:02:03 +000010386ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010387 ipv6_bgp_neighbor_received_routes_cmd,
10388 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10389 SHOW_STR
10390 IPV6_STR
10391 BGP_STR
10392 "Detailed information on TCP and BGP neighbor connections\n"
10393 "Neighbor to display information about\n"
10394 "Neighbor to display information about\n"
10395 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010396
10397/* old command */
10398DEFUN (ipv6_mbgp_neighbor_received_routes,
10399 ipv6_mbgp_neighbor_received_routes_cmd,
10400 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10401 SHOW_STR
10402 IPV6_STR
10403 MBGP_STR
10404 "Detailed information on TCP and BGP neighbor connections\n"
10405 "Neighbor to display information about\n"
10406 "Neighbor to display information about\n"
10407 "Display the received routes from neighbor\n")
10408{
paulbb46e942003-10-24 19:02:03 +000010409 struct peer *peer;
10410
10411 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10412 if (! peer)
10413 return CMD_WARNING;
10414
10415 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010416}
paulbb46e942003-10-24 19:02:03 +000010417
10418DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10419 show_bgp_view_neighbor_received_prefix_filter_cmd,
10420 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10421 SHOW_STR
10422 BGP_STR
10423 "BGP view\n"
10424 "View name\n"
10425 "Detailed information on TCP and BGP neighbor connections\n"
10426 "Neighbor to display information about\n"
10427 "Neighbor to display information about\n"
10428 "Display information received from a BGP neighbor\n"
10429 "Display the prefixlist filter\n")
10430{
10431 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010432 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010433 struct peer *peer;
10434 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010435 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010436
10437 /* BGP structure lookup. */
10438 bgp = bgp_lookup_by_name (argv[0]);
10439 if (bgp == NULL)
10440 {
10441 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10442 return CMD_WARNING;
10443 }
10444
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010445 ret = str2sockunion (argv[1], &su);
10446 if (ret < 0)
10447 {
10448 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10449 return CMD_WARNING;
10450 }
paulbb46e942003-10-24 19:02:03 +000010451
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010452 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010453 if (! peer)
10454 return CMD_WARNING;
10455
10456 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10457 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10458 if (count)
10459 {
10460 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10461 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10462 }
10463
10464 return CMD_SUCCESS;
10465}
10466
10467ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10468 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10469 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10470 SHOW_STR
10471 BGP_STR
10472 "BGP view\n"
10473 "View name\n"
10474 "Address family\n"
10475 "Detailed information on TCP and BGP neighbor connections\n"
10476 "Neighbor to display information about\n"
10477 "Neighbor to display information about\n"
10478 "Display information received from a BGP neighbor\n"
10479 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010480#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010481
paul94f2b392005-06-28 12:44:16 +000010482static int
paulbb46e942003-10-24 19:02:03 +000010483bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010484 safi_t safi, enum bgp_show_type type)
10485{
paul718e3742002-12-13 20:15:29 +000010486 if (! peer || ! peer->afc[afi][safi])
10487 {
10488 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010489 return CMD_WARNING;
10490 }
10491
ajs5a646652004-11-05 01:25:55 +000010492 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010493}
10494
10495DEFUN (show_ip_bgp_neighbor_routes,
10496 show_ip_bgp_neighbor_routes_cmd,
10497 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10498 SHOW_STR
10499 IP_STR
10500 BGP_STR
10501 "Detailed information on TCP and BGP neighbor connections\n"
10502 "Neighbor to display information about\n"
10503 "Neighbor to display information about\n"
10504 "Display routes learned from neighbor\n")
10505{
paulbb46e942003-10-24 19:02:03 +000010506 struct peer *peer;
10507
10508 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10509 if (! peer)
10510 return CMD_WARNING;
10511
10512 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010513 bgp_show_type_neighbor);
10514}
10515
10516DEFUN (show_ip_bgp_neighbor_flap,
10517 show_ip_bgp_neighbor_flap_cmd,
10518 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10519 SHOW_STR
10520 IP_STR
10521 BGP_STR
10522 "Detailed information on TCP and BGP neighbor connections\n"
10523 "Neighbor to display information about\n"
10524 "Neighbor to display information about\n"
10525 "Display flap statistics of the routes learned from neighbor\n")
10526{
paulbb46e942003-10-24 19:02:03 +000010527 struct peer *peer;
10528
10529 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10530 if (! peer)
10531 return CMD_WARNING;
10532
10533 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010534 bgp_show_type_flap_neighbor);
10535}
10536
10537DEFUN (show_ip_bgp_neighbor_damp,
10538 show_ip_bgp_neighbor_damp_cmd,
10539 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10540 SHOW_STR
10541 IP_STR
10542 BGP_STR
10543 "Detailed information on TCP and BGP neighbor connections\n"
10544 "Neighbor to display information about\n"
10545 "Neighbor to display information about\n"
10546 "Display the dampened routes received from neighbor\n")
10547{
paulbb46e942003-10-24 19:02:03 +000010548 struct peer *peer;
10549
10550 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10551 if (! peer)
10552 return CMD_WARNING;
10553
10554 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010555 bgp_show_type_damp_neighbor);
10556}
10557
10558DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10559 show_ip_bgp_ipv4_neighbor_routes_cmd,
10560 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10561 SHOW_STR
10562 IP_STR
10563 BGP_STR
10564 "Address family\n"
10565 "Address Family modifier\n"
10566 "Address Family modifier\n"
10567 "Detailed information on TCP and BGP neighbor connections\n"
10568 "Neighbor to display information about\n"
10569 "Neighbor to display information about\n"
10570 "Display routes learned from neighbor\n")
10571{
paulbb46e942003-10-24 19:02:03 +000010572 struct peer *peer;
10573
10574 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10575 if (! peer)
10576 return CMD_WARNING;
10577
paul718e3742002-12-13 20:15:29 +000010578 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010579 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010580 bgp_show_type_neighbor);
10581
paulbb46e942003-10-24 19:02:03 +000010582 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010583 bgp_show_type_neighbor);
10584}
paulbb46e942003-10-24 19:02:03 +000010585
paulfee0f4c2004-09-13 05:12:46 +000010586DEFUN (show_ip_bgp_view_rsclient,
10587 show_ip_bgp_view_rsclient_cmd,
10588 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10589 SHOW_STR
10590 IP_STR
10591 BGP_STR
10592 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010593 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010594 "Information about Route Server Client\n"
10595 NEIGHBOR_ADDR_STR)
10596{
10597 struct bgp_table *table;
10598 struct peer *peer;
10599
10600 if (argc == 2)
10601 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10602 else
10603 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10604
10605 if (! peer)
10606 return CMD_WARNING;
10607
10608 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10609 {
10610 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10611 VTY_NEWLINE);
10612 return CMD_WARNING;
10613 }
10614
10615 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10616 PEER_FLAG_RSERVER_CLIENT))
10617 {
10618 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10619 VTY_NEWLINE);
10620 return CMD_WARNING;
10621 }
10622
10623 table = peer->rib[AFI_IP][SAFI_UNICAST];
10624
ajs5a646652004-11-05 01:25:55 +000010625 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010626}
10627
10628ALIAS (show_ip_bgp_view_rsclient,
10629 show_ip_bgp_rsclient_cmd,
10630 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10631 SHOW_STR
10632 IP_STR
10633 BGP_STR
10634 "Information about Route Server Client\n"
10635 NEIGHBOR_ADDR_STR)
10636
Michael Lambert95cbbd22010-07-23 14:43:04 -040010637DEFUN (show_bgp_view_ipv4_safi_rsclient,
10638 show_bgp_view_ipv4_safi_rsclient_cmd,
10639 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10640 SHOW_STR
10641 BGP_STR
10642 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010643 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010644 "Address family\n"
10645 "Address Family modifier\n"
10646 "Address Family modifier\n"
10647 "Information about Route Server Client\n"
10648 NEIGHBOR_ADDR_STR)
10649{
10650 struct bgp_table *table;
10651 struct peer *peer;
10652 safi_t safi;
10653
10654 if (argc == 3) {
10655 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10656 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10657 } else {
10658 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10659 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10660 }
10661
10662 if (! peer)
10663 return CMD_WARNING;
10664
10665 if (! peer->afc[AFI_IP][safi])
10666 {
10667 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10668 VTY_NEWLINE);
10669 return CMD_WARNING;
10670 }
10671
10672 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10673 PEER_FLAG_RSERVER_CLIENT))
10674 {
10675 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10676 VTY_NEWLINE);
10677 return CMD_WARNING;
10678 }
10679
10680 table = peer->rib[AFI_IP][safi];
10681
10682 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10683}
10684
10685ALIAS (show_bgp_view_ipv4_safi_rsclient,
10686 show_bgp_ipv4_safi_rsclient_cmd,
10687 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10688 SHOW_STR
10689 BGP_STR
10690 "Address family\n"
10691 "Address Family modifier\n"
10692 "Address Family modifier\n"
10693 "Information about Route Server Client\n"
10694 NEIGHBOR_ADDR_STR)
10695
paulfee0f4c2004-09-13 05:12:46 +000010696DEFUN (show_ip_bgp_view_rsclient_route,
10697 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010698 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010699 SHOW_STR
10700 IP_STR
10701 BGP_STR
10702 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010703 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010704 "Information about Route Server Client\n"
10705 NEIGHBOR_ADDR_STR
10706 "Network in the BGP routing table to display\n")
10707{
10708 struct bgp *bgp;
10709 struct peer *peer;
10710
10711 /* BGP structure lookup. */
10712 if (argc == 3)
10713 {
10714 bgp = bgp_lookup_by_name (argv[0]);
10715 if (bgp == NULL)
10716 {
10717 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10718 return CMD_WARNING;
10719 }
10720 }
10721 else
10722 {
10723 bgp = bgp_get_default ();
10724 if (bgp == NULL)
10725 {
10726 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10727 return CMD_WARNING;
10728 }
10729 }
10730
10731 if (argc == 3)
10732 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10733 else
10734 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10735
10736 if (! peer)
10737 return CMD_WARNING;
10738
10739 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10740 {
10741 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10742 VTY_NEWLINE);
10743 return CMD_WARNING;
10744}
10745
10746 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10747 PEER_FLAG_RSERVER_CLIENT))
10748 {
10749 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10750 VTY_NEWLINE);
10751 return CMD_WARNING;
10752 }
10753
10754 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10755 (argc == 3) ? argv[2] : argv[1],
10756 AFI_IP, SAFI_UNICAST, NULL, 0);
10757}
10758
10759ALIAS (show_ip_bgp_view_rsclient_route,
10760 show_ip_bgp_rsclient_route_cmd,
10761 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10762 SHOW_STR
10763 IP_STR
10764 BGP_STR
10765 "Information about Route Server Client\n"
10766 NEIGHBOR_ADDR_STR
10767 "Network in the BGP routing table to display\n")
10768
Michael Lambert95cbbd22010-07-23 14:43:04 -040010769DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10770 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10771 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10772 SHOW_STR
10773 BGP_STR
10774 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010775 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010776 "Address family\n"
10777 "Address Family modifier\n"
10778 "Address Family modifier\n"
10779 "Information about Route Server Client\n"
10780 NEIGHBOR_ADDR_STR
10781 "Network in the BGP routing table to display\n")
10782{
10783 struct bgp *bgp;
10784 struct peer *peer;
10785 safi_t safi;
10786
10787 /* BGP structure lookup. */
10788 if (argc == 4)
10789 {
10790 bgp = bgp_lookup_by_name (argv[0]);
10791 if (bgp == NULL)
10792 {
10793 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10794 return CMD_WARNING;
10795 }
10796 }
10797 else
10798 {
10799 bgp = bgp_get_default ();
10800 if (bgp == NULL)
10801 {
10802 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10803 return CMD_WARNING;
10804 }
10805 }
10806
10807 if (argc == 4) {
10808 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10809 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10810 } else {
10811 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10812 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10813 }
10814
10815 if (! peer)
10816 return CMD_WARNING;
10817
10818 if (! peer->afc[AFI_IP][safi])
10819 {
10820 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10821 VTY_NEWLINE);
10822 return CMD_WARNING;
10823}
10824
10825 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10826 PEER_FLAG_RSERVER_CLIENT))
10827 {
10828 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10829 VTY_NEWLINE);
10830 return CMD_WARNING;
10831 }
10832
10833 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10834 (argc == 4) ? argv[3] : argv[2],
10835 AFI_IP, safi, NULL, 0);
10836}
10837
10838ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10839 show_bgp_ipv4_safi_rsclient_route_cmd,
10840 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10841 SHOW_STR
10842 BGP_STR
10843 "Address family\n"
10844 "Address Family modifier\n"
10845 "Address Family modifier\n"
10846 "Information about Route Server Client\n"
10847 NEIGHBOR_ADDR_STR
10848 "Network in the BGP routing table to display\n")
10849
paulfee0f4c2004-09-13 05:12:46 +000010850DEFUN (show_ip_bgp_view_rsclient_prefix,
10851 show_ip_bgp_view_rsclient_prefix_cmd,
10852 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10853 SHOW_STR
10854 IP_STR
10855 BGP_STR
10856 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010857 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010858 "Information about Route Server Client\n"
10859 NEIGHBOR_ADDR_STR
10860 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10861{
10862 struct bgp *bgp;
10863 struct peer *peer;
10864
10865 /* BGP structure lookup. */
10866 if (argc == 3)
10867 {
10868 bgp = bgp_lookup_by_name (argv[0]);
10869 if (bgp == NULL)
10870 {
10871 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10872 return CMD_WARNING;
10873 }
10874 }
10875 else
10876 {
10877 bgp = bgp_get_default ();
10878 if (bgp == NULL)
10879 {
10880 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10881 return CMD_WARNING;
10882 }
10883 }
10884
10885 if (argc == 3)
10886 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10887 else
10888 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10889
10890 if (! peer)
10891 return CMD_WARNING;
10892
10893 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10894 {
10895 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10896 VTY_NEWLINE);
10897 return CMD_WARNING;
10898}
10899
10900 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10901 PEER_FLAG_RSERVER_CLIENT))
10902{
10903 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10904 VTY_NEWLINE);
10905 return CMD_WARNING;
10906 }
10907
10908 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10909 (argc == 3) ? argv[2] : argv[1],
10910 AFI_IP, SAFI_UNICAST, NULL, 1);
10911}
10912
10913ALIAS (show_ip_bgp_view_rsclient_prefix,
10914 show_ip_bgp_rsclient_prefix_cmd,
10915 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10916 SHOW_STR
10917 IP_STR
10918 BGP_STR
10919 "Information about Route Server Client\n"
10920 NEIGHBOR_ADDR_STR
10921 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10922
Michael Lambert95cbbd22010-07-23 14:43:04 -040010923DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10924 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10925 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10926 SHOW_STR
10927 BGP_STR
10928 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010929 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010930 "Address family\n"
10931 "Address Family modifier\n"
10932 "Address Family modifier\n"
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{
10937 struct bgp *bgp;
10938 struct peer *peer;
10939 safi_t safi;
10940
10941 /* BGP structure lookup. */
10942 if (argc == 4)
10943 {
10944 bgp = bgp_lookup_by_name (argv[0]);
10945 if (bgp == NULL)
10946 {
10947 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10948 return CMD_WARNING;
10949 }
10950 }
10951 else
10952 {
10953 bgp = bgp_get_default ();
10954 if (bgp == NULL)
10955 {
10956 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10957 return CMD_WARNING;
10958 }
10959 }
10960
10961 if (argc == 4) {
10962 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10963 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10964 } else {
10965 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10966 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10967 }
10968
10969 if (! peer)
10970 return CMD_WARNING;
10971
10972 if (! peer->afc[AFI_IP][safi])
10973 {
10974 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10975 VTY_NEWLINE);
10976 return CMD_WARNING;
10977}
10978
10979 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10980 PEER_FLAG_RSERVER_CLIENT))
10981{
10982 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10983 VTY_NEWLINE);
10984 return CMD_WARNING;
10985 }
10986
10987 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10988 (argc == 4) ? argv[3] : argv[2],
10989 AFI_IP, safi, NULL, 1);
10990}
10991
10992ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10993 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10994 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10995 SHOW_STR
10996 BGP_STR
10997 "Address family\n"
10998 "Address Family modifier\n"
10999 "Address Family modifier\n"
11000 "Information about Route Server Client\n"
11001 NEIGHBOR_ADDR_STR
11002 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011003
paul718e3742002-12-13 20:15:29 +000011004#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011005DEFUN (show_bgp_view_neighbor_routes,
11006 show_bgp_view_neighbor_routes_cmd,
11007 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11008 SHOW_STR
11009 BGP_STR
11010 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011011 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011012 "Detailed information on TCP and BGP neighbor connections\n"
11013 "Neighbor to display information about\n"
11014 "Neighbor to display information about\n"
11015 "Display routes learned from neighbor\n")
11016{
11017 struct peer *peer;
11018
11019 if (argc == 2)
11020 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11021 else
11022 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11023
11024 if (! peer)
11025 return CMD_WARNING;
11026
11027 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11028 bgp_show_type_neighbor);
11029}
11030
11031ALIAS (show_bgp_view_neighbor_routes,
11032 show_bgp_view_ipv6_neighbor_routes_cmd,
11033 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11034 SHOW_STR
11035 BGP_STR
11036 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011037 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011038 "Address family\n"
11039 "Detailed information on TCP and BGP neighbor connections\n"
11040 "Neighbor to display information about\n"
11041 "Neighbor to display information about\n"
11042 "Display routes learned from neighbor\n")
11043
11044DEFUN (show_bgp_view_neighbor_damp,
11045 show_bgp_view_neighbor_damp_cmd,
11046 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11047 SHOW_STR
11048 BGP_STR
11049 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011050 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011051 "Detailed information on TCP and BGP neighbor connections\n"
11052 "Neighbor to display information about\n"
11053 "Neighbor to display information about\n"
11054 "Display the dampened routes received from neighbor\n")
11055{
11056 struct peer *peer;
11057
11058 if (argc == 2)
11059 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11060 else
11061 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11062
11063 if (! peer)
11064 return CMD_WARNING;
11065
11066 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11067 bgp_show_type_damp_neighbor);
11068}
11069
11070ALIAS (show_bgp_view_neighbor_damp,
11071 show_bgp_view_ipv6_neighbor_damp_cmd,
11072 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11073 SHOW_STR
11074 BGP_STR
11075 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011076 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011077 "Address family\n"
11078 "Detailed information on TCP and BGP neighbor connections\n"
11079 "Neighbor to display information about\n"
11080 "Neighbor to display information about\n"
11081 "Display the dampened routes received from neighbor\n")
11082
11083DEFUN (show_bgp_view_neighbor_flap,
11084 show_bgp_view_neighbor_flap_cmd,
11085 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11086 SHOW_STR
11087 BGP_STR
11088 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011089 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011090 "Detailed information on TCP and BGP neighbor connections\n"
11091 "Neighbor to display information about\n"
11092 "Neighbor to display information about\n"
11093 "Display flap statistics of the routes learned from neighbor\n")
11094{
11095 struct peer *peer;
11096
11097 if (argc == 2)
11098 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11099 else
11100 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11101
11102 if (! peer)
11103 return CMD_WARNING;
11104
11105 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11106 bgp_show_type_flap_neighbor);
11107}
11108
11109ALIAS (show_bgp_view_neighbor_flap,
11110 show_bgp_view_ipv6_neighbor_flap_cmd,
11111 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11112 SHOW_STR
11113 BGP_STR
11114 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011115 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011116 "Address family\n"
11117 "Detailed information on TCP and BGP neighbor connections\n"
11118 "Neighbor to display information about\n"
11119 "Neighbor to display information about\n"
11120 "Display flap statistics of the routes learned from neighbor\n")
11121
11122ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011123 show_bgp_neighbor_routes_cmd,
11124 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11125 SHOW_STR
11126 BGP_STR
11127 "Detailed information on TCP and BGP neighbor connections\n"
11128 "Neighbor to display information about\n"
11129 "Neighbor to display information about\n"
11130 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011131
paulbb46e942003-10-24 19:02:03 +000011132
11133ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011134 show_bgp_ipv6_neighbor_routes_cmd,
11135 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11136 SHOW_STR
11137 BGP_STR
11138 "Address family\n"
11139 "Detailed information on TCP and BGP neighbor connections\n"
11140 "Neighbor to display information about\n"
11141 "Neighbor to display information about\n"
11142 "Display routes learned from neighbor\n")
11143
11144/* old command */
paulbb46e942003-10-24 19:02:03 +000011145ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011146 ipv6_bgp_neighbor_routes_cmd,
11147 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11148 SHOW_STR
11149 IPV6_STR
11150 BGP_STR
11151 "Detailed information on TCP and BGP neighbor connections\n"
11152 "Neighbor to display information about\n"
11153 "Neighbor to display information about\n"
11154 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011155
11156/* old command */
11157DEFUN (ipv6_mbgp_neighbor_routes,
11158 ipv6_mbgp_neighbor_routes_cmd,
11159 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11160 SHOW_STR
11161 IPV6_STR
11162 MBGP_STR
11163 "Detailed information on TCP and BGP neighbor connections\n"
11164 "Neighbor to display information about\n"
11165 "Neighbor to display information about\n"
11166 "Display routes learned from neighbor\n")
11167{
paulbb46e942003-10-24 19:02:03 +000011168 struct peer *peer;
11169
11170 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11171 if (! peer)
11172 return CMD_WARNING;
11173
11174 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011175 bgp_show_type_neighbor);
11176}
paulbb46e942003-10-24 19:02:03 +000011177
11178ALIAS (show_bgp_view_neighbor_flap,
11179 show_bgp_neighbor_flap_cmd,
11180 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11181 SHOW_STR
11182 BGP_STR
11183 "Detailed information on TCP and BGP neighbor connections\n"
11184 "Neighbor to display information about\n"
11185 "Neighbor to display information about\n"
11186 "Display flap statistics of the routes learned from neighbor\n")
11187
11188ALIAS (show_bgp_view_neighbor_flap,
11189 show_bgp_ipv6_neighbor_flap_cmd,
11190 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11191 SHOW_STR
11192 BGP_STR
11193 "Address family\n"
11194 "Detailed information on TCP and BGP neighbor connections\n"
11195 "Neighbor to display information about\n"
11196 "Neighbor to display information about\n"
11197 "Display flap statistics of the routes learned from neighbor\n")
11198
11199ALIAS (show_bgp_view_neighbor_damp,
11200 show_bgp_neighbor_damp_cmd,
11201 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11202 SHOW_STR
11203 BGP_STR
11204 "Detailed information on TCP and BGP neighbor connections\n"
11205 "Neighbor to display information about\n"
11206 "Neighbor to display information about\n"
11207 "Display the dampened routes received from neighbor\n")
11208
11209ALIAS (show_bgp_view_neighbor_damp,
11210 show_bgp_ipv6_neighbor_damp_cmd,
11211 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11212 SHOW_STR
11213 BGP_STR
11214 "Address family\n"
11215 "Detailed information on TCP and BGP neighbor connections\n"
11216 "Neighbor to display information about\n"
11217 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011218 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011219
11220DEFUN (show_bgp_view_rsclient,
11221 show_bgp_view_rsclient_cmd,
11222 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11223 SHOW_STR
11224 BGP_STR
11225 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011226 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011227 "Information about Route Server Client\n"
11228 NEIGHBOR_ADDR_STR)
11229{
11230 struct bgp_table *table;
11231 struct peer *peer;
11232
11233 if (argc == 2)
11234 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11235 else
11236 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11237
11238 if (! peer)
11239 return CMD_WARNING;
11240
11241 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11242 {
11243 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11244 VTY_NEWLINE);
11245 return CMD_WARNING;
11246 }
11247
11248 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11249 PEER_FLAG_RSERVER_CLIENT))
11250 {
11251 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11252 VTY_NEWLINE);
11253 return CMD_WARNING;
11254 }
11255
11256 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11257
ajs5a646652004-11-05 01:25:55 +000011258 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011259}
11260
11261ALIAS (show_bgp_view_rsclient,
11262 show_bgp_rsclient_cmd,
11263 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11264 SHOW_STR
11265 BGP_STR
11266 "Information about Route Server Client\n"
11267 NEIGHBOR_ADDR_STR)
11268
Michael Lambert95cbbd22010-07-23 14:43:04 -040011269DEFUN (show_bgp_view_ipv6_safi_rsclient,
11270 show_bgp_view_ipv6_safi_rsclient_cmd,
11271 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11272 SHOW_STR
11273 BGP_STR
11274 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011275 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011276 "Address family\n"
11277 "Address Family modifier\n"
11278 "Address Family modifier\n"
11279 "Information about Route Server Client\n"
11280 NEIGHBOR_ADDR_STR)
11281{
11282 struct bgp_table *table;
11283 struct peer *peer;
11284 safi_t safi;
11285
11286 if (argc == 3) {
11287 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11288 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11289 } else {
11290 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11291 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11292 }
11293
11294 if (! peer)
11295 return CMD_WARNING;
11296
11297 if (! peer->afc[AFI_IP6][safi])
11298 {
11299 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11300 VTY_NEWLINE);
11301 return CMD_WARNING;
11302 }
11303
11304 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11305 PEER_FLAG_RSERVER_CLIENT))
11306 {
11307 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11308 VTY_NEWLINE);
11309 return CMD_WARNING;
11310 }
11311
11312 table = peer->rib[AFI_IP6][safi];
11313
11314 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11315}
11316
11317ALIAS (show_bgp_view_ipv6_safi_rsclient,
11318 show_bgp_ipv6_safi_rsclient_cmd,
11319 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11320 SHOW_STR
11321 BGP_STR
11322 "Address family\n"
11323 "Address Family modifier\n"
11324 "Address Family modifier\n"
11325 "Information about Route Server Client\n"
11326 NEIGHBOR_ADDR_STR)
11327
paulfee0f4c2004-09-13 05:12:46 +000011328DEFUN (show_bgp_view_rsclient_route,
11329 show_bgp_view_rsclient_route_cmd,
11330 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11331 SHOW_STR
11332 BGP_STR
11333 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011334 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011335 "Information about Route Server Client\n"
11336 NEIGHBOR_ADDR_STR
11337 "Network in the BGP routing table to display\n")
11338{
11339 struct bgp *bgp;
11340 struct peer *peer;
11341
11342 /* BGP structure lookup. */
11343 if (argc == 3)
11344 {
11345 bgp = bgp_lookup_by_name (argv[0]);
11346 if (bgp == NULL)
11347 {
11348 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11349 return CMD_WARNING;
11350 }
11351 }
11352 else
11353 {
11354 bgp = bgp_get_default ();
11355 if (bgp == NULL)
11356 {
11357 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11358 return CMD_WARNING;
11359 }
11360 }
11361
11362 if (argc == 3)
11363 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11364 else
11365 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11366
11367 if (! peer)
11368 return CMD_WARNING;
11369
11370 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11371 {
11372 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11373 VTY_NEWLINE);
11374 return CMD_WARNING;
11375 }
11376
11377 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11378 PEER_FLAG_RSERVER_CLIENT))
11379 {
11380 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11381 VTY_NEWLINE);
11382 return CMD_WARNING;
11383 }
11384
11385 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11386 (argc == 3) ? argv[2] : argv[1],
11387 AFI_IP6, SAFI_UNICAST, NULL, 0);
11388}
11389
11390ALIAS (show_bgp_view_rsclient_route,
11391 show_bgp_rsclient_route_cmd,
11392 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11393 SHOW_STR
11394 BGP_STR
11395 "Information about Route Server Client\n"
11396 NEIGHBOR_ADDR_STR
11397 "Network in the BGP routing table to display\n")
11398
Michael Lambert95cbbd22010-07-23 14:43:04 -040011399DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11400 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11401 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11402 SHOW_STR
11403 BGP_STR
11404 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011405 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011406 "Address family\n"
11407 "Address Family modifier\n"
11408 "Address Family modifier\n"
11409 "Information about Route Server Client\n"
11410 NEIGHBOR_ADDR_STR
11411 "Network in the BGP routing table to display\n")
11412{
11413 struct bgp *bgp;
11414 struct peer *peer;
11415 safi_t safi;
11416
11417 /* BGP structure lookup. */
11418 if (argc == 4)
11419 {
11420 bgp = bgp_lookup_by_name (argv[0]);
11421 if (bgp == NULL)
11422 {
11423 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11424 return CMD_WARNING;
11425 }
11426 }
11427 else
11428 {
11429 bgp = bgp_get_default ();
11430 if (bgp == NULL)
11431 {
11432 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11433 return CMD_WARNING;
11434 }
11435 }
11436
11437 if (argc == 4) {
11438 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11439 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11440 } else {
11441 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11442 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11443 }
11444
11445 if (! peer)
11446 return CMD_WARNING;
11447
11448 if (! peer->afc[AFI_IP6][safi])
11449 {
11450 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11451 VTY_NEWLINE);
11452 return CMD_WARNING;
11453}
11454
11455 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11456 PEER_FLAG_RSERVER_CLIENT))
11457 {
11458 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11459 VTY_NEWLINE);
11460 return CMD_WARNING;
11461 }
11462
11463 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11464 (argc == 4) ? argv[3] : argv[2],
11465 AFI_IP6, safi, NULL, 0);
11466}
11467
11468ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11469 show_bgp_ipv6_safi_rsclient_route_cmd,
11470 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11471 SHOW_STR
11472 BGP_STR
11473 "Address family\n"
11474 "Address Family modifier\n"
11475 "Address Family modifier\n"
11476 "Information about Route Server Client\n"
11477 NEIGHBOR_ADDR_STR
11478 "Network in the BGP routing table to display\n")
11479
paulfee0f4c2004-09-13 05:12:46 +000011480DEFUN (show_bgp_view_rsclient_prefix,
11481 show_bgp_view_rsclient_prefix_cmd,
11482 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11483 SHOW_STR
11484 BGP_STR
11485 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011486 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011487 "Information about Route Server Client\n"
11488 NEIGHBOR_ADDR_STR
11489 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11490{
11491 struct bgp *bgp;
11492 struct peer *peer;
11493
11494 /* BGP structure lookup. */
11495 if (argc == 3)
11496 {
11497 bgp = bgp_lookup_by_name (argv[0]);
11498 if (bgp == NULL)
11499 {
11500 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11501 return CMD_WARNING;
11502 }
11503 }
11504 else
11505 {
11506 bgp = bgp_get_default ();
11507 if (bgp == NULL)
11508 {
11509 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11510 return CMD_WARNING;
11511 }
11512 }
11513
11514 if (argc == 3)
11515 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11516 else
11517 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11518
11519 if (! peer)
11520 return CMD_WARNING;
11521
11522 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11523 {
11524 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11525 VTY_NEWLINE);
11526 return CMD_WARNING;
11527 }
11528
11529 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11530 PEER_FLAG_RSERVER_CLIENT))
11531 {
11532 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11533 VTY_NEWLINE);
11534 return CMD_WARNING;
11535 }
11536
11537 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11538 (argc == 3) ? argv[2] : argv[1],
11539 AFI_IP6, SAFI_UNICAST, NULL, 1);
11540}
11541
11542ALIAS (show_bgp_view_rsclient_prefix,
11543 show_bgp_rsclient_prefix_cmd,
11544 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11545 SHOW_STR
11546 BGP_STR
11547 "Information about Route Server Client\n"
11548 NEIGHBOR_ADDR_STR
11549 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11550
Michael Lambert95cbbd22010-07-23 14:43:04 -040011551DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11552 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11553 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11554 SHOW_STR
11555 BGP_STR
11556 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011557 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011558 "Address family\n"
11559 "Address Family modifier\n"
11560 "Address Family modifier\n"
11561 "Information about Route Server Client\n"
11562 NEIGHBOR_ADDR_STR
11563 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11564{
11565 struct bgp *bgp;
11566 struct peer *peer;
11567 safi_t safi;
11568
11569 /* BGP structure lookup. */
11570 if (argc == 4)
11571 {
11572 bgp = bgp_lookup_by_name (argv[0]);
11573 if (bgp == NULL)
11574 {
11575 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11576 return CMD_WARNING;
11577 }
11578 }
11579 else
11580 {
11581 bgp = bgp_get_default ();
11582 if (bgp == NULL)
11583 {
11584 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11585 return CMD_WARNING;
11586 }
11587 }
11588
11589 if (argc == 4) {
11590 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11591 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11592 } else {
11593 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11594 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11595 }
11596
11597 if (! peer)
11598 return CMD_WARNING;
11599
11600 if (! peer->afc[AFI_IP6][safi])
11601 {
11602 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11603 VTY_NEWLINE);
11604 return CMD_WARNING;
11605}
11606
11607 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11608 PEER_FLAG_RSERVER_CLIENT))
11609{
11610 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11611 VTY_NEWLINE);
11612 return CMD_WARNING;
11613 }
11614
11615 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11616 (argc == 4) ? argv[3] : argv[2],
11617 AFI_IP6, safi, NULL, 1);
11618}
11619
11620ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11621 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11622 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11623 SHOW_STR
11624 BGP_STR
11625 "Address family\n"
11626 "Address Family modifier\n"
11627 "Address Family modifier\n"
11628 "Information about Route Server Client\n"
11629 NEIGHBOR_ADDR_STR
11630 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11631
paul718e3742002-12-13 20:15:29 +000011632#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011633
paul718e3742002-12-13 20:15:29 +000011634struct bgp_table *bgp_distance_table;
11635
11636struct bgp_distance
11637{
11638 /* Distance value for the IP source prefix. */
11639 u_char distance;
11640
11641 /* Name of the access-list to be matched. */
11642 char *access_list;
11643};
11644
paul94f2b392005-06-28 12:44:16 +000011645static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011646bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011647{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011648 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011649}
11650
paul94f2b392005-06-28 12:44:16 +000011651static void
paul718e3742002-12-13 20:15:29 +000011652bgp_distance_free (struct bgp_distance *bdistance)
11653{
11654 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11655}
11656
paul94f2b392005-06-28 12:44:16 +000011657static int
paulfd79ac92004-10-13 05:06:08 +000011658bgp_distance_set (struct vty *vty, const char *distance_str,
11659 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011660{
11661 int ret;
11662 struct prefix_ipv4 p;
11663 u_char distance;
11664 struct bgp_node *rn;
11665 struct bgp_distance *bdistance;
11666
11667 ret = str2prefix_ipv4 (ip_str, &p);
11668 if (ret == 0)
11669 {
11670 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11671 return CMD_WARNING;
11672 }
11673
11674 distance = atoi (distance_str);
11675
11676 /* Get BGP distance node. */
11677 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11678 if (rn->info)
11679 {
11680 bdistance = rn->info;
11681 bgp_unlock_node (rn);
11682 }
11683 else
11684 {
11685 bdistance = bgp_distance_new ();
11686 rn->info = bdistance;
11687 }
11688
11689 /* Set distance value. */
11690 bdistance->distance = distance;
11691
11692 /* Reset access-list configuration. */
11693 if (bdistance->access_list)
11694 {
11695 free (bdistance->access_list);
11696 bdistance->access_list = NULL;
11697 }
11698 if (access_list_str)
11699 bdistance->access_list = strdup (access_list_str);
11700
11701 return CMD_SUCCESS;
11702}
11703
paul94f2b392005-06-28 12:44:16 +000011704static int
paulfd79ac92004-10-13 05:06:08 +000011705bgp_distance_unset (struct vty *vty, const char *distance_str,
11706 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011707{
11708 int ret;
11709 struct prefix_ipv4 p;
11710 u_char distance;
11711 struct bgp_node *rn;
11712 struct bgp_distance *bdistance;
11713
11714 ret = str2prefix_ipv4 (ip_str, &p);
11715 if (ret == 0)
11716 {
11717 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11718 return CMD_WARNING;
11719 }
11720
11721 distance = atoi (distance_str);
11722
11723 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11724 if (! rn)
11725 {
11726 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11727 return CMD_WARNING;
11728 }
11729
11730 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011731
11732 if (bdistance->distance != distance)
11733 {
11734 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11735 return CMD_WARNING;
11736 }
11737
paul718e3742002-12-13 20:15:29 +000011738 if (bdistance->access_list)
11739 free (bdistance->access_list);
11740 bgp_distance_free (bdistance);
11741
11742 rn->info = NULL;
11743 bgp_unlock_node (rn);
11744 bgp_unlock_node (rn);
11745
11746 return CMD_SUCCESS;
11747}
11748
paul718e3742002-12-13 20:15:29 +000011749/* Apply BGP information to distance method. */
11750u_char
11751bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11752{
11753 struct bgp_node *rn;
11754 struct prefix_ipv4 q;
11755 struct peer *peer;
11756 struct bgp_distance *bdistance;
11757 struct access_list *alist;
11758 struct bgp_static *bgp_static;
11759
11760 if (! bgp)
11761 return 0;
11762
11763 if (p->family != AF_INET)
11764 return 0;
11765
11766 peer = rinfo->peer;
11767
11768 if (peer->su.sa.sa_family != AF_INET)
11769 return 0;
11770
11771 memset (&q, 0, sizeof (struct prefix_ipv4));
11772 q.family = AF_INET;
11773 q.prefix = peer->su.sin.sin_addr;
11774 q.prefixlen = IPV4_MAX_BITLEN;
11775
11776 /* Check source address. */
11777 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11778 if (rn)
11779 {
11780 bdistance = rn->info;
11781 bgp_unlock_node (rn);
11782
11783 if (bdistance->access_list)
11784 {
11785 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11786 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11787 return bdistance->distance;
11788 }
11789 else
11790 return bdistance->distance;
11791 }
11792
11793 /* Backdoor check. */
11794 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11795 if (rn)
11796 {
11797 bgp_static = rn->info;
11798 bgp_unlock_node (rn);
11799
11800 if (bgp_static->backdoor)
11801 {
11802 if (bgp->distance_local)
11803 return bgp->distance_local;
11804 else
11805 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11806 }
11807 }
11808
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011809 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011810 {
11811 if (bgp->distance_ebgp)
11812 return bgp->distance_ebgp;
11813 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11814 }
11815 else
11816 {
11817 if (bgp->distance_ibgp)
11818 return bgp->distance_ibgp;
11819 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11820 }
11821}
11822
11823DEFUN (bgp_distance,
11824 bgp_distance_cmd,
11825 "distance bgp <1-255> <1-255> <1-255>",
11826 "Define an administrative distance\n"
11827 "BGP distance\n"
11828 "Distance for routes external to the AS\n"
11829 "Distance for routes internal to the AS\n"
11830 "Distance for local routes\n")
11831{
11832 struct bgp *bgp;
11833
11834 bgp = vty->index;
11835
11836 bgp->distance_ebgp = atoi (argv[0]);
11837 bgp->distance_ibgp = atoi (argv[1]);
11838 bgp->distance_local = atoi (argv[2]);
11839 return CMD_SUCCESS;
11840}
11841
11842DEFUN (no_bgp_distance,
11843 no_bgp_distance_cmd,
11844 "no distance bgp <1-255> <1-255> <1-255>",
11845 NO_STR
11846 "Define an administrative distance\n"
11847 "BGP distance\n"
11848 "Distance for routes external to the AS\n"
11849 "Distance for routes internal to the AS\n"
11850 "Distance for local routes\n")
11851{
11852 struct bgp *bgp;
11853
11854 bgp = vty->index;
11855
11856 bgp->distance_ebgp= 0;
11857 bgp->distance_ibgp = 0;
11858 bgp->distance_local = 0;
11859 return CMD_SUCCESS;
11860}
11861
11862ALIAS (no_bgp_distance,
11863 no_bgp_distance2_cmd,
11864 "no distance bgp",
11865 NO_STR
11866 "Define an administrative distance\n"
11867 "BGP distance\n")
11868
11869DEFUN (bgp_distance_source,
11870 bgp_distance_source_cmd,
11871 "distance <1-255> A.B.C.D/M",
11872 "Define an administrative distance\n"
11873 "Administrative distance\n"
11874 "IP source prefix\n")
11875{
11876 bgp_distance_set (vty, argv[0], argv[1], NULL);
11877 return CMD_SUCCESS;
11878}
11879
11880DEFUN (no_bgp_distance_source,
11881 no_bgp_distance_source_cmd,
11882 "no distance <1-255> A.B.C.D/M",
11883 NO_STR
11884 "Define an administrative distance\n"
11885 "Administrative distance\n"
11886 "IP source prefix\n")
11887{
11888 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11889 return CMD_SUCCESS;
11890}
11891
11892DEFUN (bgp_distance_source_access_list,
11893 bgp_distance_source_access_list_cmd,
11894 "distance <1-255> A.B.C.D/M WORD",
11895 "Define an administrative distance\n"
11896 "Administrative distance\n"
11897 "IP source prefix\n"
11898 "Access list name\n")
11899{
11900 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11901 return CMD_SUCCESS;
11902}
11903
11904DEFUN (no_bgp_distance_source_access_list,
11905 no_bgp_distance_source_access_list_cmd,
11906 "no distance <1-255> A.B.C.D/M WORD",
11907 NO_STR
11908 "Define an administrative distance\n"
11909 "Administrative distance\n"
11910 "IP source prefix\n"
11911 "Access list name\n")
11912{
11913 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11914 return CMD_SUCCESS;
11915}
David Lamparter6b0655a2014-06-04 06:53:35 +020011916
paul718e3742002-12-13 20:15:29 +000011917DEFUN (bgp_damp_set,
11918 bgp_damp_set_cmd,
11919 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11920 "BGP Specific commands\n"
11921 "Enable route-flap dampening\n"
11922 "Half-life time for the penalty\n"
11923 "Value to start reusing a route\n"
11924 "Value to start suppressing a route\n"
11925 "Maximum duration to suppress a stable route\n")
11926{
11927 struct bgp *bgp;
11928 int half = DEFAULT_HALF_LIFE * 60;
11929 int reuse = DEFAULT_REUSE;
11930 int suppress = DEFAULT_SUPPRESS;
11931 int max = 4 * half;
11932
11933 if (argc == 4)
11934 {
11935 half = atoi (argv[0]) * 60;
11936 reuse = atoi (argv[1]);
11937 suppress = atoi (argv[2]);
11938 max = atoi (argv[3]) * 60;
11939 }
11940 else if (argc == 1)
11941 {
11942 half = atoi (argv[0]) * 60;
11943 max = 4 * half;
11944 }
11945
11946 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000011947
11948 if (suppress < reuse)
11949 {
11950 vty_out (vty, "Suppress value cannot be less than reuse value %s",
11951 VTY_NEWLINE);
11952 return 0;
11953 }
11954
paul718e3742002-12-13 20:15:29 +000011955 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11956 half, reuse, suppress, max);
11957}
11958
11959ALIAS (bgp_damp_set,
11960 bgp_damp_set2_cmd,
11961 "bgp dampening <1-45>",
11962 "BGP Specific commands\n"
11963 "Enable route-flap dampening\n"
11964 "Half-life time for the penalty\n")
11965
11966ALIAS (bgp_damp_set,
11967 bgp_damp_set3_cmd,
11968 "bgp dampening",
11969 "BGP Specific commands\n"
11970 "Enable route-flap dampening\n")
11971
11972DEFUN (bgp_damp_unset,
11973 bgp_damp_unset_cmd,
11974 "no bgp dampening",
11975 NO_STR
11976 "BGP Specific commands\n"
11977 "Enable route-flap dampening\n")
11978{
11979 struct bgp *bgp;
11980
11981 bgp = vty->index;
11982 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11983}
11984
11985ALIAS (bgp_damp_unset,
11986 bgp_damp_unset2_cmd,
11987 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11988 NO_STR
11989 "BGP Specific commands\n"
11990 "Enable route-flap dampening\n"
11991 "Half-life time for the penalty\n"
11992 "Value to start reusing a route\n"
11993 "Value to start suppressing a route\n"
11994 "Maximum duration to suppress a stable route\n")
11995
11996DEFUN (show_ip_bgp_dampened_paths,
11997 show_ip_bgp_dampened_paths_cmd,
11998 "show ip bgp dampened-paths",
11999 SHOW_STR
12000 IP_STR
12001 BGP_STR
12002 "Display paths suppressed due to dampening\n")
12003{
ajs5a646652004-11-05 01:25:55 +000012004 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12005 NULL);
paul718e3742002-12-13 20:15:29 +000012006}
12007
12008DEFUN (show_ip_bgp_flap_statistics,
12009 show_ip_bgp_flap_statistics_cmd,
12010 "show ip bgp flap-statistics",
12011 SHOW_STR
12012 IP_STR
12013 BGP_STR
12014 "Display flap statistics of routes\n")
12015{
ajs5a646652004-11-05 01:25:55 +000012016 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12017 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012018}
David Lamparter6b0655a2014-06-04 06:53:35 +020012019
paul718e3742002-12-13 20:15:29 +000012020/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012021static int
paulfd79ac92004-10-13 05:06:08 +000012022bgp_clear_damp_route (struct vty *vty, const char *view_name,
12023 const char *ip_str, afi_t afi, safi_t safi,
12024 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012025{
12026 int ret;
12027 struct prefix match;
12028 struct bgp_node *rn;
12029 struct bgp_node *rm;
12030 struct bgp_info *ri;
12031 struct bgp_info *ri_temp;
12032 struct bgp *bgp;
12033 struct bgp_table *table;
12034
12035 /* BGP structure lookup. */
12036 if (view_name)
12037 {
12038 bgp = bgp_lookup_by_name (view_name);
12039 if (bgp == NULL)
12040 {
12041 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12042 return CMD_WARNING;
12043 }
12044 }
12045 else
12046 {
12047 bgp = bgp_get_default ();
12048 if (bgp == NULL)
12049 {
12050 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12051 return CMD_WARNING;
12052 }
12053 }
12054
12055 /* Check IP address argument. */
12056 ret = str2prefix (ip_str, &match);
12057 if (! ret)
12058 {
12059 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12060 return CMD_WARNING;
12061 }
12062
12063 match.family = afi2family (afi);
12064
12065 if (safi == SAFI_MPLS_VPN)
12066 {
12067 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12068 {
12069 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12070 continue;
12071
12072 if ((table = rn->info) != NULL)
12073 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012074 {
12075 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12076 {
12077 ri = rm->info;
12078 while (ri)
12079 {
12080 if (ri->extra && ri->extra->damp_info)
12081 {
12082 ri_temp = ri->next;
12083 bgp_damp_info_free (ri->extra->damp_info, 1);
12084 ri = ri_temp;
12085 }
12086 else
12087 ri = ri->next;
12088 }
12089 }
12090
12091 bgp_unlock_node (rm);
12092 }
paul718e3742002-12-13 20:15:29 +000012093 }
12094 }
12095 else
12096 {
12097 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012098 {
12099 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12100 {
12101 ri = rn->info;
12102 while (ri)
12103 {
12104 if (ri->extra && ri->extra->damp_info)
12105 {
12106 ri_temp = ri->next;
12107 bgp_damp_info_free (ri->extra->damp_info, 1);
12108 ri = ri_temp;
12109 }
12110 else
12111 ri = ri->next;
12112 }
12113 }
12114
12115 bgp_unlock_node (rn);
12116 }
paul718e3742002-12-13 20:15:29 +000012117 }
12118
12119 return CMD_SUCCESS;
12120}
12121
12122DEFUN (clear_ip_bgp_dampening,
12123 clear_ip_bgp_dampening_cmd,
12124 "clear ip bgp dampening",
12125 CLEAR_STR
12126 IP_STR
12127 BGP_STR
12128 "Clear route flap dampening information\n")
12129{
12130 bgp_damp_info_clean ();
12131 return CMD_SUCCESS;
12132}
12133
12134DEFUN (clear_ip_bgp_dampening_prefix,
12135 clear_ip_bgp_dampening_prefix_cmd,
12136 "clear ip bgp dampening A.B.C.D/M",
12137 CLEAR_STR
12138 IP_STR
12139 BGP_STR
12140 "Clear route flap dampening information\n"
12141 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12142{
12143 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12144 SAFI_UNICAST, NULL, 1);
12145}
12146
12147DEFUN (clear_ip_bgp_dampening_address,
12148 clear_ip_bgp_dampening_address_cmd,
12149 "clear ip bgp dampening A.B.C.D",
12150 CLEAR_STR
12151 IP_STR
12152 BGP_STR
12153 "Clear route flap dampening information\n"
12154 "Network to clear damping information\n")
12155{
12156 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12157 SAFI_UNICAST, NULL, 0);
12158}
12159
12160DEFUN (clear_ip_bgp_dampening_address_mask,
12161 clear_ip_bgp_dampening_address_mask_cmd,
12162 "clear ip bgp dampening A.B.C.D A.B.C.D",
12163 CLEAR_STR
12164 IP_STR
12165 BGP_STR
12166 "Clear route flap dampening information\n"
12167 "Network to clear damping information\n"
12168 "Network mask\n")
12169{
12170 int ret;
12171 char prefix_str[BUFSIZ];
12172
12173 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12174 if (! ret)
12175 {
12176 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12177 return CMD_WARNING;
12178 }
12179
12180 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12181 SAFI_UNICAST, NULL, 0);
12182}
David Lamparter6b0655a2014-06-04 06:53:35 +020012183
paul94f2b392005-06-28 12:44:16 +000012184static int
paul718e3742002-12-13 20:15:29 +000012185bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12186 afi_t afi, safi_t safi, int *write)
12187{
12188 struct bgp_node *prn;
12189 struct bgp_node *rn;
12190 struct bgp_table *table;
12191 struct prefix *p;
12192 struct prefix_rd *prd;
12193 struct bgp_static *bgp_static;
12194 u_int32_t label;
12195 char buf[SU_ADDRSTRLEN];
12196 char rdbuf[RD_ADDRSTRLEN];
12197
12198 /* Network configuration. */
12199 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12200 if ((table = prn->info) != NULL)
12201 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12202 if ((bgp_static = rn->info) != NULL)
12203 {
12204 p = &rn->p;
12205 prd = (struct prefix_rd *) &prn->p;
12206
12207 /* "address-family" display. */
12208 bgp_config_write_family_header (vty, afi, safi, write);
12209
12210 /* "network" configuration display. */
12211 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12212 label = decode_label (bgp_static->tag);
12213
12214 vty_out (vty, " network %s/%d rd %s tag %d",
12215 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12216 p->prefixlen,
12217 rdbuf, label);
12218 vty_out (vty, "%s", VTY_NEWLINE);
12219 }
12220 return 0;
12221}
12222
12223/* Configuration of static route announcement and aggregate
12224 information. */
12225int
12226bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12227 afi_t afi, safi_t safi, int *write)
12228{
12229 struct bgp_node *rn;
12230 struct prefix *p;
12231 struct bgp_static *bgp_static;
12232 struct bgp_aggregate *bgp_aggregate;
12233 char buf[SU_ADDRSTRLEN];
12234
12235 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12236 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12237
12238 /* Network configuration. */
12239 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12240 if ((bgp_static = rn->info) != NULL)
12241 {
12242 p = &rn->p;
12243
12244 /* "address-family" display. */
12245 bgp_config_write_family_header (vty, afi, safi, write);
12246
12247 /* "network" configuration display. */
12248 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12249 {
12250 u_int32_t destination;
12251 struct in_addr netmask;
12252
12253 destination = ntohl (p->u.prefix4.s_addr);
12254 masklen2ip (p->prefixlen, &netmask);
12255 vty_out (vty, " network %s",
12256 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12257
12258 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12259 || (IN_CLASSB (destination) && p->prefixlen == 16)
12260 || (IN_CLASSA (destination) && p->prefixlen == 8)
12261 || p->u.prefix4.s_addr == 0)
12262 {
12263 /* Natural mask is not display. */
12264 }
12265 else
12266 vty_out (vty, " mask %s", inet_ntoa (netmask));
12267 }
12268 else
12269 {
12270 vty_out (vty, " network %s/%d",
12271 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12272 p->prefixlen);
12273 }
12274
12275 if (bgp_static->rmap.name)
12276 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012277 else
12278 {
12279 if (bgp_static->backdoor)
12280 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012281 }
paul718e3742002-12-13 20:15:29 +000012282
12283 vty_out (vty, "%s", VTY_NEWLINE);
12284 }
12285
12286 /* Aggregate-address configuration. */
12287 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12288 if ((bgp_aggregate = rn->info) != NULL)
12289 {
12290 p = &rn->p;
12291
12292 /* "address-family" display. */
12293 bgp_config_write_family_header (vty, afi, safi, write);
12294
12295 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12296 {
12297 struct in_addr netmask;
12298
12299 masklen2ip (p->prefixlen, &netmask);
12300 vty_out (vty, " aggregate-address %s %s",
12301 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12302 inet_ntoa (netmask));
12303 }
12304 else
12305 {
12306 vty_out (vty, " aggregate-address %s/%d",
12307 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12308 p->prefixlen);
12309 }
12310
12311 if (bgp_aggregate->as_set)
12312 vty_out (vty, " as-set");
12313
12314 if (bgp_aggregate->summary_only)
12315 vty_out (vty, " summary-only");
12316
12317 vty_out (vty, "%s", VTY_NEWLINE);
12318 }
12319
12320 return 0;
12321}
12322
12323int
12324bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12325{
12326 struct bgp_node *rn;
12327 struct bgp_distance *bdistance;
12328
12329 /* Distance configuration. */
12330 if (bgp->distance_ebgp
12331 && bgp->distance_ibgp
12332 && bgp->distance_local
12333 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12334 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12335 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12336 vty_out (vty, " distance bgp %d %d %d%s",
12337 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12338 VTY_NEWLINE);
12339
12340 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12341 if ((bdistance = rn->info) != NULL)
12342 {
12343 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12344 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12345 bdistance->access_list ? bdistance->access_list : "",
12346 VTY_NEWLINE);
12347 }
12348
12349 return 0;
12350}
12351
12352/* Allocate routing table structure and install commands. */
12353void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012354bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012355{
12356 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012357 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012358
12359 /* IPv4 BGP commands. */
12360 install_element (BGP_NODE, &bgp_network_cmd);
12361 install_element (BGP_NODE, &bgp_network_mask_cmd);
12362 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12363 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12364 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12365 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12366 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12367 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12368 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12369 install_element (BGP_NODE, &no_bgp_network_cmd);
12370 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12371 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12372 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12373 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12374 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12375 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12376 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12377 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12378
12379 install_element (BGP_NODE, &aggregate_address_cmd);
12380 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12381 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12382 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12383 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12384 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12385 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12386 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12387 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12388 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12389 install_element (BGP_NODE, &no_aggregate_address_cmd);
12390 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12391 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12392 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12393 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12394 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12395 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12396 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12397 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12398 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12399
12400 /* IPv4 unicast configuration. */
12401 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12402 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12403 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12404 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12405 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12406 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012407 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012408 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12409 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12410 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12411 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12412 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012413
paul718e3742002-12-13 20:15:29 +000012414 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12415 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12416 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12417 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12418 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12419 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12420 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12421 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12422 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12423 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12424 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12425 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12426 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12427 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12428 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12429 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12430 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12431 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12432 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12433 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12434
12435 /* IPv4 multicast configuration. */
12436 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12437 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12438 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12439 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12440 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12441 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12442 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12443 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12444 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12445 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12446 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12447 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12448 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12449 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12450 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12451 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12452 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12453 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12454 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12455 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12456 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12457 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12458 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12459 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12460 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12461 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12462 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12463 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12464 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12465 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12466 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12467 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12468
12469 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012471 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012472 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012474 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012475 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012479 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012480 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12493 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12494 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012505 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12506 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12507 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12508 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12509 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012510 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012528 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012529 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12533 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12534 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12536 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12537 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12539 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12540 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12541 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12542 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12543 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12544 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012545 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012546 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012547 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012548 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012549 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012550 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012551 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12552 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012553 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012554 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012555 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012556 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012557 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012558 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012559
12560 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12561 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12562 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012563 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012564 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12565 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12566 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012567 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012568 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12569 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12570 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12571 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12572 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12573 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12574 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12575 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12576 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12577 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12578 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012580 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12581 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12582 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12583 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12584 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012585 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12586 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12587 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12588 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12589 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12590 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12591 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12592 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12593 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012594 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012595 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012596 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012597 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012598 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012599 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012600 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012601
12602 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012604 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012605 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012607 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012608 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012612 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012613 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12626 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012638 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12639 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12640 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12641 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12642 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012643 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012661 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012662 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12666 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12667 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12669 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12670 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12672 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12673 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12674 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12675 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12676 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12677 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012678 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012679 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012680 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012681 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012682 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012683 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012684 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012686 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012687 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012688 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012689 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012690 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012691 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012692
12693 /* BGP dampening clear commands */
12694 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12695 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12696 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12697 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12698
Paul Jakmaff7924f2006-09-04 01:10:36 +000012699 /* prefix count */
12700 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12701 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12702 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012703#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012704 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12705
paul718e3742002-12-13 20:15:29 +000012706 /* New config IPv6 BGP commands. */
12707 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12708 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12709 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12710 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12711
12712 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12713 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12714 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12715 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12716
G.Balaji73bfe0b2011-09-23 22:36:20 +053012717 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12718 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12719
paul718e3742002-12-13 20:15:29 +000012720 /* Old config IPv6 BGP commands. */
12721 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12722 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12723
12724 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12725 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12726 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12727 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12728
12729 install_element (VIEW_NODE, &show_bgp_cmd);
12730 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012731 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012732 install_element (VIEW_NODE, &show_bgp_route_cmd);
12733 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012734 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012735 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12736 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012737 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012738 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12739 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12740 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12741 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12742 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12743 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12744 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12745 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12746 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12748 install_element (VIEW_NODE, &show_bgp_community_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12750 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12751 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12752 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12754 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12756 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12758 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12760 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12762 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12764 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12766 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12768 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12769 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12770 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12771 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12772 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12773 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12774 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12775 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12776 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12777 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012778 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12779 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12780 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12781 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012782 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012783 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012784 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012785 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012786 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012787 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012788 install_element (VIEW_NODE, &show_bgp_view_cmd);
12789 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12790 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12791 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12792 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12793 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12794 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12795 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12796 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12797 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12798 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12799 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12800 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12801 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12802 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12803 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12804 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12805 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012806 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012807 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012808 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012809 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012810 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012811 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012812
12813 /* Restricted:
12814 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12815 */
12816 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12817 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012818 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012819 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12820 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012821 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012822 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12823 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12824 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12826 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12828 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12829 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12830 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12832 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12833 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12835 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12836 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12837 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12838 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012839 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012840 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012841 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012842 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12843 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12844 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12845 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12846 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12847 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12848 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012849 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012850 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012851 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012852
12853 install_element (ENABLE_NODE, &show_bgp_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012855 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012856 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012858 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012859 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012861 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012862 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012902 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012906 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012907 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012908 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012909 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012910 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012911 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012912 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12916 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12917 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12928 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12929 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012930 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012931 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012932 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012933 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012934 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012935 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012936
12937 /* Statistics */
12938 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12939 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12940 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12941 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12942
paul718e3742002-12-13 20:15:29 +000012943 /* old command */
12944 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12945 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12946 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12948 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12949 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12950 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12951 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12966 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12967 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12968 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12969 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12970 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12971 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12972 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12973 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12974 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12975 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12976 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12977 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12978 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12979 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012980
paul718e3742002-12-13 20:15:29 +000012981 /* old command */
12982 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12983 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12984 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12986 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12987 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12988 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12989 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13004 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13005 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13006 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13007 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13008 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13009 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13010 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13011 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13012 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13013 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13014 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13015 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13016 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13017 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13018
13019 /* old command */
13020 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13021 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13022 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13023 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13024
13025 /* old command */
13026 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13027 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13028 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13029 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13030
13031 /* old command */
13032 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13033 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13034 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13035 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13036#endif /* HAVE_IPV6 */
13037
13038 install_element (BGP_NODE, &bgp_distance_cmd);
13039 install_element (BGP_NODE, &no_bgp_distance_cmd);
13040 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13041 install_element (BGP_NODE, &bgp_distance_source_cmd);
13042 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13043 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13044 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13045
13046 install_element (BGP_NODE, &bgp_damp_set_cmd);
13047 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13048 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13049 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13050 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13051 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13052 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13053 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13054 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13055 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013056
13057 /* Deprecated AS-Pathlimit commands */
13058 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13059 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13060 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13061 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13062 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13063 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13064
13065 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13066 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13067 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13068 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13069 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13070 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13071
13072 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13073 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13074 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13075 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13076 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13077 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13078
13079 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13080 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13081 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13082 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13083 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13084 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13085
13086 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13087 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13088 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13089 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13090 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13091 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13092
13093 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13094 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13095 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13096 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13097 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13098 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013099
13100#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013101 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13102 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013103#endif
paul718e3742002-12-13 20:15:29 +000013104}
Chris Caputo228da422009-07-18 05:44:03 +000013105
13106void
13107bgp_route_finish (void)
13108{
13109 bgp_table_unlock (bgp_distance_table);
13110 bgp_distance_table = NULL;
13111}