blob: b024d80d8e9aa5f81b0c395910b5d1d78e9aac3f [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
Lou Berger050defe2016-01-12 13:41:59 -05001483 memset (&attr, 0, sizeof(struct attr));
1484 memset (&extra, 0, sizeof(struct attr_extra));
1485
paulfee0f4c2004-09-13 05:12:46 +00001486 p = &rn->p;
1487
Paul Jakma9eda90c2007-08-30 13:36:17 +00001488 /* Announce route to Established peer. */
1489 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001490 return 0;
1491
Paul Jakma9eda90c2007-08-30 13:36:17 +00001492 /* Address family configuration check. */
1493 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001494 return 0;
1495
Paul Jakma9eda90c2007-08-30 13:36:17 +00001496 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001497 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1498 PEER_STATUS_ORF_WAIT_REFRESH))
1499 return 0;
1500
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001501 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1502 attr.extra = &extra;
1503
Avneesh Sachdev67174042012-08-17 08:19:49 -07001504 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001505 {
1506 case BGP_TABLE_MAIN:
1507 /* Announcement to peer->conf. If the route is filtered,
1508 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001509 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1510 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001511 else
1512 bgp_adj_out_unset (rn, peer, p, afi, safi);
1513 break;
1514 case BGP_TABLE_RSCLIENT:
1515 /* Announcement to peer->conf. If the route is filtered,
1516 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001517 if (selected &&
1518 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1519 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1520 else
1521 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001522 break;
1523 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001524
Lou Berger050defe2016-01-12 13:41:59 -05001525 bgp_attr_flush (&attr);
paulfee0f4c2004-09-13 05:12:46 +00001526 return 0;
paul200df112005-06-01 11:17:05 +00001527}
paulfee0f4c2004-09-13 05:12:46 +00001528
paul200df112005-06-01 11:17:05 +00001529struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001530{
paul200df112005-06-01 11:17:05 +00001531 struct bgp *bgp;
1532 struct bgp_node *rn;
1533 afi_t afi;
1534 safi_t safi;
1535};
1536
1537static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001538bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001539{
paul0fb58d52005-11-14 14:31:49 +00001540 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001541 struct bgp *bgp = pq->bgp;
1542 struct bgp_node *rn = pq->rn;
1543 afi_t afi = pq->afi;
1544 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001545 struct bgp_info *new_select;
1546 struct bgp_info *old_select;
1547 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001548 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001549 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001550
paulfee0f4c2004-09-13 05:12:46 +00001551 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001552 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001553 new_select = old_and_new.new;
1554 old_select = old_and_new.old;
1555
paul200df112005-06-01 11:17:05 +00001556 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1557 {
Chris Caputo228da422009-07-18 05:44:03 +00001558 if (rsclient->group)
1559 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1560 {
1561 /* Nothing to do. */
1562 if (old_select && old_select == new_select)
1563 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1564 continue;
paulfee0f4c2004-09-13 05:12:46 +00001565
Chris Caputo228da422009-07-18 05:44:03 +00001566 if (old_select)
1567 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1568 if (new_select)
1569 {
1570 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1571 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001572 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1573 }
paulfee0f4c2004-09-13 05:12:46 +00001574
Chris Caputo228da422009-07-18 05:44:03 +00001575 bgp_process_announce_selected (rsclient, new_select, rn,
1576 afi, safi);
1577 }
paul200df112005-06-01 11:17:05 +00001578 }
1579 else
1580 {
hassob7395792005-08-26 12:58:38 +00001581 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001582 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001583 if (new_select)
1584 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001585 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1586 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001587 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001588 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001589 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001590 }
paulfee0f4c2004-09-13 05:12:46 +00001591
paulb40d9392005-08-22 22:34:41 +00001592 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1593 bgp_info_reap (rn, old_select);
1594
paul200df112005-06-01 11:17:05 +00001595 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1596 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001597}
1598
paul200df112005-06-01 11:17:05 +00001599static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001600bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001601{
paul0fb58d52005-11-14 14:31:49 +00001602 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001603 struct bgp *bgp = pq->bgp;
1604 struct bgp_node *rn = pq->rn;
1605 afi_t afi = pq->afi;
1606 safi_t safi = pq->safi;
1607 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001608 struct bgp_info *new_select;
1609 struct bgp_info *old_select;
1610 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001611 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001612 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001613
paulfee0f4c2004-09-13 05:12:46 +00001614 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001615 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001616 old_select = old_and_new.old;
1617 new_select = old_and_new.new;
1618
1619 /* Nothing to do. */
1620 if (old_select && old_select == new_select)
1621 {
1622 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001623 {
Josh Bailey8196f132011-07-20 20:47:07 -07001624 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1625 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001626 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001627
Josh Bailey8196f132011-07-20 20:47:07 -07001628 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001629 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1630 return WQ_SUCCESS;
1631 }
paulfee0f4c2004-09-13 05:12:46 +00001632 }
paul718e3742002-12-13 20:15:29 +00001633
hasso338b3422005-02-23 14:27:24 +00001634 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001635 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001636 if (new_select)
1637 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001638 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1639 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001640 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001641 }
1642
1643
paul718e3742002-12-13 20:15:29 +00001644 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001645 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001646 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001647 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001648 }
1649
1650 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001651 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1652 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001653 {
1654 if (new_select
1655 && new_select->type == ZEBRA_ROUTE_BGP
1656 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001657 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001658 else
1659 {
1660 /* Withdraw the route from the kernel. */
1661 if (old_select
1662 && old_select->type == ZEBRA_ROUTE_BGP
1663 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001664 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001665 }
1666 }
paulb40d9392005-08-22 22:34:41 +00001667
Lou Berger050defe2016-01-12 13:41:59 -05001668 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001669 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1670 bgp_info_reap (rn, old_select);
1671
paul200df112005-06-01 11:17:05 +00001672 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1673 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001674}
1675
paul200df112005-06-01 11:17:05 +00001676static void
paul0fb58d52005-11-14 14:31:49 +00001677bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001678{
paul0fb58d52005-11-14 14:31:49 +00001679 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001680 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001681
Chris Caputo228da422009-07-18 05:44:03 +00001682 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001683 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001684 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001685 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1686}
1687
1688static void
1689bgp_process_queue_init (void)
1690{
1691 bm->process_main_queue
1692 = work_queue_new (bm->master, "process_main_queue");
1693 bm->process_rsclient_queue
1694 = work_queue_new (bm->master, "process_rsclient_queue");
1695
1696 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1697 {
1698 zlog_err ("%s: Failed to allocate work queue", __func__);
1699 exit (1);
1700 }
1701
1702 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001703 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001704 bm->process_main_queue->spec.max_retries = 0;
1705 bm->process_main_queue->spec.hold = 50;
1706
Paul Jakma838bbde2010-01-08 14:05:32 +00001707 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001708 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1709 bm->process_rsclient_queue->spec.max_retries = 0;
1710 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001711}
1712
1713void
paulfee0f4c2004-09-13 05:12:46 +00001714bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1715{
paul200df112005-06-01 11:17:05 +00001716 struct bgp_process_queue *pqnode;
1717
1718 /* already scheduled for processing? */
1719 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1720 return;
1721
Paul Jakma91b9e852015-12-01 14:32:11 +00001722 if (rn->info == NULL)
1723 {
1724 /* XXX: Perhaps remove before next release, after we've flushed out
1725 * any obvious cases
1726 */
1727 assert (rn->info != NULL);
1728 char buf[PREFIX_STRLEN];
1729 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1730 __func__,
1731 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1732 return;
1733 }
1734
paul200df112005-06-01 11:17:05 +00001735 if ( (bm->process_main_queue == NULL) ||
1736 (bm->process_rsclient_queue == NULL) )
1737 bgp_process_queue_init ();
1738
1739 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1740 sizeof (struct bgp_process_queue));
1741 if (!pqnode)
1742 return;
Chris Caputo228da422009-07-18 05:44:03 +00001743
1744 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001745 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001746 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001747 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001748 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001749 pqnode->afi = afi;
1750 pqnode->safi = safi;
1751
Avneesh Sachdev67174042012-08-17 08:19:49 -07001752 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001753 {
paul200df112005-06-01 11:17:05 +00001754 case BGP_TABLE_MAIN:
1755 work_queue_add (bm->process_main_queue, pqnode);
1756 break;
1757 case BGP_TABLE_RSCLIENT:
1758 work_queue_add (bm->process_rsclient_queue, pqnode);
1759 break;
paulfee0f4c2004-09-13 05:12:46 +00001760 }
paul200df112005-06-01 11:17:05 +00001761
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001762 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001763 return;
paulfee0f4c2004-09-13 05:12:46 +00001764}
hasso0a486e52005-02-01 20:57:17 +00001765
paul94f2b392005-06-28 12:44:16 +00001766static int
hasso0a486e52005-02-01 20:57:17 +00001767bgp_maximum_prefix_restart_timer (struct thread *thread)
1768{
1769 struct peer *peer;
1770
1771 peer = THREAD_ARG (thread);
1772 peer->t_pmax_restart = NULL;
1773
1774 if (BGP_DEBUG (events, EVENTS))
1775 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1776 peer->host);
1777
1778 peer_clear (peer);
1779
1780 return 0;
1781}
1782
paulfee0f4c2004-09-13 05:12:46 +00001783int
paul5228ad22004-06-04 17:58:18 +00001784bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1785 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001786{
hassoe0701b72004-05-20 09:19:34 +00001787 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1788 return 0;
1789
1790 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001791 {
hassoe0701b72004-05-20 09:19:34 +00001792 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1793 && ! always)
1794 return 0;
paul718e3742002-12-13 20:15:29 +00001795
hassoe0701b72004-05-20 09:19:34 +00001796 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001797 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1798 "limit %ld", afi_safi_print (afi, safi), peer->host,
1799 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001800 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001801
hassoe0701b72004-05-20 09:19:34 +00001802 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1803 return 0;
paul718e3742002-12-13 20:15:29 +00001804
hassoe0701b72004-05-20 09:19:34 +00001805 {
paul5228ad22004-06-04 17:58:18 +00001806 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001807
1808 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001809 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001810
1811 ndata[0] = (afi >> 8);
1812 ndata[1] = afi;
1813 ndata[2] = safi;
1814 ndata[3] = (peer->pmax[afi][safi] >> 24);
1815 ndata[4] = (peer->pmax[afi][safi] >> 16);
1816 ndata[5] = (peer->pmax[afi][safi] >> 8);
1817 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001818
1819 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1820 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1821 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1822 }
hasso0a486e52005-02-01 20:57:17 +00001823
1824 /* restart timer start */
1825 if (peer->pmax_restart[afi][safi])
1826 {
1827 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1828
1829 if (BGP_DEBUG (events, EVENTS))
1830 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1831 peer->host, peer->v_pmax_restart);
1832
1833 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1834 peer->v_pmax_restart);
1835 }
1836
hassoe0701b72004-05-20 09:19:34 +00001837 return 1;
paul718e3742002-12-13 20:15:29 +00001838 }
hassoe0701b72004-05-20 09:19:34 +00001839 else
1840 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1841
1842 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1843 {
1844 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1845 && ! always)
1846 return 0;
1847
1848 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001849 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1850 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1851 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001852 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1853 }
1854 else
1855 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001856 return 0;
1857}
1858
paulb40d9392005-08-22 22:34:41 +00001859/* Unconditionally remove the route from the RIB, without taking
1860 * damping into consideration (eg, because the session went down)
1861 */
paul94f2b392005-06-28 12:44:16 +00001862static void
paul718e3742002-12-13 20:15:29 +00001863bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1864 afi_t afi, safi_t safi)
1865{
paul902212c2006-02-05 17:51:19 +00001866 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1867
1868 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1869 bgp_info_delete (rn, ri); /* keep historical info */
1870
paulb40d9392005-08-22 22:34:41 +00001871 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001872}
1873
paul94f2b392005-06-28 12:44:16 +00001874static void
paul718e3742002-12-13 20:15:29 +00001875bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001876 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001877{
paul718e3742002-12-13 20:15:29 +00001878 int status = BGP_DAMP_NONE;
1879
paulb40d9392005-08-22 22:34:41 +00001880 /* apply dampening, if result is suppressed, we'll be retaining
1881 * the bgp_info in the RIB for historical reference.
1882 */
1883 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001884 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001885 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1886 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001887 {
paul902212c2006-02-05 17:51:19 +00001888 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1889 return;
1890 }
1891
1892 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001893}
1894
paul94f2b392005-06-28 12:44:16 +00001895static void
paulfee0f4c2004-09-13 05:12:46 +00001896bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1897 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1898 int sub_type, struct prefix_rd *prd, u_char *tag)
1899{
1900 struct bgp_node *rn;
1901 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001902 struct attr new_attr;
1903 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001904 struct attr *attr_new;
1905 struct attr *attr_new2;
1906 struct bgp_info *ri;
1907 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001908 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001909 char buf[SU_ADDRSTRLEN];
1910
1911 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1912 if (peer == rsclient)
1913 return;
1914
1915 bgp = peer->bgp;
1916 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1917
1918 /* Check previously received route. */
1919 for (ri = rn->info; ri; ri = ri->next)
1920 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1921 break;
1922
1923 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001924 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001925 {
1926 reason = "as-path contains our own AS;";
1927 goto filtered;
1928 }
1929
1930 /* Route reflector originator ID check. */
1931 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001932 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001933 {
1934 reason = "originator is us;";
1935 goto filtered;
1936 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001937
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001938 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001939 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001940
1941 /* Apply export policy. */
1942 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1943 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1944 {
1945 reason = "export-policy;";
1946 goto filtered;
1947 }
1948
1949 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001950
paulfee0f4c2004-09-13 05:12:46 +00001951 /* Apply import policy. */
1952 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1953 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001954 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001955
1956 reason = "import-policy;";
1957 goto filtered;
1958 }
1959
1960 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001961 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001962
1963 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001964 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001965 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001966 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001967 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001968 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001969 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001970 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001971
1972 reason = "martian next-hop;";
1973 goto filtered;
1974 }
1975 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001976
paulfee0f4c2004-09-13 05:12:46 +00001977 /* If the update is implicit withdraw. */
1978 if (ri)
1979 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001980 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001981
1982 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001983 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1984 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001985 {
1986
Paul Jakma1a392d42006-09-07 00:24:49 +00001987 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001988
1989 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001990 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001991 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1992 peer->host,
1993 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1994 p->prefixlen, rsclient->host);
1995
Chris Caputo228da422009-07-18 05:44:03 +00001996 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001997 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05001998 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00001999 return;
paulfee0f4c2004-09-13 05:12:46 +00002000 }
2001
Paul Jakma16d2e242007-04-10 19:32:10 +00002002 /* Withdraw/Announce before we fully processed the withdraw */
2003 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2004 bgp_info_restore (rn, ri);
2005
paulfee0f4c2004-09-13 05:12:46 +00002006 /* Received Logging. */
2007 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002008 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002009 peer->host,
2010 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2011 p->prefixlen, rsclient->host);
2012
2013 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002014 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002015
2016 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002017 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002018 ri->attr = attr_new;
2019
2020 /* Update MPLS tag. */
2021 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002022 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002023
Paul Jakma1a392d42006-09-07 00:24:49 +00002024 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002025
2026 /* Process change. */
2027 bgp_process (bgp, rn, afi, safi);
2028 bgp_unlock_node (rn);
2029
2030 return;
2031 }
2032
2033 /* Received Logging. */
2034 if (BGP_DEBUG (update, UPDATE_IN))
2035 {
ajsd2c1f162004-12-08 21:10:20 +00002036 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002037 peer->host,
2038 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2039 p->prefixlen, rsclient->host);
2040 }
2041
2042 /* Make new BGP info. */
2043 new = bgp_info_new ();
2044 new->type = type;
2045 new->sub_type = sub_type;
2046 new->peer = peer;
2047 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002048 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002049
2050 /* Update MPLS tag. */
2051 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002052 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002053
Paul Jakma1a392d42006-09-07 00:24:49 +00002054 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002055
2056 /* Register new BGP information. */
2057 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002058
2059 /* route_node_get lock */
2060 bgp_unlock_node (rn);
2061
paulfee0f4c2004-09-13 05:12:46 +00002062 /* Process change. */
2063 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002064
paulfee0f4c2004-09-13 05:12:46 +00002065 return;
2066
2067 filtered:
2068
2069 /* This BGP update is filtered. Log the reason then update BGP entry. */
2070 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002071 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002072 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2073 peer->host,
2074 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2075 p->prefixlen, rsclient->host, reason);
2076
2077 if (ri)
paulb40d9392005-08-22 22:34:41 +00002078 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002079
2080 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002081
paulfee0f4c2004-09-13 05:12:46 +00002082 return;
2083}
2084
paul94f2b392005-06-28 12:44:16 +00002085static void
paulfee0f4c2004-09-13 05:12:46 +00002086bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2087 struct peer *peer, struct prefix *p, int type, int sub_type,
2088 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002089{
paulfee0f4c2004-09-13 05:12:46 +00002090 struct bgp_node *rn;
2091 struct bgp_info *ri;
2092 char buf[SU_ADDRSTRLEN];
2093
2094 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002095 return;
paulfee0f4c2004-09-13 05:12:46 +00002096
2097 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2098
2099 /* Lookup withdrawn route. */
2100 for (ri = rn->info; ri; ri = ri->next)
2101 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2102 break;
2103
2104 /* Withdraw specified route from routing table. */
2105 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002106 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002107 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002108 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002109 "%s Can't find the route %s/%d", peer->host,
2110 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2111 p->prefixlen);
2112
2113 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002114 bgp_unlock_node (rn);
2115}
paulfee0f4c2004-09-13 05:12:46 +00002116
paul94f2b392005-06-28 12:44:16 +00002117static int
paulfee0f4c2004-09-13 05:12:46 +00002118bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002119 afi_t afi, safi_t safi, int type, int sub_type,
2120 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2121{
2122 int ret;
2123 int aspath_loop_count = 0;
2124 struct bgp_node *rn;
2125 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002126 struct attr new_attr;
2127 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002128 struct attr *attr_new;
2129 struct bgp_info *ri;
2130 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002131 const char *reason;
paul718e3742002-12-13 20:15:29 +00002132 char buf[SU_ADDRSTRLEN];
2133
2134 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002135 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002136
paul718e3742002-12-13 20:15:29 +00002137 /* When peer's soft reconfiguration enabled. Record input packet in
2138 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002139 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2140 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002141 bgp_adj_in_set (rn, peer, attr);
2142
2143 /* Check previously received route. */
2144 for (ri = rn->info; ri; ri = ri->next)
2145 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2146 break;
2147
2148 /* AS path local-as loop check. */
2149 if (peer->change_local_as)
2150 {
2151 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2152 aspath_loop_count = 1;
2153
2154 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2155 {
2156 reason = "as-path contains our own AS;";
2157 goto filtered;
2158 }
2159 }
2160
2161 /* AS path loop check. */
2162 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2163 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2164 && aspath_loop_check(attr->aspath, bgp->confed_id)
2165 > peer->allowas_in[afi][safi]))
2166 {
2167 reason = "as-path contains our own AS;";
2168 goto filtered;
2169 }
2170
2171 /* Route reflector originator ID check. */
2172 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002173 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002174 {
2175 reason = "originator is us;";
2176 goto filtered;
2177 }
2178
2179 /* Route reflector cluster ID check. */
2180 if (bgp_cluster_filter (peer, attr))
2181 {
2182 reason = "reflected from the same cluster;";
2183 goto filtered;
2184 }
2185
2186 /* Apply incoming filter. */
2187 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2188 {
2189 reason = "filter;";
2190 goto filtered;
2191 }
2192
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002193 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002194 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002195
David Lamparterc460e572014-06-04 00:54:58 +02002196 /* Apply incoming route-map.
2197 * NB: new_attr may now contain newly allocated values from route-map "set"
2198 * commands, so we need bgp_attr_flush in the error paths, until we intern
2199 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002200 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2201 {
2202 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002203 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002204 goto filtered;
2205 }
2206
2207 /* IPv4 unicast next hop check. */
2208 if (afi == AFI_IP && safi == SAFI_UNICAST)
2209 {
2210 /* If the peer is EBGP and nexthop is not on connected route,
2211 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002212 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002213 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002214 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002215 {
2216 reason = "non-connected next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002217 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002218 goto filtered;
2219 }
2220
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002221 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002222 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002223 if (new_attr.nexthop.s_addr == 0
2224 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2225 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002226 {
2227 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002228 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002229 goto filtered;
2230 }
2231 }
2232
2233 attr_new = bgp_attr_intern (&new_attr);
2234
2235 /* If the update is implicit withdraw. */
2236 if (ri)
2237 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002238 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002239
2240 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002241 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2242 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002243 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002244 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002245
2246 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002247 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002248 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2249 {
2250 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002251 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002252 peer->host,
2253 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2254 p->prefixlen);
2255
paul902212c2006-02-05 17:51:19 +00002256 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2257 {
2258 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2259 bgp_process (bgp, rn, afi, safi);
2260 }
paul718e3742002-12-13 20:15:29 +00002261 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002262 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002263 {
2264 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002265 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002266 "%s rcvd %s/%d...duplicate ignored",
2267 peer->host,
2268 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2269 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002270
2271 /* graceful restart STALE flag unset. */
2272 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2273 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002274 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002275 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002276 }
paul718e3742002-12-13 20:15:29 +00002277 }
2278
2279 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002280 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002281 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002282
paul718e3742002-12-13 20:15:29 +00002283 return 0;
2284 }
2285
Paul Jakma16d2e242007-04-10 19:32:10 +00002286 /* Withdraw/Announce before we fully processed the withdraw */
2287 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2288 {
2289 if (BGP_DEBUG (update, UPDATE_IN))
2290 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2291 peer->host,
2292 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2293 p->prefixlen);
2294 bgp_info_restore (rn, ri);
2295 }
2296
paul718e3742002-12-13 20:15:29 +00002297 /* Received Logging. */
2298 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002299 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002300 peer->host,
2301 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2302 p->prefixlen);
2303
hasso93406d82005-02-02 14:40:33 +00002304 /* graceful restart STALE flag unset. */
2305 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002306 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002307
paul718e3742002-12-13 20:15:29 +00002308 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002309 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002310
2311 /* implicit withdraw, decrement aggregate and pcount here.
2312 * only if update is accepted, they'll increment below.
2313 */
paul902212c2006-02-05 17:51:19 +00002314 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2315
paul718e3742002-12-13 20:15:29 +00002316 /* Update bgp route dampening information. */
2317 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002318 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002319 {
2320 /* This is implicit withdraw so we should update dampening
2321 information. */
2322 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2323 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002324 }
2325
paul718e3742002-12-13 20:15:29 +00002326 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002327 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002328 ri->attr = attr_new;
2329
2330 /* Update MPLS tag. */
2331 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002332 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002333
Lou Berger050defe2016-01-12 13:41:59 -05002334 bgp_attr_flush (&new_attr);
2335
paul718e3742002-12-13 20:15:29 +00002336 /* Update bgp route dampening information. */
2337 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002338 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002339 {
2340 /* Now we do normal update dampening. */
2341 ret = bgp_damp_update (ri, rn, afi, safi);
2342 if (ret == BGP_DAMP_SUPPRESSED)
2343 {
2344 bgp_unlock_node (rn);
2345 return 0;
2346 }
2347 }
2348
2349 /* Nexthop reachability check. */
2350 if ((afi == AFI_IP || afi == AFI_IP6)
2351 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002352 && (peer->sort == BGP_PEER_IBGP
2353 || peer->sort == BGP_PEER_CONFED
2354 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002355 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002356 {
2357 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002358 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002359 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002360 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002361 }
2362 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002363 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002364
Lou Berger050defe2016-01-12 13:41:59 -05002365 bgp_attr_flush (&new_attr);
2366
paul718e3742002-12-13 20:15:29 +00002367 /* Process change. */
2368 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2369
2370 bgp_process (bgp, rn, afi, safi);
2371 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002372
paul718e3742002-12-13 20:15:29 +00002373 return 0;
2374 }
2375
2376 /* Received Logging. */
2377 if (BGP_DEBUG (update, UPDATE_IN))
2378 {
ajsd2c1f162004-12-08 21:10:20 +00002379 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002380 peer->host,
2381 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2382 p->prefixlen);
2383 }
2384
paul718e3742002-12-13 20:15:29 +00002385 /* Make new BGP info. */
2386 new = bgp_info_new ();
2387 new->type = type;
2388 new->sub_type = sub_type;
2389 new->peer = peer;
2390 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002391 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002392
2393 /* Update MPLS tag. */
2394 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002395 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002396
2397 /* Nexthop reachability check. */
2398 if ((afi == AFI_IP || afi == AFI_IP6)
2399 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002400 && (peer->sort == BGP_PEER_IBGP
2401 || peer->sort == BGP_PEER_CONFED
2402 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002403 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002404 {
2405 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002406 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002407 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002408 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002409 }
2410 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002411 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002412
paul902212c2006-02-05 17:51:19 +00002413 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002414 bgp_aggregate_increment (bgp, p, new, afi, safi);
2415
2416 /* Register new BGP information. */
2417 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002418
2419 /* route_node_get lock */
2420 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002421
Lou Berger050defe2016-01-12 13:41:59 -05002422 bgp_attr_flush (&new_attr);
2423
paul718e3742002-12-13 20:15:29 +00002424 /* If maximum prefix count is configured and current prefix
2425 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002426 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2427 return -1;
paul718e3742002-12-13 20:15:29 +00002428
2429 /* Process change. */
2430 bgp_process (bgp, rn, afi, safi);
2431
2432 return 0;
2433
2434 /* This BGP update is filtered. Log the reason then update BGP
2435 entry. */
2436 filtered:
2437 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002438 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002439 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2440 peer->host,
2441 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2442 p->prefixlen, reason);
2443
2444 if (ri)
paulb40d9392005-08-22 22:34:41 +00002445 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002446
2447 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002448 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002449
paul718e3742002-12-13 20:15:29 +00002450 return 0;
2451}
2452
2453int
paulfee0f4c2004-09-13 05:12:46 +00002454bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2455 afi_t afi, safi_t safi, int type, int sub_type,
2456 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2457{
2458 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002459 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002460 struct bgp *bgp;
2461 int ret;
2462
2463 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2464 soft_reconfig);
2465
2466 bgp = peer->bgp;
2467
2468 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002469 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002470 {
2471 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2472 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2473 sub_type, prd, tag);
2474 }
2475
2476 return ret;
2477}
2478
2479int
paul718e3742002-12-13 20:15:29 +00002480bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002481 afi_t afi, safi_t safi, int type, int sub_type,
2482 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002483{
2484 struct bgp *bgp;
2485 char buf[SU_ADDRSTRLEN];
2486 struct bgp_node *rn;
2487 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002488 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002489 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002490
2491 bgp = peer->bgp;
2492
David Lamparter4584c232015-04-13 09:50:00 +02002493 /* Lookup node. */
2494 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2495
2496 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2497 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2498 * the iteration over all RS clients.
2499 * Since we need to remove the entry from adj_in anyway, do that first and
2500 * if there was no entry, we don't need to do anything more. */
2501 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2502 && peer != bgp->peer_self)
2503 if (!bgp_adj_in_unset (rn, peer))
2504 {
2505 if (BGP_DEBUG (update, UPDATE_IN))
2506 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2507 "not in adj-in", peer->host,
2508 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2509 p->prefixlen);
2510 bgp_unlock_node (rn);
2511 return 0;
2512 }
2513
paulfee0f4c2004-09-13 05:12:46 +00002514 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002515 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002516 {
2517 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2518 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2519 }
2520
paul718e3742002-12-13 20:15:29 +00002521 /* Logging. */
2522 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002523 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002524 peer->host,
2525 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2526 p->prefixlen);
2527
paul718e3742002-12-13 20:15:29 +00002528 /* Lookup withdrawn route. */
2529 for (ri = rn->info; ri; ri = ri->next)
2530 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2531 break;
2532
2533 /* Withdraw specified route from routing table. */
2534 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002535 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002536 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002537 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002538 "%s Can't find the route %s/%d", peer->host,
2539 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2540 p->prefixlen);
2541
2542 /* Unlock bgp_node_get() lock. */
2543 bgp_unlock_node (rn);
2544
2545 return 0;
2546}
David Lamparter6b0655a2014-06-04 06:53:35 +02002547
paul718e3742002-12-13 20:15:29 +00002548void
2549bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2550{
2551 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002552 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002553 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002554 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002555 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002556 struct bgp_node *rn;
2557 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002558 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002559
Paul Jakmab2497022007-06-14 11:17:58 +00002560 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002561 return;
2562
paul718e3742002-12-13 20:15:29 +00002563 bgp = peer->bgp;
2564 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002565
paul718e3742002-12-13 20:15:29 +00002566 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2567 aspath = attr.aspath;
2568 attr.local_pref = bgp->default_local_pref;
2569 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2570
2571 if (afi == AFI_IP)
2572 str2prefix ("0.0.0.0/0", &p);
2573#ifdef HAVE_IPV6
2574 else if (afi == AFI_IP6)
2575 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002576 struct attr_extra *ae = attr.extra;
2577
paul718e3742002-12-13 20:15:29 +00002578 str2prefix ("::/0", &p);
2579
2580 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002581 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002582 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002583 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002584
2585 /* If the peer is on shared nextwork and we have link-local
2586 nexthop set it. */
2587 if (peer->shared_network
2588 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2589 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002590 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002591 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002592 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002593 }
2594 }
2595#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002596
2597 if (peer->default_rmap[afi][safi].name)
2598 {
paulfee0f4c2004-09-13 05:12:46 +00002599 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002600 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2601 {
2602 for (ri = rn->info; ri; ri = ri->next)
2603 {
2604 struct attr dummy_attr;
2605 struct attr_extra dummy_extra;
2606 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002607
Christian Frankedcab1bb2012-12-07 16:45:52 +00002608 /* Provide dummy so the route-map can't modify the attributes */
2609 dummy_attr.extra = &dummy_extra;
2610 bgp_attr_dup(&dummy_attr, ri->attr);
2611 info.peer = ri->peer;
2612 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002613
Christian Frankedcab1bb2012-12-07 16:45:52 +00002614 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2615 RMAP_BGP, &info);
2616
2617 /* The route map might have set attributes. If we don't flush them
2618 * here, they will be leaked. */
2619 bgp_attr_flush(&dummy_attr);
2620 if (ret != RMAP_DENYMATCH)
2621 break;
2622 }
2623 if (ret != RMAP_DENYMATCH)
2624 break;
2625 }
paulfee0f4c2004-09-13 05:12:46 +00002626 bgp->peer_self->rmap_type = 0;
2627
paul718e3742002-12-13 20:15:29 +00002628 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002629 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002630 }
2631
2632 if (withdraw)
2633 {
2634 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2635 bgp_default_withdraw_send (peer, afi, safi);
2636 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2637 }
2638 else
2639 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002640 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2641 {
2642 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2643 bgp_default_update_send (peer, &attr, afi, safi, from);
2644 }
paul718e3742002-12-13 20:15:29 +00002645 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002646
2647 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002648 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002649}
David Lamparter6b0655a2014-06-04 06:53:35 +02002650
paul718e3742002-12-13 20:15:29 +00002651static void
2652bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002653 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002654{
2655 struct bgp_node *rn;
2656 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002657 struct attr attr;
2658 struct attr_extra extra;
2659
paul718e3742002-12-13 20:15:29 +00002660 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002661 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002662
2663 if (safi != SAFI_MPLS_VPN
2664 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2665 bgp_default_originate (peer, afi, safi, 0);
2666
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002667 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2668 attr.extra = &extra;
2669
paul718e3742002-12-13 20:15:29 +00002670 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2671 for (ri = rn->info; ri; ri = ri->next)
2672 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2673 {
paulfee0f4c2004-09-13 05:12:46 +00002674 if ( (rsclient) ?
2675 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2676 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002677 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2678 else
2679 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2680 }
2681}
2682
2683void
2684bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2685{
2686 struct bgp_node *rn;
2687 struct bgp_table *table;
2688
2689 if (peer->status != Established)
2690 return;
2691
2692 if (! peer->afc_nego[afi][safi])
2693 return;
2694
2695 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2696 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2697 return;
2698
2699 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002700 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002701 else
2702 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2703 rn = bgp_route_next(rn))
2704 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002705 bgp_announce_table (peer, afi, safi, table, 0);
2706
2707 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2708 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002709}
2710
2711void
2712bgp_announce_route_all (struct peer *peer)
2713{
2714 afi_t afi;
2715 safi_t safi;
2716
2717 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2718 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2719 bgp_announce_route (peer, afi, safi);
2720}
David Lamparter6b0655a2014-06-04 06:53:35 +02002721
paul718e3742002-12-13 20:15:29 +00002722static void
paulfee0f4c2004-09-13 05:12:46 +00002723bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002724 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002725{
2726 struct bgp_node *rn;
2727 struct bgp_adj_in *ain;
2728
2729 if (! table)
2730 table = rsclient->bgp->rib[afi][safi];
2731
2732 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2733 for (ain = rn->adj_in; ain; ain = ain->next)
2734 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002735 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002736 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002737
paulfee0f4c2004-09-13 05:12:46 +00002738 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002739 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002740 }
2741}
2742
2743void
2744bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2745{
2746 struct bgp_table *table;
2747 struct bgp_node *rn;
2748
2749 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002750 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002751
2752 else
2753 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2754 rn = bgp_route_next (rn))
2755 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002756 {
2757 struct prefix_rd prd;
2758 prd.family = AF_UNSPEC;
2759 prd.prefixlen = 64;
2760 memcpy(&prd.val, rn->p.u.val, 8);
2761
2762 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2763 }
paulfee0f4c2004-09-13 05:12:46 +00002764}
David Lamparter6b0655a2014-06-04 06:53:35 +02002765
paulfee0f4c2004-09-13 05:12:46 +00002766static void
paul718e3742002-12-13 20:15:29 +00002767bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002768 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002769{
2770 int ret;
2771 struct bgp_node *rn;
2772 struct bgp_adj_in *ain;
2773
2774 if (! table)
2775 table = peer->bgp->rib[afi][safi];
2776
2777 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2778 for (ain = rn->adj_in; ain; ain = ain->next)
2779 {
2780 if (ain->peer == peer)
2781 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002782 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002783 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002784
paul718e3742002-12-13 20:15:29 +00002785 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2786 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002787 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002788
paul718e3742002-12-13 20:15:29 +00002789 if (ret < 0)
2790 {
2791 bgp_unlock_node (rn);
2792 return;
2793 }
2794 continue;
2795 }
2796 }
2797}
2798
2799void
2800bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2801{
2802 struct bgp_node *rn;
2803 struct bgp_table *table;
2804
2805 if (peer->status != Established)
2806 return;
2807
2808 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002809 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002810 else
2811 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2812 rn = bgp_route_next (rn))
2813 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002814 {
2815 struct prefix_rd prd;
2816 prd.family = AF_UNSPEC;
2817 prd.prefixlen = 64;
2818 memcpy(&prd.val, rn->p.u.val, 8);
2819
2820 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2821 }
paul718e3742002-12-13 20:15:29 +00002822}
David Lamparter6b0655a2014-06-04 06:53:35 +02002823
Chris Caputo228da422009-07-18 05:44:03 +00002824
2825struct bgp_clear_node_queue
2826{
2827 struct bgp_node *rn;
2828 enum bgp_clear_route_type purpose;
2829};
2830
paul200df112005-06-01 11:17:05 +00002831static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002832bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002833{
Chris Caputo228da422009-07-18 05:44:03 +00002834 struct bgp_clear_node_queue *cnq = data;
2835 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002836 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002837 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002838 afi_t afi = bgp_node_table (rn)->afi;
2839 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002840
Paul Jakma64e580a2006-02-21 01:09:01 +00002841 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002842
Paul Jakma64e580a2006-02-21 01:09:01 +00002843 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002844 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002845 {
2846 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002847 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2848 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002849 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002850 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2851 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002852 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002853 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002854 break;
2855 }
paul200df112005-06-01 11:17:05 +00002856 return WQ_SUCCESS;
2857}
2858
2859static void
paul0fb58d52005-11-14 14:31:49 +00002860bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002861{
Chris Caputo228da422009-07-18 05:44:03 +00002862 struct bgp_clear_node_queue *cnq = data;
2863 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002864 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002865
2866 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002867 bgp_table_unlock (table);
2868 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002869}
2870
2871static void
paul94f2b392005-06-28 12:44:16 +00002872bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002873{
Paul Jakma64e580a2006-02-21 01:09:01 +00002874 struct peer *peer = wq->spec.data;
2875
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002876 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002877 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002878
2879 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002880}
2881
2882static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002883bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002884{
Paul Jakmaa2943652009-07-21 14:02:04 +01002885 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002886
Paul Jakmaa2943652009-07-21 14:02:04 +01002887 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002888#undef CLEAR_QUEUE_NAME_LEN
2889
2890 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002891 {
2892 zlog_err ("%s: Failed to allocate work queue", __func__);
2893 exit (1);
2894 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002895 peer->clear_node_queue->spec.hold = 10;
2896 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2897 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2898 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2899 peer->clear_node_queue->spec.max_retries = 0;
2900
2901 /* we only 'lock' this peer reference when the queue is actually active */
2902 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002903}
2904
paul718e3742002-12-13 20:15:29 +00002905static void
2906bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002907 struct bgp_table *table, struct peer *rsclient,
2908 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002909{
2910 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002911
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002912
paul718e3742002-12-13 20:15:29 +00002913 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002914 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002915
hasso6cf159b2005-03-21 10:28:14 +00002916 /* If still no table => afi/safi isn't configured at all or smth. */
2917 if (! table)
2918 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002919
2920 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2921 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002922 struct bgp_info *ri;
2923 struct bgp_adj_in *ain;
2924 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002925
2926 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2927 * queued for every clearing peer, regardless of whether it is
2928 * relevant to the peer at hand.
2929 *
2930 * Overview: There are 3 different indices which need to be
2931 * scrubbed, potentially, when a peer is removed:
2932 *
2933 * 1 peer's routes visible via the RIB (ie accepted routes)
2934 * 2 peer's routes visible by the (optional) peer's adj-in index
2935 * 3 other routes visible by the peer's adj-out index
2936 *
2937 * 3 there is no hurry in scrubbing, once the struct peer is
2938 * removed from bgp->peer, we could just GC such deleted peer's
2939 * adj-outs at our leisure.
2940 *
2941 * 1 and 2 must be 'scrubbed' in some way, at least made
2942 * invisible via RIB index before peer session is allowed to be
2943 * brought back up. So one needs to know when such a 'search' is
2944 * complete.
2945 *
2946 * Ideally:
2947 *
2948 * - there'd be a single global queue or a single RIB walker
2949 * - rather than tracking which route_nodes still need to be
2950 * examined on a peer basis, we'd track which peers still
2951 * aren't cleared
2952 *
2953 * Given that our per-peer prefix-counts now should be reliable,
2954 * this may actually be achievable. It doesn't seem to be a huge
2955 * problem at this time,
2956 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002957 for (ain = rn->adj_in; ain; ain = ain->next)
2958 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2959 {
2960 bgp_adj_in_remove (rn, ain);
2961 bgp_unlock_node (rn);
2962 break;
2963 }
2964 for (aout = rn->adj_out; aout; aout = aout->next)
2965 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2966 {
2967 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2968 bgp_unlock_node (rn);
2969 break;
2970 }
2971
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002972 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002973 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002974 {
Chris Caputo228da422009-07-18 05:44:03 +00002975 struct bgp_clear_node_queue *cnq;
2976
2977 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002978 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002979 bgp_lock_node (rn);
2980 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2981 sizeof (struct bgp_clear_node_queue));
2982 cnq->rn = rn;
2983 cnq->purpose = purpose;
2984 work_queue_add (peer->clear_node_queue, cnq);
2985 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002986 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002987 }
2988 return;
2989}
2990
2991void
Chris Caputo228da422009-07-18 05:44:03 +00002992bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2993 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002994{
2995 struct bgp_node *rn;
2996 struct bgp_table *table;
2997 struct peer *rsclient;
2998 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002999
Paul Jakma64e580a2006-02-21 01:09:01 +00003000 if (peer->clear_node_queue == NULL)
3001 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00003002
Paul Jakmaca058a32006-09-14 02:58:49 +00003003 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3004 * Idle until it receives a Clearing_Completed event. This protects
3005 * against peers which flap faster than we can we clear, which could
3006 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003007 *
3008 * a) race with routes from the new session being installed before
3009 * clear_route_node visits the node (to delete the route of that
3010 * peer)
3011 * b) resource exhaustion, clear_route_node likely leads to an entry
3012 * on the process_main queue. Fast-flapping could cause that queue
3013 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003014 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003015
3016 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3017 * the unlock will happen upon work-queue completion; other wise, the
3018 * unlock happens at the end of this function.
3019 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003020 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003021 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003022 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003023 {
Chris Caputo228da422009-07-18 05:44:03 +00003024 case BGP_CLEAR_ROUTE_NORMAL:
3025 if (safi != SAFI_MPLS_VPN)
3026 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3027 else
3028 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3029 rn = bgp_route_next (rn))
3030 if ((table = rn->info) != NULL)
3031 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3032
3033 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3034 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3035 PEER_FLAG_RSERVER_CLIENT))
3036 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3037 break;
3038
3039 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003040 /*
3041 * gpz 091009: TBD why don't we have special handling for
3042 * SAFI_MPLS_VPN here in the original quagga code?
3043 * (and, by extension, for SAFI_ENCAP)
3044 */
Chris Caputo228da422009-07-18 05:44:03 +00003045 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3046 break;
3047
3048 default:
3049 assert (0);
3050 break;
paulfee0f4c2004-09-13 05:12:46 +00003051 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003052
3053 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003054 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003055 peer_unlock (peer);
3056
paul718e3742002-12-13 20:15:29 +00003057}
3058
3059void
3060bgp_clear_route_all (struct peer *peer)
3061{
3062 afi_t afi;
3063 safi_t safi;
3064
3065 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3066 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003067 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003068}
3069
Lou Berger82dd7072016-01-12 13:41:57 -05003070/*
3071 * Finish freeing things when exiting
3072 */
3073static void
3074bgp_drain_workqueue_immediate (struct work_queue *wq)
3075{
3076 if (!wq)
3077 return;
3078
3079 if (!wq->thread)
3080 {
3081 /*
3082 * no thread implies no queued items
3083 */
3084 assert(!wq->items->count);
3085 return;
3086 }
3087
3088 while (wq->items->count)
3089 {
3090 if (wq->thread)
3091 thread_cancel(wq->thread);
3092 work_queue_run(wq->thread);
3093 }
3094}
3095
3096/*
3097 * Special function to process clear node queue when bgpd is exiting
3098 * and the thread scheduler is no longer running.
3099 */
3100void
3101bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3102{
3103 if (!peer)
3104 return;
3105
3106 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3107}
3108
3109/*
3110 * The work queues are not specific to a BGP instance, but the
3111 * items in them refer to BGP instances, so this should be called
3112 * before each BGP instance is deleted.
3113 */
3114void
3115bgp_process_queues_drain_immediate(void)
3116{
3117 bgp_drain_workqueue_immediate(bm->process_main_queue);
3118 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3119}
3120
paul718e3742002-12-13 20:15:29 +00003121void
3122bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3123{
3124 struct bgp_table *table;
3125 struct bgp_node *rn;
3126 struct bgp_adj_in *ain;
3127
3128 table = peer->bgp->rib[afi][safi];
3129
3130 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3131 for (ain = rn->adj_in; ain ; ain = ain->next)
3132 if (ain->peer == peer)
3133 {
3134 bgp_adj_in_remove (rn, ain);
3135 bgp_unlock_node (rn);
3136 break;
3137 }
3138}
hasso93406d82005-02-02 14:40:33 +00003139
3140void
3141bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3142{
3143 struct bgp_node *rn;
3144 struct bgp_info *ri;
3145 struct bgp_table *table;
3146
3147 table = peer->bgp->rib[afi][safi];
3148
3149 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3150 {
3151 for (ri = rn->info; ri; ri = ri->next)
3152 if (ri->peer == peer)
3153 {
3154 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3155 bgp_rib_remove (rn, ri, peer, afi, safi);
3156 break;
3157 }
3158 }
3159}
David Lamparter6b0655a2014-06-04 06:53:35 +02003160
Lou Berger82dd7072016-01-12 13:41:57 -05003161static void
3162bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3163{
3164 struct bgp_node *rn;
3165 struct bgp_info *ri;
3166 struct bgp_info *next;
3167
3168 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3169 for (ri = rn->info; ri; ri = next)
3170 {
3171 next = ri->next;
3172 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3173 && ri->type == ZEBRA_ROUTE_BGP
3174 && ri->sub_type == BGP_ROUTE_NORMAL)
3175 bgp_zebra_withdraw (&rn->p, ri, safi);
3176 }
3177}
3178
paul718e3742002-12-13 20:15:29 +00003179/* Delete all kernel routes. */
3180void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003181bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003182{
3183 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003184 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003185 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003186
paul1eb8ef22005-04-07 07:30:20 +00003187 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003188 {
Lou Berger82dd7072016-01-12 13:41:57 -05003189 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3190 {
3191 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003192
Lou Berger82dd7072016-01-12 13:41:57 -05003193 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003194
Lou Berger82dd7072016-01-12 13:41:57 -05003195 /*
3196 * VPN and ENCAP tables are two-level (RD is top level)
3197 */
3198 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3199 rn = bgp_route_next (rn))
3200 if (rn->info)
3201 {
3202 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3203 bgp_table_finish ((struct bgp_table **)&(rn->info));
3204 rn->info = NULL;
3205 bgp_unlock_node(rn);
3206 }
3207 }
paul718e3742002-12-13 20:15:29 +00003208 }
3209}
3210
3211void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003212bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003213{
3214 vty_reset ();
3215 bgp_zclient_reset ();
3216 access_list_reset ();
3217 prefix_list_reset ();
3218}
David Lamparter6b0655a2014-06-04 06:53:35 +02003219
paul718e3742002-12-13 20:15:29 +00003220/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3221 value. */
3222int
3223bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3224{
3225 u_char *pnt;
3226 u_char *lim;
3227 struct prefix p;
3228 int psize;
3229 int ret;
3230
3231 /* Check peer status. */
3232 if (peer->status != Established)
3233 return 0;
3234
3235 pnt = packet->nlri;
3236 lim = pnt + packet->length;
3237
3238 for (; pnt < lim; pnt += psize)
3239 {
3240 /* Clear prefix structure. */
3241 memset (&p, 0, sizeof (struct prefix));
3242
3243 /* Fetch prefix length. */
3244 p.prefixlen = *pnt++;
3245 p.family = afi2family (packet->afi);
3246
3247 /* Already checked in nlri_sanity_check(). We do double check
3248 here. */
3249 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3250 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3251 return -1;
3252
3253 /* Packet size overflow check. */
3254 psize = PSIZE (p.prefixlen);
3255
3256 /* When packet overflow occur return immediately. */
3257 if (pnt + psize > lim)
3258 return -1;
3259
3260 /* Fetch prefix from NLRI packet. */
3261 memcpy (&p.u.prefix, pnt, psize);
3262
3263 /* Check address. */
3264 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3265 {
3266 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3267 {
paulf5ba3872004-07-09 12:11:31 +00003268 /*
3269 * From draft-ietf-idr-bgp4-22, Section 6.3:
3270 * If a BGP router receives an UPDATE message with a
3271 * semantically incorrect NLRI field, in which a prefix is
3272 * semantically incorrect (eg. an unexpected multicast IP
3273 * address), it should ignore the prefix.
3274 */
paul718e3742002-12-13 20:15:29 +00003275 zlog (peer->log, LOG_ERR,
3276 "IPv4 unicast NLRI is multicast address %s",
3277 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003278
paul718e3742002-12-13 20:15:29 +00003279 return -1;
3280 }
3281 }
3282
3283#ifdef HAVE_IPV6
3284 /* Check address. */
3285 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3286 {
3287 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3288 {
3289 char buf[BUFSIZ];
3290
3291 zlog (peer->log, LOG_WARNING,
3292 "IPv6 link-local NLRI received %s ignore this NLRI",
3293 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3294
3295 continue;
3296 }
3297 }
3298#endif /* HAVE_IPV6 */
3299
3300 /* Normal process. */
3301 if (attr)
3302 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3303 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3304 else
3305 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3306 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3307
3308 /* Address family configuration mismatch or maximum-prefix count
3309 overflow. */
3310 if (ret < 0)
3311 return -1;
3312 }
3313
3314 /* Packet length consistency check. */
3315 if (pnt != lim)
3316 return -1;
3317
3318 return 0;
3319}
3320
3321/* NLRI encode syntax check routine. */
3322int
Lou Berger050defe2016-01-12 13:41:59 -05003323bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi,
3324 u_char *pnt, bgp_size_t length)
paul718e3742002-12-13 20:15:29 +00003325{
3326 u_char *end;
3327 u_char prefixlen;
3328 int psize;
3329
3330 end = pnt + length;
3331
3332 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3333 syntactic validity. If the field is syntactically incorrect,
3334 then the Error Subcode is set to Invalid Network Field. */
3335
3336 while (pnt < end)
3337 {
3338 prefixlen = *pnt++;
3339
3340 /* Prefix length check. */
3341 if ((afi == AFI_IP && prefixlen > 32)
3342 || (afi == AFI_IP6 && prefixlen > 128))
3343 {
3344 plog_err (peer->log,
3345 "%s [Error] Update packet error (wrong prefix length %d)",
3346 peer->host, prefixlen);
3347 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3348 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3349 return -1;
3350 }
3351
3352 /* Packet size overflow check. */
3353 psize = PSIZE (prefixlen);
3354
3355 if (pnt + psize > end)
3356 {
3357 plog_err (peer->log,
3358 "%s [Error] Update packet error"
3359 " (prefix data overflow prefix size is %d)",
3360 peer->host, psize);
3361 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3362 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3363 return -1;
3364 }
3365
3366 pnt += psize;
3367 }
3368
3369 /* Packet length consistency check. */
3370 if (pnt != end)
3371 {
3372 plog_err (peer->log,
3373 "%s [Error] Update packet error"
3374 " (prefix length mismatch with total length)",
3375 peer->host);
3376 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3377 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3378 return -1;
3379 }
3380 return 0;
3381}
David Lamparter6b0655a2014-06-04 06:53:35 +02003382
paul94f2b392005-06-28 12:44:16 +00003383static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003384bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003385{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003386 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003387}
3388
paul94f2b392005-06-28 12:44:16 +00003389static void
paul718e3742002-12-13 20:15:29 +00003390bgp_static_free (struct bgp_static *bgp_static)
3391{
3392 if (bgp_static->rmap.name)
3393 free (bgp_static->rmap.name);
3394 XFREE (MTYPE_BGP_STATIC, bgp_static);
3395}
3396
paul94f2b392005-06-28 12:44:16 +00003397static void
paulfee0f4c2004-09-13 05:12:46 +00003398bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3399 struct prefix *p, afi_t afi, safi_t safi)
3400{
3401 struct bgp_node *rn;
3402 struct bgp_info *ri;
3403
3404 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3405
3406 /* Check selected route and self inserted route. */
3407 for (ri = rn->info; ri; ri = ri->next)
3408 if (ri->peer == bgp->peer_self
3409 && ri->type == ZEBRA_ROUTE_BGP
3410 && ri->sub_type == BGP_ROUTE_STATIC)
3411 break;
3412
3413 /* Withdraw static BGP route from routing table. */
3414 if (ri)
3415 {
paulfee0f4c2004-09-13 05:12:46 +00003416 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003417 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003418 }
3419
3420 /* Unlock bgp_node_lookup. */
3421 bgp_unlock_node (rn);
3422}
3423
paul94f2b392005-06-28 12:44:16 +00003424static void
paulfee0f4c2004-09-13 05:12:46 +00003425bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003426 struct bgp_static *bgp_static,
3427 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003428{
3429 struct bgp_node *rn;
3430 struct bgp_info *ri;
3431 struct bgp_info *new;
3432 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003433 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003434 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003435 struct attr new_attr;
3436 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003437 struct bgp *bgp;
3438 int ret;
3439 char buf[SU_ADDRSTRLEN];
3440
3441 bgp = rsclient->bgp;
3442
Paul Jakma06e110f2006-05-12 23:29:22 +00003443 assert (bgp_static);
3444 if (!bgp_static)
3445 return;
3446
paulfee0f4c2004-09-13 05:12:46 +00003447 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3448
3449 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003450
3451 attr.nexthop = bgp_static->igpnexthop;
3452 attr.med = bgp_static->igpmetric;
3453 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003454
Paul Jakma41367172007-08-06 15:24:51 +00003455 if (bgp_static->atomic)
3456 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3457
paulfee0f4c2004-09-13 05:12:46 +00003458 /* Apply network route-map for export to this rsclient. */
3459 if (bgp_static->rmap.name)
3460 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003461 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003462 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003463 info.attr = &attr_tmp;
3464
paulfee0f4c2004-09-13 05:12:46 +00003465 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3466 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3467
3468 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3469
3470 rsclient->rmap_type = 0;
3471
3472 if (ret == RMAP_DENYMATCH)
3473 {
3474 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003475 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003476
3477 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003478 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003479 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003480 bgp_attr_extra_free (&attr);
3481
paulfee0f4c2004-09-13 05:12:46 +00003482 return;
3483 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003484 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003485 }
3486 else
3487 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003488
3489 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003490 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003491
paulfee0f4c2004-09-13 05:12:46 +00003492 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3493
Paul Jakmafb982c22007-05-04 20:15:47 +00003494 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3495 == RMAP_DENY)
3496 {
paulfee0f4c2004-09-13 05:12:46 +00003497 /* This BGP update is filtered. Log the reason then update BGP entry. */
3498 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003499 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003500 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3501 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3502 p->prefixlen, rsclient->host);
3503
3504 bgp->peer_self->rmap_type = 0;
3505
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003506 bgp_attr_unintern (&attr_new);
3507 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003508 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003509
3510 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3511
3512 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003513 }
paulfee0f4c2004-09-13 05:12:46 +00003514
3515 bgp->peer_self->rmap_type = 0;
3516
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003517 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003518 attr_new = bgp_attr_intern (&new_attr);
3519
3520 for (ri = rn->info; ri; ri = ri->next)
3521 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3522 && ri->sub_type == BGP_ROUTE_STATIC)
3523 break;
3524
3525 if (ri)
3526 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003527 if (attrhash_cmp (ri->attr, attr_new) &&
3528 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003529 {
3530 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003531 bgp_attr_unintern (&attr_new);
3532 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003533 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003534 return;
3535 }
3536 else
3537 {
3538 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003539 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003540
3541 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003542 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3543 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003544 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003545 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003546 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003547
3548 /* Process change. */
3549 bgp_process (bgp, rn, afi, safi);
3550 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003551 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003552 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003553 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003554 }
paulfee0f4c2004-09-13 05:12:46 +00003555 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003556
paulfee0f4c2004-09-13 05:12:46 +00003557 /* Make new BGP info. */
3558 new = bgp_info_new ();
3559 new->type = ZEBRA_ROUTE_BGP;
3560 new->sub_type = BGP_ROUTE_STATIC;
3561 new->peer = bgp->peer_self;
3562 SET_FLAG (new->flags, BGP_INFO_VALID);
3563 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003564 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003565
3566 /* Register new BGP information. */
3567 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003568
3569 /* route_node_get lock */
3570 bgp_unlock_node (rn);
3571
paulfee0f4c2004-09-13 05:12:46 +00003572 /* Process change. */
3573 bgp_process (bgp, rn, afi, safi);
3574
3575 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003576 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003577 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003578}
3579
paul94f2b392005-06-28 12:44:16 +00003580static void
paulfee0f4c2004-09-13 05:12:46 +00003581bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003582 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3583{
3584 struct bgp_node *rn;
3585 struct bgp_info *ri;
3586 struct bgp_info *new;
3587 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003588 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003589 struct attr *attr_new;
3590 int ret;
3591
Paul Jakmadd8103a2006-05-12 23:27:30 +00003592 assert (bgp_static);
3593 if (!bgp_static)
3594 return;
3595
paulfee0f4c2004-09-13 05:12:46 +00003596 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003597
3598 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003599
3600 attr.nexthop = bgp_static->igpnexthop;
3601 attr.med = bgp_static->igpmetric;
3602 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003603
Paul Jakma41367172007-08-06 15:24:51 +00003604 if (bgp_static->atomic)
3605 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3606
paul718e3742002-12-13 20:15:29 +00003607 /* Apply route-map. */
3608 if (bgp_static->rmap.name)
3609 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003610 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003611 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003612 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003613
paulfee0f4c2004-09-13 05:12:46 +00003614 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3615
paul718e3742002-12-13 20:15:29 +00003616 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003617
paulfee0f4c2004-09-13 05:12:46 +00003618 bgp->peer_self->rmap_type = 0;
3619
paul718e3742002-12-13 20:15:29 +00003620 if (ret == RMAP_DENYMATCH)
3621 {
3622 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003623 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003624
3625 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003626 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003627 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003628 bgp_static_withdraw (bgp, p, afi, safi);
3629 return;
3630 }
paul286e1e72003-08-08 00:24:31 +00003631 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003632 }
paul286e1e72003-08-08 00:24:31 +00003633 else
3634 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003635
3636 for (ri = rn->info; ri; ri = ri->next)
3637 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3638 && ri->sub_type == BGP_ROUTE_STATIC)
3639 break;
3640
3641 if (ri)
3642 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003643 if (attrhash_cmp (ri->attr, attr_new) &&
3644 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003645 {
3646 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003647 bgp_attr_unintern (&attr_new);
3648 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003649 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003650 return;
3651 }
3652 else
3653 {
3654 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003655 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003656
3657 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003658 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3659 bgp_info_restore(rn, ri);
3660 else
3661 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003662 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003663 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003664 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003665
3666 /* Process change. */
3667 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3668 bgp_process (bgp, rn, afi, safi);
3669 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003670 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003671 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003672 return;
3673 }
3674 }
3675
3676 /* Make new BGP info. */
3677 new = bgp_info_new ();
3678 new->type = ZEBRA_ROUTE_BGP;
3679 new->sub_type = BGP_ROUTE_STATIC;
3680 new->peer = bgp->peer_self;
3681 SET_FLAG (new->flags, BGP_INFO_VALID);
3682 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003683 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003684
3685 /* Aggregate address increment. */
3686 bgp_aggregate_increment (bgp, p, new, afi, safi);
3687
3688 /* Register new BGP information. */
3689 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003690
3691 /* route_node_get lock */
3692 bgp_unlock_node (rn);
3693
paul718e3742002-12-13 20:15:29 +00003694 /* Process change. */
3695 bgp_process (bgp, rn, afi, safi);
3696
3697 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003698 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003699 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003700}
3701
3702void
paulfee0f4c2004-09-13 05:12:46 +00003703bgp_static_update (struct bgp *bgp, struct prefix *p,
3704 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3705{
3706 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003707 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003708
3709 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3710
paul1eb8ef22005-04-07 07:30:20 +00003711 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003712 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003713 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3714 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003715 }
3716}
3717
paul718e3742002-12-13 20:15:29 +00003718void
3719bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3720 safi_t safi)
3721{
3722 struct bgp_node *rn;
3723 struct bgp_info *ri;
3724
paulfee0f4c2004-09-13 05:12:46 +00003725 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003726
3727 /* Check selected route and self inserted route. */
3728 for (ri = rn->info; ri; ri = ri->next)
3729 if (ri->peer == bgp->peer_self
3730 && ri->type == ZEBRA_ROUTE_BGP
3731 && ri->sub_type == BGP_ROUTE_STATIC)
3732 break;
3733
3734 /* Withdraw static BGP route from routing table. */
3735 if (ri)
3736 {
3737 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003738 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003739 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003740 }
3741
3742 /* Unlock bgp_node_lookup. */
3743 bgp_unlock_node (rn);
3744}
3745
3746void
paulfee0f4c2004-09-13 05:12:46 +00003747bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3748{
3749 struct bgp_static *bgp_static;
3750 struct bgp *bgp;
3751 struct bgp_node *rn;
3752 struct prefix *p;
3753
3754 bgp = rsclient->bgp;
3755
3756 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3757 if ((bgp_static = rn->info) != NULL)
3758 {
3759 p = &rn->p;
3760
3761 bgp_static_update_rsclient (rsclient, p, bgp_static,
3762 afi, safi);
3763 }
3764}
3765
Lou Bergera76d9ca2016-01-12 13:41:53 -05003766/*
3767 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3768 */
paul94f2b392005-06-28 12:44:16 +00003769static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003770bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3771 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003772{
3773 struct bgp_node *rn;
3774 struct bgp_info *ri;
3775
paulfee0f4c2004-09-13 05:12:46 +00003776 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003777
3778 /* Check selected route and self inserted route. */
3779 for (ri = rn->info; ri; ri = ri->next)
3780 if (ri->peer == bgp->peer_self
3781 && ri->type == ZEBRA_ROUTE_BGP
3782 && ri->sub_type == BGP_ROUTE_STATIC)
3783 break;
3784
3785 /* Withdraw static BGP route from routing table. */
3786 if (ri)
3787 {
3788 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003789 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003790 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003791 }
3792
3793 /* Unlock bgp_node_lookup. */
3794 bgp_unlock_node (rn);
3795}
3796
Lou Bergera76d9ca2016-01-12 13:41:53 -05003797static void
3798bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3799 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3800{
3801 struct bgp_node *rn;
3802 struct bgp_info *new;
3803 struct attr *attr_new;
3804 struct attr attr = { 0 };
3805 struct bgp_info *ri;
3806
3807 assert (bgp_static);
3808
3809 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3810
3811 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3812
3813 attr.nexthop = bgp_static->igpnexthop;
3814 attr.med = bgp_static->igpmetric;
3815 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3816
3817 /* Apply route-map. */
3818 if (bgp_static->rmap.name)
3819 {
3820 struct attr attr_tmp = attr;
3821 struct bgp_info info;
3822 int ret;
3823
3824 info.peer = bgp->peer_self;
3825 info.attr = &attr_tmp;
3826
3827 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3828
3829 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3830
3831 bgp->peer_self->rmap_type = 0;
3832
3833 if (ret == RMAP_DENYMATCH)
3834 {
3835 /* Free uninterned attribute. */
3836 bgp_attr_flush (&attr_tmp);
3837
3838 /* Unintern original. */
3839 aspath_unintern (&attr.aspath);
3840 bgp_attr_extra_free (&attr);
3841 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3842 bgp_static->tag);
3843 return;
3844 }
3845
3846 attr_new = bgp_attr_intern (&attr_tmp);
3847 }
3848 else
3849 {
3850 attr_new = bgp_attr_intern (&attr);
3851 }
3852
3853 for (ri = rn->info; ri; ri = ri->next)
3854 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3855 && ri->sub_type == BGP_ROUTE_STATIC)
3856 break;
3857
3858 if (ri)
3859 {
3860 if (attrhash_cmp (ri->attr, attr_new) &&
3861 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3862 {
3863 bgp_unlock_node (rn);
3864 bgp_attr_unintern (&attr_new);
3865 aspath_unintern (&attr.aspath);
3866 bgp_attr_extra_free (&attr);
3867 return;
3868 }
3869 else
3870 {
3871 /* The attribute is changed. */
3872 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3873
3874 /* Rewrite BGP route information. */
3875 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3876 bgp_info_restore(rn, ri);
3877 else
3878 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3879 bgp_attr_unintern (&ri->attr);
3880 ri->attr = attr_new;
3881 ri->uptime = bgp_clock ();
3882
3883 /* Process change. */
3884 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3885 bgp_process (bgp, rn, afi, safi);
3886 bgp_unlock_node (rn);
3887 aspath_unintern (&attr.aspath);
3888 bgp_attr_extra_free (&attr);
3889 return;
3890 }
3891 }
3892
3893
3894 /* Make new BGP info. */
3895 new = bgp_info_new ();
3896 new->type = ZEBRA_ROUTE_BGP;
3897 new->sub_type = BGP_ROUTE_STATIC;
3898 new->peer = bgp->peer_self;
3899 new->attr = attr_new;
3900 SET_FLAG (new->flags, BGP_INFO_VALID);
3901 new->uptime = bgp_clock ();
3902 new->extra = bgp_info_extra_new();
3903 memcpy (new->extra->tag, bgp_static->tag, 3);
3904
3905 /* Aggregate address increment. */
3906 bgp_aggregate_increment (bgp, p, new, afi, safi);
3907
3908 /* Register new BGP information. */
3909 bgp_info_add (rn, new);
3910
3911 /* route_node_get lock */
3912 bgp_unlock_node (rn);
3913
3914 /* Process change. */
3915 bgp_process (bgp, rn, afi, safi);
3916
3917 /* Unintern original. */
3918 aspath_unintern (&attr.aspath);
3919 bgp_attr_extra_free (&attr);
3920}
3921
paul718e3742002-12-13 20:15:29 +00003922/* Configure static BGP network. When user don't run zebra, static
3923 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003924static int
paulfd79ac92004-10-13 05:06:08 +00003925bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003926 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003927{
3928 int ret;
3929 struct prefix p;
3930 struct bgp_static *bgp_static;
3931 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003932 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003933
3934 /* Convert IP prefix string to struct prefix. */
3935 ret = str2prefix (ip_str, &p);
3936 if (! ret)
3937 {
3938 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3939 return CMD_WARNING;
3940 }
3941#ifdef HAVE_IPV6
3942 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3943 {
3944 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3945 VTY_NEWLINE);
3946 return CMD_WARNING;
3947 }
3948#endif /* HAVE_IPV6 */
3949
3950 apply_mask (&p);
3951
3952 /* Set BGP static route configuration. */
3953 rn = bgp_node_get (bgp->route[afi][safi], &p);
3954
3955 if (rn->info)
3956 {
3957 /* Configuration change. */
3958 bgp_static = rn->info;
3959
3960 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003961 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3962 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003963
paul718e3742002-12-13 20:15:29 +00003964 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003965
paul718e3742002-12-13 20:15:29 +00003966 if (rmap)
3967 {
3968 if (bgp_static->rmap.name)
3969 free (bgp_static->rmap.name);
3970 bgp_static->rmap.name = strdup (rmap);
3971 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3972 }
3973 else
3974 {
3975 if (bgp_static->rmap.name)
3976 free (bgp_static->rmap.name);
3977 bgp_static->rmap.name = NULL;
3978 bgp_static->rmap.map = NULL;
3979 bgp_static->valid = 0;
3980 }
3981 bgp_unlock_node (rn);
3982 }
3983 else
3984 {
3985 /* New configuration. */
3986 bgp_static = bgp_static_new ();
3987 bgp_static->backdoor = backdoor;
3988 bgp_static->valid = 0;
3989 bgp_static->igpmetric = 0;
3990 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003991
paul718e3742002-12-13 20:15:29 +00003992 if (rmap)
3993 {
3994 if (bgp_static->rmap.name)
3995 free (bgp_static->rmap.name);
3996 bgp_static->rmap.name = strdup (rmap);
3997 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3998 }
3999 rn->info = bgp_static;
4000 }
4001
4002 /* If BGP scan is not enabled, we should install this route here. */
4003 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4004 {
4005 bgp_static->valid = 1;
4006
4007 if (need_update)
4008 bgp_static_withdraw (bgp, &p, afi, safi);
4009
4010 if (! bgp_static->backdoor)
4011 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4012 }
4013
4014 return CMD_SUCCESS;
4015}
4016
4017/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00004018static int
paulfd79ac92004-10-13 05:06:08 +00004019bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04004020 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004021{
4022 int ret;
4023 struct prefix p;
4024 struct bgp_static *bgp_static;
4025 struct bgp_node *rn;
4026
4027 /* Convert IP prefix string to struct prefix. */
4028 ret = str2prefix (ip_str, &p);
4029 if (! ret)
4030 {
4031 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4032 return CMD_WARNING;
4033 }
4034#ifdef HAVE_IPV6
4035 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4036 {
4037 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4038 VTY_NEWLINE);
4039 return CMD_WARNING;
4040 }
4041#endif /* HAVE_IPV6 */
4042
4043 apply_mask (&p);
4044
4045 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4046 if (! rn)
4047 {
4048 vty_out (vty, "%% Can't find specified static route configuration.%s",
4049 VTY_NEWLINE);
4050 return CMD_WARNING;
4051 }
4052
4053 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004054
paul718e3742002-12-13 20:15:29 +00004055 /* Update BGP RIB. */
4056 if (! bgp_static->backdoor)
4057 bgp_static_withdraw (bgp, &p, afi, safi);
4058
4059 /* Clear configuration. */
4060 bgp_static_free (bgp_static);
4061 rn->info = NULL;
4062 bgp_unlock_node (rn);
4063 bgp_unlock_node (rn);
4064
4065 return CMD_SUCCESS;
4066}
4067
4068/* Called from bgp_delete(). Delete all static routes from the BGP
4069 instance. */
4070void
4071bgp_static_delete (struct bgp *bgp)
4072{
4073 afi_t afi;
4074 safi_t safi;
4075 struct bgp_node *rn;
4076 struct bgp_node *rm;
4077 struct bgp_table *table;
4078 struct bgp_static *bgp_static;
4079
4080 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4081 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4082 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4083 if (rn->info != NULL)
4084 {
4085 if (safi == SAFI_MPLS_VPN)
4086 {
4087 table = rn->info;
4088
4089 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4090 {
4091 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004092 bgp_static_withdraw_safi (bgp, &rm->p,
4093 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004094 (struct prefix_rd *)&rn->p,
4095 bgp_static->tag);
4096 bgp_static_free (bgp_static);
4097 rn->info = NULL;
4098 bgp_unlock_node (rn);
4099 }
4100 }
4101 else
4102 {
4103 bgp_static = rn->info;
4104 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4105 bgp_static_free (bgp_static);
4106 rn->info = NULL;
4107 bgp_unlock_node (rn);
4108 }
4109 }
4110}
4111
Lou Bergera76d9ca2016-01-12 13:41:53 -05004112/*
4113 * gpz 110624
4114 * Currently this is used to set static routes for VPN and ENCAP.
4115 * I think it can probably be factored with bgp_static_set.
4116 */
paul718e3742002-12-13 20:15:29 +00004117int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004118bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4119 const char *rd_str, const char *tag_str,
4120 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004121{
4122 int ret;
4123 struct prefix p;
4124 struct prefix_rd prd;
4125 struct bgp *bgp;
4126 struct bgp_node *prn;
4127 struct bgp_node *rn;
4128 struct bgp_table *table;
4129 struct bgp_static *bgp_static;
4130 u_char tag[3];
4131
4132 bgp = vty->index;
4133
4134 ret = str2prefix (ip_str, &p);
4135 if (! ret)
4136 {
4137 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4138 return CMD_WARNING;
4139 }
4140 apply_mask (&p);
4141
4142 ret = str2prefix_rd (rd_str, &prd);
4143 if (! ret)
4144 {
4145 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4146 return CMD_WARNING;
4147 }
4148
4149 ret = str2tag (tag_str, tag);
4150 if (! ret)
4151 {
4152 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4153 return CMD_WARNING;
4154 }
4155
Lou Bergera76d9ca2016-01-12 13:41:53 -05004156 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004157 (struct prefix *)&prd);
4158 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004159 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004160 else
4161 bgp_unlock_node (prn);
4162 table = prn->info;
4163
4164 rn = bgp_node_get (table, &p);
4165
4166 if (rn->info)
4167 {
4168 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4169 bgp_unlock_node (rn);
4170 }
4171 else
4172 {
4173 /* New configuration. */
4174 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004175 bgp_static->backdoor = 0;
4176 bgp_static->valid = 0;
4177 bgp_static->igpmetric = 0;
4178 bgp_static->igpnexthop.s_addr = 0;
4179 memcpy(bgp_static->tag, tag, 3);
4180 bgp_static->prd = prd;
4181
4182 if (rmap_str)
4183 {
4184 if (bgp_static->rmap.name)
4185 free (bgp_static->rmap.name);
4186 bgp_static->rmap.name = strdup (rmap_str);
4187 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4188 }
paul718e3742002-12-13 20:15:29 +00004189 rn->info = bgp_static;
4190
Lou Bergera76d9ca2016-01-12 13:41:53 -05004191 bgp_static->valid = 1;
4192 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004193 }
4194
4195 return CMD_SUCCESS;
4196}
4197
4198/* Configure static BGP network. */
4199int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004200bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4201 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004202{
4203 int ret;
4204 struct bgp *bgp;
4205 struct prefix p;
4206 struct prefix_rd prd;
4207 struct bgp_node *prn;
4208 struct bgp_node *rn;
4209 struct bgp_table *table;
4210 struct bgp_static *bgp_static;
4211 u_char tag[3];
4212
4213 bgp = vty->index;
4214
4215 /* Convert IP prefix string to struct prefix. */
4216 ret = str2prefix (ip_str, &p);
4217 if (! ret)
4218 {
4219 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4220 return CMD_WARNING;
4221 }
4222 apply_mask (&p);
4223
4224 ret = str2prefix_rd (rd_str, &prd);
4225 if (! ret)
4226 {
4227 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4228 return CMD_WARNING;
4229 }
4230
4231 ret = str2tag (tag_str, tag);
4232 if (! ret)
4233 {
4234 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4235 return CMD_WARNING;
4236 }
4237
Lou Bergera76d9ca2016-01-12 13:41:53 -05004238 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004239 (struct prefix *)&prd);
4240 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004241 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004242 else
4243 bgp_unlock_node (prn);
4244 table = prn->info;
4245
4246 rn = bgp_node_lookup (table, &p);
4247
4248 if (rn)
4249 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004250 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004251
4252 bgp_static = rn->info;
4253 bgp_static_free (bgp_static);
4254 rn->info = NULL;
4255 bgp_unlock_node (rn);
4256 bgp_unlock_node (rn);
4257 }
4258 else
4259 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4260
4261 return CMD_SUCCESS;
4262}
David Lamparter6b0655a2014-06-04 06:53:35 +02004263
paul718e3742002-12-13 20:15:29 +00004264DEFUN (bgp_network,
4265 bgp_network_cmd,
4266 "network A.B.C.D/M",
4267 "Specify a network to announce via BGP\n"
4268 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4269{
4270 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004271 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004272}
4273
4274DEFUN (bgp_network_route_map,
4275 bgp_network_route_map_cmd,
4276 "network A.B.C.D/M route-map WORD",
4277 "Specify a network to announce via BGP\n"
4278 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4279 "Route-map to modify the attributes\n"
4280 "Name of the route map\n")
4281{
4282 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004283 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004284}
4285
4286DEFUN (bgp_network_backdoor,
4287 bgp_network_backdoor_cmd,
4288 "network A.B.C.D/M backdoor",
4289 "Specify a network to announce via BGP\n"
4290 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4291 "Specify a BGP backdoor route\n")
4292{
Paul Jakma41367172007-08-06 15:24:51 +00004293 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004294 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004295}
4296
4297DEFUN (bgp_network_mask,
4298 bgp_network_mask_cmd,
4299 "network A.B.C.D mask A.B.C.D",
4300 "Specify a network to announce via BGP\n"
4301 "Network number\n"
4302 "Network mask\n"
4303 "Network mask\n")
4304{
4305 int ret;
4306 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004307
paul718e3742002-12-13 20:15:29 +00004308 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4309 if (! ret)
4310 {
4311 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4312 return CMD_WARNING;
4313 }
4314
4315 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004316 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004317}
4318
4319DEFUN (bgp_network_mask_route_map,
4320 bgp_network_mask_route_map_cmd,
4321 "network A.B.C.D mask A.B.C.D route-map WORD",
4322 "Specify a network to announce via BGP\n"
4323 "Network number\n"
4324 "Network mask\n"
4325 "Network mask\n"
4326 "Route-map to modify the attributes\n"
4327 "Name of the route map\n")
4328{
4329 int ret;
4330 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004331
paul718e3742002-12-13 20:15:29 +00004332 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4333 if (! ret)
4334 {
4335 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4336 return CMD_WARNING;
4337 }
4338
4339 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004340 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004341}
4342
4343DEFUN (bgp_network_mask_backdoor,
4344 bgp_network_mask_backdoor_cmd,
4345 "network A.B.C.D mask A.B.C.D backdoor",
4346 "Specify a network to announce via BGP\n"
4347 "Network number\n"
4348 "Network mask\n"
4349 "Network mask\n"
4350 "Specify a BGP backdoor route\n")
4351{
4352 int ret;
4353 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004354
paul718e3742002-12-13 20:15:29 +00004355 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4356 if (! ret)
4357 {
4358 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4359 return CMD_WARNING;
4360 }
4361
Paul Jakma41367172007-08-06 15:24:51 +00004362 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004363 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004364}
4365
4366DEFUN (bgp_network_mask_natural,
4367 bgp_network_mask_natural_cmd,
4368 "network A.B.C.D",
4369 "Specify a network to announce via BGP\n"
4370 "Network number\n")
4371{
4372 int ret;
4373 char prefix_str[BUFSIZ];
4374
4375 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4376 if (! ret)
4377 {
4378 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4379 return CMD_WARNING;
4380 }
4381
4382 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004383 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004384}
4385
4386DEFUN (bgp_network_mask_natural_route_map,
4387 bgp_network_mask_natural_route_map_cmd,
4388 "network A.B.C.D route-map WORD",
4389 "Specify a network to announce via BGP\n"
4390 "Network number\n"
4391 "Route-map to modify the attributes\n"
4392 "Name of the route map\n")
4393{
4394 int ret;
4395 char prefix_str[BUFSIZ];
4396
4397 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4398 if (! ret)
4399 {
4400 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4401 return CMD_WARNING;
4402 }
4403
4404 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004405 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004406}
4407
4408DEFUN (bgp_network_mask_natural_backdoor,
4409 bgp_network_mask_natural_backdoor_cmd,
4410 "network A.B.C.D backdoor",
4411 "Specify a network to announce via BGP\n"
4412 "Network number\n"
4413 "Specify a BGP backdoor route\n")
4414{
4415 int ret;
4416 char prefix_str[BUFSIZ];
4417
4418 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4419 if (! ret)
4420 {
4421 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4422 return CMD_WARNING;
4423 }
4424
Paul Jakma41367172007-08-06 15:24:51 +00004425 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004426 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004427}
4428
4429DEFUN (no_bgp_network,
4430 no_bgp_network_cmd,
4431 "no network A.B.C.D/M",
4432 NO_STR
4433 "Specify a network to announce via BGP\n"
4434 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4435{
4436 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4437 bgp_node_safi (vty));
4438}
4439
4440ALIAS (no_bgp_network,
4441 no_bgp_network_route_map_cmd,
4442 "no network A.B.C.D/M route-map WORD",
4443 NO_STR
4444 "Specify a network to announce via BGP\n"
4445 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4446 "Route-map to modify the attributes\n"
4447 "Name of the route map\n")
4448
4449ALIAS (no_bgp_network,
4450 no_bgp_network_backdoor_cmd,
4451 "no network A.B.C.D/M backdoor",
4452 NO_STR
4453 "Specify a network to announce via BGP\n"
4454 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4455 "Specify a BGP backdoor route\n")
4456
4457DEFUN (no_bgp_network_mask,
4458 no_bgp_network_mask_cmd,
4459 "no network A.B.C.D mask A.B.C.D",
4460 NO_STR
4461 "Specify a network to announce via BGP\n"
4462 "Network number\n"
4463 "Network mask\n"
4464 "Network mask\n")
4465{
4466 int ret;
4467 char prefix_str[BUFSIZ];
4468
4469 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4470 if (! ret)
4471 {
4472 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4473 return CMD_WARNING;
4474 }
4475
4476 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4477 bgp_node_safi (vty));
4478}
4479
4480ALIAS (no_bgp_network_mask,
4481 no_bgp_network_mask_route_map_cmd,
4482 "no network A.B.C.D mask A.B.C.D route-map WORD",
4483 NO_STR
4484 "Specify a network to announce via BGP\n"
4485 "Network number\n"
4486 "Network mask\n"
4487 "Network mask\n"
4488 "Route-map to modify the attributes\n"
4489 "Name of the route map\n")
4490
4491ALIAS (no_bgp_network_mask,
4492 no_bgp_network_mask_backdoor_cmd,
4493 "no network A.B.C.D mask A.B.C.D backdoor",
4494 NO_STR
4495 "Specify a network to announce via BGP\n"
4496 "Network number\n"
4497 "Network mask\n"
4498 "Network mask\n"
4499 "Specify a BGP backdoor route\n")
4500
4501DEFUN (no_bgp_network_mask_natural,
4502 no_bgp_network_mask_natural_cmd,
4503 "no network A.B.C.D",
4504 NO_STR
4505 "Specify a network to announce via BGP\n"
4506 "Network number\n")
4507{
4508 int ret;
4509 char prefix_str[BUFSIZ];
4510
4511 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4512 if (! ret)
4513 {
4514 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4515 return CMD_WARNING;
4516 }
4517
4518 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4519 bgp_node_safi (vty));
4520}
4521
4522ALIAS (no_bgp_network_mask_natural,
4523 no_bgp_network_mask_natural_route_map_cmd,
4524 "no network A.B.C.D route-map WORD",
4525 NO_STR
4526 "Specify a network to announce via BGP\n"
4527 "Network number\n"
4528 "Route-map to modify the attributes\n"
4529 "Name of the route map\n")
4530
4531ALIAS (no_bgp_network_mask_natural,
4532 no_bgp_network_mask_natural_backdoor_cmd,
4533 "no network A.B.C.D backdoor",
4534 NO_STR
4535 "Specify a network to announce via BGP\n"
4536 "Network number\n"
4537 "Specify a BGP backdoor route\n")
4538
4539#ifdef HAVE_IPV6
4540DEFUN (ipv6_bgp_network,
4541 ipv6_bgp_network_cmd,
4542 "network X:X::X:X/M",
4543 "Specify a network to announce via BGP\n"
4544 "IPv6 prefix <network>/<length>\n")
4545{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304546 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004547 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004548}
4549
4550DEFUN (ipv6_bgp_network_route_map,
4551 ipv6_bgp_network_route_map_cmd,
4552 "network X:X::X:X/M route-map WORD",
4553 "Specify a network to announce via BGP\n"
4554 "IPv6 prefix <network>/<length>\n"
4555 "Route-map to modify the attributes\n"
4556 "Name of the route map\n")
4557{
4558 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004559 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004560}
4561
4562DEFUN (no_ipv6_bgp_network,
4563 no_ipv6_bgp_network_cmd,
4564 "no network X:X::X:X/M",
4565 NO_STR
4566 "Specify a network to announce via BGP\n"
4567 "IPv6 prefix <network>/<length>\n")
4568{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304569 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004570}
4571
4572ALIAS (no_ipv6_bgp_network,
4573 no_ipv6_bgp_network_route_map_cmd,
4574 "no network X:X::X:X/M route-map WORD",
4575 NO_STR
4576 "Specify a network to announce via BGP\n"
4577 "IPv6 prefix <network>/<length>\n"
4578 "Route-map to modify the attributes\n"
4579 "Name of the route map\n")
4580
4581ALIAS (ipv6_bgp_network,
4582 old_ipv6_bgp_network_cmd,
4583 "ipv6 bgp network X:X::X:X/M",
4584 IPV6_STR
4585 BGP_STR
4586 "Specify a network to announce via BGP\n"
4587 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4588
4589ALIAS (no_ipv6_bgp_network,
4590 old_no_ipv6_bgp_network_cmd,
4591 "no ipv6 bgp network X:X::X:X/M",
4592 NO_STR
4593 IPV6_STR
4594 BGP_STR
4595 "Specify a network to announce via BGP\n"
4596 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4597#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004598
4599/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4600ALIAS_DEPRECATED (bgp_network,
4601 bgp_network_ttl_cmd,
4602 "network A.B.C.D/M pathlimit <0-255>",
4603 "Specify a network to announce via BGP\n"
4604 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4605 "AS-Path hopcount limit attribute\n"
4606 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4607ALIAS_DEPRECATED (bgp_network_backdoor,
4608 bgp_network_backdoor_ttl_cmd,
4609 "network A.B.C.D/M backdoor pathlimit <0-255>",
4610 "Specify a network to announce via BGP\n"
4611 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4612 "Specify a BGP backdoor route\n"
4613 "AS-Path hopcount limit attribute\n"
4614 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4615ALIAS_DEPRECATED (bgp_network_mask,
4616 bgp_network_mask_ttl_cmd,
4617 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4618 "Specify a network to announce via BGP\n"
4619 "Network number\n"
4620 "Network mask\n"
4621 "Network mask\n"
4622 "AS-Path hopcount limit attribute\n"
4623 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4624ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4625 bgp_network_mask_backdoor_ttl_cmd,
4626 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4627 "Specify a network to announce via BGP\n"
4628 "Network number\n"
4629 "Network mask\n"
4630 "Network mask\n"
4631 "Specify a BGP backdoor route\n"
4632 "AS-Path hopcount limit attribute\n"
4633 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4634ALIAS_DEPRECATED (bgp_network_mask_natural,
4635 bgp_network_mask_natural_ttl_cmd,
4636 "network A.B.C.D pathlimit <0-255>",
4637 "Specify a network to announce via BGP\n"
4638 "Network number\n"
4639 "AS-Path hopcount limit attribute\n"
4640 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4641ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4642 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004643 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004644 "Specify a network to announce via BGP\n"
4645 "Network number\n"
4646 "Specify a BGP backdoor route\n"
4647 "AS-Path hopcount limit attribute\n"
4648 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4649ALIAS_DEPRECATED (no_bgp_network,
4650 no_bgp_network_ttl_cmd,
4651 "no network A.B.C.D/M pathlimit <0-255>",
4652 NO_STR
4653 "Specify a network to announce via BGP\n"
4654 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4655 "AS-Path hopcount limit attribute\n"
4656 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4657ALIAS_DEPRECATED (no_bgp_network,
4658 no_bgp_network_backdoor_ttl_cmd,
4659 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4660 NO_STR
4661 "Specify a network to announce via BGP\n"
4662 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4663 "Specify a BGP backdoor route\n"
4664 "AS-Path hopcount limit attribute\n"
4665 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4666ALIAS_DEPRECATED (no_bgp_network,
4667 no_bgp_network_mask_ttl_cmd,
4668 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4669 NO_STR
4670 "Specify a network to announce via BGP\n"
4671 "Network number\n"
4672 "Network mask\n"
4673 "Network mask\n"
4674 "AS-Path hopcount limit attribute\n"
4675 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4676ALIAS_DEPRECATED (no_bgp_network_mask,
4677 no_bgp_network_mask_backdoor_ttl_cmd,
4678 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4679 NO_STR
4680 "Specify a network to announce via BGP\n"
4681 "Network number\n"
4682 "Network mask\n"
4683 "Network mask\n"
4684 "Specify a BGP backdoor route\n"
4685 "AS-Path hopcount limit attribute\n"
4686 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4687ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4688 no_bgp_network_mask_natural_ttl_cmd,
4689 "no network A.B.C.D pathlimit <0-255>",
4690 NO_STR
4691 "Specify a network to announce via BGP\n"
4692 "Network number\n"
4693 "AS-Path hopcount limit attribute\n"
4694 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4695ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4696 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4697 "no network A.B.C.D backdoor pathlimit <0-255>",
4698 NO_STR
4699 "Specify a network to announce via BGP\n"
4700 "Network number\n"
4701 "Specify a BGP backdoor route\n"
4702 "AS-Path hopcount limit attribute\n"
4703 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004704#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004705ALIAS_DEPRECATED (ipv6_bgp_network,
4706 ipv6_bgp_network_ttl_cmd,
4707 "network X:X::X:X/M pathlimit <0-255>",
4708 "Specify a network to announce via BGP\n"
4709 "IPv6 prefix <network>/<length>\n"
4710 "AS-Path hopcount limit attribute\n"
4711 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4712ALIAS_DEPRECATED (no_ipv6_bgp_network,
4713 no_ipv6_bgp_network_ttl_cmd,
4714 "no network X:X::X:X/M pathlimit <0-255>",
4715 NO_STR
4716 "Specify a network to announce via BGP\n"
4717 "IPv6 prefix <network>/<length>\n"
4718 "AS-Path hopcount limit attribute\n"
4719 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004720#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004721
paul718e3742002-12-13 20:15:29 +00004722/* Aggreagete address:
4723
4724 advertise-map Set condition to advertise attribute
4725 as-set Generate AS set path information
4726 attribute-map Set attributes of aggregate
4727 route-map Set parameters of aggregate
4728 summary-only Filter more specific routes from updates
4729 suppress-map Conditionally filter more specific routes from updates
4730 <cr>
4731 */
4732struct bgp_aggregate
4733{
4734 /* Summary-only flag. */
4735 u_char summary_only;
4736
4737 /* AS set generation. */
4738 u_char as_set;
4739
4740 /* Route-map for aggregated route. */
4741 struct route_map *map;
4742
4743 /* Suppress-count. */
4744 unsigned long count;
4745
4746 /* SAFI configuration. */
4747 safi_t safi;
4748};
4749
paul94f2b392005-06-28 12:44:16 +00004750static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004751bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004752{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004753 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004754}
4755
paul94f2b392005-06-28 12:44:16 +00004756static void
paul718e3742002-12-13 20:15:29 +00004757bgp_aggregate_free (struct bgp_aggregate *aggregate)
4758{
4759 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4760}
4761
paul94f2b392005-06-28 12:44:16 +00004762static void
paul718e3742002-12-13 20:15:29 +00004763bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4764 afi_t afi, safi_t safi, struct bgp_info *del,
4765 struct bgp_aggregate *aggregate)
4766{
4767 struct bgp_table *table;
4768 struct bgp_node *top;
4769 struct bgp_node *rn;
4770 u_char origin;
4771 struct aspath *aspath = NULL;
4772 struct aspath *asmerge = NULL;
4773 struct community *community = NULL;
4774 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004775 struct bgp_info *ri;
4776 struct bgp_info *new;
4777 int first = 1;
4778 unsigned long match = 0;
4779
paul718e3742002-12-13 20:15:29 +00004780 /* ORIGIN attribute: If at least one route among routes that are
4781 aggregated has ORIGIN with the value INCOMPLETE, then the
4782 aggregated route must have the ORIGIN attribute with the value
4783 INCOMPLETE. Otherwise, if at least one route among routes that
4784 are aggregated has ORIGIN with the value EGP, then the aggregated
4785 route must have the origin attribute with the value EGP. In all
4786 other case the value of the ORIGIN attribute of the aggregated
4787 route is INTERNAL. */
4788 origin = BGP_ORIGIN_IGP;
4789
4790 table = bgp->rib[afi][safi];
4791
4792 top = bgp_node_get (table, p);
4793 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4794 if (rn->p.prefixlen > p->prefixlen)
4795 {
4796 match = 0;
4797
4798 for (ri = rn->info; ri; ri = ri->next)
4799 {
4800 if (BGP_INFO_HOLDDOWN (ri))
4801 continue;
4802
4803 if (del && ri == del)
4804 continue;
4805
4806 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004807 first = 0;
paul718e3742002-12-13 20:15:29 +00004808
4809#ifdef AGGREGATE_NEXTHOP_CHECK
4810 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4811 || ri->attr->med != med)
4812 {
4813 if (aspath)
4814 aspath_free (aspath);
4815 if (community)
4816 community_free (community);
4817 bgp_unlock_node (rn);
4818 bgp_unlock_node (top);
4819 return;
4820 }
4821#endif /* AGGREGATE_NEXTHOP_CHECK */
4822
4823 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4824 {
4825 if (aggregate->summary_only)
4826 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004827 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004828 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004829 match++;
4830 }
4831
4832 aggregate->count++;
4833
4834 if (aggregate->as_set)
4835 {
4836 if (origin < ri->attr->origin)
4837 origin = ri->attr->origin;
4838
4839 if (aspath)
4840 {
4841 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4842 aspath_free (aspath);
4843 aspath = asmerge;
4844 }
4845 else
4846 aspath = aspath_dup (ri->attr->aspath);
4847
4848 if (ri->attr->community)
4849 {
4850 if (community)
4851 {
4852 commerge = community_merge (community,
4853 ri->attr->community);
4854 community = community_uniq_sort (commerge);
4855 community_free (commerge);
4856 }
4857 else
4858 community = community_dup (ri->attr->community);
4859 }
4860 }
4861 }
4862 }
4863 if (match)
4864 bgp_process (bgp, rn, afi, safi);
4865 }
4866 bgp_unlock_node (top);
4867
4868 if (rinew)
4869 {
4870 aggregate->count++;
4871
4872 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004873 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004874
4875 if (aggregate->as_set)
4876 {
4877 if (origin < rinew->attr->origin)
4878 origin = rinew->attr->origin;
4879
4880 if (aspath)
4881 {
4882 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4883 aspath_free (aspath);
4884 aspath = asmerge;
4885 }
4886 else
4887 aspath = aspath_dup (rinew->attr->aspath);
4888
4889 if (rinew->attr->community)
4890 {
4891 if (community)
4892 {
4893 commerge = community_merge (community,
4894 rinew->attr->community);
4895 community = community_uniq_sort (commerge);
4896 community_free (commerge);
4897 }
4898 else
4899 community = community_dup (rinew->attr->community);
4900 }
4901 }
4902 }
4903
4904 if (aggregate->count > 0)
4905 {
4906 rn = bgp_node_get (table, p);
4907 new = bgp_info_new ();
4908 new->type = ZEBRA_ROUTE_BGP;
4909 new->sub_type = BGP_ROUTE_AGGREGATE;
4910 new->peer = bgp->peer_self;
4911 SET_FLAG (new->flags, BGP_INFO_VALID);
4912 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004913 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004914
4915 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004916 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004917 bgp_process (bgp, rn, afi, safi);
4918 }
4919 else
4920 {
4921 if (aspath)
4922 aspath_free (aspath);
4923 if (community)
4924 community_free (community);
4925 }
4926}
4927
4928void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4929 struct bgp_aggregate *);
4930
4931void
4932bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4933 struct bgp_info *ri, afi_t afi, safi_t safi)
4934{
4935 struct bgp_node *child;
4936 struct bgp_node *rn;
4937 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004938 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004939
4940 /* MPLS-VPN aggregation is not yet supported. */
4941 if (safi == SAFI_MPLS_VPN)
4942 return;
4943
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004944 table = bgp->aggregate[afi][safi];
4945
4946 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004947 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004948 return;
4949
paul718e3742002-12-13 20:15:29 +00004950 if (p->prefixlen == 0)
4951 return;
4952
4953 if (BGP_INFO_HOLDDOWN (ri))
4954 return;
4955
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004956 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004957
4958 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004959 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004960 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4961 {
4962 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004963 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004964 }
4965 bgp_unlock_node (child);
4966}
4967
4968void
4969bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4970 struct bgp_info *del, afi_t afi, safi_t safi)
4971{
4972 struct bgp_node *child;
4973 struct bgp_node *rn;
4974 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004975 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004976
4977 /* MPLS-VPN aggregation is not yet supported. */
4978 if (safi == SAFI_MPLS_VPN)
4979 return;
4980
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004981 table = bgp->aggregate[afi][safi];
4982
4983 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004984 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004985 return;
4986
paul718e3742002-12-13 20:15:29 +00004987 if (p->prefixlen == 0)
4988 return;
4989
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004990 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004991
4992 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004993 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00004994 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4995 {
4996 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004997 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004998 }
4999 bgp_unlock_node (child);
5000}
5001
paul94f2b392005-06-28 12:44:16 +00005002static void
paul718e3742002-12-13 20:15:29 +00005003bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5004 struct bgp_aggregate *aggregate)
5005{
5006 struct bgp_table *table;
5007 struct bgp_node *top;
5008 struct bgp_node *rn;
5009 struct bgp_info *new;
5010 struct bgp_info *ri;
5011 unsigned long match;
5012 u_char origin = BGP_ORIGIN_IGP;
5013 struct aspath *aspath = NULL;
5014 struct aspath *asmerge = NULL;
5015 struct community *community = NULL;
5016 struct community *commerge = NULL;
5017
5018 table = bgp->rib[afi][safi];
5019
5020 /* Sanity check. */
5021 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5022 return;
5023 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5024 return;
5025
5026 /* If routes exists below this node, generate aggregate routes. */
5027 top = bgp_node_get (table, p);
5028 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5029 if (rn->p.prefixlen > p->prefixlen)
5030 {
5031 match = 0;
5032
5033 for (ri = rn->info; ri; ri = ri->next)
5034 {
5035 if (BGP_INFO_HOLDDOWN (ri))
5036 continue;
5037
5038 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5039 {
5040 /* summary-only aggregate route suppress aggregated
5041 route announcement. */
5042 if (aggregate->summary_only)
5043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005044 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005045 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005046 match++;
5047 }
5048 /* as-set aggregate route generate origin, as path,
5049 community aggregation. */
5050 if (aggregate->as_set)
5051 {
5052 if (origin < ri->attr->origin)
5053 origin = ri->attr->origin;
5054
5055 if (aspath)
5056 {
5057 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5058 aspath_free (aspath);
5059 aspath = asmerge;
5060 }
5061 else
5062 aspath = aspath_dup (ri->attr->aspath);
5063
5064 if (ri->attr->community)
5065 {
5066 if (community)
5067 {
5068 commerge = community_merge (community,
5069 ri->attr->community);
5070 community = community_uniq_sort (commerge);
5071 community_free (commerge);
5072 }
5073 else
5074 community = community_dup (ri->attr->community);
5075 }
5076 }
5077 aggregate->count++;
5078 }
5079 }
5080
5081 /* If this node is suppressed, process the change. */
5082 if (match)
5083 bgp_process (bgp, rn, afi, safi);
5084 }
5085 bgp_unlock_node (top);
5086
5087 /* Add aggregate route to BGP table. */
5088 if (aggregate->count)
5089 {
5090 rn = bgp_node_get (table, p);
5091
5092 new = bgp_info_new ();
5093 new->type = ZEBRA_ROUTE_BGP;
5094 new->sub_type = BGP_ROUTE_AGGREGATE;
5095 new->peer = bgp->peer_self;
5096 SET_FLAG (new->flags, BGP_INFO_VALID);
5097 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03005098 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005099
5100 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005101 bgp_unlock_node (rn);
5102
paul718e3742002-12-13 20:15:29 +00005103 /* Process change. */
5104 bgp_process (bgp, rn, afi, safi);
5105 }
Denil Virae2a92582015-08-11 13:34:59 -07005106 else
5107 {
5108 if (aspath)
5109 aspath_free (aspath);
5110 if (community)
5111 community_free (community);
5112 }
paul718e3742002-12-13 20:15:29 +00005113}
5114
5115void
5116bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5117 safi_t safi, struct bgp_aggregate *aggregate)
5118{
5119 struct bgp_table *table;
5120 struct bgp_node *top;
5121 struct bgp_node *rn;
5122 struct bgp_info *ri;
5123 unsigned long match;
5124
5125 table = bgp->rib[afi][safi];
5126
5127 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5128 return;
5129 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5130 return;
5131
5132 /* If routes exists below this node, generate aggregate routes. */
5133 top = bgp_node_get (table, p);
5134 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5135 if (rn->p.prefixlen > p->prefixlen)
5136 {
5137 match = 0;
5138
5139 for (ri = rn->info; ri; ri = ri->next)
5140 {
5141 if (BGP_INFO_HOLDDOWN (ri))
5142 continue;
5143
5144 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5145 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005146 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005147 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005148 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005149
Paul Jakmafb982c22007-05-04 20:15:47 +00005150 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005151 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005152 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005153 match++;
5154 }
5155 }
5156 aggregate->count--;
5157 }
5158 }
5159
Paul Jakmafb982c22007-05-04 20:15:47 +00005160 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005161 if (match)
5162 bgp_process (bgp, rn, afi, safi);
5163 }
5164 bgp_unlock_node (top);
5165
5166 /* Delete aggregate route from BGP table. */
5167 rn = bgp_node_get (table, p);
5168
5169 for (ri = rn->info; ri; ri = ri->next)
5170 if (ri->peer == bgp->peer_self
5171 && ri->type == ZEBRA_ROUTE_BGP
5172 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5173 break;
5174
5175 /* Withdraw static BGP route from routing table. */
5176 if (ri)
5177 {
paul718e3742002-12-13 20:15:29 +00005178 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005179 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005180 }
5181
5182 /* Unlock bgp_node_lookup. */
5183 bgp_unlock_node (rn);
5184}
5185
5186/* Aggregate route attribute. */
5187#define AGGREGATE_SUMMARY_ONLY 1
5188#define AGGREGATE_AS_SET 1
5189
paul94f2b392005-06-28 12:44:16 +00005190static int
Robert Baysf6269b42010-08-05 10:26:28 -07005191bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5192 afi_t afi, safi_t safi)
5193{
5194 int ret;
5195 struct prefix p;
5196 struct bgp_node *rn;
5197 struct bgp *bgp;
5198 struct bgp_aggregate *aggregate;
5199
5200 /* Convert string to prefix structure. */
5201 ret = str2prefix (prefix_str, &p);
5202 if (!ret)
5203 {
5204 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5205 return CMD_WARNING;
5206 }
5207 apply_mask (&p);
5208
5209 /* Get BGP structure. */
5210 bgp = vty->index;
5211
5212 /* Old configuration check. */
5213 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5214 if (! rn)
5215 {
5216 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5217 VTY_NEWLINE);
5218 return CMD_WARNING;
5219 }
5220
5221 aggregate = rn->info;
5222 if (aggregate->safi & SAFI_UNICAST)
5223 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5224 if (aggregate->safi & SAFI_MULTICAST)
5225 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5226
5227 /* Unlock aggregate address configuration. */
5228 rn->info = NULL;
5229 bgp_aggregate_free (aggregate);
5230 bgp_unlock_node (rn);
5231 bgp_unlock_node (rn);
5232
5233 return CMD_SUCCESS;
5234}
5235
5236static int
5237bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005238 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005239 u_char summary_only, u_char as_set)
5240{
5241 int ret;
5242 struct prefix p;
5243 struct bgp_node *rn;
5244 struct bgp *bgp;
5245 struct bgp_aggregate *aggregate;
5246
5247 /* Convert string to prefix structure. */
5248 ret = str2prefix (prefix_str, &p);
5249 if (!ret)
5250 {
5251 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5252 return CMD_WARNING;
5253 }
5254 apply_mask (&p);
5255
5256 /* Get BGP structure. */
5257 bgp = vty->index;
5258
5259 /* Old configuration check. */
5260 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5261
5262 if (rn->info)
5263 {
5264 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005265 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005266 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5267 if (ret)
5268 {
Robert Bays368473f2010-08-05 10:26:29 -07005269 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5270 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005271 return CMD_WARNING;
5272 }
paul718e3742002-12-13 20:15:29 +00005273 }
5274
5275 /* Make aggregate address structure. */
5276 aggregate = bgp_aggregate_new ();
5277 aggregate->summary_only = summary_only;
5278 aggregate->as_set = as_set;
5279 aggregate->safi = safi;
5280 rn->info = aggregate;
5281
5282 /* Aggregate address insert into BGP routing table. */
5283 if (safi & SAFI_UNICAST)
5284 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5285 if (safi & SAFI_MULTICAST)
5286 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5287
5288 return CMD_SUCCESS;
5289}
5290
paul718e3742002-12-13 20:15:29 +00005291DEFUN (aggregate_address,
5292 aggregate_address_cmd,
5293 "aggregate-address A.B.C.D/M",
5294 "Configure BGP aggregate entries\n"
5295 "Aggregate prefix\n")
5296{
5297 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5298}
5299
5300DEFUN (aggregate_address_mask,
5301 aggregate_address_mask_cmd,
5302 "aggregate-address A.B.C.D A.B.C.D",
5303 "Configure BGP aggregate entries\n"
5304 "Aggregate address\n"
5305 "Aggregate mask\n")
5306{
5307 int ret;
5308 char prefix_str[BUFSIZ];
5309
5310 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5311
5312 if (! ret)
5313 {
5314 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5315 return CMD_WARNING;
5316 }
5317
5318 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5319 0, 0);
5320}
5321
5322DEFUN (aggregate_address_summary_only,
5323 aggregate_address_summary_only_cmd,
5324 "aggregate-address A.B.C.D/M summary-only",
5325 "Configure BGP aggregate entries\n"
5326 "Aggregate prefix\n"
5327 "Filter more specific routes from updates\n")
5328{
5329 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5330 AGGREGATE_SUMMARY_ONLY, 0);
5331}
5332
5333DEFUN (aggregate_address_mask_summary_only,
5334 aggregate_address_mask_summary_only_cmd,
5335 "aggregate-address A.B.C.D A.B.C.D summary-only",
5336 "Configure BGP aggregate entries\n"
5337 "Aggregate address\n"
5338 "Aggregate mask\n"
5339 "Filter more specific routes from updates\n")
5340{
5341 int ret;
5342 char prefix_str[BUFSIZ];
5343
5344 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5345
5346 if (! ret)
5347 {
5348 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5349 return CMD_WARNING;
5350 }
5351
5352 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5353 AGGREGATE_SUMMARY_ONLY, 0);
5354}
5355
5356DEFUN (aggregate_address_as_set,
5357 aggregate_address_as_set_cmd,
5358 "aggregate-address A.B.C.D/M as-set",
5359 "Configure BGP aggregate entries\n"
5360 "Aggregate prefix\n"
5361 "Generate AS set path information\n")
5362{
5363 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5364 0, AGGREGATE_AS_SET);
5365}
5366
5367DEFUN (aggregate_address_mask_as_set,
5368 aggregate_address_mask_as_set_cmd,
5369 "aggregate-address A.B.C.D A.B.C.D as-set",
5370 "Configure BGP aggregate entries\n"
5371 "Aggregate address\n"
5372 "Aggregate mask\n"
5373 "Generate AS set path information\n")
5374{
5375 int ret;
5376 char prefix_str[BUFSIZ];
5377
5378 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5379
5380 if (! ret)
5381 {
5382 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5383 return CMD_WARNING;
5384 }
5385
5386 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5387 0, AGGREGATE_AS_SET);
5388}
5389
5390
5391DEFUN (aggregate_address_as_set_summary,
5392 aggregate_address_as_set_summary_cmd,
5393 "aggregate-address A.B.C.D/M as-set summary-only",
5394 "Configure BGP aggregate entries\n"
5395 "Aggregate prefix\n"
5396 "Generate AS set path information\n"
5397 "Filter more specific routes from updates\n")
5398{
5399 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5400 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5401}
5402
5403ALIAS (aggregate_address_as_set_summary,
5404 aggregate_address_summary_as_set_cmd,
5405 "aggregate-address A.B.C.D/M summary-only as-set",
5406 "Configure BGP aggregate entries\n"
5407 "Aggregate prefix\n"
5408 "Filter more specific routes from updates\n"
5409 "Generate AS set path information\n")
5410
5411DEFUN (aggregate_address_mask_as_set_summary,
5412 aggregate_address_mask_as_set_summary_cmd,
5413 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5414 "Configure BGP aggregate entries\n"
5415 "Aggregate address\n"
5416 "Aggregate mask\n"
5417 "Generate AS set path information\n"
5418 "Filter more specific routes from updates\n")
5419{
5420 int ret;
5421 char prefix_str[BUFSIZ];
5422
5423 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5424
5425 if (! ret)
5426 {
5427 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5428 return CMD_WARNING;
5429 }
5430
5431 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5432 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5433}
5434
5435ALIAS (aggregate_address_mask_as_set_summary,
5436 aggregate_address_mask_summary_as_set_cmd,
5437 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5438 "Configure BGP aggregate entries\n"
5439 "Aggregate address\n"
5440 "Aggregate mask\n"
5441 "Filter more specific routes from updates\n"
5442 "Generate AS set path information\n")
5443
5444DEFUN (no_aggregate_address,
5445 no_aggregate_address_cmd,
5446 "no aggregate-address A.B.C.D/M",
5447 NO_STR
5448 "Configure BGP aggregate entries\n"
5449 "Aggregate prefix\n")
5450{
5451 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5452}
5453
5454ALIAS (no_aggregate_address,
5455 no_aggregate_address_summary_only_cmd,
5456 "no aggregate-address A.B.C.D/M summary-only",
5457 NO_STR
5458 "Configure BGP aggregate entries\n"
5459 "Aggregate prefix\n"
5460 "Filter more specific routes from updates\n")
5461
5462ALIAS (no_aggregate_address,
5463 no_aggregate_address_as_set_cmd,
5464 "no aggregate-address A.B.C.D/M as-set",
5465 NO_STR
5466 "Configure BGP aggregate entries\n"
5467 "Aggregate prefix\n"
5468 "Generate AS set path information\n")
5469
5470ALIAS (no_aggregate_address,
5471 no_aggregate_address_as_set_summary_cmd,
5472 "no aggregate-address A.B.C.D/M as-set summary-only",
5473 NO_STR
5474 "Configure BGP aggregate entries\n"
5475 "Aggregate prefix\n"
5476 "Generate AS set path information\n"
5477 "Filter more specific routes from updates\n")
5478
5479ALIAS (no_aggregate_address,
5480 no_aggregate_address_summary_as_set_cmd,
5481 "no aggregate-address A.B.C.D/M summary-only as-set",
5482 NO_STR
5483 "Configure BGP aggregate entries\n"
5484 "Aggregate prefix\n"
5485 "Filter more specific routes from updates\n"
5486 "Generate AS set path information\n")
5487
5488DEFUN (no_aggregate_address_mask,
5489 no_aggregate_address_mask_cmd,
5490 "no aggregate-address A.B.C.D A.B.C.D",
5491 NO_STR
5492 "Configure BGP aggregate entries\n"
5493 "Aggregate address\n"
5494 "Aggregate mask\n")
5495{
5496 int ret;
5497 char prefix_str[BUFSIZ];
5498
5499 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5500
5501 if (! ret)
5502 {
5503 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5504 return CMD_WARNING;
5505 }
5506
5507 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5508}
5509
5510ALIAS (no_aggregate_address_mask,
5511 no_aggregate_address_mask_summary_only_cmd,
5512 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5513 NO_STR
5514 "Configure BGP aggregate entries\n"
5515 "Aggregate address\n"
5516 "Aggregate mask\n"
5517 "Filter more specific routes from updates\n")
5518
5519ALIAS (no_aggregate_address_mask,
5520 no_aggregate_address_mask_as_set_cmd,
5521 "no aggregate-address A.B.C.D A.B.C.D as-set",
5522 NO_STR
5523 "Configure BGP aggregate entries\n"
5524 "Aggregate address\n"
5525 "Aggregate mask\n"
5526 "Generate AS set path information\n")
5527
5528ALIAS (no_aggregate_address_mask,
5529 no_aggregate_address_mask_as_set_summary_cmd,
5530 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5531 NO_STR
5532 "Configure BGP aggregate entries\n"
5533 "Aggregate address\n"
5534 "Aggregate mask\n"
5535 "Generate AS set path information\n"
5536 "Filter more specific routes from updates\n")
5537
5538ALIAS (no_aggregate_address_mask,
5539 no_aggregate_address_mask_summary_as_set_cmd,
5540 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5541 NO_STR
5542 "Configure BGP aggregate entries\n"
5543 "Aggregate address\n"
5544 "Aggregate mask\n"
5545 "Filter more specific routes from updates\n"
5546 "Generate AS set path information\n")
5547
5548#ifdef HAVE_IPV6
5549DEFUN (ipv6_aggregate_address,
5550 ipv6_aggregate_address_cmd,
5551 "aggregate-address X:X::X:X/M",
5552 "Configure BGP aggregate entries\n"
5553 "Aggregate prefix\n")
5554{
5555 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5556}
5557
5558DEFUN (ipv6_aggregate_address_summary_only,
5559 ipv6_aggregate_address_summary_only_cmd,
5560 "aggregate-address X:X::X:X/M summary-only",
5561 "Configure BGP aggregate entries\n"
5562 "Aggregate prefix\n"
5563 "Filter more specific routes from updates\n")
5564{
5565 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5566 AGGREGATE_SUMMARY_ONLY, 0);
5567}
5568
5569DEFUN (no_ipv6_aggregate_address,
5570 no_ipv6_aggregate_address_cmd,
5571 "no aggregate-address X:X::X:X/M",
5572 NO_STR
5573 "Configure BGP aggregate entries\n"
5574 "Aggregate prefix\n")
5575{
5576 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5577}
5578
5579DEFUN (no_ipv6_aggregate_address_summary_only,
5580 no_ipv6_aggregate_address_summary_only_cmd,
5581 "no aggregate-address X:X::X:X/M summary-only",
5582 NO_STR
5583 "Configure BGP aggregate entries\n"
5584 "Aggregate prefix\n"
5585 "Filter more specific routes from updates\n")
5586{
5587 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5588}
5589
5590ALIAS (ipv6_aggregate_address,
5591 old_ipv6_aggregate_address_cmd,
5592 "ipv6 bgp aggregate-address X:X::X:X/M",
5593 IPV6_STR
5594 BGP_STR
5595 "Configure BGP aggregate entries\n"
5596 "Aggregate prefix\n")
5597
5598ALIAS (ipv6_aggregate_address_summary_only,
5599 old_ipv6_aggregate_address_summary_only_cmd,
5600 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5601 IPV6_STR
5602 BGP_STR
5603 "Configure BGP aggregate entries\n"
5604 "Aggregate prefix\n"
5605 "Filter more specific routes from updates\n")
5606
5607ALIAS (no_ipv6_aggregate_address,
5608 old_no_ipv6_aggregate_address_cmd,
5609 "no ipv6 bgp aggregate-address X:X::X:X/M",
5610 NO_STR
5611 IPV6_STR
5612 BGP_STR
5613 "Configure BGP aggregate entries\n"
5614 "Aggregate prefix\n")
5615
5616ALIAS (no_ipv6_aggregate_address_summary_only,
5617 old_no_ipv6_aggregate_address_summary_only_cmd,
5618 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5619 NO_STR
5620 IPV6_STR
5621 BGP_STR
5622 "Configure BGP aggregate entries\n"
5623 "Aggregate prefix\n"
5624 "Filter more specific routes from updates\n")
5625#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005626
paul718e3742002-12-13 20:15:29 +00005627/* Redistribute route treatment. */
5628void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005629bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5630 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005631 u_int32_t metric, u_char type)
5632{
5633 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005634 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005635 struct bgp_info *new;
5636 struct bgp_info *bi;
5637 struct bgp_info info;
5638 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005639 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005640 struct attr *new_attr;
5641 afi_t afi;
5642 int ret;
5643
5644 /* Make default attribute. */
5645 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5646 if (nexthop)
5647 attr.nexthop = *nexthop;
5648
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005649#ifdef HAVE_IPV6
5650 if (nexthop6)
5651 {
5652 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5653 extra->mp_nexthop_global = *nexthop6;
5654 extra->mp_nexthop_len = 16;
5655 }
5656#endif
5657
paul718e3742002-12-13 20:15:29 +00005658 attr.med = metric;
5659 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5660
paul1eb8ef22005-04-07 07:30:20 +00005661 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005662 {
5663 afi = family2afi (p->family);
5664
5665 if (bgp->redist[afi][type])
5666 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005667 struct attr attr_new;
5668 struct attr_extra extra_new;
5669
paul718e3742002-12-13 20:15:29 +00005670 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005671 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005672 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005673
5674 if (bgp->redist_metric_flag[afi][type])
5675 attr_new.med = bgp->redist_metric[afi][type];
5676
5677 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005678 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005679 {
5680 info.peer = bgp->peer_self;
5681 info.attr = &attr_new;
5682
paulfee0f4c2004-09-13 05:12:46 +00005683 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5684
paul718e3742002-12-13 20:15:29 +00005685 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5686 &info);
paulfee0f4c2004-09-13 05:12:46 +00005687
5688 bgp->peer_self->rmap_type = 0;
5689
paul718e3742002-12-13 20:15:29 +00005690 if (ret == RMAP_DENYMATCH)
5691 {
5692 /* Free uninterned attribute. */
5693 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005694
paul718e3742002-12-13 20:15:29 +00005695 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005696 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005697 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005698 bgp_redistribute_delete (p, type);
5699 return;
5700 }
5701 }
5702
Paul Jakmafb982c22007-05-04 20:15:47 +00005703 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5704 afi, SAFI_UNICAST, p, NULL);
5705
paul718e3742002-12-13 20:15:29 +00005706 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005707
paul718e3742002-12-13 20:15:29 +00005708 for (bi = bn->info; bi; bi = bi->next)
5709 if (bi->peer == bgp->peer_self
5710 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5711 break;
5712
5713 if (bi)
5714 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005715 if (attrhash_cmp (bi->attr, new_attr) &&
5716 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005717 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005718 bgp_attr_unintern (&new_attr);
5719 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005720 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005721 bgp_unlock_node (bn);
5722 return;
5723 }
5724 else
5725 {
5726 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005727 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005728
5729 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005730 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5731 bgp_info_restore(bn, bi);
5732 else
5733 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005734 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005735 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005736 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005737
5738 /* Process change. */
5739 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5740 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5741 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005742 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005743 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005744 return;
5745 }
5746 }
5747
5748 new = bgp_info_new ();
5749 new->type = type;
5750 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5751 new->peer = bgp->peer_self;
5752 SET_FLAG (new->flags, BGP_INFO_VALID);
5753 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005754 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005755
5756 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5757 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005758 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005759 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5760 }
5761 }
5762
5763 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005764 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005765 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005766}
5767
5768void
5769bgp_redistribute_delete (struct prefix *p, u_char type)
5770{
5771 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005772 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005773 afi_t afi;
5774 struct bgp_node *rn;
5775 struct bgp_info *ri;
5776
paul1eb8ef22005-04-07 07:30:20 +00005777 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005778 {
5779 afi = family2afi (p->family);
5780
5781 if (bgp->redist[afi][type])
5782 {
paulfee0f4c2004-09-13 05:12:46 +00005783 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005784
5785 for (ri = rn->info; ri; ri = ri->next)
5786 if (ri->peer == bgp->peer_self
5787 && ri->type == type)
5788 break;
5789
5790 if (ri)
5791 {
5792 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005793 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005794 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005795 }
5796 bgp_unlock_node (rn);
5797 }
5798 }
5799}
5800
5801/* Withdraw specified route type's route. */
5802void
5803bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5804{
5805 struct bgp_node *rn;
5806 struct bgp_info *ri;
5807 struct bgp_table *table;
5808
5809 table = bgp->rib[afi][SAFI_UNICAST];
5810
5811 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5812 {
5813 for (ri = rn->info; ri; ri = ri->next)
5814 if (ri->peer == bgp->peer_self
5815 && ri->type == type)
5816 break;
5817
5818 if (ri)
5819 {
5820 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005821 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005822 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005823 }
5824 }
5825}
David Lamparter6b0655a2014-06-04 06:53:35 +02005826
paul718e3742002-12-13 20:15:29 +00005827/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005828static void
paul718e3742002-12-13 20:15:29 +00005829route_vty_out_route (struct prefix *p, struct vty *vty)
5830{
5831 int len;
5832 u_int32_t destination;
5833 char buf[BUFSIZ];
5834
5835 if (p->family == AF_INET)
5836 {
5837 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5838 destination = ntohl (p->u.prefix4.s_addr);
5839
5840 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5841 || (IN_CLASSB (destination) && p->prefixlen == 16)
5842 || (IN_CLASSA (destination) && p->prefixlen == 8)
5843 || p->u.prefix4.s_addr == 0)
5844 {
5845 /* When mask is natural, mask is not displayed. */
5846 }
5847 else
5848 len += vty_out (vty, "/%d", p->prefixlen);
5849 }
5850 else
5851 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5852 p->prefixlen);
5853
5854 len = 17 - len;
5855 if (len < 1)
5856 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5857 else
5858 vty_out (vty, "%*s", len, " ");
5859}
5860
paul718e3742002-12-13 20:15:29 +00005861enum bgp_display_type
5862{
5863 normal_list,
5864};
5865
paulb40d9392005-08-22 22:34:41 +00005866/* Print the short form route status for a bgp_info */
5867static void
5868route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005869{
paulb40d9392005-08-22 22:34:41 +00005870 /* Route status display. */
5871 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5872 vty_out (vty, "R");
5873 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005874 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005875 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005876 vty_out (vty, "s");
5877 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5878 vty_out (vty, "*");
5879 else
5880 vty_out (vty, " ");
5881
5882 /* Selected */
5883 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5884 vty_out (vty, "h");
5885 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5886 vty_out (vty, "d");
5887 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5888 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005889 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5890 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005891 else
5892 vty_out (vty, " ");
5893
5894 /* Internal route. */
5895 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5896 vty_out (vty, "i");
5897 else
paulb40d9392005-08-22 22:34:41 +00005898 vty_out (vty, " ");
5899}
5900
5901/* called from terminal list command */
5902void
5903route_vty_out (struct vty *vty, struct prefix *p,
5904 struct bgp_info *binfo, int display, safi_t safi)
5905{
5906 struct attr *attr;
5907
5908 /* short status lead text */
5909 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005910
5911 /* print prefix and mask */
5912 if (! display)
5913 route_vty_out_route (p, vty);
5914 else
5915 vty_out (vty, "%*s", 17, " ");
5916
5917 /* Print attribute */
5918 attr = binfo->attr;
5919 if (attr)
5920 {
5921 if (p->family == AF_INET)
5922 {
5923 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005924 vty_out (vty, "%-16s",
5925 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005926 else
5927 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5928 }
5929#ifdef HAVE_IPV6
5930 else if (p->family == AF_INET6)
5931 {
5932 int len;
5933 char buf[BUFSIZ];
5934
5935 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005936 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5937 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005938 len = 16 - len;
5939 if (len < 1)
5940 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5941 else
5942 vty_out (vty, "%*s", len, " ");
5943 }
5944#endif /* HAVE_IPV6 */
5945
5946 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005947 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005948 else
5949 vty_out (vty, " ");
5950
5951 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005952 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005953 else
5954 vty_out (vty, " ");
5955
Paul Jakmafb982c22007-05-04 20:15:47 +00005956 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005957
Paul Jakmab2518c12006-05-12 23:48:40 +00005958 /* Print aspath */
5959 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005960 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005961
Paul Jakmab2518c12006-05-12 23:48:40 +00005962 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005963 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005964 }
paul718e3742002-12-13 20:15:29 +00005965 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005966}
5967
5968/* called from terminal list command */
5969void
5970route_vty_out_tmp (struct vty *vty, struct prefix *p,
5971 struct attr *attr, safi_t safi)
5972{
5973 /* Route status display. */
5974 vty_out (vty, "*");
5975 vty_out (vty, ">");
5976 vty_out (vty, " ");
5977
5978 /* print prefix and mask */
5979 route_vty_out_route (p, vty);
5980
5981 /* Print attribute */
5982 if (attr)
5983 {
5984 if (p->family == AF_INET)
5985 {
5986 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005987 vty_out (vty, "%-16s",
5988 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005989 else
5990 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5991 }
5992#ifdef HAVE_IPV6
5993 else if (p->family == AF_INET6)
5994 {
5995 int len;
5996 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005997
5998 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005999
6000 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006001 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6002 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006003 len = 16 - len;
6004 if (len < 1)
6005 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6006 else
6007 vty_out (vty, "%*s", len, " ");
6008 }
6009#endif /* HAVE_IPV6 */
6010
6011 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006012 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00006013 else
6014 vty_out (vty, " ");
6015
6016 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006017 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006018 else
6019 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006020
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006021 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006022
Paul Jakmab2518c12006-05-12 23:48:40 +00006023 /* Print aspath */
6024 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006025 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006026
Paul Jakmab2518c12006-05-12 23:48:40 +00006027 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006028 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006029 }
paul718e3742002-12-13 20:15:29 +00006030
6031 vty_out (vty, "%s", VTY_NEWLINE);
6032}
6033
ajs5a646652004-11-05 01:25:55 +00006034void
paul718e3742002-12-13 20:15:29 +00006035route_vty_out_tag (struct vty *vty, struct prefix *p,
6036 struct bgp_info *binfo, int display, safi_t safi)
6037{
6038 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006039 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006040
6041 if (!binfo->extra)
6042 return;
6043
paulb40d9392005-08-22 22:34:41 +00006044 /* short status lead text */
6045 route_vty_short_status_out (vty, binfo);
6046
paul718e3742002-12-13 20:15:29 +00006047 /* print prefix and mask */
6048 if (! display)
6049 route_vty_out_route (p, vty);
6050 else
6051 vty_out (vty, "%*s", 17, " ");
6052
6053 /* Print attribute */
6054 attr = binfo->attr;
6055 if (attr)
6056 {
6057 if (p->family == AF_INET)
6058 {
6059 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00006060 vty_out (vty, "%-16s",
6061 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006062 else
6063 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6064 }
6065#ifdef HAVE_IPV6
6066 else if (p->family == AF_INET6)
6067 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006068 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006069 char buf[BUFSIZ];
6070 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006071 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006072 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006073 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6074 buf, BUFSIZ));
6075 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006076 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006077 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6078 buf, BUFSIZ),
6079 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6080 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006081
6082 }
6083#endif /* HAVE_IPV6 */
6084 }
6085
Paul Jakmafb982c22007-05-04 20:15:47 +00006086 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006087
6088 vty_out (vty, "notag/%d", label);
6089
6090 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006091}
6092
6093/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006094static void
paul718e3742002-12-13 20:15:29 +00006095damp_route_vty_out (struct vty *vty, struct prefix *p,
6096 struct bgp_info *binfo, int display, safi_t safi)
6097{
6098 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006099 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006100 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006101
paulb40d9392005-08-22 22:34:41 +00006102 /* short status lead text */
6103 route_vty_short_status_out (vty, binfo);
6104
paul718e3742002-12-13 20:15:29 +00006105 /* print prefix and mask */
6106 if (! display)
6107 route_vty_out_route (p, vty);
6108 else
6109 vty_out (vty, "%*s", 17, " ");
6110
6111 len = vty_out (vty, "%s", binfo->peer->host);
6112 len = 17 - len;
6113 if (len < 1)
6114 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6115 else
6116 vty_out (vty, "%*s", len, " ");
6117
Chris Caputo50aef6f2009-06-23 06:06:49 +00006118 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006119
6120 /* Print attribute */
6121 attr = binfo->attr;
6122 if (attr)
6123 {
6124 /* Print aspath */
6125 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006126 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006127
6128 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006129 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006130 }
6131 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006132}
6133
paul718e3742002-12-13 20:15:29 +00006134/* flap route */
ajs5a646652004-11-05 01:25:55 +00006135static void
paul718e3742002-12-13 20:15:29 +00006136flap_route_vty_out (struct vty *vty, struct prefix *p,
6137 struct bgp_info *binfo, int display, safi_t safi)
6138{
6139 struct attr *attr;
6140 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006141 char timebuf[BGP_UPTIME_LEN];
6142 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006143
6144 if (!binfo->extra)
6145 return;
6146
6147 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006148
paulb40d9392005-08-22 22:34:41 +00006149 /* short status lead text */
6150 route_vty_short_status_out (vty, binfo);
6151
paul718e3742002-12-13 20:15:29 +00006152 /* print prefix and mask */
6153 if (! display)
6154 route_vty_out_route (p, vty);
6155 else
6156 vty_out (vty, "%*s", 17, " ");
6157
6158 len = vty_out (vty, "%s", binfo->peer->host);
6159 len = 16 - len;
6160 if (len < 1)
6161 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6162 else
6163 vty_out (vty, "%*s", len, " ");
6164
6165 len = vty_out (vty, "%d", bdi->flap);
6166 len = 5 - len;
6167 if (len < 1)
6168 vty_out (vty, " ");
6169 else
6170 vty_out (vty, "%*s ", len, " ");
6171
6172 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6173 timebuf, BGP_UPTIME_LEN));
6174
6175 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6176 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006177 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006178 else
6179 vty_out (vty, "%*s ", 8, " ");
6180
6181 /* Print attribute */
6182 attr = binfo->attr;
6183 if (attr)
6184 {
6185 /* Print aspath */
6186 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006187 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006188
6189 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006190 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006191 }
6192 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006193}
6194
paul94f2b392005-06-28 12:44:16 +00006195static void
paul718e3742002-12-13 20:15:29 +00006196route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6197 struct bgp_info *binfo, afi_t afi, safi_t safi)
6198{
6199 char buf[INET6_ADDRSTRLEN];
6200 char buf1[BUFSIZ];
6201 struct attr *attr;
6202 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006203#ifdef HAVE_CLOCK_MONOTONIC
6204 time_t tbuf;
6205#endif
paul718e3742002-12-13 20:15:29 +00006206
6207 attr = binfo->attr;
6208
6209 if (attr)
6210 {
6211 /* Line1 display AS-path, Aggregator */
6212 if (attr->aspath)
6213 {
6214 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006215 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006216 vty_out (vty, "Local");
6217 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006218 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006219 }
6220
paulb40d9392005-08-22 22:34:41 +00006221 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6222 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006223 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6224 vty_out (vty, ", (stale)");
6225 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006226 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006227 attr->extra->aggregator_as,
6228 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006229 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6230 vty_out (vty, ", (Received from a RR-client)");
6231 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6232 vty_out (vty, ", (Received from a RS-client)");
6233 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6234 vty_out (vty, ", (history entry)");
6235 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6236 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006237 vty_out (vty, "%s", VTY_NEWLINE);
6238
6239 /* Line2 display Next-hop, Neighbor, Router-id */
6240 if (p->family == AF_INET)
6241 {
6242 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006243 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006244 inet_ntoa (attr->nexthop));
6245 }
6246#ifdef HAVE_IPV6
6247 else
6248 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006249 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006250 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006251 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006252 buf, INET6_ADDRSTRLEN));
6253 }
6254#endif /* HAVE_IPV6 */
6255
6256 if (binfo->peer == bgp->peer_self)
6257 {
6258 vty_out (vty, " from %s ",
6259 p->family == AF_INET ? "0.0.0.0" : "::");
6260 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6261 }
6262 else
6263 {
6264 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6265 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006266 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006267 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006268 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006269 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006270 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006271 else
6272 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6273 }
6274 vty_out (vty, "%s", VTY_NEWLINE);
6275
6276#ifdef HAVE_IPV6
6277 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006278 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006279 {
6280 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006281 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006282 buf, INET6_ADDRSTRLEN),
6283 VTY_NEWLINE);
6284 }
6285#endif /* HAVE_IPV6 */
6286
6287 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6288 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6289
6290 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006291 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006292
6293 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006294 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006295 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006296 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006297
Paul Jakmafb982c22007-05-04 20:15:47 +00006298 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006299 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006300
6301 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6302 vty_out (vty, ", valid");
6303
6304 if (binfo->peer != bgp->peer_self)
6305 {
6306 if (binfo->peer->as == binfo->peer->local_as)
6307 vty_out (vty, ", internal");
6308 else
6309 vty_out (vty, ", %s",
6310 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6311 }
6312 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6313 vty_out (vty, ", aggregated, local");
6314 else if (binfo->type != ZEBRA_ROUTE_BGP)
6315 vty_out (vty, ", sourced");
6316 else
6317 vty_out (vty, ", sourced, local");
6318
6319 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6320 vty_out (vty, ", atomic-aggregate");
6321
Josh Baileyde8d5df2011-07-20 20:46:01 -07006322 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6323 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6324 bgp_info_mpath_count (binfo)))
6325 vty_out (vty, ", multipath");
6326
paul718e3742002-12-13 20:15:29 +00006327 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6328 vty_out (vty, ", best");
6329
6330 vty_out (vty, "%s", VTY_NEWLINE);
6331
6332 /* Line 4 display Community */
6333 if (attr->community)
6334 vty_out (vty, " Community: %s%s", attr->community->str,
6335 VTY_NEWLINE);
6336
6337 /* Line 5 display Extended-community */
6338 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006339 vty_out (vty, " Extended Community: %s%s",
6340 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006341
6342 /* Line 6 display Originator, Cluster-id */
6343 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6344 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6345 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006346 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006347 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006348 vty_out (vty, " Originator: %s",
6349 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006350
6351 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6352 {
6353 int i;
6354 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006355 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6356 vty_out (vty, "%s ",
6357 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006358 }
6359 vty_out (vty, "%s", VTY_NEWLINE);
6360 }
Paul Jakma41367172007-08-06 15:24:51 +00006361
Paul Jakmafb982c22007-05-04 20:15:47 +00006362 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006363 bgp_damp_info_vty (vty, binfo);
6364
6365 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006366#ifdef HAVE_CLOCK_MONOTONIC
6367 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006368 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006369#else
6370 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6371#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006372 }
6373 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006374}
6375
6376#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6377 "h history, * valid, > best, = multipath,%s"\
6378 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006379#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006380#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6381#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6382#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6383
6384enum bgp_show_type
6385{
6386 bgp_show_type_normal,
6387 bgp_show_type_regexp,
6388 bgp_show_type_prefix_list,
6389 bgp_show_type_filter_list,
6390 bgp_show_type_route_map,
6391 bgp_show_type_neighbor,
6392 bgp_show_type_cidr_only,
6393 bgp_show_type_prefix_longer,
6394 bgp_show_type_community_all,
6395 bgp_show_type_community,
6396 bgp_show_type_community_exact,
6397 bgp_show_type_community_list,
6398 bgp_show_type_community_list_exact,
6399 bgp_show_type_flap_statistics,
6400 bgp_show_type_flap_address,
6401 bgp_show_type_flap_prefix,
6402 bgp_show_type_flap_cidr_only,
6403 bgp_show_type_flap_regexp,
6404 bgp_show_type_flap_filter_list,
6405 bgp_show_type_flap_prefix_list,
6406 bgp_show_type_flap_prefix_longer,
6407 bgp_show_type_flap_route_map,
6408 bgp_show_type_flap_neighbor,
6409 bgp_show_type_dampend_paths,
6410 bgp_show_type_damp_neighbor
6411};
6412
ajs5a646652004-11-05 01:25:55 +00006413static int
paulfee0f4c2004-09-13 05:12:46 +00006414bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006415 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006416{
paul718e3742002-12-13 20:15:29 +00006417 struct bgp_info *ri;
6418 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006419 int header = 1;
paul718e3742002-12-13 20:15:29 +00006420 int display;
ajs5a646652004-11-05 01:25:55 +00006421 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006422
6423 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006424 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006425
paul718e3742002-12-13 20:15:29 +00006426 /* Start processing of routes. */
6427 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6428 if (rn->info != NULL)
6429 {
6430 display = 0;
6431
6432 for (ri = rn->info; ri; ri = ri->next)
6433 {
ajs5a646652004-11-05 01:25:55 +00006434 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006435 || type == bgp_show_type_flap_address
6436 || type == bgp_show_type_flap_prefix
6437 || type == bgp_show_type_flap_cidr_only
6438 || type == bgp_show_type_flap_regexp
6439 || type == bgp_show_type_flap_filter_list
6440 || type == bgp_show_type_flap_prefix_list
6441 || type == bgp_show_type_flap_prefix_longer
6442 || type == bgp_show_type_flap_route_map
6443 || type == bgp_show_type_flap_neighbor
6444 || type == bgp_show_type_dampend_paths
6445 || type == bgp_show_type_damp_neighbor)
6446 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006447 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006448 continue;
6449 }
6450 if (type == bgp_show_type_regexp
6451 || type == bgp_show_type_flap_regexp)
6452 {
ajs5a646652004-11-05 01:25:55 +00006453 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006454
6455 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6456 continue;
6457 }
6458 if (type == bgp_show_type_prefix_list
6459 || type == bgp_show_type_flap_prefix_list)
6460 {
ajs5a646652004-11-05 01:25:55 +00006461 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006462
6463 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6464 continue;
6465 }
6466 if (type == bgp_show_type_filter_list
6467 || type == bgp_show_type_flap_filter_list)
6468 {
ajs5a646652004-11-05 01:25:55 +00006469 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006470
6471 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6472 continue;
6473 }
6474 if (type == bgp_show_type_route_map
6475 || type == bgp_show_type_flap_route_map)
6476 {
ajs5a646652004-11-05 01:25:55 +00006477 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006478 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006479 struct attr dummy_attr;
6480 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006481 int ret;
6482
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006483 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006484 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006485
paul718e3742002-12-13 20:15:29 +00006486 binfo.peer = ri->peer;
6487 binfo.attr = &dummy_attr;
6488
6489 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006490 if (ret == RMAP_DENYMATCH)
6491 continue;
6492 }
6493 if (type == bgp_show_type_neighbor
6494 || type == bgp_show_type_flap_neighbor
6495 || type == bgp_show_type_damp_neighbor)
6496 {
ajs5a646652004-11-05 01:25:55 +00006497 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006498
6499 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6500 continue;
6501 }
6502 if (type == bgp_show_type_cidr_only
6503 || type == bgp_show_type_flap_cidr_only)
6504 {
6505 u_int32_t destination;
6506
6507 destination = ntohl (rn->p.u.prefix4.s_addr);
6508 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6509 continue;
6510 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6511 continue;
6512 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6513 continue;
6514 }
6515 if (type == bgp_show_type_prefix_longer
6516 || type == bgp_show_type_flap_prefix_longer)
6517 {
ajs5a646652004-11-05 01:25:55 +00006518 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006519
6520 if (! prefix_match (p, &rn->p))
6521 continue;
6522 }
6523 if (type == bgp_show_type_community_all)
6524 {
6525 if (! ri->attr->community)
6526 continue;
6527 }
6528 if (type == bgp_show_type_community)
6529 {
ajs5a646652004-11-05 01:25:55 +00006530 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006531
6532 if (! ri->attr->community ||
6533 ! community_match (ri->attr->community, com))
6534 continue;
6535 }
6536 if (type == bgp_show_type_community_exact)
6537 {
ajs5a646652004-11-05 01:25:55 +00006538 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006539
6540 if (! ri->attr->community ||
6541 ! community_cmp (ri->attr->community, com))
6542 continue;
6543 }
6544 if (type == bgp_show_type_community_list)
6545 {
ajs5a646652004-11-05 01:25:55 +00006546 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006547
6548 if (! community_list_match (ri->attr->community, list))
6549 continue;
6550 }
6551 if (type == bgp_show_type_community_list_exact)
6552 {
ajs5a646652004-11-05 01:25:55 +00006553 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006554
6555 if (! community_list_exact_match (ri->attr->community, list))
6556 continue;
6557 }
6558 if (type == bgp_show_type_flap_address
6559 || type == bgp_show_type_flap_prefix)
6560 {
ajs5a646652004-11-05 01:25:55 +00006561 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006562
6563 if (! prefix_match (&rn->p, p))
6564 continue;
6565
6566 if (type == bgp_show_type_flap_prefix)
6567 if (p->prefixlen != rn->p.prefixlen)
6568 continue;
6569 }
6570 if (type == bgp_show_type_dampend_paths
6571 || type == bgp_show_type_damp_neighbor)
6572 {
6573 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6574 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6575 continue;
6576 }
6577
6578 if (header)
6579 {
hasso93406d82005-02-02 14:40:33 +00006580 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6581 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6582 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006583 if (type == bgp_show_type_dampend_paths
6584 || type == bgp_show_type_damp_neighbor)
6585 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6586 else if (type == bgp_show_type_flap_statistics
6587 || type == bgp_show_type_flap_address
6588 || type == bgp_show_type_flap_prefix
6589 || type == bgp_show_type_flap_cidr_only
6590 || type == bgp_show_type_flap_regexp
6591 || type == bgp_show_type_flap_filter_list
6592 || type == bgp_show_type_flap_prefix_list
6593 || type == bgp_show_type_flap_prefix_longer
6594 || type == bgp_show_type_flap_route_map
6595 || type == bgp_show_type_flap_neighbor)
6596 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6597 else
6598 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006599 header = 0;
6600 }
6601
6602 if (type == bgp_show_type_dampend_paths
6603 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006604 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006605 else if (type == bgp_show_type_flap_statistics
6606 || type == bgp_show_type_flap_address
6607 || type == bgp_show_type_flap_prefix
6608 || type == bgp_show_type_flap_cidr_only
6609 || type == bgp_show_type_flap_regexp
6610 || type == bgp_show_type_flap_filter_list
6611 || type == bgp_show_type_flap_prefix_list
6612 || type == bgp_show_type_flap_prefix_longer
6613 || type == bgp_show_type_flap_route_map
6614 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006615 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006616 else
ajs5a646652004-11-05 01:25:55 +00006617 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006618 display++;
6619 }
6620 if (display)
ajs5a646652004-11-05 01:25:55 +00006621 output_count++;
paul718e3742002-12-13 20:15:29 +00006622 }
6623
6624 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006625 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006626 {
6627 if (type == bgp_show_type_normal)
6628 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6629 }
6630 else
6631 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006632 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006633
6634 return CMD_SUCCESS;
6635}
6636
ajs5a646652004-11-05 01:25:55 +00006637static int
paulfee0f4c2004-09-13 05:12:46 +00006638bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006639 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006640{
6641 struct bgp_table *table;
6642
6643 if (bgp == NULL) {
6644 bgp = bgp_get_default ();
6645 }
6646
6647 if (bgp == NULL)
6648 {
6649 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6650 return CMD_WARNING;
6651 }
6652
6653
6654 table = bgp->rib[afi][safi];
6655
ajs5a646652004-11-05 01:25:55 +00006656 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006657}
6658
paul718e3742002-12-13 20:15:29 +00006659/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006660static void
paul718e3742002-12-13 20:15:29 +00006661route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6662 struct bgp_node *rn,
6663 struct prefix_rd *prd, afi_t afi, safi_t safi)
6664{
6665 struct bgp_info *ri;
6666 struct prefix *p;
6667 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006668 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006669 char buf1[INET6_ADDRSTRLEN];
6670 char buf2[INET6_ADDRSTRLEN];
6671 int count = 0;
6672 int best = 0;
6673 int suppress = 0;
6674 int no_export = 0;
6675 int no_advertise = 0;
6676 int local_as = 0;
6677 int first = 0;
6678
6679 p = &rn->p;
6680 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6681 (safi == SAFI_MPLS_VPN ?
6682 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6683 safi == SAFI_MPLS_VPN ? ":" : "",
6684 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6685 p->prefixlen, VTY_NEWLINE);
6686
6687 for (ri = rn->info; ri; ri = ri->next)
6688 {
6689 count++;
6690 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6691 {
6692 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006693 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006694 suppress = 1;
6695 if (ri->attr->community != NULL)
6696 {
6697 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6698 no_advertise = 1;
6699 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6700 no_export = 1;
6701 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6702 local_as = 1;
6703 }
6704 }
6705 }
6706
6707 vty_out (vty, "Paths: (%d available", count);
6708 if (best)
6709 {
6710 vty_out (vty, ", best #%d", best);
6711 if (safi == SAFI_UNICAST)
6712 vty_out (vty, ", table Default-IP-Routing-Table");
6713 }
6714 else
6715 vty_out (vty, ", no best path");
6716 if (no_advertise)
6717 vty_out (vty, ", not advertised to any peer");
6718 else if (no_export)
6719 vty_out (vty, ", not advertised to EBGP peer");
6720 else if (local_as)
6721 vty_out (vty, ", not advertised outside local AS");
6722 if (suppress)
6723 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6724 vty_out (vty, ")%s", VTY_NEWLINE);
6725
6726 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006727 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006728 {
6729 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6730 {
6731 if (! first)
6732 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6733 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6734 first = 1;
6735 }
6736 }
6737 if (! first)
6738 vty_out (vty, " Not advertised to any peer");
6739 vty_out (vty, "%s", VTY_NEWLINE);
6740}
6741
6742/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006743static int
paulfee0f4c2004-09-13 05:12:46 +00006744bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006745 struct bgp_table *rib, const char *ip_str,
6746 afi_t afi, safi_t safi, struct prefix_rd *prd,
6747 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006748{
6749 int ret;
6750 int header;
6751 int display = 0;
6752 struct prefix match;
6753 struct bgp_node *rn;
6754 struct bgp_node *rm;
6755 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006756 struct bgp_table *table;
6757
Lou Berger050defe2016-01-12 13:41:59 -05006758 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006759 /* Check IP address argument. */
6760 ret = str2prefix (ip_str, &match);
6761 if (! ret)
6762 {
6763 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6764 return CMD_WARNING;
6765 }
6766
6767 match.family = afi2family (afi);
6768
6769 if (safi == SAFI_MPLS_VPN)
6770 {
paulfee0f4c2004-09-13 05:12:46 +00006771 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006772 {
6773 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6774 continue;
6775
6776 if ((table = rn->info) != NULL)
6777 {
6778 header = 1;
6779
6780 if ((rm = bgp_node_match (table, &match)) != NULL)
6781 {
6782 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006783 {
6784 bgp_unlock_node (rm);
6785 continue;
6786 }
paul718e3742002-12-13 20:15:29 +00006787
6788 for (ri = rm->info; ri; ri = ri->next)
6789 {
6790 if (header)
6791 {
6792 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6793 AFI_IP, SAFI_MPLS_VPN);
6794
6795 header = 0;
6796 }
6797 display++;
6798 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6799 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006800
6801 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006802 }
6803 }
6804 }
6805 }
6806 else
6807 {
6808 header = 1;
6809
paulfee0f4c2004-09-13 05:12:46 +00006810 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006811 {
6812 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6813 {
6814 for (ri = rn->info; ri; ri = ri->next)
6815 {
6816 if (header)
6817 {
6818 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6819 header = 0;
6820 }
6821 display++;
6822 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6823 }
6824 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006825
6826 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006827 }
6828 }
6829
6830 if (! display)
6831 {
6832 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6833 return CMD_WARNING;
6834 }
6835
6836 return CMD_SUCCESS;
6837}
6838
paulfee0f4c2004-09-13 05:12:46 +00006839/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006840static int
paulfd79ac92004-10-13 05:06:08 +00006841bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006842 afi_t afi, safi_t safi, struct prefix_rd *prd,
6843 int prefix_check)
6844{
6845 struct bgp *bgp;
6846
6847 /* BGP structure lookup. */
6848 if (view_name)
6849 {
6850 bgp = bgp_lookup_by_name (view_name);
6851 if (bgp == NULL)
6852 {
6853 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6854 return CMD_WARNING;
6855 }
6856 }
6857 else
6858 {
6859 bgp = bgp_get_default ();
6860 if (bgp == NULL)
6861 {
6862 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6863 return CMD_WARNING;
6864 }
6865 }
6866
6867 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6868 afi, safi, prd, prefix_check);
6869}
6870
paul718e3742002-12-13 20:15:29 +00006871/* BGP route print out function. */
6872DEFUN (show_ip_bgp,
6873 show_ip_bgp_cmd,
6874 "show ip bgp",
6875 SHOW_STR
6876 IP_STR
6877 BGP_STR)
6878{
ajs5a646652004-11-05 01:25:55 +00006879 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006880}
6881
6882DEFUN (show_ip_bgp_ipv4,
6883 show_ip_bgp_ipv4_cmd,
6884 "show ip bgp ipv4 (unicast|multicast)",
6885 SHOW_STR
6886 IP_STR
6887 BGP_STR
6888 "Address family\n"
6889 "Address Family modifier\n"
6890 "Address Family modifier\n")
6891{
6892 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006893 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6894 NULL);
paul718e3742002-12-13 20:15:29 +00006895
ajs5a646652004-11-05 01:25:55 +00006896 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006897}
6898
Michael Lambert95cbbd22010-07-23 14:43:04 -04006899ALIAS (show_ip_bgp_ipv4,
6900 show_bgp_ipv4_safi_cmd,
6901 "show bgp ipv4 (unicast|multicast)",
6902 SHOW_STR
6903 BGP_STR
6904 "Address family\n"
6905 "Address Family modifier\n"
6906 "Address Family modifier\n")
6907
paul718e3742002-12-13 20:15:29 +00006908DEFUN (show_ip_bgp_route,
6909 show_ip_bgp_route_cmd,
6910 "show ip bgp A.B.C.D",
6911 SHOW_STR
6912 IP_STR
6913 BGP_STR
6914 "Network in the BGP routing table to display\n")
6915{
6916 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6917}
6918
6919DEFUN (show_ip_bgp_ipv4_route,
6920 show_ip_bgp_ipv4_route_cmd,
6921 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6922 SHOW_STR
6923 IP_STR
6924 BGP_STR
6925 "Address family\n"
6926 "Address Family modifier\n"
6927 "Address Family modifier\n"
6928 "Network in the BGP routing table to display\n")
6929{
6930 if (strncmp (argv[0], "m", 1) == 0)
6931 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6932
6933 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6934}
6935
Michael Lambert95cbbd22010-07-23 14:43:04 -04006936ALIAS (show_ip_bgp_ipv4_route,
6937 show_bgp_ipv4_safi_route_cmd,
6938 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6939 SHOW_STR
6940 BGP_STR
6941 "Address family\n"
6942 "Address Family modifier\n"
6943 "Address Family modifier\n"
6944 "Network in the BGP routing table to display\n")
6945
paul718e3742002-12-13 20:15:29 +00006946DEFUN (show_ip_bgp_vpnv4_all_route,
6947 show_ip_bgp_vpnv4_all_route_cmd,
6948 "show ip bgp vpnv4 all A.B.C.D",
6949 SHOW_STR
6950 IP_STR
6951 BGP_STR
6952 "Display VPNv4 NLRI specific information\n"
6953 "Display information about all VPNv4 NLRIs\n"
6954 "Network in the BGP routing table to display\n")
6955{
6956 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6957}
6958
6959DEFUN (show_ip_bgp_vpnv4_rd_route,
6960 show_ip_bgp_vpnv4_rd_route_cmd,
6961 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6962 SHOW_STR
6963 IP_STR
6964 BGP_STR
6965 "Display VPNv4 NLRI specific information\n"
6966 "Display information for a route distinguisher\n"
6967 "VPN Route Distinguisher\n"
6968 "Network in the BGP routing table to display\n")
6969{
6970 int ret;
6971 struct prefix_rd prd;
6972
6973 ret = str2prefix_rd (argv[0], &prd);
6974 if (! ret)
6975 {
6976 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6977 return CMD_WARNING;
6978 }
6979 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6980}
6981
6982DEFUN (show_ip_bgp_prefix,
6983 show_ip_bgp_prefix_cmd,
6984 "show ip bgp A.B.C.D/M",
6985 SHOW_STR
6986 IP_STR
6987 BGP_STR
6988 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6989{
6990 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6991}
6992
6993DEFUN (show_ip_bgp_ipv4_prefix,
6994 show_ip_bgp_ipv4_prefix_cmd,
6995 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6996 SHOW_STR
6997 IP_STR
6998 BGP_STR
6999 "Address family\n"
7000 "Address Family modifier\n"
7001 "Address Family modifier\n"
7002 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7003{
7004 if (strncmp (argv[0], "m", 1) == 0)
7005 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
7006
7007 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7008}
7009
Michael Lambert95cbbd22010-07-23 14:43:04 -04007010ALIAS (show_ip_bgp_ipv4_prefix,
7011 show_bgp_ipv4_safi_prefix_cmd,
7012 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
7013 SHOW_STR
7014 BGP_STR
7015 "Address family\n"
7016 "Address Family modifier\n"
7017 "Address Family modifier\n"
7018 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7019
paul718e3742002-12-13 20:15:29 +00007020DEFUN (show_ip_bgp_vpnv4_all_prefix,
7021 show_ip_bgp_vpnv4_all_prefix_cmd,
7022 "show ip bgp vpnv4 all A.B.C.D/M",
7023 SHOW_STR
7024 IP_STR
7025 BGP_STR
7026 "Display VPNv4 NLRI specific information\n"
7027 "Display information about all VPNv4 NLRIs\n"
7028 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7029{
7030 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
7031}
7032
7033DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7034 show_ip_bgp_vpnv4_rd_prefix_cmd,
7035 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7036 SHOW_STR
7037 IP_STR
7038 BGP_STR
7039 "Display VPNv4 NLRI specific information\n"
7040 "Display information for a route distinguisher\n"
7041 "VPN Route Distinguisher\n"
7042 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7043{
7044 int ret;
7045 struct prefix_rd prd;
7046
7047 ret = str2prefix_rd (argv[0], &prd);
7048 if (! ret)
7049 {
7050 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7051 return CMD_WARNING;
7052 }
7053 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
7054}
7055
7056DEFUN (show_ip_bgp_view,
7057 show_ip_bgp_view_cmd,
7058 "show ip bgp view WORD",
7059 SHOW_STR
7060 IP_STR
7061 BGP_STR
7062 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007063 "View name\n")
paul718e3742002-12-13 20:15:29 +00007064{
paulbb46e942003-10-24 19:02:03 +00007065 struct bgp *bgp;
7066
7067 /* BGP structure lookup. */
7068 bgp = bgp_lookup_by_name (argv[0]);
7069 if (bgp == NULL)
7070 {
7071 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7072 return CMD_WARNING;
7073 }
7074
ajs5a646652004-11-05 01:25:55 +00007075 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007076}
7077
7078DEFUN (show_ip_bgp_view_route,
7079 show_ip_bgp_view_route_cmd,
7080 "show ip bgp view WORD A.B.C.D",
7081 SHOW_STR
7082 IP_STR
7083 BGP_STR
7084 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007085 "View name\n"
paul718e3742002-12-13 20:15:29 +00007086 "Network in the BGP routing table to display\n")
7087{
7088 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7089}
7090
7091DEFUN (show_ip_bgp_view_prefix,
7092 show_ip_bgp_view_prefix_cmd,
7093 "show ip bgp view WORD A.B.C.D/M",
7094 SHOW_STR
7095 IP_STR
7096 BGP_STR
7097 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007098 "View name\n"
paul718e3742002-12-13 20:15:29 +00007099 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7100{
7101 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7102}
7103
7104#ifdef HAVE_IPV6
7105DEFUN (show_bgp,
7106 show_bgp_cmd,
7107 "show bgp",
7108 SHOW_STR
7109 BGP_STR)
7110{
ajs5a646652004-11-05 01:25:55 +00007111 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7112 NULL);
paul718e3742002-12-13 20:15:29 +00007113}
7114
7115ALIAS (show_bgp,
7116 show_bgp_ipv6_cmd,
7117 "show bgp ipv6",
7118 SHOW_STR
7119 BGP_STR
7120 "Address family\n")
7121
Michael Lambert95cbbd22010-07-23 14:43:04 -04007122DEFUN (show_bgp_ipv6_safi,
7123 show_bgp_ipv6_safi_cmd,
7124 "show bgp ipv6 (unicast|multicast)",
7125 SHOW_STR
7126 BGP_STR
7127 "Address family\n"
7128 "Address Family modifier\n"
7129 "Address Family modifier\n")
7130{
7131 if (strncmp (argv[0], "m", 1) == 0)
7132 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7133 NULL);
7134
7135 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7136}
7137
paul718e3742002-12-13 20:15:29 +00007138/* old command */
7139DEFUN (show_ipv6_bgp,
7140 show_ipv6_bgp_cmd,
7141 "show ipv6 bgp",
7142 SHOW_STR
7143 IP_STR
7144 BGP_STR)
7145{
ajs5a646652004-11-05 01:25:55 +00007146 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7147 NULL);
paul718e3742002-12-13 20:15:29 +00007148}
7149
7150DEFUN (show_bgp_route,
7151 show_bgp_route_cmd,
7152 "show bgp X:X::X:X",
7153 SHOW_STR
7154 BGP_STR
7155 "Network in the BGP routing table to display\n")
7156{
7157 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7158}
7159
7160ALIAS (show_bgp_route,
7161 show_bgp_ipv6_route_cmd,
7162 "show bgp ipv6 X:X::X:X",
7163 SHOW_STR
7164 BGP_STR
7165 "Address family\n"
7166 "Network in the BGP routing table to display\n")
7167
Michael Lambert95cbbd22010-07-23 14:43:04 -04007168DEFUN (show_bgp_ipv6_safi_route,
7169 show_bgp_ipv6_safi_route_cmd,
7170 "show bgp ipv6 (unicast|multicast) X:X::X:X",
7171 SHOW_STR
7172 BGP_STR
7173 "Address family\n"
7174 "Address Family modifier\n"
7175 "Address Family modifier\n"
7176 "Network in the BGP routing table to display\n")
7177{
7178 if (strncmp (argv[0], "m", 1) == 0)
7179 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7180
7181 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7182}
7183
paul718e3742002-12-13 20:15:29 +00007184/* old command */
7185DEFUN (show_ipv6_bgp_route,
7186 show_ipv6_bgp_route_cmd,
7187 "show ipv6 bgp X:X::X:X",
7188 SHOW_STR
7189 IP_STR
7190 BGP_STR
7191 "Network in the BGP routing table to display\n")
7192{
7193 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7194}
7195
7196DEFUN (show_bgp_prefix,
7197 show_bgp_prefix_cmd,
7198 "show bgp X:X::X:X/M",
7199 SHOW_STR
7200 BGP_STR
7201 "IPv6 prefix <network>/<length>\n")
7202{
7203 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7204}
7205
7206ALIAS (show_bgp_prefix,
7207 show_bgp_ipv6_prefix_cmd,
7208 "show bgp ipv6 X:X::X:X/M",
7209 SHOW_STR
7210 BGP_STR
7211 "Address family\n"
7212 "IPv6 prefix <network>/<length>\n")
7213
Michael Lambert95cbbd22010-07-23 14:43:04 -04007214DEFUN (show_bgp_ipv6_safi_prefix,
7215 show_bgp_ipv6_safi_prefix_cmd,
7216 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7217 SHOW_STR
7218 BGP_STR
7219 "Address family\n"
7220 "Address Family modifier\n"
7221 "Address Family modifier\n"
7222 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7223{
7224 if (strncmp (argv[0], "m", 1) == 0)
7225 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7226
7227 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7228}
7229
paul718e3742002-12-13 20:15:29 +00007230/* old command */
7231DEFUN (show_ipv6_bgp_prefix,
7232 show_ipv6_bgp_prefix_cmd,
7233 "show ipv6 bgp X:X::X:X/M",
7234 SHOW_STR
7235 IP_STR
7236 BGP_STR
7237 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7238{
7239 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7240}
7241
paulbb46e942003-10-24 19:02:03 +00007242DEFUN (show_bgp_view,
7243 show_bgp_view_cmd,
7244 "show bgp view WORD",
7245 SHOW_STR
7246 BGP_STR
7247 "BGP view\n"
7248 "View name\n")
7249{
7250 struct bgp *bgp;
7251
7252 /* BGP structure lookup. */
7253 bgp = bgp_lookup_by_name (argv[0]);
7254 if (bgp == NULL)
7255 {
7256 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7257 return CMD_WARNING;
7258 }
7259
ajs5a646652004-11-05 01:25:55 +00007260 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007261}
7262
7263ALIAS (show_bgp_view,
7264 show_bgp_view_ipv6_cmd,
7265 "show bgp view WORD ipv6",
7266 SHOW_STR
7267 BGP_STR
7268 "BGP view\n"
7269 "View name\n"
7270 "Address family\n")
7271
7272DEFUN (show_bgp_view_route,
7273 show_bgp_view_route_cmd,
7274 "show bgp view WORD X:X::X:X",
7275 SHOW_STR
7276 BGP_STR
7277 "BGP view\n"
7278 "View name\n"
7279 "Network in the BGP routing table to display\n")
7280{
7281 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7282}
7283
7284ALIAS (show_bgp_view_route,
7285 show_bgp_view_ipv6_route_cmd,
7286 "show bgp view WORD ipv6 X:X::X:X",
7287 SHOW_STR
7288 BGP_STR
7289 "BGP view\n"
7290 "View name\n"
7291 "Address family\n"
7292 "Network in the BGP routing table to display\n")
7293
7294DEFUN (show_bgp_view_prefix,
7295 show_bgp_view_prefix_cmd,
7296 "show bgp view WORD X:X::X:X/M",
7297 SHOW_STR
7298 BGP_STR
7299 "BGP view\n"
7300 "View name\n"
7301 "IPv6 prefix <network>/<length>\n")
7302{
7303 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7304}
7305
7306ALIAS (show_bgp_view_prefix,
7307 show_bgp_view_ipv6_prefix_cmd,
7308 "show bgp view WORD ipv6 X:X::X:X/M",
7309 SHOW_STR
7310 BGP_STR
7311 "BGP view\n"
7312 "View name\n"
7313 "Address family\n"
7314 "IPv6 prefix <network>/<length>\n")
7315
paul718e3742002-12-13 20:15:29 +00007316/* old command */
7317DEFUN (show_ipv6_mbgp,
7318 show_ipv6_mbgp_cmd,
7319 "show ipv6 mbgp",
7320 SHOW_STR
7321 IP_STR
7322 MBGP_STR)
7323{
ajs5a646652004-11-05 01:25:55 +00007324 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7325 NULL);
paul718e3742002-12-13 20:15:29 +00007326}
7327
7328/* old command */
7329DEFUN (show_ipv6_mbgp_route,
7330 show_ipv6_mbgp_route_cmd,
7331 "show ipv6 mbgp X:X::X:X",
7332 SHOW_STR
7333 IP_STR
7334 MBGP_STR
7335 "Network in the MBGP routing table to display\n")
7336{
7337 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7338}
7339
7340/* old command */
7341DEFUN (show_ipv6_mbgp_prefix,
7342 show_ipv6_mbgp_prefix_cmd,
7343 "show ipv6 mbgp X:X::X:X/M",
7344 SHOW_STR
7345 IP_STR
7346 MBGP_STR
7347 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7348{
7349 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7350}
7351#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007352
paul718e3742002-12-13 20:15:29 +00007353
paul94f2b392005-06-28 12:44:16 +00007354static int
paulfd79ac92004-10-13 05:06:08 +00007355bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007356 safi_t safi, enum bgp_show_type type)
7357{
7358 int i;
7359 struct buffer *b;
7360 char *regstr;
7361 int first;
7362 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007363 int rc;
paul718e3742002-12-13 20:15:29 +00007364
7365 first = 0;
7366 b = buffer_new (1024);
7367 for (i = 0; i < argc; i++)
7368 {
7369 if (first)
7370 buffer_putc (b, ' ');
7371 else
7372 {
7373 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7374 continue;
7375 first = 1;
7376 }
7377
7378 buffer_putstr (b, argv[i]);
7379 }
7380 buffer_putc (b, '\0');
7381
7382 regstr = buffer_getstr (b);
7383 buffer_free (b);
7384
7385 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007386 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007387 if (! regex)
7388 {
7389 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7390 VTY_NEWLINE);
7391 return CMD_WARNING;
7392 }
7393
ajs5a646652004-11-05 01:25:55 +00007394 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7395 bgp_regex_free (regex);
7396 return rc;
paul718e3742002-12-13 20:15:29 +00007397}
7398
7399DEFUN (show_ip_bgp_regexp,
7400 show_ip_bgp_regexp_cmd,
7401 "show ip bgp regexp .LINE",
7402 SHOW_STR
7403 IP_STR
7404 BGP_STR
7405 "Display routes matching the AS path regular expression\n"
7406 "A regular-expression to match the BGP AS paths\n")
7407{
7408 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7409 bgp_show_type_regexp);
7410}
7411
7412DEFUN (show_ip_bgp_flap_regexp,
7413 show_ip_bgp_flap_regexp_cmd,
7414 "show ip bgp flap-statistics regexp .LINE",
7415 SHOW_STR
7416 IP_STR
7417 BGP_STR
7418 "Display flap statistics of routes\n"
7419 "Display routes matching the AS path regular expression\n"
7420 "A regular-expression to match the BGP AS paths\n")
7421{
7422 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7423 bgp_show_type_flap_regexp);
7424}
7425
Balaji3921cc52015-05-16 23:12:17 +05307426ALIAS (show_ip_bgp_flap_regexp,
7427 show_ip_bgp_damp_flap_regexp_cmd,
7428 "show ip bgp dampening flap-statistics regexp .LINE",
7429 SHOW_STR
7430 IP_STR
7431 BGP_STR
7432 "Display detailed information about dampening\n"
7433 "Display flap statistics of routes\n"
7434 "Display routes matching the AS path regular expression\n"
7435 "A regular-expression to match the BGP AS paths\n")
7436
paul718e3742002-12-13 20:15:29 +00007437DEFUN (show_ip_bgp_ipv4_regexp,
7438 show_ip_bgp_ipv4_regexp_cmd,
7439 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7440 SHOW_STR
7441 IP_STR
7442 BGP_STR
7443 "Address family\n"
7444 "Address Family modifier\n"
7445 "Address Family modifier\n"
7446 "Display routes matching the AS path regular expression\n"
7447 "A regular-expression to match the BGP AS paths\n")
7448{
7449 if (strncmp (argv[0], "m", 1) == 0)
7450 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7451 bgp_show_type_regexp);
7452
7453 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7454 bgp_show_type_regexp);
7455}
7456
7457#ifdef HAVE_IPV6
7458DEFUN (show_bgp_regexp,
7459 show_bgp_regexp_cmd,
7460 "show bgp regexp .LINE",
7461 SHOW_STR
7462 BGP_STR
7463 "Display routes matching the AS path regular expression\n"
7464 "A regular-expression to match the BGP AS paths\n")
7465{
7466 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7467 bgp_show_type_regexp);
7468}
7469
7470ALIAS (show_bgp_regexp,
7471 show_bgp_ipv6_regexp_cmd,
7472 "show bgp ipv6 regexp .LINE",
7473 SHOW_STR
7474 BGP_STR
7475 "Address family\n"
7476 "Display routes matching the AS path regular expression\n"
7477 "A regular-expression to match the BGP AS paths\n")
7478
7479/* old command */
7480DEFUN (show_ipv6_bgp_regexp,
7481 show_ipv6_bgp_regexp_cmd,
7482 "show ipv6 bgp regexp .LINE",
7483 SHOW_STR
7484 IP_STR
7485 BGP_STR
7486 "Display routes matching the AS path regular expression\n"
7487 "A regular-expression to match the BGP AS paths\n")
7488{
7489 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7490 bgp_show_type_regexp);
7491}
7492
7493/* old command */
7494DEFUN (show_ipv6_mbgp_regexp,
7495 show_ipv6_mbgp_regexp_cmd,
7496 "show ipv6 mbgp regexp .LINE",
7497 SHOW_STR
7498 IP_STR
7499 BGP_STR
7500 "Display routes matching the AS path regular expression\n"
7501 "A regular-expression to match the MBGP AS paths\n")
7502{
7503 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7504 bgp_show_type_regexp);
7505}
7506#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007507
paul94f2b392005-06-28 12:44:16 +00007508static int
paulfd79ac92004-10-13 05:06:08 +00007509bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007510 safi_t safi, enum bgp_show_type type)
7511{
7512 struct prefix_list *plist;
7513
7514 plist = prefix_list_lookup (afi, prefix_list_str);
7515 if (plist == NULL)
7516 {
7517 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7518 prefix_list_str, VTY_NEWLINE);
7519 return CMD_WARNING;
7520 }
7521
ajs5a646652004-11-05 01:25:55 +00007522 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007523}
7524
7525DEFUN (show_ip_bgp_prefix_list,
7526 show_ip_bgp_prefix_list_cmd,
7527 "show ip bgp prefix-list WORD",
7528 SHOW_STR
7529 IP_STR
7530 BGP_STR
7531 "Display routes conforming to the prefix-list\n"
7532 "IP prefix-list name\n")
7533{
7534 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7535 bgp_show_type_prefix_list);
7536}
7537
7538DEFUN (show_ip_bgp_flap_prefix_list,
7539 show_ip_bgp_flap_prefix_list_cmd,
7540 "show ip bgp flap-statistics prefix-list WORD",
7541 SHOW_STR
7542 IP_STR
7543 BGP_STR
7544 "Display flap statistics of routes\n"
7545 "Display routes conforming to the prefix-list\n"
7546 "IP prefix-list name\n")
7547{
7548 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7549 bgp_show_type_flap_prefix_list);
7550}
7551
Balaji3921cc52015-05-16 23:12:17 +05307552ALIAS (show_ip_bgp_flap_prefix_list,
7553 show_ip_bgp_damp_flap_prefix_list_cmd,
7554 "show ip bgp dampening flap-statistics prefix-list WORD",
7555 SHOW_STR
7556 IP_STR
7557 BGP_STR
7558 "Display detailed information about dampening\n"
7559 "Display flap statistics of routes\n"
7560 "Display routes conforming to the prefix-list\n"
7561 "IP prefix-list name\n")
7562
paul718e3742002-12-13 20:15:29 +00007563DEFUN (show_ip_bgp_ipv4_prefix_list,
7564 show_ip_bgp_ipv4_prefix_list_cmd,
7565 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7566 SHOW_STR
7567 IP_STR
7568 BGP_STR
7569 "Address family\n"
7570 "Address Family modifier\n"
7571 "Address Family modifier\n"
7572 "Display routes conforming to the prefix-list\n"
7573 "IP prefix-list name\n")
7574{
7575 if (strncmp (argv[0], "m", 1) == 0)
7576 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7577 bgp_show_type_prefix_list);
7578
7579 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7580 bgp_show_type_prefix_list);
7581}
7582
7583#ifdef HAVE_IPV6
7584DEFUN (show_bgp_prefix_list,
7585 show_bgp_prefix_list_cmd,
7586 "show bgp prefix-list WORD",
7587 SHOW_STR
7588 BGP_STR
7589 "Display routes conforming to the prefix-list\n"
7590 "IPv6 prefix-list name\n")
7591{
7592 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7593 bgp_show_type_prefix_list);
7594}
7595
7596ALIAS (show_bgp_prefix_list,
7597 show_bgp_ipv6_prefix_list_cmd,
7598 "show bgp ipv6 prefix-list WORD",
7599 SHOW_STR
7600 BGP_STR
7601 "Address family\n"
7602 "Display routes conforming to the prefix-list\n"
7603 "IPv6 prefix-list name\n")
7604
7605/* old command */
7606DEFUN (show_ipv6_bgp_prefix_list,
7607 show_ipv6_bgp_prefix_list_cmd,
7608 "show ipv6 bgp prefix-list WORD",
7609 SHOW_STR
7610 IPV6_STR
7611 BGP_STR
7612 "Display routes matching the prefix-list\n"
7613 "IPv6 prefix-list name\n")
7614{
7615 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7616 bgp_show_type_prefix_list);
7617}
7618
7619/* old command */
7620DEFUN (show_ipv6_mbgp_prefix_list,
7621 show_ipv6_mbgp_prefix_list_cmd,
7622 "show ipv6 mbgp prefix-list WORD",
7623 SHOW_STR
7624 IPV6_STR
7625 MBGP_STR
7626 "Display routes matching the prefix-list\n"
7627 "IPv6 prefix-list name\n")
7628{
7629 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7630 bgp_show_type_prefix_list);
7631}
7632#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007633
paul94f2b392005-06-28 12:44:16 +00007634static int
paulfd79ac92004-10-13 05:06:08 +00007635bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007636 safi_t safi, enum bgp_show_type type)
7637{
7638 struct as_list *as_list;
7639
7640 as_list = as_list_lookup (filter);
7641 if (as_list == NULL)
7642 {
7643 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7644 return CMD_WARNING;
7645 }
7646
ajs5a646652004-11-05 01:25:55 +00007647 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007648}
7649
7650DEFUN (show_ip_bgp_filter_list,
7651 show_ip_bgp_filter_list_cmd,
7652 "show ip bgp filter-list WORD",
7653 SHOW_STR
7654 IP_STR
7655 BGP_STR
7656 "Display routes conforming to the filter-list\n"
7657 "Regular expression access list name\n")
7658{
7659 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7660 bgp_show_type_filter_list);
7661}
7662
7663DEFUN (show_ip_bgp_flap_filter_list,
7664 show_ip_bgp_flap_filter_list_cmd,
7665 "show ip bgp flap-statistics filter-list WORD",
7666 SHOW_STR
7667 IP_STR
7668 BGP_STR
7669 "Display flap statistics of routes\n"
7670 "Display routes conforming to the filter-list\n"
7671 "Regular expression access list name\n")
7672{
7673 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7674 bgp_show_type_flap_filter_list);
7675}
7676
Balaji3921cc52015-05-16 23:12:17 +05307677ALIAS (show_ip_bgp_flap_filter_list,
7678 show_ip_bgp_damp_flap_filter_list_cmd,
7679 "show ip bgp dampening flap-statistics filter-list WORD",
7680 SHOW_STR
7681 IP_STR
7682 BGP_STR
7683 "Display detailed information about dampening\n"
7684 "Display flap statistics of routes\n"
7685 "Display routes conforming to the filter-list\n"
7686 "Regular expression access list name\n")
7687
paul718e3742002-12-13 20:15:29 +00007688DEFUN (show_ip_bgp_ipv4_filter_list,
7689 show_ip_bgp_ipv4_filter_list_cmd,
7690 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7691 SHOW_STR
7692 IP_STR
7693 BGP_STR
7694 "Address family\n"
7695 "Address Family modifier\n"
7696 "Address Family modifier\n"
7697 "Display routes conforming to the filter-list\n"
7698 "Regular expression access list name\n")
7699{
7700 if (strncmp (argv[0], "m", 1) == 0)
7701 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7702 bgp_show_type_filter_list);
7703
7704 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7705 bgp_show_type_filter_list);
7706}
7707
7708#ifdef HAVE_IPV6
7709DEFUN (show_bgp_filter_list,
7710 show_bgp_filter_list_cmd,
7711 "show bgp filter-list WORD",
7712 SHOW_STR
7713 BGP_STR
7714 "Display routes conforming to the filter-list\n"
7715 "Regular expression access list name\n")
7716{
7717 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7718 bgp_show_type_filter_list);
7719}
7720
7721ALIAS (show_bgp_filter_list,
7722 show_bgp_ipv6_filter_list_cmd,
7723 "show bgp ipv6 filter-list WORD",
7724 SHOW_STR
7725 BGP_STR
7726 "Address family\n"
7727 "Display routes conforming to the filter-list\n"
7728 "Regular expression access list name\n")
7729
7730/* old command */
7731DEFUN (show_ipv6_bgp_filter_list,
7732 show_ipv6_bgp_filter_list_cmd,
7733 "show ipv6 bgp filter-list WORD",
7734 SHOW_STR
7735 IPV6_STR
7736 BGP_STR
7737 "Display routes conforming to the filter-list\n"
7738 "Regular expression access list name\n")
7739{
7740 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7741 bgp_show_type_filter_list);
7742}
7743
7744/* old command */
7745DEFUN (show_ipv6_mbgp_filter_list,
7746 show_ipv6_mbgp_filter_list_cmd,
7747 "show ipv6 mbgp filter-list WORD",
7748 SHOW_STR
7749 IPV6_STR
7750 MBGP_STR
7751 "Display routes conforming to the filter-list\n"
7752 "Regular expression access list name\n")
7753{
7754 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7755 bgp_show_type_filter_list);
7756}
7757#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007758
Balaji3921cc52015-05-16 23:12:17 +05307759DEFUN (show_ip_bgp_dampening_info,
7760 show_ip_bgp_dampening_params_cmd,
7761 "show ip bgp dampening parameters",
7762 SHOW_STR
7763 IP_STR
7764 BGP_STR
7765 "Display detailed information about dampening\n"
7766 "Display detail of configured dampening parameters\n")
7767{
7768 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
7769}
7770
paul94f2b392005-06-28 12:44:16 +00007771static int
paulfd79ac92004-10-13 05:06:08 +00007772bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007773 safi_t safi, enum bgp_show_type type)
7774{
7775 struct route_map *rmap;
7776
7777 rmap = route_map_lookup_by_name (rmap_str);
7778 if (! rmap)
7779 {
7780 vty_out (vty, "%% %s is not a valid route-map name%s",
7781 rmap_str, VTY_NEWLINE);
7782 return CMD_WARNING;
7783 }
7784
ajs5a646652004-11-05 01:25:55 +00007785 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007786}
7787
7788DEFUN (show_ip_bgp_route_map,
7789 show_ip_bgp_route_map_cmd,
7790 "show ip bgp route-map WORD",
7791 SHOW_STR
7792 IP_STR
7793 BGP_STR
7794 "Display routes matching the route-map\n"
7795 "A route-map to match on\n")
7796{
7797 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7798 bgp_show_type_route_map);
7799}
7800
7801DEFUN (show_ip_bgp_flap_route_map,
7802 show_ip_bgp_flap_route_map_cmd,
7803 "show ip bgp flap-statistics route-map WORD",
7804 SHOW_STR
7805 IP_STR
7806 BGP_STR
7807 "Display flap statistics of routes\n"
7808 "Display routes matching the route-map\n"
7809 "A route-map to match on\n")
7810{
7811 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7812 bgp_show_type_flap_route_map);
7813}
7814
Balaji3921cc52015-05-16 23:12:17 +05307815ALIAS (show_ip_bgp_flap_route_map,
7816 show_ip_bgp_damp_flap_route_map_cmd,
7817 "show ip bgp dampening flap-statistics route-map WORD",
7818 SHOW_STR
7819 IP_STR
7820 BGP_STR
7821 "Display detailed information about dampening\n"
7822 "Display flap statistics of routes\n"
7823 "Display routes matching the route-map\n"
7824 "A route-map to match on\n")
7825
paul718e3742002-12-13 20:15:29 +00007826DEFUN (show_ip_bgp_ipv4_route_map,
7827 show_ip_bgp_ipv4_route_map_cmd,
7828 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7829 SHOW_STR
7830 IP_STR
7831 BGP_STR
7832 "Address family\n"
7833 "Address Family modifier\n"
7834 "Address Family modifier\n"
7835 "Display routes matching the route-map\n"
7836 "A route-map to match on\n")
7837{
7838 if (strncmp (argv[0], "m", 1) == 0)
7839 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7840 bgp_show_type_route_map);
7841
7842 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7843 bgp_show_type_route_map);
7844}
7845
7846DEFUN (show_bgp_route_map,
7847 show_bgp_route_map_cmd,
7848 "show bgp route-map WORD",
7849 SHOW_STR
7850 BGP_STR
7851 "Display routes matching the route-map\n"
7852 "A route-map to match on\n")
7853{
7854 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7855 bgp_show_type_route_map);
7856}
7857
7858ALIAS (show_bgp_route_map,
7859 show_bgp_ipv6_route_map_cmd,
7860 "show bgp ipv6 route-map WORD",
7861 SHOW_STR
7862 BGP_STR
7863 "Address family\n"
7864 "Display routes matching the route-map\n"
7865 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007866
paul718e3742002-12-13 20:15:29 +00007867DEFUN (show_ip_bgp_cidr_only,
7868 show_ip_bgp_cidr_only_cmd,
7869 "show ip bgp cidr-only",
7870 SHOW_STR
7871 IP_STR
7872 BGP_STR
7873 "Display only routes with non-natural netmasks\n")
7874{
7875 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007876 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007877}
7878
7879DEFUN (show_ip_bgp_flap_cidr_only,
7880 show_ip_bgp_flap_cidr_only_cmd,
7881 "show ip bgp flap-statistics cidr-only",
7882 SHOW_STR
7883 IP_STR
7884 BGP_STR
7885 "Display flap statistics of routes\n"
7886 "Display only routes with non-natural netmasks\n")
7887{
7888 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007889 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007890}
7891
Balaji3921cc52015-05-16 23:12:17 +05307892ALIAS (show_ip_bgp_flap_cidr_only,
7893 show_ip_bgp_damp_flap_cidr_only_cmd,
7894 "show ip bgp dampening flap-statistics cidr-only",
7895 SHOW_STR
7896 IP_STR
7897 BGP_STR
7898 "Display detailed information about dampening\n"
7899 "Display flap statistics of routes\n"
7900 "Display only routes with non-natural netmasks\n")
7901
paul718e3742002-12-13 20:15:29 +00007902DEFUN (show_ip_bgp_ipv4_cidr_only,
7903 show_ip_bgp_ipv4_cidr_only_cmd,
7904 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7905 SHOW_STR
7906 IP_STR
7907 BGP_STR
7908 "Address family\n"
7909 "Address Family modifier\n"
7910 "Address Family modifier\n"
7911 "Display only routes with non-natural netmasks\n")
7912{
7913 if (strncmp (argv[0], "m", 1) == 0)
7914 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007915 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007916
7917 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007918 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007919}
David Lamparter6b0655a2014-06-04 06:53:35 +02007920
paul718e3742002-12-13 20:15:29 +00007921DEFUN (show_ip_bgp_community_all,
7922 show_ip_bgp_community_all_cmd,
7923 "show ip bgp community",
7924 SHOW_STR
7925 IP_STR
7926 BGP_STR
7927 "Display routes matching the communities\n")
7928{
7929 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007930 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007931}
7932
7933DEFUN (show_ip_bgp_ipv4_community_all,
7934 show_ip_bgp_ipv4_community_all_cmd,
7935 "show ip bgp ipv4 (unicast|multicast) community",
7936 SHOW_STR
7937 IP_STR
7938 BGP_STR
7939 "Address family\n"
7940 "Address Family modifier\n"
7941 "Address Family modifier\n"
7942 "Display routes matching the communities\n")
7943{
7944 if (strncmp (argv[0], "m", 1) == 0)
7945 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007946 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007947
7948 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007949 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007950}
7951
7952#ifdef HAVE_IPV6
7953DEFUN (show_bgp_community_all,
7954 show_bgp_community_all_cmd,
7955 "show bgp community",
7956 SHOW_STR
7957 BGP_STR
7958 "Display routes matching the communities\n")
7959{
7960 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007961 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007962}
7963
7964ALIAS (show_bgp_community_all,
7965 show_bgp_ipv6_community_all_cmd,
7966 "show bgp ipv6 community",
7967 SHOW_STR
7968 BGP_STR
7969 "Address family\n"
7970 "Display routes matching the communities\n")
7971
7972/* old command */
7973DEFUN (show_ipv6_bgp_community_all,
7974 show_ipv6_bgp_community_all_cmd,
7975 "show ipv6 bgp community",
7976 SHOW_STR
7977 IPV6_STR
7978 BGP_STR
7979 "Display routes matching the communities\n")
7980{
7981 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007982 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007983}
7984
7985/* old command */
7986DEFUN (show_ipv6_mbgp_community_all,
7987 show_ipv6_mbgp_community_all_cmd,
7988 "show ipv6 mbgp community",
7989 SHOW_STR
7990 IPV6_STR
7991 MBGP_STR
7992 "Display routes matching the communities\n")
7993{
7994 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007995 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007996}
7997#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007998
paul94f2b392005-06-28 12:44:16 +00007999static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04008000bgp_show_community (struct vty *vty, const char *view_name, int argc,
8001 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008002{
8003 struct community *com;
8004 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008005 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00008006 int i;
8007 char *str;
8008 int first = 0;
8009
Michael Lambert95cbbd22010-07-23 14:43:04 -04008010 /* BGP structure lookup */
8011 if (view_name)
8012 {
8013 bgp = bgp_lookup_by_name (view_name);
8014 if (bgp == NULL)
8015 {
8016 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8017 return CMD_WARNING;
8018 }
8019 }
8020 else
8021 {
8022 bgp = bgp_get_default ();
8023 if (bgp == NULL)
8024 {
8025 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8026 return CMD_WARNING;
8027 }
8028 }
8029
paul718e3742002-12-13 20:15:29 +00008030 b = buffer_new (1024);
8031 for (i = 0; i < argc; i++)
8032 {
8033 if (first)
8034 buffer_putc (b, ' ');
8035 else
8036 {
8037 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8038 continue;
8039 first = 1;
8040 }
8041
8042 buffer_putstr (b, argv[i]);
8043 }
8044 buffer_putc (b, '\0');
8045
8046 str = buffer_getstr (b);
8047 buffer_free (b);
8048
8049 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00008050 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00008051 if (! com)
8052 {
8053 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8054 return CMD_WARNING;
8055 }
8056
Michael Lambert95cbbd22010-07-23 14:43:04 -04008057 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00008058 (exact ? bgp_show_type_community_exact :
8059 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00008060}
8061
8062DEFUN (show_ip_bgp_community,
8063 show_ip_bgp_community_cmd,
8064 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
8065 SHOW_STR
8066 IP_STR
8067 BGP_STR
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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008074 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008075}
8076
8077ALIAS (show_ip_bgp_community,
8078 show_ip_bgp_community2_cmd,
8079 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8080 SHOW_STR
8081 IP_STR
8082 BGP_STR
8083 "Display routes matching the communities\n"
8084 "community number\n"
8085 "Do not send outside local AS (well-known community)\n"
8086 "Do not advertise to any peer (well-known community)\n"
8087 "Do not export to next AS (well-known community)\n"
8088 "community number\n"
8089 "Do not send outside local AS (well-known community)\n"
8090 "Do not advertise to any peer (well-known community)\n"
8091 "Do not export to next AS (well-known community)\n")
8092
8093ALIAS (show_ip_bgp_community,
8094 show_ip_bgp_community3_cmd,
8095 "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)",
8096 SHOW_STR
8097 IP_STR
8098 BGP_STR
8099 "Display routes matching the communities\n"
8100 "community number\n"
8101 "Do not send outside local AS (well-known community)\n"
8102 "Do not advertise to any peer (well-known community)\n"
8103 "Do not export to next AS (well-known community)\n"
8104 "community number\n"
8105 "Do not send outside local AS (well-known community)\n"
8106 "Do not advertise to any peer (well-known community)\n"
8107 "Do not export to next AS (well-known community)\n"
8108 "community number\n"
8109 "Do not send outside local AS (well-known community)\n"
8110 "Do not advertise to any peer (well-known community)\n"
8111 "Do not export to next AS (well-known community)\n")
8112
8113ALIAS (show_ip_bgp_community,
8114 show_ip_bgp_community4_cmd,
8115 "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)",
8116 SHOW_STR
8117 IP_STR
8118 BGP_STR
8119 "Display routes matching the communities\n"
8120 "community number\n"
8121 "Do not send outside local AS (well-known community)\n"
8122 "Do not advertise to any peer (well-known community)\n"
8123 "Do not export to next AS (well-known community)\n"
8124 "community number\n"
8125 "Do not send outside local AS (well-known community)\n"
8126 "Do not advertise to any peer (well-known community)\n"
8127 "Do not export to next AS (well-known community)\n"
8128 "community number\n"
8129 "Do not send outside local AS (well-known community)\n"
8130 "Do not advertise to any peer (well-known community)\n"
8131 "Do not export to next AS (well-known community)\n"
8132 "community number\n"
8133 "Do not send outside local AS (well-known community)\n"
8134 "Do not advertise to any peer (well-known community)\n"
8135 "Do not export to next AS (well-known community)\n")
8136
8137DEFUN (show_ip_bgp_ipv4_community,
8138 show_ip_bgp_ipv4_community_cmd,
8139 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8140 SHOW_STR
8141 IP_STR
8142 BGP_STR
8143 "Address family\n"
8144 "Address Family modifier\n"
8145 "Address Family modifier\n"
8146 "Display routes matching the communities\n"
8147 "community number\n"
8148 "Do not send outside local AS (well-known community)\n"
8149 "Do not advertise to any peer (well-known community)\n"
8150 "Do not export to next AS (well-known community)\n")
8151{
8152 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008153 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008154
Michael Lambert95cbbd22010-07-23 14:43:04 -04008155 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008156}
8157
8158ALIAS (show_ip_bgp_ipv4_community,
8159 show_ip_bgp_ipv4_community2_cmd,
8160 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8161 SHOW_STR
8162 IP_STR
8163 BGP_STR
8164 "Address family\n"
8165 "Address Family modifier\n"
8166 "Address Family modifier\n"
8167 "Display routes matching the communities\n"
8168 "community number\n"
8169 "Do not send outside local AS (well-known community)\n"
8170 "Do not advertise to any peer (well-known community)\n"
8171 "Do not export to next AS (well-known community)\n"
8172 "community number\n"
8173 "Do not send outside local AS (well-known community)\n"
8174 "Do not advertise to any peer (well-known community)\n"
8175 "Do not export to next AS (well-known community)\n")
8176
8177ALIAS (show_ip_bgp_ipv4_community,
8178 show_ip_bgp_ipv4_community3_cmd,
8179 "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)",
8180 SHOW_STR
8181 IP_STR
8182 BGP_STR
8183 "Address family\n"
8184 "Address Family modifier\n"
8185 "Address Family modifier\n"
8186 "Display routes matching the communities\n"
8187 "community number\n"
8188 "Do not send outside local AS (well-known community)\n"
8189 "Do not advertise to any peer (well-known community)\n"
8190 "Do not export to next AS (well-known community)\n"
8191 "community number\n"
8192 "Do not send outside local AS (well-known community)\n"
8193 "Do not advertise to any peer (well-known community)\n"
8194 "Do not export to next AS (well-known community)\n"
8195 "community number\n"
8196 "Do not send outside local AS (well-known community)\n"
8197 "Do not advertise to any peer (well-known community)\n"
8198 "Do not export to next AS (well-known community)\n")
8199
8200ALIAS (show_ip_bgp_ipv4_community,
8201 show_ip_bgp_ipv4_community4_cmd,
8202 "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)",
8203 SHOW_STR
8204 IP_STR
8205 BGP_STR
8206 "Address family\n"
8207 "Address Family modifier\n"
8208 "Address Family modifier\n"
8209 "Display routes matching the communities\n"
8210 "community number\n"
8211 "Do not send outside local AS (well-known community)\n"
8212 "Do not advertise to any peer (well-known community)\n"
8213 "Do not export to next AS (well-known community)\n"
8214 "community number\n"
8215 "Do not send outside local AS (well-known community)\n"
8216 "Do not advertise to any peer (well-known community)\n"
8217 "Do not export to next AS (well-known community)\n"
8218 "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
Michael Lambert95cbbd22010-07-23 14:43:04 -04008227DEFUN (show_bgp_view_afi_safi_community_all,
8228 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008229 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008230 SHOW_STR
8231 BGP_STR
8232 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008233 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008234 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008235 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008236 "Address Family modifier\n"
8237 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008238 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008239{
8240 int afi;
8241 int safi;
8242 struct bgp *bgp;
8243
8244 /* BGP structure lookup. */
8245 bgp = bgp_lookup_by_name (argv[0]);
8246 if (bgp == NULL)
8247 {
8248 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8249 return CMD_WARNING;
8250 }
8251
Michael Lambert95cbbd22010-07-23 14:43:04 -04008252 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8253 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008254 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8255}
8256
8257DEFUN (show_bgp_view_afi_safi_community,
8258 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008259 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008260 SHOW_STR
8261 BGP_STR
8262 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008263 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008264 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008265 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008266 "Address family modifier\n"
8267 "Address family modifier\n"
8268 "Display routes matching the communities\n"
8269 "community number\n"
8270 "Do not send outside local AS (well-known community)\n"
8271 "Do not advertise to any peer (well-known community)\n"
8272 "Do not export to next AS (well-known community)\n")
8273{
8274 int afi;
8275 int safi;
8276
Michael Lambert95cbbd22010-07-23 14:43:04 -04008277 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8278 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8279 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04008280}
8281
8282ALIAS (show_bgp_view_afi_safi_community,
8283 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008284 "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 -04008285 SHOW_STR
8286 BGP_STR
8287 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008288 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008289 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008290 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008291 "Address family modifier\n"
8292 "Address family modifier\n"
8293 "Display routes matching the communities\n"
8294 "community number\n"
8295 "Do not send outside local AS (well-known community)\n"
8296 "Do not advertise to any peer (well-known community)\n"
8297 "Do not export to next AS (well-known community)\n"
8298 "community number\n"
8299 "Do not send outside local AS (well-known community)\n"
8300 "Do not advertise to any peer (well-known community)\n"
8301 "Do not export to next AS (well-known community)\n")
8302
8303ALIAS (show_bgp_view_afi_safi_community,
8304 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008305 "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 -04008306 SHOW_STR
8307 BGP_STR
8308 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008309 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008310 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008311 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008312 "Address family modifier\n"
8313 "Address family modifier\n"
8314 "Display routes matching the communities\n"
8315 "community number\n"
8316 "Do not send outside local AS (well-known community)\n"
8317 "Do not advertise to any peer (well-known community)\n"
8318 "Do not export to next AS (well-known community)\n"
8319 "community number\n"
8320 "Do not send outside local AS (well-known community)\n"
8321 "Do not advertise to any peer (well-known community)\n"
8322 "Do not export to next AS (well-known community)\n"
8323 "community number\n"
8324 "Do not send outside local AS (well-known community)\n"
8325 "Do not advertise to any peer (well-known community)\n"
8326 "Do not export to next AS (well-known community)\n")
8327
8328ALIAS (show_bgp_view_afi_safi_community,
8329 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008330 "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 -04008331 SHOW_STR
8332 BGP_STR
8333 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008334 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008335 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008336 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008337 "Address family modifier\n"
8338 "Address family modifier\n"
8339 "Display routes matching the communities\n"
8340 "community number\n"
8341 "Do not send outside local AS (well-known community)\n"
8342 "Do not advertise to any peer (well-known community)\n"
8343 "Do not export to next AS (well-known community)\n"
8344 "community number\n"
8345 "Do not send outside local AS (well-known community)\n"
8346 "Do not advertise to any peer (well-known community)\n"
8347 "Do not export to next AS (well-known community)\n"
8348 "community number\n"
8349 "Do not send outside local AS (well-known community)\n"
8350 "Do not advertise to any peer (well-known community)\n"
8351 "Do not export to next AS (well-known community)\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
paul718e3742002-12-13 20:15:29 +00008357DEFUN (show_ip_bgp_community_exact,
8358 show_ip_bgp_community_exact_cmd,
8359 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8360 SHOW_STR
8361 IP_STR
8362 BGP_STR
8363 "Display routes matching the communities\n"
8364 "community number\n"
8365 "Do not send outside local AS (well-known community)\n"
8366 "Do not advertise to any peer (well-known community)\n"
8367 "Do not export to next AS (well-known community)\n"
8368 "Exact match of the communities")
8369{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008370 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008371}
8372
8373ALIAS (show_ip_bgp_community_exact,
8374 show_ip_bgp_community2_exact_cmd,
8375 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8376 SHOW_STR
8377 IP_STR
8378 BGP_STR
8379 "Display routes matching the communities\n"
8380 "community number\n"
8381 "Do not send outside local AS (well-known community)\n"
8382 "Do not advertise to any peer (well-known community)\n"
8383 "Do not export to next AS (well-known community)\n"
8384 "community number\n"
8385 "Do not send outside local AS (well-known community)\n"
8386 "Do not advertise to any peer (well-known community)\n"
8387 "Do not export to next AS (well-known community)\n"
8388 "Exact match of the communities")
8389
8390ALIAS (show_ip_bgp_community_exact,
8391 show_ip_bgp_community3_exact_cmd,
8392 "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",
8393 SHOW_STR
8394 IP_STR
8395 BGP_STR
8396 "Display routes matching the communities\n"
8397 "community number\n"
8398 "Do not send outside local AS (well-known community)\n"
8399 "Do not advertise to any peer (well-known community)\n"
8400 "Do not export to next AS (well-known community)\n"
8401 "community number\n"
8402 "Do not send outside local AS (well-known community)\n"
8403 "Do not advertise to any peer (well-known community)\n"
8404 "Do not export to next AS (well-known community)\n"
8405 "community number\n"
8406 "Do not send outside local AS (well-known community)\n"
8407 "Do not advertise to any peer (well-known community)\n"
8408 "Do not export to next AS (well-known community)\n"
8409 "Exact match of the communities")
8410
8411ALIAS (show_ip_bgp_community_exact,
8412 show_ip_bgp_community4_exact_cmd,
8413 "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",
8414 SHOW_STR
8415 IP_STR
8416 BGP_STR
8417 "Display routes matching the communities\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 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "Exact match of the communities")
8435
8436DEFUN (show_ip_bgp_ipv4_community_exact,
8437 show_ip_bgp_ipv4_community_exact_cmd,
8438 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8439 SHOW_STR
8440 IP_STR
8441 BGP_STR
8442 "Address family\n"
8443 "Address Family modifier\n"
8444 "Address Family modifier\n"
8445 "Display routes matching the communities\n"
8446 "community number\n"
8447 "Do not send outside local AS (well-known community)\n"
8448 "Do not advertise to any peer (well-known community)\n"
8449 "Do not export to next AS (well-known community)\n"
8450 "Exact match of the communities")
8451{
8452 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008453 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008454
Michael Lambert95cbbd22010-07-23 14:43:04 -04008455 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008456}
8457
8458ALIAS (show_ip_bgp_ipv4_community_exact,
8459 show_ip_bgp_ipv4_community2_exact_cmd,
8460 "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",
8461 SHOW_STR
8462 IP_STR
8463 BGP_STR
8464 "Address family\n"
8465 "Address Family modifier\n"
8466 "Address Family modifier\n"
8467 "Display routes matching the communities\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n"
8476 "Exact match of the communities")
8477
8478ALIAS (show_ip_bgp_ipv4_community_exact,
8479 show_ip_bgp_ipv4_community3_exact_cmd,
8480 "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",
8481 SHOW_STR
8482 IP_STR
8483 BGP_STR
8484 "Address family\n"
8485 "Address Family modifier\n"
8486 "Address Family modifier\n"
8487 "Display routes matching the communities\n"
8488 "community number\n"
8489 "Do not send outside local AS (well-known community)\n"
8490 "Do not advertise to any peer (well-known community)\n"
8491 "Do not export to next AS (well-known community)\n"
8492 "community number\n"
8493 "Do not send outside local AS (well-known community)\n"
8494 "Do not advertise to any peer (well-known community)\n"
8495 "Do not export to next AS (well-known community)\n"
8496 "community number\n"
8497 "Do not send outside local AS (well-known community)\n"
8498 "Do not advertise to any peer (well-known community)\n"
8499 "Do not export to next AS (well-known community)\n"
8500 "Exact match of the communities")
8501
8502ALIAS (show_ip_bgp_ipv4_community_exact,
8503 show_ip_bgp_ipv4_community4_exact_cmd,
8504 "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",
8505 SHOW_STR
8506 IP_STR
8507 BGP_STR
8508 "Address family\n"
8509 "Address Family modifier\n"
8510 "Address Family modifier\n"
8511 "Display routes matching the communities\n"
8512 "community number\n"
8513 "Do not send outside local AS (well-known community)\n"
8514 "Do not advertise to any peer (well-known community)\n"
8515 "Do not export to next AS (well-known community)\n"
8516 "community number\n"
8517 "Do not send outside local AS (well-known community)\n"
8518 "Do not advertise to any peer (well-known community)\n"
8519 "Do not export to next AS (well-known community)\n"
8520 "community number\n"
8521 "Do not send outside local AS (well-known community)\n"
8522 "Do not advertise to any peer (well-known community)\n"
8523 "Do not export to next AS (well-known community)\n"
8524 "community number\n"
8525 "Do not send outside local AS (well-known community)\n"
8526 "Do not advertise to any peer (well-known community)\n"
8527 "Do not export to next AS (well-known community)\n"
8528 "Exact match of the communities")
8529
8530#ifdef HAVE_IPV6
8531DEFUN (show_bgp_community,
8532 show_bgp_community_cmd,
8533 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8534 SHOW_STR
8535 BGP_STR
8536 "Display routes matching the communities\n"
8537 "community number\n"
8538 "Do not send outside local AS (well-known community)\n"
8539 "Do not advertise to any peer (well-known community)\n"
8540 "Do not export to next AS (well-known community)\n")
8541{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008542 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008543}
8544
8545ALIAS (show_bgp_community,
8546 show_bgp_ipv6_community_cmd,
8547 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8548 SHOW_STR
8549 BGP_STR
8550 "Address family\n"
8551 "Display routes matching the communities\n"
8552 "community number\n"
8553 "Do not send outside local AS (well-known community)\n"
8554 "Do not advertise to any peer (well-known community)\n"
8555 "Do not export to next AS (well-known community)\n")
8556
8557ALIAS (show_bgp_community,
8558 show_bgp_community2_cmd,
8559 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8560 SHOW_STR
8561 BGP_STR
8562 "Display routes matching the communities\n"
8563 "community number\n"
8564 "Do not send outside local AS (well-known community)\n"
8565 "Do not advertise to any peer (well-known community)\n"
8566 "Do not export to next AS (well-known community)\n"
8567 "community number\n"
8568 "Do not send outside local AS (well-known community)\n"
8569 "Do not advertise to any peer (well-known community)\n"
8570 "Do not export to next AS (well-known community)\n")
8571
8572ALIAS (show_bgp_community,
8573 show_bgp_ipv6_community2_cmd,
8574 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8575 SHOW_STR
8576 BGP_STR
8577 "Address family\n"
8578 "Display routes matching the communities\n"
8579 "community number\n"
8580 "Do not send outside local AS (well-known community)\n"
8581 "Do not advertise to any peer (well-known community)\n"
8582 "Do not export to next AS (well-known community)\n"
8583 "community number\n"
8584 "Do not send outside local AS (well-known community)\n"
8585 "Do not advertise to any peer (well-known community)\n"
8586 "Do not export to next AS (well-known community)\n")
8587
8588ALIAS (show_bgp_community,
8589 show_bgp_community3_cmd,
8590 "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)",
8591 SHOW_STR
8592 BGP_STR
8593 "Display routes matching the communities\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "community number\n"
8599 "Do not send outside local AS (well-known community)\n"
8600 "Do not advertise to any peer (well-known community)\n"
8601 "Do not export to next AS (well-known community)\n"
8602 "community number\n"
8603 "Do not send outside local AS (well-known community)\n"
8604 "Do not advertise to any peer (well-known community)\n"
8605 "Do not export to next AS (well-known community)\n")
8606
8607ALIAS (show_bgp_community,
8608 show_bgp_ipv6_community3_cmd,
8609 "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)",
8610 SHOW_STR
8611 BGP_STR
8612 "Address family\n"
8613 "Display routes matching the communities\n"
8614 "community number\n"
8615 "Do not send outside local AS (well-known community)\n"
8616 "Do not advertise to any peer (well-known community)\n"
8617 "Do not export to next AS (well-known community)\n"
8618 "community number\n"
8619 "Do not send outside local AS (well-known community)\n"
8620 "Do not advertise to any peer (well-known community)\n"
8621 "Do not export to next AS (well-known community)\n"
8622 "community number\n"
8623 "Do not send outside local AS (well-known community)\n"
8624 "Do not advertise to any peer (well-known community)\n"
8625 "Do not export to next AS (well-known community)\n")
8626
8627ALIAS (show_bgp_community,
8628 show_bgp_community4_cmd,
8629 "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)",
8630 SHOW_STR
8631 BGP_STR
8632 "Display routes matching the communities\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\n"
8641 "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
8650ALIAS (show_bgp_community,
8651 show_bgp_ipv6_community4_cmd,
8652 "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)",
8653 SHOW_STR
8654 BGP_STR
8655 "Address family\n"
8656 "Display routes matching the communities\n"
8657 "community number\n"
8658 "Do not send outside local AS (well-known community)\n"
8659 "Do not advertise to any peer (well-known community)\n"
8660 "Do not export to next AS (well-known community)\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
8674/* old command */
8675DEFUN (show_ipv6_bgp_community,
8676 show_ipv6_bgp_community_cmd,
8677 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8678 SHOW_STR
8679 IPV6_STR
8680 BGP_STR
8681 "Display routes matching the communities\n"
8682 "community number\n"
8683 "Do not send outside local AS (well-known community)\n"
8684 "Do not advertise to any peer (well-known community)\n"
8685 "Do not export to next AS (well-known community)\n")
8686{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008687 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008688}
8689
8690/* old command */
8691ALIAS (show_ipv6_bgp_community,
8692 show_ipv6_bgp_community2_cmd,
8693 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8694 SHOW_STR
8695 IPV6_STR
8696 BGP_STR
8697 "Display routes matching the communities\n"
8698 "community number\n"
8699 "Do not send outside local AS (well-known community)\n"
8700 "Do not advertise to any peer (well-known community)\n"
8701 "Do not export to next AS (well-known community)\n"
8702 "community number\n"
8703 "Do not send outside local AS (well-known community)\n"
8704 "Do not advertise to any peer (well-known community)\n"
8705 "Do not export to next AS (well-known community)\n")
8706
8707/* old command */
8708ALIAS (show_ipv6_bgp_community,
8709 show_ipv6_bgp_community3_cmd,
8710 "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)",
8711 SHOW_STR
8712 IPV6_STR
8713 BGP_STR
8714 "Display routes matching the communities\n"
8715 "community number\n"
8716 "Do not send outside local AS (well-known community)\n"
8717 "Do not advertise to any peer (well-known community)\n"
8718 "Do not export to next AS (well-known community)\n"
8719 "community number\n"
8720 "Do not send outside local AS (well-known community)\n"
8721 "Do not advertise to any peer (well-known community)\n"
8722 "Do not export to next AS (well-known community)\n"
8723 "community number\n"
8724 "Do not send outside local AS (well-known community)\n"
8725 "Do not advertise to any peer (well-known community)\n"
8726 "Do not export to next AS (well-known community)\n")
8727
8728/* old command */
8729ALIAS (show_ipv6_bgp_community,
8730 show_ipv6_bgp_community4_cmd,
8731 "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)",
8732 SHOW_STR
8733 IPV6_STR
8734 BGP_STR
8735 "Display routes matching the communities\n"
8736 "community number\n"
8737 "Do not send outside local AS (well-known community)\n"
8738 "Do not advertise to any peer (well-known community)\n"
8739 "Do not export to next AS (well-known community)\n"
8740 "community number\n"
8741 "Do not send outside local AS (well-known community)\n"
8742 "Do not advertise to any peer (well-known community)\n"
8743 "Do not export to next AS (well-known community)\n"
8744 "community number\n"
8745 "Do not send outside local AS (well-known community)\n"
8746 "Do not advertise to any peer (well-known community)\n"
8747 "Do not export to next AS (well-known community)\n"
8748 "community number\n"
8749 "Do not send outside local AS (well-known community)\n"
8750 "Do not advertise to any peer (well-known community)\n"
8751 "Do not export to next AS (well-known community)\n")
8752
8753DEFUN (show_bgp_community_exact,
8754 show_bgp_community_exact_cmd,
8755 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8756 SHOW_STR
8757 BGP_STR
8758 "Display routes matching the communities\n"
8759 "community number\n"
8760 "Do not send outside local AS (well-known community)\n"
8761 "Do not advertise to any peer (well-known community)\n"
8762 "Do not export to next AS (well-known community)\n"
8763 "Exact match of the communities")
8764{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008765 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008766}
8767
8768ALIAS (show_bgp_community_exact,
8769 show_bgp_ipv6_community_exact_cmd,
8770 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8771 SHOW_STR
8772 BGP_STR
8773 "Address family\n"
8774 "Display routes matching the communities\n"
8775 "community number\n"
8776 "Do not send outside local AS (well-known community)\n"
8777 "Do not advertise to any peer (well-known community)\n"
8778 "Do not export to next AS (well-known community)\n"
8779 "Exact match of the communities")
8780
8781ALIAS (show_bgp_community_exact,
8782 show_bgp_community2_exact_cmd,
8783 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8784 SHOW_STR
8785 BGP_STR
8786 "Display routes matching the communities\n"
8787 "community number\n"
8788 "Do not send outside local AS (well-known community)\n"
8789 "Do not advertise to any peer (well-known community)\n"
8790 "Do not export to next AS (well-known community)\n"
8791 "community number\n"
8792 "Do not send outside local AS (well-known community)\n"
8793 "Do not advertise to any peer (well-known community)\n"
8794 "Do not export to next AS (well-known community)\n"
8795 "Exact match of the communities")
8796
8797ALIAS (show_bgp_community_exact,
8798 show_bgp_ipv6_community2_exact_cmd,
8799 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8800 SHOW_STR
8801 BGP_STR
8802 "Address family\n"
8803 "Display routes matching the communities\n"
8804 "community number\n"
8805 "Do not send outside local AS (well-known community)\n"
8806 "Do not advertise to any peer (well-known community)\n"
8807 "Do not export to next AS (well-known community)\n"
8808 "community number\n"
8809 "Do not send outside local AS (well-known community)\n"
8810 "Do not advertise to any peer (well-known community)\n"
8811 "Do not export to next AS (well-known community)\n"
8812 "Exact match of the communities")
8813
8814ALIAS (show_bgp_community_exact,
8815 show_bgp_community3_exact_cmd,
8816 "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",
8817 SHOW_STR
8818 BGP_STR
8819 "Display routes matching the communities\n"
8820 "community number\n"
8821 "Do not send outside local AS (well-known community)\n"
8822 "Do not advertise to any peer (well-known community)\n"
8823 "Do not export to next AS (well-known community)\n"
8824 "community number\n"
8825 "Do not send outside local AS (well-known community)\n"
8826 "Do not advertise to any peer (well-known community)\n"
8827 "Do not export to next AS (well-known community)\n"
8828 "community number\n"
8829 "Do not send outside local AS (well-known community)\n"
8830 "Do not advertise to any peer (well-known community)\n"
8831 "Do not export to next AS (well-known community)\n"
8832 "Exact match of the communities")
8833
8834ALIAS (show_bgp_community_exact,
8835 show_bgp_ipv6_community3_exact_cmd,
8836 "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",
8837 SHOW_STR
8838 BGP_STR
8839 "Address family\n"
8840 "Display routes matching the communities\n"
8841 "community number\n"
8842 "Do not send outside local AS (well-known community)\n"
8843 "Do not advertise to any peer (well-known community)\n"
8844 "Do not export to next AS (well-known community)\n"
8845 "community number\n"
8846 "Do not send outside local AS (well-known community)\n"
8847 "Do not advertise to any peer (well-known community)\n"
8848 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8854
8855ALIAS (show_bgp_community_exact,
8856 show_bgp_community4_exact_cmd,
8857 "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",
8858 SHOW_STR
8859 BGP_STR
8860 "Display routes matching the communities\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 "community number\n"
8866 "Do not send outside local AS (well-known community)\n"
8867 "Do not advertise to any peer (well-known community)\n"
8868 "Do not export to next AS (well-known community)\n"
8869 "community number\n"
8870 "Do not send outside local AS (well-known community)\n"
8871 "Do not advertise to any peer (well-known community)\n"
8872 "Do not export to next AS (well-known community)\n"
8873 "community number\n"
8874 "Do not send outside local AS (well-known community)\n"
8875 "Do not advertise to any peer (well-known community)\n"
8876 "Do not export to next AS (well-known community)\n"
8877 "Exact match of the communities")
8878
8879ALIAS (show_bgp_community_exact,
8880 show_bgp_ipv6_community4_exact_cmd,
8881 "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",
8882 SHOW_STR
8883 BGP_STR
8884 "Address family\n"
8885 "Display routes matching the communities\n"
8886 "community number\n"
8887 "Do not send outside local AS (well-known community)\n"
8888 "Do not advertise to any peer (well-known community)\n"
8889 "Do not export to next AS (well-known community)\n"
8890 "community number\n"
8891 "Do not send outside local AS (well-known community)\n"
8892 "Do not advertise to any peer (well-known community)\n"
8893 "Do not export to next AS (well-known community)\n"
8894 "community number\n"
8895 "Do not send outside local AS (well-known community)\n"
8896 "Do not advertise to any peer (well-known community)\n"
8897 "Do not export to next AS (well-known community)\n"
8898 "community number\n"
8899 "Do not send outside local AS (well-known community)\n"
8900 "Do not advertise to any peer (well-known community)\n"
8901 "Do not export to next AS (well-known community)\n"
8902 "Exact match of the communities")
8903
8904/* old command */
8905DEFUN (show_ipv6_bgp_community_exact,
8906 show_ipv6_bgp_community_exact_cmd,
8907 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8908 SHOW_STR
8909 IPV6_STR
8910 BGP_STR
8911 "Display routes matching the communities\n"
8912 "community number\n"
8913 "Do not send outside local AS (well-known community)\n"
8914 "Do not advertise to any peer (well-known community)\n"
8915 "Do not export to next AS (well-known community)\n"
8916 "Exact match of the communities")
8917{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008918 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008919}
8920
8921/* old command */
8922ALIAS (show_ipv6_bgp_community_exact,
8923 show_ipv6_bgp_community2_exact_cmd,
8924 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8925 SHOW_STR
8926 IPV6_STR
8927 BGP_STR
8928 "Display routes matching the communities\n"
8929 "community number\n"
8930 "Do not send outside local AS (well-known community)\n"
8931 "Do not advertise to any peer (well-known community)\n"
8932 "Do not export to next AS (well-known community)\n"
8933 "community number\n"
8934 "Do not send outside local AS (well-known community)\n"
8935 "Do not advertise to any peer (well-known community)\n"
8936 "Do not export to next AS (well-known community)\n"
8937 "Exact match of the communities")
8938
8939/* old command */
8940ALIAS (show_ipv6_bgp_community_exact,
8941 show_ipv6_bgp_community3_exact_cmd,
8942 "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",
8943 SHOW_STR
8944 IPV6_STR
8945 BGP_STR
8946 "Display routes matching the communities\n"
8947 "community number\n"
8948 "Do not send outside local AS (well-known community)\n"
8949 "Do not advertise to any peer (well-known community)\n"
8950 "Do not export to next AS (well-known community)\n"
8951 "community number\n"
8952 "Do not send outside local AS (well-known community)\n"
8953 "Do not advertise to any peer (well-known community)\n"
8954 "Do not export to next AS (well-known community)\n"
8955 "community number\n"
8956 "Do not send outside local AS (well-known community)\n"
8957 "Do not advertise to any peer (well-known community)\n"
8958 "Do not export to next AS (well-known community)\n"
8959 "Exact match of the communities")
8960
8961/* old command */
8962ALIAS (show_ipv6_bgp_community_exact,
8963 show_ipv6_bgp_community4_exact_cmd,
8964 "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",
8965 SHOW_STR
8966 IPV6_STR
8967 BGP_STR
8968 "Display routes matching the communities\n"
8969 "community number\n"
8970 "Do not send outside local AS (well-known community)\n"
8971 "Do not advertise to any peer (well-known community)\n"
8972 "Do not export to next AS (well-known community)\n"
8973 "community number\n"
8974 "Do not send outside local AS (well-known community)\n"
8975 "Do not advertise to any peer (well-known community)\n"
8976 "Do not export to next AS (well-known community)\n"
8977 "community number\n"
8978 "Do not send outside local AS (well-known community)\n"
8979 "Do not advertise to any peer (well-known community)\n"
8980 "Do not export to next AS (well-known community)\n"
8981 "community number\n"
8982 "Do not send outside local AS (well-known community)\n"
8983 "Do not advertise to any peer (well-known community)\n"
8984 "Do not export to next AS (well-known community)\n"
8985 "Exact match of the communities")
8986
8987/* old command */
8988DEFUN (show_ipv6_mbgp_community,
8989 show_ipv6_mbgp_community_cmd,
8990 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8991 SHOW_STR
8992 IPV6_STR
8993 MBGP_STR
8994 "Display routes matching the communities\n"
8995 "community number\n"
8996 "Do not send outside local AS (well-known community)\n"
8997 "Do not advertise to any peer (well-known community)\n"
8998 "Do not export to next AS (well-known community)\n")
8999{
Michael Lambert95cbbd22010-07-23 14:43:04 -04009000 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00009001}
9002
9003/* old command */
9004ALIAS (show_ipv6_mbgp_community,
9005 show_ipv6_mbgp_community2_cmd,
9006 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9007 SHOW_STR
9008 IPV6_STR
9009 MBGP_STR
9010 "Display routes matching the communities\n"
9011 "community number\n"
9012 "Do not send outside local AS (well-known community)\n"
9013 "Do not advertise to any peer (well-known community)\n"
9014 "Do not export to next AS (well-known community)\n"
9015 "community number\n"
9016 "Do not send outside local AS (well-known community)\n"
9017 "Do not advertise to any peer (well-known community)\n"
9018 "Do not export to next AS (well-known community)\n")
9019
9020/* old command */
9021ALIAS (show_ipv6_mbgp_community,
9022 show_ipv6_mbgp_community3_cmd,
9023 "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)",
9024 SHOW_STR
9025 IPV6_STR
9026 MBGP_STR
9027 "Display routes matching the communities\n"
9028 "community number\n"
9029 "Do not send outside local AS (well-known community)\n"
9030 "Do not advertise to any peer (well-known community)\n"
9031 "Do not export to next AS (well-known community)\n"
9032 "community number\n"
9033 "Do not send outside local AS (well-known community)\n"
9034 "Do not advertise to any peer (well-known community)\n"
9035 "Do not export to next AS (well-known community)\n"
9036 "community number\n"
9037 "Do not send outside local AS (well-known community)\n"
9038 "Do not advertise to any peer (well-known community)\n"
9039 "Do not export to next AS (well-known community)\n")
9040
9041/* old command */
9042ALIAS (show_ipv6_mbgp_community,
9043 show_ipv6_mbgp_community4_cmd,
9044 "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)",
9045 SHOW_STR
9046 IPV6_STR
9047 MBGP_STR
9048 "Display routes matching the communities\n"
9049 "community number\n"
9050 "Do not send outside local AS (well-known community)\n"
9051 "Do not advertise to any peer (well-known community)\n"
9052 "Do not export to next AS (well-known community)\n"
9053 "community number\n"
9054 "Do not send outside local AS (well-known community)\n"
9055 "Do not advertise to any peer (well-known community)\n"
9056 "Do not export to next AS (well-known community)\n"
9057 "community number\n"
9058 "Do not send outside local AS (well-known community)\n"
9059 "Do not advertise to any peer (well-known community)\n"
9060 "Do not export to next AS (well-known community)\n"
9061 "community number\n"
9062 "Do not send outside local AS (well-known community)\n"
9063 "Do not advertise to any peer (well-known community)\n"
9064 "Do not export to next AS (well-known community)\n")
9065
9066/* old command */
9067DEFUN (show_ipv6_mbgp_community_exact,
9068 show_ipv6_mbgp_community_exact_cmd,
9069 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9070 SHOW_STR
9071 IPV6_STR
9072 MBGP_STR
9073 "Display routes matching the communities\n"
9074 "community number\n"
9075 "Do not send outside local AS (well-known community)\n"
9076 "Do not advertise to any peer (well-known community)\n"
9077 "Do not export to next AS (well-known community)\n"
9078 "Exact match of the communities")
9079{
Michael Lambert95cbbd22010-07-23 14:43:04 -04009080 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00009081}
9082
9083/* old command */
9084ALIAS (show_ipv6_mbgp_community_exact,
9085 show_ipv6_mbgp_community2_exact_cmd,
9086 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9087 SHOW_STR
9088 IPV6_STR
9089 MBGP_STR
9090 "Display routes matching the communities\n"
9091 "community number\n"
9092 "Do not send outside local AS (well-known community)\n"
9093 "Do not advertise to any peer (well-known community)\n"
9094 "Do not export to next AS (well-known community)\n"
9095 "community number\n"
9096 "Do not send outside local AS (well-known community)\n"
9097 "Do not advertise to any peer (well-known community)\n"
9098 "Do not export to next AS (well-known community)\n"
9099 "Exact match of the communities")
9100
9101/* old command */
9102ALIAS (show_ipv6_mbgp_community_exact,
9103 show_ipv6_mbgp_community3_exact_cmd,
9104 "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",
9105 SHOW_STR
9106 IPV6_STR
9107 MBGP_STR
9108 "Display routes matching the communities\n"
9109 "community number\n"
9110 "Do not send outside local AS (well-known community)\n"
9111 "Do not advertise to any peer (well-known community)\n"
9112 "Do not export to next AS (well-known community)\n"
9113 "community number\n"
9114 "Do not send outside local AS (well-known community)\n"
9115 "Do not advertise to any peer (well-known community)\n"
9116 "Do not export to next AS (well-known community)\n"
9117 "community number\n"
9118 "Do not send outside local AS (well-known community)\n"
9119 "Do not advertise to any peer (well-known community)\n"
9120 "Do not export to next AS (well-known community)\n"
9121 "Exact match of the communities")
9122
9123/* old command */
9124ALIAS (show_ipv6_mbgp_community_exact,
9125 show_ipv6_mbgp_community4_exact_cmd,
9126 "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",
9127 SHOW_STR
9128 IPV6_STR
9129 MBGP_STR
9130 "Display routes matching the communities\n"
9131 "community number\n"
9132 "Do not send outside local AS (well-known community)\n"
9133 "Do not advertise to any peer (well-known community)\n"
9134 "Do not export to next AS (well-known community)\n"
9135 "community number\n"
9136 "Do not send outside local AS (well-known community)\n"
9137 "Do not advertise to any peer (well-known community)\n"
9138 "Do not export to next AS (well-known community)\n"
9139 "community number\n"
9140 "Do not send outside local AS (well-known community)\n"
9141 "Do not advertise to any peer (well-known community)\n"
9142 "Do not export to next AS (well-known community)\n"
9143 "community number\n"
9144 "Do not send outside local AS (well-known community)\n"
9145 "Do not advertise to any peer (well-known community)\n"
9146 "Do not export to next AS (well-known community)\n"
9147 "Exact match of the communities")
9148#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009149
paul94f2b392005-06-28 12:44:16 +00009150static int
paulfd79ac92004-10-13 05:06:08 +00009151bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04009152 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009153{
9154 struct community_list *list;
9155
hassofee6e4e2005-02-02 16:29:31 +00009156 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00009157 if (list == NULL)
9158 {
9159 vty_out (vty, "%% %s is not a valid community-list name%s", com,
9160 VTY_NEWLINE);
9161 return CMD_WARNING;
9162 }
9163
ajs5a646652004-11-05 01:25:55 +00009164 return bgp_show (vty, NULL, afi, safi,
9165 (exact ? bgp_show_type_community_list_exact :
9166 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00009167}
9168
9169DEFUN (show_ip_bgp_community_list,
9170 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009171 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009172 SHOW_STR
9173 IP_STR
9174 BGP_STR
9175 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009176 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009177 "community-list name\n")
9178{
9179 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9180}
9181
9182DEFUN (show_ip_bgp_ipv4_community_list,
9183 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009184 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009185 SHOW_STR
9186 IP_STR
9187 BGP_STR
9188 "Address family\n"
9189 "Address Family modifier\n"
9190 "Address Family modifier\n"
9191 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009192 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009193 "community-list name\n")
9194{
9195 if (strncmp (argv[0], "m", 1) == 0)
9196 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9197
9198 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9199}
9200
9201DEFUN (show_ip_bgp_community_list_exact,
9202 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009203 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009204 SHOW_STR
9205 IP_STR
9206 BGP_STR
9207 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009208 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009209 "community-list name\n"
9210 "Exact match of the communities\n")
9211{
9212 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9213}
9214
9215DEFUN (show_ip_bgp_ipv4_community_list_exact,
9216 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009217 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009218 SHOW_STR
9219 IP_STR
9220 BGP_STR
9221 "Address family\n"
9222 "Address Family modifier\n"
9223 "Address Family modifier\n"
9224 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009225 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009226 "community-list name\n"
9227 "Exact match of the communities\n")
9228{
9229 if (strncmp (argv[0], "m", 1) == 0)
9230 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9231
9232 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9233}
9234
9235#ifdef HAVE_IPV6
9236DEFUN (show_bgp_community_list,
9237 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009238 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009239 SHOW_STR
9240 BGP_STR
9241 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009242 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009243 "community-list name\n")
9244{
9245 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9246}
9247
9248ALIAS (show_bgp_community_list,
9249 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009250 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009251 SHOW_STR
9252 BGP_STR
9253 "Address family\n"
9254 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009255 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009256 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009257
9258/* old command */
9259DEFUN (show_ipv6_bgp_community_list,
9260 show_ipv6_bgp_community_list_cmd,
9261 "show ipv6 bgp community-list WORD",
9262 SHOW_STR
9263 IPV6_STR
9264 BGP_STR
9265 "Display routes matching the community-list\n"
9266 "community-list name\n")
9267{
9268 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9269}
9270
9271/* old command */
9272DEFUN (show_ipv6_mbgp_community_list,
9273 show_ipv6_mbgp_community_list_cmd,
9274 "show ipv6 mbgp community-list WORD",
9275 SHOW_STR
9276 IPV6_STR
9277 MBGP_STR
9278 "Display routes matching the community-list\n"
9279 "community-list name\n")
9280{
9281 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9282}
9283
9284DEFUN (show_bgp_community_list_exact,
9285 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009286 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009287 SHOW_STR
9288 BGP_STR
9289 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009290 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009291 "community-list name\n"
9292 "Exact match of the communities\n")
9293{
9294 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9295}
9296
9297ALIAS (show_bgp_community_list_exact,
9298 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009299 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009300 SHOW_STR
9301 BGP_STR
9302 "Address family\n"
9303 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009304 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009305 "community-list name\n"
9306 "Exact match of the communities\n")
9307
9308/* old command */
9309DEFUN (show_ipv6_bgp_community_list_exact,
9310 show_ipv6_bgp_community_list_exact_cmd,
9311 "show ipv6 bgp community-list WORD exact-match",
9312 SHOW_STR
9313 IPV6_STR
9314 BGP_STR
9315 "Display routes matching the community-list\n"
9316 "community-list name\n"
9317 "Exact match of the communities\n")
9318{
9319 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9320}
9321
9322/* old command */
9323DEFUN (show_ipv6_mbgp_community_list_exact,
9324 show_ipv6_mbgp_community_list_exact_cmd,
9325 "show ipv6 mbgp community-list WORD exact-match",
9326 SHOW_STR
9327 IPV6_STR
9328 MBGP_STR
9329 "Display routes matching the community-list\n"
9330 "community-list name\n"
9331 "Exact match of the communities\n")
9332{
9333 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9334}
9335#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009336
paul94f2b392005-06-28 12:44:16 +00009337static int
paulfd79ac92004-10-13 05:06:08 +00009338bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009339 safi_t safi, enum bgp_show_type type)
9340{
9341 int ret;
9342 struct prefix *p;
9343
9344 p = prefix_new();
9345
9346 ret = str2prefix (prefix, p);
9347 if (! ret)
9348 {
9349 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9350 return CMD_WARNING;
9351 }
9352
ajs5a646652004-11-05 01:25:55 +00009353 ret = bgp_show (vty, NULL, afi, safi, type, p);
9354 prefix_free(p);
9355 return ret;
paul718e3742002-12-13 20:15:29 +00009356}
9357
9358DEFUN (show_ip_bgp_prefix_longer,
9359 show_ip_bgp_prefix_longer_cmd,
9360 "show ip bgp A.B.C.D/M longer-prefixes",
9361 SHOW_STR
9362 IP_STR
9363 BGP_STR
9364 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9365 "Display route and more specific routes\n")
9366{
9367 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9368 bgp_show_type_prefix_longer);
9369}
9370
9371DEFUN (show_ip_bgp_flap_prefix_longer,
9372 show_ip_bgp_flap_prefix_longer_cmd,
9373 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9374 SHOW_STR
9375 IP_STR
9376 BGP_STR
9377 "Display flap statistics of routes\n"
9378 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9379 "Display route and more specific routes\n")
9380{
9381 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9382 bgp_show_type_flap_prefix_longer);
9383}
9384
Balaji3921cc52015-05-16 23:12:17 +05309385ALIAS (show_ip_bgp_flap_prefix_longer,
9386 show_ip_bgp_damp_flap_prefix_longer_cmd,
9387 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
9388 SHOW_STR
9389 IP_STR
9390 BGP_STR
9391 "Display detailed information about dampening\n"
9392 "Display flap statistics of routes\n"
9393 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9394 "Display route and more specific routes\n")
9395
paul718e3742002-12-13 20:15:29 +00009396DEFUN (show_ip_bgp_ipv4_prefix_longer,
9397 show_ip_bgp_ipv4_prefix_longer_cmd,
9398 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9399 SHOW_STR
9400 IP_STR
9401 BGP_STR
9402 "Address family\n"
9403 "Address Family modifier\n"
9404 "Address Family modifier\n"
9405 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9406 "Display route and more specific routes\n")
9407{
9408 if (strncmp (argv[0], "m", 1) == 0)
9409 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9410 bgp_show_type_prefix_longer);
9411
9412 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9413 bgp_show_type_prefix_longer);
9414}
9415
9416DEFUN (show_ip_bgp_flap_address,
9417 show_ip_bgp_flap_address_cmd,
9418 "show ip bgp flap-statistics A.B.C.D",
9419 SHOW_STR
9420 IP_STR
9421 BGP_STR
9422 "Display flap statistics of routes\n"
9423 "Network in the BGP routing table to display\n")
9424{
9425 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9426 bgp_show_type_flap_address);
9427}
9428
Balaji3921cc52015-05-16 23:12:17 +05309429ALIAS (show_ip_bgp_flap_address,
9430 show_ip_bgp_damp_flap_address_cmd,
9431 "show ip bgp dampening flap-statistics A.B.C.D",
9432 SHOW_STR
9433 IP_STR
9434 BGP_STR
9435 "Display detailed information about dampening\n"
9436 "Display flap statistics of routes\n"
9437 "Network in the BGP routing table to display\n")
9438
paul718e3742002-12-13 20:15:29 +00009439DEFUN (show_ip_bgp_flap_prefix,
9440 show_ip_bgp_flap_prefix_cmd,
9441 "show ip bgp flap-statistics A.B.C.D/M",
9442 SHOW_STR
9443 IP_STR
9444 BGP_STR
9445 "Display flap statistics of routes\n"
9446 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9447{
9448 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9449 bgp_show_type_flap_prefix);
9450}
Balaji3921cc52015-05-16 23:12:17 +05309451
9452ALIAS (show_ip_bgp_flap_prefix,
9453 show_ip_bgp_damp_flap_prefix_cmd,
9454 "show ip bgp dampening flap-statistics A.B.C.D/M",
9455 SHOW_STR
9456 IP_STR
9457 BGP_STR
9458 "Display detailed information about dampening\n"
9459 "Display flap statistics of routes\n"
9460 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9461
paul718e3742002-12-13 20:15:29 +00009462#ifdef HAVE_IPV6
9463DEFUN (show_bgp_prefix_longer,
9464 show_bgp_prefix_longer_cmd,
9465 "show bgp X:X::X:X/M longer-prefixes",
9466 SHOW_STR
9467 BGP_STR
9468 "IPv6 prefix <network>/<length>\n"
9469 "Display route and more specific routes\n")
9470{
9471 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9472 bgp_show_type_prefix_longer);
9473}
9474
9475ALIAS (show_bgp_prefix_longer,
9476 show_bgp_ipv6_prefix_longer_cmd,
9477 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9478 SHOW_STR
9479 BGP_STR
9480 "Address family\n"
9481 "IPv6 prefix <network>/<length>\n"
9482 "Display route and more specific routes\n")
9483
9484/* old command */
9485DEFUN (show_ipv6_bgp_prefix_longer,
9486 show_ipv6_bgp_prefix_longer_cmd,
9487 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9488 SHOW_STR
9489 IPV6_STR
9490 BGP_STR
9491 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9492 "Display route and more specific routes\n")
9493{
9494 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9495 bgp_show_type_prefix_longer);
9496}
9497
9498/* old command */
9499DEFUN (show_ipv6_mbgp_prefix_longer,
9500 show_ipv6_mbgp_prefix_longer_cmd,
9501 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9502 SHOW_STR
9503 IPV6_STR
9504 MBGP_STR
9505 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9506 "Display route and more specific routes\n")
9507{
9508 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9509 bgp_show_type_prefix_longer);
9510}
9511#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009512
paul94f2b392005-06-28 12:44:16 +00009513static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009514peer_lookup_in_view (struct vty *vty, const char *view_name,
9515 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009516{
9517 int ret;
9518 struct bgp *bgp;
9519 struct peer *peer;
9520 union sockunion su;
9521
9522 /* BGP structure lookup. */
9523 if (view_name)
9524 {
9525 bgp = bgp_lookup_by_name (view_name);
9526 if (! bgp)
9527 {
9528 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9529 return NULL;
9530 }
9531 }
paul5228ad22004-06-04 17:58:18 +00009532 else
paulbb46e942003-10-24 19:02:03 +00009533 {
9534 bgp = bgp_get_default ();
9535 if (! bgp)
9536 {
9537 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9538 return NULL;
9539 }
9540 }
9541
9542 /* Get peer sockunion. */
9543 ret = str2sockunion (ip_str, &su);
9544 if (ret < 0)
9545 {
9546 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9547 return NULL;
9548 }
9549
9550 /* Peer structure lookup. */
9551 peer = peer_lookup (bgp, &su);
9552 if (! peer)
9553 {
9554 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9555 return NULL;
9556 }
9557
9558 return peer;
9559}
David Lamparter6b0655a2014-06-04 06:53:35 +02009560
Paul Jakma2815e612006-09-14 02:56:07 +00009561enum bgp_stats
9562{
9563 BGP_STATS_MAXBITLEN = 0,
9564 BGP_STATS_RIB,
9565 BGP_STATS_PREFIXES,
9566 BGP_STATS_TOTPLEN,
9567 BGP_STATS_UNAGGREGATEABLE,
9568 BGP_STATS_MAX_AGGREGATEABLE,
9569 BGP_STATS_AGGREGATES,
9570 BGP_STATS_SPACE,
9571 BGP_STATS_ASPATH_COUNT,
9572 BGP_STATS_ASPATH_MAXHOPS,
9573 BGP_STATS_ASPATH_TOTHOPS,
9574 BGP_STATS_ASPATH_MAXSIZE,
9575 BGP_STATS_ASPATH_TOTSIZE,
9576 BGP_STATS_ASN_HIGHEST,
9577 BGP_STATS_MAX,
9578};
paulbb46e942003-10-24 19:02:03 +00009579
Paul Jakma2815e612006-09-14 02:56:07 +00009580static const char *table_stats_strs[] =
9581{
9582 [BGP_STATS_PREFIXES] = "Total Prefixes",
9583 [BGP_STATS_TOTPLEN] = "Average prefix length",
9584 [BGP_STATS_RIB] = "Total Advertisements",
9585 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9586 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9587 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9588 [BGP_STATS_SPACE] = "Address space advertised",
9589 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9590 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9591 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9592 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9593 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9594 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9595 [BGP_STATS_MAX] = NULL,
9596};
9597
9598struct bgp_table_stats
9599{
9600 struct bgp_table *table;
9601 unsigned long long counts[BGP_STATS_MAX];
9602};
9603
9604#if 0
9605#define TALLY_SIGFIG 100000
9606static unsigned long
9607ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9608{
9609 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9610 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9611 unsigned long ret = newtot / count;
9612
9613 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9614 return ret + 1;
9615 else
9616 return ret;
9617}
9618#endif
9619
9620static int
9621bgp_table_stats_walker (struct thread *t)
9622{
9623 struct bgp_node *rn;
9624 struct bgp_node *top;
9625 struct bgp_table_stats *ts = THREAD_ARG (t);
9626 unsigned int space = 0;
9627
Paul Jakma53d9f672006-10-15 23:41:16 +00009628 if (!(top = bgp_table_top (ts->table)))
9629 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009630
9631 switch (top->p.family)
9632 {
9633 case AF_INET:
9634 space = IPV4_MAX_BITLEN;
9635 break;
9636 case AF_INET6:
9637 space = IPV6_MAX_BITLEN;
9638 break;
9639 }
9640
9641 ts->counts[BGP_STATS_MAXBITLEN] = space;
9642
9643 for (rn = top; rn; rn = bgp_route_next (rn))
9644 {
9645 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009646 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009647 unsigned int rinum = 0;
9648
9649 if (rn == top)
9650 continue;
9651
9652 if (!rn->info)
9653 continue;
9654
9655 ts->counts[BGP_STATS_PREFIXES]++;
9656 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9657
9658#if 0
9659 ts->counts[BGP_STATS_AVGPLEN]
9660 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9661 ts->counts[BGP_STATS_AVGPLEN],
9662 rn->p.prefixlen);
9663#endif
9664
9665 /* check if the prefix is included by any other announcements */
9666 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009667 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009668
9669 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009670 {
9671 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9672 /* announced address space */
9673 if (space)
9674 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9675 }
Paul Jakma2815e612006-09-14 02:56:07 +00009676 else if (prn->info)
9677 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9678
Paul Jakma2815e612006-09-14 02:56:07 +00009679 for (ri = rn->info; ri; ri = ri->next)
9680 {
9681 rinum++;
9682 ts->counts[BGP_STATS_RIB]++;
9683
9684 if (ri->attr &&
9685 (CHECK_FLAG (ri->attr->flag,
9686 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9687 ts->counts[BGP_STATS_AGGREGATES]++;
9688
9689 /* as-path stats */
9690 if (ri->attr && ri->attr->aspath)
9691 {
9692 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9693 unsigned int size = aspath_size (ri->attr->aspath);
9694 as_t highest = aspath_highest (ri->attr->aspath);
9695
9696 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9697
9698 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9699 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9700
9701 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9702 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9703
9704 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9705 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9706#if 0
9707 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9708 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9709 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9710 hops);
9711 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9712 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9713 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9714 size);
9715#endif
9716 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9717 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9718 }
9719 }
9720 }
9721 return 0;
9722}
9723
9724static int
9725bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9726{
9727 struct bgp_table_stats ts;
9728 unsigned int i;
9729
9730 if (!bgp->rib[afi][safi])
9731 {
9732 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9733 return CMD_WARNING;
9734 }
9735
9736 memset (&ts, 0, sizeof (ts));
9737 ts.table = bgp->rib[afi][safi];
9738 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9739
9740 vty_out (vty, "BGP %s RIB statistics%s%s",
9741 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9742
9743 for (i = 0; i < BGP_STATS_MAX; i++)
9744 {
9745 if (!table_stats_strs[i])
9746 continue;
9747
9748 switch (i)
9749 {
9750#if 0
9751 case BGP_STATS_ASPATH_AVGHOPS:
9752 case BGP_STATS_ASPATH_AVGSIZE:
9753 case BGP_STATS_AVGPLEN:
9754 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9755 vty_out (vty, "%12.2f",
9756 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9757 break;
9758#endif
9759 case BGP_STATS_ASPATH_TOTHOPS:
9760 case BGP_STATS_ASPATH_TOTSIZE:
9761 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9762 vty_out (vty, "%12.2f",
9763 ts.counts[i] ?
9764 (float)ts.counts[i] /
9765 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9766 : 0);
9767 break;
9768 case BGP_STATS_TOTPLEN:
9769 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9770 vty_out (vty, "%12.2f",
9771 ts.counts[i] ?
9772 (float)ts.counts[i] /
9773 (float)ts.counts[BGP_STATS_PREFIXES]
9774 : 0);
9775 break;
9776 case BGP_STATS_SPACE:
9777 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9778 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9779 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9780 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009781 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009782 vty_out (vty, "%12.2f%s",
9783 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009784 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009785 VTY_NEWLINE);
9786 vty_out (vty, "%30s: ", "/8 equivalent ");
9787 vty_out (vty, "%12.2f%s",
9788 (float)ts.counts[BGP_STATS_SPACE] /
9789 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9790 VTY_NEWLINE);
9791 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9792 break;
9793 vty_out (vty, "%30s: ", "/24 equivalent ");
9794 vty_out (vty, "%12.2f",
9795 (float)ts.counts[BGP_STATS_SPACE] /
9796 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9797 break;
9798 default:
9799 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9800 vty_out (vty, "%12llu", ts.counts[i]);
9801 }
9802
9803 vty_out (vty, "%s", VTY_NEWLINE);
9804 }
9805 return CMD_SUCCESS;
9806}
9807
9808static int
9809bgp_table_stats_vty (struct vty *vty, const char *name,
9810 const char *afi_str, const char *safi_str)
9811{
9812 struct bgp *bgp;
9813 afi_t afi;
9814 safi_t safi;
9815
9816 if (name)
9817 bgp = bgp_lookup_by_name (name);
9818 else
9819 bgp = bgp_get_default ();
9820
9821 if (!bgp)
9822 {
9823 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9824 return CMD_WARNING;
9825 }
9826 if (strncmp (afi_str, "ipv", 3) == 0)
9827 {
9828 if (strncmp (afi_str, "ipv4", 4) == 0)
9829 afi = AFI_IP;
9830 else if (strncmp (afi_str, "ipv6", 4) == 0)
9831 afi = AFI_IP6;
9832 else
9833 {
9834 vty_out (vty, "%% Invalid address family %s%s",
9835 afi_str, VTY_NEWLINE);
9836 return CMD_WARNING;
9837 }
9838 if (strncmp (safi_str, "m", 1) == 0)
9839 safi = SAFI_MULTICAST;
9840 else if (strncmp (safi_str, "u", 1) == 0)
9841 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009842 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9843 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009844 else
9845 {
9846 vty_out (vty, "%% Invalid subsequent address family %s%s",
9847 safi_str, VTY_NEWLINE);
9848 return CMD_WARNING;
9849 }
9850 }
9851 else
9852 {
9853 vty_out (vty, "%% Invalid address family %s%s",
9854 afi_str, VTY_NEWLINE);
9855 return CMD_WARNING;
9856 }
9857
Paul Jakma2815e612006-09-14 02:56:07 +00009858 return bgp_table_stats (vty, bgp, afi, safi);
9859}
9860
9861DEFUN (show_bgp_statistics,
9862 show_bgp_statistics_cmd,
9863 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9864 SHOW_STR
9865 BGP_STR
9866 "Address family\n"
9867 "Address family\n"
9868 "Address Family modifier\n"
9869 "Address Family modifier\n"
9870 "BGP RIB advertisement statistics\n")
9871{
9872 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9873}
9874
9875ALIAS (show_bgp_statistics,
9876 show_bgp_statistics_vpnv4_cmd,
9877 "show bgp (ipv4) (vpnv4) statistics",
9878 SHOW_STR
9879 BGP_STR
9880 "Address family\n"
9881 "Address Family modifier\n"
9882 "BGP RIB advertisement statistics\n")
9883
9884DEFUN (show_bgp_statistics_view,
9885 show_bgp_statistics_view_cmd,
9886 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9887 SHOW_STR
9888 BGP_STR
9889 "BGP view\n"
9890 "Address family\n"
9891 "Address family\n"
9892 "Address Family modifier\n"
9893 "Address Family modifier\n"
9894 "BGP RIB advertisement statistics\n")
9895{
9896 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9897}
9898
9899ALIAS (show_bgp_statistics_view,
9900 show_bgp_statistics_view_vpnv4_cmd,
9901 "show bgp view WORD (ipv4) (vpnv4) statistics",
9902 SHOW_STR
9903 BGP_STR
9904 "BGP view\n"
9905 "Address family\n"
9906 "Address Family modifier\n"
9907 "BGP RIB advertisement statistics\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02009908
Paul Jakmaff7924f2006-09-04 01:10:36 +00009909enum bgp_pcounts
9910{
9911 PCOUNT_ADJ_IN = 0,
9912 PCOUNT_DAMPED,
9913 PCOUNT_REMOVED,
9914 PCOUNT_HISTORY,
9915 PCOUNT_STALE,
9916 PCOUNT_VALID,
9917 PCOUNT_ALL,
9918 PCOUNT_COUNTED,
9919 PCOUNT_PFCNT, /* the figure we display to users */
9920 PCOUNT_MAX,
9921};
9922
9923static const char *pcount_strs[] =
9924{
9925 [PCOUNT_ADJ_IN] = "Adj-in",
9926 [PCOUNT_DAMPED] = "Damped",
9927 [PCOUNT_REMOVED] = "Removed",
9928 [PCOUNT_HISTORY] = "History",
9929 [PCOUNT_STALE] = "Stale",
9930 [PCOUNT_VALID] = "Valid",
9931 [PCOUNT_ALL] = "All RIB",
9932 [PCOUNT_COUNTED] = "PfxCt counted",
9933 [PCOUNT_PFCNT] = "Useable",
9934 [PCOUNT_MAX] = NULL,
9935};
9936
Paul Jakma2815e612006-09-14 02:56:07 +00009937struct peer_pcounts
9938{
9939 unsigned int count[PCOUNT_MAX];
9940 const struct peer *peer;
9941 const struct bgp_table *table;
9942};
9943
Paul Jakmaff7924f2006-09-04 01:10:36 +00009944static int
Paul Jakma2815e612006-09-14 02:56:07 +00009945bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009946{
9947 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009948 struct peer_pcounts *pc = THREAD_ARG (t);
9949 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009950
Paul Jakma2815e612006-09-14 02:56:07 +00009951 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009952 {
9953 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009954 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009955
9956 for (ain = rn->adj_in; ain; ain = ain->next)
9957 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009958 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009959
Paul Jakmaff7924f2006-09-04 01:10:36 +00009960 for (ri = rn->info; ri; ri = ri->next)
9961 {
9962 char buf[SU_ADDRSTRLEN];
9963
9964 if (ri->peer != peer)
9965 continue;
9966
Paul Jakma2815e612006-09-14 02:56:07 +00009967 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009968
9969 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009970 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009971 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009972 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009973 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009974 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009975 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009976 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009977 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009978 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009979 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009980 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009981
9982 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9983 {
Paul Jakma2815e612006-09-14 02:56:07 +00009984 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009985 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009986 plog_warn (peer->log,
9987 "%s [pcount] %s/%d is counted but flags 0x%x",
9988 peer->host,
9989 inet_ntop(rn->p.family, &rn->p.u.prefix,
9990 buf, SU_ADDRSTRLEN),
9991 rn->p.prefixlen,
9992 ri->flags);
9993 }
9994 else
9995 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009996 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009997 plog_warn (peer->log,
9998 "%s [pcount] %s/%d not counted but flags 0x%x",
9999 peer->host,
10000 inet_ntop(rn->p.family, &rn->p.u.prefix,
10001 buf, SU_ADDRSTRLEN),
10002 rn->p.prefixlen,
10003 ri->flags);
10004 }
10005 }
10006 }
Paul Jakma2815e612006-09-14 02:56:07 +000010007 return 0;
10008}
Paul Jakmaff7924f2006-09-04 01:10:36 +000010009
Paul Jakma2815e612006-09-14 02:56:07 +000010010static int
10011bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
10012{
10013 struct peer_pcounts pcounts = { .peer = peer };
10014 unsigned int i;
10015
10016 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10017 || !peer->bgp->rib[afi][safi])
10018 {
10019 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10020 return CMD_WARNING;
10021 }
10022
10023 memset (&pcounts, 0, sizeof(pcounts));
10024 pcounts.peer = peer;
10025 pcounts.table = peer->bgp->rib[afi][safi];
10026
10027 /* in-place call via thread subsystem so as to record execution time
10028 * stats for the thread-walk (i.e. ensure this can't be blamed on
10029 * on just vty_read()).
10030 */
10031 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10032
Paul Jakmaff7924f2006-09-04 01:10:36 +000010033 vty_out (vty, "Prefix counts for %s, %s%s",
10034 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10035 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10036 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10037 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10038
10039 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000010040 vty_out (vty, "%20s: %-10d%s",
10041 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010042
Paul Jakma2815e612006-09-14 02:56:07 +000010043 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000010044 {
10045 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10046 peer->host, VTY_NEWLINE);
10047 vty_out (vty, "Please report this bug, with the above command output%s",
10048 VTY_NEWLINE);
10049 }
10050
10051 return CMD_SUCCESS;
10052}
10053
10054DEFUN (show_ip_bgp_neighbor_prefix_counts,
10055 show_ip_bgp_neighbor_prefix_counts_cmd,
10056 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10057 SHOW_STR
10058 IP_STR
10059 BGP_STR
10060 "Detailed information on TCP and BGP neighbor connections\n"
10061 "Neighbor to display information about\n"
10062 "Neighbor to display information about\n"
10063 "Display detailed prefix count information\n")
10064{
10065 struct peer *peer;
10066
10067 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10068 if (! peer)
10069 return CMD_WARNING;
10070
10071 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10072}
10073
10074DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
10075 show_bgp_ipv6_neighbor_prefix_counts_cmd,
10076 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10077 SHOW_STR
10078 BGP_STR
10079 "Address family\n"
10080 "Detailed information on TCP and BGP neighbor connections\n"
10081 "Neighbor to display information about\n"
10082 "Neighbor to display information about\n"
10083 "Display detailed prefix count information\n")
10084{
10085 struct peer *peer;
10086
10087 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10088 if (! peer)
10089 return CMD_WARNING;
10090
10091 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10092}
10093
10094DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
10095 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
10096 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10097 SHOW_STR
10098 IP_STR
10099 BGP_STR
10100 "Address family\n"
10101 "Address Family modifier\n"
10102 "Address Family modifier\n"
10103 "Detailed information on TCP and BGP neighbor connections\n"
10104 "Neighbor to display information about\n"
10105 "Neighbor to display information about\n"
10106 "Display detailed prefix count information\n")
10107{
10108 struct peer *peer;
10109
10110 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10111 if (! peer)
10112 return CMD_WARNING;
10113
10114 if (strncmp (argv[0], "m", 1) == 0)
10115 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
10116
10117 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10118}
10119
10120DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
10121 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
10122 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10123 SHOW_STR
10124 IP_STR
10125 BGP_STR
10126 "Address family\n"
10127 "Address Family modifier\n"
10128 "Address Family modifier\n"
10129 "Detailed information on TCP and BGP neighbor connections\n"
10130 "Neighbor to display information about\n"
10131 "Neighbor to display information about\n"
10132 "Display detailed prefix count information\n")
10133{
10134 struct peer *peer;
10135
10136 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10137 if (! peer)
10138 return CMD_WARNING;
10139
10140 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
10141}
10142
10143
paul94f2b392005-06-28 12:44:16 +000010144static void
paul718e3742002-12-13 20:15:29 +000010145show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10146 int in)
10147{
10148 struct bgp_table *table;
10149 struct bgp_adj_in *ain;
10150 struct bgp_adj_out *adj;
10151 unsigned long output_count;
10152 struct bgp_node *rn;
10153 int header1 = 1;
10154 struct bgp *bgp;
10155 int header2 = 1;
10156
paulbb46e942003-10-24 19:02:03 +000010157 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000010158
10159 if (! bgp)
10160 return;
10161
10162 table = bgp->rib[afi][safi];
10163
10164 output_count = 0;
10165
10166 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
10167 PEER_STATUS_DEFAULT_ORIGINATE))
10168 {
10169 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (bgp->router_id), VTY_NEWLINE);
hasso93406d82005-02-02 14:40:33 +000010170 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10171 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010172
10173 vty_out (vty, "Originating default network 0.0.0.0%s%s",
10174 VTY_NEWLINE, VTY_NEWLINE);
10175 header1 = 0;
10176 }
10177
10178 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10179 if (in)
10180 {
10181 for (ain = rn->adj_in; ain; ain = ain->next)
10182 if (ain->peer == peer)
10183 {
10184 if (header1)
10185 {
10186 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 +000010187 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10188 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010189 header1 = 0;
10190 }
10191 if (header2)
10192 {
10193 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10194 header2 = 0;
10195 }
10196 if (ain->attr)
10197 {
10198 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
10199 output_count++;
10200 }
10201 }
10202 }
10203 else
10204 {
10205 for (adj = rn->adj_out; adj; adj = adj->next)
10206 if (adj->peer == peer)
10207 {
10208 if (header1)
10209 {
10210 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 +000010211 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10212 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010213 header1 = 0;
10214 }
10215 if (header2)
10216 {
10217 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10218 header2 = 0;
10219 }
10220 if (adj->attr)
10221 {
10222 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10223 output_count++;
10224 }
10225 }
10226 }
10227
10228 if (output_count != 0)
10229 vty_out (vty, "%sTotal number of prefixes %ld%s",
10230 VTY_NEWLINE, output_count, VTY_NEWLINE);
10231}
10232
paul94f2b392005-06-28 12:44:16 +000010233static int
paulbb46e942003-10-24 19:02:03 +000010234peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10235{
paul718e3742002-12-13 20:15:29 +000010236 if (! peer || ! peer->afc[afi][safi])
10237 {
10238 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10239 return CMD_WARNING;
10240 }
10241
10242 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10243 {
10244 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10245 VTY_NEWLINE);
10246 return CMD_WARNING;
10247 }
10248
10249 show_adj_route (vty, peer, afi, safi, in);
10250
10251 return CMD_SUCCESS;
10252}
10253
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010254DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10255 show_ip_bgp_view_neighbor_advertised_route_cmd,
10256 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10257 SHOW_STR
10258 IP_STR
10259 BGP_STR
10260 "BGP view\n"
10261 "View name\n"
10262 "Detailed information on TCP and BGP neighbor connections\n"
10263 "Neighbor to display information about\n"
10264 "Neighbor to display information about\n"
10265 "Display the routes advertised to a BGP neighbor\n")
10266{
10267 struct peer *peer;
10268
10269 if (argc == 2)
10270 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10271 else
10272 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10273
10274 if (! peer)
10275 return CMD_WARNING;
10276
10277 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
10278}
10279
10280ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010281 show_ip_bgp_neighbor_advertised_route_cmd,
10282 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10283 SHOW_STR
10284 IP_STR
10285 BGP_STR
10286 "Detailed information on TCP and BGP neighbor connections\n"
10287 "Neighbor to display information about\n"
10288 "Neighbor to display information about\n"
10289 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +000010290
10291DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10292 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10293 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10294 SHOW_STR
10295 IP_STR
10296 BGP_STR
10297 "Address family\n"
10298 "Address Family modifier\n"
10299 "Address Family modifier\n"
10300 "Detailed information on TCP and BGP neighbor connections\n"
10301 "Neighbor to display information about\n"
10302 "Neighbor to display information about\n"
10303 "Display the routes advertised to a BGP neighbor\n")
10304{
paulbb46e942003-10-24 19:02:03 +000010305 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010306
paulbb46e942003-10-24 19:02:03 +000010307 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10308 if (! peer)
10309 return CMD_WARNING;
10310
10311 if (strncmp (argv[0], "m", 1) == 0)
10312 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10313
10314 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010315}
10316
10317#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010318DEFUN (show_bgp_view_neighbor_advertised_route,
10319 show_bgp_view_neighbor_advertised_route_cmd,
10320 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10321 SHOW_STR
10322 BGP_STR
10323 "BGP view\n"
10324 "View name\n"
10325 "Detailed information on TCP and BGP neighbor connections\n"
10326 "Neighbor to display information about\n"
10327 "Neighbor to display information about\n"
10328 "Display the routes advertised to a BGP neighbor\n")
10329{
10330 struct peer *peer;
10331
10332 if (argc == 2)
10333 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10334 else
10335 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10336
10337 if (! peer)
10338 return CMD_WARNING;
10339
10340 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10341}
10342
10343ALIAS (show_bgp_view_neighbor_advertised_route,
10344 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10345 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10346 SHOW_STR
10347 BGP_STR
10348 "BGP view\n"
10349 "View name\n"
10350 "Address family\n"
10351 "Detailed information on TCP and BGP neighbor connections\n"
10352 "Neighbor to display information about\n"
10353 "Neighbor to display information about\n"
10354 "Display the routes advertised to a BGP neighbor\n")
10355
10356DEFUN (show_bgp_view_neighbor_received_routes,
10357 show_bgp_view_neighbor_received_routes_cmd,
10358 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10359 SHOW_STR
10360 BGP_STR
10361 "BGP view\n"
10362 "View name\n"
10363 "Detailed information on TCP and BGP neighbor connections\n"
10364 "Neighbor to display information about\n"
10365 "Neighbor to display information about\n"
10366 "Display the received routes from neighbor\n")
10367{
10368 struct peer *peer;
10369
10370 if (argc == 2)
10371 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10372 else
10373 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10374
10375 if (! peer)
10376 return CMD_WARNING;
10377
10378 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10379}
10380
10381ALIAS (show_bgp_view_neighbor_received_routes,
10382 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10383 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10384 SHOW_STR
10385 BGP_STR
10386 "BGP view\n"
10387 "View name\n"
10388 "Address family\n"
10389 "Detailed information on TCP and BGP neighbor connections\n"
10390 "Neighbor to display information about\n"
10391 "Neighbor to display information about\n"
10392 "Display the received routes from neighbor\n")
10393
10394ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010395 show_bgp_neighbor_advertised_route_cmd,
10396 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10397 SHOW_STR
10398 BGP_STR
10399 "Detailed information on TCP and BGP neighbor connections\n"
10400 "Neighbor to display information about\n"
10401 "Neighbor to display information about\n"
10402 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010403
10404ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010405 show_bgp_ipv6_neighbor_advertised_route_cmd,
10406 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10407 SHOW_STR
10408 BGP_STR
10409 "Address family\n"
10410 "Detailed information on TCP and BGP neighbor connections\n"
10411 "Neighbor to display information about\n"
10412 "Neighbor to display information about\n"
10413 "Display the routes advertised to a BGP neighbor\n")
10414
10415/* old command */
paulbb46e942003-10-24 19:02:03 +000010416ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010417 ipv6_bgp_neighbor_advertised_route_cmd,
10418 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10419 SHOW_STR
10420 IPV6_STR
10421 BGP_STR
10422 "Detailed information on TCP and BGP neighbor connections\n"
10423 "Neighbor to display information about\n"
10424 "Neighbor to display information about\n"
10425 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010426
paul718e3742002-12-13 20:15:29 +000010427/* old command */
10428DEFUN (ipv6_mbgp_neighbor_advertised_route,
10429 ipv6_mbgp_neighbor_advertised_route_cmd,
10430 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10431 SHOW_STR
10432 IPV6_STR
10433 MBGP_STR
10434 "Detailed information on TCP and BGP neighbor connections\n"
10435 "Neighbor to display information about\n"
10436 "Neighbor to display information about\n"
10437 "Display the routes advertised to a BGP neighbor\n")
10438{
paulbb46e942003-10-24 19:02:03 +000010439 struct peer *peer;
10440
10441 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10442 if (! peer)
10443 return CMD_WARNING;
10444
10445 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010446}
10447#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010448
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010449DEFUN (show_ip_bgp_view_neighbor_received_routes,
10450 show_ip_bgp_view_neighbor_received_routes_cmd,
10451 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10452 SHOW_STR
10453 IP_STR
10454 BGP_STR
10455 "BGP view\n"
10456 "View name\n"
10457 "Detailed information on TCP and BGP neighbor connections\n"
10458 "Neighbor to display information about\n"
10459 "Neighbor to display information about\n"
10460 "Display the received routes from neighbor\n")
10461{
10462 struct peer *peer;
10463
10464 if (argc == 2)
10465 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10466 else
10467 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10468
10469 if (! peer)
10470 return CMD_WARNING;
10471
10472 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10473}
10474
10475ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010476 show_ip_bgp_neighbor_received_routes_cmd,
10477 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10478 SHOW_STR
10479 IP_STR
10480 BGP_STR
10481 "Detailed information on TCP and BGP neighbor connections\n"
10482 "Neighbor to display information about\n"
10483 "Neighbor to display information about\n"
10484 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010485
10486DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10487 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10488 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10489 SHOW_STR
10490 IP_STR
10491 BGP_STR
10492 "Address family\n"
10493 "Address Family modifier\n"
10494 "Address Family modifier\n"
10495 "Detailed information on TCP and BGP neighbor connections\n"
10496 "Neighbor to display information about\n"
10497 "Neighbor to display information about\n"
10498 "Display the received routes from neighbor\n")
10499{
paulbb46e942003-10-24 19:02:03 +000010500 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010501
paulbb46e942003-10-24 19:02:03 +000010502 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10503 if (! peer)
10504 return CMD_WARNING;
10505
10506 if (strncmp (argv[0], "m", 1) == 0)
10507 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10508
10509 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010510}
10511
Michael Lambert95cbbd22010-07-23 14:43:04 -040010512DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10513 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010514 "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 -040010515 SHOW_STR
10516 BGP_STR
10517 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010518 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010519 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010520 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010521 "Address family modifier\n"
10522 "Address family modifier\n"
10523 "Detailed information on TCP and BGP neighbor connections\n"
10524 "Neighbor to display information about\n"
10525 "Neighbor to display information about\n"
10526 "Display the advertised routes to neighbor\n"
10527 "Display the received routes from neighbor\n")
10528{
10529 int afi;
10530 int safi;
10531 int in;
10532 struct peer *peer;
10533
David Lamparter94bad672015-03-03 08:52:22 +010010534 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010535
10536 if (! peer)
10537 return CMD_WARNING;
10538
Michael Lambert95cbbd22010-07-23 14:43:04 -040010539 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10540 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10541 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010542
10543 return peer_adj_routes (vty, peer, afi, safi, in);
10544}
10545
paul718e3742002-12-13 20:15:29 +000010546DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10547 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10548 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10549 SHOW_STR
10550 IP_STR
10551 BGP_STR
10552 "Detailed information on TCP and BGP neighbor connections\n"
10553 "Neighbor to display information about\n"
10554 "Neighbor to display information about\n"
10555 "Display information received from a BGP neighbor\n"
10556 "Display the prefixlist filter\n")
10557{
10558 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010559 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010560 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010561 int count, ret;
paul718e3742002-12-13 20:15:29 +000010562
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010563 ret = str2sockunion (argv[0], &su);
10564 if (ret < 0)
10565 {
10566 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10567 return CMD_WARNING;
10568 }
paul718e3742002-12-13 20:15:29 +000010569
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010570 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010571 if (! peer)
10572 return CMD_WARNING;
10573
10574 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10575 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10576 if (count)
10577 {
10578 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10579 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10580 }
10581
10582 return CMD_SUCCESS;
10583}
10584
10585DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10586 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10587 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10588 SHOW_STR
10589 IP_STR
10590 BGP_STR
10591 "Address family\n"
10592 "Address Family modifier\n"
10593 "Address Family modifier\n"
10594 "Detailed information on TCP and BGP neighbor connections\n"
10595 "Neighbor to display information about\n"
10596 "Neighbor to display information about\n"
10597 "Display information received from a BGP neighbor\n"
10598 "Display the prefixlist filter\n")
10599{
10600 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010601 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010602 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010603 int count, ret;
paul718e3742002-12-13 20:15:29 +000010604
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010605 ret = str2sockunion (argv[1], &su);
10606 if (ret < 0)
10607 {
10608 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10609 return CMD_WARNING;
10610 }
paul718e3742002-12-13 20:15:29 +000010611
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010612 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010613 if (! peer)
10614 return CMD_WARNING;
10615
10616 if (strncmp (argv[0], "m", 1) == 0)
10617 {
10618 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10619 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10620 if (count)
10621 {
10622 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10623 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10624 }
10625 }
10626 else
10627 {
10628 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10629 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10630 if (count)
10631 {
10632 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10633 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10634 }
10635 }
10636
10637 return CMD_SUCCESS;
10638}
10639
10640
10641#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010642ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010643 show_bgp_neighbor_received_routes_cmd,
10644 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10645 SHOW_STR
10646 BGP_STR
10647 "Detailed information on TCP and BGP neighbor connections\n"
10648 "Neighbor to display information about\n"
10649 "Neighbor to display information about\n"
10650 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010651
paulbb46e942003-10-24 19:02:03 +000010652ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010653 show_bgp_ipv6_neighbor_received_routes_cmd,
10654 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10655 SHOW_STR
10656 BGP_STR
10657 "Address family\n"
10658 "Detailed information on TCP and BGP neighbor connections\n"
10659 "Neighbor to display information about\n"
10660 "Neighbor to display information about\n"
10661 "Display the received routes from neighbor\n")
10662
10663DEFUN (show_bgp_neighbor_received_prefix_filter,
10664 show_bgp_neighbor_received_prefix_filter_cmd,
10665 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10666 SHOW_STR
10667 BGP_STR
10668 "Detailed information on TCP and BGP neighbor connections\n"
10669 "Neighbor to display information about\n"
10670 "Neighbor to display information about\n"
10671 "Display information received from a BGP neighbor\n"
10672 "Display the prefixlist filter\n")
10673{
10674 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010675 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010676 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010677 int count, ret;
paul718e3742002-12-13 20:15:29 +000010678
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010679 ret = str2sockunion (argv[0], &su);
10680 if (ret < 0)
10681 {
10682 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10683 return CMD_WARNING;
10684 }
paul718e3742002-12-13 20:15:29 +000010685
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010686 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010687 if (! peer)
10688 return CMD_WARNING;
10689
10690 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10691 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10692 if (count)
10693 {
10694 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10695 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10696 }
10697
10698 return CMD_SUCCESS;
10699}
10700
10701ALIAS (show_bgp_neighbor_received_prefix_filter,
10702 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10703 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10704 SHOW_STR
10705 BGP_STR
10706 "Address family\n"
10707 "Detailed information on TCP and BGP neighbor connections\n"
10708 "Neighbor to display information about\n"
10709 "Neighbor to display information about\n"
10710 "Display information received from a BGP neighbor\n"
10711 "Display the prefixlist filter\n")
10712
10713/* old command */
paulbb46e942003-10-24 19:02:03 +000010714ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010715 ipv6_bgp_neighbor_received_routes_cmd,
10716 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10717 SHOW_STR
10718 IPV6_STR
10719 BGP_STR
10720 "Detailed information on TCP and BGP neighbor connections\n"
10721 "Neighbor to display information about\n"
10722 "Neighbor to display information about\n"
10723 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010724
10725/* old command */
10726DEFUN (ipv6_mbgp_neighbor_received_routes,
10727 ipv6_mbgp_neighbor_received_routes_cmd,
10728 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10729 SHOW_STR
10730 IPV6_STR
10731 MBGP_STR
10732 "Detailed information on TCP and BGP neighbor connections\n"
10733 "Neighbor to display information about\n"
10734 "Neighbor to display information about\n"
10735 "Display the received routes from neighbor\n")
10736{
paulbb46e942003-10-24 19:02:03 +000010737 struct peer *peer;
10738
10739 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10740 if (! peer)
10741 return CMD_WARNING;
10742
10743 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010744}
paulbb46e942003-10-24 19:02:03 +000010745
10746DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10747 show_bgp_view_neighbor_received_prefix_filter_cmd,
10748 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10749 SHOW_STR
10750 BGP_STR
10751 "BGP view\n"
10752 "View name\n"
10753 "Detailed information on TCP and BGP neighbor connections\n"
10754 "Neighbor to display information about\n"
10755 "Neighbor to display information about\n"
10756 "Display information received from a BGP neighbor\n"
10757 "Display the prefixlist filter\n")
10758{
10759 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010760 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010761 struct peer *peer;
10762 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010763 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010764
10765 /* BGP structure lookup. */
10766 bgp = bgp_lookup_by_name (argv[0]);
10767 if (bgp == NULL)
10768 {
10769 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10770 return CMD_WARNING;
10771 }
10772
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010773 ret = str2sockunion (argv[1], &su);
10774 if (ret < 0)
10775 {
10776 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10777 return CMD_WARNING;
10778 }
paulbb46e942003-10-24 19:02:03 +000010779
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010780 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010781 if (! peer)
10782 return CMD_WARNING;
10783
10784 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10785 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10786 if (count)
10787 {
10788 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10789 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10790 }
10791
10792 return CMD_SUCCESS;
10793}
10794
10795ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10796 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10797 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10798 SHOW_STR
10799 BGP_STR
10800 "BGP view\n"
10801 "View name\n"
10802 "Address family\n"
10803 "Detailed information on TCP and BGP neighbor connections\n"
10804 "Neighbor to display information about\n"
10805 "Neighbor to display information about\n"
10806 "Display information received from a BGP neighbor\n"
10807 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010808#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010809
paul94f2b392005-06-28 12:44:16 +000010810static int
paulbb46e942003-10-24 19:02:03 +000010811bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010812 safi_t safi, enum bgp_show_type type)
10813{
paul718e3742002-12-13 20:15:29 +000010814 if (! peer || ! peer->afc[afi][safi])
10815 {
10816 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010817 return CMD_WARNING;
10818 }
10819
ajs5a646652004-11-05 01:25:55 +000010820 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010821}
10822
10823DEFUN (show_ip_bgp_neighbor_routes,
10824 show_ip_bgp_neighbor_routes_cmd,
10825 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10826 SHOW_STR
10827 IP_STR
10828 BGP_STR
10829 "Detailed information on TCP and BGP neighbor connections\n"
10830 "Neighbor to display information about\n"
10831 "Neighbor to display information about\n"
10832 "Display routes learned from neighbor\n")
10833{
paulbb46e942003-10-24 19:02:03 +000010834 struct peer *peer;
10835
10836 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10837 if (! peer)
10838 return CMD_WARNING;
10839
10840 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010841 bgp_show_type_neighbor);
10842}
10843
10844DEFUN (show_ip_bgp_neighbor_flap,
10845 show_ip_bgp_neighbor_flap_cmd,
10846 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10847 SHOW_STR
10848 IP_STR
10849 BGP_STR
10850 "Detailed information on TCP and BGP neighbor connections\n"
10851 "Neighbor to display information about\n"
10852 "Neighbor to display information about\n"
10853 "Display flap statistics of the routes learned from neighbor\n")
10854{
paulbb46e942003-10-24 19:02:03 +000010855 struct peer *peer;
10856
10857 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10858 if (! peer)
10859 return CMD_WARNING;
10860
10861 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010862 bgp_show_type_flap_neighbor);
10863}
10864
10865DEFUN (show_ip_bgp_neighbor_damp,
10866 show_ip_bgp_neighbor_damp_cmd,
10867 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10868 SHOW_STR
10869 IP_STR
10870 BGP_STR
10871 "Detailed information on TCP and BGP neighbor connections\n"
10872 "Neighbor to display information about\n"
10873 "Neighbor to display information about\n"
10874 "Display the dampened routes received from neighbor\n")
10875{
paulbb46e942003-10-24 19:02:03 +000010876 struct peer *peer;
10877
10878 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10879 if (! peer)
10880 return CMD_WARNING;
10881
10882 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010883 bgp_show_type_damp_neighbor);
10884}
10885
10886DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10887 show_ip_bgp_ipv4_neighbor_routes_cmd,
10888 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10889 SHOW_STR
10890 IP_STR
10891 BGP_STR
10892 "Address family\n"
10893 "Address Family modifier\n"
10894 "Address Family modifier\n"
10895 "Detailed information on TCP and BGP neighbor connections\n"
10896 "Neighbor to display information about\n"
10897 "Neighbor to display information about\n"
10898 "Display routes learned from neighbor\n")
10899{
paulbb46e942003-10-24 19:02:03 +000010900 struct peer *peer;
10901
10902 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10903 if (! peer)
10904 return CMD_WARNING;
10905
paul718e3742002-12-13 20:15:29 +000010906 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010907 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010908 bgp_show_type_neighbor);
10909
paulbb46e942003-10-24 19:02:03 +000010910 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010911 bgp_show_type_neighbor);
10912}
paulbb46e942003-10-24 19:02:03 +000010913
paulfee0f4c2004-09-13 05:12:46 +000010914DEFUN (show_ip_bgp_view_rsclient,
10915 show_ip_bgp_view_rsclient_cmd,
10916 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10917 SHOW_STR
10918 IP_STR
10919 BGP_STR
10920 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010921 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010922 "Information about Route Server Client\n"
10923 NEIGHBOR_ADDR_STR)
10924{
10925 struct bgp_table *table;
10926 struct peer *peer;
10927
10928 if (argc == 2)
10929 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10930 else
10931 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10932
10933 if (! peer)
10934 return CMD_WARNING;
10935
10936 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10937 {
10938 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10939 VTY_NEWLINE);
10940 return CMD_WARNING;
10941 }
10942
10943 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10944 PEER_FLAG_RSERVER_CLIENT))
10945 {
10946 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10947 VTY_NEWLINE);
10948 return CMD_WARNING;
10949 }
10950
10951 table = peer->rib[AFI_IP][SAFI_UNICAST];
10952
ajs5a646652004-11-05 01:25:55 +000010953 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010954}
10955
10956ALIAS (show_ip_bgp_view_rsclient,
10957 show_ip_bgp_rsclient_cmd,
10958 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10959 SHOW_STR
10960 IP_STR
10961 BGP_STR
10962 "Information about Route Server Client\n"
10963 NEIGHBOR_ADDR_STR)
10964
Michael Lambert95cbbd22010-07-23 14:43:04 -040010965DEFUN (show_bgp_view_ipv4_safi_rsclient,
10966 show_bgp_view_ipv4_safi_rsclient_cmd,
10967 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10968 SHOW_STR
10969 BGP_STR
10970 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010971 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010972 "Address family\n"
10973 "Address Family modifier\n"
10974 "Address Family modifier\n"
10975 "Information about Route Server Client\n"
10976 NEIGHBOR_ADDR_STR)
10977{
10978 struct bgp_table *table;
10979 struct peer *peer;
10980 safi_t safi;
10981
10982 if (argc == 3) {
10983 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10984 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10985 } else {
10986 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10987 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10988 }
10989
10990 if (! peer)
10991 return CMD_WARNING;
10992
10993 if (! peer->afc[AFI_IP][safi])
10994 {
10995 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10996 VTY_NEWLINE);
10997 return CMD_WARNING;
10998 }
10999
11000 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11001 PEER_FLAG_RSERVER_CLIENT))
11002 {
11003 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11004 VTY_NEWLINE);
11005 return CMD_WARNING;
11006 }
11007
11008 table = peer->rib[AFI_IP][safi];
11009
11010 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11011}
11012
11013ALIAS (show_bgp_view_ipv4_safi_rsclient,
11014 show_bgp_ipv4_safi_rsclient_cmd,
11015 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11016 SHOW_STR
11017 BGP_STR
11018 "Address family\n"
11019 "Address Family modifier\n"
11020 "Address Family modifier\n"
11021 "Information about Route Server Client\n"
11022 NEIGHBOR_ADDR_STR)
11023
paulfee0f4c2004-09-13 05:12:46 +000011024DEFUN (show_ip_bgp_view_rsclient_route,
11025 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010011026 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000011027 SHOW_STR
11028 IP_STR
11029 BGP_STR
11030 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011031 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011032 "Information about Route Server Client\n"
11033 NEIGHBOR_ADDR_STR
11034 "Network in the BGP routing table to display\n")
11035{
11036 struct bgp *bgp;
11037 struct peer *peer;
11038
11039 /* BGP structure lookup. */
11040 if (argc == 3)
11041 {
11042 bgp = bgp_lookup_by_name (argv[0]);
11043 if (bgp == NULL)
11044 {
11045 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11046 return CMD_WARNING;
11047 }
11048 }
11049 else
11050 {
11051 bgp = bgp_get_default ();
11052 if (bgp == NULL)
11053 {
11054 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11055 return CMD_WARNING;
11056 }
11057 }
11058
11059 if (argc == 3)
11060 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11061 else
11062 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11063
11064 if (! peer)
11065 return CMD_WARNING;
11066
11067 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11068 {
11069 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11070 VTY_NEWLINE);
11071 return CMD_WARNING;
11072}
11073
11074 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11075 PEER_FLAG_RSERVER_CLIENT))
11076 {
11077 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11078 VTY_NEWLINE);
11079 return CMD_WARNING;
11080 }
11081
11082 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11083 (argc == 3) ? argv[2] : argv[1],
11084 AFI_IP, SAFI_UNICAST, NULL, 0);
11085}
11086
11087ALIAS (show_ip_bgp_view_rsclient_route,
11088 show_ip_bgp_rsclient_route_cmd,
11089 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11090 SHOW_STR
11091 IP_STR
11092 BGP_STR
11093 "Information about Route Server Client\n"
11094 NEIGHBOR_ADDR_STR
11095 "Network in the BGP routing table to display\n")
11096
Michael Lambert95cbbd22010-07-23 14:43:04 -040011097DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11098 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11099 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11100 SHOW_STR
11101 BGP_STR
11102 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011103 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011104 "Address family\n"
11105 "Address Family modifier\n"
11106 "Address Family modifier\n"
11107 "Information about Route Server Client\n"
11108 NEIGHBOR_ADDR_STR
11109 "Network in the BGP routing table to display\n")
11110{
11111 struct bgp *bgp;
11112 struct peer *peer;
11113 safi_t safi;
11114
11115 /* BGP structure lookup. */
11116 if (argc == 4)
11117 {
11118 bgp = bgp_lookup_by_name (argv[0]);
11119 if (bgp == NULL)
11120 {
11121 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11122 return CMD_WARNING;
11123 }
11124 }
11125 else
11126 {
11127 bgp = bgp_get_default ();
11128 if (bgp == NULL)
11129 {
11130 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11131 return CMD_WARNING;
11132 }
11133 }
11134
11135 if (argc == 4) {
11136 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11137 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11138 } else {
11139 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11140 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11141 }
11142
11143 if (! peer)
11144 return CMD_WARNING;
11145
11146 if (! peer->afc[AFI_IP][safi])
11147 {
11148 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11149 VTY_NEWLINE);
11150 return CMD_WARNING;
11151}
11152
11153 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11154 PEER_FLAG_RSERVER_CLIENT))
11155 {
11156 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11157 VTY_NEWLINE);
11158 return CMD_WARNING;
11159 }
11160
11161 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11162 (argc == 4) ? argv[3] : argv[2],
11163 AFI_IP, safi, NULL, 0);
11164}
11165
11166ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
11167 show_bgp_ipv4_safi_rsclient_route_cmd,
11168 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11169 SHOW_STR
11170 BGP_STR
11171 "Address family\n"
11172 "Address Family modifier\n"
11173 "Address Family modifier\n"
11174 "Information about Route Server Client\n"
11175 NEIGHBOR_ADDR_STR
11176 "Network in the BGP routing table to display\n")
11177
paulfee0f4c2004-09-13 05:12:46 +000011178DEFUN (show_ip_bgp_view_rsclient_prefix,
11179 show_ip_bgp_view_rsclient_prefix_cmd,
11180 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11181 SHOW_STR
11182 IP_STR
11183 BGP_STR
11184 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011185 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011186 "Information about Route Server Client\n"
11187 NEIGHBOR_ADDR_STR
11188 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11189{
11190 struct bgp *bgp;
11191 struct peer *peer;
11192
11193 /* BGP structure lookup. */
11194 if (argc == 3)
11195 {
11196 bgp = bgp_lookup_by_name (argv[0]);
11197 if (bgp == NULL)
11198 {
11199 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11200 return CMD_WARNING;
11201 }
11202 }
11203 else
11204 {
11205 bgp = bgp_get_default ();
11206 if (bgp == NULL)
11207 {
11208 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11209 return CMD_WARNING;
11210 }
11211 }
11212
11213 if (argc == 3)
11214 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11215 else
11216 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11217
11218 if (! peer)
11219 return CMD_WARNING;
11220
11221 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11222 {
11223 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11224 VTY_NEWLINE);
11225 return CMD_WARNING;
11226}
11227
11228 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11229 PEER_FLAG_RSERVER_CLIENT))
11230{
11231 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11232 VTY_NEWLINE);
11233 return CMD_WARNING;
11234 }
11235
11236 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11237 (argc == 3) ? argv[2] : argv[1],
11238 AFI_IP, SAFI_UNICAST, NULL, 1);
11239}
11240
11241ALIAS (show_ip_bgp_view_rsclient_prefix,
11242 show_ip_bgp_rsclient_prefix_cmd,
11243 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11244 SHOW_STR
11245 IP_STR
11246 BGP_STR
11247 "Information about Route Server Client\n"
11248 NEIGHBOR_ADDR_STR
11249 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11250
Michael Lambert95cbbd22010-07-23 14:43:04 -040011251DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11252 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11253 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11254 SHOW_STR
11255 BGP_STR
11256 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011257 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011258 "Address family\n"
11259 "Address Family modifier\n"
11260 "Address Family modifier\n"
11261 "Information about Route Server Client\n"
11262 NEIGHBOR_ADDR_STR
11263 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11264{
11265 struct bgp *bgp;
11266 struct peer *peer;
11267 safi_t safi;
11268
11269 /* BGP structure lookup. */
11270 if (argc == 4)
11271 {
11272 bgp = bgp_lookup_by_name (argv[0]);
11273 if (bgp == NULL)
11274 {
11275 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11276 return CMD_WARNING;
11277 }
11278 }
11279 else
11280 {
11281 bgp = bgp_get_default ();
11282 if (bgp == NULL)
11283 {
11284 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11285 return CMD_WARNING;
11286 }
11287 }
11288
11289 if (argc == 4) {
11290 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11291 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11292 } else {
11293 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11294 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11295 }
11296
11297 if (! peer)
11298 return CMD_WARNING;
11299
11300 if (! peer->afc[AFI_IP][safi])
11301 {
11302 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11303 VTY_NEWLINE);
11304 return CMD_WARNING;
11305}
11306
11307 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11308 PEER_FLAG_RSERVER_CLIENT))
11309{
11310 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11311 VTY_NEWLINE);
11312 return CMD_WARNING;
11313 }
11314
11315 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11316 (argc == 4) ? argv[3] : argv[2],
11317 AFI_IP, safi, NULL, 1);
11318}
11319
11320ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11321 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11322 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11323 SHOW_STR
11324 BGP_STR
11325 "Address family\n"
11326 "Address Family modifier\n"
11327 "Address Family modifier\n"
11328 "Information about Route Server Client\n"
11329 NEIGHBOR_ADDR_STR
11330 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011331
paul718e3742002-12-13 20:15:29 +000011332#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011333DEFUN (show_bgp_view_neighbor_routes,
11334 show_bgp_view_neighbor_routes_cmd,
11335 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11336 SHOW_STR
11337 BGP_STR
11338 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011339 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011340 "Detailed information on TCP and BGP neighbor connections\n"
11341 "Neighbor to display information about\n"
11342 "Neighbor to display information about\n"
11343 "Display routes learned from neighbor\n")
11344{
11345 struct peer *peer;
11346
11347 if (argc == 2)
11348 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11349 else
11350 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11351
11352 if (! peer)
11353 return CMD_WARNING;
11354
11355 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11356 bgp_show_type_neighbor);
11357}
11358
11359ALIAS (show_bgp_view_neighbor_routes,
11360 show_bgp_view_ipv6_neighbor_routes_cmd,
11361 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11362 SHOW_STR
11363 BGP_STR
11364 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011365 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011366 "Address family\n"
11367 "Detailed information on TCP and BGP neighbor connections\n"
11368 "Neighbor to display information about\n"
11369 "Neighbor to display information about\n"
11370 "Display routes learned from neighbor\n")
11371
11372DEFUN (show_bgp_view_neighbor_damp,
11373 show_bgp_view_neighbor_damp_cmd,
11374 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11375 SHOW_STR
11376 BGP_STR
11377 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011378 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011379 "Detailed information on TCP and BGP neighbor connections\n"
11380 "Neighbor to display information about\n"
11381 "Neighbor to display information about\n"
11382 "Display the dampened routes received from neighbor\n")
11383{
11384 struct peer *peer;
11385
11386 if (argc == 2)
11387 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11388 else
11389 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11390
11391 if (! peer)
11392 return CMD_WARNING;
11393
11394 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11395 bgp_show_type_damp_neighbor);
11396}
11397
11398ALIAS (show_bgp_view_neighbor_damp,
11399 show_bgp_view_ipv6_neighbor_damp_cmd,
11400 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11401 SHOW_STR
11402 BGP_STR
11403 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011404 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011405 "Address family\n"
11406 "Detailed information on TCP and BGP neighbor connections\n"
11407 "Neighbor to display information about\n"
11408 "Neighbor to display information about\n"
11409 "Display the dampened routes received from neighbor\n")
11410
11411DEFUN (show_bgp_view_neighbor_flap,
11412 show_bgp_view_neighbor_flap_cmd,
11413 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11414 SHOW_STR
11415 BGP_STR
11416 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011417 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011418 "Detailed information on TCP and BGP neighbor connections\n"
11419 "Neighbor to display information about\n"
11420 "Neighbor to display information about\n"
11421 "Display flap statistics of the routes learned from neighbor\n")
11422{
11423 struct peer *peer;
11424
11425 if (argc == 2)
11426 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11427 else
11428 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11429
11430 if (! peer)
11431 return CMD_WARNING;
11432
11433 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11434 bgp_show_type_flap_neighbor);
11435}
11436
11437ALIAS (show_bgp_view_neighbor_flap,
11438 show_bgp_view_ipv6_neighbor_flap_cmd,
11439 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11440 SHOW_STR
11441 BGP_STR
11442 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011443 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011444 "Address family\n"
11445 "Detailed information on TCP and BGP neighbor connections\n"
11446 "Neighbor to display information about\n"
11447 "Neighbor to display information about\n"
11448 "Display flap statistics of the routes learned from neighbor\n")
11449
11450ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011451 show_bgp_neighbor_routes_cmd,
11452 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11453 SHOW_STR
11454 BGP_STR
11455 "Detailed information on TCP and BGP neighbor connections\n"
11456 "Neighbor to display information about\n"
11457 "Neighbor to display information about\n"
11458 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011459
paulbb46e942003-10-24 19:02:03 +000011460
11461ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011462 show_bgp_ipv6_neighbor_routes_cmd,
11463 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11464 SHOW_STR
11465 BGP_STR
11466 "Address family\n"
11467 "Detailed information on TCP and BGP neighbor connections\n"
11468 "Neighbor to display information about\n"
11469 "Neighbor to display information about\n"
11470 "Display routes learned from neighbor\n")
11471
11472/* old command */
paulbb46e942003-10-24 19:02:03 +000011473ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011474 ipv6_bgp_neighbor_routes_cmd,
11475 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11476 SHOW_STR
11477 IPV6_STR
11478 BGP_STR
11479 "Detailed information on TCP and BGP neighbor connections\n"
11480 "Neighbor to display information about\n"
11481 "Neighbor to display information about\n"
11482 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011483
11484/* old command */
11485DEFUN (ipv6_mbgp_neighbor_routes,
11486 ipv6_mbgp_neighbor_routes_cmd,
11487 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11488 SHOW_STR
11489 IPV6_STR
11490 MBGP_STR
11491 "Detailed information on TCP and BGP neighbor connections\n"
11492 "Neighbor to display information about\n"
11493 "Neighbor to display information about\n"
11494 "Display routes learned from neighbor\n")
11495{
paulbb46e942003-10-24 19:02:03 +000011496 struct peer *peer;
11497
11498 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11499 if (! peer)
11500 return CMD_WARNING;
11501
11502 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011503 bgp_show_type_neighbor);
11504}
paulbb46e942003-10-24 19:02:03 +000011505
11506ALIAS (show_bgp_view_neighbor_flap,
11507 show_bgp_neighbor_flap_cmd,
11508 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11509 SHOW_STR
11510 BGP_STR
11511 "Detailed information on TCP and BGP neighbor connections\n"
11512 "Neighbor to display information about\n"
11513 "Neighbor to display information about\n"
11514 "Display flap statistics of the routes learned from neighbor\n")
11515
11516ALIAS (show_bgp_view_neighbor_flap,
11517 show_bgp_ipv6_neighbor_flap_cmd,
11518 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11519 SHOW_STR
11520 BGP_STR
11521 "Address family\n"
11522 "Detailed information on TCP and BGP neighbor connections\n"
11523 "Neighbor to display information about\n"
11524 "Neighbor to display information about\n"
11525 "Display flap statistics of the routes learned from neighbor\n")
11526
11527ALIAS (show_bgp_view_neighbor_damp,
11528 show_bgp_neighbor_damp_cmd,
11529 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11530 SHOW_STR
11531 BGP_STR
11532 "Detailed information on TCP and BGP neighbor connections\n"
11533 "Neighbor to display information about\n"
11534 "Neighbor to display information about\n"
11535 "Display the dampened routes received from neighbor\n")
11536
11537ALIAS (show_bgp_view_neighbor_damp,
11538 show_bgp_ipv6_neighbor_damp_cmd,
11539 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11540 SHOW_STR
11541 BGP_STR
11542 "Address family\n"
11543 "Detailed information on TCP and BGP neighbor connections\n"
11544 "Neighbor to display information about\n"
11545 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011546 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011547
11548DEFUN (show_bgp_view_rsclient,
11549 show_bgp_view_rsclient_cmd,
11550 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11551 SHOW_STR
11552 BGP_STR
11553 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011554 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011555 "Information about Route Server Client\n"
11556 NEIGHBOR_ADDR_STR)
11557{
11558 struct bgp_table *table;
11559 struct peer *peer;
11560
11561 if (argc == 2)
11562 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11563 else
11564 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11565
11566 if (! peer)
11567 return CMD_WARNING;
11568
11569 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11570 {
11571 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11572 VTY_NEWLINE);
11573 return CMD_WARNING;
11574 }
11575
11576 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11577 PEER_FLAG_RSERVER_CLIENT))
11578 {
11579 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11580 VTY_NEWLINE);
11581 return CMD_WARNING;
11582 }
11583
11584 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11585
ajs5a646652004-11-05 01:25:55 +000011586 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011587}
11588
11589ALIAS (show_bgp_view_rsclient,
11590 show_bgp_rsclient_cmd,
11591 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11592 SHOW_STR
11593 BGP_STR
11594 "Information about Route Server Client\n"
11595 NEIGHBOR_ADDR_STR)
11596
Michael Lambert95cbbd22010-07-23 14:43:04 -040011597DEFUN (show_bgp_view_ipv6_safi_rsclient,
11598 show_bgp_view_ipv6_safi_rsclient_cmd,
11599 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11600 SHOW_STR
11601 BGP_STR
11602 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011603 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011604 "Address family\n"
11605 "Address Family modifier\n"
11606 "Address Family modifier\n"
11607 "Information about Route Server Client\n"
11608 NEIGHBOR_ADDR_STR)
11609{
11610 struct bgp_table *table;
11611 struct peer *peer;
11612 safi_t safi;
11613
11614 if (argc == 3) {
11615 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11616 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11617 } else {
11618 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11619 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11620 }
11621
11622 if (! peer)
11623 return CMD_WARNING;
11624
11625 if (! peer->afc[AFI_IP6][safi])
11626 {
11627 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11628 VTY_NEWLINE);
11629 return CMD_WARNING;
11630 }
11631
11632 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11633 PEER_FLAG_RSERVER_CLIENT))
11634 {
11635 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11636 VTY_NEWLINE);
11637 return CMD_WARNING;
11638 }
11639
11640 table = peer->rib[AFI_IP6][safi];
11641
11642 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11643}
11644
11645ALIAS (show_bgp_view_ipv6_safi_rsclient,
11646 show_bgp_ipv6_safi_rsclient_cmd,
11647 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11648 SHOW_STR
11649 BGP_STR
11650 "Address family\n"
11651 "Address Family modifier\n"
11652 "Address Family modifier\n"
11653 "Information about Route Server Client\n"
11654 NEIGHBOR_ADDR_STR)
11655
paulfee0f4c2004-09-13 05:12:46 +000011656DEFUN (show_bgp_view_rsclient_route,
11657 show_bgp_view_rsclient_route_cmd,
11658 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11659 SHOW_STR
11660 BGP_STR
11661 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011662 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011663 "Information about Route Server Client\n"
11664 NEIGHBOR_ADDR_STR
11665 "Network in the BGP routing table to display\n")
11666{
11667 struct bgp *bgp;
11668 struct peer *peer;
11669
11670 /* BGP structure lookup. */
11671 if (argc == 3)
11672 {
11673 bgp = bgp_lookup_by_name (argv[0]);
11674 if (bgp == NULL)
11675 {
11676 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11677 return CMD_WARNING;
11678 }
11679 }
11680 else
11681 {
11682 bgp = bgp_get_default ();
11683 if (bgp == NULL)
11684 {
11685 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11686 return CMD_WARNING;
11687 }
11688 }
11689
11690 if (argc == 3)
11691 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11692 else
11693 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11694
11695 if (! peer)
11696 return CMD_WARNING;
11697
11698 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11699 {
11700 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11701 VTY_NEWLINE);
11702 return CMD_WARNING;
11703 }
11704
11705 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11706 PEER_FLAG_RSERVER_CLIENT))
11707 {
11708 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11709 VTY_NEWLINE);
11710 return CMD_WARNING;
11711 }
11712
11713 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11714 (argc == 3) ? argv[2] : argv[1],
11715 AFI_IP6, SAFI_UNICAST, NULL, 0);
11716}
11717
11718ALIAS (show_bgp_view_rsclient_route,
11719 show_bgp_rsclient_route_cmd,
11720 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11721 SHOW_STR
11722 BGP_STR
11723 "Information about Route Server Client\n"
11724 NEIGHBOR_ADDR_STR
11725 "Network in the BGP routing table to display\n")
11726
Michael Lambert95cbbd22010-07-23 14:43:04 -040011727DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11728 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11729 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11730 SHOW_STR
11731 BGP_STR
11732 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011733 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011734 "Address family\n"
11735 "Address Family modifier\n"
11736 "Address Family modifier\n"
11737 "Information about Route Server Client\n"
11738 NEIGHBOR_ADDR_STR
11739 "Network in the BGP routing table to display\n")
11740{
11741 struct bgp *bgp;
11742 struct peer *peer;
11743 safi_t safi;
11744
11745 /* BGP structure lookup. */
11746 if (argc == 4)
11747 {
11748 bgp = bgp_lookup_by_name (argv[0]);
11749 if (bgp == NULL)
11750 {
11751 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11752 return CMD_WARNING;
11753 }
11754 }
11755 else
11756 {
11757 bgp = bgp_get_default ();
11758 if (bgp == NULL)
11759 {
11760 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11761 return CMD_WARNING;
11762 }
11763 }
11764
11765 if (argc == 4) {
11766 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11767 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11768 } else {
11769 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11770 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11771 }
11772
11773 if (! peer)
11774 return CMD_WARNING;
11775
11776 if (! peer->afc[AFI_IP6][safi])
11777 {
11778 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11779 VTY_NEWLINE);
11780 return CMD_WARNING;
11781}
11782
11783 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11784 PEER_FLAG_RSERVER_CLIENT))
11785 {
11786 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11787 VTY_NEWLINE);
11788 return CMD_WARNING;
11789 }
11790
11791 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11792 (argc == 4) ? argv[3] : argv[2],
11793 AFI_IP6, safi, NULL, 0);
11794}
11795
11796ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11797 show_bgp_ipv6_safi_rsclient_route_cmd,
11798 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11799 SHOW_STR
11800 BGP_STR
11801 "Address family\n"
11802 "Address Family modifier\n"
11803 "Address Family modifier\n"
11804 "Information about Route Server Client\n"
11805 NEIGHBOR_ADDR_STR
11806 "Network in the BGP routing table to display\n")
11807
paulfee0f4c2004-09-13 05:12:46 +000011808DEFUN (show_bgp_view_rsclient_prefix,
11809 show_bgp_view_rsclient_prefix_cmd,
11810 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11811 SHOW_STR
11812 BGP_STR
11813 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011814 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011815 "Information about Route Server Client\n"
11816 NEIGHBOR_ADDR_STR
11817 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11818{
11819 struct bgp *bgp;
11820 struct peer *peer;
11821
11822 /* BGP structure lookup. */
11823 if (argc == 3)
11824 {
11825 bgp = bgp_lookup_by_name (argv[0]);
11826 if (bgp == NULL)
11827 {
11828 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11829 return CMD_WARNING;
11830 }
11831 }
11832 else
11833 {
11834 bgp = bgp_get_default ();
11835 if (bgp == NULL)
11836 {
11837 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11838 return CMD_WARNING;
11839 }
11840 }
11841
11842 if (argc == 3)
11843 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11844 else
11845 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11846
11847 if (! peer)
11848 return CMD_WARNING;
11849
11850 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11851 {
11852 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11853 VTY_NEWLINE);
11854 return CMD_WARNING;
11855 }
11856
11857 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11858 PEER_FLAG_RSERVER_CLIENT))
11859 {
11860 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11861 VTY_NEWLINE);
11862 return CMD_WARNING;
11863 }
11864
11865 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11866 (argc == 3) ? argv[2] : argv[1],
11867 AFI_IP6, SAFI_UNICAST, NULL, 1);
11868}
11869
11870ALIAS (show_bgp_view_rsclient_prefix,
11871 show_bgp_rsclient_prefix_cmd,
11872 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11873 SHOW_STR
11874 BGP_STR
11875 "Information about Route Server Client\n"
11876 NEIGHBOR_ADDR_STR
11877 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11878
Michael Lambert95cbbd22010-07-23 14:43:04 -040011879DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11880 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11881 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11882 SHOW_STR
11883 BGP_STR
11884 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011885 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011886 "Address family\n"
11887 "Address Family modifier\n"
11888 "Address Family modifier\n"
11889 "Information about Route Server Client\n"
11890 NEIGHBOR_ADDR_STR
11891 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11892{
11893 struct bgp *bgp;
11894 struct peer *peer;
11895 safi_t safi;
11896
11897 /* BGP structure lookup. */
11898 if (argc == 4)
11899 {
11900 bgp = bgp_lookup_by_name (argv[0]);
11901 if (bgp == NULL)
11902 {
11903 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11904 return CMD_WARNING;
11905 }
11906 }
11907 else
11908 {
11909 bgp = bgp_get_default ();
11910 if (bgp == NULL)
11911 {
11912 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11913 return CMD_WARNING;
11914 }
11915 }
11916
11917 if (argc == 4) {
11918 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11919 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11920 } else {
11921 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11922 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11923 }
11924
11925 if (! peer)
11926 return CMD_WARNING;
11927
11928 if (! peer->afc[AFI_IP6][safi])
11929 {
11930 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11931 VTY_NEWLINE);
11932 return CMD_WARNING;
11933}
11934
11935 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11936 PEER_FLAG_RSERVER_CLIENT))
11937{
11938 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11939 VTY_NEWLINE);
11940 return CMD_WARNING;
11941 }
11942
11943 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11944 (argc == 4) ? argv[3] : argv[2],
11945 AFI_IP6, safi, NULL, 1);
11946}
11947
11948ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11949 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11950 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11951 SHOW_STR
11952 BGP_STR
11953 "Address family\n"
11954 "Address Family modifier\n"
11955 "Address Family modifier\n"
11956 "Information about Route Server Client\n"
11957 NEIGHBOR_ADDR_STR
11958 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11959
paul718e3742002-12-13 20:15:29 +000011960#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011961
paul718e3742002-12-13 20:15:29 +000011962struct bgp_table *bgp_distance_table;
11963
11964struct bgp_distance
11965{
11966 /* Distance value for the IP source prefix. */
11967 u_char distance;
11968
11969 /* Name of the access-list to be matched. */
11970 char *access_list;
11971};
11972
paul94f2b392005-06-28 12:44:16 +000011973static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011974bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011975{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011976 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011977}
11978
paul94f2b392005-06-28 12:44:16 +000011979static void
paul718e3742002-12-13 20:15:29 +000011980bgp_distance_free (struct bgp_distance *bdistance)
11981{
11982 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11983}
11984
paul94f2b392005-06-28 12:44:16 +000011985static int
paulfd79ac92004-10-13 05:06:08 +000011986bgp_distance_set (struct vty *vty, const char *distance_str,
11987 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011988{
11989 int ret;
11990 struct prefix_ipv4 p;
11991 u_char distance;
11992 struct bgp_node *rn;
11993 struct bgp_distance *bdistance;
11994
11995 ret = str2prefix_ipv4 (ip_str, &p);
11996 if (ret == 0)
11997 {
11998 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11999 return CMD_WARNING;
12000 }
12001
12002 distance = atoi (distance_str);
12003
12004 /* Get BGP distance node. */
12005 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
12006 if (rn->info)
12007 {
12008 bdistance = rn->info;
12009 bgp_unlock_node (rn);
12010 }
12011 else
12012 {
12013 bdistance = bgp_distance_new ();
12014 rn->info = bdistance;
12015 }
12016
12017 /* Set distance value. */
12018 bdistance->distance = distance;
12019
12020 /* Reset access-list configuration. */
12021 if (bdistance->access_list)
12022 {
12023 free (bdistance->access_list);
12024 bdistance->access_list = NULL;
12025 }
12026 if (access_list_str)
12027 bdistance->access_list = strdup (access_list_str);
12028
12029 return CMD_SUCCESS;
12030}
12031
paul94f2b392005-06-28 12:44:16 +000012032static int
paulfd79ac92004-10-13 05:06:08 +000012033bgp_distance_unset (struct vty *vty, const char *distance_str,
12034 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000012035{
12036 int ret;
12037 struct prefix_ipv4 p;
12038 u_char distance;
12039 struct bgp_node *rn;
12040 struct bgp_distance *bdistance;
12041
12042 ret = str2prefix_ipv4 (ip_str, &p);
12043 if (ret == 0)
12044 {
12045 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12046 return CMD_WARNING;
12047 }
12048
12049 distance = atoi (distance_str);
12050
12051 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
12052 if (! rn)
12053 {
12054 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
12055 return CMD_WARNING;
12056 }
12057
12058 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010012059
12060 if (bdistance->distance != distance)
12061 {
12062 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
12063 return CMD_WARNING;
12064 }
12065
paul718e3742002-12-13 20:15:29 +000012066 if (bdistance->access_list)
12067 free (bdistance->access_list);
12068 bgp_distance_free (bdistance);
12069
12070 rn->info = NULL;
12071 bgp_unlock_node (rn);
12072 bgp_unlock_node (rn);
12073
12074 return CMD_SUCCESS;
12075}
12076
paul718e3742002-12-13 20:15:29 +000012077/* Apply BGP information to distance method. */
12078u_char
12079bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
12080{
12081 struct bgp_node *rn;
12082 struct prefix_ipv4 q;
12083 struct peer *peer;
12084 struct bgp_distance *bdistance;
12085 struct access_list *alist;
12086 struct bgp_static *bgp_static;
12087
12088 if (! bgp)
12089 return 0;
12090
12091 if (p->family != AF_INET)
12092 return 0;
12093
12094 peer = rinfo->peer;
12095
12096 if (peer->su.sa.sa_family != AF_INET)
12097 return 0;
12098
12099 memset (&q, 0, sizeof (struct prefix_ipv4));
12100 q.family = AF_INET;
12101 q.prefix = peer->su.sin.sin_addr;
12102 q.prefixlen = IPV4_MAX_BITLEN;
12103
12104 /* Check source address. */
12105 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
12106 if (rn)
12107 {
12108 bdistance = rn->info;
12109 bgp_unlock_node (rn);
12110
12111 if (bdistance->access_list)
12112 {
12113 alist = access_list_lookup (AFI_IP, bdistance->access_list);
12114 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
12115 return bdistance->distance;
12116 }
12117 else
12118 return bdistance->distance;
12119 }
12120
12121 /* Backdoor check. */
12122 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
12123 if (rn)
12124 {
12125 bgp_static = rn->info;
12126 bgp_unlock_node (rn);
12127
12128 if (bgp_static->backdoor)
12129 {
12130 if (bgp->distance_local)
12131 return bgp->distance_local;
12132 else
12133 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12134 }
12135 }
12136
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000012137 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000012138 {
12139 if (bgp->distance_ebgp)
12140 return bgp->distance_ebgp;
12141 return ZEBRA_EBGP_DISTANCE_DEFAULT;
12142 }
12143 else
12144 {
12145 if (bgp->distance_ibgp)
12146 return bgp->distance_ibgp;
12147 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12148 }
12149}
12150
12151DEFUN (bgp_distance,
12152 bgp_distance_cmd,
12153 "distance bgp <1-255> <1-255> <1-255>",
12154 "Define an administrative distance\n"
12155 "BGP distance\n"
12156 "Distance for routes external to the AS\n"
12157 "Distance for routes internal to the AS\n"
12158 "Distance for local routes\n")
12159{
12160 struct bgp *bgp;
12161
12162 bgp = vty->index;
12163
12164 bgp->distance_ebgp = atoi (argv[0]);
12165 bgp->distance_ibgp = atoi (argv[1]);
12166 bgp->distance_local = atoi (argv[2]);
12167 return CMD_SUCCESS;
12168}
12169
12170DEFUN (no_bgp_distance,
12171 no_bgp_distance_cmd,
12172 "no distance bgp <1-255> <1-255> <1-255>",
12173 NO_STR
12174 "Define an administrative distance\n"
12175 "BGP distance\n"
12176 "Distance for routes external to the AS\n"
12177 "Distance for routes internal to the AS\n"
12178 "Distance for local routes\n")
12179{
12180 struct bgp *bgp;
12181
12182 bgp = vty->index;
12183
12184 bgp->distance_ebgp= 0;
12185 bgp->distance_ibgp = 0;
12186 bgp->distance_local = 0;
12187 return CMD_SUCCESS;
12188}
12189
12190ALIAS (no_bgp_distance,
12191 no_bgp_distance2_cmd,
12192 "no distance bgp",
12193 NO_STR
12194 "Define an administrative distance\n"
12195 "BGP distance\n")
12196
12197DEFUN (bgp_distance_source,
12198 bgp_distance_source_cmd,
12199 "distance <1-255> A.B.C.D/M",
12200 "Define an administrative distance\n"
12201 "Administrative distance\n"
12202 "IP source prefix\n")
12203{
12204 bgp_distance_set (vty, argv[0], argv[1], NULL);
12205 return CMD_SUCCESS;
12206}
12207
12208DEFUN (no_bgp_distance_source,
12209 no_bgp_distance_source_cmd,
12210 "no distance <1-255> A.B.C.D/M",
12211 NO_STR
12212 "Define an administrative distance\n"
12213 "Administrative distance\n"
12214 "IP source prefix\n")
12215{
12216 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12217 return CMD_SUCCESS;
12218}
12219
12220DEFUN (bgp_distance_source_access_list,
12221 bgp_distance_source_access_list_cmd,
12222 "distance <1-255> A.B.C.D/M WORD",
12223 "Define an administrative distance\n"
12224 "Administrative distance\n"
12225 "IP source prefix\n"
12226 "Access list name\n")
12227{
12228 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12229 return CMD_SUCCESS;
12230}
12231
12232DEFUN (no_bgp_distance_source_access_list,
12233 no_bgp_distance_source_access_list_cmd,
12234 "no distance <1-255> A.B.C.D/M WORD",
12235 NO_STR
12236 "Define an administrative distance\n"
12237 "Administrative distance\n"
12238 "IP source prefix\n"
12239 "Access list name\n")
12240{
12241 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12242 return CMD_SUCCESS;
12243}
David Lamparter6b0655a2014-06-04 06:53:35 +020012244
paul718e3742002-12-13 20:15:29 +000012245DEFUN (bgp_damp_set,
12246 bgp_damp_set_cmd,
12247 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12248 "BGP Specific commands\n"
12249 "Enable route-flap dampening\n"
12250 "Half-life time for the penalty\n"
12251 "Value to start reusing a route\n"
12252 "Value to start suppressing a route\n"
12253 "Maximum duration to suppress a stable route\n")
12254{
12255 struct bgp *bgp;
12256 int half = DEFAULT_HALF_LIFE * 60;
12257 int reuse = DEFAULT_REUSE;
12258 int suppress = DEFAULT_SUPPRESS;
12259 int max = 4 * half;
12260
12261 if (argc == 4)
12262 {
12263 half = atoi (argv[0]) * 60;
12264 reuse = atoi (argv[1]);
12265 suppress = atoi (argv[2]);
12266 max = atoi (argv[3]) * 60;
12267 }
12268 else if (argc == 1)
12269 {
12270 half = atoi (argv[0]) * 60;
12271 max = 4 * half;
12272 }
12273
12274 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012275
12276 if (suppress < reuse)
12277 {
12278 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12279 VTY_NEWLINE);
12280 return 0;
12281 }
12282
paul718e3742002-12-13 20:15:29 +000012283 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12284 half, reuse, suppress, max);
12285}
12286
12287ALIAS (bgp_damp_set,
12288 bgp_damp_set2_cmd,
12289 "bgp dampening <1-45>",
12290 "BGP Specific commands\n"
12291 "Enable route-flap dampening\n"
12292 "Half-life time for the penalty\n")
12293
12294ALIAS (bgp_damp_set,
12295 bgp_damp_set3_cmd,
12296 "bgp dampening",
12297 "BGP Specific commands\n"
12298 "Enable route-flap dampening\n")
12299
12300DEFUN (bgp_damp_unset,
12301 bgp_damp_unset_cmd,
12302 "no bgp dampening",
12303 NO_STR
12304 "BGP Specific commands\n"
12305 "Enable route-flap dampening\n")
12306{
12307 struct bgp *bgp;
12308
12309 bgp = vty->index;
12310 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12311}
12312
12313ALIAS (bgp_damp_unset,
12314 bgp_damp_unset2_cmd,
12315 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12316 NO_STR
12317 "BGP Specific commands\n"
12318 "Enable route-flap dampening\n"
12319 "Half-life time for the penalty\n"
12320 "Value to start reusing a route\n"
12321 "Value to start suppressing a route\n"
12322 "Maximum duration to suppress a stable route\n")
12323
12324DEFUN (show_ip_bgp_dampened_paths,
12325 show_ip_bgp_dampened_paths_cmd,
12326 "show ip bgp dampened-paths",
12327 SHOW_STR
12328 IP_STR
12329 BGP_STR
12330 "Display paths suppressed due to dampening\n")
12331{
ajs5a646652004-11-05 01:25:55 +000012332 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12333 NULL);
paul718e3742002-12-13 20:15:29 +000012334}
12335
Balaji3921cc52015-05-16 23:12:17 +053012336ALIAS (show_ip_bgp_dampened_paths,
12337 show_ip_bgp_damp_dampened_paths_cmd,
12338 "show ip bgp dampening dampened-paths",
12339 SHOW_STR
12340 IP_STR
12341 BGP_STR
12342 "Display detailed information about dampening\n"
12343 "Display paths suppressed due to dampening\n")
12344
paul718e3742002-12-13 20:15:29 +000012345DEFUN (show_ip_bgp_flap_statistics,
12346 show_ip_bgp_flap_statistics_cmd,
12347 "show ip bgp flap-statistics",
12348 SHOW_STR
12349 IP_STR
12350 BGP_STR
12351 "Display flap statistics of routes\n")
12352{
ajs5a646652004-11-05 01:25:55 +000012353 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12354 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012355}
David Lamparter6b0655a2014-06-04 06:53:35 +020012356
Balaji3921cc52015-05-16 23:12:17 +053012357ALIAS (show_ip_bgp_flap_statistics,
12358 show_ip_bgp_damp_flap_statistics_cmd,
12359 "show ip bgp dampening flap-statistics",
12360 SHOW_STR
12361 IP_STR
12362 BGP_STR
12363 "Display detailed information about dampening\n"
12364 "Display flap statistics of routes\n")
12365
paul718e3742002-12-13 20:15:29 +000012366/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012367static int
paulfd79ac92004-10-13 05:06:08 +000012368bgp_clear_damp_route (struct vty *vty, const char *view_name,
12369 const char *ip_str, afi_t afi, safi_t safi,
12370 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012371{
12372 int ret;
12373 struct prefix match;
12374 struct bgp_node *rn;
12375 struct bgp_node *rm;
12376 struct bgp_info *ri;
12377 struct bgp_info *ri_temp;
12378 struct bgp *bgp;
12379 struct bgp_table *table;
12380
12381 /* BGP structure lookup. */
12382 if (view_name)
12383 {
12384 bgp = bgp_lookup_by_name (view_name);
12385 if (bgp == NULL)
12386 {
12387 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12388 return CMD_WARNING;
12389 }
12390 }
12391 else
12392 {
12393 bgp = bgp_get_default ();
12394 if (bgp == NULL)
12395 {
12396 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12397 return CMD_WARNING;
12398 }
12399 }
12400
12401 /* Check IP address argument. */
12402 ret = str2prefix (ip_str, &match);
12403 if (! ret)
12404 {
12405 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12406 return CMD_WARNING;
12407 }
12408
12409 match.family = afi2family (afi);
12410
12411 if (safi == SAFI_MPLS_VPN)
12412 {
12413 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12414 {
12415 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12416 continue;
12417
12418 if ((table = rn->info) != NULL)
12419 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012420 {
12421 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12422 {
12423 ri = rm->info;
12424 while (ri)
12425 {
12426 if (ri->extra && ri->extra->damp_info)
12427 {
12428 ri_temp = ri->next;
12429 bgp_damp_info_free (ri->extra->damp_info, 1);
12430 ri = ri_temp;
12431 }
12432 else
12433 ri = ri->next;
12434 }
12435 }
12436
12437 bgp_unlock_node (rm);
12438 }
paul718e3742002-12-13 20:15:29 +000012439 }
12440 }
12441 else
12442 {
12443 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012444 {
12445 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12446 {
12447 ri = rn->info;
12448 while (ri)
12449 {
12450 if (ri->extra && ri->extra->damp_info)
12451 {
12452 ri_temp = ri->next;
12453 bgp_damp_info_free (ri->extra->damp_info, 1);
12454 ri = ri_temp;
12455 }
12456 else
12457 ri = ri->next;
12458 }
12459 }
12460
12461 bgp_unlock_node (rn);
12462 }
paul718e3742002-12-13 20:15:29 +000012463 }
12464
12465 return CMD_SUCCESS;
12466}
12467
12468DEFUN (clear_ip_bgp_dampening,
12469 clear_ip_bgp_dampening_cmd,
12470 "clear ip bgp dampening",
12471 CLEAR_STR
12472 IP_STR
12473 BGP_STR
12474 "Clear route flap dampening information\n")
12475{
12476 bgp_damp_info_clean ();
12477 return CMD_SUCCESS;
12478}
12479
12480DEFUN (clear_ip_bgp_dampening_prefix,
12481 clear_ip_bgp_dampening_prefix_cmd,
12482 "clear ip bgp dampening A.B.C.D/M",
12483 CLEAR_STR
12484 IP_STR
12485 BGP_STR
12486 "Clear route flap dampening information\n"
12487 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12488{
12489 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12490 SAFI_UNICAST, NULL, 1);
12491}
12492
12493DEFUN (clear_ip_bgp_dampening_address,
12494 clear_ip_bgp_dampening_address_cmd,
12495 "clear ip bgp dampening A.B.C.D",
12496 CLEAR_STR
12497 IP_STR
12498 BGP_STR
12499 "Clear route flap dampening information\n"
12500 "Network to clear damping information\n")
12501{
12502 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12503 SAFI_UNICAST, NULL, 0);
12504}
12505
12506DEFUN (clear_ip_bgp_dampening_address_mask,
12507 clear_ip_bgp_dampening_address_mask_cmd,
12508 "clear ip bgp dampening A.B.C.D A.B.C.D",
12509 CLEAR_STR
12510 IP_STR
12511 BGP_STR
12512 "Clear route flap dampening information\n"
12513 "Network to clear damping information\n"
12514 "Network mask\n")
12515{
12516 int ret;
12517 char prefix_str[BUFSIZ];
12518
12519 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12520 if (! ret)
12521 {
12522 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12523 return CMD_WARNING;
12524 }
12525
12526 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12527 SAFI_UNICAST, NULL, 0);
12528}
David Lamparter6b0655a2014-06-04 06:53:35 +020012529
paul94f2b392005-06-28 12:44:16 +000012530static int
paul718e3742002-12-13 20:15:29 +000012531bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12532 afi_t afi, safi_t safi, int *write)
12533{
12534 struct bgp_node *prn;
12535 struct bgp_node *rn;
12536 struct bgp_table *table;
12537 struct prefix *p;
12538 struct prefix_rd *prd;
12539 struct bgp_static *bgp_static;
12540 u_int32_t label;
12541 char buf[SU_ADDRSTRLEN];
12542 char rdbuf[RD_ADDRSTRLEN];
12543
12544 /* Network configuration. */
12545 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12546 if ((table = prn->info) != NULL)
12547 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12548 if ((bgp_static = rn->info) != NULL)
12549 {
12550 p = &rn->p;
12551 prd = (struct prefix_rd *) &prn->p;
12552
12553 /* "address-family" display. */
12554 bgp_config_write_family_header (vty, afi, safi, write);
12555
12556 /* "network" configuration display. */
12557 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12558 label = decode_label (bgp_static->tag);
12559
12560 vty_out (vty, " network %s/%d rd %s tag %d",
12561 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12562 p->prefixlen,
12563 rdbuf, label);
12564 vty_out (vty, "%s", VTY_NEWLINE);
12565 }
12566 return 0;
12567}
12568
12569/* Configuration of static route announcement and aggregate
12570 information. */
12571int
12572bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12573 afi_t afi, safi_t safi, int *write)
12574{
12575 struct bgp_node *rn;
12576 struct prefix *p;
12577 struct bgp_static *bgp_static;
12578 struct bgp_aggregate *bgp_aggregate;
12579 char buf[SU_ADDRSTRLEN];
12580
12581 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12582 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12583
12584 /* Network configuration. */
12585 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12586 if ((bgp_static = rn->info) != NULL)
12587 {
12588 p = &rn->p;
12589
12590 /* "address-family" display. */
12591 bgp_config_write_family_header (vty, afi, safi, write);
12592
12593 /* "network" configuration display. */
12594 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12595 {
12596 u_int32_t destination;
12597 struct in_addr netmask;
12598
12599 destination = ntohl (p->u.prefix4.s_addr);
12600 masklen2ip (p->prefixlen, &netmask);
12601 vty_out (vty, " network %s",
12602 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12603
12604 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12605 || (IN_CLASSB (destination) && p->prefixlen == 16)
12606 || (IN_CLASSA (destination) && p->prefixlen == 8)
12607 || p->u.prefix4.s_addr == 0)
12608 {
12609 /* Natural mask is not display. */
12610 }
12611 else
12612 vty_out (vty, " mask %s", inet_ntoa (netmask));
12613 }
12614 else
12615 {
12616 vty_out (vty, " network %s/%d",
12617 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12618 p->prefixlen);
12619 }
12620
12621 if (bgp_static->rmap.name)
12622 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012623 else
12624 {
12625 if (bgp_static->backdoor)
12626 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012627 }
paul718e3742002-12-13 20:15:29 +000012628
12629 vty_out (vty, "%s", VTY_NEWLINE);
12630 }
12631
12632 /* Aggregate-address configuration. */
12633 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12634 if ((bgp_aggregate = rn->info) != NULL)
12635 {
12636 p = &rn->p;
12637
12638 /* "address-family" display. */
12639 bgp_config_write_family_header (vty, afi, safi, write);
12640
12641 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12642 {
12643 struct in_addr netmask;
12644
12645 masklen2ip (p->prefixlen, &netmask);
12646 vty_out (vty, " aggregate-address %s %s",
12647 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12648 inet_ntoa (netmask));
12649 }
12650 else
12651 {
12652 vty_out (vty, " aggregate-address %s/%d",
12653 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12654 p->prefixlen);
12655 }
12656
12657 if (bgp_aggregate->as_set)
12658 vty_out (vty, " as-set");
12659
12660 if (bgp_aggregate->summary_only)
12661 vty_out (vty, " summary-only");
12662
12663 vty_out (vty, "%s", VTY_NEWLINE);
12664 }
12665
12666 return 0;
12667}
12668
12669int
12670bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12671{
12672 struct bgp_node *rn;
12673 struct bgp_distance *bdistance;
12674
12675 /* Distance configuration. */
12676 if (bgp->distance_ebgp
12677 && bgp->distance_ibgp
12678 && bgp->distance_local
12679 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12680 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12681 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12682 vty_out (vty, " distance bgp %d %d %d%s",
12683 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12684 VTY_NEWLINE);
12685
12686 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12687 if ((bdistance = rn->info) != NULL)
12688 {
12689 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12690 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12691 bdistance->access_list ? bdistance->access_list : "",
12692 VTY_NEWLINE);
12693 }
12694
12695 return 0;
12696}
12697
12698/* Allocate routing table structure and install commands. */
12699void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012700bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012701{
12702 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012703 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012704
12705 /* IPv4 BGP commands. */
12706 install_element (BGP_NODE, &bgp_network_cmd);
12707 install_element (BGP_NODE, &bgp_network_mask_cmd);
12708 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12709 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12710 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12711 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12712 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12713 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12714 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12715 install_element (BGP_NODE, &no_bgp_network_cmd);
12716 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12717 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12718 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12719 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12720 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12721 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12722 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12723 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12724
12725 install_element (BGP_NODE, &aggregate_address_cmd);
12726 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12727 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12728 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12729 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12730 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12731 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12732 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12733 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12734 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12735 install_element (BGP_NODE, &no_aggregate_address_cmd);
12736 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12737 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12738 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12739 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12740 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12741 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12742 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12743 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12744 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12745
12746 /* IPv4 unicast configuration. */
12747 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12748 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12749 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12750 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12751 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12752 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012753 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012754 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12755 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12756 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12757 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12758 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012759
paul718e3742002-12-13 20:15:29 +000012760 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12761 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12762 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12763 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12764 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12765 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12766 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12767 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12768 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12769 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12770 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12771 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12772 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12773 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12774 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12775 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12776 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12777 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12778 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12779 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12780
12781 /* IPv4 multicast configuration. */
12782 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12783 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12784 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12785 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12786 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12787 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12788 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12789 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12790 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12791 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12792 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12793 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12794 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12795 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12796 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12797 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12798 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12799 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12800 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12801 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12802 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12803 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12804 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12805 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12806 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12807 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12808 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12809 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12810 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12811 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12812 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12813 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12814
12815 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12816 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012817 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012818 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12819 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012820 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012821 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12822 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12823 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12824 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012825 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012826 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12827 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12828 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12829 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12830 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12831 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12832 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12833 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12834 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12835 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12836 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12837 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12838 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12839 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12840 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12841 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12842 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12843 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12844 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12845 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12846 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12847 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12848 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12849 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12850 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012851 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12852 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12853 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12854 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12855 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012856 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12857 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12858 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12859 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12860 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12861 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12862 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12863 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12864 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12865 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12866 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12867 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12868 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12869 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12870 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12871 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12872 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12873 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012874 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012875 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12876 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12877 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12878 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012879 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012880 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012881 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012882 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012883 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012884 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012885 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012886 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12887 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012888 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012889 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12890 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012891 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012892 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012893 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012894 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012895 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012896 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012897 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012898 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12899 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012900 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012901 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012902 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012903 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012904 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012905 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012906 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12907 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012908 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012909 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012910 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012911 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012912 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012913 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012914
12915 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12916 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12917 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012918 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012919 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12920 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12921 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012922 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012923 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12924 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12925 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12926 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12927 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12928 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12929 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12930 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12931 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12932 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12933 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12934 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012935 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12936 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12937 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12938 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12939 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012940 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12941 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12942 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12943 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12944 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12945 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12946 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12947 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12948 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012949 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012950 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012951 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012952 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012953 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012954 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012955 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012956
12957 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12958 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012959 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012960 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12961 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012962 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012963 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12964 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12965 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12966 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012967 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012968 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12969 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12970 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12971 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12972 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12973 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12974 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12975 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12976 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12977 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12978 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12979 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12980 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12981 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12982 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12983 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12984 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12985 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12986 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12987 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12988 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12989 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12990 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12991 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12992 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012993 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12994 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12995 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12996 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12997 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012998 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12999 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
13000 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
13001 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
13002 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13003 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13004 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13005 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13006 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
13007 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13008 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
13009 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13010 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
13011 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13012 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
13013 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
13014 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
13015 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013016 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013017 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
13018 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13019 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13020 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013021 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000013022 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013023 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000013024 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013025 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000013026 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013027 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000013028 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
13029 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013030 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000013031 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013032 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000013033 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013034 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000013035 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013036 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
13037 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000013038 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013039 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000013040 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013041 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000013042 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
13043 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013044 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013045 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013046 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013047 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013048 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013049 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010013050 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13051 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013052 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013053 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013054 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013055 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013056 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013057 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013058
13059 /* BGP dampening clear commands */
13060 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13061 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13062 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13063 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13064
Paul Jakmaff7924f2006-09-04 01:10:36 +000013065 /* prefix count */
13066 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
13067 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
13068 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000013069#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000013070 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13071
paul718e3742002-12-13 20:15:29 +000013072 /* New config IPv6 BGP commands. */
13073 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13074 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
13075 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13076 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13077
13078 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13079 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13080 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13081 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
13082
G.Balaji73bfe0b2011-09-23 22:36:20 +053013083 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13084 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
13085
paul718e3742002-12-13 20:15:29 +000013086 /* Old config IPv6 BGP commands. */
13087 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13088 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13089
13090 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13091 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13092 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13093 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13094
13095 install_element (VIEW_NODE, &show_bgp_cmd);
13096 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013097 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013098 install_element (VIEW_NODE, &show_bgp_route_cmd);
13099 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013100 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013101 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
13102 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013103 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013104 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
13105 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
13106 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
13107 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
13108 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
13109 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
13110 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
13111 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
13112 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
13113 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
13114 install_element (VIEW_NODE, &show_bgp_community_cmd);
13115 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
13116 install_element (VIEW_NODE, &show_bgp_community2_cmd);
13117 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
13118 install_element (VIEW_NODE, &show_bgp_community3_cmd);
13119 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
13120 install_element (VIEW_NODE, &show_bgp_community4_cmd);
13121 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
13122 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
13123 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
13124 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
13125 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
13126 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
13127 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
13128 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
13129 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13130 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
13131 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
13132 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
13133 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13134 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
13135 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13136 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
13137 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13138 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
13139 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13140 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
13141 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13142 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13143 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013144 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
13145 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13146 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
13147 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013148 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013149 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013150 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013151 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013152 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013153 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013154 install_element (VIEW_NODE, &show_bgp_view_cmd);
13155 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
13156 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
13157 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
13158 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
13159 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
13160 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13161 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13162 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13163 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13164 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
13165 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13166 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13167 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13168 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
13169 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13170 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
13171 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013172 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013173 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013174 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013175 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013176 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013177 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013178
13179 /* Restricted:
13180 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13181 */
13182 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
13183 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013184 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013185 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
13186 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013187 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013188 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
13189 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
13190 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
13191 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
13192 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
13193 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
13194 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
13195 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
13196 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
13197 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
13198 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
13199 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13200 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13201 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13202 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13203 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13204 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013205 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013206 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013207 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013208 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
13209 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13210 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13211 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13212 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13213 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13214 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013215 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013216 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013217 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013218
13219 install_element (ENABLE_NODE, &show_bgp_cmd);
13220 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013221 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013222 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13223 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013224 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013225 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13226 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013227 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013228 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13229 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13230 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13231 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13232 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13233 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13234 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13235 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13236 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13237 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13238 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13239 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13240 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13241 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13242 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13243 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13244 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13245 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13246 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13247 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13248 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13249 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13250 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13251 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13252 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13253 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13254 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13255 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13256 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13257 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13258 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13259 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13260 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13261 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13262 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13263 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13264 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13265 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13266 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13267 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013268 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13269 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13270 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13271 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013272 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013273 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013274 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013275 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013276 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013277 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013278 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13279 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13280 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13281 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13282 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13283 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13284 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13285 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13286 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13287 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13288 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13289 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13290 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13291 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13292 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13293 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13294 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13295 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013296 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013297 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013298 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013299 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013300 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013301 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013302
13303 /* Statistics */
13304 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
13305 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
13306 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
13307 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
13308
paul718e3742002-12-13 20:15:29 +000013309 /* old command */
13310 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13311 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13312 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13313 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13314 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13315 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13316 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13317 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13318 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13319 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13320 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13321 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13322 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13323 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13324 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13325 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13326 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13327 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13328 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13329 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13330 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13331 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13332 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13333 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13334 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13335 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13336 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13337 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13338 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13339 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13340 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13341 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13342 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13343 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13344 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13345 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013346
paul718e3742002-12-13 20:15:29 +000013347 /* old command */
13348 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13349 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13350 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13351 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13352 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13353 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13354 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13355 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13356 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13357 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13358 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13359 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13360 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13361 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13362 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13363 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13364 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13365 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13366 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13367 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13368 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13369 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13370 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13371 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13372 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13373 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13374 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13375 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13376 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13377 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13378 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13379 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13380 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13381 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13382 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13383 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13384
13385 /* old command */
13386 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13387 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13388 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13389 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13390
13391 /* old command */
13392 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13393 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13394 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13395 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13396
13397 /* old command */
13398 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13399 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13400 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13401 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13402#endif /* HAVE_IPV6 */
13403
13404 install_element (BGP_NODE, &bgp_distance_cmd);
13405 install_element (BGP_NODE, &no_bgp_distance_cmd);
13406 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13407 install_element (BGP_NODE, &bgp_distance_source_cmd);
13408 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13409 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13410 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13411
13412 install_element (BGP_NODE, &bgp_damp_set_cmd);
13413 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13414 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13415 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13416 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13417 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13418 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13419 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13420 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13421 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013422
13423 /* Deprecated AS-Pathlimit commands */
13424 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13425 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13426 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13427 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13428 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13429 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13430
13431 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13432 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13433 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13434 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13435 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13436 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13437
13438 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13439 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13440 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13441 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13442 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13443 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13444
13445 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13446 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13447 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13448 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13449 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13450 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13451
13452 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13453 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13454 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13455 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13456 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13457 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13458
13459 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13460 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13461 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13462 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13463 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13464 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013465
13466#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013467 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13468 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013469#endif
paul718e3742002-12-13 20:15:29 +000013470}
Chris Caputo228da422009-07-18 05:44:03 +000013471
13472void
13473bgp_route_finish (void)
13474{
13475 bgp_table_unlock (bgp_distance_table);
13476 bgp_distance_table = NULL;
13477}