blob: 868fbe56e611c332c66fbfb83f60661c25360b21 [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
Paul Jakma6d4742b2015-11-25 17:14:37 +0000324/* Compare two bgp route entity. Return -1 if new is preferred, 1 if exist
325 * is preferred, or 0 if they are the same (usually will only occur if
326 * multipath is enabled */
paul94f2b392005-06-28 12:44:16 +0000327static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700328bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
Paul Jakma6d4742b2015-11-25 17:14:37 +0000329 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +0000330{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000331 struct attr *newattr, *existattr;
332 struct attr_extra *newattre, *existattre;
333 bgp_peer_sort_t new_sort;
334 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000335 u_int32_t new_pref;
336 u_int32_t exist_pref;
337 u_int32_t new_med;
338 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000339 u_int32_t new_weight;
340 u_int32_t exist_weight;
341 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000342 struct in_addr new_id;
343 struct in_addr exist_id;
344 int new_cluster;
345 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000346 int internal_as_route;
347 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000348 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700349
paul718e3742002-12-13 20:15:29 +0000350 /* 0. Null check. */
351 if (new == NULL)
paul718e3742002-12-13 20:15:29 +0000352 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000353 if (exist == NULL)
354 return -1;
paul718e3742002-12-13 20:15:29 +0000355
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000370 return -1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000371 if (new_weight < exist_weight)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000372 return 1;
paul718e3742002-12-13 20:15:29 +0000373
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000383 return -1;
paul718e3742002-12-13 20:15:29 +0000384 if (new_pref < exist_pref)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000385 return 1;
paul718e3742002-12-13 20:15:29 +0000386
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))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000393 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000394 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000395 return 1;
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))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000411 return -1;
paulfe69a502005-09-10 16:55:02 +0000412 if ( aspath_hops > (exist_hops + exist_confeds))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000413 return 1;
hasso68118452005-04-08 15:40:36 +0000414 }
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000420 return -1;
paulfe69a502005-09-10 16:55:02 +0000421 if (newhops > exist_hops)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000422 return 1;
hasso68118452005-04-08 15:40:36 +0000423 }
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000428 return -1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 if (newattr->origin > existattr->origin)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000430 return 1;
paul718e3742002-12-13 20:15:29 +0000431
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000451 return -1;
paul718e3742002-12-13 20:15:29 +0000452 if (new_med > exist_med)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000453 return 1;
paul718e3742002-12-13 20:15:29 +0000454 }
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))
Paul Jakma6d4742b2015-11-25 17:14:37 +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))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000465 return 1;
paul718e3742002-12-13 20:15:29 +0000466
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)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000476 return -1;
Josh Bailey96450fa2011-07-20 20:45:12 -0700477 if (newm > existm)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000478 return 1;
paul718e3742002-12-13 20:15:29 +0000479
480 /* 9. Maximum path check. */
Paul Jakma6d4742b2015-11-25 17:14:37 +0000481 if (bgp_mpath_is_configured (bgp, afi, safi))
Josh Bailey96450fa2011-07-20 20:45:12 -0700482 {
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000483 if (bgp_flag_check(bgp, BGP_FLAG_ASPATH_MULTIPATH_RELAX))
484 {
Paul Jakma6d4742b2015-11-25 17:14:37 +0000485 /*
486 * For the two paths, all comparison steps till IGP metric
487 * have succeeded - including AS_PATH hop count. Since 'bgp
488 * bestpath as-path multipath-relax' knob is on, we don't need
489 * an exact match of AS_PATH. Thus, mark the paths are equal.
490 * That will trigger both these paths to get into the multipath
491 * array.
492 */
493 return 0;
Pradosh Mohapatra2fdd4552013-09-07 07:02:36 +0000494 }
495 else if (new->peer->sort == BGP_PEER_IBGP)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000496 {
497 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
498 return 0;
499 }
Josh Bailey96450fa2011-07-20 20:45:12 -0700500 else if (new->peer->as == exist->peer->as)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000501 return 0;
Josh Bailey96450fa2011-07-20 20:45:12 -0700502 }
paul718e3742002-12-13 20:15:29 +0000503
504 /* 10. If both paths are external, prefer the path that was received
505 first (the oldest one). This step minimizes route-flap, since a
506 newer path won't displace an older one, even if it was the
507 preferred route based on the additional decision criteria below. */
508 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000509 && new_sort == BGP_PEER_EBGP
510 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000511 {
512 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000513 return -1;
paul718e3742002-12-13 20:15:29 +0000514 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000515 return 1;
paul718e3742002-12-13 20:15:29 +0000516 }
517
vivekbd4b7f12014-09-30 15:54:45 -0700518 /* 11. Router-ID comparision. */
519 /* If one of the paths is "stale", the corresponding peer router-id will
520 * be 0 and would always win over the other path. If originator id is
521 * used for the comparision, it will decide which path is better.
522 */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000523 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
524 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000525 else
526 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000527 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
528 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000529 else
530 exist_id.s_addr = exist->peer->remote_id.s_addr;
531
532 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000533 return -1;
paul718e3742002-12-13 20:15:29 +0000534 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000535 return 1;
paul718e3742002-12-13 20:15:29 +0000536
537 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000538 new_cluster = exist_cluster = 0;
539
540 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
541 new_cluster = newattre->cluster->length;
542 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
543 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000544
545 if (new_cluster < exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000546 return -1;
paul718e3742002-12-13 20:15:29 +0000547 if (new_cluster > exist_cluster)
Paul Jakma6d4742b2015-11-25 17:14:37 +0000548 return 1;
paul718e3742002-12-13 20:15:29 +0000549
550 /* 13. Neighbor address comparision. */
vivekbd4b7f12014-09-30 15:54:45 -0700551 /* Do this only if neither path is "stale" as stale paths do not have
552 * valid peer information (as the connection may or may not be up).
553 */
554 if (CHECK_FLAG (exist->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000555 return -1;
vivekbd4b7f12014-09-30 15:54:45 -0700556 if (CHECK_FLAG (new->flags, BGP_INFO_STALE))
Paul Jakma6d4742b2015-11-25 17:14:37 +0000557 return 1;
Timo Teräs2820a012015-06-24 15:27:21 +0300558 /* locally configured routes to advertise do not have su_remote */
559 if (new->peer->su_remote == NULL)
Timo Teräs2820a012015-06-24 15:27:21 +0300560 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000561 if (exist->peer->su_remote == NULL)
562 return -1;
Timo Teräs2820a012015-06-24 15:27:21 +0300563
paul718e3742002-12-13 20:15:29 +0000564 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
565
566 if (ret == 1)
paul718e3742002-12-13 20:15:29 +0000567 return 1;
Paul Jakma6d4742b2015-11-25 17:14:37 +0000568 if (ret == -1)
569 return -1;
paul718e3742002-12-13 20:15:29 +0000570
Paul Jakma6d4742b2015-11-25 17:14:37 +0000571 return -1;
paul718e3742002-12-13 20:15:29 +0000572}
573
paul94f2b392005-06-28 12:44:16 +0000574static enum filter_type
paul718e3742002-12-13 20:15:29 +0000575bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
576 afi_t afi, safi_t safi)
577{
578 struct bgp_filter *filter;
579
580 filter = &peer->filter[afi][safi];
581
Paul Jakma650f76c2009-06-25 18:06:31 +0100582#define FILTER_EXIST_WARN(F,f,filter) \
583 if (BGP_DEBUG (update, UPDATE_IN) \
584 && !(F ## _IN (filter))) \
585 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
586 peer->host, #f, F ## _IN_NAME(filter));
587
588 if (DISTRIBUTE_IN_NAME (filter)) {
589 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
590
paul718e3742002-12-13 20:15:29 +0000591 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
592 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100593 }
paul718e3742002-12-13 20:15:29 +0000594
Paul Jakma650f76c2009-06-25 18:06:31 +0100595 if (PREFIX_LIST_IN_NAME (filter)) {
596 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
597
paul718e3742002-12-13 20:15:29 +0000598 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
599 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100600 }
paul718e3742002-12-13 20:15:29 +0000601
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 if (FILTER_LIST_IN_NAME (filter)) {
603 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
604
paul718e3742002-12-13 20:15:29 +0000605 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
606 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100607 }
608
paul718e3742002-12-13 20:15:29 +0000609 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100610#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000611}
612
paul94f2b392005-06-28 12:44:16 +0000613static enum filter_type
paul718e3742002-12-13 20:15:29 +0000614bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
615 afi_t afi, safi_t safi)
616{
617 struct bgp_filter *filter;
618
619 filter = &peer->filter[afi][safi];
620
Paul Jakma650f76c2009-06-25 18:06:31 +0100621#define FILTER_EXIST_WARN(F,f,filter) \
622 if (BGP_DEBUG (update, UPDATE_OUT) \
623 && !(F ## _OUT (filter))) \
624 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
625 peer->host, #f, F ## _OUT_NAME(filter));
626
627 if (DISTRIBUTE_OUT_NAME (filter)) {
628 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
629
paul718e3742002-12-13 20:15:29 +0000630 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
631 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100632 }
paul718e3742002-12-13 20:15:29 +0000633
Paul Jakma650f76c2009-06-25 18:06:31 +0100634 if (PREFIX_LIST_OUT_NAME (filter)) {
635 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
636
paul718e3742002-12-13 20:15:29 +0000637 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
638 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100639 }
paul718e3742002-12-13 20:15:29 +0000640
Paul Jakma650f76c2009-06-25 18:06:31 +0100641 if (FILTER_LIST_OUT_NAME (filter)) {
642 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
643
paul718e3742002-12-13 20:15:29 +0000644 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
645 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100646 }
paul718e3742002-12-13 20:15:29 +0000647
648 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100649#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000650}
651
652/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000653static int
paul718e3742002-12-13 20:15:29 +0000654bgp_community_filter (struct peer *peer, struct attr *attr)
655{
656 if (attr->community)
657 {
658 /* NO_ADVERTISE check. */
659 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
660 return 1;
661
662 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000663 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000664 community_include (attr->community, COMMUNITY_NO_EXPORT))
665 return 1;
666
667 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000668 if (peer->sort == BGP_PEER_EBGP
669 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000670 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
671 return 1;
672 }
673 return 0;
674}
675
676/* Route reflection loop check. */
677static int
678bgp_cluster_filter (struct peer *peer, struct attr *attr)
679{
680 struct in_addr cluster_id;
681
Paul Jakmafb982c22007-05-04 20:15:47 +0000682 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000683 {
684 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
685 cluster_id = peer->bgp->cluster_id;
686 else
687 cluster_id = peer->bgp->router_id;
688
Paul Jakmafb982c22007-05-04 20:15:47 +0000689 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000690 return 1;
691 }
692 return 0;
693}
David Lamparter6b0655a2014-06-04 06:53:35 +0200694
paul94f2b392005-06-28 12:44:16 +0000695static int
paul718e3742002-12-13 20:15:29 +0000696bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
697 afi_t afi, safi_t safi)
698{
699 struct bgp_filter *filter;
700 struct bgp_info info;
701 route_map_result_t ret;
702
703 filter = &peer->filter[afi][safi];
704
705 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000706 if (peer->weight)
707 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000708
709 /* Route map apply. */
710 if (ROUTE_MAP_IN_NAME (filter))
711 {
712 /* Duplicate current value to new strucutre for modification. */
713 info.peer = peer;
714 info.attr = attr;
715
paulac41b2a2003-08-12 05:32:27 +0000716 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
717
paul718e3742002-12-13 20:15:29 +0000718 /* Apply BGP route map to the attribute. */
719 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000720
721 peer->rmap_type = 0;
722
paul718e3742002-12-13 20:15:29 +0000723 if (ret == RMAP_DENYMATCH)
David Lamparterc460e572014-06-04 00:54:58 +0200724 /* caller has multiple error paths with bgp_attr_flush() */
725 return RMAP_DENY;
paul718e3742002-12-13 20:15:29 +0000726 }
727 return RMAP_PERMIT;
728}
David Lamparter6b0655a2014-06-04 06:53:35 +0200729
paul94f2b392005-06-28 12:44:16 +0000730static int
paulfee0f4c2004-09-13 05:12:46 +0000731bgp_export_modifier (struct peer *rsclient, struct peer *peer,
732 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
733{
734 struct bgp_filter *filter;
735 struct bgp_info info;
736 route_map_result_t ret;
737
738 filter = &peer->filter[afi][safi];
739
740 /* Route map apply. */
741 if (ROUTE_MAP_EXPORT_NAME (filter))
742 {
743 /* Duplicate current value to new strucutre for modification. */
744 info.peer = rsclient;
745 info.attr = attr;
746
747 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
748
749 /* Apply BGP route map to the attribute. */
750 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
751
752 rsclient->rmap_type = 0;
753
754 if (ret == RMAP_DENYMATCH)
755 {
756 /* Free newly generated AS path and community by route-map. */
757 bgp_attr_flush (attr);
758 return RMAP_DENY;
759 }
760 }
761 return RMAP_PERMIT;
762}
763
paul94f2b392005-06-28 12:44:16 +0000764static int
paulfee0f4c2004-09-13 05:12:46 +0000765bgp_import_modifier (struct peer *rsclient, struct peer *peer,
766 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
767{
768 struct bgp_filter *filter;
769 struct bgp_info info;
770 route_map_result_t ret;
771
772 filter = &rsclient->filter[afi][safi];
773
774 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000775 if (peer->weight)
776 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000777
778 /* Route map apply. */
779 if (ROUTE_MAP_IMPORT_NAME (filter))
780 {
781 /* Duplicate current value to new strucutre for modification. */
782 info.peer = peer;
783 info.attr = attr;
784
785 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
786
787 /* Apply BGP route map to the attribute. */
788 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
789
790 peer->rmap_type = 0;
791
792 if (ret == RMAP_DENYMATCH)
793 {
794 /* Free newly generated AS path and community by route-map. */
795 bgp_attr_flush (attr);
796 return RMAP_DENY;
797 }
798 }
799 return RMAP_PERMIT;
800}
David Lamparter6b0655a2014-06-04 06:53:35 +0200801
paul94f2b392005-06-28 12:44:16 +0000802static int
paul718e3742002-12-13 20:15:29 +0000803bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
804 struct attr *attr, afi_t afi, safi_t safi)
805{
806 int ret;
807 char buf[SU_ADDRSTRLEN];
808 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000809 struct peer *from;
810 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000811 int transparent;
812 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700813 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000814
815 from = ri->peer;
816 filter = &peer->filter[afi][safi];
817 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700818 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000819
Paul Jakma750e8142008-07-22 21:11:48 +0000820 if (DISABLE_BGP_ANNOUNCE)
821 return 0;
paul718e3742002-12-13 20:15:29 +0000822
paulfee0f4c2004-09-13 05:12:46 +0000823 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
824 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
825 return 0;
826
paul718e3742002-12-13 20:15:29 +0000827 /* Do not send back route to sender. */
828 if (from == peer)
829 return 0;
830
831 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000832 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000833 if (! UNSUPPRESS_MAP_NAME (filter))
834 return 0;
835
836 /* Default route check. */
837 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
838 {
839 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
840 return 0;
841#ifdef HAVE_IPV6
842 else if (p->family == AF_INET6 && p->prefixlen == 0)
843 return 0;
844#endif /* HAVE_IPV6 */
845 }
846
paul286e1e72003-08-08 00:24:31 +0000847 /* Transparency check. */
848 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
849 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
850 transparent = 1;
851 else
852 transparent = 0;
853
paul718e3742002-12-13 20:15:29 +0000854 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700855 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000856 return 0;
857
858 /* If the attribute has originator-id and it is same as remote
859 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700860 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000861 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700862 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000863 {
864 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000865 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000866 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
867 peer->host,
868 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
869 p->prefixlen);
870 return 0;
871 }
872 }
873
874 /* ORF prefix-list filter check */
875 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
876 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
877 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
878 if (peer->orf_plist[afi][safi])
879 {
880 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
881 return 0;
882 }
883
884 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700885 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000886 {
887 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000888 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000889 "%s [Update:SEND] %s/%d is filtered",
890 peer->host,
891 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
892 p->prefixlen);
893 return 0;
894 }
895
896#ifdef BGP_SEND_ASPATH_CHECK
897 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700898 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000899 {
900 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000901 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400902 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000903 peer->host, peer->as);
904 return 0;
905 }
906#endif /* BGP_SEND_ASPATH_CHECK */
907
908 /* If we're a CONFED we need to loop check the CONFED ID too */
909 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
910 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700911 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000912 {
913 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000914 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400915 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000916 peer->host,
917 bgp->confed_id);
918 return 0;
919 }
920 }
921
922 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000923 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000924 reflect = 1;
925 else
926 reflect = 0;
927
928 /* IBGP reflection check. */
929 if (reflect)
930 {
931 /* A route from a Client peer. */
932 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
933 {
934 /* Reflect to all the Non-Client peers and also to the
935 Client peers other than the originator. Originator check
936 is already done. So there is noting to do. */
937 /* no bgp client-to-client reflection check. */
938 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
939 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
940 return 0;
941 }
942 else
943 {
944 /* A route from a Non-client peer. Reflect to all other
945 clients. */
946 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
947 return 0;
948 }
949 }
Paul Jakma41367172007-08-06 15:24:51 +0000950
paul718e3742002-12-13 20:15:29 +0000951 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700952 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000953
paul718e3742002-12-13 20:15:29 +0000954 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000955 if ((peer->sort == BGP_PEER_IBGP
956 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000957 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
958 {
959 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
960 attr->local_pref = bgp->default_local_pref;
961 }
962
Pradosh Mohapatra689bb662013-09-07 07:13:37 +0000963 /* If originator-id is not set and the route is to be reflected,
964 set the originator id */
965 if (peer && from && peer->sort == BGP_PEER_IBGP &&
966 from->sort == BGP_PEER_IBGP &&
967 (! (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))))
968 {
969 attr->extra = bgp_attr_extra_get(attr);
970 IPV4_ADDR_COPY(&(attr->extra->originator_id), &(from->remote_id));
971 SET_FLAG(attr->flag, BGP_ATTR_ORIGINATOR_ID);
972 }
973
paul718e3742002-12-13 20:15:29 +0000974 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000975 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000976 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
977 {
978 if (ri->peer != bgp->peer_self && ! transparent
979 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
980 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
981 }
982
983 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300984 if (transparent
985 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000986 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
987 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000988#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000989 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000990 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000991#endif /* HAVE_IPV6 */
992 )))
paul718e3742002-12-13 20:15:29 +0000993 {
994 /* NEXT-HOP Unchanged. */
995 }
996 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
997 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
998#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000999 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001000 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001001#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001002 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001003 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1004 {
1005 /* Set IPv4 nexthop. */
1006 if (p->family == AF_INET)
1007 {
1008 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001009 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1010 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001011 else
1012 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1013 }
1014#ifdef HAVE_IPV6
1015 /* Set IPv6 nexthop. */
1016 if (p->family == AF_INET6)
1017 {
1018 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001019 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001020 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001021 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001022 }
1023#endif /* HAVE_IPV6 */
1024 }
1025
1026#ifdef HAVE_IPV6
1027 if (p->family == AF_INET6)
1028 {
paulfee0f4c2004-09-13 05:12:46 +00001029 /* Left nexthop_local unchanged if so configured. */
1030 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1031 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1032 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001033 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1034 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001035 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001036 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001037 }
1038
1039 /* Default nexthop_local treatment for non-RS-Clients */
1040 else
1041 {
paul718e3742002-12-13 20:15:29 +00001042 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001043 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001044
1045 /* Set link-local address for shared network peer. */
1046 if (peer->shared_network
1047 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1048 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001049 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001050 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001051 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001052 }
1053
1054 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1055 address.*/
1056 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001057 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001058
1059 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1060 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001061 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001062 }
paulfee0f4c2004-09-13 05:12:46 +00001063
1064 }
paul718e3742002-12-13 20:15:29 +00001065#endif /* HAVE_IPV6 */
1066
1067 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001068 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001069 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1070 && aspath_private_as_check (attr->aspath))
1071 attr->aspath = aspath_empty_get ();
1072
1073 /* Route map & unsuppress-map apply. */
1074 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001075 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001076 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001077 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001078 struct attr dummy_attr;
1079 struct attr_extra dummy_extra;
1080
1081 dummy_attr.extra = &dummy_extra;
1082
paul718e3742002-12-13 20:15:29 +00001083 info.peer = peer;
1084 info.attr = attr;
1085
1086 /* The route reflector is not allowed to modify the attributes
1087 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001088 if (from->sort == BGP_PEER_IBGP
1089 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001090 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001091 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001092 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001093 }
paulac41b2a2003-08-12 05:32:27 +00001094
1095 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1096
Paul Jakmafb982c22007-05-04 20:15:47 +00001097 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001098 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1099 else
1100 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1101
paulac41b2a2003-08-12 05:32:27 +00001102 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001103
paul718e3742002-12-13 20:15:29 +00001104 if (ret == RMAP_DENYMATCH)
1105 {
1106 bgp_attr_flush (attr);
1107 return 0;
1108 }
1109 }
1110 return 1;
1111}
1112
paul94f2b392005-06-28 12:44:16 +00001113static int
paulfee0f4c2004-09-13 05:12:46 +00001114bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1115 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001116{
paulfee0f4c2004-09-13 05:12:46 +00001117 int ret;
1118 char buf[SU_ADDRSTRLEN];
1119 struct bgp_filter *filter;
1120 struct bgp_info info;
1121 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001122 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001123
1124 from = ri->peer;
1125 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001126 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001127
Paul Jakma750e8142008-07-22 21:11:48 +00001128 if (DISABLE_BGP_ANNOUNCE)
1129 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001130
1131 /* Do not send back route to sender. */
1132 if (from == rsclient)
1133 return 0;
1134
1135 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001136 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001137 if (! UNSUPPRESS_MAP_NAME (filter))
1138 return 0;
1139
1140 /* Default route check. */
1141 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1142 PEER_STATUS_DEFAULT_ORIGINATE))
1143 {
1144 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1145 return 0;
1146#ifdef HAVE_IPV6
1147 else if (p->family == AF_INET6 && p->prefixlen == 0)
1148 return 0;
1149#endif /* HAVE_IPV6 */
1150 }
1151
1152 /* If the attribute has originator-id and it is same as remote
1153 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001154 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001155 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001156 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001157 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001158 {
1159 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001160 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001161 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1162 rsclient->host,
1163 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1164 p->prefixlen);
1165 return 0;
1166 }
1167 }
1168
1169 /* ORF prefix-list filter check */
1170 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1171 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1172 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1173 if (rsclient->orf_plist[afi][safi])
1174 {
1175 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1176 return 0;
1177 }
1178
1179 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001180 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001181 {
1182 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001183 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001184 "%s [Update:SEND] %s/%d is filtered",
1185 rsclient->host,
1186 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1187 p->prefixlen);
1188 return 0;
1189 }
1190
1191#ifdef BGP_SEND_ASPATH_CHECK
1192 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001193 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001194 {
1195 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001196 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001197 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001198 rsclient->host, rsclient->as);
1199 return 0;
1200 }
1201#endif /* BGP_SEND_ASPATH_CHECK */
1202
1203 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001204 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001205
1206 /* next-hop-set */
1207 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1208#ifdef HAVE_IPV6
1209 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001211#endif /* HAVE_IPV6 */
1212 )
1213 {
1214 /* Set IPv4 nexthop. */
1215 if (p->family == AF_INET)
1216 {
1217 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001218 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001219 IPV4_MAX_BYTELEN);
1220 else
1221 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1222 }
1223#ifdef HAVE_IPV6
1224 /* Set IPv6 nexthop. */
1225 if (p->family == AF_INET6)
1226 {
1227 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001228 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001229 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001230 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001231 }
1232#endif /* HAVE_IPV6 */
1233 }
1234
1235#ifdef HAVE_IPV6
1236 if (p->family == AF_INET6)
1237 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001238 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001239
paulfee0f4c2004-09-13 05:12:46 +00001240 /* Left nexthop_local unchanged if so configured. */
1241 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1242 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1243 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1245 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001246 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001248 }
1249
1250 /* Default nexthop_local treatment for RS-Clients */
1251 else
1252 {
1253 /* Announcer and RS-Client are both in the same network */
1254 if (rsclient->shared_network && from->shared_network &&
1255 (rsclient->ifindex == from->ifindex))
1256 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001257 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1258 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001259 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001261 }
1262
1263 /* Set link-local address for shared network peer. */
1264 else if (rsclient->shared_network
1265 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1266 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001268 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001269 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001270 }
1271
1272 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001273 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001274 }
1275
1276 }
1277#endif /* HAVE_IPV6 */
1278
1279
1280 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001281 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001282 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1283 && aspath_private_as_check (attr->aspath))
1284 attr->aspath = aspath_empty_get ();
1285
1286 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001287 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001288 {
1289 info.peer = rsclient;
1290 info.attr = attr;
1291
1292 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1293
Paul Jakmafb982c22007-05-04 20:15:47 +00001294 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001295 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1296 else
1297 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1298
1299 rsclient->rmap_type = 0;
1300
1301 if (ret == RMAP_DENYMATCH)
1302 {
1303 bgp_attr_flush (attr);
1304 return 0;
1305 }
1306 }
1307
1308 return 1;
1309}
1310
1311struct bgp_info_pair
1312{
1313 struct bgp_info *old;
1314 struct bgp_info *new;
1315};
1316
paul94f2b392005-06-28 12:44:16 +00001317static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001318bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001319 struct bgp_info_pair *result,
1320 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001321{
paul718e3742002-12-13 20:15:29 +00001322 struct bgp_info *new_select;
1323 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001324 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001325 struct bgp_info *ri1;
1326 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001327 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001328 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001329 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001330
1331 result->old = result->new = NULL;
1332
1333 if (rn->info == NULL)
1334 {
1335 char buf[PREFIX_STRLEN];
1336 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1337 __func__,
1338 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1339 return;
1340 }
1341
Josh Bailey96450fa2011-07-20 20:45:12 -07001342 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001343 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001344
paul718e3742002-12-13 20:15:29 +00001345 /* bgp deterministic-med */
1346 new_select = NULL;
1347 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1348 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1349 {
1350 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1351 continue;
1352 if (BGP_INFO_HOLDDOWN (ri1))
1353 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001354 if (ri1->peer && ri1->peer != bgp->peer_self)
1355 if (ri1->peer->status != Established)
1356 continue;
paul718e3742002-12-13 20:15:29 +00001357
1358 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001359 if (do_mpath)
1360 bgp_mp_list_add (&mp_list, ri1);
1361 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001362 if (ri1->next)
1363 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1364 {
1365 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1366 continue;
1367 if (BGP_INFO_HOLDDOWN (ri2))
1368 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001369 if (ri2->peer &&
1370 ri2->peer != bgp->peer_self &&
1371 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1372 if (ri2->peer->status != Established)
1373 continue;
paul718e3742002-12-13 20:15:29 +00001374
1375 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1376 || aspath_cmp_left_confed (ri1->attr->aspath,
1377 ri2->attr->aspath))
1378 {
Josh Bailey6918e742011-07-20 20:48:20 -07001379 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1380 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001381 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1382 == -1)
paul718e3742002-12-13 20:15:29 +00001383 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001384 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001385 new_select = ri2;
1386 }
1387
Paul Jakma6d4742b2015-11-25 17:14:37 +00001388 if (do_mpath)
1389 {
1390 if (cmpret != 0)
1391 bgp_mp_list_clear (&mp_list);
1392
1393 if (cmpret == 0 || cmpret == -1)
1394 bgp_mp_list_add (&mp_list, ri2);
1395 }
Josh Bailey6918e742011-07-20 20:48:20 -07001396
Paul Jakma1a392d42006-09-07 00:24:49 +00001397 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001398 }
1399 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001400 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1401 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001402
Paul Jakma6d4742b2015-11-25 17:14:37 +00001403 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001404 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001405 }
1406
1407 /* Check old selected route and new selected route. */
1408 old_select = NULL;
1409 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001410 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001411 {
1412 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1413 old_select = ri;
1414
1415 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001416 {
1417 /* reap REMOVED routes, if needs be
1418 * selected route must stay for a while longer though
1419 */
1420 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1421 && (ri != old_select))
1422 bgp_info_reap (rn, ri);
1423
1424 continue;
1425 }
paul718e3742002-12-13 20:15:29 +00001426
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001427 if (ri->peer &&
1428 ri->peer != bgp->peer_self &&
1429 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1430 if (ri->peer->status != Established)
1431 continue;
1432
paul718e3742002-12-13 20:15:29 +00001433 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1434 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1435 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001436 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001437 continue;
1438 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001439 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1440 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001441
Paul Jakma6d4742b2015-11-25 17:14:37 +00001442 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001443 {
Josh Bailey6918e742011-07-20 20:48:20 -07001444 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1445 bgp_mp_dmed_deselect (new_select);
1446
Josh Bailey96450fa2011-07-20 20:45:12 -07001447 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001448 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001449 else if (cmpret == 1 && do_mpath
1450 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001451 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001452
Paul Jakma6d4742b2015-11-25 17:14:37 +00001453 if (do_mpath)
1454 {
1455 if (cmpret != 0)
1456 bgp_mp_list_clear (&mp_list);
1457
1458 if (cmpret == 0 || cmpret == -1)
1459 bgp_mp_list_add (&mp_list, ri);
1460 }
paul718e3742002-12-13 20:15:29 +00001461 }
paulfee0f4c2004-09-13 05:12:46 +00001462
Josh Bailey6918e742011-07-20 20:48:20 -07001463 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001464 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001465
Josh Bailey0b597ef2011-07-20 20:49:11 -07001466 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001467 bgp_mp_list_clear (&mp_list);
1468
1469 result->old = old_select;
1470 result->new = new_select;
1471
1472 return;
paulfee0f4c2004-09-13 05:12:46 +00001473}
1474
paul94f2b392005-06-28 12:44:16 +00001475static int
paulfee0f4c2004-09-13 05:12:46 +00001476bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001477 struct bgp_node *rn, afi_t afi, safi_t safi)
1478{
paulfee0f4c2004-09-13 05:12:46 +00001479 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001480 struct attr attr;
1481 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001482
1483 p = &rn->p;
1484
Paul Jakma9eda90c2007-08-30 13:36:17 +00001485 /* Announce route to Established peer. */
1486 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001487 return 0;
1488
Paul Jakma9eda90c2007-08-30 13:36:17 +00001489 /* Address family configuration check. */
1490 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001491 return 0;
1492
Paul Jakma9eda90c2007-08-30 13:36:17 +00001493 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001494 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1495 PEER_STATUS_ORF_WAIT_REFRESH))
1496 return 0;
1497
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001498 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1499 attr.extra = &extra;
1500
Avneesh Sachdev67174042012-08-17 08:19:49 -07001501 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001502 {
1503 case BGP_TABLE_MAIN:
1504 /* Announcement to peer->conf. If the route is filtered,
1505 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001506 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1507 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001508 else
1509 bgp_adj_out_unset (rn, peer, p, afi, safi);
1510 break;
1511 case BGP_TABLE_RSCLIENT:
1512 /* Announcement to peer->conf. If the route is filtered,
1513 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001514 if (selected &&
1515 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1516 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1517 else
1518 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001519 break;
1520 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001521
paulfee0f4c2004-09-13 05:12:46 +00001522 return 0;
paul200df112005-06-01 11:17:05 +00001523}
paulfee0f4c2004-09-13 05:12:46 +00001524
paul200df112005-06-01 11:17:05 +00001525struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001526{
paul200df112005-06-01 11:17:05 +00001527 struct bgp *bgp;
1528 struct bgp_node *rn;
1529 afi_t afi;
1530 safi_t safi;
1531};
1532
1533static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001534bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001535{
paul0fb58d52005-11-14 14:31:49 +00001536 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001537 struct bgp *bgp = pq->bgp;
1538 struct bgp_node *rn = pq->rn;
1539 afi_t afi = pq->afi;
1540 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001541 struct bgp_info *new_select;
1542 struct bgp_info *old_select;
1543 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001544 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001545 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001546
paulfee0f4c2004-09-13 05:12:46 +00001547 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001548 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001549 new_select = old_and_new.new;
1550 old_select = old_and_new.old;
1551
paul200df112005-06-01 11:17:05 +00001552 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1553 {
Chris Caputo228da422009-07-18 05:44:03 +00001554 if (rsclient->group)
1555 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1556 {
1557 /* Nothing to do. */
1558 if (old_select && old_select == new_select)
1559 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1560 continue;
paulfee0f4c2004-09-13 05:12:46 +00001561
Chris Caputo228da422009-07-18 05:44:03 +00001562 if (old_select)
1563 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1564 if (new_select)
1565 {
1566 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1567 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001568 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1569 }
paulfee0f4c2004-09-13 05:12:46 +00001570
Chris Caputo228da422009-07-18 05:44:03 +00001571 bgp_process_announce_selected (rsclient, new_select, rn,
1572 afi, safi);
1573 }
paul200df112005-06-01 11:17:05 +00001574 }
1575 else
1576 {
hassob7395792005-08-26 12:58:38 +00001577 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001578 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001579 if (new_select)
1580 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001581 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1582 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001583 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001584 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001585 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001586 }
paulfee0f4c2004-09-13 05:12:46 +00001587
paulb40d9392005-08-22 22:34:41 +00001588 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1589 bgp_info_reap (rn, old_select);
1590
paul200df112005-06-01 11:17:05 +00001591 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1592 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001593}
1594
paul200df112005-06-01 11:17:05 +00001595static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001596bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001597{
paul0fb58d52005-11-14 14:31:49 +00001598 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001599 struct bgp *bgp = pq->bgp;
1600 struct bgp_node *rn = pq->rn;
1601 afi_t afi = pq->afi;
1602 safi_t safi = pq->safi;
1603 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001604 struct bgp_info *new_select;
1605 struct bgp_info *old_select;
1606 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001607 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001608 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001609
paulfee0f4c2004-09-13 05:12:46 +00001610 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001611 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001612 old_select = old_and_new.old;
1613 new_select = old_and_new.new;
1614
1615 /* Nothing to do. */
1616 if (old_select && old_select == new_select)
1617 {
1618 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001619 {
Josh Bailey8196f132011-07-20 20:47:07 -07001620 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1621 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001622 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001623
Josh Bailey8196f132011-07-20 20:47:07 -07001624 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001625 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1626 return WQ_SUCCESS;
1627 }
paulfee0f4c2004-09-13 05:12:46 +00001628 }
paul718e3742002-12-13 20:15:29 +00001629
hasso338b3422005-02-23 14:27:24 +00001630 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001631 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001632 if (new_select)
1633 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001634 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1635 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001636 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001637 }
1638
1639
paul718e3742002-12-13 20:15:29 +00001640 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001641 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001642 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001643 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001644 }
1645
1646 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001647 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1648 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001649 {
1650 if (new_select
1651 && new_select->type == ZEBRA_ROUTE_BGP
1652 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001653 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001654 else
1655 {
1656 /* Withdraw the route from the kernel. */
1657 if (old_select
1658 && old_select->type == ZEBRA_ROUTE_BGP
1659 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001660 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001661 }
1662 }
paulb40d9392005-08-22 22:34:41 +00001663
1664 /* Reap old select bgp_info, it it has been removed */
1665 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1666 bgp_info_reap (rn, old_select);
1667
paul200df112005-06-01 11:17:05 +00001668 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1669 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001670}
1671
paul200df112005-06-01 11:17:05 +00001672static void
paul0fb58d52005-11-14 14:31:49 +00001673bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001674{
paul0fb58d52005-11-14 14:31:49 +00001675 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001676 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001677
Chris Caputo228da422009-07-18 05:44:03 +00001678 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001679 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001680 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001681 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1682}
1683
1684static void
1685bgp_process_queue_init (void)
1686{
1687 bm->process_main_queue
1688 = work_queue_new (bm->master, "process_main_queue");
1689 bm->process_rsclient_queue
1690 = work_queue_new (bm->master, "process_rsclient_queue");
1691
1692 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1693 {
1694 zlog_err ("%s: Failed to allocate work queue", __func__);
1695 exit (1);
1696 }
1697
1698 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001699 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001700 bm->process_main_queue->spec.max_retries = 0;
1701 bm->process_main_queue->spec.hold = 50;
1702
Paul Jakma838bbde2010-01-08 14:05:32 +00001703 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001704 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1705 bm->process_rsclient_queue->spec.max_retries = 0;
1706 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001707}
1708
1709void
paulfee0f4c2004-09-13 05:12:46 +00001710bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1711{
paul200df112005-06-01 11:17:05 +00001712 struct bgp_process_queue *pqnode;
1713
1714 /* already scheduled for processing? */
1715 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1716 return;
1717
Paul Jakma91b9e852015-12-01 14:32:11 +00001718 if (rn->info == NULL)
1719 {
1720 /* XXX: Perhaps remove before next release, after we've flushed out
1721 * any obvious cases
1722 */
1723 assert (rn->info != NULL);
1724 char buf[PREFIX_STRLEN];
1725 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1726 __func__,
1727 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1728 return;
1729 }
1730
paul200df112005-06-01 11:17:05 +00001731 if ( (bm->process_main_queue == NULL) ||
1732 (bm->process_rsclient_queue == NULL) )
1733 bgp_process_queue_init ();
1734
1735 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1736 sizeof (struct bgp_process_queue));
1737 if (!pqnode)
1738 return;
Chris Caputo228da422009-07-18 05:44:03 +00001739
1740 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001741 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001742 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001743 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001744 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001745 pqnode->afi = afi;
1746 pqnode->safi = safi;
1747
Avneesh Sachdev67174042012-08-17 08:19:49 -07001748 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001749 {
paul200df112005-06-01 11:17:05 +00001750 case BGP_TABLE_MAIN:
1751 work_queue_add (bm->process_main_queue, pqnode);
1752 break;
1753 case BGP_TABLE_RSCLIENT:
1754 work_queue_add (bm->process_rsclient_queue, pqnode);
1755 break;
paulfee0f4c2004-09-13 05:12:46 +00001756 }
paul200df112005-06-01 11:17:05 +00001757
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001758 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001759 return;
paulfee0f4c2004-09-13 05:12:46 +00001760}
hasso0a486e52005-02-01 20:57:17 +00001761
paul94f2b392005-06-28 12:44:16 +00001762static int
hasso0a486e52005-02-01 20:57:17 +00001763bgp_maximum_prefix_restart_timer (struct thread *thread)
1764{
1765 struct peer *peer;
1766
1767 peer = THREAD_ARG (thread);
1768 peer->t_pmax_restart = NULL;
1769
1770 if (BGP_DEBUG (events, EVENTS))
1771 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1772 peer->host);
1773
1774 peer_clear (peer);
1775
1776 return 0;
1777}
1778
paulfee0f4c2004-09-13 05:12:46 +00001779int
paul5228ad22004-06-04 17:58:18 +00001780bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1781 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001782{
hassoe0701b72004-05-20 09:19:34 +00001783 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1784 return 0;
1785
1786 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001787 {
hassoe0701b72004-05-20 09:19:34 +00001788 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1789 && ! always)
1790 return 0;
paul718e3742002-12-13 20:15:29 +00001791
hassoe0701b72004-05-20 09:19:34 +00001792 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001793 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1794 "limit %ld", afi_safi_print (afi, safi), peer->host,
1795 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001796 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001797
hassoe0701b72004-05-20 09:19:34 +00001798 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1799 return 0;
paul718e3742002-12-13 20:15:29 +00001800
hassoe0701b72004-05-20 09:19:34 +00001801 {
paul5228ad22004-06-04 17:58:18 +00001802 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001803
1804 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001805 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001806
1807 ndata[0] = (afi >> 8);
1808 ndata[1] = afi;
1809 ndata[2] = safi;
1810 ndata[3] = (peer->pmax[afi][safi] >> 24);
1811 ndata[4] = (peer->pmax[afi][safi] >> 16);
1812 ndata[5] = (peer->pmax[afi][safi] >> 8);
1813 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001814
1815 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1816 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1817 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1818 }
hasso0a486e52005-02-01 20:57:17 +00001819
1820 /* restart timer start */
1821 if (peer->pmax_restart[afi][safi])
1822 {
1823 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1824
1825 if (BGP_DEBUG (events, EVENTS))
1826 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1827 peer->host, peer->v_pmax_restart);
1828
1829 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1830 peer->v_pmax_restart);
1831 }
1832
hassoe0701b72004-05-20 09:19:34 +00001833 return 1;
paul718e3742002-12-13 20:15:29 +00001834 }
hassoe0701b72004-05-20 09:19:34 +00001835 else
1836 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1837
1838 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1839 {
1840 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1841 && ! always)
1842 return 0;
1843
1844 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001845 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1846 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1847 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001848 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1849 }
1850 else
1851 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001852 return 0;
1853}
1854
paulb40d9392005-08-22 22:34:41 +00001855/* Unconditionally remove the route from the RIB, without taking
1856 * damping into consideration (eg, because the session went down)
1857 */
paul94f2b392005-06-28 12:44:16 +00001858static void
paul718e3742002-12-13 20:15:29 +00001859bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1860 afi_t afi, safi_t safi)
1861{
paul902212c2006-02-05 17:51:19 +00001862 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1863
1864 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1865 bgp_info_delete (rn, ri); /* keep historical info */
1866
paulb40d9392005-08-22 22:34:41 +00001867 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001868}
1869
paul94f2b392005-06-28 12:44:16 +00001870static void
paul718e3742002-12-13 20:15:29 +00001871bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001872 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001873{
paul718e3742002-12-13 20:15:29 +00001874 int status = BGP_DAMP_NONE;
1875
paulb40d9392005-08-22 22:34:41 +00001876 /* apply dampening, if result is suppressed, we'll be retaining
1877 * the bgp_info in the RIB for historical reference.
1878 */
1879 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001880 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001881 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1882 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001883 {
paul902212c2006-02-05 17:51:19 +00001884 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1885 return;
1886 }
1887
1888 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001889}
1890
paul94f2b392005-06-28 12:44:16 +00001891static void
paulfee0f4c2004-09-13 05:12:46 +00001892bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1893 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1894 int sub_type, struct prefix_rd *prd, u_char *tag)
1895{
1896 struct bgp_node *rn;
1897 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001898 struct attr new_attr;
1899 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001900 struct attr *attr_new;
1901 struct attr *attr_new2;
1902 struct bgp_info *ri;
1903 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001904 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001905 char buf[SU_ADDRSTRLEN];
1906
1907 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1908 if (peer == rsclient)
1909 return;
1910
1911 bgp = peer->bgp;
1912 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1913
1914 /* Check previously received route. */
1915 for (ri = rn->info; ri; ri = ri->next)
1916 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1917 break;
1918
1919 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001920 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001921 {
1922 reason = "as-path contains our own AS;";
1923 goto filtered;
1924 }
1925
1926 /* Route reflector originator ID check. */
1927 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001928 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001929 {
1930 reason = "originator is us;";
1931 goto filtered;
1932 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001933
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001934 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001935 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001936
1937 /* Apply export policy. */
1938 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1939 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1940 {
1941 reason = "export-policy;";
1942 goto filtered;
1943 }
1944
1945 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001946
paulfee0f4c2004-09-13 05:12:46 +00001947 /* Apply import policy. */
1948 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1949 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001950 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 reason = "import-policy;";
1953 goto filtered;
1954 }
1955
1956 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001957 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001958
1959 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001960 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001961 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001962 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001963 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001964 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001965 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001966 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001967
1968 reason = "martian next-hop;";
1969 goto filtered;
1970 }
1971 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001972
paulfee0f4c2004-09-13 05:12:46 +00001973 /* If the update is implicit withdraw. */
1974 if (ri)
1975 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001976 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001977
1978 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001979 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1980 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001981 {
1982
Paul Jakma1a392d42006-09-07 00:24:49 +00001983 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001984
1985 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001986 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001987 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1988 peer->host,
1989 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1990 p->prefixlen, rsclient->host);
1991
Chris Caputo228da422009-07-18 05:44:03 +00001992 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001993 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001994
Chris Caputo228da422009-07-18 05:44:03 +00001995 return;
paulfee0f4c2004-09-13 05:12:46 +00001996 }
1997
Paul Jakma16d2e242007-04-10 19:32:10 +00001998 /* Withdraw/Announce before we fully processed the withdraw */
1999 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2000 bgp_info_restore (rn, ri);
2001
paulfee0f4c2004-09-13 05:12:46 +00002002 /* Received Logging. */
2003 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002004 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002005 peer->host,
2006 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2007 p->prefixlen, rsclient->host);
2008
2009 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002010 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002011
2012 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002013 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002014 ri->attr = attr_new;
2015
2016 /* Update MPLS tag. */
2017 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002018 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002019
Paul Jakma1a392d42006-09-07 00:24:49 +00002020 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002021
2022 /* Process change. */
2023 bgp_process (bgp, rn, afi, safi);
2024 bgp_unlock_node (rn);
2025
2026 return;
2027 }
2028
2029 /* Received Logging. */
2030 if (BGP_DEBUG (update, UPDATE_IN))
2031 {
ajsd2c1f162004-12-08 21:10:20 +00002032 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002033 peer->host,
2034 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2035 p->prefixlen, rsclient->host);
2036 }
2037
2038 /* Make new BGP info. */
2039 new = bgp_info_new ();
2040 new->type = type;
2041 new->sub_type = sub_type;
2042 new->peer = peer;
2043 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002044 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002045
2046 /* Update MPLS tag. */
2047 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002048 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002049
Paul Jakma1a392d42006-09-07 00:24:49 +00002050 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002051
2052 /* Register new BGP information. */
2053 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002054
2055 /* route_node_get lock */
2056 bgp_unlock_node (rn);
2057
paulfee0f4c2004-09-13 05:12:46 +00002058 /* Process change. */
2059 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002060
paulfee0f4c2004-09-13 05:12:46 +00002061 return;
2062
2063 filtered:
2064
2065 /* This BGP update is filtered. Log the reason then update BGP entry. */
2066 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002067 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002068 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2069 peer->host,
2070 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2071 p->prefixlen, rsclient->host, reason);
2072
2073 if (ri)
paulb40d9392005-08-22 22:34:41 +00002074 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002075
2076 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002077
paulfee0f4c2004-09-13 05:12:46 +00002078 return;
2079}
2080
paul94f2b392005-06-28 12:44:16 +00002081static void
paulfee0f4c2004-09-13 05:12:46 +00002082bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2083 struct peer *peer, struct prefix *p, int type, int sub_type,
2084 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002085{
paulfee0f4c2004-09-13 05:12:46 +00002086 struct bgp_node *rn;
2087 struct bgp_info *ri;
2088 char buf[SU_ADDRSTRLEN];
2089
2090 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002091 return;
paulfee0f4c2004-09-13 05:12:46 +00002092
2093 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2094
2095 /* Lookup withdrawn route. */
2096 for (ri = rn->info; ri; ri = ri->next)
2097 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2098 break;
2099
2100 /* Withdraw specified route from routing table. */
2101 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002102 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002103 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002104 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002105 "%s Can't find the route %s/%d", peer->host,
2106 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2107 p->prefixlen);
2108
2109 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002110 bgp_unlock_node (rn);
2111}
paulfee0f4c2004-09-13 05:12:46 +00002112
paul94f2b392005-06-28 12:44:16 +00002113static int
paulfee0f4c2004-09-13 05:12:46 +00002114bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002115 afi_t afi, safi_t safi, int type, int sub_type,
2116 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2117{
2118 int ret;
2119 int aspath_loop_count = 0;
2120 struct bgp_node *rn;
2121 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002122 struct attr new_attr;
2123 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002124 struct attr *attr_new;
2125 struct bgp_info *ri;
2126 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002127 const char *reason;
paul718e3742002-12-13 20:15:29 +00002128 char buf[SU_ADDRSTRLEN];
2129
2130 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002131 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002132
paul718e3742002-12-13 20:15:29 +00002133 /* When peer's soft reconfiguration enabled. Record input packet in
2134 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002135 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2136 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002137 bgp_adj_in_set (rn, peer, attr);
2138
2139 /* Check previously received route. */
2140 for (ri = rn->info; ri; ri = ri->next)
2141 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2142 break;
2143
2144 /* AS path local-as loop check. */
2145 if (peer->change_local_as)
2146 {
2147 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2148 aspath_loop_count = 1;
2149
2150 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2151 {
2152 reason = "as-path contains our own AS;";
2153 goto filtered;
2154 }
2155 }
2156
2157 /* AS path loop check. */
2158 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2159 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2160 && aspath_loop_check(attr->aspath, bgp->confed_id)
2161 > peer->allowas_in[afi][safi]))
2162 {
2163 reason = "as-path contains our own AS;";
2164 goto filtered;
2165 }
2166
2167 /* Route reflector originator ID check. */
2168 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002169 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002170 {
2171 reason = "originator is us;";
2172 goto filtered;
2173 }
2174
2175 /* Route reflector cluster ID check. */
2176 if (bgp_cluster_filter (peer, attr))
2177 {
2178 reason = "reflected from the same cluster;";
2179 goto filtered;
2180 }
2181
2182 /* Apply incoming filter. */
2183 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2184 {
2185 reason = "filter;";
2186 goto filtered;
2187 }
2188
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002189 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002190 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002191
David Lamparterc460e572014-06-04 00:54:58 +02002192 /* Apply incoming route-map.
2193 * NB: new_attr may now contain newly allocated values from route-map "set"
2194 * commands, so we need bgp_attr_flush in the error paths, until we intern
2195 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002196 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2197 {
2198 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002199 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002200 goto filtered;
2201 }
2202
2203 /* IPv4 unicast next hop check. */
2204 if (afi == AFI_IP && safi == SAFI_UNICAST)
2205 {
2206 /* If the peer is EBGP and nexthop is not on connected route,
2207 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002208 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002209 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002210 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002211 {
2212 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002213 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002214 goto filtered;
2215 }
2216
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002217 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002218 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002219 if (new_attr.nexthop.s_addr == 0
2220 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2221 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002222 {
2223 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002224 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002225 goto filtered;
2226 }
2227 }
2228
2229 attr_new = bgp_attr_intern (&new_attr);
2230
2231 /* If the update is implicit withdraw. */
2232 if (ri)
2233 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002234 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002235
2236 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002237 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2238 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002239 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002240 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002241
2242 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002243 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002244 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2245 {
2246 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002247 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002248 peer->host,
2249 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2250 p->prefixlen);
2251
paul902212c2006-02-05 17:51:19 +00002252 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2253 {
2254 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2255 bgp_process (bgp, rn, afi, safi);
2256 }
paul718e3742002-12-13 20:15:29 +00002257 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002258 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002259 {
2260 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002261 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002262 "%s rcvd %s/%d...duplicate ignored",
2263 peer->host,
2264 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2265 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002266
2267 /* graceful restart STALE flag unset. */
2268 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2269 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002270 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002271 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002272 }
paul718e3742002-12-13 20:15:29 +00002273 }
2274
2275 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002276 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002277
paul718e3742002-12-13 20:15:29 +00002278 return 0;
2279 }
2280
Paul Jakma16d2e242007-04-10 19:32:10 +00002281 /* Withdraw/Announce before we fully processed the withdraw */
2282 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2283 {
2284 if (BGP_DEBUG (update, UPDATE_IN))
2285 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2286 peer->host,
2287 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2288 p->prefixlen);
2289 bgp_info_restore (rn, ri);
2290 }
2291
paul718e3742002-12-13 20:15:29 +00002292 /* Received Logging. */
2293 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002294 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002295 peer->host,
2296 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2297 p->prefixlen);
2298
hasso93406d82005-02-02 14:40:33 +00002299 /* graceful restart STALE flag unset. */
2300 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002301 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002302
paul718e3742002-12-13 20:15:29 +00002303 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002304 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002305
2306 /* implicit withdraw, decrement aggregate and pcount here.
2307 * only if update is accepted, they'll increment below.
2308 */
paul902212c2006-02-05 17:51:19 +00002309 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2310
paul718e3742002-12-13 20:15:29 +00002311 /* Update bgp route dampening information. */
2312 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002313 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002314 {
2315 /* This is implicit withdraw so we should update dampening
2316 information. */
2317 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2318 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002319 }
2320
paul718e3742002-12-13 20:15:29 +00002321 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002322 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002323 ri->attr = attr_new;
2324
2325 /* Update MPLS tag. */
2326 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002327 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002328
2329 /* Update bgp route dampening information. */
2330 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002331 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002332 {
2333 /* Now we do normal update dampening. */
2334 ret = bgp_damp_update (ri, rn, afi, safi);
2335 if (ret == BGP_DAMP_SUPPRESSED)
2336 {
2337 bgp_unlock_node (rn);
2338 return 0;
2339 }
2340 }
2341
2342 /* Nexthop reachability check. */
2343 if ((afi == AFI_IP || afi == AFI_IP6)
2344 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002345 && (peer->sort == BGP_PEER_IBGP
2346 || peer->sort == BGP_PEER_CONFED
2347 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002348 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002349 {
2350 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002351 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002352 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002353 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002354 }
2355 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002356 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002357
2358 /* Process change. */
2359 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2360
2361 bgp_process (bgp, rn, afi, safi);
2362 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002363
paul718e3742002-12-13 20:15:29 +00002364 return 0;
2365 }
2366
2367 /* Received Logging. */
2368 if (BGP_DEBUG (update, UPDATE_IN))
2369 {
ajsd2c1f162004-12-08 21:10:20 +00002370 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002371 peer->host,
2372 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2373 p->prefixlen);
2374 }
2375
paul718e3742002-12-13 20:15:29 +00002376 /* Make new BGP info. */
2377 new = bgp_info_new ();
2378 new->type = type;
2379 new->sub_type = sub_type;
2380 new->peer = peer;
2381 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002382 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002383
2384 /* Update MPLS tag. */
2385 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002386 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002387
2388 /* Nexthop reachability check. */
2389 if ((afi == AFI_IP || afi == AFI_IP6)
2390 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002391 && (peer->sort == BGP_PEER_IBGP
2392 || peer->sort == BGP_PEER_CONFED
2393 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002394 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002395 {
2396 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002397 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002398 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002399 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002400 }
2401 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002402 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002403
paul902212c2006-02-05 17:51:19 +00002404 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002405 bgp_aggregate_increment (bgp, p, new, afi, safi);
2406
2407 /* Register new BGP information. */
2408 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002409
2410 /* route_node_get lock */
2411 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002412
paul718e3742002-12-13 20:15:29 +00002413 /* If maximum prefix count is configured and current prefix
2414 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002415 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2416 return -1;
paul718e3742002-12-13 20:15:29 +00002417
2418 /* Process change. */
2419 bgp_process (bgp, rn, afi, safi);
2420
2421 return 0;
2422
2423 /* This BGP update is filtered. Log the reason then update BGP
2424 entry. */
2425 filtered:
2426 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002427 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002428 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2429 peer->host,
2430 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2431 p->prefixlen, reason);
2432
2433 if (ri)
paulb40d9392005-08-22 22:34:41 +00002434 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002435
2436 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002437
paul718e3742002-12-13 20:15:29 +00002438 return 0;
2439}
2440
2441int
paulfee0f4c2004-09-13 05:12:46 +00002442bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2443 afi_t afi, safi_t safi, int type, int sub_type,
2444 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2445{
2446 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002447 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002448 struct bgp *bgp;
2449 int ret;
2450
2451 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2452 soft_reconfig);
2453
2454 bgp = peer->bgp;
2455
2456 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002457 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002458 {
2459 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2460 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2461 sub_type, prd, tag);
2462 }
2463
2464 return ret;
2465}
2466
2467int
paul718e3742002-12-13 20:15:29 +00002468bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002469 afi_t afi, safi_t safi, int type, int sub_type,
2470 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002471{
2472 struct bgp *bgp;
2473 char buf[SU_ADDRSTRLEN];
2474 struct bgp_node *rn;
2475 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002476 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002477 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002478
2479 bgp = peer->bgp;
2480
David Lamparter4584c232015-04-13 09:50:00 +02002481 /* Lookup node. */
2482 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2483
2484 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2485 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2486 * the iteration over all RS clients.
2487 * Since we need to remove the entry from adj_in anyway, do that first and
2488 * if there was no entry, we don't need to do anything more. */
2489 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2490 && peer != bgp->peer_self)
2491 if (!bgp_adj_in_unset (rn, peer))
2492 {
2493 if (BGP_DEBUG (update, UPDATE_IN))
2494 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2495 "not in adj-in", peer->host,
2496 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2497 p->prefixlen);
2498 bgp_unlock_node (rn);
2499 return 0;
2500 }
2501
paulfee0f4c2004-09-13 05:12:46 +00002502 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002503 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002504 {
2505 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2506 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2507 }
2508
paul718e3742002-12-13 20:15:29 +00002509 /* Logging. */
2510 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002511 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002512 peer->host,
2513 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2514 p->prefixlen);
2515
paul718e3742002-12-13 20:15:29 +00002516 /* Lookup withdrawn route. */
2517 for (ri = rn->info; ri; ri = ri->next)
2518 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2519 break;
2520
2521 /* Withdraw specified route from routing table. */
2522 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002523 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002524 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002525 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002526 "%s Can't find the route %s/%d", peer->host,
2527 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2528 p->prefixlen);
2529
2530 /* Unlock bgp_node_get() lock. */
2531 bgp_unlock_node (rn);
2532
2533 return 0;
2534}
David Lamparter6b0655a2014-06-04 06:53:35 +02002535
paul718e3742002-12-13 20:15:29 +00002536void
2537bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2538{
2539 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002540 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002541 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002542 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002543 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002544 struct bgp_node *rn;
2545 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002546 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002547
Paul Jakmab2497022007-06-14 11:17:58 +00002548 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002549 return;
2550
paul718e3742002-12-13 20:15:29 +00002551 bgp = peer->bgp;
2552 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002553
paul718e3742002-12-13 20:15:29 +00002554 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2555 aspath = attr.aspath;
2556 attr.local_pref = bgp->default_local_pref;
2557 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2558
2559 if (afi == AFI_IP)
2560 str2prefix ("0.0.0.0/0", &p);
2561#ifdef HAVE_IPV6
2562 else if (afi == AFI_IP6)
2563 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002564 struct attr_extra *ae = attr.extra;
2565
paul718e3742002-12-13 20:15:29 +00002566 str2prefix ("::/0", &p);
2567
2568 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002569 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002570 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002571 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002572
2573 /* If the peer is on shared nextwork and we have link-local
2574 nexthop set it. */
2575 if (peer->shared_network
2576 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2577 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002578 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002579 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002580 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002581 }
2582 }
2583#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002584
2585 if (peer->default_rmap[afi][safi].name)
2586 {
paulfee0f4c2004-09-13 05:12:46 +00002587 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002588 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2589 {
2590 for (ri = rn->info; ri; ri = ri->next)
2591 {
2592 struct attr dummy_attr;
2593 struct attr_extra dummy_extra;
2594 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002595
Christian Frankedcab1bb2012-12-07 16:45:52 +00002596 /* Provide dummy so the route-map can't modify the attributes */
2597 dummy_attr.extra = &dummy_extra;
2598 bgp_attr_dup(&dummy_attr, ri->attr);
2599 info.peer = ri->peer;
2600 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002601
Christian Frankedcab1bb2012-12-07 16:45:52 +00002602 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2603 RMAP_BGP, &info);
2604
2605 /* The route map might have set attributes. If we don't flush them
2606 * here, they will be leaked. */
2607 bgp_attr_flush(&dummy_attr);
2608 if (ret != RMAP_DENYMATCH)
2609 break;
2610 }
2611 if (ret != RMAP_DENYMATCH)
2612 break;
2613 }
paulfee0f4c2004-09-13 05:12:46 +00002614 bgp->peer_self->rmap_type = 0;
2615
paul718e3742002-12-13 20:15:29 +00002616 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002617 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002618 }
2619
2620 if (withdraw)
2621 {
2622 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2623 bgp_default_withdraw_send (peer, afi, safi);
2624 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2625 }
2626 else
2627 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002628 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2629 {
2630 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2631 bgp_default_update_send (peer, &attr, afi, safi, from);
2632 }
paul718e3742002-12-13 20:15:29 +00002633 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002634
2635 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002636 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002637}
David Lamparter6b0655a2014-06-04 06:53:35 +02002638
paul718e3742002-12-13 20:15:29 +00002639static void
2640bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002641 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002642{
2643 struct bgp_node *rn;
2644 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002645 struct attr attr;
2646 struct attr_extra extra;
2647
paul718e3742002-12-13 20:15:29 +00002648 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002649 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002650
2651 if (safi != SAFI_MPLS_VPN
2652 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2653 bgp_default_originate (peer, afi, safi, 0);
2654
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002655 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2656 attr.extra = &extra;
2657
paul718e3742002-12-13 20:15:29 +00002658 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2659 for (ri = rn->info; ri; ri = ri->next)
2660 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2661 {
paulfee0f4c2004-09-13 05:12:46 +00002662 if ( (rsclient) ?
2663 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2664 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002665 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2666 else
2667 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2668 }
2669}
2670
2671void
2672bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2673{
2674 struct bgp_node *rn;
2675 struct bgp_table *table;
2676
2677 if (peer->status != Established)
2678 return;
2679
2680 if (! peer->afc_nego[afi][safi])
2681 return;
2682
2683 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2684 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2685 return;
2686
2687 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002688 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002689 else
2690 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2691 rn = bgp_route_next(rn))
2692 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002693 bgp_announce_table (peer, afi, safi, table, 0);
2694
2695 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2696 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002697}
2698
2699void
2700bgp_announce_route_all (struct peer *peer)
2701{
2702 afi_t afi;
2703 safi_t safi;
2704
2705 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2706 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2707 bgp_announce_route (peer, afi, safi);
2708}
David Lamparter6b0655a2014-06-04 06:53:35 +02002709
paul718e3742002-12-13 20:15:29 +00002710static void
paulfee0f4c2004-09-13 05:12:46 +00002711bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002712 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002713{
2714 struct bgp_node *rn;
2715 struct bgp_adj_in *ain;
2716
2717 if (! table)
2718 table = rsclient->bgp->rib[afi][safi];
2719
2720 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2721 for (ain = rn->adj_in; ain; ain = ain->next)
2722 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002723 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002724 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002725
paulfee0f4c2004-09-13 05:12:46 +00002726 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002727 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002728 }
2729}
2730
2731void
2732bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2733{
2734 struct bgp_table *table;
2735 struct bgp_node *rn;
2736
2737 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002738 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002739
2740 else
2741 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2742 rn = bgp_route_next (rn))
2743 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002744 {
2745 struct prefix_rd prd;
2746 prd.family = AF_UNSPEC;
2747 prd.prefixlen = 64;
2748 memcpy(&prd.val, rn->p.u.val, 8);
2749
2750 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2751 }
paulfee0f4c2004-09-13 05:12:46 +00002752}
David Lamparter6b0655a2014-06-04 06:53:35 +02002753
paulfee0f4c2004-09-13 05:12:46 +00002754static void
paul718e3742002-12-13 20:15:29 +00002755bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002756 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002757{
2758 int ret;
2759 struct bgp_node *rn;
2760 struct bgp_adj_in *ain;
2761
2762 if (! table)
2763 table = peer->bgp->rib[afi][safi];
2764
2765 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2766 for (ain = rn->adj_in; ain; ain = ain->next)
2767 {
2768 if (ain->peer == peer)
2769 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002770 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002771 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002772
paul718e3742002-12-13 20:15:29 +00002773 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2774 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002775 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002776
paul718e3742002-12-13 20:15:29 +00002777 if (ret < 0)
2778 {
2779 bgp_unlock_node (rn);
2780 return;
2781 }
2782 continue;
2783 }
2784 }
2785}
2786
2787void
2788bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2789{
2790 struct bgp_node *rn;
2791 struct bgp_table *table;
2792
2793 if (peer->status != Established)
2794 return;
2795
2796 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002797 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002798 else
2799 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2800 rn = bgp_route_next (rn))
2801 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002802 {
2803 struct prefix_rd prd;
2804 prd.family = AF_UNSPEC;
2805 prd.prefixlen = 64;
2806 memcpy(&prd.val, rn->p.u.val, 8);
2807
2808 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2809 }
paul718e3742002-12-13 20:15:29 +00002810}
David Lamparter6b0655a2014-06-04 06:53:35 +02002811
Chris Caputo228da422009-07-18 05:44:03 +00002812
2813struct bgp_clear_node_queue
2814{
2815 struct bgp_node *rn;
2816 enum bgp_clear_route_type purpose;
2817};
2818
paul200df112005-06-01 11:17:05 +00002819static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002820bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002821{
Chris Caputo228da422009-07-18 05:44:03 +00002822 struct bgp_clear_node_queue *cnq = data;
2823 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002824 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002825 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002826 afi_t afi = bgp_node_table (rn)->afi;
2827 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002828
Paul Jakma64e580a2006-02-21 01:09:01 +00002829 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002830
Paul Jakma64e580a2006-02-21 01:09:01 +00002831 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002832 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002833 {
2834 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002835 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2836 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002837 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002838 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2839 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002840 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002841 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002842 break;
2843 }
paul200df112005-06-01 11:17:05 +00002844 return WQ_SUCCESS;
2845}
2846
2847static void
paul0fb58d52005-11-14 14:31:49 +00002848bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002849{
Chris Caputo228da422009-07-18 05:44:03 +00002850 struct bgp_clear_node_queue *cnq = data;
2851 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002852 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002853
2854 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002855 bgp_table_unlock (table);
2856 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002857}
2858
2859static void
paul94f2b392005-06-28 12:44:16 +00002860bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002861{
Paul Jakma64e580a2006-02-21 01:09:01 +00002862 struct peer *peer = wq->spec.data;
2863
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002864 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002865 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002866
2867 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002868}
2869
2870static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002871bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002872{
Paul Jakmaa2943652009-07-21 14:02:04 +01002873 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002874
Paul Jakmaa2943652009-07-21 14:02:04 +01002875 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002876#undef CLEAR_QUEUE_NAME_LEN
2877
2878 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002879 {
2880 zlog_err ("%s: Failed to allocate work queue", __func__);
2881 exit (1);
2882 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002883 peer->clear_node_queue->spec.hold = 10;
2884 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2885 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2886 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2887 peer->clear_node_queue->spec.max_retries = 0;
2888
2889 /* we only 'lock' this peer reference when the queue is actually active */
2890 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002891}
2892
paul718e3742002-12-13 20:15:29 +00002893static void
2894bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002895 struct bgp_table *table, struct peer *rsclient,
2896 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002897{
2898 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002899
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002900
paul718e3742002-12-13 20:15:29 +00002901 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002902 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002903
hasso6cf159b2005-03-21 10:28:14 +00002904 /* If still no table => afi/safi isn't configured at all or smth. */
2905 if (! table)
2906 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002907
2908 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2909 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002910 struct bgp_info *ri;
2911 struct bgp_adj_in *ain;
2912 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002913
2914 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2915 * queued for every clearing peer, regardless of whether it is
2916 * relevant to the peer at hand.
2917 *
2918 * Overview: There are 3 different indices which need to be
2919 * scrubbed, potentially, when a peer is removed:
2920 *
2921 * 1 peer's routes visible via the RIB (ie accepted routes)
2922 * 2 peer's routes visible by the (optional) peer's adj-in index
2923 * 3 other routes visible by the peer's adj-out index
2924 *
2925 * 3 there is no hurry in scrubbing, once the struct peer is
2926 * removed from bgp->peer, we could just GC such deleted peer's
2927 * adj-outs at our leisure.
2928 *
2929 * 1 and 2 must be 'scrubbed' in some way, at least made
2930 * invisible via RIB index before peer session is allowed to be
2931 * brought back up. So one needs to know when such a 'search' is
2932 * complete.
2933 *
2934 * Ideally:
2935 *
2936 * - there'd be a single global queue or a single RIB walker
2937 * - rather than tracking which route_nodes still need to be
2938 * examined on a peer basis, we'd track which peers still
2939 * aren't cleared
2940 *
2941 * Given that our per-peer prefix-counts now should be reliable,
2942 * this may actually be achievable. It doesn't seem to be a huge
2943 * problem at this time,
2944 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002945 for (ain = rn->adj_in; ain; ain = ain->next)
2946 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2947 {
2948 bgp_adj_in_remove (rn, ain);
2949 bgp_unlock_node (rn);
2950 break;
2951 }
2952 for (aout = rn->adj_out; aout; aout = aout->next)
2953 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2954 {
2955 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2956 bgp_unlock_node (rn);
2957 break;
2958 }
2959
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002960 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002961 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002962 {
Chris Caputo228da422009-07-18 05:44:03 +00002963 struct bgp_clear_node_queue *cnq;
2964
2965 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002966 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002967 bgp_lock_node (rn);
2968 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2969 sizeof (struct bgp_clear_node_queue));
2970 cnq->rn = rn;
2971 cnq->purpose = purpose;
2972 work_queue_add (peer->clear_node_queue, cnq);
2973 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002974 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002975 }
2976 return;
2977}
2978
2979void
Chris Caputo228da422009-07-18 05:44:03 +00002980bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2981 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002982{
2983 struct bgp_node *rn;
2984 struct bgp_table *table;
2985 struct peer *rsclient;
2986 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002987
Paul Jakma64e580a2006-02-21 01:09:01 +00002988 if (peer->clear_node_queue == NULL)
2989 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002990
Paul Jakmaca058a32006-09-14 02:58:49 +00002991 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2992 * Idle until it receives a Clearing_Completed event. This protects
2993 * against peers which flap faster than we can we clear, which could
2994 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002995 *
2996 * a) race with routes from the new session being installed before
2997 * clear_route_node visits the node (to delete the route of that
2998 * peer)
2999 * b) resource exhaustion, clear_route_node likely leads to an entry
3000 * on the process_main queue. Fast-flapping could cause that queue
3001 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003002 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003003
3004 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3005 * the unlock will happen upon work-queue completion; other wise, the
3006 * unlock happens at the end of this function.
3007 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003008 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003009 peer_lock (peer);
paulfee0f4c2004-09-13 05:12:46 +00003010
Chris Caputo228da422009-07-18 05:44:03 +00003011 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003012 {
Chris Caputo228da422009-07-18 05:44:03 +00003013 case BGP_CLEAR_ROUTE_NORMAL:
3014 if (safi != SAFI_MPLS_VPN)
3015 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3016 else
3017 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3018 rn = bgp_route_next (rn))
3019 if ((table = rn->info) != NULL)
3020 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3021
3022 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3023 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3024 PEER_FLAG_RSERVER_CLIENT))
3025 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3026 break;
3027
3028 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
3029 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3030 break;
3031
3032 default:
3033 assert (0);
3034 break;
paulfee0f4c2004-09-13 05:12:46 +00003035 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003036
3037 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003038 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003039 peer_unlock (peer);
3040
paul718e3742002-12-13 20:15:29 +00003041}
3042
3043void
3044bgp_clear_route_all (struct peer *peer)
3045{
3046 afi_t afi;
3047 safi_t safi;
3048
3049 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3050 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003051 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003052}
3053
Lou Berger82dd7072016-01-12 13:41:57 -05003054/*
3055 * Finish freeing things when exiting
3056 */
3057static void
3058bgp_drain_workqueue_immediate (struct work_queue *wq)
3059{
3060 if (!wq)
3061 return;
3062
3063 if (!wq->thread)
3064 {
3065 /*
3066 * no thread implies no queued items
3067 */
3068 assert(!wq->items->count);
3069 return;
3070 }
3071
3072 while (wq->items->count)
3073 {
3074 if (wq->thread)
3075 thread_cancel(wq->thread);
3076 work_queue_run(wq->thread);
3077 }
3078}
3079
3080/*
3081 * Special function to process clear node queue when bgpd is exiting
3082 * and the thread scheduler is no longer running.
3083 */
3084void
3085bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3086{
3087 if (!peer)
3088 return;
3089
3090 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3091}
3092
3093/*
3094 * The work queues are not specific to a BGP instance, but the
3095 * items in them refer to BGP instances, so this should be called
3096 * before each BGP instance is deleted.
3097 */
3098void
3099bgp_process_queues_drain_immediate(void)
3100{
3101 bgp_drain_workqueue_immediate(bm->process_main_queue);
3102 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3103}
3104
paul718e3742002-12-13 20:15:29 +00003105void
3106bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3107{
3108 struct bgp_table *table;
3109 struct bgp_node *rn;
3110 struct bgp_adj_in *ain;
3111
3112 table = peer->bgp->rib[afi][safi];
3113
3114 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3115 for (ain = rn->adj_in; ain ; ain = ain->next)
3116 if (ain->peer == peer)
3117 {
3118 bgp_adj_in_remove (rn, ain);
3119 bgp_unlock_node (rn);
3120 break;
3121 }
3122}
hasso93406d82005-02-02 14:40:33 +00003123
3124void
3125bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3126{
3127 struct bgp_node *rn;
3128 struct bgp_info *ri;
3129 struct bgp_table *table;
3130
3131 table = peer->bgp->rib[afi][safi];
3132
3133 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3134 {
3135 for (ri = rn->info; ri; ri = ri->next)
3136 if (ri->peer == peer)
3137 {
3138 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3139 bgp_rib_remove (rn, ri, peer, afi, safi);
3140 break;
3141 }
3142 }
3143}
David Lamparter6b0655a2014-06-04 06:53:35 +02003144
Lou Berger82dd7072016-01-12 13:41:57 -05003145static void
3146bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3147{
3148 struct bgp_node *rn;
3149 struct bgp_info *ri;
3150 struct bgp_info *next;
3151
3152 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3153 for (ri = rn->info; ri; ri = next)
3154 {
3155 next = ri->next;
3156 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3157 && ri->type == ZEBRA_ROUTE_BGP
3158 && ri->sub_type == BGP_ROUTE_NORMAL)
3159 bgp_zebra_withdraw (&rn->p, ri, safi);
3160 }
3161}
3162
paul718e3742002-12-13 20:15:29 +00003163/* Delete all kernel routes. */
3164void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003165bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003166{
3167 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003168 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003169 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003170
paul1eb8ef22005-04-07 07:30:20 +00003171 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003172 {
Lou Berger82dd7072016-01-12 13:41:57 -05003173 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3174 {
3175 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003176
Lou Berger82dd7072016-01-12 13:41:57 -05003177 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003178
Lou Berger82dd7072016-01-12 13:41:57 -05003179 /*
3180 * VPN and ENCAP tables are two-level (RD is top level)
3181 */
3182 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3183 rn = bgp_route_next (rn))
3184 if (rn->info)
3185 {
3186 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3187 bgp_table_finish ((struct bgp_table **)&(rn->info));
3188 rn->info = NULL;
3189 bgp_unlock_node(rn);
3190 }
3191 }
paul718e3742002-12-13 20:15:29 +00003192 }
3193}
3194
3195void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003196bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003197{
3198 vty_reset ();
3199 bgp_zclient_reset ();
3200 access_list_reset ();
3201 prefix_list_reset ();
3202}
David Lamparter6b0655a2014-06-04 06:53:35 +02003203
paul718e3742002-12-13 20:15:29 +00003204/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3205 value. */
3206int
3207bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3208{
3209 u_char *pnt;
3210 u_char *lim;
3211 struct prefix p;
3212 int psize;
3213 int ret;
3214
3215 /* Check peer status. */
3216 if (peer->status != Established)
3217 return 0;
3218
3219 pnt = packet->nlri;
3220 lim = pnt + packet->length;
3221
3222 for (; pnt < lim; pnt += psize)
3223 {
3224 /* Clear prefix structure. */
3225 memset (&p, 0, sizeof (struct prefix));
3226
3227 /* Fetch prefix length. */
3228 p.prefixlen = *pnt++;
3229 p.family = afi2family (packet->afi);
3230
3231 /* Already checked in nlri_sanity_check(). We do double check
3232 here. */
3233 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3234 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3235 return -1;
3236
3237 /* Packet size overflow check. */
3238 psize = PSIZE (p.prefixlen);
3239
3240 /* When packet overflow occur return immediately. */
3241 if (pnt + psize > lim)
3242 return -1;
3243
3244 /* Fetch prefix from NLRI packet. */
3245 memcpy (&p.u.prefix, pnt, psize);
3246
3247 /* Check address. */
3248 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3249 {
3250 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3251 {
paulf5ba3872004-07-09 12:11:31 +00003252 /*
3253 * From draft-ietf-idr-bgp4-22, Section 6.3:
3254 * If a BGP router receives an UPDATE message with a
3255 * semantically incorrect NLRI field, in which a prefix is
3256 * semantically incorrect (eg. an unexpected multicast IP
3257 * address), it should ignore the prefix.
3258 */
paul718e3742002-12-13 20:15:29 +00003259 zlog (peer->log, LOG_ERR,
3260 "IPv4 unicast NLRI is multicast address %s",
3261 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003262
paul718e3742002-12-13 20:15:29 +00003263 return -1;
3264 }
3265 }
3266
3267#ifdef HAVE_IPV6
3268 /* Check address. */
3269 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3270 {
3271 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3272 {
3273 char buf[BUFSIZ];
3274
3275 zlog (peer->log, LOG_WARNING,
3276 "IPv6 link-local NLRI received %s ignore this NLRI",
3277 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3278
3279 continue;
3280 }
3281 }
3282#endif /* HAVE_IPV6 */
3283
3284 /* Normal process. */
3285 if (attr)
3286 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3287 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3288 else
3289 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3290 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3291
3292 /* Address family configuration mismatch or maximum-prefix count
3293 overflow. */
3294 if (ret < 0)
3295 return -1;
3296 }
3297
3298 /* Packet length consistency check. */
3299 if (pnt != lim)
3300 return -1;
3301
3302 return 0;
3303}
3304
3305/* NLRI encode syntax check routine. */
3306int
3307bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3308 bgp_size_t length)
3309{
3310 u_char *end;
3311 u_char prefixlen;
3312 int psize;
3313
3314 end = pnt + length;
3315
3316 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3317 syntactic validity. If the field is syntactically incorrect,
3318 then the Error Subcode is set to Invalid Network Field. */
3319
3320 while (pnt < end)
3321 {
3322 prefixlen = *pnt++;
3323
3324 /* Prefix length check. */
3325 if ((afi == AFI_IP && prefixlen > 32)
3326 || (afi == AFI_IP6 && prefixlen > 128))
3327 {
3328 plog_err (peer->log,
3329 "%s [Error] Update packet error (wrong prefix length %d)",
3330 peer->host, prefixlen);
3331 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3332 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3333 return -1;
3334 }
3335
3336 /* Packet size overflow check. */
3337 psize = PSIZE (prefixlen);
3338
3339 if (pnt + psize > end)
3340 {
3341 plog_err (peer->log,
3342 "%s [Error] Update packet error"
3343 " (prefix data overflow prefix size is %d)",
3344 peer->host, psize);
3345 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3346 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3347 return -1;
3348 }
3349
3350 pnt += psize;
3351 }
3352
3353 /* Packet length consistency check. */
3354 if (pnt != end)
3355 {
3356 plog_err (peer->log,
3357 "%s [Error] Update packet error"
3358 " (prefix length mismatch with total length)",
3359 peer->host);
3360 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3361 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3362 return -1;
3363 }
3364 return 0;
3365}
David Lamparter6b0655a2014-06-04 06:53:35 +02003366
paul94f2b392005-06-28 12:44:16 +00003367static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003368bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003369{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003370 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003371}
3372
paul94f2b392005-06-28 12:44:16 +00003373static void
paul718e3742002-12-13 20:15:29 +00003374bgp_static_free (struct bgp_static *bgp_static)
3375{
3376 if (bgp_static->rmap.name)
3377 free (bgp_static->rmap.name);
3378 XFREE (MTYPE_BGP_STATIC, bgp_static);
3379}
3380
paul94f2b392005-06-28 12:44:16 +00003381static void
paulfee0f4c2004-09-13 05:12:46 +00003382bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3383 struct prefix *p, afi_t afi, safi_t safi)
3384{
3385 struct bgp_node *rn;
3386 struct bgp_info *ri;
3387
3388 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3389
3390 /* Check selected route and self inserted route. */
3391 for (ri = rn->info; ri; ri = ri->next)
3392 if (ri->peer == bgp->peer_self
3393 && ri->type == ZEBRA_ROUTE_BGP
3394 && ri->sub_type == BGP_ROUTE_STATIC)
3395 break;
3396
3397 /* Withdraw static BGP route from routing table. */
3398 if (ri)
3399 {
paulfee0f4c2004-09-13 05:12:46 +00003400 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003401 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003402 }
3403
3404 /* Unlock bgp_node_lookup. */
3405 bgp_unlock_node (rn);
3406}
3407
paul94f2b392005-06-28 12:44:16 +00003408static void
paulfee0f4c2004-09-13 05:12:46 +00003409bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003410 struct bgp_static *bgp_static,
3411 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003412{
3413 struct bgp_node *rn;
3414 struct bgp_info *ri;
3415 struct bgp_info *new;
3416 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003417 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003418 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003419 struct attr new_attr;
3420 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003421 struct bgp *bgp;
3422 int ret;
3423 char buf[SU_ADDRSTRLEN];
3424
3425 bgp = rsclient->bgp;
3426
Paul Jakma06e110f2006-05-12 23:29:22 +00003427 assert (bgp_static);
3428 if (!bgp_static)
3429 return;
3430
paulfee0f4c2004-09-13 05:12:46 +00003431 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3432
3433 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003434
3435 attr.nexthop = bgp_static->igpnexthop;
3436 attr.med = bgp_static->igpmetric;
3437 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003438
Paul Jakma41367172007-08-06 15:24:51 +00003439 if (bgp_static->atomic)
3440 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3441
paulfee0f4c2004-09-13 05:12:46 +00003442 /* Apply network route-map for export to this rsclient. */
3443 if (bgp_static->rmap.name)
3444 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003445 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003446 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003447 info.attr = &attr_tmp;
3448
paulfee0f4c2004-09-13 05:12:46 +00003449 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3450 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3451
3452 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3453
3454 rsclient->rmap_type = 0;
3455
3456 if (ret == RMAP_DENYMATCH)
3457 {
3458 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003459 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003460
3461 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003462 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003463 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003464 bgp_attr_extra_free (&attr);
3465
paulfee0f4c2004-09-13 05:12:46 +00003466 return;
3467 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003468 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003469 }
3470 else
3471 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003472
3473 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003474 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003475
paulfee0f4c2004-09-13 05:12:46 +00003476 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3477
Paul Jakmafb982c22007-05-04 20:15:47 +00003478 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3479 == RMAP_DENY)
3480 {
paulfee0f4c2004-09-13 05:12:46 +00003481 /* This BGP update is filtered. Log the reason then update BGP entry. */
3482 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003483 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003484 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3485 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3486 p->prefixlen, rsclient->host);
3487
3488 bgp->peer_self->rmap_type = 0;
3489
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003490 bgp_attr_unintern (&attr_new);
3491 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003492 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003493
3494 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3495
3496 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003497 }
paulfee0f4c2004-09-13 05:12:46 +00003498
3499 bgp->peer_self->rmap_type = 0;
3500
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003501 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003502 attr_new = bgp_attr_intern (&new_attr);
3503
3504 for (ri = rn->info; ri; ri = ri->next)
3505 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3506 && ri->sub_type == BGP_ROUTE_STATIC)
3507 break;
3508
3509 if (ri)
3510 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003511 if (attrhash_cmp (ri->attr, attr_new) &&
3512 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003513 {
3514 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003515 bgp_attr_unintern (&attr_new);
3516 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003517 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003518 return;
3519 }
3520 else
3521 {
3522 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003523 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003524
3525 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003526 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3527 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003528 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003529 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003530 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003531
3532 /* Process change. */
3533 bgp_process (bgp, rn, afi, safi);
3534 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003535 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003536 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003537 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003538 }
paulfee0f4c2004-09-13 05:12:46 +00003539 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003540
paulfee0f4c2004-09-13 05:12:46 +00003541 /* Make new BGP info. */
3542 new = bgp_info_new ();
3543 new->type = ZEBRA_ROUTE_BGP;
3544 new->sub_type = BGP_ROUTE_STATIC;
3545 new->peer = bgp->peer_self;
3546 SET_FLAG (new->flags, BGP_INFO_VALID);
3547 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003548 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003549
3550 /* Register new BGP information. */
3551 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003552
3553 /* route_node_get lock */
3554 bgp_unlock_node (rn);
3555
paulfee0f4c2004-09-13 05:12:46 +00003556 /* Process change. */
3557 bgp_process (bgp, rn, afi, safi);
3558
3559 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003560 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003561 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003562}
3563
paul94f2b392005-06-28 12:44:16 +00003564static void
paulfee0f4c2004-09-13 05:12:46 +00003565bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003566 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3567{
3568 struct bgp_node *rn;
3569 struct bgp_info *ri;
3570 struct bgp_info *new;
3571 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003572 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003573 struct attr *attr_new;
3574 int ret;
3575
Paul Jakmadd8103a2006-05-12 23:27:30 +00003576 assert (bgp_static);
3577 if (!bgp_static)
3578 return;
3579
paulfee0f4c2004-09-13 05:12:46 +00003580 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003581
3582 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003583
3584 attr.nexthop = bgp_static->igpnexthop;
3585 attr.med = bgp_static->igpmetric;
3586 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003587
Paul Jakma41367172007-08-06 15:24:51 +00003588 if (bgp_static->atomic)
3589 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3590
paul718e3742002-12-13 20:15:29 +00003591 /* Apply route-map. */
3592 if (bgp_static->rmap.name)
3593 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003594 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003595 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003596 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003597
paulfee0f4c2004-09-13 05:12:46 +00003598 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3599
paul718e3742002-12-13 20:15:29 +00003600 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003601
paulfee0f4c2004-09-13 05:12:46 +00003602 bgp->peer_self->rmap_type = 0;
3603
paul718e3742002-12-13 20:15:29 +00003604 if (ret == RMAP_DENYMATCH)
3605 {
3606 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003607 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003608
3609 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003610 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003611 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003612 bgp_static_withdraw (bgp, p, afi, safi);
3613 return;
3614 }
paul286e1e72003-08-08 00:24:31 +00003615 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003616 }
paul286e1e72003-08-08 00:24:31 +00003617 else
3618 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003619
3620 for (ri = rn->info; ri; ri = ri->next)
3621 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3622 && ri->sub_type == BGP_ROUTE_STATIC)
3623 break;
3624
3625 if (ri)
3626 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003627 if (attrhash_cmp (ri->attr, attr_new) &&
3628 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003629 {
3630 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003631 bgp_attr_unintern (&attr_new);
3632 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003633 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003634 return;
3635 }
3636 else
3637 {
3638 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003639 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003640
3641 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003642 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3643 bgp_info_restore(rn, ri);
3644 else
3645 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003646 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003647 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003648 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003649
3650 /* Process change. */
3651 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3652 bgp_process (bgp, rn, afi, safi);
3653 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003654 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003655 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003656 return;
3657 }
3658 }
3659
3660 /* Make new BGP info. */
3661 new = bgp_info_new ();
3662 new->type = ZEBRA_ROUTE_BGP;
3663 new->sub_type = BGP_ROUTE_STATIC;
3664 new->peer = bgp->peer_self;
3665 SET_FLAG (new->flags, BGP_INFO_VALID);
3666 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003667 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003668
3669 /* Aggregate address increment. */
3670 bgp_aggregate_increment (bgp, p, new, afi, safi);
3671
3672 /* Register new BGP information. */
3673 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003674
3675 /* route_node_get lock */
3676 bgp_unlock_node (rn);
3677
paul718e3742002-12-13 20:15:29 +00003678 /* Process change. */
3679 bgp_process (bgp, rn, afi, safi);
3680
3681 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003682 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003683 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003684}
3685
3686void
paulfee0f4c2004-09-13 05:12:46 +00003687bgp_static_update (struct bgp *bgp, struct prefix *p,
3688 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3689{
3690 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003691 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003692
3693 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3694
paul1eb8ef22005-04-07 07:30:20 +00003695 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003696 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003697 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3698 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003699 }
3700}
3701
paul718e3742002-12-13 20:15:29 +00003702void
3703bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3704 safi_t safi)
3705{
3706 struct bgp_node *rn;
3707 struct bgp_info *ri;
3708
paulfee0f4c2004-09-13 05:12:46 +00003709 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003710
3711 /* Check selected route and self inserted route. */
3712 for (ri = rn->info; ri; ri = ri->next)
3713 if (ri->peer == bgp->peer_self
3714 && ri->type == ZEBRA_ROUTE_BGP
3715 && ri->sub_type == BGP_ROUTE_STATIC)
3716 break;
3717
3718 /* Withdraw static BGP route from routing table. */
3719 if (ri)
3720 {
3721 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003722 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003723 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003724 }
3725
3726 /* Unlock bgp_node_lookup. */
3727 bgp_unlock_node (rn);
3728}
3729
3730void
paulfee0f4c2004-09-13 05:12:46 +00003731bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3732{
3733 struct bgp_static *bgp_static;
3734 struct bgp *bgp;
3735 struct bgp_node *rn;
3736 struct prefix *p;
3737
3738 bgp = rsclient->bgp;
3739
3740 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3741 if ((bgp_static = rn->info) != NULL)
3742 {
3743 p = &rn->p;
3744
3745 bgp_static_update_rsclient (rsclient, p, bgp_static,
3746 afi, safi);
3747 }
3748}
3749
Lou Bergera76d9ca2016-01-12 13:41:53 -05003750/*
3751 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3752 */
paul94f2b392005-06-28 12:44:16 +00003753static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003754bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3755 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003756{
3757 struct bgp_node *rn;
3758 struct bgp_info *ri;
3759
paulfee0f4c2004-09-13 05:12:46 +00003760 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003761
3762 /* Check selected route and self inserted route. */
3763 for (ri = rn->info; ri; ri = ri->next)
3764 if (ri->peer == bgp->peer_self
3765 && ri->type == ZEBRA_ROUTE_BGP
3766 && ri->sub_type == BGP_ROUTE_STATIC)
3767 break;
3768
3769 /* Withdraw static BGP route from routing table. */
3770 if (ri)
3771 {
3772 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003773 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003774 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003775 }
3776
3777 /* Unlock bgp_node_lookup. */
3778 bgp_unlock_node (rn);
3779}
3780
Lou Bergera76d9ca2016-01-12 13:41:53 -05003781static void
3782bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3783 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3784{
3785 struct bgp_node *rn;
3786 struct bgp_info *new;
3787 struct attr *attr_new;
3788 struct attr attr = { 0 };
3789 struct bgp_info *ri;
3790
3791 assert (bgp_static);
3792
3793 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3794
3795 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3796
3797 attr.nexthop = bgp_static->igpnexthop;
3798 attr.med = bgp_static->igpmetric;
3799 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3800
3801 /* Apply route-map. */
3802 if (bgp_static->rmap.name)
3803 {
3804 struct attr attr_tmp = attr;
3805 struct bgp_info info;
3806 int ret;
3807
3808 info.peer = bgp->peer_self;
3809 info.attr = &attr_tmp;
3810
3811 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3812
3813 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3814
3815 bgp->peer_self->rmap_type = 0;
3816
3817 if (ret == RMAP_DENYMATCH)
3818 {
3819 /* Free uninterned attribute. */
3820 bgp_attr_flush (&attr_tmp);
3821
3822 /* Unintern original. */
3823 aspath_unintern (&attr.aspath);
3824 bgp_attr_extra_free (&attr);
3825 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3826 bgp_static->tag);
3827 return;
3828 }
3829
3830 attr_new = bgp_attr_intern (&attr_tmp);
3831 }
3832 else
3833 {
3834 attr_new = bgp_attr_intern (&attr);
3835 }
3836
3837 for (ri = rn->info; ri; ri = ri->next)
3838 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3839 && ri->sub_type == BGP_ROUTE_STATIC)
3840 break;
3841
3842 if (ri)
3843 {
3844 if (attrhash_cmp (ri->attr, attr_new) &&
3845 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3846 {
3847 bgp_unlock_node (rn);
3848 bgp_attr_unintern (&attr_new);
3849 aspath_unintern (&attr.aspath);
3850 bgp_attr_extra_free (&attr);
3851 return;
3852 }
3853 else
3854 {
3855 /* The attribute is changed. */
3856 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3857
3858 /* Rewrite BGP route information. */
3859 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3860 bgp_info_restore(rn, ri);
3861 else
3862 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3863 bgp_attr_unintern (&ri->attr);
3864 ri->attr = attr_new;
3865 ri->uptime = bgp_clock ();
3866
3867 /* Process change. */
3868 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3869 bgp_process (bgp, rn, afi, safi);
3870 bgp_unlock_node (rn);
3871 aspath_unintern (&attr.aspath);
3872 bgp_attr_extra_free (&attr);
3873 return;
3874 }
3875 }
3876
3877
3878 /* Make new BGP info. */
3879 new = bgp_info_new ();
3880 new->type = ZEBRA_ROUTE_BGP;
3881 new->sub_type = BGP_ROUTE_STATIC;
3882 new->peer = bgp->peer_self;
3883 new->attr = attr_new;
3884 SET_FLAG (new->flags, BGP_INFO_VALID);
3885 new->uptime = bgp_clock ();
3886 new->extra = bgp_info_extra_new();
3887 memcpy (new->extra->tag, bgp_static->tag, 3);
3888
3889 /* Aggregate address increment. */
3890 bgp_aggregate_increment (bgp, p, new, afi, safi);
3891
3892 /* Register new BGP information. */
3893 bgp_info_add (rn, new);
3894
3895 /* route_node_get lock */
3896 bgp_unlock_node (rn);
3897
3898 /* Process change. */
3899 bgp_process (bgp, rn, afi, safi);
3900
3901 /* Unintern original. */
3902 aspath_unintern (&attr.aspath);
3903 bgp_attr_extra_free (&attr);
3904}
3905
paul718e3742002-12-13 20:15:29 +00003906/* Configure static BGP network. When user don't run zebra, static
3907 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003908static int
paulfd79ac92004-10-13 05:06:08 +00003909bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003910 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003911{
3912 int ret;
3913 struct prefix p;
3914 struct bgp_static *bgp_static;
3915 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003916 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003917
3918 /* Convert IP prefix string to struct prefix. */
3919 ret = str2prefix (ip_str, &p);
3920 if (! ret)
3921 {
3922 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3923 return CMD_WARNING;
3924 }
3925#ifdef HAVE_IPV6
3926 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3927 {
3928 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3929 VTY_NEWLINE);
3930 return CMD_WARNING;
3931 }
3932#endif /* HAVE_IPV6 */
3933
3934 apply_mask (&p);
3935
3936 /* Set BGP static route configuration. */
3937 rn = bgp_node_get (bgp->route[afi][safi], &p);
3938
3939 if (rn->info)
3940 {
3941 /* Configuration change. */
3942 bgp_static = rn->info;
3943
3944 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003945 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3946 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003947
paul718e3742002-12-13 20:15:29 +00003948 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003949
paul718e3742002-12-13 20:15:29 +00003950 if (rmap)
3951 {
3952 if (bgp_static->rmap.name)
3953 free (bgp_static->rmap.name);
3954 bgp_static->rmap.name = strdup (rmap);
3955 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3956 }
3957 else
3958 {
3959 if (bgp_static->rmap.name)
3960 free (bgp_static->rmap.name);
3961 bgp_static->rmap.name = NULL;
3962 bgp_static->rmap.map = NULL;
3963 bgp_static->valid = 0;
3964 }
3965 bgp_unlock_node (rn);
3966 }
3967 else
3968 {
3969 /* New configuration. */
3970 bgp_static = bgp_static_new ();
3971 bgp_static->backdoor = backdoor;
3972 bgp_static->valid = 0;
3973 bgp_static->igpmetric = 0;
3974 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003975
paul718e3742002-12-13 20:15:29 +00003976 if (rmap)
3977 {
3978 if (bgp_static->rmap.name)
3979 free (bgp_static->rmap.name);
3980 bgp_static->rmap.name = strdup (rmap);
3981 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3982 }
3983 rn->info = bgp_static;
3984 }
3985
3986 /* If BGP scan is not enabled, we should install this route here. */
3987 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3988 {
3989 bgp_static->valid = 1;
3990
3991 if (need_update)
3992 bgp_static_withdraw (bgp, &p, afi, safi);
3993
3994 if (! bgp_static->backdoor)
3995 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3996 }
3997
3998 return CMD_SUCCESS;
3999}
4000
4001/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00004002static int
paulfd79ac92004-10-13 05:06:08 +00004003bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04004004 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004005{
4006 int ret;
4007 struct prefix p;
4008 struct bgp_static *bgp_static;
4009 struct bgp_node *rn;
4010
4011 /* Convert IP prefix string to struct prefix. */
4012 ret = str2prefix (ip_str, &p);
4013 if (! ret)
4014 {
4015 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4016 return CMD_WARNING;
4017 }
4018#ifdef HAVE_IPV6
4019 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4020 {
4021 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4022 VTY_NEWLINE);
4023 return CMD_WARNING;
4024 }
4025#endif /* HAVE_IPV6 */
4026
4027 apply_mask (&p);
4028
4029 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4030 if (! rn)
4031 {
4032 vty_out (vty, "%% Can't find specified static route configuration.%s",
4033 VTY_NEWLINE);
4034 return CMD_WARNING;
4035 }
4036
4037 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004038
paul718e3742002-12-13 20:15:29 +00004039 /* Update BGP RIB. */
4040 if (! bgp_static->backdoor)
4041 bgp_static_withdraw (bgp, &p, afi, safi);
4042
4043 /* Clear configuration. */
4044 bgp_static_free (bgp_static);
4045 rn->info = NULL;
4046 bgp_unlock_node (rn);
4047 bgp_unlock_node (rn);
4048
4049 return CMD_SUCCESS;
4050}
4051
4052/* Called from bgp_delete(). Delete all static routes from the BGP
4053 instance. */
4054void
4055bgp_static_delete (struct bgp *bgp)
4056{
4057 afi_t afi;
4058 safi_t safi;
4059 struct bgp_node *rn;
4060 struct bgp_node *rm;
4061 struct bgp_table *table;
4062 struct bgp_static *bgp_static;
4063
4064 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4065 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4066 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4067 if (rn->info != NULL)
4068 {
4069 if (safi == SAFI_MPLS_VPN)
4070 {
4071 table = rn->info;
4072
4073 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4074 {
4075 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004076 bgp_static_withdraw_safi (bgp, &rm->p,
4077 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004078 (struct prefix_rd *)&rn->p,
4079 bgp_static->tag);
4080 bgp_static_free (bgp_static);
4081 rn->info = NULL;
4082 bgp_unlock_node (rn);
4083 }
4084 }
4085 else
4086 {
4087 bgp_static = rn->info;
4088 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4089 bgp_static_free (bgp_static);
4090 rn->info = NULL;
4091 bgp_unlock_node (rn);
4092 }
4093 }
4094}
4095
Lou Bergera76d9ca2016-01-12 13:41:53 -05004096/*
4097 * gpz 110624
4098 * Currently this is used to set static routes for VPN and ENCAP.
4099 * I think it can probably be factored with bgp_static_set.
4100 */
paul718e3742002-12-13 20:15:29 +00004101int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004102bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4103 const char *rd_str, const char *tag_str,
4104 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004105{
4106 int ret;
4107 struct prefix p;
4108 struct prefix_rd prd;
4109 struct bgp *bgp;
4110 struct bgp_node *prn;
4111 struct bgp_node *rn;
4112 struct bgp_table *table;
4113 struct bgp_static *bgp_static;
4114 u_char tag[3];
4115
4116 bgp = vty->index;
4117
4118 ret = str2prefix (ip_str, &p);
4119 if (! ret)
4120 {
4121 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4122 return CMD_WARNING;
4123 }
4124 apply_mask (&p);
4125
4126 ret = str2prefix_rd (rd_str, &prd);
4127 if (! ret)
4128 {
4129 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4130 return CMD_WARNING;
4131 }
4132
4133 ret = str2tag (tag_str, tag);
4134 if (! ret)
4135 {
4136 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4137 return CMD_WARNING;
4138 }
4139
Lou Bergera76d9ca2016-01-12 13:41:53 -05004140 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004141 (struct prefix *)&prd);
4142 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004143 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004144 else
4145 bgp_unlock_node (prn);
4146 table = prn->info;
4147
4148 rn = bgp_node_get (table, &p);
4149
4150 if (rn->info)
4151 {
4152 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4153 bgp_unlock_node (rn);
4154 }
4155 else
4156 {
4157 /* New configuration. */
4158 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004159 bgp_static->backdoor = 0;
4160 bgp_static->valid = 0;
4161 bgp_static->igpmetric = 0;
4162 bgp_static->igpnexthop.s_addr = 0;
4163 memcpy(bgp_static->tag, tag, 3);
4164 bgp_static->prd = prd;
4165
4166 if (rmap_str)
4167 {
4168 if (bgp_static->rmap.name)
4169 free (bgp_static->rmap.name);
4170 bgp_static->rmap.name = strdup (rmap_str);
4171 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4172 }
paul718e3742002-12-13 20:15:29 +00004173 rn->info = bgp_static;
4174
Lou Bergera76d9ca2016-01-12 13:41:53 -05004175 bgp_static->valid = 1;
4176 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004177 }
4178
4179 return CMD_SUCCESS;
4180}
4181
4182/* Configure static BGP network. */
4183int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004184bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4185 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004186{
4187 int ret;
4188 struct bgp *bgp;
4189 struct prefix p;
4190 struct prefix_rd prd;
4191 struct bgp_node *prn;
4192 struct bgp_node *rn;
4193 struct bgp_table *table;
4194 struct bgp_static *bgp_static;
4195 u_char tag[3];
4196
4197 bgp = vty->index;
4198
4199 /* Convert IP prefix string to struct prefix. */
4200 ret = str2prefix (ip_str, &p);
4201 if (! ret)
4202 {
4203 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4204 return CMD_WARNING;
4205 }
4206 apply_mask (&p);
4207
4208 ret = str2prefix_rd (rd_str, &prd);
4209 if (! ret)
4210 {
4211 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4212 return CMD_WARNING;
4213 }
4214
4215 ret = str2tag (tag_str, tag);
4216 if (! ret)
4217 {
4218 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4219 return CMD_WARNING;
4220 }
4221
Lou Bergera76d9ca2016-01-12 13:41:53 -05004222 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004223 (struct prefix *)&prd);
4224 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004225 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004226 else
4227 bgp_unlock_node (prn);
4228 table = prn->info;
4229
4230 rn = bgp_node_lookup (table, &p);
4231
4232 if (rn)
4233 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004234 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004235
4236 bgp_static = rn->info;
4237 bgp_static_free (bgp_static);
4238 rn->info = NULL;
4239 bgp_unlock_node (rn);
4240 bgp_unlock_node (rn);
4241 }
4242 else
4243 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4244
4245 return CMD_SUCCESS;
4246}
David Lamparter6b0655a2014-06-04 06:53:35 +02004247
paul718e3742002-12-13 20:15:29 +00004248DEFUN (bgp_network,
4249 bgp_network_cmd,
4250 "network A.B.C.D/M",
4251 "Specify a network to announce via BGP\n"
4252 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4253{
4254 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004255 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004256}
4257
4258DEFUN (bgp_network_route_map,
4259 bgp_network_route_map_cmd,
4260 "network A.B.C.D/M route-map WORD",
4261 "Specify a network to announce via BGP\n"
4262 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4263 "Route-map to modify the attributes\n"
4264 "Name of the route map\n")
4265{
4266 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004267 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004268}
4269
4270DEFUN (bgp_network_backdoor,
4271 bgp_network_backdoor_cmd,
4272 "network A.B.C.D/M backdoor",
4273 "Specify a network to announce via BGP\n"
4274 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4275 "Specify a BGP backdoor route\n")
4276{
Paul Jakma41367172007-08-06 15:24:51 +00004277 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004278 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004279}
4280
4281DEFUN (bgp_network_mask,
4282 bgp_network_mask_cmd,
4283 "network A.B.C.D mask A.B.C.D",
4284 "Specify a network to announce via BGP\n"
4285 "Network number\n"
4286 "Network mask\n"
4287 "Network mask\n")
4288{
4289 int ret;
4290 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004291
paul718e3742002-12-13 20:15:29 +00004292 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4293 if (! ret)
4294 {
4295 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4296 return CMD_WARNING;
4297 }
4298
4299 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004300 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004301}
4302
4303DEFUN (bgp_network_mask_route_map,
4304 bgp_network_mask_route_map_cmd,
4305 "network A.B.C.D mask A.B.C.D route-map WORD",
4306 "Specify a network to announce via BGP\n"
4307 "Network number\n"
4308 "Network mask\n"
4309 "Network mask\n"
4310 "Route-map to modify the attributes\n"
4311 "Name of the route map\n")
4312{
4313 int ret;
4314 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004315
paul718e3742002-12-13 20:15:29 +00004316 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4317 if (! ret)
4318 {
4319 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4320 return CMD_WARNING;
4321 }
4322
4323 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004324 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004325}
4326
4327DEFUN (bgp_network_mask_backdoor,
4328 bgp_network_mask_backdoor_cmd,
4329 "network A.B.C.D mask A.B.C.D backdoor",
4330 "Specify a network to announce via BGP\n"
4331 "Network number\n"
4332 "Network mask\n"
4333 "Network mask\n"
4334 "Specify a BGP backdoor route\n")
4335{
4336 int ret;
4337 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004338
paul718e3742002-12-13 20:15:29 +00004339 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4340 if (! ret)
4341 {
4342 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4343 return CMD_WARNING;
4344 }
4345
Paul Jakma41367172007-08-06 15:24:51 +00004346 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004347 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004348}
4349
4350DEFUN (bgp_network_mask_natural,
4351 bgp_network_mask_natural_cmd,
4352 "network A.B.C.D",
4353 "Specify a network to announce via BGP\n"
4354 "Network number\n")
4355{
4356 int ret;
4357 char prefix_str[BUFSIZ];
4358
4359 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4360 if (! ret)
4361 {
4362 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4363 return CMD_WARNING;
4364 }
4365
4366 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004367 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004368}
4369
4370DEFUN (bgp_network_mask_natural_route_map,
4371 bgp_network_mask_natural_route_map_cmd,
4372 "network A.B.C.D route-map WORD",
4373 "Specify a network to announce via BGP\n"
4374 "Network number\n"
4375 "Route-map to modify the attributes\n"
4376 "Name of the route map\n")
4377{
4378 int ret;
4379 char prefix_str[BUFSIZ];
4380
4381 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4382 if (! ret)
4383 {
4384 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4385 return CMD_WARNING;
4386 }
4387
4388 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004389 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004390}
4391
4392DEFUN (bgp_network_mask_natural_backdoor,
4393 bgp_network_mask_natural_backdoor_cmd,
4394 "network A.B.C.D backdoor",
4395 "Specify a network to announce via BGP\n"
4396 "Network number\n"
4397 "Specify a BGP backdoor route\n")
4398{
4399 int ret;
4400 char prefix_str[BUFSIZ];
4401
4402 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4403 if (! ret)
4404 {
4405 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4406 return CMD_WARNING;
4407 }
4408
Paul Jakma41367172007-08-06 15:24:51 +00004409 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004410 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004411}
4412
4413DEFUN (no_bgp_network,
4414 no_bgp_network_cmd,
4415 "no network A.B.C.D/M",
4416 NO_STR
4417 "Specify a network to announce via BGP\n"
4418 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4419{
4420 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4421 bgp_node_safi (vty));
4422}
4423
4424ALIAS (no_bgp_network,
4425 no_bgp_network_route_map_cmd,
4426 "no network A.B.C.D/M route-map WORD",
4427 NO_STR
4428 "Specify a network to announce via BGP\n"
4429 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4430 "Route-map to modify the attributes\n"
4431 "Name of the route map\n")
4432
4433ALIAS (no_bgp_network,
4434 no_bgp_network_backdoor_cmd,
4435 "no network A.B.C.D/M backdoor",
4436 NO_STR
4437 "Specify a network to announce via BGP\n"
4438 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4439 "Specify a BGP backdoor route\n")
4440
4441DEFUN (no_bgp_network_mask,
4442 no_bgp_network_mask_cmd,
4443 "no network A.B.C.D mask A.B.C.D",
4444 NO_STR
4445 "Specify a network to announce via BGP\n"
4446 "Network number\n"
4447 "Network mask\n"
4448 "Network mask\n")
4449{
4450 int ret;
4451 char prefix_str[BUFSIZ];
4452
4453 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4454 if (! ret)
4455 {
4456 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4457 return CMD_WARNING;
4458 }
4459
4460 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4461 bgp_node_safi (vty));
4462}
4463
4464ALIAS (no_bgp_network_mask,
4465 no_bgp_network_mask_route_map_cmd,
4466 "no network A.B.C.D mask A.B.C.D route-map WORD",
4467 NO_STR
4468 "Specify a network to announce via BGP\n"
4469 "Network number\n"
4470 "Network mask\n"
4471 "Network mask\n"
4472 "Route-map to modify the attributes\n"
4473 "Name of the route map\n")
4474
4475ALIAS (no_bgp_network_mask,
4476 no_bgp_network_mask_backdoor_cmd,
4477 "no network A.B.C.D mask A.B.C.D backdoor",
4478 NO_STR
4479 "Specify a network to announce via BGP\n"
4480 "Network number\n"
4481 "Network mask\n"
4482 "Network mask\n"
4483 "Specify a BGP backdoor route\n")
4484
4485DEFUN (no_bgp_network_mask_natural,
4486 no_bgp_network_mask_natural_cmd,
4487 "no network A.B.C.D",
4488 NO_STR
4489 "Specify a network to announce via BGP\n"
4490 "Network number\n")
4491{
4492 int ret;
4493 char prefix_str[BUFSIZ];
4494
4495 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4496 if (! ret)
4497 {
4498 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4499 return CMD_WARNING;
4500 }
4501
4502 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4503 bgp_node_safi (vty));
4504}
4505
4506ALIAS (no_bgp_network_mask_natural,
4507 no_bgp_network_mask_natural_route_map_cmd,
4508 "no network A.B.C.D route-map WORD",
4509 NO_STR
4510 "Specify a network to announce via BGP\n"
4511 "Network number\n"
4512 "Route-map to modify the attributes\n"
4513 "Name of the route map\n")
4514
4515ALIAS (no_bgp_network_mask_natural,
4516 no_bgp_network_mask_natural_backdoor_cmd,
4517 "no network A.B.C.D backdoor",
4518 NO_STR
4519 "Specify a network to announce via BGP\n"
4520 "Network number\n"
4521 "Specify a BGP backdoor route\n")
4522
4523#ifdef HAVE_IPV6
4524DEFUN (ipv6_bgp_network,
4525 ipv6_bgp_network_cmd,
4526 "network X:X::X:X/M",
4527 "Specify a network to announce via BGP\n"
4528 "IPv6 prefix <network>/<length>\n")
4529{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304530 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004531 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004532}
4533
4534DEFUN (ipv6_bgp_network_route_map,
4535 ipv6_bgp_network_route_map_cmd,
4536 "network X:X::X:X/M route-map WORD",
4537 "Specify a network to announce via BGP\n"
4538 "IPv6 prefix <network>/<length>\n"
4539 "Route-map to modify the attributes\n"
4540 "Name of the route map\n")
4541{
4542 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004543 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004544}
4545
4546DEFUN (no_ipv6_bgp_network,
4547 no_ipv6_bgp_network_cmd,
4548 "no network X:X::X:X/M",
4549 NO_STR
4550 "Specify a network to announce via BGP\n"
4551 "IPv6 prefix <network>/<length>\n")
4552{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304553 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004554}
4555
4556ALIAS (no_ipv6_bgp_network,
4557 no_ipv6_bgp_network_route_map_cmd,
4558 "no network X:X::X:X/M route-map WORD",
4559 NO_STR
4560 "Specify a network to announce via BGP\n"
4561 "IPv6 prefix <network>/<length>\n"
4562 "Route-map to modify the attributes\n"
4563 "Name of the route map\n")
4564
4565ALIAS (ipv6_bgp_network,
4566 old_ipv6_bgp_network_cmd,
4567 "ipv6 bgp network X:X::X:X/M",
4568 IPV6_STR
4569 BGP_STR
4570 "Specify a network to announce via BGP\n"
4571 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4572
4573ALIAS (no_ipv6_bgp_network,
4574 old_no_ipv6_bgp_network_cmd,
4575 "no ipv6 bgp network X:X::X:X/M",
4576 NO_STR
4577 IPV6_STR
4578 BGP_STR
4579 "Specify a network to announce via BGP\n"
4580 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4581#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004582
4583/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4584ALIAS_DEPRECATED (bgp_network,
4585 bgp_network_ttl_cmd,
4586 "network A.B.C.D/M pathlimit <0-255>",
4587 "Specify a network to announce via BGP\n"
4588 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4589 "AS-Path hopcount limit attribute\n"
4590 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4591ALIAS_DEPRECATED (bgp_network_backdoor,
4592 bgp_network_backdoor_ttl_cmd,
4593 "network A.B.C.D/M backdoor pathlimit <0-255>",
4594 "Specify a network to announce via BGP\n"
4595 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4596 "Specify a BGP backdoor route\n"
4597 "AS-Path hopcount limit attribute\n"
4598 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4599ALIAS_DEPRECATED (bgp_network_mask,
4600 bgp_network_mask_ttl_cmd,
4601 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4602 "Specify a network to announce via BGP\n"
4603 "Network number\n"
4604 "Network mask\n"
4605 "Network mask\n"
4606 "AS-Path hopcount limit attribute\n"
4607 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4608ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4609 bgp_network_mask_backdoor_ttl_cmd,
4610 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4611 "Specify a network to announce via BGP\n"
4612 "Network number\n"
4613 "Network mask\n"
4614 "Network mask\n"
4615 "Specify a BGP backdoor route\n"
4616 "AS-Path hopcount limit attribute\n"
4617 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4618ALIAS_DEPRECATED (bgp_network_mask_natural,
4619 bgp_network_mask_natural_ttl_cmd,
4620 "network A.B.C.D pathlimit <0-255>",
4621 "Specify a network to announce via BGP\n"
4622 "Network number\n"
4623 "AS-Path hopcount limit attribute\n"
4624 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4625ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4626 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004627 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004628 "Specify a network to announce via BGP\n"
4629 "Network number\n"
4630 "Specify a BGP backdoor route\n"
4631 "AS-Path hopcount limit attribute\n"
4632 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4633ALIAS_DEPRECATED (no_bgp_network,
4634 no_bgp_network_ttl_cmd,
4635 "no network A.B.C.D/M pathlimit <0-255>",
4636 NO_STR
4637 "Specify a network to announce via BGP\n"
4638 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4639 "AS-Path hopcount limit attribute\n"
4640 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4641ALIAS_DEPRECATED (no_bgp_network,
4642 no_bgp_network_backdoor_ttl_cmd,
4643 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4644 NO_STR
4645 "Specify a network to announce via BGP\n"
4646 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4647 "Specify a BGP backdoor route\n"
4648 "AS-Path hopcount limit attribute\n"
4649 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4650ALIAS_DEPRECATED (no_bgp_network,
4651 no_bgp_network_mask_ttl_cmd,
4652 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4653 NO_STR
4654 "Specify a network to announce via BGP\n"
4655 "Network number\n"
4656 "Network mask\n"
4657 "Network mask\n"
4658 "AS-Path hopcount limit attribute\n"
4659 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4660ALIAS_DEPRECATED (no_bgp_network_mask,
4661 no_bgp_network_mask_backdoor_ttl_cmd,
4662 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4663 NO_STR
4664 "Specify a network to announce via BGP\n"
4665 "Network number\n"
4666 "Network mask\n"
4667 "Network mask\n"
4668 "Specify a BGP backdoor route\n"
4669 "AS-Path hopcount limit attribute\n"
4670 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4671ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4672 no_bgp_network_mask_natural_ttl_cmd,
4673 "no network A.B.C.D pathlimit <0-255>",
4674 NO_STR
4675 "Specify a network to announce via BGP\n"
4676 "Network number\n"
4677 "AS-Path hopcount limit attribute\n"
4678 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4679ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4680 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4681 "no network A.B.C.D backdoor pathlimit <0-255>",
4682 NO_STR
4683 "Specify a network to announce via BGP\n"
4684 "Network number\n"
4685 "Specify a BGP backdoor route\n"
4686 "AS-Path hopcount limit attribute\n"
4687 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004688#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004689ALIAS_DEPRECATED (ipv6_bgp_network,
4690 ipv6_bgp_network_ttl_cmd,
4691 "network X:X::X:X/M pathlimit <0-255>",
4692 "Specify a network to announce via BGP\n"
4693 "IPv6 prefix <network>/<length>\n"
4694 "AS-Path hopcount limit attribute\n"
4695 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4696ALIAS_DEPRECATED (no_ipv6_bgp_network,
4697 no_ipv6_bgp_network_ttl_cmd,
4698 "no network X:X::X:X/M pathlimit <0-255>",
4699 NO_STR
4700 "Specify a network to announce via BGP\n"
4701 "IPv6 prefix <network>/<length>\n"
4702 "AS-Path hopcount limit attribute\n"
4703 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004704#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004705
paul718e3742002-12-13 20:15:29 +00004706/* Aggreagete address:
4707
4708 advertise-map Set condition to advertise attribute
4709 as-set Generate AS set path information
4710 attribute-map Set attributes of aggregate
4711 route-map Set parameters of aggregate
4712 summary-only Filter more specific routes from updates
4713 suppress-map Conditionally filter more specific routes from updates
4714 <cr>
4715 */
4716struct bgp_aggregate
4717{
4718 /* Summary-only flag. */
4719 u_char summary_only;
4720
4721 /* AS set generation. */
4722 u_char as_set;
4723
4724 /* Route-map for aggregated route. */
4725 struct route_map *map;
4726
4727 /* Suppress-count. */
4728 unsigned long count;
4729
4730 /* SAFI configuration. */
4731 safi_t safi;
4732};
4733
paul94f2b392005-06-28 12:44:16 +00004734static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004735bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004736{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004737 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004738}
4739
paul94f2b392005-06-28 12:44:16 +00004740static void
paul718e3742002-12-13 20:15:29 +00004741bgp_aggregate_free (struct bgp_aggregate *aggregate)
4742{
4743 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4744}
4745
paul94f2b392005-06-28 12:44:16 +00004746static void
paul718e3742002-12-13 20:15:29 +00004747bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4748 afi_t afi, safi_t safi, struct bgp_info *del,
4749 struct bgp_aggregate *aggregate)
4750{
4751 struct bgp_table *table;
4752 struct bgp_node *top;
4753 struct bgp_node *rn;
4754 u_char origin;
4755 struct aspath *aspath = NULL;
4756 struct aspath *asmerge = NULL;
4757 struct community *community = NULL;
4758 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004759 struct bgp_info *ri;
4760 struct bgp_info *new;
4761 int first = 1;
4762 unsigned long match = 0;
4763
paul718e3742002-12-13 20:15:29 +00004764 /* ORIGIN attribute: If at least one route among routes that are
4765 aggregated has ORIGIN with the value INCOMPLETE, then the
4766 aggregated route must have the ORIGIN attribute with the value
4767 INCOMPLETE. Otherwise, if at least one route among routes that
4768 are aggregated has ORIGIN with the value EGP, then the aggregated
4769 route must have the origin attribute with the value EGP. In all
4770 other case the value of the ORIGIN attribute of the aggregated
4771 route is INTERNAL. */
4772 origin = BGP_ORIGIN_IGP;
4773
4774 table = bgp->rib[afi][safi];
4775
4776 top = bgp_node_get (table, p);
4777 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4778 if (rn->p.prefixlen > p->prefixlen)
4779 {
4780 match = 0;
4781
4782 for (ri = rn->info; ri; ri = ri->next)
4783 {
4784 if (BGP_INFO_HOLDDOWN (ri))
4785 continue;
4786
4787 if (del && ri == del)
4788 continue;
4789
4790 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004791 first = 0;
paul718e3742002-12-13 20:15:29 +00004792
4793#ifdef AGGREGATE_NEXTHOP_CHECK
4794 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4795 || ri->attr->med != med)
4796 {
4797 if (aspath)
4798 aspath_free (aspath);
4799 if (community)
4800 community_free (community);
4801 bgp_unlock_node (rn);
4802 bgp_unlock_node (top);
4803 return;
4804 }
4805#endif /* AGGREGATE_NEXTHOP_CHECK */
4806
4807 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4808 {
4809 if (aggregate->summary_only)
4810 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004811 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004812 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004813 match++;
4814 }
4815
4816 aggregate->count++;
4817
4818 if (aggregate->as_set)
4819 {
4820 if (origin < ri->attr->origin)
4821 origin = ri->attr->origin;
4822
4823 if (aspath)
4824 {
4825 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4826 aspath_free (aspath);
4827 aspath = asmerge;
4828 }
4829 else
4830 aspath = aspath_dup (ri->attr->aspath);
4831
4832 if (ri->attr->community)
4833 {
4834 if (community)
4835 {
4836 commerge = community_merge (community,
4837 ri->attr->community);
4838 community = community_uniq_sort (commerge);
4839 community_free (commerge);
4840 }
4841 else
4842 community = community_dup (ri->attr->community);
4843 }
4844 }
4845 }
4846 }
4847 if (match)
4848 bgp_process (bgp, rn, afi, safi);
4849 }
4850 bgp_unlock_node (top);
4851
4852 if (rinew)
4853 {
4854 aggregate->count++;
4855
4856 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004857 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004858
4859 if (aggregate->as_set)
4860 {
4861 if (origin < rinew->attr->origin)
4862 origin = rinew->attr->origin;
4863
4864 if (aspath)
4865 {
4866 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4867 aspath_free (aspath);
4868 aspath = asmerge;
4869 }
4870 else
4871 aspath = aspath_dup (rinew->attr->aspath);
4872
4873 if (rinew->attr->community)
4874 {
4875 if (community)
4876 {
4877 commerge = community_merge (community,
4878 rinew->attr->community);
4879 community = community_uniq_sort (commerge);
4880 community_free (commerge);
4881 }
4882 else
4883 community = community_dup (rinew->attr->community);
4884 }
4885 }
4886 }
4887
4888 if (aggregate->count > 0)
4889 {
4890 rn = bgp_node_get (table, p);
4891 new = bgp_info_new ();
4892 new->type = ZEBRA_ROUTE_BGP;
4893 new->sub_type = BGP_ROUTE_AGGREGATE;
4894 new->peer = bgp->peer_self;
4895 SET_FLAG (new->flags, BGP_INFO_VALID);
4896 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004897 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004898
4899 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004900 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004901 bgp_process (bgp, rn, afi, safi);
4902 }
4903 else
4904 {
4905 if (aspath)
4906 aspath_free (aspath);
4907 if (community)
4908 community_free (community);
4909 }
4910}
4911
4912void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4913 struct bgp_aggregate *);
4914
4915void
4916bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4917 struct bgp_info *ri, afi_t afi, safi_t safi)
4918{
4919 struct bgp_node *child;
4920 struct bgp_node *rn;
4921 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004922 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004923
4924 /* MPLS-VPN aggregation is not yet supported. */
4925 if (safi == SAFI_MPLS_VPN)
4926 return;
4927
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004928 table = bgp->aggregate[afi][safi];
4929
4930 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004931 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004932 return;
4933
paul718e3742002-12-13 20:15:29 +00004934 if (p->prefixlen == 0)
4935 return;
4936
4937 if (BGP_INFO_HOLDDOWN (ri))
4938 return;
4939
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004940 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004941
4942 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004943 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004944 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4945 {
4946 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004947 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004948 }
4949 bgp_unlock_node (child);
4950}
4951
4952void
4953bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4954 struct bgp_info *del, afi_t afi, safi_t safi)
4955{
4956 struct bgp_node *child;
4957 struct bgp_node *rn;
4958 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004959 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004960
4961 /* MPLS-VPN aggregation is not yet supported. */
4962 if (safi == SAFI_MPLS_VPN)
4963 return;
4964
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004965 table = bgp->aggregate[afi][safi];
4966
4967 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004968 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004969 return;
4970
paul718e3742002-12-13 20:15:29 +00004971 if (p->prefixlen == 0)
4972 return;
4973
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004974 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004975
4976 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004977 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004978 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4979 {
4980 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004981 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004982 }
4983 bgp_unlock_node (child);
4984}
4985
paul94f2b392005-06-28 12:44:16 +00004986static void
paul718e3742002-12-13 20:15:29 +00004987bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4988 struct bgp_aggregate *aggregate)
4989{
4990 struct bgp_table *table;
4991 struct bgp_node *top;
4992 struct bgp_node *rn;
4993 struct bgp_info *new;
4994 struct bgp_info *ri;
4995 unsigned long match;
4996 u_char origin = BGP_ORIGIN_IGP;
4997 struct aspath *aspath = NULL;
4998 struct aspath *asmerge = NULL;
4999 struct community *community = NULL;
5000 struct community *commerge = NULL;
5001
5002 table = bgp->rib[afi][safi];
5003
5004 /* Sanity check. */
5005 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5006 return;
5007 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5008 return;
5009
5010 /* If routes exists below this node, generate aggregate routes. */
5011 top = bgp_node_get (table, p);
5012 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5013 if (rn->p.prefixlen > p->prefixlen)
5014 {
5015 match = 0;
5016
5017 for (ri = rn->info; ri; ri = ri->next)
5018 {
5019 if (BGP_INFO_HOLDDOWN (ri))
5020 continue;
5021
5022 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5023 {
5024 /* summary-only aggregate route suppress aggregated
5025 route announcement. */
5026 if (aggregate->summary_only)
5027 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005028 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005029 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005030 match++;
5031 }
5032 /* as-set aggregate route generate origin, as path,
5033 community aggregation. */
5034 if (aggregate->as_set)
5035 {
5036 if (origin < ri->attr->origin)
5037 origin = ri->attr->origin;
5038
5039 if (aspath)
5040 {
5041 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5042 aspath_free (aspath);
5043 aspath = asmerge;
5044 }
5045 else
5046 aspath = aspath_dup (ri->attr->aspath);
5047
5048 if (ri->attr->community)
5049 {
5050 if (community)
5051 {
5052 commerge = community_merge (community,
5053 ri->attr->community);
5054 community = community_uniq_sort (commerge);
5055 community_free (commerge);
5056 }
5057 else
5058 community = community_dup (ri->attr->community);
5059 }
5060 }
5061 aggregate->count++;
5062 }
5063 }
5064
5065 /* If this node is suppressed, process the change. */
5066 if (match)
5067 bgp_process (bgp, rn, afi, safi);
5068 }
5069 bgp_unlock_node (top);
5070
5071 /* Add aggregate route to BGP table. */
5072 if (aggregate->count)
5073 {
5074 rn = bgp_node_get (table, p);
5075
5076 new = bgp_info_new ();
5077 new->type = ZEBRA_ROUTE_BGP;
5078 new->sub_type = BGP_ROUTE_AGGREGATE;
5079 new->peer = bgp->peer_self;
5080 SET_FLAG (new->flags, BGP_INFO_VALID);
5081 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03005082 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005083
5084 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005085 bgp_unlock_node (rn);
5086
paul718e3742002-12-13 20:15:29 +00005087 /* Process change. */
5088 bgp_process (bgp, rn, afi, safi);
5089 }
Denil Virae2a92582015-08-11 13:34:59 -07005090 else
5091 {
5092 if (aspath)
5093 aspath_free (aspath);
5094 if (community)
5095 community_free (community);
5096 }
paul718e3742002-12-13 20:15:29 +00005097}
5098
5099void
5100bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5101 safi_t safi, struct bgp_aggregate *aggregate)
5102{
5103 struct bgp_table *table;
5104 struct bgp_node *top;
5105 struct bgp_node *rn;
5106 struct bgp_info *ri;
5107 unsigned long match;
5108
5109 table = bgp->rib[afi][safi];
5110
5111 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5112 return;
5113 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5114 return;
5115
5116 /* If routes exists below this node, generate aggregate routes. */
5117 top = bgp_node_get (table, p);
5118 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5119 if (rn->p.prefixlen > p->prefixlen)
5120 {
5121 match = 0;
5122
5123 for (ri = rn->info; ri; ri = ri->next)
5124 {
5125 if (BGP_INFO_HOLDDOWN (ri))
5126 continue;
5127
5128 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5129 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005130 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005131 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005132 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005133
Paul Jakmafb982c22007-05-04 20:15:47 +00005134 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005135 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005136 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005137 match++;
5138 }
5139 }
5140 aggregate->count--;
5141 }
5142 }
5143
Paul Jakmafb982c22007-05-04 20:15:47 +00005144 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005145 if (match)
5146 bgp_process (bgp, rn, afi, safi);
5147 }
5148 bgp_unlock_node (top);
5149
5150 /* Delete aggregate route from BGP table. */
5151 rn = bgp_node_get (table, p);
5152
5153 for (ri = rn->info; ri; ri = ri->next)
5154 if (ri->peer == bgp->peer_self
5155 && ri->type == ZEBRA_ROUTE_BGP
5156 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5157 break;
5158
5159 /* Withdraw static BGP route from routing table. */
5160 if (ri)
5161 {
paul718e3742002-12-13 20:15:29 +00005162 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005163 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005164 }
5165
5166 /* Unlock bgp_node_lookup. */
5167 bgp_unlock_node (rn);
5168}
5169
5170/* Aggregate route attribute. */
5171#define AGGREGATE_SUMMARY_ONLY 1
5172#define AGGREGATE_AS_SET 1
5173
paul94f2b392005-06-28 12:44:16 +00005174static int
Robert Baysf6269b42010-08-05 10:26:28 -07005175bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5176 afi_t afi, safi_t safi)
5177{
5178 int ret;
5179 struct prefix p;
5180 struct bgp_node *rn;
5181 struct bgp *bgp;
5182 struct bgp_aggregate *aggregate;
5183
5184 /* Convert string to prefix structure. */
5185 ret = str2prefix (prefix_str, &p);
5186 if (!ret)
5187 {
5188 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5189 return CMD_WARNING;
5190 }
5191 apply_mask (&p);
5192
5193 /* Get BGP structure. */
5194 bgp = vty->index;
5195
5196 /* Old configuration check. */
5197 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5198 if (! rn)
5199 {
5200 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5201 VTY_NEWLINE);
5202 return CMD_WARNING;
5203 }
5204
5205 aggregate = rn->info;
5206 if (aggregate->safi & SAFI_UNICAST)
5207 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5208 if (aggregate->safi & SAFI_MULTICAST)
5209 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5210
5211 /* Unlock aggregate address configuration. */
5212 rn->info = NULL;
5213 bgp_aggregate_free (aggregate);
5214 bgp_unlock_node (rn);
5215 bgp_unlock_node (rn);
5216
5217 return CMD_SUCCESS;
5218}
5219
5220static int
5221bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005222 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005223 u_char summary_only, u_char as_set)
5224{
5225 int ret;
5226 struct prefix p;
5227 struct bgp_node *rn;
5228 struct bgp *bgp;
5229 struct bgp_aggregate *aggregate;
5230
5231 /* Convert string to prefix structure. */
5232 ret = str2prefix (prefix_str, &p);
5233 if (!ret)
5234 {
5235 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5236 return CMD_WARNING;
5237 }
5238 apply_mask (&p);
5239
5240 /* Get BGP structure. */
5241 bgp = vty->index;
5242
5243 /* Old configuration check. */
5244 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5245
5246 if (rn->info)
5247 {
5248 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005249 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005250 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5251 if (ret)
5252 {
Robert Bays368473f2010-08-05 10:26:29 -07005253 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5254 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005255 return CMD_WARNING;
5256 }
paul718e3742002-12-13 20:15:29 +00005257 }
5258
5259 /* Make aggregate address structure. */
5260 aggregate = bgp_aggregate_new ();
5261 aggregate->summary_only = summary_only;
5262 aggregate->as_set = as_set;
5263 aggregate->safi = safi;
5264 rn->info = aggregate;
5265
5266 /* Aggregate address insert into BGP routing table. */
5267 if (safi & SAFI_UNICAST)
5268 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5269 if (safi & SAFI_MULTICAST)
5270 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5271
5272 return CMD_SUCCESS;
5273}
5274
paul718e3742002-12-13 20:15:29 +00005275DEFUN (aggregate_address,
5276 aggregate_address_cmd,
5277 "aggregate-address A.B.C.D/M",
5278 "Configure BGP aggregate entries\n"
5279 "Aggregate prefix\n")
5280{
5281 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5282}
5283
5284DEFUN (aggregate_address_mask,
5285 aggregate_address_mask_cmd,
5286 "aggregate-address A.B.C.D A.B.C.D",
5287 "Configure BGP aggregate entries\n"
5288 "Aggregate address\n"
5289 "Aggregate mask\n")
5290{
5291 int ret;
5292 char prefix_str[BUFSIZ];
5293
5294 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5295
5296 if (! ret)
5297 {
5298 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5299 return CMD_WARNING;
5300 }
5301
5302 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5303 0, 0);
5304}
5305
5306DEFUN (aggregate_address_summary_only,
5307 aggregate_address_summary_only_cmd,
5308 "aggregate-address A.B.C.D/M summary-only",
5309 "Configure BGP aggregate entries\n"
5310 "Aggregate prefix\n"
5311 "Filter more specific routes from updates\n")
5312{
5313 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5314 AGGREGATE_SUMMARY_ONLY, 0);
5315}
5316
5317DEFUN (aggregate_address_mask_summary_only,
5318 aggregate_address_mask_summary_only_cmd,
5319 "aggregate-address A.B.C.D A.B.C.D summary-only",
5320 "Configure BGP aggregate entries\n"
5321 "Aggregate address\n"
5322 "Aggregate mask\n"
5323 "Filter more specific routes from updates\n")
5324{
5325 int ret;
5326 char prefix_str[BUFSIZ];
5327
5328 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5329
5330 if (! ret)
5331 {
5332 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5333 return CMD_WARNING;
5334 }
5335
5336 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5337 AGGREGATE_SUMMARY_ONLY, 0);
5338}
5339
5340DEFUN (aggregate_address_as_set,
5341 aggregate_address_as_set_cmd,
5342 "aggregate-address A.B.C.D/M as-set",
5343 "Configure BGP aggregate entries\n"
5344 "Aggregate prefix\n"
5345 "Generate AS set path information\n")
5346{
5347 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5348 0, AGGREGATE_AS_SET);
5349}
5350
5351DEFUN (aggregate_address_mask_as_set,
5352 aggregate_address_mask_as_set_cmd,
5353 "aggregate-address A.B.C.D A.B.C.D as-set",
5354 "Configure BGP aggregate entries\n"
5355 "Aggregate address\n"
5356 "Aggregate mask\n"
5357 "Generate AS set path information\n")
5358{
5359 int ret;
5360 char prefix_str[BUFSIZ];
5361
5362 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5363
5364 if (! ret)
5365 {
5366 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5367 return CMD_WARNING;
5368 }
5369
5370 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5371 0, AGGREGATE_AS_SET);
5372}
5373
5374
5375DEFUN (aggregate_address_as_set_summary,
5376 aggregate_address_as_set_summary_cmd,
5377 "aggregate-address A.B.C.D/M as-set summary-only",
5378 "Configure BGP aggregate entries\n"
5379 "Aggregate prefix\n"
5380 "Generate AS set path information\n"
5381 "Filter more specific routes from updates\n")
5382{
5383 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5384 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5385}
5386
5387ALIAS (aggregate_address_as_set_summary,
5388 aggregate_address_summary_as_set_cmd,
5389 "aggregate-address A.B.C.D/M summary-only as-set",
5390 "Configure BGP aggregate entries\n"
5391 "Aggregate prefix\n"
5392 "Filter more specific routes from updates\n"
5393 "Generate AS set path information\n")
5394
5395DEFUN (aggregate_address_mask_as_set_summary,
5396 aggregate_address_mask_as_set_summary_cmd,
5397 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5398 "Configure BGP aggregate entries\n"
5399 "Aggregate address\n"
5400 "Aggregate mask\n"
5401 "Generate AS set path information\n"
5402 "Filter more specific routes from updates\n")
5403{
5404 int ret;
5405 char prefix_str[BUFSIZ];
5406
5407 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5408
5409 if (! ret)
5410 {
5411 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5412 return CMD_WARNING;
5413 }
5414
5415 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5416 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5417}
5418
5419ALIAS (aggregate_address_mask_as_set_summary,
5420 aggregate_address_mask_summary_as_set_cmd,
5421 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5422 "Configure BGP aggregate entries\n"
5423 "Aggregate address\n"
5424 "Aggregate mask\n"
5425 "Filter more specific routes from updates\n"
5426 "Generate AS set path information\n")
5427
5428DEFUN (no_aggregate_address,
5429 no_aggregate_address_cmd,
5430 "no aggregate-address A.B.C.D/M",
5431 NO_STR
5432 "Configure BGP aggregate entries\n"
5433 "Aggregate prefix\n")
5434{
5435 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5436}
5437
5438ALIAS (no_aggregate_address,
5439 no_aggregate_address_summary_only_cmd,
5440 "no aggregate-address A.B.C.D/M summary-only",
5441 NO_STR
5442 "Configure BGP aggregate entries\n"
5443 "Aggregate prefix\n"
5444 "Filter more specific routes from updates\n")
5445
5446ALIAS (no_aggregate_address,
5447 no_aggregate_address_as_set_cmd,
5448 "no aggregate-address A.B.C.D/M as-set",
5449 NO_STR
5450 "Configure BGP aggregate entries\n"
5451 "Aggregate prefix\n"
5452 "Generate AS set path information\n")
5453
5454ALIAS (no_aggregate_address,
5455 no_aggregate_address_as_set_summary_cmd,
5456 "no aggregate-address A.B.C.D/M as-set summary-only",
5457 NO_STR
5458 "Configure BGP aggregate entries\n"
5459 "Aggregate prefix\n"
5460 "Generate AS set path information\n"
5461 "Filter more specific routes from updates\n")
5462
5463ALIAS (no_aggregate_address,
5464 no_aggregate_address_summary_as_set_cmd,
5465 "no aggregate-address A.B.C.D/M summary-only as-set",
5466 NO_STR
5467 "Configure BGP aggregate entries\n"
5468 "Aggregate prefix\n"
5469 "Filter more specific routes from updates\n"
5470 "Generate AS set path information\n")
5471
5472DEFUN (no_aggregate_address_mask,
5473 no_aggregate_address_mask_cmd,
5474 "no aggregate-address A.B.C.D A.B.C.D",
5475 NO_STR
5476 "Configure BGP aggregate entries\n"
5477 "Aggregate address\n"
5478 "Aggregate mask\n")
5479{
5480 int ret;
5481 char prefix_str[BUFSIZ];
5482
5483 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5484
5485 if (! ret)
5486 {
5487 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5488 return CMD_WARNING;
5489 }
5490
5491 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5492}
5493
5494ALIAS (no_aggregate_address_mask,
5495 no_aggregate_address_mask_summary_only_cmd,
5496 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5497 NO_STR
5498 "Configure BGP aggregate entries\n"
5499 "Aggregate address\n"
5500 "Aggregate mask\n"
5501 "Filter more specific routes from updates\n")
5502
5503ALIAS (no_aggregate_address_mask,
5504 no_aggregate_address_mask_as_set_cmd,
5505 "no aggregate-address A.B.C.D A.B.C.D as-set",
5506 NO_STR
5507 "Configure BGP aggregate entries\n"
5508 "Aggregate address\n"
5509 "Aggregate mask\n"
5510 "Generate AS set path information\n")
5511
5512ALIAS (no_aggregate_address_mask,
5513 no_aggregate_address_mask_as_set_summary_cmd,
5514 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5515 NO_STR
5516 "Configure BGP aggregate entries\n"
5517 "Aggregate address\n"
5518 "Aggregate mask\n"
5519 "Generate AS set path information\n"
5520 "Filter more specific routes from updates\n")
5521
5522ALIAS (no_aggregate_address_mask,
5523 no_aggregate_address_mask_summary_as_set_cmd,
5524 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5525 NO_STR
5526 "Configure BGP aggregate entries\n"
5527 "Aggregate address\n"
5528 "Aggregate mask\n"
5529 "Filter more specific routes from updates\n"
5530 "Generate AS set path information\n")
5531
5532#ifdef HAVE_IPV6
5533DEFUN (ipv6_aggregate_address,
5534 ipv6_aggregate_address_cmd,
5535 "aggregate-address X:X::X:X/M",
5536 "Configure BGP aggregate entries\n"
5537 "Aggregate prefix\n")
5538{
5539 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5540}
5541
5542DEFUN (ipv6_aggregate_address_summary_only,
5543 ipv6_aggregate_address_summary_only_cmd,
5544 "aggregate-address X:X::X:X/M summary-only",
5545 "Configure BGP aggregate entries\n"
5546 "Aggregate prefix\n"
5547 "Filter more specific routes from updates\n")
5548{
5549 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5550 AGGREGATE_SUMMARY_ONLY, 0);
5551}
5552
5553DEFUN (no_ipv6_aggregate_address,
5554 no_ipv6_aggregate_address_cmd,
5555 "no aggregate-address X:X::X:X/M",
5556 NO_STR
5557 "Configure BGP aggregate entries\n"
5558 "Aggregate prefix\n")
5559{
5560 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5561}
5562
5563DEFUN (no_ipv6_aggregate_address_summary_only,
5564 no_ipv6_aggregate_address_summary_only_cmd,
5565 "no aggregate-address X:X::X:X/M summary-only",
5566 NO_STR
5567 "Configure BGP aggregate entries\n"
5568 "Aggregate prefix\n"
5569 "Filter more specific routes from updates\n")
5570{
5571 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5572}
5573
5574ALIAS (ipv6_aggregate_address,
5575 old_ipv6_aggregate_address_cmd,
5576 "ipv6 bgp aggregate-address X:X::X:X/M",
5577 IPV6_STR
5578 BGP_STR
5579 "Configure BGP aggregate entries\n"
5580 "Aggregate prefix\n")
5581
5582ALIAS (ipv6_aggregate_address_summary_only,
5583 old_ipv6_aggregate_address_summary_only_cmd,
5584 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5585 IPV6_STR
5586 BGP_STR
5587 "Configure BGP aggregate entries\n"
5588 "Aggregate prefix\n"
5589 "Filter more specific routes from updates\n")
5590
5591ALIAS (no_ipv6_aggregate_address,
5592 old_no_ipv6_aggregate_address_cmd,
5593 "no ipv6 bgp aggregate-address X:X::X:X/M",
5594 NO_STR
5595 IPV6_STR
5596 BGP_STR
5597 "Configure BGP aggregate entries\n"
5598 "Aggregate prefix\n")
5599
5600ALIAS (no_ipv6_aggregate_address_summary_only,
5601 old_no_ipv6_aggregate_address_summary_only_cmd,
5602 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5603 NO_STR
5604 IPV6_STR
5605 BGP_STR
5606 "Configure BGP aggregate entries\n"
5607 "Aggregate prefix\n"
5608 "Filter more specific routes from updates\n")
5609#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005610
paul718e3742002-12-13 20:15:29 +00005611/* Redistribute route treatment. */
5612void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005613bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5614 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005615 u_int32_t metric, u_char type)
5616{
5617 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005618 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005619 struct bgp_info *new;
5620 struct bgp_info *bi;
5621 struct bgp_info info;
5622 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005623 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005624 struct attr *new_attr;
5625 afi_t afi;
5626 int ret;
5627
5628 /* Make default attribute. */
5629 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5630 if (nexthop)
5631 attr.nexthop = *nexthop;
5632
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005633#ifdef HAVE_IPV6
5634 if (nexthop6)
5635 {
5636 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5637 extra->mp_nexthop_global = *nexthop6;
5638 extra->mp_nexthop_len = 16;
5639 }
5640#endif
5641
paul718e3742002-12-13 20:15:29 +00005642 attr.med = metric;
5643 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5644
paul1eb8ef22005-04-07 07:30:20 +00005645 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005646 {
5647 afi = family2afi (p->family);
5648
5649 if (bgp->redist[afi][type])
5650 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005651 struct attr attr_new;
5652 struct attr_extra extra_new;
5653
paul718e3742002-12-13 20:15:29 +00005654 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005655 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005656 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005657
5658 if (bgp->redist_metric_flag[afi][type])
5659 attr_new.med = bgp->redist_metric[afi][type];
5660
5661 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005662 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005663 {
5664 info.peer = bgp->peer_self;
5665 info.attr = &attr_new;
5666
paulfee0f4c2004-09-13 05:12:46 +00005667 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5668
paul718e3742002-12-13 20:15:29 +00005669 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5670 &info);
paulfee0f4c2004-09-13 05:12:46 +00005671
5672 bgp->peer_self->rmap_type = 0;
5673
paul718e3742002-12-13 20:15:29 +00005674 if (ret == RMAP_DENYMATCH)
5675 {
5676 /* Free uninterned attribute. */
5677 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005678
paul718e3742002-12-13 20:15:29 +00005679 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005680 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005681 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005682 bgp_redistribute_delete (p, type);
5683 return;
5684 }
5685 }
5686
Paul Jakmafb982c22007-05-04 20:15:47 +00005687 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5688 afi, SAFI_UNICAST, p, NULL);
5689
paul718e3742002-12-13 20:15:29 +00005690 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005691
paul718e3742002-12-13 20:15:29 +00005692 for (bi = bn->info; bi; bi = bi->next)
5693 if (bi->peer == bgp->peer_self
5694 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5695 break;
5696
5697 if (bi)
5698 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005699 if (attrhash_cmp (bi->attr, new_attr) &&
5700 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005701 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005702 bgp_attr_unintern (&new_attr);
5703 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005704 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005705 bgp_unlock_node (bn);
5706 return;
5707 }
5708 else
5709 {
5710 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005711 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005712
5713 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005714 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5715 bgp_info_restore(bn, bi);
5716 else
5717 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005718 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005719 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005720 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005721
5722 /* Process change. */
5723 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5724 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5725 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005726 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005727 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005728 return;
5729 }
5730 }
5731
5732 new = bgp_info_new ();
5733 new->type = type;
5734 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5735 new->peer = bgp->peer_self;
5736 SET_FLAG (new->flags, BGP_INFO_VALID);
5737 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005738 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005739
5740 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5741 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005742 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005743 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5744 }
5745 }
5746
5747 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005748 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005749 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005750}
5751
5752void
5753bgp_redistribute_delete (struct prefix *p, u_char type)
5754{
5755 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005756 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005757 afi_t afi;
5758 struct bgp_node *rn;
5759 struct bgp_info *ri;
5760
paul1eb8ef22005-04-07 07:30:20 +00005761 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005762 {
5763 afi = family2afi (p->family);
5764
5765 if (bgp->redist[afi][type])
5766 {
paulfee0f4c2004-09-13 05:12:46 +00005767 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005768
5769 for (ri = rn->info; ri; ri = ri->next)
5770 if (ri->peer == bgp->peer_self
5771 && ri->type == type)
5772 break;
5773
5774 if (ri)
5775 {
5776 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005777 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005778 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005779 }
5780 bgp_unlock_node (rn);
5781 }
5782 }
5783}
5784
5785/* Withdraw specified route type's route. */
5786void
5787bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5788{
5789 struct bgp_node *rn;
5790 struct bgp_info *ri;
5791 struct bgp_table *table;
5792
5793 table = bgp->rib[afi][SAFI_UNICAST];
5794
5795 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5796 {
5797 for (ri = rn->info; ri; ri = ri->next)
5798 if (ri->peer == bgp->peer_self
5799 && ri->type == type)
5800 break;
5801
5802 if (ri)
5803 {
5804 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005805 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005806 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005807 }
5808 }
5809}
David Lamparter6b0655a2014-06-04 06:53:35 +02005810
paul718e3742002-12-13 20:15:29 +00005811/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005812static void
paul718e3742002-12-13 20:15:29 +00005813route_vty_out_route (struct prefix *p, struct vty *vty)
5814{
5815 int len;
5816 u_int32_t destination;
5817 char buf[BUFSIZ];
5818
5819 if (p->family == AF_INET)
5820 {
5821 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5822 destination = ntohl (p->u.prefix4.s_addr);
5823
5824 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5825 || (IN_CLASSB (destination) && p->prefixlen == 16)
5826 || (IN_CLASSA (destination) && p->prefixlen == 8)
5827 || p->u.prefix4.s_addr == 0)
5828 {
5829 /* When mask is natural, mask is not displayed. */
5830 }
5831 else
5832 len += vty_out (vty, "/%d", p->prefixlen);
5833 }
5834 else
5835 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5836 p->prefixlen);
5837
5838 len = 17 - len;
5839 if (len < 1)
5840 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5841 else
5842 vty_out (vty, "%*s", len, " ");
5843}
5844
paul718e3742002-12-13 20:15:29 +00005845enum bgp_display_type
5846{
5847 normal_list,
5848};
5849
paulb40d9392005-08-22 22:34:41 +00005850/* Print the short form route status for a bgp_info */
5851static void
5852route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005853{
paulb40d9392005-08-22 22:34:41 +00005854 /* Route status display. */
5855 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5856 vty_out (vty, "R");
5857 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005858 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005859 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005860 vty_out (vty, "s");
5861 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5862 vty_out (vty, "*");
5863 else
5864 vty_out (vty, " ");
5865
5866 /* Selected */
5867 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5868 vty_out (vty, "h");
5869 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5870 vty_out (vty, "d");
5871 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5872 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005873 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5874 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005875 else
5876 vty_out (vty, " ");
5877
5878 /* Internal route. */
5879 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5880 vty_out (vty, "i");
5881 else
paulb40d9392005-08-22 22:34:41 +00005882 vty_out (vty, " ");
5883}
5884
5885/* called from terminal list command */
5886void
5887route_vty_out (struct vty *vty, struct prefix *p,
5888 struct bgp_info *binfo, int display, safi_t safi)
5889{
5890 struct attr *attr;
5891
5892 /* short status lead text */
5893 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005894
5895 /* print prefix and mask */
5896 if (! display)
5897 route_vty_out_route (p, vty);
5898 else
5899 vty_out (vty, "%*s", 17, " ");
5900
5901 /* Print attribute */
5902 attr = binfo->attr;
5903 if (attr)
5904 {
5905 if (p->family == AF_INET)
5906 {
5907 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005908 vty_out (vty, "%-16s",
5909 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005910 else
5911 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5912 }
5913#ifdef HAVE_IPV6
5914 else if (p->family == AF_INET6)
5915 {
5916 int len;
5917 char buf[BUFSIZ];
5918
5919 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005920 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5921 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005922 len = 16 - len;
5923 if (len < 1)
5924 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5925 else
5926 vty_out (vty, "%*s", len, " ");
5927 }
5928#endif /* HAVE_IPV6 */
5929
5930 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005931 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005932 else
5933 vty_out (vty, " ");
5934
5935 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005936 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005937 else
5938 vty_out (vty, " ");
5939
Paul Jakmafb982c22007-05-04 20:15:47 +00005940 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005941
Paul Jakmab2518c12006-05-12 23:48:40 +00005942 /* Print aspath */
5943 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005944 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005945
Paul Jakmab2518c12006-05-12 23:48:40 +00005946 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005947 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005948 }
paul718e3742002-12-13 20:15:29 +00005949 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005950}
5951
5952/* called from terminal list command */
5953void
5954route_vty_out_tmp (struct vty *vty, struct prefix *p,
5955 struct attr *attr, safi_t safi)
5956{
5957 /* Route status display. */
5958 vty_out (vty, "*");
5959 vty_out (vty, ">");
5960 vty_out (vty, " ");
5961
5962 /* print prefix and mask */
5963 route_vty_out_route (p, vty);
5964
5965 /* Print attribute */
5966 if (attr)
5967 {
5968 if (p->family == AF_INET)
5969 {
5970 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005971 vty_out (vty, "%-16s",
5972 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005973 else
5974 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5975 }
5976#ifdef HAVE_IPV6
5977 else if (p->family == AF_INET6)
5978 {
5979 int len;
5980 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005981
5982 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005983
5984 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005985 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5986 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005987 len = 16 - len;
5988 if (len < 1)
5989 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5990 else
5991 vty_out (vty, "%*s", len, " ");
5992 }
5993#endif /* HAVE_IPV6 */
5994
5995 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005996 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005997 else
5998 vty_out (vty, " ");
5999
6000 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006001 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006002 else
6003 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006004
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006005 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006006
Paul Jakmab2518c12006-05-12 23:48:40 +00006007 /* Print aspath */
6008 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006009 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006010
Paul Jakmab2518c12006-05-12 23:48:40 +00006011 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006012 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006013 }
paul718e3742002-12-13 20:15:29 +00006014
6015 vty_out (vty, "%s", VTY_NEWLINE);
6016}
6017
ajs5a646652004-11-05 01:25:55 +00006018void
paul718e3742002-12-13 20:15:29 +00006019route_vty_out_tag (struct vty *vty, struct prefix *p,
6020 struct bgp_info *binfo, int display, safi_t safi)
6021{
6022 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006023 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006024
6025 if (!binfo->extra)
6026 return;
6027
paulb40d9392005-08-22 22:34:41 +00006028 /* short status lead text */
6029 route_vty_short_status_out (vty, binfo);
6030
paul718e3742002-12-13 20:15:29 +00006031 /* print prefix and mask */
6032 if (! display)
6033 route_vty_out_route (p, vty);
6034 else
6035 vty_out (vty, "%*s", 17, " ");
6036
6037 /* Print attribute */
6038 attr = binfo->attr;
6039 if (attr)
6040 {
6041 if (p->family == AF_INET)
6042 {
6043 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00006044 vty_out (vty, "%-16s",
6045 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006046 else
6047 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6048 }
6049#ifdef HAVE_IPV6
6050 else if (p->family == AF_INET6)
6051 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006052 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006053 char buf[BUFSIZ];
6054 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006055 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006056 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006057 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6058 buf, BUFSIZ));
6059 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006060 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006061 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6062 buf, BUFSIZ),
6063 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6064 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006065
6066 }
6067#endif /* HAVE_IPV6 */
6068 }
6069
Paul Jakmafb982c22007-05-04 20:15:47 +00006070 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006071
6072 vty_out (vty, "notag/%d", label);
6073
6074 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006075}
6076
6077/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006078static void
paul718e3742002-12-13 20:15:29 +00006079damp_route_vty_out (struct vty *vty, struct prefix *p,
6080 struct bgp_info *binfo, int display, safi_t safi)
6081{
6082 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006083 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006084 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006085
paulb40d9392005-08-22 22:34:41 +00006086 /* short status lead text */
6087 route_vty_short_status_out (vty, binfo);
6088
paul718e3742002-12-13 20:15:29 +00006089 /* print prefix and mask */
6090 if (! display)
6091 route_vty_out_route (p, vty);
6092 else
6093 vty_out (vty, "%*s", 17, " ");
6094
6095 len = vty_out (vty, "%s", binfo->peer->host);
6096 len = 17 - len;
6097 if (len < 1)
6098 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6099 else
6100 vty_out (vty, "%*s", len, " ");
6101
Chris Caputo50aef6f2009-06-23 06:06:49 +00006102 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006103
6104 /* Print attribute */
6105 attr = binfo->attr;
6106 if (attr)
6107 {
6108 /* Print aspath */
6109 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006110 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006111
6112 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006113 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006114 }
6115 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006116}
6117
paul718e3742002-12-13 20:15:29 +00006118/* flap route */
ajs5a646652004-11-05 01:25:55 +00006119static void
paul718e3742002-12-13 20:15:29 +00006120flap_route_vty_out (struct vty *vty, struct prefix *p,
6121 struct bgp_info *binfo, int display, safi_t safi)
6122{
6123 struct attr *attr;
6124 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006125 char timebuf[BGP_UPTIME_LEN];
6126 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006127
6128 if (!binfo->extra)
6129 return;
6130
6131 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006132
paulb40d9392005-08-22 22:34:41 +00006133 /* short status lead text */
6134 route_vty_short_status_out (vty, binfo);
6135
paul718e3742002-12-13 20:15:29 +00006136 /* print prefix and mask */
6137 if (! display)
6138 route_vty_out_route (p, vty);
6139 else
6140 vty_out (vty, "%*s", 17, " ");
6141
6142 len = vty_out (vty, "%s", binfo->peer->host);
6143 len = 16 - len;
6144 if (len < 1)
6145 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6146 else
6147 vty_out (vty, "%*s", len, " ");
6148
6149 len = vty_out (vty, "%d", bdi->flap);
6150 len = 5 - len;
6151 if (len < 1)
6152 vty_out (vty, " ");
6153 else
6154 vty_out (vty, "%*s ", len, " ");
6155
6156 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6157 timebuf, BGP_UPTIME_LEN));
6158
6159 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6160 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006161 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006162 else
6163 vty_out (vty, "%*s ", 8, " ");
6164
6165 /* Print attribute */
6166 attr = binfo->attr;
6167 if (attr)
6168 {
6169 /* Print aspath */
6170 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006171 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006172
6173 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006174 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006175 }
6176 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006177}
6178
paul94f2b392005-06-28 12:44:16 +00006179static void
paul718e3742002-12-13 20:15:29 +00006180route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6181 struct bgp_info *binfo, afi_t afi, safi_t safi)
6182{
6183 char buf[INET6_ADDRSTRLEN];
6184 char buf1[BUFSIZ];
6185 struct attr *attr;
6186 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006187#ifdef HAVE_CLOCK_MONOTONIC
6188 time_t tbuf;
6189#endif
paul718e3742002-12-13 20:15:29 +00006190
6191 attr = binfo->attr;
6192
6193 if (attr)
6194 {
6195 /* Line1 display AS-path, Aggregator */
6196 if (attr->aspath)
6197 {
6198 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006199 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006200 vty_out (vty, "Local");
6201 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006202 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006203 }
6204
paulb40d9392005-08-22 22:34:41 +00006205 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6206 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006207 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6208 vty_out (vty, ", (stale)");
6209 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006210 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006211 attr->extra->aggregator_as,
6212 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006213 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6214 vty_out (vty, ", (Received from a RR-client)");
6215 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6216 vty_out (vty, ", (Received from a RS-client)");
6217 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6218 vty_out (vty, ", (history entry)");
6219 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6220 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006221 vty_out (vty, "%s", VTY_NEWLINE);
6222
6223 /* Line2 display Next-hop, Neighbor, Router-id */
6224 if (p->family == AF_INET)
6225 {
6226 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006227 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006228 inet_ntoa (attr->nexthop));
6229 }
6230#ifdef HAVE_IPV6
6231 else
6232 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006233 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006234 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006235 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006236 buf, INET6_ADDRSTRLEN));
6237 }
6238#endif /* HAVE_IPV6 */
6239
6240 if (binfo->peer == bgp->peer_self)
6241 {
6242 vty_out (vty, " from %s ",
6243 p->family == AF_INET ? "0.0.0.0" : "::");
6244 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6245 }
6246 else
6247 {
6248 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6249 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006250 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006251 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006252 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006253 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006254 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006255 else
6256 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6257 }
6258 vty_out (vty, "%s", VTY_NEWLINE);
6259
6260#ifdef HAVE_IPV6
6261 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006262 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006263 {
6264 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006265 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006266 buf, INET6_ADDRSTRLEN),
6267 VTY_NEWLINE);
6268 }
6269#endif /* HAVE_IPV6 */
6270
6271 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6272 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6273
6274 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006275 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006276
6277 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006278 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006279 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006280 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006281
Paul Jakmafb982c22007-05-04 20:15:47 +00006282 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006283 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006284
6285 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6286 vty_out (vty, ", valid");
6287
6288 if (binfo->peer != bgp->peer_self)
6289 {
6290 if (binfo->peer->as == binfo->peer->local_as)
6291 vty_out (vty, ", internal");
6292 else
6293 vty_out (vty, ", %s",
6294 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6295 }
6296 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6297 vty_out (vty, ", aggregated, local");
6298 else if (binfo->type != ZEBRA_ROUTE_BGP)
6299 vty_out (vty, ", sourced");
6300 else
6301 vty_out (vty, ", sourced, local");
6302
6303 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6304 vty_out (vty, ", atomic-aggregate");
6305
Josh Baileyde8d5df2011-07-20 20:46:01 -07006306 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6307 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6308 bgp_info_mpath_count (binfo)))
6309 vty_out (vty, ", multipath");
6310
paul718e3742002-12-13 20:15:29 +00006311 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6312 vty_out (vty, ", best");
6313
6314 vty_out (vty, "%s", VTY_NEWLINE);
6315
6316 /* Line 4 display Community */
6317 if (attr->community)
6318 vty_out (vty, " Community: %s%s", attr->community->str,
6319 VTY_NEWLINE);
6320
6321 /* Line 5 display Extended-community */
6322 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006323 vty_out (vty, " Extended Community: %s%s",
6324 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006325
6326 /* Line 6 display Originator, Cluster-id */
6327 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6328 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6329 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006330 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006331 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006332 vty_out (vty, " Originator: %s",
6333 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006334
6335 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6336 {
6337 int i;
6338 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006339 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6340 vty_out (vty, "%s ",
6341 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006342 }
6343 vty_out (vty, "%s", VTY_NEWLINE);
6344 }
Paul Jakma41367172007-08-06 15:24:51 +00006345
Paul Jakmafb982c22007-05-04 20:15:47 +00006346 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006347 bgp_damp_info_vty (vty, binfo);
6348
6349 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006350#ifdef HAVE_CLOCK_MONOTONIC
6351 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006352 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006353#else
6354 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6355#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006356 }
6357 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006358}
6359
6360#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6361 "h history, * valid, > best, = multipath,%s"\
6362 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006363#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006364#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6365#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6366#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6367
6368enum bgp_show_type
6369{
6370 bgp_show_type_normal,
6371 bgp_show_type_regexp,
6372 bgp_show_type_prefix_list,
6373 bgp_show_type_filter_list,
6374 bgp_show_type_route_map,
6375 bgp_show_type_neighbor,
6376 bgp_show_type_cidr_only,
6377 bgp_show_type_prefix_longer,
6378 bgp_show_type_community_all,
6379 bgp_show_type_community,
6380 bgp_show_type_community_exact,
6381 bgp_show_type_community_list,
6382 bgp_show_type_community_list_exact,
6383 bgp_show_type_flap_statistics,
6384 bgp_show_type_flap_address,
6385 bgp_show_type_flap_prefix,
6386 bgp_show_type_flap_cidr_only,
6387 bgp_show_type_flap_regexp,
6388 bgp_show_type_flap_filter_list,
6389 bgp_show_type_flap_prefix_list,
6390 bgp_show_type_flap_prefix_longer,
6391 bgp_show_type_flap_route_map,
6392 bgp_show_type_flap_neighbor,
6393 bgp_show_type_dampend_paths,
6394 bgp_show_type_damp_neighbor
6395};
6396
ajs5a646652004-11-05 01:25:55 +00006397static int
paulfee0f4c2004-09-13 05:12:46 +00006398bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006399 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006400{
paul718e3742002-12-13 20:15:29 +00006401 struct bgp_info *ri;
6402 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006403 int header = 1;
paul718e3742002-12-13 20:15:29 +00006404 int display;
ajs5a646652004-11-05 01:25:55 +00006405 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006406
6407 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006408 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006409
paul718e3742002-12-13 20:15:29 +00006410 /* Start processing of routes. */
6411 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6412 if (rn->info != NULL)
6413 {
6414 display = 0;
6415
6416 for (ri = rn->info; ri; ri = ri->next)
6417 {
ajs5a646652004-11-05 01:25:55 +00006418 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006419 || type == bgp_show_type_flap_address
6420 || type == bgp_show_type_flap_prefix
6421 || type == bgp_show_type_flap_cidr_only
6422 || type == bgp_show_type_flap_regexp
6423 || type == bgp_show_type_flap_filter_list
6424 || type == bgp_show_type_flap_prefix_list
6425 || type == bgp_show_type_flap_prefix_longer
6426 || type == bgp_show_type_flap_route_map
6427 || type == bgp_show_type_flap_neighbor
6428 || type == bgp_show_type_dampend_paths
6429 || type == bgp_show_type_damp_neighbor)
6430 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006431 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006432 continue;
6433 }
6434 if (type == bgp_show_type_regexp
6435 || type == bgp_show_type_flap_regexp)
6436 {
ajs5a646652004-11-05 01:25:55 +00006437 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006438
6439 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6440 continue;
6441 }
6442 if (type == bgp_show_type_prefix_list
6443 || type == bgp_show_type_flap_prefix_list)
6444 {
ajs5a646652004-11-05 01:25:55 +00006445 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006446
6447 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6448 continue;
6449 }
6450 if (type == bgp_show_type_filter_list
6451 || type == bgp_show_type_flap_filter_list)
6452 {
ajs5a646652004-11-05 01:25:55 +00006453 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006454
6455 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6456 continue;
6457 }
6458 if (type == bgp_show_type_route_map
6459 || type == bgp_show_type_flap_route_map)
6460 {
ajs5a646652004-11-05 01:25:55 +00006461 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006462 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006463 struct attr dummy_attr;
6464 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006465 int ret;
6466
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006467 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006468 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006469
paul718e3742002-12-13 20:15:29 +00006470 binfo.peer = ri->peer;
6471 binfo.attr = &dummy_attr;
6472
6473 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006474 if (ret == RMAP_DENYMATCH)
6475 continue;
6476 }
6477 if (type == bgp_show_type_neighbor
6478 || type == bgp_show_type_flap_neighbor
6479 || type == bgp_show_type_damp_neighbor)
6480 {
ajs5a646652004-11-05 01:25:55 +00006481 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006482
6483 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6484 continue;
6485 }
6486 if (type == bgp_show_type_cidr_only
6487 || type == bgp_show_type_flap_cidr_only)
6488 {
6489 u_int32_t destination;
6490
6491 destination = ntohl (rn->p.u.prefix4.s_addr);
6492 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6493 continue;
6494 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6495 continue;
6496 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6497 continue;
6498 }
6499 if (type == bgp_show_type_prefix_longer
6500 || type == bgp_show_type_flap_prefix_longer)
6501 {
ajs5a646652004-11-05 01:25:55 +00006502 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006503
6504 if (! prefix_match (p, &rn->p))
6505 continue;
6506 }
6507 if (type == bgp_show_type_community_all)
6508 {
6509 if (! ri->attr->community)
6510 continue;
6511 }
6512 if (type == bgp_show_type_community)
6513 {
ajs5a646652004-11-05 01:25:55 +00006514 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006515
6516 if (! ri->attr->community ||
6517 ! community_match (ri->attr->community, com))
6518 continue;
6519 }
6520 if (type == bgp_show_type_community_exact)
6521 {
ajs5a646652004-11-05 01:25:55 +00006522 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006523
6524 if (! ri->attr->community ||
6525 ! community_cmp (ri->attr->community, com))
6526 continue;
6527 }
6528 if (type == bgp_show_type_community_list)
6529 {
ajs5a646652004-11-05 01:25:55 +00006530 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006531
6532 if (! community_list_match (ri->attr->community, list))
6533 continue;
6534 }
6535 if (type == bgp_show_type_community_list_exact)
6536 {
ajs5a646652004-11-05 01:25:55 +00006537 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006538
6539 if (! community_list_exact_match (ri->attr->community, list))
6540 continue;
6541 }
6542 if (type == bgp_show_type_flap_address
6543 || type == bgp_show_type_flap_prefix)
6544 {
ajs5a646652004-11-05 01:25:55 +00006545 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006546
6547 if (! prefix_match (&rn->p, p))
6548 continue;
6549
6550 if (type == bgp_show_type_flap_prefix)
6551 if (p->prefixlen != rn->p.prefixlen)
6552 continue;
6553 }
6554 if (type == bgp_show_type_dampend_paths
6555 || type == bgp_show_type_damp_neighbor)
6556 {
6557 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6558 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6559 continue;
6560 }
6561
6562 if (header)
6563 {
hasso93406d82005-02-02 14:40:33 +00006564 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6565 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6566 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006567 if (type == bgp_show_type_dampend_paths
6568 || type == bgp_show_type_damp_neighbor)
6569 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6570 else if (type == bgp_show_type_flap_statistics
6571 || type == bgp_show_type_flap_address
6572 || type == bgp_show_type_flap_prefix
6573 || type == bgp_show_type_flap_cidr_only
6574 || type == bgp_show_type_flap_regexp
6575 || type == bgp_show_type_flap_filter_list
6576 || type == bgp_show_type_flap_prefix_list
6577 || type == bgp_show_type_flap_prefix_longer
6578 || type == bgp_show_type_flap_route_map
6579 || type == bgp_show_type_flap_neighbor)
6580 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6581 else
6582 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006583 header = 0;
6584 }
6585
6586 if (type == bgp_show_type_dampend_paths
6587 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006588 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006589 else if (type == bgp_show_type_flap_statistics
6590 || type == bgp_show_type_flap_address
6591 || type == bgp_show_type_flap_prefix
6592 || type == bgp_show_type_flap_cidr_only
6593 || type == bgp_show_type_flap_regexp
6594 || type == bgp_show_type_flap_filter_list
6595 || type == bgp_show_type_flap_prefix_list
6596 || type == bgp_show_type_flap_prefix_longer
6597 || type == bgp_show_type_flap_route_map
6598 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006599 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006600 else
ajs5a646652004-11-05 01:25:55 +00006601 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006602 display++;
6603 }
6604 if (display)
ajs5a646652004-11-05 01:25:55 +00006605 output_count++;
paul718e3742002-12-13 20:15:29 +00006606 }
6607
6608 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006609 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006610 {
6611 if (type == bgp_show_type_normal)
6612 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6613 }
6614 else
6615 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006616 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006617
6618 return CMD_SUCCESS;
6619}
6620
ajs5a646652004-11-05 01:25:55 +00006621static int
paulfee0f4c2004-09-13 05:12:46 +00006622bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006623 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006624{
6625 struct bgp_table *table;
6626
6627 if (bgp == NULL) {
6628 bgp = bgp_get_default ();
6629 }
6630
6631 if (bgp == NULL)
6632 {
6633 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6634 return CMD_WARNING;
6635 }
6636
6637
6638 table = bgp->rib[afi][safi];
6639
ajs5a646652004-11-05 01:25:55 +00006640 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006641}
6642
paul718e3742002-12-13 20:15:29 +00006643/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006644static void
paul718e3742002-12-13 20:15:29 +00006645route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6646 struct bgp_node *rn,
6647 struct prefix_rd *prd, afi_t afi, safi_t safi)
6648{
6649 struct bgp_info *ri;
6650 struct prefix *p;
6651 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006652 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006653 char buf1[INET6_ADDRSTRLEN];
6654 char buf2[INET6_ADDRSTRLEN];
6655 int count = 0;
6656 int best = 0;
6657 int suppress = 0;
6658 int no_export = 0;
6659 int no_advertise = 0;
6660 int local_as = 0;
6661 int first = 0;
6662
6663 p = &rn->p;
6664 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6665 (safi == SAFI_MPLS_VPN ?
6666 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6667 safi == SAFI_MPLS_VPN ? ":" : "",
6668 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6669 p->prefixlen, VTY_NEWLINE);
6670
6671 for (ri = rn->info; ri; ri = ri->next)
6672 {
6673 count++;
6674 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6675 {
6676 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006677 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006678 suppress = 1;
6679 if (ri->attr->community != NULL)
6680 {
6681 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6682 no_advertise = 1;
6683 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6684 no_export = 1;
6685 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6686 local_as = 1;
6687 }
6688 }
6689 }
6690
6691 vty_out (vty, "Paths: (%d available", count);
6692 if (best)
6693 {
6694 vty_out (vty, ", best #%d", best);
6695 if (safi == SAFI_UNICAST)
6696 vty_out (vty, ", table Default-IP-Routing-Table");
6697 }
6698 else
6699 vty_out (vty, ", no best path");
6700 if (no_advertise)
6701 vty_out (vty, ", not advertised to any peer");
6702 else if (no_export)
6703 vty_out (vty, ", not advertised to EBGP peer");
6704 else if (local_as)
6705 vty_out (vty, ", not advertised outside local AS");
6706 if (suppress)
6707 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6708 vty_out (vty, ")%s", VTY_NEWLINE);
6709
6710 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006711 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006712 {
6713 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6714 {
6715 if (! first)
6716 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6717 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6718 first = 1;
6719 }
6720 }
6721 if (! first)
6722 vty_out (vty, " Not advertised to any peer");
6723 vty_out (vty, "%s", VTY_NEWLINE);
6724}
6725
6726/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006727static int
paulfee0f4c2004-09-13 05:12:46 +00006728bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006729 struct bgp_table *rib, const char *ip_str,
6730 afi_t afi, safi_t safi, struct prefix_rd *prd,
6731 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006732{
6733 int ret;
6734 int header;
6735 int display = 0;
6736 struct prefix match;
6737 struct bgp_node *rn;
6738 struct bgp_node *rm;
6739 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006740 struct bgp_table *table;
6741
paul718e3742002-12-13 20:15:29 +00006742 /* Check IP address argument. */
6743 ret = str2prefix (ip_str, &match);
6744 if (! ret)
6745 {
6746 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6747 return CMD_WARNING;
6748 }
6749
6750 match.family = afi2family (afi);
6751
6752 if (safi == SAFI_MPLS_VPN)
6753 {
paulfee0f4c2004-09-13 05:12:46 +00006754 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006755 {
6756 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6757 continue;
6758
6759 if ((table = rn->info) != NULL)
6760 {
6761 header = 1;
6762
6763 if ((rm = bgp_node_match (table, &match)) != NULL)
6764 {
6765 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006766 {
6767 bgp_unlock_node (rm);
6768 continue;
6769 }
paul718e3742002-12-13 20:15:29 +00006770
6771 for (ri = rm->info; ri; ri = ri->next)
6772 {
6773 if (header)
6774 {
6775 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6776 AFI_IP, SAFI_MPLS_VPN);
6777
6778 header = 0;
6779 }
6780 display++;
6781 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6782 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006783
6784 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006785 }
6786 }
6787 }
6788 }
6789 else
6790 {
6791 header = 1;
6792
paulfee0f4c2004-09-13 05:12:46 +00006793 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006794 {
6795 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6796 {
6797 for (ri = rn->info; ri; ri = ri->next)
6798 {
6799 if (header)
6800 {
6801 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6802 header = 0;
6803 }
6804 display++;
6805 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6806 }
6807 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006808
6809 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006810 }
6811 }
6812
6813 if (! display)
6814 {
6815 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6816 return CMD_WARNING;
6817 }
6818
6819 return CMD_SUCCESS;
6820}
6821
paulfee0f4c2004-09-13 05:12:46 +00006822/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006823static int
paulfd79ac92004-10-13 05:06:08 +00006824bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006825 afi_t afi, safi_t safi, struct prefix_rd *prd,
6826 int prefix_check)
6827{
6828 struct bgp *bgp;
6829
6830 /* BGP structure lookup. */
6831 if (view_name)
6832 {
6833 bgp = bgp_lookup_by_name (view_name);
6834 if (bgp == NULL)
6835 {
6836 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6837 return CMD_WARNING;
6838 }
6839 }
6840 else
6841 {
6842 bgp = bgp_get_default ();
6843 if (bgp == NULL)
6844 {
6845 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6846 return CMD_WARNING;
6847 }
6848 }
6849
6850 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6851 afi, safi, prd, prefix_check);
6852}
6853
paul718e3742002-12-13 20:15:29 +00006854/* BGP route print out function. */
6855DEFUN (show_ip_bgp,
6856 show_ip_bgp_cmd,
6857 "show ip bgp",
6858 SHOW_STR
6859 IP_STR
6860 BGP_STR)
6861{
ajs5a646652004-11-05 01:25:55 +00006862 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006863}
6864
6865DEFUN (show_ip_bgp_ipv4,
6866 show_ip_bgp_ipv4_cmd,
6867 "show ip bgp ipv4 (unicast|multicast)",
6868 SHOW_STR
6869 IP_STR
6870 BGP_STR
6871 "Address family\n"
6872 "Address Family modifier\n"
6873 "Address Family modifier\n")
6874{
6875 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006876 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6877 NULL);
paul718e3742002-12-13 20:15:29 +00006878
ajs5a646652004-11-05 01:25:55 +00006879 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006880}
6881
Michael Lambert95cbbd22010-07-23 14:43:04 -04006882ALIAS (show_ip_bgp_ipv4,
6883 show_bgp_ipv4_safi_cmd,
6884 "show bgp ipv4 (unicast|multicast)",
6885 SHOW_STR
6886 BGP_STR
6887 "Address family\n"
6888 "Address Family modifier\n"
6889 "Address Family modifier\n")
6890
paul718e3742002-12-13 20:15:29 +00006891DEFUN (show_ip_bgp_route,
6892 show_ip_bgp_route_cmd,
6893 "show ip bgp A.B.C.D",
6894 SHOW_STR
6895 IP_STR
6896 BGP_STR
6897 "Network in the BGP routing table to display\n")
6898{
6899 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6900}
6901
6902DEFUN (show_ip_bgp_ipv4_route,
6903 show_ip_bgp_ipv4_route_cmd,
6904 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6905 SHOW_STR
6906 IP_STR
6907 BGP_STR
6908 "Address family\n"
6909 "Address Family modifier\n"
6910 "Address Family modifier\n"
6911 "Network in the BGP routing table to display\n")
6912{
6913 if (strncmp (argv[0], "m", 1) == 0)
6914 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6915
6916 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6917}
6918
Michael Lambert95cbbd22010-07-23 14:43:04 -04006919ALIAS (show_ip_bgp_ipv4_route,
6920 show_bgp_ipv4_safi_route_cmd,
6921 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6922 SHOW_STR
6923 BGP_STR
6924 "Address family\n"
6925 "Address Family modifier\n"
6926 "Address Family modifier\n"
6927 "Network in the BGP routing table to display\n")
6928
paul718e3742002-12-13 20:15:29 +00006929DEFUN (show_ip_bgp_vpnv4_all_route,
6930 show_ip_bgp_vpnv4_all_route_cmd,
6931 "show ip bgp vpnv4 all A.B.C.D",
6932 SHOW_STR
6933 IP_STR
6934 BGP_STR
6935 "Display VPNv4 NLRI specific information\n"
6936 "Display information about all VPNv4 NLRIs\n"
6937 "Network in the BGP routing table to display\n")
6938{
6939 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6940}
6941
6942DEFUN (show_ip_bgp_vpnv4_rd_route,
6943 show_ip_bgp_vpnv4_rd_route_cmd,
6944 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6945 SHOW_STR
6946 IP_STR
6947 BGP_STR
6948 "Display VPNv4 NLRI specific information\n"
6949 "Display information for a route distinguisher\n"
6950 "VPN Route Distinguisher\n"
6951 "Network in the BGP routing table to display\n")
6952{
6953 int ret;
6954 struct prefix_rd prd;
6955
6956 ret = str2prefix_rd (argv[0], &prd);
6957 if (! ret)
6958 {
6959 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6960 return CMD_WARNING;
6961 }
6962 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6963}
6964
6965DEFUN (show_ip_bgp_prefix,
6966 show_ip_bgp_prefix_cmd,
6967 "show ip bgp A.B.C.D/M",
6968 SHOW_STR
6969 IP_STR
6970 BGP_STR
6971 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6972{
6973 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6974}
6975
6976DEFUN (show_ip_bgp_ipv4_prefix,
6977 show_ip_bgp_ipv4_prefix_cmd,
6978 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6979 SHOW_STR
6980 IP_STR
6981 BGP_STR
6982 "Address family\n"
6983 "Address Family modifier\n"
6984 "Address Family modifier\n"
6985 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6986{
6987 if (strncmp (argv[0], "m", 1) == 0)
6988 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6989
6990 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6991}
6992
Michael Lambert95cbbd22010-07-23 14:43:04 -04006993ALIAS (show_ip_bgp_ipv4_prefix,
6994 show_bgp_ipv4_safi_prefix_cmd,
6995 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6996 SHOW_STR
6997 BGP_STR
6998 "Address family\n"
6999 "Address Family modifier\n"
7000 "Address Family modifier\n"
7001 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7002
paul718e3742002-12-13 20:15:29 +00007003DEFUN (show_ip_bgp_vpnv4_all_prefix,
7004 show_ip_bgp_vpnv4_all_prefix_cmd,
7005 "show ip bgp vpnv4 all A.B.C.D/M",
7006 SHOW_STR
7007 IP_STR
7008 BGP_STR
7009 "Display VPNv4 NLRI specific information\n"
7010 "Display information about all VPNv4 NLRIs\n"
7011 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7012{
7013 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
7014}
7015
7016DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7017 show_ip_bgp_vpnv4_rd_prefix_cmd,
7018 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7019 SHOW_STR
7020 IP_STR
7021 BGP_STR
7022 "Display VPNv4 NLRI specific information\n"
7023 "Display information for a route distinguisher\n"
7024 "VPN Route Distinguisher\n"
7025 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7026{
7027 int ret;
7028 struct prefix_rd prd;
7029
7030 ret = str2prefix_rd (argv[0], &prd);
7031 if (! ret)
7032 {
7033 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7034 return CMD_WARNING;
7035 }
7036 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
7037}
7038
7039DEFUN (show_ip_bgp_view,
7040 show_ip_bgp_view_cmd,
7041 "show ip bgp view WORD",
7042 SHOW_STR
7043 IP_STR
7044 BGP_STR
7045 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007046 "View name\n")
paul718e3742002-12-13 20:15:29 +00007047{
paulbb46e942003-10-24 19:02:03 +00007048 struct bgp *bgp;
7049
7050 /* BGP structure lookup. */
7051 bgp = bgp_lookup_by_name (argv[0]);
7052 if (bgp == NULL)
7053 {
7054 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7055 return CMD_WARNING;
7056 }
7057
ajs5a646652004-11-05 01:25:55 +00007058 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007059}
7060
7061DEFUN (show_ip_bgp_view_route,
7062 show_ip_bgp_view_route_cmd,
7063 "show ip bgp view WORD A.B.C.D",
7064 SHOW_STR
7065 IP_STR
7066 BGP_STR
7067 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007068 "View name\n"
paul718e3742002-12-13 20:15:29 +00007069 "Network in the BGP routing table to display\n")
7070{
7071 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7072}
7073
7074DEFUN (show_ip_bgp_view_prefix,
7075 show_ip_bgp_view_prefix_cmd,
7076 "show ip bgp view WORD A.B.C.D/M",
7077 SHOW_STR
7078 IP_STR
7079 BGP_STR
7080 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007081 "View name\n"
paul718e3742002-12-13 20:15:29 +00007082 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7083{
7084 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7085}
7086
7087#ifdef HAVE_IPV6
7088DEFUN (show_bgp,
7089 show_bgp_cmd,
7090 "show bgp",
7091 SHOW_STR
7092 BGP_STR)
7093{
ajs5a646652004-11-05 01:25:55 +00007094 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7095 NULL);
paul718e3742002-12-13 20:15:29 +00007096}
7097
7098ALIAS (show_bgp,
7099 show_bgp_ipv6_cmd,
7100 "show bgp ipv6",
7101 SHOW_STR
7102 BGP_STR
7103 "Address family\n")
7104
Michael Lambert95cbbd22010-07-23 14:43:04 -04007105DEFUN (show_bgp_ipv6_safi,
7106 show_bgp_ipv6_safi_cmd,
7107 "show bgp ipv6 (unicast|multicast)",
7108 SHOW_STR
7109 BGP_STR
7110 "Address family\n"
7111 "Address Family modifier\n"
7112 "Address Family modifier\n")
7113{
7114 if (strncmp (argv[0], "m", 1) == 0)
7115 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7116 NULL);
7117
7118 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7119}
7120
paul718e3742002-12-13 20:15:29 +00007121/* old command */
7122DEFUN (show_ipv6_bgp,
7123 show_ipv6_bgp_cmd,
7124 "show ipv6 bgp",
7125 SHOW_STR
7126 IP_STR
7127 BGP_STR)
7128{
ajs5a646652004-11-05 01:25:55 +00007129 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7130 NULL);
paul718e3742002-12-13 20:15:29 +00007131}
7132
7133DEFUN (show_bgp_route,
7134 show_bgp_route_cmd,
7135 "show bgp X:X::X:X",
7136 SHOW_STR
7137 BGP_STR
7138 "Network in the BGP routing table to display\n")
7139{
7140 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7141}
7142
7143ALIAS (show_bgp_route,
7144 show_bgp_ipv6_route_cmd,
7145 "show bgp ipv6 X:X::X:X",
7146 SHOW_STR
7147 BGP_STR
7148 "Address family\n"
7149 "Network in the BGP routing table to display\n")
7150
Michael Lambert95cbbd22010-07-23 14:43:04 -04007151DEFUN (show_bgp_ipv6_safi_route,
7152 show_bgp_ipv6_safi_route_cmd,
7153 "show bgp ipv6 (unicast|multicast) X:X::X:X",
7154 SHOW_STR
7155 BGP_STR
7156 "Address family\n"
7157 "Address Family modifier\n"
7158 "Address Family modifier\n"
7159 "Network in the BGP routing table to display\n")
7160{
7161 if (strncmp (argv[0], "m", 1) == 0)
7162 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7163
7164 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7165}
7166
paul718e3742002-12-13 20:15:29 +00007167/* old command */
7168DEFUN (show_ipv6_bgp_route,
7169 show_ipv6_bgp_route_cmd,
7170 "show ipv6 bgp X:X::X:X",
7171 SHOW_STR
7172 IP_STR
7173 BGP_STR
7174 "Network in the BGP routing table to display\n")
7175{
7176 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7177}
7178
7179DEFUN (show_bgp_prefix,
7180 show_bgp_prefix_cmd,
7181 "show bgp X:X::X:X/M",
7182 SHOW_STR
7183 BGP_STR
7184 "IPv6 prefix <network>/<length>\n")
7185{
7186 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7187}
7188
7189ALIAS (show_bgp_prefix,
7190 show_bgp_ipv6_prefix_cmd,
7191 "show bgp ipv6 X:X::X:X/M",
7192 SHOW_STR
7193 BGP_STR
7194 "Address family\n"
7195 "IPv6 prefix <network>/<length>\n")
7196
Michael Lambert95cbbd22010-07-23 14:43:04 -04007197DEFUN (show_bgp_ipv6_safi_prefix,
7198 show_bgp_ipv6_safi_prefix_cmd,
7199 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7200 SHOW_STR
7201 BGP_STR
7202 "Address family\n"
7203 "Address Family modifier\n"
7204 "Address Family modifier\n"
7205 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7206{
7207 if (strncmp (argv[0], "m", 1) == 0)
7208 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7209
7210 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7211}
7212
paul718e3742002-12-13 20:15:29 +00007213/* old command */
7214DEFUN (show_ipv6_bgp_prefix,
7215 show_ipv6_bgp_prefix_cmd,
7216 "show ipv6 bgp X:X::X:X/M",
7217 SHOW_STR
7218 IP_STR
7219 BGP_STR
7220 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7221{
7222 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7223}
7224
paulbb46e942003-10-24 19:02:03 +00007225DEFUN (show_bgp_view,
7226 show_bgp_view_cmd,
7227 "show bgp view WORD",
7228 SHOW_STR
7229 BGP_STR
7230 "BGP view\n"
7231 "View name\n")
7232{
7233 struct bgp *bgp;
7234
7235 /* BGP structure lookup. */
7236 bgp = bgp_lookup_by_name (argv[0]);
7237 if (bgp == NULL)
7238 {
7239 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7240 return CMD_WARNING;
7241 }
7242
ajs5a646652004-11-05 01:25:55 +00007243 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007244}
7245
7246ALIAS (show_bgp_view,
7247 show_bgp_view_ipv6_cmd,
7248 "show bgp view WORD ipv6",
7249 SHOW_STR
7250 BGP_STR
7251 "BGP view\n"
7252 "View name\n"
7253 "Address family\n")
7254
7255DEFUN (show_bgp_view_route,
7256 show_bgp_view_route_cmd,
7257 "show bgp view WORD X:X::X:X",
7258 SHOW_STR
7259 BGP_STR
7260 "BGP view\n"
7261 "View name\n"
7262 "Network in the BGP routing table to display\n")
7263{
7264 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7265}
7266
7267ALIAS (show_bgp_view_route,
7268 show_bgp_view_ipv6_route_cmd,
7269 "show bgp view WORD ipv6 X:X::X:X",
7270 SHOW_STR
7271 BGP_STR
7272 "BGP view\n"
7273 "View name\n"
7274 "Address family\n"
7275 "Network in the BGP routing table to display\n")
7276
7277DEFUN (show_bgp_view_prefix,
7278 show_bgp_view_prefix_cmd,
7279 "show bgp view WORD X:X::X:X/M",
7280 SHOW_STR
7281 BGP_STR
7282 "BGP view\n"
7283 "View name\n"
7284 "IPv6 prefix <network>/<length>\n")
7285{
7286 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7287}
7288
7289ALIAS (show_bgp_view_prefix,
7290 show_bgp_view_ipv6_prefix_cmd,
7291 "show bgp view WORD ipv6 X:X::X:X/M",
7292 SHOW_STR
7293 BGP_STR
7294 "BGP view\n"
7295 "View name\n"
7296 "Address family\n"
7297 "IPv6 prefix <network>/<length>\n")
7298
paul718e3742002-12-13 20:15:29 +00007299/* old command */
7300DEFUN (show_ipv6_mbgp,
7301 show_ipv6_mbgp_cmd,
7302 "show ipv6 mbgp",
7303 SHOW_STR
7304 IP_STR
7305 MBGP_STR)
7306{
ajs5a646652004-11-05 01:25:55 +00007307 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7308 NULL);
paul718e3742002-12-13 20:15:29 +00007309}
7310
7311/* old command */
7312DEFUN (show_ipv6_mbgp_route,
7313 show_ipv6_mbgp_route_cmd,
7314 "show ipv6 mbgp X:X::X:X",
7315 SHOW_STR
7316 IP_STR
7317 MBGP_STR
7318 "Network in the MBGP routing table to display\n")
7319{
7320 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7321}
7322
7323/* old command */
7324DEFUN (show_ipv6_mbgp_prefix,
7325 show_ipv6_mbgp_prefix_cmd,
7326 "show ipv6 mbgp X:X::X:X/M",
7327 SHOW_STR
7328 IP_STR
7329 MBGP_STR
7330 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7331{
7332 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7333}
7334#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007335
paul718e3742002-12-13 20:15:29 +00007336
paul94f2b392005-06-28 12:44:16 +00007337static int
paulfd79ac92004-10-13 05:06:08 +00007338bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007339 safi_t safi, enum bgp_show_type type)
7340{
7341 int i;
7342 struct buffer *b;
7343 char *regstr;
7344 int first;
7345 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007346 int rc;
paul718e3742002-12-13 20:15:29 +00007347
7348 first = 0;
7349 b = buffer_new (1024);
7350 for (i = 0; i < argc; i++)
7351 {
7352 if (first)
7353 buffer_putc (b, ' ');
7354 else
7355 {
7356 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7357 continue;
7358 first = 1;
7359 }
7360
7361 buffer_putstr (b, argv[i]);
7362 }
7363 buffer_putc (b, '\0');
7364
7365 regstr = buffer_getstr (b);
7366 buffer_free (b);
7367
7368 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007369 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007370 if (! regex)
7371 {
7372 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7373 VTY_NEWLINE);
7374 return CMD_WARNING;
7375 }
7376
ajs5a646652004-11-05 01:25:55 +00007377 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7378 bgp_regex_free (regex);
7379 return rc;
paul718e3742002-12-13 20:15:29 +00007380}
7381
7382DEFUN (show_ip_bgp_regexp,
7383 show_ip_bgp_regexp_cmd,
7384 "show ip bgp regexp .LINE",
7385 SHOW_STR
7386 IP_STR
7387 BGP_STR
7388 "Display routes matching the AS path regular expression\n"
7389 "A regular-expression to match the BGP AS paths\n")
7390{
7391 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7392 bgp_show_type_regexp);
7393}
7394
7395DEFUN (show_ip_bgp_flap_regexp,
7396 show_ip_bgp_flap_regexp_cmd,
7397 "show ip bgp flap-statistics regexp .LINE",
7398 SHOW_STR
7399 IP_STR
7400 BGP_STR
7401 "Display flap statistics of routes\n"
7402 "Display routes matching the AS path regular expression\n"
7403 "A regular-expression to match the BGP AS paths\n")
7404{
7405 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7406 bgp_show_type_flap_regexp);
7407}
7408
Balaji3921cc52015-05-16 23:12:17 +05307409ALIAS (show_ip_bgp_flap_regexp,
7410 show_ip_bgp_damp_flap_regexp_cmd,
7411 "show ip bgp dampening flap-statistics regexp .LINE",
7412 SHOW_STR
7413 IP_STR
7414 BGP_STR
7415 "Display detailed information about dampening\n"
7416 "Display flap statistics of routes\n"
7417 "Display routes matching the AS path regular expression\n"
7418 "A regular-expression to match the BGP AS paths\n")
7419
paul718e3742002-12-13 20:15:29 +00007420DEFUN (show_ip_bgp_ipv4_regexp,
7421 show_ip_bgp_ipv4_regexp_cmd,
7422 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7423 SHOW_STR
7424 IP_STR
7425 BGP_STR
7426 "Address family\n"
7427 "Address Family modifier\n"
7428 "Address Family modifier\n"
7429 "Display routes matching the AS path regular expression\n"
7430 "A regular-expression to match the BGP AS paths\n")
7431{
7432 if (strncmp (argv[0], "m", 1) == 0)
7433 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7434 bgp_show_type_regexp);
7435
7436 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7437 bgp_show_type_regexp);
7438}
7439
7440#ifdef HAVE_IPV6
7441DEFUN (show_bgp_regexp,
7442 show_bgp_regexp_cmd,
7443 "show bgp regexp .LINE",
7444 SHOW_STR
7445 BGP_STR
7446 "Display routes matching the AS path regular expression\n"
7447 "A regular-expression to match the BGP AS paths\n")
7448{
7449 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7450 bgp_show_type_regexp);
7451}
7452
7453ALIAS (show_bgp_regexp,
7454 show_bgp_ipv6_regexp_cmd,
7455 "show bgp ipv6 regexp .LINE",
7456 SHOW_STR
7457 BGP_STR
7458 "Address family\n"
7459 "Display routes matching the AS path regular expression\n"
7460 "A regular-expression to match the BGP AS paths\n")
7461
7462/* old command */
7463DEFUN (show_ipv6_bgp_regexp,
7464 show_ipv6_bgp_regexp_cmd,
7465 "show ipv6 bgp regexp .LINE",
7466 SHOW_STR
7467 IP_STR
7468 BGP_STR
7469 "Display routes matching the AS path regular expression\n"
7470 "A regular-expression to match the BGP AS paths\n")
7471{
7472 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7473 bgp_show_type_regexp);
7474}
7475
7476/* old command */
7477DEFUN (show_ipv6_mbgp_regexp,
7478 show_ipv6_mbgp_regexp_cmd,
7479 "show ipv6 mbgp regexp .LINE",
7480 SHOW_STR
7481 IP_STR
7482 BGP_STR
7483 "Display routes matching the AS path regular expression\n"
7484 "A regular-expression to match the MBGP AS paths\n")
7485{
7486 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7487 bgp_show_type_regexp);
7488}
7489#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007490
paul94f2b392005-06-28 12:44:16 +00007491static int
paulfd79ac92004-10-13 05:06:08 +00007492bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007493 safi_t safi, enum bgp_show_type type)
7494{
7495 struct prefix_list *plist;
7496
7497 plist = prefix_list_lookup (afi, prefix_list_str);
7498 if (plist == NULL)
7499 {
7500 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7501 prefix_list_str, VTY_NEWLINE);
7502 return CMD_WARNING;
7503 }
7504
ajs5a646652004-11-05 01:25:55 +00007505 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007506}
7507
7508DEFUN (show_ip_bgp_prefix_list,
7509 show_ip_bgp_prefix_list_cmd,
7510 "show ip bgp prefix-list WORD",
7511 SHOW_STR
7512 IP_STR
7513 BGP_STR
7514 "Display routes conforming to the prefix-list\n"
7515 "IP prefix-list name\n")
7516{
7517 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7518 bgp_show_type_prefix_list);
7519}
7520
7521DEFUN (show_ip_bgp_flap_prefix_list,
7522 show_ip_bgp_flap_prefix_list_cmd,
7523 "show ip bgp flap-statistics prefix-list WORD",
7524 SHOW_STR
7525 IP_STR
7526 BGP_STR
7527 "Display flap statistics of routes\n"
7528 "Display routes conforming to the prefix-list\n"
7529 "IP prefix-list name\n")
7530{
7531 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7532 bgp_show_type_flap_prefix_list);
7533}
7534
Balaji3921cc52015-05-16 23:12:17 +05307535ALIAS (show_ip_bgp_flap_prefix_list,
7536 show_ip_bgp_damp_flap_prefix_list_cmd,
7537 "show ip bgp dampening flap-statistics prefix-list WORD",
7538 SHOW_STR
7539 IP_STR
7540 BGP_STR
7541 "Display detailed information about dampening\n"
7542 "Display flap statistics of routes\n"
7543 "Display routes conforming to the prefix-list\n"
7544 "IP prefix-list name\n")
7545
paul718e3742002-12-13 20:15:29 +00007546DEFUN (show_ip_bgp_ipv4_prefix_list,
7547 show_ip_bgp_ipv4_prefix_list_cmd,
7548 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7549 SHOW_STR
7550 IP_STR
7551 BGP_STR
7552 "Address family\n"
7553 "Address Family modifier\n"
7554 "Address Family modifier\n"
7555 "Display routes conforming to the prefix-list\n"
7556 "IP prefix-list name\n")
7557{
7558 if (strncmp (argv[0], "m", 1) == 0)
7559 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7560 bgp_show_type_prefix_list);
7561
7562 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7563 bgp_show_type_prefix_list);
7564}
7565
7566#ifdef HAVE_IPV6
7567DEFUN (show_bgp_prefix_list,
7568 show_bgp_prefix_list_cmd,
7569 "show bgp prefix-list WORD",
7570 SHOW_STR
7571 BGP_STR
7572 "Display routes conforming to the prefix-list\n"
7573 "IPv6 prefix-list name\n")
7574{
7575 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7576 bgp_show_type_prefix_list);
7577}
7578
7579ALIAS (show_bgp_prefix_list,
7580 show_bgp_ipv6_prefix_list_cmd,
7581 "show bgp ipv6 prefix-list WORD",
7582 SHOW_STR
7583 BGP_STR
7584 "Address family\n"
7585 "Display routes conforming to the prefix-list\n"
7586 "IPv6 prefix-list name\n")
7587
7588/* old command */
7589DEFUN (show_ipv6_bgp_prefix_list,
7590 show_ipv6_bgp_prefix_list_cmd,
7591 "show ipv6 bgp prefix-list WORD",
7592 SHOW_STR
7593 IPV6_STR
7594 BGP_STR
7595 "Display routes matching the prefix-list\n"
7596 "IPv6 prefix-list name\n")
7597{
7598 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7599 bgp_show_type_prefix_list);
7600}
7601
7602/* old command */
7603DEFUN (show_ipv6_mbgp_prefix_list,
7604 show_ipv6_mbgp_prefix_list_cmd,
7605 "show ipv6 mbgp prefix-list WORD",
7606 SHOW_STR
7607 IPV6_STR
7608 MBGP_STR
7609 "Display routes matching the prefix-list\n"
7610 "IPv6 prefix-list name\n")
7611{
7612 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7613 bgp_show_type_prefix_list);
7614}
7615#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007616
paul94f2b392005-06-28 12:44:16 +00007617static int
paulfd79ac92004-10-13 05:06:08 +00007618bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007619 safi_t safi, enum bgp_show_type type)
7620{
7621 struct as_list *as_list;
7622
7623 as_list = as_list_lookup (filter);
7624 if (as_list == NULL)
7625 {
7626 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7627 return CMD_WARNING;
7628 }
7629
ajs5a646652004-11-05 01:25:55 +00007630 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007631}
7632
7633DEFUN (show_ip_bgp_filter_list,
7634 show_ip_bgp_filter_list_cmd,
7635 "show ip bgp filter-list WORD",
7636 SHOW_STR
7637 IP_STR
7638 BGP_STR
7639 "Display routes conforming to the filter-list\n"
7640 "Regular expression access list name\n")
7641{
7642 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7643 bgp_show_type_filter_list);
7644}
7645
7646DEFUN (show_ip_bgp_flap_filter_list,
7647 show_ip_bgp_flap_filter_list_cmd,
7648 "show ip bgp flap-statistics filter-list WORD",
7649 SHOW_STR
7650 IP_STR
7651 BGP_STR
7652 "Display flap statistics of routes\n"
7653 "Display routes conforming to the filter-list\n"
7654 "Regular expression access list name\n")
7655{
7656 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7657 bgp_show_type_flap_filter_list);
7658}
7659
Balaji3921cc52015-05-16 23:12:17 +05307660ALIAS (show_ip_bgp_flap_filter_list,
7661 show_ip_bgp_damp_flap_filter_list_cmd,
7662 "show ip bgp dampening flap-statistics filter-list WORD",
7663 SHOW_STR
7664 IP_STR
7665 BGP_STR
7666 "Display detailed information about dampening\n"
7667 "Display flap statistics of routes\n"
7668 "Display routes conforming to the filter-list\n"
7669 "Regular expression access list name\n")
7670
paul718e3742002-12-13 20:15:29 +00007671DEFUN (show_ip_bgp_ipv4_filter_list,
7672 show_ip_bgp_ipv4_filter_list_cmd,
7673 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7674 SHOW_STR
7675 IP_STR
7676 BGP_STR
7677 "Address family\n"
7678 "Address Family modifier\n"
7679 "Address Family modifier\n"
7680 "Display routes conforming to the filter-list\n"
7681 "Regular expression access list name\n")
7682{
7683 if (strncmp (argv[0], "m", 1) == 0)
7684 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7685 bgp_show_type_filter_list);
7686
7687 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7688 bgp_show_type_filter_list);
7689}
7690
7691#ifdef HAVE_IPV6
7692DEFUN (show_bgp_filter_list,
7693 show_bgp_filter_list_cmd,
7694 "show bgp filter-list WORD",
7695 SHOW_STR
7696 BGP_STR
7697 "Display routes conforming to the filter-list\n"
7698 "Regular expression access list name\n")
7699{
7700 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7701 bgp_show_type_filter_list);
7702}
7703
7704ALIAS (show_bgp_filter_list,
7705 show_bgp_ipv6_filter_list_cmd,
7706 "show bgp ipv6 filter-list WORD",
7707 SHOW_STR
7708 BGP_STR
7709 "Address family\n"
7710 "Display routes conforming to the filter-list\n"
7711 "Regular expression access list name\n")
7712
7713/* old command */
7714DEFUN (show_ipv6_bgp_filter_list,
7715 show_ipv6_bgp_filter_list_cmd,
7716 "show ipv6 bgp filter-list WORD",
7717 SHOW_STR
7718 IPV6_STR
7719 BGP_STR
7720 "Display routes conforming to the filter-list\n"
7721 "Regular expression access list name\n")
7722{
7723 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7724 bgp_show_type_filter_list);
7725}
7726
7727/* old command */
7728DEFUN (show_ipv6_mbgp_filter_list,
7729 show_ipv6_mbgp_filter_list_cmd,
7730 "show ipv6 mbgp filter-list WORD",
7731 SHOW_STR
7732 IPV6_STR
7733 MBGP_STR
7734 "Display routes conforming to the filter-list\n"
7735 "Regular expression access list name\n")
7736{
7737 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7738 bgp_show_type_filter_list);
7739}
7740#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007741
Balaji3921cc52015-05-16 23:12:17 +05307742DEFUN (show_ip_bgp_dampening_info,
7743 show_ip_bgp_dampening_params_cmd,
7744 "show ip bgp dampening parameters",
7745 SHOW_STR
7746 IP_STR
7747 BGP_STR
7748 "Display detailed information about dampening\n"
7749 "Display detail of configured dampening parameters\n")
7750{
7751 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
7752}
7753
paul94f2b392005-06-28 12:44:16 +00007754static int
paulfd79ac92004-10-13 05:06:08 +00007755bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007756 safi_t safi, enum bgp_show_type type)
7757{
7758 struct route_map *rmap;
7759
7760 rmap = route_map_lookup_by_name (rmap_str);
7761 if (! rmap)
7762 {
7763 vty_out (vty, "%% %s is not a valid route-map name%s",
7764 rmap_str, VTY_NEWLINE);
7765 return CMD_WARNING;
7766 }
7767
ajs5a646652004-11-05 01:25:55 +00007768 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007769}
7770
7771DEFUN (show_ip_bgp_route_map,
7772 show_ip_bgp_route_map_cmd,
7773 "show ip bgp route-map WORD",
7774 SHOW_STR
7775 IP_STR
7776 BGP_STR
7777 "Display routes matching the route-map\n"
7778 "A route-map to match on\n")
7779{
7780 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7781 bgp_show_type_route_map);
7782}
7783
7784DEFUN (show_ip_bgp_flap_route_map,
7785 show_ip_bgp_flap_route_map_cmd,
7786 "show ip bgp flap-statistics route-map WORD",
7787 SHOW_STR
7788 IP_STR
7789 BGP_STR
7790 "Display flap statistics of routes\n"
7791 "Display routes matching the route-map\n"
7792 "A route-map to match on\n")
7793{
7794 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7795 bgp_show_type_flap_route_map);
7796}
7797
Balaji3921cc52015-05-16 23:12:17 +05307798ALIAS (show_ip_bgp_flap_route_map,
7799 show_ip_bgp_damp_flap_route_map_cmd,
7800 "show ip bgp dampening flap-statistics route-map WORD",
7801 SHOW_STR
7802 IP_STR
7803 BGP_STR
7804 "Display detailed information about dampening\n"
7805 "Display flap statistics of routes\n"
7806 "Display routes matching the route-map\n"
7807 "A route-map to match on\n")
7808
paul718e3742002-12-13 20:15:29 +00007809DEFUN (show_ip_bgp_ipv4_route_map,
7810 show_ip_bgp_ipv4_route_map_cmd,
7811 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7812 SHOW_STR
7813 IP_STR
7814 BGP_STR
7815 "Address family\n"
7816 "Address Family modifier\n"
7817 "Address Family modifier\n"
7818 "Display routes matching the route-map\n"
7819 "A route-map to match on\n")
7820{
7821 if (strncmp (argv[0], "m", 1) == 0)
7822 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7823 bgp_show_type_route_map);
7824
7825 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7826 bgp_show_type_route_map);
7827}
7828
7829DEFUN (show_bgp_route_map,
7830 show_bgp_route_map_cmd,
7831 "show bgp route-map WORD",
7832 SHOW_STR
7833 BGP_STR
7834 "Display routes matching the route-map\n"
7835 "A route-map to match on\n")
7836{
7837 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7838 bgp_show_type_route_map);
7839}
7840
7841ALIAS (show_bgp_route_map,
7842 show_bgp_ipv6_route_map_cmd,
7843 "show bgp ipv6 route-map WORD",
7844 SHOW_STR
7845 BGP_STR
7846 "Address family\n"
7847 "Display routes matching the route-map\n"
7848 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007849
paul718e3742002-12-13 20:15:29 +00007850DEFUN (show_ip_bgp_cidr_only,
7851 show_ip_bgp_cidr_only_cmd,
7852 "show ip bgp cidr-only",
7853 SHOW_STR
7854 IP_STR
7855 BGP_STR
7856 "Display only routes with non-natural netmasks\n")
7857{
7858 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007859 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007860}
7861
7862DEFUN (show_ip_bgp_flap_cidr_only,
7863 show_ip_bgp_flap_cidr_only_cmd,
7864 "show ip bgp flap-statistics cidr-only",
7865 SHOW_STR
7866 IP_STR
7867 BGP_STR
7868 "Display flap statistics of routes\n"
7869 "Display only routes with non-natural netmasks\n")
7870{
7871 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007872 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007873}
7874
Balaji3921cc52015-05-16 23:12:17 +05307875ALIAS (show_ip_bgp_flap_cidr_only,
7876 show_ip_bgp_damp_flap_cidr_only_cmd,
7877 "show ip bgp dampening flap-statistics cidr-only",
7878 SHOW_STR
7879 IP_STR
7880 BGP_STR
7881 "Display detailed information about dampening\n"
7882 "Display flap statistics of routes\n"
7883 "Display only routes with non-natural netmasks\n")
7884
paul718e3742002-12-13 20:15:29 +00007885DEFUN (show_ip_bgp_ipv4_cidr_only,
7886 show_ip_bgp_ipv4_cidr_only_cmd,
7887 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7888 SHOW_STR
7889 IP_STR
7890 BGP_STR
7891 "Address family\n"
7892 "Address Family modifier\n"
7893 "Address Family modifier\n"
7894 "Display only routes with non-natural netmasks\n")
7895{
7896 if (strncmp (argv[0], "m", 1) == 0)
7897 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007898 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007899
7900 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007901 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007902}
David Lamparter6b0655a2014-06-04 06:53:35 +02007903
paul718e3742002-12-13 20:15:29 +00007904DEFUN (show_ip_bgp_community_all,
7905 show_ip_bgp_community_all_cmd,
7906 "show ip bgp community",
7907 SHOW_STR
7908 IP_STR
7909 BGP_STR
7910 "Display routes matching the communities\n")
7911{
7912 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007913 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007914}
7915
7916DEFUN (show_ip_bgp_ipv4_community_all,
7917 show_ip_bgp_ipv4_community_all_cmd,
7918 "show ip bgp ipv4 (unicast|multicast) community",
7919 SHOW_STR
7920 IP_STR
7921 BGP_STR
7922 "Address family\n"
7923 "Address Family modifier\n"
7924 "Address Family modifier\n"
7925 "Display routes matching the communities\n")
7926{
7927 if (strncmp (argv[0], "m", 1) == 0)
7928 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007929 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007930
7931 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007932 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007933}
7934
7935#ifdef HAVE_IPV6
7936DEFUN (show_bgp_community_all,
7937 show_bgp_community_all_cmd,
7938 "show bgp community",
7939 SHOW_STR
7940 BGP_STR
7941 "Display routes matching the communities\n")
7942{
7943 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007944 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007945}
7946
7947ALIAS (show_bgp_community_all,
7948 show_bgp_ipv6_community_all_cmd,
7949 "show bgp ipv6 community",
7950 SHOW_STR
7951 BGP_STR
7952 "Address family\n"
7953 "Display routes matching the communities\n")
7954
7955/* old command */
7956DEFUN (show_ipv6_bgp_community_all,
7957 show_ipv6_bgp_community_all_cmd,
7958 "show ipv6 bgp community",
7959 SHOW_STR
7960 IPV6_STR
7961 BGP_STR
7962 "Display routes matching the communities\n")
7963{
7964 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007965 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007966}
7967
7968/* old command */
7969DEFUN (show_ipv6_mbgp_community_all,
7970 show_ipv6_mbgp_community_all_cmd,
7971 "show ipv6 mbgp community",
7972 SHOW_STR
7973 IPV6_STR
7974 MBGP_STR
7975 "Display routes matching the communities\n")
7976{
7977 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007978 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007979}
7980#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007981
paul94f2b392005-06-28 12:44:16 +00007982static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007983bgp_show_community (struct vty *vty, const char *view_name, int argc,
7984 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007985{
7986 struct community *com;
7987 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007988 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007989 int i;
7990 char *str;
7991 int first = 0;
7992
Michael Lambert95cbbd22010-07-23 14:43:04 -04007993 /* BGP structure lookup */
7994 if (view_name)
7995 {
7996 bgp = bgp_lookup_by_name (view_name);
7997 if (bgp == NULL)
7998 {
7999 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8000 return CMD_WARNING;
8001 }
8002 }
8003 else
8004 {
8005 bgp = bgp_get_default ();
8006 if (bgp == NULL)
8007 {
8008 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8009 return CMD_WARNING;
8010 }
8011 }
8012
paul718e3742002-12-13 20:15:29 +00008013 b = buffer_new (1024);
8014 for (i = 0; i < argc; i++)
8015 {
8016 if (first)
8017 buffer_putc (b, ' ');
8018 else
8019 {
8020 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8021 continue;
8022 first = 1;
8023 }
8024
8025 buffer_putstr (b, argv[i]);
8026 }
8027 buffer_putc (b, '\0');
8028
8029 str = buffer_getstr (b);
8030 buffer_free (b);
8031
8032 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00008033 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00008034 if (! com)
8035 {
8036 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8037 return CMD_WARNING;
8038 }
8039
Michael Lambert95cbbd22010-07-23 14:43:04 -04008040 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00008041 (exact ? bgp_show_type_community_exact :
8042 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00008043}
8044
8045DEFUN (show_ip_bgp_community,
8046 show_ip_bgp_community_cmd,
8047 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
8048 SHOW_STR
8049 IP_STR
8050 BGP_STR
8051 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008057 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008058}
8059
8060ALIAS (show_ip_bgp_community,
8061 show_ip_bgp_community2_cmd,
8062 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8063 SHOW_STR
8064 IP_STR
8065 BGP_STR
8066 "Display routes matching the communities\n"
8067 "community number\n"
8068 "Do not send outside local AS (well-known community)\n"
8069 "Do not advertise to any peer (well-known community)\n"
8070 "Do not export to next AS (well-known community)\n"
8071 "community number\n"
8072 "Do not send outside local AS (well-known community)\n"
8073 "Do not advertise to any peer (well-known community)\n"
8074 "Do not export to next AS (well-known community)\n")
8075
8076ALIAS (show_ip_bgp_community,
8077 show_ip_bgp_community3_cmd,
8078 "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)",
8079 SHOW_STR
8080 IP_STR
8081 BGP_STR
8082 "Display routes matching the communities\n"
8083 "community number\n"
8084 "Do not send outside local AS (well-known community)\n"
8085 "Do not advertise to any peer (well-known community)\n"
8086 "Do not export to next AS (well-known community)\n"
8087 "community number\n"
8088 "Do not send outside local AS (well-known community)\n"
8089 "Do not advertise to any peer (well-known community)\n"
8090 "Do not export to next AS (well-known community)\n"
8091 "community number\n"
8092 "Do not send outside local AS (well-known community)\n"
8093 "Do not advertise to any peer (well-known community)\n"
8094 "Do not export to next AS (well-known community)\n")
8095
8096ALIAS (show_ip_bgp_community,
8097 show_ip_bgp_community4_cmd,
8098 "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)",
8099 SHOW_STR
8100 IP_STR
8101 BGP_STR
8102 "Display routes matching the communities\n"
8103 "community number\n"
8104 "Do not send outside local AS (well-known community)\n"
8105 "Do not advertise to any peer (well-known community)\n"
8106 "Do not export to next AS (well-known community)\n"
8107 "community number\n"
8108 "Do not send outside local AS (well-known community)\n"
8109 "Do not advertise to any peer (well-known community)\n"
8110 "Do not export to next AS (well-known community)\n"
8111 "community number\n"
8112 "Do not send outside local AS (well-known community)\n"
8113 "Do not advertise to any peer (well-known community)\n"
8114 "Do not export to next AS (well-known community)\n"
8115 "community number\n"
8116 "Do not send outside local AS (well-known community)\n"
8117 "Do not advertise to any peer (well-known community)\n"
8118 "Do not export to next AS (well-known community)\n")
8119
8120DEFUN (show_ip_bgp_ipv4_community,
8121 show_ip_bgp_ipv4_community_cmd,
8122 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8123 SHOW_STR
8124 IP_STR
8125 BGP_STR
8126 "Address family\n"
8127 "Address Family modifier\n"
8128 "Address Family modifier\n"
8129 "Display routes matching the communities\n"
8130 "community number\n"
8131 "Do not send outside local AS (well-known community)\n"
8132 "Do not advertise to any peer (well-known community)\n"
8133 "Do not export to next AS (well-known community)\n")
8134{
8135 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008136 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008137
Michael Lambert95cbbd22010-07-23 14:43:04 -04008138 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008139}
8140
8141ALIAS (show_ip_bgp_ipv4_community,
8142 show_ip_bgp_ipv4_community2_cmd,
8143 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8144 SHOW_STR
8145 IP_STR
8146 BGP_STR
8147 "Address family\n"
8148 "Address Family modifier\n"
8149 "Address Family modifier\n"
8150 "Display routes matching the communities\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n")
8159
8160ALIAS (show_ip_bgp_ipv4_community,
8161 show_ip_bgp_ipv4_community3_cmd,
8162 "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)",
8163 SHOW_STR
8164 IP_STR
8165 BGP_STR
8166 "Address family\n"
8167 "Address Family modifier\n"
8168 "Address Family modifier\n"
8169 "Display routes matching the communities\n"
8170 "community number\n"
8171 "Do not send outside local AS (well-known community)\n"
8172 "Do not advertise to any peer (well-known community)\n"
8173 "Do not export to next AS (well-known community)\n"
8174 "community number\n"
8175 "Do not send outside local AS (well-known community)\n"
8176 "Do not advertise to any peer (well-known community)\n"
8177 "Do not export to next AS (well-known community)\n"
8178 "community number\n"
8179 "Do not send outside local AS (well-known community)\n"
8180 "Do not advertise to any peer (well-known community)\n"
8181 "Do not export to next AS (well-known community)\n")
8182
8183ALIAS (show_ip_bgp_ipv4_community,
8184 show_ip_bgp_ipv4_community4_cmd,
8185 "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)",
8186 SHOW_STR
8187 IP_STR
8188 BGP_STR
8189 "Address family\n"
8190 "Address Family modifier\n"
8191 "Address Family modifier\n"
8192 "Display routes matching the communities\n"
8193 "community number\n"
8194 "Do not send outside local AS (well-known community)\n"
8195 "Do not advertise to any peer (well-known community)\n"
8196 "Do not export to next AS (well-known community)\n"
8197 "community number\n"
8198 "Do not send outside local AS (well-known community)\n"
8199 "Do not advertise to any peer (well-known community)\n"
8200 "Do not export to next AS (well-known community)\n"
8201 "community number\n"
8202 "Do not send outside local AS (well-known community)\n"
8203 "Do not advertise to any peer (well-known community)\n"
8204 "Do not export to next AS (well-known community)\n"
8205 "community number\n"
8206 "Do not send outside local AS (well-known community)\n"
8207 "Do not advertise to any peer (well-known community)\n"
8208 "Do not export to next AS (well-known community)\n")
8209
Michael Lambert95cbbd22010-07-23 14:43:04 -04008210DEFUN (show_bgp_view_afi_safi_community_all,
8211 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008212 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008213 SHOW_STR
8214 BGP_STR
8215 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008216 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008217 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008218 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008219 "Address Family modifier\n"
8220 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008221 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008222{
8223 int afi;
8224 int safi;
8225 struct bgp *bgp;
8226
8227 /* BGP structure lookup. */
8228 bgp = bgp_lookup_by_name (argv[0]);
8229 if (bgp == NULL)
8230 {
8231 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8232 return CMD_WARNING;
8233 }
8234
Michael Lambert95cbbd22010-07-23 14:43:04 -04008235 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8236 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008237 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8238}
8239
8240DEFUN (show_bgp_view_afi_safi_community,
8241 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008242 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008243 SHOW_STR
8244 BGP_STR
8245 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008246 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008247 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008248 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008249 "Address family modifier\n"
8250 "Address family modifier\n"
8251 "Display routes matching the communities\n"
8252 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n")
8256{
8257 int afi;
8258 int safi;
8259
Michael Lambert95cbbd22010-07-23 14:43:04 -04008260 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8261 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8262 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04008263}
8264
8265ALIAS (show_bgp_view_afi_safi_community,
8266 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008267 "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 -04008268 SHOW_STR
8269 BGP_STR
8270 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008271 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008272 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008273 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008274 "Address family modifier\n"
8275 "Address family modifier\n"
8276 "Display routes matching the communities\n"
8277 "community number\n"
8278 "Do not send outside local AS (well-known community)\n"
8279 "Do not advertise to any peer (well-known community)\n"
8280 "Do not export to next AS (well-known community)\n"
8281 "community number\n"
8282 "Do not send outside local AS (well-known community)\n"
8283 "Do not advertise to any peer (well-known community)\n"
8284 "Do not export to next AS (well-known community)\n")
8285
8286ALIAS (show_bgp_view_afi_safi_community,
8287 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008288 "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 -04008289 SHOW_STR
8290 BGP_STR
8291 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008292 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008293 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008294 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008295 "Address family modifier\n"
8296 "Address family modifier\n"
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_view_afi_safi_community,
8312 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008313 "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 -04008314 SHOW_STR
8315 BGP_STR
8316 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008317 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008318 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008319 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008320 "Address family modifier\n"
8321 "Address family modifier\n"
8322 "Display routes matching the communities\n"
8323 "community number\n"
8324 "Do not send outside local AS (well-known community)\n"
8325 "Do not advertise to any peer (well-known community)\n"
8326 "Do not export to next AS (well-known community)\n"
8327 "community number\n"
8328 "Do not send outside local AS (well-known community)\n"
8329 "Do not advertise to any peer (well-known community)\n"
8330 "Do not export to next AS (well-known community)\n"
8331 "community number\n"
8332 "Do not send outside local AS (well-known community)\n"
8333 "Do not advertise to any peer (well-known community)\n"
8334 "Do not export to next AS (well-known community)\n"
8335 "community number\n"
8336 "Do not send outside local AS (well-known community)\n"
8337 "Do not advertise to any peer (well-known community)\n"
8338 "Do not export to next AS (well-known community)\n")
8339
paul718e3742002-12-13 20:15:29 +00008340DEFUN (show_ip_bgp_community_exact,
8341 show_ip_bgp_community_exact_cmd,
8342 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8343 SHOW_STR
8344 IP_STR
8345 BGP_STR
8346 "Display routes matching the communities\n"
8347 "community number\n"
8348 "Do not send outside local AS (well-known community)\n"
8349 "Do not advertise to any peer (well-known community)\n"
8350 "Do not export to next AS (well-known community)\n"
8351 "Exact match of the communities")
8352{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008353 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008354}
8355
8356ALIAS (show_ip_bgp_community_exact,
8357 show_ip_bgp_community2_exact_cmd,
8358 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8359 SHOW_STR
8360 IP_STR
8361 BGP_STR
8362 "Display routes matching the communities\n"
8363 "community number\n"
8364 "Do not send outside local AS (well-known community)\n"
8365 "Do not advertise to any peer (well-known community)\n"
8366 "Do not export to next AS (well-known community)\n"
8367 "community number\n"
8368 "Do not send outside local AS (well-known community)\n"
8369 "Do not advertise to any peer (well-known community)\n"
8370 "Do not export to next AS (well-known community)\n"
8371 "Exact match of the communities")
8372
8373ALIAS (show_ip_bgp_community_exact,
8374 show_ip_bgp_community3_exact_cmd,
8375 "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",
8376 SHOW_STR
8377 IP_STR
8378 BGP_STR
8379 "Display routes matching the communities\n"
8380 "community number\n"
8381 "Do not send outside local AS (well-known community)\n"
8382 "Do not advertise to any peer (well-known community)\n"
8383 "Do not export to next AS (well-known community)\n"
8384 "community number\n"
8385 "Do not send outside local AS (well-known community)\n"
8386 "Do not advertise to any peer (well-known community)\n"
8387 "Do not export to next AS (well-known community)\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\n"
8392 "Exact match of the communities")
8393
8394ALIAS (show_ip_bgp_community_exact,
8395 show_ip_bgp_community4_exact_cmd,
8396 "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",
8397 SHOW_STR
8398 IP_STR
8399 BGP_STR
8400 "Display routes matching the communities\n"
8401 "community number\n"
8402 "Do not send outside local AS (well-known community)\n"
8403 "Do not advertise to any peer (well-known community)\n"
8404 "Do not export to next AS (well-known community)\n"
8405 "community number\n"
8406 "Do not send outside local AS (well-known community)\n"
8407 "Do not advertise to any peer (well-known community)\n"
8408 "Do not export to next AS (well-known community)\n"
8409 "community number\n"
8410 "Do not send outside local AS (well-known community)\n"
8411 "Do not advertise to any peer (well-known community)\n"
8412 "Do not export to next AS (well-known community)\n"
8413 "community number\n"
8414 "Do not send outside local AS (well-known community)\n"
8415 "Do not advertise to any peer (well-known community)\n"
8416 "Do not export to next AS (well-known community)\n"
8417 "Exact match of the communities")
8418
8419DEFUN (show_ip_bgp_ipv4_community_exact,
8420 show_ip_bgp_ipv4_community_exact_cmd,
8421 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8422 SHOW_STR
8423 IP_STR
8424 BGP_STR
8425 "Address family\n"
8426 "Address Family modifier\n"
8427 "Address Family modifier\n"
8428 "Display routes matching the communities\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "Exact match of the communities")
8434{
8435 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008436 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008437
Michael Lambert95cbbd22010-07-23 14:43:04 -04008438 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008439}
8440
8441ALIAS (show_ip_bgp_ipv4_community_exact,
8442 show_ip_bgp_ipv4_community2_exact_cmd,
8443 "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",
8444 SHOW_STR
8445 IP_STR
8446 BGP_STR
8447 "Address family\n"
8448 "Address Family modifier\n"
8449 "Address Family modifier\n"
8450 "Display routes matching the communities\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n"
8459 "Exact match of the communities")
8460
8461ALIAS (show_ip_bgp_ipv4_community_exact,
8462 show_ip_bgp_ipv4_community3_exact_cmd,
8463 "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",
8464 SHOW_STR
8465 IP_STR
8466 BGP_STR
8467 "Address family\n"
8468 "Address Family modifier\n"
8469 "Address Family modifier\n"
8470 "Display routes matching the communities\n"
8471 "community number\n"
8472 "Do not send outside local AS (well-known community)\n"
8473 "Do not advertise to any peer (well-known community)\n"
8474 "Do not export to next AS (well-known community)\n"
8475 "community number\n"
8476 "Do not send outside local AS (well-known community)\n"
8477 "Do not advertise to any peer (well-known community)\n"
8478 "Do not export to next AS (well-known community)\n"
8479 "community number\n"
8480 "Do not send outside local AS (well-known community)\n"
8481 "Do not advertise to any peer (well-known community)\n"
8482 "Do not export to next AS (well-known community)\n"
8483 "Exact match of the communities")
8484
8485ALIAS (show_ip_bgp_ipv4_community_exact,
8486 show_ip_bgp_ipv4_community4_exact_cmd,
8487 "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",
8488 SHOW_STR
8489 IP_STR
8490 BGP_STR
8491 "Address family\n"
8492 "Address Family modifier\n"
8493 "Address Family modifier\n"
8494 "Display routes matching the communities\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 "community number\n"
8500 "Do not send outside local AS (well-known community)\n"
8501 "Do not advertise to any peer (well-known community)\n"
8502 "Do not export to next AS (well-known community)\n"
8503 "community number\n"
8504 "Do not send outside local AS (well-known community)\n"
8505 "Do not advertise to any peer (well-known community)\n"
8506 "Do not export to next AS (well-known community)\n"
8507 "community number\n"
8508 "Do not send outside local AS (well-known community)\n"
8509 "Do not advertise to any peer (well-known community)\n"
8510 "Do not export to next AS (well-known community)\n"
8511 "Exact match of the communities")
8512
8513#ifdef HAVE_IPV6
8514DEFUN (show_bgp_community,
8515 show_bgp_community_cmd,
8516 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8517 SHOW_STR
8518 BGP_STR
8519 "Display routes matching the communities\n"
8520 "community number\n"
8521 "Do not send outside local AS (well-known community)\n"
8522 "Do not advertise to any peer (well-known community)\n"
8523 "Do not export to next AS (well-known community)\n")
8524{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008525 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008526}
8527
8528ALIAS (show_bgp_community,
8529 show_bgp_ipv6_community_cmd,
8530 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8531 SHOW_STR
8532 BGP_STR
8533 "Address family\n"
8534 "Display routes matching the communities\n"
8535 "community number\n"
8536 "Do not send outside local AS (well-known community)\n"
8537 "Do not advertise to any peer (well-known community)\n"
8538 "Do not export to next AS (well-known community)\n")
8539
8540ALIAS (show_bgp_community,
8541 show_bgp_community2_cmd,
8542 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8543 SHOW_STR
8544 BGP_STR
8545 "Display routes matching the communities\n"
8546 "community number\n"
8547 "Do not send outside local AS (well-known community)\n"
8548 "Do not advertise to any peer (well-known community)\n"
8549 "Do not export to next AS (well-known community)\n"
8550 "community number\n"
8551 "Do not send outside local AS (well-known community)\n"
8552 "Do not advertise to any peer (well-known community)\n"
8553 "Do not export to next AS (well-known community)\n")
8554
8555ALIAS (show_bgp_community,
8556 show_bgp_ipv6_community2_cmd,
8557 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8558 SHOW_STR
8559 BGP_STR
8560 "Address family\n"
8561 "Display routes matching the communities\n"
8562 "community number\n"
8563 "Do not send outside local AS (well-known community)\n"
8564 "Do not advertise to any peer (well-known community)\n"
8565 "Do not export to next AS (well-known community)\n"
8566 "community number\n"
8567 "Do not send outside local AS (well-known community)\n"
8568 "Do not advertise to any peer (well-known community)\n"
8569 "Do not export to next AS (well-known community)\n")
8570
8571ALIAS (show_bgp_community,
8572 show_bgp_community3_cmd,
8573 "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)",
8574 SHOW_STR
8575 BGP_STR
8576 "Display routes matching the communities\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 "community number\n"
8582 "Do not send outside local AS (well-known community)\n"
8583 "Do not advertise to any peer (well-known community)\n"
8584 "Do not export to next AS (well-known community)\n"
8585 "community number\n"
8586 "Do not send outside local AS (well-known community)\n"
8587 "Do not advertise to any peer (well-known community)\n"
8588 "Do not export to next AS (well-known community)\n")
8589
8590ALIAS (show_bgp_community,
8591 show_bgp_ipv6_community3_cmd,
8592 "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)",
8593 SHOW_STR
8594 BGP_STR
8595 "Address family\n"
8596 "Display routes matching the communities\n"
8597 "community number\n"
8598 "Do not send outside local AS (well-known community)\n"
8599 "Do not advertise to any peer (well-known community)\n"
8600 "Do not export to next AS (well-known community)\n"
8601 "community number\n"
8602 "Do not send outside local AS (well-known community)\n"
8603 "Do not advertise to any peer (well-known community)\n"
8604 "Do not export to next AS (well-known community)\n"
8605 "community number\n"
8606 "Do not send outside local AS (well-known community)\n"
8607 "Do not advertise to any peer (well-known community)\n"
8608 "Do not export to next AS (well-known community)\n")
8609
8610ALIAS (show_bgp_community,
8611 show_bgp_community4_cmd,
8612 "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)",
8613 SHOW_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 "community number\n"
8621 "Do not send outside local AS (well-known community)\n"
8622 "Do not advertise to any peer (well-known community)\n"
8623 "Do not export to next AS (well-known community)\n"
8624 "community number\n"
8625 "Do not send outside local AS (well-known community)\n"
8626 "Do not advertise to any peer (well-known community)\n"
8627 "Do not export to next AS (well-known community)\n"
8628 "community number\n"
8629 "Do not send outside local AS (well-known community)\n"
8630 "Do not advertise to any peer (well-known community)\n"
8631 "Do not export to next AS (well-known community)\n")
8632
8633ALIAS (show_bgp_community,
8634 show_bgp_ipv6_community4_cmd,
8635 "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)",
8636 SHOW_STR
8637 BGP_STR
8638 "Address family\n"
8639 "Display routes matching the communities\n"
8640 "community number\n"
8641 "Do not send outside local AS (well-known community)\n"
8642 "Do not advertise to any peer (well-known community)\n"
8643 "Do not export to next AS (well-known community)\n"
8644 "community number\n"
8645 "Do not send outside local AS (well-known community)\n"
8646 "Do not advertise to any peer (well-known community)\n"
8647 "Do not export to next AS (well-known community)\n"
8648 "community number\n"
8649 "Do not send outside local AS (well-known community)\n"
8650 "Do not advertise to any peer (well-known community)\n"
8651 "Do not export to next AS (well-known community)\n"
8652 "community number\n"
8653 "Do not send outside local AS (well-known community)\n"
8654 "Do not advertise to any peer (well-known community)\n"
8655 "Do not export to next AS (well-known community)\n")
8656
8657/* old command */
8658DEFUN (show_ipv6_bgp_community,
8659 show_ipv6_bgp_community_cmd,
8660 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8661 SHOW_STR
8662 IPV6_STR
8663 BGP_STR
8664 "Display routes matching the communities\n"
8665 "community number\n"
8666 "Do not send outside local AS (well-known community)\n"
8667 "Do not advertise to any peer (well-known community)\n"
8668 "Do not export to next AS (well-known community)\n")
8669{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008670 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008671}
8672
8673/* old command */
8674ALIAS (show_ipv6_bgp_community,
8675 show_ipv6_bgp_community2_cmd,
8676 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8677 SHOW_STR
8678 IPV6_STR
8679 BGP_STR
8680 "Display routes matching the communities\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
8690/* old command */
8691ALIAS (show_ipv6_bgp_community,
8692 show_ipv6_bgp_community3_cmd,
8693 "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)",
8694 SHOW_STR
8695 IPV6_STR
8696 BGP_STR
8697 "Display routes matching the communities\n"
8698 "community number\n"
8699 "Do not send outside local AS (well-known community)\n"
8700 "Do not advertise to any peer (well-known community)\n"
8701 "Do not export to next AS (well-known community)\n"
8702 "community number\n"
8703 "Do not send outside local AS (well-known community)\n"
8704 "Do not advertise to any peer (well-known community)\n"
8705 "Do not export to next AS (well-known community)\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n")
8710
8711/* old command */
8712ALIAS (show_ipv6_bgp_community,
8713 show_ipv6_bgp_community4_cmd,
8714 "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)",
8715 SHOW_STR
8716 IPV6_STR
8717 BGP_STR
8718 "Display routes matching the communities\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 "community number\n"
8724 "Do not send outside local AS (well-known community)\n"
8725 "Do not advertise to any peer (well-known community)\n"
8726 "Do not export to next AS (well-known community)\n"
8727 "community number\n"
8728 "Do not send outside local AS (well-known community)\n"
8729 "Do not advertise to any peer (well-known community)\n"
8730 "Do not export to next AS (well-known community)\n"
8731 "community number\n"
8732 "Do not send outside local AS (well-known community)\n"
8733 "Do not advertise to any peer (well-known community)\n"
8734 "Do not export to next AS (well-known community)\n")
8735
8736DEFUN (show_bgp_community_exact,
8737 show_bgp_community_exact_cmd,
8738 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8739 SHOW_STR
8740 BGP_STR
8741 "Display routes matching the communities\n"
8742 "community number\n"
8743 "Do not send outside local AS (well-known community)\n"
8744 "Do not advertise to any peer (well-known community)\n"
8745 "Do not export to next AS (well-known community)\n"
8746 "Exact match of the communities")
8747{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008748 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008749}
8750
8751ALIAS (show_bgp_community_exact,
8752 show_bgp_ipv6_community_exact_cmd,
8753 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8754 SHOW_STR
8755 BGP_STR
8756 "Address family\n"
8757 "Display routes matching the communities\n"
8758 "community number\n"
8759 "Do not send outside local AS (well-known community)\n"
8760 "Do not advertise to any peer (well-known community)\n"
8761 "Do not export to next AS (well-known community)\n"
8762 "Exact match of the communities")
8763
8764ALIAS (show_bgp_community_exact,
8765 show_bgp_community2_exact_cmd,
8766 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8767 SHOW_STR
8768 BGP_STR
8769 "Display routes matching the communities\n"
8770 "community number\n"
8771 "Do not send outside local AS (well-known community)\n"
8772 "Do not advertise to any peer (well-known community)\n"
8773 "Do not export to next AS (well-known community)\n"
8774 "community number\n"
8775 "Do not send outside local AS (well-known community)\n"
8776 "Do not advertise to any peer (well-known community)\n"
8777 "Do not export to next AS (well-known community)\n"
8778 "Exact match of the communities")
8779
8780ALIAS (show_bgp_community_exact,
8781 show_bgp_ipv6_community2_exact_cmd,
8782 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8783 SHOW_STR
8784 BGP_STR
8785 "Address family\n"
8786 "Display routes matching the communities\n"
8787 "community number\n"
8788 "Do not send outside local AS (well-known community)\n"
8789 "Do not advertise to any peer (well-known community)\n"
8790 "Do not export to next AS (well-known community)\n"
8791 "community number\n"
8792 "Do not send outside local AS (well-known community)\n"
8793 "Do not advertise to any peer (well-known community)\n"
8794 "Do not export to next AS (well-known community)\n"
8795 "Exact match of the communities")
8796
8797ALIAS (show_bgp_community_exact,
8798 show_bgp_community3_exact_cmd,
8799 "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",
8800 SHOW_STR
8801 BGP_STR
8802 "Display routes matching the communities\n"
8803 "community number\n"
8804 "Do not send outside local AS (well-known community)\n"
8805 "Do not advertise to any peer (well-known community)\n"
8806 "Do not export to next AS (well-known community)\n"
8807 "community number\n"
8808 "Do not send outside local AS (well-known community)\n"
8809 "Do not advertise to any peer (well-known community)\n"
8810 "Do not export to next AS (well-known community)\n"
8811 "community number\n"
8812 "Do not send outside local AS (well-known community)\n"
8813 "Do not advertise to any peer (well-known community)\n"
8814 "Do not export to next AS (well-known community)\n"
8815 "Exact match of the communities")
8816
8817ALIAS (show_bgp_community_exact,
8818 show_bgp_ipv6_community3_exact_cmd,
8819 "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",
8820 SHOW_STR
8821 BGP_STR
8822 "Address family\n"
8823 "Display routes matching the communities\n"
8824 "community number\n"
8825 "Do not send outside local AS (well-known community)\n"
8826 "Do not advertise to any peer (well-known community)\n"
8827 "Do not export to next AS (well-known community)\n"
8828 "community number\n"
8829 "Do not send outside local AS (well-known community)\n"
8830 "Do not advertise to any peer (well-known community)\n"
8831 "Do not export to next AS (well-known community)\n"
8832 "community number\n"
8833 "Do not send outside local AS (well-known community)\n"
8834 "Do not advertise to any peer (well-known community)\n"
8835 "Do not export to next AS (well-known community)\n"
8836 "Exact match of the communities")
8837
8838ALIAS (show_bgp_community_exact,
8839 show_bgp_community4_exact_cmd,
8840 "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",
8841 SHOW_STR
8842 BGP_STR
8843 "Display routes matching the communities\n"
8844 "community number\n"
8845 "Do not send outside local AS (well-known community)\n"
8846 "Do not advertise to any peer (well-known community)\n"
8847 "Do not export to next AS (well-known community)\n"
8848 "community number\n"
8849 "Do not send outside local AS (well-known community)\n"
8850 "Do not advertise to any peer (well-known community)\n"
8851 "Do not export to next AS (well-known community)\n"
8852 "community number\n"
8853 "Do not send outside local AS (well-known community)\n"
8854 "Do not advertise to any peer (well-known community)\n"
8855 "Do not export to next AS (well-known community)\n"
8856 "community number\n"
8857 "Do not send outside local AS (well-known community)\n"
8858 "Do not advertise to any peer (well-known community)\n"
8859 "Do not export to next AS (well-known community)\n"
8860 "Exact match of the communities")
8861
8862ALIAS (show_bgp_community_exact,
8863 show_bgp_ipv6_community4_exact_cmd,
8864 "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",
8865 SHOW_STR
8866 BGP_STR
8867 "Address family\n"
8868 "Display routes matching the communities\n"
8869 "community number\n"
8870 "Do not send outside local AS (well-known community)\n"
8871 "Do not advertise to any peer (well-known community)\n"
8872 "Do not export to next AS (well-known community)\n"
8873 "community number\n"
8874 "Do not send outside local AS (well-known community)\n"
8875 "Do not advertise to any peer (well-known community)\n"
8876 "Do not export to next AS (well-known community)\n"
8877 "community number\n"
8878 "Do not send outside local AS (well-known community)\n"
8879 "Do not advertise to any peer (well-known community)\n"
8880 "Do not export to next AS (well-known community)\n"
8881 "community number\n"
8882 "Do not send outside local AS (well-known community)\n"
8883 "Do not advertise to any peer (well-known community)\n"
8884 "Do not export to next AS (well-known community)\n"
8885 "Exact match of the communities")
8886
8887/* old command */
8888DEFUN (show_ipv6_bgp_community_exact,
8889 show_ipv6_bgp_community_exact_cmd,
8890 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8891 SHOW_STR
8892 IPV6_STR
8893 BGP_STR
8894 "Display routes matching the communities\n"
8895 "community number\n"
8896 "Do not send outside local AS (well-known community)\n"
8897 "Do not advertise to any peer (well-known community)\n"
8898 "Do not export to next AS (well-known community)\n"
8899 "Exact match of the communities")
8900{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008901 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008902}
8903
8904/* old command */
8905ALIAS (show_ipv6_bgp_community_exact,
8906 show_ipv6_bgp_community2_exact_cmd,
8907 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8908 SHOW_STR
8909 IPV6_STR
8910 BGP_STR
8911 "Display routes matching the communities\n"
8912 "community number\n"
8913 "Do not send outside local AS (well-known community)\n"
8914 "Do not advertise to any peer (well-known community)\n"
8915 "Do not export to next AS (well-known community)\n"
8916 "community number\n"
8917 "Do not send outside local AS (well-known community)\n"
8918 "Do not advertise to any peer (well-known community)\n"
8919 "Do not export to next AS (well-known community)\n"
8920 "Exact match of the communities")
8921
8922/* old command */
8923ALIAS (show_ipv6_bgp_community_exact,
8924 show_ipv6_bgp_community3_exact_cmd,
8925 "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",
8926 SHOW_STR
8927 IPV6_STR
8928 BGP_STR
8929 "Display routes matching the communities\n"
8930 "community number\n"
8931 "Do not send outside local AS (well-known community)\n"
8932 "Do not advertise to any peer (well-known community)\n"
8933 "Do not export to next AS (well-known community)\n"
8934 "community number\n"
8935 "Do not send outside local AS (well-known community)\n"
8936 "Do not advertise to any peer (well-known community)\n"
8937 "Do not export to next AS (well-known community)\n"
8938 "community number\n"
8939 "Do not send outside local AS (well-known community)\n"
8940 "Do not advertise to any peer (well-known community)\n"
8941 "Do not export to next AS (well-known community)\n"
8942 "Exact match of the communities")
8943
8944/* old command */
8945ALIAS (show_ipv6_bgp_community_exact,
8946 show_ipv6_bgp_community4_exact_cmd,
8947 "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",
8948 SHOW_STR
8949 IPV6_STR
8950 BGP_STR
8951 "Display routes matching the communities\n"
8952 "community number\n"
8953 "Do not send outside local AS (well-known community)\n"
8954 "Do not advertise to any peer (well-known community)\n"
8955 "Do not export to next AS (well-known community)\n"
8956 "community number\n"
8957 "Do not send outside local AS (well-known community)\n"
8958 "Do not advertise to any peer (well-known community)\n"
8959 "Do not export to next AS (well-known community)\n"
8960 "community number\n"
8961 "Do not send outside local AS (well-known community)\n"
8962 "Do not advertise to any peer (well-known community)\n"
8963 "Do not export to next AS (well-known community)\n"
8964 "community number\n"
8965 "Do not send outside local AS (well-known community)\n"
8966 "Do not advertise to any peer (well-known community)\n"
8967 "Do not export to next AS (well-known community)\n"
8968 "Exact match of the communities")
8969
8970/* old command */
8971DEFUN (show_ipv6_mbgp_community,
8972 show_ipv6_mbgp_community_cmd,
8973 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8974 SHOW_STR
8975 IPV6_STR
8976 MBGP_STR
8977 "Display routes matching the communities\n"
8978 "community number\n"
8979 "Do not send outside local AS (well-known community)\n"
8980 "Do not advertise to any peer (well-known community)\n"
8981 "Do not export to next AS (well-known community)\n")
8982{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008983 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008984}
8985
8986/* old command */
8987ALIAS (show_ipv6_mbgp_community,
8988 show_ipv6_mbgp_community2_cmd,
8989 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8990 SHOW_STR
8991 IPV6_STR
8992 MBGP_STR
8993 "Display routes matching the communities\n"
8994 "community number\n"
8995 "Do not send outside local AS (well-known community)\n"
8996 "Do not advertise to any peer (well-known community)\n"
8997 "Do not export to next AS (well-known community)\n"
8998 "community number\n"
8999 "Do not send outside local AS (well-known community)\n"
9000 "Do not advertise to any peer (well-known community)\n"
9001 "Do not export to next AS (well-known community)\n")
9002
9003/* old command */
9004ALIAS (show_ipv6_mbgp_community,
9005 show_ipv6_mbgp_community3_cmd,
9006 "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)",
9007 SHOW_STR
9008 IPV6_STR
9009 MBGP_STR
9010 "Display routes matching the communities\n"
9011 "community number\n"
9012 "Do not send outside local AS (well-known community)\n"
9013 "Do not advertise to any peer (well-known community)\n"
9014 "Do not export to next AS (well-known community)\n"
9015 "community number\n"
9016 "Do not send outside local AS (well-known community)\n"
9017 "Do not advertise to any peer (well-known community)\n"
9018 "Do not export to next AS (well-known community)\n"
9019 "community number\n"
9020 "Do not send outside local AS (well-known community)\n"
9021 "Do not advertise to any peer (well-known community)\n"
9022 "Do not export to next AS (well-known community)\n")
9023
9024/* old command */
9025ALIAS (show_ipv6_mbgp_community,
9026 show_ipv6_mbgp_community4_cmd,
9027 "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)",
9028 SHOW_STR
9029 IPV6_STR
9030 MBGP_STR
9031 "Display routes matching the communities\n"
9032 "community number\n"
9033 "Do not send outside local AS (well-known community)\n"
9034 "Do not advertise to any peer (well-known community)\n"
9035 "Do not export to next AS (well-known community)\n"
9036 "community number\n"
9037 "Do not send outside local AS (well-known community)\n"
9038 "Do not advertise to any peer (well-known community)\n"
9039 "Do not export to next AS (well-known community)\n"
9040 "community number\n"
9041 "Do not send outside local AS (well-known community)\n"
9042 "Do not advertise to any peer (well-known community)\n"
9043 "Do not export to next AS (well-known community)\n"
9044 "community number\n"
9045 "Do not send outside local AS (well-known community)\n"
9046 "Do not advertise to any peer (well-known community)\n"
9047 "Do not export to next AS (well-known community)\n")
9048
9049/* old command */
9050DEFUN (show_ipv6_mbgp_community_exact,
9051 show_ipv6_mbgp_community_exact_cmd,
9052 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9053 SHOW_STR
9054 IPV6_STR
9055 MBGP_STR
9056 "Display routes matching the communities\n"
9057 "community number\n"
9058 "Do not send outside local AS (well-known community)\n"
9059 "Do not advertise to any peer (well-known community)\n"
9060 "Do not export to next AS (well-known community)\n"
9061 "Exact match of the communities")
9062{
Michael Lambert95cbbd22010-07-23 14:43:04 -04009063 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00009064}
9065
9066/* old command */
9067ALIAS (show_ipv6_mbgp_community_exact,
9068 show_ipv6_mbgp_community2_exact_cmd,
9069 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9070 SHOW_STR
9071 IPV6_STR
9072 MBGP_STR
9073 "Display routes matching the communities\n"
9074 "community number\n"
9075 "Do not send outside local AS (well-known community)\n"
9076 "Do not advertise to any peer (well-known community)\n"
9077 "Do not export to next AS (well-known community)\n"
9078 "community number\n"
9079 "Do not send outside local AS (well-known community)\n"
9080 "Do not advertise to any peer (well-known community)\n"
9081 "Do not export to next AS (well-known community)\n"
9082 "Exact match of the communities")
9083
9084/* old command */
9085ALIAS (show_ipv6_mbgp_community_exact,
9086 show_ipv6_mbgp_community3_exact_cmd,
9087 "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",
9088 SHOW_STR
9089 IPV6_STR
9090 MBGP_STR
9091 "Display routes matching the communities\n"
9092 "community number\n"
9093 "Do not send outside local AS (well-known community)\n"
9094 "Do not advertise to any peer (well-known community)\n"
9095 "Do not export to next AS (well-known community)\n"
9096 "community number\n"
9097 "Do not send outside local AS (well-known community)\n"
9098 "Do not advertise to any peer (well-known community)\n"
9099 "Do not export to next AS (well-known community)\n"
9100 "community number\n"
9101 "Do not send outside local AS (well-known community)\n"
9102 "Do not advertise to any peer (well-known community)\n"
9103 "Do not export to next AS (well-known community)\n"
9104 "Exact match of the communities")
9105
9106/* old command */
9107ALIAS (show_ipv6_mbgp_community_exact,
9108 show_ipv6_mbgp_community4_exact_cmd,
9109 "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",
9110 SHOW_STR
9111 IPV6_STR
9112 MBGP_STR
9113 "Display routes matching the communities\n"
9114 "community number\n"
9115 "Do not send outside local AS (well-known community)\n"
9116 "Do not advertise to any peer (well-known community)\n"
9117 "Do not export to next AS (well-known community)\n"
9118 "community number\n"
9119 "Do not send outside local AS (well-known community)\n"
9120 "Do not advertise to any peer (well-known community)\n"
9121 "Do not export to next AS (well-known community)\n"
9122 "community number\n"
9123 "Do not send outside local AS (well-known community)\n"
9124 "Do not advertise to any peer (well-known community)\n"
9125 "Do not export to next AS (well-known community)\n"
9126 "community number\n"
9127 "Do not send outside local AS (well-known community)\n"
9128 "Do not advertise to any peer (well-known community)\n"
9129 "Do not export to next AS (well-known community)\n"
9130 "Exact match of the communities")
9131#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009132
paul94f2b392005-06-28 12:44:16 +00009133static int
paulfd79ac92004-10-13 05:06:08 +00009134bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04009135 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009136{
9137 struct community_list *list;
9138
hassofee6e4e2005-02-02 16:29:31 +00009139 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00009140 if (list == NULL)
9141 {
9142 vty_out (vty, "%% %s is not a valid community-list name%s", com,
9143 VTY_NEWLINE);
9144 return CMD_WARNING;
9145 }
9146
ajs5a646652004-11-05 01:25:55 +00009147 return bgp_show (vty, NULL, afi, safi,
9148 (exact ? bgp_show_type_community_list_exact :
9149 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00009150}
9151
9152DEFUN (show_ip_bgp_community_list,
9153 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009154 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009155 SHOW_STR
9156 IP_STR
9157 BGP_STR
9158 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009159 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009160 "community-list name\n")
9161{
9162 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9163}
9164
9165DEFUN (show_ip_bgp_ipv4_community_list,
9166 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009167 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009168 SHOW_STR
9169 IP_STR
9170 BGP_STR
9171 "Address family\n"
9172 "Address Family modifier\n"
9173 "Address Family modifier\n"
9174 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009175 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009176 "community-list name\n")
9177{
9178 if (strncmp (argv[0], "m", 1) == 0)
9179 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9180
9181 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9182}
9183
9184DEFUN (show_ip_bgp_community_list_exact,
9185 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009186 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009187 SHOW_STR
9188 IP_STR
9189 BGP_STR
9190 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009191 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009192 "community-list name\n"
9193 "Exact match of the communities\n")
9194{
9195 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9196}
9197
9198DEFUN (show_ip_bgp_ipv4_community_list_exact,
9199 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009200 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009201 SHOW_STR
9202 IP_STR
9203 BGP_STR
9204 "Address family\n"
9205 "Address Family modifier\n"
9206 "Address Family modifier\n"
9207 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009208 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009209 "community-list name\n"
9210 "Exact match of the communities\n")
9211{
9212 if (strncmp (argv[0], "m", 1) == 0)
9213 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9214
9215 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9216}
9217
9218#ifdef HAVE_IPV6
9219DEFUN (show_bgp_community_list,
9220 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009221 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009222 SHOW_STR
9223 BGP_STR
9224 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009225 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009226 "community-list name\n")
9227{
9228 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9229}
9230
9231ALIAS (show_bgp_community_list,
9232 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009233 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009234 SHOW_STR
9235 BGP_STR
9236 "Address family\n"
9237 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009238 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009239 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009240
9241/* old command */
9242DEFUN (show_ipv6_bgp_community_list,
9243 show_ipv6_bgp_community_list_cmd,
9244 "show ipv6 bgp community-list WORD",
9245 SHOW_STR
9246 IPV6_STR
9247 BGP_STR
9248 "Display routes matching the community-list\n"
9249 "community-list name\n")
9250{
9251 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9252}
9253
9254/* old command */
9255DEFUN (show_ipv6_mbgp_community_list,
9256 show_ipv6_mbgp_community_list_cmd,
9257 "show ipv6 mbgp community-list WORD",
9258 SHOW_STR
9259 IPV6_STR
9260 MBGP_STR
9261 "Display routes matching the community-list\n"
9262 "community-list name\n")
9263{
9264 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9265}
9266
9267DEFUN (show_bgp_community_list_exact,
9268 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009269 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009270 SHOW_STR
9271 BGP_STR
9272 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009273 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009274 "community-list name\n"
9275 "Exact match of the communities\n")
9276{
9277 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9278}
9279
9280ALIAS (show_bgp_community_list_exact,
9281 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009282 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009283 SHOW_STR
9284 BGP_STR
9285 "Address family\n"
9286 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009287 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009288 "community-list name\n"
9289 "Exact match of the communities\n")
9290
9291/* old command */
9292DEFUN (show_ipv6_bgp_community_list_exact,
9293 show_ipv6_bgp_community_list_exact_cmd,
9294 "show ipv6 bgp community-list WORD exact-match",
9295 SHOW_STR
9296 IPV6_STR
9297 BGP_STR
9298 "Display routes matching the community-list\n"
9299 "community-list name\n"
9300 "Exact match of the communities\n")
9301{
9302 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9303}
9304
9305/* old command */
9306DEFUN (show_ipv6_mbgp_community_list_exact,
9307 show_ipv6_mbgp_community_list_exact_cmd,
9308 "show ipv6 mbgp community-list WORD exact-match",
9309 SHOW_STR
9310 IPV6_STR
9311 MBGP_STR
9312 "Display routes matching the community-list\n"
9313 "community-list name\n"
9314 "Exact match of the communities\n")
9315{
9316 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9317}
9318#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009319
paul94f2b392005-06-28 12:44:16 +00009320static int
paulfd79ac92004-10-13 05:06:08 +00009321bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009322 safi_t safi, enum bgp_show_type type)
9323{
9324 int ret;
9325 struct prefix *p;
9326
9327 p = prefix_new();
9328
9329 ret = str2prefix (prefix, p);
9330 if (! ret)
9331 {
9332 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9333 return CMD_WARNING;
9334 }
9335
ajs5a646652004-11-05 01:25:55 +00009336 ret = bgp_show (vty, NULL, afi, safi, type, p);
9337 prefix_free(p);
9338 return ret;
paul718e3742002-12-13 20:15:29 +00009339}
9340
9341DEFUN (show_ip_bgp_prefix_longer,
9342 show_ip_bgp_prefix_longer_cmd,
9343 "show ip bgp A.B.C.D/M longer-prefixes",
9344 SHOW_STR
9345 IP_STR
9346 BGP_STR
9347 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9348 "Display route and more specific routes\n")
9349{
9350 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9351 bgp_show_type_prefix_longer);
9352}
9353
9354DEFUN (show_ip_bgp_flap_prefix_longer,
9355 show_ip_bgp_flap_prefix_longer_cmd,
9356 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9357 SHOW_STR
9358 IP_STR
9359 BGP_STR
9360 "Display flap statistics of routes\n"
9361 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9362 "Display route and more specific routes\n")
9363{
9364 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9365 bgp_show_type_flap_prefix_longer);
9366}
9367
Balaji3921cc52015-05-16 23:12:17 +05309368ALIAS (show_ip_bgp_flap_prefix_longer,
9369 show_ip_bgp_damp_flap_prefix_longer_cmd,
9370 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
9371 SHOW_STR
9372 IP_STR
9373 BGP_STR
9374 "Display detailed information about dampening\n"
9375 "Display flap statistics of routes\n"
9376 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9377 "Display route and more specific routes\n")
9378
paul718e3742002-12-13 20:15:29 +00009379DEFUN (show_ip_bgp_ipv4_prefix_longer,
9380 show_ip_bgp_ipv4_prefix_longer_cmd,
9381 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9382 SHOW_STR
9383 IP_STR
9384 BGP_STR
9385 "Address family\n"
9386 "Address Family modifier\n"
9387 "Address Family modifier\n"
9388 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9389 "Display route and more specific routes\n")
9390{
9391 if (strncmp (argv[0], "m", 1) == 0)
9392 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9393 bgp_show_type_prefix_longer);
9394
9395 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9396 bgp_show_type_prefix_longer);
9397}
9398
9399DEFUN (show_ip_bgp_flap_address,
9400 show_ip_bgp_flap_address_cmd,
9401 "show ip bgp flap-statistics A.B.C.D",
9402 SHOW_STR
9403 IP_STR
9404 BGP_STR
9405 "Display flap statistics of routes\n"
9406 "Network in the BGP routing table to display\n")
9407{
9408 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9409 bgp_show_type_flap_address);
9410}
9411
Balaji3921cc52015-05-16 23:12:17 +05309412ALIAS (show_ip_bgp_flap_address,
9413 show_ip_bgp_damp_flap_address_cmd,
9414 "show ip bgp dampening flap-statistics A.B.C.D",
9415 SHOW_STR
9416 IP_STR
9417 BGP_STR
9418 "Display detailed information about dampening\n"
9419 "Display flap statistics of routes\n"
9420 "Network in the BGP routing table to display\n")
9421
paul718e3742002-12-13 20:15:29 +00009422DEFUN (show_ip_bgp_flap_prefix,
9423 show_ip_bgp_flap_prefix_cmd,
9424 "show ip bgp flap-statistics A.B.C.D/M",
9425 SHOW_STR
9426 IP_STR
9427 BGP_STR
9428 "Display flap statistics of routes\n"
9429 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9430{
9431 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9432 bgp_show_type_flap_prefix);
9433}
Balaji3921cc52015-05-16 23:12:17 +05309434
9435ALIAS (show_ip_bgp_flap_prefix,
9436 show_ip_bgp_damp_flap_prefix_cmd,
9437 "show ip bgp dampening flap-statistics A.B.C.D/M",
9438 SHOW_STR
9439 IP_STR
9440 BGP_STR
9441 "Display detailed information about dampening\n"
9442 "Display flap statistics of routes\n"
9443 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9444
paul718e3742002-12-13 20:15:29 +00009445#ifdef HAVE_IPV6
9446DEFUN (show_bgp_prefix_longer,
9447 show_bgp_prefix_longer_cmd,
9448 "show bgp X:X::X:X/M longer-prefixes",
9449 SHOW_STR
9450 BGP_STR
9451 "IPv6 prefix <network>/<length>\n"
9452 "Display route and more specific routes\n")
9453{
9454 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9455 bgp_show_type_prefix_longer);
9456}
9457
9458ALIAS (show_bgp_prefix_longer,
9459 show_bgp_ipv6_prefix_longer_cmd,
9460 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9461 SHOW_STR
9462 BGP_STR
9463 "Address family\n"
9464 "IPv6 prefix <network>/<length>\n"
9465 "Display route and more specific routes\n")
9466
9467/* old command */
9468DEFUN (show_ipv6_bgp_prefix_longer,
9469 show_ipv6_bgp_prefix_longer_cmd,
9470 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9471 SHOW_STR
9472 IPV6_STR
9473 BGP_STR
9474 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9475 "Display route and more specific routes\n")
9476{
9477 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9478 bgp_show_type_prefix_longer);
9479}
9480
9481/* old command */
9482DEFUN (show_ipv6_mbgp_prefix_longer,
9483 show_ipv6_mbgp_prefix_longer_cmd,
9484 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9485 SHOW_STR
9486 IPV6_STR
9487 MBGP_STR
9488 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9489 "Display route and more specific routes\n")
9490{
9491 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9492 bgp_show_type_prefix_longer);
9493}
9494#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009495
paul94f2b392005-06-28 12:44:16 +00009496static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009497peer_lookup_in_view (struct vty *vty, const char *view_name,
9498 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009499{
9500 int ret;
9501 struct bgp *bgp;
9502 struct peer *peer;
9503 union sockunion su;
9504
9505 /* BGP structure lookup. */
9506 if (view_name)
9507 {
9508 bgp = bgp_lookup_by_name (view_name);
9509 if (! bgp)
9510 {
9511 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9512 return NULL;
9513 }
9514 }
paul5228ad22004-06-04 17:58:18 +00009515 else
paulbb46e942003-10-24 19:02:03 +00009516 {
9517 bgp = bgp_get_default ();
9518 if (! bgp)
9519 {
9520 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9521 return NULL;
9522 }
9523 }
9524
9525 /* Get peer sockunion. */
9526 ret = str2sockunion (ip_str, &su);
9527 if (ret < 0)
9528 {
9529 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9530 return NULL;
9531 }
9532
9533 /* Peer structure lookup. */
9534 peer = peer_lookup (bgp, &su);
9535 if (! peer)
9536 {
9537 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9538 return NULL;
9539 }
9540
9541 return peer;
9542}
David Lamparter6b0655a2014-06-04 06:53:35 +02009543
Paul Jakma2815e612006-09-14 02:56:07 +00009544enum bgp_stats
9545{
9546 BGP_STATS_MAXBITLEN = 0,
9547 BGP_STATS_RIB,
9548 BGP_STATS_PREFIXES,
9549 BGP_STATS_TOTPLEN,
9550 BGP_STATS_UNAGGREGATEABLE,
9551 BGP_STATS_MAX_AGGREGATEABLE,
9552 BGP_STATS_AGGREGATES,
9553 BGP_STATS_SPACE,
9554 BGP_STATS_ASPATH_COUNT,
9555 BGP_STATS_ASPATH_MAXHOPS,
9556 BGP_STATS_ASPATH_TOTHOPS,
9557 BGP_STATS_ASPATH_MAXSIZE,
9558 BGP_STATS_ASPATH_TOTSIZE,
9559 BGP_STATS_ASN_HIGHEST,
9560 BGP_STATS_MAX,
9561};
paulbb46e942003-10-24 19:02:03 +00009562
Paul Jakma2815e612006-09-14 02:56:07 +00009563static const char *table_stats_strs[] =
9564{
9565 [BGP_STATS_PREFIXES] = "Total Prefixes",
9566 [BGP_STATS_TOTPLEN] = "Average prefix length",
9567 [BGP_STATS_RIB] = "Total Advertisements",
9568 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9569 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9570 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9571 [BGP_STATS_SPACE] = "Address space advertised",
9572 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9573 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9574 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9575 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9576 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9577 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9578 [BGP_STATS_MAX] = NULL,
9579};
9580
9581struct bgp_table_stats
9582{
9583 struct bgp_table *table;
9584 unsigned long long counts[BGP_STATS_MAX];
9585};
9586
9587#if 0
9588#define TALLY_SIGFIG 100000
9589static unsigned long
9590ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9591{
9592 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9593 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9594 unsigned long ret = newtot / count;
9595
9596 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9597 return ret + 1;
9598 else
9599 return ret;
9600}
9601#endif
9602
9603static int
9604bgp_table_stats_walker (struct thread *t)
9605{
9606 struct bgp_node *rn;
9607 struct bgp_node *top;
9608 struct bgp_table_stats *ts = THREAD_ARG (t);
9609 unsigned int space = 0;
9610
Paul Jakma53d9f672006-10-15 23:41:16 +00009611 if (!(top = bgp_table_top (ts->table)))
9612 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009613
9614 switch (top->p.family)
9615 {
9616 case AF_INET:
9617 space = IPV4_MAX_BITLEN;
9618 break;
9619 case AF_INET6:
9620 space = IPV6_MAX_BITLEN;
9621 break;
9622 }
9623
9624 ts->counts[BGP_STATS_MAXBITLEN] = space;
9625
9626 for (rn = top; rn; rn = bgp_route_next (rn))
9627 {
9628 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009629 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009630 unsigned int rinum = 0;
9631
9632 if (rn == top)
9633 continue;
9634
9635 if (!rn->info)
9636 continue;
9637
9638 ts->counts[BGP_STATS_PREFIXES]++;
9639 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9640
9641#if 0
9642 ts->counts[BGP_STATS_AVGPLEN]
9643 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9644 ts->counts[BGP_STATS_AVGPLEN],
9645 rn->p.prefixlen);
9646#endif
9647
9648 /* check if the prefix is included by any other announcements */
9649 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009650 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009651
9652 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009653 {
9654 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9655 /* announced address space */
9656 if (space)
9657 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9658 }
Paul Jakma2815e612006-09-14 02:56:07 +00009659 else if (prn->info)
9660 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9661
Paul Jakma2815e612006-09-14 02:56:07 +00009662 for (ri = rn->info; ri; ri = ri->next)
9663 {
9664 rinum++;
9665 ts->counts[BGP_STATS_RIB]++;
9666
9667 if (ri->attr &&
9668 (CHECK_FLAG (ri->attr->flag,
9669 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9670 ts->counts[BGP_STATS_AGGREGATES]++;
9671
9672 /* as-path stats */
9673 if (ri->attr && ri->attr->aspath)
9674 {
9675 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9676 unsigned int size = aspath_size (ri->attr->aspath);
9677 as_t highest = aspath_highest (ri->attr->aspath);
9678
9679 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9680
9681 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9682 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9683
9684 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9685 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9686
9687 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9688 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9689#if 0
9690 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9691 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9692 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9693 hops);
9694 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9695 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9696 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9697 size);
9698#endif
9699 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9700 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9701 }
9702 }
9703 }
9704 return 0;
9705}
9706
9707static int
9708bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9709{
9710 struct bgp_table_stats ts;
9711 unsigned int i;
9712
9713 if (!bgp->rib[afi][safi])
9714 {
9715 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9716 return CMD_WARNING;
9717 }
9718
9719 memset (&ts, 0, sizeof (ts));
9720 ts.table = bgp->rib[afi][safi];
9721 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9722
9723 vty_out (vty, "BGP %s RIB statistics%s%s",
9724 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9725
9726 for (i = 0; i < BGP_STATS_MAX; i++)
9727 {
9728 if (!table_stats_strs[i])
9729 continue;
9730
9731 switch (i)
9732 {
9733#if 0
9734 case BGP_STATS_ASPATH_AVGHOPS:
9735 case BGP_STATS_ASPATH_AVGSIZE:
9736 case BGP_STATS_AVGPLEN:
9737 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9738 vty_out (vty, "%12.2f",
9739 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9740 break;
9741#endif
9742 case BGP_STATS_ASPATH_TOTHOPS:
9743 case BGP_STATS_ASPATH_TOTSIZE:
9744 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9745 vty_out (vty, "%12.2f",
9746 ts.counts[i] ?
9747 (float)ts.counts[i] /
9748 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9749 : 0);
9750 break;
9751 case BGP_STATS_TOTPLEN:
9752 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9753 vty_out (vty, "%12.2f",
9754 ts.counts[i] ?
9755 (float)ts.counts[i] /
9756 (float)ts.counts[BGP_STATS_PREFIXES]
9757 : 0);
9758 break;
9759 case BGP_STATS_SPACE:
9760 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9761 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9762 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9763 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009764 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009765 vty_out (vty, "%12.2f%s",
9766 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009767 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009768 VTY_NEWLINE);
9769 vty_out (vty, "%30s: ", "/8 equivalent ");
9770 vty_out (vty, "%12.2f%s",
9771 (float)ts.counts[BGP_STATS_SPACE] /
9772 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9773 VTY_NEWLINE);
9774 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9775 break;
9776 vty_out (vty, "%30s: ", "/24 equivalent ");
9777 vty_out (vty, "%12.2f",
9778 (float)ts.counts[BGP_STATS_SPACE] /
9779 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9780 break;
9781 default:
9782 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9783 vty_out (vty, "%12llu", ts.counts[i]);
9784 }
9785
9786 vty_out (vty, "%s", VTY_NEWLINE);
9787 }
9788 return CMD_SUCCESS;
9789}
9790
9791static int
9792bgp_table_stats_vty (struct vty *vty, const char *name,
9793 const char *afi_str, const char *safi_str)
9794{
9795 struct bgp *bgp;
9796 afi_t afi;
9797 safi_t safi;
9798
9799 if (name)
9800 bgp = bgp_lookup_by_name (name);
9801 else
9802 bgp = bgp_get_default ();
9803
9804 if (!bgp)
9805 {
9806 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9807 return CMD_WARNING;
9808 }
9809 if (strncmp (afi_str, "ipv", 3) == 0)
9810 {
9811 if (strncmp (afi_str, "ipv4", 4) == 0)
9812 afi = AFI_IP;
9813 else if (strncmp (afi_str, "ipv6", 4) == 0)
9814 afi = AFI_IP6;
9815 else
9816 {
9817 vty_out (vty, "%% Invalid address family %s%s",
9818 afi_str, VTY_NEWLINE);
9819 return CMD_WARNING;
9820 }
9821 if (strncmp (safi_str, "m", 1) == 0)
9822 safi = SAFI_MULTICAST;
9823 else if (strncmp (safi_str, "u", 1) == 0)
9824 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009825 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9826 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009827 else
9828 {
9829 vty_out (vty, "%% Invalid subsequent address family %s%s",
9830 safi_str, VTY_NEWLINE);
9831 return CMD_WARNING;
9832 }
9833 }
9834 else
9835 {
9836 vty_out (vty, "%% Invalid address family %s%s",
9837 afi_str, VTY_NEWLINE);
9838 return CMD_WARNING;
9839 }
9840
Paul Jakma2815e612006-09-14 02:56:07 +00009841 return bgp_table_stats (vty, bgp, afi, safi);
9842}
9843
9844DEFUN (show_bgp_statistics,
9845 show_bgp_statistics_cmd,
9846 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9847 SHOW_STR
9848 BGP_STR
9849 "Address family\n"
9850 "Address family\n"
9851 "Address Family modifier\n"
9852 "Address Family modifier\n"
9853 "BGP RIB advertisement statistics\n")
9854{
9855 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9856}
9857
9858ALIAS (show_bgp_statistics,
9859 show_bgp_statistics_vpnv4_cmd,
9860 "show bgp (ipv4) (vpnv4) statistics",
9861 SHOW_STR
9862 BGP_STR
9863 "Address family\n"
9864 "Address Family modifier\n"
9865 "BGP RIB advertisement statistics\n")
9866
9867DEFUN (show_bgp_statistics_view,
9868 show_bgp_statistics_view_cmd,
9869 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9870 SHOW_STR
9871 BGP_STR
9872 "BGP view\n"
9873 "Address family\n"
9874 "Address family\n"
9875 "Address Family modifier\n"
9876 "Address Family modifier\n"
9877 "BGP RIB advertisement statistics\n")
9878{
9879 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9880}
9881
9882ALIAS (show_bgp_statistics_view,
9883 show_bgp_statistics_view_vpnv4_cmd,
9884 "show bgp view WORD (ipv4) (vpnv4) statistics",
9885 SHOW_STR
9886 BGP_STR
9887 "BGP view\n"
9888 "Address family\n"
9889 "Address Family modifier\n"
9890 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009891
Paul Jakmaff7924f2006-09-04 01:10:36 +00009892enum bgp_pcounts
9893{
9894 PCOUNT_ADJ_IN = 0,
9895 PCOUNT_DAMPED,
9896 PCOUNT_REMOVED,
9897 PCOUNT_HISTORY,
9898 PCOUNT_STALE,
9899 PCOUNT_VALID,
9900 PCOUNT_ALL,
9901 PCOUNT_COUNTED,
9902 PCOUNT_PFCNT, /* the figure we display to users */
9903 PCOUNT_MAX,
9904};
9905
9906static const char *pcount_strs[] =
9907{
9908 [PCOUNT_ADJ_IN] = "Adj-in",
9909 [PCOUNT_DAMPED] = "Damped",
9910 [PCOUNT_REMOVED] = "Removed",
9911 [PCOUNT_HISTORY] = "History",
9912 [PCOUNT_STALE] = "Stale",
9913 [PCOUNT_VALID] = "Valid",
9914 [PCOUNT_ALL] = "All RIB",
9915 [PCOUNT_COUNTED] = "PfxCt counted",
9916 [PCOUNT_PFCNT] = "Useable",
9917 [PCOUNT_MAX] = NULL,
9918};
9919
Paul Jakma2815e612006-09-14 02:56:07 +00009920struct peer_pcounts
9921{
9922 unsigned int count[PCOUNT_MAX];
9923 const struct peer *peer;
9924 const struct bgp_table *table;
9925};
9926
Paul Jakmaff7924f2006-09-04 01:10:36 +00009927static int
Paul Jakma2815e612006-09-14 02:56:07 +00009928bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009929{
9930 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009931 struct peer_pcounts *pc = THREAD_ARG (t);
9932 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009933
Paul Jakma2815e612006-09-14 02:56:07 +00009934 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009935 {
9936 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009937 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009938
9939 for (ain = rn->adj_in; ain; ain = ain->next)
9940 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009941 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009942
Paul Jakmaff7924f2006-09-04 01:10:36 +00009943 for (ri = rn->info; ri; ri = ri->next)
9944 {
9945 char buf[SU_ADDRSTRLEN];
9946
9947 if (ri->peer != peer)
9948 continue;
9949
Paul Jakma2815e612006-09-14 02:56:07 +00009950 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009951
9952 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009953 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009954 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009955 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009956 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009957 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009958 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009959 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009960 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009961 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009962 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009963 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009964
9965 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9966 {
Paul Jakma2815e612006-09-14 02:56:07 +00009967 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009968 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009969 plog_warn (peer->log,
9970 "%s [pcount] %s/%d is counted but flags 0x%x",
9971 peer->host,
9972 inet_ntop(rn->p.family, &rn->p.u.prefix,
9973 buf, SU_ADDRSTRLEN),
9974 rn->p.prefixlen,
9975 ri->flags);
9976 }
9977 else
9978 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009979 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009980 plog_warn (peer->log,
9981 "%s [pcount] %s/%d not counted but flags 0x%x",
9982 peer->host,
9983 inet_ntop(rn->p.family, &rn->p.u.prefix,
9984 buf, SU_ADDRSTRLEN),
9985 rn->p.prefixlen,
9986 ri->flags);
9987 }
9988 }
9989 }
Paul Jakma2815e612006-09-14 02:56:07 +00009990 return 0;
9991}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009992
Paul Jakma2815e612006-09-14 02:56:07 +00009993static int
9994bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9995{
9996 struct peer_pcounts pcounts = { .peer = peer };
9997 unsigned int i;
9998
9999 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10000 || !peer->bgp->rib[afi][safi])
10001 {
10002 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10003 return CMD_WARNING;
10004 }
10005
10006 memset (&pcounts, 0, sizeof(pcounts));
10007 pcounts.peer = peer;
10008 pcounts.table = peer->bgp->rib[afi][safi];
10009
10010 /* in-place call via thread subsystem so as to record execution time
10011 * stats for the thread-walk (i.e. ensure this can't be blamed on
10012 * on just vty_read()).
10013 */
10014 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10015
Paul Jakmaff7924f2006-09-04 01:10:36 +000010016 vty_out (vty, "Prefix counts for %s, %s%s",
10017 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10018 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10019 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10020 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10021
10022 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000010023 vty_out (vty, "%20s: %-10d%s",
10024 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010025
Paul Jakma2815e612006-09-14 02:56:07 +000010026 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000010027 {
10028 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10029 peer->host, VTY_NEWLINE);
10030 vty_out (vty, "Please report this bug, with the above command output%s",
10031 VTY_NEWLINE);
10032 }
10033
10034 return CMD_SUCCESS;
10035}
10036
10037DEFUN (show_ip_bgp_neighbor_prefix_counts,
10038 show_ip_bgp_neighbor_prefix_counts_cmd,
10039 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10040 SHOW_STR
10041 IP_STR
10042 BGP_STR
10043 "Detailed information on TCP and BGP neighbor connections\n"
10044 "Neighbor to display information about\n"
10045 "Neighbor to display information about\n"
10046 "Display detailed prefix count information\n")
10047{
10048 struct peer *peer;
10049
10050 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10051 if (! peer)
10052 return CMD_WARNING;
10053
10054 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10055}
10056
10057DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
10058 show_bgp_ipv6_neighbor_prefix_counts_cmd,
10059 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10060 SHOW_STR
10061 BGP_STR
10062 "Address family\n"
10063 "Detailed information on TCP and BGP neighbor connections\n"
10064 "Neighbor to display information about\n"
10065 "Neighbor to display information about\n"
10066 "Display detailed prefix count information\n")
10067{
10068 struct peer *peer;
10069
10070 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10071 if (! peer)
10072 return CMD_WARNING;
10073
10074 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10075}
10076
10077DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
10078 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
10079 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10080 SHOW_STR
10081 IP_STR
10082 BGP_STR
10083 "Address family\n"
10084 "Address Family modifier\n"
10085 "Address Family modifier\n"
10086 "Detailed information on TCP and BGP neighbor connections\n"
10087 "Neighbor to display information about\n"
10088 "Neighbor to display information about\n"
10089 "Display detailed prefix count information\n")
10090{
10091 struct peer *peer;
10092
10093 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10094 if (! peer)
10095 return CMD_WARNING;
10096
10097 if (strncmp (argv[0], "m", 1) == 0)
10098 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
10099
10100 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10101}
10102
10103DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
10104 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
10105 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10106 SHOW_STR
10107 IP_STR
10108 BGP_STR
10109 "Address family\n"
10110 "Address Family modifier\n"
10111 "Address Family modifier\n"
10112 "Detailed information on TCP and BGP neighbor connections\n"
10113 "Neighbor to display information about\n"
10114 "Neighbor to display information about\n"
10115 "Display detailed prefix count information\n")
10116{
10117 struct peer *peer;
10118
10119 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10120 if (! peer)
10121 return CMD_WARNING;
10122
10123 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
10124}
10125
10126
paul94f2b392005-06-28 12:44:16 +000010127static void
paul718e3742002-12-13 20:15:29 +000010128show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10129 int in)
10130{
10131 struct bgp_table *table;
10132 struct bgp_adj_in *ain;
10133 struct bgp_adj_out *adj;
10134 unsigned long output_count;
10135 struct bgp_node *rn;
10136 int header1 = 1;
10137 struct bgp *bgp;
10138 int header2 = 1;
10139
paulbb46e942003-10-24 19:02:03 +000010140 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000010141
10142 if (! bgp)
10143 return;
10144
10145 table = bgp->rib[afi][safi];
10146
10147 output_count = 0;
10148
10149 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
10150 PEER_STATUS_DEFAULT_ORIGINATE))
10151 {
10152 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 +000010153 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10154 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010155
10156 vty_out (vty, "Originating default network 0.0.0.0%s%s",
10157 VTY_NEWLINE, VTY_NEWLINE);
10158 header1 = 0;
10159 }
10160
10161 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10162 if (in)
10163 {
10164 for (ain = rn->adj_in; ain; ain = ain->next)
10165 if (ain->peer == peer)
10166 {
10167 if (header1)
10168 {
10169 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 +000010170 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10171 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010172 header1 = 0;
10173 }
10174 if (header2)
10175 {
10176 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10177 header2 = 0;
10178 }
10179 if (ain->attr)
10180 {
10181 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
10182 output_count++;
10183 }
10184 }
10185 }
10186 else
10187 {
10188 for (adj = rn->adj_out; adj; adj = adj->next)
10189 if (adj->peer == peer)
10190 {
10191 if (header1)
10192 {
10193 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 +000010194 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10195 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010196 header1 = 0;
10197 }
10198 if (header2)
10199 {
10200 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10201 header2 = 0;
10202 }
10203 if (adj->attr)
10204 {
10205 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10206 output_count++;
10207 }
10208 }
10209 }
10210
10211 if (output_count != 0)
10212 vty_out (vty, "%sTotal number of prefixes %ld%s",
10213 VTY_NEWLINE, output_count, VTY_NEWLINE);
10214}
10215
paul94f2b392005-06-28 12:44:16 +000010216static int
paulbb46e942003-10-24 19:02:03 +000010217peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10218{
paul718e3742002-12-13 20:15:29 +000010219 if (! peer || ! peer->afc[afi][safi])
10220 {
10221 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10222 return CMD_WARNING;
10223 }
10224
10225 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10226 {
10227 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10228 VTY_NEWLINE);
10229 return CMD_WARNING;
10230 }
10231
10232 show_adj_route (vty, peer, afi, safi, in);
10233
10234 return CMD_SUCCESS;
10235}
10236
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010237DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10238 show_ip_bgp_view_neighbor_advertised_route_cmd,
10239 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10240 SHOW_STR
10241 IP_STR
10242 BGP_STR
10243 "BGP view\n"
10244 "View name\n"
10245 "Detailed information on TCP and BGP neighbor connections\n"
10246 "Neighbor to display information about\n"
10247 "Neighbor to display information about\n"
10248 "Display the routes advertised to a BGP neighbor\n")
10249{
10250 struct peer *peer;
10251
10252 if (argc == 2)
10253 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10254 else
10255 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10256
10257 if (! peer)
10258 return CMD_WARNING;
10259
10260 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
10261}
10262
10263ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010264 show_ip_bgp_neighbor_advertised_route_cmd,
10265 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10266 SHOW_STR
10267 IP_STR
10268 BGP_STR
10269 "Detailed information on TCP and BGP neighbor connections\n"
10270 "Neighbor to display information about\n"
10271 "Neighbor to display information about\n"
10272 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +000010273
10274DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10275 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10276 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10277 SHOW_STR
10278 IP_STR
10279 BGP_STR
10280 "Address family\n"
10281 "Address Family modifier\n"
10282 "Address Family modifier\n"
10283 "Detailed information on TCP and BGP neighbor connections\n"
10284 "Neighbor to display information about\n"
10285 "Neighbor to display information about\n"
10286 "Display the routes advertised to a BGP neighbor\n")
10287{
paulbb46e942003-10-24 19:02:03 +000010288 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010289
paulbb46e942003-10-24 19:02:03 +000010290 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10291 if (! peer)
10292 return CMD_WARNING;
10293
10294 if (strncmp (argv[0], "m", 1) == 0)
10295 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10296
10297 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010298}
10299
10300#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010301DEFUN (show_bgp_view_neighbor_advertised_route,
10302 show_bgp_view_neighbor_advertised_route_cmd,
10303 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10304 SHOW_STR
10305 BGP_STR
10306 "BGP view\n"
10307 "View name\n"
10308 "Detailed information on TCP and BGP neighbor connections\n"
10309 "Neighbor to display information about\n"
10310 "Neighbor to display information about\n"
10311 "Display the routes advertised to a BGP neighbor\n")
10312{
10313 struct peer *peer;
10314
10315 if (argc == 2)
10316 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10317 else
10318 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10319
10320 if (! peer)
10321 return CMD_WARNING;
10322
10323 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10324}
10325
10326ALIAS (show_bgp_view_neighbor_advertised_route,
10327 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10328 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10329 SHOW_STR
10330 BGP_STR
10331 "BGP view\n"
10332 "View name\n"
10333 "Address family\n"
10334 "Detailed information on TCP and BGP neighbor connections\n"
10335 "Neighbor to display information about\n"
10336 "Neighbor to display information about\n"
10337 "Display the routes advertised to a BGP neighbor\n")
10338
10339DEFUN (show_bgp_view_neighbor_received_routes,
10340 show_bgp_view_neighbor_received_routes_cmd,
10341 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10342 SHOW_STR
10343 BGP_STR
10344 "BGP view\n"
10345 "View name\n"
10346 "Detailed information on TCP and BGP neighbor connections\n"
10347 "Neighbor to display information about\n"
10348 "Neighbor to display information about\n"
10349 "Display the received routes from neighbor\n")
10350{
10351 struct peer *peer;
10352
10353 if (argc == 2)
10354 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10355 else
10356 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10357
10358 if (! peer)
10359 return CMD_WARNING;
10360
10361 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10362}
10363
10364ALIAS (show_bgp_view_neighbor_received_routes,
10365 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10366 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10367 SHOW_STR
10368 BGP_STR
10369 "BGP view\n"
10370 "View name\n"
10371 "Address family\n"
10372 "Detailed information on TCP and BGP neighbor connections\n"
10373 "Neighbor to display information about\n"
10374 "Neighbor to display information about\n"
10375 "Display the received routes from neighbor\n")
10376
10377ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010378 show_bgp_neighbor_advertised_route_cmd,
10379 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10380 SHOW_STR
10381 BGP_STR
10382 "Detailed information on TCP and BGP neighbor connections\n"
10383 "Neighbor to display information about\n"
10384 "Neighbor to display information about\n"
10385 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010386
10387ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010388 show_bgp_ipv6_neighbor_advertised_route_cmd,
10389 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10390 SHOW_STR
10391 BGP_STR
10392 "Address family\n"
10393 "Detailed information on TCP and BGP neighbor connections\n"
10394 "Neighbor to display information about\n"
10395 "Neighbor to display information about\n"
10396 "Display the routes advertised to a BGP neighbor\n")
10397
10398/* old command */
paulbb46e942003-10-24 19:02:03 +000010399ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010400 ipv6_bgp_neighbor_advertised_route_cmd,
10401 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10402 SHOW_STR
10403 IPV6_STR
10404 BGP_STR
10405 "Detailed information on TCP and BGP neighbor connections\n"
10406 "Neighbor to display information about\n"
10407 "Neighbor to display information about\n"
10408 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010409
paul718e3742002-12-13 20:15:29 +000010410/* old command */
10411DEFUN (ipv6_mbgp_neighbor_advertised_route,
10412 ipv6_mbgp_neighbor_advertised_route_cmd,
10413 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10414 SHOW_STR
10415 IPV6_STR
10416 MBGP_STR
10417 "Detailed information on TCP and BGP neighbor connections\n"
10418 "Neighbor to display information about\n"
10419 "Neighbor to display information about\n"
10420 "Display the routes advertised to a BGP neighbor\n")
10421{
paulbb46e942003-10-24 19:02:03 +000010422 struct peer *peer;
10423
10424 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10425 if (! peer)
10426 return CMD_WARNING;
10427
10428 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010429}
10430#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010431
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010432DEFUN (show_ip_bgp_view_neighbor_received_routes,
10433 show_ip_bgp_view_neighbor_received_routes_cmd,
10434 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10435 SHOW_STR
10436 IP_STR
10437 BGP_STR
10438 "BGP view\n"
10439 "View name\n"
10440 "Detailed information on TCP and BGP neighbor connections\n"
10441 "Neighbor to display information about\n"
10442 "Neighbor to display information about\n"
10443 "Display the received routes from neighbor\n")
10444{
10445 struct peer *peer;
10446
10447 if (argc == 2)
10448 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10449 else
10450 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10451
10452 if (! peer)
10453 return CMD_WARNING;
10454
10455 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10456}
10457
10458ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010459 show_ip_bgp_neighbor_received_routes_cmd,
10460 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10461 SHOW_STR
10462 IP_STR
10463 BGP_STR
10464 "Detailed information on TCP and BGP neighbor connections\n"
10465 "Neighbor to display information about\n"
10466 "Neighbor to display information about\n"
10467 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010468
10469DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10470 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10471 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10472 SHOW_STR
10473 IP_STR
10474 BGP_STR
10475 "Address family\n"
10476 "Address Family modifier\n"
10477 "Address Family modifier\n"
10478 "Detailed information on TCP and BGP neighbor connections\n"
10479 "Neighbor to display information about\n"
10480 "Neighbor to display information about\n"
10481 "Display the received routes from neighbor\n")
10482{
paulbb46e942003-10-24 19:02:03 +000010483 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010484
paulbb46e942003-10-24 19:02:03 +000010485 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10486 if (! peer)
10487 return CMD_WARNING;
10488
10489 if (strncmp (argv[0], "m", 1) == 0)
10490 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10491
10492 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010493}
10494
Michael Lambert95cbbd22010-07-23 14:43:04 -040010495DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10496 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010497 "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 -040010498 SHOW_STR
10499 BGP_STR
10500 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010501 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010502 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010503 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010504 "Address family modifier\n"
10505 "Address family modifier\n"
10506 "Detailed information on TCP and BGP neighbor connections\n"
10507 "Neighbor to display information about\n"
10508 "Neighbor to display information about\n"
10509 "Display the advertised routes to neighbor\n"
10510 "Display the received routes from neighbor\n")
10511{
10512 int afi;
10513 int safi;
10514 int in;
10515 struct peer *peer;
10516
David Lamparter94bad672015-03-03 08:52:22 +010010517 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010518
10519 if (! peer)
10520 return CMD_WARNING;
10521
Michael Lambert95cbbd22010-07-23 14:43:04 -040010522 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10523 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10524 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010525
10526 return peer_adj_routes (vty, peer, afi, safi, in);
10527}
10528
paul718e3742002-12-13 20:15:29 +000010529DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10530 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10531 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10532 SHOW_STR
10533 IP_STR
10534 BGP_STR
10535 "Detailed information on TCP and BGP neighbor connections\n"
10536 "Neighbor to display information about\n"
10537 "Neighbor to display information about\n"
10538 "Display information received from a BGP neighbor\n"
10539 "Display the prefixlist filter\n")
10540{
10541 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010542 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010543 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010544 int count, ret;
paul718e3742002-12-13 20:15:29 +000010545
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010546 ret = str2sockunion (argv[0], &su);
10547 if (ret < 0)
10548 {
10549 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10550 return CMD_WARNING;
10551 }
paul718e3742002-12-13 20:15:29 +000010552
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010553 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010554 if (! peer)
10555 return CMD_WARNING;
10556
10557 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10558 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10559 if (count)
10560 {
10561 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10562 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10563 }
10564
10565 return CMD_SUCCESS;
10566}
10567
10568DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10569 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10570 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10571 SHOW_STR
10572 IP_STR
10573 BGP_STR
10574 "Address family\n"
10575 "Address Family modifier\n"
10576 "Address Family modifier\n"
10577 "Detailed information on TCP and BGP neighbor connections\n"
10578 "Neighbor to display information about\n"
10579 "Neighbor to display information about\n"
10580 "Display information received from a BGP neighbor\n"
10581 "Display the prefixlist filter\n")
10582{
10583 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010584 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010585 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010586 int count, ret;
paul718e3742002-12-13 20:15:29 +000010587
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010588 ret = str2sockunion (argv[1], &su);
10589 if (ret < 0)
10590 {
10591 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10592 return CMD_WARNING;
10593 }
paul718e3742002-12-13 20:15:29 +000010594
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010595 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010596 if (! peer)
10597 return CMD_WARNING;
10598
10599 if (strncmp (argv[0], "m", 1) == 0)
10600 {
10601 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10602 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10603 if (count)
10604 {
10605 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10606 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10607 }
10608 }
10609 else
10610 {
10611 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10612 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10613 if (count)
10614 {
10615 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10616 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10617 }
10618 }
10619
10620 return CMD_SUCCESS;
10621}
10622
10623
10624#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010625ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010626 show_bgp_neighbor_received_routes_cmd,
10627 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10628 SHOW_STR
10629 BGP_STR
10630 "Detailed information on TCP and BGP neighbor connections\n"
10631 "Neighbor to display information about\n"
10632 "Neighbor to display information about\n"
10633 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010634
paulbb46e942003-10-24 19:02:03 +000010635ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010636 show_bgp_ipv6_neighbor_received_routes_cmd,
10637 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10638 SHOW_STR
10639 BGP_STR
10640 "Address family\n"
10641 "Detailed information on TCP and BGP neighbor connections\n"
10642 "Neighbor to display information about\n"
10643 "Neighbor to display information about\n"
10644 "Display the received routes from neighbor\n")
10645
10646DEFUN (show_bgp_neighbor_received_prefix_filter,
10647 show_bgp_neighbor_received_prefix_filter_cmd,
10648 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10649 SHOW_STR
10650 BGP_STR
10651 "Detailed information on TCP and BGP neighbor connections\n"
10652 "Neighbor to display information about\n"
10653 "Neighbor to display information about\n"
10654 "Display information received from a BGP neighbor\n"
10655 "Display the prefixlist filter\n")
10656{
10657 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010658 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010659 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010660 int count, ret;
paul718e3742002-12-13 20:15:29 +000010661
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010662 ret = str2sockunion (argv[0], &su);
10663 if (ret < 0)
10664 {
10665 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10666 return CMD_WARNING;
10667 }
paul718e3742002-12-13 20:15:29 +000010668
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010669 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010670 if (! peer)
10671 return CMD_WARNING;
10672
10673 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10674 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10675 if (count)
10676 {
10677 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10678 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10679 }
10680
10681 return CMD_SUCCESS;
10682}
10683
10684ALIAS (show_bgp_neighbor_received_prefix_filter,
10685 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10686 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10687 SHOW_STR
10688 BGP_STR
10689 "Address family\n"
10690 "Detailed information on TCP and BGP neighbor connections\n"
10691 "Neighbor to display information about\n"
10692 "Neighbor to display information about\n"
10693 "Display information received from a BGP neighbor\n"
10694 "Display the prefixlist filter\n")
10695
10696/* old command */
paulbb46e942003-10-24 19:02:03 +000010697ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010698 ipv6_bgp_neighbor_received_routes_cmd,
10699 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10700 SHOW_STR
10701 IPV6_STR
10702 BGP_STR
10703 "Detailed information on TCP and BGP neighbor connections\n"
10704 "Neighbor to display information about\n"
10705 "Neighbor to display information about\n"
10706 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010707
10708/* old command */
10709DEFUN (ipv6_mbgp_neighbor_received_routes,
10710 ipv6_mbgp_neighbor_received_routes_cmd,
10711 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10712 SHOW_STR
10713 IPV6_STR
10714 MBGP_STR
10715 "Detailed information on TCP and BGP neighbor connections\n"
10716 "Neighbor to display information about\n"
10717 "Neighbor to display information about\n"
10718 "Display the received routes from neighbor\n")
10719{
paulbb46e942003-10-24 19:02:03 +000010720 struct peer *peer;
10721
10722 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10723 if (! peer)
10724 return CMD_WARNING;
10725
10726 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010727}
paulbb46e942003-10-24 19:02:03 +000010728
10729DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10730 show_bgp_view_neighbor_received_prefix_filter_cmd,
10731 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10732 SHOW_STR
10733 BGP_STR
10734 "BGP view\n"
10735 "View name\n"
10736 "Detailed information on TCP and BGP neighbor connections\n"
10737 "Neighbor to display information about\n"
10738 "Neighbor to display information about\n"
10739 "Display information received from a BGP neighbor\n"
10740 "Display the prefixlist filter\n")
10741{
10742 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010743 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010744 struct peer *peer;
10745 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010746 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010747
10748 /* BGP structure lookup. */
10749 bgp = bgp_lookup_by_name (argv[0]);
10750 if (bgp == NULL)
10751 {
10752 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10753 return CMD_WARNING;
10754 }
10755
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010756 ret = str2sockunion (argv[1], &su);
10757 if (ret < 0)
10758 {
10759 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10760 return CMD_WARNING;
10761 }
paulbb46e942003-10-24 19:02:03 +000010762
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010763 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010764 if (! peer)
10765 return CMD_WARNING;
10766
10767 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10768 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10769 if (count)
10770 {
10771 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10772 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10773 }
10774
10775 return CMD_SUCCESS;
10776}
10777
10778ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10779 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10780 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10781 SHOW_STR
10782 BGP_STR
10783 "BGP view\n"
10784 "View name\n"
10785 "Address family\n"
10786 "Detailed information on TCP and BGP neighbor connections\n"
10787 "Neighbor to display information about\n"
10788 "Neighbor to display information about\n"
10789 "Display information received from a BGP neighbor\n"
10790 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010791#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010792
paul94f2b392005-06-28 12:44:16 +000010793static int
paulbb46e942003-10-24 19:02:03 +000010794bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010795 safi_t safi, enum bgp_show_type type)
10796{
paul718e3742002-12-13 20:15:29 +000010797 if (! peer || ! peer->afc[afi][safi])
10798 {
10799 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010800 return CMD_WARNING;
10801 }
10802
ajs5a646652004-11-05 01:25:55 +000010803 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010804}
10805
10806DEFUN (show_ip_bgp_neighbor_routes,
10807 show_ip_bgp_neighbor_routes_cmd,
10808 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10809 SHOW_STR
10810 IP_STR
10811 BGP_STR
10812 "Detailed information on TCP and BGP neighbor connections\n"
10813 "Neighbor to display information about\n"
10814 "Neighbor to display information about\n"
10815 "Display routes learned from neighbor\n")
10816{
paulbb46e942003-10-24 19:02:03 +000010817 struct peer *peer;
10818
10819 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10820 if (! peer)
10821 return CMD_WARNING;
10822
10823 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010824 bgp_show_type_neighbor);
10825}
10826
10827DEFUN (show_ip_bgp_neighbor_flap,
10828 show_ip_bgp_neighbor_flap_cmd,
10829 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10830 SHOW_STR
10831 IP_STR
10832 BGP_STR
10833 "Detailed information on TCP and BGP neighbor connections\n"
10834 "Neighbor to display information about\n"
10835 "Neighbor to display information about\n"
10836 "Display flap statistics of the routes learned from neighbor\n")
10837{
paulbb46e942003-10-24 19:02:03 +000010838 struct peer *peer;
10839
10840 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10841 if (! peer)
10842 return CMD_WARNING;
10843
10844 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010845 bgp_show_type_flap_neighbor);
10846}
10847
10848DEFUN (show_ip_bgp_neighbor_damp,
10849 show_ip_bgp_neighbor_damp_cmd,
10850 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10851 SHOW_STR
10852 IP_STR
10853 BGP_STR
10854 "Detailed information on TCP and BGP neighbor connections\n"
10855 "Neighbor to display information about\n"
10856 "Neighbor to display information about\n"
10857 "Display the dampened routes received from neighbor\n")
10858{
paulbb46e942003-10-24 19:02:03 +000010859 struct peer *peer;
10860
10861 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10862 if (! peer)
10863 return CMD_WARNING;
10864
10865 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010866 bgp_show_type_damp_neighbor);
10867}
10868
10869DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10870 show_ip_bgp_ipv4_neighbor_routes_cmd,
10871 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10872 SHOW_STR
10873 IP_STR
10874 BGP_STR
10875 "Address family\n"
10876 "Address Family modifier\n"
10877 "Address Family modifier\n"
10878 "Detailed information on TCP and BGP neighbor connections\n"
10879 "Neighbor to display information about\n"
10880 "Neighbor to display information about\n"
10881 "Display routes learned from neighbor\n")
10882{
paulbb46e942003-10-24 19:02:03 +000010883 struct peer *peer;
10884
10885 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10886 if (! peer)
10887 return CMD_WARNING;
10888
paul718e3742002-12-13 20:15:29 +000010889 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010890 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010891 bgp_show_type_neighbor);
10892
paulbb46e942003-10-24 19:02:03 +000010893 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010894 bgp_show_type_neighbor);
10895}
paulbb46e942003-10-24 19:02:03 +000010896
paulfee0f4c2004-09-13 05:12:46 +000010897DEFUN (show_ip_bgp_view_rsclient,
10898 show_ip_bgp_view_rsclient_cmd,
10899 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10900 SHOW_STR
10901 IP_STR
10902 BGP_STR
10903 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010904 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010905 "Information about Route Server Client\n"
10906 NEIGHBOR_ADDR_STR)
10907{
10908 struct bgp_table *table;
10909 struct peer *peer;
10910
10911 if (argc == 2)
10912 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10913 else
10914 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10915
10916 if (! peer)
10917 return CMD_WARNING;
10918
10919 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10920 {
10921 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10922 VTY_NEWLINE);
10923 return CMD_WARNING;
10924 }
10925
10926 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10927 PEER_FLAG_RSERVER_CLIENT))
10928 {
10929 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10930 VTY_NEWLINE);
10931 return CMD_WARNING;
10932 }
10933
10934 table = peer->rib[AFI_IP][SAFI_UNICAST];
10935
ajs5a646652004-11-05 01:25:55 +000010936 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010937}
10938
10939ALIAS (show_ip_bgp_view_rsclient,
10940 show_ip_bgp_rsclient_cmd,
10941 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10942 SHOW_STR
10943 IP_STR
10944 BGP_STR
10945 "Information about Route Server Client\n"
10946 NEIGHBOR_ADDR_STR)
10947
Michael Lambert95cbbd22010-07-23 14:43:04 -040010948DEFUN (show_bgp_view_ipv4_safi_rsclient,
10949 show_bgp_view_ipv4_safi_rsclient_cmd,
10950 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10951 SHOW_STR
10952 BGP_STR
10953 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010954 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010955 "Address family\n"
10956 "Address Family modifier\n"
10957 "Address Family modifier\n"
10958 "Information about Route Server Client\n"
10959 NEIGHBOR_ADDR_STR)
10960{
10961 struct bgp_table *table;
10962 struct peer *peer;
10963 safi_t safi;
10964
10965 if (argc == 3) {
10966 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10967 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10968 } else {
10969 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10970 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10971 }
10972
10973 if (! peer)
10974 return CMD_WARNING;
10975
10976 if (! peer->afc[AFI_IP][safi])
10977 {
10978 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10979 VTY_NEWLINE);
10980 return CMD_WARNING;
10981 }
10982
10983 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10984 PEER_FLAG_RSERVER_CLIENT))
10985 {
10986 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10987 VTY_NEWLINE);
10988 return CMD_WARNING;
10989 }
10990
10991 table = peer->rib[AFI_IP][safi];
10992
10993 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10994}
10995
10996ALIAS (show_bgp_view_ipv4_safi_rsclient,
10997 show_bgp_ipv4_safi_rsclient_cmd,
10998 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10999 SHOW_STR
11000 BGP_STR
11001 "Address family\n"
11002 "Address Family modifier\n"
11003 "Address Family modifier\n"
11004 "Information about Route Server Client\n"
11005 NEIGHBOR_ADDR_STR)
11006
paulfee0f4c2004-09-13 05:12:46 +000011007DEFUN (show_ip_bgp_view_rsclient_route,
11008 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010011009 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000011010 SHOW_STR
11011 IP_STR
11012 BGP_STR
11013 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011014 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011015 "Information about Route Server Client\n"
11016 NEIGHBOR_ADDR_STR
11017 "Network in the BGP routing table to display\n")
11018{
11019 struct bgp *bgp;
11020 struct peer *peer;
11021
11022 /* BGP structure lookup. */
11023 if (argc == 3)
11024 {
11025 bgp = bgp_lookup_by_name (argv[0]);
11026 if (bgp == NULL)
11027 {
11028 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11029 return CMD_WARNING;
11030 }
11031 }
11032 else
11033 {
11034 bgp = bgp_get_default ();
11035 if (bgp == NULL)
11036 {
11037 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11038 return CMD_WARNING;
11039 }
11040 }
11041
11042 if (argc == 3)
11043 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11044 else
11045 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11046
11047 if (! peer)
11048 return CMD_WARNING;
11049
11050 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11051 {
11052 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11053 VTY_NEWLINE);
11054 return CMD_WARNING;
11055}
11056
11057 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11058 PEER_FLAG_RSERVER_CLIENT))
11059 {
11060 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11061 VTY_NEWLINE);
11062 return CMD_WARNING;
11063 }
11064
11065 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11066 (argc == 3) ? argv[2] : argv[1],
11067 AFI_IP, SAFI_UNICAST, NULL, 0);
11068}
11069
11070ALIAS (show_ip_bgp_view_rsclient_route,
11071 show_ip_bgp_rsclient_route_cmd,
11072 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11073 SHOW_STR
11074 IP_STR
11075 BGP_STR
11076 "Information about Route Server Client\n"
11077 NEIGHBOR_ADDR_STR
11078 "Network in the BGP routing table to display\n")
11079
Michael Lambert95cbbd22010-07-23 14:43:04 -040011080DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11081 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11082 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11083 SHOW_STR
11084 BGP_STR
11085 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011086 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011087 "Address family\n"
11088 "Address Family modifier\n"
11089 "Address Family modifier\n"
11090 "Information about Route Server Client\n"
11091 NEIGHBOR_ADDR_STR
11092 "Network in the BGP routing table to display\n")
11093{
11094 struct bgp *bgp;
11095 struct peer *peer;
11096 safi_t safi;
11097
11098 /* BGP structure lookup. */
11099 if (argc == 4)
11100 {
11101 bgp = bgp_lookup_by_name (argv[0]);
11102 if (bgp == NULL)
11103 {
11104 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11105 return CMD_WARNING;
11106 }
11107 }
11108 else
11109 {
11110 bgp = bgp_get_default ();
11111 if (bgp == NULL)
11112 {
11113 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11114 return CMD_WARNING;
11115 }
11116 }
11117
11118 if (argc == 4) {
11119 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11120 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11121 } else {
11122 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11123 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11124 }
11125
11126 if (! peer)
11127 return CMD_WARNING;
11128
11129 if (! peer->afc[AFI_IP][safi])
11130 {
11131 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11132 VTY_NEWLINE);
11133 return CMD_WARNING;
11134}
11135
11136 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11137 PEER_FLAG_RSERVER_CLIENT))
11138 {
11139 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11140 VTY_NEWLINE);
11141 return CMD_WARNING;
11142 }
11143
11144 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11145 (argc == 4) ? argv[3] : argv[2],
11146 AFI_IP, safi, NULL, 0);
11147}
11148
11149ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
11150 show_bgp_ipv4_safi_rsclient_route_cmd,
11151 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11152 SHOW_STR
11153 BGP_STR
11154 "Address family\n"
11155 "Address Family modifier\n"
11156 "Address Family modifier\n"
11157 "Information about Route Server Client\n"
11158 NEIGHBOR_ADDR_STR
11159 "Network in the BGP routing table to display\n")
11160
paulfee0f4c2004-09-13 05:12:46 +000011161DEFUN (show_ip_bgp_view_rsclient_prefix,
11162 show_ip_bgp_view_rsclient_prefix_cmd,
11163 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11164 SHOW_STR
11165 IP_STR
11166 BGP_STR
11167 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011168 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011169 "Information about Route Server Client\n"
11170 NEIGHBOR_ADDR_STR
11171 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11172{
11173 struct bgp *bgp;
11174 struct peer *peer;
11175
11176 /* BGP structure lookup. */
11177 if (argc == 3)
11178 {
11179 bgp = bgp_lookup_by_name (argv[0]);
11180 if (bgp == NULL)
11181 {
11182 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11183 return CMD_WARNING;
11184 }
11185 }
11186 else
11187 {
11188 bgp = bgp_get_default ();
11189 if (bgp == NULL)
11190 {
11191 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11192 return CMD_WARNING;
11193 }
11194 }
11195
11196 if (argc == 3)
11197 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11198 else
11199 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11200
11201 if (! peer)
11202 return CMD_WARNING;
11203
11204 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11205 {
11206 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11207 VTY_NEWLINE);
11208 return CMD_WARNING;
11209}
11210
11211 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11212 PEER_FLAG_RSERVER_CLIENT))
11213{
11214 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11215 VTY_NEWLINE);
11216 return CMD_WARNING;
11217 }
11218
11219 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11220 (argc == 3) ? argv[2] : argv[1],
11221 AFI_IP, SAFI_UNICAST, NULL, 1);
11222}
11223
11224ALIAS (show_ip_bgp_view_rsclient_prefix,
11225 show_ip_bgp_rsclient_prefix_cmd,
11226 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11227 SHOW_STR
11228 IP_STR
11229 BGP_STR
11230 "Information about Route Server Client\n"
11231 NEIGHBOR_ADDR_STR
11232 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11233
Michael Lambert95cbbd22010-07-23 14:43:04 -040011234DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11235 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11236 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11237 SHOW_STR
11238 BGP_STR
11239 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011240 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011241 "Address family\n"
11242 "Address Family modifier\n"
11243 "Address Family modifier\n"
11244 "Information about Route Server Client\n"
11245 NEIGHBOR_ADDR_STR
11246 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11247{
11248 struct bgp *bgp;
11249 struct peer *peer;
11250 safi_t safi;
11251
11252 /* BGP structure lookup. */
11253 if (argc == 4)
11254 {
11255 bgp = bgp_lookup_by_name (argv[0]);
11256 if (bgp == NULL)
11257 {
11258 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11259 return CMD_WARNING;
11260 }
11261 }
11262 else
11263 {
11264 bgp = bgp_get_default ();
11265 if (bgp == NULL)
11266 {
11267 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11268 return CMD_WARNING;
11269 }
11270 }
11271
11272 if (argc == 4) {
11273 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11274 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11275 } else {
11276 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11277 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11278 }
11279
11280 if (! peer)
11281 return CMD_WARNING;
11282
11283 if (! peer->afc[AFI_IP][safi])
11284 {
11285 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11286 VTY_NEWLINE);
11287 return CMD_WARNING;
11288}
11289
11290 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11291 PEER_FLAG_RSERVER_CLIENT))
11292{
11293 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11294 VTY_NEWLINE);
11295 return CMD_WARNING;
11296 }
11297
11298 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11299 (argc == 4) ? argv[3] : argv[2],
11300 AFI_IP, safi, NULL, 1);
11301}
11302
11303ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11304 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11305 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11306 SHOW_STR
11307 BGP_STR
11308 "Address family\n"
11309 "Address Family modifier\n"
11310 "Address Family modifier\n"
11311 "Information about Route Server Client\n"
11312 NEIGHBOR_ADDR_STR
11313 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011314
paul718e3742002-12-13 20:15:29 +000011315#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011316DEFUN (show_bgp_view_neighbor_routes,
11317 show_bgp_view_neighbor_routes_cmd,
11318 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11319 SHOW_STR
11320 BGP_STR
11321 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011322 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011323 "Detailed information on TCP and BGP neighbor connections\n"
11324 "Neighbor to display information about\n"
11325 "Neighbor to display information about\n"
11326 "Display routes learned from neighbor\n")
11327{
11328 struct peer *peer;
11329
11330 if (argc == 2)
11331 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11332 else
11333 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11334
11335 if (! peer)
11336 return CMD_WARNING;
11337
11338 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11339 bgp_show_type_neighbor);
11340}
11341
11342ALIAS (show_bgp_view_neighbor_routes,
11343 show_bgp_view_ipv6_neighbor_routes_cmd,
11344 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11345 SHOW_STR
11346 BGP_STR
11347 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011348 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011349 "Address family\n"
11350 "Detailed information on TCP and BGP neighbor connections\n"
11351 "Neighbor to display information about\n"
11352 "Neighbor to display information about\n"
11353 "Display routes learned from neighbor\n")
11354
11355DEFUN (show_bgp_view_neighbor_damp,
11356 show_bgp_view_neighbor_damp_cmd,
11357 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11358 SHOW_STR
11359 BGP_STR
11360 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011361 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011362 "Detailed information on TCP and BGP neighbor connections\n"
11363 "Neighbor to display information about\n"
11364 "Neighbor to display information about\n"
11365 "Display the dampened routes received from neighbor\n")
11366{
11367 struct peer *peer;
11368
11369 if (argc == 2)
11370 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11371 else
11372 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11373
11374 if (! peer)
11375 return CMD_WARNING;
11376
11377 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11378 bgp_show_type_damp_neighbor);
11379}
11380
11381ALIAS (show_bgp_view_neighbor_damp,
11382 show_bgp_view_ipv6_neighbor_damp_cmd,
11383 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11384 SHOW_STR
11385 BGP_STR
11386 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011387 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011388 "Address family\n"
11389 "Detailed information on TCP and BGP neighbor connections\n"
11390 "Neighbor to display information about\n"
11391 "Neighbor to display information about\n"
11392 "Display the dampened routes received from neighbor\n")
11393
11394DEFUN (show_bgp_view_neighbor_flap,
11395 show_bgp_view_neighbor_flap_cmd,
11396 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11397 SHOW_STR
11398 BGP_STR
11399 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011400 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011401 "Detailed information on TCP and BGP neighbor connections\n"
11402 "Neighbor to display information about\n"
11403 "Neighbor to display information about\n"
11404 "Display flap statistics of the routes learned from neighbor\n")
11405{
11406 struct peer *peer;
11407
11408 if (argc == 2)
11409 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11410 else
11411 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11412
11413 if (! peer)
11414 return CMD_WARNING;
11415
11416 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11417 bgp_show_type_flap_neighbor);
11418}
11419
11420ALIAS (show_bgp_view_neighbor_flap,
11421 show_bgp_view_ipv6_neighbor_flap_cmd,
11422 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11423 SHOW_STR
11424 BGP_STR
11425 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011426 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011427 "Address family\n"
11428 "Detailed information on TCP and BGP neighbor connections\n"
11429 "Neighbor to display information about\n"
11430 "Neighbor to display information about\n"
11431 "Display flap statistics of the routes learned from neighbor\n")
11432
11433ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011434 show_bgp_neighbor_routes_cmd,
11435 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11436 SHOW_STR
11437 BGP_STR
11438 "Detailed information on TCP and BGP neighbor connections\n"
11439 "Neighbor to display information about\n"
11440 "Neighbor to display information about\n"
11441 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011442
paulbb46e942003-10-24 19:02:03 +000011443
11444ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011445 show_bgp_ipv6_neighbor_routes_cmd,
11446 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11447 SHOW_STR
11448 BGP_STR
11449 "Address family\n"
11450 "Detailed information on TCP and BGP neighbor connections\n"
11451 "Neighbor to display information about\n"
11452 "Neighbor to display information about\n"
11453 "Display routes learned from neighbor\n")
11454
11455/* old command */
paulbb46e942003-10-24 19:02:03 +000011456ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011457 ipv6_bgp_neighbor_routes_cmd,
11458 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11459 SHOW_STR
11460 IPV6_STR
11461 BGP_STR
11462 "Detailed information on TCP and BGP neighbor connections\n"
11463 "Neighbor to display information about\n"
11464 "Neighbor to display information about\n"
11465 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011466
11467/* old command */
11468DEFUN (ipv6_mbgp_neighbor_routes,
11469 ipv6_mbgp_neighbor_routes_cmd,
11470 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11471 SHOW_STR
11472 IPV6_STR
11473 MBGP_STR
11474 "Detailed information on TCP and BGP neighbor connections\n"
11475 "Neighbor to display information about\n"
11476 "Neighbor to display information about\n"
11477 "Display routes learned from neighbor\n")
11478{
paulbb46e942003-10-24 19:02:03 +000011479 struct peer *peer;
11480
11481 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11482 if (! peer)
11483 return CMD_WARNING;
11484
11485 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011486 bgp_show_type_neighbor);
11487}
paulbb46e942003-10-24 19:02:03 +000011488
11489ALIAS (show_bgp_view_neighbor_flap,
11490 show_bgp_neighbor_flap_cmd,
11491 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11492 SHOW_STR
11493 BGP_STR
11494 "Detailed information on TCP and BGP neighbor connections\n"
11495 "Neighbor to display information about\n"
11496 "Neighbor to display information about\n"
11497 "Display flap statistics of the routes learned from neighbor\n")
11498
11499ALIAS (show_bgp_view_neighbor_flap,
11500 show_bgp_ipv6_neighbor_flap_cmd,
11501 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11502 SHOW_STR
11503 BGP_STR
11504 "Address family\n"
11505 "Detailed information on TCP and BGP neighbor connections\n"
11506 "Neighbor to display information about\n"
11507 "Neighbor to display information about\n"
11508 "Display flap statistics of the routes learned from neighbor\n")
11509
11510ALIAS (show_bgp_view_neighbor_damp,
11511 show_bgp_neighbor_damp_cmd,
11512 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11513 SHOW_STR
11514 BGP_STR
11515 "Detailed information on TCP and BGP neighbor connections\n"
11516 "Neighbor to display information about\n"
11517 "Neighbor to display information about\n"
11518 "Display the dampened routes received from neighbor\n")
11519
11520ALIAS (show_bgp_view_neighbor_damp,
11521 show_bgp_ipv6_neighbor_damp_cmd,
11522 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11523 SHOW_STR
11524 BGP_STR
11525 "Address family\n"
11526 "Detailed information on TCP and BGP neighbor connections\n"
11527 "Neighbor to display information about\n"
11528 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011529 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011530
11531DEFUN (show_bgp_view_rsclient,
11532 show_bgp_view_rsclient_cmd,
11533 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11534 SHOW_STR
11535 BGP_STR
11536 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011537 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011538 "Information about Route Server Client\n"
11539 NEIGHBOR_ADDR_STR)
11540{
11541 struct bgp_table *table;
11542 struct peer *peer;
11543
11544 if (argc == 2)
11545 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11546 else
11547 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11548
11549 if (! peer)
11550 return CMD_WARNING;
11551
11552 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11553 {
11554 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11555 VTY_NEWLINE);
11556 return CMD_WARNING;
11557 }
11558
11559 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11560 PEER_FLAG_RSERVER_CLIENT))
11561 {
11562 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11563 VTY_NEWLINE);
11564 return CMD_WARNING;
11565 }
11566
11567 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11568
ajs5a646652004-11-05 01:25:55 +000011569 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011570}
11571
11572ALIAS (show_bgp_view_rsclient,
11573 show_bgp_rsclient_cmd,
11574 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11575 SHOW_STR
11576 BGP_STR
11577 "Information about Route Server Client\n"
11578 NEIGHBOR_ADDR_STR)
11579
Michael Lambert95cbbd22010-07-23 14:43:04 -040011580DEFUN (show_bgp_view_ipv6_safi_rsclient,
11581 show_bgp_view_ipv6_safi_rsclient_cmd,
11582 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11583 SHOW_STR
11584 BGP_STR
11585 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011586 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011587 "Address family\n"
11588 "Address Family modifier\n"
11589 "Address Family modifier\n"
11590 "Information about Route Server Client\n"
11591 NEIGHBOR_ADDR_STR)
11592{
11593 struct bgp_table *table;
11594 struct peer *peer;
11595 safi_t safi;
11596
11597 if (argc == 3) {
11598 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11599 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11600 } else {
11601 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11602 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11603 }
11604
11605 if (! peer)
11606 return CMD_WARNING;
11607
11608 if (! peer->afc[AFI_IP6][safi])
11609 {
11610 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11611 VTY_NEWLINE);
11612 return CMD_WARNING;
11613 }
11614
11615 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11616 PEER_FLAG_RSERVER_CLIENT))
11617 {
11618 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11619 VTY_NEWLINE);
11620 return CMD_WARNING;
11621 }
11622
11623 table = peer->rib[AFI_IP6][safi];
11624
11625 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11626}
11627
11628ALIAS (show_bgp_view_ipv6_safi_rsclient,
11629 show_bgp_ipv6_safi_rsclient_cmd,
11630 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11631 SHOW_STR
11632 BGP_STR
11633 "Address family\n"
11634 "Address Family modifier\n"
11635 "Address Family modifier\n"
11636 "Information about Route Server Client\n"
11637 NEIGHBOR_ADDR_STR)
11638
paulfee0f4c2004-09-13 05:12:46 +000011639DEFUN (show_bgp_view_rsclient_route,
11640 show_bgp_view_rsclient_route_cmd,
11641 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11642 SHOW_STR
11643 BGP_STR
11644 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011645 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011646 "Information about Route Server Client\n"
11647 NEIGHBOR_ADDR_STR
11648 "Network in the BGP routing table to display\n")
11649{
11650 struct bgp *bgp;
11651 struct peer *peer;
11652
11653 /* BGP structure lookup. */
11654 if (argc == 3)
11655 {
11656 bgp = bgp_lookup_by_name (argv[0]);
11657 if (bgp == NULL)
11658 {
11659 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11660 return CMD_WARNING;
11661 }
11662 }
11663 else
11664 {
11665 bgp = bgp_get_default ();
11666 if (bgp == NULL)
11667 {
11668 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11669 return CMD_WARNING;
11670 }
11671 }
11672
11673 if (argc == 3)
11674 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11675 else
11676 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11677
11678 if (! peer)
11679 return CMD_WARNING;
11680
11681 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11682 {
11683 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11684 VTY_NEWLINE);
11685 return CMD_WARNING;
11686 }
11687
11688 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11689 PEER_FLAG_RSERVER_CLIENT))
11690 {
11691 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11692 VTY_NEWLINE);
11693 return CMD_WARNING;
11694 }
11695
11696 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11697 (argc == 3) ? argv[2] : argv[1],
11698 AFI_IP6, SAFI_UNICAST, NULL, 0);
11699}
11700
11701ALIAS (show_bgp_view_rsclient_route,
11702 show_bgp_rsclient_route_cmd,
11703 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11704 SHOW_STR
11705 BGP_STR
11706 "Information about Route Server Client\n"
11707 NEIGHBOR_ADDR_STR
11708 "Network in the BGP routing table to display\n")
11709
Michael Lambert95cbbd22010-07-23 14:43:04 -040011710DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11711 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11712 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11713 SHOW_STR
11714 BGP_STR
11715 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011716 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011717 "Address family\n"
11718 "Address Family modifier\n"
11719 "Address Family modifier\n"
11720 "Information about Route Server Client\n"
11721 NEIGHBOR_ADDR_STR
11722 "Network in the BGP routing table to display\n")
11723{
11724 struct bgp *bgp;
11725 struct peer *peer;
11726 safi_t safi;
11727
11728 /* BGP structure lookup. */
11729 if (argc == 4)
11730 {
11731 bgp = bgp_lookup_by_name (argv[0]);
11732 if (bgp == NULL)
11733 {
11734 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11735 return CMD_WARNING;
11736 }
11737 }
11738 else
11739 {
11740 bgp = bgp_get_default ();
11741 if (bgp == NULL)
11742 {
11743 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11744 return CMD_WARNING;
11745 }
11746 }
11747
11748 if (argc == 4) {
11749 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11750 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11751 } else {
11752 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11753 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11754 }
11755
11756 if (! peer)
11757 return CMD_WARNING;
11758
11759 if (! peer->afc[AFI_IP6][safi])
11760 {
11761 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11762 VTY_NEWLINE);
11763 return CMD_WARNING;
11764}
11765
11766 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11767 PEER_FLAG_RSERVER_CLIENT))
11768 {
11769 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11770 VTY_NEWLINE);
11771 return CMD_WARNING;
11772 }
11773
11774 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11775 (argc == 4) ? argv[3] : argv[2],
11776 AFI_IP6, safi, NULL, 0);
11777}
11778
11779ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11780 show_bgp_ipv6_safi_rsclient_route_cmd,
11781 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11782 SHOW_STR
11783 BGP_STR
11784 "Address family\n"
11785 "Address Family modifier\n"
11786 "Address Family modifier\n"
11787 "Information about Route Server Client\n"
11788 NEIGHBOR_ADDR_STR
11789 "Network in the BGP routing table to display\n")
11790
paulfee0f4c2004-09-13 05:12:46 +000011791DEFUN (show_bgp_view_rsclient_prefix,
11792 show_bgp_view_rsclient_prefix_cmd,
11793 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11794 SHOW_STR
11795 BGP_STR
11796 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011797 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011798 "Information about Route Server Client\n"
11799 NEIGHBOR_ADDR_STR
11800 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11801{
11802 struct bgp *bgp;
11803 struct peer *peer;
11804
11805 /* BGP structure lookup. */
11806 if (argc == 3)
11807 {
11808 bgp = bgp_lookup_by_name (argv[0]);
11809 if (bgp == NULL)
11810 {
11811 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11812 return CMD_WARNING;
11813 }
11814 }
11815 else
11816 {
11817 bgp = bgp_get_default ();
11818 if (bgp == NULL)
11819 {
11820 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11821 return CMD_WARNING;
11822 }
11823 }
11824
11825 if (argc == 3)
11826 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11827 else
11828 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11829
11830 if (! peer)
11831 return CMD_WARNING;
11832
11833 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11834 {
11835 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11836 VTY_NEWLINE);
11837 return CMD_WARNING;
11838 }
11839
11840 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11841 PEER_FLAG_RSERVER_CLIENT))
11842 {
11843 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11844 VTY_NEWLINE);
11845 return CMD_WARNING;
11846 }
11847
11848 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11849 (argc == 3) ? argv[2] : argv[1],
11850 AFI_IP6, SAFI_UNICAST, NULL, 1);
11851}
11852
11853ALIAS (show_bgp_view_rsclient_prefix,
11854 show_bgp_rsclient_prefix_cmd,
11855 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11856 SHOW_STR
11857 BGP_STR
11858 "Information about Route Server Client\n"
11859 NEIGHBOR_ADDR_STR
11860 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11861
Michael Lambert95cbbd22010-07-23 14:43:04 -040011862DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11863 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11864 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11865 SHOW_STR
11866 BGP_STR
11867 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011868 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011869 "Address family\n"
11870 "Address Family modifier\n"
11871 "Address Family modifier\n"
11872 "Information about Route Server Client\n"
11873 NEIGHBOR_ADDR_STR
11874 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11875{
11876 struct bgp *bgp;
11877 struct peer *peer;
11878 safi_t safi;
11879
11880 /* BGP structure lookup. */
11881 if (argc == 4)
11882 {
11883 bgp = bgp_lookup_by_name (argv[0]);
11884 if (bgp == NULL)
11885 {
11886 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11887 return CMD_WARNING;
11888 }
11889 }
11890 else
11891 {
11892 bgp = bgp_get_default ();
11893 if (bgp == NULL)
11894 {
11895 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11896 return CMD_WARNING;
11897 }
11898 }
11899
11900 if (argc == 4) {
11901 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11902 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11903 } else {
11904 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11905 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11906 }
11907
11908 if (! peer)
11909 return CMD_WARNING;
11910
11911 if (! peer->afc[AFI_IP6][safi])
11912 {
11913 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11914 VTY_NEWLINE);
11915 return CMD_WARNING;
11916}
11917
11918 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11919 PEER_FLAG_RSERVER_CLIENT))
11920{
11921 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11922 VTY_NEWLINE);
11923 return CMD_WARNING;
11924 }
11925
11926 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11927 (argc == 4) ? argv[3] : argv[2],
11928 AFI_IP6, safi, NULL, 1);
11929}
11930
11931ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11932 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11933 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11934 SHOW_STR
11935 BGP_STR
11936 "Address family\n"
11937 "Address Family modifier\n"
11938 "Address Family modifier\n"
11939 "Information about Route Server Client\n"
11940 NEIGHBOR_ADDR_STR
11941 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11942
paul718e3742002-12-13 20:15:29 +000011943#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011944
paul718e3742002-12-13 20:15:29 +000011945struct bgp_table *bgp_distance_table;
11946
11947struct bgp_distance
11948{
11949 /* Distance value for the IP source prefix. */
11950 u_char distance;
11951
11952 /* Name of the access-list to be matched. */
11953 char *access_list;
11954};
11955
paul94f2b392005-06-28 12:44:16 +000011956static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011957bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011958{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011959 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011960}
11961
paul94f2b392005-06-28 12:44:16 +000011962static void
paul718e3742002-12-13 20:15:29 +000011963bgp_distance_free (struct bgp_distance *bdistance)
11964{
11965 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11966}
11967
paul94f2b392005-06-28 12:44:16 +000011968static int
paulfd79ac92004-10-13 05:06:08 +000011969bgp_distance_set (struct vty *vty, const char *distance_str,
11970 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011971{
11972 int ret;
11973 struct prefix_ipv4 p;
11974 u_char distance;
11975 struct bgp_node *rn;
11976 struct bgp_distance *bdistance;
11977
11978 ret = str2prefix_ipv4 (ip_str, &p);
11979 if (ret == 0)
11980 {
11981 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11982 return CMD_WARNING;
11983 }
11984
11985 distance = atoi (distance_str);
11986
11987 /* Get BGP distance node. */
11988 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11989 if (rn->info)
11990 {
11991 bdistance = rn->info;
11992 bgp_unlock_node (rn);
11993 }
11994 else
11995 {
11996 bdistance = bgp_distance_new ();
11997 rn->info = bdistance;
11998 }
11999
12000 /* Set distance value. */
12001 bdistance->distance = distance;
12002
12003 /* Reset access-list configuration. */
12004 if (bdistance->access_list)
12005 {
12006 free (bdistance->access_list);
12007 bdistance->access_list = NULL;
12008 }
12009 if (access_list_str)
12010 bdistance->access_list = strdup (access_list_str);
12011
12012 return CMD_SUCCESS;
12013}
12014
paul94f2b392005-06-28 12:44:16 +000012015static int
paulfd79ac92004-10-13 05:06:08 +000012016bgp_distance_unset (struct vty *vty, const char *distance_str,
12017 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000012018{
12019 int ret;
12020 struct prefix_ipv4 p;
12021 u_char distance;
12022 struct bgp_node *rn;
12023 struct bgp_distance *bdistance;
12024
12025 ret = str2prefix_ipv4 (ip_str, &p);
12026 if (ret == 0)
12027 {
12028 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12029 return CMD_WARNING;
12030 }
12031
12032 distance = atoi (distance_str);
12033
12034 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
12035 if (! rn)
12036 {
12037 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
12038 return CMD_WARNING;
12039 }
12040
12041 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010012042
12043 if (bdistance->distance != distance)
12044 {
12045 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
12046 return CMD_WARNING;
12047 }
12048
paul718e3742002-12-13 20:15:29 +000012049 if (bdistance->access_list)
12050 free (bdistance->access_list);
12051 bgp_distance_free (bdistance);
12052
12053 rn->info = NULL;
12054 bgp_unlock_node (rn);
12055 bgp_unlock_node (rn);
12056
12057 return CMD_SUCCESS;
12058}
12059
paul718e3742002-12-13 20:15:29 +000012060/* Apply BGP information to distance method. */
12061u_char
12062bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
12063{
12064 struct bgp_node *rn;
12065 struct prefix_ipv4 q;
12066 struct peer *peer;
12067 struct bgp_distance *bdistance;
12068 struct access_list *alist;
12069 struct bgp_static *bgp_static;
12070
12071 if (! bgp)
12072 return 0;
12073
12074 if (p->family != AF_INET)
12075 return 0;
12076
12077 peer = rinfo->peer;
12078
12079 if (peer->su.sa.sa_family != AF_INET)
12080 return 0;
12081
12082 memset (&q, 0, sizeof (struct prefix_ipv4));
12083 q.family = AF_INET;
12084 q.prefix = peer->su.sin.sin_addr;
12085 q.prefixlen = IPV4_MAX_BITLEN;
12086
12087 /* Check source address. */
12088 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
12089 if (rn)
12090 {
12091 bdistance = rn->info;
12092 bgp_unlock_node (rn);
12093
12094 if (bdistance->access_list)
12095 {
12096 alist = access_list_lookup (AFI_IP, bdistance->access_list);
12097 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
12098 return bdistance->distance;
12099 }
12100 else
12101 return bdistance->distance;
12102 }
12103
12104 /* Backdoor check. */
12105 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
12106 if (rn)
12107 {
12108 bgp_static = rn->info;
12109 bgp_unlock_node (rn);
12110
12111 if (bgp_static->backdoor)
12112 {
12113 if (bgp->distance_local)
12114 return bgp->distance_local;
12115 else
12116 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12117 }
12118 }
12119
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000012120 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000012121 {
12122 if (bgp->distance_ebgp)
12123 return bgp->distance_ebgp;
12124 return ZEBRA_EBGP_DISTANCE_DEFAULT;
12125 }
12126 else
12127 {
12128 if (bgp->distance_ibgp)
12129 return bgp->distance_ibgp;
12130 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12131 }
12132}
12133
12134DEFUN (bgp_distance,
12135 bgp_distance_cmd,
12136 "distance bgp <1-255> <1-255> <1-255>",
12137 "Define an administrative distance\n"
12138 "BGP distance\n"
12139 "Distance for routes external to the AS\n"
12140 "Distance for routes internal to the AS\n"
12141 "Distance for local routes\n")
12142{
12143 struct bgp *bgp;
12144
12145 bgp = vty->index;
12146
12147 bgp->distance_ebgp = atoi (argv[0]);
12148 bgp->distance_ibgp = atoi (argv[1]);
12149 bgp->distance_local = atoi (argv[2]);
12150 return CMD_SUCCESS;
12151}
12152
12153DEFUN (no_bgp_distance,
12154 no_bgp_distance_cmd,
12155 "no distance bgp <1-255> <1-255> <1-255>",
12156 NO_STR
12157 "Define an administrative distance\n"
12158 "BGP distance\n"
12159 "Distance for routes external to the AS\n"
12160 "Distance for routes internal to the AS\n"
12161 "Distance for local routes\n")
12162{
12163 struct bgp *bgp;
12164
12165 bgp = vty->index;
12166
12167 bgp->distance_ebgp= 0;
12168 bgp->distance_ibgp = 0;
12169 bgp->distance_local = 0;
12170 return CMD_SUCCESS;
12171}
12172
12173ALIAS (no_bgp_distance,
12174 no_bgp_distance2_cmd,
12175 "no distance bgp",
12176 NO_STR
12177 "Define an administrative distance\n"
12178 "BGP distance\n")
12179
12180DEFUN (bgp_distance_source,
12181 bgp_distance_source_cmd,
12182 "distance <1-255> A.B.C.D/M",
12183 "Define an administrative distance\n"
12184 "Administrative distance\n"
12185 "IP source prefix\n")
12186{
12187 bgp_distance_set (vty, argv[0], argv[1], NULL);
12188 return CMD_SUCCESS;
12189}
12190
12191DEFUN (no_bgp_distance_source,
12192 no_bgp_distance_source_cmd,
12193 "no distance <1-255> A.B.C.D/M",
12194 NO_STR
12195 "Define an administrative distance\n"
12196 "Administrative distance\n"
12197 "IP source prefix\n")
12198{
12199 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12200 return CMD_SUCCESS;
12201}
12202
12203DEFUN (bgp_distance_source_access_list,
12204 bgp_distance_source_access_list_cmd,
12205 "distance <1-255> A.B.C.D/M WORD",
12206 "Define an administrative distance\n"
12207 "Administrative distance\n"
12208 "IP source prefix\n"
12209 "Access list name\n")
12210{
12211 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12212 return CMD_SUCCESS;
12213}
12214
12215DEFUN (no_bgp_distance_source_access_list,
12216 no_bgp_distance_source_access_list_cmd,
12217 "no distance <1-255> A.B.C.D/M WORD",
12218 NO_STR
12219 "Define an administrative distance\n"
12220 "Administrative distance\n"
12221 "IP source prefix\n"
12222 "Access list name\n")
12223{
12224 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12225 return CMD_SUCCESS;
12226}
David Lamparter6b0655a2014-06-04 06:53:35 +020012227
paul718e3742002-12-13 20:15:29 +000012228DEFUN (bgp_damp_set,
12229 bgp_damp_set_cmd,
12230 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12231 "BGP Specific commands\n"
12232 "Enable route-flap dampening\n"
12233 "Half-life time for the penalty\n"
12234 "Value to start reusing a route\n"
12235 "Value to start suppressing a route\n"
12236 "Maximum duration to suppress a stable route\n")
12237{
12238 struct bgp *bgp;
12239 int half = DEFAULT_HALF_LIFE * 60;
12240 int reuse = DEFAULT_REUSE;
12241 int suppress = DEFAULT_SUPPRESS;
12242 int max = 4 * half;
12243
12244 if (argc == 4)
12245 {
12246 half = atoi (argv[0]) * 60;
12247 reuse = atoi (argv[1]);
12248 suppress = atoi (argv[2]);
12249 max = atoi (argv[3]) * 60;
12250 }
12251 else if (argc == 1)
12252 {
12253 half = atoi (argv[0]) * 60;
12254 max = 4 * half;
12255 }
12256
12257 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012258
12259 if (suppress < reuse)
12260 {
12261 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12262 VTY_NEWLINE);
12263 return 0;
12264 }
12265
paul718e3742002-12-13 20:15:29 +000012266 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12267 half, reuse, suppress, max);
12268}
12269
12270ALIAS (bgp_damp_set,
12271 bgp_damp_set2_cmd,
12272 "bgp dampening <1-45>",
12273 "BGP Specific commands\n"
12274 "Enable route-flap dampening\n"
12275 "Half-life time for the penalty\n")
12276
12277ALIAS (bgp_damp_set,
12278 bgp_damp_set3_cmd,
12279 "bgp dampening",
12280 "BGP Specific commands\n"
12281 "Enable route-flap dampening\n")
12282
12283DEFUN (bgp_damp_unset,
12284 bgp_damp_unset_cmd,
12285 "no bgp dampening",
12286 NO_STR
12287 "BGP Specific commands\n"
12288 "Enable route-flap dampening\n")
12289{
12290 struct bgp *bgp;
12291
12292 bgp = vty->index;
12293 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12294}
12295
12296ALIAS (bgp_damp_unset,
12297 bgp_damp_unset2_cmd,
12298 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12299 NO_STR
12300 "BGP Specific commands\n"
12301 "Enable route-flap dampening\n"
12302 "Half-life time for the penalty\n"
12303 "Value to start reusing a route\n"
12304 "Value to start suppressing a route\n"
12305 "Maximum duration to suppress a stable route\n")
12306
12307DEFUN (show_ip_bgp_dampened_paths,
12308 show_ip_bgp_dampened_paths_cmd,
12309 "show ip bgp dampened-paths",
12310 SHOW_STR
12311 IP_STR
12312 BGP_STR
12313 "Display paths suppressed due to dampening\n")
12314{
ajs5a646652004-11-05 01:25:55 +000012315 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12316 NULL);
paul718e3742002-12-13 20:15:29 +000012317}
12318
Balaji3921cc52015-05-16 23:12:17 +053012319ALIAS (show_ip_bgp_dampened_paths,
12320 show_ip_bgp_damp_dampened_paths_cmd,
12321 "show ip bgp dampening dampened-paths",
12322 SHOW_STR
12323 IP_STR
12324 BGP_STR
12325 "Display detailed information about dampening\n"
12326 "Display paths suppressed due to dampening\n")
12327
paul718e3742002-12-13 20:15:29 +000012328DEFUN (show_ip_bgp_flap_statistics,
12329 show_ip_bgp_flap_statistics_cmd,
12330 "show ip bgp flap-statistics",
12331 SHOW_STR
12332 IP_STR
12333 BGP_STR
12334 "Display flap statistics of routes\n")
12335{
ajs5a646652004-11-05 01:25:55 +000012336 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12337 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012338}
David Lamparter6b0655a2014-06-04 06:53:35 +020012339
Balaji3921cc52015-05-16 23:12:17 +053012340ALIAS (show_ip_bgp_flap_statistics,
12341 show_ip_bgp_damp_flap_statistics_cmd,
12342 "show ip bgp dampening flap-statistics",
12343 SHOW_STR
12344 IP_STR
12345 BGP_STR
12346 "Display detailed information about dampening\n"
12347 "Display flap statistics of routes\n")
12348
paul718e3742002-12-13 20:15:29 +000012349/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012350static int
paulfd79ac92004-10-13 05:06:08 +000012351bgp_clear_damp_route (struct vty *vty, const char *view_name,
12352 const char *ip_str, afi_t afi, safi_t safi,
12353 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012354{
12355 int ret;
12356 struct prefix match;
12357 struct bgp_node *rn;
12358 struct bgp_node *rm;
12359 struct bgp_info *ri;
12360 struct bgp_info *ri_temp;
12361 struct bgp *bgp;
12362 struct bgp_table *table;
12363
12364 /* BGP structure lookup. */
12365 if (view_name)
12366 {
12367 bgp = bgp_lookup_by_name (view_name);
12368 if (bgp == NULL)
12369 {
12370 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12371 return CMD_WARNING;
12372 }
12373 }
12374 else
12375 {
12376 bgp = bgp_get_default ();
12377 if (bgp == NULL)
12378 {
12379 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12380 return CMD_WARNING;
12381 }
12382 }
12383
12384 /* Check IP address argument. */
12385 ret = str2prefix (ip_str, &match);
12386 if (! ret)
12387 {
12388 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12389 return CMD_WARNING;
12390 }
12391
12392 match.family = afi2family (afi);
12393
12394 if (safi == SAFI_MPLS_VPN)
12395 {
12396 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12397 {
12398 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12399 continue;
12400
12401 if ((table = rn->info) != NULL)
12402 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012403 {
12404 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12405 {
12406 ri = rm->info;
12407 while (ri)
12408 {
12409 if (ri->extra && ri->extra->damp_info)
12410 {
12411 ri_temp = ri->next;
12412 bgp_damp_info_free (ri->extra->damp_info, 1);
12413 ri = ri_temp;
12414 }
12415 else
12416 ri = ri->next;
12417 }
12418 }
12419
12420 bgp_unlock_node (rm);
12421 }
paul718e3742002-12-13 20:15:29 +000012422 }
12423 }
12424 else
12425 {
12426 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012427 {
12428 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12429 {
12430 ri = rn->info;
12431 while (ri)
12432 {
12433 if (ri->extra && ri->extra->damp_info)
12434 {
12435 ri_temp = ri->next;
12436 bgp_damp_info_free (ri->extra->damp_info, 1);
12437 ri = ri_temp;
12438 }
12439 else
12440 ri = ri->next;
12441 }
12442 }
12443
12444 bgp_unlock_node (rn);
12445 }
paul718e3742002-12-13 20:15:29 +000012446 }
12447
12448 return CMD_SUCCESS;
12449}
12450
12451DEFUN (clear_ip_bgp_dampening,
12452 clear_ip_bgp_dampening_cmd,
12453 "clear ip bgp dampening",
12454 CLEAR_STR
12455 IP_STR
12456 BGP_STR
12457 "Clear route flap dampening information\n")
12458{
12459 bgp_damp_info_clean ();
12460 return CMD_SUCCESS;
12461}
12462
12463DEFUN (clear_ip_bgp_dampening_prefix,
12464 clear_ip_bgp_dampening_prefix_cmd,
12465 "clear ip bgp dampening A.B.C.D/M",
12466 CLEAR_STR
12467 IP_STR
12468 BGP_STR
12469 "Clear route flap dampening information\n"
12470 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12471{
12472 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12473 SAFI_UNICAST, NULL, 1);
12474}
12475
12476DEFUN (clear_ip_bgp_dampening_address,
12477 clear_ip_bgp_dampening_address_cmd,
12478 "clear ip bgp dampening A.B.C.D",
12479 CLEAR_STR
12480 IP_STR
12481 BGP_STR
12482 "Clear route flap dampening information\n"
12483 "Network to clear damping information\n")
12484{
12485 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12486 SAFI_UNICAST, NULL, 0);
12487}
12488
12489DEFUN (clear_ip_bgp_dampening_address_mask,
12490 clear_ip_bgp_dampening_address_mask_cmd,
12491 "clear ip bgp dampening A.B.C.D A.B.C.D",
12492 CLEAR_STR
12493 IP_STR
12494 BGP_STR
12495 "Clear route flap dampening information\n"
12496 "Network to clear damping information\n"
12497 "Network mask\n")
12498{
12499 int ret;
12500 char prefix_str[BUFSIZ];
12501
12502 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12503 if (! ret)
12504 {
12505 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12506 return CMD_WARNING;
12507 }
12508
12509 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12510 SAFI_UNICAST, NULL, 0);
12511}
David Lamparter6b0655a2014-06-04 06:53:35 +020012512
paul94f2b392005-06-28 12:44:16 +000012513static int
paul718e3742002-12-13 20:15:29 +000012514bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12515 afi_t afi, safi_t safi, int *write)
12516{
12517 struct bgp_node *prn;
12518 struct bgp_node *rn;
12519 struct bgp_table *table;
12520 struct prefix *p;
12521 struct prefix_rd *prd;
12522 struct bgp_static *bgp_static;
12523 u_int32_t label;
12524 char buf[SU_ADDRSTRLEN];
12525 char rdbuf[RD_ADDRSTRLEN];
12526
12527 /* Network configuration. */
12528 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12529 if ((table = prn->info) != NULL)
12530 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12531 if ((bgp_static = rn->info) != NULL)
12532 {
12533 p = &rn->p;
12534 prd = (struct prefix_rd *) &prn->p;
12535
12536 /* "address-family" display. */
12537 bgp_config_write_family_header (vty, afi, safi, write);
12538
12539 /* "network" configuration display. */
12540 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12541 label = decode_label (bgp_static->tag);
12542
12543 vty_out (vty, " network %s/%d rd %s tag %d",
12544 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12545 p->prefixlen,
12546 rdbuf, label);
12547 vty_out (vty, "%s", VTY_NEWLINE);
12548 }
12549 return 0;
12550}
12551
12552/* Configuration of static route announcement and aggregate
12553 information. */
12554int
12555bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12556 afi_t afi, safi_t safi, int *write)
12557{
12558 struct bgp_node *rn;
12559 struct prefix *p;
12560 struct bgp_static *bgp_static;
12561 struct bgp_aggregate *bgp_aggregate;
12562 char buf[SU_ADDRSTRLEN];
12563
12564 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12565 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12566
12567 /* Network configuration. */
12568 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12569 if ((bgp_static = rn->info) != NULL)
12570 {
12571 p = &rn->p;
12572
12573 /* "address-family" display. */
12574 bgp_config_write_family_header (vty, afi, safi, write);
12575
12576 /* "network" configuration display. */
12577 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12578 {
12579 u_int32_t destination;
12580 struct in_addr netmask;
12581
12582 destination = ntohl (p->u.prefix4.s_addr);
12583 masklen2ip (p->prefixlen, &netmask);
12584 vty_out (vty, " network %s",
12585 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12586
12587 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12588 || (IN_CLASSB (destination) && p->prefixlen == 16)
12589 || (IN_CLASSA (destination) && p->prefixlen == 8)
12590 || p->u.prefix4.s_addr == 0)
12591 {
12592 /* Natural mask is not display. */
12593 }
12594 else
12595 vty_out (vty, " mask %s", inet_ntoa (netmask));
12596 }
12597 else
12598 {
12599 vty_out (vty, " network %s/%d",
12600 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12601 p->prefixlen);
12602 }
12603
12604 if (bgp_static->rmap.name)
12605 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012606 else
12607 {
12608 if (bgp_static->backdoor)
12609 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012610 }
paul718e3742002-12-13 20:15:29 +000012611
12612 vty_out (vty, "%s", VTY_NEWLINE);
12613 }
12614
12615 /* Aggregate-address configuration. */
12616 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12617 if ((bgp_aggregate = rn->info) != NULL)
12618 {
12619 p = &rn->p;
12620
12621 /* "address-family" display. */
12622 bgp_config_write_family_header (vty, afi, safi, write);
12623
12624 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12625 {
12626 struct in_addr netmask;
12627
12628 masklen2ip (p->prefixlen, &netmask);
12629 vty_out (vty, " aggregate-address %s %s",
12630 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12631 inet_ntoa (netmask));
12632 }
12633 else
12634 {
12635 vty_out (vty, " aggregate-address %s/%d",
12636 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12637 p->prefixlen);
12638 }
12639
12640 if (bgp_aggregate->as_set)
12641 vty_out (vty, " as-set");
12642
12643 if (bgp_aggregate->summary_only)
12644 vty_out (vty, " summary-only");
12645
12646 vty_out (vty, "%s", VTY_NEWLINE);
12647 }
12648
12649 return 0;
12650}
12651
12652int
12653bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12654{
12655 struct bgp_node *rn;
12656 struct bgp_distance *bdistance;
12657
12658 /* Distance configuration. */
12659 if (bgp->distance_ebgp
12660 && bgp->distance_ibgp
12661 && bgp->distance_local
12662 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12663 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12664 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12665 vty_out (vty, " distance bgp %d %d %d%s",
12666 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12667 VTY_NEWLINE);
12668
12669 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12670 if ((bdistance = rn->info) != NULL)
12671 {
12672 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12673 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12674 bdistance->access_list ? bdistance->access_list : "",
12675 VTY_NEWLINE);
12676 }
12677
12678 return 0;
12679}
12680
12681/* Allocate routing table structure and install commands. */
12682void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012683bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012684{
12685 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012686 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012687
12688 /* IPv4 BGP commands. */
12689 install_element (BGP_NODE, &bgp_network_cmd);
12690 install_element (BGP_NODE, &bgp_network_mask_cmd);
12691 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12692 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12693 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12694 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12695 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12696 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12697 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12698 install_element (BGP_NODE, &no_bgp_network_cmd);
12699 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12700 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12701 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12702 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12703 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12704 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12705 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12706 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12707
12708 install_element (BGP_NODE, &aggregate_address_cmd);
12709 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12710 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12711 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12712 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12713 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12714 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12715 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12716 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12717 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12718 install_element (BGP_NODE, &no_aggregate_address_cmd);
12719 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12720 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12721 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12722 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12723 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12724 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12725 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12726 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12727 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12728
12729 /* IPv4 unicast configuration. */
12730 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12731 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12732 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12733 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12734 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12735 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012736 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012737 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12738 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12739 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12740 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12741 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012742
paul718e3742002-12-13 20:15:29 +000012743 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12744 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12745 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12746 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12747 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12748 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12749 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12750 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12751 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12752 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12753 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12754 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12755 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12756 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12757 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12758 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12759 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12760 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12761 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12762 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12763
12764 /* IPv4 multicast configuration. */
12765 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12766 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12767 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12768 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12769 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12770 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12771 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12772 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12773 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12774 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12775 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12776 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12777 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12778 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12779 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12780 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12781 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12782 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12783 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12784 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12785 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12786 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12787 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12788 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12789 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12790 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12791 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12792 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12793 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12794 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12795 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12796 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12797
12798 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12799 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012800 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012801 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12802 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012803 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012804 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12805 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12806 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12807 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012808 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012809 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12810 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12811 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12812 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12813 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12814 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12815 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12816 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12817 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12818 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12819 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12820 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12821 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12822 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12823 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12824 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12825 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12826 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12827 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12828 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12829 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12830 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12831 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12832 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12833 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012834 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12835 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12836 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12837 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12838 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012839 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12840 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12841 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12842 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12843 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12844 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12845 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12846 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12847 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12848 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12849 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12850 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12851 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12852 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12853 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12854 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12855 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12856 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012857 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012858 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12859 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12860 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12861 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012862 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012863 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012864 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012865 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012866 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012867 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012868 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012869 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12870 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012871 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012872 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12873 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012874 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012875 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012876 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012877 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012878 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012879 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012880 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012881 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12882 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012883 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012884 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012885 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012886 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012887 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012888 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012889 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12890 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012891 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012892 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012893 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012894 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012895 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012896 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012897
12898 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12899 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12900 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012901 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012902 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12903 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12904 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012905 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012906 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12907 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12908 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12909 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12910 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12911 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12912 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12913 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12914 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12915 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12916 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12917 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012918 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12919 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12920 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12921 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12922 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012923 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12924 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12925 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12926 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12927 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12928 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12929 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12930 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12931 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012932 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012933 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012934 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012935 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012936 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012937 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012938 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012939
12940 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12941 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012942 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012943 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12944 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012945 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012946 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12947 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12948 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12949 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012950 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012951 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12952 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12953 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12954 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12955 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12956 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12957 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12958 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12959 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12960 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12961 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12962 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12963 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12964 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12965 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12966 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12967 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12968 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12969 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12970 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12971 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12972 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12973 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12974 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12975 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012976 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12977 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12978 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12979 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12980 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012981 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12982 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12983 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12984 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12985 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12986 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12987 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12988 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12989 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12990 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12991 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12992 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12993 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12994 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12995 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12996 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12997 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12998 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012999 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013000 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
13001 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13002 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13003 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013004 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000013005 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013006 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000013007 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013008 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000013009 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013010 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000013011 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
13012 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013013 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000013014 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013015 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000013016 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013017 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000013018 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013019 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
13020 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000013021 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013022 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000013023 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013024 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000013025 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
13026 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013027 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013028 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013029 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013030 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013031 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013032 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010013033 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13034 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013035 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013036 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013037 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013038 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013039 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013040 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013041
13042 /* BGP dampening clear commands */
13043 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13044 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13045 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13046 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13047
Paul Jakmaff7924f2006-09-04 01:10:36 +000013048 /* prefix count */
13049 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
13050 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
13051 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000013052#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000013053 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13054
paul718e3742002-12-13 20:15:29 +000013055 /* New config IPv6 BGP commands. */
13056 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13057 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
13058 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13059 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13060
13061 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13062 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13063 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13064 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
13065
G.Balaji73bfe0b2011-09-23 22:36:20 +053013066 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13067 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
13068
paul718e3742002-12-13 20:15:29 +000013069 /* Old config IPv6 BGP commands. */
13070 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13071 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13072
13073 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13074 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13075 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13076 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13077
13078 install_element (VIEW_NODE, &show_bgp_cmd);
13079 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013080 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013081 install_element (VIEW_NODE, &show_bgp_route_cmd);
13082 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013083 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013084 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
13085 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013086 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013087 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
13088 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
13089 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
13090 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
13091 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
13092 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
13093 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
13094 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
13095 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
13096 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
13097 install_element (VIEW_NODE, &show_bgp_community_cmd);
13098 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
13099 install_element (VIEW_NODE, &show_bgp_community2_cmd);
13100 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
13101 install_element (VIEW_NODE, &show_bgp_community3_cmd);
13102 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
13103 install_element (VIEW_NODE, &show_bgp_community4_cmd);
13104 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
13105 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
13106 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
13107 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
13108 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
13109 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
13110 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
13111 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
13112 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13113 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
13114 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
13115 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
13116 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13117 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
13118 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13119 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
13120 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13121 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
13122 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13123 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
13124 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13125 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13126 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013127 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
13128 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13129 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
13130 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013131 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013132 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013133 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013134 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013135 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013136 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013137 install_element (VIEW_NODE, &show_bgp_view_cmd);
13138 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
13139 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
13140 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
13141 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
13142 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
13143 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13144 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13145 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13146 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13147 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
13148 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13149 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13150 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13151 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
13152 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13153 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
13154 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013155 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013156 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013157 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013158 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013159 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013160 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013161
13162 /* Restricted:
13163 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13164 */
13165 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
13166 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013167 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013168 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
13169 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013170 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013171 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
13172 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
13173 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
13174 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
13175 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
13176 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
13177 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
13178 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
13179 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
13180 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
13181 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
13182 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13183 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13184 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13185 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13186 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13187 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013188 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013189 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013190 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013191 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
13192 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13193 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13194 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13195 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13196 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13197 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013198 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013199 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013200 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013201
13202 install_element (ENABLE_NODE, &show_bgp_cmd);
13203 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013204 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013205 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13206 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013207 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013208 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13209 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013210 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013211 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13212 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13213 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13214 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13215 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13216 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13217 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13218 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13219 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13220 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13221 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13222 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13223 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13224 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13225 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13226 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13227 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13228 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13229 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13230 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13231 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13232 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13233 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13234 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13235 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13236 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13237 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13238 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13239 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13240 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13241 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13242 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13243 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13244 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13245 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13246 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13247 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13248 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13249 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13250 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013251 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13252 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13253 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13254 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013255 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013256 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013257 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013258 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013259 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013260 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013261 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13262 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13263 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13264 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13265 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13266 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13267 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13268 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13269 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13270 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13271 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13272 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13273 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13274 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13275 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13276 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13277 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13278 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013279 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013280 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013281 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013282 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013283 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013284 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013285
13286 /* Statistics */
13287 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13288 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13289 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13290 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13291
paul718e3742002-12-13 20:15:29 +000013292 /* old command */
13293 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13294 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13295 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13296 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13297 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13298 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13299 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13300 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13301 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13302 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13303 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13304 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13305 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13306 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13307 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13308 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13309 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13310 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13311 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13312 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13313 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13314 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13315 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13316 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13317 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13318 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13319 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13320 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13321 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13322 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13323 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13324 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13325 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13326 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13327 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13328 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013329
paul718e3742002-12-13 20:15:29 +000013330 /* old command */
13331 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13332 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13333 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13334 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13335 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13336 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13337 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13338 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13339 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13340 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13341 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13342 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13343 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13344 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13345 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13346 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13347 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13348 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13349 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13350 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13351 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13352 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13353 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13354 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13355 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13356 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13357 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13358 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13359 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13360 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13361 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13362 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13363 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13364 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13365 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13366 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13367
13368 /* old command */
13369 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13370 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13371 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13372 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13373
13374 /* old command */
13375 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13376 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13377 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13378 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13379
13380 /* old command */
13381 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13382 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13383 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13384 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13385#endif /* HAVE_IPV6 */
13386
13387 install_element (BGP_NODE, &bgp_distance_cmd);
13388 install_element (BGP_NODE, &no_bgp_distance_cmd);
13389 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13390 install_element (BGP_NODE, &bgp_distance_source_cmd);
13391 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13392 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13393 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13394
13395 install_element (BGP_NODE, &bgp_damp_set_cmd);
13396 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13397 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13398 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13399 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13400 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13401 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13402 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13403 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13404 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013405
13406 /* Deprecated AS-Pathlimit commands */
13407 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13408 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13409 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13410 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13411 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13412 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13413
13414 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13415 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13416 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13417 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13418 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13419 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13420
13421 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13422 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13423 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13424 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13425 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13426 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13427
13428 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13429 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13430 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13431 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13432 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13433 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13434
13435 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13436 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13437 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13438 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13439 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13440 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13441
13442 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13443 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13444 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13445 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13446 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13447 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013448
13449#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013450 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13451 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013452#endif
paul718e3742002-12-13 20:15:29 +000013453}
Chris Caputo228da422009-07-18 05:44:03 +000013454
13455void
13456bgp_route_finish (void)
13457{
13458 bgp_table_unlock (bgp_distance_table);
13459 bgp_distance_table = NULL;
13460}