blob: a780e9de21254873284c13ba09961c2105fb60a2 [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
Lou Berger298cc2f2016-01-12 13:42:02 -050074 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000075 {
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
Lou Berger298cc2f2016-01-12 13:42:02 -050087 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000088 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
Lou Berger298cc2f2016-01-12 13:42:02 -0500983
984#define NEXTHOP_IS_V4 (\
985 (safi != SAFI_ENCAP && p->family == AF_INET) || \
986 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 4))
987
988#ifdef HAVE_IPV6
989#define NEXTHOP_IS_V6 (\
990 (safi != SAFI_ENCAP && p->family == AF_INET6) || \
991 (safi == SAFI_ENCAP && attr->extra->mp_nexthop_len == 16))
992#endif
993
paul718e3742002-12-13 20:15:29 +0000994 /* next-hop-set */
Timo Teräs9e7a53c2014-04-24 10:22:37 +0300995 if (transparent
996 || (reflect && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF_ALL))
paul718e3742002-12-13 20:15:29 +0000997 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
Lou Berger298cc2f2016-01-12 13:42:02 -0500998 && ((NEXTHOP_IS_V4 && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000999#ifdef HAVE_IPV6
Lou Berger298cc2f2016-01-12 13:42:02 -05001000 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +00001002#endif /* HAVE_IPV6 */
1003 )))
paul718e3742002-12-13 20:15:29 +00001004 {
1005 /* NEXT-HOP Unchanged. */
1006 }
1007 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
Lou Berger298cc2f2016-01-12 13:42:02 -05001008 || (NEXTHOP_IS_V4 && attr->nexthop.s_addr == 0)
paul718e3742002-12-13 20:15:29 +00001009#ifdef HAVE_IPV6
Lou Berger298cc2f2016-01-12 13:42:02 -05001010 || (NEXTHOP_IS_V6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001011 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +00001012#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001013 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001014 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
1015 {
1016 /* Set IPv4 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001017 if (NEXTHOP_IS_V4)
paul718e3742002-12-13 20:15:29 +00001018 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001019 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001020 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
1021 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +00001022 else
1023 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
1024 }
1025#ifdef HAVE_IPV6
1026 /* Set IPv6 nexthop. */
Lou Berger298cc2f2016-01-12 13:42:02 -05001027 if (NEXTHOP_IS_V6)
paul718e3742002-12-13 20:15:29 +00001028 {
1029 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001030 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00001031 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001032 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001033 }
1034#endif /* HAVE_IPV6 */
1035 }
1036
1037#ifdef HAVE_IPV6
Lou Berger298cc2f2016-01-12 13:42:02 -05001038 if (p->family == AF_INET6 && safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00001039 {
paulfee0f4c2004-09-13 05:12:46 +00001040 /* Left nexthop_local unchanged if so configured. */
1041 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1042 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1043 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1045 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001046 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001047 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001048 }
1049
1050 /* Default nexthop_local treatment for non-RS-Clients */
1051 else
1052 {
paul718e3742002-12-13 20:15:29 +00001053 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001054 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001055
1056 /* Set link-local address for shared network peer. */
1057 if (peer->shared_network
1058 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1059 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001060 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001061 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001062 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001063 }
1064
1065 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1066 address.*/
1067 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001068 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001069
1070 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1071 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001072 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001073 }
paulfee0f4c2004-09-13 05:12:46 +00001074
1075 }
paul718e3742002-12-13 20:15:29 +00001076#endif /* HAVE_IPV6 */
1077
1078 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001079 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001080 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1081 && aspath_private_as_check (attr->aspath))
1082 attr->aspath = aspath_empty_get ();
1083
1084 /* Route map & unsuppress-map apply. */
1085 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001086 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001087 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001088 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001089 struct attr dummy_attr;
1090 struct attr_extra dummy_extra;
1091
1092 dummy_attr.extra = &dummy_extra;
1093
paul718e3742002-12-13 20:15:29 +00001094 info.peer = peer;
1095 info.attr = attr;
1096
1097 /* The route reflector is not allowed to modify the attributes
1098 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001099 if (from->sort == BGP_PEER_IBGP
1100 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001101 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001102 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001103 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001104 }
paulac41b2a2003-08-12 05:32:27 +00001105
1106 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1107
Paul Jakmafb982c22007-05-04 20:15:47 +00001108 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001109 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1110 else
1111 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1112
paulac41b2a2003-08-12 05:32:27 +00001113 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001114
paul718e3742002-12-13 20:15:29 +00001115 if (ret == RMAP_DENYMATCH)
1116 {
1117 bgp_attr_flush (attr);
1118 return 0;
1119 }
1120 }
1121 return 1;
1122}
1123
paul94f2b392005-06-28 12:44:16 +00001124static int
paulfee0f4c2004-09-13 05:12:46 +00001125bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1126 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001127{
paulfee0f4c2004-09-13 05:12:46 +00001128 int ret;
1129 char buf[SU_ADDRSTRLEN];
1130 struct bgp_filter *filter;
1131 struct bgp_info info;
1132 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001133 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001134
1135 from = ri->peer;
1136 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001137 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001138
Paul Jakma750e8142008-07-22 21:11:48 +00001139 if (DISABLE_BGP_ANNOUNCE)
1140 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001141
1142 /* Do not send back route to sender. */
1143 if (from == rsclient)
1144 return 0;
1145
1146 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001147 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001148 if (! UNSUPPRESS_MAP_NAME (filter))
1149 return 0;
1150
1151 /* Default route check. */
1152 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1153 PEER_STATUS_DEFAULT_ORIGINATE))
1154 {
1155 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1156 return 0;
1157#ifdef HAVE_IPV6
1158 else if (p->family == AF_INET6 && p->prefixlen == 0)
1159 return 0;
1160#endif /* HAVE_IPV6 */
1161 }
1162
1163 /* If the attribute has originator-id and it is same as remote
1164 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001165 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001166 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001167 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001168 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001169 {
1170 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001171 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001172 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1173 rsclient->host,
1174 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1175 p->prefixlen);
1176 return 0;
1177 }
1178 }
1179
1180 /* ORF prefix-list filter check */
1181 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1182 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1183 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1184 if (rsclient->orf_plist[afi][safi])
1185 {
1186 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1187 return 0;
1188 }
1189
1190 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001191 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001192 {
1193 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001194 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001195 "%s [Update:SEND] %s/%d is filtered",
1196 rsclient->host,
1197 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1198 p->prefixlen);
1199 return 0;
1200 }
1201
1202#ifdef BGP_SEND_ASPATH_CHECK
1203 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001204 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001205 {
1206 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001207 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001208 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001209 rsclient->host, rsclient->as);
1210 return 0;
1211 }
1212#endif /* BGP_SEND_ASPATH_CHECK */
1213
1214 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001215 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001216
1217 /* next-hop-set */
1218 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1219#ifdef HAVE_IPV6
1220 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001221 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001222#endif /* HAVE_IPV6 */
1223 )
1224 {
1225 /* Set IPv4 nexthop. */
1226 if (p->family == AF_INET)
1227 {
Lou Berger298cc2f2016-01-12 13:42:02 -05001228 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00001229 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001230 IPV4_MAX_BYTELEN);
1231 else
1232 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1233 }
1234#ifdef HAVE_IPV6
1235 /* Set IPv6 nexthop. */
1236 if (p->family == AF_INET6)
1237 {
1238 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001240 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001241 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001242 }
1243#endif /* HAVE_IPV6 */
1244 }
1245
1246#ifdef HAVE_IPV6
1247 if (p->family == AF_INET6)
1248 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001249 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001250
paulfee0f4c2004-09-13 05:12:46 +00001251 /* Left nexthop_local unchanged if so configured. */
1252 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1253 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1254 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001255 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1256 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001257 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001258 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001259 }
1260
1261 /* Default nexthop_local treatment for RS-Clients */
1262 else
1263 {
1264 /* Announcer and RS-Client are both in the same network */
1265 if (rsclient->shared_network && from->shared_network &&
1266 (rsclient->ifindex == from->ifindex))
1267 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001268 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1269 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001270 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001271 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001272 }
1273
1274 /* Set link-local address for shared network peer. */
1275 else if (rsclient->shared_network
1276 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1277 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001278 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001279 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001280 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001281 }
1282
1283 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001284 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001285 }
1286
1287 }
1288#endif /* HAVE_IPV6 */
1289
1290
1291 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001292 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001293 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1294 && aspath_private_as_check (attr->aspath))
1295 attr->aspath = aspath_empty_get ();
1296
1297 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001298 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001299 {
1300 info.peer = rsclient;
1301 info.attr = attr;
1302
1303 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1304
Paul Jakmafb982c22007-05-04 20:15:47 +00001305 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001306 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1307 else
1308 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1309
1310 rsclient->rmap_type = 0;
1311
1312 if (ret == RMAP_DENYMATCH)
1313 {
1314 bgp_attr_flush (attr);
1315 return 0;
1316 }
1317 }
1318
1319 return 1;
1320}
1321
1322struct bgp_info_pair
1323{
1324 struct bgp_info *old;
1325 struct bgp_info *new;
1326};
1327
paul94f2b392005-06-28 12:44:16 +00001328static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001329bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
Paul Jakma6d4742b2015-11-25 17:14:37 +00001330 struct bgp_info_pair *result,
1331 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00001332{
paul718e3742002-12-13 20:15:29 +00001333 struct bgp_info *new_select;
1334 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001335 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001336 struct bgp_info *ri1;
1337 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001338 struct bgp_info *nextri = NULL;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001339 int cmpret, do_mpath;
Josh Bailey96450fa2011-07-20 20:45:12 -07001340 struct list mp_list;
Paul Jakma91b9e852015-12-01 14:32:11 +00001341
1342 result->old = result->new = NULL;
1343
1344 if (rn->info == NULL)
1345 {
1346 char buf[PREFIX_STRLEN];
1347 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1348 __func__,
1349 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1350 return;
1351 }
1352
Josh Bailey96450fa2011-07-20 20:45:12 -07001353 bgp_mp_list_init (&mp_list);
Paul Jakma6d4742b2015-11-25 17:14:37 +00001354 do_mpath = bgp_mpath_is_configured (bgp, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001355
paul718e3742002-12-13 20:15:29 +00001356 /* bgp deterministic-med */
1357 new_select = NULL;
1358 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1359 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1360 {
1361 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1362 continue;
1363 if (BGP_INFO_HOLDDOWN (ri1))
1364 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001365 if (ri1->peer && ri1->peer != bgp->peer_self)
1366 if (ri1->peer->status != Established)
1367 continue;
paul718e3742002-12-13 20:15:29 +00001368
1369 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001370 if (do_mpath)
1371 bgp_mp_list_add (&mp_list, ri1);
1372 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001373 if (ri1->next)
1374 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1375 {
1376 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1377 continue;
1378 if (BGP_INFO_HOLDDOWN (ri2))
1379 continue;
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001380 if (ri2->peer &&
1381 ri2->peer != bgp->peer_self &&
1382 !CHECK_FLAG (ri2->peer->sflags, PEER_STATUS_NSF_WAIT))
1383 if (ri2->peer->status != Established)
1384 continue;
paul718e3742002-12-13 20:15:29 +00001385
1386 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1387 || aspath_cmp_left_confed (ri1->attr->aspath,
1388 ri2->attr->aspath))
1389 {
Josh Bailey6918e742011-07-20 20:48:20 -07001390 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1391 old_select = ri2;
Paul Jakma6d4742b2015-11-25 17:14:37 +00001392 if ((cmpret = bgp_info_cmp (bgp, ri2, new_select, afi, safi))
1393 == -1)
paul718e3742002-12-13 20:15:29 +00001394 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001395 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001396 new_select = ri2;
1397 }
1398
Paul Jakma6d4742b2015-11-25 17:14:37 +00001399 if (do_mpath)
1400 {
1401 if (cmpret != 0)
1402 bgp_mp_list_clear (&mp_list);
1403
1404 if (cmpret == 0 || cmpret == -1)
1405 bgp_mp_list_add (&mp_list, ri2);
1406 }
Josh Bailey6918e742011-07-20 20:48:20 -07001407
Paul Jakma1a392d42006-09-07 00:24:49 +00001408 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001409 }
1410 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001411 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1412 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001413
Paul Jakma6d4742b2015-11-25 17:14:37 +00001414 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey6918e742011-07-20 20:48:20 -07001415 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001416 }
1417
1418 /* Check old selected route and new selected route. */
1419 old_select = NULL;
1420 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001421 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001422 {
1423 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1424 old_select = ri;
1425
1426 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001427 {
1428 /* reap REMOVED routes, if needs be
1429 * selected route must stay for a while longer though
1430 */
1431 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1432 && (ri != old_select))
1433 bgp_info_reap (rn, ri);
1434
1435 continue;
1436 }
paul718e3742002-12-13 20:15:29 +00001437
Dinesh G Dutt234e5c82015-02-01 00:56:12 -08001438 if (ri->peer &&
1439 ri->peer != bgp->peer_self &&
1440 !CHECK_FLAG (ri->peer->sflags, PEER_STATUS_NSF_WAIT))
1441 if (ri->peer->status != Established)
1442 continue;
1443
paul718e3742002-12-13 20:15:29 +00001444 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1445 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1446 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001447 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001448 continue;
1449 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001450 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1451 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001452
Paul Jakma6d4742b2015-11-25 17:14:37 +00001453 if ((cmpret = bgp_info_cmp (bgp, ri, new_select, afi, safi)) == -1)
Josh Bailey96450fa2011-07-20 20:45:12 -07001454 {
Josh Bailey6918e742011-07-20 20:48:20 -07001455 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1456 bgp_mp_dmed_deselect (new_select);
1457
Josh Bailey96450fa2011-07-20 20:45:12 -07001458 new_select = ri;
Josh Bailey96450fa2011-07-20 20:45:12 -07001459 }
Paul Jakma6d4742b2015-11-25 17:14:37 +00001460 else if (cmpret == 1 && do_mpath
1461 && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Josh Bailey6918e742011-07-20 20:48:20 -07001462 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001463
Paul Jakma6d4742b2015-11-25 17:14:37 +00001464 if (do_mpath)
1465 {
1466 if (cmpret != 0)
1467 bgp_mp_list_clear (&mp_list);
1468
1469 if (cmpret == 0 || cmpret == -1)
1470 bgp_mp_list_add (&mp_list, ri);
1471 }
paul718e3742002-12-13 20:15:29 +00001472 }
paulfee0f4c2004-09-13 05:12:46 +00001473
Josh Bailey6918e742011-07-20 20:48:20 -07001474 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
Paul Jakma6d4742b2015-11-25 17:14:37 +00001475 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, afi, safi);
Josh Bailey96450fa2011-07-20 20:45:12 -07001476
Josh Bailey0b597ef2011-07-20 20:49:11 -07001477 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001478 bgp_mp_list_clear (&mp_list);
1479
1480 result->old = old_select;
1481 result->new = new_select;
1482
1483 return;
paulfee0f4c2004-09-13 05:12:46 +00001484}
1485
paul94f2b392005-06-28 12:44:16 +00001486static int
paulfee0f4c2004-09-13 05:12:46 +00001487bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001488 struct bgp_node *rn, afi_t afi, safi_t safi)
1489{
paulfee0f4c2004-09-13 05:12:46 +00001490 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001491 struct attr attr;
1492 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001493
Lou Berger050defe2016-01-12 13:41:59 -05001494 memset (&attr, 0, sizeof(struct attr));
1495 memset (&extra, 0, sizeof(struct attr_extra));
1496
paulfee0f4c2004-09-13 05:12:46 +00001497 p = &rn->p;
1498
Paul Jakma9eda90c2007-08-30 13:36:17 +00001499 /* Announce route to Established peer. */
1500 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001501 return 0;
1502
Paul Jakma9eda90c2007-08-30 13:36:17 +00001503 /* Address family configuration check. */
1504 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001505 return 0;
1506
Paul Jakma9eda90c2007-08-30 13:36:17 +00001507 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001508 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1509 PEER_STATUS_ORF_WAIT_REFRESH))
1510 return 0;
1511
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001512 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1513 attr.extra = &extra;
1514
Avneesh Sachdev67174042012-08-17 08:19:49 -07001515 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001516 {
1517 case BGP_TABLE_MAIN:
1518 /* Announcement to peer->conf. If the route is filtered,
1519 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001520 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1521 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001522 else
1523 bgp_adj_out_unset (rn, peer, p, afi, safi);
1524 break;
1525 case BGP_TABLE_RSCLIENT:
1526 /* Announcement to peer->conf. If the route is filtered,
1527 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001528 if (selected &&
1529 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1530 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1531 else
1532 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001533 break;
1534 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001535
Lou Berger050defe2016-01-12 13:41:59 -05001536 bgp_attr_flush (&attr);
paulfee0f4c2004-09-13 05:12:46 +00001537 return 0;
paul200df112005-06-01 11:17:05 +00001538}
paulfee0f4c2004-09-13 05:12:46 +00001539
paul200df112005-06-01 11:17:05 +00001540struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001541{
paul200df112005-06-01 11:17:05 +00001542 struct bgp *bgp;
1543 struct bgp_node *rn;
1544 afi_t afi;
1545 safi_t safi;
1546};
1547
1548static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001549bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001550{
paul0fb58d52005-11-14 14:31:49 +00001551 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001552 struct bgp *bgp = pq->bgp;
1553 struct bgp_node *rn = pq->rn;
1554 afi_t afi = pq->afi;
1555 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001556 struct bgp_info *new_select;
1557 struct bgp_info *old_select;
1558 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001559 struct listnode *node, *nnode;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001560 struct peer *rsclient = bgp_node_table (rn)->owner;
paul200df112005-06-01 11:17:05 +00001561
paulfee0f4c2004-09-13 05:12:46 +00001562 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001563 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001564 new_select = old_and_new.new;
1565 old_select = old_and_new.old;
1566
paul200df112005-06-01 11:17:05 +00001567 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1568 {
Chris Caputo228da422009-07-18 05:44:03 +00001569 if (rsclient->group)
1570 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1571 {
1572 /* Nothing to do. */
1573 if (old_select && old_select == new_select)
1574 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1575 continue;
paulfee0f4c2004-09-13 05:12:46 +00001576
Chris Caputo228da422009-07-18 05:44:03 +00001577 if (old_select)
1578 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1579 if (new_select)
1580 {
1581 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1582 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001583 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1584 }
paulfee0f4c2004-09-13 05:12:46 +00001585
Chris Caputo228da422009-07-18 05:44:03 +00001586 bgp_process_announce_selected (rsclient, new_select, rn,
1587 afi, safi);
1588 }
paul200df112005-06-01 11:17:05 +00001589 }
1590 else
1591 {
hassob7395792005-08-26 12:58:38 +00001592 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001593 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001594 if (new_select)
1595 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001596 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1597 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001598 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001599 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001600 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001601 }
paulfee0f4c2004-09-13 05:12:46 +00001602
paulb40d9392005-08-22 22:34:41 +00001603 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1604 bgp_info_reap (rn, old_select);
1605
paul200df112005-06-01 11:17:05 +00001606 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1607 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001608}
1609
paul200df112005-06-01 11:17:05 +00001610static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001611bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001612{
paul0fb58d52005-11-14 14:31:49 +00001613 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001614 struct bgp *bgp = pq->bgp;
1615 struct bgp_node *rn = pq->rn;
1616 afi_t afi = pq->afi;
1617 safi_t safi = pq->safi;
1618 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001619 struct bgp_info *new_select;
1620 struct bgp_info *old_select;
1621 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001622 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001623 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001624
paulfee0f4c2004-09-13 05:12:46 +00001625 /* Best path selection. */
Paul Jakma6d4742b2015-11-25 17:14:37 +00001626 bgp_best_selection (bgp, rn, &old_and_new, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001627 old_select = old_and_new.old;
1628 new_select = old_and_new.new;
1629
1630 /* Nothing to do. */
1631 if (old_select && old_select == new_select)
1632 {
1633 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001634 {
Josh Bailey8196f132011-07-20 20:47:07 -07001635 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1636 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001637 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001638
Josh Bailey8196f132011-07-20 20:47:07 -07001639 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001640 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1641 return WQ_SUCCESS;
1642 }
paulfee0f4c2004-09-13 05:12:46 +00001643 }
paul718e3742002-12-13 20:15:29 +00001644
hasso338b3422005-02-23 14:27:24 +00001645 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001646 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001647 if (new_select)
1648 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001649 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1650 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001651 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001652 }
1653
1654
paul718e3742002-12-13 20:15:29 +00001655 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001656 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001657 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001658 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001659 }
1660
1661 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001662 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1663 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001664 {
1665 if (new_select
1666 && new_select->type == ZEBRA_ROUTE_BGP
1667 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001668 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001669 else
1670 {
1671 /* Withdraw the route from the kernel. */
1672 if (old_select
1673 && old_select->type == ZEBRA_ROUTE_BGP
1674 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001675 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001676 }
1677 }
paulb40d9392005-08-22 22:34:41 +00001678
Lou Berger050defe2016-01-12 13:41:59 -05001679 /* Reap old select bgp_info, if it has been removed */
paulb40d9392005-08-22 22:34:41 +00001680 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1681 bgp_info_reap (rn, old_select);
1682
paul200df112005-06-01 11:17:05 +00001683 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1684 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001685}
1686
paul200df112005-06-01 11:17:05 +00001687static void
paul0fb58d52005-11-14 14:31:49 +00001688bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001689{
paul0fb58d52005-11-14 14:31:49 +00001690 struct bgp_process_queue *pq = data;
Avneesh Sachdev67174042012-08-17 08:19:49 -07001691 struct bgp_table *table = bgp_node_table (pq->rn);
paul0fb58d52005-11-14 14:31:49 +00001692
Chris Caputo228da422009-07-18 05:44:03 +00001693 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001694 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001695 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001696 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1697}
1698
1699static void
1700bgp_process_queue_init (void)
1701{
1702 bm->process_main_queue
1703 = work_queue_new (bm->master, "process_main_queue");
1704 bm->process_rsclient_queue
1705 = work_queue_new (bm->master, "process_rsclient_queue");
1706
1707 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1708 {
1709 zlog_err ("%s: Failed to allocate work queue", __func__);
1710 exit (1);
1711 }
1712
1713 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001714 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001715 bm->process_main_queue->spec.max_retries = 0;
1716 bm->process_main_queue->spec.hold = 50;
1717
Paul Jakma838bbde2010-01-08 14:05:32 +00001718 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
David Lamparterd43f8b32015-03-03 08:54:54 +01001719 bm->process_rsclient_queue->spec.del_item_data = &bgp_processq_del;
1720 bm->process_rsclient_queue->spec.max_retries = 0;
1721 bm->process_rsclient_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001722}
1723
1724void
paulfee0f4c2004-09-13 05:12:46 +00001725bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1726{
paul200df112005-06-01 11:17:05 +00001727 struct bgp_process_queue *pqnode;
1728
1729 /* already scheduled for processing? */
1730 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1731 return;
1732
Paul Jakma91b9e852015-12-01 14:32:11 +00001733 if (rn->info == NULL)
1734 {
1735 /* XXX: Perhaps remove before next release, after we've flushed out
1736 * any obvious cases
1737 */
1738 assert (rn->info != NULL);
1739 char buf[PREFIX_STRLEN];
1740 zlog_warn ("%s: Called for route_node %s with no routing entries!",
1741 __func__,
1742 prefix2str (&(bgp_node_to_rnode (rn)->p), buf, sizeof(buf)));
1743 return;
1744 }
1745
paul200df112005-06-01 11:17:05 +00001746 if ( (bm->process_main_queue == NULL) ||
1747 (bm->process_rsclient_queue == NULL) )
1748 bgp_process_queue_init ();
1749
1750 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1751 sizeof (struct bgp_process_queue));
1752 if (!pqnode)
1753 return;
Chris Caputo228da422009-07-18 05:44:03 +00001754
1755 /* all unlocked in bgp_processq_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07001756 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00001757 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001758 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001759 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001760 pqnode->afi = afi;
1761 pqnode->safi = safi;
1762
Avneesh Sachdev67174042012-08-17 08:19:49 -07001763 switch (bgp_node_table (rn)->type)
paulfee0f4c2004-09-13 05:12:46 +00001764 {
paul200df112005-06-01 11:17:05 +00001765 case BGP_TABLE_MAIN:
1766 work_queue_add (bm->process_main_queue, pqnode);
1767 break;
1768 case BGP_TABLE_RSCLIENT:
1769 work_queue_add (bm->process_rsclient_queue, pqnode);
1770 break;
paulfee0f4c2004-09-13 05:12:46 +00001771 }
paul200df112005-06-01 11:17:05 +00001772
Stephen Hemminger07ff4dc2013-01-04 22:29:20 +00001773 SET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
paul200df112005-06-01 11:17:05 +00001774 return;
paulfee0f4c2004-09-13 05:12:46 +00001775}
hasso0a486e52005-02-01 20:57:17 +00001776
paul94f2b392005-06-28 12:44:16 +00001777static int
hasso0a486e52005-02-01 20:57:17 +00001778bgp_maximum_prefix_restart_timer (struct thread *thread)
1779{
1780 struct peer *peer;
1781
1782 peer = THREAD_ARG (thread);
1783 peer->t_pmax_restart = NULL;
1784
1785 if (BGP_DEBUG (events, EVENTS))
1786 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1787 peer->host);
1788
1789 peer_clear (peer);
1790
1791 return 0;
1792}
1793
paulfee0f4c2004-09-13 05:12:46 +00001794int
paul5228ad22004-06-04 17:58:18 +00001795bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1796 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001797{
hassoe0701b72004-05-20 09:19:34 +00001798 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1799 return 0;
1800
1801 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001802 {
hassoe0701b72004-05-20 09:19:34 +00001803 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1804 && ! always)
1805 return 0;
paul718e3742002-12-13 20:15:29 +00001806
hassoe0701b72004-05-20 09:19:34 +00001807 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001808 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1809 "limit %ld", afi_safi_print (afi, safi), peer->host,
1810 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001811 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001812
hassoe0701b72004-05-20 09:19:34 +00001813 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1814 return 0;
paul718e3742002-12-13 20:15:29 +00001815
hassoe0701b72004-05-20 09:19:34 +00001816 {
paul5228ad22004-06-04 17:58:18 +00001817 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001818
1819 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001820 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001821
1822 ndata[0] = (afi >> 8);
1823 ndata[1] = afi;
1824 ndata[2] = safi;
1825 ndata[3] = (peer->pmax[afi][safi] >> 24);
1826 ndata[4] = (peer->pmax[afi][safi] >> 16);
1827 ndata[5] = (peer->pmax[afi][safi] >> 8);
1828 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001829
1830 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1831 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1832 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1833 }
hasso0a486e52005-02-01 20:57:17 +00001834
1835 /* restart timer start */
1836 if (peer->pmax_restart[afi][safi])
1837 {
1838 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1839
1840 if (BGP_DEBUG (events, EVENTS))
1841 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1842 peer->host, peer->v_pmax_restart);
1843
1844 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1845 peer->v_pmax_restart);
1846 }
1847
hassoe0701b72004-05-20 09:19:34 +00001848 return 1;
paul718e3742002-12-13 20:15:29 +00001849 }
hassoe0701b72004-05-20 09:19:34 +00001850 else
1851 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1852
1853 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1854 {
1855 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1856 && ! always)
1857 return 0;
1858
1859 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001860 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1861 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1862 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001863 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1864 }
1865 else
1866 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001867 return 0;
1868}
1869
paulb40d9392005-08-22 22:34:41 +00001870/* Unconditionally remove the route from the RIB, without taking
1871 * damping into consideration (eg, because the session went down)
1872 */
paul94f2b392005-06-28 12:44:16 +00001873static void
paul718e3742002-12-13 20:15:29 +00001874bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1875 afi_t afi, safi_t safi)
1876{
paul902212c2006-02-05 17:51:19 +00001877 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1878
1879 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1880 bgp_info_delete (rn, ri); /* keep historical info */
1881
paulb40d9392005-08-22 22:34:41 +00001882 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001883}
1884
paul94f2b392005-06-28 12:44:16 +00001885static void
paul718e3742002-12-13 20:15:29 +00001886bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
Lou Berger050defe2016-01-12 13:41:59 -05001887 afi_t afi, safi_t safi, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00001888{
paul718e3742002-12-13 20:15:29 +00001889 int status = BGP_DAMP_NONE;
1890
paulb40d9392005-08-22 22:34:41 +00001891 /* apply dampening, if result is suppressed, we'll be retaining
1892 * the bgp_info in the RIB for historical reference.
1893 */
1894 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001895 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001896 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1897 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001898 {
paul902212c2006-02-05 17:51:19 +00001899 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1900 return;
1901 }
1902
1903 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001904}
1905
paul94f2b392005-06-28 12:44:16 +00001906static void
paulfee0f4c2004-09-13 05:12:46 +00001907bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1908 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1909 int sub_type, struct prefix_rd *prd, u_char *tag)
1910{
1911 struct bgp_node *rn;
1912 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001913 struct attr new_attr;
1914 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001915 struct attr *attr_new;
1916 struct attr *attr_new2;
1917 struct bgp_info *ri;
1918 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001919 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001920 char buf[SU_ADDRSTRLEN];
1921
1922 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1923 if (peer == rsclient)
1924 return;
1925
1926 bgp = peer->bgp;
1927 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1928
1929 /* Check previously received route. */
1930 for (ri = rn->info; ri; ri = ri->next)
1931 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1932 break;
1933
1934 /* AS path loop check. */
Milan Kocian000e1572013-10-18 07:59:38 +00001935 if (aspath_loop_check (attr->aspath, rsclient->as) > rsclient->allowas_in[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001936 {
1937 reason = "as-path contains our own AS;";
1938 goto filtered;
1939 }
1940
1941 /* Route reflector originator ID check. */
1942 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001943 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001944 {
1945 reason = "originator is us;";
1946 goto filtered;
1947 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001948
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001949 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001950 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 /* Apply export policy. */
1953 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1954 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1955 {
1956 reason = "export-policy;";
1957 goto filtered;
1958 }
1959
1960 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001961
paulfee0f4c2004-09-13 05:12:46 +00001962 /* Apply import policy. */
1963 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1964 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001965 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001966
1967 reason = "import-policy;";
1968 goto filtered;
1969 }
1970
1971 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001972 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001973
1974 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001975 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001976 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001977 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001978 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001979 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001980 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001981 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001982
1983 reason = "martian next-hop;";
1984 goto filtered;
1985 }
1986 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001987
paulfee0f4c2004-09-13 05:12:46 +00001988 /* If the update is implicit withdraw. */
1989 if (ri)
1990 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001991 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001992
1993 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001994 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1995 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001996 {
1997
Paul Jakma1a392d42006-09-07 00:24:49 +00001998 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001999
2000 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002001 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002002 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
2003 peer->host,
2004 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2005 p->prefixlen, rsclient->host);
2006
Chris Caputo228da422009-07-18 05:44:03 +00002007 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002008 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002009 bgp_attr_flush(&new_attr);
Chris Caputo228da422009-07-18 05:44:03 +00002010 return;
paulfee0f4c2004-09-13 05:12:46 +00002011 }
2012
Paul Jakma16d2e242007-04-10 19:32:10 +00002013 /* Withdraw/Announce before we fully processed the withdraw */
2014 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2015 bgp_info_restore (rn, ri);
2016
paulfee0f4c2004-09-13 05:12:46 +00002017 /* Received Logging. */
2018 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002019 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002020 peer->host,
2021 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2022 p->prefixlen, rsclient->host);
2023
2024 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002025 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00002026
2027 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002028 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00002029 ri->attr = attr_new;
2030
2031 /* Update MPLS tag. */
2032 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002033 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002034
Paul Jakma1a392d42006-09-07 00:24:49 +00002035 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002036
2037 /* Process change. */
2038 bgp_process (bgp, rn, afi, safi);
2039 bgp_unlock_node (rn);
2040
2041 return;
2042 }
2043
2044 /* Received Logging. */
2045 if (BGP_DEBUG (update, UPDATE_IN))
2046 {
ajsd2c1f162004-12-08 21:10:20 +00002047 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00002048 peer->host,
2049 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2050 p->prefixlen, rsclient->host);
2051 }
2052
2053 /* Make new BGP info. */
2054 new = bgp_info_new ();
2055 new->type = type;
2056 new->sub_type = sub_type;
2057 new->peer = peer;
2058 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002059 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00002060
2061 /* Update MPLS tag. */
2062 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002063 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00002064
Paul Jakma1a392d42006-09-07 00:24:49 +00002065 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00002066
2067 /* Register new BGP information. */
2068 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002069
2070 /* route_node_get lock */
2071 bgp_unlock_node (rn);
2072
paulfee0f4c2004-09-13 05:12:46 +00002073 /* Process change. */
2074 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002075
paulfee0f4c2004-09-13 05:12:46 +00002076 return;
2077
2078 filtered:
2079
2080 /* This BGP update is filtered. Log the reason then update BGP entry. */
2081 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002082 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002083 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2084 peer->host,
2085 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2086 p->prefixlen, rsclient->host, reason);
2087
2088 if (ri)
paulb40d9392005-08-22 22:34:41 +00002089 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002090
2091 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002092
paulfee0f4c2004-09-13 05:12:46 +00002093 return;
2094}
2095
paul94f2b392005-06-28 12:44:16 +00002096static void
paulfee0f4c2004-09-13 05:12:46 +00002097bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2098 struct peer *peer, struct prefix *p, int type, int sub_type,
2099 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002100{
paulfee0f4c2004-09-13 05:12:46 +00002101 struct bgp_node *rn;
2102 struct bgp_info *ri;
2103 char buf[SU_ADDRSTRLEN];
2104
2105 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002106 return;
paulfee0f4c2004-09-13 05:12:46 +00002107
2108 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2109
2110 /* Lookup withdrawn route. */
2111 for (ri = rn->info; ri; ri = ri->next)
2112 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2113 break;
2114
2115 /* Withdraw specified route from routing table. */
2116 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002117 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paulfee0f4c2004-09-13 05:12:46 +00002118 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002119 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002120 "%s Can't find the route %s/%d", peer->host,
2121 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2122 p->prefixlen);
2123
2124 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002125 bgp_unlock_node (rn);
2126}
paulfee0f4c2004-09-13 05:12:46 +00002127
paul94f2b392005-06-28 12:44:16 +00002128static int
paulfee0f4c2004-09-13 05:12:46 +00002129bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002130 afi_t afi, safi_t safi, int type, int sub_type,
2131 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2132{
2133 int ret;
2134 int aspath_loop_count = 0;
2135 struct bgp_node *rn;
2136 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002137 struct attr new_attr;
2138 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002139 struct attr *attr_new;
2140 struct bgp_info *ri;
2141 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002142 const char *reason;
paul718e3742002-12-13 20:15:29 +00002143 char buf[SU_ADDRSTRLEN];
2144
2145 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002146 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002147
paul718e3742002-12-13 20:15:29 +00002148 /* When peer's soft reconfiguration enabled. Record input packet in
2149 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002150 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2151 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002152 bgp_adj_in_set (rn, peer, attr);
2153
2154 /* Check previously received route. */
2155 for (ri = rn->info; ri; ri = ri->next)
2156 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2157 break;
2158
2159 /* AS path local-as loop check. */
2160 if (peer->change_local_as)
2161 {
2162 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2163 aspath_loop_count = 1;
2164
2165 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2166 {
2167 reason = "as-path contains our own AS;";
2168 goto filtered;
2169 }
2170 }
2171
2172 /* AS path loop check. */
2173 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2174 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2175 && aspath_loop_check(attr->aspath, bgp->confed_id)
2176 > peer->allowas_in[afi][safi]))
2177 {
2178 reason = "as-path contains our own AS;";
2179 goto filtered;
2180 }
2181
2182 /* Route reflector originator ID check. */
2183 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002184 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002185 {
2186 reason = "originator is us;";
2187 goto filtered;
2188 }
2189
2190 /* Route reflector cluster ID check. */
2191 if (bgp_cluster_filter (peer, attr))
2192 {
2193 reason = "reflected from the same cluster;";
2194 goto filtered;
2195 }
2196
2197 /* Apply incoming filter. */
2198 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2199 {
2200 reason = "filter;";
2201 goto filtered;
2202 }
2203
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002204 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002205 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002206
David Lamparterc460e572014-06-04 00:54:58 +02002207 /* Apply incoming route-map.
2208 * NB: new_attr may now contain newly allocated values from route-map "set"
2209 * commands, so we need bgp_attr_flush in the error paths, until we intern
2210 * the attr (which takes over the memory references) */
paul718e3742002-12-13 20:15:29 +00002211 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2212 {
2213 reason = "route-map;";
David Lamparterc460e572014-06-04 00:54:58 +02002214 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002215 goto filtered;
2216 }
2217
2218 /* IPv4 unicast next hop check. */
2219 if (afi == AFI_IP && safi == SAFI_UNICAST)
2220 {
2221 /* If the peer is EBGP and nexthop is not on connected route,
2222 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002223 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002224 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002225 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002226 {
2227 reason = "non-connected 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
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002232 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002233 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002234 if (new_attr.nexthop.s_addr == 0
2235 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2236 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002237 {
2238 reason = "martian next-hop;";
David Lamparterc460e572014-06-04 00:54:58 +02002239 bgp_attr_flush (&new_attr);
paul718e3742002-12-13 20:15:29 +00002240 goto filtered;
2241 }
2242 }
2243
2244 attr_new = bgp_attr_intern (&new_attr);
2245
2246 /* If the update is implicit withdraw. */
2247 if (ri)
2248 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002249 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002250
2251 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002252 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2253 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002254 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002255 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002256
2257 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002258 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002259 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2260 {
2261 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002262 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002263 peer->host,
2264 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2265 p->prefixlen);
2266
paul902212c2006-02-05 17:51:19 +00002267 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2268 {
2269 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2270 bgp_process (bgp, rn, afi, safi);
2271 }
paul718e3742002-12-13 20:15:29 +00002272 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002273 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002274 {
2275 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002276 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002277 "%s rcvd %s/%d...duplicate ignored",
2278 peer->host,
2279 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2280 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002281
2282 /* graceful restart STALE flag unset. */
2283 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2284 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002286 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002287 }
paul718e3742002-12-13 20:15:29 +00002288 }
2289
2290 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002291 bgp_attr_unintern (&attr_new);
Lou Berger050defe2016-01-12 13:41:59 -05002292 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002293
paul718e3742002-12-13 20:15:29 +00002294 return 0;
2295 }
2296
Paul Jakma16d2e242007-04-10 19:32:10 +00002297 /* Withdraw/Announce before we fully processed the withdraw */
2298 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2299 {
2300 if (BGP_DEBUG (update, UPDATE_IN))
2301 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2302 peer->host,
2303 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2304 p->prefixlen);
2305 bgp_info_restore (rn, ri);
2306 }
2307
paul718e3742002-12-13 20:15:29 +00002308 /* Received Logging. */
2309 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002310 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002311 peer->host,
2312 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2313 p->prefixlen);
2314
hasso93406d82005-02-02 14:40:33 +00002315 /* graceful restart STALE flag unset. */
2316 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002317 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002318
paul718e3742002-12-13 20:15:29 +00002319 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002320 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002321
2322 /* implicit withdraw, decrement aggregate and pcount here.
2323 * only if update is accepted, they'll increment below.
2324 */
paul902212c2006-02-05 17:51:19 +00002325 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2326
paul718e3742002-12-13 20:15:29 +00002327 /* Update bgp route dampening information. */
2328 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002329 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002330 {
2331 /* This is implicit withdraw so we should update dampening
2332 information. */
2333 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2334 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002335 }
2336
paul718e3742002-12-13 20:15:29 +00002337 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002338 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002339 ri->attr = attr_new;
2340
2341 /* Update MPLS tag. */
2342 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002343 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002344
Lou Berger050defe2016-01-12 13:41:59 -05002345 bgp_attr_flush (&new_attr);
2346
paul718e3742002-12-13 20:15:29 +00002347 /* Update bgp route dampening information. */
2348 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002349 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002350 {
2351 /* Now we do normal update dampening. */
2352 ret = bgp_damp_update (ri, rn, afi, safi);
2353 if (ret == BGP_DAMP_SUPPRESSED)
2354 {
2355 bgp_unlock_node (rn);
2356 return 0;
2357 }
2358 }
2359
2360 /* Nexthop reachability check. */
2361 if ((afi == AFI_IP || afi == AFI_IP6)
2362 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002363 && (peer->sort == BGP_PEER_IBGP
2364 || peer->sort == BGP_PEER_CONFED
2365 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002366 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002367 {
2368 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002369 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002370 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002371 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002372 }
2373 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002374 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002375
Lou Berger050defe2016-01-12 13:41:59 -05002376 bgp_attr_flush (&new_attr);
2377
paul718e3742002-12-13 20:15:29 +00002378 /* Process change. */
2379 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2380
2381 bgp_process (bgp, rn, afi, safi);
2382 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002383
paul718e3742002-12-13 20:15:29 +00002384 return 0;
2385 }
2386
2387 /* Received Logging. */
2388 if (BGP_DEBUG (update, UPDATE_IN))
2389 {
ajsd2c1f162004-12-08 21:10:20 +00002390 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002391 peer->host,
2392 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2393 p->prefixlen);
2394 }
2395
paul718e3742002-12-13 20:15:29 +00002396 /* Make new BGP info. */
2397 new = bgp_info_new ();
2398 new->type = type;
2399 new->sub_type = sub_type;
2400 new->peer = peer;
2401 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002402 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002403
2404 /* Update MPLS tag. */
2405 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002406 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002407
2408 /* Nexthop reachability check. */
2409 if ((afi == AFI_IP || afi == AFI_IP6)
2410 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002411 && (peer->sort == BGP_PEER_IBGP
2412 || peer->sort == BGP_PEER_CONFED
2413 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002414 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002415 {
2416 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002417 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002418 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002419 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002420 }
2421 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002422 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002423
paul902212c2006-02-05 17:51:19 +00002424 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002425 bgp_aggregate_increment (bgp, p, new, afi, safi);
2426
2427 /* Register new BGP information. */
2428 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002429
2430 /* route_node_get lock */
2431 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002432
Lou Berger050defe2016-01-12 13:41:59 -05002433 bgp_attr_flush (&new_attr);
2434
paul718e3742002-12-13 20:15:29 +00002435 /* If maximum prefix count is configured and current prefix
2436 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002437 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2438 return -1;
paul718e3742002-12-13 20:15:29 +00002439
2440 /* Process change. */
2441 bgp_process (bgp, rn, afi, safi);
2442
2443 return 0;
2444
2445 /* This BGP update is filtered. Log the reason then update BGP
2446 entry. */
2447 filtered:
2448 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002449 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002450 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2451 peer->host,
2452 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2453 p->prefixlen, reason);
2454
2455 if (ri)
paulb40d9392005-08-22 22:34:41 +00002456 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002457
2458 bgp_unlock_node (rn);
Lou Berger050defe2016-01-12 13:41:59 -05002459 bgp_attr_flush (&new_attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002460
paul718e3742002-12-13 20:15:29 +00002461 return 0;
2462}
2463
2464int
paulfee0f4c2004-09-13 05:12:46 +00002465bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2466 afi_t afi, safi_t safi, int type, int sub_type,
2467 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2468{
2469 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002470 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002471 struct bgp *bgp;
2472 int ret;
2473
2474 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2475 soft_reconfig);
2476
2477 bgp = peer->bgp;
2478
2479 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002480 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002481 {
2482 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2483 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2484 sub_type, prd, tag);
2485 }
2486
2487 return ret;
2488}
2489
2490int
paul718e3742002-12-13 20:15:29 +00002491bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002492 afi_t afi, safi_t safi, int type, int sub_type,
2493 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002494{
2495 struct bgp *bgp;
2496 char buf[SU_ADDRSTRLEN];
2497 struct bgp_node *rn;
2498 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002499 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002500 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002501
2502 bgp = peer->bgp;
2503
David Lamparter4584c232015-04-13 09:50:00 +02002504 /* Lookup node. */
2505 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
2506
2507 /* Cisco IOS 12.4(24)T4 on session establishment sends withdraws for all
2508 * routes that are filtered. This tanks out Quagga RS pretty badly due to
2509 * the iteration over all RS clients.
2510 * Since we need to remove the entry from adj_in anyway, do that first and
2511 * if there was no entry, we don't need to do anything more. */
2512 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2513 && peer != bgp->peer_self)
2514 if (!bgp_adj_in_unset (rn, peer))
2515 {
2516 if (BGP_DEBUG (update, UPDATE_IN))
2517 zlog (peer->log, LOG_DEBUG, "%s withdrawing route %s/%d "
2518 "not in adj-in", peer->host,
2519 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2520 p->prefixlen);
2521 bgp_unlock_node (rn);
2522 return 0;
2523 }
2524
paulfee0f4c2004-09-13 05:12:46 +00002525 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002526 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002527 {
2528 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2529 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2530 }
2531
paul718e3742002-12-13 20:15:29 +00002532 /* Logging. */
2533 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002534 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002535 peer->host,
2536 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2537 p->prefixlen);
2538
paul718e3742002-12-13 20:15:29 +00002539 /* Lookup withdrawn route. */
2540 for (ri = rn->info; ri; ri = ri->next)
2541 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2542 break;
2543
2544 /* Withdraw specified route from routing table. */
2545 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Lou Berger050defe2016-01-12 13:41:59 -05002546 bgp_rib_withdraw (rn, ri, peer, afi, safi, prd);
paul718e3742002-12-13 20:15:29 +00002547 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002548 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002549 "%s Can't find the route %s/%d", peer->host,
2550 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2551 p->prefixlen);
2552
2553 /* Unlock bgp_node_get() lock. */
2554 bgp_unlock_node (rn);
2555
2556 return 0;
2557}
David Lamparter6b0655a2014-06-04 06:53:35 +02002558
paul718e3742002-12-13 20:15:29 +00002559void
2560bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2561{
2562 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002563 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002564 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002565 struct prefix p;
paul718e3742002-12-13 20:15:29 +00002566 struct peer *from;
Christian Frankedcab1bb2012-12-07 16:45:52 +00002567 struct bgp_node *rn;
2568 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00002569 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002570
Paul Jakmab2497022007-06-14 11:17:58 +00002571 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002572 return;
2573
paul718e3742002-12-13 20:15:29 +00002574 bgp = peer->bgp;
2575 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002576
paul718e3742002-12-13 20:15:29 +00002577 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2578 aspath = attr.aspath;
2579 attr.local_pref = bgp->default_local_pref;
2580 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2581
2582 if (afi == AFI_IP)
2583 str2prefix ("0.0.0.0/0", &p);
2584#ifdef HAVE_IPV6
2585 else if (afi == AFI_IP6)
2586 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002587 struct attr_extra *ae = attr.extra;
2588
paul718e3742002-12-13 20:15:29 +00002589 str2prefix ("::/0", &p);
2590
2591 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002592 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002593 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002594 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002595
2596 /* If the peer is on shared nextwork and we have link-local
2597 nexthop set it. */
2598 if (peer->shared_network
2599 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2600 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002601 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002602 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002603 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002604 }
2605 }
2606#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002607
2608 if (peer->default_rmap[afi][safi].name)
2609 {
paulfee0f4c2004-09-13 05:12:46 +00002610 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
Christian Frankedcab1bb2012-12-07 16:45:52 +00002611 for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn))
2612 {
2613 for (ri = rn->info; ri; ri = ri->next)
2614 {
2615 struct attr dummy_attr;
2616 struct attr_extra dummy_extra;
2617 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00002618
Christian Frankedcab1bb2012-12-07 16:45:52 +00002619 /* Provide dummy so the route-map can't modify the attributes */
2620 dummy_attr.extra = &dummy_extra;
2621 bgp_attr_dup(&dummy_attr, ri->attr);
2622 info.peer = ri->peer;
2623 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00002624
Christian Frankedcab1bb2012-12-07 16:45:52 +00002625 ret = route_map_apply(peer->default_rmap[afi][safi].map, &rn->p,
2626 RMAP_BGP, &info);
2627
2628 /* The route map might have set attributes. If we don't flush them
2629 * here, they will be leaked. */
2630 bgp_attr_flush(&dummy_attr);
2631 if (ret != RMAP_DENYMATCH)
2632 break;
2633 }
2634 if (ret != RMAP_DENYMATCH)
2635 break;
2636 }
paulfee0f4c2004-09-13 05:12:46 +00002637 bgp->peer_self->rmap_type = 0;
2638
paul718e3742002-12-13 20:15:29 +00002639 if (ret == RMAP_DENYMATCH)
Christian Frankedcab1bb2012-12-07 16:45:52 +00002640 withdraw = 1;
paul718e3742002-12-13 20:15:29 +00002641 }
2642
2643 if (withdraw)
2644 {
2645 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2646 bgp_default_withdraw_send (peer, afi, safi);
2647 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2648 }
2649 else
2650 {
Christian Frankedcab1bb2012-12-07 16:45:52 +00002651 if (! CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2652 {
2653 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2654 bgp_default_update_send (peer, &attr, afi, safi, from);
2655 }
paul718e3742002-12-13 20:15:29 +00002656 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002657
2658 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002659 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002660}
David Lamparter6b0655a2014-06-04 06:53:35 +02002661
paul718e3742002-12-13 20:15:29 +00002662static void
2663bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002664 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002665{
2666 struct bgp_node *rn;
2667 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002668 struct attr attr;
2669 struct attr_extra extra;
2670
Lou Berger298cc2f2016-01-12 13:42:02 -05002671 memset(&extra, 0, sizeof(extra));
2672
paul718e3742002-12-13 20:15:29 +00002673 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002674 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002675
Lou Berger298cc2f2016-01-12 13:42:02 -05002676 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP)
paul718e3742002-12-13 20:15:29 +00002677 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2678 bgp_default_originate (peer, afi, safi, 0);
2679
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002680 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2681 attr.extra = &extra;
2682
paul718e3742002-12-13 20:15:29 +00002683 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2684 for (ri = rn->info; ri; ri = ri->next)
2685 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2686 {
paulfee0f4c2004-09-13 05:12:46 +00002687 if ( (rsclient) ?
2688 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2689 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002690 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2691 else
2692 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2693 }
Lou Berger298cc2f2016-01-12 13:42:02 -05002694
2695 bgp_attr_flush_encap(&attr);
paul718e3742002-12-13 20:15:29 +00002696}
2697
2698void
2699bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2700{
2701 struct bgp_node *rn;
2702 struct bgp_table *table;
2703
2704 if (peer->status != Established)
2705 return;
2706
2707 if (! peer->afc_nego[afi][safi])
2708 return;
2709
2710 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2711 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2712 return;
2713
Lou Berger298cc2f2016-01-12 13:42:02 -05002714 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
paulfee0f4c2004-09-13 05:12:46 +00002715 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002716 else
2717 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2718 rn = bgp_route_next(rn))
2719 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002720 bgp_announce_table (peer, afi, safi, table, 0);
2721
2722 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2723 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002724}
2725
2726void
2727bgp_announce_route_all (struct peer *peer)
2728{
2729 afi_t afi;
2730 safi_t safi;
2731
2732 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2733 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2734 bgp_announce_route (peer, afi, safi);
2735}
David Lamparter6b0655a2014-06-04 06:53:35 +02002736
paul718e3742002-12-13 20:15:29 +00002737static void
paulfee0f4c2004-09-13 05:12:46 +00002738bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002739 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002740{
2741 struct bgp_node *rn;
2742 struct bgp_adj_in *ain;
2743
2744 if (! table)
2745 table = rsclient->bgp->rib[afi][safi];
2746
2747 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2748 for (ain = rn->adj_in; ain; ain = ain->next)
2749 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002750 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002751 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002752
paulfee0f4c2004-09-13 05:12:46 +00002753 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Christian Franked53d8fd2013-01-28 07:14:43 +01002754 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd, tag);
paulfee0f4c2004-09-13 05:12:46 +00002755 }
2756}
2757
2758void
2759bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2760{
2761 struct bgp_table *table;
2762 struct bgp_node *rn;
2763
Lou Berger298cc2f2016-01-12 13:42:02 -05002764 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002765 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002766
2767 else
2768 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2769 rn = bgp_route_next (rn))
2770 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002771 {
2772 struct prefix_rd prd;
2773 prd.family = AF_UNSPEC;
2774 prd.prefixlen = 64;
2775 memcpy(&prd.val, rn->p.u.val, 8);
2776
2777 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2778 }
paulfee0f4c2004-09-13 05:12:46 +00002779}
David Lamparter6b0655a2014-06-04 06:53:35 +02002780
paulfee0f4c2004-09-13 05:12:46 +00002781static void
paul718e3742002-12-13 20:15:29 +00002782bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002783 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002784{
2785 int ret;
2786 struct bgp_node *rn;
2787 struct bgp_adj_in *ain;
2788
2789 if (! table)
2790 table = peer->bgp->rib[afi][safi];
2791
2792 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2793 for (ain = rn->adj_in; ain; ain = ain->next)
2794 {
2795 if (ain->peer == peer)
2796 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002797 struct bgp_info *ri = rn->info;
Christian Franked53d8fd2013-01-28 07:14:43 +01002798 u_char *tag = (ri && ri->extra) ? ri->extra->tag : NULL;
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002799
paul718e3742002-12-13 20:15:29 +00002800 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2801 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Christian Franked53d8fd2013-01-28 07:14:43 +01002802 prd, tag, 1);
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002803
paul718e3742002-12-13 20:15:29 +00002804 if (ret < 0)
2805 {
2806 bgp_unlock_node (rn);
2807 return;
2808 }
2809 continue;
2810 }
2811 }
2812}
2813
2814void
2815bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2816{
2817 struct bgp_node *rn;
2818 struct bgp_table *table;
2819
2820 if (peer->status != Established)
2821 return;
2822
Lou Berger298cc2f2016-01-12 13:42:02 -05002823 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002824 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002825 else
2826 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2827 rn = bgp_route_next (rn))
2828 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002829 {
2830 struct prefix_rd prd;
2831 prd.family = AF_UNSPEC;
2832 prd.prefixlen = 64;
2833 memcpy(&prd.val, rn->p.u.val, 8);
2834
2835 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2836 }
paul718e3742002-12-13 20:15:29 +00002837}
David Lamparter6b0655a2014-06-04 06:53:35 +02002838
Chris Caputo228da422009-07-18 05:44:03 +00002839
2840struct bgp_clear_node_queue
2841{
2842 struct bgp_node *rn;
2843 enum bgp_clear_route_type purpose;
2844};
2845
paul200df112005-06-01 11:17:05 +00002846static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002847bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002848{
Chris Caputo228da422009-07-18 05:44:03 +00002849 struct bgp_clear_node_queue *cnq = data;
2850 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002851 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002852 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002853 afi_t afi = bgp_node_table (rn)->afi;
2854 safi_t safi = bgp_node_table (rn)->safi;
paul200df112005-06-01 11:17:05 +00002855
Paul Jakma64e580a2006-02-21 01:09:01 +00002856 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002857
Paul Jakma64e580a2006-02-21 01:09:01 +00002858 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002859 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002860 {
2861 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002862 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2863 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002864 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002865 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2866 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002867 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002868 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002869 break;
2870 }
paul200df112005-06-01 11:17:05 +00002871 return WQ_SUCCESS;
2872}
2873
2874static void
paul0fb58d52005-11-14 14:31:49 +00002875bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002876{
Chris Caputo228da422009-07-18 05:44:03 +00002877 struct bgp_clear_node_queue *cnq = data;
2878 struct bgp_node *rn = cnq->rn;
Avneesh Sachdev67174042012-08-17 08:19:49 -07002879 struct bgp_table *table = bgp_node_table (rn);
Paul Jakma64e580a2006-02-21 01:09:01 +00002880
2881 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002882 bgp_table_unlock (table);
2883 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002884}
2885
2886static void
paul94f2b392005-06-28 12:44:16 +00002887bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002888{
Paul Jakma64e580a2006-02-21 01:09:01 +00002889 struct peer *peer = wq->spec.data;
2890
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002891 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002892 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002893
2894 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002895}
2896
2897static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002898bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002899{
Paul Jakmaa2943652009-07-21 14:02:04 +01002900 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002901
Paul Jakmaa2943652009-07-21 14:02:04 +01002902 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002903#undef CLEAR_QUEUE_NAME_LEN
2904
2905 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002906 {
2907 zlog_err ("%s: Failed to allocate work queue", __func__);
2908 exit (1);
2909 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002910 peer->clear_node_queue->spec.hold = 10;
2911 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2912 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2913 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2914 peer->clear_node_queue->spec.max_retries = 0;
2915
2916 /* we only 'lock' this peer reference when the queue is actually active */
2917 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002918}
2919
paul718e3742002-12-13 20:15:29 +00002920static void
2921bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002922 struct bgp_table *table, struct peer *rsclient,
2923 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002924{
2925 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002926
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002927
paul718e3742002-12-13 20:15:29 +00002928 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002929 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002930
hasso6cf159b2005-03-21 10:28:14 +00002931 /* If still no table => afi/safi isn't configured at all or smth. */
2932 if (! table)
2933 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002934
2935 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2936 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002937 struct bgp_info *ri;
2938 struct bgp_adj_in *ain;
2939 struct bgp_adj_out *aout;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002940
2941 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2942 * queued for every clearing peer, regardless of whether it is
2943 * relevant to the peer at hand.
2944 *
2945 * Overview: There are 3 different indices which need to be
2946 * scrubbed, potentially, when a peer is removed:
2947 *
2948 * 1 peer's routes visible via the RIB (ie accepted routes)
2949 * 2 peer's routes visible by the (optional) peer's adj-in index
2950 * 3 other routes visible by the peer's adj-out index
2951 *
2952 * 3 there is no hurry in scrubbing, once the struct peer is
2953 * removed from bgp->peer, we could just GC such deleted peer's
2954 * adj-outs at our leisure.
2955 *
2956 * 1 and 2 must be 'scrubbed' in some way, at least made
2957 * invisible via RIB index before peer session is allowed to be
2958 * brought back up. So one needs to know when such a 'search' is
2959 * complete.
2960 *
2961 * Ideally:
2962 *
2963 * - there'd be a single global queue or a single RIB walker
2964 * - rather than tracking which route_nodes still need to be
2965 * examined on a peer basis, we'd track which peers still
2966 * aren't cleared
2967 *
2968 * Given that our per-peer prefix-counts now should be reliable,
2969 * this may actually be achievable. It doesn't seem to be a huge
2970 * problem at this time,
2971 */
Jorge Boncompte [DTI2]24e50f22012-05-07 15:17:33 +00002972 for (ain = rn->adj_in; ain; ain = ain->next)
2973 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2974 {
2975 bgp_adj_in_remove (rn, ain);
2976 bgp_unlock_node (rn);
2977 break;
2978 }
2979 for (aout = rn->adj_out; aout; aout = aout->next)
2980 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
2981 {
2982 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2983 bgp_unlock_node (rn);
2984 break;
2985 }
2986
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002987 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002988 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002989 {
Chris Caputo228da422009-07-18 05:44:03 +00002990 struct bgp_clear_node_queue *cnq;
2991
2992 /* both unlocked in bgp_clear_node_queue_del */
Avneesh Sachdev67174042012-08-17 08:19:49 -07002993 bgp_table_lock (bgp_node_table (rn));
Chris Caputo228da422009-07-18 05:44:03 +00002994 bgp_lock_node (rn);
2995 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2996 sizeof (struct bgp_clear_node_queue));
2997 cnq->rn = rn;
2998 cnq->purpose = purpose;
2999 work_queue_add (peer->clear_node_queue, cnq);
3000 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00003001 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00003002 }
3003 return;
3004}
3005
3006void
Chris Caputo228da422009-07-18 05:44:03 +00003007bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
3008 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00003009{
3010 struct bgp_node *rn;
3011 struct bgp_table *table;
3012 struct peer *rsclient;
3013 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00003014
Paul Jakma64e580a2006-02-21 01:09:01 +00003015 if (peer->clear_node_queue == NULL)
3016 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00003017
Paul Jakmaca058a32006-09-14 02:58:49 +00003018 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
3019 * Idle until it receives a Clearing_Completed event. This protects
3020 * against peers which flap faster than we can we clear, which could
3021 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00003022 *
3023 * a) race with routes from the new session being installed before
3024 * clear_route_node visits the node (to delete the route of that
3025 * peer)
3026 * b) resource exhaustion, clear_route_node likely leads to an entry
3027 * on the process_main queue. Fast-flapping could cause that queue
3028 * to grow and grow.
paul200df112005-06-01 11:17:05 +00003029 */
Donald Sharp7ef42212015-03-30 06:32:52 -07003030
3031 /* lock peer in assumption that clear-node-queue will get nodes; if so,
3032 * the unlock will happen upon work-queue completion; other wise, the
3033 * unlock happens at the end of this function.
3034 */
Paul Jakmaca058a32006-09-14 02:58:49 +00003035 if (!peer->clear_node_queue->thread)
Lou Berger050defe2016-01-12 13:41:59 -05003036 peer_lock (peer); /* bgp_clear_node_complete */
Chris Caputo228da422009-07-18 05:44:03 +00003037 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00003038 {
Chris Caputo228da422009-07-18 05:44:03 +00003039 case BGP_CLEAR_ROUTE_NORMAL:
Lou Berger298cc2f2016-01-12 13:42:02 -05003040 if ((safi != SAFI_MPLS_VPN) && (safi != SAFI_ENCAP))
Chris Caputo228da422009-07-18 05:44:03 +00003041 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
3042 else
3043 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
3044 rn = bgp_route_next (rn))
3045 if ((table = rn->info) != NULL)
3046 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
3047
3048 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
3049 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
3050 PEER_FLAG_RSERVER_CLIENT))
3051 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
3052 break;
3053
3054 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
Lou Berger050defe2016-01-12 13:41:59 -05003055 /*
3056 * gpz 091009: TBD why don't we have special handling for
3057 * SAFI_MPLS_VPN here in the original quagga code?
3058 * (and, by extension, for SAFI_ENCAP)
3059 */
Chris Caputo228da422009-07-18 05:44:03 +00003060 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
3061 break;
3062
3063 default:
3064 assert (0);
3065 break;
paulfee0f4c2004-09-13 05:12:46 +00003066 }
Donald Sharp7ef42212015-03-30 06:32:52 -07003067
3068 /* unlock if no nodes got added to the clear-node-queue. */
Paul Jakma65ca75e2006-05-04 08:08:15 +00003069 if (!peer->clear_node_queue->thread)
Donald Sharp7ef42212015-03-30 06:32:52 -07003070 peer_unlock (peer);
3071
paul718e3742002-12-13 20:15:29 +00003072}
3073
3074void
3075bgp_clear_route_all (struct peer *peer)
3076{
3077 afi_t afi;
3078 safi_t safi;
3079
3080 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3081 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00003082 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00003083}
3084
Lou Berger82dd7072016-01-12 13:41:57 -05003085/*
3086 * Finish freeing things when exiting
3087 */
3088static void
3089bgp_drain_workqueue_immediate (struct work_queue *wq)
3090{
3091 if (!wq)
3092 return;
3093
3094 if (!wq->thread)
3095 {
3096 /*
3097 * no thread implies no queued items
3098 */
3099 assert(!wq->items->count);
3100 return;
3101 }
3102
3103 while (wq->items->count)
3104 {
3105 if (wq->thread)
3106 thread_cancel(wq->thread);
3107 work_queue_run(wq->thread);
3108 }
3109}
3110
3111/*
3112 * Special function to process clear node queue when bgpd is exiting
3113 * and the thread scheduler is no longer running.
3114 */
3115void
3116bgp_peer_clear_node_queue_drain_immediate(struct peer *peer)
3117{
3118 if (!peer)
3119 return;
3120
3121 bgp_drain_workqueue_immediate(peer->clear_node_queue);
3122}
3123
3124/*
3125 * The work queues are not specific to a BGP instance, but the
3126 * items in them refer to BGP instances, so this should be called
3127 * before each BGP instance is deleted.
3128 */
3129void
3130bgp_process_queues_drain_immediate(void)
3131{
3132 bgp_drain_workqueue_immediate(bm->process_main_queue);
3133 bgp_drain_workqueue_immediate(bm->process_rsclient_queue);
3134}
3135
paul718e3742002-12-13 20:15:29 +00003136void
3137bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
3138{
3139 struct bgp_table *table;
3140 struct bgp_node *rn;
3141 struct bgp_adj_in *ain;
3142
3143 table = peer->bgp->rib[afi][safi];
3144
3145 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3146 for (ain = rn->adj_in; ain ; ain = ain->next)
3147 if (ain->peer == peer)
3148 {
3149 bgp_adj_in_remove (rn, ain);
3150 bgp_unlock_node (rn);
3151 break;
3152 }
3153}
hasso93406d82005-02-02 14:40:33 +00003154
3155void
3156bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
3157{
3158 struct bgp_node *rn;
3159 struct bgp_info *ri;
3160 struct bgp_table *table;
3161
3162 table = peer->bgp->rib[afi][safi];
3163
3164 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3165 {
3166 for (ri = rn->info; ri; ri = ri->next)
3167 if (ri->peer == peer)
3168 {
3169 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3170 bgp_rib_remove (rn, ri, peer, afi, safi);
3171 break;
3172 }
3173 }
3174}
David Lamparter6b0655a2014-06-04 06:53:35 +02003175
Lou Berger82dd7072016-01-12 13:41:57 -05003176static void
3177bgp_cleanup_table(struct bgp_table *table, safi_t safi)
3178{
3179 struct bgp_node *rn;
3180 struct bgp_info *ri;
3181 struct bgp_info *next;
3182
3183 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3184 for (ri = rn->info; ri; ri = next)
3185 {
3186 next = ri->next;
3187 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3188 && ri->type == ZEBRA_ROUTE_BGP
3189 && ri->sub_type == BGP_ROUTE_NORMAL)
3190 bgp_zebra_withdraw (&rn->p, ri, safi);
3191 }
3192}
3193
paul718e3742002-12-13 20:15:29 +00003194/* Delete all kernel routes. */
3195void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003196bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003197{
3198 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003199 struct listnode *node, *nnode;
Lou Berger82dd7072016-01-12 13:41:57 -05003200 afi_t afi;
paul718e3742002-12-13 20:15:29 +00003201
paul1eb8ef22005-04-07 07:30:20 +00003202 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003203 {
Lou Berger82dd7072016-01-12 13:41:57 -05003204 for (afi = AFI_IP; afi < AFI_MAX; ++afi)
3205 {
3206 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00003207
Lou Berger82dd7072016-01-12 13:41:57 -05003208 bgp_cleanup_table(bgp->rib[afi][SAFI_UNICAST], SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003209
Lou Berger82dd7072016-01-12 13:41:57 -05003210 /*
3211 * VPN and ENCAP tables are two-level (RD is top level)
3212 */
3213 for (rn = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn;
3214 rn = bgp_route_next (rn))
Lou Berger298cc2f2016-01-12 13:42:02 -05003215 {
3216 if (rn->info)
Lou Berger82dd7072016-01-12 13:41:57 -05003217 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003218 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_MPLS_VPN);
3219 bgp_table_finish ((struct bgp_table **)&(rn->info));
3220 rn->info = NULL;
3221 bgp_unlock_node(rn);
Lou Berger82dd7072016-01-12 13:41:57 -05003222 }
Lou Berger298cc2f2016-01-12 13:42:02 -05003223 }
3224
3225 for (rn = bgp_table_top(bgp->rib[afi][SAFI_ENCAP]); rn;
3226 rn = bgp_route_next (rn))
3227 {
3228 if (rn->info)
3229 {
3230 bgp_cleanup_table((struct bgp_table *)(rn->info), SAFI_ENCAP);
3231 bgp_table_finish ((struct bgp_table **)&(rn->info));
3232 rn->info = NULL;
3233 bgp_unlock_node(rn);
3234 }
3235 }
Lou Berger82dd7072016-01-12 13:41:57 -05003236 }
paul718e3742002-12-13 20:15:29 +00003237 }
3238}
3239
3240void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003241bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003242{
3243 vty_reset ();
3244 bgp_zclient_reset ();
3245 access_list_reset ();
3246 prefix_list_reset ();
3247}
David Lamparter6b0655a2014-06-04 06:53:35 +02003248
paul718e3742002-12-13 20:15:29 +00003249/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3250 value. */
3251int
3252bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3253{
3254 u_char *pnt;
3255 u_char *lim;
3256 struct prefix p;
3257 int psize;
3258 int ret;
3259
3260 /* Check peer status. */
3261 if (peer->status != Established)
3262 return 0;
3263
3264 pnt = packet->nlri;
3265 lim = pnt + packet->length;
3266
3267 for (; pnt < lim; pnt += psize)
3268 {
3269 /* Clear prefix structure. */
3270 memset (&p, 0, sizeof (struct prefix));
3271
3272 /* Fetch prefix length. */
3273 p.prefixlen = *pnt++;
3274 p.family = afi2family (packet->afi);
3275
3276 /* Already checked in nlri_sanity_check(). We do double check
3277 here. */
3278 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3279 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3280 return -1;
3281
3282 /* Packet size overflow check. */
3283 psize = PSIZE (p.prefixlen);
3284
3285 /* When packet overflow occur return immediately. */
3286 if (pnt + psize > lim)
3287 return -1;
3288
3289 /* Fetch prefix from NLRI packet. */
3290 memcpy (&p.u.prefix, pnt, psize);
3291
3292 /* Check address. */
3293 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3294 {
3295 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3296 {
paulf5ba3872004-07-09 12:11:31 +00003297 /*
3298 * From draft-ietf-idr-bgp4-22, Section 6.3:
3299 * If a BGP router receives an UPDATE message with a
3300 * semantically incorrect NLRI field, in which a prefix is
3301 * semantically incorrect (eg. an unexpected multicast IP
3302 * address), it should ignore the prefix.
3303 */
paul718e3742002-12-13 20:15:29 +00003304 zlog (peer->log, LOG_ERR,
3305 "IPv4 unicast NLRI is multicast address %s",
3306 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003307
paul718e3742002-12-13 20:15:29 +00003308 return -1;
3309 }
3310 }
3311
3312#ifdef HAVE_IPV6
3313 /* Check address. */
3314 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3315 {
3316 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3317 {
3318 char buf[BUFSIZ];
3319
3320 zlog (peer->log, LOG_WARNING,
3321 "IPv6 link-local NLRI received %s ignore this NLRI",
3322 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3323
3324 continue;
3325 }
3326 }
3327#endif /* HAVE_IPV6 */
3328
3329 /* Normal process. */
3330 if (attr)
3331 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3332 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3333 else
3334 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3335 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3336
3337 /* Address family configuration mismatch or maximum-prefix count
3338 overflow. */
3339 if (ret < 0)
3340 return -1;
3341 }
3342
3343 /* Packet length consistency check. */
3344 if (pnt != lim)
3345 return -1;
3346
3347 return 0;
3348}
3349
3350/* NLRI encode syntax check routine. */
3351int
Lou Berger050defe2016-01-12 13:41:59 -05003352bgp_nlri_sanity_check (struct peer *peer, int afi, safi_t safi,
3353 u_char *pnt, bgp_size_t length)
paul718e3742002-12-13 20:15:29 +00003354{
3355 u_char *end;
3356 u_char prefixlen;
3357 int psize;
3358
3359 end = pnt + length;
3360
3361 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3362 syntactic validity. If the field is syntactically incorrect,
3363 then the Error Subcode is set to Invalid Network Field. */
3364
3365 while (pnt < end)
3366 {
Lou Berger298cc2f2016-01-12 13:42:02 -05003367 int badlength;
paul718e3742002-12-13 20:15:29 +00003368 prefixlen = *pnt++;
3369
3370 /* Prefix length check. */
Lou Berger298cc2f2016-01-12 13:42:02 -05003371 badlength = 0;
3372 if (safi == SAFI_ENCAP) {
3373 if (prefixlen > 128)
3374 badlength = 1;
3375 } else {
3376 if ((afi == AFI_IP && prefixlen > 32) ||
3377 (afi == AFI_IP6 && prefixlen > 128)) {
3378
3379 badlength = 1;
3380 }
3381 }
3382 if (badlength)
paul718e3742002-12-13 20:15:29 +00003383 {
3384 plog_err (peer->log,
3385 "%s [Error] Update packet error (wrong prefix length %d)",
3386 peer->host, prefixlen);
3387 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3388 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3389 return -1;
3390 }
3391
3392 /* Packet size overflow check. */
3393 psize = PSIZE (prefixlen);
3394
3395 if (pnt + psize > end)
3396 {
3397 plog_err (peer->log,
3398 "%s [Error] Update packet error"
3399 " (prefix data overflow prefix size is %d)",
3400 peer->host, psize);
3401 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3402 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3403 return -1;
3404 }
3405
3406 pnt += psize;
3407 }
3408
3409 /* Packet length consistency check. */
3410 if (pnt != end)
3411 {
3412 plog_err (peer->log,
3413 "%s [Error] Update packet error"
3414 " (prefix length mismatch with total length)",
3415 peer->host);
3416 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3417 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3418 return -1;
3419 }
3420 return 0;
3421}
David Lamparter6b0655a2014-06-04 06:53:35 +02003422
paul94f2b392005-06-28 12:44:16 +00003423static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003424bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003425{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003426 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003427}
3428
paul94f2b392005-06-28 12:44:16 +00003429static void
paul718e3742002-12-13 20:15:29 +00003430bgp_static_free (struct bgp_static *bgp_static)
3431{
3432 if (bgp_static->rmap.name)
3433 free (bgp_static->rmap.name);
3434 XFREE (MTYPE_BGP_STATIC, bgp_static);
3435}
3436
paul94f2b392005-06-28 12:44:16 +00003437static void
paulfee0f4c2004-09-13 05:12:46 +00003438bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3439 struct prefix *p, afi_t afi, safi_t safi)
3440{
3441 struct bgp_node *rn;
3442 struct bgp_info *ri;
3443
3444 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3445
3446 /* Check selected route and self inserted route. */
3447 for (ri = rn->info; ri; ri = ri->next)
3448 if (ri->peer == bgp->peer_self
3449 && ri->type == ZEBRA_ROUTE_BGP
3450 && ri->sub_type == BGP_ROUTE_STATIC)
3451 break;
3452
3453 /* Withdraw static BGP route from routing table. */
3454 if (ri)
3455 {
paulfee0f4c2004-09-13 05:12:46 +00003456 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003457 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003458 }
3459
3460 /* Unlock bgp_node_lookup. */
3461 bgp_unlock_node (rn);
3462}
3463
paul94f2b392005-06-28 12:44:16 +00003464static void
paulfee0f4c2004-09-13 05:12:46 +00003465bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003466 struct bgp_static *bgp_static,
3467 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003468{
3469 struct bgp_node *rn;
3470 struct bgp_info *ri;
3471 struct bgp_info *new;
3472 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003473 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003474 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003475 struct attr new_attr;
3476 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003477 struct bgp *bgp;
3478 int ret;
3479 char buf[SU_ADDRSTRLEN];
3480
3481 bgp = rsclient->bgp;
3482
Paul Jakma06e110f2006-05-12 23:29:22 +00003483 assert (bgp_static);
3484 if (!bgp_static)
3485 return;
3486
paulfee0f4c2004-09-13 05:12:46 +00003487 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3488
3489 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003490
3491 attr.nexthop = bgp_static->igpnexthop;
3492 attr.med = bgp_static->igpmetric;
3493 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003494
Paul Jakma41367172007-08-06 15:24:51 +00003495 if (bgp_static->atomic)
3496 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3497
paulfee0f4c2004-09-13 05:12:46 +00003498 /* Apply network route-map for export to this rsclient. */
3499 if (bgp_static->rmap.name)
3500 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003501 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003502 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003503 info.attr = &attr_tmp;
3504
paulfee0f4c2004-09-13 05:12:46 +00003505 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3506 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3507
3508 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3509
3510 rsclient->rmap_type = 0;
3511
3512 if (ret == RMAP_DENYMATCH)
3513 {
3514 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003515 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003516
3517 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003518 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003519 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003520 bgp_attr_extra_free (&attr);
3521
paulfee0f4c2004-09-13 05:12:46 +00003522 return;
3523 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003524 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003525 }
3526 else
3527 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003528
3529 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003530 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003531
paulfee0f4c2004-09-13 05:12:46 +00003532 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3533
Paul Jakmafb982c22007-05-04 20:15:47 +00003534 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3535 == RMAP_DENY)
3536 {
paulfee0f4c2004-09-13 05:12:46 +00003537 /* This BGP update is filtered. Log the reason then update BGP entry. */
3538 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003539 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003540 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3541 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3542 p->prefixlen, rsclient->host);
3543
3544 bgp->peer_self->rmap_type = 0;
3545
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003546 bgp_attr_unintern (&attr_new);
3547 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003548 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003549
3550 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3551
3552 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003553 }
paulfee0f4c2004-09-13 05:12:46 +00003554
3555 bgp->peer_self->rmap_type = 0;
3556
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003557 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003558 attr_new = bgp_attr_intern (&new_attr);
3559
3560 for (ri = rn->info; ri; ri = ri->next)
3561 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3562 && ri->sub_type == BGP_ROUTE_STATIC)
3563 break;
3564
3565 if (ri)
3566 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003567 if (attrhash_cmp (ri->attr, attr_new) &&
3568 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003569 {
3570 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003571 bgp_attr_unintern (&attr_new);
3572 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003573 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003574 return;
3575 }
3576 else
3577 {
3578 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003579 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003580
3581 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003582 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3583 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003584 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003585 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003586 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003587
3588 /* Process change. */
3589 bgp_process (bgp, rn, afi, safi);
3590 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003591 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003592 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003593 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003594 }
paulfee0f4c2004-09-13 05:12:46 +00003595 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003596
paulfee0f4c2004-09-13 05:12:46 +00003597 /* Make new BGP info. */
3598 new = bgp_info_new ();
3599 new->type = ZEBRA_ROUTE_BGP;
3600 new->sub_type = BGP_ROUTE_STATIC;
3601 new->peer = bgp->peer_self;
3602 SET_FLAG (new->flags, BGP_INFO_VALID);
3603 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003604 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003605
3606 /* Register new BGP information. */
3607 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003608
3609 /* route_node_get lock */
3610 bgp_unlock_node (rn);
3611
paulfee0f4c2004-09-13 05:12:46 +00003612 /* Process change. */
3613 bgp_process (bgp, rn, afi, safi);
3614
3615 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003616 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003617 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003618}
3619
paul94f2b392005-06-28 12:44:16 +00003620static void
paulfee0f4c2004-09-13 05:12:46 +00003621bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003622 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3623{
3624 struct bgp_node *rn;
3625 struct bgp_info *ri;
3626 struct bgp_info *new;
3627 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003628 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003629 struct attr *attr_new;
3630 int ret;
3631
Paul Jakmadd8103a2006-05-12 23:27:30 +00003632 assert (bgp_static);
3633 if (!bgp_static)
3634 return;
3635
paulfee0f4c2004-09-13 05:12:46 +00003636 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003637
3638 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003639
3640 attr.nexthop = bgp_static->igpnexthop;
3641 attr.med = bgp_static->igpmetric;
3642 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003643
Paul Jakma41367172007-08-06 15:24:51 +00003644 if (bgp_static->atomic)
3645 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3646
paul718e3742002-12-13 20:15:29 +00003647 /* Apply route-map. */
3648 if (bgp_static->rmap.name)
3649 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003650 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003651 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003652 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003653
paulfee0f4c2004-09-13 05:12:46 +00003654 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3655
paul718e3742002-12-13 20:15:29 +00003656 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003657
paulfee0f4c2004-09-13 05:12:46 +00003658 bgp->peer_self->rmap_type = 0;
3659
paul718e3742002-12-13 20:15:29 +00003660 if (ret == RMAP_DENYMATCH)
3661 {
3662 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003663 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003664
3665 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003666 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003667 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003668 bgp_static_withdraw (bgp, p, afi, safi);
3669 return;
3670 }
paul286e1e72003-08-08 00:24:31 +00003671 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003672 }
paul286e1e72003-08-08 00:24:31 +00003673 else
3674 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003675
3676 for (ri = rn->info; ri; ri = ri->next)
3677 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3678 && ri->sub_type == BGP_ROUTE_STATIC)
3679 break;
3680
3681 if (ri)
3682 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003683 if (attrhash_cmp (ri->attr, attr_new) &&
3684 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003685 {
3686 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003687 bgp_attr_unintern (&attr_new);
3688 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003689 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003690 return;
3691 }
3692 else
3693 {
3694 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003695 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003696
3697 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003698 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3699 bgp_info_restore(rn, ri);
3700 else
3701 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003702 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003703 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003704 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003705
3706 /* Process change. */
3707 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3708 bgp_process (bgp, rn, afi, safi);
3709 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003710 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003711 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003712 return;
3713 }
3714 }
3715
3716 /* Make new BGP info. */
3717 new = bgp_info_new ();
3718 new->type = ZEBRA_ROUTE_BGP;
3719 new->sub_type = BGP_ROUTE_STATIC;
3720 new->peer = bgp->peer_self;
3721 SET_FLAG (new->flags, BGP_INFO_VALID);
3722 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003723 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003724
3725 /* Aggregate address increment. */
3726 bgp_aggregate_increment (bgp, p, new, afi, safi);
3727
3728 /* Register new BGP information. */
3729 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003730
3731 /* route_node_get lock */
3732 bgp_unlock_node (rn);
3733
paul718e3742002-12-13 20:15:29 +00003734 /* Process change. */
3735 bgp_process (bgp, rn, afi, safi);
3736
3737 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003738 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003739 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003740}
3741
3742void
paulfee0f4c2004-09-13 05:12:46 +00003743bgp_static_update (struct bgp *bgp, struct prefix *p,
3744 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3745{
3746 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003747 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003748
3749 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3750
paul1eb8ef22005-04-07 07:30:20 +00003751 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003752 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003753 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3754 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003755 }
3756}
3757
paul718e3742002-12-13 20:15:29 +00003758void
3759bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3760 safi_t safi)
3761{
3762 struct bgp_node *rn;
3763 struct bgp_info *ri;
3764
paulfee0f4c2004-09-13 05:12:46 +00003765 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003766
3767 /* Check selected route and self inserted route. */
3768 for (ri = rn->info; ri; ri = ri->next)
3769 if (ri->peer == bgp->peer_self
3770 && ri->type == ZEBRA_ROUTE_BGP
3771 && ri->sub_type == BGP_ROUTE_STATIC)
3772 break;
3773
3774 /* Withdraw static BGP route from routing table. */
3775 if (ri)
3776 {
3777 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003778 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003779 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003780 }
3781
3782 /* Unlock bgp_node_lookup. */
3783 bgp_unlock_node (rn);
3784}
3785
3786void
paulfee0f4c2004-09-13 05:12:46 +00003787bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3788{
3789 struct bgp_static *bgp_static;
3790 struct bgp *bgp;
3791 struct bgp_node *rn;
3792 struct prefix *p;
3793
3794 bgp = rsclient->bgp;
3795
3796 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3797 if ((bgp_static = rn->info) != NULL)
3798 {
3799 p = &rn->p;
3800
3801 bgp_static_update_rsclient (rsclient, p, bgp_static,
3802 afi, safi);
3803 }
3804}
3805
Lou Bergera76d9ca2016-01-12 13:41:53 -05003806/*
3807 * Used for SAFI_MPLS_VPN and SAFI_ENCAP
3808 */
paul94f2b392005-06-28 12:44:16 +00003809static void
Lou Bergera76d9ca2016-01-12 13:41:53 -05003810bgp_static_withdraw_safi (struct bgp *bgp, struct prefix *p, afi_t afi,
3811 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003812{
3813 struct bgp_node *rn;
3814 struct bgp_info *ri;
3815
paulfee0f4c2004-09-13 05:12:46 +00003816 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003817
3818 /* Check selected route and self inserted route. */
3819 for (ri = rn->info; ri; ri = ri->next)
3820 if (ri->peer == bgp->peer_self
3821 && ri->type == ZEBRA_ROUTE_BGP
3822 && ri->sub_type == BGP_ROUTE_STATIC)
3823 break;
3824
3825 /* Withdraw static BGP route from routing table. */
3826 if (ri)
3827 {
3828 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003829 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003830 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003831 }
3832
3833 /* Unlock bgp_node_lookup. */
3834 bgp_unlock_node (rn);
3835}
3836
Lou Bergera76d9ca2016-01-12 13:41:53 -05003837static void
3838bgp_static_update_safi (struct bgp *bgp, struct prefix *p,
3839 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3840{
3841 struct bgp_node *rn;
3842 struct bgp_info *new;
3843 struct attr *attr_new;
3844 struct attr attr = { 0 };
3845 struct bgp_info *ri;
3846
3847 assert (bgp_static);
3848
3849 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, &bgp_static->prd);
3850
3851 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
3852
3853 attr.nexthop = bgp_static->igpnexthop;
3854 attr.med = bgp_static->igpmetric;
3855 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
3856
3857 /* Apply route-map. */
3858 if (bgp_static->rmap.name)
3859 {
3860 struct attr attr_tmp = attr;
3861 struct bgp_info info;
3862 int ret;
3863
3864 info.peer = bgp->peer_self;
3865 info.attr = &attr_tmp;
3866
3867 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3868
3869 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3870
3871 bgp->peer_self->rmap_type = 0;
3872
3873 if (ret == RMAP_DENYMATCH)
3874 {
3875 /* Free uninterned attribute. */
3876 bgp_attr_flush (&attr_tmp);
3877
3878 /* Unintern original. */
3879 aspath_unintern (&attr.aspath);
3880 bgp_attr_extra_free (&attr);
3881 bgp_static_withdraw_safi (bgp, p, afi, safi, &bgp_static->prd,
3882 bgp_static->tag);
3883 return;
3884 }
3885
3886 attr_new = bgp_attr_intern (&attr_tmp);
3887 }
3888 else
3889 {
3890 attr_new = bgp_attr_intern (&attr);
3891 }
3892
3893 for (ri = rn->info; ri; ri = ri->next)
3894 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3895 && ri->sub_type == BGP_ROUTE_STATIC)
3896 break;
3897
3898 if (ri)
3899 {
3900 if (attrhash_cmp (ri->attr, attr_new) &&
3901 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3902 {
3903 bgp_unlock_node (rn);
3904 bgp_attr_unintern (&attr_new);
3905 aspath_unintern (&attr.aspath);
3906 bgp_attr_extra_free (&attr);
3907 return;
3908 }
3909 else
3910 {
3911 /* The attribute is changed. */
3912 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
3913
3914 /* Rewrite BGP route information. */
3915 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3916 bgp_info_restore(rn, ri);
3917 else
3918 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
3919 bgp_attr_unintern (&ri->attr);
3920 ri->attr = attr_new;
3921 ri->uptime = bgp_clock ();
3922
3923 /* Process change. */
3924 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3925 bgp_process (bgp, rn, afi, safi);
3926 bgp_unlock_node (rn);
3927 aspath_unintern (&attr.aspath);
3928 bgp_attr_extra_free (&attr);
3929 return;
3930 }
3931 }
3932
3933
3934 /* Make new BGP info. */
3935 new = bgp_info_new ();
3936 new->type = ZEBRA_ROUTE_BGP;
3937 new->sub_type = BGP_ROUTE_STATIC;
3938 new->peer = bgp->peer_self;
3939 new->attr = attr_new;
3940 SET_FLAG (new->flags, BGP_INFO_VALID);
3941 new->uptime = bgp_clock ();
3942 new->extra = bgp_info_extra_new();
3943 memcpy (new->extra->tag, bgp_static->tag, 3);
3944
3945 /* Aggregate address increment. */
3946 bgp_aggregate_increment (bgp, p, new, afi, safi);
3947
3948 /* Register new BGP information. */
3949 bgp_info_add (rn, new);
3950
3951 /* route_node_get lock */
3952 bgp_unlock_node (rn);
3953
3954 /* Process change. */
3955 bgp_process (bgp, rn, afi, safi);
3956
3957 /* Unintern original. */
3958 aspath_unintern (&attr.aspath);
3959 bgp_attr_extra_free (&attr);
3960}
3961
paul718e3742002-12-13 20:15:29 +00003962/* Configure static BGP network. When user don't run zebra, static
3963 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003964static int
paulfd79ac92004-10-13 05:06:08 +00003965bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003966 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003967{
3968 int ret;
3969 struct prefix p;
3970 struct bgp_static *bgp_static;
3971 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003972 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003973
3974 /* Convert IP prefix string to struct prefix. */
3975 ret = str2prefix (ip_str, &p);
3976 if (! ret)
3977 {
3978 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3979 return CMD_WARNING;
3980 }
3981#ifdef HAVE_IPV6
3982 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3983 {
3984 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3985 VTY_NEWLINE);
3986 return CMD_WARNING;
3987 }
3988#endif /* HAVE_IPV6 */
3989
3990 apply_mask (&p);
3991
3992 /* Set BGP static route configuration. */
3993 rn = bgp_node_get (bgp->route[afi][safi], &p);
3994
3995 if (rn->info)
3996 {
3997 /* Configuration change. */
3998 bgp_static = rn->info;
3999
4000 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004001 if (bgp_static->valid && bgp_static->backdoor != backdoor)
4002 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00004003
paul718e3742002-12-13 20:15:29 +00004004 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00004005
paul718e3742002-12-13 20:15:29 +00004006 if (rmap)
4007 {
4008 if (bgp_static->rmap.name)
4009 free (bgp_static->rmap.name);
4010 bgp_static->rmap.name = strdup (rmap);
4011 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4012 }
4013 else
4014 {
4015 if (bgp_static->rmap.name)
4016 free (bgp_static->rmap.name);
4017 bgp_static->rmap.name = NULL;
4018 bgp_static->rmap.map = NULL;
4019 bgp_static->valid = 0;
4020 }
4021 bgp_unlock_node (rn);
4022 }
4023 else
4024 {
4025 /* New configuration. */
4026 bgp_static = bgp_static_new ();
4027 bgp_static->backdoor = backdoor;
4028 bgp_static->valid = 0;
4029 bgp_static->igpmetric = 0;
4030 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00004031
paul718e3742002-12-13 20:15:29 +00004032 if (rmap)
4033 {
4034 if (bgp_static->rmap.name)
4035 free (bgp_static->rmap.name);
4036 bgp_static->rmap.name = strdup (rmap);
4037 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
4038 }
4039 rn->info = bgp_static;
4040 }
4041
4042 /* If BGP scan is not enabled, we should install this route here. */
4043 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
4044 {
4045 bgp_static->valid = 1;
4046
4047 if (need_update)
4048 bgp_static_withdraw (bgp, &p, afi, safi);
4049
4050 if (! bgp_static->backdoor)
4051 bgp_static_update (bgp, &p, bgp_static, afi, safi);
4052 }
4053
4054 return CMD_SUCCESS;
4055}
4056
4057/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00004058static int
paulfd79ac92004-10-13 05:06:08 +00004059bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04004060 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004061{
4062 int ret;
4063 struct prefix p;
4064 struct bgp_static *bgp_static;
4065 struct bgp_node *rn;
4066
4067 /* Convert IP prefix string to struct prefix. */
4068 ret = str2prefix (ip_str, &p);
4069 if (! ret)
4070 {
4071 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4072 return CMD_WARNING;
4073 }
4074#ifdef HAVE_IPV6
4075 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
4076 {
4077 vty_out (vty, "%% Malformed prefix (link-local address)%s",
4078 VTY_NEWLINE);
4079 return CMD_WARNING;
4080 }
4081#endif /* HAVE_IPV6 */
4082
4083 apply_mask (&p);
4084
4085 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
4086 if (! rn)
4087 {
4088 vty_out (vty, "%% Can't find specified static route configuration.%s",
4089 VTY_NEWLINE);
4090 return CMD_WARNING;
4091 }
4092
4093 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00004094
paul718e3742002-12-13 20:15:29 +00004095 /* Update BGP RIB. */
4096 if (! bgp_static->backdoor)
4097 bgp_static_withdraw (bgp, &p, afi, safi);
4098
4099 /* Clear configuration. */
4100 bgp_static_free (bgp_static);
4101 rn->info = NULL;
4102 bgp_unlock_node (rn);
4103 bgp_unlock_node (rn);
4104
4105 return CMD_SUCCESS;
4106}
4107
4108/* Called from bgp_delete(). Delete all static routes from the BGP
4109 instance. */
4110void
4111bgp_static_delete (struct bgp *bgp)
4112{
4113 afi_t afi;
4114 safi_t safi;
4115 struct bgp_node *rn;
4116 struct bgp_node *rm;
4117 struct bgp_table *table;
4118 struct bgp_static *bgp_static;
4119
4120 for (afi = AFI_IP; afi < AFI_MAX; afi++)
4121 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
4122 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
4123 if (rn->info != NULL)
4124 {
Lou Berger298cc2f2016-01-12 13:42:02 -05004125 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004126 {
4127 table = rn->info;
4128
4129 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
4130 {
4131 bgp_static = rn->info;
Lou Bergera76d9ca2016-01-12 13:41:53 -05004132 bgp_static_withdraw_safi (bgp, &rm->p,
4133 AFI_IP, safi,
paul718e3742002-12-13 20:15:29 +00004134 (struct prefix_rd *)&rn->p,
4135 bgp_static->tag);
4136 bgp_static_free (bgp_static);
4137 rn->info = NULL;
4138 bgp_unlock_node (rn);
4139 }
4140 }
4141 else
4142 {
4143 bgp_static = rn->info;
4144 bgp_static_withdraw (bgp, &rn->p, afi, safi);
4145 bgp_static_free (bgp_static);
4146 rn->info = NULL;
4147 bgp_unlock_node (rn);
4148 }
4149 }
4150}
4151
Lou Bergera76d9ca2016-01-12 13:41:53 -05004152/*
4153 * gpz 110624
4154 * Currently this is used to set static routes for VPN and ENCAP.
4155 * I think it can probably be factored with bgp_static_set.
4156 */
paul718e3742002-12-13 20:15:29 +00004157int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004158bgp_static_set_safi (safi_t safi, struct vty *vty, const char *ip_str,
4159 const char *rd_str, const char *tag_str,
4160 const char *rmap_str)
paul718e3742002-12-13 20:15:29 +00004161{
4162 int ret;
4163 struct prefix p;
4164 struct prefix_rd prd;
4165 struct bgp *bgp;
4166 struct bgp_node *prn;
4167 struct bgp_node *rn;
4168 struct bgp_table *table;
4169 struct bgp_static *bgp_static;
4170 u_char tag[3];
4171
4172 bgp = vty->index;
4173
4174 ret = str2prefix (ip_str, &p);
4175 if (! ret)
4176 {
4177 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4178 return CMD_WARNING;
4179 }
4180 apply_mask (&p);
4181
4182 ret = str2prefix_rd (rd_str, &prd);
4183 if (! ret)
4184 {
4185 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4186 return CMD_WARNING;
4187 }
4188
4189 ret = str2tag (tag_str, tag);
4190 if (! ret)
4191 {
4192 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4193 return CMD_WARNING;
4194 }
4195
Lou Bergera76d9ca2016-01-12 13:41:53 -05004196 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004197 (struct prefix *)&prd);
4198 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004199 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004200 else
4201 bgp_unlock_node (prn);
4202 table = prn->info;
4203
4204 rn = bgp_node_get (table, &p);
4205
4206 if (rn->info)
4207 {
4208 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
4209 bgp_unlock_node (rn);
4210 }
4211 else
4212 {
4213 /* New configuration. */
4214 bgp_static = bgp_static_new ();
Lou Bergera76d9ca2016-01-12 13:41:53 -05004215 bgp_static->backdoor = 0;
4216 bgp_static->valid = 0;
4217 bgp_static->igpmetric = 0;
4218 bgp_static->igpnexthop.s_addr = 0;
4219 memcpy(bgp_static->tag, tag, 3);
4220 bgp_static->prd = prd;
4221
4222 if (rmap_str)
4223 {
4224 if (bgp_static->rmap.name)
4225 free (bgp_static->rmap.name);
4226 bgp_static->rmap.name = strdup (rmap_str);
4227 bgp_static->rmap.map = route_map_lookup_by_name (rmap_str);
4228 }
paul718e3742002-12-13 20:15:29 +00004229 rn->info = bgp_static;
4230
Lou Bergera76d9ca2016-01-12 13:41:53 -05004231 bgp_static->valid = 1;
4232 bgp_static_update_safi (bgp, &p, bgp_static, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004233 }
4234
4235 return CMD_SUCCESS;
4236}
4237
4238/* Configure static BGP network. */
4239int
Lou Bergera76d9ca2016-01-12 13:41:53 -05004240bgp_static_unset_safi(safi_t safi, struct vty *vty, const char *ip_str,
4241 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00004242{
4243 int ret;
4244 struct bgp *bgp;
4245 struct prefix p;
4246 struct prefix_rd prd;
4247 struct bgp_node *prn;
4248 struct bgp_node *rn;
4249 struct bgp_table *table;
4250 struct bgp_static *bgp_static;
4251 u_char tag[3];
4252
4253 bgp = vty->index;
4254
4255 /* Convert IP prefix string to struct prefix. */
4256 ret = str2prefix (ip_str, &p);
4257 if (! ret)
4258 {
4259 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
4260 return CMD_WARNING;
4261 }
4262 apply_mask (&p);
4263
4264 ret = str2prefix_rd (rd_str, &prd);
4265 if (! ret)
4266 {
4267 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
4268 return CMD_WARNING;
4269 }
4270
4271 ret = str2tag (tag_str, tag);
4272 if (! ret)
4273 {
4274 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
4275 return CMD_WARNING;
4276 }
4277
Lou Bergera76d9ca2016-01-12 13:41:53 -05004278 prn = bgp_node_get (bgp->route[AFI_IP][safi],
paul718e3742002-12-13 20:15:29 +00004279 (struct prefix *)&prd);
4280 if (prn->info == NULL)
Lou Bergera76d9ca2016-01-12 13:41:53 -05004281 prn->info = bgp_table_init (AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00004282 else
4283 bgp_unlock_node (prn);
4284 table = prn->info;
4285
4286 rn = bgp_node_lookup (table, &p);
4287
4288 if (rn)
4289 {
Lou Bergera76d9ca2016-01-12 13:41:53 -05004290 bgp_static_withdraw_safi (bgp, &p, AFI_IP, safi, &prd, tag);
paul718e3742002-12-13 20:15:29 +00004291
4292 bgp_static = rn->info;
4293 bgp_static_free (bgp_static);
4294 rn->info = NULL;
4295 bgp_unlock_node (rn);
4296 bgp_unlock_node (rn);
4297 }
4298 else
4299 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
4300
4301 return CMD_SUCCESS;
4302}
David Lamparter6b0655a2014-06-04 06:53:35 +02004303
paul718e3742002-12-13 20:15:29 +00004304DEFUN (bgp_network,
4305 bgp_network_cmd,
4306 "network A.B.C.D/M",
4307 "Specify a network to announce via BGP\n"
4308 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4309{
4310 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004311 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004312}
4313
4314DEFUN (bgp_network_route_map,
4315 bgp_network_route_map_cmd,
4316 "network A.B.C.D/M route-map WORD",
4317 "Specify a network to announce via BGP\n"
4318 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4319 "Route-map to modify the attributes\n"
4320 "Name of the route map\n")
4321{
4322 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004323 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004324}
4325
4326DEFUN (bgp_network_backdoor,
4327 bgp_network_backdoor_cmd,
4328 "network A.B.C.D/M backdoor",
4329 "Specify a network to announce via BGP\n"
4330 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4331 "Specify a BGP backdoor route\n")
4332{
Paul Jakma41367172007-08-06 15:24:51 +00004333 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004334 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004335}
4336
4337DEFUN (bgp_network_mask,
4338 bgp_network_mask_cmd,
4339 "network A.B.C.D mask A.B.C.D",
4340 "Specify a network to announce via BGP\n"
4341 "Network number\n"
4342 "Network mask\n"
4343 "Network mask\n")
4344{
4345 int ret;
4346 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004347
paul718e3742002-12-13 20:15:29 +00004348 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4349 if (! ret)
4350 {
4351 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4352 return CMD_WARNING;
4353 }
4354
4355 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004356 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004357}
4358
4359DEFUN (bgp_network_mask_route_map,
4360 bgp_network_mask_route_map_cmd,
4361 "network A.B.C.D mask A.B.C.D route-map WORD",
4362 "Specify a network to announce via BGP\n"
4363 "Network number\n"
4364 "Network mask\n"
4365 "Network mask\n"
4366 "Route-map to modify the attributes\n"
4367 "Name of the route map\n")
4368{
4369 int ret;
4370 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004371
paul718e3742002-12-13 20:15:29 +00004372 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4373 if (! ret)
4374 {
4375 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4376 return CMD_WARNING;
4377 }
4378
4379 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004380 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004381}
4382
4383DEFUN (bgp_network_mask_backdoor,
4384 bgp_network_mask_backdoor_cmd,
4385 "network A.B.C.D mask A.B.C.D backdoor",
4386 "Specify a network to announce via BGP\n"
4387 "Network number\n"
4388 "Network mask\n"
4389 "Network mask\n"
4390 "Specify a BGP backdoor route\n")
4391{
4392 int ret;
4393 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004394
paul718e3742002-12-13 20:15:29 +00004395 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4396 if (! ret)
4397 {
4398 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4399 return CMD_WARNING;
4400 }
4401
Paul Jakma41367172007-08-06 15:24:51 +00004402 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004403 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004404}
4405
4406DEFUN (bgp_network_mask_natural,
4407 bgp_network_mask_natural_cmd,
4408 "network A.B.C.D",
4409 "Specify a network to announce via BGP\n"
4410 "Network number\n")
4411{
4412 int ret;
4413 char prefix_str[BUFSIZ];
4414
4415 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4416 if (! ret)
4417 {
4418 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4419 return CMD_WARNING;
4420 }
4421
4422 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004423 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004424}
4425
4426DEFUN (bgp_network_mask_natural_route_map,
4427 bgp_network_mask_natural_route_map_cmd,
4428 "network A.B.C.D route-map WORD",
4429 "Specify a network to announce via BGP\n"
4430 "Network number\n"
4431 "Route-map to modify the attributes\n"
4432 "Name of the route map\n")
4433{
4434 int ret;
4435 char prefix_str[BUFSIZ];
4436
4437 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4438 if (! ret)
4439 {
4440 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4441 return CMD_WARNING;
4442 }
4443
4444 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004445 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004446}
4447
4448DEFUN (bgp_network_mask_natural_backdoor,
4449 bgp_network_mask_natural_backdoor_cmd,
4450 "network A.B.C.D backdoor",
4451 "Specify a network to announce via BGP\n"
4452 "Network number\n"
4453 "Specify a BGP backdoor route\n")
4454{
4455 int ret;
4456 char prefix_str[BUFSIZ];
4457
4458 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4459 if (! ret)
4460 {
4461 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4462 return CMD_WARNING;
4463 }
4464
Paul Jakma41367172007-08-06 15:24:51 +00004465 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004466 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004467}
4468
4469DEFUN (no_bgp_network,
4470 no_bgp_network_cmd,
4471 "no network A.B.C.D/M",
4472 NO_STR
4473 "Specify a network to announce via BGP\n"
4474 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4475{
4476 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4477 bgp_node_safi (vty));
4478}
4479
4480ALIAS (no_bgp_network,
4481 no_bgp_network_route_map_cmd,
4482 "no network A.B.C.D/M route-map WORD",
4483 NO_STR
4484 "Specify a network to announce via BGP\n"
4485 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4486 "Route-map to modify the attributes\n"
4487 "Name of the route map\n")
4488
4489ALIAS (no_bgp_network,
4490 no_bgp_network_backdoor_cmd,
4491 "no network A.B.C.D/M backdoor",
4492 NO_STR
4493 "Specify a network to announce via BGP\n"
4494 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4495 "Specify a BGP backdoor route\n")
4496
4497DEFUN (no_bgp_network_mask,
4498 no_bgp_network_mask_cmd,
4499 "no network A.B.C.D mask A.B.C.D",
4500 NO_STR
4501 "Specify a network to announce via BGP\n"
4502 "Network number\n"
4503 "Network mask\n"
4504 "Network mask\n")
4505{
4506 int ret;
4507 char prefix_str[BUFSIZ];
4508
4509 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4510 if (! ret)
4511 {
4512 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4513 return CMD_WARNING;
4514 }
4515
4516 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4517 bgp_node_safi (vty));
4518}
4519
4520ALIAS (no_bgp_network_mask,
4521 no_bgp_network_mask_route_map_cmd,
4522 "no network A.B.C.D mask A.B.C.D route-map WORD",
4523 NO_STR
4524 "Specify a network to announce via BGP\n"
4525 "Network number\n"
4526 "Network mask\n"
4527 "Network mask\n"
4528 "Route-map to modify the attributes\n"
4529 "Name of the route map\n")
4530
4531ALIAS (no_bgp_network_mask,
4532 no_bgp_network_mask_backdoor_cmd,
4533 "no network A.B.C.D mask A.B.C.D backdoor",
4534 NO_STR
4535 "Specify a network to announce via BGP\n"
4536 "Network number\n"
4537 "Network mask\n"
4538 "Network mask\n"
4539 "Specify a BGP backdoor route\n")
4540
4541DEFUN (no_bgp_network_mask_natural,
4542 no_bgp_network_mask_natural_cmd,
4543 "no network A.B.C.D",
4544 NO_STR
4545 "Specify a network to announce via BGP\n"
4546 "Network number\n")
4547{
4548 int ret;
4549 char prefix_str[BUFSIZ];
4550
4551 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4552 if (! ret)
4553 {
4554 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4555 return CMD_WARNING;
4556 }
4557
4558 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4559 bgp_node_safi (vty));
4560}
4561
4562ALIAS (no_bgp_network_mask_natural,
4563 no_bgp_network_mask_natural_route_map_cmd,
4564 "no network A.B.C.D route-map WORD",
4565 NO_STR
4566 "Specify a network to announce via BGP\n"
4567 "Network number\n"
4568 "Route-map to modify the attributes\n"
4569 "Name of the route map\n")
4570
4571ALIAS (no_bgp_network_mask_natural,
4572 no_bgp_network_mask_natural_backdoor_cmd,
4573 "no network A.B.C.D backdoor",
4574 NO_STR
4575 "Specify a network to announce via BGP\n"
4576 "Network number\n"
4577 "Specify a BGP backdoor route\n")
4578
4579#ifdef HAVE_IPV6
4580DEFUN (ipv6_bgp_network,
4581 ipv6_bgp_network_cmd,
4582 "network X:X::X:X/M",
4583 "Specify a network to announce via BGP\n"
4584 "IPv6 prefix <network>/<length>\n")
4585{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304586 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004587 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004588}
4589
4590DEFUN (ipv6_bgp_network_route_map,
4591 ipv6_bgp_network_route_map_cmd,
4592 "network X:X::X:X/M route-map WORD",
4593 "Specify a network to announce via BGP\n"
4594 "IPv6 prefix <network>/<length>\n"
4595 "Route-map to modify the attributes\n"
4596 "Name of the route map\n")
4597{
4598 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004599 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004600}
4601
4602DEFUN (no_ipv6_bgp_network,
4603 no_ipv6_bgp_network_cmd,
4604 "no network X:X::X:X/M",
4605 NO_STR
4606 "Specify a network to announce via BGP\n"
4607 "IPv6 prefix <network>/<length>\n")
4608{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304609 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004610}
4611
4612ALIAS (no_ipv6_bgp_network,
4613 no_ipv6_bgp_network_route_map_cmd,
4614 "no network X:X::X:X/M route-map WORD",
4615 NO_STR
4616 "Specify a network to announce via BGP\n"
4617 "IPv6 prefix <network>/<length>\n"
4618 "Route-map to modify the attributes\n"
4619 "Name of the route map\n")
4620
4621ALIAS (ipv6_bgp_network,
4622 old_ipv6_bgp_network_cmd,
4623 "ipv6 bgp network X:X::X:X/M",
4624 IPV6_STR
4625 BGP_STR
4626 "Specify a network to announce via BGP\n"
4627 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4628
4629ALIAS (no_ipv6_bgp_network,
4630 old_no_ipv6_bgp_network_cmd,
4631 "no ipv6 bgp network X:X::X:X/M",
4632 NO_STR
4633 IPV6_STR
4634 BGP_STR
4635 "Specify a network to announce via BGP\n"
4636 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4637#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004638
4639/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4640ALIAS_DEPRECATED (bgp_network,
4641 bgp_network_ttl_cmd,
4642 "network A.B.C.D/M pathlimit <0-255>",
4643 "Specify a network to announce via BGP\n"
4644 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4645 "AS-Path hopcount limit attribute\n"
4646 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4647ALIAS_DEPRECATED (bgp_network_backdoor,
4648 bgp_network_backdoor_ttl_cmd,
4649 "network A.B.C.D/M backdoor pathlimit <0-255>",
4650 "Specify a network to announce via BGP\n"
4651 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4652 "Specify a BGP backdoor route\n"
4653 "AS-Path hopcount limit attribute\n"
4654 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4655ALIAS_DEPRECATED (bgp_network_mask,
4656 bgp_network_mask_ttl_cmd,
4657 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4658 "Specify a network to announce via BGP\n"
4659 "Network number\n"
4660 "Network mask\n"
4661 "Network mask\n"
4662 "AS-Path hopcount limit attribute\n"
4663 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4664ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4665 bgp_network_mask_backdoor_ttl_cmd,
4666 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4667 "Specify a network to announce via BGP\n"
4668 "Network number\n"
4669 "Network mask\n"
4670 "Network mask\n"
4671 "Specify a BGP backdoor route\n"
4672 "AS-Path hopcount limit attribute\n"
4673 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4674ALIAS_DEPRECATED (bgp_network_mask_natural,
4675 bgp_network_mask_natural_ttl_cmd,
4676 "network A.B.C.D pathlimit <0-255>",
4677 "Specify a network to announce via BGP\n"
4678 "Network number\n"
4679 "AS-Path hopcount limit attribute\n"
4680 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4681ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4682 bgp_network_mask_natural_backdoor_ttl_cmd,
Christian Franke2b005152013-09-30 12:27:49 +00004683 "network A.B.C.D backdoor pathlimit <1-255>",
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004684 "Specify a network to announce via BGP\n"
4685 "Network number\n"
4686 "Specify a BGP backdoor route\n"
4687 "AS-Path hopcount limit attribute\n"
4688 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4689ALIAS_DEPRECATED (no_bgp_network,
4690 no_bgp_network_ttl_cmd,
4691 "no network A.B.C.D/M pathlimit <0-255>",
4692 NO_STR
4693 "Specify a network to announce via BGP\n"
4694 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4695 "AS-Path hopcount limit attribute\n"
4696 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4697ALIAS_DEPRECATED (no_bgp_network,
4698 no_bgp_network_backdoor_ttl_cmd,
4699 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4700 NO_STR
4701 "Specify a network to announce via BGP\n"
4702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4703 "Specify a BGP backdoor route\n"
4704 "AS-Path hopcount limit attribute\n"
4705 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4706ALIAS_DEPRECATED (no_bgp_network,
4707 no_bgp_network_mask_ttl_cmd,
4708 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4709 NO_STR
4710 "Specify a network to announce via BGP\n"
4711 "Network number\n"
4712 "Network mask\n"
4713 "Network mask\n"
4714 "AS-Path hopcount limit attribute\n"
4715 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4716ALIAS_DEPRECATED (no_bgp_network_mask,
4717 no_bgp_network_mask_backdoor_ttl_cmd,
4718 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4719 NO_STR
4720 "Specify a network to announce via BGP\n"
4721 "Network number\n"
4722 "Network mask\n"
4723 "Network mask\n"
4724 "Specify a BGP backdoor route\n"
4725 "AS-Path hopcount limit attribute\n"
4726 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4727ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4728 no_bgp_network_mask_natural_ttl_cmd,
4729 "no network A.B.C.D pathlimit <0-255>",
4730 NO_STR
4731 "Specify a network to announce via BGP\n"
4732 "Network number\n"
4733 "AS-Path hopcount limit attribute\n"
4734 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4735ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4736 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4737 "no network A.B.C.D backdoor pathlimit <0-255>",
4738 NO_STR
4739 "Specify a network to announce via BGP\n"
4740 "Network number\n"
4741 "Specify a BGP backdoor route\n"
4742 "AS-Path hopcount limit attribute\n"
4743 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004744#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004745ALIAS_DEPRECATED (ipv6_bgp_network,
4746 ipv6_bgp_network_ttl_cmd,
4747 "network X:X::X:X/M pathlimit <0-255>",
4748 "Specify a network to announce via BGP\n"
4749 "IPv6 prefix <network>/<length>\n"
4750 "AS-Path hopcount limit attribute\n"
4751 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4752ALIAS_DEPRECATED (no_ipv6_bgp_network,
4753 no_ipv6_bgp_network_ttl_cmd,
4754 "no network X:X::X:X/M pathlimit <0-255>",
4755 NO_STR
4756 "Specify a network to announce via BGP\n"
4757 "IPv6 prefix <network>/<length>\n"
4758 "AS-Path hopcount limit attribute\n"
4759 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004760#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02004761
paul718e3742002-12-13 20:15:29 +00004762/* Aggreagete address:
4763
4764 advertise-map Set condition to advertise attribute
4765 as-set Generate AS set path information
4766 attribute-map Set attributes of aggregate
4767 route-map Set parameters of aggregate
4768 summary-only Filter more specific routes from updates
4769 suppress-map Conditionally filter more specific routes from updates
4770 <cr>
4771 */
4772struct bgp_aggregate
4773{
4774 /* Summary-only flag. */
4775 u_char summary_only;
4776
4777 /* AS set generation. */
4778 u_char as_set;
4779
4780 /* Route-map for aggregated route. */
4781 struct route_map *map;
4782
4783 /* Suppress-count. */
4784 unsigned long count;
4785
4786 /* SAFI configuration. */
4787 safi_t safi;
4788};
4789
paul94f2b392005-06-28 12:44:16 +00004790static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004791bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004792{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004793 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004794}
4795
paul94f2b392005-06-28 12:44:16 +00004796static void
paul718e3742002-12-13 20:15:29 +00004797bgp_aggregate_free (struct bgp_aggregate *aggregate)
4798{
4799 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4800}
4801
paul94f2b392005-06-28 12:44:16 +00004802static void
paul718e3742002-12-13 20:15:29 +00004803bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4804 afi_t afi, safi_t safi, struct bgp_info *del,
4805 struct bgp_aggregate *aggregate)
4806{
4807 struct bgp_table *table;
4808 struct bgp_node *top;
4809 struct bgp_node *rn;
4810 u_char origin;
4811 struct aspath *aspath = NULL;
4812 struct aspath *asmerge = NULL;
4813 struct community *community = NULL;
4814 struct community *commerge = NULL;
paul718e3742002-12-13 20:15:29 +00004815 struct bgp_info *ri;
4816 struct bgp_info *new;
4817 int first = 1;
4818 unsigned long match = 0;
4819
paul718e3742002-12-13 20:15:29 +00004820 /* ORIGIN attribute: If at least one route among routes that are
4821 aggregated has ORIGIN with the value INCOMPLETE, then the
4822 aggregated route must have the ORIGIN attribute with the value
4823 INCOMPLETE. Otherwise, if at least one route among routes that
4824 are aggregated has ORIGIN with the value EGP, then the aggregated
4825 route must have the origin attribute with the value EGP. In all
4826 other case the value of the ORIGIN attribute of the aggregated
4827 route is INTERNAL. */
4828 origin = BGP_ORIGIN_IGP;
4829
4830 table = bgp->rib[afi][safi];
4831
4832 top = bgp_node_get (table, p);
4833 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4834 if (rn->p.prefixlen > p->prefixlen)
4835 {
4836 match = 0;
4837
4838 for (ri = rn->info; ri; ri = ri->next)
4839 {
4840 if (BGP_INFO_HOLDDOWN (ri))
4841 continue;
4842
4843 if (del && ri == del)
4844 continue;
4845
4846 if (! rinew && first)
Paul Jakma7aa9dce2014-09-19 14:42:23 +01004847 first = 0;
paul718e3742002-12-13 20:15:29 +00004848
4849#ifdef AGGREGATE_NEXTHOP_CHECK
4850 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4851 || ri->attr->med != med)
4852 {
4853 if (aspath)
4854 aspath_free (aspath);
4855 if (community)
4856 community_free (community);
4857 bgp_unlock_node (rn);
4858 bgp_unlock_node (top);
4859 return;
4860 }
4861#endif /* AGGREGATE_NEXTHOP_CHECK */
4862
4863 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4864 {
4865 if (aggregate->summary_only)
4866 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004867 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004868 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004869 match++;
4870 }
4871
4872 aggregate->count++;
4873
4874 if (aggregate->as_set)
4875 {
4876 if (origin < ri->attr->origin)
4877 origin = ri->attr->origin;
4878
4879 if (aspath)
4880 {
4881 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4882 aspath_free (aspath);
4883 aspath = asmerge;
4884 }
4885 else
4886 aspath = aspath_dup (ri->attr->aspath);
4887
4888 if (ri->attr->community)
4889 {
4890 if (community)
4891 {
4892 commerge = community_merge (community,
4893 ri->attr->community);
4894 community = community_uniq_sort (commerge);
4895 community_free (commerge);
4896 }
4897 else
4898 community = community_dup (ri->attr->community);
4899 }
4900 }
4901 }
4902 }
4903 if (match)
4904 bgp_process (bgp, rn, afi, safi);
4905 }
4906 bgp_unlock_node (top);
4907
4908 if (rinew)
4909 {
4910 aggregate->count++;
4911
4912 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004913 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004914
4915 if (aggregate->as_set)
4916 {
4917 if (origin < rinew->attr->origin)
4918 origin = rinew->attr->origin;
4919
4920 if (aspath)
4921 {
4922 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4923 aspath_free (aspath);
4924 aspath = asmerge;
4925 }
4926 else
4927 aspath = aspath_dup (rinew->attr->aspath);
4928
4929 if (rinew->attr->community)
4930 {
4931 if (community)
4932 {
4933 commerge = community_merge (community,
4934 rinew->attr->community);
4935 community = community_uniq_sort (commerge);
4936 community_free (commerge);
4937 }
4938 else
4939 community = community_dup (rinew->attr->community);
4940 }
4941 }
4942 }
4943
4944 if (aggregate->count > 0)
4945 {
4946 rn = bgp_node_get (table, p);
4947 new = bgp_info_new ();
4948 new->type = ZEBRA_ROUTE_BGP;
4949 new->sub_type = BGP_ROUTE_AGGREGATE;
4950 new->peer = bgp->peer_self;
4951 SET_FLAG (new->flags, BGP_INFO_VALID);
4952 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004953 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004954
4955 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004956 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004957 bgp_process (bgp, rn, afi, safi);
4958 }
4959 else
4960 {
4961 if (aspath)
4962 aspath_free (aspath);
4963 if (community)
4964 community_free (community);
4965 }
4966}
4967
4968void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4969 struct bgp_aggregate *);
4970
4971void
4972bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4973 struct bgp_info *ri, afi_t afi, safi_t safi)
4974{
4975 struct bgp_node *child;
4976 struct bgp_node *rn;
4977 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004978 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004979
4980 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05004981 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00004982 return;
4983
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004984 table = bgp->aggregate[afi][safi];
4985
4986 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004987 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004988 return;
4989
paul718e3742002-12-13 20:15:29 +00004990 if (p->prefixlen == 0)
4991 return;
4992
4993 if (BGP_INFO_HOLDDOWN (ri))
4994 return;
4995
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004996 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004997
4998 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07004999 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00005000 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5001 {
5002 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00005003 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00005004 }
5005 bgp_unlock_node (child);
5006}
5007
5008void
5009bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
5010 struct bgp_info *del, afi_t afi, safi_t safi)
5011{
5012 struct bgp_node *child;
5013 struct bgp_node *rn;
5014 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00005015 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00005016
5017 /* MPLS-VPN aggregation is not yet supported. */
Lou Berger298cc2f2016-01-12 13:42:02 -05005018 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00005019 return;
5020
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00005021 table = bgp->aggregate[afi][safi];
5022
5023 /* No aggregates configured. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07005024 if (bgp_table_top_nolock (table) == NULL)
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00005025 return;
5026
paul718e3742002-12-13 20:15:29 +00005027 if (p->prefixlen == 0)
5028 return;
5029
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02005030 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00005031
5032 /* Aggregate address configuration check. */
Avneesh Sachdev67174042012-08-17 08:19:49 -07005033 for (rn = child; rn; rn = bgp_node_parent_nolock (rn))
paul718e3742002-12-13 20:15:29 +00005034 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
5035 {
5036 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00005037 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00005038 }
5039 bgp_unlock_node (child);
5040}
5041
paul94f2b392005-06-28 12:44:16 +00005042static void
paul718e3742002-12-13 20:15:29 +00005043bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
5044 struct bgp_aggregate *aggregate)
5045{
5046 struct bgp_table *table;
5047 struct bgp_node *top;
5048 struct bgp_node *rn;
5049 struct bgp_info *new;
5050 struct bgp_info *ri;
5051 unsigned long match;
5052 u_char origin = BGP_ORIGIN_IGP;
5053 struct aspath *aspath = NULL;
5054 struct aspath *asmerge = NULL;
5055 struct community *community = NULL;
5056 struct community *commerge = NULL;
5057
5058 table = bgp->rib[afi][safi];
5059
5060 /* Sanity check. */
5061 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5062 return;
5063 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5064 return;
5065
5066 /* If routes exists below this node, generate aggregate routes. */
5067 top = bgp_node_get (table, p);
5068 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5069 if (rn->p.prefixlen > p->prefixlen)
5070 {
5071 match = 0;
5072
5073 for (ri = rn->info; ri; ri = ri->next)
5074 {
5075 if (BGP_INFO_HOLDDOWN (ri))
5076 continue;
5077
5078 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5079 {
5080 /* summary-only aggregate route suppress aggregated
5081 route announcement. */
5082 if (aggregate->summary_only)
5083 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005084 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00005085 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005086 match++;
5087 }
5088 /* as-set aggregate route generate origin, as path,
5089 community aggregation. */
5090 if (aggregate->as_set)
5091 {
5092 if (origin < ri->attr->origin)
5093 origin = ri->attr->origin;
5094
5095 if (aspath)
5096 {
5097 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
5098 aspath_free (aspath);
5099 aspath = asmerge;
5100 }
5101 else
5102 aspath = aspath_dup (ri->attr->aspath);
5103
5104 if (ri->attr->community)
5105 {
5106 if (community)
5107 {
5108 commerge = community_merge (community,
5109 ri->attr->community);
5110 community = community_uniq_sort (commerge);
5111 community_free (commerge);
5112 }
5113 else
5114 community = community_dup (ri->attr->community);
5115 }
5116 }
5117 aggregate->count++;
5118 }
5119 }
5120
5121 /* If this node is suppressed, process the change. */
5122 if (match)
5123 bgp_process (bgp, rn, afi, safi);
5124 }
5125 bgp_unlock_node (top);
5126
5127 /* Add aggregate route to BGP table. */
5128 if (aggregate->count)
5129 {
5130 rn = bgp_node_get (table, p);
5131
5132 new = bgp_info_new ();
5133 new->type = ZEBRA_ROUTE_BGP;
5134 new->sub_type = BGP_ROUTE_AGGREGATE;
5135 new->peer = bgp->peer_self;
5136 SET_FLAG (new->flags, BGP_INFO_VALID);
5137 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03005138 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005139
5140 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00005141 bgp_unlock_node (rn);
5142
paul718e3742002-12-13 20:15:29 +00005143 /* Process change. */
5144 bgp_process (bgp, rn, afi, safi);
5145 }
Denil Virae2a92582015-08-11 13:34:59 -07005146 else
5147 {
5148 if (aspath)
5149 aspath_free (aspath);
5150 if (community)
5151 community_free (community);
5152 }
paul718e3742002-12-13 20:15:29 +00005153}
5154
5155void
5156bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
5157 safi_t safi, struct bgp_aggregate *aggregate)
5158{
5159 struct bgp_table *table;
5160 struct bgp_node *top;
5161 struct bgp_node *rn;
5162 struct bgp_info *ri;
5163 unsigned long match;
5164
5165 table = bgp->rib[afi][safi];
5166
5167 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
5168 return;
5169 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
5170 return;
5171
5172 /* If routes exists below this node, generate aggregate routes. */
5173 top = bgp_node_get (table, p);
5174 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
5175 if (rn->p.prefixlen > p->prefixlen)
5176 {
5177 match = 0;
5178
5179 for (ri = rn->info; ri; ri = ri->next)
5180 {
5181 if (BGP_INFO_HOLDDOWN (ri))
5182 continue;
5183
5184 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
5185 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005186 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00005187 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005188 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00005189
Paul Jakmafb982c22007-05-04 20:15:47 +00005190 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00005191 {
Paul Jakma1a392d42006-09-07 00:24:49 +00005192 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005193 match++;
5194 }
5195 }
5196 aggregate->count--;
5197 }
5198 }
5199
Paul Jakmafb982c22007-05-04 20:15:47 +00005200 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00005201 if (match)
5202 bgp_process (bgp, rn, afi, safi);
5203 }
5204 bgp_unlock_node (top);
5205
5206 /* Delete aggregate route from BGP table. */
5207 rn = bgp_node_get (table, p);
5208
5209 for (ri = rn->info; ri; ri = ri->next)
5210 if (ri->peer == bgp->peer_self
5211 && ri->type == ZEBRA_ROUTE_BGP
5212 && ri->sub_type == BGP_ROUTE_AGGREGATE)
5213 break;
5214
5215 /* Withdraw static BGP route from routing table. */
5216 if (ri)
5217 {
paul718e3742002-12-13 20:15:29 +00005218 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005219 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00005220 }
5221
5222 /* Unlock bgp_node_lookup. */
5223 bgp_unlock_node (rn);
5224}
5225
5226/* Aggregate route attribute. */
5227#define AGGREGATE_SUMMARY_ONLY 1
5228#define AGGREGATE_AS_SET 1
5229
paul94f2b392005-06-28 12:44:16 +00005230static int
Robert Baysf6269b42010-08-05 10:26:28 -07005231bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5232 afi_t afi, safi_t safi)
5233{
5234 int ret;
5235 struct prefix p;
5236 struct bgp_node *rn;
5237 struct bgp *bgp;
5238 struct bgp_aggregate *aggregate;
5239
5240 /* Convert string to prefix structure. */
5241 ret = str2prefix (prefix_str, &p);
5242 if (!ret)
5243 {
5244 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5245 return CMD_WARNING;
5246 }
5247 apply_mask (&p);
5248
5249 /* Get BGP structure. */
5250 bgp = vty->index;
5251
5252 /* Old configuration check. */
5253 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5254 if (! rn)
5255 {
5256 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5257 VTY_NEWLINE);
5258 return CMD_WARNING;
5259 }
5260
5261 aggregate = rn->info;
5262 if (aggregate->safi & SAFI_UNICAST)
5263 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5264 if (aggregate->safi & SAFI_MULTICAST)
5265 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5266
5267 /* Unlock aggregate address configuration. */
5268 rn->info = NULL;
5269 bgp_aggregate_free (aggregate);
5270 bgp_unlock_node (rn);
5271 bgp_unlock_node (rn);
5272
5273 return CMD_SUCCESS;
5274}
5275
5276static int
5277bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00005278 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00005279 u_char summary_only, u_char as_set)
5280{
5281 int ret;
5282 struct prefix p;
5283 struct bgp_node *rn;
5284 struct bgp *bgp;
5285 struct bgp_aggregate *aggregate;
5286
5287 /* Convert string to prefix structure. */
5288 ret = str2prefix (prefix_str, &p);
5289 if (!ret)
5290 {
5291 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5292 return CMD_WARNING;
5293 }
5294 apply_mask (&p);
5295
5296 /* Get BGP structure. */
5297 bgp = vty->index;
5298
5299 /* Old configuration check. */
5300 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
5301
5302 if (rn->info)
5303 {
5304 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07005305 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07005306 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
5307 if (ret)
5308 {
Robert Bays368473f2010-08-05 10:26:29 -07005309 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
5310 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07005311 return CMD_WARNING;
5312 }
paul718e3742002-12-13 20:15:29 +00005313 }
5314
5315 /* Make aggregate address structure. */
5316 aggregate = bgp_aggregate_new ();
5317 aggregate->summary_only = summary_only;
5318 aggregate->as_set = as_set;
5319 aggregate->safi = safi;
5320 rn->info = aggregate;
5321
5322 /* Aggregate address insert into BGP routing table. */
5323 if (safi & SAFI_UNICAST)
5324 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5325 if (safi & SAFI_MULTICAST)
5326 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5327
5328 return CMD_SUCCESS;
5329}
5330
paul718e3742002-12-13 20:15:29 +00005331DEFUN (aggregate_address,
5332 aggregate_address_cmd,
5333 "aggregate-address A.B.C.D/M",
5334 "Configure BGP aggregate entries\n"
5335 "Aggregate prefix\n")
5336{
5337 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5338}
5339
5340DEFUN (aggregate_address_mask,
5341 aggregate_address_mask_cmd,
5342 "aggregate-address A.B.C.D A.B.C.D",
5343 "Configure BGP aggregate entries\n"
5344 "Aggregate address\n"
5345 "Aggregate mask\n")
5346{
5347 int ret;
5348 char prefix_str[BUFSIZ];
5349
5350 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5351
5352 if (! ret)
5353 {
5354 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5355 return CMD_WARNING;
5356 }
5357
5358 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5359 0, 0);
5360}
5361
5362DEFUN (aggregate_address_summary_only,
5363 aggregate_address_summary_only_cmd,
5364 "aggregate-address A.B.C.D/M summary-only",
5365 "Configure BGP aggregate entries\n"
5366 "Aggregate prefix\n"
5367 "Filter more specific routes from updates\n")
5368{
5369 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5370 AGGREGATE_SUMMARY_ONLY, 0);
5371}
5372
5373DEFUN (aggregate_address_mask_summary_only,
5374 aggregate_address_mask_summary_only_cmd,
5375 "aggregate-address A.B.C.D A.B.C.D summary-only",
5376 "Configure BGP aggregate entries\n"
5377 "Aggregate address\n"
5378 "Aggregate mask\n"
5379 "Filter more specific routes from updates\n")
5380{
5381 int ret;
5382 char prefix_str[BUFSIZ];
5383
5384 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5385
5386 if (! ret)
5387 {
5388 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5389 return CMD_WARNING;
5390 }
5391
5392 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5393 AGGREGATE_SUMMARY_ONLY, 0);
5394}
5395
5396DEFUN (aggregate_address_as_set,
5397 aggregate_address_as_set_cmd,
5398 "aggregate-address A.B.C.D/M as-set",
5399 "Configure BGP aggregate entries\n"
5400 "Aggregate prefix\n"
5401 "Generate AS set path information\n")
5402{
5403 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5404 0, AGGREGATE_AS_SET);
5405}
5406
5407DEFUN (aggregate_address_mask_as_set,
5408 aggregate_address_mask_as_set_cmd,
5409 "aggregate-address A.B.C.D A.B.C.D as-set",
5410 "Configure BGP aggregate entries\n"
5411 "Aggregate address\n"
5412 "Aggregate mask\n"
5413 "Generate AS set path information\n")
5414{
5415 int ret;
5416 char prefix_str[BUFSIZ];
5417
5418 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5419
5420 if (! ret)
5421 {
5422 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5423 return CMD_WARNING;
5424 }
5425
5426 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5427 0, AGGREGATE_AS_SET);
5428}
5429
5430
5431DEFUN (aggregate_address_as_set_summary,
5432 aggregate_address_as_set_summary_cmd,
5433 "aggregate-address A.B.C.D/M as-set summary-only",
5434 "Configure BGP aggregate entries\n"
5435 "Aggregate prefix\n"
5436 "Generate AS set path information\n"
5437 "Filter more specific routes from updates\n")
5438{
5439 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5440 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5441}
5442
5443ALIAS (aggregate_address_as_set_summary,
5444 aggregate_address_summary_as_set_cmd,
5445 "aggregate-address A.B.C.D/M summary-only as-set",
5446 "Configure BGP aggregate entries\n"
5447 "Aggregate prefix\n"
5448 "Filter more specific routes from updates\n"
5449 "Generate AS set path information\n")
5450
5451DEFUN (aggregate_address_mask_as_set_summary,
5452 aggregate_address_mask_as_set_summary_cmd,
5453 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5454 "Configure BGP aggregate entries\n"
5455 "Aggregate address\n"
5456 "Aggregate mask\n"
5457 "Generate AS set path information\n"
5458 "Filter more specific routes from updates\n")
5459{
5460 int ret;
5461 char prefix_str[BUFSIZ];
5462
5463 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5464
5465 if (! ret)
5466 {
5467 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5468 return CMD_WARNING;
5469 }
5470
5471 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5472 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5473}
5474
5475ALIAS (aggregate_address_mask_as_set_summary,
5476 aggregate_address_mask_summary_as_set_cmd,
5477 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5478 "Configure BGP aggregate entries\n"
5479 "Aggregate address\n"
5480 "Aggregate mask\n"
5481 "Filter more specific routes from updates\n"
5482 "Generate AS set path information\n")
5483
5484DEFUN (no_aggregate_address,
5485 no_aggregate_address_cmd,
5486 "no aggregate-address A.B.C.D/M",
5487 NO_STR
5488 "Configure BGP aggregate entries\n"
5489 "Aggregate prefix\n")
5490{
5491 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5492}
5493
5494ALIAS (no_aggregate_address,
5495 no_aggregate_address_summary_only_cmd,
5496 "no aggregate-address A.B.C.D/M summary-only",
5497 NO_STR
5498 "Configure BGP aggregate entries\n"
5499 "Aggregate prefix\n"
5500 "Filter more specific routes from updates\n")
5501
5502ALIAS (no_aggregate_address,
5503 no_aggregate_address_as_set_cmd,
5504 "no aggregate-address A.B.C.D/M as-set",
5505 NO_STR
5506 "Configure BGP aggregate entries\n"
5507 "Aggregate prefix\n"
5508 "Generate AS set path information\n")
5509
5510ALIAS (no_aggregate_address,
5511 no_aggregate_address_as_set_summary_cmd,
5512 "no aggregate-address A.B.C.D/M as-set summary-only",
5513 NO_STR
5514 "Configure BGP aggregate entries\n"
5515 "Aggregate prefix\n"
5516 "Generate AS set path information\n"
5517 "Filter more specific routes from updates\n")
5518
5519ALIAS (no_aggregate_address,
5520 no_aggregate_address_summary_as_set_cmd,
5521 "no aggregate-address A.B.C.D/M summary-only as-set",
5522 NO_STR
5523 "Configure BGP aggregate entries\n"
5524 "Aggregate prefix\n"
5525 "Filter more specific routes from updates\n"
5526 "Generate AS set path information\n")
5527
5528DEFUN (no_aggregate_address_mask,
5529 no_aggregate_address_mask_cmd,
5530 "no aggregate-address A.B.C.D A.B.C.D",
5531 NO_STR
5532 "Configure BGP aggregate entries\n"
5533 "Aggregate address\n"
5534 "Aggregate mask\n")
5535{
5536 int ret;
5537 char prefix_str[BUFSIZ];
5538
5539 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5540
5541 if (! ret)
5542 {
5543 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5544 return CMD_WARNING;
5545 }
5546
5547 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5548}
5549
5550ALIAS (no_aggregate_address_mask,
5551 no_aggregate_address_mask_summary_only_cmd,
5552 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5553 NO_STR
5554 "Configure BGP aggregate entries\n"
5555 "Aggregate address\n"
5556 "Aggregate mask\n"
5557 "Filter more specific routes from updates\n")
5558
5559ALIAS (no_aggregate_address_mask,
5560 no_aggregate_address_mask_as_set_cmd,
5561 "no aggregate-address A.B.C.D A.B.C.D as-set",
5562 NO_STR
5563 "Configure BGP aggregate entries\n"
5564 "Aggregate address\n"
5565 "Aggregate mask\n"
5566 "Generate AS set path information\n")
5567
5568ALIAS (no_aggregate_address_mask,
5569 no_aggregate_address_mask_as_set_summary_cmd,
5570 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5571 NO_STR
5572 "Configure BGP aggregate entries\n"
5573 "Aggregate address\n"
5574 "Aggregate mask\n"
5575 "Generate AS set path information\n"
5576 "Filter more specific routes from updates\n")
5577
5578ALIAS (no_aggregate_address_mask,
5579 no_aggregate_address_mask_summary_as_set_cmd,
5580 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5581 NO_STR
5582 "Configure BGP aggregate entries\n"
5583 "Aggregate address\n"
5584 "Aggregate mask\n"
5585 "Filter more specific routes from updates\n"
5586 "Generate AS set path information\n")
5587
5588#ifdef HAVE_IPV6
5589DEFUN (ipv6_aggregate_address,
5590 ipv6_aggregate_address_cmd,
5591 "aggregate-address X:X::X:X/M",
5592 "Configure BGP aggregate entries\n"
5593 "Aggregate prefix\n")
5594{
5595 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5596}
5597
5598DEFUN (ipv6_aggregate_address_summary_only,
5599 ipv6_aggregate_address_summary_only_cmd,
5600 "aggregate-address X:X::X:X/M summary-only",
5601 "Configure BGP aggregate entries\n"
5602 "Aggregate prefix\n"
5603 "Filter more specific routes from updates\n")
5604{
5605 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5606 AGGREGATE_SUMMARY_ONLY, 0);
5607}
5608
5609DEFUN (no_ipv6_aggregate_address,
5610 no_ipv6_aggregate_address_cmd,
5611 "no aggregate-address X:X::X:X/M",
5612 NO_STR
5613 "Configure BGP aggregate entries\n"
5614 "Aggregate prefix\n")
5615{
5616 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5617}
5618
5619DEFUN (no_ipv6_aggregate_address_summary_only,
5620 no_ipv6_aggregate_address_summary_only_cmd,
5621 "no aggregate-address X:X::X:X/M summary-only",
5622 NO_STR
5623 "Configure BGP aggregate entries\n"
5624 "Aggregate prefix\n"
5625 "Filter more specific routes from updates\n")
5626{
5627 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5628}
5629
5630ALIAS (ipv6_aggregate_address,
5631 old_ipv6_aggregate_address_cmd,
5632 "ipv6 bgp aggregate-address X:X::X:X/M",
5633 IPV6_STR
5634 BGP_STR
5635 "Configure BGP aggregate entries\n"
5636 "Aggregate prefix\n")
5637
5638ALIAS (ipv6_aggregate_address_summary_only,
5639 old_ipv6_aggregate_address_summary_only_cmd,
5640 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5641 IPV6_STR
5642 BGP_STR
5643 "Configure BGP aggregate entries\n"
5644 "Aggregate prefix\n"
5645 "Filter more specific routes from updates\n")
5646
5647ALIAS (no_ipv6_aggregate_address,
5648 old_no_ipv6_aggregate_address_cmd,
5649 "no ipv6 bgp aggregate-address X:X::X:X/M",
5650 NO_STR
5651 IPV6_STR
5652 BGP_STR
5653 "Configure BGP aggregate entries\n"
5654 "Aggregate prefix\n")
5655
5656ALIAS (no_ipv6_aggregate_address_summary_only,
5657 old_no_ipv6_aggregate_address_summary_only_cmd,
5658 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5659 NO_STR
5660 IPV6_STR
5661 BGP_STR
5662 "Configure BGP aggregate entries\n"
5663 "Aggregate prefix\n"
5664 "Filter more specific routes from updates\n")
5665#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02005666
paul718e3742002-12-13 20:15:29 +00005667/* Redistribute route treatment. */
5668void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005669bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5670 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005671 u_int32_t metric, u_char type)
5672{
5673 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005674 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005675 struct bgp_info *new;
5676 struct bgp_info *bi;
5677 struct bgp_info info;
5678 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005679 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005680 struct attr *new_attr;
5681 afi_t afi;
5682 int ret;
5683
5684 /* Make default attribute. */
5685 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5686 if (nexthop)
5687 attr.nexthop = *nexthop;
5688
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005689#ifdef HAVE_IPV6
5690 if (nexthop6)
5691 {
5692 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5693 extra->mp_nexthop_global = *nexthop6;
5694 extra->mp_nexthop_len = 16;
5695 }
5696#endif
5697
paul718e3742002-12-13 20:15:29 +00005698 attr.med = metric;
5699 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5700
paul1eb8ef22005-04-07 07:30:20 +00005701 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005702 {
5703 afi = family2afi (p->family);
5704
5705 if (bgp->redist[afi][type])
5706 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005707 struct attr attr_new;
5708 struct attr_extra extra_new;
5709
paul718e3742002-12-13 20:15:29 +00005710 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005711 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005712 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005713
5714 if (bgp->redist_metric_flag[afi][type])
5715 attr_new.med = bgp->redist_metric[afi][type];
5716
5717 /* Apply route-map. */
Daniel Walton1994dc82015-09-17 10:15:59 -04005718 if (bgp->rmap[afi][type].name)
paul718e3742002-12-13 20:15:29 +00005719 {
5720 info.peer = bgp->peer_self;
5721 info.attr = &attr_new;
5722
paulfee0f4c2004-09-13 05:12:46 +00005723 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5724
paul718e3742002-12-13 20:15:29 +00005725 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5726 &info);
paulfee0f4c2004-09-13 05:12:46 +00005727
5728 bgp->peer_self->rmap_type = 0;
5729
paul718e3742002-12-13 20:15:29 +00005730 if (ret == RMAP_DENYMATCH)
5731 {
5732 /* Free uninterned attribute. */
5733 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005734
paul718e3742002-12-13 20:15:29 +00005735 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005736 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005737 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005738 bgp_redistribute_delete (p, type);
5739 return;
5740 }
5741 }
5742
Paul Jakmafb982c22007-05-04 20:15:47 +00005743 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5744 afi, SAFI_UNICAST, p, NULL);
5745
paul718e3742002-12-13 20:15:29 +00005746 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005747
paul718e3742002-12-13 20:15:29 +00005748 for (bi = bn->info; bi; bi = bi->next)
5749 if (bi->peer == bgp->peer_self
5750 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5751 break;
5752
5753 if (bi)
5754 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005755 if (attrhash_cmp (bi->attr, new_attr) &&
5756 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005757 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005758 bgp_attr_unintern (&new_attr);
5759 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005760 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005761 bgp_unlock_node (bn);
5762 return;
5763 }
5764 else
5765 {
5766 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005767 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005768
5769 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005770 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5771 bgp_info_restore(bn, bi);
5772 else
5773 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005774 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005775 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005776 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005777
5778 /* Process change. */
5779 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5780 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5781 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005782 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005783 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005784 return;
5785 }
5786 }
5787
5788 new = bgp_info_new ();
5789 new->type = type;
5790 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5791 new->peer = bgp->peer_self;
5792 SET_FLAG (new->flags, BGP_INFO_VALID);
5793 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005794 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005795
5796 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5797 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005798 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005799 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5800 }
5801 }
5802
5803 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005804 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005805 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005806}
5807
5808void
5809bgp_redistribute_delete (struct prefix *p, u_char type)
5810{
5811 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005812 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005813 afi_t afi;
5814 struct bgp_node *rn;
5815 struct bgp_info *ri;
5816
paul1eb8ef22005-04-07 07:30:20 +00005817 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005818 {
5819 afi = family2afi (p->family);
5820
5821 if (bgp->redist[afi][type])
5822 {
paulfee0f4c2004-09-13 05:12:46 +00005823 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005824
5825 for (ri = rn->info; ri; ri = ri->next)
5826 if (ri->peer == bgp->peer_self
5827 && ri->type == type)
5828 break;
5829
5830 if (ri)
5831 {
5832 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005833 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005834 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005835 }
5836 bgp_unlock_node (rn);
5837 }
5838 }
5839}
5840
5841/* Withdraw specified route type's route. */
5842void
5843bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5844{
5845 struct bgp_node *rn;
5846 struct bgp_info *ri;
5847 struct bgp_table *table;
5848
5849 table = bgp->rib[afi][SAFI_UNICAST];
5850
5851 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5852 {
5853 for (ri = rn->info; ri; ri = ri->next)
5854 if (ri->peer == bgp->peer_self
5855 && ri->type == type)
5856 break;
5857
5858 if (ri)
5859 {
5860 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005861 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005862 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005863 }
5864 }
5865}
David Lamparter6b0655a2014-06-04 06:53:35 +02005866
paul718e3742002-12-13 20:15:29 +00005867/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005868static void
paul718e3742002-12-13 20:15:29 +00005869route_vty_out_route (struct prefix *p, struct vty *vty)
5870{
5871 int len;
5872 u_int32_t destination;
5873 char buf[BUFSIZ];
5874
5875 if (p->family == AF_INET)
5876 {
5877 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5878 destination = ntohl (p->u.prefix4.s_addr);
5879
5880 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5881 || (IN_CLASSB (destination) && p->prefixlen == 16)
5882 || (IN_CLASSA (destination) && p->prefixlen == 8)
5883 || p->u.prefix4.s_addr == 0)
5884 {
5885 /* When mask is natural, mask is not displayed. */
5886 }
5887 else
5888 len += vty_out (vty, "/%d", p->prefixlen);
5889 }
5890 else
5891 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5892 p->prefixlen);
5893
5894 len = 17 - len;
5895 if (len < 1)
5896 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5897 else
5898 vty_out (vty, "%*s", len, " ");
5899}
5900
paul718e3742002-12-13 20:15:29 +00005901enum bgp_display_type
5902{
5903 normal_list,
5904};
5905
paulb40d9392005-08-22 22:34:41 +00005906/* Print the short form route status for a bgp_info */
5907static void
5908route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005909{
paulb40d9392005-08-22 22:34:41 +00005910 /* Route status display. */
5911 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5912 vty_out (vty, "R");
5913 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005914 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005915 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005916 vty_out (vty, "s");
5917 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5918 vty_out (vty, "*");
5919 else
5920 vty_out (vty, " ");
5921
5922 /* Selected */
5923 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5924 vty_out (vty, "h");
5925 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5926 vty_out (vty, "d");
5927 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5928 vty_out (vty, ">");
Boian Bonevb366b512013-09-09 16:41:35 +00005929 else if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH))
5930 vty_out (vty, "=");
paul718e3742002-12-13 20:15:29 +00005931 else
5932 vty_out (vty, " ");
5933
5934 /* Internal route. */
5935 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5936 vty_out (vty, "i");
5937 else
paulb40d9392005-08-22 22:34:41 +00005938 vty_out (vty, " ");
5939}
5940
5941/* called from terminal list command */
5942void
5943route_vty_out (struct vty *vty, struct prefix *p,
5944 struct bgp_info *binfo, int display, safi_t safi)
5945{
5946 struct attr *attr;
5947
5948 /* short status lead text */
5949 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005950
5951 /* print prefix and mask */
5952 if (! display)
5953 route_vty_out_route (p, vty);
5954 else
5955 vty_out (vty, "%*s", 17, " ");
5956
5957 /* Print attribute */
5958 attr = binfo->attr;
5959 if (attr)
5960 {
paul718e3742002-12-13 20:15:29 +00005961
Lou Berger298cc2f2016-01-12 13:42:02 -05005962 /*
5963 * NEXTHOP start
5964 */
5965
5966 /*
5967 * For ENCAP routes, nexthop address family is not
5968 * neccessarily the same as the prefix address family.
5969 * Both SAFI_MPLS_VPN and SAFI_ENCAP use the MP nexthop field
5970 */
5971 if ((safi == SAFI_ENCAP) || (safi == SAFI_MPLS_VPN)) {
5972 if (attr->extra) {
5973 char buf[BUFSIZ];
5974 int af = NEXTHOP_FAMILY(attr->extra->mp_nexthop_len);
5975
5976 switch (af) {
5977 case AF_INET:
5978 vty_out (vty, "%s", inet_ntop(af,
5979 &attr->extra->mp_nexthop_global_in, buf, BUFSIZ));
5980 break;
5981#if HAVE_IPV6
5982 case AF_INET6:
5983 vty_out (vty, "%s", inet_ntop(af,
5984 &attr->extra->mp_nexthop_global, buf, BUFSIZ));
5985 break;
5986#endif
5987
5988 default:
5989 vty_out(vty, "?");
5990 }
5991 } else {
5992 vty_out(vty, "?");
paul718e3742002-12-13 20:15:29 +00005993 }
Lou Berger298cc2f2016-01-12 13:42:02 -05005994 } else {
5995
5996 if (p->family == AF_INET)
5997 {
5998 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5999 }
6000#ifdef HAVE_IPV6
6001 else if (p->family == AF_INET6)
6002 {
6003 int len;
6004 char buf[BUFSIZ];
6005
6006 len = vty_out (vty, "%s",
6007 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6008 buf, BUFSIZ));
6009 len = 16 - len;
6010 if (len < 1)
6011 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6012 else
6013 vty_out (vty, "%*s", len, " ");
6014 }
paul718e3742002-12-13 20:15:29 +00006015#endif /* HAVE_IPV6 */
Lou Berger298cc2f2016-01-12 13:42:02 -05006016 else
6017 {
6018 vty_out(vty, "?");
6019 }
6020 }
6021
6022 /*
6023 * NEXTHOP end
6024 */
6025
paul718e3742002-12-13 20:15:29 +00006026
6027 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006028 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00006029 else
6030 vty_out (vty, " ");
6031
6032 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006033 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006034 else
6035 vty_out (vty, " ");
6036
Paul Jakmafb982c22007-05-04 20:15:47 +00006037 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00006038
Paul Jakmab2518c12006-05-12 23:48:40 +00006039 /* Print aspath */
6040 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006041 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006042
Paul Jakmab2518c12006-05-12 23:48:40 +00006043 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006044 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006045 }
paul718e3742002-12-13 20:15:29 +00006046 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006047}
6048
6049/* called from terminal list command */
6050void
6051route_vty_out_tmp (struct vty *vty, struct prefix *p,
6052 struct attr *attr, safi_t safi)
6053{
6054 /* Route status display. */
6055 vty_out (vty, "*");
6056 vty_out (vty, ">");
6057 vty_out (vty, " ");
6058
6059 /* print prefix and mask */
6060 route_vty_out_route (p, vty);
6061
6062 /* Print attribute */
6063 if (attr)
6064 {
6065 if (p->family == AF_INET)
6066 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006067 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006068 vty_out (vty, "%-16s",
6069 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006070 else
6071 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6072 }
6073#ifdef HAVE_IPV6
6074 else if (p->family == AF_INET6)
6075 {
6076 int len;
6077 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006078
6079 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006080
6081 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006082 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6083 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006084 len = 16 - len;
6085 if (len < 1)
6086 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
6087 else
6088 vty_out (vty, "%*s", len, " ");
6089 }
6090#endif /* HAVE_IPV6 */
6091
6092 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006093 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00006094 else
6095 vty_out (vty, " ");
6096
6097 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006098 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006099 else
6100 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006101
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006102 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00006103
Paul Jakmab2518c12006-05-12 23:48:40 +00006104 /* Print aspath */
6105 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006106 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006107
Paul Jakmab2518c12006-05-12 23:48:40 +00006108 /* Print origin */
paul718e3742002-12-13 20:15:29 +00006109 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00006110 }
paul718e3742002-12-13 20:15:29 +00006111
6112 vty_out (vty, "%s", VTY_NEWLINE);
6113}
6114
ajs5a646652004-11-05 01:25:55 +00006115void
paul718e3742002-12-13 20:15:29 +00006116route_vty_out_tag (struct vty *vty, struct prefix *p,
6117 struct bgp_info *binfo, int display, safi_t safi)
6118{
6119 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006120 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00006121
6122 if (!binfo->extra)
6123 return;
6124
paulb40d9392005-08-22 22:34:41 +00006125 /* short status lead text */
6126 route_vty_short_status_out (vty, binfo);
6127
paul718e3742002-12-13 20:15:29 +00006128 /* print prefix and mask */
6129 if (! display)
6130 route_vty_out_route (p, vty);
6131 else
6132 vty_out (vty, "%*s", 17, " ");
6133
6134 /* Print attribute */
6135 attr = binfo->attr;
6136 if (attr)
6137 {
6138 if (p->family == AF_INET)
6139 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006140 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
Paul Jakmafb982c22007-05-04 20:15:47 +00006141 vty_out (vty, "%-16s",
6142 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00006143 else
6144 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
6145 }
6146#ifdef HAVE_IPV6
6147 else if (p->family == AF_INET6)
6148 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006149 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006150 char buf[BUFSIZ];
6151 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00006152 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00006153 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006154 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6155 buf, BUFSIZ));
6156 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006157 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006158 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
6159 buf, BUFSIZ),
6160 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
6161 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00006162
6163 }
6164#endif /* HAVE_IPV6 */
6165 }
6166
Paul Jakmafb982c22007-05-04 20:15:47 +00006167 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00006168
6169 vty_out (vty, "notag/%d", label);
6170
6171 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006172}
6173
6174/* dampening route */
ajs5a646652004-11-05 01:25:55 +00006175static void
paul718e3742002-12-13 20:15:29 +00006176damp_route_vty_out (struct vty *vty, struct prefix *p,
6177 struct bgp_info *binfo, int display, safi_t safi)
6178{
6179 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00006180 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00006181 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00006182
paulb40d9392005-08-22 22:34:41 +00006183 /* short status lead text */
6184 route_vty_short_status_out (vty, binfo);
6185
paul718e3742002-12-13 20:15:29 +00006186 /* print prefix and mask */
6187 if (! display)
6188 route_vty_out_route (p, vty);
6189 else
6190 vty_out (vty, "%*s", 17, " ");
6191
6192 len = vty_out (vty, "%s", binfo->peer->host);
6193 len = 17 - len;
6194 if (len < 1)
6195 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
6196 else
6197 vty_out (vty, "%*s", len, " ");
6198
Chris Caputo50aef6f2009-06-23 06:06:49 +00006199 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006200
6201 /* Print attribute */
6202 attr = binfo->attr;
6203 if (attr)
6204 {
6205 /* Print aspath */
6206 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006207 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006208
6209 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006210 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006211 }
6212 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006213}
6214
paul718e3742002-12-13 20:15:29 +00006215/* flap route */
ajs5a646652004-11-05 01:25:55 +00006216static void
paul718e3742002-12-13 20:15:29 +00006217flap_route_vty_out (struct vty *vty, struct prefix *p,
6218 struct bgp_info *binfo, int display, safi_t safi)
6219{
6220 struct attr *attr;
6221 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00006222 char timebuf[BGP_UPTIME_LEN];
6223 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00006224
6225 if (!binfo->extra)
6226 return;
6227
6228 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00006229
paulb40d9392005-08-22 22:34:41 +00006230 /* short status lead text */
6231 route_vty_short_status_out (vty, binfo);
6232
paul718e3742002-12-13 20:15:29 +00006233 /* print prefix and mask */
6234 if (! display)
6235 route_vty_out_route (p, vty);
6236 else
6237 vty_out (vty, "%*s", 17, " ");
6238
6239 len = vty_out (vty, "%s", binfo->peer->host);
6240 len = 16 - len;
6241 if (len < 1)
6242 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
6243 else
6244 vty_out (vty, "%*s", len, " ");
6245
6246 len = vty_out (vty, "%d", bdi->flap);
6247 len = 5 - len;
6248 if (len < 1)
6249 vty_out (vty, " ");
6250 else
6251 vty_out (vty, "%*s ", len, " ");
6252
6253 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
6254 timebuf, BGP_UPTIME_LEN));
6255
6256 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
6257 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00006258 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00006259 else
6260 vty_out (vty, "%*s ", 8, " ");
6261
6262 /* Print attribute */
6263 attr = binfo->attr;
6264 if (attr)
6265 {
6266 /* Print aspath */
6267 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006268 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00006269
6270 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00006271 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00006272 }
6273 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006274}
6275
paul94f2b392005-06-28 12:44:16 +00006276static void
paul718e3742002-12-13 20:15:29 +00006277route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
6278 struct bgp_info *binfo, afi_t afi, safi_t safi)
6279{
6280 char buf[INET6_ADDRSTRLEN];
6281 char buf1[BUFSIZ];
6282 struct attr *attr;
6283 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03006284#ifdef HAVE_CLOCK_MONOTONIC
6285 time_t tbuf;
6286#endif
paul718e3742002-12-13 20:15:29 +00006287
6288 attr = binfo->attr;
6289
6290 if (attr)
6291 {
6292 /* Line1 display AS-path, Aggregator */
6293 if (attr->aspath)
6294 {
6295 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00006296 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00006297 vty_out (vty, "Local");
6298 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00006299 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00006300 }
6301
paulb40d9392005-08-22 22:34:41 +00006302 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
6303 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00006304 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
6305 vty_out (vty, ", (stale)");
6306 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04006307 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00006308 attr->extra->aggregator_as,
6309 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00006310 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
6311 vty_out (vty, ", (Received from a RR-client)");
6312 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
6313 vty_out (vty, ", (Received from a RS-client)");
6314 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6315 vty_out (vty, ", (history entry)");
6316 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
6317 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00006318 vty_out (vty, "%s", VTY_NEWLINE);
6319
6320 /* Line2 display Next-hop, Neighbor, Router-id */
6321 if (p->family == AF_INET)
6322 {
Lou Berger298cc2f2016-01-12 13:42:02 -05006323 vty_out (vty, " %s", ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) ?
Paul Jakmafb982c22007-05-04 20:15:47 +00006324 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00006325 inet_ntoa (attr->nexthop));
6326 }
6327#ifdef HAVE_IPV6
6328 else
6329 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006330 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006331 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006332 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00006333 buf, INET6_ADDRSTRLEN));
6334 }
6335#endif /* HAVE_IPV6 */
6336
6337 if (binfo->peer == bgp->peer_self)
6338 {
6339 vty_out (vty, " from %s ",
6340 p->family == AF_INET ? "0.0.0.0" : "::");
6341 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6342 }
6343 else
6344 {
6345 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6346 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006347 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02006348 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006349 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006350 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006351 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006352 else
6353 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6354 }
6355 vty_out (vty, "%s", VTY_NEWLINE);
6356
6357#ifdef HAVE_IPV6
6358 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006359 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006360 {
6361 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006362 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006363 buf, INET6_ADDRSTRLEN),
6364 VTY_NEWLINE);
6365 }
6366#endif /* HAVE_IPV6 */
6367
6368 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6369 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6370
6371 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006372 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006373
6374 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006375 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006376 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006377 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006378
Paul Jakmafb982c22007-05-04 20:15:47 +00006379 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006380 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006381
6382 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6383 vty_out (vty, ", valid");
6384
6385 if (binfo->peer != bgp->peer_self)
6386 {
6387 if (binfo->peer->as == binfo->peer->local_as)
6388 vty_out (vty, ", internal");
6389 else
6390 vty_out (vty, ", %s",
6391 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6392 }
6393 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6394 vty_out (vty, ", aggregated, local");
6395 else if (binfo->type != ZEBRA_ROUTE_BGP)
6396 vty_out (vty, ", sourced");
6397 else
6398 vty_out (vty, ", sourced, local");
6399
6400 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6401 vty_out (vty, ", atomic-aggregate");
6402
Josh Baileyde8d5df2011-07-20 20:46:01 -07006403 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6404 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6405 bgp_info_mpath_count (binfo)))
6406 vty_out (vty, ", multipath");
6407
paul718e3742002-12-13 20:15:29 +00006408 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6409 vty_out (vty, ", best");
6410
6411 vty_out (vty, "%s", VTY_NEWLINE);
6412
6413 /* Line 4 display Community */
6414 if (attr->community)
6415 vty_out (vty, " Community: %s%s", attr->community->str,
6416 VTY_NEWLINE);
6417
6418 /* Line 5 display Extended-community */
6419 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006420 vty_out (vty, " Extended Community: %s%s",
6421 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006422
6423 /* Line 6 display Originator, Cluster-id */
6424 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6425 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6426 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006427 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006428 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006429 vty_out (vty, " Originator: %s",
6430 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006431
6432 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6433 {
6434 int i;
6435 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006436 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6437 vty_out (vty, "%s ",
6438 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006439 }
6440 vty_out (vty, "%s", VTY_NEWLINE);
6441 }
Paul Jakma41367172007-08-06 15:24:51 +00006442
Paul Jakmafb982c22007-05-04 20:15:47 +00006443 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006444 bgp_damp_info_vty (vty, binfo);
6445
6446 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006447#ifdef HAVE_CLOCK_MONOTONIC
6448 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006449 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006450#else
6451 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6452#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006453 }
6454 vty_out (vty, "%s", VTY_NEWLINE);
Boian Bonevb366b512013-09-09 16:41:35 +00006455}
6456
6457#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, "\
6458 "h history, * valid, > best, = multipath,%s"\
6459 " i internal, r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006460#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006461#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6462#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6463#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6464
6465enum bgp_show_type
6466{
6467 bgp_show_type_normal,
6468 bgp_show_type_regexp,
6469 bgp_show_type_prefix_list,
6470 bgp_show_type_filter_list,
6471 bgp_show_type_route_map,
6472 bgp_show_type_neighbor,
6473 bgp_show_type_cidr_only,
6474 bgp_show_type_prefix_longer,
6475 bgp_show_type_community_all,
6476 bgp_show_type_community,
6477 bgp_show_type_community_exact,
6478 bgp_show_type_community_list,
6479 bgp_show_type_community_list_exact,
6480 bgp_show_type_flap_statistics,
6481 bgp_show_type_flap_address,
6482 bgp_show_type_flap_prefix,
6483 bgp_show_type_flap_cidr_only,
6484 bgp_show_type_flap_regexp,
6485 bgp_show_type_flap_filter_list,
6486 bgp_show_type_flap_prefix_list,
6487 bgp_show_type_flap_prefix_longer,
6488 bgp_show_type_flap_route_map,
6489 bgp_show_type_flap_neighbor,
6490 bgp_show_type_dampend_paths,
6491 bgp_show_type_damp_neighbor
6492};
6493
ajs5a646652004-11-05 01:25:55 +00006494static int
paulfee0f4c2004-09-13 05:12:46 +00006495bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006496 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006497{
paul718e3742002-12-13 20:15:29 +00006498 struct bgp_info *ri;
6499 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006500 int header = 1;
paul718e3742002-12-13 20:15:29 +00006501 int display;
ajs5a646652004-11-05 01:25:55 +00006502 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006503
6504 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006505 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006506
paul718e3742002-12-13 20:15:29 +00006507 /* Start processing of routes. */
6508 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6509 if (rn->info != NULL)
6510 {
6511 display = 0;
6512
6513 for (ri = rn->info; ri; ri = ri->next)
6514 {
ajs5a646652004-11-05 01:25:55 +00006515 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006516 || type == bgp_show_type_flap_address
6517 || type == bgp_show_type_flap_prefix
6518 || type == bgp_show_type_flap_cidr_only
6519 || type == bgp_show_type_flap_regexp
6520 || type == bgp_show_type_flap_filter_list
6521 || type == bgp_show_type_flap_prefix_list
6522 || type == bgp_show_type_flap_prefix_longer
6523 || type == bgp_show_type_flap_route_map
6524 || type == bgp_show_type_flap_neighbor
6525 || type == bgp_show_type_dampend_paths
6526 || type == bgp_show_type_damp_neighbor)
6527 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006528 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006529 continue;
6530 }
6531 if (type == bgp_show_type_regexp
6532 || type == bgp_show_type_flap_regexp)
6533 {
ajs5a646652004-11-05 01:25:55 +00006534 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006535
6536 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6537 continue;
6538 }
6539 if (type == bgp_show_type_prefix_list
6540 || type == bgp_show_type_flap_prefix_list)
6541 {
ajs5a646652004-11-05 01:25:55 +00006542 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006543
6544 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6545 continue;
6546 }
6547 if (type == bgp_show_type_filter_list
6548 || type == bgp_show_type_flap_filter_list)
6549 {
ajs5a646652004-11-05 01:25:55 +00006550 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006551
6552 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6553 continue;
6554 }
6555 if (type == bgp_show_type_route_map
6556 || type == bgp_show_type_flap_route_map)
6557 {
ajs5a646652004-11-05 01:25:55 +00006558 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006559 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006560 struct attr dummy_attr;
6561 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006562 int ret;
6563
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006564 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006565 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006566
paul718e3742002-12-13 20:15:29 +00006567 binfo.peer = ri->peer;
6568 binfo.attr = &dummy_attr;
6569
6570 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006571 if (ret == RMAP_DENYMATCH)
6572 continue;
6573 }
6574 if (type == bgp_show_type_neighbor
6575 || type == bgp_show_type_flap_neighbor
6576 || type == bgp_show_type_damp_neighbor)
6577 {
ajs5a646652004-11-05 01:25:55 +00006578 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006579
6580 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6581 continue;
6582 }
6583 if (type == bgp_show_type_cidr_only
6584 || type == bgp_show_type_flap_cidr_only)
6585 {
6586 u_int32_t destination;
6587
6588 destination = ntohl (rn->p.u.prefix4.s_addr);
6589 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6590 continue;
6591 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6592 continue;
6593 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6594 continue;
6595 }
6596 if (type == bgp_show_type_prefix_longer
6597 || type == bgp_show_type_flap_prefix_longer)
6598 {
ajs5a646652004-11-05 01:25:55 +00006599 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006600
6601 if (! prefix_match (p, &rn->p))
6602 continue;
6603 }
6604 if (type == bgp_show_type_community_all)
6605 {
6606 if (! ri->attr->community)
6607 continue;
6608 }
6609 if (type == bgp_show_type_community)
6610 {
ajs5a646652004-11-05 01:25:55 +00006611 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006612
6613 if (! ri->attr->community ||
6614 ! community_match (ri->attr->community, com))
6615 continue;
6616 }
6617 if (type == bgp_show_type_community_exact)
6618 {
ajs5a646652004-11-05 01:25:55 +00006619 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006620
6621 if (! ri->attr->community ||
6622 ! community_cmp (ri->attr->community, com))
6623 continue;
6624 }
6625 if (type == bgp_show_type_community_list)
6626 {
ajs5a646652004-11-05 01:25:55 +00006627 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006628
6629 if (! community_list_match (ri->attr->community, list))
6630 continue;
6631 }
6632 if (type == bgp_show_type_community_list_exact)
6633 {
ajs5a646652004-11-05 01:25:55 +00006634 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006635
6636 if (! community_list_exact_match (ri->attr->community, list))
6637 continue;
6638 }
6639 if (type == bgp_show_type_flap_address
6640 || type == bgp_show_type_flap_prefix)
6641 {
ajs5a646652004-11-05 01:25:55 +00006642 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006643
6644 if (! prefix_match (&rn->p, p))
6645 continue;
6646
6647 if (type == bgp_show_type_flap_prefix)
6648 if (p->prefixlen != rn->p.prefixlen)
6649 continue;
6650 }
6651 if (type == bgp_show_type_dampend_paths
6652 || type == bgp_show_type_damp_neighbor)
6653 {
6654 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6655 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6656 continue;
6657 }
6658
6659 if (header)
6660 {
hasso93406d82005-02-02 14:40:33 +00006661 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6662 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6663 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006664 if (type == bgp_show_type_dampend_paths
6665 || type == bgp_show_type_damp_neighbor)
6666 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6667 else if (type == bgp_show_type_flap_statistics
6668 || type == bgp_show_type_flap_address
6669 || type == bgp_show_type_flap_prefix
6670 || type == bgp_show_type_flap_cidr_only
6671 || type == bgp_show_type_flap_regexp
6672 || type == bgp_show_type_flap_filter_list
6673 || type == bgp_show_type_flap_prefix_list
6674 || type == bgp_show_type_flap_prefix_longer
6675 || type == bgp_show_type_flap_route_map
6676 || type == bgp_show_type_flap_neighbor)
6677 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6678 else
6679 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006680 header = 0;
6681 }
6682
6683 if (type == bgp_show_type_dampend_paths
6684 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006685 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006686 else if (type == bgp_show_type_flap_statistics
6687 || type == bgp_show_type_flap_address
6688 || type == bgp_show_type_flap_prefix
6689 || type == bgp_show_type_flap_cidr_only
6690 || type == bgp_show_type_flap_regexp
6691 || type == bgp_show_type_flap_filter_list
6692 || type == bgp_show_type_flap_prefix_list
6693 || type == bgp_show_type_flap_prefix_longer
6694 || type == bgp_show_type_flap_route_map
6695 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006696 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006697 else
ajs5a646652004-11-05 01:25:55 +00006698 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006699 display++;
6700 }
6701 if (display)
ajs5a646652004-11-05 01:25:55 +00006702 output_count++;
paul718e3742002-12-13 20:15:29 +00006703 }
6704
6705 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006706 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006707 {
6708 if (type == bgp_show_type_normal)
6709 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6710 }
6711 else
6712 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006713 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006714
6715 return CMD_SUCCESS;
6716}
6717
ajs5a646652004-11-05 01:25:55 +00006718static int
paulfee0f4c2004-09-13 05:12:46 +00006719bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006720 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006721{
6722 struct bgp_table *table;
6723
6724 if (bgp == NULL) {
6725 bgp = bgp_get_default ();
6726 }
6727
6728 if (bgp == NULL)
6729 {
6730 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6731 return CMD_WARNING;
6732 }
6733
6734
6735 table = bgp->rib[afi][safi];
6736
ajs5a646652004-11-05 01:25:55 +00006737 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006738}
6739
paul718e3742002-12-13 20:15:29 +00006740/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006741static void
paul718e3742002-12-13 20:15:29 +00006742route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6743 struct bgp_node *rn,
6744 struct prefix_rd *prd, afi_t afi, safi_t safi)
6745{
6746 struct bgp_info *ri;
6747 struct prefix *p;
6748 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006749 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006750 char buf1[INET6_ADDRSTRLEN];
6751 char buf2[INET6_ADDRSTRLEN];
6752 int count = 0;
6753 int best = 0;
6754 int suppress = 0;
6755 int no_export = 0;
6756 int no_advertise = 0;
6757 int local_as = 0;
6758 int first = 0;
Lou Berger298cc2f2016-01-12 13:42:02 -05006759 int printrd = ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP));
paul718e3742002-12-13 20:15:29 +00006760
6761 p = &rn->p;
6762 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
Lou Berger298cc2f2016-01-12 13:42:02 -05006763 (printrd ? prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6764 printrd ? ":" : "",
paul718e3742002-12-13 20:15:29 +00006765 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6766 p->prefixlen, VTY_NEWLINE);
6767
6768 for (ri = rn->info; ri; ri = ri->next)
6769 {
6770 count++;
6771 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6772 {
6773 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006774 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006775 suppress = 1;
6776 if (ri->attr->community != NULL)
6777 {
6778 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6779 no_advertise = 1;
6780 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6781 no_export = 1;
6782 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6783 local_as = 1;
6784 }
6785 }
6786 }
6787
6788 vty_out (vty, "Paths: (%d available", count);
6789 if (best)
6790 {
6791 vty_out (vty, ", best #%d", best);
6792 if (safi == SAFI_UNICAST)
6793 vty_out (vty, ", table Default-IP-Routing-Table");
6794 }
6795 else
6796 vty_out (vty, ", no best path");
6797 if (no_advertise)
6798 vty_out (vty, ", not advertised to any peer");
6799 else if (no_export)
6800 vty_out (vty, ", not advertised to EBGP peer");
6801 else if (local_as)
6802 vty_out (vty, ", not advertised outside local AS");
6803 if (suppress)
6804 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6805 vty_out (vty, ")%s", VTY_NEWLINE);
6806
6807 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006808 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006809 {
6810 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6811 {
6812 if (! first)
6813 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6814 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6815 first = 1;
6816 }
6817 }
6818 if (! first)
6819 vty_out (vty, " Not advertised to any peer");
6820 vty_out (vty, "%s", VTY_NEWLINE);
6821}
6822
6823/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006824static int
paulfee0f4c2004-09-13 05:12:46 +00006825bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006826 struct bgp_table *rib, const char *ip_str,
6827 afi_t afi, safi_t safi, struct prefix_rd *prd,
6828 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006829{
6830 int ret;
6831 int header;
6832 int display = 0;
6833 struct prefix match;
6834 struct bgp_node *rn;
6835 struct bgp_node *rm;
6836 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006837 struct bgp_table *table;
6838
Lou Berger050defe2016-01-12 13:41:59 -05006839 memset (&match, 0, sizeof (struct prefix)); /* keep valgrind happy */
paul718e3742002-12-13 20:15:29 +00006840 /* Check IP address argument. */
6841 ret = str2prefix (ip_str, &match);
6842 if (! ret)
6843 {
6844 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6845 return CMD_WARNING;
6846 }
6847
6848 match.family = afi2family (afi);
6849
Lou Berger298cc2f2016-01-12 13:42:02 -05006850 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +00006851 {
paulfee0f4c2004-09-13 05:12:46 +00006852 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006853 {
6854 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6855 continue;
6856
6857 if ((table = rn->info) != NULL)
6858 {
6859 header = 1;
6860
6861 if ((rm = bgp_node_match (table, &match)) != NULL)
6862 {
6863 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006864 {
6865 bgp_unlock_node (rm);
6866 continue;
6867 }
paul718e3742002-12-13 20:15:29 +00006868
6869 for (ri = rm->info; ri; ri = ri->next)
6870 {
6871 if (header)
6872 {
6873 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
Lou Berger298cc2f2016-01-12 13:42:02 -05006874 AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006875
6876 header = 0;
6877 }
6878 display++;
Lou Berger298cc2f2016-01-12 13:42:02 -05006879 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, safi);
paul718e3742002-12-13 20:15:29 +00006880 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006881
6882 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006883 }
6884 }
6885 }
6886 }
6887 else
6888 {
6889 header = 1;
6890
paulfee0f4c2004-09-13 05:12:46 +00006891 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006892 {
6893 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6894 {
6895 for (ri = rn->info; ri; ri = ri->next)
6896 {
6897 if (header)
6898 {
6899 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6900 header = 0;
6901 }
6902 display++;
6903 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6904 }
6905 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006906
6907 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006908 }
6909 }
6910
6911 if (! display)
6912 {
6913 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6914 return CMD_WARNING;
6915 }
6916
6917 return CMD_SUCCESS;
6918}
6919
paulfee0f4c2004-09-13 05:12:46 +00006920/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006921static int
paulfd79ac92004-10-13 05:06:08 +00006922bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006923 afi_t afi, safi_t safi, struct prefix_rd *prd,
6924 int prefix_check)
6925{
6926 struct bgp *bgp;
6927
6928 /* BGP structure lookup. */
6929 if (view_name)
6930 {
6931 bgp = bgp_lookup_by_name (view_name);
6932 if (bgp == NULL)
6933 {
6934 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6935 return CMD_WARNING;
6936 }
6937 }
6938 else
6939 {
6940 bgp = bgp_get_default ();
6941 if (bgp == NULL)
6942 {
6943 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6944 return CMD_WARNING;
6945 }
6946 }
6947
6948 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6949 afi, safi, prd, prefix_check);
6950}
6951
paul718e3742002-12-13 20:15:29 +00006952/* BGP route print out function. */
6953DEFUN (show_ip_bgp,
6954 show_ip_bgp_cmd,
6955 "show ip bgp",
6956 SHOW_STR
6957 IP_STR
6958 BGP_STR)
6959{
ajs5a646652004-11-05 01:25:55 +00006960 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006961}
6962
6963DEFUN (show_ip_bgp_ipv4,
6964 show_ip_bgp_ipv4_cmd,
6965 "show ip bgp ipv4 (unicast|multicast)",
6966 SHOW_STR
6967 IP_STR
6968 BGP_STR
6969 "Address family\n"
6970 "Address Family modifier\n"
6971 "Address Family modifier\n")
6972{
6973 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006974 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6975 NULL);
paul718e3742002-12-13 20:15:29 +00006976
ajs5a646652004-11-05 01:25:55 +00006977 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006978}
6979
Michael Lambert95cbbd22010-07-23 14:43:04 -04006980ALIAS (show_ip_bgp_ipv4,
6981 show_bgp_ipv4_safi_cmd,
6982 "show bgp ipv4 (unicast|multicast)",
6983 SHOW_STR
6984 BGP_STR
6985 "Address family\n"
6986 "Address Family modifier\n"
6987 "Address Family modifier\n")
6988
paul718e3742002-12-13 20:15:29 +00006989DEFUN (show_ip_bgp_route,
6990 show_ip_bgp_route_cmd,
6991 "show ip bgp A.B.C.D",
6992 SHOW_STR
6993 IP_STR
6994 BGP_STR
6995 "Network in the BGP routing table to display\n")
6996{
6997 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6998}
6999
7000DEFUN (show_ip_bgp_ipv4_route,
7001 show_ip_bgp_ipv4_route_cmd,
7002 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
7003 SHOW_STR
7004 IP_STR
7005 BGP_STR
7006 "Address family\n"
7007 "Address Family modifier\n"
7008 "Address Family modifier\n"
7009 "Network in the BGP routing table to display\n")
7010{
7011 if (strncmp (argv[0], "m", 1) == 0)
7012 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
7013
7014 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7015}
7016
Michael Lambert95cbbd22010-07-23 14:43:04 -04007017ALIAS (show_ip_bgp_ipv4_route,
7018 show_bgp_ipv4_safi_route_cmd,
7019 "show bgp ipv4 (unicast|multicast) A.B.C.D",
7020 SHOW_STR
7021 BGP_STR
7022 "Address family\n"
7023 "Address Family modifier\n"
7024 "Address Family modifier\n"
7025 "Network in the BGP routing table to display\n")
7026
paul718e3742002-12-13 20:15:29 +00007027DEFUN (show_ip_bgp_vpnv4_all_route,
7028 show_ip_bgp_vpnv4_all_route_cmd,
7029 "show ip bgp vpnv4 all A.B.C.D",
7030 SHOW_STR
7031 IP_STR
7032 BGP_STR
7033 "Display VPNv4 NLRI specific information\n"
7034 "Display information about all VPNv4 NLRIs\n"
7035 "Network in the BGP routing table to display\n")
7036{
7037 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
7038}
7039
7040DEFUN (show_ip_bgp_vpnv4_rd_route,
7041 show_ip_bgp_vpnv4_rd_route_cmd,
7042 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
7043 SHOW_STR
7044 IP_STR
7045 BGP_STR
7046 "Display VPNv4 NLRI specific information\n"
7047 "Display information for a route distinguisher\n"
7048 "VPN Route Distinguisher\n"
7049 "Network in the BGP routing table to display\n")
7050{
7051 int ret;
7052 struct prefix_rd prd;
7053
7054 ret = str2prefix_rd (argv[0], &prd);
7055 if (! ret)
7056 {
7057 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7058 return CMD_WARNING;
7059 }
7060 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
7061}
7062
7063DEFUN (show_ip_bgp_prefix,
7064 show_ip_bgp_prefix_cmd,
7065 "show ip bgp A.B.C.D/M",
7066 SHOW_STR
7067 IP_STR
7068 BGP_STR
7069 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7070{
7071 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
7072}
7073
7074DEFUN (show_ip_bgp_ipv4_prefix,
7075 show_ip_bgp_ipv4_prefix_cmd,
7076 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7077 SHOW_STR
7078 IP_STR
7079 BGP_STR
7080 "Address family\n"
7081 "Address Family modifier\n"
7082 "Address Family modifier\n"
7083 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7084{
7085 if (strncmp (argv[0], "m", 1) == 0)
7086 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
7087
7088 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7089}
7090
Michael Lambert95cbbd22010-07-23 14:43:04 -04007091ALIAS (show_ip_bgp_ipv4_prefix,
7092 show_bgp_ipv4_safi_prefix_cmd,
7093 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
7094 SHOW_STR
7095 BGP_STR
7096 "Address family\n"
7097 "Address Family modifier\n"
7098 "Address Family modifier\n"
7099 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7100
paul718e3742002-12-13 20:15:29 +00007101DEFUN (show_ip_bgp_vpnv4_all_prefix,
7102 show_ip_bgp_vpnv4_all_prefix_cmd,
7103 "show ip bgp vpnv4 all A.B.C.D/M",
7104 SHOW_STR
7105 IP_STR
7106 BGP_STR
7107 "Display VPNv4 NLRI specific information\n"
7108 "Display information about all VPNv4 NLRIs\n"
7109 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7110{
7111 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
7112}
7113
7114DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7115 show_ip_bgp_vpnv4_rd_prefix_cmd,
7116 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7117 SHOW_STR
7118 IP_STR
7119 BGP_STR
7120 "Display VPNv4 NLRI specific information\n"
7121 "Display information for a route distinguisher\n"
7122 "VPN Route Distinguisher\n"
7123 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7124{
7125 int ret;
7126 struct prefix_rd prd;
7127
7128 ret = str2prefix_rd (argv[0], &prd);
7129 if (! ret)
7130 {
7131 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7132 return CMD_WARNING;
7133 }
7134 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
7135}
7136
7137DEFUN (show_ip_bgp_view,
7138 show_ip_bgp_view_cmd,
7139 "show ip bgp view WORD",
7140 SHOW_STR
7141 IP_STR
7142 BGP_STR
7143 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007144 "View name\n")
paul718e3742002-12-13 20:15:29 +00007145{
paulbb46e942003-10-24 19:02:03 +00007146 struct bgp *bgp;
7147
7148 /* BGP structure lookup. */
7149 bgp = bgp_lookup_by_name (argv[0]);
7150 if (bgp == NULL)
7151 {
7152 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7153 return CMD_WARNING;
7154 }
7155
ajs5a646652004-11-05 01:25:55 +00007156 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007157}
7158
7159DEFUN (show_ip_bgp_view_route,
7160 show_ip_bgp_view_route_cmd,
7161 "show ip bgp view WORD A.B.C.D",
7162 SHOW_STR
7163 IP_STR
7164 BGP_STR
7165 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007166 "View name\n"
paul718e3742002-12-13 20:15:29 +00007167 "Network in the BGP routing table to display\n")
7168{
7169 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
7170}
7171
7172DEFUN (show_ip_bgp_view_prefix,
7173 show_ip_bgp_view_prefix_cmd,
7174 "show ip bgp view WORD A.B.C.D/M",
7175 SHOW_STR
7176 IP_STR
7177 BGP_STR
7178 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007179 "View name\n"
paul718e3742002-12-13 20:15:29 +00007180 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7181{
7182 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7183}
7184
7185#ifdef HAVE_IPV6
7186DEFUN (show_bgp,
7187 show_bgp_cmd,
7188 "show bgp",
7189 SHOW_STR
7190 BGP_STR)
7191{
ajs5a646652004-11-05 01:25:55 +00007192 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7193 NULL);
paul718e3742002-12-13 20:15:29 +00007194}
7195
7196ALIAS (show_bgp,
7197 show_bgp_ipv6_cmd,
7198 "show bgp ipv6",
7199 SHOW_STR
7200 BGP_STR
7201 "Address family\n")
7202
Michael Lambert95cbbd22010-07-23 14:43:04 -04007203DEFUN (show_bgp_ipv6_safi,
7204 show_bgp_ipv6_safi_cmd,
7205 "show bgp ipv6 (unicast|multicast)",
7206 SHOW_STR
7207 BGP_STR
7208 "Address family\n"
7209 "Address Family modifier\n"
7210 "Address Family modifier\n")
7211{
7212 if (strncmp (argv[0], "m", 1) == 0)
7213 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7214 NULL);
7215
7216 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
7217}
7218
paul718e3742002-12-13 20:15:29 +00007219/* old command */
7220DEFUN (show_ipv6_bgp,
7221 show_ipv6_bgp_cmd,
7222 "show ipv6 bgp",
7223 SHOW_STR
7224 IP_STR
7225 BGP_STR)
7226{
ajs5a646652004-11-05 01:25:55 +00007227 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
7228 NULL);
paul718e3742002-12-13 20:15:29 +00007229}
7230
7231DEFUN (show_bgp_route,
7232 show_bgp_route_cmd,
7233 "show bgp X:X::X:X",
7234 SHOW_STR
7235 BGP_STR
7236 "Network in the BGP routing table to display\n")
7237{
7238 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7239}
7240
7241ALIAS (show_bgp_route,
7242 show_bgp_ipv6_route_cmd,
7243 "show bgp ipv6 X:X::X:X",
7244 SHOW_STR
7245 BGP_STR
7246 "Address family\n"
7247 "Network in the BGP routing table to display\n")
7248
Michael Lambert95cbbd22010-07-23 14:43:04 -04007249DEFUN (show_bgp_ipv6_safi_route,
7250 show_bgp_ipv6_safi_route_cmd,
7251 "show bgp ipv6 (unicast|multicast) X:X::X:X",
7252 SHOW_STR
7253 BGP_STR
7254 "Address family\n"
7255 "Address Family modifier\n"
7256 "Address Family modifier\n"
7257 "Network in the BGP routing table to display\n")
7258{
7259 if (strncmp (argv[0], "m", 1) == 0)
7260 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7261
7262 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7263}
7264
paul718e3742002-12-13 20:15:29 +00007265/* old command */
7266DEFUN (show_ipv6_bgp_route,
7267 show_ipv6_bgp_route_cmd,
7268 "show ipv6 bgp X:X::X:X",
7269 SHOW_STR
7270 IP_STR
7271 BGP_STR
7272 "Network in the BGP routing table to display\n")
7273{
7274 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7275}
7276
7277DEFUN (show_bgp_prefix,
7278 show_bgp_prefix_cmd,
7279 "show bgp X:X::X:X/M",
7280 SHOW_STR
7281 BGP_STR
7282 "IPv6 prefix <network>/<length>\n")
7283{
7284 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7285}
7286
7287ALIAS (show_bgp_prefix,
7288 show_bgp_ipv6_prefix_cmd,
7289 "show bgp ipv6 X:X::X:X/M",
7290 SHOW_STR
7291 BGP_STR
7292 "Address family\n"
7293 "IPv6 prefix <network>/<length>\n")
7294
Michael Lambert95cbbd22010-07-23 14:43:04 -04007295DEFUN (show_bgp_ipv6_safi_prefix,
7296 show_bgp_ipv6_safi_prefix_cmd,
7297 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7298 SHOW_STR
7299 BGP_STR
7300 "Address family\n"
7301 "Address Family modifier\n"
7302 "Address Family modifier\n"
7303 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7304{
7305 if (strncmp (argv[0], "m", 1) == 0)
7306 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7307
7308 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7309}
7310
paul718e3742002-12-13 20:15:29 +00007311/* old command */
7312DEFUN (show_ipv6_bgp_prefix,
7313 show_ipv6_bgp_prefix_cmd,
7314 "show ipv6 bgp X:X::X:X/M",
7315 SHOW_STR
7316 IP_STR
7317 BGP_STR
7318 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7319{
7320 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7321}
7322
paulbb46e942003-10-24 19:02:03 +00007323DEFUN (show_bgp_view,
7324 show_bgp_view_cmd,
7325 "show bgp view WORD",
7326 SHOW_STR
7327 BGP_STR
7328 "BGP view\n"
7329 "View name\n")
7330{
7331 struct bgp *bgp;
7332
7333 /* BGP structure lookup. */
7334 bgp = bgp_lookup_by_name (argv[0]);
7335 if (bgp == NULL)
7336 {
7337 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7338 return CMD_WARNING;
7339 }
7340
ajs5a646652004-11-05 01:25:55 +00007341 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007342}
7343
7344ALIAS (show_bgp_view,
7345 show_bgp_view_ipv6_cmd,
7346 "show bgp view WORD ipv6",
7347 SHOW_STR
7348 BGP_STR
7349 "BGP view\n"
7350 "View name\n"
7351 "Address family\n")
7352
7353DEFUN (show_bgp_view_route,
7354 show_bgp_view_route_cmd,
7355 "show bgp view WORD X:X::X:X",
7356 SHOW_STR
7357 BGP_STR
7358 "BGP view\n"
7359 "View name\n"
7360 "Network in the BGP routing table to display\n")
7361{
7362 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7363}
7364
7365ALIAS (show_bgp_view_route,
7366 show_bgp_view_ipv6_route_cmd,
7367 "show bgp view WORD ipv6 X:X::X:X",
7368 SHOW_STR
7369 BGP_STR
7370 "BGP view\n"
7371 "View name\n"
7372 "Address family\n"
7373 "Network in the BGP routing table to display\n")
7374
7375DEFUN (show_bgp_view_prefix,
7376 show_bgp_view_prefix_cmd,
7377 "show bgp view WORD X:X::X:X/M",
7378 SHOW_STR
7379 BGP_STR
7380 "BGP view\n"
7381 "View name\n"
7382 "IPv6 prefix <network>/<length>\n")
7383{
7384 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7385}
7386
7387ALIAS (show_bgp_view_prefix,
7388 show_bgp_view_ipv6_prefix_cmd,
7389 "show bgp view WORD ipv6 X:X::X:X/M",
7390 SHOW_STR
7391 BGP_STR
7392 "BGP view\n"
7393 "View name\n"
7394 "Address family\n"
7395 "IPv6 prefix <network>/<length>\n")
7396
paul718e3742002-12-13 20:15:29 +00007397/* old command */
7398DEFUN (show_ipv6_mbgp,
7399 show_ipv6_mbgp_cmd,
7400 "show ipv6 mbgp",
7401 SHOW_STR
7402 IP_STR
7403 MBGP_STR)
7404{
ajs5a646652004-11-05 01:25:55 +00007405 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7406 NULL);
paul718e3742002-12-13 20:15:29 +00007407}
7408
7409/* old command */
7410DEFUN (show_ipv6_mbgp_route,
7411 show_ipv6_mbgp_route_cmd,
7412 "show ipv6 mbgp X:X::X:X",
7413 SHOW_STR
7414 IP_STR
7415 MBGP_STR
7416 "Network in the MBGP routing table to display\n")
7417{
7418 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7419}
7420
7421/* old command */
7422DEFUN (show_ipv6_mbgp_prefix,
7423 show_ipv6_mbgp_prefix_cmd,
7424 "show ipv6 mbgp X:X::X:X/M",
7425 SHOW_STR
7426 IP_STR
7427 MBGP_STR
7428 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7429{
7430 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7431}
7432#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007433
paul718e3742002-12-13 20:15:29 +00007434
paul94f2b392005-06-28 12:44:16 +00007435static int
paulfd79ac92004-10-13 05:06:08 +00007436bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007437 safi_t safi, enum bgp_show_type type)
7438{
7439 int i;
7440 struct buffer *b;
7441 char *regstr;
7442 int first;
7443 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007444 int rc;
paul718e3742002-12-13 20:15:29 +00007445
7446 first = 0;
7447 b = buffer_new (1024);
7448 for (i = 0; i < argc; i++)
7449 {
7450 if (first)
7451 buffer_putc (b, ' ');
7452 else
7453 {
7454 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7455 continue;
7456 first = 1;
7457 }
7458
7459 buffer_putstr (b, argv[i]);
7460 }
7461 buffer_putc (b, '\0');
7462
7463 regstr = buffer_getstr (b);
7464 buffer_free (b);
7465
7466 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007467 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007468 if (! regex)
7469 {
7470 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7471 VTY_NEWLINE);
7472 return CMD_WARNING;
7473 }
7474
ajs5a646652004-11-05 01:25:55 +00007475 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7476 bgp_regex_free (regex);
7477 return rc;
paul718e3742002-12-13 20:15:29 +00007478}
7479
7480DEFUN (show_ip_bgp_regexp,
7481 show_ip_bgp_regexp_cmd,
7482 "show ip 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_IP, SAFI_UNICAST,
7490 bgp_show_type_regexp);
7491}
7492
7493DEFUN (show_ip_bgp_flap_regexp,
7494 show_ip_bgp_flap_regexp_cmd,
7495 "show ip bgp flap-statistics regexp .LINE",
7496 SHOW_STR
7497 IP_STR
7498 BGP_STR
7499 "Display flap statistics of routes\n"
7500 "Display routes matching the AS path regular expression\n"
7501 "A regular-expression to match the BGP AS paths\n")
7502{
7503 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7504 bgp_show_type_flap_regexp);
7505}
7506
Balaji3921cc52015-05-16 23:12:17 +05307507ALIAS (show_ip_bgp_flap_regexp,
7508 show_ip_bgp_damp_flap_regexp_cmd,
7509 "show ip bgp dampening flap-statistics regexp .LINE",
7510 SHOW_STR
7511 IP_STR
7512 BGP_STR
7513 "Display detailed information about dampening\n"
7514 "Display flap statistics of routes\n"
7515 "Display routes matching the AS path regular expression\n"
7516 "A regular-expression to match the BGP AS paths\n")
7517
paul718e3742002-12-13 20:15:29 +00007518DEFUN (show_ip_bgp_ipv4_regexp,
7519 show_ip_bgp_ipv4_regexp_cmd,
7520 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7521 SHOW_STR
7522 IP_STR
7523 BGP_STR
7524 "Address family\n"
7525 "Address Family modifier\n"
7526 "Address Family modifier\n"
7527 "Display routes matching the AS path regular expression\n"
7528 "A regular-expression to match the BGP AS paths\n")
7529{
7530 if (strncmp (argv[0], "m", 1) == 0)
7531 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7532 bgp_show_type_regexp);
7533
7534 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7535 bgp_show_type_regexp);
7536}
7537
7538#ifdef HAVE_IPV6
7539DEFUN (show_bgp_regexp,
7540 show_bgp_regexp_cmd,
7541 "show bgp regexp .LINE",
7542 SHOW_STR
7543 BGP_STR
7544 "Display routes matching the AS path regular expression\n"
7545 "A regular-expression to match the BGP AS paths\n")
7546{
7547 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7548 bgp_show_type_regexp);
7549}
7550
7551ALIAS (show_bgp_regexp,
7552 show_bgp_ipv6_regexp_cmd,
7553 "show bgp ipv6 regexp .LINE",
7554 SHOW_STR
7555 BGP_STR
7556 "Address family\n"
7557 "Display routes matching the AS path regular expression\n"
7558 "A regular-expression to match the BGP AS paths\n")
7559
7560/* old command */
7561DEFUN (show_ipv6_bgp_regexp,
7562 show_ipv6_bgp_regexp_cmd,
7563 "show ipv6 bgp regexp .LINE",
7564 SHOW_STR
7565 IP_STR
7566 BGP_STR
7567 "Display routes matching the AS path regular expression\n"
7568 "A regular-expression to match the BGP AS paths\n")
7569{
7570 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7571 bgp_show_type_regexp);
7572}
7573
7574/* old command */
7575DEFUN (show_ipv6_mbgp_regexp,
7576 show_ipv6_mbgp_regexp_cmd,
7577 "show ipv6 mbgp regexp .LINE",
7578 SHOW_STR
7579 IP_STR
7580 BGP_STR
7581 "Display routes matching the AS path regular expression\n"
7582 "A regular-expression to match the MBGP AS paths\n")
7583{
7584 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7585 bgp_show_type_regexp);
7586}
7587#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007588
paul94f2b392005-06-28 12:44:16 +00007589static int
paulfd79ac92004-10-13 05:06:08 +00007590bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007591 safi_t safi, enum bgp_show_type type)
7592{
7593 struct prefix_list *plist;
7594
7595 plist = prefix_list_lookup (afi, prefix_list_str);
7596 if (plist == NULL)
7597 {
7598 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7599 prefix_list_str, VTY_NEWLINE);
7600 return CMD_WARNING;
7601 }
7602
ajs5a646652004-11-05 01:25:55 +00007603 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007604}
7605
7606DEFUN (show_ip_bgp_prefix_list,
7607 show_ip_bgp_prefix_list_cmd,
7608 "show ip bgp prefix-list WORD",
7609 SHOW_STR
7610 IP_STR
7611 BGP_STR
7612 "Display routes conforming to the prefix-list\n"
7613 "IP prefix-list name\n")
7614{
7615 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7616 bgp_show_type_prefix_list);
7617}
7618
7619DEFUN (show_ip_bgp_flap_prefix_list,
7620 show_ip_bgp_flap_prefix_list_cmd,
7621 "show ip bgp flap-statistics prefix-list WORD",
7622 SHOW_STR
7623 IP_STR
7624 BGP_STR
7625 "Display flap statistics of routes\n"
7626 "Display routes conforming to the prefix-list\n"
7627 "IP prefix-list name\n")
7628{
7629 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7630 bgp_show_type_flap_prefix_list);
7631}
7632
Balaji3921cc52015-05-16 23:12:17 +05307633ALIAS (show_ip_bgp_flap_prefix_list,
7634 show_ip_bgp_damp_flap_prefix_list_cmd,
7635 "show ip bgp dampening flap-statistics prefix-list WORD",
7636 SHOW_STR
7637 IP_STR
7638 BGP_STR
7639 "Display detailed information about dampening\n"
7640 "Display flap statistics of routes\n"
7641 "Display routes conforming to the prefix-list\n"
7642 "IP prefix-list name\n")
7643
paul718e3742002-12-13 20:15:29 +00007644DEFUN (show_ip_bgp_ipv4_prefix_list,
7645 show_ip_bgp_ipv4_prefix_list_cmd,
7646 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7647 SHOW_STR
7648 IP_STR
7649 BGP_STR
7650 "Address family\n"
7651 "Address Family modifier\n"
7652 "Address Family modifier\n"
7653 "Display routes conforming to the prefix-list\n"
7654 "IP prefix-list name\n")
7655{
7656 if (strncmp (argv[0], "m", 1) == 0)
7657 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7658 bgp_show_type_prefix_list);
7659
7660 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7661 bgp_show_type_prefix_list);
7662}
7663
7664#ifdef HAVE_IPV6
7665DEFUN (show_bgp_prefix_list,
7666 show_bgp_prefix_list_cmd,
7667 "show bgp prefix-list WORD",
7668 SHOW_STR
7669 BGP_STR
7670 "Display routes conforming to the prefix-list\n"
7671 "IPv6 prefix-list name\n")
7672{
7673 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7674 bgp_show_type_prefix_list);
7675}
7676
7677ALIAS (show_bgp_prefix_list,
7678 show_bgp_ipv6_prefix_list_cmd,
7679 "show bgp ipv6 prefix-list WORD",
7680 SHOW_STR
7681 BGP_STR
7682 "Address family\n"
7683 "Display routes conforming to the prefix-list\n"
7684 "IPv6 prefix-list name\n")
7685
7686/* old command */
7687DEFUN (show_ipv6_bgp_prefix_list,
7688 show_ipv6_bgp_prefix_list_cmd,
7689 "show ipv6 bgp prefix-list WORD",
7690 SHOW_STR
7691 IPV6_STR
7692 BGP_STR
7693 "Display routes matching the prefix-list\n"
7694 "IPv6 prefix-list name\n")
7695{
7696 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7697 bgp_show_type_prefix_list);
7698}
7699
7700/* old command */
7701DEFUN (show_ipv6_mbgp_prefix_list,
7702 show_ipv6_mbgp_prefix_list_cmd,
7703 "show ipv6 mbgp prefix-list WORD",
7704 SHOW_STR
7705 IPV6_STR
7706 MBGP_STR
7707 "Display routes matching the prefix-list\n"
7708 "IPv6 prefix-list name\n")
7709{
7710 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7711 bgp_show_type_prefix_list);
7712}
7713#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007714
paul94f2b392005-06-28 12:44:16 +00007715static int
paulfd79ac92004-10-13 05:06:08 +00007716bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007717 safi_t safi, enum bgp_show_type type)
7718{
7719 struct as_list *as_list;
7720
7721 as_list = as_list_lookup (filter);
7722 if (as_list == NULL)
7723 {
7724 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7725 return CMD_WARNING;
7726 }
7727
ajs5a646652004-11-05 01:25:55 +00007728 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007729}
7730
7731DEFUN (show_ip_bgp_filter_list,
7732 show_ip_bgp_filter_list_cmd,
7733 "show ip bgp filter-list WORD",
7734 SHOW_STR
7735 IP_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_IP, SAFI_UNICAST,
7741 bgp_show_type_filter_list);
7742}
7743
7744DEFUN (show_ip_bgp_flap_filter_list,
7745 show_ip_bgp_flap_filter_list_cmd,
7746 "show ip bgp flap-statistics filter-list WORD",
7747 SHOW_STR
7748 IP_STR
7749 BGP_STR
7750 "Display flap statistics of routes\n"
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_IP, SAFI_UNICAST,
7755 bgp_show_type_flap_filter_list);
7756}
7757
Balaji3921cc52015-05-16 23:12:17 +05307758ALIAS (show_ip_bgp_flap_filter_list,
7759 show_ip_bgp_damp_flap_filter_list_cmd,
7760 "show ip bgp dampening flap-statistics filter-list WORD",
7761 SHOW_STR
7762 IP_STR
7763 BGP_STR
7764 "Display detailed information about dampening\n"
7765 "Display flap statistics of routes\n"
7766 "Display routes conforming to the filter-list\n"
7767 "Regular expression access list name\n")
7768
paul718e3742002-12-13 20:15:29 +00007769DEFUN (show_ip_bgp_ipv4_filter_list,
7770 show_ip_bgp_ipv4_filter_list_cmd,
7771 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7772 SHOW_STR
7773 IP_STR
7774 BGP_STR
7775 "Address family\n"
7776 "Address Family modifier\n"
7777 "Address Family modifier\n"
7778 "Display routes conforming to the filter-list\n"
7779 "Regular expression access list name\n")
7780{
7781 if (strncmp (argv[0], "m", 1) == 0)
7782 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7783 bgp_show_type_filter_list);
7784
7785 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7786 bgp_show_type_filter_list);
7787}
7788
7789#ifdef HAVE_IPV6
7790DEFUN (show_bgp_filter_list,
7791 show_bgp_filter_list_cmd,
7792 "show bgp filter-list WORD",
7793 SHOW_STR
7794 BGP_STR
7795 "Display routes conforming to the filter-list\n"
7796 "Regular expression access list name\n")
7797{
7798 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7799 bgp_show_type_filter_list);
7800}
7801
7802ALIAS (show_bgp_filter_list,
7803 show_bgp_ipv6_filter_list_cmd,
7804 "show bgp ipv6 filter-list WORD",
7805 SHOW_STR
7806 BGP_STR
7807 "Address family\n"
7808 "Display routes conforming to the filter-list\n"
7809 "Regular expression access list name\n")
7810
7811/* old command */
7812DEFUN (show_ipv6_bgp_filter_list,
7813 show_ipv6_bgp_filter_list_cmd,
7814 "show ipv6 bgp filter-list WORD",
7815 SHOW_STR
7816 IPV6_STR
7817 BGP_STR
7818 "Display routes conforming to the filter-list\n"
7819 "Regular expression access list name\n")
7820{
7821 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7822 bgp_show_type_filter_list);
7823}
7824
7825/* old command */
7826DEFUN (show_ipv6_mbgp_filter_list,
7827 show_ipv6_mbgp_filter_list_cmd,
7828 "show ipv6 mbgp filter-list WORD",
7829 SHOW_STR
7830 IPV6_STR
7831 MBGP_STR
7832 "Display routes conforming to the filter-list\n"
7833 "Regular expression access list name\n")
7834{
7835 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7836 bgp_show_type_filter_list);
7837}
7838#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007839
Balaji3921cc52015-05-16 23:12:17 +05307840DEFUN (show_ip_bgp_dampening_info,
7841 show_ip_bgp_dampening_params_cmd,
7842 "show ip bgp dampening parameters",
7843 SHOW_STR
7844 IP_STR
7845 BGP_STR
7846 "Display detailed information about dampening\n"
7847 "Display detail of configured dampening parameters\n")
7848{
7849 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
7850}
7851
paul94f2b392005-06-28 12:44:16 +00007852static int
paulfd79ac92004-10-13 05:06:08 +00007853bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007854 safi_t safi, enum bgp_show_type type)
7855{
7856 struct route_map *rmap;
7857
7858 rmap = route_map_lookup_by_name (rmap_str);
7859 if (! rmap)
7860 {
7861 vty_out (vty, "%% %s is not a valid route-map name%s",
7862 rmap_str, VTY_NEWLINE);
7863 return CMD_WARNING;
7864 }
7865
ajs5a646652004-11-05 01:25:55 +00007866 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007867}
7868
7869DEFUN (show_ip_bgp_route_map,
7870 show_ip_bgp_route_map_cmd,
7871 "show ip bgp route-map WORD",
7872 SHOW_STR
7873 IP_STR
7874 BGP_STR
7875 "Display routes matching the route-map\n"
7876 "A route-map to match on\n")
7877{
7878 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7879 bgp_show_type_route_map);
7880}
7881
7882DEFUN (show_ip_bgp_flap_route_map,
7883 show_ip_bgp_flap_route_map_cmd,
7884 "show ip bgp flap-statistics route-map WORD",
7885 SHOW_STR
7886 IP_STR
7887 BGP_STR
7888 "Display flap statistics of routes\n"
7889 "Display routes matching the route-map\n"
7890 "A route-map to match on\n")
7891{
7892 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7893 bgp_show_type_flap_route_map);
7894}
7895
Balaji3921cc52015-05-16 23:12:17 +05307896ALIAS (show_ip_bgp_flap_route_map,
7897 show_ip_bgp_damp_flap_route_map_cmd,
7898 "show ip bgp dampening flap-statistics route-map WORD",
7899 SHOW_STR
7900 IP_STR
7901 BGP_STR
7902 "Display detailed information about dampening\n"
7903 "Display flap statistics of routes\n"
7904 "Display routes matching the route-map\n"
7905 "A route-map to match on\n")
7906
paul718e3742002-12-13 20:15:29 +00007907DEFUN (show_ip_bgp_ipv4_route_map,
7908 show_ip_bgp_ipv4_route_map_cmd,
7909 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7910 SHOW_STR
7911 IP_STR
7912 BGP_STR
7913 "Address family\n"
7914 "Address Family modifier\n"
7915 "Address Family modifier\n"
7916 "Display routes matching the route-map\n"
7917 "A route-map to match on\n")
7918{
7919 if (strncmp (argv[0], "m", 1) == 0)
7920 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7921 bgp_show_type_route_map);
7922
7923 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7924 bgp_show_type_route_map);
7925}
7926
7927DEFUN (show_bgp_route_map,
7928 show_bgp_route_map_cmd,
7929 "show bgp route-map WORD",
7930 SHOW_STR
7931 BGP_STR
7932 "Display routes matching the route-map\n"
7933 "A route-map to match on\n")
7934{
7935 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7936 bgp_show_type_route_map);
7937}
7938
7939ALIAS (show_bgp_route_map,
7940 show_bgp_ipv6_route_map_cmd,
7941 "show bgp ipv6 route-map WORD",
7942 SHOW_STR
7943 BGP_STR
7944 "Address family\n"
7945 "Display routes matching the route-map\n"
7946 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007947
paul718e3742002-12-13 20:15:29 +00007948DEFUN (show_ip_bgp_cidr_only,
7949 show_ip_bgp_cidr_only_cmd,
7950 "show ip bgp cidr-only",
7951 SHOW_STR
7952 IP_STR
7953 BGP_STR
7954 "Display only routes with non-natural netmasks\n")
7955{
7956 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007957 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007958}
7959
7960DEFUN (show_ip_bgp_flap_cidr_only,
7961 show_ip_bgp_flap_cidr_only_cmd,
7962 "show ip bgp flap-statistics cidr-only",
7963 SHOW_STR
7964 IP_STR
7965 BGP_STR
7966 "Display flap statistics of routes\n"
7967 "Display only routes with non-natural netmasks\n")
7968{
7969 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007970 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007971}
7972
Balaji3921cc52015-05-16 23:12:17 +05307973ALIAS (show_ip_bgp_flap_cidr_only,
7974 show_ip_bgp_damp_flap_cidr_only_cmd,
7975 "show ip bgp dampening flap-statistics cidr-only",
7976 SHOW_STR
7977 IP_STR
7978 BGP_STR
7979 "Display detailed information about dampening\n"
7980 "Display flap statistics of routes\n"
7981 "Display only routes with non-natural netmasks\n")
7982
paul718e3742002-12-13 20:15:29 +00007983DEFUN (show_ip_bgp_ipv4_cidr_only,
7984 show_ip_bgp_ipv4_cidr_only_cmd,
7985 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7986 SHOW_STR
7987 IP_STR
7988 BGP_STR
7989 "Address family\n"
7990 "Address Family modifier\n"
7991 "Address Family modifier\n"
7992 "Display only routes with non-natural netmasks\n")
7993{
7994 if (strncmp (argv[0], "m", 1) == 0)
7995 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007996 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007997
7998 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007999 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00008000}
David Lamparter6b0655a2014-06-04 06:53:35 +02008001
paul718e3742002-12-13 20:15:29 +00008002DEFUN (show_ip_bgp_community_all,
8003 show_ip_bgp_community_all_cmd,
8004 "show ip bgp community",
8005 SHOW_STR
8006 IP_STR
8007 BGP_STR
8008 "Display routes matching the communities\n")
8009{
8010 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00008011 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00008012}
8013
8014DEFUN (show_ip_bgp_ipv4_community_all,
8015 show_ip_bgp_ipv4_community_all_cmd,
8016 "show ip bgp ipv4 (unicast|multicast) community",
8017 SHOW_STR
8018 IP_STR
8019 BGP_STR
8020 "Address family\n"
8021 "Address Family modifier\n"
8022 "Address Family modifier\n"
8023 "Display routes matching the communities\n")
8024{
8025 if (strncmp (argv[0], "m", 1) == 0)
8026 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00008027 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00008028
8029 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00008030 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00008031}
8032
8033#ifdef HAVE_IPV6
8034DEFUN (show_bgp_community_all,
8035 show_bgp_community_all_cmd,
8036 "show bgp community",
8037 SHOW_STR
8038 BGP_STR
8039 "Display routes matching the communities\n")
8040{
8041 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00008042 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00008043}
8044
8045ALIAS (show_bgp_community_all,
8046 show_bgp_ipv6_community_all_cmd,
8047 "show bgp ipv6 community",
8048 SHOW_STR
8049 BGP_STR
8050 "Address family\n"
8051 "Display routes matching the communities\n")
8052
8053/* old command */
8054DEFUN (show_ipv6_bgp_community_all,
8055 show_ipv6_bgp_community_all_cmd,
8056 "show ipv6 bgp community",
8057 SHOW_STR
8058 IPV6_STR
8059 BGP_STR
8060 "Display routes matching the communities\n")
8061{
8062 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00008063 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00008064}
8065
8066/* old command */
8067DEFUN (show_ipv6_mbgp_community_all,
8068 show_ipv6_mbgp_community_all_cmd,
8069 "show ipv6 mbgp community",
8070 SHOW_STR
8071 IPV6_STR
8072 MBGP_STR
8073 "Display routes matching the communities\n")
8074{
8075 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00008076 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00008077}
8078#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02008079
paul94f2b392005-06-28 12:44:16 +00008080static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04008081bgp_show_community (struct vty *vty, const char *view_name, int argc,
8082 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008083{
8084 struct community *com;
8085 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008086 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00008087 int i;
8088 char *str;
8089 int first = 0;
8090
Michael Lambert95cbbd22010-07-23 14:43:04 -04008091 /* BGP structure lookup */
8092 if (view_name)
8093 {
8094 bgp = bgp_lookup_by_name (view_name);
8095 if (bgp == NULL)
8096 {
8097 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8098 return CMD_WARNING;
8099 }
8100 }
8101 else
8102 {
8103 bgp = bgp_get_default ();
8104 if (bgp == NULL)
8105 {
8106 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8107 return CMD_WARNING;
8108 }
8109 }
8110
paul718e3742002-12-13 20:15:29 +00008111 b = buffer_new (1024);
8112 for (i = 0; i < argc; i++)
8113 {
8114 if (first)
8115 buffer_putc (b, ' ');
8116 else
8117 {
8118 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8119 continue;
8120 first = 1;
8121 }
8122
8123 buffer_putstr (b, argv[i]);
8124 }
8125 buffer_putc (b, '\0');
8126
8127 str = buffer_getstr (b);
8128 buffer_free (b);
8129
8130 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00008131 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00008132 if (! com)
8133 {
8134 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8135 return CMD_WARNING;
8136 }
8137
Michael Lambert95cbbd22010-07-23 14:43:04 -04008138 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00008139 (exact ? bgp_show_type_community_exact :
8140 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00008141}
8142
8143DEFUN (show_ip_bgp_community,
8144 show_ip_bgp_community_cmd,
8145 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
8146 SHOW_STR
8147 IP_STR
8148 BGP_STR
8149 "Display routes matching the communities\n"
8150 "community number\n"
8151 "Do not send outside local AS (well-known community)\n"
8152 "Do not advertise to any peer (well-known community)\n"
8153 "Do not export to next AS (well-known community)\n")
8154{
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_community,
8159 show_ip_bgp_community2_cmd,
8160 "show ip bgp 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 "Display routes matching the communities\n"
8165 "community number\n"
8166 "Do not send outside local AS (well-known community)\n"
8167 "Do not advertise to any peer (well-known community)\n"
8168 "Do not export to next AS (well-known community)\n"
8169 "community number\n"
8170 "Do not send outside local AS (well-known community)\n"
8171 "Do not advertise to any peer (well-known community)\n"
8172 "Do not export to next AS (well-known community)\n")
8173
8174ALIAS (show_ip_bgp_community,
8175 show_ip_bgp_community3_cmd,
8176 "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)",
8177 SHOW_STR
8178 IP_STR
8179 BGP_STR
8180 "Display routes matching the communities\n"
8181 "community number\n"
8182 "Do not send outside local AS (well-known community)\n"
8183 "Do not advertise to any peer (well-known community)\n"
8184 "Do not export to next AS (well-known community)\n"
8185 "community number\n"
8186 "Do not send outside local AS (well-known community)\n"
8187 "Do not advertise to any peer (well-known community)\n"
8188 "Do not export to next AS (well-known community)\n"
8189 "community number\n"
8190 "Do not send outside local AS (well-known community)\n"
8191 "Do not advertise to any peer (well-known community)\n"
8192 "Do not export to next AS (well-known community)\n")
8193
8194ALIAS (show_ip_bgp_community,
8195 show_ip_bgp_community4_cmd,
8196 "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)",
8197 SHOW_STR
8198 IP_STR
8199 BGP_STR
8200 "Display routes matching the communities\n"
8201 "community number\n"
8202 "Do not send outside local AS (well-known community)\n"
8203 "Do not advertise to any peer (well-known community)\n"
8204 "Do not export to next AS (well-known community)\n"
8205 "community number\n"
8206 "Do not send outside local AS (well-known community)\n"
8207 "Do not advertise to any peer (well-known community)\n"
8208 "Do not export to next AS (well-known community)\n"
8209 "community number\n"
8210 "Do not send outside local AS (well-known community)\n"
8211 "Do not advertise to any peer (well-known community)\n"
8212 "Do not export to next AS (well-known community)\n"
8213 "community number\n"
8214 "Do not send outside local AS (well-known community)\n"
8215 "Do not advertise to any peer (well-known community)\n"
8216 "Do not export to next AS (well-known community)\n")
8217
8218DEFUN (show_ip_bgp_ipv4_community,
8219 show_ip_bgp_ipv4_community_cmd,
8220 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8221 SHOW_STR
8222 IP_STR
8223 BGP_STR
8224 "Address family\n"
8225 "Address Family modifier\n"
8226 "Address Family modifier\n"
8227 "Display routes matching the communities\n"
8228 "community number\n"
8229 "Do not send outside local AS (well-known community)\n"
8230 "Do not advertise to any peer (well-known community)\n"
8231 "Do not export to next AS (well-known community)\n")
8232{
8233 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008234 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008235
Michael Lambert95cbbd22010-07-23 14:43:04 -04008236 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008237}
8238
8239ALIAS (show_ip_bgp_ipv4_community,
8240 show_ip_bgp_ipv4_community2_cmd,
8241 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8242 SHOW_STR
8243 IP_STR
8244 BGP_STR
8245 "Address family\n"
8246 "Address Family modifier\n"
8247 "Address Family modifier\n"
8248 "Display routes matching the communities\n"
8249 "community number\n"
8250 "Do not send outside local AS (well-known community)\n"
8251 "Do not advertise to any peer (well-known community)\n"
8252 "Do not export to next AS (well-known community)\n"
8253 "community number\n"
8254 "Do not send outside local AS (well-known community)\n"
8255 "Do not advertise to any peer (well-known community)\n"
8256 "Do not export to next AS (well-known community)\n")
8257
8258ALIAS (show_ip_bgp_ipv4_community,
8259 show_ip_bgp_ipv4_community3_cmd,
8260 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8261 SHOW_STR
8262 IP_STR
8263 BGP_STR
8264 "Address family\n"
8265 "Address Family modifier\n"
8266 "Address Family modifier\n"
8267 "Display routes matching the communities\n"
8268 "community number\n"
8269 "Do not send outside local AS (well-known community)\n"
8270 "Do not advertise to any peer (well-known community)\n"
8271 "Do not export to next AS (well-known community)\n"
8272 "community number\n"
8273 "Do not send outside local AS (well-known community)\n"
8274 "Do not advertise to any peer (well-known community)\n"
8275 "Do not export to next AS (well-known community)\n"
8276 "community number\n"
8277 "Do not send outside local AS (well-known community)\n"
8278 "Do not advertise to any peer (well-known community)\n"
8279 "Do not export to next AS (well-known community)\n")
8280
8281ALIAS (show_ip_bgp_ipv4_community,
8282 show_ip_bgp_ipv4_community4_cmd,
8283 "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)",
8284 SHOW_STR
8285 IP_STR
8286 BGP_STR
8287 "Address family\n"
8288 "Address Family modifier\n"
8289 "Address Family modifier\n"
8290 "Display routes matching the communities\n"
8291 "community number\n"
8292 "Do not send outside local AS (well-known community)\n"
8293 "Do not advertise to any peer (well-known community)\n"
8294 "Do not export to next AS (well-known community)\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n"
8299 "community number\n"
8300 "Do not send outside local AS (well-known community)\n"
8301 "Do not advertise to any peer (well-known community)\n"
8302 "Do not export to next AS (well-known community)\n"
8303 "community number\n"
8304 "Do not send outside local AS (well-known community)\n"
8305 "Do not advertise to any peer (well-known community)\n"
8306 "Do not export to next AS (well-known community)\n")
8307
Michael Lambert95cbbd22010-07-23 14:43:04 -04008308DEFUN (show_bgp_view_afi_safi_community_all,
8309 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008310 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008311 SHOW_STR
8312 BGP_STR
8313 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008314 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008315 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008316 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008317 "Address Family modifier\n"
8318 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008319 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008320{
8321 int afi;
8322 int safi;
8323 struct bgp *bgp;
8324
8325 /* BGP structure lookup. */
8326 bgp = bgp_lookup_by_name (argv[0]);
8327 if (bgp == NULL)
8328 {
8329 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8330 return CMD_WARNING;
8331 }
8332
Michael Lambert95cbbd22010-07-23 14:43:04 -04008333 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8334 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008335 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8336}
8337
8338DEFUN (show_bgp_view_afi_safi_community,
8339 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008340 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008341 SHOW_STR
8342 BGP_STR
8343 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008344 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008345 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008346 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008347 "Address family modifier\n"
8348 "Address family modifier\n"
8349 "Display routes matching the communities\n"
8350 "community number\n"
8351 "Do not send outside local AS (well-known community)\n"
8352 "Do not advertise to any peer (well-known community)\n"
8353 "Do not export to next AS (well-known community)\n")
8354{
8355 int afi;
8356 int safi;
8357
Michael Lambert95cbbd22010-07-23 14:43:04 -04008358 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8359 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8360 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04008361}
8362
8363ALIAS (show_bgp_view_afi_safi_community,
8364 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008365 "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 -04008366 SHOW_STR
8367 BGP_STR
8368 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008369 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008370 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008371 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008372 "Address family modifier\n"
8373 "Address family modifier\n"
8374 "Display routes matching the communities\n"
8375 "community number\n"
8376 "Do not send outside local AS (well-known community)\n"
8377 "Do not advertise to any peer (well-known community)\n"
8378 "Do not export to next AS (well-known community)\n"
8379 "community number\n"
8380 "Do not send outside local AS (well-known community)\n"
8381 "Do not advertise to any peer (well-known community)\n"
8382 "Do not export to next AS (well-known community)\n")
8383
8384ALIAS (show_bgp_view_afi_safi_community,
8385 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008386 "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 -04008387 SHOW_STR
8388 BGP_STR
8389 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008390 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008391 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008392 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008393 "Address family modifier\n"
8394 "Address family modifier\n"
8395 "Display routes matching the communities\n"
8396 "community number\n"
8397 "Do not send outside local AS (well-known community)\n"
8398 "Do not advertise to any peer (well-known community)\n"
8399 "Do not export to next AS (well-known community)\n"
8400 "community number\n"
8401 "Do not send outside local AS (well-known community)\n"
8402 "Do not advertise to any peer (well-known community)\n"
8403 "Do not export to next AS (well-known community)\n"
8404 "community number\n"
8405 "Do not send outside local AS (well-known community)\n"
8406 "Do not advertise to any peer (well-known community)\n"
8407 "Do not export to next AS (well-known community)\n")
8408
8409ALIAS (show_bgp_view_afi_safi_community,
8410 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008411 "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 -04008412 SHOW_STR
8413 BGP_STR
8414 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008415 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008416 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008417 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008418 "Address family modifier\n"
8419 "Address family modifier\n"
8420 "Display routes matching the communities\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "community number\n"
8434 "Do not send outside local AS (well-known community)\n"
8435 "Do not advertise to any peer (well-known community)\n"
8436 "Do not export to next AS (well-known community)\n")
8437
paul718e3742002-12-13 20:15:29 +00008438DEFUN (show_ip_bgp_community_exact,
8439 show_ip_bgp_community_exact_cmd,
8440 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8441 SHOW_STR
8442 IP_STR
8443 BGP_STR
8444 "Display routes matching the communities\n"
8445 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n"
8449 "Exact match of the communities")
8450{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008451 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008452}
8453
8454ALIAS (show_ip_bgp_community_exact,
8455 show_ip_bgp_community2_exact_cmd,
8456 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8457 SHOW_STR
8458 IP_STR
8459 BGP_STR
8460 "Display routes matching the communities\n"
8461 "community number\n"
8462 "Do not send outside local AS (well-known community)\n"
8463 "Do not advertise to any peer (well-known community)\n"
8464 "Do not export to next AS (well-known community)\n"
8465 "community number\n"
8466 "Do not send outside local AS (well-known community)\n"
8467 "Do not advertise to any peer (well-known community)\n"
8468 "Do not export to next AS (well-known community)\n"
8469 "Exact match of the communities")
8470
8471ALIAS (show_ip_bgp_community_exact,
8472 show_ip_bgp_community3_exact_cmd,
8473 "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",
8474 SHOW_STR
8475 IP_STR
8476 BGP_STR
8477 "Display routes matching the communities\n"
8478 "community number\n"
8479 "Do not send outside local AS (well-known community)\n"
8480 "Do not advertise to any peer (well-known community)\n"
8481 "Do not export to next AS (well-known community)\n"
8482 "community number\n"
8483 "Do not send outside local AS (well-known community)\n"
8484 "Do not advertise to any peer (well-known community)\n"
8485 "Do not export to next AS (well-known community)\n"
8486 "community number\n"
8487 "Do not send outside local AS (well-known community)\n"
8488 "Do not advertise to any peer (well-known community)\n"
8489 "Do not export to next AS (well-known community)\n"
8490 "Exact match of the communities")
8491
8492ALIAS (show_ip_bgp_community_exact,
8493 show_ip_bgp_community4_exact_cmd,
8494 "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",
8495 SHOW_STR
8496 IP_STR
8497 BGP_STR
8498 "Display routes matching the communities\n"
8499 "community number\n"
8500 "Do not send outside local AS (well-known community)\n"
8501 "Do not advertise to any peer (well-known community)\n"
8502 "Do not export to next AS (well-known community)\n"
8503 "community number\n"
8504 "Do not send outside local AS (well-known community)\n"
8505 "Do not advertise to any peer (well-known community)\n"
8506 "Do not export to next AS (well-known community)\n"
8507 "community number\n"
8508 "Do not send outside local AS (well-known community)\n"
8509 "Do not advertise to any peer (well-known community)\n"
8510 "Do not export to next AS (well-known community)\n"
8511 "community number\n"
8512 "Do not send outside local AS (well-known community)\n"
8513 "Do not advertise to any peer (well-known community)\n"
8514 "Do not export to next AS (well-known community)\n"
8515 "Exact match of the communities")
8516
8517DEFUN (show_ip_bgp_ipv4_community_exact,
8518 show_ip_bgp_ipv4_community_exact_cmd,
8519 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8520 SHOW_STR
8521 IP_STR
8522 BGP_STR
8523 "Address family\n"
8524 "Address Family modifier\n"
8525 "Address Family modifier\n"
8526 "Display routes matching the communities\n"
8527 "community number\n"
8528 "Do not send outside local AS (well-known community)\n"
8529 "Do not advertise to any peer (well-known community)\n"
8530 "Do not export to next AS (well-known community)\n"
8531 "Exact match of the communities")
8532{
8533 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008534 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008535
Michael Lambert95cbbd22010-07-23 14:43:04 -04008536 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008537}
8538
8539ALIAS (show_ip_bgp_ipv4_community_exact,
8540 show_ip_bgp_ipv4_community2_exact_cmd,
8541 "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",
8542 SHOW_STR
8543 IP_STR
8544 BGP_STR
8545 "Address family\n"
8546 "Address Family modifier\n"
8547 "Address Family modifier\n"
8548 "Display routes matching the communities\n"
8549 "community number\n"
8550 "Do not send outside local AS (well-known community)\n"
8551 "Do not advertise to any peer (well-known community)\n"
8552 "Do not export to next AS (well-known community)\n"
8553 "community number\n"
8554 "Do not send outside local AS (well-known community)\n"
8555 "Do not advertise to any peer (well-known community)\n"
8556 "Do not export to next AS (well-known community)\n"
8557 "Exact match of the communities")
8558
8559ALIAS (show_ip_bgp_ipv4_community_exact,
8560 show_ip_bgp_ipv4_community3_exact_cmd,
8561 "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",
8562 SHOW_STR
8563 IP_STR
8564 BGP_STR
8565 "Address family\n"
8566 "Address Family modifier\n"
8567 "Address Family modifier\n"
8568 "Display routes matching the communities\n"
8569 "community number\n"
8570 "Do not send outside local AS (well-known community)\n"
8571 "Do not advertise to any peer (well-known community)\n"
8572 "Do not export to next AS (well-known community)\n"
8573 "community number\n"
8574 "Do not send outside local AS (well-known community)\n"
8575 "Do not advertise to any peer (well-known community)\n"
8576 "Do not export to next AS (well-known community)\n"
8577 "community number\n"
8578 "Do not send outside local AS (well-known community)\n"
8579 "Do not advertise to any peer (well-known community)\n"
8580 "Do not export to next AS (well-known community)\n"
8581 "Exact match of the communities")
8582
8583ALIAS (show_ip_bgp_ipv4_community_exact,
8584 show_ip_bgp_ipv4_community4_exact_cmd,
8585 "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",
8586 SHOW_STR
8587 IP_STR
8588 BGP_STR
8589 "Address family\n"
8590 "Address Family modifier\n"
8591 "Address Family modifier\n"
8592 "Display routes matching the communities\n"
8593 "community number\n"
8594 "Do not send outside local AS (well-known community)\n"
8595 "Do not advertise to any peer (well-known community)\n"
8596 "Do not export to next AS (well-known community)\n"
8597 "community number\n"
8598 "Do not send outside local AS (well-known community)\n"
8599 "Do not advertise to any peer (well-known community)\n"
8600 "Do not export to next AS (well-known community)\n"
8601 "community number\n"
8602 "Do not send outside local AS (well-known community)\n"
8603 "Do not advertise to any peer (well-known community)\n"
8604 "Do not export to next AS (well-known community)\n"
8605 "community number\n"
8606 "Do not send outside local AS (well-known community)\n"
8607 "Do not advertise to any peer (well-known community)\n"
8608 "Do not export to next AS (well-known community)\n"
8609 "Exact match of the communities")
8610
8611#ifdef HAVE_IPV6
8612DEFUN (show_bgp_community,
8613 show_bgp_community_cmd,
8614 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8615 SHOW_STR
8616 BGP_STR
8617 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008623 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008624}
8625
8626ALIAS (show_bgp_community,
8627 show_bgp_ipv6_community_cmd,
8628 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8629 SHOW_STR
8630 BGP_STR
8631 "Address family\n"
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
8638ALIAS (show_bgp_community,
8639 show_bgp_community2_cmd,
8640 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8641 SHOW_STR
8642 BGP_STR
8643 "Display routes matching the communities\n"
8644 "community number\n"
8645 "Do not send outside local AS (well-known community)\n"
8646 "Do not advertise to any peer (well-known community)\n"
8647 "Do not export to next AS (well-known community)\n"
8648 "community number\n"
8649 "Do not send outside local AS (well-known community)\n"
8650 "Do not advertise to any peer (well-known community)\n"
8651 "Do not export to next AS (well-known community)\n")
8652
8653ALIAS (show_bgp_community,
8654 show_bgp_ipv6_community2_cmd,
8655 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8656 SHOW_STR
8657 BGP_STR
8658 "Address family\n"
8659 "Display routes matching the communities\n"
8660 "community number\n"
8661 "Do not send outside local AS (well-known community)\n"
8662 "Do not advertise to any peer (well-known community)\n"
8663 "Do not export to next AS (well-known community)\n"
8664 "community number\n"
8665 "Do not send outside local AS (well-known community)\n"
8666 "Do not advertise to any peer (well-known community)\n"
8667 "Do not export to next AS (well-known community)\n")
8668
8669ALIAS (show_bgp_community,
8670 show_bgp_community3_cmd,
8671 "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)",
8672 SHOW_STR
8673 BGP_STR
8674 "Display routes matching the communities\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n"
8679 "community number\n"
8680 "Do not send outside local AS (well-known community)\n"
8681 "Do not advertise to any peer (well-known community)\n"
8682 "Do not export to next AS (well-known community)\n"
8683 "community number\n"
8684 "Do not send outside local AS (well-known community)\n"
8685 "Do not advertise to any peer (well-known community)\n"
8686 "Do not export to next AS (well-known community)\n")
8687
8688ALIAS (show_bgp_community,
8689 show_bgp_ipv6_community3_cmd,
8690 "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)",
8691 SHOW_STR
8692 BGP_STR
8693 "Address family\n"
8694 "Display routes matching the communities\n"
8695 "community number\n"
8696 "Do not send outside local AS (well-known community)\n"
8697 "Do not advertise to any peer (well-known community)\n"
8698 "Do not export to next AS (well-known community)\n"
8699 "community number\n"
8700 "Do not send outside local AS (well-known community)\n"
8701 "Do not advertise to any peer (well-known community)\n"
8702 "Do not export to next AS (well-known community)\n"
8703 "community number\n"
8704 "Do not send outside local AS (well-known community)\n"
8705 "Do not advertise to any peer (well-known community)\n"
8706 "Do not export to next AS (well-known community)\n")
8707
8708ALIAS (show_bgp_community,
8709 show_bgp_community4_cmd,
8710 "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)",
8711 SHOW_STR
8712 BGP_STR
8713 "Display routes matching the communities\n"
8714 "community number\n"
8715 "Do not send outside local AS (well-known community)\n"
8716 "Do not advertise to any peer (well-known community)\n"
8717 "Do not export to next AS (well-known community)\n"
8718 "community number\n"
8719 "Do not send outside local AS (well-known community)\n"
8720 "Do not advertise to any peer (well-known community)\n"
8721 "Do not export to next AS (well-known community)\n"
8722 "community number\n"
8723 "Do not send outside local AS (well-known community)\n"
8724 "Do not advertise to any peer (well-known community)\n"
8725 "Do not export to next AS (well-known community)\n"
8726 "community number\n"
8727 "Do not send outside local AS (well-known community)\n"
8728 "Do not advertise to any peer (well-known community)\n"
8729 "Do not export to next AS (well-known community)\n")
8730
8731ALIAS (show_bgp_community,
8732 show_bgp_ipv6_community4_cmd,
8733 "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)",
8734 SHOW_STR
8735 BGP_STR
8736 "Address family\n"
8737 "Display routes matching the communities\n"
8738 "community number\n"
8739 "Do not send outside local AS (well-known community)\n"
8740 "Do not advertise to any peer (well-known community)\n"
8741 "Do not export to next AS (well-known community)\n"
8742 "community number\n"
8743 "Do not send outside local AS (well-known community)\n"
8744 "Do not advertise to any peer (well-known community)\n"
8745 "Do not export to next AS (well-known community)\n"
8746 "community number\n"
8747 "Do not send outside local AS (well-known community)\n"
8748 "Do not advertise to any peer (well-known community)\n"
8749 "Do not export to next AS (well-known community)\n"
8750 "community number\n"
8751 "Do not send outside local AS (well-known community)\n"
8752 "Do not advertise to any peer (well-known community)\n"
8753 "Do not export to next AS (well-known community)\n")
8754
8755/* old command */
8756DEFUN (show_ipv6_bgp_community,
8757 show_ipv6_bgp_community_cmd,
8758 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8759 SHOW_STR
8760 IPV6_STR
8761 BGP_STR
8762 "Display routes matching the communities\n"
8763 "community number\n"
8764 "Do not send outside local AS (well-known community)\n"
8765 "Do not advertise to any peer (well-known community)\n"
8766 "Do not export to next AS (well-known community)\n")
8767{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008768 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008769}
8770
8771/* old command */
8772ALIAS (show_ipv6_bgp_community,
8773 show_ipv6_bgp_community2_cmd,
8774 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8775 SHOW_STR
8776 IPV6_STR
8777 BGP_STR
8778 "Display routes matching the communities\n"
8779 "community number\n"
8780 "Do not send outside local AS (well-known community)\n"
8781 "Do not advertise to any peer (well-known community)\n"
8782 "Do not export to next AS (well-known community)\n"
8783 "community number\n"
8784 "Do not send outside local AS (well-known community)\n"
8785 "Do not advertise to any peer (well-known community)\n"
8786 "Do not export to next AS (well-known community)\n")
8787
8788/* old command */
8789ALIAS (show_ipv6_bgp_community,
8790 show_ipv6_bgp_community3_cmd,
8791 "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)",
8792 SHOW_STR
8793 IPV6_STR
8794 BGP_STR
8795 "Display routes matching the communities\n"
8796 "community number\n"
8797 "Do not send outside local AS (well-known community)\n"
8798 "Do not advertise to any peer (well-known community)\n"
8799 "Do not export to next AS (well-known community)\n"
8800 "community number\n"
8801 "Do not send outside local AS (well-known community)\n"
8802 "Do not advertise to any peer (well-known community)\n"
8803 "Do not export to next AS (well-known community)\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
8809/* old command */
8810ALIAS (show_ipv6_bgp_community,
8811 show_ipv6_bgp_community4_cmd,
8812 "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)",
8813 SHOW_STR
8814 IPV6_STR
8815 BGP_STR
8816 "Display routes matching the communities\n"
8817 "community number\n"
8818 "Do not send outside local AS (well-known community)\n"
8819 "Do not advertise to any peer (well-known community)\n"
8820 "Do not export to next AS (well-known community)\n"
8821 "community number\n"
8822 "Do not send outside local AS (well-known community)\n"
8823 "Do not advertise to any peer (well-known community)\n"
8824 "Do not export to next AS (well-known community)\n"
8825 "community number\n"
8826 "Do not send outside local AS (well-known community)\n"
8827 "Do not advertise to any peer (well-known community)\n"
8828 "Do not export to next AS (well-known community)\n"
8829 "community number\n"
8830 "Do not send outside local AS (well-known community)\n"
8831 "Do not advertise to any peer (well-known community)\n"
8832 "Do not export to next AS (well-known community)\n")
8833
8834DEFUN (show_bgp_community_exact,
8835 show_bgp_community_exact_cmd,
8836 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8837 SHOW_STR
8838 BGP_STR
8839 "Display routes matching the communities\n"
8840 "community number\n"
8841 "Do not send outside local AS (well-known community)\n"
8842 "Do not advertise to any peer (well-known community)\n"
8843 "Do not export to next AS (well-known community)\n"
8844 "Exact match of the communities")
8845{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008846 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008847}
8848
8849ALIAS (show_bgp_community_exact,
8850 show_bgp_ipv6_community_exact_cmd,
8851 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8852 SHOW_STR
8853 BGP_STR
8854 "Address family\n"
8855 "Display routes matching the communities\n"
8856 "community number\n"
8857 "Do not send outside local AS (well-known community)\n"
8858 "Do not advertise to any peer (well-known community)\n"
8859 "Do not export to next AS (well-known community)\n"
8860 "Exact match of the communities")
8861
8862ALIAS (show_bgp_community_exact,
8863 show_bgp_community2_exact_cmd,
8864 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8865 SHOW_STR
8866 BGP_STR
8867 "Display routes matching the communities\n"
8868 "community number\n"
8869 "Do not send outside local AS (well-known community)\n"
8870 "Do not advertise to any peer (well-known community)\n"
8871 "Do not export to next AS (well-known community)\n"
8872 "community number\n"
8873 "Do not send outside local AS (well-known community)\n"
8874 "Do not advertise to any peer (well-known community)\n"
8875 "Do not export to next AS (well-known community)\n"
8876 "Exact match of the communities")
8877
8878ALIAS (show_bgp_community_exact,
8879 show_bgp_ipv6_community2_exact_cmd,
8880 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8881 SHOW_STR
8882 BGP_STR
8883 "Address family\n"
8884 "Display routes matching the communities\n"
8885 "community number\n"
8886 "Do not send outside local AS (well-known community)\n"
8887 "Do not advertise to any peer (well-known community)\n"
8888 "Do not export to next AS (well-known community)\n"
8889 "community number\n"
8890 "Do not send outside local AS (well-known community)\n"
8891 "Do not advertise to any peer (well-known community)\n"
8892 "Do not export to next AS (well-known community)\n"
8893 "Exact match of the communities")
8894
8895ALIAS (show_bgp_community_exact,
8896 show_bgp_community3_exact_cmd,
8897 "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",
8898 SHOW_STR
8899 BGP_STR
8900 "Display routes matching the communities\n"
8901 "community number\n"
8902 "Do not send outside local AS (well-known community)\n"
8903 "Do not advertise to any peer (well-known community)\n"
8904 "Do not export to next AS (well-known community)\n"
8905 "community number\n"
8906 "Do not send outside local AS (well-known community)\n"
8907 "Do not advertise to any peer (well-known community)\n"
8908 "Do not export to next AS (well-known community)\n"
8909 "community number\n"
8910 "Do not send outside local AS (well-known community)\n"
8911 "Do not advertise to any peer (well-known community)\n"
8912 "Do not export to next AS (well-known community)\n"
8913 "Exact match of the communities")
8914
8915ALIAS (show_bgp_community_exact,
8916 show_bgp_ipv6_community3_exact_cmd,
8917 "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",
8918 SHOW_STR
8919 BGP_STR
8920 "Address family\n"
8921 "Display routes matching the communities\n"
8922 "community number\n"
8923 "Do not send outside local AS (well-known community)\n"
8924 "Do not advertise to any peer (well-known community)\n"
8925 "Do not export to next AS (well-known community)\n"
8926 "community number\n"
8927 "Do not send outside local AS (well-known community)\n"
8928 "Do not advertise to any peer (well-known community)\n"
8929 "Do not export to next AS (well-known community)\n"
8930 "community number\n"
8931 "Do not send outside local AS (well-known community)\n"
8932 "Do not advertise to any peer (well-known community)\n"
8933 "Do not export to next AS (well-known community)\n"
8934 "Exact match of the communities")
8935
8936ALIAS (show_bgp_community_exact,
8937 show_bgp_community4_exact_cmd,
8938 "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",
8939 SHOW_STR
8940 BGP_STR
8941 "Display routes matching the communities\n"
8942 "community number\n"
8943 "Do not send outside local AS (well-known community)\n"
8944 "Do not advertise to any peer (well-known community)\n"
8945 "Do not export to next AS (well-known community)\n"
8946 "community number\n"
8947 "Do not send outside local AS (well-known community)\n"
8948 "Do not advertise to any peer (well-known community)\n"
8949 "Do not export to next AS (well-known community)\n"
8950 "community number\n"
8951 "Do not send outside local AS (well-known community)\n"
8952 "Do not advertise to any peer (well-known community)\n"
8953 "Do not export to next AS (well-known community)\n"
8954 "community number\n"
8955 "Do not send outside local AS (well-known community)\n"
8956 "Do not advertise to any peer (well-known community)\n"
8957 "Do not export to next AS (well-known community)\n"
8958 "Exact match of the communities")
8959
8960ALIAS (show_bgp_community_exact,
8961 show_bgp_ipv6_community4_exact_cmd,
8962 "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",
8963 SHOW_STR
8964 BGP_STR
8965 "Address family\n"
8966 "Display routes matching the communities\n"
8967 "community number\n"
8968 "Do not send outside local AS (well-known community)\n"
8969 "Do not advertise to any peer (well-known community)\n"
8970 "Do not export to next AS (well-known community)\n"
8971 "community number\n"
8972 "Do not send outside local AS (well-known community)\n"
8973 "Do not advertise to any peer (well-known community)\n"
8974 "Do not export to next AS (well-known community)\n"
8975 "community number\n"
8976 "Do not send outside local AS (well-known community)\n"
8977 "Do not advertise to any peer (well-known community)\n"
8978 "Do not export to next AS (well-known community)\n"
8979 "community number\n"
8980 "Do not send outside local AS (well-known community)\n"
8981 "Do not advertise to any peer (well-known community)\n"
8982 "Do not export to next AS (well-known community)\n"
8983 "Exact match of the communities")
8984
8985/* old command */
8986DEFUN (show_ipv6_bgp_community_exact,
8987 show_ipv6_bgp_community_exact_cmd,
8988 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8989 SHOW_STR
8990 IPV6_STR
8991 BGP_STR
8992 "Display routes matching the communities\n"
8993 "community number\n"
8994 "Do not send outside local AS (well-known community)\n"
8995 "Do not advertise to any peer (well-known community)\n"
8996 "Do not export to next AS (well-known community)\n"
8997 "Exact match of the communities")
8998{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008999 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00009000}
9001
9002/* old command */
9003ALIAS (show_ipv6_bgp_community_exact,
9004 show_ipv6_bgp_community2_exact_cmd,
9005 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9006 SHOW_STR
9007 IPV6_STR
9008 BGP_STR
9009 "Display routes matching the communities\n"
9010 "community number\n"
9011 "Do not send outside local AS (well-known community)\n"
9012 "Do not advertise to any peer (well-known community)\n"
9013 "Do not export to next AS (well-known community)\n"
9014 "community number\n"
9015 "Do not send outside local AS (well-known community)\n"
9016 "Do not advertise to any peer (well-known community)\n"
9017 "Do not export to next AS (well-known community)\n"
9018 "Exact match of the communities")
9019
9020/* old command */
9021ALIAS (show_ipv6_bgp_community_exact,
9022 show_ipv6_bgp_community3_exact_cmd,
9023 "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",
9024 SHOW_STR
9025 IPV6_STR
9026 BGP_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 "Exact match of the communities")
9041
9042/* old command */
9043ALIAS (show_ipv6_bgp_community_exact,
9044 show_ipv6_bgp_community4_exact_cmd,
9045 "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",
9046 SHOW_STR
9047 IPV6_STR
9048 BGP_STR
9049 "Display routes matching the communities\n"
9050 "community number\n"
9051 "Do not send outside local AS (well-known community)\n"
9052 "Do not advertise to any peer (well-known community)\n"
9053 "Do not export to next AS (well-known community)\n"
9054 "community number\n"
9055 "Do not send outside local AS (well-known community)\n"
9056 "Do not advertise to any peer (well-known community)\n"
9057 "Do not export to next AS (well-known community)\n"
9058 "community number\n"
9059 "Do not send outside local AS (well-known community)\n"
9060 "Do not advertise to any peer (well-known community)\n"
9061 "Do not export to next AS (well-known community)\n"
9062 "community number\n"
9063 "Do not send outside local AS (well-known community)\n"
9064 "Do not advertise to any peer (well-known community)\n"
9065 "Do not export to next AS (well-known community)\n"
9066 "Exact match of the communities")
9067
9068/* old command */
9069DEFUN (show_ipv6_mbgp_community,
9070 show_ipv6_mbgp_community_cmd,
9071 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
9072 SHOW_STR
9073 IPV6_STR
9074 MBGP_STR
9075 "Display routes matching the communities\n"
9076 "community number\n"
9077 "Do not send outside local AS (well-known community)\n"
9078 "Do not advertise to any peer (well-known community)\n"
9079 "Do not export to next AS (well-known community)\n")
9080{
Michael Lambert95cbbd22010-07-23 14:43:04 -04009081 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00009082}
9083
9084/* old command */
9085ALIAS (show_ipv6_mbgp_community,
9086 show_ipv6_mbgp_community2_cmd,
9087 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
9088 SHOW_STR
9089 IPV6_STR
9090 MBGP_STR
9091 "Display routes matching the communities\n"
9092 "community number\n"
9093 "Do not send outside local AS (well-known community)\n"
9094 "Do not advertise to any peer (well-known community)\n"
9095 "Do not export to next AS (well-known community)\n"
9096 "community number\n"
9097 "Do not send outside local AS (well-known community)\n"
9098 "Do not advertise to any peer (well-known community)\n"
9099 "Do not export to next AS (well-known community)\n")
9100
9101/* old command */
9102ALIAS (show_ipv6_mbgp_community,
9103 show_ipv6_mbgp_community3_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)",
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
9122/* old command */
9123ALIAS (show_ipv6_mbgp_community,
9124 show_ipv6_mbgp_community4_cmd,
9125 "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)",
9126 SHOW_STR
9127 IPV6_STR
9128 MBGP_STR
9129 "Display routes matching the communities\n"
9130 "community number\n"
9131 "Do not send outside local AS (well-known community)\n"
9132 "Do not advertise to any peer (well-known community)\n"
9133 "Do not export to next AS (well-known community)\n"
9134 "community number\n"
9135 "Do not send outside local AS (well-known community)\n"
9136 "Do not advertise to any peer (well-known community)\n"
9137 "Do not export to next AS (well-known community)\n"
9138 "community number\n"
9139 "Do not send outside local AS (well-known community)\n"
9140 "Do not advertise to any peer (well-known community)\n"
9141 "Do not export to next AS (well-known community)\n"
9142 "community number\n"
9143 "Do not send outside local AS (well-known community)\n"
9144 "Do not advertise to any peer (well-known community)\n"
9145 "Do not export to next AS (well-known community)\n")
9146
9147/* old command */
9148DEFUN (show_ipv6_mbgp_community_exact,
9149 show_ipv6_mbgp_community_exact_cmd,
9150 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9151 SHOW_STR
9152 IPV6_STR
9153 MBGP_STR
9154 "Display routes matching the communities\n"
9155 "community number\n"
9156 "Do not send outside local AS (well-known community)\n"
9157 "Do not advertise to any peer (well-known community)\n"
9158 "Do not export to next AS (well-known community)\n"
9159 "Exact match of the communities")
9160{
Michael Lambert95cbbd22010-07-23 14:43:04 -04009161 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00009162}
9163
9164/* old command */
9165ALIAS (show_ipv6_mbgp_community_exact,
9166 show_ipv6_mbgp_community2_exact_cmd,
9167 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9168 SHOW_STR
9169 IPV6_STR
9170 MBGP_STR
9171 "Display routes matching the communities\n"
9172 "community number\n"
9173 "Do not send outside local AS (well-known community)\n"
9174 "Do not advertise to any peer (well-known community)\n"
9175 "Do not export to next AS (well-known community)\n"
9176 "community number\n"
9177 "Do not send outside local AS (well-known community)\n"
9178 "Do not advertise to any peer (well-known community)\n"
9179 "Do not export to next AS (well-known community)\n"
9180 "Exact match of the communities")
9181
9182/* old command */
9183ALIAS (show_ipv6_mbgp_community_exact,
9184 show_ipv6_mbgp_community3_exact_cmd,
9185 "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",
9186 SHOW_STR
9187 IPV6_STR
9188 MBGP_STR
9189 "Display routes matching the communities\n"
9190 "community number\n"
9191 "Do not send outside local AS (well-known community)\n"
9192 "Do not advertise to any peer (well-known community)\n"
9193 "Do not export to next AS (well-known community)\n"
9194 "community number\n"
9195 "Do not send outside local AS (well-known community)\n"
9196 "Do not advertise to any peer (well-known community)\n"
9197 "Do not export to next AS (well-known community)\n"
9198 "community number\n"
9199 "Do not send outside local AS (well-known community)\n"
9200 "Do not advertise to any peer (well-known community)\n"
9201 "Do not export to next AS (well-known community)\n"
9202 "Exact match of the communities")
9203
9204/* old command */
9205ALIAS (show_ipv6_mbgp_community_exact,
9206 show_ipv6_mbgp_community4_exact_cmd,
9207 "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",
9208 SHOW_STR
9209 IPV6_STR
9210 MBGP_STR
9211 "Display routes matching the communities\n"
9212 "community number\n"
9213 "Do not send outside local AS (well-known community)\n"
9214 "Do not advertise to any peer (well-known community)\n"
9215 "Do not export to next AS (well-known community)\n"
9216 "community number\n"
9217 "Do not send outside local AS (well-known community)\n"
9218 "Do not advertise to any peer (well-known community)\n"
9219 "Do not export to next AS (well-known community)\n"
9220 "community number\n"
9221 "Do not send outside local AS (well-known community)\n"
9222 "Do not advertise to any peer (well-known community)\n"
9223 "Do not export to next AS (well-known community)\n"
9224 "community number\n"
9225 "Do not send outside local AS (well-known community)\n"
9226 "Do not advertise to any peer (well-known community)\n"
9227 "Do not export to next AS (well-known community)\n"
9228 "Exact match of the communities")
9229#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009230
paul94f2b392005-06-28 12:44:16 +00009231static int
paulfd79ac92004-10-13 05:06:08 +00009232bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04009233 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009234{
9235 struct community_list *list;
9236
hassofee6e4e2005-02-02 16:29:31 +00009237 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00009238 if (list == NULL)
9239 {
9240 vty_out (vty, "%% %s is not a valid community-list name%s", com,
9241 VTY_NEWLINE);
9242 return CMD_WARNING;
9243 }
9244
ajs5a646652004-11-05 01:25:55 +00009245 return bgp_show (vty, NULL, afi, safi,
9246 (exact ? bgp_show_type_community_list_exact :
9247 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00009248}
9249
9250DEFUN (show_ip_bgp_community_list,
9251 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009252 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009253 SHOW_STR
9254 IP_STR
9255 BGP_STR
9256 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009257 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009258 "community-list name\n")
9259{
9260 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9261}
9262
9263DEFUN (show_ip_bgp_ipv4_community_list,
9264 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009265 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009266 SHOW_STR
9267 IP_STR
9268 BGP_STR
9269 "Address family\n"
9270 "Address Family modifier\n"
9271 "Address Family modifier\n"
9272 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009273 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009274 "community-list name\n")
9275{
9276 if (strncmp (argv[0], "m", 1) == 0)
9277 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9278
9279 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9280}
9281
9282DEFUN (show_ip_bgp_community_list_exact,
9283 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009284 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009285 SHOW_STR
9286 IP_STR
9287 BGP_STR
9288 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009289 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009290 "community-list name\n"
9291 "Exact match of the communities\n")
9292{
9293 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9294}
9295
9296DEFUN (show_ip_bgp_ipv4_community_list_exact,
9297 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009298 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009299 SHOW_STR
9300 IP_STR
9301 BGP_STR
9302 "Address family\n"
9303 "Address Family modifier\n"
9304 "Address Family modifier\n"
9305 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009306 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009307 "community-list name\n"
9308 "Exact match of the communities\n")
9309{
9310 if (strncmp (argv[0], "m", 1) == 0)
9311 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9312
9313 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9314}
9315
9316#ifdef HAVE_IPV6
9317DEFUN (show_bgp_community_list,
9318 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009319 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009320 SHOW_STR
9321 BGP_STR
9322 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009323 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009324 "community-list name\n")
9325{
9326 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9327}
9328
9329ALIAS (show_bgp_community_list,
9330 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009331 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009332 SHOW_STR
9333 BGP_STR
9334 "Address family\n"
9335 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009336 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009337 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009338
9339/* old command */
9340DEFUN (show_ipv6_bgp_community_list,
9341 show_ipv6_bgp_community_list_cmd,
9342 "show ipv6 bgp community-list WORD",
9343 SHOW_STR
9344 IPV6_STR
9345 BGP_STR
9346 "Display routes matching the community-list\n"
9347 "community-list name\n")
9348{
9349 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9350}
9351
9352/* old command */
9353DEFUN (show_ipv6_mbgp_community_list,
9354 show_ipv6_mbgp_community_list_cmd,
9355 "show ipv6 mbgp community-list WORD",
9356 SHOW_STR
9357 IPV6_STR
9358 MBGP_STR
9359 "Display routes matching the community-list\n"
9360 "community-list name\n")
9361{
9362 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9363}
9364
9365DEFUN (show_bgp_community_list_exact,
9366 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009367 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009368 SHOW_STR
9369 BGP_STR
9370 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009371 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009372 "community-list name\n"
9373 "Exact match of the communities\n")
9374{
9375 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9376}
9377
9378ALIAS (show_bgp_community_list_exact,
9379 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009380 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009381 SHOW_STR
9382 BGP_STR
9383 "Address family\n"
9384 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009385 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009386 "community-list name\n"
9387 "Exact match of the communities\n")
9388
9389/* old command */
9390DEFUN (show_ipv6_bgp_community_list_exact,
9391 show_ipv6_bgp_community_list_exact_cmd,
9392 "show ipv6 bgp community-list WORD exact-match",
9393 SHOW_STR
9394 IPV6_STR
9395 BGP_STR
9396 "Display routes matching the community-list\n"
9397 "community-list name\n"
9398 "Exact match of the communities\n")
9399{
9400 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9401}
9402
9403/* old command */
9404DEFUN (show_ipv6_mbgp_community_list_exact,
9405 show_ipv6_mbgp_community_list_exact_cmd,
9406 "show ipv6 mbgp community-list WORD exact-match",
9407 SHOW_STR
9408 IPV6_STR
9409 MBGP_STR
9410 "Display routes matching the community-list\n"
9411 "community-list name\n"
9412 "Exact match of the communities\n")
9413{
9414 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9415}
9416#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009417
paul94f2b392005-06-28 12:44:16 +00009418static int
paulfd79ac92004-10-13 05:06:08 +00009419bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009420 safi_t safi, enum bgp_show_type type)
9421{
9422 int ret;
9423 struct prefix *p;
9424
9425 p = prefix_new();
9426
9427 ret = str2prefix (prefix, p);
9428 if (! ret)
9429 {
9430 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9431 return CMD_WARNING;
9432 }
9433
ajs5a646652004-11-05 01:25:55 +00009434 ret = bgp_show (vty, NULL, afi, safi, type, p);
9435 prefix_free(p);
9436 return ret;
paul718e3742002-12-13 20:15:29 +00009437}
9438
9439DEFUN (show_ip_bgp_prefix_longer,
9440 show_ip_bgp_prefix_longer_cmd,
9441 "show ip bgp A.B.C.D/M longer-prefixes",
9442 SHOW_STR
9443 IP_STR
9444 BGP_STR
9445 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9446 "Display route and more specific routes\n")
9447{
9448 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9449 bgp_show_type_prefix_longer);
9450}
9451
9452DEFUN (show_ip_bgp_flap_prefix_longer,
9453 show_ip_bgp_flap_prefix_longer_cmd,
9454 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9455 SHOW_STR
9456 IP_STR
9457 BGP_STR
9458 "Display flap statistics of routes\n"
9459 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9460 "Display route and more specific routes\n")
9461{
9462 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9463 bgp_show_type_flap_prefix_longer);
9464}
9465
Balaji3921cc52015-05-16 23:12:17 +05309466ALIAS (show_ip_bgp_flap_prefix_longer,
9467 show_ip_bgp_damp_flap_prefix_longer_cmd,
9468 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
9469 SHOW_STR
9470 IP_STR
9471 BGP_STR
9472 "Display detailed information about dampening\n"
9473 "Display flap statistics of routes\n"
9474 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9475 "Display route and more specific routes\n")
9476
paul718e3742002-12-13 20:15:29 +00009477DEFUN (show_ip_bgp_ipv4_prefix_longer,
9478 show_ip_bgp_ipv4_prefix_longer_cmd,
9479 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9480 SHOW_STR
9481 IP_STR
9482 BGP_STR
9483 "Address family\n"
9484 "Address Family modifier\n"
9485 "Address Family modifier\n"
9486 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9487 "Display route and more specific routes\n")
9488{
9489 if (strncmp (argv[0], "m", 1) == 0)
9490 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9491 bgp_show_type_prefix_longer);
9492
9493 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9494 bgp_show_type_prefix_longer);
9495}
9496
9497DEFUN (show_ip_bgp_flap_address,
9498 show_ip_bgp_flap_address_cmd,
9499 "show ip bgp flap-statistics A.B.C.D",
9500 SHOW_STR
9501 IP_STR
9502 BGP_STR
9503 "Display flap statistics of routes\n"
9504 "Network in the BGP routing table to display\n")
9505{
9506 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9507 bgp_show_type_flap_address);
9508}
9509
Balaji3921cc52015-05-16 23:12:17 +05309510ALIAS (show_ip_bgp_flap_address,
9511 show_ip_bgp_damp_flap_address_cmd,
9512 "show ip bgp dampening flap-statistics A.B.C.D",
9513 SHOW_STR
9514 IP_STR
9515 BGP_STR
9516 "Display detailed information about dampening\n"
9517 "Display flap statistics of routes\n"
9518 "Network in the BGP routing table to display\n")
9519
paul718e3742002-12-13 20:15:29 +00009520DEFUN (show_ip_bgp_flap_prefix,
9521 show_ip_bgp_flap_prefix_cmd,
9522 "show ip bgp flap-statistics A.B.C.D/M",
9523 SHOW_STR
9524 IP_STR
9525 BGP_STR
9526 "Display flap statistics of routes\n"
9527 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9528{
9529 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9530 bgp_show_type_flap_prefix);
9531}
Balaji3921cc52015-05-16 23:12:17 +05309532
9533ALIAS (show_ip_bgp_flap_prefix,
9534 show_ip_bgp_damp_flap_prefix_cmd,
9535 "show ip bgp dampening flap-statistics A.B.C.D/M",
9536 SHOW_STR
9537 IP_STR
9538 BGP_STR
9539 "Display detailed information about dampening\n"
9540 "Display flap statistics of routes\n"
9541 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9542
paul718e3742002-12-13 20:15:29 +00009543#ifdef HAVE_IPV6
9544DEFUN (show_bgp_prefix_longer,
9545 show_bgp_prefix_longer_cmd,
9546 "show bgp X:X::X:X/M longer-prefixes",
9547 SHOW_STR
9548 BGP_STR
9549 "IPv6 prefix <network>/<length>\n"
9550 "Display route and more specific routes\n")
9551{
9552 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9553 bgp_show_type_prefix_longer);
9554}
9555
9556ALIAS (show_bgp_prefix_longer,
9557 show_bgp_ipv6_prefix_longer_cmd,
9558 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9559 SHOW_STR
9560 BGP_STR
9561 "Address family\n"
9562 "IPv6 prefix <network>/<length>\n"
9563 "Display route and more specific routes\n")
9564
9565/* old command */
9566DEFUN (show_ipv6_bgp_prefix_longer,
9567 show_ipv6_bgp_prefix_longer_cmd,
9568 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9569 SHOW_STR
9570 IPV6_STR
9571 BGP_STR
9572 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9573 "Display route and more specific routes\n")
9574{
9575 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9576 bgp_show_type_prefix_longer);
9577}
9578
9579/* old command */
9580DEFUN (show_ipv6_mbgp_prefix_longer,
9581 show_ipv6_mbgp_prefix_longer_cmd,
9582 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9583 SHOW_STR
9584 IPV6_STR
9585 MBGP_STR
9586 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9587 "Display route and more specific routes\n")
9588{
9589 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9590 bgp_show_type_prefix_longer);
9591}
9592#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009593
paul94f2b392005-06-28 12:44:16 +00009594static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009595peer_lookup_in_view (struct vty *vty, const char *view_name,
9596 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009597{
9598 int ret;
9599 struct bgp *bgp;
9600 struct peer *peer;
9601 union sockunion su;
9602
9603 /* BGP structure lookup. */
9604 if (view_name)
9605 {
9606 bgp = bgp_lookup_by_name (view_name);
9607 if (! bgp)
9608 {
9609 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9610 return NULL;
9611 }
9612 }
paul5228ad22004-06-04 17:58:18 +00009613 else
paulbb46e942003-10-24 19:02:03 +00009614 {
9615 bgp = bgp_get_default ();
9616 if (! bgp)
9617 {
9618 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9619 return NULL;
9620 }
9621 }
9622
9623 /* Get peer sockunion. */
9624 ret = str2sockunion (ip_str, &su);
9625 if (ret < 0)
9626 {
9627 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9628 return NULL;
9629 }
9630
9631 /* Peer structure lookup. */
9632 peer = peer_lookup (bgp, &su);
9633 if (! peer)
9634 {
9635 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9636 return NULL;
9637 }
9638
9639 return peer;
9640}
David Lamparter6b0655a2014-06-04 06:53:35 +02009641
Paul Jakma2815e612006-09-14 02:56:07 +00009642enum bgp_stats
9643{
9644 BGP_STATS_MAXBITLEN = 0,
9645 BGP_STATS_RIB,
9646 BGP_STATS_PREFIXES,
9647 BGP_STATS_TOTPLEN,
9648 BGP_STATS_UNAGGREGATEABLE,
9649 BGP_STATS_MAX_AGGREGATEABLE,
9650 BGP_STATS_AGGREGATES,
9651 BGP_STATS_SPACE,
9652 BGP_STATS_ASPATH_COUNT,
9653 BGP_STATS_ASPATH_MAXHOPS,
9654 BGP_STATS_ASPATH_TOTHOPS,
9655 BGP_STATS_ASPATH_MAXSIZE,
9656 BGP_STATS_ASPATH_TOTSIZE,
9657 BGP_STATS_ASN_HIGHEST,
9658 BGP_STATS_MAX,
9659};
paulbb46e942003-10-24 19:02:03 +00009660
Paul Jakma2815e612006-09-14 02:56:07 +00009661static const char *table_stats_strs[] =
9662{
9663 [BGP_STATS_PREFIXES] = "Total Prefixes",
9664 [BGP_STATS_TOTPLEN] = "Average prefix length",
9665 [BGP_STATS_RIB] = "Total Advertisements",
9666 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9667 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9668 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9669 [BGP_STATS_SPACE] = "Address space advertised",
9670 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9671 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9672 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9673 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9674 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9675 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9676 [BGP_STATS_MAX] = NULL,
9677};
9678
9679struct bgp_table_stats
9680{
9681 struct bgp_table *table;
9682 unsigned long long counts[BGP_STATS_MAX];
9683};
9684
9685#if 0
9686#define TALLY_SIGFIG 100000
9687static unsigned long
9688ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9689{
9690 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9691 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9692 unsigned long ret = newtot / count;
9693
9694 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9695 return ret + 1;
9696 else
9697 return ret;
9698}
9699#endif
9700
9701static int
9702bgp_table_stats_walker (struct thread *t)
9703{
9704 struct bgp_node *rn;
9705 struct bgp_node *top;
9706 struct bgp_table_stats *ts = THREAD_ARG (t);
9707 unsigned int space = 0;
9708
Paul Jakma53d9f672006-10-15 23:41:16 +00009709 if (!(top = bgp_table_top (ts->table)))
9710 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009711
9712 switch (top->p.family)
9713 {
9714 case AF_INET:
9715 space = IPV4_MAX_BITLEN;
9716 break;
9717 case AF_INET6:
9718 space = IPV6_MAX_BITLEN;
9719 break;
9720 }
9721
9722 ts->counts[BGP_STATS_MAXBITLEN] = space;
9723
9724 for (rn = top; rn; rn = bgp_route_next (rn))
9725 {
9726 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009727 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009728 unsigned int rinum = 0;
9729
9730 if (rn == top)
9731 continue;
9732
9733 if (!rn->info)
9734 continue;
9735
9736 ts->counts[BGP_STATS_PREFIXES]++;
9737 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9738
9739#if 0
9740 ts->counts[BGP_STATS_AVGPLEN]
9741 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9742 ts->counts[BGP_STATS_AVGPLEN],
9743 rn->p.prefixlen);
9744#endif
9745
9746 /* check if the prefix is included by any other announcements */
9747 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009748 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009749
9750 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009751 {
9752 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9753 /* announced address space */
9754 if (space)
9755 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9756 }
Paul Jakma2815e612006-09-14 02:56:07 +00009757 else if (prn->info)
9758 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9759
Paul Jakma2815e612006-09-14 02:56:07 +00009760 for (ri = rn->info; ri; ri = ri->next)
9761 {
9762 rinum++;
9763 ts->counts[BGP_STATS_RIB]++;
9764
9765 if (ri->attr &&
9766 (CHECK_FLAG (ri->attr->flag,
9767 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9768 ts->counts[BGP_STATS_AGGREGATES]++;
9769
9770 /* as-path stats */
9771 if (ri->attr && ri->attr->aspath)
9772 {
9773 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9774 unsigned int size = aspath_size (ri->attr->aspath);
9775 as_t highest = aspath_highest (ri->attr->aspath);
9776
9777 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9778
9779 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9780 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9781
9782 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9783 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9784
9785 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9786 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9787#if 0
9788 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9789 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9790 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9791 hops);
9792 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9793 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9794 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9795 size);
9796#endif
9797 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9798 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9799 }
9800 }
9801 }
9802 return 0;
9803}
9804
9805static int
9806bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9807{
9808 struct bgp_table_stats ts;
9809 unsigned int i;
9810
9811 if (!bgp->rib[afi][safi])
9812 {
9813 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9814 return CMD_WARNING;
9815 }
9816
9817 memset (&ts, 0, sizeof (ts));
9818 ts.table = bgp->rib[afi][safi];
9819 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9820
9821 vty_out (vty, "BGP %s RIB statistics%s%s",
9822 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9823
9824 for (i = 0; i < BGP_STATS_MAX; i++)
9825 {
9826 if (!table_stats_strs[i])
9827 continue;
9828
9829 switch (i)
9830 {
9831#if 0
9832 case BGP_STATS_ASPATH_AVGHOPS:
9833 case BGP_STATS_ASPATH_AVGSIZE:
9834 case BGP_STATS_AVGPLEN:
9835 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9836 vty_out (vty, "%12.2f",
9837 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9838 break;
9839#endif
9840 case BGP_STATS_ASPATH_TOTHOPS:
9841 case BGP_STATS_ASPATH_TOTSIZE:
9842 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9843 vty_out (vty, "%12.2f",
9844 ts.counts[i] ?
9845 (float)ts.counts[i] /
9846 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9847 : 0);
9848 break;
9849 case BGP_STATS_TOTPLEN:
9850 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9851 vty_out (vty, "%12.2f",
9852 ts.counts[i] ?
9853 (float)ts.counts[i] /
9854 (float)ts.counts[BGP_STATS_PREFIXES]
9855 : 0);
9856 break;
9857 case BGP_STATS_SPACE:
9858 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9859 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9860 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9861 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009862 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009863 vty_out (vty, "%12.2f%s",
9864 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009865 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009866 VTY_NEWLINE);
9867 vty_out (vty, "%30s: ", "/8 equivalent ");
9868 vty_out (vty, "%12.2f%s",
9869 (float)ts.counts[BGP_STATS_SPACE] /
9870 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9871 VTY_NEWLINE);
9872 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9873 break;
9874 vty_out (vty, "%30s: ", "/24 equivalent ");
9875 vty_out (vty, "%12.2f",
9876 (float)ts.counts[BGP_STATS_SPACE] /
9877 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9878 break;
9879 default:
9880 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9881 vty_out (vty, "%12llu", ts.counts[i]);
9882 }
9883
9884 vty_out (vty, "%s", VTY_NEWLINE);
9885 }
9886 return CMD_SUCCESS;
9887}
9888
9889static int
9890bgp_table_stats_vty (struct vty *vty, const char *name,
9891 const char *afi_str, const char *safi_str)
9892{
9893 struct bgp *bgp;
9894 afi_t afi;
9895 safi_t safi;
9896
9897 if (name)
9898 bgp = bgp_lookup_by_name (name);
9899 else
9900 bgp = bgp_get_default ();
9901
9902 if (!bgp)
9903 {
9904 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9905 return CMD_WARNING;
9906 }
9907 if (strncmp (afi_str, "ipv", 3) == 0)
9908 {
9909 if (strncmp (afi_str, "ipv4", 4) == 0)
9910 afi = AFI_IP;
9911 else if (strncmp (afi_str, "ipv6", 4) == 0)
9912 afi = AFI_IP6;
9913 else
9914 {
9915 vty_out (vty, "%% Invalid address family %s%s",
9916 afi_str, VTY_NEWLINE);
9917 return CMD_WARNING;
9918 }
Lou Berger298cc2f2016-01-12 13:42:02 -05009919 switch (safi_str[0]) {
9920 case 'm':
9921 safi = SAFI_MULTICAST;
9922 break;
9923 case 'u':
9924 safi = SAFI_UNICAST;
9925 break;
9926 case 'v':
9927 safi = SAFI_MPLS_LABELED_VPN;
9928 break;
9929 case 'e':
9930 safi = SAFI_ENCAP;
9931 break;
9932 default:
9933 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +00009934 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -05009935 return CMD_WARNING;
9936 }
Paul Jakma2815e612006-09-14 02:56:07 +00009937 }
9938 else
9939 {
Lou Berger298cc2f2016-01-12 13:42:02 -05009940 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +00009941 afi_str, VTY_NEWLINE);
9942 return CMD_WARNING;
9943 }
9944
Paul Jakma2815e612006-09-14 02:56:07 +00009945 return bgp_table_stats (vty, bgp, afi, safi);
9946}
9947
9948DEFUN (show_bgp_statistics,
9949 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -05009950 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009951 SHOW_STR
9952 BGP_STR
9953 "Address family\n"
9954 "Address family\n"
9955 "Address Family modifier\n"
9956 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -05009957 "Address Family modifier\n"
9958 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +00009959 "BGP RIB advertisement statistics\n")
9960{
9961 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9962}
9963
Paul Jakma2815e612006-09-14 02:56:07 +00009964DEFUN (show_bgp_statistics_view,
9965 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -05009966 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009967 SHOW_STR
9968 BGP_STR
9969 "BGP view\n"
9970 "Address family\n"
9971 "Address family\n"
9972 "Address Family modifier\n"
9973 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -05009974 "Address Family modifier\n"
9975 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +00009976 "BGP RIB advertisement statistics\n")
9977{
9978 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9979}
9980
Lou Berger298cc2f2016-01-12 13:42:02 -05009981#if 0 /* added as options to above command */
Paul Jakma2815e612006-09-14 02:56:07 +00009982ALIAS (show_bgp_statistics_view,
Lou Berger298cc2f2016-01-12 13:42:02 -05009983 show_bgp_statistics_view_encap_cmd,
9984 "show bgp view WORD (ipv4) (encap) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009985 SHOW_STR
9986 BGP_STR
9987 "BGP view\n"
9988 "Address family\n"
9989 "Address Family modifier\n"
9990 "BGP RIB advertisement statistics\n")
Lou Berger298cc2f2016-01-12 13:42:02 -05009991#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02009992
Paul Jakmaff7924f2006-09-04 01:10:36 +00009993enum bgp_pcounts
9994{
9995 PCOUNT_ADJ_IN = 0,
9996 PCOUNT_DAMPED,
9997 PCOUNT_REMOVED,
9998 PCOUNT_HISTORY,
9999 PCOUNT_STALE,
10000 PCOUNT_VALID,
10001 PCOUNT_ALL,
10002 PCOUNT_COUNTED,
10003 PCOUNT_PFCNT, /* the figure we display to users */
10004 PCOUNT_MAX,
10005};
10006
10007static const char *pcount_strs[] =
10008{
10009 [PCOUNT_ADJ_IN] = "Adj-in",
10010 [PCOUNT_DAMPED] = "Damped",
10011 [PCOUNT_REMOVED] = "Removed",
10012 [PCOUNT_HISTORY] = "History",
10013 [PCOUNT_STALE] = "Stale",
10014 [PCOUNT_VALID] = "Valid",
10015 [PCOUNT_ALL] = "All RIB",
10016 [PCOUNT_COUNTED] = "PfxCt counted",
10017 [PCOUNT_PFCNT] = "Useable",
10018 [PCOUNT_MAX] = NULL,
10019};
10020
Paul Jakma2815e612006-09-14 02:56:07 +000010021struct peer_pcounts
10022{
10023 unsigned int count[PCOUNT_MAX];
10024 const struct peer *peer;
10025 const struct bgp_table *table;
10026};
10027
Paul Jakmaff7924f2006-09-04 01:10:36 +000010028static int
Paul Jakma2815e612006-09-14 02:56:07 +000010029bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +000010030{
10031 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +000010032 struct peer_pcounts *pc = THREAD_ARG (t);
10033 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010034
Paul Jakma2815e612006-09-14 02:56:07 +000010035 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +000010036 {
10037 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +000010038 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010039
10040 for (ain = rn->adj_in; ain; ain = ain->next)
10041 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +000010042 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010043
Paul Jakmaff7924f2006-09-04 01:10:36 +000010044 for (ri = rn->info; ri; ri = ri->next)
10045 {
10046 char buf[SU_ADDRSTRLEN];
10047
10048 if (ri->peer != peer)
10049 continue;
10050
Paul Jakma2815e612006-09-14 02:56:07 +000010051 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010052
10053 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +000010054 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010055 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +000010056 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010057 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +000010058 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010059 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +000010060 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010061 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +000010062 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000010063 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +000010064 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +000010065
10066 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
10067 {
Paul Jakma2815e612006-09-14 02:56:07 +000010068 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +000010069 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000010070 plog_warn (peer->log,
10071 "%s [pcount] %s/%d is counted but flags 0x%x",
10072 peer->host,
10073 inet_ntop(rn->p.family, &rn->p.u.prefix,
10074 buf, SU_ADDRSTRLEN),
10075 rn->p.prefixlen,
10076 ri->flags);
10077 }
10078 else
10079 {
Paul Jakma1a392d42006-09-07 00:24:49 +000010080 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +000010081 plog_warn (peer->log,
10082 "%s [pcount] %s/%d not counted but flags 0x%x",
10083 peer->host,
10084 inet_ntop(rn->p.family, &rn->p.u.prefix,
10085 buf, SU_ADDRSTRLEN),
10086 rn->p.prefixlen,
10087 ri->flags);
10088 }
10089 }
10090 }
Paul Jakma2815e612006-09-14 02:56:07 +000010091 return 0;
10092}
Paul Jakmaff7924f2006-09-04 01:10:36 +000010093
Paul Jakma2815e612006-09-14 02:56:07 +000010094static int
10095bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
10096{
10097 struct peer_pcounts pcounts = { .peer = peer };
10098 unsigned int i;
10099
10100 if (!peer || !peer->bgp || !peer->afc[afi][safi]
10101 || !peer->bgp->rib[afi][safi])
10102 {
10103 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10104 return CMD_WARNING;
10105 }
10106
10107 memset (&pcounts, 0, sizeof(pcounts));
10108 pcounts.peer = peer;
10109 pcounts.table = peer->bgp->rib[afi][safi];
10110
10111 /* in-place call via thread subsystem so as to record execution time
10112 * stats for the thread-walk (i.e. ensure this can't be blamed on
10113 * on just vty_read()).
10114 */
10115 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10116
Paul Jakmaff7924f2006-09-04 01:10:36 +000010117 vty_out (vty, "Prefix counts for %s, %s%s",
10118 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10119 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10120 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10121 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10122
10123 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000010124 vty_out (vty, "%20s: %-10d%s",
10125 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010126
Paul Jakma2815e612006-09-14 02:56:07 +000010127 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000010128 {
10129 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10130 peer->host, VTY_NEWLINE);
10131 vty_out (vty, "Please report this bug, with the above command output%s",
10132 VTY_NEWLINE);
10133 }
10134
10135 return CMD_SUCCESS;
10136}
10137
10138DEFUN (show_ip_bgp_neighbor_prefix_counts,
10139 show_ip_bgp_neighbor_prefix_counts_cmd,
10140 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10141 SHOW_STR
10142 IP_STR
10143 BGP_STR
10144 "Detailed information on TCP and BGP neighbor connections\n"
10145 "Neighbor to display information about\n"
10146 "Neighbor to display information about\n"
10147 "Display detailed prefix count information\n")
10148{
10149 struct peer *peer;
10150
10151 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10152 if (! peer)
10153 return CMD_WARNING;
10154
10155 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10156}
10157
10158DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
10159 show_bgp_ipv6_neighbor_prefix_counts_cmd,
10160 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10161 SHOW_STR
10162 BGP_STR
10163 "Address family\n"
10164 "Detailed information on TCP and BGP neighbor connections\n"
10165 "Neighbor to display information about\n"
10166 "Neighbor to display information about\n"
10167 "Display detailed prefix count information\n")
10168{
10169 struct peer *peer;
10170
10171 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10172 if (! peer)
10173 return CMD_WARNING;
10174
10175 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10176}
10177
10178DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
10179 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
10180 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10181 SHOW_STR
10182 IP_STR
10183 BGP_STR
10184 "Address family\n"
10185 "Address Family modifier\n"
10186 "Address Family modifier\n"
10187 "Detailed information on TCP and BGP neighbor connections\n"
10188 "Neighbor to display information about\n"
10189 "Neighbor to display information about\n"
10190 "Display detailed prefix count information\n")
10191{
10192 struct peer *peer;
10193
10194 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10195 if (! peer)
10196 return CMD_WARNING;
10197
10198 if (strncmp (argv[0], "m", 1) == 0)
10199 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
10200
10201 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10202}
10203
10204DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
10205 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
10206 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10207 SHOW_STR
10208 IP_STR
10209 BGP_STR
10210 "Address family\n"
10211 "Address Family modifier\n"
10212 "Address Family modifier\n"
10213 "Detailed information on TCP and BGP neighbor connections\n"
10214 "Neighbor to display information about\n"
10215 "Neighbor to display information about\n"
10216 "Display detailed prefix count information\n")
10217{
10218 struct peer *peer;
10219
10220 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10221 if (! peer)
10222 return CMD_WARNING;
10223
10224 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
10225}
10226
10227
paul94f2b392005-06-28 12:44:16 +000010228static void
paul718e3742002-12-13 20:15:29 +000010229show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10230 int in)
10231{
10232 struct bgp_table *table;
10233 struct bgp_adj_in *ain;
10234 struct bgp_adj_out *adj;
10235 unsigned long output_count;
10236 struct bgp_node *rn;
10237 int header1 = 1;
10238 struct bgp *bgp;
10239 int header2 = 1;
10240
paulbb46e942003-10-24 19:02:03 +000010241 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000010242
10243 if (! bgp)
10244 return;
10245
10246 table = bgp->rib[afi][safi];
10247
10248 output_count = 0;
10249
10250 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
10251 PEER_STATUS_DEFAULT_ORIGINATE))
10252 {
10253 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 +000010254 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10255 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010256
10257 vty_out (vty, "Originating default network 0.0.0.0%s%s",
10258 VTY_NEWLINE, VTY_NEWLINE);
10259 header1 = 0;
10260 }
10261
10262 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10263 if (in)
10264 {
10265 for (ain = rn->adj_in; ain; ain = ain->next)
10266 if (ain->peer == peer)
10267 {
10268 if (header1)
10269 {
10270 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 +000010271 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10272 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010273 header1 = 0;
10274 }
10275 if (header2)
10276 {
10277 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10278 header2 = 0;
10279 }
10280 if (ain->attr)
10281 {
10282 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
10283 output_count++;
10284 }
10285 }
10286 }
10287 else
10288 {
10289 for (adj = rn->adj_out; adj; adj = adj->next)
10290 if (adj->peer == peer)
10291 {
10292 if (header1)
10293 {
10294 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 +000010295 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10296 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010297 header1 = 0;
10298 }
10299 if (header2)
10300 {
10301 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10302 header2 = 0;
10303 }
10304 if (adj->attr)
10305 {
10306 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10307 output_count++;
10308 }
10309 }
10310 }
10311
10312 if (output_count != 0)
10313 vty_out (vty, "%sTotal number of prefixes %ld%s",
10314 VTY_NEWLINE, output_count, VTY_NEWLINE);
10315}
10316
paul94f2b392005-06-28 12:44:16 +000010317static int
paulbb46e942003-10-24 19:02:03 +000010318peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10319{
paul718e3742002-12-13 20:15:29 +000010320 if (! peer || ! peer->afc[afi][safi])
10321 {
10322 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10323 return CMD_WARNING;
10324 }
10325
10326 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10327 {
10328 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10329 VTY_NEWLINE);
10330 return CMD_WARNING;
10331 }
10332
10333 show_adj_route (vty, peer, afi, safi, in);
10334
10335 return CMD_SUCCESS;
10336}
10337
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010338DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10339 show_ip_bgp_view_neighbor_advertised_route_cmd,
10340 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10341 SHOW_STR
10342 IP_STR
10343 BGP_STR
10344 "BGP view\n"
10345 "View name\n"
10346 "Detailed information on TCP and BGP neighbor connections\n"
10347 "Neighbor to display information about\n"
10348 "Neighbor to display information about\n"
10349 "Display the routes advertised to a BGP neighbor\n")
10350{
10351 struct peer *peer;
10352
10353 if (argc == 2)
10354 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10355 else
10356 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10357
10358 if (! peer)
10359 return CMD_WARNING;
10360
10361 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
10362}
10363
10364ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010365 show_ip_bgp_neighbor_advertised_route_cmd,
10366 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10367 SHOW_STR
10368 IP_STR
10369 BGP_STR
10370 "Detailed information on TCP and BGP neighbor connections\n"
10371 "Neighbor to display information about\n"
10372 "Neighbor to display information about\n"
10373 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +000010374
10375DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10376 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10377 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10378 SHOW_STR
10379 IP_STR
10380 BGP_STR
10381 "Address family\n"
10382 "Address Family modifier\n"
10383 "Address Family modifier\n"
10384 "Detailed information on TCP and BGP neighbor connections\n"
10385 "Neighbor to display information about\n"
10386 "Neighbor to display information about\n"
10387 "Display the routes advertised to a BGP neighbor\n")
10388{
paulbb46e942003-10-24 19:02:03 +000010389 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010390
paulbb46e942003-10-24 19:02:03 +000010391 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10392 if (! peer)
10393 return CMD_WARNING;
10394
10395 if (strncmp (argv[0], "m", 1) == 0)
10396 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10397
10398 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010399}
10400
10401#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010402DEFUN (show_bgp_view_neighbor_advertised_route,
10403 show_bgp_view_neighbor_advertised_route_cmd,
10404 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10405 SHOW_STR
10406 BGP_STR
10407 "BGP view\n"
10408 "View name\n"
10409 "Detailed information on TCP and BGP neighbor connections\n"
10410 "Neighbor to display information about\n"
10411 "Neighbor to display information about\n"
10412 "Display the routes advertised to a BGP neighbor\n")
10413{
10414 struct peer *peer;
10415
10416 if (argc == 2)
10417 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10418 else
10419 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10420
10421 if (! peer)
10422 return CMD_WARNING;
10423
10424 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10425}
10426
10427ALIAS (show_bgp_view_neighbor_advertised_route,
10428 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10429 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10430 SHOW_STR
10431 BGP_STR
10432 "BGP view\n"
10433 "View name\n"
10434 "Address family\n"
10435 "Detailed information on TCP and BGP neighbor connections\n"
10436 "Neighbor to display information about\n"
10437 "Neighbor to display information about\n"
10438 "Display the routes advertised to a BGP neighbor\n")
10439
10440DEFUN (show_bgp_view_neighbor_received_routes,
10441 show_bgp_view_neighbor_received_routes_cmd,
10442 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10443 SHOW_STR
10444 BGP_STR
10445 "BGP view\n"
10446 "View name\n"
10447 "Detailed information on TCP and BGP neighbor connections\n"
10448 "Neighbor to display information about\n"
10449 "Neighbor to display information about\n"
10450 "Display the received routes from neighbor\n")
10451{
10452 struct peer *peer;
10453
10454 if (argc == 2)
10455 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10456 else
10457 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10458
10459 if (! peer)
10460 return CMD_WARNING;
10461
10462 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10463}
10464
10465ALIAS (show_bgp_view_neighbor_received_routes,
10466 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10467 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10468 SHOW_STR
10469 BGP_STR
10470 "BGP view\n"
10471 "View name\n"
10472 "Address family\n"
10473 "Detailed information on TCP and BGP neighbor connections\n"
10474 "Neighbor to display information about\n"
10475 "Neighbor to display information about\n"
10476 "Display the received routes from neighbor\n")
10477
10478ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010479 show_bgp_neighbor_advertised_route_cmd,
10480 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10481 SHOW_STR
10482 BGP_STR
10483 "Detailed information on TCP and BGP neighbor connections\n"
10484 "Neighbor to display information about\n"
10485 "Neighbor to display information about\n"
10486 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010487
10488ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010489 show_bgp_ipv6_neighbor_advertised_route_cmd,
10490 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10491 SHOW_STR
10492 BGP_STR
10493 "Address family\n"
10494 "Detailed information on TCP and BGP neighbor connections\n"
10495 "Neighbor to display information about\n"
10496 "Neighbor to display information about\n"
10497 "Display the routes advertised to a BGP neighbor\n")
10498
10499/* old command */
paulbb46e942003-10-24 19:02:03 +000010500ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010501 ipv6_bgp_neighbor_advertised_route_cmd,
10502 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10503 SHOW_STR
10504 IPV6_STR
10505 BGP_STR
10506 "Detailed information on TCP and BGP neighbor connections\n"
10507 "Neighbor to display information about\n"
10508 "Neighbor to display information about\n"
10509 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010510
paul718e3742002-12-13 20:15:29 +000010511/* old command */
10512DEFUN (ipv6_mbgp_neighbor_advertised_route,
10513 ipv6_mbgp_neighbor_advertised_route_cmd,
10514 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10515 SHOW_STR
10516 IPV6_STR
10517 MBGP_STR
10518 "Detailed information on TCP and BGP neighbor connections\n"
10519 "Neighbor to display information about\n"
10520 "Neighbor to display information about\n"
10521 "Display the routes advertised to a BGP neighbor\n")
10522{
paulbb46e942003-10-24 19:02:03 +000010523 struct peer *peer;
10524
10525 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10526 if (! peer)
10527 return CMD_WARNING;
10528
10529 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010530}
10531#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010532
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010533DEFUN (show_ip_bgp_view_neighbor_received_routes,
10534 show_ip_bgp_view_neighbor_received_routes_cmd,
10535 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10536 SHOW_STR
10537 IP_STR
10538 BGP_STR
10539 "BGP view\n"
10540 "View name\n"
10541 "Detailed information on TCP and BGP neighbor connections\n"
10542 "Neighbor to display information about\n"
10543 "Neighbor to display information about\n"
10544 "Display the received routes from neighbor\n")
10545{
10546 struct peer *peer;
10547
10548 if (argc == 2)
10549 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10550 else
10551 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10552
10553 if (! peer)
10554 return CMD_WARNING;
10555
10556 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10557}
10558
10559ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010560 show_ip_bgp_neighbor_received_routes_cmd,
10561 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10562 SHOW_STR
10563 IP_STR
10564 BGP_STR
10565 "Detailed information on TCP and BGP neighbor connections\n"
10566 "Neighbor to display information about\n"
10567 "Neighbor to display information about\n"
10568 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010569
10570DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10571 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10572 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10573 SHOW_STR
10574 IP_STR
10575 BGP_STR
10576 "Address family\n"
10577 "Address Family modifier\n"
10578 "Address Family modifier\n"
10579 "Detailed information on TCP and BGP neighbor connections\n"
10580 "Neighbor to display information about\n"
10581 "Neighbor to display information about\n"
10582 "Display the received routes from neighbor\n")
10583{
paulbb46e942003-10-24 19:02:03 +000010584 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010585
paulbb46e942003-10-24 19:02:03 +000010586 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10587 if (! peer)
10588 return CMD_WARNING;
10589
10590 if (strncmp (argv[0], "m", 1) == 0)
10591 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10592
10593 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010594}
10595
Michael Lambert95cbbd22010-07-23 14:43:04 -040010596DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10597 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010598 "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 -040010599 SHOW_STR
10600 BGP_STR
10601 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010602 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010603 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010604 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010605 "Address family modifier\n"
10606 "Address family modifier\n"
10607 "Detailed information on TCP and BGP neighbor connections\n"
10608 "Neighbor to display information about\n"
10609 "Neighbor to display information about\n"
10610 "Display the advertised routes to neighbor\n"
10611 "Display the received routes from neighbor\n")
10612{
10613 int afi;
10614 int safi;
10615 int in;
10616 struct peer *peer;
10617
David Lamparter94bad672015-03-03 08:52:22 +010010618 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010619
10620 if (! peer)
10621 return CMD_WARNING;
10622
Michael Lambert95cbbd22010-07-23 14:43:04 -040010623 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10624 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10625 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010626
10627 return peer_adj_routes (vty, peer, afi, safi, in);
10628}
10629
paul718e3742002-12-13 20:15:29 +000010630DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10631 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10632 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10633 SHOW_STR
10634 IP_STR
10635 BGP_STR
10636 "Detailed information on TCP and BGP neighbor connections\n"
10637 "Neighbor to display information about\n"
10638 "Neighbor to display information about\n"
10639 "Display information received from a BGP neighbor\n"
10640 "Display the prefixlist filter\n")
10641{
10642 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010643 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010644 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010645 int count, ret;
paul718e3742002-12-13 20:15:29 +000010646
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010647 ret = str2sockunion (argv[0], &su);
10648 if (ret < 0)
10649 {
10650 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10651 return CMD_WARNING;
10652 }
paul718e3742002-12-13 20:15:29 +000010653
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010654 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010655 if (! peer)
10656 return CMD_WARNING;
10657
10658 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10659 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10660 if (count)
10661 {
10662 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10663 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10664 }
10665
10666 return CMD_SUCCESS;
10667}
10668
10669DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10670 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10671 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10672 SHOW_STR
10673 IP_STR
10674 BGP_STR
10675 "Address family\n"
10676 "Address Family modifier\n"
10677 "Address Family modifier\n"
10678 "Detailed information on TCP and BGP neighbor connections\n"
10679 "Neighbor to display information about\n"
10680 "Neighbor to display information about\n"
10681 "Display information received from a BGP neighbor\n"
10682 "Display the prefixlist filter\n")
10683{
10684 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010685 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010686 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010687 int count, ret;
paul718e3742002-12-13 20:15:29 +000010688
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010689 ret = str2sockunion (argv[1], &su);
10690 if (ret < 0)
10691 {
10692 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10693 return CMD_WARNING;
10694 }
paul718e3742002-12-13 20:15:29 +000010695
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010696 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010697 if (! peer)
10698 return CMD_WARNING;
10699
10700 if (strncmp (argv[0], "m", 1) == 0)
10701 {
10702 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10703 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10704 if (count)
10705 {
10706 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10707 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10708 }
10709 }
10710 else
10711 {
10712 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10713 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10714 if (count)
10715 {
10716 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10717 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10718 }
10719 }
10720
10721 return CMD_SUCCESS;
10722}
10723
10724
10725#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010726ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010727 show_bgp_neighbor_received_routes_cmd,
10728 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10729 SHOW_STR
10730 BGP_STR
10731 "Detailed information on TCP and BGP neighbor connections\n"
10732 "Neighbor to display information about\n"
10733 "Neighbor to display information about\n"
10734 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010735
paulbb46e942003-10-24 19:02:03 +000010736ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010737 show_bgp_ipv6_neighbor_received_routes_cmd,
10738 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10739 SHOW_STR
10740 BGP_STR
10741 "Address family\n"
10742 "Detailed information on TCP and BGP neighbor connections\n"
10743 "Neighbor to display information about\n"
10744 "Neighbor to display information about\n"
10745 "Display the received routes from neighbor\n")
10746
10747DEFUN (show_bgp_neighbor_received_prefix_filter,
10748 show_bgp_neighbor_received_prefix_filter_cmd,
10749 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10750 SHOW_STR
10751 BGP_STR
10752 "Detailed information on TCP and BGP neighbor connections\n"
10753 "Neighbor to display information about\n"
10754 "Neighbor to display information about\n"
10755 "Display information received from a BGP neighbor\n"
10756 "Display the prefixlist filter\n")
10757{
10758 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010759 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010760 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010761 int count, ret;
paul718e3742002-12-13 20:15:29 +000010762
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010763 ret = str2sockunion (argv[0], &su);
10764 if (ret < 0)
10765 {
10766 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10767 return CMD_WARNING;
10768 }
paul718e3742002-12-13 20:15:29 +000010769
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010770 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010771 if (! peer)
10772 return CMD_WARNING;
10773
10774 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10775 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10776 if (count)
10777 {
10778 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10779 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10780 }
10781
10782 return CMD_SUCCESS;
10783}
10784
10785ALIAS (show_bgp_neighbor_received_prefix_filter,
10786 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10787 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10788 SHOW_STR
10789 BGP_STR
10790 "Address family\n"
10791 "Detailed information on TCP and BGP neighbor connections\n"
10792 "Neighbor to display information about\n"
10793 "Neighbor to display information about\n"
10794 "Display information received from a BGP neighbor\n"
10795 "Display the prefixlist filter\n")
10796
10797/* old command */
paulbb46e942003-10-24 19:02:03 +000010798ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010799 ipv6_bgp_neighbor_received_routes_cmd,
10800 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10801 SHOW_STR
10802 IPV6_STR
10803 BGP_STR
10804 "Detailed information on TCP and BGP neighbor connections\n"
10805 "Neighbor to display information about\n"
10806 "Neighbor to display information about\n"
10807 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010808
10809/* old command */
10810DEFUN (ipv6_mbgp_neighbor_received_routes,
10811 ipv6_mbgp_neighbor_received_routes_cmd,
10812 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10813 SHOW_STR
10814 IPV6_STR
10815 MBGP_STR
10816 "Detailed information on TCP and BGP neighbor connections\n"
10817 "Neighbor to display information about\n"
10818 "Neighbor to display information about\n"
10819 "Display the received routes from neighbor\n")
10820{
paulbb46e942003-10-24 19:02:03 +000010821 struct peer *peer;
10822
10823 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10824 if (! peer)
10825 return CMD_WARNING;
10826
10827 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010828}
paulbb46e942003-10-24 19:02:03 +000010829
10830DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10831 show_bgp_view_neighbor_received_prefix_filter_cmd,
10832 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10833 SHOW_STR
10834 BGP_STR
10835 "BGP view\n"
10836 "View name\n"
10837 "Detailed information on TCP and BGP neighbor connections\n"
10838 "Neighbor to display information about\n"
10839 "Neighbor to display information about\n"
10840 "Display information received from a BGP neighbor\n"
10841 "Display the prefixlist filter\n")
10842{
10843 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010844 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010845 struct peer *peer;
10846 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010847 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010848
10849 /* BGP structure lookup. */
10850 bgp = bgp_lookup_by_name (argv[0]);
10851 if (bgp == NULL)
10852 {
10853 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10854 return CMD_WARNING;
10855 }
10856
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010857 ret = str2sockunion (argv[1], &su);
10858 if (ret < 0)
10859 {
10860 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10861 return CMD_WARNING;
10862 }
paulbb46e942003-10-24 19:02:03 +000010863
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010864 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010865 if (! peer)
10866 return CMD_WARNING;
10867
10868 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10869 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10870 if (count)
10871 {
10872 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10873 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10874 }
10875
10876 return CMD_SUCCESS;
10877}
10878
10879ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10880 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10881 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10882 SHOW_STR
10883 BGP_STR
10884 "BGP view\n"
10885 "View name\n"
10886 "Address family\n"
10887 "Detailed information on TCP and BGP neighbor connections\n"
10888 "Neighbor to display information about\n"
10889 "Neighbor to display information about\n"
10890 "Display information received from a BGP neighbor\n"
10891 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010892#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010893
paul94f2b392005-06-28 12:44:16 +000010894static int
paulbb46e942003-10-24 19:02:03 +000010895bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010896 safi_t safi, enum bgp_show_type type)
10897{
paul718e3742002-12-13 20:15:29 +000010898 if (! peer || ! peer->afc[afi][safi])
10899 {
10900 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010901 return CMD_WARNING;
10902 }
10903
ajs5a646652004-11-05 01:25:55 +000010904 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010905}
10906
10907DEFUN (show_ip_bgp_neighbor_routes,
10908 show_ip_bgp_neighbor_routes_cmd,
10909 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10910 SHOW_STR
10911 IP_STR
10912 BGP_STR
10913 "Detailed information on TCP and BGP neighbor connections\n"
10914 "Neighbor to display information about\n"
10915 "Neighbor to display information about\n"
10916 "Display routes learned from neighbor\n")
10917{
paulbb46e942003-10-24 19:02:03 +000010918 struct peer *peer;
10919
10920 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10921 if (! peer)
10922 return CMD_WARNING;
10923
10924 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010925 bgp_show_type_neighbor);
10926}
10927
10928DEFUN (show_ip_bgp_neighbor_flap,
10929 show_ip_bgp_neighbor_flap_cmd,
10930 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10931 SHOW_STR
10932 IP_STR
10933 BGP_STR
10934 "Detailed information on TCP and BGP neighbor connections\n"
10935 "Neighbor to display information about\n"
10936 "Neighbor to display information about\n"
10937 "Display flap statistics of the routes learned from neighbor\n")
10938{
paulbb46e942003-10-24 19:02:03 +000010939 struct peer *peer;
10940
10941 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10942 if (! peer)
10943 return CMD_WARNING;
10944
10945 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010946 bgp_show_type_flap_neighbor);
10947}
10948
10949DEFUN (show_ip_bgp_neighbor_damp,
10950 show_ip_bgp_neighbor_damp_cmd,
10951 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10952 SHOW_STR
10953 IP_STR
10954 BGP_STR
10955 "Detailed information on TCP and BGP neighbor connections\n"
10956 "Neighbor to display information about\n"
10957 "Neighbor to display information about\n"
10958 "Display the dampened routes received from neighbor\n")
10959{
paulbb46e942003-10-24 19:02:03 +000010960 struct peer *peer;
10961
10962 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10963 if (! peer)
10964 return CMD_WARNING;
10965
10966 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010967 bgp_show_type_damp_neighbor);
10968}
10969
10970DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10971 show_ip_bgp_ipv4_neighbor_routes_cmd,
10972 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10973 SHOW_STR
10974 IP_STR
10975 BGP_STR
10976 "Address family\n"
10977 "Address Family modifier\n"
10978 "Address Family modifier\n"
10979 "Detailed information on TCP and BGP neighbor connections\n"
10980 "Neighbor to display information about\n"
10981 "Neighbor to display information about\n"
10982 "Display routes learned from neighbor\n")
10983{
paulbb46e942003-10-24 19:02:03 +000010984 struct peer *peer;
10985
10986 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10987 if (! peer)
10988 return CMD_WARNING;
10989
paul718e3742002-12-13 20:15:29 +000010990 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010991 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010992 bgp_show_type_neighbor);
10993
paulbb46e942003-10-24 19:02:03 +000010994 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010995 bgp_show_type_neighbor);
10996}
paulbb46e942003-10-24 19:02:03 +000010997
paulfee0f4c2004-09-13 05:12:46 +000010998DEFUN (show_ip_bgp_view_rsclient,
10999 show_ip_bgp_view_rsclient_cmd,
11000 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11001 SHOW_STR
11002 IP_STR
11003 BGP_STR
11004 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011005 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011006 "Information about Route Server Client\n"
11007 NEIGHBOR_ADDR_STR)
11008{
11009 struct bgp_table *table;
11010 struct peer *peer;
11011
11012 if (argc == 2)
11013 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11014 else
11015 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11016
11017 if (! peer)
11018 return CMD_WARNING;
11019
11020 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11021 {
11022 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11023 VTY_NEWLINE);
11024 return CMD_WARNING;
11025 }
11026
11027 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11028 PEER_FLAG_RSERVER_CLIENT))
11029 {
11030 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11031 VTY_NEWLINE);
11032 return CMD_WARNING;
11033 }
11034
11035 table = peer->rib[AFI_IP][SAFI_UNICAST];
11036
ajs5a646652004-11-05 01:25:55 +000011037 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011038}
11039
11040ALIAS (show_ip_bgp_view_rsclient,
11041 show_ip_bgp_rsclient_cmd,
11042 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
11043 SHOW_STR
11044 IP_STR
11045 BGP_STR
11046 "Information about Route Server Client\n"
11047 NEIGHBOR_ADDR_STR)
11048
Michael Lambert95cbbd22010-07-23 14:43:04 -040011049DEFUN (show_bgp_view_ipv4_safi_rsclient,
11050 show_bgp_view_ipv4_safi_rsclient_cmd,
11051 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11052 SHOW_STR
11053 BGP_STR
11054 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011055 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011056 "Address family\n"
11057 "Address Family modifier\n"
11058 "Address Family modifier\n"
11059 "Information about Route Server Client\n"
11060 NEIGHBOR_ADDR_STR)
11061{
11062 struct bgp_table *table;
11063 struct peer *peer;
11064 safi_t safi;
11065
11066 if (argc == 3) {
11067 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11068 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11069 } else {
11070 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11071 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11072 }
11073
11074 if (! peer)
11075 return CMD_WARNING;
11076
11077 if (! peer->afc[AFI_IP][safi])
11078 {
11079 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11080 VTY_NEWLINE);
11081 return CMD_WARNING;
11082 }
11083
11084 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11085 PEER_FLAG_RSERVER_CLIENT))
11086 {
11087 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11088 VTY_NEWLINE);
11089 return CMD_WARNING;
11090 }
11091
11092 table = peer->rib[AFI_IP][safi];
11093
11094 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11095}
11096
11097ALIAS (show_bgp_view_ipv4_safi_rsclient,
11098 show_bgp_ipv4_safi_rsclient_cmd,
11099 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11100 SHOW_STR
11101 BGP_STR
11102 "Address family\n"
11103 "Address Family modifier\n"
11104 "Address Family modifier\n"
11105 "Information about Route Server Client\n"
11106 NEIGHBOR_ADDR_STR)
11107
paulfee0f4c2004-09-13 05:12:46 +000011108DEFUN (show_ip_bgp_view_rsclient_route,
11109 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010011110 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000011111 SHOW_STR
11112 IP_STR
11113 BGP_STR
11114 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011115 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011116 "Information about Route Server Client\n"
11117 NEIGHBOR_ADDR_STR
11118 "Network in the BGP routing table to display\n")
11119{
11120 struct bgp *bgp;
11121 struct peer *peer;
11122
11123 /* BGP structure lookup. */
11124 if (argc == 3)
11125 {
11126 bgp = bgp_lookup_by_name (argv[0]);
11127 if (bgp == NULL)
11128 {
11129 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11130 return CMD_WARNING;
11131 }
11132 }
11133 else
11134 {
11135 bgp = bgp_get_default ();
11136 if (bgp == NULL)
11137 {
11138 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11139 return CMD_WARNING;
11140 }
11141 }
11142
11143 if (argc == 3)
11144 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11145 else
11146 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11147
11148 if (! peer)
11149 return CMD_WARNING;
11150
11151 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11152 {
11153 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11154 VTY_NEWLINE);
11155 return CMD_WARNING;
11156}
11157
11158 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11159 PEER_FLAG_RSERVER_CLIENT))
11160 {
11161 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11162 VTY_NEWLINE);
11163 return CMD_WARNING;
11164 }
11165
11166 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11167 (argc == 3) ? argv[2] : argv[1],
11168 AFI_IP, SAFI_UNICAST, NULL, 0);
11169}
11170
11171ALIAS (show_ip_bgp_view_rsclient_route,
11172 show_ip_bgp_rsclient_route_cmd,
11173 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11174 SHOW_STR
11175 IP_STR
11176 BGP_STR
11177 "Information about Route Server Client\n"
11178 NEIGHBOR_ADDR_STR
11179 "Network in the BGP routing table to display\n")
11180
Michael Lambert95cbbd22010-07-23 14:43:04 -040011181DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11182 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11183 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11184 SHOW_STR
11185 BGP_STR
11186 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011187 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011188 "Address family\n"
11189 "Address Family modifier\n"
11190 "Address Family modifier\n"
11191 "Information about Route Server Client\n"
11192 NEIGHBOR_ADDR_STR
11193 "Network in the BGP routing table to display\n")
11194{
11195 struct bgp *bgp;
11196 struct peer *peer;
11197 safi_t safi;
11198
11199 /* BGP structure lookup. */
11200 if (argc == 4)
11201 {
11202 bgp = bgp_lookup_by_name (argv[0]);
11203 if (bgp == NULL)
11204 {
11205 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11206 return CMD_WARNING;
11207 }
11208 }
11209 else
11210 {
11211 bgp = bgp_get_default ();
11212 if (bgp == NULL)
11213 {
11214 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11215 return CMD_WARNING;
11216 }
11217 }
11218
11219 if (argc == 4) {
11220 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11221 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11222 } else {
11223 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11224 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11225 }
11226
11227 if (! peer)
11228 return CMD_WARNING;
11229
11230 if (! peer->afc[AFI_IP][safi])
11231 {
11232 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11233 VTY_NEWLINE);
11234 return CMD_WARNING;
11235}
11236
11237 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11238 PEER_FLAG_RSERVER_CLIENT))
11239 {
11240 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11241 VTY_NEWLINE);
11242 return CMD_WARNING;
11243 }
11244
11245 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11246 (argc == 4) ? argv[3] : argv[2],
11247 AFI_IP, safi, NULL, 0);
11248}
11249
11250ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
11251 show_bgp_ipv4_safi_rsclient_route_cmd,
11252 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11253 SHOW_STR
11254 BGP_STR
11255 "Address family\n"
11256 "Address Family modifier\n"
11257 "Address Family modifier\n"
11258 "Information about Route Server Client\n"
11259 NEIGHBOR_ADDR_STR
11260 "Network in the BGP routing table to display\n")
11261
paulfee0f4c2004-09-13 05:12:46 +000011262DEFUN (show_ip_bgp_view_rsclient_prefix,
11263 show_ip_bgp_view_rsclient_prefix_cmd,
11264 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11265 SHOW_STR
11266 IP_STR
11267 BGP_STR
11268 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011269 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011270 "Information about Route Server Client\n"
11271 NEIGHBOR_ADDR_STR
11272 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11273{
11274 struct bgp *bgp;
11275 struct peer *peer;
11276
11277 /* BGP structure lookup. */
11278 if (argc == 3)
11279 {
11280 bgp = bgp_lookup_by_name (argv[0]);
11281 if (bgp == NULL)
11282 {
11283 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11284 return CMD_WARNING;
11285 }
11286 }
11287 else
11288 {
11289 bgp = bgp_get_default ();
11290 if (bgp == NULL)
11291 {
11292 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11293 return CMD_WARNING;
11294 }
11295 }
11296
11297 if (argc == 3)
11298 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11299 else
11300 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11301
11302 if (! peer)
11303 return CMD_WARNING;
11304
11305 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11306 {
11307 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11308 VTY_NEWLINE);
11309 return CMD_WARNING;
11310}
11311
11312 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11313 PEER_FLAG_RSERVER_CLIENT))
11314{
11315 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11316 VTY_NEWLINE);
11317 return CMD_WARNING;
11318 }
11319
11320 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11321 (argc == 3) ? argv[2] : argv[1],
11322 AFI_IP, SAFI_UNICAST, NULL, 1);
11323}
11324
11325ALIAS (show_ip_bgp_view_rsclient_prefix,
11326 show_ip_bgp_rsclient_prefix_cmd,
11327 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11328 SHOW_STR
11329 IP_STR
11330 BGP_STR
11331 "Information about Route Server Client\n"
11332 NEIGHBOR_ADDR_STR
11333 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11334
Michael Lambert95cbbd22010-07-23 14:43:04 -040011335DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11336 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11337 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11338 SHOW_STR
11339 BGP_STR
11340 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011341 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011342 "Address family\n"
11343 "Address Family modifier\n"
11344 "Address Family modifier\n"
11345 "Information about Route Server Client\n"
11346 NEIGHBOR_ADDR_STR
11347 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11348{
11349 struct bgp *bgp;
11350 struct peer *peer;
11351 safi_t safi;
11352
11353 /* BGP structure lookup. */
11354 if (argc == 4)
11355 {
11356 bgp = bgp_lookup_by_name (argv[0]);
11357 if (bgp == NULL)
11358 {
11359 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11360 return CMD_WARNING;
11361 }
11362 }
11363 else
11364 {
11365 bgp = bgp_get_default ();
11366 if (bgp == NULL)
11367 {
11368 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11369 return CMD_WARNING;
11370 }
11371 }
11372
11373 if (argc == 4) {
11374 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11375 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11376 } else {
11377 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11378 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11379 }
11380
11381 if (! peer)
11382 return CMD_WARNING;
11383
11384 if (! peer->afc[AFI_IP][safi])
11385 {
11386 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11387 VTY_NEWLINE);
11388 return CMD_WARNING;
11389}
11390
11391 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11392 PEER_FLAG_RSERVER_CLIENT))
11393{
11394 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11395 VTY_NEWLINE);
11396 return CMD_WARNING;
11397 }
11398
11399 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11400 (argc == 4) ? argv[3] : argv[2],
11401 AFI_IP, safi, NULL, 1);
11402}
11403
11404ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11405 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11406 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11407 SHOW_STR
11408 BGP_STR
11409 "Address family\n"
11410 "Address Family modifier\n"
11411 "Address Family modifier\n"
11412 "Information about Route Server Client\n"
11413 NEIGHBOR_ADDR_STR
11414 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011415
paul718e3742002-12-13 20:15:29 +000011416#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011417DEFUN (show_bgp_view_neighbor_routes,
11418 show_bgp_view_neighbor_routes_cmd,
11419 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11420 SHOW_STR
11421 BGP_STR
11422 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011423 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011424 "Detailed information on TCP and BGP neighbor connections\n"
11425 "Neighbor to display information about\n"
11426 "Neighbor to display information about\n"
11427 "Display routes learned from neighbor\n")
11428{
11429 struct peer *peer;
11430
11431 if (argc == 2)
11432 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11433 else
11434 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11435
11436 if (! peer)
11437 return CMD_WARNING;
11438
11439 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11440 bgp_show_type_neighbor);
11441}
11442
11443ALIAS (show_bgp_view_neighbor_routes,
11444 show_bgp_view_ipv6_neighbor_routes_cmd,
11445 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11446 SHOW_STR
11447 BGP_STR
11448 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011449 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011450 "Address family\n"
11451 "Detailed information on TCP and BGP neighbor connections\n"
11452 "Neighbor to display information about\n"
11453 "Neighbor to display information about\n"
11454 "Display routes learned from neighbor\n")
11455
11456DEFUN (show_bgp_view_neighbor_damp,
11457 show_bgp_view_neighbor_damp_cmd,
11458 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11459 SHOW_STR
11460 BGP_STR
11461 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011462 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011463 "Detailed information on TCP and BGP neighbor connections\n"
11464 "Neighbor to display information about\n"
11465 "Neighbor to display information about\n"
11466 "Display the dampened routes received from neighbor\n")
11467{
11468 struct peer *peer;
11469
11470 if (argc == 2)
11471 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11472 else
11473 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11474
11475 if (! peer)
11476 return CMD_WARNING;
11477
11478 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11479 bgp_show_type_damp_neighbor);
11480}
11481
11482ALIAS (show_bgp_view_neighbor_damp,
11483 show_bgp_view_ipv6_neighbor_damp_cmd,
11484 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11485 SHOW_STR
11486 BGP_STR
11487 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011488 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011489 "Address family\n"
11490 "Detailed information on TCP and BGP neighbor connections\n"
11491 "Neighbor to display information about\n"
11492 "Neighbor to display information about\n"
11493 "Display the dampened routes received from neighbor\n")
11494
11495DEFUN (show_bgp_view_neighbor_flap,
11496 show_bgp_view_neighbor_flap_cmd,
11497 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11498 SHOW_STR
11499 BGP_STR
11500 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011501 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011502 "Detailed information on TCP and BGP neighbor connections\n"
11503 "Neighbor to display information about\n"
11504 "Neighbor to display information about\n"
11505 "Display flap statistics of the routes learned from neighbor\n")
11506{
11507 struct peer *peer;
11508
11509 if (argc == 2)
11510 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11511 else
11512 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11513
11514 if (! peer)
11515 return CMD_WARNING;
11516
11517 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11518 bgp_show_type_flap_neighbor);
11519}
11520
11521ALIAS (show_bgp_view_neighbor_flap,
11522 show_bgp_view_ipv6_neighbor_flap_cmd,
11523 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11524 SHOW_STR
11525 BGP_STR
11526 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011527 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011528 "Address family\n"
11529 "Detailed information on TCP and BGP neighbor connections\n"
11530 "Neighbor to display information about\n"
11531 "Neighbor to display information about\n"
11532 "Display flap statistics of the routes learned from neighbor\n")
11533
11534ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011535 show_bgp_neighbor_routes_cmd,
11536 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11537 SHOW_STR
11538 BGP_STR
11539 "Detailed information on TCP and BGP neighbor connections\n"
11540 "Neighbor to display information about\n"
11541 "Neighbor to display information about\n"
11542 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011543
paulbb46e942003-10-24 19:02:03 +000011544
11545ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011546 show_bgp_ipv6_neighbor_routes_cmd,
11547 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11548 SHOW_STR
11549 BGP_STR
11550 "Address family\n"
11551 "Detailed information on TCP and BGP neighbor connections\n"
11552 "Neighbor to display information about\n"
11553 "Neighbor to display information about\n"
11554 "Display routes learned from neighbor\n")
11555
11556/* old command */
paulbb46e942003-10-24 19:02:03 +000011557ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011558 ipv6_bgp_neighbor_routes_cmd,
11559 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11560 SHOW_STR
11561 IPV6_STR
11562 BGP_STR
11563 "Detailed information on TCP and BGP neighbor connections\n"
11564 "Neighbor to display information about\n"
11565 "Neighbor to display information about\n"
11566 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011567
11568/* old command */
11569DEFUN (ipv6_mbgp_neighbor_routes,
11570 ipv6_mbgp_neighbor_routes_cmd,
11571 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11572 SHOW_STR
11573 IPV6_STR
11574 MBGP_STR
11575 "Detailed information on TCP and BGP neighbor connections\n"
11576 "Neighbor to display information about\n"
11577 "Neighbor to display information about\n"
11578 "Display routes learned from neighbor\n")
11579{
paulbb46e942003-10-24 19:02:03 +000011580 struct peer *peer;
11581
11582 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11583 if (! peer)
11584 return CMD_WARNING;
11585
11586 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011587 bgp_show_type_neighbor);
11588}
paulbb46e942003-10-24 19:02:03 +000011589
11590ALIAS (show_bgp_view_neighbor_flap,
11591 show_bgp_neighbor_flap_cmd,
11592 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11593 SHOW_STR
11594 BGP_STR
11595 "Detailed information on TCP and BGP neighbor connections\n"
11596 "Neighbor to display information about\n"
11597 "Neighbor to display information about\n"
11598 "Display flap statistics of the routes learned from neighbor\n")
11599
11600ALIAS (show_bgp_view_neighbor_flap,
11601 show_bgp_ipv6_neighbor_flap_cmd,
11602 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11603 SHOW_STR
11604 BGP_STR
11605 "Address family\n"
11606 "Detailed information on TCP and BGP neighbor connections\n"
11607 "Neighbor to display information about\n"
11608 "Neighbor to display information about\n"
11609 "Display flap statistics of the routes learned from neighbor\n")
11610
11611ALIAS (show_bgp_view_neighbor_damp,
11612 show_bgp_neighbor_damp_cmd,
11613 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11614 SHOW_STR
11615 BGP_STR
11616 "Detailed information on TCP and BGP neighbor connections\n"
11617 "Neighbor to display information about\n"
11618 "Neighbor to display information about\n"
11619 "Display the dampened routes received from neighbor\n")
11620
11621ALIAS (show_bgp_view_neighbor_damp,
11622 show_bgp_ipv6_neighbor_damp_cmd,
11623 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11624 SHOW_STR
11625 BGP_STR
11626 "Address family\n"
11627 "Detailed information on TCP and BGP neighbor connections\n"
11628 "Neighbor to display information about\n"
11629 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011630 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011631
11632DEFUN (show_bgp_view_rsclient,
11633 show_bgp_view_rsclient_cmd,
11634 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11635 SHOW_STR
11636 BGP_STR
11637 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011638 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011639 "Information about Route Server Client\n"
11640 NEIGHBOR_ADDR_STR)
11641{
11642 struct bgp_table *table;
11643 struct peer *peer;
11644
11645 if (argc == 2)
11646 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11647 else
11648 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11649
11650 if (! peer)
11651 return CMD_WARNING;
11652
11653 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11654 {
11655 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11656 VTY_NEWLINE);
11657 return CMD_WARNING;
11658 }
11659
11660 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11661 PEER_FLAG_RSERVER_CLIENT))
11662 {
11663 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11664 VTY_NEWLINE);
11665 return CMD_WARNING;
11666 }
11667
11668 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11669
ajs5a646652004-11-05 01:25:55 +000011670 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011671}
11672
11673ALIAS (show_bgp_view_rsclient,
11674 show_bgp_rsclient_cmd,
11675 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11676 SHOW_STR
11677 BGP_STR
11678 "Information about Route Server Client\n"
11679 NEIGHBOR_ADDR_STR)
11680
Michael Lambert95cbbd22010-07-23 14:43:04 -040011681DEFUN (show_bgp_view_ipv6_safi_rsclient,
11682 show_bgp_view_ipv6_safi_rsclient_cmd,
11683 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11684 SHOW_STR
11685 BGP_STR
11686 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011687 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011688 "Address family\n"
11689 "Address Family modifier\n"
11690 "Address Family modifier\n"
11691 "Information about Route Server Client\n"
11692 NEIGHBOR_ADDR_STR)
11693{
11694 struct bgp_table *table;
11695 struct peer *peer;
11696 safi_t safi;
11697
11698 if (argc == 3) {
11699 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11700 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11701 } else {
11702 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11703 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11704 }
11705
11706 if (! peer)
11707 return CMD_WARNING;
11708
11709 if (! peer->afc[AFI_IP6][safi])
11710 {
11711 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11712 VTY_NEWLINE);
11713 return CMD_WARNING;
11714 }
11715
11716 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11717 PEER_FLAG_RSERVER_CLIENT))
11718 {
11719 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11720 VTY_NEWLINE);
11721 return CMD_WARNING;
11722 }
11723
11724 table = peer->rib[AFI_IP6][safi];
11725
11726 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11727}
11728
11729ALIAS (show_bgp_view_ipv6_safi_rsclient,
11730 show_bgp_ipv6_safi_rsclient_cmd,
11731 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11732 SHOW_STR
11733 BGP_STR
11734 "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
paulfee0f4c2004-09-13 05:12:46 +000011740DEFUN (show_bgp_view_rsclient_route,
11741 show_bgp_view_rsclient_route_cmd,
11742 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11743 SHOW_STR
11744 BGP_STR
11745 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011746 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011747 "Information about Route Server Client\n"
11748 NEIGHBOR_ADDR_STR
11749 "Network in the BGP routing table to display\n")
11750{
11751 struct bgp *bgp;
11752 struct peer *peer;
11753
11754 /* BGP structure lookup. */
11755 if (argc == 3)
11756 {
11757 bgp = bgp_lookup_by_name (argv[0]);
11758 if (bgp == NULL)
11759 {
11760 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11761 return CMD_WARNING;
11762 }
11763 }
11764 else
11765 {
11766 bgp = bgp_get_default ();
11767 if (bgp == NULL)
11768 {
11769 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11770 return CMD_WARNING;
11771 }
11772 }
11773
11774 if (argc == 3)
11775 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11776 else
11777 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11778
11779 if (! peer)
11780 return CMD_WARNING;
11781
11782 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11783 {
11784 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11785 VTY_NEWLINE);
11786 return CMD_WARNING;
11787 }
11788
11789 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11790 PEER_FLAG_RSERVER_CLIENT))
11791 {
11792 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11793 VTY_NEWLINE);
11794 return CMD_WARNING;
11795 }
11796
11797 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11798 (argc == 3) ? argv[2] : argv[1],
11799 AFI_IP6, SAFI_UNICAST, NULL, 0);
11800}
11801
11802ALIAS (show_bgp_view_rsclient_route,
11803 show_bgp_rsclient_route_cmd,
11804 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11805 SHOW_STR
11806 BGP_STR
11807 "Information about Route Server Client\n"
11808 NEIGHBOR_ADDR_STR
11809 "Network in the BGP routing table to display\n")
11810
Michael Lambert95cbbd22010-07-23 14:43:04 -040011811DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11812 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11813 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11814 SHOW_STR
11815 BGP_STR
11816 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011817 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011818 "Address family\n"
11819 "Address Family modifier\n"
11820 "Address Family modifier\n"
11821 "Information about Route Server Client\n"
11822 NEIGHBOR_ADDR_STR
11823 "Network in the BGP routing table to display\n")
11824{
11825 struct bgp *bgp;
11826 struct peer *peer;
11827 safi_t safi;
11828
11829 /* BGP structure lookup. */
11830 if (argc == 4)
11831 {
11832 bgp = bgp_lookup_by_name (argv[0]);
11833 if (bgp == NULL)
11834 {
11835 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11836 return CMD_WARNING;
11837 }
11838 }
11839 else
11840 {
11841 bgp = bgp_get_default ();
11842 if (bgp == NULL)
11843 {
11844 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11845 return CMD_WARNING;
11846 }
11847 }
11848
11849 if (argc == 4) {
11850 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11851 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11852 } else {
11853 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11854 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11855 }
11856
11857 if (! peer)
11858 return CMD_WARNING;
11859
11860 if (! peer->afc[AFI_IP6][safi])
11861 {
11862 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11863 VTY_NEWLINE);
11864 return CMD_WARNING;
11865}
11866
11867 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11868 PEER_FLAG_RSERVER_CLIENT))
11869 {
11870 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11871 VTY_NEWLINE);
11872 return CMD_WARNING;
11873 }
11874
11875 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11876 (argc == 4) ? argv[3] : argv[2],
11877 AFI_IP6, safi, NULL, 0);
11878}
11879
11880ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11881 show_bgp_ipv6_safi_rsclient_route_cmd,
11882 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11883 SHOW_STR
11884 BGP_STR
11885 "Address family\n"
11886 "Address Family modifier\n"
11887 "Address Family modifier\n"
11888 "Information about Route Server Client\n"
11889 NEIGHBOR_ADDR_STR
11890 "Network in the BGP routing table to display\n")
11891
paulfee0f4c2004-09-13 05:12:46 +000011892DEFUN (show_bgp_view_rsclient_prefix,
11893 show_bgp_view_rsclient_prefix_cmd,
11894 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11895 SHOW_STR
11896 BGP_STR
11897 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011898 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011899 "Information about Route Server Client\n"
11900 NEIGHBOR_ADDR_STR
11901 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11902{
11903 struct bgp *bgp;
11904 struct peer *peer;
11905
11906 /* BGP structure lookup. */
11907 if (argc == 3)
11908 {
11909 bgp = bgp_lookup_by_name (argv[0]);
11910 if (bgp == NULL)
11911 {
11912 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11913 return CMD_WARNING;
11914 }
11915 }
11916 else
11917 {
11918 bgp = bgp_get_default ();
11919 if (bgp == NULL)
11920 {
11921 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11922 return CMD_WARNING;
11923 }
11924 }
11925
11926 if (argc == 3)
11927 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11928 else
11929 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11930
11931 if (! peer)
11932 return CMD_WARNING;
11933
11934 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11935 {
11936 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11937 VTY_NEWLINE);
11938 return CMD_WARNING;
11939 }
11940
11941 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11942 PEER_FLAG_RSERVER_CLIENT))
11943 {
11944 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11945 VTY_NEWLINE);
11946 return CMD_WARNING;
11947 }
11948
11949 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11950 (argc == 3) ? argv[2] : argv[1],
11951 AFI_IP6, SAFI_UNICAST, NULL, 1);
11952}
11953
11954ALIAS (show_bgp_view_rsclient_prefix,
11955 show_bgp_rsclient_prefix_cmd,
11956 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11957 SHOW_STR
11958 BGP_STR
11959 "Information about Route Server Client\n"
11960 NEIGHBOR_ADDR_STR
11961 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11962
Michael Lambert95cbbd22010-07-23 14:43:04 -040011963DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11964 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11965 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11966 SHOW_STR
11967 BGP_STR
11968 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011969 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011970 "Address family\n"
11971 "Address Family modifier\n"
11972 "Address Family modifier\n"
11973 "Information about Route Server Client\n"
11974 NEIGHBOR_ADDR_STR
11975 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11976{
11977 struct bgp *bgp;
11978 struct peer *peer;
11979 safi_t safi;
11980
11981 /* BGP structure lookup. */
11982 if (argc == 4)
11983 {
11984 bgp = bgp_lookup_by_name (argv[0]);
11985 if (bgp == NULL)
11986 {
11987 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11988 return CMD_WARNING;
11989 }
11990 }
11991 else
11992 {
11993 bgp = bgp_get_default ();
11994 if (bgp == NULL)
11995 {
11996 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11997 return CMD_WARNING;
11998 }
11999 }
12000
12001 if (argc == 4) {
12002 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
12003 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12004 } else {
12005 peer = peer_lookup_in_view (vty, NULL, argv[1]);
12006 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
12007 }
12008
12009 if (! peer)
12010 return CMD_WARNING;
12011
12012 if (! peer->afc[AFI_IP6][safi])
12013 {
12014 vty_out (vty, "%% Activate the neighbor for the address family first%s",
12015 VTY_NEWLINE);
12016 return CMD_WARNING;
12017}
12018
12019 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
12020 PEER_FLAG_RSERVER_CLIENT))
12021{
12022 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
12023 VTY_NEWLINE);
12024 return CMD_WARNING;
12025 }
12026
12027 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
12028 (argc == 4) ? argv[3] : argv[2],
12029 AFI_IP6, safi, NULL, 1);
12030}
12031
12032ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
12033 show_bgp_ipv6_safi_rsclient_prefix_cmd,
12034 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
12035 SHOW_STR
12036 BGP_STR
12037 "Address family\n"
12038 "Address Family modifier\n"
12039 "Address Family modifier\n"
12040 "Information about Route Server Client\n"
12041 NEIGHBOR_ADDR_STR
12042 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
12043
paul718e3742002-12-13 20:15:29 +000012044#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020012045
paul718e3742002-12-13 20:15:29 +000012046struct bgp_table *bgp_distance_table;
12047
12048struct bgp_distance
12049{
12050 /* Distance value for the IP source prefix. */
12051 u_char distance;
12052
12053 /* Name of the access-list to be matched. */
12054 char *access_list;
12055};
12056
paul94f2b392005-06-28 12:44:16 +000012057static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012058bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000012059{
Stephen Hemminger393deb92008-08-18 14:13:29 -070012060 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000012061}
12062
paul94f2b392005-06-28 12:44:16 +000012063static void
paul718e3742002-12-13 20:15:29 +000012064bgp_distance_free (struct bgp_distance *bdistance)
12065{
12066 XFREE (MTYPE_BGP_DISTANCE, bdistance);
12067}
12068
paul94f2b392005-06-28 12:44:16 +000012069static int
paulfd79ac92004-10-13 05:06:08 +000012070bgp_distance_set (struct vty *vty, const char *distance_str,
12071 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000012072{
12073 int ret;
12074 struct prefix_ipv4 p;
12075 u_char distance;
12076 struct bgp_node *rn;
12077 struct bgp_distance *bdistance;
12078
12079 ret = str2prefix_ipv4 (ip_str, &p);
12080 if (ret == 0)
12081 {
12082 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12083 return CMD_WARNING;
12084 }
12085
12086 distance = atoi (distance_str);
12087
12088 /* Get BGP distance node. */
12089 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
12090 if (rn->info)
12091 {
12092 bdistance = rn->info;
12093 bgp_unlock_node (rn);
12094 }
12095 else
12096 {
12097 bdistance = bgp_distance_new ();
12098 rn->info = bdistance;
12099 }
12100
12101 /* Set distance value. */
12102 bdistance->distance = distance;
12103
12104 /* Reset access-list configuration. */
12105 if (bdistance->access_list)
12106 {
12107 free (bdistance->access_list);
12108 bdistance->access_list = NULL;
12109 }
12110 if (access_list_str)
12111 bdistance->access_list = strdup (access_list_str);
12112
12113 return CMD_SUCCESS;
12114}
12115
paul94f2b392005-06-28 12:44:16 +000012116static int
paulfd79ac92004-10-13 05:06:08 +000012117bgp_distance_unset (struct vty *vty, const char *distance_str,
12118 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000012119{
12120 int ret;
12121 struct prefix_ipv4 p;
12122 u_char distance;
12123 struct bgp_node *rn;
12124 struct bgp_distance *bdistance;
12125
12126 ret = str2prefix_ipv4 (ip_str, &p);
12127 if (ret == 0)
12128 {
12129 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12130 return CMD_WARNING;
12131 }
12132
12133 distance = atoi (distance_str);
12134
12135 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
12136 if (! rn)
12137 {
12138 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
12139 return CMD_WARNING;
12140 }
12141
12142 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010012143
12144 if (bdistance->distance != distance)
12145 {
12146 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
12147 return CMD_WARNING;
12148 }
12149
paul718e3742002-12-13 20:15:29 +000012150 if (bdistance->access_list)
12151 free (bdistance->access_list);
12152 bgp_distance_free (bdistance);
12153
12154 rn->info = NULL;
12155 bgp_unlock_node (rn);
12156 bgp_unlock_node (rn);
12157
12158 return CMD_SUCCESS;
12159}
12160
paul718e3742002-12-13 20:15:29 +000012161/* Apply BGP information to distance method. */
12162u_char
12163bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
12164{
12165 struct bgp_node *rn;
12166 struct prefix_ipv4 q;
12167 struct peer *peer;
12168 struct bgp_distance *bdistance;
12169 struct access_list *alist;
12170 struct bgp_static *bgp_static;
12171
12172 if (! bgp)
12173 return 0;
12174
12175 if (p->family != AF_INET)
12176 return 0;
12177
12178 peer = rinfo->peer;
12179
12180 if (peer->su.sa.sa_family != AF_INET)
12181 return 0;
12182
12183 memset (&q, 0, sizeof (struct prefix_ipv4));
12184 q.family = AF_INET;
12185 q.prefix = peer->su.sin.sin_addr;
12186 q.prefixlen = IPV4_MAX_BITLEN;
12187
12188 /* Check source address. */
12189 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
12190 if (rn)
12191 {
12192 bdistance = rn->info;
12193 bgp_unlock_node (rn);
12194
12195 if (bdistance->access_list)
12196 {
12197 alist = access_list_lookup (AFI_IP, bdistance->access_list);
12198 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
12199 return bdistance->distance;
12200 }
12201 else
12202 return bdistance->distance;
12203 }
12204
12205 /* Backdoor check. */
12206 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
12207 if (rn)
12208 {
12209 bgp_static = rn->info;
12210 bgp_unlock_node (rn);
12211
12212 if (bgp_static->backdoor)
12213 {
12214 if (bgp->distance_local)
12215 return bgp->distance_local;
12216 else
12217 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12218 }
12219 }
12220
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000012221 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000012222 {
12223 if (bgp->distance_ebgp)
12224 return bgp->distance_ebgp;
12225 return ZEBRA_EBGP_DISTANCE_DEFAULT;
12226 }
12227 else
12228 {
12229 if (bgp->distance_ibgp)
12230 return bgp->distance_ibgp;
12231 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12232 }
12233}
12234
12235DEFUN (bgp_distance,
12236 bgp_distance_cmd,
12237 "distance bgp <1-255> <1-255> <1-255>",
12238 "Define an administrative distance\n"
12239 "BGP distance\n"
12240 "Distance for routes external to the AS\n"
12241 "Distance for routes internal to the AS\n"
12242 "Distance for local routes\n")
12243{
12244 struct bgp *bgp;
12245
12246 bgp = vty->index;
12247
12248 bgp->distance_ebgp = atoi (argv[0]);
12249 bgp->distance_ibgp = atoi (argv[1]);
12250 bgp->distance_local = atoi (argv[2]);
12251 return CMD_SUCCESS;
12252}
12253
12254DEFUN (no_bgp_distance,
12255 no_bgp_distance_cmd,
12256 "no distance bgp <1-255> <1-255> <1-255>",
12257 NO_STR
12258 "Define an administrative distance\n"
12259 "BGP distance\n"
12260 "Distance for routes external to the AS\n"
12261 "Distance for routes internal to the AS\n"
12262 "Distance for local routes\n")
12263{
12264 struct bgp *bgp;
12265
12266 bgp = vty->index;
12267
12268 bgp->distance_ebgp= 0;
12269 bgp->distance_ibgp = 0;
12270 bgp->distance_local = 0;
12271 return CMD_SUCCESS;
12272}
12273
12274ALIAS (no_bgp_distance,
12275 no_bgp_distance2_cmd,
12276 "no distance bgp",
12277 NO_STR
12278 "Define an administrative distance\n"
12279 "BGP distance\n")
12280
12281DEFUN (bgp_distance_source,
12282 bgp_distance_source_cmd,
12283 "distance <1-255> A.B.C.D/M",
12284 "Define an administrative distance\n"
12285 "Administrative distance\n"
12286 "IP source prefix\n")
12287{
12288 bgp_distance_set (vty, argv[0], argv[1], NULL);
12289 return CMD_SUCCESS;
12290}
12291
12292DEFUN (no_bgp_distance_source,
12293 no_bgp_distance_source_cmd,
12294 "no distance <1-255> A.B.C.D/M",
12295 NO_STR
12296 "Define an administrative distance\n"
12297 "Administrative distance\n"
12298 "IP source prefix\n")
12299{
12300 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12301 return CMD_SUCCESS;
12302}
12303
12304DEFUN (bgp_distance_source_access_list,
12305 bgp_distance_source_access_list_cmd,
12306 "distance <1-255> A.B.C.D/M WORD",
12307 "Define an administrative distance\n"
12308 "Administrative distance\n"
12309 "IP source prefix\n"
12310 "Access list name\n")
12311{
12312 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12313 return CMD_SUCCESS;
12314}
12315
12316DEFUN (no_bgp_distance_source_access_list,
12317 no_bgp_distance_source_access_list_cmd,
12318 "no distance <1-255> A.B.C.D/M WORD",
12319 NO_STR
12320 "Define an administrative distance\n"
12321 "Administrative distance\n"
12322 "IP source prefix\n"
12323 "Access list name\n")
12324{
12325 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12326 return CMD_SUCCESS;
12327}
David Lamparter6b0655a2014-06-04 06:53:35 +020012328
paul718e3742002-12-13 20:15:29 +000012329DEFUN (bgp_damp_set,
12330 bgp_damp_set_cmd,
12331 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12332 "BGP Specific commands\n"
12333 "Enable route-flap dampening\n"
12334 "Half-life time for the penalty\n"
12335 "Value to start reusing a route\n"
12336 "Value to start suppressing a route\n"
12337 "Maximum duration to suppress a stable route\n")
12338{
12339 struct bgp *bgp;
12340 int half = DEFAULT_HALF_LIFE * 60;
12341 int reuse = DEFAULT_REUSE;
12342 int suppress = DEFAULT_SUPPRESS;
12343 int max = 4 * half;
12344
12345 if (argc == 4)
12346 {
12347 half = atoi (argv[0]) * 60;
12348 reuse = atoi (argv[1]);
12349 suppress = atoi (argv[2]);
12350 max = atoi (argv[3]) * 60;
12351 }
12352 else if (argc == 1)
12353 {
12354 half = atoi (argv[0]) * 60;
12355 max = 4 * half;
12356 }
12357
12358 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012359
12360 if (suppress < reuse)
12361 {
12362 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12363 VTY_NEWLINE);
12364 return 0;
12365 }
12366
paul718e3742002-12-13 20:15:29 +000012367 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12368 half, reuse, suppress, max);
12369}
12370
12371ALIAS (bgp_damp_set,
12372 bgp_damp_set2_cmd,
12373 "bgp dampening <1-45>",
12374 "BGP Specific commands\n"
12375 "Enable route-flap dampening\n"
12376 "Half-life time for the penalty\n")
12377
12378ALIAS (bgp_damp_set,
12379 bgp_damp_set3_cmd,
12380 "bgp dampening",
12381 "BGP Specific commands\n"
12382 "Enable route-flap dampening\n")
12383
12384DEFUN (bgp_damp_unset,
12385 bgp_damp_unset_cmd,
12386 "no bgp dampening",
12387 NO_STR
12388 "BGP Specific commands\n"
12389 "Enable route-flap dampening\n")
12390{
12391 struct bgp *bgp;
12392
12393 bgp = vty->index;
12394 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12395}
12396
12397ALIAS (bgp_damp_unset,
12398 bgp_damp_unset2_cmd,
12399 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12400 NO_STR
12401 "BGP Specific commands\n"
12402 "Enable route-flap dampening\n"
12403 "Half-life time for the penalty\n"
12404 "Value to start reusing a route\n"
12405 "Value to start suppressing a route\n"
12406 "Maximum duration to suppress a stable route\n")
12407
12408DEFUN (show_ip_bgp_dampened_paths,
12409 show_ip_bgp_dampened_paths_cmd,
12410 "show ip bgp dampened-paths",
12411 SHOW_STR
12412 IP_STR
12413 BGP_STR
12414 "Display paths suppressed due to dampening\n")
12415{
ajs5a646652004-11-05 01:25:55 +000012416 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12417 NULL);
paul718e3742002-12-13 20:15:29 +000012418}
12419
Balaji3921cc52015-05-16 23:12:17 +053012420ALIAS (show_ip_bgp_dampened_paths,
12421 show_ip_bgp_damp_dampened_paths_cmd,
12422 "show ip bgp dampening dampened-paths",
12423 SHOW_STR
12424 IP_STR
12425 BGP_STR
12426 "Display detailed information about dampening\n"
12427 "Display paths suppressed due to dampening\n")
12428
paul718e3742002-12-13 20:15:29 +000012429DEFUN (show_ip_bgp_flap_statistics,
12430 show_ip_bgp_flap_statistics_cmd,
12431 "show ip bgp flap-statistics",
12432 SHOW_STR
12433 IP_STR
12434 BGP_STR
12435 "Display flap statistics of routes\n")
12436{
ajs5a646652004-11-05 01:25:55 +000012437 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12438 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012439}
David Lamparter6b0655a2014-06-04 06:53:35 +020012440
Balaji3921cc52015-05-16 23:12:17 +053012441ALIAS (show_ip_bgp_flap_statistics,
12442 show_ip_bgp_damp_flap_statistics_cmd,
12443 "show ip bgp dampening flap-statistics",
12444 SHOW_STR
12445 IP_STR
12446 BGP_STR
12447 "Display detailed information about dampening\n"
12448 "Display flap statistics of routes\n")
12449
paul718e3742002-12-13 20:15:29 +000012450/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012451static int
paulfd79ac92004-10-13 05:06:08 +000012452bgp_clear_damp_route (struct vty *vty, const char *view_name,
12453 const char *ip_str, afi_t afi, safi_t safi,
12454 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012455{
12456 int ret;
12457 struct prefix match;
12458 struct bgp_node *rn;
12459 struct bgp_node *rm;
12460 struct bgp_info *ri;
12461 struct bgp_info *ri_temp;
12462 struct bgp *bgp;
12463 struct bgp_table *table;
12464
12465 /* BGP structure lookup. */
12466 if (view_name)
12467 {
12468 bgp = bgp_lookup_by_name (view_name);
12469 if (bgp == NULL)
12470 {
12471 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12472 return CMD_WARNING;
12473 }
12474 }
12475 else
12476 {
12477 bgp = bgp_get_default ();
12478 if (bgp == NULL)
12479 {
12480 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12481 return CMD_WARNING;
12482 }
12483 }
12484
12485 /* Check IP address argument. */
12486 ret = str2prefix (ip_str, &match);
12487 if (! ret)
12488 {
12489 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12490 return CMD_WARNING;
12491 }
12492
12493 match.family = afi2family (afi);
12494
Lou Berger298cc2f2016-01-12 13:42:02 -050012495 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000012496 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012497 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000012498 {
12499 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12500 continue;
12501
12502 if ((table = rn->info) != NULL)
12503 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012504 {
12505 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12506 {
12507 ri = rm->info;
12508 while (ri)
12509 {
12510 if (ri->extra && ri->extra->damp_info)
12511 {
12512 ri_temp = ri->next;
12513 bgp_damp_info_free (ri->extra->damp_info, 1);
12514 ri = ri_temp;
12515 }
12516 else
12517 ri = ri->next;
12518 }
12519 }
12520
12521 bgp_unlock_node (rm);
12522 }
paul718e3742002-12-13 20:15:29 +000012523 }
12524 }
12525 else
12526 {
12527 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012528 {
12529 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12530 {
12531 ri = rn->info;
12532 while (ri)
12533 {
12534 if (ri->extra && ri->extra->damp_info)
12535 {
12536 ri_temp = ri->next;
12537 bgp_damp_info_free (ri->extra->damp_info, 1);
12538 ri = ri_temp;
12539 }
12540 else
12541 ri = ri->next;
12542 }
12543 }
12544
12545 bgp_unlock_node (rn);
12546 }
paul718e3742002-12-13 20:15:29 +000012547 }
12548
12549 return CMD_SUCCESS;
12550}
12551
12552DEFUN (clear_ip_bgp_dampening,
12553 clear_ip_bgp_dampening_cmd,
12554 "clear ip bgp dampening",
12555 CLEAR_STR
12556 IP_STR
12557 BGP_STR
12558 "Clear route flap dampening information\n")
12559{
12560 bgp_damp_info_clean ();
12561 return CMD_SUCCESS;
12562}
12563
12564DEFUN (clear_ip_bgp_dampening_prefix,
12565 clear_ip_bgp_dampening_prefix_cmd,
12566 "clear ip bgp dampening A.B.C.D/M",
12567 CLEAR_STR
12568 IP_STR
12569 BGP_STR
12570 "Clear route flap dampening information\n"
12571 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12572{
12573 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12574 SAFI_UNICAST, NULL, 1);
12575}
12576
12577DEFUN (clear_ip_bgp_dampening_address,
12578 clear_ip_bgp_dampening_address_cmd,
12579 "clear ip bgp dampening A.B.C.D",
12580 CLEAR_STR
12581 IP_STR
12582 BGP_STR
12583 "Clear route flap dampening information\n"
12584 "Network to clear damping information\n")
12585{
12586 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12587 SAFI_UNICAST, NULL, 0);
12588}
12589
12590DEFUN (clear_ip_bgp_dampening_address_mask,
12591 clear_ip_bgp_dampening_address_mask_cmd,
12592 "clear ip bgp dampening A.B.C.D A.B.C.D",
12593 CLEAR_STR
12594 IP_STR
12595 BGP_STR
12596 "Clear route flap dampening information\n"
12597 "Network to clear damping information\n"
12598 "Network mask\n")
12599{
12600 int ret;
12601 char prefix_str[BUFSIZ];
12602
12603 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12604 if (! ret)
12605 {
12606 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12607 return CMD_WARNING;
12608 }
12609
12610 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12611 SAFI_UNICAST, NULL, 0);
12612}
David Lamparter6b0655a2014-06-04 06:53:35 +020012613
Lou Berger298cc2f2016-01-12 13:42:02 -050012614/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000012615static int
paul718e3742002-12-13 20:15:29 +000012616bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12617 afi_t afi, safi_t safi, int *write)
12618{
12619 struct bgp_node *prn;
12620 struct bgp_node *rn;
12621 struct bgp_table *table;
12622 struct prefix *p;
12623 struct prefix_rd *prd;
12624 struct bgp_static *bgp_static;
12625 u_int32_t label;
12626 char buf[SU_ADDRSTRLEN];
12627 char rdbuf[RD_ADDRSTRLEN];
12628
12629 /* Network configuration. */
12630 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12631 if ((table = prn->info) != NULL)
12632 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12633 if ((bgp_static = rn->info) != NULL)
12634 {
12635 p = &rn->p;
12636 prd = (struct prefix_rd *) &prn->p;
12637
12638 /* "address-family" display. */
12639 bgp_config_write_family_header (vty, afi, safi, write);
12640
12641 /* "network" configuration display. */
12642 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12643 label = decode_label (bgp_static->tag);
12644
12645 vty_out (vty, " network %s/%d rd %s tag %d",
12646 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12647 p->prefixlen,
12648 rdbuf, label);
12649 vty_out (vty, "%s", VTY_NEWLINE);
12650 }
12651 return 0;
12652}
12653
12654/* Configuration of static route announcement and aggregate
12655 information. */
12656int
12657bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12658 afi_t afi, safi_t safi, int *write)
12659{
12660 struct bgp_node *rn;
12661 struct prefix *p;
12662 struct bgp_static *bgp_static;
12663 struct bgp_aggregate *bgp_aggregate;
12664 char buf[SU_ADDRSTRLEN];
12665
Lou Berger298cc2f2016-01-12 13:42:02 -050012666 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000012667 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12668
12669 /* Network configuration. */
12670 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12671 if ((bgp_static = rn->info) != NULL)
12672 {
12673 p = &rn->p;
12674
12675 /* "address-family" display. */
12676 bgp_config_write_family_header (vty, afi, safi, write);
12677
12678 /* "network" configuration display. */
12679 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12680 {
12681 u_int32_t destination;
12682 struct in_addr netmask;
12683
12684 destination = ntohl (p->u.prefix4.s_addr);
12685 masklen2ip (p->prefixlen, &netmask);
12686 vty_out (vty, " network %s",
12687 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12688
12689 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12690 || (IN_CLASSB (destination) && p->prefixlen == 16)
12691 || (IN_CLASSA (destination) && p->prefixlen == 8)
12692 || p->u.prefix4.s_addr == 0)
12693 {
12694 /* Natural mask is not display. */
12695 }
12696 else
12697 vty_out (vty, " mask %s", inet_ntoa (netmask));
12698 }
12699 else
12700 {
12701 vty_out (vty, " network %s/%d",
12702 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12703 p->prefixlen);
12704 }
12705
12706 if (bgp_static->rmap.name)
12707 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012708 else
12709 {
12710 if (bgp_static->backdoor)
12711 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012712 }
paul718e3742002-12-13 20:15:29 +000012713
12714 vty_out (vty, "%s", VTY_NEWLINE);
12715 }
12716
12717 /* Aggregate-address configuration. */
12718 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12719 if ((bgp_aggregate = rn->info) != NULL)
12720 {
12721 p = &rn->p;
12722
12723 /* "address-family" display. */
12724 bgp_config_write_family_header (vty, afi, safi, write);
12725
12726 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12727 {
12728 struct in_addr netmask;
12729
12730 masklen2ip (p->prefixlen, &netmask);
12731 vty_out (vty, " aggregate-address %s %s",
12732 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12733 inet_ntoa (netmask));
12734 }
12735 else
12736 {
12737 vty_out (vty, " aggregate-address %s/%d",
12738 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12739 p->prefixlen);
12740 }
12741
12742 if (bgp_aggregate->as_set)
12743 vty_out (vty, " as-set");
12744
12745 if (bgp_aggregate->summary_only)
12746 vty_out (vty, " summary-only");
12747
12748 vty_out (vty, "%s", VTY_NEWLINE);
12749 }
12750
12751 return 0;
12752}
12753
12754int
12755bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12756{
12757 struct bgp_node *rn;
12758 struct bgp_distance *bdistance;
12759
12760 /* Distance configuration. */
12761 if (bgp->distance_ebgp
12762 && bgp->distance_ibgp
12763 && bgp->distance_local
12764 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12765 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12766 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12767 vty_out (vty, " distance bgp %d %d %d%s",
12768 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12769 VTY_NEWLINE);
12770
12771 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12772 if ((bdistance = rn->info) != NULL)
12773 {
12774 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12775 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12776 bdistance->access_list ? bdistance->access_list : "",
12777 VTY_NEWLINE);
12778 }
12779
12780 return 0;
12781}
12782
12783/* Allocate routing table structure and install commands. */
12784void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012785bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012786{
12787 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012788 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012789
12790 /* IPv4 BGP commands. */
12791 install_element (BGP_NODE, &bgp_network_cmd);
12792 install_element (BGP_NODE, &bgp_network_mask_cmd);
12793 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12794 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12795 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12796 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12797 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12798 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12799 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12800 install_element (BGP_NODE, &no_bgp_network_cmd);
12801 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12802 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12803 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12804 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12805 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12806 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12807 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12808 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12809
12810 install_element (BGP_NODE, &aggregate_address_cmd);
12811 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12812 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12813 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12814 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12815 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12816 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12817 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12818 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12819 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12820 install_element (BGP_NODE, &no_aggregate_address_cmd);
12821 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12822 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12823 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12824 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12825 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12826 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12827 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12828 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12829 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12830
12831 /* IPv4 unicast configuration. */
12832 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12833 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12834 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12835 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12836 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12837 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012838 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012839 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12840 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12841 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12842 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12843 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012844
paul718e3742002-12-13 20:15:29 +000012845 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12846 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12847 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12848 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12849 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12850 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12851 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12852 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12853 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12854 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12855 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12856 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12857 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12858 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12859 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12860 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12861 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12862 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12863 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12864 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12865
12866 /* IPv4 multicast configuration. */
12867 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12868 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12869 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12870 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12871 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12872 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12873 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12874 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12875 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12876 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12877 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12878 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12879 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12880 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12881 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12882 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12883 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12884 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12885 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12886 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12887 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12888 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12889 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12890 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12891 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12892 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12893 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12894 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12895 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12896 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12897 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12898 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12899
12900 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12901 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012902 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012903 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12904 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012905 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012906 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12907 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12908 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12909 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012910 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012911 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12912 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12913 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12914 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12915 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12916 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12917 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12918 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12919 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12920 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12921 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12922 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12923 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12924 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12925 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12926 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12927 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12928 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12929 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12930 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12931 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12932 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12933 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12934 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12935 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012936 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12937 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12938 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12939 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12940 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012941 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12942 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12943 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12944 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12945 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12946 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12947 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12948 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12949 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12950 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12951 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12952 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12953 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12954 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12955 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12956 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12957 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12958 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012959 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012960 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12961 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12962 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12963 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012964 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012965 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012966 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012967 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012968 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012969 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012970 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012971 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12972 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012973 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012974 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12975 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012976 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012977 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012978 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012979 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012980 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012981 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012982 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012983 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12984 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012985 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012986 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012987 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012988 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012989 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012990 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012991 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12992 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012993 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012994 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012995 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012996 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012997 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012998 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012999
13000 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
13001 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
13002 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013003 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013004 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13005 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
13006 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013007 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013008 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13009 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13010 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
13011 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
13012 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
13013 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
13014 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
13015 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
13016 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
13017 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
13018 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
13019 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013020 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13021 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
13022 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
13023 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
13024 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013025 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
13026 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
13027 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
13028 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
13029 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13030 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13031 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13032 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13033 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013034 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013035 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013036 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013037 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013038 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013039 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013040 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013041
13042 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
13043 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013044 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013045 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
13046 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013047 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013048 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
13049 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
13050 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
13051 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013052 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013053 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
13054 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
13055 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
13056 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
13057 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
13058 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
13059 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
13060 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
13061 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
13062 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
13063 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
13064 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
13065 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
13066 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
13067 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
13068 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
13069 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
13070 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
13071 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
13072 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
13073 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
13074 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
13075 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
13076 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
13077 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013078 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
13079 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
13080 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
13081 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
13082 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000013083 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
13084 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
13085 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
13086 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
13087 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
13088 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
13089 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
13090 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
13091 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
13092 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
13093 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
13094 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
13095 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
13096 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
13097 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
13098 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
13099 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
13100 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013101 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000013102 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
13103 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
13104 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
13105 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013106 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000013107 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013108 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000013109 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013110 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000013111 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013112 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000013113 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
13114 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013115 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000013116 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013117 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000013118 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013119 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000013120 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013121 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
13122 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000013123 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013124 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000013125 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013126 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000013127 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
13128 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013129 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013130 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013131 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013132 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013133 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013134 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010013135 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13136 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013137 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013138 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013139 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013140 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013141 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013142 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013143
13144 /* BGP dampening clear commands */
13145 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13146 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13147 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13148 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13149
Paul Jakmaff7924f2006-09-04 01:10:36 +000013150 /* prefix count */
13151 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
13152 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
13153 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000013154#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000013155 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13156
paul718e3742002-12-13 20:15:29 +000013157 /* New config IPv6 BGP commands. */
13158 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13159 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
13160 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13161 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13162
13163 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13164 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13165 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13166 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
13167
G.Balaji73bfe0b2011-09-23 22:36:20 +053013168 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13169 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
13170
paul718e3742002-12-13 20:15:29 +000013171 /* Old config IPv6 BGP commands. */
13172 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13173 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13174
13175 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13176 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13177 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13178 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13179
13180 install_element (VIEW_NODE, &show_bgp_cmd);
13181 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013182 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013183 install_element (VIEW_NODE, &show_bgp_route_cmd);
13184 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013185 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013186 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
13187 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013188 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013189 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
13190 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
13191 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
13192 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
13193 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
13194 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
13195 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
13196 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
13197 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
13198 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
13199 install_element (VIEW_NODE, &show_bgp_community_cmd);
13200 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
13201 install_element (VIEW_NODE, &show_bgp_community2_cmd);
13202 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
13203 install_element (VIEW_NODE, &show_bgp_community3_cmd);
13204 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
13205 install_element (VIEW_NODE, &show_bgp_community4_cmd);
13206 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
13207 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
13208 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
13209 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
13210 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
13211 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
13212 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
13213 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
13214 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13215 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
13216 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
13217 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
13218 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13219 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
13220 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13221 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
13222 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13223 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
13224 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13225 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
13226 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13227 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13228 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013229 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
13230 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13231 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
13232 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013233 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013234 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013235 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013236 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013237 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013238 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013239 install_element (VIEW_NODE, &show_bgp_view_cmd);
13240 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
13241 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
13242 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
13243 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
13244 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
13245 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13246 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13247 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13248 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13249 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
13250 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13251 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13252 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13253 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
13254 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13255 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
13256 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013257 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013258 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013259 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013260 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013261 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013262 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013263
13264 /* Restricted:
13265 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13266 */
13267 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
13268 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013269 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013270 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
13271 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013272 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013273 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
13274 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
13275 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
13276 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
13277 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
13278 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
13279 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
13280 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
13281 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
13282 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
13283 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
13284 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13285 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13286 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13287 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13288 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13289 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013290 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013291 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013292 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013293 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
13294 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13295 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13296 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13297 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13298 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13299 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013300 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013301 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013302 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013303
13304 install_element (ENABLE_NODE, &show_bgp_cmd);
13305 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013306 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013307 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13308 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013309 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013310 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13311 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013312 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013313 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13314 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13315 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13316 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13317 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13318 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13319 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13320 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13321 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13322 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13323 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13324 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13325 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13326 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13327 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13328 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13329 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13330 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13331 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13332 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13333 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13334 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13335 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13336 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13337 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13338 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13339 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13340 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13341 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13342 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13343 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13344 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13345 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13346 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13347 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13348 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13349 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13350 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13351 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13352 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013353 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13354 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13355 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13356 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013357 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013358 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013359 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013360 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013361 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013362 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013363 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13364 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13365 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13366 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13367 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13368 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13369 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13370 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13371 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13372 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13373 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13374 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13375 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13376 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13377 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13378 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13379 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13380 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013381 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013382 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013383 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013384 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013385 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013386 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013387
13388 /* Statistics */
13389 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger298cc2f2016-01-12 13:42:02 -050013390 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013391 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
Lou Berger298cc2f2016-01-12 13:42:02 -050013392 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013393
paul718e3742002-12-13 20:15:29 +000013394 /* old command */
13395 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13396 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13397 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13398 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13399 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13400 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13401 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13402 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13403 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13404 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13405 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13406 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13407 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13408 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13409 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13410 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13411 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13412 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13413 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13414 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13415 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13416 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13417 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13418 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13419 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13420 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13421 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13422 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13423 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13424 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13425 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13426 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13427 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13428 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13429 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13430 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013431
paul718e3742002-12-13 20:15:29 +000013432 /* old command */
13433 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13434 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13435 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13436 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13437 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13438 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13439 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13440 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13441 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13442 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13443 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13444 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13445 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13446 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13447 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13448 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13449 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13450 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13451 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13452 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13453 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13454 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13455 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13456 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13457 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13458 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13459 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13460 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13461 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13462 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13463 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13464 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13465 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13466 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13467 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13468 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13469
13470 /* old command */
13471 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13472 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13473 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13474 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13475
13476 /* old command */
13477 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13478 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13479 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13480 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13481
13482 /* old command */
13483 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13484 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13485 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13486 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13487#endif /* HAVE_IPV6 */
13488
13489 install_element (BGP_NODE, &bgp_distance_cmd);
13490 install_element (BGP_NODE, &no_bgp_distance_cmd);
13491 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13492 install_element (BGP_NODE, &bgp_distance_source_cmd);
13493 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13494 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13495 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13496
13497 install_element (BGP_NODE, &bgp_damp_set_cmd);
13498 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13499 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13500 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13501 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13502 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13503 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13504 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13505 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13506 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013507
13508 /* Deprecated AS-Pathlimit commands */
13509 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13510 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13511 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13512 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13513 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13514 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13515
13516 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13517 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13518 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13519 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13520 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13521 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13522
13523 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13524 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13525 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13526 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13527 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13528 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13529
13530 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13531 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13532 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13533 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13534 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13535 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13536
13537 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13538 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13539 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13540 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13541 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13542 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13543
13544 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13545 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13546 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13547 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13548 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13549 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013550
13551#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013552 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13553 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013554#endif
paul718e3742002-12-13 20:15:29 +000013555}
Chris Caputo228da422009-07-18 05:44:03 +000013556
13557void
13558bgp_route_finish (void)
13559{
13560 bgp_table_unlock (bgp_distance_table);
13561 bgp_distance_table = NULL;
13562}