blob: 8aa6daa8ed9e6ad70b38992de9b3f850b7fe4ddf [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
3054void
3055bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3056{
3057 struct bgp_table *table;
3058 struct bgp_node *rn;
3059 struct bgp_adj_in *ain;
3060
3061 table = peer->bgp->rib[afi][safi];
3062
3063 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3064 for (ain = rn->adj_in; ain ; ain = ain->next)
3065 if (ain->peer == peer)
3066 {
3067 bgp_adj_in_remove (rn, ain);
3068 bgp_unlock_node (rn);
3069 break;
3070 }
3071}
hasso93406d82005-02-02 14:40:33 +00003072
3073void
3074bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3075{
3076 struct bgp_node *rn;
3077 struct bgp_info *ri;
3078 struct bgp_table *table;
3079
3080 table = peer->bgp->rib[afi][safi];
3081
3082 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3083 {
3084 for (ri = rn->info; ri; ri = ri->next)
3085 if (ri->peer == peer)
3086 {
3087 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3088 bgp_rib_remove (rn, ri, peer, afi, safi);
3089 break;
3090 }
3091 }
3092}
David Lamparter6b0655a2014-06-04 06:53:35 +02003093
paul718e3742002-12-13 20:15:29 +00003094/* Delete all kernel routes. */
3095void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003096bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003097{
3098 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003099 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003100 struct bgp_node *rn;
3101 struct bgp_table *table;
3102 struct bgp_info *ri;
3103
paul1eb8ef22005-04-07 07:30:20 +00003104 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003105 {
3106 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3107
3108 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3109 for (ri = rn->info; ri; ri = ri->next)
3110 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3111 && ri->type == ZEBRA_ROUTE_BGP
3112 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003113 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003114
3115 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3116
3117 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3118 for (ri = rn->info; ri; ri = ri->next)
3119 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3120 && ri->type == ZEBRA_ROUTE_BGP
3121 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003122 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003123 }
3124}
3125
3126void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003127bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003128{
3129 vty_reset ();
3130 bgp_zclient_reset ();
3131 access_list_reset ();
3132 prefix_list_reset ();
3133}
David Lamparter6b0655a2014-06-04 06:53:35 +02003134
paul718e3742002-12-13 20:15:29 +00003135/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3136 value. */
3137int
3138bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3139{
3140 u_char *pnt;
3141 u_char *lim;
3142 struct prefix p;
3143 int psize;
3144 int ret;
3145
3146 /* Check peer status. */
3147 if (peer->status != Established)
3148 return 0;
3149
3150 pnt = packet->nlri;
3151 lim = pnt + packet->length;
3152
3153 for (; pnt < lim; pnt += psize)
3154 {
3155 /* Clear prefix structure. */
3156 memset (&p, 0, sizeof (struct prefix));
3157
3158 /* Fetch prefix length. */
3159 p.prefixlen = *pnt++;
3160 p.family = afi2family (packet->afi);
3161
3162 /* Already checked in nlri_sanity_check(). We do double check
3163 here. */
3164 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3165 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3166 return -1;
3167
3168 /* Packet size overflow check. */
3169 psize = PSIZE (p.prefixlen);
3170
3171 /* When packet overflow occur return immediately. */
3172 if (pnt + psize > lim)
3173 return -1;
3174
3175 /* Fetch prefix from NLRI packet. */
3176 memcpy (&p.u.prefix, pnt, psize);
3177
3178 /* Check address. */
3179 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3180 {
3181 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3182 {
paulf5ba3872004-07-09 12:11:31 +00003183 /*
3184 * From draft-ietf-idr-bgp4-22, Section 6.3:
3185 * If a BGP router receives an UPDATE message with a
3186 * semantically incorrect NLRI field, in which a prefix is
3187 * semantically incorrect (eg. an unexpected multicast IP
3188 * address), it should ignore the prefix.
3189 */
paul718e3742002-12-13 20:15:29 +00003190 zlog (peer->log, LOG_ERR,
3191 "IPv4 unicast NLRI is multicast address %s",
3192 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003193
paul718e3742002-12-13 20:15:29 +00003194 return -1;
3195 }
3196 }
3197
3198#ifdef HAVE_IPV6
3199 /* Check address. */
3200 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3201 {
3202 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3203 {
3204 char buf[BUFSIZ];
3205
3206 zlog (peer->log, LOG_WARNING,
3207 "IPv6 link-local NLRI received %s ignore this NLRI",
3208 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3209
3210 continue;
3211 }
3212 }
3213#endif /* HAVE_IPV6 */
3214
3215 /* Normal process. */
3216 if (attr)
3217 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3218 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3219 else
3220 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3221 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3222
3223 /* Address family configuration mismatch or maximum-prefix count
3224 overflow. */
3225 if (ret < 0)
3226 return -1;
3227 }
3228
3229 /* Packet length consistency check. */
3230 if (pnt != lim)
3231 return -1;
3232
3233 return 0;
3234}
3235
3236/* NLRI encode syntax check routine. */
3237int
3238bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3239 bgp_size_t length)
3240{
3241 u_char *end;
3242 u_char prefixlen;
3243 int psize;
3244
3245 end = pnt + length;
3246
3247 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3248 syntactic validity. If the field is syntactically incorrect,
3249 then the Error Subcode is set to Invalid Network Field. */
3250
3251 while (pnt < end)
3252 {
3253 prefixlen = *pnt++;
3254
3255 /* Prefix length check. */
3256 if ((afi == AFI_IP && prefixlen > 32)
3257 || (afi == AFI_IP6 && prefixlen > 128))
3258 {
3259 plog_err (peer->log,
3260 "%s [Error] Update packet error (wrong prefix length %d)",
3261 peer->host, prefixlen);
3262 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3263 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3264 return -1;
3265 }
3266
3267 /* Packet size overflow check. */
3268 psize = PSIZE (prefixlen);
3269
3270 if (pnt + psize > end)
3271 {
3272 plog_err (peer->log,
3273 "%s [Error] Update packet error"
3274 " (prefix data overflow prefix size is %d)",
3275 peer->host, psize);
3276 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3277 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3278 return -1;
3279 }
3280
3281 pnt += psize;
3282 }
3283
3284 /* Packet length consistency check. */
3285 if (pnt != end)
3286 {
3287 plog_err (peer->log,
3288 "%s [Error] Update packet error"
3289 " (prefix length mismatch with total length)",
3290 peer->host);
3291 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3292 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3293 return -1;
3294 }
3295 return 0;
3296}
David Lamparter6b0655a2014-06-04 06:53:35 +02003297
paul94f2b392005-06-28 12:44:16 +00003298static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003299bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003300{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003301 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003302}
3303
paul94f2b392005-06-28 12:44:16 +00003304static void
paul718e3742002-12-13 20:15:29 +00003305bgp_static_free (struct bgp_static *bgp_static)
3306{
3307 if (bgp_static->rmap.name)
3308 free (bgp_static->rmap.name);
3309 XFREE (MTYPE_BGP_STATIC, bgp_static);
3310}
3311
paul94f2b392005-06-28 12:44:16 +00003312static void
paulfee0f4c2004-09-13 05:12:46 +00003313bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3314 struct prefix *p, afi_t afi, safi_t safi)
3315{
3316 struct bgp_node *rn;
3317 struct bgp_info *ri;
3318
3319 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3320
3321 /* Check selected route and self inserted route. */
3322 for (ri = rn->info; ri; ri = ri->next)
3323 if (ri->peer == bgp->peer_self
3324 && ri->type == ZEBRA_ROUTE_BGP
3325 && ri->sub_type == BGP_ROUTE_STATIC)
3326 break;
3327
3328 /* Withdraw static BGP route from routing table. */
3329 if (ri)
3330 {
paulfee0f4c2004-09-13 05:12:46 +00003331 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003332 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003333 }
3334
3335 /* Unlock bgp_node_lookup. */
3336 bgp_unlock_node (rn);
3337}
3338
paul94f2b392005-06-28 12:44:16 +00003339static void
paulfee0f4c2004-09-13 05:12:46 +00003340bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003341 struct bgp_static *bgp_static,
3342 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003343{
3344 struct bgp_node *rn;
3345 struct bgp_info *ri;
3346 struct bgp_info *new;
3347 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003348 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003349 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003350 struct attr new_attr;
3351 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003352 struct bgp *bgp;
3353 int ret;
3354 char buf[SU_ADDRSTRLEN];
3355
3356 bgp = rsclient->bgp;
3357
Paul Jakma06e110f2006-05-12 23:29:22 +00003358 assert (bgp_static);
3359 if (!bgp_static)
3360 return;
3361
paulfee0f4c2004-09-13 05:12:46 +00003362 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3363
3364 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003365
3366 attr.nexthop = bgp_static->igpnexthop;
3367 attr.med = bgp_static->igpmetric;
3368 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003369
Paul Jakma41367172007-08-06 15:24:51 +00003370 if (bgp_static->atomic)
3371 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3372
paulfee0f4c2004-09-13 05:12:46 +00003373 /* Apply network route-map for export to this rsclient. */
3374 if (bgp_static->rmap.name)
3375 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003376 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003377 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003378 info.attr = &attr_tmp;
3379
paulfee0f4c2004-09-13 05:12:46 +00003380 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3381 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3382
3383 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3384
3385 rsclient->rmap_type = 0;
3386
3387 if (ret == RMAP_DENYMATCH)
3388 {
3389 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003390 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003391
3392 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003393 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003394 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003395 bgp_attr_extra_free (&attr);
3396
paulfee0f4c2004-09-13 05:12:46 +00003397 return;
3398 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003399 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003400 }
3401 else
3402 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003403
3404 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003405 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003406
paulfee0f4c2004-09-13 05:12:46 +00003407 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3408
Paul Jakmafb982c22007-05-04 20:15:47 +00003409 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3410 == RMAP_DENY)
3411 {
paulfee0f4c2004-09-13 05:12:46 +00003412 /* This BGP update is filtered. Log the reason then update BGP entry. */
3413 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003414 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003415 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3416 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3417 p->prefixlen, rsclient->host);
3418
3419 bgp->peer_self->rmap_type = 0;
3420
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003421 bgp_attr_unintern (&attr_new);
3422 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003423 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003424
3425 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3426
3427 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003428 }
paulfee0f4c2004-09-13 05:12:46 +00003429
3430 bgp->peer_self->rmap_type = 0;
3431
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003432 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003433 attr_new = bgp_attr_intern (&new_attr);
3434
3435 for (ri = rn->info; ri; ri = ri->next)
3436 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3437 && ri->sub_type == BGP_ROUTE_STATIC)
3438 break;
3439
3440 if (ri)
3441 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003442 if (attrhash_cmp (ri->attr, attr_new) &&
3443 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003444 {
3445 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003446 bgp_attr_unintern (&attr_new);
3447 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003448 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003449 return;
3450 }
3451 else
3452 {
3453 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003454 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003455
3456 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003457 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3458 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003459 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003460 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003461 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003462
3463 /* Process change. */
3464 bgp_process (bgp, rn, afi, safi);
3465 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003466 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003467 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003468 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003469 }
paulfee0f4c2004-09-13 05:12:46 +00003470 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003471
paulfee0f4c2004-09-13 05:12:46 +00003472 /* Make new BGP info. */
3473 new = bgp_info_new ();
3474 new->type = ZEBRA_ROUTE_BGP;
3475 new->sub_type = BGP_ROUTE_STATIC;
3476 new->peer = bgp->peer_self;
3477 SET_FLAG (new->flags, BGP_INFO_VALID);
3478 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003479 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003480
3481 /* Register new BGP information. */
3482 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003483
3484 /* route_node_get lock */
3485 bgp_unlock_node (rn);
3486
paulfee0f4c2004-09-13 05:12:46 +00003487 /* Process change. */
3488 bgp_process (bgp, rn, afi, safi);
3489
3490 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003491 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
paul94f2b392005-06-28 12:44:16 +00003495static void
paulfee0f4c2004-09-13 05:12:46 +00003496bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003497 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3498{
3499 struct bgp_node *rn;
3500 struct bgp_info *ri;
3501 struct bgp_info *new;
3502 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003503 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003504 struct attr *attr_new;
3505 int ret;
3506
Paul Jakmadd8103a2006-05-12 23:27:30 +00003507 assert (bgp_static);
3508 if (!bgp_static)
3509 return;
3510
paulfee0f4c2004-09-13 05:12:46 +00003511 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003512
3513 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003514
3515 attr.nexthop = bgp_static->igpnexthop;
3516 attr.med = bgp_static->igpmetric;
3517 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003518
Paul Jakma41367172007-08-06 15:24:51 +00003519 if (bgp_static->atomic)
3520 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3521
paul718e3742002-12-13 20:15:29 +00003522 /* Apply route-map. */
3523 if (bgp_static->rmap.name)
3524 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003525 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003526 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003527 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003528
paulfee0f4c2004-09-13 05:12:46 +00003529 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3530
paul718e3742002-12-13 20:15:29 +00003531 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003532
paulfee0f4c2004-09-13 05:12:46 +00003533 bgp->peer_self->rmap_type = 0;
3534
paul718e3742002-12-13 20:15:29 +00003535 if (ret == RMAP_DENYMATCH)
3536 {
3537 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003538 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003539
3540 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003541 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003542 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003543 bgp_static_withdraw (bgp, p, afi, safi);
3544 return;
3545 }
paul286e1e72003-08-08 00:24:31 +00003546 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003547 }
paul286e1e72003-08-08 00:24:31 +00003548 else
3549 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003550
3551 for (ri = rn->info; ri; ri = ri->next)
3552 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3553 && ri->sub_type == BGP_ROUTE_STATIC)
3554 break;
3555
3556 if (ri)
3557 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003558 if (attrhash_cmp (ri->attr, attr_new) &&
3559 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003560 {
3561 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003562 bgp_attr_unintern (&attr_new);
3563 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003564 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003565 return;
3566 }
3567 else
3568 {
3569 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003570 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003571
3572 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003573 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3574 bgp_info_restore(rn, ri);
3575 else
3576 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003577 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003578 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003579 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003580
3581 /* Process change. */
3582 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3583 bgp_process (bgp, rn, afi, safi);
3584 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003585 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003586 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003587 return;
3588 }
3589 }
3590
3591 /* Make new BGP info. */
3592 new = bgp_info_new ();
3593 new->type = ZEBRA_ROUTE_BGP;
3594 new->sub_type = BGP_ROUTE_STATIC;
3595 new->peer = bgp->peer_self;
3596 SET_FLAG (new->flags, BGP_INFO_VALID);
3597 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003598 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003599
3600 /* Aggregate address increment. */
3601 bgp_aggregate_increment (bgp, p, new, afi, safi);
3602
3603 /* Register new BGP information. */
3604 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003605
3606 /* route_node_get lock */
3607 bgp_unlock_node (rn);
3608
paul718e3742002-12-13 20:15:29 +00003609 /* Process change. */
3610 bgp_process (bgp, rn, afi, safi);
3611
3612 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003613 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003614 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003615}
3616
3617void
paulfee0f4c2004-09-13 05:12:46 +00003618bgp_static_update (struct bgp *bgp, struct prefix *p,
3619 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3620{
3621 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003622 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003623
3624 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3625
paul1eb8ef22005-04-07 07:30:20 +00003626 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003627 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003628 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3629 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003630 }
3631}
3632
paul94f2b392005-06-28 12:44:16 +00003633static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003634bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3635 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003636{
3637 struct bgp_node *rn;
3638 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003639
paulfee0f4c2004-09-13 05:12:46 +00003640 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003641
3642 /* Make new BGP info. */
3643 new = bgp_info_new ();
3644 new->type = ZEBRA_ROUTE_BGP;
3645 new->sub_type = BGP_ROUTE_STATIC;
3646 new->peer = bgp->peer_self;
3647 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3648 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003649 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003650 new->extra = bgp_info_extra_new();
3651 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003652
3653 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003654 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003655
3656 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003657 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003658
paul200df112005-06-01 11:17:05 +00003659 /* route_node_get lock */
3660 bgp_unlock_node (rn);
3661
paul718e3742002-12-13 20:15:29 +00003662 /* Process change. */
3663 bgp_process (bgp, rn, afi, safi);
3664}
3665
3666void
3667bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3668 safi_t safi)
3669{
3670 struct bgp_node *rn;
3671 struct bgp_info *ri;
3672
paulfee0f4c2004-09-13 05:12:46 +00003673 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003674
3675 /* Check selected route and self inserted route. */
3676 for (ri = rn->info; ri; ri = ri->next)
3677 if (ri->peer == bgp->peer_self
3678 && ri->type == ZEBRA_ROUTE_BGP
3679 && ri->sub_type == BGP_ROUTE_STATIC)
3680 break;
3681
3682 /* Withdraw static BGP route from routing table. */
3683 if (ri)
3684 {
3685 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003686 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003687 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003688 }
3689
3690 /* Unlock bgp_node_lookup. */
3691 bgp_unlock_node (rn);
3692}
3693
3694void
paulfee0f4c2004-09-13 05:12:46 +00003695bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3696{
3697 struct bgp_static *bgp_static;
3698 struct bgp *bgp;
3699 struct bgp_node *rn;
3700 struct prefix *p;
3701
3702 bgp = rsclient->bgp;
3703
3704 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3705 if ((bgp_static = rn->info) != NULL)
3706 {
3707 p = &rn->p;
3708
3709 bgp_static_update_rsclient (rsclient, p, bgp_static,
3710 afi, safi);
3711 }
3712}
3713
paul94f2b392005-06-28 12:44:16 +00003714static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003715bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3716 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003717{
3718 struct bgp_node *rn;
3719 struct bgp_info *ri;
3720
paulfee0f4c2004-09-13 05:12:46 +00003721 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003722
3723 /* Check selected route and self inserted route. */
3724 for (ri = rn->info; ri; ri = ri->next)
3725 if (ri->peer == bgp->peer_self
3726 && ri->type == ZEBRA_ROUTE_BGP
3727 && ri->sub_type == BGP_ROUTE_STATIC)
3728 break;
3729
3730 /* Withdraw static BGP route from routing table. */
3731 if (ri)
3732 {
3733 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003734 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003735 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003736 }
3737
3738 /* Unlock bgp_node_lookup. */
3739 bgp_unlock_node (rn);
3740}
3741
3742/* Configure static BGP network. When user don't run zebra, static
3743 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003744static int
paulfd79ac92004-10-13 05:06:08 +00003745bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003746 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003747{
3748 int ret;
3749 struct prefix p;
3750 struct bgp_static *bgp_static;
3751 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003752 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003753
3754 /* Convert IP prefix string to struct prefix. */
3755 ret = str2prefix (ip_str, &p);
3756 if (! ret)
3757 {
3758 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3759 return CMD_WARNING;
3760 }
3761#ifdef HAVE_IPV6
3762 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3763 {
3764 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3765 VTY_NEWLINE);
3766 return CMD_WARNING;
3767 }
3768#endif /* HAVE_IPV6 */
3769
3770 apply_mask (&p);
3771
3772 /* Set BGP static route configuration. */
3773 rn = bgp_node_get (bgp->route[afi][safi], &p);
3774
3775 if (rn->info)
3776 {
3777 /* Configuration change. */
3778 bgp_static = rn->info;
3779
3780 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003781 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3782 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003783
paul718e3742002-12-13 20:15:29 +00003784 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003785
paul718e3742002-12-13 20:15:29 +00003786 if (rmap)
3787 {
3788 if (bgp_static->rmap.name)
3789 free (bgp_static->rmap.name);
3790 bgp_static->rmap.name = strdup (rmap);
3791 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3792 }
3793 else
3794 {
3795 if (bgp_static->rmap.name)
3796 free (bgp_static->rmap.name);
3797 bgp_static->rmap.name = NULL;
3798 bgp_static->rmap.map = NULL;
3799 bgp_static->valid = 0;
3800 }
3801 bgp_unlock_node (rn);
3802 }
3803 else
3804 {
3805 /* New configuration. */
3806 bgp_static = bgp_static_new ();
3807 bgp_static->backdoor = backdoor;
3808 bgp_static->valid = 0;
3809 bgp_static->igpmetric = 0;
3810 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003811
paul718e3742002-12-13 20:15:29 +00003812 if (rmap)
3813 {
3814 if (bgp_static->rmap.name)
3815 free (bgp_static->rmap.name);
3816 bgp_static->rmap.name = strdup (rmap);
3817 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3818 }
3819 rn->info = bgp_static;
3820 }
3821
3822 /* If BGP scan is not enabled, we should install this route here. */
3823 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3824 {
3825 bgp_static->valid = 1;
3826
3827 if (need_update)
3828 bgp_static_withdraw (bgp, &p, afi, safi);
3829
3830 if (! bgp_static->backdoor)
3831 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3832 }
3833
3834 return CMD_SUCCESS;
3835}
3836
3837/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003838static int
paulfd79ac92004-10-13 05:06:08 +00003839bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003840 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003841{
3842 int ret;
3843 struct prefix p;
3844 struct bgp_static *bgp_static;
3845 struct bgp_node *rn;
3846
3847 /* Convert IP prefix string to struct prefix. */
3848 ret = str2prefix (ip_str, &p);
3849 if (! ret)
3850 {
3851 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3852 return CMD_WARNING;
3853 }
3854#ifdef HAVE_IPV6
3855 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3856 {
3857 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3858 VTY_NEWLINE);
3859 return CMD_WARNING;
3860 }
3861#endif /* HAVE_IPV6 */
3862
3863 apply_mask (&p);
3864
3865 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3866 if (! rn)
3867 {
3868 vty_out (vty, "%% Can't find specified static route configuration.%s",
3869 VTY_NEWLINE);
3870 return CMD_WARNING;
3871 }
3872
3873 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003874
paul718e3742002-12-13 20:15:29 +00003875 /* Update BGP RIB. */
3876 if (! bgp_static->backdoor)
3877 bgp_static_withdraw (bgp, &p, afi, safi);
3878
3879 /* Clear configuration. */
3880 bgp_static_free (bgp_static);
3881 rn->info = NULL;
3882 bgp_unlock_node (rn);
3883 bgp_unlock_node (rn);
3884
3885 return CMD_SUCCESS;
3886}
3887
3888/* Called from bgp_delete(). Delete all static routes from the BGP
3889 instance. */
3890void
3891bgp_static_delete (struct bgp *bgp)
3892{
3893 afi_t afi;
3894 safi_t safi;
3895 struct bgp_node *rn;
3896 struct bgp_node *rm;
3897 struct bgp_table *table;
3898 struct bgp_static *bgp_static;
3899
3900 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3901 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3902 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3903 if (rn->info != NULL)
3904 {
3905 if (safi == SAFI_MPLS_VPN)
3906 {
3907 table = rn->info;
3908
3909 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3910 {
3911 bgp_static = rn->info;
3912 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3913 AFI_IP, SAFI_MPLS_VPN,
3914 (struct prefix_rd *)&rn->p,
3915 bgp_static->tag);
3916 bgp_static_free (bgp_static);
3917 rn->info = NULL;
3918 bgp_unlock_node (rn);
3919 }
3920 }
3921 else
3922 {
3923 bgp_static = rn->info;
3924 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3925 bgp_static_free (bgp_static);
3926 rn->info = NULL;
3927 bgp_unlock_node (rn);
3928 }
3929 }
3930}
3931
3932int
paulfd79ac92004-10-13 05:06:08 +00003933bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3934 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003935{
3936 int ret;
3937 struct prefix p;
3938 struct prefix_rd prd;
3939 struct bgp *bgp;
3940 struct bgp_node *prn;
3941 struct bgp_node *rn;
3942 struct bgp_table *table;
3943 struct bgp_static *bgp_static;
3944 u_char tag[3];
3945
3946 bgp = vty->index;
3947
3948 ret = str2prefix (ip_str, &p);
3949 if (! ret)
3950 {
3951 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3952 return CMD_WARNING;
3953 }
3954 apply_mask (&p);
3955
3956 ret = str2prefix_rd (rd_str, &prd);
3957 if (! ret)
3958 {
3959 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3960 return CMD_WARNING;
3961 }
3962
3963 ret = str2tag (tag_str, tag);
3964 if (! ret)
3965 {
3966 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3967 return CMD_WARNING;
3968 }
3969
3970 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3971 (struct prefix *)&prd);
3972 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003973 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003974 else
3975 bgp_unlock_node (prn);
3976 table = prn->info;
3977
3978 rn = bgp_node_get (table, &p);
3979
3980 if (rn->info)
3981 {
3982 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3983 bgp_unlock_node (rn);
3984 }
3985 else
3986 {
3987 /* New configuration. */
3988 bgp_static = bgp_static_new ();
3989 bgp_static->valid = 1;
3990 memcpy (bgp_static->tag, tag, 3);
3991 rn->info = bgp_static;
3992
3993 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3994 }
3995
3996 return CMD_SUCCESS;
3997}
3998
3999/* Configure static BGP network. */
4000int
paulfd79ac92004-10-13 05:06:08 +00004001bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
4002 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004003{
4004 int ret;
4005 struct bgp *bgp;
4006 struct prefix p;
4007 struct prefix_rd prd;
4008 struct bgp_node *prn;
4009 struct bgp_node *rn;
4010 struct bgp_table *table;
4011 struct bgp_static *bgp_static;
4012 u_char tag[3];
4013
4014 bgp = vty->index;
4015
4016 /* Convert IP prefix string to struct prefix. */
4017 ret = str2prefix (ip_str, &p);
4018 if (! ret)
4019 {
4020 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4021 return CMD_WARNING;
4022 }
4023 apply_mask (&p);
4024
4025 ret = str2prefix_rd (rd_str, &prd);
4026 if (! ret)
4027 {
4028 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4029 return CMD_WARNING;
4030 }
4031
4032 ret = str2tag (tag_str, tag);
4033 if (! ret)
4034 {
4035 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4036 return CMD_WARNING;
4037 }
4038
4039 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
4040 (struct prefix *)&prd);
4041 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00004042 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00004043 else
4044 bgp_unlock_node (prn);
4045 table = prn->info;
4046
4047 rn = bgp_node_lookup (table, &p);
4048
4049 if (rn)
4050 {
4051 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
4052
4053 bgp_static = rn->info;
4054 bgp_static_free (bgp_static);
4055 rn->info = NULL;
4056 bgp_unlock_node (rn);
4057 bgp_unlock_node (rn);
4058 }
4059 else
4060 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4061
4062 return CMD_SUCCESS;
4063}
David Lamparter6b0655a2014-06-04 06:53:35 +02004064
paul718e3742002-12-13 20:15:29 +00004065DEFUN (bgp_network,
4066 bgp_network_cmd,
4067 "network A.B.C.D/M",
4068 "Specify a network to announce via BGP\n"
4069 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4070{
4071 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004072 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004073}
4074
4075DEFUN (bgp_network_route_map,
4076 bgp_network_route_map_cmd,
4077 "network A.B.C.D/M route-map WORD",
4078 "Specify a network to announce via BGP\n"
4079 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4080 "Route-map to modify the attributes\n"
4081 "Name of the route map\n")
4082{
4083 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004084 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004085}
4086
4087DEFUN (bgp_network_backdoor,
4088 bgp_network_backdoor_cmd,
4089 "network A.B.C.D/M backdoor",
4090 "Specify a network to announce via BGP\n"
4091 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4092 "Specify a BGP backdoor route\n")
4093{
Paul Jakma41367172007-08-06 15:24:51 +00004094 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004095 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004096}
4097
4098DEFUN (bgp_network_mask,
4099 bgp_network_mask_cmd,
4100 "network A.B.C.D mask A.B.C.D",
4101 "Specify a network to announce via BGP\n"
4102 "Network number\n"
4103 "Network mask\n"
4104 "Network mask\n")
4105{
4106 int ret;
4107 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004108
paul718e3742002-12-13 20:15:29 +00004109 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4110 if (! ret)
4111 {
4112 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4113 return CMD_WARNING;
4114 }
4115
4116 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004117 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004118}
4119
4120DEFUN (bgp_network_mask_route_map,
4121 bgp_network_mask_route_map_cmd,
4122 "network A.B.C.D mask A.B.C.D route-map WORD",
4123 "Specify a network to announce via BGP\n"
4124 "Network number\n"
4125 "Network mask\n"
4126 "Network mask\n"
4127 "Route-map to modify the attributes\n"
4128 "Name of the route map\n")
4129{
4130 int ret;
4131 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004132
paul718e3742002-12-13 20:15:29 +00004133 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4134 if (! ret)
4135 {
4136 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4137 return CMD_WARNING;
4138 }
4139
4140 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004141 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004142}
4143
4144DEFUN (bgp_network_mask_backdoor,
4145 bgp_network_mask_backdoor_cmd,
4146 "network A.B.C.D mask A.B.C.D backdoor",
4147 "Specify a network to announce via BGP\n"
4148 "Network number\n"
4149 "Network mask\n"
4150 "Network mask\n"
4151 "Specify a BGP backdoor route\n")
4152{
4153 int ret;
4154 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004155
paul718e3742002-12-13 20:15:29 +00004156 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4157 if (! ret)
4158 {
4159 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4160 return CMD_WARNING;
4161 }
4162
Paul Jakma41367172007-08-06 15:24:51 +00004163 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004164 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004165}
4166
4167DEFUN (bgp_network_mask_natural,
4168 bgp_network_mask_natural_cmd,
4169 "network A.B.C.D",
4170 "Specify a network to announce via BGP\n"
4171 "Network number\n")
4172{
4173 int ret;
4174 char prefix_str[BUFSIZ];
4175
4176 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4177 if (! ret)
4178 {
4179 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4180 return CMD_WARNING;
4181 }
4182
4183 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004184 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004185}
4186
4187DEFUN (bgp_network_mask_natural_route_map,
4188 bgp_network_mask_natural_route_map_cmd,
4189 "network A.B.C.D route-map WORD",
4190 "Specify a network to announce via BGP\n"
4191 "Network number\n"
4192 "Route-map to modify the attributes\n"
4193 "Name of the route map\n")
4194{
4195 int ret;
4196 char prefix_str[BUFSIZ];
4197
4198 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4199 if (! ret)
4200 {
4201 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4202 return CMD_WARNING;
4203 }
4204
4205 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004206 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004207}
4208
4209DEFUN (bgp_network_mask_natural_backdoor,
4210 bgp_network_mask_natural_backdoor_cmd,
4211 "network A.B.C.D backdoor",
4212 "Specify a network to announce via BGP\n"
4213 "Network number\n"
4214 "Specify a BGP backdoor route\n")
4215{
4216 int ret;
4217 char prefix_str[BUFSIZ];
4218
4219 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4220 if (! ret)
4221 {
4222 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4223 return CMD_WARNING;
4224 }
4225
Paul Jakma41367172007-08-06 15:24:51 +00004226 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004227 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004228}
4229
4230DEFUN (no_bgp_network,
4231 no_bgp_network_cmd,
4232 "no network A.B.C.D/M",
4233 NO_STR
4234 "Specify a network to announce via BGP\n"
4235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4236{
4237 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4238 bgp_node_safi (vty));
4239}
4240
4241ALIAS (no_bgp_network,
4242 no_bgp_network_route_map_cmd,
4243 "no network A.B.C.D/M route-map WORD",
4244 NO_STR
4245 "Specify a network to announce via BGP\n"
4246 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4247 "Route-map to modify the attributes\n"
4248 "Name of the route map\n")
4249
4250ALIAS (no_bgp_network,
4251 no_bgp_network_backdoor_cmd,
4252 "no network A.B.C.D/M backdoor",
4253 NO_STR
4254 "Specify a network to announce via BGP\n"
4255 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4256 "Specify a BGP backdoor route\n")
4257
4258DEFUN (no_bgp_network_mask,
4259 no_bgp_network_mask_cmd,
4260 "no network A.B.C.D mask A.B.C.D",
4261 NO_STR
4262 "Specify a network to announce via BGP\n"
4263 "Network number\n"
4264 "Network mask\n"
4265 "Network mask\n")
4266{
4267 int ret;
4268 char prefix_str[BUFSIZ];
4269
4270 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4271 if (! ret)
4272 {
4273 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4274 return CMD_WARNING;
4275 }
4276
4277 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4278 bgp_node_safi (vty));
4279}
4280
4281ALIAS (no_bgp_network_mask,
4282 no_bgp_network_mask_route_map_cmd,
4283 "no network A.B.C.D mask A.B.C.D route-map WORD",
4284 NO_STR
4285 "Specify a network to announce via BGP\n"
4286 "Network number\n"
4287 "Network mask\n"
4288 "Network mask\n"
4289 "Route-map to modify the attributes\n"
4290 "Name of the route map\n")
4291
4292ALIAS (no_bgp_network_mask,
4293 no_bgp_network_mask_backdoor_cmd,
4294 "no network A.B.C.D mask A.B.C.D backdoor",
4295 NO_STR
4296 "Specify a network to announce via BGP\n"
4297 "Network number\n"
4298 "Network mask\n"
4299 "Network mask\n"
4300 "Specify a BGP backdoor route\n")
4301
4302DEFUN (no_bgp_network_mask_natural,
4303 no_bgp_network_mask_natural_cmd,
4304 "no network A.B.C.D",
4305 NO_STR
4306 "Specify a network to announce via BGP\n"
4307 "Network number\n")
4308{
4309 int ret;
4310 char prefix_str[BUFSIZ];
4311
4312 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4313 if (! ret)
4314 {
4315 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4316 return CMD_WARNING;
4317 }
4318
4319 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4320 bgp_node_safi (vty));
4321}
4322
4323ALIAS (no_bgp_network_mask_natural,
4324 no_bgp_network_mask_natural_route_map_cmd,
4325 "no network A.B.C.D route-map WORD",
4326 NO_STR
4327 "Specify a network to announce via BGP\n"
4328 "Network number\n"
4329 "Route-map to modify the attributes\n"
4330 "Name of the route map\n")
4331
4332ALIAS (no_bgp_network_mask_natural,
4333 no_bgp_network_mask_natural_backdoor_cmd,
4334 "no network A.B.C.D backdoor",
4335 NO_STR
4336 "Specify a network to announce via BGP\n"
4337 "Network number\n"
4338 "Specify a BGP backdoor route\n")
4339
4340#ifdef HAVE_IPV6
4341DEFUN (ipv6_bgp_network,
4342 ipv6_bgp_network_cmd,
4343 "network X:X::X:X/M",
4344 "Specify a network to announce via BGP\n"
4345 "IPv6 prefix <network>/<length>\n")
4346{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304347 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004348 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004349}
4350
4351DEFUN (ipv6_bgp_network_route_map,
4352 ipv6_bgp_network_route_map_cmd,
4353 "network X:X::X:X/M route-map WORD",
4354 "Specify a network to announce via BGP\n"
4355 "IPv6 prefix <network>/<length>\n"
4356 "Route-map to modify the attributes\n"
4357 "Name of the route map\n")
4358{
4359 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004360 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004361}
4362
4363DEFUN (no_ipv6_bgp_network,
4364 no_ipv6_bgp_network_cmd,
4365 "no network X:X::X:X/M",
4366 NO_STR
4367 "Specify a network to announce via BGP\n"
4368 "IPv6 prefix <network>/<length>\n")
4369{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304370 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004371}
4372
4373ALIAS (no_ipv6_bgp_network,
4374 no_ipv6_bgp_network_route_map_cmd,
4375 "no network X:X::X:X/M route-map WORD",
4376 NO_STR
4377 "Specify a network to announce via BGP\n"
4378 "IPv6 prefix <network>/<length>\n"
4379 "Route-map to modify the attributes\n"
4380 "Name of the route map\n")
4381
4382ALIAS (ipv6_bgp_network,
4383 old_ipv6_bgp_network_cmd,
4384 "ipv6 bgp network X:X::X:X/M",
4385 IPV6_STR
4386 BGP_STR
4387 "Specify a network to announce via BGP\n"
4388 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4389
4390ALIAS (no_ipv6_bgp_network,
4391 old_no_ipv6_bgp_network_cmd,
4392 "no ipv6 bgp network X:X::X:X/M",
4393 NO_STR
4394 IPV6_STR
4395 BGP_STR
4396 "Specify a network to announce via BGP\n"
4397 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4398#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004399
4400/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4401ALIAS_DEPRECATED (bgp_network,
4402 bgp_network_ttl_cmd,
4403 "network A.B.C.D/M pathlimit <0-255>",
4404 "Specify a network to announce via BGP\n"
4405 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4406 "AS-Path hopcount limit attribute\n"
4407 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4408ALIAS_DEPRECATED (bgp_network_backdoor,
4409 bgp_network_backdoor_ttl_cmd,
4410 "network A.B.C.D/M backdoor pathlimit <0-255>",
4411 "Specify a network to announce via BGP\n"
4412 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4413 "Specify a BGP backdoor route\n"
4414 "AS-Path hopcount limit attribute\n"
4415 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4416ALIAS_DEPRECATED (bgp_network_mask,
4417 bgp_network_mask_ttl_cmd,
4418 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4419 "Specify a network to announce via BGP\n"
4420 "Network number\n"
4421 "Network mask\n"
4422 "Network mask\n"
4423 "AS-Path hopcount limit attribute\n"
4424 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4425ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4426 bgp_network_mask_backdoor_ttl_cmd,
4427 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4428 "Specify a network to announce via BGP\n"
4429 "Network number\n"
4430 "Network mask\n"
4431 "Network mask\n"
4432 "Specify a BGP backdoor route\n"
4433 "AS-Path hopcount limit attribute\n"
4434 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4435ALIAS_DEPRECATED (bgp_network_mask_natural,
4436 bgp_network_mask_natural_ttl_cmd,
4437 "network A.B.C.D pathlimit <0-255>",
4438 "Specify a network to announce via BGP\n"
4439 "Network number\n"
4440 "AS-Path hopcount limit attribute\n"
4441 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4442ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4443 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004444 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004445 "Specify a network to announce via BGP\n"
4446 "Network number\n"
4447 "Specify a BGP backdoor route\n"
4448 "AS-Path hopcount limit attribute\n"
4449 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4450ALIAS_DEPRECATED (no_bgp_network,
4451 no_bgp_network_ttl_cmd,
4452 "no network A.B.C.D/M pathlimit <0-255>",
4453 NO_STR
4454 "Specify a network to announce via BGP\n"
4455 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4456 "AS-Path hopcount limit attribute\n"
4457 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4458ALIAS_DEPRECATED (no_bgp_network,
4459 no_bgp_network_backdoor_ttl_cmd,
4460 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4461 NO_STR
4462 "Specify a network to announce via BGP\n"
4463 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4464 "Specify a BGP backdoor route\n"
4465 "AS-Path hopcount limit attribute\n"
4466 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4467ALIAS_DEPRECATED (no_bgp_network,
4468 no_bgp_network_mask_ttl_cmd,
4469 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4470 NO_STR
4471 "Specify a network to announce via BGP\n"
4472 "Network number\n"
4473 "Network mask\n"
4474 "Network mask\n"
4475 "AS-Path hopcount limit attribute\n"
4476 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4477ALIAS_DEPRECATED (no_bgp_network_mask,
4478 no_bgp_network_mask_backdoor_ttl_cmd,
4479 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4480 NO_STR
4481 "Specify a network to announce via BGP\n"
4482 "Network number\n"
4483 "Network mask\n"
4484 "Network mask\n"
4485 "Specify a BGP backdoor route\n"
4486 "AS-Path hopcount limit attribute\n"
4487 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4488ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4489 no_bgp_network_mask_natural_ttl_cmd,
4490 "no network A.B.C.D pathlimit <0-255>",
4491 NO_STR
4492 "Specify a network to announce via BGP\n"
4493 "Network number\n"
4494 "AS-Path hopcount limit attribute\n"
4495 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4496ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4497 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4498 "no network A.B.C.D backdoor pathlimit <0-255>",
4499 NO_STR
4500 "Specify a network to announce via BGP\n"
4501 "Network number\n"
4502 "Specify a BGP backdoor route\n"
4503 "AS-Path hopcount limit attribute\n"
4504 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004505#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004506ALIAS_DEPRECATED (ipv6_bgp_network,
4507 ipv6_bgp_network_ttl_cmd,
4508 "network X:X::X:X/M pathlimit <0-255>",
4509 "Specify a network to announce via BGP\n"
4510 "IPv6 prefix <network>/<length>\n"
4511 "AS-Path hopcount limit attribute\n"
4512 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4513ALIAS_DEPRECATED (no_ipv6_bgp_network,
4514 no_ipv6_bgp_network_ttl_cmd,
4515 "no network X:X::X:X/M pathlimit <0-255>",
4516 NO_STR
4517 "Specify a network to announce via BGP\n"
4518 "IPv6 prefix <network>/<length>\n"
4519 "AS-Path hopcount limit attribute\n"
4520 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004521#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004522
paul718e3742002-12-13 20:15:29 +00004523/* Aggreagete address:
4524
4525 advertise-map Set condition to advertise attribute
4526 as-set Generate AS set path information
4527 attribute-map Set attributes of aggregate
4528 route-map Set parameters of aggregate
4529 summary-only Filter more specific routes from updates
4530 suppress-map Conditionally filter more specific routes from updates
4531 <cr>
4532 */
4533struct bgp_aggregate
4534{
4535 /* Summary-only flag. */
4536 u_char summary_only;
4537
4538 /* AS set generation. */
4539 u_char as_set;
4540
4541 /* Route-map for aggregated route. */
4542 struct route_map *map;
4543
4544 /* Suppress-count. */
4545 unsigned long count;
4546
4547 /* SAFI configuration. */
4548 safi_t safi;
4549};
4550
paul94f2b392005-06-28 12:44:16 +00004551static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004552bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004553{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004554 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004555}
4556
paul94f2b392005-06-28 12:44:16 +00004557static void
paul718e3742002-12-13 20:15:29 +00004558bgp_aggregate_free (struct bgp_aggregate *aggregate)
4559{
4560 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4561}
4562
paul94f2b392005-06-28 12:44:16 +00004563static void
paul718e3742002-12-13 20:15:29 +00004564bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4565 afi_t afi, safi_t safi, struct bgp_info *del,
4566 struct bgp_aggregate *aggregate)
4567{
4568 struct bgp_table *table;
4569 struct bgp_node *top;
4570 struct bgp_node *rn;
4571 u_char origin;
4572 struct aspath *aspath = NULL;
4573 struct aspath *asmerge = NULL;
4574 struct community *community = NULL;
4575 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004576 struct bgp_info *ri;
4577 struct bgp_info *new;
4578 int first = 1;
4579 unsigned long match = 0;
4580
paul718e3742002-12-13 20:15:29 +00004581 /* ORIGIN attribute: If at least one route among routes that are
4582 aggregated has ORIGIN with the value INCOMPLETE, then the
4583 aggregated route must have the ORIGIN attribute with the value
4584 INCOMPLETE. Otherwise, if at least one route among routes that
4585 are aggregated has ORIGIN with the value EGP, then the aggregated
4586 route must have the origin attribute with the value EGP. In all
4587 other case the value of the ORIGIN attribute of the aggregated
4588 route is INTERNAL. */
4589 origin = BGP_ORIGIN_IGP;
4590
4591 table = bgp->rib[afi][safi];
4592
4593 top = bgp_node_get (table, p);
4594 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4595 if (rn->p.prefixlen > p->prefixlen)
4596 {
4597 match = 0;
4598
4599 for (ri = rn->info; ri; ri = ri->next)
4600 {
4601 if (BGP_INFO_HOLDDOWN (ri))
4602 continue;
4603
4604 if (del && ri == del)
4605 continue;
4606
4607 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004608 first = 0;
paul718e3742002-12-13 20:15:29 +00004609
4610#ifdef AGGREGATE_NEXTHOP_CHECK
4611 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4612 || ri->attr->med != med)
4613 {
4614 if (aspath)
4615 aspath_free (aspath);
4616 if (community)
4617 community_free (community);
4618 bgp_unlock_node (rn);
4619 bgp_unlock_node (top);
4620 return;
4621 }
4622#endif /* AGGREGATE_NEXTHOP_CHECK */
4623
4624 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4625 {
4626 if (aggregate->summary_only)
4627 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004628 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004629 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004630 match++;
4631 }
4632
4633 aggregate->count++;
4634
4635 if (aggregate->as_set)
4636 {
4637 if (origin < ri->attr->origin)
4638 origin = ri->attr->origin;
4639
4640 if (aspath)
4641 {
4642 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4643 aspath_free (aspath);
4644 aspath = asmerge;
4645 }
4646 else
4647 aspath = aspath_dup (ri->attr->aspath);
4648
4649 if (ri->attr->community)
4650 {
4651 if (community)
4652 {
4653 commerge = community_merge (community,
4654 ri->attr->community);
4655 community = community_uniq_sort (commerge);
4656 community_free (commerge);
4657 }
4658 else
4659 community = community_dup (ri->attr->community);
4660 }
4661 }
4662 }
4663 }
4664 if (match)
4665 bgp_process (bgp, rn, afi, safi);
4666 }
4667 bgp_unlock_node (top);
4668
4669 if (rinew)
4670 {
4671 aggregate->count++;
4672
4673 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004674 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004675
4676 if (aggregate->as_set)
4677 {
4678 if (origin < rinew->attr->origin)
4679 origin = rinew->attr->origin;
4680
4681 if (aspath)
4682 {
4683 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4684 aspath_free (aspath);
4685 aspath = asmerge;
4686 }
4687 else
4688 aspath = aspath_dup (rinew->attr->aspath);
4689
4690 if (rinew->attr->community)
4691 {
4692 if (community)
4693 {
4694 commerge = community_merge (community,
4695 rinew->attr->community);
4696 community = community_uniq_sort (commerge);
4697 community_free (commerge);
4698 }
4699 else
4700 community = community_dup (rinew->attr->community);
4701 }
4702 }
4703 }
4704
4705 if (aggregate->count > 0)
4706 {
4707 rn = bgp_node_get (table, p);
4708 new = bgp_info_new ();
4709 new->type = ZEBRA_ROUTE_BGP;
4710 new->sub_type = BGP_ROUTE_AGGREGATE;
4711 new->peer = bgp->peer_self;
4712 SET_FLAG (new->flags, BGP_INFO_VALID);
4713 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004714 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004715
4716 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004717 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004718 bgp_process (bgp, rn, afi, safi);
4719 }
4720 else
4721 {
4722 if (aspath)
4723 aspath_free (aspath);
4724 if (community)
4725 community_free (community);
4726 }
4727}
4728
4729void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4730 struct bgp_aggregate *);
4731
4732void
4733bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4734 struct bgp_info *ri, afi_t afi, safi_t safi)
4735{
4736 struct bgp_node *child;
4737 struct bgp_node *rn;
4738 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004739 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004740
4741 /* MPLS-VPN aggregation is not yet supported. */
4742 if (safi == SAFI_MPLS_VPN)
4743 return;
4744
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004745 table = bgp->aggregate[afi][safi];
4746
4747 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004748 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004749 return;
4750
paul718e3742002-12-13 20:15:29 +00004751 if (p->prefixlen == 0)
4752 return;
4753
4754 if (BGP_INFO_HOLDDOWN (ri))
4755 return;
4756
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004757 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004758
4759 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004760 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004761 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4762 {
4763 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004764 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004765 }
4766 bgp_unlock_node (child);
4767}
4768
4769void
4770bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4771 struct bgp_info *del, afi_t afi, safi_t safi)
4772{
4773 struct bgp_node *child;
4774 struct bgp_node *rn;
4775 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004776 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004777
4778 /* MPLS-VPN aggregation is not yet supported. */
4779 if (safi == SAFI_MPLS_VPN)
4780 return;
4781
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004782 table = bgp->aggregate[afi][safi];
4783
4784 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004785 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004786 return;
4787
paul718e3742002-12-13 20:15:29 +00004788 if (p->prefixlen == 0)
4789 return;
4790
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004791 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004792
4793 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004794 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004795 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4796 {
4797 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004798 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004799 }
4800 bgp_unlock_node (child);
4801}
4802
paul94f2b392005-06-28 12:44:16 +00004803static void
paul718e3742002-12-13 20:15:29 +00004804bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4805 struct bgp_aggregate *aggregate)
4806{
4807 struct bgp_table *table;
4808 struct bgp_node *top;
4809 struct bgp_node *rn;
4810 struct bgp_info *new;
4811 struct bgp_info *ri;
4812 unsigned long match;
4813 u_char origin = BGP_ORIGIN_IGP;
4814 struct aspath *aspath = NULL;
4815 struct aspath *asmerge = NULL;
4816 struct community *community = NULL;
4817 struct community *commerge = NULL;
4818
4819 table = bgp->rib[afi][safi];
4820
4821 /* Sanity check. */
4822 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4823 return;
4824 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4825 return;
4826
4827 /* If routes exists below this node, generate aggregate routes. */
4828 top = bgp_node_get (table, p);
4829 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4830 if (rn->p.prefixlen > p->prefixlen)
4831 {
4832 match = 0;
4833
4834 for (ri = rn->info; ri; ri = ri->next)
4835 {
4836 if (BGP_INFO_HOLDDOWN (ri))
4837 continue;
4838
4839 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4840 {
4841 /* summary-only aggregate route suppress aggregated
4842 route announcement. */
4843 if (aggregate->summary_only)
4844 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004845 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004846 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004847 match++;
4848 }
4849 /* as-set aggregate route generate origin, as path,
4850 community aggregation. */
4851 if (aggregate->as_set)
4852 {
4853 if (origin < ri->attr->origin)
4854 origin = ri->attr->origin;
4855
4856 if (aspath)
4857 {
4858 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4859 aspath_free (aspath);
4860 aspath = asmerge;
4861 }
4862 else
4863 aspath = aspath_dup (ri->attr->aspath);
4864
4865 if (ri->attr->community)
4866 {
4867 if (community)
4868 {
4869 commerge = community_merge (community,
4870 ri->attr->community);
4871 community = community_uniq_sort (commerge);
4872 community_free (commerge);
4873 }
4874 else
4875 community = community_dup (ri->attr->community);
4876 }
4877 }
4878 aggregate->count++;
4879 }
4880 }
4881
4882 /* If this node is suppressed, process the change. */
4883 if (match)
4884 bgp_process (bgp, rn, afi, safi);
4885 }
4886 bgp_unlock_node (top);
4887
4888 /* Add aggregate route to BGP table. */
4889 if (aggregate->count)
4890 {
4891 rn = bgp_node_get (table, p);
4892
4893 new = bgp_info_new ();
4894 new->type = ZEBRA_ROUTE_BGP;
4895 new->sub_type = BGP_ROUTE_AGGREGATE;
4896 new->peer = bgp->peer_self;
4897 SET_FLAG (new->flags, BGP_INFO_VALID);
4898 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004899 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004900
4901 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004902 bgp_unlock_node (rn);
4903
paul718e3742002-12-13 20:15:29 +00004904 /* Process change. */
4905 bgp_process (bgp, rn, afi, safi);
4906 }
Denil Virae2a92582015-08-11 13:34:59 -07004907 else
4908 {
4909 if (aspath)
4910 aspath_free (aspath);
4911 if (community)
4912 community_free (community);
4913 }
paul718e3742002-12-13 20:15:29 +00004914}
4915
4916void
4917bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4918 safi_t safi, struct bgp_aggregate *aggregate)
4919{
4920 struct bgp_table *table;
4921 struct bgp_node *top;
4922 struct bgp_node *rn;
4923 struct bgp_info *ri;
4924 unsigned long match;
4925
4926 table = bgp->rib[afi][safi];
4927
4928 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4929 return;
4930 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4931 return;
4932
4933 /* If routes exists below this node, generate aggregate routes. */
4934 top = bgp_node_get (table, p);
4935 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4936 if (rn->p.prefixlen > p->prefixlen)
4937 {
4938 match = 0;
4939
4940 for (ri = rn->info; ri; ri = ri->next)
4941 {
4942 if (BGP_INFO_HOLDDOWN (ri))
4943 continue;
4944
4945 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4946 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004947 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004948 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004949 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004950
Paul Jakmafb982c22007-05-04 20:15:47 +00004951 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004952 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004953 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004954 match++;
4955 }
4956 }
4957 aggregate->count--;
4958 }
4959 }
4960
Paul Jakmafb982c22007-05-04 20:15:47 +00004961 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004962 if (match)
4963 bgp_process (bgp, rn, afi, safi);
4964 }
4965 bgp_unlock_node (top);
4966
4967 /* Delete aggregate route from BGP table. */
4968 rn = bgp_node_get (table, p);
4969
4970 for (ri = rn->info; ri; ri = ri->next)
4971 if (ri->peer == bgp->peer_self
4972 && ri->type == ZEBRA_ROUTE_BGP
4973 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4974 break;
4975
4976 /* Withdraw static BGP route from routing table. */
4977 if (ri)
4978 {
paul718e3742002-12-13 20:15:29 +00004979 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004980 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004981 }
4982
4983 /* Unlock bgp_node_lookup. */
4984 bgp_unlock_node (rn);
4985}
4986
4987/* Aggregate route attribute. */
4988#define AGGREGATE_SUMMARY_ONLY 1
4989#define AGGREGATE_AS_SET 1
4990
paul94f2b392005-06-28 12:44:16 +00004991static int
Robert Baysf6269b42010-08-05 10:26:28 -07004992bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4993 afi_t afi, safi_t safi)
4994{
4995 int ret;
4996 struct prefix p;
4997 struct bgp_node *rn;
4998 struct bgp *bgp;
4999 struct bgp_aggregate *aggregate;
5000
5001 /* Convert string to prefix structure. */
5002 ret = str2prefix (prefix_str, &p);
5003 if (!ret)
5004 {
5005 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5006 return CMD_WARNING;
5007 }
5008 apply_mask (&p);
5009
5010 /* Get BGP structure. */
5011 bgp = vty->index;
5012
5013 /* Old configuration check. */
5014 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5015 if (! rn)
5016 {
5017 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5018 VTY_NEWLINE);
5019 return CMD_WARNING;
5020 }
5021
5022 aggregate = rn->info;
5023 if (aggregate->safi & SAFI_UNICAST)
5024 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5025 if (aggregate->safi & SAFI_MULTICAST)
5026 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5027
5028 /* Unlock aggregate address configuration. */
5029 rn->info = NULL;
5030 bgp_aggregate_free (aggregate);
5031 bgp_unlock_node (rn);
5032 bgp_unlock_node (rn);
5033
5034 return CMD_SUCCESS;
5035}
5036
5037static int
5038bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005039 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005040 u_char summary_only, u_char as_set)
5041{
5042 int ret;
5043 struct prefix p;
5044 struct bgp_node *rn;
5045 struct bgp *bgp;
5046 struct bgp_aggregate *aggregate;
5047
5048 /* Convert string to prefix structure. */
5049 ret = str2prefix (prefix_str, &p);
5050 if (!ret)
5051 {
5052 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5053 return CMD_WARNING;
5054 }
5055 apply_mask (&p);
5056
5057 /* Get BGP structure. */
5058 bgp = vty->index;
5059
5060 /* Old configuration check. */
5061 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5062
5063 if (rn->info)
5064 {
5065 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005066 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005067 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5068 if (ret)
5069 {
Robert Bays368473f2010-08-05 10:26:29 -07005070 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5071 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005072 return CMD_WARNING;
5073 }
paul718e3742002-12-13 20:15:29 +00005074 }
5075
5076 /* Make aggregate address structure. */
5077 aggregate = bgp_aggregate_new ();
5078 aggregate->summary_only = summary_only;
5079 aggregate->as_set = as_set;
5080 aggregate->safi = safi;
5081 rn->info = aggregate;
5082
5083 /* Aggregate address insert into BGP routing table. */
5084 if (safi & SAFI_UNICAST)
5085 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5086 if (safi & SAFI_MULTICAST)
5087 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5088
5089 return CMD_SUCCESS;
5090}
5091
paul718e3742002-12-13 20:15:29 +00005092DEFUN (aggregate_address,
5093 aggregate_address_cmd,
5094 "aggregate-address A.B.C.D/M",
5095 "Configure BGP aggregate entries\n"
5096 "Aggregate prefix\n")
5097{
5098 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5099}
5100
5101DEFUN (aggregate_address_mask,
5102 aggregate_address_mask_cmd,
5103 "aggregate-address A.B.C.D A.B.C.D",
5104 "Configure BGP aggregate entries\n"
5105 "Aggregate address\n"
5106 "Aggregate mask\n")
5107{
5108 int ret;
5109 char prefix_str[BUFSIZ];
5110
5111 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5112
5113 if (! ret)
5114 {
5115 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5116 return CMD_WARNING;
5117 }
5118
5119 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5120 0, 0);
5121}
5122
5123DEFUN (aggregate_address_summary_only,
5124 aggregate_address_summary_only_cmd,
5125 "aggregate-address A.B.C.D/M summary-only",
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate prefix\n"
5128 "Filter more specific routes from updates\n")
5129{
5130 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5131 AGGREGATE_SUMMARY_ONLY, 0);
5132}
5133
5134DEFUN (aggregate_address_mask_summary_only,
5135 aggregate_address_mask_summary_only_cmd,
5136 "aggregate-address A.B.C.D A.B.C.D summary-only",
5137 "Configure BGP aggregate entries\n"
5138 "Aggregate address\n"
5139 "Aggregate mask\n"
5140 "Filter more specific routes from updates\n")
5141{
5142 int ret;
5143 char prefix_str[BUFSIZ];
5144
5145 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5146
5147 if (! ret)
5148 {
5149 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5150 return CMD_WARNING;
5151 }
5152
5153 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5154 AGGREGATE_SUMMARY_ONLY, 0);
5155}
5156
5157DEFUN (aggregate_address_as_set,
5158 aggregate_address_as_set_cmd,
5159 "aggregate-address A.B.C.D/M as-set",
5160 "Configure BGP aggregate entries\n"
5161 "Aggregate prefix\n"
5162 "Generate AS set path information\n")
5163{
5164 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5165 0, AGGREGATE_AS_SET);
5166}
5167
5168DEFUN (aggregate_address_mask_as_set,
5169 aggregate_address_mask_as_set_cmd,
5170 "aggregate-address A.B.C.D A.B.C.D as-set",
5171 "Configure BGP aggregate entries\n"
5172 "Aggregate address\n"
5173 "Aggregate mask\n"
5174 "Generate AS set path information\n")
5175{
5176 int ret;
5177 char prefix_str[BUFSIZ];
5178
5179 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5180
5181 if (! ret)
5182 {
5183 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5184 return CMD_WARNING;
5185 }
5186
5187 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5188 0, AGGREGATE_AS_SET);
5189}
5190
5191
5192DEFUN (aggregate_address_as_set_summary,
5193 aggregate_address_as_set_summary_cmd,
5194 "aggregate-address A.B.C.D/M as-set summary-only",
5195 "Configure BGP aggregate entries\n"
5196 "Aggregate prefix\n"
5197 "Generate AS set path information\n"
5198 "Filter more specific routes from updates\n")
5199{
5200 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5201 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5202}
5203
5204ALIAS (aggregate_address_as_set_summary,
5205 aggregate_address_summary_as_set_cmd,
5206 "aggregate-address A.B.C.D/M summary-only as-set",
5207 "Configure BGP aggregate entries\n"
5208 "Aggregate prefix\n"
5209 "Filter more specific routes from updates\n"
5210 "Generate AS set path information\n")
5211
5212DEFUN (aggregate_address_mask_as_set_summary,
5213 aggregate_address_mask_as_set_summary_cmd,
5214 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5215 "Configure BGP aggregate entries\n"
5216 "Aggregate address\n"
5217 "Aggregate mask\n"
5218 "Generate AS set path information\n"
5219 "Filter more specific routes from updates\n")
5220{
5221 int ret;
5222 char prefix_str[BUFSIZ];
5223
5224 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5225
5226 if (! ret)
5227 {
5228 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5229 return CMD_WARNING;
5230 }
5231
5232 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5233 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5234}
5235
5236ALIAS (aggregate_address_mask_as_set_summary,
5237 aggregate_address_mask_summary_as_set_cmd,
5238 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5239 "Configure BGP aggregate entries\n"
5240 "Aggregate address\n"
5241 "Aggregate mask\n"
5242 "Filter more specific routes from updates\n"
5243 "Generate AS set path information\n")
5244
5245DEFUN (no_aggregate_address,
5246 no_aggregate_address_cmd,
5247 "no aggregate-address A.B.C.D/M",
5248 NO_STR
5249 "Configure BGP aggregate entries\n"
5250 "Aggregate prefix\n")
5251{
5252 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5253}
5254
5255ALIAS (no_aggregate_address,
5256 no_aggregate_address_summary_only_cmd,
5257 "no aggregate-address A.B.C.D/M summary-only",
5258 NO_STR
5259 "Configure BGP aggregate entries\n"
5260 "Aggregate prefix\n"
5261 "Filter more specific routes from updates\n")
5262
5263ALIAS (no_aggregate_address,
5264 no_aggregate_address_as_set_cmd,
5265 "no aggregate-address A.B.C.D/M as-set",
5266 NO_STR
5267 "Configure BGP aggregate entries\n"
5268 "Aggregate prefix\n"
5269 "Generate AS set path information\n")
5270
5271ALIAS (no_aggregate_address,
5272 no_aggregate_address_as_set_summary_cmd,
5273 "no aggregate-address A.B.C.D/M as-set summary-only",
5274 NO_STR
5275 "Configure BGP aggregate entries\n"
5276 "Aggregate prefix\n"
5277 "Generate AS set path information\n"
5278 "Filter more specific routes from updates\n")
5279
5280ALIAS (no_aggregate_address,
5281 no_aggregate_address_summary_as_set_cmd,
5282 "no aggregate-address A.B.C.D/M summary-only as-set",
5283 NO_STR
5284 "Configure BGP aggregate entries\n"
5285 "Aggregate prefix\n"
5286 "Filter more specific routes from updates\n"
5287 "Generate AS set path information\n")
5288
5289DEFUN (no_aggregate_address_mask,
5290 no_aggregate_address_mask_cmd,
5291 "no aggregate-address A.B.C.D A.B.C.D",
5292 NO_STR
5293 "Configure BGP aggregate entries\n"
5294 "Aggregate address\n"
5295 "Aggregate mask\n")
5296{
5297 int ret;
5298 char prefix_str[BUFSIZ];
5299
5300 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5301
5302 if (! ret)
5303 {
5304 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5305 return CMD_WARNING;
5306 }
5307
5308 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5309}
5310
5311ALIAS (no_aggregate_address_mask,
5312 no_aggregate_address_mask_summary_only_cmd,
5313 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5314 NO_STR
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate address\n"
5317 "Aggregate mask\n"
5318 "Filter more specific routes from updates\n")
5319
5320ALIAS (no_aggregate_address_mask,
5321 no_aggregate_address_mask_as_set_cmd,
5322 "no aggregate-address A.B.C.D A.B.C.D as-set",
5323 NO_STR
5324 "Configure BGP aggregate entries\n"
5325 "Aggregate address\n"
5326 "Aggregate mask\n"
5327 "Generate AS set path information\n")
5328
5329ALIAS (no_aggregate_address_mask,
5330 no_aggregate_address_mask_as_set_summary_cmd,
5331 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5332 NO_STR
5333 "Configure BGP aggregate entries\n"
5334 "Aggregate address\n"
5335 "Aggregate mask\n"
5336 "Generate AS set path information\n"
5337 "Filter more specific routes from updates\n")
5338
5339ALIAS (no_aggregate_address_mask,
5340 no_aggregate_address_mask_summary_as_set_cmd,
5341 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5342 NO_STR
5343 "Configure BGP aggregate entries\n"
5344 "Aggregate address\n"
5345 "Aggregate mask\n"
5346 "Filter more specific routes from updates\n"
5347 "Generate AS set path information\n")
5348
5349#ifdef HAVE_IPV6
5350DEFUN (ipv6_aggregate_address,
5351 ipv6_aggregate_address_cmd,
5352 "aggregate-address X:X::X:X/M",
5353 "Configure BGP aggregate entries\n"
5354 "Aggregate prefix\n")
5355{
5356 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5357}
5358
5359DEFUN (ipv6_aggregate_address_summary_only,
5360 ipv6_aggregate_address_summary_only_cmd,
5361 "aggregate-address X:X::X:X/M summary-only",
5362 "Configure BGP aggregate entries\n"
5363 "Aggregate prefix\n"
5364 "Filter more specific routes from updates\n")
5365{
5366 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5367 AGGREGATE_SUMMARY_ONLY, 0);
5368}
5369
5370DEFUN (no_ipv6_aggregate_address,
5371 no_ipv6_aggregate_address_cmd,
5372 "no aggregate-address X:X::X:X/M",
5373 NO_STR
5374 "Configure BGP aggregate entries\n"
5375 "Aggregate prefix\n")
5376{
5377 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5378}
5379
5380DEFUN (no_ipv6_aggregate_address_summary_only,
5381 no_ipv6_aggregate_address_summary_only_cmd,
5382 "no aggregate-address X:X::X:X/M summary-only",
5383 NO_STR
5384 "Configure BGP aggregate entries\n"
5385 "Aggregate prefix\n"
5386 "Filter more specific routes from updates\n")
5387{
5388 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5389}
5390
5391ALIAS (ipv6_aggregate_address,
5392 old_ipv6_aggregate_address_cmd,
5393 "ipv6 bgp aggregate-address X:X::X:X/M",
5394 IPV6_STR
5395 BGP_STR
5396 "Configure BGP aggregate entries\n"
5397 "Aggregate prefix\n")
5398
5399ALIAS (ipv6_aggregate_address_summary_only,
5400 old_ipv6_aggregate_address_summary_only_cmd,
5401 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5402 IPV6_STR
5403 BGP_STR
5404 "Configure BGP aggregate entries\n"
5405 "Aggregate prefix\n"
5406 "Filter more specific routes from updates\n")
5407
5408ALIAS (no_ipv6_aggregate_address,
5409 old_no_ipv6_aggregate_address_cmd,
5410 "no ipv6 bgp aggregate-address X:X::X:X/M",
5411 NO_STR
5412 IPV6_STR
5413 BGP_STR
5414 "Configure BGP aggregate entries\n"
5415 "Aggregate prefix\n")
5416
5417ALIAS (no_ipv6_aggregate_address_summary_only,
5418 old_no_ipv6_aggregate_address_summary_only_cmd,
5419 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5420 NO_STR
5421 IPV6_STR
5422 BGP_STR
5423 "Configure BGP aggregate entries\n"
5424 "Aggregate prefix\n"
5425 "Filter more specific routes from updates\n")
5426#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005427
paul718e3742002-12-13 20:15:29 +00005428/* Redistribute route treatment. */
5429void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005430bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5431 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005432 u_int32_t metric, u_char type)
5433{
5434 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005435 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005436 struct bgp_info *new;
5437 struct bgp_info *bi;
5438 struct bgp_info info;
5439 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005440 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005441 struct attr *new_attr;
5442 afi_t afi;
5443 int ret;
5444
5445 /* Make default attribute. */
5446 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5447 if (nexthop)
5448 attr.nexthop = *nexthop;
5449
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005450#ifdef HAVE_IPV6
5451 if (nexthop6)
5452 {
5453 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5454 extra->mp_nexthop_global = *nexthop6;
5455 extra->mp_nexthop_len = 16;
5456 }
5457#endif
5458
paul718e3742002-12-13 20:15:29 +00005459 attr.med = metric;
5460 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5461
paul1eb8ef22005-04-07 07:30:20 +00005462 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005463 {
5464 afi = family2afi (p->family);
5465
5466 if (bgp->redist[afi][type])
5467 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005468 struct attr attr_new;
5469 struct attr_extra extra_new;
5470
paul718e3742002-12-13 20:15:29 +00005471 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005472 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005473 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005474
5475 if (bgp->redist_metric_flag[afi][type])
5476 attr_new.med = bgp->redist_metric[afi][type];
5477
5478 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005479 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005480 {
5481 info.peer = bgp->peer_self;
5482 info.attr = &attr_new;
5483
paulfee0f4c2004-09-13 05:12:46 +00005484 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5485
paul718e3742002-12-13 20:15:29 +00005486 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5487 &info);
paulfee0f4c2004-09-13 05:12:46 +00005488
5489 bgp->peer_self->rmap_type = 0;
5490
paul718e3742002-12-13 20:15:29 +00005491 if (ret == RMAP_DENYMATCH)
5492 {
5493 /* Free uninterned attribute. */
5494 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005495
paul718e3742002-12-13 20:15:29 +00005496 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005497 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005498 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005499 bgp_redistribute_delete (p, type);
5500 return;
5501 }
5502 }
5503
Paul Jakmafb982c22007-05-04 20:15:47 +00005504 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5505 afi, SAFI_UNICAST, p, NULL);
5506
paul718e3742002-12-13 20:15:29 +00005507 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005508
paul718e3742002-12-13 20:15:29 +00005509 for (bi = bn->info; bi; bi = bi->next)
5510 if (bi->peer == bgp->peer_self
5511 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5512 break;
5513
5514 if (bi)
5515 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005516 if (attrhash_cmp (bi->attr, new_attr) &&
5517 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005518 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005519 bgp_attr_unintern (&new_attr);
5520 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005521 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005522 bgp_unlock_node (bn);
5523 return;
5524 }
5525 else
5526 {
5527 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005528 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005529
5530 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005531 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5532 bgp_info_restore(bn, bi);
5533 else
5534 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005535 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005536 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005537 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005538
5539 /* Process change. */
5540 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5541 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5542 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005543 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005544 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005545 return;
5546 }
5547 }
5548
5549 new = bgp_info_new ();
5550 new->type = type;
5551 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5552 new->peer = bgp->peer_self;
5553 SET_FLAG (new->flags, BGP_INFO_VALID);
5554 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005555 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005556
5557 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5558 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005559 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005560 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5561 }
5562 }
5563
5564 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005565 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005566 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005567}
5568
5569void
5570bgp_redistribute_delete (struct prefix *p, u_char type)
5571{
5572 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005573 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005574 afi_t afi;
5575 struct bgp_node *rn;
5576 struct bgp_info *ri;
5577
paul1eb8ef22005-04-07 07:30:20 +00005578 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005579 {
5580 afi = family2afi (p->family);
5581
5582 if (bgp->redist[afi][type])
5583 {
paulfee0f4c2004-09-13 05:12:46 +00005584 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005585
5586 for (ri = rn->info; ri; ri = ri->next)
5587 if (ri->peer == bgp->peer_self
5588 && ri->type == type)
5589 break;
5590
5591 if (ri)
5592 {
5593 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005594 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005595 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005596 }
5597 bgp_unlock_node (rn);
5598 }
5599 }
5600}
5601
5602/* Withdraw specified route type's route. */
5603void
5604bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5605{
5606 struct bgp_node *rn;
5607 struct bgp_info *ri;
5608 struct bgp_table *table;
5609
5610 table = bgp->rib[afi][SAFI_UNICAST];
5611
5612 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5613 {
5614 for (ri = rn->info; ri; ri = ri->next)
5615 if (ri->peer == bgp->peer_self
5616 && ri->type == type)
5617 break;
5618
5619 if (ri)
5620 {
5621 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005622 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005623 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005624 }
5625 }
5626}
David Lamparter6b0655a2014-06-04 06:53:35 +02005627
paul718e3742002-12-13 20:15:29 +00005628/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005629static void
paul718e3742002-12-13 20:15:29 +00005630route_vty_out_route (struct prefix *p, struct vty *vty)
5631{
5632 int len;
5633 u_int32_t destination;
5634 char buf[BUFSIZ];
5635
5636 if (p->family == AF_INET)
5637 {
5638 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5639 destination = ntohl (p->u.prefix4.s_addr);
5640
5641 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5642 || (IN_CLASSB (destination) && p->prefixlen == 16)
5643 || (IN_CLASSA (destination) && p->prefixlen == 8)
5644 || p->u.prefix4.s_addr == 0)
5645 {
5646 /* When mask is natural, mask is not displayed. */
5647 }
5648 else
5649 len += vty_out (vty, "/%d", p->prefixlen);
5650 }
5651 else
5652 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5653 p->prefixlen);
5654
5655 len = 17 - len;
5656 if (len < 1)
5657 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5658 else
5659 vty_out (vty, "%*s", len, " ");
5660}
5661
paul718e3742002-12-13 20:15:29 +00005662enum bgp_display_type
5663{
5664 normal_list,
5665};
5666
paulb40d9392005-08-22 22:34:41 +00005667/* Print the short form route status for a bgp_info */
5668static void
5669route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005670{
paulb40d9392005-08-22 22:34:41 +00005671 /* Route status display. */
5672 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5673 vty_out (vty, "R");
5674 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005675 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005676 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005677 vty_out (vty, "s");
5678 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5679 vty_out (vty, "*");
5680 else
5681 vty_out (vty, " ");
5682
5683 /* Selected */
5684 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5685 vty_out (vty, "h");
5686 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5687 vty_out (vty, "d");
5688 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5689 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005690 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5691 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005692 else
5693 vty_out (vty, " ");
5694
5695 /* Internal route. */
5696 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5697 vty_out (vty, "i");
5698 else
paulb40d9392005-08-22 22:34:41 +00005699 vty_out (vty, " ");
5700}
5701
5702/* called from terminal list command */
5703void
5704route_vty_out (struct vty *vty, struct prefix *p,
5705 struct bgp_info *binfo, int display, safi_t safi)
5706{
5707 struct attr *attr;
5708
5709 /* short status lead text */
5710 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005711
5712 /* print prefix and mask */
5713 if (! display)
5714 route_vty_out_route (p, vty);
5715 else
5716 vty_out (vty, "%*s", 17, " ");
5717
5718 /* Print attribute */
5719 attr = binfo->attr;
5720 if (attr)
5721 {
5722 if (p->family == AF_INET)
5723 {
5724 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005725 vty_out (vty, "%-16s",
5726 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005727 else
5728 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5729 }
5730#ifdef HAVE_IPV6
5731 else if (p->family == AF_INET6)
5732 {
5733 int len;
5734 char buf[BUFSIZ];
5735
5736 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005737 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5738 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005739 len = 16 - len;
5740 if (len < 1)
5741 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5742 else
5743 vty_out (vty, "%*s", len, " ");
5744 }
5745#endif /* HAVE_IPV6 */
5746
5747 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005748 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005749 else
5750 vty_out (vty, " ");
5751
5752 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005753 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005754 else
5755 vty_out (vty, " ");
5756
Paul Jakmafb982c22007-05-04 20:15:47 +00005757 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005758
Paul Jakmab2518c12006-05-12 23:48:40 +00005759 /* Print aspath */
5760 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005761 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005762
Paul Jakmab2518c12006-05-12 23:48:40 +00005763 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005764 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005765 }
paul718e3742002-12-13 20:15:29 +00005766 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005767}
5768
5769/* called from terminal list command */
5770void
5771route_vty_out_tmp (struct vty *vty, struct prefix *p,
5772 struct attr *attr, safi_t safi)
5773{
5774 /* Route status display. */
5775 vty_out (vty, "*");
5776 vty_out (vty, ">");
5777 vty_out (vty, " ");
5778
5779 /* print prefix and mask */
5780 route_vty_out_route (p, vty);
5781
5782 /* Print attribute */
5783 if (attr)
5784 {
5785 if (p->family == AF_INET)
5786 {
5787 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005788 vty_out (vty, "%-16s",
5789 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005790 else
5791 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5792 }
5793#ifdef HAVE_IPV6
5794 else if (p->family == AF_INET6)
5795 {
5796 int len;
5797 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005798
5799 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005800
5801 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005802 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5803 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005804 len = 16 - len;
5805 if (len < 1)
5806 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5807 else
5808 vty_out (vty, "%*s", len, " ");
5809 }
5810#endif /* HAVE_IPV6 */
5811
5812 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005813 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005814 else
5815 vty_out (vty, " ");
5816
5817 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005818 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005819 else
5820 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005821
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005822 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005823
Paul Jakmab2518c12006-05-12 23:48:40 +00005824 /* Print aspath */
5825 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005826 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005827
Paul Jakmab2518c12006-05-12 23:48:40 +00005828 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005829 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005830 }
paul718e3742002-12-13 20:15:29 +00005831
5832 vty_out (vty, "%s", VTY_NEWLINE);
5833}
5834
ajs5a646652004-11-05 01:25:55 +00005835void
paul718e3742002-12-13 20:15:29 +00005836route_vty_out_tag (struct vty *vty, struct prefix *p,
5837 struct bgp_info *binfo, int display, safi_t safi)
5838{
5839 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005840 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005841
5842 if (!binfo->extra)
5843 return;
5844
paulb40d9392005-08-22 22:34:41 +00005845 /* short status lead text */
5846 route_vty_short_status_out (vty, binfo);
5847
paul718e3742002-12-13 20:15:29 +00005848 /* print prefix and mask */
5849 if (! display)
5850 route_vty_out_route (p, vty);
5851 else
5852 vty_out (vty, "%*s", 17, " ");
5853
5854 /* Print attribute */
5855 attr = binfo->attr;
5856 if (attr)
5857 {
5858 if (p->family == AF_INET)
5859 {
5860 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005861 vty_out (vty, "%-16s",
5862 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005863 else
5864 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5865 }
5866#ifdef HAVE_IPV6
5867 else if (p->family == AF_INET6)
5868 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005869 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005870 char buf[BUFSIZ];
5871 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005872 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005873 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005874 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5875 buf, BUFSIZ));
5876 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005877 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005878 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5879 buf, BUFSIZ),
5880 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5881 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005882
5883 }
5884#endif /* HAVE_IPV6 */
5885 }
5886
Paul Jakmafb982c22007-05-04 20:15:47 +00005887 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005888
5889 vty_out (vty, "notag/%d", label);
5890
5891 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005892}
5893
5894/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005895static void
paul718e3742002-12-13 20:15:29 +00005896damp_route_vty_out (struct vty *vty, struct prefix *p,
5897 struct bgp_info *binfo, int display, safi_t safi)
5898{
5899 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005900 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005901 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005902
paulb40d9392005-08-22 22:34:41 +00005903 /* short status lead text */
5904 route_vty_short_status_out (vty, binfo);
5905
paul718e3742002-12-13 20:15:29 +00005906 /* print prefix and mask */
5907 if (! display)
5908 route_vty_out_route (p, vty);
5909 else
5910 vty_out (vty, "%*s", 17, " ");
5911
5912 len = vty_out (vty, "%s", binfo->peer->host);
5913 len = 17 - len;
5914 if (len < 1)
5915 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5916 else
5917 vty_out (vty, "%*s", len, " ");
5918
Chris Caputo50aef6f2009-06-23 06:06:49 +00005919 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005920
5921 /* Print attribute */
5922 attr = binfo->attr;
5923 if (attr)
5924 {
5925 /* Print aspath */
5926 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005927 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005928
5929 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005930 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005931 }
5932 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005933}
5934
paul718e3742002-12-13 20:15:29 +00005935/* flap route */
ajs5a646652004-11-05 01:25:55 +00005936static void
paul718e3742002-12-13 20:15:29 +00005937flap_route_vty_out (struct vty *vty, struct prefix *p,
5938 struct bgp_info *binfo, int display, safi_t safi)
5939{
5940 struct attr *attr;
5941 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005942 char timebuf[BGP_UPTIME_LEN];
5943 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005944
5945 if (!binfo->extra)
5946 return;
5947
5948 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005949
paulb40d9392005-08-22 22:34:41 +00005950 /* short status lead text */
5951 route_vty_short_status_out (vty, binfo);
5952
paul718e3742002-12-13 20:15:29 +00005953 /* print prefix and mask */
5954 if (! display)
5955 route_vty_out_route (p, vty);
5956 else
5957 vty_out (vty, "%*s", 17, " ");
5958
5959 len = vty_out (vty, "%s", binfo->peer->host);
5960 len = 16 - len;
5961 if (len < 1)
5962 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5963 else
5964 vty_out (vty, "%*s", len, " ");
5965
5966 len = vty_out (vty, "%d", bdi->flap);
5967 len = 5 - len;
5968 if (len < 1)
5969 vty_out (vty, " ");
5970 else
5971 vty_out (vty, "%*s ", len, " ");
5972
5973 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5974 timebuf, BGP_UPTIME_LEN));
5975
5976 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5977 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005978 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005979 else
5980 vty_out (vty, "%*s ", 8, " ");
5981
5982 /* Print attribute */
5983 attr = binfo->attr;
5984 if (attr)
5985 {
5986 /* Print aspath */
5987 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005988 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005989
5990 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005991 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005992 }
5993 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005994}
5995
paul94f2b392005-06-28 12:44:16 +00005996static void
paul718e3742002-12-13 20:15:29 +00005997route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5998 struct bgp_info *binfo, afi_t afi, safi_t safi)
5999{
6000 char buf[INET6_ADDRSTRLEN];
6001 char buf1[BUFSIZ];
6002 struct attr *attr;
6003 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006004#ifdef HAVE_CLOCK_MONOTONIC
6005 time_t tbuf;
6006#endif
paul718e3742002-12-13 20:15:29 +00006007
6008 attr = binfo->attr;
6009
6010 if (attr)
6011 {
6012 /* Line1 display AS-path, Aggregator */
6013 if (attr->aspath)
6014 {
6015 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006016 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006017 vty_out (vty, "Local");
6018 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006019 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006020 }
6021
paulb40d9392005-08-22 22:34:41 +00006022 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6023 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006024 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6025 vty_out (vty, ", (stale)");
6026 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006027 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006028 attr->extra->aggregator_as,
6029 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006030 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6031 vty_out (vty, ", (Received from a RR-client)");
6032 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6033 vty_out (vty, ", (Received from a RS-client)");
6034 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6035 vty_out (vty, ", (history entry)");
6036 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6037 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006038 vty_out (vty, "%s", VTY_NEWLINE);
6039
6040 /* Line2 display Next-hop, Neighbor, Router-id */
6041 if (p->family == AF_INET)
6042 {
6043 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006044 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006045 inet_ntoa (attr->nexthop));
6046 }
6047#ifdef HAVE_IPV6
6048 else
6049 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006050 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006051 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006052 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006053 buf, INET6_ADDRSTRLEN));
6054 }
6055#endif /* HAVE_IPV6 */
6056
6057 if (binfo->peer == bgp->peer_self)
6058 {
6059 vty_out (vty, " from %s ",
6060 p->family == AF_INET ? "0.0.0.0" : "::");
6061 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6062 }
6063 else
6064 {
6065 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6066 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006067 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006068 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006069 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006070 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006071 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006072 else
6073 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6074 }
6075 vty_out (vty, "%s", VTY_NEWLINE);
6076
6077#ifdef HAVE_IPV6
6078 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006079 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006080 {
6081 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006082 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006083 buf, INET6_ADDRSTRLEN),
6084 VTY_NEWLINE);
6085 }
6086#endif /* HAVE_IPV6 */
6087
6088 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6089 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6090
6091 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006092 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006093
6094 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006095 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006096 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006097 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006098
Paul Jakmafb982c22007-05-04 20:15:47 +00006099 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006100 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006101
6102 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6103 vty_out (vty, ", valid");
6104
6105 if (binfo->peer != bgp->peer_self)
6106 {
6107 if (binfo->peer->as == binfo->peer->local_as)
6108 vty_out (vty, ", internal");
6109 else
6110 vty_out (vty, ", %s",
6111 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6112 }
6113 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6114 vty_out (vty, ", aggregated, local");
6115 else if (binfo->type != ZEBRA_ROUTE_BGP)
6116 vty_out (vty, ", sourced");
6117 else
6118 vty_out (vty, ", sourced, local");
6119
6120 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6121 vty_out (vty, ", atomic-aggregate");
6122
Josh Baileyde8d5df2011-07-20 20:46:01 -07006123 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6124 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6125 bgp_info_mpath_count (binfo)))
6126 vty_out (vty, ", multipath");
6127
paul718e3742002-12-13 20:15:29 +00006128 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6129 vty_out (vty, ", best");
6130
6131 vty_out (vty, "%s", VTY_NEWLINE);
6132
6133 /* Line 4 display Community */
6134 if (attr->community)
6135 vty_out (vty, " Community: %s%s", attr->community->str,
6136 VTY_NEWLINE);
6137
6138 /* Line 5 display Extended-community */
6139 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006140 vty_out (vty, " Extended Community: %s%s",
6141 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006142
6143 /* Line 6 display Originator, Cluster-id */
6144 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6145 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6146 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006147 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006148 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006149 vty_out (vty, " Originator: %s",
6150 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006151
6152 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6153 {
6154 int i;
6155 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006156 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6157 vty_out (vty, "%s ",
6158 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006159 }
6160 vty_out (vty, "%s", VTY_NEWLINE);
6161 }
Paul Jakma41367172007-08-06 15:24:51 +00006162
Paul Jakmafb982c22007-05-04 20:15:47 +00006163 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006164 bgp_damp_info_vty (vty, binfo);
6165
6166 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006167#ifdef HAVE_CLOCK_MONOTONIC
6168 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006169 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006170#else
6171 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6172#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006173 }
6174 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006175}
6176
6177#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6178 "h history, * valid, > best, = multipath,%s"\
6179 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006180#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006181#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6182#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6183#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6184
6185enum bgp_show_type
6186{
6187 bgp_show_type_normal,
6188 bgp_show_type_regexp,
6189 bgp_show_type_prefix_list,
6190 bgp_show_type_filter_list,
6191 bgp_show_type_route_map,
6192 bgp_show_type_neighbor,
6193 bgp_show_type_cidr_only,
6194 bgp_show_type_prefix_longer,
6195 bgp_show_type_community_all,
6196 bgp_show_type_community,
6197 bgp_show_type_community_exact,
6198 bgp_show_type_community_list,
6199 bgp_show_type_community_list_exact,
6200 bgp_show_type_flap_statistics,
6201 bgp_show_type_flap_address,
6202 bgp_show_type_flap_prefix,
6203 bgp_show_type_flap_cidr_only,
6204 bgp_show_type_flap_regexp,
6205 bgp_show_type_flap_filter_list,
6206 bgp_show_type_flap_prefix_list,
6207 bgp_show_type_flap_prefix_longer,
6208 bgp_show_type_flap_route_map,
6209 bgp_show_type_flap_neighbor,
6210 bgp_show_type_dampend_paths,
6211 bgp_show_type_damp_neighbor
6212};
6213
ajs5a646652004-11-05 01:25:55 +00006214static int
paulfee0f4c2004-09-13 05:12:46 +00006215bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006216 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006217{
paul718e3742002-12-13 20:15:29 +00006218 struct bgp_info *ri;
6219 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006220 int header = 1;
paul718e3742002-12-13 20:15:29 +00006221 int display;
ajs5a646652004-11-05 01:25:55 +00006222 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006223
6224 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006225 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006226
paul718e3742002-12-13 20:15:29 +00006227 /* Start processing of routes. */
6228 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6229 if (rn->info != NULL)
6230 {
6231 display = 0;
6232
6233 for (ri = rn->info; ri; ri = ri->next)
6234 {
ajs5a646652004-11-05 01:25:55 +00006235 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006236 || type == bgp_show_type_flap_address
6237 || type == bgp_show_type_flap_prefix
6238 || type == bgp_show_type_flap_cidr_only
6239 || type == bgp_show_type_flap_regexp
6240 || type == bgp_show_type_flap_filter_list
6241 || type == bgp_show_type_flap_prefix_list
6242 || type == bgp_show_type_flap_prefix_longer
6243 || type == bgp_show_type_flap_route_map
6244 || type == bgp_show_type_flap_neighbor
6245 || type == bgp_show_type_dampend_paths
6246 || type == bgp_show_type_damp_neighbor)
6247 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006248 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006249 continue;
6250 }
6251 if (type == bgp_show_type_regexp
6252 || type == bgp_show_type_flap_regexp)
6253 {
ajs5a646652004-11-05 01:25:55 +00006254 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006255
6256 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6257 continue;
6258 }
6259 if (type == bgp_show_type_prefix_list
6260 || type == bgp_show_type_flap_prefix_list)
6261 {
ajs5a646652004-11-05 01:25:55 +00006262 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006263
6264 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6265 continue;
6266 }
6267 if (type == bgp_show_type_filter_list
6268 || type == bgp_show_type_flap_filter_list)
6269 {
ajs5a646652004-11-05 01:25:55 +00006270 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006271
6272 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6273 continue;
6274 }
6275 if (type == bgp_show_type_route_map
6276 || type == bgp_show_type_flap_route_map)
6277 {
ajs5a646652004-11-05 01:25:55 +00006278 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006279 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006280 struct attr dummy_attr;
6281 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006282 int ret;
6283
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006284 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006285 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006286
paul718e3742002-12-13 20:15:29 +00006287 binfo.peer = ri->peer;
6288 binfo.attr = &dummy_attr;
6289
6290 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006291 if (ret == RMAP_DENYMATCH)
6292 continue;
6293 }
6294 if (type == bgp_show_type_neighbor
6295 || type == bgp_show_type_flap_neighbor
6296 || type == bgp_show_type_damp_neighbor)
6297 {
ajs5a646652004-11-05 01:25:55 +00006298 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006299
6300 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6301 continue;
6302 }
6303 if (type == bgp_show_type_cidr_only
6304 || type == bgp_show_type_flap_cidr_only)
6305 {
6306 u_int32_t destination;
6307
6308 destination = ntohl (rn->p.u.prefix4.s_addr);
6309 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6310 continue;
6311 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6312 continue;
6313 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6314 continue;
6315 }
6316 if (type == bgp_show_type_prefix_longer
6317 || type == bgp_show_type_flap_prefix_longer)
6318 {
ajs5a646652004-11-05 01:25:55 +00006319 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006320
6321 if (! prefix_match (p, &rn->p))
6322 continue;
6323 }
6324 if (type == bgp_show_type_community_all)
6325 {
6326 if (! ri->attr->community)
6327 continue;
6328 }
6329 if (type == bgp_show_type_community)
6330 {
ajs5a646652004-11-05 01:25:55 +00006331 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006332
6333 if (! ri->attr->community ||
6334 ! community_match (ri->attr->community, com))
6335 continue;
6336 }
6337 if (type == bgp_show_type_community_exact)
6338 {
ajs5a646652004-11-05 01:25:55 +00006339 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006340
6341 if (! ri->attr->community ||
6342 ! community_cmp (ri->attr->community, com))
6343 continue;
6344 }
6345 if (type == bgp_show_type_community_list)
6346 {
ajs5a646652004-11-05 01:25:55 +00006347 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006348
6349 if (! community_list_match (ri->attr->community, list))
6350 continue;
6351 }
6352 if (type == bgp_show_type_community_list_exact)
6353 {
ajs5a646652004-11-05 01:25:55 +00006354 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006355
6356 if (! community_list_exact_match (ri->attr->community, list))
6357 continue;
6358 }
6359 if (type == bgp_show_type_flap_address
6360 || type == bgp_show_type_flap_prefix)
6361 {
ajs5a646652004-11-05 01:25:55 +00006362 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006363
6364 if (! prefix_match (&rn->p, p))
6365 continue;
6366
6367 if (type == bgp_show_type_flap_prefix)
6368 if (p->prefixlen != rn->p.prefixlen)
6369 continue;
6370 }
6371 if (type == bgp_show_type_dampend_paths
6372 || type == bgp_show_type_damp_neighbor)
6373 {
6374 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6375 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6376 continue;
6377 }
6378
6379 if (header)
6380 {
hasso93406d82005-02-02 14:40:33 +00006381 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6382 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6383 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006384 if (type == bgp_show_type_dampend_paths
6385 || type == bgp_show_type_damp_neighbor)
6386 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6387 else if (type == bgp_show_type_flap_statistics
6388 || type == bgp_show_type_flap_address
6389 || type == bgp_show_type_flap_prefix
6390 || type == bgp_show_type_flap_cidr_only
6391 || type == bgp_show_type_flap_regexp
6392 || type == bgp_show_type_flap_filter_list
6393 || type == bgp_show_type_flap_prefix_list
6394 || type == bgp_show_type_flap_prefix_longer
6395 || type == bgp_show_type_flap_route_map
6396 || type == bgp_show_type_flap_neighbor)
6397 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6398 else
6399 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006400 header = 0;
6401 }
6402
6403 if (type == bgp_show_type_dampend_paths
6404 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006405 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006406 else if (type == bgp_show_type_flap_statistics
6407 || type == bgp_show_type_flap_address
6408 || type == bgp_show_type_flap_prefix
6409 || type == bgp_show_type_flap_cidr_only
6410 || type == bgp_show_type_flap_regexp
6411 || type == bgp_show_type_flap_filter_list
6412 || type == bgp_show_type_flap_prefix_list
6413 || type == bgp_show_type_flap_prefix_longer
6414 || type == bgp_show_type_flap_route_map
6415 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006416 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006417 else
ajs5a646652004-11-05 01:25:55 +00006418 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006419 display++;
6420 }
6421 if (display)
ajs5a646652004-11-05 01:25:55 +00006422 output_count++;
paul718e3742002-12-13 20:15:29 +00006423 }
6424
6425 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006426 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006427 {
6428 if (type == bgp_show_type_normal)
6429 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6430 }
6431 else
6432 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006433 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006434
6435 return CMD_SUCCESS;
6436}
6437
ajs5a646652004-11-05 01:25:55 +00006438static int
paulfee0f4c2004-09-13 05:12:46 +00006439bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006440 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006441{
6442 struct bgp_table *table;
6443
6444 if (bgp == NULL) {
6445 bgp = bgp_get_default ();
6446 }
6447
6448 if (bgp == NULL)
6449 {
6450 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6451 return CMD_WARNING;
6452 }
6453
6454
6455 table = bgp->rib[afi][safi];
6456
ajs5a646652004-11-05 01:25:55 +00006457 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006458}
6459
paul718e3742002-12-13 20:15:29 +00006460/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006461static void
paul718e3742002-12-13 20:15:29 +00006462route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6463 struct bgp_node *rn,
6464 struct prefix_rd *prd, afi_t afi, safi_t safi)
6465{
6466 struct bgp_info *ri;
6467 struct prefix *p;
6468 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006469 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006470 char buf1[INET6_ADDRSTRLEN];
6471 char buf2[INET6_ADDRSTRLEN];
6472 int count = 0;
6473 int best = 0;
6474 int suppress = 0;
6475 int no_export = 0;
6476 int no_advertise = 0;
6477 int local_as = 0;
6478 int first = 0;
6479
6480 p = &rn->p;
6481 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6482 (safi == SAFI_MPLS_VPN ?
6483 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6484 safi == SAFI_MPLS_VPN ? ":" : "",
6485 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6486 p->prefixlen, VTY_NEWLINE);
6487
6488 for (ri = rn->info; ri; ri = ri->next)
6489 {
6490 count++;
6491 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6492 {
6493 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006494 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006495 suppress = 1;
6496 if (ri->attr->community != NULL)
6497 {
6498 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6499 no_advertise = 1;
6500 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6501 no_export = 1;
6502 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6503 local_as = 1;
6504 }
6505 }
6506 }
6507
6508 vty_out (vty, "Paths: (%d available", count);
6509 if (best)
6510 {
6511 vty_out (vty, ", best #%d", best);
6512 if (safi == SAFI_UNICAST)
6513 vty_out (vty, ", table Default-IP-Routing-Table");
6514 }
6515 else
6516 vty_out (vty, ", no best path");
6517 if (no_advertise)
6518 vty_out (vty, ", not advertised to any peer");
6519 else if (no_export)
6520 vty_out (vty, ", not advertised to EBGP peer");
6521 else if (local_as)
6522 vty_out (vty, ", not advertised outside local AS");
6523 if (suppress)
6524 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6525 vty_out (vty, ")%s", VTY_NEWLINE);
6526
6527 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006528 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006529 {
6530 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6531 {
6532 if (! first)
6533 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6534 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6535 first = 1;
6536 }
6537 }
6538 if (! first)
6539 vty_out (vty, " Not advertised to any peer");
6540 vty_out (vty, "%s", VTY_NEWLINE);
6541}
6542
6543/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006544static int
paulfee0f4c2004-09-13 05:12:46 +00006545bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006546 struct bgp_table *rib, const char *ip_str,
6547 afi_t afi, safi_t safi, struct prefix_rd *prd,
6548 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006549{
6550 int ret;
6551 int header;
6552 int display = 0;
6553 struct prefix match;
6554 struct bgp_node *rn;
6555 struct bgp_node *rm;
6556 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006557 struct bgp_table *table;
6558
paul718e3742002-12-13 20:15:29 +00006559 /* Check IP address argument. */
6560 ret = str2prefix (ip_str, &match);
6561 if (! ret)
6562 {
6563 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6564 return CMD_WARNING;
6565 }
6566
6567 match.family = afi2family (afi);
6568
6569 if (safi == SAFI_MPLS_VPN)
6570 {
paulfee0f4c2004-09-13 05:12:46 +00006571 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006572 {
6573 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6574 continue;
6575
6576 if ((table = rn->info) != NULL)
6577 {
6578 header = 1;
6579
6580 if ((rm = bgp_node_match (table, &match)) != NULL)
6581 {
6582 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006583 {
6584 bgp_unlock_node (rm);
6585 continue;
6586 }
paul718e3742002-12-13 20:15:29 +00006587
6588 for (ri = rm->info; ri; ri = ri->next)
6589 {
6590 if (header)
6591 {
6592 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6593 AFI_IP, SAFI_MPLS_VPN);
6594
6595 header = 0;
6596 }
6597 display++;
6598 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6599 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006600
6601 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006602 }
6603 }
6604 }
6605 }
6606 else
6607 {
6608 header = 1;
6609
paulfee0f4c2004-09-13 05:12:46 +00006610 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006611 {
6612 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6613 {
6614 for (ri = rn->info; ri; ri = ri->next)
6615 {
6616 if (header)
6617 {
6618 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6619 header = 0;
6620 }
6621 display++;
6622 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6623 }
6624 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006625
6626 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006627 }
6628 }
6629
6630 if (! display)
6631 {
6632 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6633 return CMD_WARNING;
6634 }
6635
6636 return CMD_SUCCESS;
6637}
6638
paulfee0f4c2004-09-13 05:12:46 +00006639/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006640static int
paulfd79ac92004-10-13 05:06:08 +00006641bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006642 afi_t afi, safi_t safi, struct prefix_rd *prd,
6643 int prefix_check)
6644{
6645 struct bgp *bgp;
6646
6647 /* BGP structure lookup. */
6648 if (view_name)
6649 {
6650 bgp = bgp_lookup_by_name (view_name);
6651 if (bgp == NULL)
6652 {
6653 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6654 return CMD_WARNING;
6655 }
6656 }
6657 else
6658 {
6659 bgp = bgp_get_default ();
6660 if (bgp == NULL)
6661 {
6662 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6663 return CMD_WARNING;
6664 }
6665 }
6666
6667 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6668 afi, safi, prd, prefix_check);
6669}
6670
paul718e3742002-12-13 20:15:29 +00006671/* BGP route print out function. */
6672DEFUN (show_ip_bgp,
6673 show_ip_bgp_cmd,
6674 "show ip bgp",
6675 SHOW_STR
6676 IP_STR
6677 BGP_STR)
6678{
ajs5a646652004-11-05 01:25:55 +00006679 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006680}
6681
6682DEFUN (show_ip_bgp_ipv4,
6683 show_ip_bgp_ipv4_cmd,
6684 "show ip bgp ipv4 (unicast|multicast)",
6685 SHOW_STR
6686 IP_STR
6687 BGP_STR
6688 "Address family\n"
6689 "Address Family modifier\n"
6690 "Address Family modifier\n")
6691{
6692 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006693 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6694 NULL);
paul718e3742002-12-13 20:15:29 +00006695
ajs5a646652004-11-05 01:25:55 +00006696 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006697}
6698
Michael Lambert95cbbd22010-07-23 14:43:04 -04006699ALIAS (show_ip_bgp_ipv4,
6700 show_bgp_ipv4_safi_cmd,
6701 "show bgp ipv4 (unicast|multicast)",
6702 SHOW_STR
6703 BGP_STR
6704 "Address family\n"
6705 "Address Family modifier\n"
6706 "Address Family modifier\n")
6707
paul718e3742002-12-13 20:15:29 +00006708DEFUN (show_ip_bgp_route,
6709 show_ip_bgp_route_cmd,
6710 "show ip bgp A.B.C.D",
6711 SHOW_STR
6712 IP_STR
6713 BGP_STR
6714 "Network in the BGP routing table to display\n")
6715{
6716 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6717}
6718
6719DEFUN (show_ip_bgp_ipv4_route,
6720 show_ip_bgp_ipv4_route_cmd,
6721 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6722 SHOW_STR
6723 IP_STR
6724 BGP_STR
6725 "Address family\n"
6726 "Address Family modifier\n"
6727 "Address Family modifier\n"
6728 "Network in the BGP routing table to display\n")
6729{
6730 if (strncmp (argv[0], "m", 1) == 0)
6731 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6732
6733 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6734}
6735
Michael Lambert95cbbd22010-07-23 14:43:04 -04006736ALIAS (show_ip_bgp_ipv4_route,
6737 show_bgp_ipv4_safi_route_cmd,
6738 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6739 SHOW_STR
6740 BGP_STR
6741 "Address family\n"
6742 "Address Family modifier\n"
6743 "Address Family modifier\n"
6744 "Network in the BGP routing table to display\n")
6745
paul718e3742002-12-13 20:15:29 +00006746DEFUN (show_ip_bgp_vpnv4_all_route,
6747 show_ip_bgp_vpnv4_all_route_cmd,
6748 "show ip bgp vpnv4 all A.B.C.D",
6749 SHOW_STR
6750 IP_STR
6751 BGP_STR
6752 "Display VPNv4 NLRI specific information\n"
6753 "Display information about all VPNv4 NLRIs\n"
6754 "Network in the BGP routing table to display\n")
6755{
6756 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6757}
6758
6759DEFUN (show_ip_bgp_vpnv4_rd_route,
6760 show_ip_bgp_vpnv4_rd_route_cmd,
6761 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6762 SHOW_STR
6763 IP_STR
6764 BGP_STR
6765 "Display VPNv4 NLRI specific information\n"
6766 "Display information for a route distinguisher\n"
6767 "VPN Route Distinguisher\n"
6768 "Network in the BGP routing table to display\n")
6769{
6770 int ret;
6771 struct prefix_rd prd;
6772
6773 ret = str2prefix_rd (argv[0], &prd);
6774 if (! ret)
6775 {
6776 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6777 return CMD_WARNING;
6778 }
6779 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6780}
6781
6782DEFUN (show_ip_bgp_prefix,
6783 show_ip_bgp_prefix_cmd,
6784 "show ip bgp A.B.C.D/M",
6785 SHOW_STR
6786 IP_STR
6787 BGP_STR
6788 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6789{
6790 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6791}
6792
6793DEFUN (show_ip_bgp_ipv4_prefix,
6794 show_ip_bgp_ipv4_prefix_cmd,
6795 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6796 SHOW_STR
6797 IP_STR
6798 BGP_STR
6799 "Address family\n"
6800 "Address Family modifier\n"
6801 "Address Family modifier\n"
6802 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6803{
6804 if (strncmp (argv[0], "m", 1) == 0)
6805 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6806
6807 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6808}
6809
Michael Lambert95cbbd22010-07-23 14:43:04 -04006810ALIAS (show_ip_bgp_ipv4_prefix,
6811 show_bgp_ipv4_safi_prefix_cmd,
6812 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6813 SHOW_STR
6814 BGP_STR
6815 "Address family\n"
6816 "Address Family modifier\n"
6817 "Address Family modifier\n"
6818 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6819
paul718e3742002-12-13 20:15:29 +00006820DEFUN (show_ip_bgp_vpnv4_all_prefix,
6821 show_ip_bgp_vpnv4_all_prefix_cmd,
6822 "show ip bgp vpnv4 all A.B.C.D/M",
6823 SHOW_STR
6824 IP_STR
6825 BGP_STR
6826 "Display VPNv4 NLRI specific information\n"
6827 "Display information about all VPNv4 NLRIs\n"
6828 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6829{
6830 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6831}
6832
6833DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6834 show_ip_bgp_vpnv4_rd_prefix_cmd,
6835 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6836 SHOW_STR
6837 IP_STR
6838 BGP_STR
6839 "Display VPNv4 NLRI specific information\n"
6840 "Display information for a route distinguisher\n"
6841 "VPN Route Distinguisher\n"
6842 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6843{
6844 int ret;
6845 struct prefix_rd prd;
6846
6847 ret = str2prefix_rd (argv[0], &prd);
6848 if (! ret)
6849 {
6850 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6851 return CMD_WARNING;
6852 }
6853 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6854}
6855
6856DEFUN (show_ip_bgp_view,
6857 show_ip_bgp_view_cmd,
6858 "show ip bgp view WORD",
6859 SHOW_STR
6860 IP_STR
6861 BGP_STR
6862 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006863 "View name\n")
paul718e3742002-12-13 20:15:29 +00006864{
paulbb46e942003-10-24 19:02:03 +00006865 struct bgp *bgp;
6866
6867 /* BGP structure lookup. */
6868 bgp = bgp_lookup_by_name (argv[0]);
6869 if (bgp == NULL)
6870 {
6871 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6872 return CMD_WARNING;
6873 }
6874
ajs5a646652004-11-05 01:25:55 +00006875 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006876}
6877
6878DEFUN (show_ip_bgp_view_route,
6879 show_ip_bgp_view_route_cmd,
6880 "show ip bgp view WORD A.B.C.D",
6881 SHOW_STR
6882 IP_STR
6883 BGP_STR
6884 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006885 "View name\n"
paul718e3742002-12-13 20:15:29 +00006886 "Network in the BGP routing table to display\n")
6887{
6888 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6889}
6890
6891DEFUN (show_ip_bgp_view_prefix,
6892 show_ip_bgp_view_prefix_cmd,
6893 "show ip bgp view WORD A.B.C.D/M",
6894 SHOW_STR
6895 IP_STR
6896 BGP_STR
6897 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00006898 "View name\n"
paul718e3742002-12-13 20:15:29 +00006899 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6900{
6901 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6902}
6903
6904#ifdef HAVE_IPV6
6905DEFUN (show_bgp,
6906 show_bgp_cmd,
6907 "show bgp",
6908 SHOW_STR
6909 BGP_STR)
6910{
ajs5a646652004-11-05 01:25:55 +00006911 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6912 NULL);
paul718e3742002-12-13 20:15:29 +00006913}
6914
6915ALIAS (show_bgp,
6916 show_bgp_ipv6_cmd,
6917 "show bgp ipv6",
6918 SHOW_STR
6919 BGP_STR
6920 "Address family\n")
6921
Michael Lambert95cbbd22010-07-23 14:43:04 -04006922DEFUN (show_bgp_ipv6_safi,
6923 show_bgp_ipv6_safi_cmd,
6924 "show bgp ipv6 (unicast|multicast)",
6925 SHOW_STR
6926 BGP_STR
6927 "Address family\n"
6928 "Address Family modifier\n"
6929 "Address Family modifier\n")
6930{
6931 if (strncmp (argv[0], "m", 1) == 0)
6932 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6933 NULL);
6934
6935 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6936}
6937
paul718e3742002-12-13 20:15:29 +00006938/* old command */
6939DEFUN (show_ipv6_bgp,
6940 show_ipv6_bgp_cmd,
6941 "show ipv6 bgp",
6942 SHOW_STR
6943 IP_STR
6944 BGP_STR)
6945{
ajs5a646652004-11-05 01:25:55 +00006946 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6947 NULL);
paul718e3742002-12-13 20:15:29 +00006948}
6949
6950DEFUN (show_bgp_route,
6951 show_bgp_route_cmd,
6952 "show bgp X:X::X:X",
6953 SHOW_STR
6954 BGP_STR
6955 "Network in the BGP routing table to display\n")
6956{
6957 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6958}
6959
6960ALIAS (show_bgp_route,
6961 show_bgp_ipv6_route_cmd,
6962 "show bgp ipv6 X:X::X:X",
6963 SHOW_STR
6964 BGP_STR
6965 "Address family\n"
6966 "Network in the BGP routing table to display\n")
6967
Michael Lambert95cbbd22010-07-23 14:43:04 -04006968DEFUN (show_bgp_ipv6_safi_route,
6969 show_bgp_ipv6_safi_route_cmd,
6970 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6971 SHOW_STR
6972 BGP_STR
6973 "Address family\n"
6974 "Address Family modifier\n"
6975 "Address Family modifier\n"
6976 "Network in the BGP routing table to display\n")
6977{
6978 if (strncmp (argv[0], "m", 1) == 0)
6979 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6980
6981 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6982}
6983
paul718e3742002-12-13 20:15:29 +00006984/* old command */
6985DEFUN (show_ipv6_bgp_route,
6986 show_ipv6_bgp_route_cmd,
6987 "show ipv6 bgp X:X::X:X",
6988 SHOW_STR
6989 IP_STR
6990 BGP_STR
6991 "Network in the BGP routing table to display\n")
6992{
6993 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6994}
6995
6996DEFUN (show_bgp_prefix,
6997 show_bgp_prefix_cmd,
6998 "show bgp X:X::X:X/M",
6999 SHOW_STR
7000 BGP_STR
7001 "IPv6 prefix <network>/<length>\n")
7002{
7003 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7004}
7005
7006ALIAS (show_bgp_prefix,
7007 show_bgp_ipv6_prefix_cmd,
7008 "show bgp ipv6 X:X::X:X/M",
7009 SHOW_STR
7010 BGP_STR
7011 "Address family\n"
7012 "IPv6 prefix <network>/<length>\n")
7013
Michael Lambert95cbbd22010-07-23 14:43:04 -04007014DEFUN (show_bgp_ipv6_safi_prefix,
7015 show_bgp_ipv6_safi_prefix_cmd,
7016 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7017 SHOW_STR
7018 BGP_STR
7019 "Address family\n"
7020 "Address Family modifier\n"
7021 "Address Family modifier\n"
7022 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7023{
7024 if (strncmp (argv[0], "m", 1) == 0)
7025 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7026
7027 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7028}
7029
paul718e3742002-12-13 20:15:29 +00007030/* old command */
7031DEFUN (show_ipv6_bgp_prefix,
7032 show_ipv6_bgp_prefix_cmd,
7033 "show ipv6 bgp X:X::X:X/M",
7034 SHOW_STR
7035 IP_STR
7036 BGP_STR
7037 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7038{
7039 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7040}
7041
paulbb46e942003-10-24 19:02:03 +00007042DEFUN (show_bgp_view,
7043 show_bgp_view_cmd,
7044 "show bgp view WORD",
7045 SHOW_STR
7046 BGP_STR
7047 "BGP view\n"
7048 "View name\n")
7049{
7050 struct bgp *bgp;
7051
7052 /* BGP structure lookup. */
7053 bgp = bgp_lookup_by_name (argv[0]);
7054 if (bgp == NULL)
7055 {
7056 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7057 return CMD_WARNING;
7058 }
7059
ajs5a646652004-11-05 01:25:55 +00007060 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007061}
7062
7063ALIAS (show_bgp_view,
7064 show_bgp_view_ipv6_cmd,
7065 "show bgp view WORD ipv6",
7066 SHOW_STR
7067 BGP_STR
7068 "BGP view\n"
7069 "View name\n"
7070 "Address family\n")
7071
7072DEFUN (show_bgp_view_route,
7073 show_bgp_view_route_cmd,
7074 "show bgp view WORD X:X::X:X",
7075 SHOW_STR
7076 BGP_STR
7077 "BGP view\n"
7078 "View name\n"
7079 "Network in the BGP routing table to display\n")
7080{
7081 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7082}
7083
7084ALIAS (show_bgp_view_route,
7085 show_bgp_view_ipv6_route_cmd,
7086 "show bgp view WORD ipv6 X:X::X:X",
7087 SHOW_STR
7088 BGP_STR
7089 "BGP view\n"
7090 "View name\n"
7091 "Address family\n"
7092 "Network in the BGP routing table to display\n")
7093
7094DEFUN (show_bgp_view_prefix,
7095 show_bgp_view_prefix_cmd,
7096 "show bgp view WORD X:X::X:X/M",
7097 SHOW_STR
7098 BGP_STR
7099 "BGP view\n"
7100 "View name\n"
7101 "IPv6 prefix <network>/<length>\n")
7102{
7103 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7104}
7105
7106ALIAS (show_bgp_view_prefix,
7107 show_bgp_view_ipv6_prefix_cmd,
7108 "show bgp view WORD ipv6 X:X::X:X/M",
7109 SHOW_STR
7110 BGP_STR
7111 "BGP view\n"
7112 "View name\n"
7113 "Address family\n"
7114 "IPv6 prefix <network>/<length>\n")
7115
paul718e3742002-12-13 20:15:29 +00007116/* old command */
7117DEFUN (show_ipv6_mbgp,
7118 show_ipv6_mbgp_cmd,
7119 "show ipv6 mbgp",
7120 SHOW_STR
7121 IP_STR
7122 MBGP_STR)
7123{
ajs5a646652004-11-05 01:25:55 +00007124 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7125 NULL);
paul718e3742002-12-13 20:15:29 +00007126}
7127
7128/* old command */
7129DEFUN (show_ipv6_mbgp_route,
7130 show_ipv6_mbgp_route_cmd,
7131 "show ipv6 mbgp X:X::X:X",
7132 SHOW_STR
7133 IP_STR
7134 MBGP_STR
7135 "Network in the MBGP routing table to display\n")
7136{
7137 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7138}
7139
7140/* old command */
7141DEFUN (show_ipv6_mbgp_prefix,
7142 show_ipv6_mbgp_prefix_cmd,
7143 "show ipv6 mbgp X:X::X:X/M",
7144 SHOW_STR
7145 IP_STR
7146 MBGP_STR
7147 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7148{
7149 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7150}
7151#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007152
paul718e3742002-12-13 20:15:29 +00007153
paul94f2b392005-06-28 12:44:16 +00007154static int
paulfd79ac92004-10-13 05:06:08 +00007155bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007156 safi_t safi, enum bgp_show_type type)
7157{
7158 int i;
7159 struct buffer *b;
7160 char *regstr;
7161 int first;
7162 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007163 int rc;
paul718e3742002-12-13 20:15:29 +00007164
7165 first = 0;
7166 b = buffer_new (1024);
7167 for (i = 0; i < argc; i++)
7168 {
7169 if (first)
7170 buffer_putc (b, ' ');
7171 else
7172 {
7173 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7174 continue;
7175 first = 1;
7176 }
7177
7178 buffer_putstr (b, argv[i]);
7179 }
7180 buffer_putc (b, '\0');
7181
7182 regstr = buffer_getstr (b);
7183 buffer_free (b);
7184
7185 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007186 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007187 if (! regex)
7188 {
7189 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7190 VTY_NEWLINE);
7191 return CMD_WARNING;
7192 }
7193
ajs5a646652004-11-05 01:25:55 +00007194 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7195 bgp_regex_free (regex);
7196 return rc;
paul718e3742002-12-13 20:15:29 +00007197}
7198
7199DEFUN (show_ip_bgp_regexp,
7200 show_ip_bgp_regexp_cmd,
7201 "show ip bgp regexp .LINE",
7202 SHOW_STR
7203 IP_STR
7204 BGP_STR
7205 "Display routes matching the AS path regular expression\n"
7206 "A regular-expression to match the BGP AS paths\n")
7207{
7208 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7209 bgp_show_type_regexp);
7210}
7211
7212DEFUN (show_ip_bgp_flap_regexp,
7213 show_ip_bgp_flap_regexp_cmd,
7214 "show ip bgp flap-statistics regexp .LINE",
7215 SHOW_STR
7216 IP_STR
7217 BGP_STR
7218 "Display flap statistics of routes\n"
7219 "Display routes matching the AS path regular expression\n"
7220 "A regular-expression to match the BGP AS paths\n")
7221{
7222 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7223 bgp_show_type_flap_regexp);
7224}
7225
Balaji3921cc52015-05-16 23:12:17 +05307226ALIAS (show_ip_bgp_flap_regexp,
7227 show_ip_bgp_damp_flap_regexp_cmd,
7228 "show ip bgp dampening flap-statistics regexp .LINE",
7229 SHOW_STR
7230 IP_STR
7231 BGP_STR
7232 "Display detailed information about dampening\n"
7233 "Display flap statistics of routes\n"
7234 "Display routes matching the AS path regular expression\n"
7235 "A regular-expression to match the BGP AS paths\n")
7236
paul718e3742002-12-13 20:15:29 +00007237DEFUN (show_ip_bgp_ipv4_regexp,
7238 show_ip_bgp_ipv4_regexp_cmd,
7239 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7240 SHOW_STR
7241 IP_STR
7242 BGP_STR
7243 "Address family\n"
7244 "Address Family modifier\n"
7245 "Address Family modifier\n"
7246 "Display routes matching the AS path regular expression\n"
7247 "A regular-expression to match the BGP AS paths\n")
7248{
7249 if (strncmp (argv[0], "m", 1) == 0)
7250 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7251 bgp_show_type_regexp);
7252
7253 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7254 bgp_show_type_regexp);
7255}
7256
7257#ifdef HAVE_IPV6
7258DEFUN (show_bgp_regexp,
7259 show_bgp_regexp_cmd,
7260 "show bgp regexp .LINE",
7261 SHOW_STR
7262 BGP_STR
7263 "Display routes matching the AS path regular expression\n"
7264 "A regular-expression to match the BGP AS paths\n")
7265{
7266 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7267 bgp_show_type_regexp);
7268}
7269
7270ALIAS (show_bgp_regexp,
7271 show_bgp_ipv6_regexp_cmd,
7272 "show bgp ipv6 regexp .LINE",
7273 SHOW_STR
7274 BGP_STR
7275 "Address family\n"
7276 "Display routes matching the AS path regular expression\n"
7277 "A regular-expression to match the BGP AS paths\n")
7278
7279/* old command */
7280DEFUN (show_ipv6_bgp_regexp,
7281 show_ipv6_bgp_regexp_cmd,
7282 "show ipv6 bgp regexp .LINE",
7283 SHOW_STR
7284 IP_STR
7285 BGP_STR
7286 "Display routes matching the AS path regular expression\n"
7287 "A regular-expression to match the BGP AS paths\n")
7288{
7289 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7290 bgp_show_type_regexp);
7291}
7292
7293/* old command */
7294DEFUN (show_ipv6_mbgp_regexp,
7295 show_ipv6_mbgp_regexp_cmd,
7296 "show ipv6 mbgp regexp .LINE",
7297 SHOW_STR
7298 IP_STR
7299 BGP_STR
7300 "Display routes matching the AS path regular expression\n"
7301 "A regular-expression to match the MBGP AS paths\n")
7302{
7303 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7304 bgp_show_type_regexp);
7305}
7306#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007307
paul94f2b392005-06-28 12:44:16 +00007308static int
paulfd79ac92004-10-13 05:06:08 +00007309bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007310 safi_t safi, enum bgp_show_type type)
7311{
7312 struct prefix_list *plist;
7313
7314 plist = prefix_list_lookup (afi, prefix_list_str);
7315 if (plist == NULL)
7316 {
7317 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7318 prefix_list_str, VTY_NEWLINE);
7319 return CMD_WARNING;
7320 }
7321
ajs5a646652004-11-05 01:25:55 +00007322 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007323}
7324
7325DEFUN (show_ip_bgp_prefix_list,
7326 show_ip_bgp_prefix_list_cmd,
7327 "show ip bgp prefix-list WORD",
7328 SHOW_STR
7329 IP_STR
7330 BGP_STR
7331 "Display routes conforming to the prefix-list\n"
7332 "IP prefix-list name\n")
7333{
7334 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7335 bgp_show_type_prefix_list);
7336}
7337
7338DEFUN (show_ip_bgp_flap_prefix_list,
7339 show_ip_bgp_flap_prefix_list_cmd,
7340 "show ip bgp flap-statistics prefix-list WORD",
7341 SHOW_STR
7342 IP_STR
7343 BGP_STR
7344 "Display flap statistics of routes\n"
7345 "Display routes conforming to the prefix-list\n"
7346 "IP prefix-list name\n")
7347{
7348 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7349 bgp_show_type_flap_prefix_list);
7350}
7351
Balaji3921cc52015-05-16 23:12:17 +05307352ALIAS (show_ip_bgp_flap_prefix_list,
7353 show_ip_bgp_damp_flap_prefix_list_cmd,
7354 "show ip bgp dampening flap-statistics prefix-list WORD",
7355 SHOW_STR
7356 IP_STR
7357 BGP_STR
7358 "Display detailed information about dampening\n"
7359 "Display flap statistics of routes\n"
7360 "Display routes conforming to the prefix-list\n"
7361 "IP prefix-list name\n")
7362
paul718e3742002-12-13 20:15:29 +00007363DEFUN (show_ip_bgp_ipv4_prefix_list,
7364 show_ip_bgp_ipv4_prefix_list_cmd,
7365 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7366 SHOW_STR
7367 IP_STR
7368 BGP_STR
7369 "Address family\n"
7370 "Address Family modifier\n"
7371 "Address Family modifier\n"
7372 "Display routes conforming to the prefix-list\n"
7373 "IP prefix-list name\n")
7374{
7375 if (strncmp (argv[0], "m", 1) == 0)
7376 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7377 bgp_show_type_prefix_list);
7378
7379 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7380 bgp_show_type_prefix_list);
7381}
7382
7383#ifdef HAVE_IPV6
7384DEFUN (show_bgp_prefix_list,
7385 show_bgp_prefix_list_cmd,
7386 "show bgp prefix-list WORD",
7387 SHOW_STR
7388 BGP_STR
7389 "Display routes conforming to the prefix-list\n"
7390 "IPv6 prefix-list name\n")
7391{
7392 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7393 bgp_show_type_prefix_list);
7394}
7395
7396ALIAS (show_bgp_prefix_list,
7397 show_bgp_ipv6_prefix_list_cmd,
7398 "show bgp ipv6 prefix-list WORD",
7399 SHOW_STR
7400 BGP_STR
7401 "Address family\n"
7402 "Display routes conforming to the prefix-list\n"
7403 "IPv6 prefix-list name\n")
7404
7405/* old command */
7406DEFUN (show_ipv6_bgp_prefix_list,
7407 show_ipv6_bgp_prefix_list_cmd,
7408 "show ipv6 bgp prefix-list WORD",
7409 SHOW_STR
7410 IPV6_STR
7411 BGP_STR
7412 "Display routes matching the prefix-list\n"
7413 "IPv6 prefix-list name\n")
7414{
7415 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7416 bgp_show_type_prefix_list);
7417}
7418
7419/* old command */
7420DEFUN (show_ipv6_mbgp_prefix_list,
7421 show_ipv6_mbgp_prefix_list_cmd,
7422 "show ipv6 mbgp prefix-list WORD",
7423 SHOW_STR
7424 IPV6_STR
7425 MBGP_STR
7426 "Display routes matching the prefix-list\n"
7427 "IPv6 prefix-list name\n")
7428{
7429 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7430 bgp_show_type_prefix_list);
7431}
7432#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007433
paul94f2b392005-06-28 12:44:16 +00007434static int
paulfd79ac92004-10-13 05:06:08 +00007435bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007436 safi_t safi, enum bgp_show_type type)
7437{
7438 struct as_list *as_list;
7439
7440 as_list = as_list_lookup (filter);
7441 if (as_list == NULL)
7442 {
7443 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7444 return CMD_WARNING;
7445 }
7446
ajs5a646652004-11-05 01:25:55 +00007447 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007448}
7449
7450DEFUN (show_ip_bgp_filter_list,
7451 show_ip_bgp_filter_list_cmd,
7452 "show ip bgp filter-list WORD",
7453 SHOW_STR
7454 IP_STR
7455 BGP_STR
7456 "Display routes conforming to the filter-list\n"
7457 "Regular expression access list name\n")
7458{
7459 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7460 bgp_show_type_filter_list);
7461}
7462
7463DEFUN (show_ip_bgp_flap_filter_list,
7464 show_ip_bgp_flap_filter_list_cmd,
7465 "show ip bgp flap-statistics filter-list WORD",
7466 SHOW_STR
7467 IP_STR
7468 BGP_STR
7469 "Display flap statistics of routes\n"
7470 "Display routes conforming to the filter-list\n"
7471 "Regular expression access list name\n")
7472{
7473 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7474 bgp_show_type_flap_filter_list);
7475}
7476
Balaji3921cc52015-05-16 23:12:17 +05307477ALIAS (show_ip_bgp_flap_filter_list,
7478 show_ip_bgp_damp_flap_filter_list_cmd,
7479 "show ip bgp dampening flap-statistics filter-list WORD",
7480 SHOW_STR
7481 IP_STR
7482 BGP_STR
7483 "Display detailed information about dampening\n"
7484 "Display flap statistics of routes\n"
7485 "Display routes conforming to the filter-list\n"
7486 "Regular expression access list name\n")
7487
paul718e3742002-12-13 20:15:29 +00007488DEFUN (show_ip_bgp_ipv4_filter_list,
7489 show_ip_bgp_ipv4_filter_list_cmd,
7490 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7491 SHOW_STR
7492 IP_STR
7493 BGP_STR
7494 "Address family\n"
7495 "Address Family modifier\n"
7496 "Address Family modifier\n"
7497 "Display routes conforming to the filter-list\n"
7498 "Regular expression access list name\n")
7499{
7500 if (strncmp (argv[0], "m", 1) == 0)
7501 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7502 bgp_show_type_filter_list);
7503
7504 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7505 bgp_show_type_filter_list);
7506}
7507
7508#ifdef HAVE_IPV6
7509DEFUN (show_bgp_filter_list,
7510 show_bgp_filter_list_cmd,
7511 "show bgp filter-list WORD",
7512 SHOW_STR
7513 BGP_STR
7514 "Display routes conforming to the filter-list\n"
7515 "Regular expression access list name\n")
7516{
7517 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7518 bgp_show_type_filter_list);
7519}
7520
7521ALIAS (show_bgp_filter_list,
7522 show_bgp_ipv6_filter_list_cmd,
7523 "show bgp ipv6 filter-list WORD",
7524 SHOW_STR
7525 BGP_STR
7526 "Address family\n"
7527 "Display routes conforming to the filter-list\n"
7528 "Regular expression access list name\n")
7529
7530/* old command */
7531DEFUN (show_ipv6_bgp_filter_list,
7532 show_ipv6_bgp_filter_list_cmd,
7533 "show ipv6 bgp filter-list WORD",
7534 SHOW_STR
7535 IPV6_STR
7536 BGP_STR
7537 "Display routes conforming to the filter-list\n"
7538 "Regular expression access list name\n")
7539{
7540 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7541 bgp_show_type_filter_list);
7542}
7543
7544/* old command */
7545DEFUN (show_ipv6_mbgp_filter_list,
7546 show_ipv6_mbgp_filter_list_cmd,
7547 "show ipv6 mbgp filter-list WORD",
7548 SHOW_STR
7549 IPV6_STR
7550 MBGP_STR
7551 "Display routes conforming to the filter-list\n"
7552 "Regular expression access list name\n")
7553{
7554 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7555 bgp_show_type_filter_list);
7556}
7557#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007558
Balaji3921cc52015-05-16 23:12:17 +05307559DEFUN (show_ip_bgp_dampening_info,
7560 show_ip_bgp_dampening_params_cmd,
7561 "show ip bgp dampening parameters",
7562 SHOW_STR
7563 IP_STR
7564 BGP_STR
7565 "Display detailed information about dampening\n"
7566 "Display detail of configured dampening parameters\n")
7567{
7568 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
7569}
7570
paul94f2b392005-06-28 12:44:16 +00007571static int
paulfd79ac92004-10-13 05:06:08 +00007572bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007573 safi_t safi, enum bgp_show_type type)
7574{
7575 struct route_map *rmap;
7576
7577 rmap = route_map_lookup_by_name (rmap_str);
7578 if (! rmap)
7579 {
7580 vty_out (vty, "%% %s is not a valid route-map name%s",
7581 rmap_str, VTY_NEWLINE);
7582 return CMD_WARNING;
7583 }
7584
ajs5a646652004-11-05 01:25:55 +00007585 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007586}
7587
7588DEFUN (show_ip_bgp_route_map,
7589 show_ip_bgp_route_map_cmd,
7590 "show ip bgp route-map WORD",
7591 SHOW_STR
7592 IP_STR
7593 BGP_STR
7594 "Display routes matching the route-map\n"
7595 "A route-map to match on\n")
7596{
7597 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7598 bgp_show_type_route_map);
7599}
7600
7601DEFUN (show_ip_bgp_flap_route_map,
7602 show_ip_bgp_flap_route_map_cmd,
7603 "show ip bgp flap-statistics route-map WORD",
7604 SHOW_STR
7605 IP_STR
7606 BGP_STR
7607 "Display flap statistics of routes\n"
7608 "Display routes matching the route-map\n"
7609 "A route-map to match on\n")
7610{
7611 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7612 bgp_show_type_flap_route_map);
7613}
7614
Balaji3921cc52015-05-16 23:12:17 +05307615ALIAS (show_ip_bgp_flap_route_map,
7616 show_ip_bgp_damp_flap_route_map_cmd,
7617 "show ip bgp dampening flap-statistics route-map WORD",
7618 SHOW_STR
7619 IP_STR
7620 BGP_STR
7621 "Display detailed information about dampening\n"
7622 "Display flap statistics of routes\n"
7623 "Display routes matching the route-map\n"
7624 "A route-map to match on\n")
7625
paul718e3742002-12-13 20:15:29 +00007626DEFUN (show_ip_bgp_ipv4_route_map,
7627 show_ip_bgp_ipv4_route_map_cmd,
7628 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7629 SHOW_STR
7630 IP_STR
7631 BGP_STR
7632 "Address family\n"
7633 "Address Family modifier\n"
7634 "Address Family modifier\n"
7635 "Display routes matching the route-map\n"
7636 "A route-map to match on\n")
7637{
7638 if (strncmp (argv[0], "m", 1) == 0)
7639 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7640 bgp_show_type_route_map);
7641
7642 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7643 bgp_show_type_route_map);
7644}
7645
7646DEFUN (show_bgp_route_map,
7647 show_bgp_route_map_cmd,
7648 "show bgp route-map WORD",
7649 SHOW_STR
7650 BGP_STR
7651 "Display routes matching the route-map\n"
7652 "A route-map to match on\n")
7653{
7654 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7655 bgp_show_type_route_map);
7656}
7657
7658ALIAS (show_bgp_route_map,
7659 show_bgp_ipv6_route_map_cmd,
7660 "show bgp ipv6 route-map WORD",
7661 SHOW_STR
7662 BGP_STR
7663 "Address family\n"
7664 "Display routes matching the route-map\n"
7665 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007666
paul718e3742002-12-13 20:15:29 +00007667DEFUN (show_ip_bgp_cidr_only,
7668 show_ip_bgp_cidr_only_cmd,
7669 "show ip bgp cidr-only",
7670 SHOW_STR
7671 IP_STR
7672 BGP_STR
7673 "Display only routes with non-natural netmasks\n")
7674{
7675 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007676 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007677}
7678
7679DEFUN (show_ip_bgp_flap_cidr_only,
7680 show_ip_bgp_flap_cidr_only_cmd,
7681 "show ip bgp flap-statistics cidr-only",
7682 SHOW_STR
7683 IP_STR
7684 BGP_STR
7685 "Display flap statistics of routes\n"
7686 "Display only routes with non-natural netmasks\n")
7687{
7688 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007689 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007690}
7691
Balaji3921cc52015-05-16 23:12:17 +05307692ALIAS (show_ip_bgp_flap_cidr_only,
7693 show_ip_bgp_damp_flap_cidr_only_cmd,
7694 "show ip bgp dampening flap-statistics cidr-only",
7695 SHOW_STR
7696 IP_STR
7697 BGP_STR
7698 "Display detailed information about dampening\n"
7699 "Display flap statistics of routes\n"
7700 "Display only routes with non-natural netmasks\n")
7701
paul718e3742002-12-13 20:15:29 +00007702DEFUN (show_ip_bgp_ipv4_cidr_only,
7703 show_ip_bgp_ipv4_cidr_only_cmd,
7704 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7705 SHOW_STR
7706 IP_STR
7707 BGP_STR
7708 "Address family\n"
7709 "Address Family modifier\n"
7710 "Address Family modifier\n"
7711 "Display only routes with non-natural netmasks\n")
7712{
7713 if (strncmp (argv[0], "m", 1) == 0)
7714 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007715 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007716
7717 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007718 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007719}
David Lamparter6b0655a2014-06-04 06:53:35 +02007720
paul718e3742002-12-13 20:15:29 +00007721DEFUN (show_ip_bgp_community_all,
7722 show_ip_bgp_community_all_cmd,
7723 "show ip bgp community",
7724 SHOW_STR
7725 IP_STR
7726 BGP_STR
7727 "Display routes matching the communities\n")
7728{
7729 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007730 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007731}
7732
7733DEFUN (show_ip_bgp_ipv4_community_all,
7734 show_ip_bgp_ipv4_community_all_cmd,
7735 "show ip bgp ipv4 (unicast|multicast) community",
7736 SHOW_STR
7737 IP_STR
7738 BGP_STR
7739 "Address family\n"
7740 "Address Family modifier\n"
7741 "Address Family modifier\n"
7742 "Display routes matching the communities\n")
7743{
7744 if (strncmp (argv[0], "m", 1) == 0)
7745 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007746 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007747
7748 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007749 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007750}
7751
7752#ifdef HAVE_IPV6
7753DEFUN (show_bgp_community_all,
7754 show_bgp_community_all_cmd,
7755 "show bgp community",
7756 SHOW_STR
7757 BGP_STR
7758 "Display routes matching the communities\n")
7759{
7760 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007761 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007762}
7763
7764ALIAS (show_bgp_community_all,
7765 show_bgp_ipv6_community_all_cmd,
7766 "show bgp ipv6 community",
7767 SHOW_STR
7768 BGP_STR
7769 "Address family\n"
7770 "Display routes matching the communities\n")
7771
7772/* old command */
7773DEFUN (show_ipv6_bgp_community_all,
7774 show_ipv6_bgp_community_all_cmd,
7775 "show ipv6 bgp community",
7776 SHOW_STR
7777 IPV6_STR
7778 BGP_STR
7779 "Display routes matching the communities\n")
7780{
7781 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007782 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007783}
7784
7785/* old command */
7786DEFUN (show_ipv6_mbgp_community_all,
7787 show_ipv6_mbgp_community_all_cmd,
7788 "show ipv6 mbgp community",
7789 SHOW_STR
7790 IPV6_STR
7791 MBGP_STR
7792 "Display routes matching the communities\n")
7793{
7794 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007795 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007796}
7797#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007798
paul94f2b392005-06-28 12:44:16 +00007799static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007800bgp_show_community (struct vty *vty, const char *view_name, int argc,
7801 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007802{
7803 struct community *com;
7804 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007805 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007806 int i;
7807 char *str;
7808 int first = 0;
7809
Michael Lambert95cbbd22010-07-23 14:43:04 -04007810 /* BGP structure lookup */
7811 if (view_name)
7812 {
7813 bgp = bgp_lookup_by_name (view_name);
7814 if (bgp == NULL)
7815 {
7816 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7817 return CMD_WARNING;
7818 }
7819 }
7820 else
7821 {
7822 bgp = bgp_get_default ();
7823 if (bgp == NULL)
7824 {
7825 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7826 return CMD_WARNING;
7827 }
7828 }
7829
paul718e3742002-12-13 20:15:29 +00007830 b = buffer_new (1024);
7831 for (i = 0; i < argc; i++)
7832 {
7833 if (first)
7834 buffer_putc (b, ' ');
7835 else
7836 {
7837 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7838 continue;
7839 first = 1;
7840 }
7841
7842 buffer_putstr (b, argv[i]);
7843 }
7844 buffer_putc (b, '\0');
7845
7846 str = buffer_getstr (b);
7847 buffer_free (b);
7848
7849 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007850 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007851 if (! com)
7852 {
7853 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7854 return CMD_WARNING;
7855 }
7856
Michael Lambert95cbbd22010-07-23 14:43:04 -04007857 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007858 (exact ? bgp_show_type_community_exact :
7859 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007860}
7861
7862DEFUN (show_ip_bgp_community,
7863 show_ip_bgp_community_cmd,
7864 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7865 SHOW_STR
7866 IP_STR
7867 BGP_STR
7868 "Display routes matching the communities\n"
7869 "community number\n"
7870 "Do not send outside local AS (well-known community)\n"
7871 "Do not advertise to any peer (well-known community)\n"
7872 "Do not export to next AS (well-known community)\n")
7873{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007874 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007875}
7876
7877ALIAS (show_ip_bgp_community,
7878 show_ip_bgp_community2_cmd,
7879 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7880 SHOW_STR
7881 IP_STR
7882 BGP_STR
7883 "Display routes matching the communities\n"
7884 "community number\n"
7885 "Do not send outside local AS (well-known community)\n"
7886 "Do not advertise to any peer (well-known community)\n"
7887 "Do not export to next AS (well-known community)\n"
7888 "community number\n"
7889 "Do not send outside local AS (well-known community)\n"
7890 "Do not advertise to any peer (well-known community)\n"
7891 "Do not export to next AS (well-known community)\n")
7892
7893ALIAS (show_ip_bgp_community,
7894 show_ip_bgp_community3_cmd,
7895 "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)",
7896 SHOW_STR
7897 IP_STR
7898 BGP_STR
7899 "Display routes matching the communities\n"
7900 "community number\n"
7901 "Do not send outside local AS (well-known community)\n"
7902 "Do not advertise to any peer (well-known community)\n"
7903 "Do not export to next AS (well-known community)\n"
7904 "community number\n"
7905 "Do not send outside local AS (well-known community)\n"
7906 "Do not advertise to any peer (well-known community)\n"
7907 "Do not export to next AS (well-known community)\n"
7908 "community number\n"
7909 "Do not send outside local AS (well-known community)\n"
7910 "Do not advertise to any peer (well-known community)\n"
7911 "Do not export to next AS (well-known community)\n")
7912
7913ALIAS (show_ip_bgp_community,
7914 show_ip_bgp_community4_cmd,
7915 "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)",
7916 SHOW_STR
7917 IP_STR
7918 BGP_STR
7919 "Display routes matching the communities\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n"
7928 "community number\n"
7929 "Do not send outside local AS (well-known community)\n"
7930 "Do not advertise to any peer (well-known community)\n"
7931 "Do not export to next AS (well-known community)\n"
7932 "community number\n"
7933 "Do not send outside local AS (well-known community)\n"
7934 "Do not advertise to any peer (well-known community)\n"
7935 "Do not export to next AS (well-known community)\n")
7936
7937DEFUN (show_ip_bgp_ipv4_community,
7938 show_ip_bgp_ipv4_community_cmd,
7939 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7940 SHOW_STR
7941 IP_STR
7942 BGP_STR
7943 "Address family\n"
7944 "Address Family modifier\n"
7945 "Address Family modifier\n"
7946 "Display routes matching the communities\n"
7947 "community number\n"
7948 "Do not send outside local AS (well-known community)\n"
7949 "Do not advertise to any peer (well-known community)\n"
7950 "Do not export to next AS (well-known community)\n")
7951{
7952 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007953 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007954
Michael Lambert95cbbd22010-07-23 14:43:04 -04007955 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007956}
7957
7958ALIAS (show_ip_bgp_ipv4_community,
7959 show_ip_bgp_ipv4_community2_cmd,
7960 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7961 SHOW_STR
7962 IP_STR
7963 BGP_STR
7964 "Address family\n"
7965 "Address Family modifier\n"
7966 "Address Family modifier\n"
7967 "Display routes matching the communities\n"
7968 "community number\n"
7969 "Do not send outside local AS (well-known community)\n"
7970 "Do not advertise to any peer (well-known community)\n"
7971 "Do not export to next AS (well-known community)\n"
7972 "community number\n"
7973 "Do not send outside local AS (well-known community)\n"
7974 "Do not advertise to any peer (well-known community)\n"
7975 "Do not export to next AS (well-known community)\n")
7976
7977ALIAS (show_ip_bgp_ipv4_community,
7978 show_ip_bgp_ipv4_community3_cmd,
7979 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7980 SHOW_STR
7981 IP_STR
7982 BGP_STR
7983 "Address family\n"
7984 "Address Family modifier\n"
7985 "Address Family modifier\n"
7986 "Display routes matching the communities\n"
7987 "community number\n"
7988 "Do not send outside local AS (well-known community)\n"
7989 "Do not advertise to any peer (well-known community)\n"
7990 "Do not export to next AS (well-known community)\n"
7991 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n"
7995 "community number\n"
7996 "Do not send outside local AS (well-known community)\n"
7997 "Do not advertise to any peer (well-known community)\n"
7998 "Do not export to next AS (well-known community)\n")
7999
8000ALIAS (show_ip_bgp_ipv4_community,
8001 show_ip_bgp_ipv4_community4_cmd,
8002 "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)",
8003 SHOW_STR
8004 IP_STR
8005 BGP_STR
8006 "Address family\n"
8007 "Address Family modifier\n"
8008 "Address Family modifier\n"
8009 "Display routes matching the communities\n"
8010 "community number\n"
8011 "Do not send outside local AS (well-known community)\n"
8012 "Do not advertise to any peer (well-known community)\n"
8013 "Do not export to next AS (well-known community)\n"
8014 "community number\n"
8015 "Do not send outside local AS (well-known community)\n"
8016 "Do not advertise to any peer (well-known community)\n"
8017 "Do not export to next AS (well-known community)\n"
8018 "community number\n"
8019 "Do not send outside local AS (well-known community)\n"
8020 "Do not advertise to any peer (well-known community)\n"
8021 "Do not export to next AS (well-known community)\n"
8022 "community number\n"
8023 "Do not send outside local AS (well-known community)\n"
8024 "Do not advertise to any peer (well-known community)\n"
8025 "Do not export to next AS (well-known community)\n")
8026
Michael Lambert95cbbd22010-07-23 14:43:04 -04008027DEFUN (show_bgp_view_afi_safi_community_all,
8028 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008029 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008030 SHOW_STR
8031 BGP_STR
8032 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008033 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008034 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008035 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008036 "Address Family modifier\n"
8037 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008038 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008039{
8040 int afi;
8041 int safi;
8042 struct bgp *bgp;
8043
8044 /* BGP structure lookup. */
8045 bgp = bgp_lookup_by_name (argv[0]);
8046 if (bgp == NULL)
8047 {
8048 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8049 return CMD_WARNING;
8050 }
8051
Michael Lambert95cbbd22010-07-23 14:43:04 -04008052 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8053 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008054 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8055}
8056
8057DEFUN (show_bgp_view_afi_safi_community,
8058 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008059 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008060 SHOW_STR
8061 BGP_STR
8062 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008063 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008064 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008065 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008066 "Address family modifier\n"
8067 "Address family modifier\n"
8068 "Display routes matching the communities\n"
8069 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n")
8073{
8074 int afi;
8075 int safi;
8076
Michael Lambert95cbbd22010-07-23 14:43:04 -04008077 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8078 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8079 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04008080}
8081
8082ALIAS (show_bgp_view_afi_safi_community,
8083 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008084 "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 -04008085 SHOW_STR
8086 BGP_STR
8087 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008088 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008089 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008090 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008091 "Address family modifier\n"
8092 "Address family modifier\n"
8093 "Display routes matching the communities\n"
8094 "community number\n"
8095 "Do not send outside local AS (well-known community)\n"
8096 "Do not advertise to any peer (well-known community)\n"
8097 "Do not export to next AS (well-known community)\n"
8098 "community number\n"
8099 "Do not send outside local AS (well-known community)\n"
8100 "Do not advertise to any peer (well-known community)\n"
8101 "Do not export to next AS (well-known community)\n")
8102
8103ALIAS (show_bgp_view_afi_safi_community,
8104 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008105 "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 -04008106 SHOW_STR
8107 BGP_STR
8108 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008109 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008110 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008111 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008112 "Address family modifier\n"
8113 "Address family modifier\n"
8114 "Display routes matching the communities\n"
8115 "community number\n"
8116 "Do not send outside local AS (well-known community)\n"
8117 "Do not advertise to any peer (well-known community)\n"
8118 "Do not export to next AS (well-known community)\n"
8119 "community number\n"
8120 "Do not send outside local AS (well-known community)\n"
8121 "Do not advertise to any peer (well-known community)\n"
8122 "Do not export to next AS (well-known community)\n"
8123 "community number\n"
8124 "Do not send outside local AS (well-known community)\n"
8125 "Do not advertise to any peer (well-known community)\n"
8126 "Do not export to next AS (well-known community)\n")
8127
8128ALIAS (show_bgp_view_afi_safi_community,
8129 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008130 "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 -04008131 SHOW_STR
8132 BGP_STR
8133 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008134 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008135 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008136 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008137 "Address family modifier\n"
8138 "Address family modifier\n"
8139 "Display routes matching the communities\n"
8140 "community number\n"
8141 "Do not send outside local AS (well-known community)\n"
8142 "Do not advertise to any peer (well-known community)\n"
8143 "Do not export to next AS (well-known community)\n"
8144 "community number\n"
8145 "Do not send outside local AS (well-known community)\n"
8146 "Do not advertise to any peer (well-known community)\n"
8147 "Do not export to next AS (well-known community)\n"
8148 "community number\n"
8149 "Do not send outside local AS (well-known community)\n"
8150 "Do not advertise to any peer (well-known community)\n"
8151 "Do not export to next AS (well-known community)\n"
8152 "community number\n"
8153 "Do not send outside local AS (well-known community)\n"
8154 "Do not advertise to any peer (well-known community)\n"
8155 "Do not export to next AS (well-known community)\n")
8156
paul718e3742002-12-13 20:15:29 +00008157DEFUN (show_ip_bgp_community_exact,
8158 show_ip_bgp_community_exact_cmd,
8159 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8160 SHOW_STR
8161 IP_STR
8162 BGP_STR
8163 "Display routes matching the communities\n"
8164 "community number\n"
8165 "Do not send outside local AS (well-known community)\n"
8166 "Do not advertise to any peer (well-known community)\n"
8167 "Do not export to next AS (well-known community)\n"
8168 "Exact match of the communities")
8169{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008170 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008171}
8172
8173ALIAS (show_ip_bgp_community_exact,
8174 show_ip_bgp_community2_exact_cmd,
8175 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8176 SHOW_STR
8177 IP_STR
8178 BGP_STR
8179 "Display routes matching the communities\n"
8180 "community number\n"
8181 "Do not send outside local AS (well-known community)\n"
8182 "Do not advertise to any peer (well-known community)\n"
8183 "Do not export to next AS (well-known community)\n"
8184 "community number\n"
8185 "Do not send outside local AS (well-known community)\n"
8186 "Do not advertise to any peer (well-known community)\n"
8187 "Do not export to next AS (well-known community)\n"
8188 "Exact match of the communities")
8189
8190ALIAS (show_ip_bgp_community_exact,
8191 show_ip_bgp_community3_exact_cmd,
8192 "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",
8193 SHOW_STR
8194 IP_STR
8195 BGP_STR
8196 "Display routes matching the communities\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 "Exact match of the communities")
8210
8211ALIAS (show_ip_bgp_community_exact,
8212 show_ip_bgp_community4_exact_cmd,
8213 "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",
8214 SHOW_STR
8215 IP_STR
8216 BGP_STR
8217 "Display routes matching the communities\n"
8218 "community number\n"
8219 "Do not send outside local AS (well-known community)\n"
8220 "Do not advertise to any peer (well-known community)\n"
8221 "Do not export to next AS (well-known community)\n"
8222 "community number\n"
8223 "Do not send outside local AS (well-known community)\n"
8224 "Do not advertise to any peer (well-known community)\n"
8225 "Do not export to next AS (well-known community)\n"
8226 "community number\n"
8227 "Do not send outside local AS (well-known community)\n"
8228 "Do not advertise to any peer (well-known community)\n"
8229 "Do not export to next AS (well-known community)\n"
8230 "community number\n"
8231 "Do not send outside local AS (well-known community)\n"
8232 "Do not advertise to any peer (well-known community)\n"
8233 "Do not export to next AS (well-known community)\n"
8234 "Exact match of the communities")
8235
8236DEFUN (show_ip_bgp_ipv4_community_exact,
8237 show_ip_bgp_ipv4_community_exact_cmd,
8238 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8239 SHOW_STR
8240 IP_STR
8241 BGP_STR
8242 "Address family\n"
8243 "Address Family modifier\n"
8244 "Address Family modifier\n"
8245 "Display routes matching the communities\n"
8246 "community number\n"
8247 "Do not send outside local AS (well-known community)\n"
8248 "Do not advertise to any peer (well-known community)\n"
8249 "Do not export to next AS (well-known community)\n"
8250 "Exact match of the communities")
8251{
8252 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008253 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008254
Michael Lambert95cbbd22010-07-23 14:43:04 -04008255 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008256}
8257
8258ALIAS (show_ip_bgp_ipv4_community_exact,
8259 show_ip_bgp_ipv4_community2_exact_cmd,
8260 "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",
8261 SHOW_STR
8262 IP_STR
8263 BGP_STR
8264 "Address family\n"
8265 "Address Family modifier\n"
8266 "Address Family modifier\n"
8267 "Display routes matching the communities\n"
8268 "community number\n"
8269 "Do not send outside local AS (well-known community)\n"
8270 "Do not advertise to any peer (well-known community)\n"
8271 "Do not export to next AS (well-known community)\n"
8272 "community number\n"
8273 "Do not send outside local AS (well-known community)\n"
8274 "Do not advertise to any peer (well-known community)\n"
8275 "Do not export to next AS (well-known community)\n"
8276 "Exact match of the communities")
8277
8278ALIAS (show_ip_bgp_ipv4_community_exact,
8279 show_ip_bgp_ipv4_community3_exact_cmd,
8280 "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",
8281 SHOW_STR
8282 IP_STR
8283 BGP_STR
8284 "Address family\n"
8285 "Address Family modifier\n"
8286 "Address Family modifier\n"
8287 "Display routes matching the communities\n"
8288 "community number\n"
8289 "Do not send outside local AS (well-known community)\n"
8290 "Do not advertise to any peer (well-known community)\n"
8291 "Do not export to next AS (well-known community)\n"
8292 "community number\n"
8293 "Do not send outside local AS (well-known community)\n"
8294 "Do not advertise to any peer (well-known community)\n"
8295 "Do not export to next AS (well-known community)\n"
8296 "community number\n"
8297 "Do not send outside local AS (well-known community)\n"
8298 "Do not advertise to any peer (well-known community)\n"
8299 "Do not export to next AS (well-known community)\n"
8300 "Exact match of the communities")
8301
8302ALIAS (show_ip_bgp_ipv4_community_exact,
8303 show_ip_bgp_ipv4_community4_exact_cmd,
8304 "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",
8305 SHOW_STR
8306 IP_STR
8307 BGP_STR
8308 "Address family\n"
8309 "Address Family modifier\n"
8310 "Address Family modifier\n"
8311 "Display routes matching the communities\n"
8312 "community number\n"
8313 "Do not send outside local AS (well-known community)\n"
8314 "Do not advertise to any peer (well-known community)\n"
8315 "Do not export to next AS (well-known community)\n"
8316 "community number\n"
8317 "Do not send outside local AS (well-known community)\n"
8318 "Do not advertise to any peer (well-known community)\n"
8319 "Do not export to next AS (well-known community)\n"
8320 "community number\n"
8321 "Do not send outside local AS (well-known community)\n"
8322 "Do not advertise to any peer (well-known community)\n"
8323 "Do not export to next AS (well-known community)\n"
8324 "community number\n"
8325 "Do not send outside local AS (well-known community)\n"
8326 "Do not advertise to any peer (well-known community)\n"
8327 "Do not export to next AS (well-known community)\n"
8328 "Exact match of the communities")
8329
8330#ifdef HAVE_IPV6
8331DEFUN (show_bgp_community,
8332 show_bgp_community_cmd,
8333 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8334 SHOW_STR
8335 BGP_STR
8336 "Display routes matching the communities\n"
8337 "community number\n"
8338 "Do not send outside local AS (well-known community)\n"
8339 "Do not advertise to any peer (well-known community)\n"
8340 "Do not export to next AS (well-known community)\n")
8341{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008342 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008343}
8344
8345ALIAS (show_bgp_community,
8346 show_bgp_ipv6_community_cmd,
8347 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8348 SHOW_STR
8349 BGP_STR
8350 "Address family\n"
8351 "Display routes matching the communities\n"
8352 "community number\n"
8353 "Do not send outside local AS (well-known community)\n"
8354 "Do not advertise to any peer (well-known community)\n"
8355 "Do not export to next AS (well-known community)\n")
8356
8357ALIAS (show_bgp_community,
8358 show_bgp_community2_cmd,
8359 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8360 SHOW_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
8372ALIAS (show_bgp_community,
8373 show_bgp_ipv6_community2_cmd,
8374 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8375 SHOW_STR
8376 BGP_STR
8377 "Address family\n"
8378 "Display routes matching the communities\n"
8379 "community number\n"
8380 "Do not send outside local AS (well-known community)\n"
8381 "Do not advertise to any peer (well-known community)\n"
8382 "Do not export to next AS (well-known community)\n"
8383 "community number\n"
8384 "Do not send outside local AS (well-known community)\n"
8385 "Do not advertise to any peer (well-known community)\n"
8386 "Do not export to next AS (well-known community)\n")
8387
8388ALIAS (show_bgp_community,
8389 show_bgp_community3_cmd,
8390 "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)",
8391 SHOW_STR
8392 BGP_STR
8393 "Display routes matching the communities\n"
8394 "community number\n"
8395 "Do not send outside local AS (well-known community)\n"
8396 "Do not advertise to any peer (well-known community)\n"
8397 "Do not export to next AS (well-known community)\n"
8398 "community number\n"
8399 "Do not send outside local AS (well-known community)\n"
8400 "Do not advertise to any peer (well-known community)\n"
8401 "Do not export to next AS (well-known community)\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n")
8406
8407ALIAS (show_bgp_community,
8408 show_bgp_ipv6_community3_cmd,
8409 "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)",
8410 SHOW_STR
8411 BGP_STR
8412 "Address family\n"
8413 "Display routes matching the communities\n"
8414 "community number\n"
8415 "Do not send outside local AS (well-known community)\n"
8416 "Do not advertise to any peer (well-known community)\n"
8417 "Do not export to next AS (well-known community)\n"
8418 "community number\n"
8419 "Do not send outside local AS (well-known community)\n"
8420 "Do not advertise to any peer (well-known community)\n"
8421 "Do not export to next AS (well-known community)\n"
8422 "community number\n"
8423 "Do not send outside local AS (well-known community)\n"
8424 "Do not advertise to any peer (well-known community)\n"
8425 "Do not export to next AS (well-known community)\n")
8426
8427ALIAS (show_bgp_community,
8428 show_bgp_community4_cmd,
8429 "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)",
8430 SHOW_STR
8431 BGP_STR
8432 "Display routes matching the communities\n"
8433 "community number\n"
8434 "Do not send outside local AS (well-known community)\n"
8435 "Do not advertise to any peer (well-known community)\n"
8436 "Do not export to next AS (well-known community)\n"
8437 "community number\n"
8438 "Do not send outside local AS (well-known community)\n"
8439 "Do not advertise to any peer (well-known community)\n"
8440 "Do not export to next AS (well-known community)\n"
8441 "community number\n"
8442 "Do not send outside local AS (well-known community)\n"
8443 "Do not advertise to any peer (well-known community)\n"
8444 "Do not export to next AS (well-known community)\n"
8445 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n")
8449
8450ALIAS (show_bgp_community,
8451 show_bgp_ipv6_community4_cmd,
8452 "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)",
8453 SHOW_STR
8454 BGP_STR
8455 "Address family\n"
8456 "Display routes matching the communities\n"
8457 "community number\n"
8458 "Do not send outside local AS (well-known community)\n"
8459 "Do not advertise to any peer (well-known community)\n"
8460 "Do not export to next AS (well-known community)\n"
8461 "community number\n"
8462 "Do not send outside local AS (well-known community)\n"
8463 "Do not advertise to any peer (well-known community)\n"
8464 "Do not export to next AS (well-known community)\n"
8465 "community number\n"
8466 "Do not send outside local AS (well-known community)\n"
8467 "Do not advertise to any peer (well-known community)\n"
8468 "Do not export to next AS (well-known community)\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n")
8473
8474/* old command */
8475DEFUN (show_ipv6_bgp_community,
8476 show_ipv6_bgp_community_cmd,
8477 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8478 SHOW_STR
8479 IPV6_STR
8480 BGP_STR
8481 "Display routes matching the communities\n"
8482 "community number\n"
8483 "Do not send outside local AS (well-known community)\n"
8484 "Do not advertise to any peer (well-known community)\n"
8485 "Do not export to next AS (well-known community)\n")
8486{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008487 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008488}
8489
8490/* old command */
8491ALIAS (show_ipv6_bgp_community,
8492 show_ipv6_bgp_community2_cmd,
8493 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8494 SHOW_STR
8495 IPV6_STR
8496 BGP_STR
8497 "Display routes matching the communities\n"
8498 "community number\n"
8499 "Do not send outside local AS (well-known community)\n"
8500 "Do not advertise to any peer (well-known community)\n"
8501 "Do not export to next AS (well-known community)\n"
8502 "community number\n"
8503 "Do not send outside local AS (well-known community)\n"
8504 "Do not advertise to any peer (well-known community)\n"
8505 "Do not export to next AS (well-known community)\n")
8506
8507/* old command */
8508ALIAS (show_ipv6_bgp_community,
8509 show_ipv6_bgp_community3_cmd,
8510 "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)",
8511 SHOW_STR
8512 IPV6_STR
8513 BGP_STR
8514 "Display routes matching the communities\n"
8515 "community number\n"
8516 "Do not send outside local AS (well-known community)\n"
8517 "Do not advertise to any peer (well-known community)\n"
8518 "Do not export to next AS (well-known community)\n"
8519 "community number\n"
8520 "Do not send outside local AS (well-known community)\n"
8521 "Do not advertise to any peer (well-known community)\n"
8522 "Do not export to next AS (well-known community)\n"
8523 "community number\n"
8524 "Do not send outside local AS (well-known community)\n"
8525 "Do not advertise to any peer (well-known community)\n"
8526 "Do not export to next AS (well-known community)\n")
8527
8528/* old command */
8529ALIAS (show_ipv6_bgp_community,
8530 show_ipv6_bgp_community4_cmd,
8531 "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)",
8532 SHOW_STR
8533 IPV6_STR
8534 BGP_STR
8535 "Display routes matching the communities\n"
8536 "community number\n"
8537 "Do not send outside local AS (well-known community)\n"
8538 "Do not advertise to any peer (well-known community)\n"
8539 "Do not export to next AS (well-known community)\n"
8540 "community number\n"
8541 "Do not send outside local AS (well-known community)\n"
8542 "Do not advertise to any peer (well-known community)\n"
8543 "Do not export to next AS (well-known community)\n"
8544 "community number\n"
8545 "Do not send outside local AS (well-known community)\n"
8546 "Do not advertise to any peer (well-known community)\n"
8547 "Do not export to next AS (well-known community)\n"
8548 "community number\n"
8549 "Do not send outside local AS (well-known community)\n"
8550 "Do not advertise to any peer (well-known community)\n"
8551 "Do not export to next AS (well-known community)\n")
8552
8553DEFUN (show_bgp_community_exact,
8554 show_bgp_community_exact_cmd,
8555 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8556 SHOW_STR
8557 BGP_STR
8558 "Display routes matching the communities\n"
8559 "community number\n"
8560 "Do not send outside local AS (well-known community)\n"
8561 "Do not advertise to any peer (well-known community)\n"
8562 "Do not export to next AS (well-known community)\n"
8563 "Exact match of the communities")
8564{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008565 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008566}
8567
8568ALIAS (show_bgp_community_exact,
8569 show_bgp_ipv6_community_exact_cmd,
8570 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8571 SHOW_STR
8572 BGP_STR
8573 "Address family\n"
8574 "Display routes matching the communities\n"
8575 "community number\n"
8576 "Do not send outside local AS (well-known community)\n"
8577 "Do not advertise to any peer (well-known community)\n"
8578 "Do not export to next AS (well-known community)\n"
8579 "Exact match of the communities")
8580
8581ALIAS (show_bgp_community_exact,
8582 show_bgp_community2_exact_cmd,
8583 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8584 SHOW_STR
8585 BGP_STR
8586 "Display routes matching the communities\n"
8587 "community number\n"
8588 "Do not send outside local AS (well-known community)\n"
8589 "Do not advertise to any peer (well-known community)\n"
8590 "Do not export to next AS (well-known community)\n"
8591 "community number\n"
8592 "Do not send outside local AS (well-known community)\n"
8593 "Do not advertise to any peer (well-known community)\n"
8594 "Do not export to next AS (well-known community)\n"
8595 "Exact match of the communities")
8596
8597ALIAS (show_bgp_community_exact,
8598 show_bgp_ipv6_community2_exact_cmd,
8599 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8600 SHOW_STR
8601 BGP_STR
8602 "Address family\n"
8603 "Display routes matching the communities\n"
8604 "community number\n"
8605 "Do not send outside local AS (well-known community)\n"
8606 "Do not advertise to any peer (well-known community)\n"
8607 "Do not export to next AS (well-known community)\n"
8608 "community number\n"
8609 "Do not send outside local AS (well-known community)\n"
8610 "Do not advertise to any peer (well-known community)\n"
8611 "Do not export to next AS (well-known community)\n"
8612 "Exact match of the communities")
8613
8614ALIAS (show_bgp_community_exact,
8615 show_bgp_community3_exact_cmd,
8616 "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",
8617 SHOW_STR
8618 BGP_STR
8619 "Display routes matching the communities\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 "Exact match of the communities")
8633
8634ALIAS (show_bgp_community_exact,
8635 show_bgp_ipv6_community3_exact_cmd,
8636 "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",
8637 SHOW_STR
8638 BGP_STR
8639 "Address family\n"
8640 "Display routes matching the communities\n"
8641 "community number\n"
8642 "Do not send outside local AS (well-known community)\n"
8643 "Do not advertise to any peer (well-known community)\n"
8644 "Do not export to next AS (well-known community)\n"
8645 "community number\n"
8646 "Do not send outside local AS (well-known community)\n"
8647 "Do not advertise to any peer (well-known community)\n"
8648 "Do not export to next AS (well-known community)\n"
8649 "community number\n"
8650 "Do not send outside local AS (well-known community)\n"
8651 "Do not advertise to any peer (well-known community)\n"
8652 "Do not export to next AS (well-known community)\n"
8653 "Exact match of the communities")
8654
8655ALIAS (show_bgp_community_exact,
8656 show_bgp_community4_exact_cmd,
8657 "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",
8658 SHOW_STR
8659 BGP_STR
8660 "Display routes matching the communities\n"
8661 "community number\n"
8662 "Do not send outside local AS (well-known community)\n"
8663 "Do not advertise to any peer (well-known community)\n"
8664 "Do not export to next AS (well-known community)\n"
8665 "community number\n"
8666 "Do not send outside local AS (well-known community)\n"
8667 "Do not advertise to any peer (well-known community)\n"
8668 "Do not export to next AS (well-known community)\n"
8669 "community number\n"
8670 "Do not send outside local AS (well-known community)\n"
8671 "Do not advertise to any peer (well-known community)\n"
8672 "Do not export to next AS (well-known community)\n"
8673 "community number\n"
8674 "Do not send outside local AS (well-known community)\n"
8675 "Do not advertise to any peer (well-known community)\n"
8676 "Do not export to next AS (well-known community)\n"
8677 "Exact match of the communities")
8678
8679ALIAS (show_bgp_community_exact,
8680 show_bgp_ipv6_community4_exact_cmd,
8681 "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",
8682 SHOW_STR
8683 BGP_STR
8684 "Address family\n"
8685 "Display routes matching the communities\n"
8686 "community number\n"
8687 "Do not send outside local AS (well-known community)\n"
8688 "Do not advertise to any peer (well-known community)\n"
8689 "Do not export to next AS (well-known community)\n"
8690 "community number\n"
8691 "Do not send outside local AS (well-known community)\n"
8692 "Do not advertise to any peer (well-known community)\n"
8693 "Do not export to next AS (well-known community)\n"
8694 "community number\n"
8695 "Do not send outside local AS (well-known community)\n"
8696 "Do not advertise to any peer (well-known community)\n"
8697 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8703
8704/* old command */
8705DEFUN (show_ipv6_bgp_community_exact,
8706 show_ipv6_bgp_community_exact_cmd,
8707 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8708 SHOW_STR
8709 IPV6_STR
8710 BGP_STR
8711 "Display routes matching the communities\n"
8712 "community number\n"
8713 "Do not send outside local AS (well-known community)\n"
8714 "Do not advertise to any peer (well-known community)\n"
8715 "Do not export to next AS (well-known community)\n"
8716 "Exact match of the communities")
8717{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008718 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008719}
8720
8721/* old command */
8722ALIAS (show_ipv6_bgp_community_exact,
8723 show_ipv6_bgp_community2_exact_cmd,
8724 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8725 SHOW_STR
8726 IPV6_STR
8727 BGP_STR
8728 "Display routes matching the communities\n"
8729 "community number\n"
8730 "Do not send outside local AS (well-known community)\n"
8731 "Do not advertise to any peer (well-known community)\n"
8732 "Do not export to next AS (well-known community)\n"
8733 "community number\n"
8734 "Do not send outside local AS (well-known community)\n"
8735 "Do not advertise to any peer (well-known community)\n"
8736 "Do not export to next AS (well-known community)\n"
8737 "Exact match of the communities")
8738
8739/* old command */
8740ALIAS (show_ipv6_bgp_community_exact,
8741 show_ipv6_bgp_community3_exact_cmd,
8742 "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",
8743 SHOW_STR
8744 IPV6_STR
8745 BGP_STR
8746 "Display routes matching the communities\n"
8747 "community number\n"
8748 "Do not send outside local AS (well-known community)\n"
8749 "Do not advertise to any peer (well-known community)\n"
8750 "Do not export to next AS (well-known community)\n"
8751 "community number\n"
8752 "Do not send outside local AS (well-known community)\n"
8753 "Do not advertise to any peer (well-known community)\n"
8754 "Do not export to next AS (well-known community)\n"
8755 "community number\n"
8756 "Do not send outside local AS (well-known community)\n"
8757 "Do not advertise to any peer (well-known community)\n"
8758 "Do not export to next AS (well-known community)\n"
8759 "Exact match of the communities")
8760
8761/* old command */
8762ALIAS (show_ipv6_bgp_community_exact,
8763 show_ipv6_bgp_community4_exact_cmd,
8764 "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",
8765 SHOW_STR
8766 IPV6_STR
8767 BGP_STR
8768 "Display routes matching the communities\n"
8769 "community number\n"
8770 "Do not send outside local AS (well-known community)\n"
8771 "Do not advertise to any peer (well-known community)\n"
8772 "Do not export to next AS (well-known community)\n"
8773 "community number\n"
8774 "Do not send outside local AS (well-known community)\n"
8775 "Do not advertise to any peer (well-known community)\n"
8776 "Do not export to next AS (well-known community)\n"
8777 "community number\n"
8778 "Do not send outside local AS (well-known community)\n"
8779 "Do not advertise to any peer (well-known community)\n"
8780 "Do not export to next AS (well-known community)\n"
8781 "community number\n"
8782 "Do not send outside local AS (well-known community)\n"
8783 "Do not advertise to any peer (well-known community)\n"
8784 "Do not export to next AS (well-known community)\n"
8785 "Exact match of the communities")
8786
8787/* old command */
8788DEFUN (show_ipv6_mbgp_community,
8789 show_ipv6_mbgp_community_cmd,
8790 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8791 SHOW_STR
8792 IPV6_STR
8793 MBGP_STR
8794 "Display routes matching the communities\n"
8795 "community number\n"
8796 "Do not send outside local AS (well-known community)\n"
8797 "Do not advertise to any peer (well-known community)\n"
8798 "Do not export to next AS (well-known community)\n")
8799{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008800 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008801}
8802
8803/* old command */
8804ALIAS (show_ipv6_mbgp_community,
8805 show_ipv6_mbgp_community2_cmd,
8806 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8807 SHOW_STR
8808 IPV6_STR
8809 MBGP_STR
8810 "Display routes matching the communities\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 "community number\n"
8816 "Do not send outside local AS (well-known community)\n"
8817 "Do not advertise to any peer (well-known community)\n"
8818 "Do not export to next AS (well-known community)\n")
8819
8820/* old command */
8821ALIAS (show_ipv6_mbgp_community,
8822 show_ipv6_mbgp_community3_cmd,
8823 "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)",
8824 SHOW_STR
8825 IPV6_STR
8826 MBGP_STR
8827 "Display routes matching the communities\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 "community number\n"
8837 "Do not send outside local AS (well-known community)\n"
8838 "Do not advertise to any peer (well-known community)\n"
8839 "Do not export to next AS (well-known community)\n")
8840
8841/* old command */
8842ALIAS (show_ipv6_mbgp_community,
8843 show_ipv6_mbgp_community4_cmd,
8844 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8845 SHOW_STR
8846 IPV6_STR
8847 MBGP_STR
8848 "Display routes matching the communities\n"
8849 "community number\n"
8850 "Do not send outside local AS (well-known community)\n"
8851 "Do not advertise to any peer (well-known community)\n"
8852 "Do not export to next AS (well-known community)\n"
8853 "community number\n"
8854 "Do not send outside local AS (well-known community)\n"
8855 "Do not advertise to any peer (well-known community)\n"
8856 "Do not export to next AS (well-known community)\n"
8857 "community number\n"
8858 "Do not send outside local AS (well-known community)\n"
8859 "Do not advertise to any peer (well-known community)\n"
8860 "Do not export to next AS (well-known community)\n"
8861 "community number\n"
8862 "Do not send outside local AS (well-known community)\n"
8863 "Do not advertise to any peer (well-known community)\n"
8864 "Do not export to next AS (well-known community)\n")
8865
8866/* old command */
8867DEFUN (show_ipv6_mbgp_community_exact,
8868 show_ipv6_mbgp_community_exact_cmd,
8869 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8870 SHOW_STR
8871 IPV6_STR
8872 MBGP_STR
8873 "Display routes matching the communities\n"
8874 "community number\n"
8875 "Do not send outside local AS (well-known community)\n"
8876 "Do not advertise to any peer (well-known community)\n"
8877 "Do not export to next AS (well-known community)\n"
8878 "Exact match of the communities")
8879{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008880 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008881}
8882
8883/* old command */
8884ALIAS (show_ipv6_mbgp_community_exact,
8885 show_ipv6_mbgp_community2_exact_cmd,
8886 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8887 SHOW_STR
8888 IPV6_STR
8889 MBGP_STR
8890 "Display routes matching the communities\n"
8891 "community number\n"
8892 "Do not send outside local AS (well-known community)\n"
8893 "Do not advertise to any peer (well-known community)\n"
8894 "Do not export to next AS (well-known community)\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
8901/* old command */
8902ALIAS (show_ipv6_mbgp_community_exact,
8903 show_ipv6_mbgp_community3_exact_cmd,
8904 "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",
8905 SHOW_STR
8906 IPV6_STR
8907 MBGP_STR
8908 "Display routes matching the communities\n"
8909 "community number\n"
8910 "Do not send outside local AS (well-known community)\n"
8911 "Do not advertise to any peer (well-known community)\n"
8912 "Do not export to next AS (well-known community)\n"
8913 "community number\n"
8914 "Do not send outside local AS (well-known community)\n"
8915 "Do not advertise to any peer (well-known community)\n"
8916 "Do not export to next AS (well-known community)\n"
8917 "community number\n"
8918 "Do not send outside local AS (well-known community)\n"
8919 "Do not advertise to any peer (well-known community)\n"
8920 "Do not export to next AS (well-known community)\n"
8921 "Exact match of the communities")
8922
8923/* old command */
8924ALIAS (show_ipv6_mbgp_community_exact,
8925 show_ipv6_mbgp_community4_exact_cmd,
8926 "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",
8927 SHOW_STR
8928 IPV6_STR
8929 MBGP_STR
8930 "Display routes matching the communities\n"
8931 "community number\n"
8932 "Do not send outside local AS (well-known community)\n"
8933 "Do not advertise to any peer (well-known community)\n"
8934 "Do not export to next AS (well-known community)\n"
8935 "community number\n"
8936 "Do not send outside local AS (well-known community)\n"
8937 "Do not advertise to any peer (well-known community)\n"
8938 "Do not export to next AS (well-known community)\n"
8939 "community number\n"
8940 "Do not send outside local AS (well-known community)\n"
8941 "Do not advertise to any peer (well-known community)\n"
8942 "Do not export to next AS (well-known community)\n"
8943 "community number\n"
8944 "Do not send outside local AS (well-known community)\n"
8945 "Do not advertise to any peer (well-known community)\n"
8946 "Do not export to next AS (well-known community)\n"
8947 "Exact match of the communities")
8948#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008949
paul94f2b392005-06-28 12:44:16 +00008950static int
paulfd79ac92004-10-13 05:06:08 +00008951bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008952 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008953{
8954 struct community_list *list;
8955
hassofee6e4e2005-02-02 16:29:31 +00008956 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008957 if (list == NULL)
8958 {
8959 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8960 VTY_NEWLINE);
8961 return CMD_WARNING;
8962 }
8963
ajs5a646652004-11-05 01:25:55 +00008964 return bgp_show (vty, NULL, afi, safi,
8965 (exact ? bgp_show_type_community_list_exact :
8966 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008967}
8968
8969DEFUN (show_ip_bgp_community_list,
8970 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008971 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008972 SHOW_STR
8973 IP_STR
8974 BGP_STR
8975 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008976 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008977 "community-list name\n")
8978{
8979 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8980}
8981
8982DEFUN (show_ip_bgp_ipv4_community_list,
8983 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008984 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008985 SHOW_STR
8986 IP_STR
8987 BGP_STR
8988 "Address family\n"
8989 "Address Family modifier\n"
8990 "Address Family modifier\n"
8991 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008992 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008993 "community-list name\n")
8994{
8995 if (strncmp (argv[0], "m", 1) == 0)
8996 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8997
8998 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8999}
9000
9001DEFUN (show_ip_bgp_community_list_exact,
9002 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009003 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009004 SHOW_STR
9005 IP_STR
9006 BGP_STR
9007 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009008 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009009 "community-list name\n"
9010 "Exact match of the communities\n")
9011{
9012 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9013}
9014
9015DEFUN (show_ip_bgp_ipv4_community_list_exact,
9016 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009017 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009018 SHOW_STR
9019 IP_STR
9020 BGP_STR
9021 "Address family\n"
9022 "Address Family modifier\n"
9023 "Address Family modifier\n"
9024 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009025 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009026 "community-list name\n"
9027 "Exact match of the communities\n")
9028{
9029 if (strncmp (argv[0], "m", 1) == 0)
9030 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9031
9032 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9033}
9034
9035#ifdef HAVE_IPV6
9036DEFUN (show_bgp_community_list,
9037 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009038 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009039 SHOW_STR
9040 BGP_STR
9041 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009042 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009043 "community-list name\n")
9044{
9045 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9046}
9047
9048ALIAS (show_bgp_community_list,
9049 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009050 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009051 SHOW_STR
9052 BGP_STR
9053 "Address family\n"
9054 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009055 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009056 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009057
9058/* old command */
9059DEFUN (show_ipv6_bgp_community_list,
9060 show_ipv6_bgp_community_list_cmd,
9061 "show ipv6 bgp community-list WORD",
9062 SHOW_STR
9063 IPV6_STR
9064 BGP_STR
9065 "Display routes matching the community-list\n"
9066 "community-list name\n")
9067{
9068 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9069}
9070
9071/* old command */
9072DEFUN (show_ipv6_mbgp_community_list,
9073 show_ipv6_mbgp_community_list_cmd,
9074 "show ipv6 mbgp community-list WORD",
9075 SHOW_STR
9076 IPV6_STR
9077 MBGP_STR
9078 "Display routes matching the community-list\n"
9079 "community-list name\n")
9080{
9081 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9082}
9083
9084DEFUN (show_bgp_community_list_exact,
9085 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009086 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009087 SHOW_STR
9088 BGP_STR
9089 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009090 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009091 "community-list name\n"
9092 "Exact match of the communities\n")
9093{
9094 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9095}
9096
9097ALIAS (show_bgp_community_list_exact,
9098 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009099 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009100 SHOW_STR
9101 BGP_STR
9102 "Address family\n"
9103 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009104 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009105 "community-list name\n"
9106 "Exact match of the communities\n")
9107
9108/* old command */
9109DEFUN (show_ipv6_bgp_community_list_exact,
9110 show_ipv6_bgp_community_list_exact_cmd,
9111 "show ipv6 bgp community-list WORD exact-match",
9112 SHOW_STR
9113 IPV6_STR
9114 BGP_STR
9115 "Display routes matching the community-list\n"
9116 "community-list name\n"
9117 "Exact match of the communities\n")
9118{
9119 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9120}
9121
9122/* old command */
9123DEFUN (show_ipv6_mbgp_community_list_exact,
9124 show_ipv6_mbgp_community_list_exact_cmd,
9125 "show ipv6 mbgp community-list WORD exact-match",
9126 SHOW_STR
9127 IPV6_STR
9128 MBGP_STR
9129 "Display routes matching the community-list\n"
9130 "community-list name\n"
9131 "Exact match of the communities\n")
9132{
9133 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9134}
9135#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009136
paul94f2b392005-06-28 12:44:16 +00009137static int
paulfd79ac92004-10-13 05:06:08 +00009138bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009139 safi_t safi, enum bgp_show_type type)
9140{
9141 int ret;
9142 struct prefix *p;
9143
9144 p = prefix_new();
9145
9146 ret = str2prefix (prefix, p);
9147 if (! ret)
9148 {
9149 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9150 return CMD_WARNING;
9151 }
9152
ajs5a646652004-11-05 01:25:55 +00009153 ret = bgp_show (vty, NULL, afi, safi, type, p);
9154 prefix_free(p);
9155 return ret;
paul718e3742002-12-13 20:15:29 +00009156}
9157
9158DEFUN (show_ip_bgp_prefix_longer,
9159 show_ip_bgp_prefix_longer_cmd,
9160 "show ip bgp A.B.C.D/M longer-prefixes",
9161 SHOW_STR
9162 IP_STR
9163 BGP_STR
9164 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9165 "Display route and more specific routes\n")
9166{
9167 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9168 bgp_show_type_prefix_longer);
9169}
9170
9171DEFUN (show_ip_bgp_flap_prefix_longer,
9172 show_ip_bgp_flap_prefix_longer_cmd,
9173 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9174 SHOW_STR
9175 IP_STR
9176 BGP_STR
9177 "Display flap statistics of routes\n"
9178 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9179 "Display route and more specific routes\n")
9180{
9181 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9182 bgp_show_type_flap_prefix_longer);
9183}
9184
Balaji3921cc52015-05-16 23:12:17 +05309185ALIAS (show_ip_bgp_flap_prefix_longer,
9186 show_ip_bgp_damp_flap_prefix_longer_cmd,
9187 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
9188 SHOW_STR
9189 IP_STR
9190 BGP_STR
9191 "Display detailed information about dampening\n"
9192 "Display flap statistics of routes\n"
9193 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9194 "Display route and more specific routes\n")
9195
paul718e3742002-12-13 20:15:29 +00009196DEFUN (show_ip_bgp_ipv4_prefix_longer,
9197 show_ip_bgp_ipv4_prefix_longer_cmd,
9198 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9199 SHOW_STR
9200 IP_STR
9201 BGP_STR
9202 "Address family\n"
9203 "Address Family modifier\n"
9204 "Address Family modifier\n"
9205 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9206 "Display route and more specific routes\n")
9207{
9208 if (strncmp (argv[0], "m", 1) == 0)
9209 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9210 bgp_show_type_prefix_longer);
9211
9212 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9213 bgp_show_type_prefix_longer);
9214}
9215
9216DEFUN (show_ip_bgp_flap_address,
9217 show_ip_bgp_flap_address_cmd,
9218 "show ip bgp flap-statistics A.B.C.D",
9219 SHOW_STR
9220 IP_STR
9221 BGP_STR
9222 "Display flap statistics of routes\n"
9223 "Network in the BGP routing table to display\n")
9224{
9225 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9226 bgp_show_type_flap_address);
9227}
9228
Balaji3921cc52015-05-16 23:12:17 +05309229ALIAS (show_ip_bgp_flap_address,
9230 show_ip_bgp_damp_flap_address_cmd,
9231 "show ip bgp dampening flap-statistics A.B.C.D",
9232 SHOW_STR
9233 IP_STR
9234 BGP_STR
9235 "Display detailed information about dampening\n"
9236 "Display flap statistics of routes\n"
9237 "Network in the BGP routing table to display\n")
9238
paul718e3742002-12-13 20:15:29 +00009239DEFUN (show_ip_bgp_flap_prefix,
9240 show_ip_bgp_flap_prefix_cmd,
9241 "show ip bgp flap-statistics A.B.C.D/M",
9242 SHOW_STR
9243 IP_STR
9244 BGP_STR
9245 "Display flap statistics of routes\n"
9246 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9247{
9248 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9249 bgp_show_type_flap_prefix);
9250}
Balaji3921cc52015-05-16 23:12:17 +05309251
9252ALIAS (show_ip_bgp_flap_prefix,
9253 show_ip_bgp_damp_flap_prefix_cmd,
9254 "show ip bgp dampening flap-statistics A.B.C.D/M",
9255 SHOW_STR
9256 IP_STR
9257 BGP_STR
9258 "Display detailed information about dampening\n"
9259 "Display flap statistics of routes\n"
9260 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9261
paul718e3742002-12-13 20:15:29 +00009262#ifdef HAVE_IPV6
9263DEFUN (show_bgp_prefix_longer,
9264 show_bgp_prefix_longer_cmd,
9265 "show bgp X:X::X:X/M longer-prefixes",
9266 SHOW_STR
9267 BGP_STR
9268 "IPv6 prefix <network>/<length>\n"
9269 "Display route and more specific routes\n")
9270{
9271 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9272 bgp_show_type_prefix_longer);
9273}
9274
9275ALIAS (show_bgp_prefix_longer,
9276 show_bgp_ipv6_prefix_longer_cmd,
9277 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9278 SHOW_STR
9279 BGP_STR
9280 "Address family\n"
9281 "IPv6 prefix <network>/<length>\n"
9282 "Display route and more specific routes\n")
9283
9284/* old command */
9285DEFUN (show_ipv6_bgp_prefix_longer,
9286 show_ipv6_bgp_prefix_longer_cmd,
9287 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9288 SHOW_STR
9289 IPV6_STR
9290 BGP_STR
9291 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9292 "Display route and more specific routes\n")
9293{
9294 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9295 bgp_show_type_prefix_longer);
9296}
9297
9298/* old command */
9299DEFUN (show_ipv6_mbgp_prefix_longer,
9300 show_ipv6_mbgp_prefix_longer_cmd,
9301 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9302 SHOW_STR
9303 IPV6_STR
9304 MBGP_STR
9305 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9306 "Display route and more specific routes\n")
9307{
9308 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9309 bgp_show_type_prefix_longer);
9310}
9311#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009312
paul94f2b392005-06-28 12:44:16 +00009313static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009314peer_lookup_in_view (struct vty *vty, const char *view_name,
9315 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009316{
9317 int ret;
9318 struct bgp *bgp;
9319 struct peer *peer;
9320 union sockunion su;
9321
9322 /* BGP structure lookup. */
9323 if (view_name)
9324 {
9325 bgp = bgp_lookup_by_name (view_name);
9326 if (! bgp)
9327 {
9328 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9329 return NULL;
9330 }
9331 }
paul5228ad22004-06-04 17:58:18 +00009332 else
paulbb46e942003-10-24 19:02:03 +00009333 {
9334 bgp = bgp_get_default ();
9335 if (! bgp)
9336 {
9337 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9338 return NULL;
9339 }
9340 }
9341
9342 /* Get peer sockunion. */
9343 ret = str2sockunion (ip_str, &su);
9344 if (ret < 0)
9345 {
9346 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9347 return NULL;
9348 }
9349
9350 /* Peer structure lookup. */
9351 peer = peer_lookup (bgp, &su);
9352 if (! peer)
9353 {
9354 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9355 return NULL;
9356 }
9357
9358 return peer;
9359}
David Lamparter6b0655a2014-06-04 06:53:35 +02009360
Paul Jakma2815e612006-09-14 02:56:07 +00009361enum bgp_stats
9362{
9363 BGP_STATS_MAXBITLEN = 0,
9364 BGP_STATS_RIB,
9365 BGP_STATS_PREFIXES,
9366 BGP_STATS_TOTPLEN,
9367 BGP_STATS_UNAGGREGATEABLE,
9368 BGP_STATS_MAX_AGGREGATEABLE,
9369 BGP_STATS_AGGREGATES,
9370 BGP_STATS_SPACE,
9371 BGP_STATS_ASPATH_COUNT,
9372 BGP_STATS_ASPATH_MAXHOPS,
9373 BGP_STATS_ASPATH_TOTHOPS,
9374 BGP_STATS_ASPATH_MAXSIZE,
9375 BGP_STATS_ASPATH_TOTSIZE,
9376 BGP_STATS_ASN_HIGHEST,
9377 BGP_STATS_MAX,
9378};
paulbb46e942003-10-24 19:02:03 +00009379
Paul Jakma2815e612006-09-14 02:56:07 +00009380static const char *table_stats_strs[] =
9381{
9382 [BGP_STATS_PREFIXES] = "Total Prefixes",
9383 [BGP_STATS_TOTPLEN] = "Average prefix length",
9384 [BGP_STATS_RIB] = "Total Advertisements",
9385 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9386 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9387 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9388 [BGP_STATS_SPACE] = "Address space advertised",
9389 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9390 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9391 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9392 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9393 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9394 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9395 [BGP_STATS_MAX] = NULL,
9396};
9397
9398struct bgp_table_stats
9399{
9400 struct bgp_table *table;
9401 unsigned long long counts[BGP_STATS_MAX];
9402};
9403
9404#if 0
9405#define TALLY_SIGFIG 100000
9406static unsigned long
9407ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9408{
9409 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9410 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9411 unsigned long ret = newtot / count;
9412
9413 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9414 return ret + 1;
9415 else
9416 return ret;
9417}
9418#endif
9419
9420static int
9421bgp_table_stats_walker (struct thread *t)
9422{
9423 struct bgp_node *rn;
9424 struct bgp_node *top;
9425 struct bgp_table_stats *ts = THREAD_ARG (t);
9426 unsigned int space = 0;
9427
Paul Jakma53d9f672006-10-15 23:41:16 +00009428 if (!(top = bgp_table_top (ts->table)))
9429 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009430
9431 switch (top->p.family)
9432 {
9433 case AF_INET:
9434 space = IPV4_MAX_BITLEN;
9435 break;
9436 case AF_INET6:
9437 space = IPV6_MAX_BITLEN;
9438 break;
9439 }
9440
9441 ts->counts[BGP_STATS_MAXBITLEN] = space;
9442
9443 for (rn = top; rn; rn = bgp_route_next (rn))
9444 {
9445 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009446 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009447 unsigned int rinum = 0;
9448
9449 if (rn == top)
9450 continue;
9451
9452 if (!rn->info)
9453 continue;
9454
9455 ts->counts[BGP_STATS_PREFIXES]++;
9456 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9457
9458#if 0
9459 ts->counts[BGP_STATS_AVGPLEN]
9460 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9461 ts->counts[BGP_STATS_AVGPLEN],
9462 rn->p.prefixlen);
9463#endif
9464
9465 /* check if the prefix is included by any other announcements */
9466 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009467 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009468
9469 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009470 {
9471 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9472 /* announced address space */
9473 if (space)
9474 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9475 }
Paul Jakma2815e612006-09-14 02:56:07 +00009476 else if (prn->info)
9477 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9478
Paul Jakma2815e612006-09-14 02:56:07 +00009479 for (ri = rn->info; ri; ri = ri->next)
9480 {
9481 rinum++;
9482 ts->counts[BGP_STATS_RIB]++;
9483
9484 if (ri->attr &&
9485 (CHECK_FLAG (ri->attr->flag,
9486 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9487 ts->counts[BGP_STATS_AGGREGATES]++;
9488
9489 /* as-path stats */
9490 if (ri->attr && ri->attr->aspath)
9491 {
9492 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9493 unsigned int size = aspath_size (ri->attr->aspath);
9494 as_t highest = aspath_highest (ri->attr->aspath);
9495
9496 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9497
9498 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9499 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9500
9501 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9502 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9503
9504 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9505 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9506#if 0
9507 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9508 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9509 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9510 hops);
9511 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9512 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9513 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9514 size);
9515#endif
9516 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9517 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9518 }
9519 }
9520 }
9521 return 0;
9522}
9523
9524static int
9525bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9526{
9527 struct bgp_table_stats ts;
9528 unsigned int i;
9529
9530 if (!bgp->rib[afi][safi])
9531 {
9532 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9533 return CMD_WARNING;
9534 }
9535
9536 memset (&ts, 0, sizeof (ts));
9537 ts.table = bgp->rib[afi][safi];
9538 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9539
9540 vty_out (vty, "BGP %s RIB statistics%s%s",
9541 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9542
9543 for (i = 0; i < BGP_STATS_MAX; i++)
9544 {
9545 if (!table_stats_strs[i])
9546 continue;
9547
9548 switch (i)
9549 {
9550#if 0
9551 case BGP_STATS_ASPATH_AVGHOPS:
9552 case BGP_STATS_ASPATH_AVGSIZE:
9553 case BGP_STATS_AVGPLEN:
9554 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9555 vty_out (vty, "%12.2f",
9556 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9557 break;
9558#endif
9559 case BGP_STATS_ASPATH_TOTHOPS:
9560 case BGP_STATS_ASPATH_TOTSIZE:
9561 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9562 vty_out (vty, "%12.2f",
9563 ts.counts[i] ?
9564 (float)ts.counts[i] /
9565 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9566 : 0);
9567 break;
9568 case BGP_STATS_TOTPLEN:
9569 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9570 vty_out (vty, "%12.2f",
9571 ts.counts[i] ?
9572 (float)ts.counts[i] /
9573 (float)ts.counts[BGP_STATS_PREFIXES]
9574 : 0);
9575 break;
9576 case BGP_STATS_SPACE:
9577 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9578 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9579 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9580 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009581 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009582 vty_out (vty, "%12.2f%s",
9583 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009584 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009585 VTY_NEWLINE);
9586 vty_out (vty, "%30s: ", "/8 equivalent ");
9587 vty_out (vty, "%12.2f%s",
9588 (float)ts.counts[BGP_STATS_SPACE] /
9589 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9590 VTY_NEWLINE);
9591 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9592 break;
9593 vty_out (vty, "%30s: ", "/24 equivalent ");
9594 vty_out (vty, "%12.2f",
9595 (float)ts.counts[BGP_STATS_SPACE] /
9596 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9597 break;
9598 default:
9599 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9600 vty_out (vty, "%12llu", ts.counts[i]);
9601 }
9602
9603 vty_out (vty, "%s", VTY_NEWLINE);
9604 }
9605 return CMD_SUCCESS;
9606}
9607
9608static int
9609bgp_table_stats_vty (struct vty *vty, const char *name,
9610 const char *afi_str, const char *safi_str)
9611{
9612 struct bgp *bgp;
9613 afi_t afi;
9614 safi_t safi;
9615
9616 if (name)
9617 bgp = bgp_lookup_by_name (name);
9618 else
9619 bgp = bgp_get_default ();
9620
9621 if (!bgp)
9622 {
9623 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9624 return CMD_WARNING;
9625 }
9626 if (strncmp (afi_str, "ipv", 3) == 0)
9627 {
9628 if (strncmp (afi_str, "ipv4", 4) == 0)
9629 afi = AFI_IP;
9630 else if (strncmp (afi_str, "ipv6", 4) == 0)
9631 afi = AFI_IP6;
9632 else
9633 {
9634 vty_out (vty, "%% Invalid address family %s%s",
9635 afi_str, VTY_NEWLINE);
9636 return CMD_WARNING;
9637 }
9638 if (strncmp (safi_str, "m", 1) == 0)
9639 safi = SAFI_MULTICAST;
9640 else if (strncmp (safi_str, "u", 1) == 0)
9641 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009642 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9643 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009644 else
9645 {
9646 vty_out (vty, "%% Invalid subsequent address family %s%s",
9647 safi_str, VTY_NEWLINE);
9648 return CMD_WARNING;
9649 }
9650 }
9651 else
9652 {
9653 vty_out (vty, "%% Invalid address family %s%s",
9654 afi_str, VTY_NEWLINE);
9655 return CMD_WARNING;
9656 }
9657
Paul Jakma2815e612006-09-14 02:56:07 +00009658 return bgp_table_stats (vty, bgp, afi, safi);
9659}
9660
9661DEFUN (show_bgp_statistics,
9662 show_bgp_statistics_cmd,
9663 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9664 SHOW_STR
9665 BGP_STR
9666 "Address family\n"
9667 "Address family\n"
9668 "Address Family modifier\n"
9669 "Address Family modifier\n"
9670 "BGP RIB advertisement statistics\n")
9671{
9672 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9673}
9674
9675ALIAS (show_bgp_statistics,
9676 show_bgp_statistics_vpnv4_cmd,
9677 "show bgp (ipv4) (vpnv4) statistics",
9678 SHOW_STR
9679 BGP_STR
9680 "Address family\n"
9681 "Address Family modifier\n"
9682 "BGP RIB advertisement statistics\n")
9683
9684DEFUN (show_bgp_statistics_view,
9685 show_bgp_statistics_view_cmd,
9686 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9687 SHOW_STR
9688 BGP_STR
9689 "BGP view\n"
9690 "Address family\n"
9691 "Address family\n"
9692 "Address Family modifier\n"
9693 "Address Family modifier\n"
9694 "BGP RIB advertisement statistics\n")
9695{
9696 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9697}
9698
9699ALIAS (show_bgp_statistics_view,
9700 show_bgp_statistics_view_vpnv4_cmd,
9701 "show bgp view WORD (ipv4) (vpnv4) statistics",
9702 SHOW_STR
9703 BGP_STR
9704 "BGP view\n"
9705 "Address family\n"
9706 "Address Family modifier\n"
9707 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009708
Paul Jakmaff7924f2006-09-04 01:10:36 +00009709enum bgp_pcounts
9710{
9711 PCOUNT_ADJ_IN = 0,
9712 PCOUNT_DAMPED,
9713 PCOUNT_REMOVED,
9714 PCOUNT_HISTORY,
9715 PCOUNT_STALE,
9716 PCOUNT_VALID,
9717 PCOUNT_ALL,
9718 PCOUNT_COUNTED,
9719 PCOUNT_PFCNT, /* the figure we display to users */
9720 PCOUNT_MAX,
9721};
9722
9723static const char *pcount_strs[] =
9724{
9725 [PCOUNT_ADJ_IN] = "Adj-in",
9726 [PCOUNT_DAMPED] = "Damped",
9727 [PCOUNT_REMOVED] = "Removed",
9728 [PCOUNT_HISTORY] = "History",
9729 [PCOUNT_STALE] = "Stale",
9730 [PCOUNT_VALID] = "Valid",
9731 [PCOUNT_ALL] = "All RIB",
9732 [PCOUNT_COUNTED] = "PfxCt counted",
9733 [PCOUNT_PFCNT] = "Useable",
9734 [PCOUNT_MAX] = NULL,
9735};
9736
Paul Jakma2815e612006-09-14 02:56:07 +00009737struct peer_pcounts
9738{
9739 unsigned int count[PCOUNT_MAX];
9740 const struct peer *peer;
9741 const struct bgp_table *table;
9742};
9743
Paul Jakmaff7924f2006-09-04 01:10:36 +00009744static int
Paul Jakma2815e612006-09-14 02:56:07 +00009745bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009746{
9747 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009748 struct peer_pcounts *pc = THREAD_ARG (t);
9749 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009750
Paul Jakma2815e612006-09-14 02:56:07 +00009751 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009752 {
9753 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009754 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009755
9756 for (ain = rn->adj_in; ain; ain = ain->next)
9757 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009758 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009759
Paul Jakmaff7924f2006-09-04 01:10:36 +00009760 for (ri = rn->info; ri; ri = ri->next)
9761 {
9762 char buf[SU_ADDRSTRLEN];
9763
9764 if (ri->peer != peer)
9765 continue;
9766
Paul Jakma2815e612006-09-14 02:56:07 +00009767 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009768
9769 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009770 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009771 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009772 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009773 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009774 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009775 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009776 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009777 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009778 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009779 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009780 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009781
9782 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9783 {
Paul Jakma2815e612006-09-14 02:56:07 +00009784 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009785 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009786 plog_warn (peer->log,
9787 "%s [pcount] %s/%d is counted but flags 0x%x",
9788 peer->host,
9789 inet_ntop(rn->p.family, &rn->p.u.prefix,
9790 buf, SU_ADDRSTRLEN),
9791 rn->p.prefixlen,
9792 ri->flags);
9793 }
9794 else
9795 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009796 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009797 plog_warn (peer->log,
9798 "%s [pcount] %s/%d not counted but flags 0x%x",
9799 peer->host,
9800 inet_ntop(rn->p.family, &rn->p.u.prefix,
9801 buf, SU_ADDRSTRLEN),
9802 rn->p.prefixlen,
9803 ri->flags);
9804 }
9805 }
9806 }
Paul Jakma2815e612006-09-14 02:56:07 +00009807 return 0;
9808}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009809
Paul Jakma2815e612006-09-14 02:56:07 +00009810static int
9811bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9812{
9813 struct peer_pcounts pcounts = { .peer = peer };
9814 unsigned int i;
9815
9816 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9817 || !peer->bgp->rib[afi][safi])
9818 {
9819 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9820 return CMD_WARNING;
9821 }
9822
9823 memset (&pcounts, 0, sizeof(pcounts));
9824 pcounts.peer = peer;
9825 pcounts.table = peer->bgp->rib[afi][safi];
9826
9827 /* in-place call via thread subsystem so as to record execution time
9828 * stats for the thread-walk (i.e. ensure this can't be blamed on
9829 * on just vty_read()).
9830 */
9831 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9832
Paul Jakmaff7924f2006-09-04 01:10:36 +00009833 vty_out (vty, "Prefix counts for %s, %s%s",
9834 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9835 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9836 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9837 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9838
9839 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009840 vty_out (vty, "%20s: %-10d%s",
9841 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009842
Paul Jakma2815e612006-09-14 02:56:07 +00009843 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009844 {
9845 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9846 peer->host, VTY_NEWLINE);
9847 vty_out (vty, "Please report this bug, with the above command output%s",
9848 VTY_NEWLINE);
9849 }
9850
9851 return CMD_SUCCESS;
9852}
9853
9854DEFUN (show_ip_bgp_neighbor_prefix_counts,
9855 show_ip_bgp_neighbor_prefix_counts_cmd,
9856 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9857 SHOW_STR
9858 IP_STR
9859 BGP_STR
9860 "Detailed information on TCP and BGP neighbor connections\n"
9861 "Neighbor to display information about\n"
9862 "Neighbor to display information about\n"
9863 "Display detailed prefix count information\n")
9864{
9865 struct peer *peer;
9866
9867 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9868 if (! peer)
9869 return CMD_WARNING;
9870
9871 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9872}
9873
9874DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9875 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9876 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9877 SHOW_STR
9878 BGP_STR
9879 "Address family\n"
9880 "Detailed information on TCP and BGP neighbor connections\n"
9881 "Neighbor to display information about\n"
9882 "Neighbor to display information about\n"
9883 "Display detailed prefix count information\n")
9884{
9885 struct peer *peer;
9886
9887 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9888 if (! peer)
9889 return CMD_WARNING;
9890
9891 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9892}
9893
9894DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9895 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9896 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9897 SHOW_STR
9898 IP_STR
9899 BGP_STR
9900 "Address family\n"
9901 "Address Family modifier\n"
9902 "Address Family modifier\n"
9903 "Detailed information on TCP and BGP neighbor connections\n"
9904 "Neighbor to display information about\n"
9905 "Neighbor to display information about\n"
9906 "Display detailed prefix count information\n")
9907{
9908 struct peer *peer;
9909
9910 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9911 if (! peer)
9912 return CMD_WARNING;
9913
9914 if (strncmp (argv[0], "m", 1) == 0)
9915 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9916
9917 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9918}
9919
9920DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9921 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9922 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9923 SHOW_STR
9924 IP_STR
9925 BGP_STR
9926 "Address family\n"
9927 "Address Family modifier\n"
9928 "Address Family modifier\n"
9929 "Detailed information on TCP and BGP neighbor connections\n"
9930 "Neighbor to display information about\n"
9931 "Neighbor to display information about\n"
9932 "Display detailed prefix count information\n")
9933{
9934 struct peer *peer;
9935
9936 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9937 if (! peer)
9938 return CMD_WARNING;
9939
9940 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9941}
9942
9943
paul94f2b392005-06-28 12:44:16 +00009944static void
paul718e3742002-12-13 20:15:29 +00009945show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9946 int in)
9947{
9948 struct bgp_table *table;
9949 struct bgp_adj_in *ain;
9950 struct bgp_adj_out *adj;
9951 unsigned long output_count;
9952 struct bgp_node *rn;
9953 int header1 = 1;
9954 struct bgp *bgp;
9955 int header2 = 1;
9956
paulbb46e942003-10-24 19:02:03 +00009957 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009958
9959 if (! bgp)
9960 return;
9961
9962 table = bgp->rib[afi][safi];
9963
9964 output_count = 0;
9965
9966 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9967 PEER_STATUS_DEFAULT_ORIGINATE))
9968 {
9969 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 +00009970 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9971 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009972
9973 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9974 VTY_NEWLINE, VTY_NEWLINE);
9975 header1 = 0;
9976 }
9977
9978 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9979 if (in)
9980 {
9981 for (ain = rn->adj_in; ain; ain = ain->next)
9982 if (ain->peer == peer)
9983 {
9984 if (header1)
9985 {
9986 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 +00009987 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9988 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009989 header1 = 0;
9990 }
9991 if (header2)
9992 {
9993 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9994 header2 = 0;
9995 }
9996 if (ain->attr)
9997 {
9998 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9999 output_count++;
10000 }
10001 }
10002 }
10003 else
10004 {
10005 for (adj = rn->adj_out; adj; adj = adj->next)
10006 if (adj->peer == peer)
10007 {
10008 if (header1)
10009 {
10010 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 +000010011 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10012 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010013 header1 = 0;
10014 }
10015 if (header2)
10016 {
10017 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10018 header2 = 0;
10019 }
10020 if (adj->attr)
10021 {
10022 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10023 output_count++;
10024 }
10025 }
10026 }
10027
10028 if (output_count != 0)
10029 vty_out (vty, "%sTotal number of prefixes %ld%s",
10030 VTY_NEWLINE, output_count, VTY_NEWLINE);
10031}
10032
paul94f2b392005-06-28 12:44:16 +000010033static int
paulbb46e942003-10-24 19:02:03 +000010034peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10035{
paul718e3742002-12-13 20:15:29 +000010036 if (! peer || ! peer->afc[afi][safi])
10037 {
10038 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10039 return CMD_WARNING;
10040 }
10041
10042 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10043 {
10044 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10045 VTY_NEWLINE);
10046 return CMD_WARNING;
10047 }
10048
10049 show_adj_route (vty, peer, afi, safi, in);
10050
10051 return CMD_SUCCESS;
10052}
10053
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010054DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10055 show_ip_bgp_view_neighbor_advertised_route_cmd,
10056 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10057 SHOW_STR
10058 IP_STR
10059 BGP_STR
10060 "BGP view\n"
10061 "View name\n"
10062 "Detailed information on TCP and BGP neighbor connections\n"
10063 "Neighbor to display information about\n"
10064 "Neighbor to display information about\n"
10065 "Display the routes advertised to a BGP neighbor\n")
10066{
10067 struct peer *peer;
10068
10069 if (argc == 2)
10070 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10071 else
10072 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10073
10074 if (! peer)
10075 return CMD_WARNING;
10076
10077 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
10078}
10079
10080ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010081 show_ip_bgp_neighbor_advertised_route_cmd,
10082 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10083 SHOW_STR
10084 IP_STR
10085 BGP_STR
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 the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +000010090
10091DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10092 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10093 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10094 SHOW_STR
10095 IP_STR
10096 BGP_STR
10097 "Address family\n"
10098 "Address Family modifier\n"
10099 "Address Family modifier\n"
10100 "Detailed information on TCP and BGP neighbor connections\n"
10101 "Neighbor to display information about\n"
10102 "Neighbor to display information about\n"
10103 "Display the routes advertised to a BGP neighbor\n")
10104{
paulbb46e942003-10-24 19:02:03 +000010105 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010106
paulbb46e942003-10-24 19:02:03 +000010107 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10108 if (! peer)
10109 return CMD_WARNING;
10110
10111 if (strncmp (argv[0], "m", 1) == 0)
10112 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10113
10114 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010115}
10116
10117#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010118DEFUN (show_bgp_view_neighbor_advertised_route,
10119 show_bgp_view_neighbor_advertised_route_cmd,
10120 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10121 SHOW_STR
10122 BGP_STR
10123 "BGP view\n"
10124 "View name\n"
10125 "Detailed information on TCP and BGP neighbor connections\n"
10126 "Neighbor to display information about\n"
10127 "Neighbor to display information about\n"
10128 "Display the routes advertised to a BGP neighbor\n")
10129{
10130 struct peer *peer;
10131
10132 if (argc == 2)
10133 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10134 else
10135 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10136
10137 if (! peer)
10138 return CMD_WARNING;
10139
10140 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10141}
10142
10143ALIAS (show_bgp_view_neighbor_advertised_route,
10144 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10145 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10146 SHOW_STR
10147 BGP_STR
10148 "BGP view\n"
10149 "View name\n"
10150 "Address family\n"
10151 "Detailed information on TCP and BGP neighbor connections\n"
10152 "Neighbor to display information about\n"
10153 "Neighbor to display information about\n"
10154 "Display the routes advertised to a BGP neighbor\n")
10155
10156DEFUN (show_bgp_view_neighbor_received_routes,
10157 show_bgp_view_neighbor_received_routes_cmd,
10158 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10159 SHOW_STR
10160 BGP_STR
10161 "BGP view\n"
10162 "View name\n"
10163 "Detailed information on TCP and BGP neighbor connections\n"
10164 "Neighbor to display information about\n"
10165 "Neighbor to display information about\n"
10166 "Display the received routes from neighbor\n")
10167{
10168 struct peer *peer;
10169
10170 if (argc == 2)
10171 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10172 else
10173 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10174
10175 if (! peer)
10176 return CMD_WARNING;
10177
10178 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10179}
10180
10181ALIAS (show_bgp_view_neighbor_received_routes,
10182 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10183 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10184 SHOW_STR
10185 BGP_STR
10186 "BGP view\n"
10187 "View name\n"
10188 "Address family\n"
10189 "Detailed information on TCP and BGP neighbor connections\n"
10190 "Neighbor to display information about\n"
10191 "Neighbor to display information about\n"
10192 "Display the received routes from neighbor\n")
10193
10194ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010195 show_bgp_neighbor_advertised_route_cmd,
10196 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10197 SHOW_STR
10198 BGP_STR
10199 "Detailed information on TCP and BGP neighbor connections\n"
10200 "Neighbor to display information about\n"
10201 "Neighbor to display information about\n"
10202 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010203
10204ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010205 show_bgp_ipv6_neighbor_advertised_route_cmd,
10206 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10207 SHOW_STR
10208 BGP_STR
10209 "Address family\n"
10210 "Detailed information on TCP and BGP neighbor connections\n"
10211 "Neighbor to display information about\n"
10212 "Neighbor to display information about\n"
10213 "Display the routes advertised to a BGP neighbor\n")
10214
10215/* old command */
paulbb46e942003-10-24 19:02:03 +000010216ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010217 ipv6_bgp_neighbor_advertised_route_cmd,
10218 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10219 SHOW_STR
10220 IPV6_STR
10221 BGP_STR
10222 "Detailed information on TCP and BGP neighbor connections\n"
10223 "Neighbor to display information about\n"
10224 "Neighbor to display information about\n"
10225 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010226
paul718e3742002-12-13 20:15:29 +000010227/* old command */
10228DEFUN (ipv6_mbgp_neighbor_advertised_route,
10229 ipv6_mbgp_neighbor_advertised_route_cmd,
10230 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10231 SHOW_STR
10232 IPV6_STR
10233 MBGP_STR
10234 "Detailed information on TCP and BGP neighbor connections\n"
10235 "Neighbor to display information about\n"
10236 "Neighbor to display information about\n"
10237 "Display the routes advertised to a BGP neighbor\n")
10238{
paulbb46e942003-10-24 19:02:03 +000010239 struct peer *peer;
10240
10241 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10242 if (! peer)
10243 return CMD_WARNING;
10244
10245 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010246}
10247#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010248
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010249DEFUN (show_ip_bgp_view_neighbor_received_routes,
10250 show_ip_bgp_view_neighbor_received_routes_cmd,
10251 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10252 SHOW_STR
10253 IP_STR
10254 BGP_STR
10255 "BGP view\n"
10256 "View name\n"
10257 "Detailed information on TCP and BGP neighbor connections\n"
10258 "Neighbor to display information about\n"
10259 "Neighbor to display information about\n"
10260 "Display the received routes from neighbor\n")
10261{
10262 struct peer *peer;
10263
10264 if (argc == 2)
10265 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10266 else
10267 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10268
10269 if (! peer)
10270 return CMD_WARNING;
10271
10272 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10273}
10274
10275ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010276 show_ip_bgp_neighbor_received_routes_cmd,
10277 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10278 SHOW_STR
10279 IP_STR
10280 BGP_STR
10281 "Detailed information on TCP and BGP neighbor connections\n"
10282 "Neighbor to display information about\n"
10283 "Neighbor to display information about\n"
10284 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010285
10286DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10287 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10288 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10289 SHOW_STR
10290 IP_STR
10291 BGP_STR
10292 "Address family\n"
10293 "Address Family modifier\n"
10294 "Address Family modifier\n"
10295 "Detailed information on TCP and BGP neighbor connections\n"
10296 "Neighbor to display information about\n"
10297 "Neighbor to display information about\n"
10298 "Display the received routes from neighbor\n")
10299{
paulbb46e942003-10-24 19:02:03 +000010300 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010301
paulbb46e942003-10-24 19:02:03 +000010302 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10303 if (! peer)
10304 return CMD_WARNING;
10305
10306 if (strncmp (argv[0], "m", 1) == 0)
10307 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10308
10309 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010310}
10311
Michael Lambert95cbbd22010-07-23 14:43:04 -040010312DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10313 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010314 "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 -040010315 SHOW_STR
10316 BGP_STR
10317 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010318 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010319 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010320 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010321 "Address family modifier\n"
10322 "Address family modifier\n"
10323 "Detailed information on TCP and BGP neighbor connections\n"
10324 "Neighbor to display information about\n"
10325 "Neighbor to display information about\n"
10326 "Display the advertised routes to neighbor\n"
10327 "Display the received routes from neighbor\n")
10328{
10329 int afi;
10330 int safi;
10331 int in;
10332 struct peer *peer;
10333
David Lamparter94bad672015-03-03 08:52:22 +010010334 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010335
10336 if (! peer)
10337 return CMD_WARNING;
10338
Michael Lambert95cbbd22010-07-23 14:43:04 -040010339 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10340 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10341 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010342
10343 return peer_adj_routes (vty, peer, afi, safi, in);
10344}
10345
paul718e3742002-12-13 20:15:29 +000010346DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10347 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10348 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10349 SHOW_STR
10350 IP_STR
10351 BGP_STR
10352 "Detailed information on TCP and BGP neighbor connections\n"
10353 "Neighbor to display information about\n"
10354 "Neighbor to display information about\n"
10355 "Display information received from a BGP neighbor\n"
10356 "Display the prefixlist filter\n")
10357{
10358 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010359 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010360 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010361 int count, ret;
paul718e3742002-12-13 20:15:29 +000010362
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010363 ret = str2sockunion (argv[0], &su);
10364 if (ret < 0)
10365 {
10366 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10367 return CMD_WARNING;
10368 }
paul718e3742002-12-13 20:15:29 +000010369
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010370 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010371 if (! peer)
10372 return CMD_WARNING;
10373
10374 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10375 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10376 if (count)
10377 {
10378 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10379 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10380 }
10381
10382 return CMD_SUCCESS;
10383}
10384
10385DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10386 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10387 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10388 SHOW_STR
10389 IP_STR
10390 BGP_STR
10391 "Address family\n"
10392 "Address Family modifier\n"
10393 "Address Family modifier\n"
10394 "Detailed information on TCP and BGP neighbor connections\n"
10395 "Neighbor to display information about\n"
10396 "Neighbor to display information about\n"
10397 "Display information received from a BGP neighbor\n"
10398 "Display the prefixlist filter\n")
10399{
10400 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010401 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010402 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010403 int count, ret;
paul718e3742002-12-13 20:15:29 +000010404
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010405 ret = str2sockunion (argv[1], &su);
10406 if (ret < 0)
10407 {
10408 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10409 return CMD_WARNING;
10410 }
paul718e3742002-12-13 20:15:29 +000010411
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010412 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010413 if (! peer)
10414 return CMD_WARNING;
10415
10416 if (strncmp (argv[0], "m", 1) == 0)
10417 {
10418 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10419 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10420 if (count)
10421 {
10422 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10423 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10424 }
10425 }
10426 else
10427 {
10428 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10429 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10430 if (count)
10431 {
10432 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10433 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10434 }
10435 }
10436
10437 return CMD_SUCCESS;
10438}
10439
10440
10441#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010442ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010443 show_bgp_neighbor_received_routes_cmd,
10444 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10445 SHOW_STR
10446 BGP_STR
10447 "Detailed information on TCP and BGP neighbor connections\n"
10448 "Neighbor to display information about\n"
10449 "Neighbor to display information about\n"
10450 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010451
paulbb46e942003-10-24 19:02:03 +000010452ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010453 show_bgp_ipv6_neighbor_received_routes_cmd,
10454 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10455 SHOW_STR
10456 BGP_STR
10457 "Address family\n"
10458 "Detailed information on TCP and BGP neighbor connections\n"
10459 "Neighbor to display information about\n"
10460 "Neighbor to display information about\n"
10461 "Display the received routes from neighbor\n")
10462
10463DEFUN (show_bgp_neighbor_received_prefix_filter,
10464 show_bgp_neighbor_received_prefix_filter_cmd,
10465 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10466 SHOW_STR
10467 BGP_STR
10468 "Detailed information on TCP and BGP neighbor connections\n"
10469 "Neighbor to display information about\n"
10470 "Neighbor to display information about\n"
10471 "Display information received from a BGP neighbor\n"
10472 "Display the prefixlist filter\n")
10473{
10474 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010475 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010476 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010477 int count, ret;
paul718e3742002-12-13 20:15:29 +000010478
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010479 ret = str2sockunion (argv[0], &su);
10480 if (ret < 0)
10481 {
10482 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10483 return CMD_WARNING;
10484 }
paul718e3742002-12-13 20:15:29 +000010485
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010486 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010487 if (! peer)
10488 return CMD_WARNING;
10489
10490 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10491 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10492 if (count)
10493 {
10494 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10495 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10496 }
10497
10498 return CMD_SUCCESS;
10499}
10500
10501ALIAS (show_bgp_neighbor_received_prefix_filter,
10502 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10503 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10504 SHOW_STR
10505 BGP_STR
10506 "Address family\n"
10507 "Detailed information on TCP and BGP neighbor connections\n"
10508 "Neighbor to display information about\n"
10509 "Neighbor to display information about\n"
10510 "Display information received from a BGP neighbor\n"
10511 "Display the prefixlist filter\n")
10512
10513/* old command */
paulbb46e942003-10-24 19:02:03 +000010514ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010515 ipv6_bgp_neighbor_received_routes_cmd,
10516 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10517 SHOW_STR
10518 IPV6_STR
10519 BGP_STR
10520 "Detailed information on TCP and BGP neighbor connections\n"
10521 "Neighbor to display information about\n"
10522 "Neighbor to display information about\n"
10523 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010524
10525/* old command */
10526DEFUN (ipv6_mbgp_neighbor_received_routes,
10527 ipv6_mbgp_neighbor_received_routes_cmd,
10528 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10529 SHOW_STR
10530 IPV6_STR
10531 MBGP_STR
10532 "Detailed information on TCP and BGP neighbor connections\n"
10533 "Neighbor to display information about\n"
10534 "Neighbor to display information about\n"
10535 "Display the received routes from neighbor\n")
10536{
paulbb46e942003-10-24 19:02:03 +000010537 struct peer *peer;
10538
10539 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10540 if (! peer)
10541 return CMD_WARNING;
10542
10543 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010544}
paulbb46e942003-10-24 19:02:03 +000010545
10546DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10547 show_bgp_view_neighbor_received_prefix_filter_cmd,
10548 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10549 SHOW_STR
10550 BGP_STR
10551 "BGP view\n"
10552 "View name\n"
10553 "Detailed information on TCP and BGP neighbor connections\n"
10554 "Neighbor to display information about\n"
10555 "Neighbor to display information about\n"
10556 "Display information received from a BGP neighbor\n"
10557 "Display the prefixlist filter\n")
10558{
10559 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010560 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010561 struct peer *peer;
10562 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010563 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010564
10565 /* BGP structure lookup. */
10566 bgp = bgp_lookup_by_name (argv[0]);
10567 if (bgp == NULL)
10568 {
10569 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10570 return CMD_WARNING;
10571 }
10572
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010573 ret = str2sockunion (argv[1], &su);
10574 if (ret < 0)
10575 {
10576 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10577 return CMD_WARNING;
10578 }
paulbb46e942003-10-24 19:02:03 +000010579
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010580 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010581 if (! peer)
10582 return CMD_WARNING;
10583
10584 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10585 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10586 if (count)
10587 {
10588 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10589 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10590 }
10591
10592 return CMD_SUCCESS;
10593}
10594
10595ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10596 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10597 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10598 SHOW_STR
10599 BGP_STR
10600 "BGP view\n"
10601 "View name\n"
10602 "Address family\n"
10603 "Detailed information on TCP and BGP neighbor connections\n"
10604 "Neighbor to display information about\n"
10605 "Neighbor to display information about\n"
10606 "Display information received from a BGP neighbor\n"
10607 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010608#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010609
paul94f2b392005-06-28 12:44:16 +000010610static int
paulbb46e942003-10-24 19:02:03 +000010611bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010612 safi_t safi, enum bgp_show_type type)
10613{
paul718e3742002-12-13 20:15:29 +000010614 if (! peer || ! peer->afc[afi][safi])
10615 {
10616 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010617 return CMD_WARNING;
10618 }
10619
ajs5a646652004-11-05 01:25:55 +000010620 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010621}
10622
10623DEFUN (show_ip_bgp_neighbor_routes,
10624 show_ip_bgp_neighbor_routes_cmd,
10625 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10626 SHOW_STR
10627 IP_STR
10628 BGP_STR
10629 "Detailed information on TCP and BGP neighbor connections\n"
10630 "Neighbor to display information about\n"
10631 "Neighbor to display information about\n"
10632 "Display routes learned from neighbor\n")
10633{
paulbb46e942003-10-24 19:02:03 +000010634 struct peer *peer;
10635
10636 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10637 if (! peer)
10638 return CMD_WARNING;
10639
10640 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010641 bgp_show_type_neighbor);
10642}
10643
10644DEFUN (show_ip_bgp_neighbor_flap,
10645 show_ip_bgp_neighbor_flap_cmd,
10646 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10647 SHOW_STR
10648 IP_STR
10649 BGP_STR
10650 "Detailed information on TCP and BGP neighbor connections\n"
10651 "Neighbor to display information about\n"
10652 "Neighbor to display information about\n"
10653 "Display flap statistics of the routes learned from neighbor\n")
10654{
paulbb46e942003-10-24 19:02:03 +000010655 struct peer *peer;
10656
10657 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10658 if (! peer)
10659 return CMD_WARNING;
10660
10661 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010662 bgp_show_type_flap_neighbor);
10663}
10664
10665DEFUN (show_ip_bgp_neighbor_damp,
10666 show_ip_bgp_neighbor_damp_cmd,
10667 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10668 SHOW_STR
10669 IP_STR
10670 BGP_STR
10671 "Detailed information on TCP and BGP neighbor connections\n"
10672 "Neighbor to display information about\n"
10673 "Neighbor to display information about\n"
10674 "Display the dampened routes received from neighbor\n")
10675{
paulbb46e942003-10-24 19:02:03 +000010676 struct peer *peer;
10677
10678 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10679 if (! peer)
10680 return CMD_WARNING;
10681
10682 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010683 bgp_show_type_damp_neighbor);
10684}
10685
10686DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10687 show_ip_bgp_ipv4_neighbor_routes_cmd,
10688 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10689 SHOW_STR
10690 IP_STR
10691 BGP_STR
10692 "Address family\n"
10693 "Address Family modifier\n"
10694 "Address Family modifier\n"
10695 "Detailed information on TCP and BGP neighbor connections\n"
10696 "Neighbor to display information about\n"
10697 "Neighbor to display information about\n"
10698 "Display routes learned from neighbor\n")
10699{
paulbb46e942003-10-24 19:02:03 +000010700 struct peer *peer;
10701
10702 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10703 if (! peer)
10704 return CMD_WARNING;
10705
paul718e3742002-12-13 20:15:29 +000010706 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010707 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010708 bgp_show_type_neighbor);
10709
paulbb46e942003-10-24 19:02:03 +000010710 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010711 bgp_show_type_neighbor);
10712}
paulbb46e942003-10-24 19:02:03 +000010713
paulfee0f4c2004-09-13 05:12:46 +000010714DEFUN (show_ip_bgp_view_rsclient,
10715 show_ip_bgp_view_rsclient_cmd,
10716 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10717 SHOW_STR
10718 IP_STR
10719 BGP_STR
10720 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010721 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010722 "Information about Route Server Client\n"
10723 NEIGHBOR_ADDR_STR)
10724{
10725 struct bgp_table *table;
10726 struct peer *peer;
10727
10728 if (argc == 2)
10729 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10730 else
10731 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10732
10733 if (! peer)
10734 return CMD_WARNING;
10735
10736 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10737 {
10738 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10739 VTY_NEWLINE);
10740 return CMD_WARNING;
10741 }
10742
10743 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10744 PEER_FLAG_RSERVER_CLIENT))
10745 {
10746 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10747 VTY_NEWLINE);
10748 return CMD_WARNING;
10749 }
10750
10751 table = peer->rib[AFI_IP][SAFI_UNICAST];
10752
ajs5a646652004-11-05 01:25:55 +000010753 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010754}
10755
10756ALIAS (show_ip_bgp_view_rsclient,
10757 show_ip_bgp_rsclient_cmd,
10758 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10759 SHOW_STR
10760 IP_STR
10761 BGP_STR
10762 "Information about Route Server Client\n"
10763 NEIGHBOR_ADDR_STR)
10764
Michael Lambert95cbbd22010-07-23 14:43:04 -040010765DEFUN (show_bgp_view_ipv4_safi_rsclient,
10766 show_bgp_view_ipv4_safi_rsclient_cmd,
10767 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10768 SHOW_STR
10769 BGP_STR
10770 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010771 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010772 "Address family\n"
10773 "Address Family modifier\n"
10774 "Address Family modifier\n"
10775 "Information about Route Server Client\n"
10776 NEIGHBOR_ADDR_STR)
10777{
10778 struct bgp_table *table;
10779 struct peer *peer;
10780 safi_t safi;
10781
10782 if (argc == 3) {
10783 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10784 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10785 } else {
10786 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10787 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10788 }
10789
10790 if (! peer)
10791 return CMD_WARNING;
10792
10793 if (! peer->afc[AFI_IP][safi])
10794 {
10795 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10796 VTY_NEWLINE);
10797 return CMD_WARNING;
10798 }
10799
10800 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10801 PEER_FLAG_RSERVER_CLIENT))
10802 {
10803 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10804 VTY_NEWLINE);
10805 return CMD_WARNING;
10806 }
10807
10808 table = peer->rib[AFI_IP][safi];
10809
10810 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10811}
10812
10813ALIAS (show_bgp_view_ipv4_safi_rsclient,
10814 show_bgp_ipv4_safi_rsclient_cmd,
10815 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10816 SHOW_STR
10817 BGP_STR
10818 "Address family\n"
10819 "Address Family modifier\n"
10820 "Address Family modifier\n"
10821 "Information about Route Server Client\n"
10822 NEIGHBOR_ADDR_STR)
10823
paulfee0f4c2004-09-13 05:12:46 +000010824DEFUN (show_ip_bgp_view_rsclient_route,
10825 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010826 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010827 SHOW_STR
10828 IP_STR
10829 BGP_STR
10830 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010831 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010832 "Information about Route Server Client\n"
10833 NEIGHBOR_ADDR_STR
10834 "Network in the BGP routing table to display\n")
10835{
10836 struct bgp *bgp;
10837 struct peer *peer;
10838
10839 /* BGP structure lookup. */
10840 if (argc == 3)
10841 {
10842 bgp = bgp_lookup_by_name (argv[0]);
10843 if (bgp == NULL)
10844 {
10845 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10846 return CMD_WARNING;
10847 }
10848 }
10849 else
10850 {
10851 bgp = bgp_get_default ();
10852 if (bgp == NULL)
10853 {
10854 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10855 return CMD_WARNING;
10856 }
10857 }
10858
10859 if (argc == 3)
10860 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10861 else
10862 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10863
10864 if (! peer)
10865 return CMD_WARNING;
10866
10867 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10868 {
10869 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10870 VTY_NEWLINE);
10871 return CMD_WARNING;
10872}
10873
10874 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10875 PEER_FLAG_RSERVER_CLIENT))
10876 {
10877 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10878 VTY_NEWLINE);
10879 return CMD_WARNING;
10880 }
10881
10882 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10883 (argc == 3) ? argv[2] : argv[1],
10884 AFI_IP, SAFI_UNICAST, NULL, 0);
10885}
10886
10887ALIAS (show_ip_bgp_view_rsclient_route,
10888 show_ip_bgp_rsclient_route_cmd,
10889 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10890 SHOW_STR
10891 IP_STR
10892 BGP_STR
10893 "Information about Route Server Client\n"
10894 NEIGHBOR_ADDR_STR
10895 "Network in the BGP routing table to display\n")
10896
Michael Lambert95cbbd22010-07-23 14:43:04 -040010897DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10898 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10899 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10900 SHOW_STR
10901 BGP_STR
10902 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010903 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010904 "Address family\n"
10905 "Address Family modifier\n"
10906 "Address Family modifier\n"
10907 "Information about Route Server Client\n"
10908 NEIGHBOR_ADDR_STR
10909 "Network in the BGP routing table to display\n")
10910{
10911 struct bgp *bgp;
10912 struct peer *peer;
10913 safi_t safi;
10914
10915 /* BGP structure lookup. */
10916 if (argc == 4)
10917 {
10918 bgp = bgp_lookup_by_name (argv[0]);
10919 if (bgp == NULL)
10920 {
10921 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10922 return CMD_WARNING;
10923 }
10924 }
10925 else
10926 {
10927 bgp = bgp_get_default ();
10928 if (bgp == NULL)
10929 {
10930 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10931 return CMD_WARNING;
10932 }
10933 }
10934
10935 if (argc == 4) {
10936 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10937 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10938 } else {
10939 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10940 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10941 }
10942
10943 if (! peer)
10944 return CMD_WARNING;
10945
10946 if (! peer->afc[AFI_IP][safi])
10947 {
10948 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10949 VTY_NEWLINE);
10950 return CMD_WARNING;
10951}
10952
10953 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10954 PEER_FLAG_RSERVER_CLIENT))
10955 {
10956 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10957 VTY_NEWLINE);
10958 return CMD_WARNING;
10959 }
10960
10961 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10962 (argc == 4) ? argv[3] : argv[2],
10963 AFI_IP, safi, NULL, 0);
10964}
10965
10966ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10967 show_bgp_ipv4_safi_rsclient_route_cmd,
10968 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10969 SHOW_STR
10970 BGP_STR
10971 "Address family\n"
10972 "Address Family modifier\n"
10973 "Address Family modifier\n"
10974 "Information about Route Server Client\n"
10975 NEIGHBOR_ADDR_STR
10976 "Network in the BGP routing table to display\n")
10977
paulfee0f4c2004-09-13 05:12:46 +000010978DEFUN (show_ip_bgp_view_rsclient_prefix,
10979 show_ip_bgp_view_rsclient_prefix_cmd,
10980 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10981 SHOW_STR
10982 IP_STR
10983 BGP_STR
10984 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010985 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010986 "Information about Route Server Client\n"
10987 NEIGHBOR_ADDR_STR
10988 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10989{
10990 struct bgp *bgp;
10991 struct peer *peer;
10992
10993 /* BGP structure lookup. */
10994 if (argc == 3)
10995 {
10996 bgp = bgp_lookup_by_name (argv[0]);
10997 if (bgp == NULL)
10998 {
10999 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11000 return CMD_WARNING;
11001 }
11002 }
11003 else
11004 {
11005 bgp = bgp_get_default ();
11006 if (bgp == NULL)
11007 {
11008 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11009 return CMD_WARNING;
11010 }
11011 }
11012
11013 if (argc == 3)
11014 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11015 else
11016 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11017
11018 if (! peer)
11019 return CMD_WARNING;
11020
11021 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11022 {
11023 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11024 VTY_NEWLINE);
11025 return CMD_WARNING;
11026}
11027
11028 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11029 PEER_FLAG_RSERVER_CLIENT))
11030{
11031 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11032 VTY_NEWLINE);
11033 return CMD_WARNING;
11034 }
11035
11036 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11037 (argc == 3) ? argv[2] : argv[1],
11038 AFI_IP, SAFI_UNICAST, NULL, 1);
11039}
11040
11041ALIAS (show_ip_bgp_view_rsclient_prefix,
11042 show_ip_bgp_rsclient_prefix_cmd,
11043 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11044 SHOW_STR
11045 IP_STR
11046 BGP_STR
11047 "Information about Route Server Client\n"
11048 NEIGHBOR_ADDR_STR
11049 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11050
Michael Lambert95cbbd22010-07-23 14:43:04 -040011051DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11052 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11053 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11054 SHOW_STR
11055 BGP_STR
11056 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011057 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011058 "Address family\n"
11059 "Address Family modifier\n"
11060 "Address Family modifier\n"
11061 "Information about Route Server Client\n"
11062 NEIGHBOR_ADDR_STR
11063 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11064{
11065 struct bgp *bgp;
11066 struct peer *peer;
11067 safi_t safi;
11068
11069 /* BGP structure lookup. */
11070 if (argc == 4)
11071 {
11072 bgp = bgp_lookup_by_name (argv[0]);
11073 if (bgp == NULL)
11074 {
11075 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11076 return CMD_WARNING;
11077 }
11078 }
11079 else
11080 {
11081 bgp = bgp_get_default ();
11082 if (bgp == NULL)
11083 {
11084 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11085 return CMD_WARNING;
11086 }
11087 }
11088
11089 if (argc == 4) {
11090 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11091 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11092 } else {
11093 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11094 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11095 }
11096
11097 if (! peer)
11098 return CMD_WARNING;
11099
11100 if (! peer->afc[AFI_IP][safi])
11101 {
11102 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11103 VTY_NEWLINE);
11104 return CMD_WARNING;
11105}
11106
11107 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11108 PEER_FLAG_RSERVER_CLIENT))
11109{
11110 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11111 VTY_NEWLINE);
11112 return CMD_WARNING;
11113 }
11114
11115 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11116 (argc == 4) ? argv[3] : argv[2],
11117 AFI_IP, safi, NULL, 1);
11118}
11119
11120ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11121 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11122 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11123 SHOW_STR
11124 BGP_STR
11125 "Address family\n"
11126 "Address Family modifier\n"
11127 "Address Family modifier\n"
11128 "Information about Route Server Client\n"
11129 NEIGHBOR_ADDR_STR
11130 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011131
paul718e3742002-12-13 20:15:29 +000011132#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011133DEFUN (show_bgp_view_neighbor_routes,
11134 show_bgp_view_neighbor_routes_cmd,
11135 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11136 SHOW_STR
11137 BGP_STR
11138 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011139 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011140 "Detailed information on TCP and BGP neighbor connections\n"
11141 "Neighbor to display information about\n"
11142 "Neighbor to display information about\n"
11143 "Display routes learned from neighbor\n")
11144{
11145 struct peer *peer;
11146
11147 if (argc == 2)
11148 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11149 else
11150 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11151
11152 if (! peer)
11153 return CMD_WARNING;
11154
11155 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11156 bgp_show_type_neighbor);
11157}
11158
11159ALIAS (show_bgp_view_neighbor_routes,
11160 show_bgp_view_ipv6_neighbor_routes_cmd,
11161 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11162 SHOW_STR
11163 BGP_STR
11164 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011165 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011166 "Address family\n"
11167 "Detailed information on TCP and BGP neighbor connections\n"
11168 "Neighbor to display information about\n"
11169 "Neighbor to display information about\n"
11170 "Display routes learned from neighbor\n")
11171
11172DEFUN (show_bgp_view_neighbor_damp,
11173 show_bgp_view_neighbor_damp_cmd,
11174 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11175 SHOW_STR
11176 BGP_STR
11177 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011178 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011179 "Detailed information on TCP and BGP neighbor connections\n"
11180 "Neighbor to display information about\n"
11181 "Neighbor to display information about\n"
11182 "Display the dampened routes received from neighbor\n")
11183{
11184 struct peer *peer;
11185
11186 if (argc == 2)
11187 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11188 else
11189 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11190
11191 if (! peer)
11192 return CMD_WARNING;
11193
11194 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11195 bgp_show_type_damp_neighbor);
11196}
11197
11198ALIAS (show_bgp_view_neighbor_damp,
11199 show_bgp_view_ipv6_neighbor_damp_cmd,
11200 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11201 SHOW_STR
11202 BGP_STR
11203 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011204 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011205 "Address family\n"
11206 "Detailed information on TCP and BGP neighbor connections\n"
11207 "Neighbor to display information about\n"
11208 "Neighbor to display information about\n"
11209 "Display the dampened routes received from neighbor\n")
11210
11211DEFUN (show_bgp_view_neighbor_flap,
11212 show_bgp_view_neighbor_flap_cmd,
11213 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11214 SHOW_STR
11215 BGP_STR
11216 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011217 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011218 "Detailed information on TCP and BGP neighbor connections\n"
11219 "Neighbor to display information about\n"
11220 "Neighbor to display information about\n"
11221 "Display flap statistics of the routes learned from neighbor\n")
11222{
11223 struct peer *peer;
11224
11225 if (argc == 2)
11226 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11227 else
11228 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11229
11230 if (! peer)
11231 return CMD_WARNING;
11232
11233 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11234 bgp_show_type_flap_neighbor);
11235}
11236
11237ALIAS (show_bgp_view_neighbor_flap,
11238 show_bgp_view_ipv6_neighbor_flap_cmd,
11239 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11240 SHOW_STR
11241 BGP_STR
11242 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011243 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011244 "Address family\n"
11245 "Detailed information on TCP and BGP neighbor connections\n"
11246 "Neighbor to display information about\n"
11247 "Neighbor to display information about\n"
11248 "Display flap statistics of the routes learned from neighbor\n")
11249
11250ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011251 show_bgp_neighbor_routes_cmd,
11252 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11253 SHOW_STR
11254 BGP_STR
11255 "Detailed information on TCP and BGP neighbor connections\n"
11256 "Neighbor to display information about\n"
11257 "Neighbor to display information about\n"
11258 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011259
paulbb46e942003-10-24 19:02:03 +000011260
11261ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011262 show_bgp_ipv6_neighbor_routes_cmd,
11263 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11264 SHOW_STR
11265 BGP_STR
11266 "Address family\n"
11267 "Detailed information on TCP and BGP neighbor connections\n"
11268 "Neighbor to display information about\n"
11269 "Neighbor to display information about\n"
11270 "Display routes learned from neighbor\n")
11271
11272/* old command */
paulbb46e942003-10-24 19:02:03 +000011273ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011274 ipv6_bgp_neighbor_routes_cmd,
11275 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11276 SHOW_STR
11277 IPV6_STR
11278 BGP_STR
11279 "Detailed information on TCP and BGP neighbor connections\n"
11280 "Neighbor to display information about\n"
11281 "Neighbor to display information about\n"
11282 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011283
11284/* old command */
11285DEFUN (ipv6_mbgp_neighbor_routes,
11286 ipv6_mbgp_neighbor_routes_cmd,
11287 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11288 SHOW_STR
11289 IPV6_STR
11290 MBGP_STR
11291 "Detailed information on TCP and BGP neighbor connections\n"
11292 "Neighbor to display information about\n"
11293 "Neighbor to display information about\n"
11294 "Display routes learned from neighbor\n")
11295{
paulbb46e942003-10-24 19:02:03 +000011296 struct peer *peer;
11297
11298 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11299 if (! peer)
11300 return CMD_WARNING;
11301
11302 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011303 bgp_show_type_neighbor);
11304}
paulbb46e942003-10-24 19:02:03 +000011305
11306ALIAS (show_bgp_view_neighbor_flap,
11307 show_bgp_neighbor_flap_cmd,
11308 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11309 SHOW_STR
11310 BGP_STR
11311 "Detailed information on TCP and BGP neighbor connections\n"
11312 "Neighbor to display information about\n"
11313 "Neighbor to display information about\n"
11314 "Display flap statistics of the routes learned from neighbor\n")
11315
11316ALIAS (show_bgp_view_neighbor_flap,
11317 show_bgp_ipv6_neighbor_flap_cmd,
11318 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11319 SHOW_STR
11320 BGP_STR
11321 "Address family\n"
11322 "Detailed information on TCP and BGP neighbor connections\n"
11323 "Neighbor to display information about\n"
11324 "Neighbor to display information about\n"
11325 "Display flap statistics of the routes learned from neighbor\n")
11326
11327ALIAS (show_bgp_view_neighbor_damp,
11328 show_bgp_neighbor_damp_cmd,
11329 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11330 SHOW_STR
11331 BGP_STR
11332 "Detailed information on TCP and BGP neighbor connections\n"
11333 "Neighbor to display information about\n"
11334 "Neighbor to display information about\n"
11335 "Display the dampened routes received from neighbor\n")
11336
11337ALIAS (show_bgp_view_neighbor_damp,
11338 show_bgp_ipv6_neighbor_damp_cmd,
11339 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11340 SHOW_STR
11341 BGP_STR
11342 "Address family\n"
11343 "Detailed information on TCP and BGP neighbor connections\n"
11344 "Neighbor to display information about\n"
11345 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011346 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011347
11348DEFUN (show_bgp_view_rsclient,
11349 show_bgp_view_rsclient_cmd,
11350 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11351 SHOW_STR
11352 BGP_STR
11353 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011354 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011355 "Information about Route Server Client\n"
11356 NEIGHBOR_ADDR_STR)
11357{
11358 struct bgp_table *table;
11359 struct peer *peer;
11360
11361 if (argc == 2)
11362 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11363 else
11364 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11365
11366 if (! peer)
11367 return CMD_WARNING;
11368
11369 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11370 {
11371 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11372 VTY_NEWLINE);
11373 return CMD_WARNING;
11374 }
11375
11376 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11377 PEER_FLAG_RSERVER_CLIENT))
11378 {
11379 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11380 VTY_NEWLINE);
11381 return CMD_WARNING;
11382 }
11383
11384 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11385
ajs5a646652004-11-05 01:25:55 +000011386 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011387}
11388
11389ALIAS (show_bgp_view_rsclient,
11390 show_bgp_rsclient_cmd,
11391 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11392 SHOW_STR
11393 BGP_STR
11394 "Information about Route Server Client\n"
11395 NEIGHBOR_ADDR_STR)
11396
Michael Lambert95cbbd22010-07-23 14:43:04 -040011397DEFUN (show_bgp_view_ipv6_safi_rsclient,
11398 show_bgp_view_ipv6_safi_rsclient_cmd,
11399 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11400 SHOW_STR
11401 BGP_STR
11402 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011403 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011404 "Address family\n"
11405 "Address Family modifier\n"
11406 "Address Family modifier\n"
11407 "Information about Route Server Client\n"
11408 NEIGHBOR_ADDR_STR)
11409{
11410 struct bgp_table *table;
11411 struct peer *peer;
11412 safi_t safi;
11413
11414 if (argc == 3) {
11415 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11416 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11417 } else {
11418 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11419 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11420 }
11421
11422 if (! peer)
11423 return CMD_WARNING;
11424
11425 if (! peer->afc[AFI_IP6][safi])
11426 {
11427 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11428 VTY_NEWLINE);
11429 return CMD_WARNING;
11430 }
11431
11432 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11433 PEER_FLAG_RSERVER_CLIENT))
11434 {
11435 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11436 VTY_NEWLINE);
11437 return CMD_WARNING;
11438 }
11439
11440 table = peer->rib[AFI_IP6][safi];
11441
11442 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11443}
11444
11445ALIAS (show_bgp_view_ipv6_safi_rsclient,
11446 show_bgp_ipv6_safi_rsclient_cmd,
11447 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11448 SHOW_STR
11449 BGP_STR
11450 "Address family\n"
11451 "Address Family modifier\n"
11452 "Address Family modifier\n"
11453 "Information about Route Server Client\n"
11454 NEIGHBOR_ADDR_STR)
11455
paulfee0f4c2004-09-13 05:12:46 +000011456DEFUN (show_bgp_view_rsclient_route,
11457 show_bgp_view_rsclient_route_cmd,
11458 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11459 SHOW_STR
11460 BGP_STR
11461 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011462 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011463 "Information about Route Server Client\n"
11464 NEIGHBOR_ADDR_STR
11465 "Network in the BGP routing table to display\n")
11466{
11467 struct bgp *bgp;
11468 struct peer *peer;
11469
11470 /* BGP structure lookup. */
11471 if (argc == 3)
11472 {
11473 bgp = bgp_lookup_by_name (argv[0]);
11474 if (bgp == NULL)
11475 {
11476 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11477 return CMD_WARNING;
11478 }
11479 }
11480 else
11481 {
11482 bgp = bgp_get_default ();
11483 if (bgp == NULL)
11484 {
11485 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11486 return CMD_WARNING;
11487 }
11488 }
11489
11490 if (argc == 3)
11491 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11492 else
11493 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11494
11495 if (! peer)
11496 return CMD_WARNING;
11497
11498 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11499 {
11500 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11501 VTY_NEWLINE);
11502 return CMD_WARNING;
11503 }
11504
11505 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11506 PEER_FLAG_RSERVER_CLIENT))
11507 {
11508 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11509 VTY_NEWLINE);
11510 return CMD_WARNING;
11511 }
11512
11513 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11514 (argc == 3) ? argv[2] : argv[1],
11515 AFI_IP6, SAFI_UNICAST, NULL, 0);
11516}
11517
11518ALIAS (show_bgp_view_rsclient_route,
11519 show_bgp_rsclient_route_cmd,
11520 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11521 SHOW_STR
11522 BGP_STR
11523 "Information about Route Server Client\n"
11524 NEIGHBOR_ADDR_STR
11525 "Network in the BGP routing table to display\n")
11526
Michael Lambert95cbbd22010-07-23 14:43:04 -040011527DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11528 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11529 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11530 SHOW_STR
11531 BGP_STR
11532 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011533 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011534 "Address family\n"
11535 "Address Family modifier\n"
11536 "Address Family modifier\n"
11537 "Information about Route Server Client\n"
11538 NEIGHBOR_ADDR_STR
11539 "Network in the BGP routing table to display\n")
11540{
11541 struct bgp *bgp;
11542 struct peer *peer;
11543 safi_t safi;
11544
11545 /* BGP structure lookup. */
11546 if (argc == 4)
11547 {
11548 bgp = bgp_lookup_by_name (argv[0]);
11549 if (bgp == NULL)
11550 {
11551 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11552 return CMD_WARNING;
11553 }
11554 }
11555 else
11556 {
11557 bgp = bgp_get_default ();
11558 if (bgp == NULL)
11559 {
11560 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11561 return CMD_WARNING;
11562 }
11563 }
11564
11565 if (argc == 4) {
11566 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11567 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11568 } else {
11569 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11570 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11571 }
11572
11573 if (! peer)
11574 return CMD_WARNING;
11575
11576 if (! peer->afc[AFI_IP6][safi])
11577 {
11578 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11579 VTY_NEWLINE);
11580 return CMD_WARNING;
11581}
11582
11583 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11584 PEER_FLAG_RSERVER_CLIENT))
11585 {
11586 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11587 VTY_NEWLINE);
11588 return CMD_WARNING;
11589 }
11590
11591 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11592 (argc == 4) ? argv[3] : argv[2],
11593 AFI_IP6, safi, NULL, 0);
11594}
11595
11596ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11597 show_bgp_ipv6_safi_rsclient_route_cmd,
11598 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11599 SHOW_STR
11600 BGP_STR
11601 "Address family\n"
11602 "Address Family modifier\n"
11603 "Address Family modifier\n"
11604 "Information about Route Server Client\n"
11605 NEIGHBOR_ADDR_STR
11606 "Network in the BGP routing table to display\n")
11607
paulfee0f4c2004-09-13 05:12:46 +000011608DEFUN (show_bgp_view_rsclient_prefix,
11609 show_bgp_view_rsclient_prefix_cmd,
11610 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11611 SHOW_STR
11612 BGP_STR
11613 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011614 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011615 "Information about Route Server Client\n"
11616 NEIGHBOR_ADDR_STR
11617 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11618{
11619 struct bgp *bgp;
11620 struct peer *peer;
11621
11622 /* BGP structure lookup. */
11623 if (argc == 3)
11624 {
11625 bgp = bgp_lookup_by_name (argv[0]);
11626 if (bgp == NULL)
11627 {
11628 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11629 return CMD_WARNING;
11630 }
11631 }
11632 else
11633 {
11634 bgp = bgp_get_default ();
11635 if (bgp == NULL)
11636 {
11637 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11638 return CMD_WARNING;
11639 }
11640 }
11641
11642 if (argc == 3)
11643 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11644 else
11645 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11646
11647 if (! peer)
11648 return CMD_WARNING;
11649
11650 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11651 {
11652 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11653 VTY_NEWLINE);
11654 return CMD_WARNING;
11655 }
11656
11657 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11658 PEER_FLAG_RSERVER_CLIENT))
11659 {
11660 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11661 VTY_NEWLINE);
11662 return CMD_WARNING;
11663 }
11664
11665 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11666 (argc == 3) ? argv[2] : argv[1],
11667 AFI_IP6, SAFI_UNICAST, NULL, 1);
11668}
11669
11670ALIAS (show_bgp_view_rsclient_prefix,
11671 show_bgp_rsclient_prefix_cmd,
11672 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11673 SHOW_STR
11674 BGP_STR
11675 "Information about Route Server Client\n"
11676 NEIGHBOR_ADDR_STR
11677 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11678
Michael Lambert95cbbd22010-07-23 14:43:04 -040011679DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11680 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11681 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11682 SHOW_STR
11683 BGP_STR
11684 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011685 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011686 "Address family\n"
11687 "Address Family modifier\n"
11688 "Address Family modifier\n"
11689 "Information about Route Server Client\n"
11690 NEIGHBOR_ADDR_STR
11691 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11692{
11693 struct bgp *bgp;
11694 struct peer *peer;
11695 safi_t safi;
11696
11697 /* BGP structure lookup. */
11698 if (argc == 4)
11699 {
11700 bgp = bgp_lookup_by_name (argv[0]);
11701 if (bgp == NULL)
11702 {
11703 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11704 return CMD_WARNING;
11705 }
11706 }
11707 else
11708 {
11709 bgp = bgp_get_default ();
11710 if (bgp == NULL)
11711 {
11712 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11713 return CMD_WARNING;
11714 }
11715 }
11716
11717 if (argc == 4) {
11718 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11719 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11720 } else {
11721 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11722 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11723 }
11724
11725 if (! peer)
11726 return CMD_WARNING;
11727
11728 if (! peer->afc[AFI_IP6][safi])
11729 {
11730 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11731 VTY_NEWLINE);
11732 return CMD_WARNING;
11733}
11734
11735 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11736 PEER_FLAG_RSERVER_CLIENT))
11737{
11738 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11739 VTY_NEWLINE);
11740 return CMD_WARNING;
11741 }
11742
11743 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11744 (argc == 4) ? argv[3] : argv[2],
11745 AFI_IP6, safi, NULL, 1);
11746}
11747
11748ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11749 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11750 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11751 SHOW_STR
11752 BGP_STR
11753 "Address family\n"
11754 "Address Family modifier\n"
11755 "Address Family modifier\n"
11756 "Information about Route Server Client\n"
11757 NEIGHBOR_ADDR_STR
11758 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11759
paul718e3742002-12-13 20:15:29 +000011760#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011761
paul718e3742002-12-13 20:15:29 +000011762struct bgp_table *bgp_distance_table;
11763
11764struct bgp_distance
11765{
11766 /* Distance value for the IP source prefix. */
11767 u_char distance;
11768
11769 /* Name of the access-list to be matched. */
11770 char *access_list;
11771};
11772
paul94f2b392005-06-28 12:44:16 +000011773static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011774bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011775{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011776 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011777}
11778
paul94f2b392005-06-28 12:44:16 +000011779static void
paul718e3742002-12-13 20:15:29 +000011780bgp_distance_free (struct bgp_distance *bdistance)
11781{
11782 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11783}
11784
paul94f2b392005-06-28 12:44:16 +000011785static int
paulfd79ac92004-10-13 05:06:08 +000011786bgp_distance_set (struct vty *vty, const char *distance_str,
11787 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011788{
11789 int ret;
11790 struct prefix_ipv4 p;
11791 u_char distance;
11792 struct bgp_node *rn;
11793 struct bgp_distance *bdistance;
11794
11795 ret = str2prefix_ipv4 (ip_str, &p);
11796 if (ret == 0)
11797 {
11798 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11799 return CMD_WARNING;
11800 }
11801
11802 distance = atoi (distance_str);
11803
11804 /* Get BGP distance node. */
11805 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11806 if (rn->info)
11807 {
11808 bdistance = rn->info;
11809 bgp_unlock_node (rn);
11810 }
11811 else
11812 {
11813 bdistance = bgp_distance_new ();
11814 rn->info = bdistance;
11815 }
11816
11817 /* Set distance value. */
11818 bdistance->distance = distance;
11819
11820 /* Reset access-list configuration. */
11821 if (bdistance->access_list)
11822 {
11823 free (bdistance->access_list);
11824 bdistance->access_list = NULL;
11825 }
11826 if (access_list_str)
11827 bdistance->access_list = strdup (access_list_str);
11828
11829 return CMD_SUCCESS;
11830}
11831
paul94f2b392005-06-28 12:44:16 +000011832static int
paulfd79ac92004-10-13 05:06:08 +000011833bgp_distance_unset (struct vty *vty, const char *distance_str,
11834 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011835{
11836 int ret;
11837 struct prefix_ipv4 p;
11838 u_char distance;
11839 struct bgp_node *rn;
11840 struct bgp_distance *bdistance;
11841
11842 ret = str2prefix_ipv4 (ip_str, &p);
11843 if (ret == 0)
11844 {
11845 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11846 return CMD_WARNING;
11847 }
11848
11849 distance = atoi (distance_str);
11850
11851 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11852 if (! rn)
11853 {
11854 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11855 return CMD_WARNING;
11856 }
11857
11858 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010011859
11860 if (bdistance->distance != distance)
11861 {
11862 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
11863 return CMD_WARNING;
11864 }
11865
paul718e3742002-12-13 20:15:29 +000011866 if (bdistance->access_list)
11867 free (bdistance->access_list);
11868 bgp_distance_free (bdistance);
11869
11870 rn->info = NULL;
11871 bgp_unlock_node (rn);
11872 bgp_unlock_node (rn);
11873
11874 return CMD_SUCCESS;
11875}
11876
paul718e3742002-12-13 20:15:29 +000011877/* Apply BGP information to distance method. */
11878u_char
11879bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11880{
11881 struct bgp_node *rn;
11882 struct prefix_ipv4 q;
11883 struct peer *peer;
11884 struct bgp_distance *bdistance;
11885 struct access_list *alist;
11886 struct bgp_static *bgp_static;
11887
11888 if (! bgp)
11889 return 0;
11890
11891 if (p->family != AF_INET)
11892 return 0;
11893
11894 peer = rinfo->peer;
11895
11896 if (peer->su.sa.sa_family != AF_INET)
11897 return 0;
11898
11899 memset (&q, 0, sizeof (struct prefix_ipv4));
11900 q.family = AF_INET;
11901 q.prefix = peer->su.sin.sin_addr;
11902 q.prefixlen = IPV4_MAX_BITLEN;
11903
11904 /* Check source address. */
11905 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11906 if (rn)
11907 {
11908 bdistance = rn->info;
11909 bgp_unlock_node (rn);
11910
11911 if (bdistance->access_list)
11912 {
11913 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11914 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11915 return bdistance->distance;
11916 }
11917 else
11918 return bdistance->distance;
11919 }
11920
11921 /* Backdoor check. */
11922 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11923 if (rn)
11924 {
11925 bgp_static = rn->info;
11926 bgp_unlock_node (rn);
11927
11928 if (bgp_static->backdoor)
11929 {
11930 if (bgp->distance_local)
11931 return bgp->distance_local;
11932 else
11933 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11934 }
11935 }
11936
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011937 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011938 {
11939 if (bgp->distance_ebgp)
11940 return bgp->distance_ebgp;
11941 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11942 }
11943 else
11944 {
11945 if (bgp->distance_ibgp)
11946 return bgp->distance_ibgp;
11947 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11948 }
11949}
11950
11951DEFUN (bgp_distance,
11952 bgp_distance_cmd,
11953 "distance bgp <1-255> <1-255> <1-255>",
11954 "Define an administrative distance\n"
11955 "BGP distance\n"
11956 "Distance for routes external to the AS\n"
11957 "Distance for routes internal to the AS\n"
11958 "Distance for local routes\n")
11959{
11960 struct bgp *bgp;
11961
11962 bgp = vty->index;
11963
11964 bgp->distance_ebgp = atoi (argv[0]);
11965 bgp->distance_ibgp = atoi (argv[1]);
11966 bgp->distance_local = atoi (argv[2]);
11967 return CMD_SUCCESS;
11968}
11969
11970DEFUN (no_bgp_distance,
11971 no_bgp_distance_cmd,
11972 "no distance bgp <1-255> <1-255> <1-255>",
11973 NO_STR
11974 "Define an administrative distance\n"
11975 "BGP distance\n"
11976 "Distance for routes external to the AS\n"
11977 "Distance for routes internal to the AS\n"
11978 "Distance for local routes\n")
11979{
11980 struct bgp *bgp;
11981
11982 bgp = vty->index;
11983
11984 bgp->distance_ebgp= 0;
11985 bgp->distance_ibgp = 0;
11986 bgp->distance_local = 0;
11987 return CMD_SUCCESS;
11988}
11989
11990ALIAS (no_bgp_distance,
11991 no_bgp_distance2_cmd,
11992 "no distance bgp",
11993 NO_STR
11994 "Define an administrative distance\n"
11995 "BGP distance\n")
11996
11997DEFUN (bgp_distance_source,
11998 bgp_distance_source_cmd,
11999 "distance <1-255> A.B.C.D/M",
12000 "Define an administrative distance\n"
12001 "Administrative distance\n"
12002 "IP source prefix\n")
12003{
12004 bgp_distance_set (vty, argv[0], argv[1], NULL);
12005 return CMD_SUCCESS;
12006}
12007
12008DEFUN (no_bgp_distance_source,
12009 no_bgp_distance_source_cmd,
12010 "no distance <1-255> A.B.C.D/M",
12011 NO_STR
12012 "Define an administrative distance\n"
12013 "Administrative distance\n"
12014 "IP source prefix\n")
12015{
12016 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12017 return CMD_SUCCESS;
12018}
12019
12020DEFUN (bgp_distance_source_access_list,
12021 bgp_distance_source_access_list_cmd,
12022 "distance <1-255> A.B.C.D/M WORD",
12023 "Define an administrative distance\n"
12024 "Administrative distance\n"
12025 "IP source prefix\n"
12026 "Access list name\n")
12027{
12028 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12029 return CMD_SUCCESS;
12030}
12031
12032DEFUN (no_bgp_distance_source_access_list,
12033 no_bgp_distance_source_access_list_cmd,
12034 "no distance <1-255> A.B.C.D/M WORD",
12035 NO_STR
12036 "Define an administrative distance\n"
12037 "Administrative distance\n"
12038 "IP source prefix\n"
12039 "Access list name\n")
12040{
12041 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12042 return CMD_SUCCESS;
12043}
David Lamparter6b0655a2014-06-04 06:53:35 +020012044
paul718e3742002-12-13 20:15:29 +000012045DEFUN (bgp_damp_set,
12046 bgp_damp_set_cmd,
12047 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12048 "BGP Specific commands\n"
12049 "Enable route-flap dampening\n"
12050 "Half-life time for the penalty\n"
12051 "Value to start reusing a route\n"
12052 "Value to start suppressing a route\n"
12053 "Maximum duration to suppress a stable route\n")
12054{
12055 struct bgp *bgp;
12056 int half = DEFAULT_HALF_LIFE * 60;
12057 int reuse = DEFAULT_REUSE;
12058 int suppress = DEFAULT_SUPPRESS;
12059 int max = 4 * half;
12060
12061 if (argc == 4)
12062 {
12063 half = atoi (argv[0]) * 60;
12064 reuse = atoi (argv[1]);
12065 suppress = atoi (argv[2]);
12066 max = atoi (argv[3]) * 60;
12067 }
12068 else if (argc == 1)
12069 {
12070 half = atoi (argv[0]) * 60;
12071 max = 4 * half;
12072 }
12073
12074 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012075
12076 if (suppress < reuse)
12077 {
12078 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12079 VTY_NEWLINE);
12080 return 0;
12081 }
12082
paul718e3742002-12-13 20:15:29 +000012083 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12084 half, reuse, suppress, max);
12085}
12086
12087ALIAS (bgp_damp_set,
12088 bgp_damp_set2_cmd,
12089 "bgp dampening <1-45>",
12090 "BGP Specific commands\n"
12091 "Enable route-flap dampening\n"
12092 "Half-life time for the penalty\n")
12093
12094ALIAS (bgp_damp_set,
12095 bgp_damp_set3_cmd,
12096 "bgp dampening",
12097 "BGP Specific commands\n"
12098 "Enable route-flap dampening\n")
12099
12100DEFUN (bgp_damp_unset,
12101 bgp_damp_unset_cmd,
12102 "no bgp dampening",
12103 NO_STR
12104 "BGP Specific commands\n"
12105 "Enable route-flap dampening\n")
12106{
12107 struct bgp *bgp;
12108
12109 bgp = vty->index;
12110 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12111}
12112
12113ALIAS (bgp_damp_unset,
12114 bgp_damp_unset2_cmd,
12115 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12116 NO_STR
12117 "BGP Specific commands\n"
12118 "Enable route-flap dampening\n"
12119 "Half-life time for the penalty\n"
12120 "Value to start reusing a route\n"
12121 "Value to start suppressing a route\n"
12122 "Maximum duration to suppress a stable route\n")
12123
12124DEFUN (show_ip_bgp_dampened_paths,
12125 show_ip_bgp_dampened_paths_cmd,
12126 "show ip bgp dampened-paths",
12127 SHOW_STR
12128 IP_STR
12129 BGP_STR
12130 "Display paths suppressed due to dampening\n")
12131{
ajs5a646652004-11-05 01:25:55 +000012132 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12133 NULL);
paul718e3742002-12-13 20:15:29 +000012134}
12135
Balaji3921cc52015-05-16 23:12:17 +053012136ALIAS (show_ip_bgp_dampened_paths,
12137 show_ip_bgp_damp_dampened_paths_cmd,
12138 "show ip bgp dampening dampened-paths",
12139 SHOW_STR
12140 IP_STR
12141 BGP_STR
12142 "Display detailed information about dampening\n"
12143 "Display paths suppressed due to dampening\n")
12144
paul718e3742002-12-13 20:15:29 +000012145DEFUN (show_ip_bgp_flap_statistics,
12146 show_ip_bgp_flap_statistics_cmd,
12147 "show ip bgp flap-statistics",
12148 SHOW_STR
12149 IP_STR
12150 BGP_STR
12151 "Display flap statistics of routes\n")
12152{
ajs5a646652004-11-05 01:25:55 +000012153 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12154 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012155}
David Lamparter6b0655a2014-06-04 06:53:35 +020012156
Balaji3921cc52015-05-16 23:12:17 +053012157ALIAS (show_ip_bgp_flap_statistics,
12158 show_ip_bgp_damp_flap_statistics_cmd,
12159 "show ip bgp dampening flap-statistics",
12160 SHOW_STR
12161 IP_STR
12162 BGP_STR
12163 "Display detailed information about dampening\n"
12164 "Display flap statistics of routes\n")
12165
paul718e3742002-12-13 20:15:29 +000012166/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012167static int
paulfd79ac92004-10-13 05:06:08 +000012168bgp_clear_damp_route (struct vty *vty, const char *view_name,
12169 const char *ip_str, afi_t afi, safi_t safi,
12170 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012171{
12172 int ret;
12173 struct prefix match;
12174 struct bgp_node *rn;
12175 struct bgp_node *rm;
12176 struct bgp_info *ri;
12177 struct bgp_info *ri_temp;
12178 struct bgp *bgp;
12179 struct bgp_table *table;
12180
12181 /* BGP structure lookup. */
12182 if (view_name)
12183 {
12184 bgp = bgp_lookup_by_name (view_name);
12185 if (bgp == NULL)
12186 {
12187 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12188 return CMD_WARNING;
12189 }
12190 }
12191 else
12192 {
12193 bgp = bgp_get_default ();
12194 if (bgp == NULL)
12195 {
12196 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12197 return CMD_WARNING;
12198 }
12199 }
12200
12201 /* Check IP address argument. */
12202 ret = str2prefix (ip_str, &match);
12203 if (! ret)
12204 {
12205 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12206 return CMD_WARNING;
12207 }
12208
12209 match.family = afi2family (afi);
12210
12211 if (safi == SAFI_MPLS_VPN)
12212 {
12213 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12214 {
12215 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12216 continue;
12217
12218 if ((table = rn->info) != NULL)
12219 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012220 {
12221 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12222 {
12223 ri = rm->info;
12224 while (ri)
12225 {
12226 if (ri->extra && ri->extra->damp_info)
12227 {
12228 ri_temp = ri->next;
12229 bgp_damp_info_free (ri->extra->damp_info, 1);
12230 ri = ri_temp;
12231 }
12232 else
12233 ri = ri->next;
12234 }
12235 }
12236
12237 bgp_unlock_node (rm);
12238 }
paul718e3742002-12-13 20:15:29 +000012239 }
12240 }
12241 else
12242 {
12243 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012244 {
12245 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12246 {
12247 ri = rn->info;
12248 while (ri)
12249 {
12250 if (ri->extra && ri->extra->damp_info)
12251 {
12252 ri_temp = ri->next;
12253 bgp_damp_info_free (ri->extra->damp_info, 1);
12254 ri = ri_temp;
12255 }
12256 else
12257 ri = ri->next;
12258 }
12259 }
12260
12261 bgp_unlock_node (rn);
12262 }
paul718e3742002-12-13 20:15:29 +000012263 }
12264
12265 return CMD_SUCCESS;
12266}
12267
12268DEFUN (clear_ip_bgp_dampening,
12269 clear_ip_bgp_dampening_cmd,
12270 "clear ip bgp dampening",
12271 CLEAR_STR
12272 IP_STR
12273 BGP_STR
12274 "Clear route flap dampening information\n")
12275{
12276 bgp_damp_info_clean ();
12277 return CMD_SUCCESS;
12278}
12279
12280DEFUN (clear_ip_bgp_dampening_prefix,
12281 clear_ip_bgp_dampening_prefix_cmd,
12282 "clear ip bgp dampening A.B.C.D/M",
12283 CLEAR_STR
12284 IP_STR
12285 BGP_STR
12286 "Clear route flap dampening information\n"
12287 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12288{
12289 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12290 SAFI_UNICAST, NULL, 1);
12291}
12292
12293DEFUN (clear_ip_bgp_dampening_address,
12294 clear_ip_bgp_dampening_address_cmd,
12295 "clear ip bgp dampening A.B.C.D",
12296 CLEAR_STR
12297 IP_STR
12298 BGP_STR
12299 "Clear route flap dampening information\n"
12300 "Network to clear damping information\n")
12301{
12302 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12303 SAFI_UNICAST, NULL, 0);
12304}
12305
12306DEFUN (clear_ip_bgp_dampening_address_mask,
12307 clear_ip_bgp_dampening_address_mask_cmd,
12308 "clear ip bgp dampening A.B.C.D A.B.C.D",
12309 CLEAR_STR
12310 IP_STR
12311 BGP_STR
12312 "Clear route flap dampening information\n"
12313 "Network to clear damping information\n"
12314 "Network mask\n")
12315{
12316 int ret;
12317 char prefix_str[BUFSIZ];
12318
12319 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12320 if (! ret)
12321 {
12322 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12323 return CMD_WARNING;
12324 }
12325
12326 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12327 SAFI_UNICAST, NULL, 0);
12328}
David Lamparter6b0655a2014-06-04 06:53:35 +020012329
paul94f2b392005-06-28 12:44:16 +000012330static int
paul718e3742002-12-13 20:15:29 +000012331bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12332 afi_t afi, safi_t safi, int *write)
12333{
12334 struct bgp_node *prn;
12335 struct bgp_node *rn;
12336 struct bgp_table *table;
12337 struct prefix *p;
12338 struct prefix_rd *prd;
12339 struct bgp_static *bgp_static;
12340 u_int32_t label;
12341 char buf[SU_ADDRSTRLEN];
12342 char rdbuf[RD_ADDRSTRLEN];
12343
12344 /* Network configuration. */
12345 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12346 if ((table = prn->info) != NULL)
12347 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12348 if ((bgp_static = rn->info) != NULL)
12349 {
12350 p = &rn->p;
12351 prd = (struct prefix_rd *) &prn->p;
12352
12353 /* "address-family" display. */
12354 bgp_config_write_family_header (vty, afi, safi, write);
12355
12356 /* "network" configuration display. */
12357 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12358 label = decode_label (bgp_static->tag);
12359
12360 vty_out (vty, " network %s/%d rd %s tag %d",
12361 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12362 p->prefixlen,
12363 rdbuf, label);
12364 vty_out (vty, "%s", VTY_NEWLINE);
12365 }
12366 return 0;
12367}
12368
12369/* Configuration of static route announcement and aggregate
12370 information. */
12371int
12372bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12373 afi_t afi, safi_t safi, int *write)
12374{
12375 struct bgp_node *rn;
12376 struct prefix *p;
12377 struct bgp_static *bgp_static;
12378 struct bgp_aggregate *bgp_aggregate;
12379 char buf[SU_ADDRSTRLEN];
12380
12381 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12382 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12383
12384 /* Network configuration. */
12385 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12386 if ((bgp_static = rn->info) != NULL)
12387 {
12388 p = &rn->p;
12389
12390 /* "address-family" display. */
12391 bgp_config_write_family_header (vty, afi, safi, write);
12392
12393 /* "network" configuration display. */
12394 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12395 {
12396 u_int32_t destination;
12397 struct in_addr netmask;
12398
12399 destination = ntohl (p->u.prefix4.s_addr);
12400 masklen2ip (p->prefixlen, &netmask);
12401 vty_out (vty, " network %s",
12402 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12403
12404 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12405 || (IN_CLASSB (destination) && p->prefixlen == 16)
12406 || (IN_CLASSA (destination) && p->prefixlen == 8)
12407 || p->u.prefix4.s_addr == 0)
12408 {
12409 /* Natural mask is not display. */
12410 }
12411 else
12412 vty_out (vty, " mask %s", inet_ntoa (netmask));
12413 }
12414 else
12415 {
12416 vty_out (vty, " network %s/%d",
12417 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12418 p->prefixlen);
12419 }
12420
12421 if (bgp_static->rmap.name)
12422 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012423 else
12424 {
12425 if (bgp_static->backdoor)
12426 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012427 }
paul718e3742002-12-13 20:15:29 +000012428
12429 vty_out (vty, "%s", VTY_NEWLINE);
12430 }
12431
12432 /* Aggregate-address configuration. */
12433 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12434 if ((bgp_aggregate = rn->info) != NULL)
12435 {
12436 p = &rn->p;
12437
12438 /* "address-family" display. */
12439 bgp_config_write_family_header (vty, afi, safi, write);
12440
12441 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12442 {
12443 struct in_addr netmask;
12444
12445 masklen2ip (p->prefixlen, &netmask);
12446 vty_out (vty, " aggregate-address %s %s",
12447 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12448 inet_ntoa (netmask));
12449 }
12450 else
12451 {
12452 vty_out (vty, " aggregate-address %s/%d",
12453 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12454 p->prefixlen);
12455 }
12456
12457 if (bgp_aggregate->as_set)
12458 vty_out (vty, " as-set");
12459
12460 if (bgp_aggregate->summary_only)
12461 vty_out (vty, " summary-only");
12462
12463 vty_out (vty, "%s", VTY_NEWLINE);
12464 }
12465
12466 return 0;
12467}
12468
12469int
12470bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12471{
12472 struct bgp_node *rn;
12473 struct bgp_distance *bdistance;
12474
12475 /* Distance configuration. */
12476 if (bgp->distance_ebgp
12477 && bgp->distance_ibgp
12478 && bgp->distance_local
12479 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12480 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12481 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12482 vty_out (vty, " distance bgp %d %d %d%s",
12483 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12484 VTY_NEWLINE);
12485
12486 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12487 if ((bdistance = rn->info) != NULL)
12488 {
12489 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12490 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12491 bdistance->access_list ? bdistance->access_list : "",
12492 VTY_NEWLINE);
12493 }
12494
12495 return 0;
12496}
12497
12498/* Allocate routing table structure and install commands. */
12499void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012500bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012501{
12502 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012503 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012504
12505 /* IPv4 BGP commands. */
12506 install_element (BGP_NODE, &bgp_network_cmd);
12507 install_element (BGP_NODE, &bgp_network_mask_cmd);
12508 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12509 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12510 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12511 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12512 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12513 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12514 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12515 install_element (BGP_NODE, &no_bgp_network_cmd);
12516 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12517 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12518 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12519 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12520 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12521 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12522 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12523 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12524
12525 install_element (BGP_NODE, &aggregate_address_cmd);
12526 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12527 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12528 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12529 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12530 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12531 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12532 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12533 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12534 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12535 install_element (BGP_NODE, &no_aggregate_address_cmd);
12536 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12537 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12538 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12539 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12540 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12541 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12542 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12543 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12544 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12545
12546 /* IPv4 unicast configuration. */
12547 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12548 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12549 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12550 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12551 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12552 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012553 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012554 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12555 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12556 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12557 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12558 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012559
paul718e3742002-12-13 20:15:29 +000012560 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12561 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12562 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12563 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12564 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12565 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12566 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12567 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12568 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12569 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12570 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12571 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12572 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12573 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12574 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12575 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12576 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12577 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12578 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12579 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12580
12581 /* IPv4 multicast configuration. */
12582 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12583 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12584 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12585 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12586 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12587 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12588 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12589 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12590 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12591 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12592 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12593 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12594 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12595 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12596 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12597 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12598 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12599 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12600 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12601 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12602 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12603 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12604 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12605 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12606 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12607 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12608 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12609 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12610 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12611 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12612 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12613 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12614
12615 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12616 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012617 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012618 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12619 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012620 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012621 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12622 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12623 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12624 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012625 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012626 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12627 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12628 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12629 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12630 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12631 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12632 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12633 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12634 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12635 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12636 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12637 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12638 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12639 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12640 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12641 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12642 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12643 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12644 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12645 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12646 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12647 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12648 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12649 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12650 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012651 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12652 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12653 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12654 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12655 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012656 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12657 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12658 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12659 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12660 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12661 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12662 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12663 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12664 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12665 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12666 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12667 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12668 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12669 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12670 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12671 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12672 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12673 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012674 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012675 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12676 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12677 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12678 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012679 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012680 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012681 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012682 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012683 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012684 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012685 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012686 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12687 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012688 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012689 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12690 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012691 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012692 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012693 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012694 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012695 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012696 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012697 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012698 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12699 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012700 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012701 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012702 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012703 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012704 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012705 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012706 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12707 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012708 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012709 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012710 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012711 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012712 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012713 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012714
12715 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12716 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12717 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012718 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012719 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12720 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12721 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012722 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012723 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12724 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12725 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12726 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12727 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12728 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12729 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12730 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12731 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12732 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12733 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12734 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012735 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12736 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12737 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12738 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12739 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012740 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12741 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12742 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12743 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12744 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12745 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12746 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12747 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12748 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012749 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012750 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012751 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012752 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012753 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012754 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012755 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012756
12757 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12758 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012759 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012760 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12761 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012762 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012763 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12764 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12765 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12766 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012767 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012768 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12769 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12770 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12771 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12772 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12773 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12774 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12775 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12776 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12777 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12778 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12779 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12780 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12781 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12782 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12783 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12784 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12785 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12786 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12787 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12788 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12789 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12790 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12791 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12792 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012793 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12794 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12795 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12796 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12797 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012798 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12799 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12800 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12801 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12802 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12803 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12804 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12805 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12806 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12807 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12808 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12809 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12810 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12811 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12812 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12813 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12814 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12815 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012816 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012817 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12818 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12819 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12820 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012821 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012822 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012823 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012824 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012825 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012826 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012827 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012828 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12829 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012830 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012831 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012832 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000012833 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012834 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012835 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012836 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
12837 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012838 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012839 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012840 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012841 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012842 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12843 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012844 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012845 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012846 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012847 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012848 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012849 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012850 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12851 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012852 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012853 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012854 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012855 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012856 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012857 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012858
12859 /* BGP dampening clear commands */
12860 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12861 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12862 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12863 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12864
Paul Jakmaff7924f2006-09-04 01:10:36 +000012865 /* prefix count */
12866 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12867 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12868 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012869#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012870 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12871
paul718e3742002-12-13 20:15:29 +000012872 /* New config IPv6 BGP commands. */
12873 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12874 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12875 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12876 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12877
12878 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12879 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12880 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12881 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12882
G.Balaji73bfe0b2011-09-23 22:36:20 +053012883 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12884 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12885
paul718e3742002-12-13 20:15:29 +000012886 /* Old config IPv6 BGP commands. */
12887 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12888 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12889
12890 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12891 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12892 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12893 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12894
12895 install_element (VIEW_NODE, &show_bgp_cmd);
12896 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012897 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012898 install_element (VIEW_NODE, &show_bgp_route_cmd);
12899 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012900 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012901 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12902 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012903 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012904 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12905 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12906 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12907 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12908 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12909 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12910 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12911 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12912 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12913 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12914 install_element (VIEW_NODE, &show_bgp_community_cmd);
12915 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12916 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12917 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12918 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12919 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12920 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12921 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12922 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12923 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12924 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12925 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12926 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12927 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12928 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12929 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12930 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12931 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12932 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12933 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12934 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12935 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12936 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12937 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12938 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12939 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12940 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12941 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12942 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12943 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012944 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12945 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12946 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12947 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012948 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012949 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012950 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012951 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012952 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012953 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012954 install_element (VIEW_NODE, &show_bgp_view_cmd);
12955 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12956 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12957 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12958 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12959 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12960 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12961 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12962 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12963 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12964 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12965 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12966 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12967 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12968 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12969 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12970 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12971 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012972 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012973 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012974 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012975 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012976 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012977 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012978
12979 /* Restricted:
12980 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12981 */
12982 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12983 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012984 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012985 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12986 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012987 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012988 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12989 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12990 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12991 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12992 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12993 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12994 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12995 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12996 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12997 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12998 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12999 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13000 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13001 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13002 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13003 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13004 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013005 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013006 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013007 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013008 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
13009 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13010 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13011 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13012 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13013 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13014 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013015 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013016 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013017 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013018
13019 install_element (ENABLE_NODE, &show_bgp_cmd);
13020 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013021 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013022 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13023 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013024 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013025 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13026 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013027 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013028 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13029 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13030 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13031 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13032 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13033 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13034 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13035 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13036 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13037 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13038 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13039 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13040 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13041 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13042 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13043 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13044 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13045 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13046 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13047 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13048 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13049 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13050 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13051 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13052 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13053 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13054 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13055 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13056 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13057 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13058 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13059 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13060 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13061 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13062 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13063 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13064 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13065 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13066 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13067 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013068 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13069 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13070 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13071 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013072 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013073 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013074 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013075 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013076 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013077 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013078 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13079 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13080 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13081 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13082 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13083 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13084 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13085 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13086 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13087 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13088 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13089 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13090 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13091 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13092 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13093 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13094 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13095 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013096 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013097 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013098 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013099 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013100 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013101 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013102
13103 /* Statistics */
13104 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13105 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13106 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13107 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13108
paul718e3742002-12-13 20:15:29 +000013109 /* old command */
13110 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13111 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13112 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13113 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13114 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13115 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13116 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13117 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13118 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13119 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13120 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13121 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13122 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13123 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13124 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13125 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13126 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13127 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13128 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13129 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13130 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13131 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13132 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13133 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13134 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13135 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13136 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13137 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13138 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13139 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13140 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13141 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13142 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13143 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13144 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13145 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013146
paul718e3742002-12-13 20:15:29 +000013147 /* old command */
13148 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13149 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13150 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13151 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13152 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13153 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13154 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13155 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13156 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13157 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13158 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13159 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13160 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13161 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13162 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13163 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13164 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13165 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13166 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13167 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13168 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13169 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13170 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13171 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13172 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13173 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13174 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13175 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13176 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13177 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13178 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13179 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13180 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13181 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13182 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13183 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13184
13185 /* old command */
13186 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13187 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13188 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13189 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13190
13191 /* old command */
13192 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13193 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13194 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13195 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13196
13197 /* old command */
13198 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13199 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13200 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13201 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13202#endif /* HAVE_IPV6 */
13203
13204 install_element (BGP_NODE, &bgp_distance_cmd);
13205 install_element (BGP_NODE, &no_bgp_distance_cmd);
13206 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13207 install_element (BGP_NODE, &bgp_distance_source_cmd);
13208 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13209 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13210 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13211
13212 install_element (BGP_NODE, &bgp_damp_set_cmd);
13213 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13214 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13215 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13216 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13217 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13218 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13219 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13220 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13221 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013222
13223 /* Deprecated AS-Pathlimit commands */
13224 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13225 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13226 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13227 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13228 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13229 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13230
13231 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13232 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13233 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13234 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13235 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13236 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13237
13238 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13239 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13240 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13241 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13242 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13243 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13244
13245 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13246 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13247 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13248 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13249 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13250 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13251
13252 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13253 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13254 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13255 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13256 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13257 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13258
13259 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13260 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13261 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13262 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13263 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13264 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013265
13266#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013267 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13268 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013269#endif
paul718e3742002-12-13 20:15:29 +000013270}
Chris Caputo228da422009-07-18 05:44:03 +000013271
13272void
13273bgp_route_finish (void)
13274{
13275 bgp_table_unlock (bgp_distance_table);
13276 bgp_distance_table = NULL;
13277}