blob: c28de7be0d889a0c805178d4dd82638b0fbda9a7 [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. */
Lou Berger35c36862016-01-12 13:42:06 -05006953DEFUN (show_bgp_ipv4_safi,
6954 show_bgp_ipv4_safi_cmd,
6955 "show bgp ipv4 (unicast|multicast)",
paul718e3742002-12-13 20:15:29 +00006956 SHOW_STR
paul718e3742002-12-13 20:15:29 +00006957 BGP_STR
6958 "Address family\n"
6959 "Address Family modifier\n"
6960 "Address Family modifier\n")
6961{
6962 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006963 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6964 NULL);
paul718e3742002-12-13 20:15:29 +00006965
ajs5a646652004-11-05 01:25:55 +00006966 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006967}
6968
Lou Berger35c36862016-01-12 13:42:06 -05006969DEFUN (show_bgp_ipv4_safi_route,
6970 show_bgp_ipv4_safi_route_cmd,
6971 "show bgp ipv4 (unicast|multicast) A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04006972 SHOW_STR
6973 BGP_STR
6974 "Address family\n"
6975 "Address Family modifier\n"
paul718e3742002-12-13 20:15:29 +00006976 "Address Family modifier\n"
6977 "Network in the BGP routing table to display\n")
6978{
6979 if (strncmp (argv[0], "m", 1) == 0)
6980 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6981
6982 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6983}
6984
Lou Berger35c36862016-01-12 13:42:06 -05006985DEFUN (show_bgp_ipv4_vpn_route,
6986 show_bgp_ipv4_vpn_route_cmd,
6987 "show bgp ipv4 vpn A.B.C.D",
Michael Lambert95cbbd22010-07-23 14:43:04 -04006988 SHOW_STR
6989 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05006990 "Address Family\n"
6991 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00006992 "Network in the BGP routing table to display\n")
6993{
6994 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6995}
6996
Lou Berger35c36862016-01-12 13:42:06 -05006997#ifdef HAVE_IPV6
6998DEFUN (show_bgp_ipv6_vpn_route,
6999 show_bgp_ipv6_vpn_route_cmd,
7000 "show bgp ipv6 vpn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007001 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007002 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007003 "Address Family\n"
7004 "Display VPN NLRI specific information\n"
7005 "Network in the BGP routing table to display\n")
7006{
7007 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 0);
7008}
7009#endif
7010
7011DEFUN (show_bgp_ipv4_vpn_rd_route,
7012 show_bgp_ipv4_vpn_rd_route_cmd,
7013 "show bgp ipv4 vpn rd ASN:nn_or_IP-address:nn A.B.C.D",
7014 SHOW_STR
7015 BGP_STR
7016 IP_STR
7017 "Display VPN NLRI specific information\n"
paul718e3742002-12-13 20:15:29 +00007018 "Display information for a route distinguisher\n"
7019 "VPN Route Distinguisher\n"
7020 "Network in the BGP routing table to display\n")
7021{
7022 int ret;
7023 struct prefix_rd prd;
7024
7025 ret = str2prefix_rd (argv[0], &prd);
7026 if (! ret)
7027 {
7028 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7029 return CMD_WARNING;
7030 }
7031 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
7032}
7033
Lou Berger35c36862016-01-12 13:42:06 -05007034DEFUN (show_bgp_ipv6_vpn_rd_route,
7035 show_bgp_ipv6_vpn_rd_route_cmd,
7036 "show bgp ipv6 vpn rd ASN:nn_or_IP-address:nn X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007037 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007038 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007039 "Address Family\n"
7040 "Display VPN NLRI specific information\n"
7041 "Display information for a route distinguisher\n"
7042 "VPN Route Distinguisher\n"
7043 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007044{
Lou Berger35c36862016-01-12 13:42:06 -05007045 int ret;
7046 struct prefix_rd prd;
7047
7048 ret = str2prefix_rd (argv[0], &prd);
7049 if (! ret)
7050 {
7051 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7052 return CMD_WARNING;
7053 }
7054 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MPLS_VPN, &prd, 0);
paul718e3742002-12-13 20:15:29 +00007055}
7056
7057DEFUN (show_ip_bgp_ipv4_prefix,
7058 show_ip_bgp_ipv4_prefix_cmd,
7059 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
7060 SHOW_STR
7061 IP_STR
7062 BGP_STR
7063 "Address family\n"
7064 "Address Family modifier\n"
7065 "Address Family modifier\n"
7066 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7067{
7068 if (strncmp (argv[0], "m", 1) == 0)
7069 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
7070
7071 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
7072}
7073
Michael Lambert95cbbd22010-07-23 14:43:04 -04007074ALIAS (show_ip_bgp_ipv4_prefix,
7075 show_bgp_ipv4_safi_prefix_cmd,
7076 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
7077 SHOW_STR
7078 BGP_STR
7079 "Address family\n"
7080 "Address Family modifier\n"
7081 "Address Family modifier\n"
7082 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7083
paul718e3742002-12-13 20:15:29 +00007084DEFUN (show_ip_bgp_vpnv4_all_prefix,
7085 show_ip_bgp_vpnv4_all_prefix_cmd,
7086 "show ip bgp vpnv4 all A.B.C.D/M",
7087 SHOW_STR
7088 IP_STR
7089 BGP_STR
7090 "Display VPNv4 NLRI specific information\n"
7091 "Display information about all VPNv4 NLRIs\n"
7092 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7093{
7094 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
7095}
7096
7097DEFUN (show_ip_bgp_vpnv4_rd_prefix,
7098 show_ip_bgp_vpnv4_rd_prefix_cmd,
7099 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
7100 SHOW_STR
7101 IP_STR
7102 BGP_STR
7103 "Display VPNv4 NLRI specific information\n"
7104 "Display information for a route distinguisher\n"
7105 "VPN Route Distinguisher\n"
7106 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7107{
7108 int ret;
7109 struct prefix_rd prd;
7110
7111 ret = str2prefix_rd (argv[0], &prd);
7112 if (! ret)
7113 {
7114 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
7115 return CMD_WARNING;
7116 }
7117 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
7118}
7119
7120DEFUN (show_ip_bgp_view,
7121 show_ip_bgp_view_cmd,
7122 "show ip bgp view WORD",
7123 SHOW_STR
7124 IP_STR
7125 BGP_STR
7126 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00007127 "View name\n")
paul718e3742002-12-13 20:15:29 +00007128{
paulbb46e942003-10-24 19:02:03 +00007129 struct bgp *bgp;
7130
7131 /* BGP structure lookup. */
7132 bgp = bgp_lookup_by_name (argv[0]);
7133 if (bgp == NULL)
7134 {
7135 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7136 return CMD_WARNING;
7137 }
7138
ajs5a646652004-11-05 01:25:55 +00007139 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00007140}
7141
Lou Berger35c36862016-01-12 13:42:06 -05007142DEFUN (show_bgp_ipv4_prefix,
7143 show_bgp_ipv4_prefix_cmd,
7144 "show bgp ipv4 A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007145 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007146 BGP_STR
paul718e3742002-12-13 20:15:29 +00007147 IP_STR
paul718e3742002-12-13 20:15:29 +00007148 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7149{
Lou Berger35c36862016-01-12 13:42:06 -05007150 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007151}
7152
Lou Berger35c36862016-01-12 13:42:06 -05007153DEFUN (show_bgp_ipv4_safi_prefix,
7154 show_bgp_ipv4_safi_prefix_cmd,
7155 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
Michael Lambert95cbbd22010-07-23 14:43:04 -04007156 SHOW_STR
7157 BGP_STR
7158 "Address family\n"
7159 "Address Family modifier\n"
Lou Berger35c36862016-01-12 13:42:06 -05007160 "Address Family modifier\n"
7161 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04007162{
7163 if (strncmp (argv[0], "m", 1) == 0)
Lou Berger35c36862016-01-12 13:42:06 -05007164 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007165
Lou Berger35c36862016-01-12 13:42:06 -05007166 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
Michael Lambert95cbbd22010-07-23 14:43:04 -04007167}
7168
Lou Berger35c36862016-01-12 13:42:06 -05007169DEFUN (show_bgp_ipv4_vpn_prefix,
7170 show_bgp_ipv4_vpn_prefix_cmd,
7171 "show bgp ipv4 vpn A.B.C.D/M",
paul718e3742002-12-13 20:15:29 +00007172 SHOW_STR
7173 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007174 IP_STR
7175 "Display VPN NLRI specific information\n"
7176 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paul718e3742002-12-13 20:15:29 +00007177{
Lou Berger35c36862016-01-12 13:42:06 -05007178 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007179}
7180
Lou Berger35c36862016-01-12 13:42:06 -05007181#ifdef HAVE_IPV6
7182DEFUN (show_bgp_ipv6_vpn_prefix,
7183 show_bgp_ipv6_vpn_prefix_cmd,
7184 "show bgp ipv6 vpn X:X::X:X/M",
7185 SHOW_STR
7186 BGP_STR
7187 "Address Family\n"
7188 "Display VPN NLRI specific information\n"
7189 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
7190{
7191 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MPLS_VPN, NULL, 1);
7192}
7193#endif
7194
paul718e3742002-12-13 20:15:29 +00007195ALIAS (show_bgp_route,
7196 show_bgp_ipv6_route_cmd,
7197 "show bgp ipv6 X:X::X:X",
7198 SHOW_STR
7199 BGP_STR
7200 "Address family\n"
7201 "Network in the BGP routing table to display\n")
7202
Michael Lambert95cbbd22010-07-23 14:43:04 -04007203DEFUN (show_bgp_ipv6_safi_route,
7204 show_bgp_ipv6_safi_route_cmd,
7205 "show bgp ipv6 (unicast|multicast) X:X::X:X",
7206 SHOW_STR
7207 BGP_STR
7208 "Address family\n"
7209 "Address Family modifier\n"
7210 "Address Family modifier\n"
7211 "Network in the BGP routing table to display\n")
7212{
7213 if (strncmp (argv[0], "m", 1) == 0)
7214 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7215
7216 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
7217}
7218
Lou Berger35c36862016-01-12 13:42:06 -05007219DEFUN (show_bgp_ipv6_route,
7220 show_bgp_ipv6_route_cmd,
7221 "show bgp ipv6 X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007222 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007223 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007224 "Address family\n"
paul718e3742002-12-13 20:15:29 +00007225 "Network in the BGP routing table to display\n")
7226{
7227 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
7228}
7229
Lou Berger35c36862016-01-12 13:42:06 -05007230DEFUN (show_bgp_ipv6_safi_route,
7231 show_bgp_ipv6_safi_route_cmd,
7232 "show bgp ipv6 (unicast|multicast) X:X::X:X",
paul718e3742002-12-13 20:15:29 +00007233 SHOW_STR
7234 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007235 "Address family\n"
7236 "Address Family modifier\n"
7237 "Address Family modifier\n"
7238 "Network in the BGP routing table to display\n")
paul718e3742002-12-13 20:15:29 +00007239{
Lou Berger35c36862016-01-12 13:42:06 -05007240 if (strncmp (argv[0], "m", 1) == 0)
7241 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7242
7243 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paul718e3742002-12-13 20:15:29 +00007244}
7245
Lou Berger35c36862016-01-12 13:42:06 -05007246/* new002 */
7247DEFUN (show_bgp_ipv6_prefix,
paul718e3742002-12-13 20:15:29 +00007248 show_bgp_ipv6_prefix_cmd,
7249 "show bgp ipv6 X:X::X:X/M",
7250 SHOW_STR
7251 BGP_STR
7252 "Address family\n"
Lou Berger35c36862016-01-12 13:42:06 -05007253 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7254{
7255 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
7256}
Michael Lambert95cbbd22010-07-23 14:43:04 -04007257DEFUN (show_bgp_ipv6_safi_prefix,
7258 show_bgp_ipv6_safi_prefix_cmd,
7259 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
7260 SHOW_STR
7261 BGP_STR
7262 "Address family\n"
7263 "Address Family modifier\n"
7264 "Address Family modifier\n"
7265 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7266{
7267 if (strncmp (argv[0], "m", 1) == 0)
7268 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7269
7270 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7271}
7272
paulbb46e942003-10-24 19:02:03 +00007273DEFUN (show_bgp_view,
Lou Berger35c36862016-01-12 13:42:06 -05007274 show_bgp_view_ipv6_cmd,
7275 "show bgp view WORD ipv6",
paulbb46e942003-10-24 19:02:03 +00007276 SHOW_STR
Lou Berger35c36862016-01-12 13:42:06 -05007277 BGP_STR
paulbb46e942003-10-24 19:02:03 +00007278 "BGP view\n"
Lou Berger35c36862016-01-12 13:42:06 -05007279 "View name\n"
7280 "Address family\n")
paulbb46e942003-10-24 19:02:03 +00007281{
7282 struct bgp *bgp;
7283
7284 /* BGP structure lookup. */
7285 bgp = bgp_lookup_by_name (argv[0]);
7286 if (bgp == NULL)
7287 {
7288 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7289 return CMD_WARNING;
7290 }
7291
ajs5a646652004-11-05 01:25:55 +00007292 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00007293}
paulbb46e942003-10-24 19:02:03 +00007294
7295DEFUN (show_bgp_view_route,
paulbb46e942003-10-24 19:02:03 +00007296 show_bgp_view_ipv6_route_cmd,
7297 "show bgp view WORD ipv6 X:X::X:X",
7298 SHOW_STR
7299 BGP_STR
7300 "BGP view\n"
7301 "View name\n"
7302 "Address family\n"
7303 "Network in the BGP routing table to display\n")
paulbb46e942003-10-24 19:02:03 +00007304{
Lou Berger35c36862016-01-12 13:42:06 -05007305 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
paulbb46e942003-10-24 19:02:03 +00007306}
7307
Lou Berger35c36862016-01-12 13:42:06 -05007308DEFUN (show_bgp_view_prefix,
paulbb46e942003-10-24 19:02:03 +00007309 show_bgp_view_ipv6_prefix_cmd,
7310 "show bgp view WORD ipv6 X:X::X:X/M",
7311 SHOW_STR
7312 BGP_STR
7313 "BGP view\n"
7314 "View name\n"
7315 "Address family\n"
7316 "IPv6 prefix <network>/<length>\n")
paul718e3742002-12-13 20:15:29 +00007317{
Lou Berger35c36862016-01-12 13:42:06 -05007318 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
paul718e3742002-12-13 20:15:29 +00007319}
7320
paul718e3742002-12-13 20:15:29 +00007321#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02007322
paul718e3742002-12-13 20:15:29 +00007323
paul94f2b392005-06-28 12:44:16 +00007324static int
paulfd79ac92004-10-13 05:06:08 +00007325bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007326 safi_t safi, enum bgp_show_type type)
7327{
7328 int i;
7329 struct buffer *b;
7330 char *regstr;
7331 int first;
7332 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007333 int rc;
paul718e3742002-12-13 20:15:29 +00007334
7335 first = 0;
7336 b = buffer_new (1024);
7337 for (i = 0; i < argc; i++)
7338 {
7339 if (first)
7340 buffer_putc (b, ' ');
7341 else
7342 {
7343 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7344 continue;
7345 first = 1;
7346 }
7347
7348 buffer_putstr (b, argv[i]);
7349 }
7350 buffer_putc (b, '\0');
7351
7352 regstr = buffer_getstr (b);
7353 buffer_free (b);
7354
7355 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007356 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007357 if (! regex)
7358 {
7359 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7360 VTY_NEWLINE);
7361 return CMD_WARNING;
7362 }
7363
ajs5a646652004-11-05 01:25:55 +00007364 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7365 bgp_regex_free (regex);
7366 return rc;
paul718e3742002-12-13 20:15:29 +00007367}
7368
7369DEFUN (show_ip_bgp_regexp,
7370 show_ip_bgp_regexp_cmd,
7371 "show ip bgp regexp .LINE",
7372 SHOW_STR
7373 IP_STR
7374 BGP_STR
7375 "Display routes matching the AS path regular expression\n"
7376 "A regular-expression to match the BGP AS paths\n")
7377{
7378 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7379 bgp_show_type_regexp);
7380}
7381
7382DEFUN (show_ip_bgp_flap_regexp,
7383 show_ip_bgp_flap_regexp_cmd,
7384 "show ip bgp flap-statistics regexp .LINE",
7385 SHOW_STR
7386 IP_STR
7387 BGP_STR
7388 "Display flap statistics of routes\n"
7389 "Display routes matching the AS path regular expression\n"
7390 "A regular-expression to match the BGP AS paths\n")
7391{
7392 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7393 bgp_show_type_flap_regexp);
7394}
7395
Balaji3921cc52015-05-16 23:12:17 +05307396ALIAS (show_ip_bgp_flap_regexp,
7397 show_ip_bgp_damp_flap_regexp_cmd,
7398 "show ip bgp dampening flap-statistics regexp .LINE",
7399 SHOW_STR
7400 IP_STR
7401 BGP_STR
7402 "Display detailed information about dampening\n"
7403 "Display flap statistics of routes\n"
7404 "Display routes matching the AS path regular expression\n"
7405 "A regular-expression to match the BGP AS paths\n")
7406
paul718e3742002-12-13 20:15:29 +00007407DEFUN (show_ip_bgp_ipv4_regexp,
7408 show_ip_bgp_ipv4_regexp_cmd,
7409 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7410 SHOW_STR
7411 IP_STR
7412 BGP_STR
7413 "Address family\n"
7414 "Address Family modifier\n"
7415 "Address Family modifier\n"
7416 "Display routes matching the AS path regular expression\n"
7417 "A regular-expression to match the BGP AS paths\n")
7418{
7419 if (strncmp (argv[0], "m", 1) == 0)
7420 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7421 bgp_show_type_regexp);
7422
7423 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7424 bgp_show_type_regexp);
7425}
7426
7427#ifdef HAVE_IPV6
7428DEFUN (show_bgp_regexp,
7429 show_bgp_regexp_cmd,
7430 "show bgp regexp .LINE",
7431 SHOW_STR
7432 BGP_STR
7433 "Display routes matching the AS path regular expression\n"
7434 "A regular-expression to match the BGP AS paths\n")
7435{
7436 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7437 bgp_show_type_regexp);
7438}
7439
7440ALIAS (show_bgp_regexp,
7441 show_bgp_ipv6_regexp_cmd,
7442 "show bgp ipv6 regexp .LINE",
7443 SHOW_STR
7444 BGP_STR
7445 "Address family\n"
7446 "Display routes matching the AS path regular expression\n"
7447 "A regular-expression to match the BGP AS paths\n")
7448
7449/* old command */
7450DEFUN (show_ipv6_bgp_regexp,
7451 show_ipv6_bgp_regexp_cmd,
7452 "show ipv6 bgp regexp .LINE",
7453 SHOW_STR
7454 IP_STR
7455 BGP_STR
7456 "Display routes matching the AS path regular expression\n"
7457 "A regular-expression to match the BGP AS paths\n")
7458{
7459 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7460 bgp_show_type_regexp);
7461}
7462
7463/* old command */
7464DEFUN (show_ipv6_mbgp_regexp,
7465 show_ipv6_mbgp_regexp_cmd,
7466 "show ipv6 mbgp regexp .LINE",
7467 SHOW_STR
7468 IP_STR
7469 BGP_STR
7470 "Display routes matching the AS path regular expression\n"
7471 "A regular-expression to match the MBGP AS paths\n")
7472{
7473 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7474 bgp_show_type_regexp);
7475}
7476#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007477
paul94f2b392005-06-28 12:44:16 +00007478static int
paulfd79ac92004-10-13 05:06:08 +00007479bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007480 safi_t safi, enum bgp_show_type type)
7481{
7482 struct prefix_list *plist;
7483
7484 plist = prefix_list_lookup (afi, prefix_list_str);
7485 if (plist == NULL)
7486 {
7487 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7488 prefix_list_str, VTY_NEWLINE);
7489 return CMD_WARNING;
7490 }
7491
ajs5a646652004-11-05 01:25:55 +00007492 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007493}
7494
Lou Berger35c36862016-01-12 13:42:06 -05007495DEFUN (show_bgp_ipv4_prefix_list,
7496 show_bgp_ipv4_prefix_list_cmd,
7497 "show bgp ipv4 prefix-list WORD",
paul718e3742002-12-13 20:15:29 +00007498 SHOW_STR
paul718e3742002-12-13 20:15:29 +00007499 BGP_STR
Lou Berger35c36862016-01-12 13:42:06 -05007500 IP_STR
paul718e3742002-12-13 20:15:29 +00007501 "Display routes conforming to the prefix-list\n"
7502 "IP prefix-list name\n")
7503{
7504 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7505 bgp_show_type_prefix_list);
7506}
7507
7508DEFUN (show_ip_bgp_flap_prefix_list,
7509 show_ip_bgp_flap_prefix_list_cmd,
7510 "show ip bgp flap-statistics prefix-list WORD",
7511 SHOW_STR
7512 IP_STR
7513 BGP_STR
7514 "Display flap statistics of routes\n"
7515 "Display routes conforming to the prefix-list\n"
7516 "IP prefix-list name\n")
7517{
7518 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7519 bgp_show_type_flap_prefix_list);
7520}
7521
Balaji3921cc52015-05-16 23:12:17 +05307522ALIAS (show_ip_bgp_flap_prefix_list,
7523 show_ip_bgp_damp_flap_prefix_list_cmd,
7524 "show ip bgp dampening flap-statistics prefix-list WORD",
7525 SHOW_STR
7526 IP_STR
7527 BGP_STR
7528 "Display detailed information about dampening\n"
7529 "Display flap statistics of routes\n"
7530 "Display routes conforming to the prefix-list\n"
7531 "IP prefix-list name\n")
7532
paul718e3742002-12-13 20:15:29 +00007533DEFUN (show_ip_bgp_ipv4_prefix_list,
7534 show_ip_bgp_ipv4_prefix_list_cmd,
7535 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7536 SHOW_STR
7537 IP_STR
7538 BGP_STR
7539 "Address family\n"
7540 "Address Family modifier\n"
7541 "Address Family modifier\n"
7542 "Display routes conforming to the prefix-list\n"
7543 "IP prefix-list name\n")
7544{
7545 if (strncmp (argv[0], "m", 1) == 0)
7546 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7547 bgp_show_type_prefix_list);
7548
7549 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7550 bgp_show_type_prefix_list);
7551}
7552
7553#ifdef HAVE_IPV6
7554DEFUN (show_bgp_prefix_list,
7555 show_bgp_prefix_list_cmd,
7556 "show bgp prefix-list WORD",
7557 SHOW_STR
7558 BGP_STR
7559 "Display routes conforming to the prefix-list\n"
7560 "IPv6 prefix-list name\n")
7561{
7562 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7563 bgp_show_type_prefix_list);
7564}
7565
7566ALIAS (show_bgp_prefix_list,
7567 show_bgp_ipv6_prefix_list_cmd,
7568 "show bgp ipv6 prefix-list WORD",
7569 SHOW_STR
7570 BGP_STR
7571 "Address family\n"
7572 "Display routes conforming to the prefix-list\n"
7573 "IPv6 prefix-list name\n")
7574
7575/* old command */
7576DEFUN (show_ipv6_bgp_prefix_list,
7577 show_ipv6_bgp_prefix_list_cmd,
7578 "show ipv6 bgp prefix-list WORD",
7579 SHOW_STR
7580 IPV6_STR
7581 BGP_STR
7582 "Display routes matching the prefix-list\n"
7583 "IPv6 prefix-list name\n")
7584{
7585 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7586 bgp_show_type_prefix_list);
7587}
7588
7589/* old command */
7590DEFUN (show_ipv6_mbgp_prefix_list,
7591 show_ipv6_mbgp_prefix_list_cmd,
7592 "show ipv6 mbgp prefix-list WORD",
7593 SHOW_STR
7594 IPV6_STR
7595 MBGP_STR
7596 "Display routes matching the prefix-list\n"
7597 "IPv6 prefix-list name\n")
7598{
7599 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7600 bgp_show_type_prefix_list);
7601}
7602#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007603
paul94f2b392005-06-28 12:44:16 +00007604static int
paulfd79ac92004-10-13 05:06:08 +00007605bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007606 safi_t safi, enum bgp_show_type type)
7607{
7608 struct as_list *as_list;
7609
7610 as_list = as_list_lookup (filter);
7611 if (as_list == NULL)
7612 {
7613 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7614 return CMD_WARNING;
7615 }
7616
ajs5a646652004-11-05 01:25:55 +00007617 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007618}
7619
7620DEFUN (show_ip_bgp_filter_list,
7621 show_ip_bgp_filter_list_cmd,
7622 "show ip bgp filter-list WORD",
7623 SHOW_STR
7624 IP_STR
7625 BGP_STR
7626 "Display routes conforming to the filter-list\n"
7627 "Regular expression access list name\n")
7628{
7629 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7630 bgp_show_type_filter_list);
7631}
7632
7633DEFUN (show_ip_bgp_flap_filter_list,
7634 show_ip_bgp_flap_filter_list_cmd,
7635 "show ip bgp flap-statistics filter-list WORD",
7636 SHOW_STR
7637 IP_STR
7638 BGP_STR
7639 "Display flap statistics of routes\n"
7640 "Display routes conforming to the filter-list\n"
7641 "Regular expression access list name\n")
7642{
7643 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7644 bgp_show_type_flap_filter_list);
7645}
7646
Balaji3921cc52015-05-16 23:12:17 +05307647ALIAS (show_ip_bgp_flap_filter_list,
7648 show_ip_bgp_damp_flap_filter_list_cmd,
7649 "show ip bgp dampening flap-statistics filter-list WORD",
7650 SHOW_STR
7651 IP_STR
7652 BGP_STR
7653 "Display detailed information about dampening\n"
7654 "Display flap statistics of routes\n"
7655 "Display routes conforming to the filter-list\n"
7656 "Regular expression access list name\n")
7657
paul718e3742002-12-13 20:15:29 +00007658DEFUN (show_ip_bgp_ipv4_filter_list,
7659 show_ip_bgp_ipv4_filter_list_cmd,
7660 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7661 SHOW_STR
7662 IP_STR
7663 BGP_STR
7664 "Address family\n"
7665 "Address Family modifier\n"
7666 "Address Family modifier\n"
7667 "Display routes conforming to the filter-list\n"
7668 "Regular expression access list name\n")
7669{
7670 if (strncmp (argv[0], "m", 1) == 0)
7671 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7672 bgp_show_type_filter_list);
7673
7674 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7675 bgp_show_type_filter_list);
7676}
7677
7678#ifdef HAVE_IPV6
7679DEFUN (show_bgp_filter_list,
7680 show_bgp_filter_list_cmd,
7681 "show bgp filter-list WORD",
7682 SHOW_STR
7683 BGP_STR
7684 "Display routes conforming to the filter-list\n"
7685 "Regular expression access list name\n")
7686{
7687 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7688 bgp_show_type_filter_list);
7689}
7690
7691ALIAS (show_bgp_filter_list,
7692 show_bgp_ipv6_filter_list_cmd,
7693 "show bgp ipv6 filter-list WORD",
7694 SHOW_STR
7695 BGP_STR
7696 "Address family\n"
7697 "Display routes conforming to the filter-list\n"
7698 "Regular expression access list name\n")
7699
7700/* old command */
7701DEFUN (show_ipv6_bgp_filter_list,
7702 show_ipv6_bgp_filter_list_cmd,
7703 "show ipv6 bgp filter-list WORD",
7704 SHOW_STR
7705 IPV6_STR
7706 BGP_STR
7707 "Display routes conforming to the filter-list\n"
7708 "Regular expression access list name\n")
7709{
7710 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7711 bgp_show_type_filter_list);
7712}
7713
7714/* old command */
7715DEFUN (show_ipv6_mbgp_filter_list,
7716 show_ipv6_mbgp_filter_list_cmd,
7717 "show ipv6 mbgp filter-list WORD",
7718 SHOW_STR
7719 IPV6_STR
7720 MBGP_STR
7721 "Display routes conforming to the filter-list\n"
7722 "Regular expression access list name\n")
7723{
7724 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7725 bgp_show_type_filter_list);
7726}
7727#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007728
Balaji3921cc52015-05-16 23:12:17 +05307729DEFUN (show_ip_bgp_dampening_info,
7730 show_ip_bgp_dampening_params_cmd,
7731 "show ip bgp dampening parameters",
7732 SHOW_STR
7733 IP_STR
7734 BGP_STR
7735 "Display detailed information about dampening\n"
7736 "Display detail of configured dampening parameters\n")
7737{
7738 return bgp_show_dampening_parameters (vty, AFI_IP, SAFI_UNICAST);
7739}
7740
paul94f2b392005-06-28 12:44:16 +00007741static int
paulfd79ac92004-10-13 05:06:08 +00007742bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007743 safi_t safi, enum bgp_show_type type)
7744{
7745 struct route_map *rmap;
7746
7747 rmap = route_map_lookup_by_name (rmap_str);
7748 if (! rmap)
7749 {
7750 vty_out (vty, "%% %s is not a valid route-map name%s",
7751 rmap_str, VTY_NEWLINE);
7752 return CMD_WARNING;
7753 }
7754
ajs5a646652004-11-05 01:25:55 +00007755 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007756}
7757
7758DEFUN (show_ip_bgp_route_map,
7759 show_ip_bgp_route_map_cmd,
7760 "show ip bgp route-map WORD",
7761 SHOW_STR
7762 IP_STR
7763 BGP_STR
7764 "Display routes matching the route-map\n"
7765 "A route-map to match on\n")
7766{
7767 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7768 bgp_show_type_route_map);
7769}
7770
7771DEFUN (show_ip_bgp_flap_route_map,
7772 show_ip_bgp_flap_route_map_cmd,
7773 "show ip bgp flap-statistics route-map WORD",
7774 SHOW_STR
7775 IP_STR
7776 BGP_STR
7777 "Display flap statistics of routes\n"
7778 "Display routes matching the route-map\n"
7779 "A route-map to match on\n")
7780{
7781 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7782 bgp_show_type_flap_route_map);
7783}
7784
Balaji3921cc52015-05-16 23:12:17 +05307785ALIAS (show_ip_bgp_flap_route_map,
7786 show_ip_bgp_damp_flap_route_map_cmd,
7787 "show ip bgp dampening flap-statistics route-map WORD",
7788 SHOW_STR
7789 IP_STR
7790 BGP_STR
7791 "Display detailed information about dampening\n"
7792 "Display flap statistics of routes\n"
7793 "Display routes matching the route-map\n"
7794 "A route-map to match on\n")
7795
paul718e3742002-12-13 20:15:29 +00007796DEFUN (show_ip_bgp_ipv4_route_map,
7797 show_ip_bgp_ipv4_route_map_cmd,
7798 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7799 SHOW_STR
7800 IP_STR
7801 BGP_STR
7802 "Address family\n"
7803 "Address Family modifier\n"
7804 "Address Family modifier\n"
7805 "Display routes matching the route-map\n"
7806 "A route-map to match on\n")
7807{
7808 if (strncmp (argv[0], "m", 1) == 0)
7809 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7810 bgp_show_type_route_map);
7811
7812 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7813 bgp_show_type_route_map);
7814}
7815
7816DEFUN (show_bgp_route_map,
7817 show_bgp_route_map_cmd,
7818 "show bgp route-map WORD",
7819 SHOW_STR
7820 BGP_STR
7821 "Display routes matching the route-map\n"
7822 "A route-map to match on\n")
7823{
7824 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7825 bgp_show_type_route_map);
7826}
7827
7828ALIAS (show_bgp_route_map,
7829 show_bgp_ipv6_route_map_cmd,
7830 "show bgp ipv6 route-map WORD",
7831 SHOW_STR
7832 BGP_STR
7833 "Address family\n"
7834 "Display routes matching the route-map\n"
7835 "A route-map to match on\n")
David Lamparter6b0655a2014-06-04 06:53:35 +02007836
paul718e3742002-12-13 20:15:29 +00007837DEFUN (show_ip_bgp_cidr_only,
7838 show_ip_bgp_cidr_only_cmd,
7839 "show ip bgp cidr-only",
7840 SHOW_STR
7841 IP_STR
7842 BGP_STR
7843 "Display only routes with non-natural netmasks\n")
7844{
7845 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007846 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007847}
7848
7849DEFUN (show_ip_bgp_flap_cidr_only,
7850 show_ip_bgp_flap_cidr_only_cmd,
7851 "show ip bgp flap-statistics cidr-only",
7852 SHOW_STR
7853 IP_STR
7854 BGP_STR
7855 "Display flap statistics of routes\n"
7856 "Display only routes with non-natural netmasks\n")
7857{
7858 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007859 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007860}
7861
Balaji3921cc52015-05-16 23:12:17 +05307862ALIAS (show_ip_bgp_flap_cidr_only,
7863 show_ip_bgp_damp_flap_cidr_only_cmd,
7864 "show ip bgp dampening flap-statistics cidr-only",
7865 SHOW_STR
7866 IP_STR
7867 BGP_STR
7868 "Display detailed information about dampening\n"
7869 "Display flap statistics of routes\n"
7870 "Display only routes with non-natural netmasks\n")
7871
paul718e3742002-12-13 20:15:29 +00007872DEFUN (show_ip_bgp_ipv4_cidr_only,
7873 show_ip_bgp_ipv4_cidr_only_cmd,
7874 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7875 SHOW_STR
7876 IP_STR
7877 BGP_STR
7878 "Address family\n"
7879 "Address Family modifier\n"
7880 "Address Family modifier\n"
7881 "Display only routes with non-natural netmasks\n")
7882{
7883 if (strncmp (argv[0], "m", 1) == 0)
7884 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007885 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007886
7887 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007888 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007889}
David Lamparter6b0655a2014-06-04 06:53:35 +02007890
paul718e3742002-12-13 20:15:29 +00007891DEFUN (show_ip_bgp_community_all,
7892 show_ip_bgp_community_all_cmd,
7893 "show ip bgp community",
7894 SHOW_STR
7895 IP_STR
7896 BGP_STR
7897 "Display routes matching the communities\n")
7898{
7899 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007900 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007901}
7902
7903DEFUN (show_ip_bgp_ipv4_community_all,
7904 show_ip_bgp_ipv4_community_all_cmd,
7905 "show ip bgp ipv4 (unicast|multicast) community",
7906 SHOW_STR
7907 IP_STR
7908 BGP_STR
7909 "Address family\n"
7910 "Address Family modifier\n"
7911 "Address Family modifier\n"
7912 "Display routes matching the communities\n")
7913{
7914 if (strncmp (argv[0], "m", 1) == 0)
7915 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007916 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007917
7918 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007919 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007920}
7921
7922#ifdef HAVE_IPV6
7923DEFUN (show_bgp_community_all,
7924 show_bgp_community_all_cmd,
7925 "show bgp community",
7926 SHOW_STR
7927 BGP_STR
7928 "Display routes matching the communities\n")
7929{
7930 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007931 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007932}
7933
7934ALIAS (show_bgp_community_all,
7935 show_bgp_ipv6_community_all_cmd,
7936 "show bgp ipv6 community",
7937 SHOW_STR
7938 BGP_STR
7939 "Address family\n"
7940 "Display routes matching the communities\n")
7941
7942/* old command */
7943DEFUN (show_ipv6_bgp_community_all,
7944 show_ipv6_bgp_community_all_cmd,
7945 "show ipv6 bgp community",
7946 SHOW_STR
7947 IPV6_STR
7948 BGP_STR
7949 "Display routes matching the communities\n")
7950{
7951 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007952 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007953}
7954
7955/* old command */
7956DEFUN (show_ipv6_mbgp_community_all,
7957 show_ipv6_mbgp_community_all_cmd,
7958 "show ipv6 mbgp community",
7959 SHOW_STR
7960 IPV6_STR
7961 MBGP_STR
7962 "Display routes matching the communities\n")
7963{
7964 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007965 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007966}
7967#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02007968
paul94f2b392005-06-28 12:44:16 +00007969static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007970bgp_show_community (struct vty *vty, const char *view_name, int argc,
7971 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007972{
7973 struct community *com;
7974 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007975 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007976 int i;
7977 char *str;
7978 int first = 0;
7979
Michael Lambert95cbbd22010-07-23 14:43:04 -04007980 /* BGP structure lookup */
7981 if (view_name)
7982 {
7983 bgp = bgp_lookup_by_name (view_name);
7984 if (bgp == NULL)
7985 {
7986 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7987 return CMD_WARNING;
7988 }
7989 }
7990 else
7991 {
7992 bgp = bgp_get_default ();
7993 if (bgp == NULL)
7994 {
7995 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7996 return CMD_WARNING;
7997 }
7998 }
7999
paul718e3742002-12-13 20:15:29 +00008000 b = buffer_new (1024);
8001 for (i = 0; i < argc; i++)
8002 {
8003 if (first)
8004 buffer_putc (b, ' ');
8005 else
8006 {
8007 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
8008 continue;
8009 first = 1;
8010 }
8011
8012 buffer_putstr (b, argv[i]);
8013 }
8014 buffer_putc (b, '\0');
8015
8016 str = buffer_getstr (b);
8017 buffer_free (b);
8018
8019 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00008020 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00008021 if (! com)
8022 {
8023 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
8024 return CMD_WARNING;
8025 }
8026
Michael Lambert95cbbd22010-07-23 14:43:04 -04008027 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00008028 (exact ? bgp_show_type_community_exact :
8029 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00008030}
8031
8032DEFUN (show_ip_bgp_community,
8033 show_ip_bgp_community_cmd,
8034 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
8035 SHOW_STR
8036 IP_STR
8037 BGP_STR
8038 "Display routes matching the communities\n"
8039 "community number\n"
8040 "Do not send outside local AS (well-known community)\n"
8041 "Do not advertise to any peer (well-known community)\n"
8042 "Do not export to next AS (well-known community)\n")
8043{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008044 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008045}
8046
8047ALIAS (show_ip_bgp_community,
8048 show_ip_bgp_community2_cmd,
8049 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8050 SHOW_STR
8051 IP_STR
8052 BGP_STR
8053 "Display routes matching the communities\n"
8054 "community number\n"
8055 "Do not send outside local AS (well-known community)\n"
8056 "Do not advertise to any peer (well-known community)\n"
8057 "Do not export to next AS (well-known community)\n"
8058 "community number\n"
8059 "Do not send outside local AS (well-known community)\n"
8060 "Do not advertise to any peer (well-known community)\n"
8061 "Do not export to next AS (well-known community)\n")
8062
8063ALIAS (show_ip_bgp_community,
8064 show_ip_bgp_community3_cmd,
8065 "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)",
8066 SHOW_STR
8067 IP_STR
8068 BGP_STR
8069 "Display routes matching the communities\n"
8070 "community number\n"
8071 "Do not send outside local AS (well-known community)\n"
8072 "Do not advertise to any peer (well-known community)\n"
8073 "Do not export to next AS (well-known community)\n"
8074 "community number\n"
8075 "Do not send outside local AS (well-known community)\n"
8076 "Do not advertise to any peer (well-known community)\n"
8077 "Do not export to next AS (well-known community)\n"
8078 "community number\n"
8079 "Do not send outside local AS (well-known community)\n"
8080 "Do not advertise to any peer (well-known community)\n"
8081 "Do not export to next AS (well-known community)\n")
8082
8083ALIAS (show_ip_bgp_community,
8084 show_ip_bgp_community4_cmd,
8085 "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)",
8086 SHOW_STR
8087 IP_STR
8088 BGP_STR
8089 "Display routes matching the communities\n"
8090 "community number\n"
8091 "Do not send outside local AS (well-known community)\n"
8092 "Do not advertise to any peer (well-known community)\n"
8093 "Do not export to next AS (well-known community)\n"
8094 "community number\n"
8095 "Do not send outside local AS (well-known community)\n"
8096 "Do not advertise to any peer (well-known community)\n"
8097 "Do not export to next AS (well-known community)\n"
8098 "community number\n"
8099 "Do not send outside local AS (well-known community)\n"
8100 "Do not advertise to any peer (well-known community)\n"
8101 "Do not export to next AS (well-known community)\n"
8102 "community number\n"
8103 "Do not send outside local AS (well-known community)\n"
8104 "Do not advertise to any peer (well-known community)\n"
8105 "Do not export to next AS (well-known community)\n")
8106
8107DEFUN (show_ip_bgp_ipv4_community,
8108 show_ip_bgp_ipv4_community_cmd,
8109 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
8110 SHOW_STR
8111 IP_STR
8112 BGP_STR
8113 "Address family\n"
8114 "Address Family modifier\n"
8115 "Address Family modifier\n"
8116 "Display routes matching the communities\n"
8117 "community number\n"
8118 "Do not send outside local AS (well-known community)\n"
8119 "Do not advertise to any peer (well-known community)\n"
8120 "Do not export to next AS (well-known community)\n")
8121{
8122 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008123 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008124
Michael Lambert95cbbd22010-07-23 14:43:04 -04008125 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008126}
8127
8128ALIAS (show_ip_bgp_ipv4_community,
8129 show_ip_bgp_ipv4_community2_cmd,
8130 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8131 SHOW_STR
8132 IP_STR
8133 BGP_STR
8134 "Address family\n"
8135 "Address Family modifier\n"
8136 "Address Family modifier\n"
8137 "Display routes matching the communities\n"
8138 "community number\n"
8139 "Do not send outside local AS (well-known community)\n"
8140 "Do not advertise to any peer (well-known community)\n"
8141 "Do not export to next AS (well-known community)\n"
8142 "community number\n"
8143 "Do not send outside local AS (well-known community)\n"
8144 "Do not advertise to any peer (well-known community)\n"
8145 "Do not export to next AS (well-known community)\n")
8146
8147ALIAS (show_ip_bgp_ipv4_community,
8148 show_ip_bgp_ipv4_community3_cmd,
8149 "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)",
8150 SHOW_STR
8151 IP_STR
8152 BGP_STR
8153 "Address family\n"
8154 "Address Family modifier\n"
8155 "Address Family modifier\n"
8156 "Display routes matching the communities\n"
8157 "community number\n"
8158 "Do not send outside local AS (well-known community)\n"
8159 "Do not advertise to any peer (well-known community)\n"
8160 "Do not export to next AS (well-known community)\n"
8161 "community number\n"
8162 "Do not send outside local AS (well-known community)\n"
8163 "Do not advertise to any peer (well-known community)\n"
8164 "Do not export to next AS (well-known community)\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
8170ALIAS (show_ip_bgp_ipv4_community,
8171 show_ip_bgp_ipv4_community4_cmd,
8172 "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)",
8173 SHOW_STR
8174 IP_STR
8175 BGP_STR
8176 "Address family\n"
8177 "Address Family modifier\n"
8178 "Address Family modifier\n"
8179 "Display routes matching the communities\n"
8180 "community number\n"
8181 "Do not send outside local AS (well-known community)\n"
8182 "Do not advertise to any peer (well-known community)\n"
8183 "Do not export to next AS (well-known community)\n"
8184 "community number\n"
8185 "Do not send outside local AS (well-known community)\n"
8186 "Do not advertise to any peer (well-known community)\n"
8187 "Do not export to next AS (well-known community)\n"
8188 "community number\n"
8189 "Do not send outside local AS (well-known community)\n"
8190 "Do not advertise to any peer (well-known community)\n"
8191 "Do not export to next AS (well-known community)\n"
8192 "community number\n"
8193 "Do not send outside local AS (well-known community)\n"
8194 "Do not advertise to any peer (well-known community)\n"
8195 "Do not export to next AS (well-known community)\n")
8196
Michael Lambert95cbbd22010-07-23 14:43:04 -04008197DEFUN (show_bgp_view_afi_safi_community_all,
8198 show_bgp_view_afi_safi_community_all_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008199 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008200 SHOW_STR
8201 BGP_STR
8202 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008203 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008204 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008205 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008206 "Address Family modifier\n"
8207 "Address Family modifier\n"
Christian Franke2b005152013-09-30 12:27:49 +00008208 "Display routes matching the communities\n")
Michael Lambert95cbbd22010-07-23 14:43:04 -04008209{
8210 int afi;
8211 int safi;
8212 struct bgp *bgp;
8213
8214 /* BGP structure lookup. */
8215 bgp = bgp_lookup_by_name (argv[0]);
8216 if (bgp == NULL)
8217 {
8218 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
8219 return CMD_WARNING;
8220 }
8221
Michael Lambert95cbbd22010-07-23 14:43:04 -04008222 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8223 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
Michael Lambert95cbbd22010-07-23 14:43:04 -04008224 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
8225}
8226
8227DEFUN (show_bgp_view_afi_safi_community,
8228 show_bgp_view_afi_safi_community_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008229 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
Michael Lambert95cbbd22010-07-23 14:43:04 -04008230 SHOW_STR
8231 BGP_STR
8232 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008233 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008234 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008235 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008236 "Address family modifier\n"
8237 "Address family modifier\n"
8238 "Display routes matching the communities\n"
8239 "community number\n"
8240 "Do not send outside local AS (well-known community)\n"
8241 "Do not advertise to any peer (well-known community)\n"
8242 "Do not export to next AS (well-known community)\n")
8243{
8244 int afi;
8245 int safi;
8246
Michael Lambert95cbbd22010-07-23 14:43:04 -04008247 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
8248 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
8249 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
Michael Lambert95cbbd22010-07-23 14:43:04 -04008250}
8251
8252ALIAS (show_bgp_view_afi_safi_community,
8253 show_bgp_view_afi_safi_community2_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008254 "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 -04008255 SHOW_STR
8256 BGP_STR
8257 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008258 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008259 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008260 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008261 "Address family modifier\n"
8262 "Address family modifier\n"
8263 "Display routes matching the communities\n"
8264 "community number\n"
8265 "Do not send outside local AS (well-known community)\n"
8266 "Do not advertise to any peer (well-known community)\n"
8267 "Do not export to next AS (well-known community)\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
8273ALIAS (show_bgp_view_afi_safi_community,
8274 show_bgp_view_afi_safi_community3_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008275 "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 -04008276 SHOW_STR
8277 BGP_STR
8278 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008279 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008280 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008281 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008282 "Address family modifier\n"
8283 "Address family modifier\n"
8284 "Display routes matching the communities\n"
8285 "community number\n"
8286 "Do not send outside local AS (well-known community)\n"
8287 "Do not advertise to any peer (well-known community)\n"
8288 "Do not export to next AS (well-known community)\n"
8289 "community number\n"
8290 "Do not send outside local AS (well-known community)\n"
8291 "Do not advertise to any peer (well-known community)\n"
8292 "Do not export to next AS (well-known community)\n"
8293 "community number\n"
8294 "Do not send outside local AS (well-known community)\n"
8295 "Do not advertise to any peer (well-known community)\n"
8296 "Do not export to next AS (well-known community)\n")
8297
8298ALIAS (show_bgp_view_afi_safi_community,
8299 show_bgp_view_afi_safi_community4_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -04008300 "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 -04008301 SHOW_STR
8302 BGP_STR
8303 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +00008304 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008305 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008306 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -04008307 "Address family modifier\n"
8308 "Address family modifier\n"
8309 "Display routes matching the communities\n"
8310 "community number\n"
8311 "Do not send outside local AS (well-known community)\n"
8312 "Do not advertise to any peer (well-known community)\n"
8313 "Do not export to next AS (well-known community)\n"
8314 "community number\n"
8315 "Do not send outside local AS (well-known community)\n"
8316 "Do not advertise to any peer (well-known community)\n"
8317 "Do not export to next AS (well-known community)\n"
8318 "community number\n"
8319 "Do not send outside local AS (well-known community)\n"
8320 "Do not advertise to any peer (well-known community)\n"
8321 "Do not export to next AS (well-known community)\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n")
8326
paul718e3742002-12-13 20:15:29 +00008327DEFUN (show_ip_bgp_community_exact,
8328 show_ip_bgp_community_exact_cmd,
8329 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8330 SHOW_STR
8331 IP_STR
8332 BGP_STR
8333 "Display routes matching the communities\n"
8334 "community number\n"
8335 "Do not send outside local AS (well-known community)\n"
8336 "Do not advertise to any peer (well-known community)\n"
8337 "Do not export to next AS (well-known community)\n"
8338 "Exact match of the communities")
8339{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008340 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008341}
8342
8343ALIAS (show_ip_bgp_community_exact,
8344 show_ip_bgp_community2_exact_cmd,
8345 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8346 SHOW_STR
8347 IP_STR
8348 BGP_STR
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 "community number\n"
8355 "Do not send outside local AS (well-known community)\n"
8356 "Do not advertise to any peer (well-known community)\n"
8357 "Do not export to next AS (well-known community)\n"
8358 "Exact match of the communities")
8359
8360ALIAS (show_ip_bgp_community_exact,
8361 show_ip_bgp_community3_exact_cmd,
8362 "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",
8363 SHOW_STR
8364 IP_STR
8365 BGP_STR
8366 "Display routes matching the communities\n"
8367 "community number\n"
8368 "Do not send outside local AS (well-known community)\n"
8369 "Do not advertise to any peer (well-known community)\n"
8370 "Do not export to next AS (well-known community)\n"
8371 "community number\n"
8372 "Do not send outside local AS (well-known community)\n"
8373 "Do not advertise to any peer (well-known community)\n"
8374 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8380
8381ALIAS (show_ip_bgp_community_exact,
8382 show_ip_bgp_community4_exact_cmd,
8383 "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",
8384 SHOW_STR
8385 IP_STR
8386 BGP_STR
8387 "Display routes matching the communities\n"
8388 "community number\n"
8389 "Do not send outside local AS (well-known community)\n"
8390 "Do not advertise to any peer (well-known community)\n"
8391 "Do not export to next AS (well-known community)\n"
8392 "community number\n"
8393 "Do not send outside local AS (well-known community)\n"
8394 "Do not advertise to any peer (well-known community)\n"
8395 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8405
8406DEFUN (show_ip_bgp_ipv4_community_exact,
8407 show_ip_bgp_ipv4_community_exact_cmd,
8408 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8409 SHOW_STR
8410 IP_STR
8411 BGP_STR
8412 "Address family\n"
8413 "Address Family modifier\n"
8414 "Address Family modifier\n"
8415 "Display routes matching the communities\n"
8416 "community number\n"
8417 "Do not send outside local AS (well-known community)\n"
8418 "Do not advertise to any peer (well-known community)\n"
8419 "Do not export to next AS (well-known community)\n"
8420 "Exact match of the communities")
8421{
8422 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008423 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008424
Michael Lambert95cbbd22010-07-23 14:43:04 -04008425 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008426}
8427
8428ALIAS (show_ip_bgp_ipv4_community_exact,
8429 show_ip_bgp_ipv4_community2_exact_cmd,
8430 "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",
8431 SHOW_STR
8432 IP_STR
8433 BGP_STR
8434 "Address family\n"
8435 "Address Family modifier\n"
8436 "Address Family modifier\n"
8437 "Display routes matching the communities\n"
8438 "community number\n"
8439 "Do not send outside local AS (well-known community)\n"
8440 "Do not advertise to any peer (well-known community)\n"
8441 "Do not export to next AS (well-known community)\n"
8442 "community number\n"
8443 "Do not send outside local AS (well-known community)\n"
8444 "Do not advertise to any peer (well-known community)\n"
8445 "Do not export to next AS (well-known community)\n"
8446 "Exact match of the communities")
8447
8448ALIAS (show_ip_bgp_ipv4_community_exact,
8449 show_ip_bgp_ipv4_community3_exact_cmd,
8450 "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",
8451 SHOW_STR
8452 IP_STR
8453 BGP_STR
8454 "Address family\n"
8455 "Address Family modifier\n"
8456 "Address Family modifier\n"
8457 "Display routes matching the communities\n"
8458 "community number\n"
8459 "Do not send outside local AS (well-known community)\n"
8460 "Do not advertise to any peer (well-known community)\n"
8461 "Do not export to next AS (well-known community)\n"
8462 "community number\n"
8463 "Do not send outside local AS (well-known community)\n"
8464 "Do not advertise to any peer (well-known community)\n"
8465 "Do not export to next AS (well-known community)\n"
8466 "community number\n"
8467 "Do not send outside local AS (well-known community)\n"
8468 "Do not advertise to any peer (well-known community)\n"
8469 "Do not export to next AS (well-known community)\n"
8470 "Exact match of the communities")
8471
8472ALIAS (show_ip_bgp_ipv4_community_exact,
8473 show_ip_bgp_ipv4_community4_exact_cmd,
8474 "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",
8475 SHOW_STR
8476 IP_STR
8477 BGP_STR
8478 "Address family\n"
8479 "Address Family modifier\n"
8480 "Address Family modifier\n"
8481 "Display routes matching the communities\n"
8482 "community number\n"
8483 "Do not send outside local AS (well-known community)\n"
8484 "Do not advertise to any peer (well-known community)\n"
8485 "Do not export to next AS (well-known community)\n"
8486 "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 "community number\n"
8491 "Do not send outside local AS (well-known community)\n"
8492 "Do not advertise to any peer (well-known community)\n"
8493 "Do not export to next AS (well-known community)\n"
8494 "community number\n"
8495 "Do not send outside local AS (well-known community)\n"
8496 "Do not advertise to any peer (well-known community)\n"
8497 "Do not export to next AS (well-known community)\n"
8498 "Exact match of the communities")
8499
8500#ifdef HAVE_IPV6
8501DEFUN (show_bgp_community,
8502 show_bgp_community_cmd,
8503 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8504 SHOW_STR
8505 BGP_STR
8506 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008512 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008513}
8514
8515ALIAS (show_bgp_community,
8516 show_bgp_ipv6_community_cmd,
8517 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8518 SHOW_STR
8519 BGP_STR
8520 "Address family\n"
8521 "Display routes matching the communities\n"
8522 "community number\n"
8523 "Do not send outside local AS (well-known community)\n"
8524 "Do not advertise to any peer (well-known community)\n"
8525 "Do not export to next AS (well-known community)\n")
8526
8527ALIAS (show_bgp_community,
8528 show_bgp_community2_cmd,
8529 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8530 SHOW_STR
8531 BGP_STR
8532 "Display routes matching the communities\n"
8533 "community number\n"
8534 "Do not send outside local AS (well-known community)\n"
8535 "Do not advertise to any peer (well-known community)\n"
8536 "Do not export to next AS (well-known community)\n"
8537 "community number\n"
8538 "Do not send outside local AS (well-known community)\n"
8539 "Do not advertise to any peer (well-known community)\n"
8540 "Do not export to next AS (well-known community)\n")
8541
8542ALIAS (show_bgp_community,
8543 show_bgp_ipv6_community2_cmd,
8544 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8545 SHOW_STR
8546 BGP_STR
8547 "Address family\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
8558ALIAS (show_bgp_community,
8559 show_bgp_community3_cmd,
8560 "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)",
8561 SHOW_STR
8562 BGP_STR
8563 "Display routes matching the communities\n"
8564 "community number\n"
8565 "Do not send outside local AS (well-known community)\n"
8566 "Do not advertise to any peer (well-known community)\n"
8567 "Do not export to next AS (well-known community)\n"
8568 "community number\n"
8569 "Do not send outside local AS (well-known community)\n"
8570 "Do not advertise to any peer (well-known community)\n"
8571 "Do not export to next AS (well-known community)\n"
8572 "community number\n"
8573 "Do not send outside local AS (well-known community)\n"
8574 "Do not advertise to any peer (well-known community)\n"
8575 "Do not export to next AS (well-known community)\n")
8576
8577ALIAS (show_bgp_community,
8578 show_bgp_ipv6_community3_cmd,
8579 "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)",
8580 SHOW_STR
8581 BGP_STR
8582 "Address family\n"
8583 "Display routes matching the communities\n"
8584 "community number\n"
8585 "Do not send outside local AS (well-known community)\n"
8586 "Do not advertise to any peer (well-known community)\n"
8587 "Do not export to next AS (well-known community)\n"
8588 "community number\n"
8589 "Do not send outside local AS (well-known community)\n"
8590 "Do not advertise to any peer (well-known community)\n"
8591 "Do not export to next AS (well-known community)\n"
8592 "community number\n"
8593 "Do not send outside local AS (well-known community)\n"
8594 "Do not advertise to any peer (well-known community)\n"
8595 "Do not export to next AS (well-known community)\n")
8596
8597ALIAS (show_bgp_community,
8598 show_bgp_community4_cmd,
8599 "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)",
8600 SHOW_STR
8601 BGP_STR
8602 "Display routes matching the communities\n"
8603 "community number\n"
8604 "Do not send outside local AS (well-known community)\n"
8605 "Do not advertise to any peer (well-known community)\n"
8606 "Do not export to next AS (well-known community)\n"
8607 "community number\n"
8608 "Do not send outside local AS (well-known community)\n"
8609 "Do not advertise to any peer (well-known community)\n"
8610 "Do not export to next AS (well-known community)\n"
8611 "community number\n"
8612 "Do not send outside local AS (well-known community)\n"
8613 "Do not advertise to any peer (well-known community)\n"
8614 "Do not export to next AS (well-known community)\n"
8615 "community number\n"
8616 "Do not send outside local AS (well-known community)\n"
8617 "Do not advertise to any peer (well-known community)\n"
8618 "Do not export to next AS (well-known community)\n")
8619
8620ALIAS (show_bgp_community,
8621 show_bgp_ipv6_community4_cmd,
8622 "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)",
8623 SHOW_STR
8624 BGP_STR
8625 "Address family\n"
8626 "Display routes matching the communities\n"
8627 "community number\n"
8628 "Do not send outside local AS (well-known community)\n"
8629 "Do not advertise to any peer (well-known community)\n"
8630 "Do not export to next AS (well-known community)\n"
8631 "community number\n"
8632 "Do not send outside local AS (well-known community)\n"
8633 "Do not advertise to any peer (well-known community)\n"
8634 "Do not export to next AS (well-known community)\n"
8635 "community number\n"
8636 "Do not send outside local AS (well-known community)\n"
8637 "Do not advertise to any peer (well-known community)\n"
8638 "Do not export to next AS (well-known community)\n"
8639 "community number\n"
8640 "Do not send outside local AS (well-known community)\n"
8641 "Do not advertise to any peer (well-known community)\n"
8642 "Do not export to next AS (well-known community)\n")
8643
8644/* old command */
8645DEFUN (show_ipv6_bgp_community,
8646 show_ipv6_bgp_community_cmd,
8647 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8648 SHOW_STR
8649 IPV6_STR
8650 BGP_STR
8651 "Display routes matching the communities\n"
8652 "community number\n"
8653 "Do not send outside local AS (well-known community)\n"
8654 "Do not advertise to any peer (well-known community)\n"
8655 "Do not export to next AS (well-known community)\n")
8656{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008657 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008658}
8659
8660/* old command */
8661ALIAS (show_ipv6_bgp_community,
8662 show_ipv6_bgp_community2_cmd,
8663 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8664 SHOW_STR
8665 IPV6_STR
8666 BGP_STR
8667 "Display routes matching the communities\n"
8668 "community number\n"
8669 "Do not send outside local AS (well-known community)\n"
8670 "Do not advertise to any peer (well-known community)\n"
8671 "Do not export to next AS (well-known community)\n"
8672 "community number\n"
8673 "Do not send outside local AS (well-known community)\n"
8674 "Do not advertise to any peer (well-known community)\n"
8675 "Do not export to next AS (well-known community)\n")
8676
8677/* old command */
8678ALIAS (show_ipv6_bgp_community,
8679 show_ipv6_bgp_community3_cmd,
8680 "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)",
8681 SHOW_STR
8682 IPV6_STR
8683 BGP_STR
8684 "Display routes matching the communities\n"
8685 "community number\n"
8686 "Do not send outside local AS (well-known community)\n"
8687 "Do not advertise to any peer (well-known community)\n"
8688 "Do not export to next AS (well-known community)\n"
8689 "community number\n"
8690 "Do not send outside local AS (well-known community)\n"
8691 "Do not advertise to any peer (well-known community)\n"
8692 "Do not export to next AS (well-known community)\n"
8693 "community number\n"
8694 "Do not send outside local AS (well-known community)\n"
8695 "Do not advertise to any peer (well-known community)\n"
8696 "Do not export to next AS (well-known community)\n")
8697
8698/* old command */
8699ALIAS (show_ipv6_bgp_community,
8700 show_ipv6_bgp_community4_cmd,
8701 "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)",
8702 SHOW_STR
8703 IPV6_STR
8704 BGP_STR
8705 "Display routes matching the communities\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n"
8710 "community number\n"
8711 "Do not send outside local AS (well-known community)\n"
8712 "Do not advertise to any peer (well-known community)\n"
8713 "Do not export to next AS (well-known community)\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
8723DEFUN (show_bgp_community_exact,
8724 show_bgp_community_exact_cmd,
8725 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8726 SHOW_STR
8727 BGP_STR
8728 "Display routes matching the communities\n"
8729 "community number\n"
8730 "Do not send outside local AS (well-known community)\n"
8731 "Do not advertise to any peer (well-known community)\n"
8732 "Do not export to next AS (well-known community)\n"
8733 "Exact match of the communities")
8734{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008735 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008736}
8737
8738ALIAS (show_bgp_community_exact,
8739 show_bgp_ipv6_community_exact_cmd,
8740 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8741 SHOW_STR
8742 BGP_STR
8743 "Address family\n"
8744 "Display routes matching the communities\n"
8745 "community number\n"
8746 "Do not send outside local AS (well-known community)\n"
8747 "Do not advertise to any peer (well-known community)\n"
8748 "Do not export to next AS (well-known community)\n"
8749 "Exact match of the communities")
8750
8751ALIAS (show_bgp_community_exact,
8752 show_bgp_community2_exact_cmd,
8753 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8754 SHOW_STR
8755 BGP_STR
8756 "Display routes matching the communities\n"
8757 "community number\n"
8758 "Do not send outside local AS (well-known community)\n"
8759 "Do not advertise to any peer (well-known community)\n"
8760 "Do not export to next AS (well-known community)\n"
8761 "community number\n"
8762 "Do not send outside local AS (well-known community)\n"
8763 "Do not advertise to any peer (well-known community)\n"
8764 "Do not export to next AS (well-known community)\n"
8765 "Exact match of the communities")
8766
8767ALIAS (show_bgp_community_exact,
8768 show_bgp_ipv6_community2_exact_cmd,
8769 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8770 SHOW_STR
8771 BGP_STR
8772 "Address family\n"
8773 "Display routes matching the communities\n"
8774 "community number\n"
8775 "Do not send outside local AS (well-known community)\n"
8776 "Do not advertise to any peer (well-known community)\n"
8777 "Do not export to next AS (well-known community)\n"
8778 "community number\n"
8779 "Do not send outside local AS (well-known community)\n"
8780 "Do not advertise to any peer (well-known community)\n"
8781 "Do not export to next AS (well-known community)\n"
8782 "Exact match of the communities")
8783
8784ALIAS (show_bgp_community_exact,
8785 show_bgp_community3_exact_cmd,
8786 "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",
8787 SHOW_STR
8788 BGP_STR
8789 "Display routes matching the communities\n"
8790 "community number\n"
8791 "Do not send outside local AS (well-known community)\n"
8792 "Do not advertise to any peer (well-known community)\n"
8793 "Do not export to next AS (well-known community)\n"
8794 "community number\n"
8795 "Do not send outside local AS (well-known community)\n"
8796 "Do not advertise to any peer (well-known community)\n"
8797 "Do not export to next AS (well-known community)\n"
8798 "community number\n"
8799 "Do not send outside local AS (well-known community)\n"
8800 "Do not advertise to any peer (well-known community)\n"
8801 "Do not export to next AS (well-known community)\n"
8802 "Exact match of the communities")
8803
8804ALIAS (show_bgp_community_exact,
8805 show_bgp_ipv6_community3_exact_cmd,
8806 "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",
8807 SHOW_STR
8808 BGP_STR
8809 "Address family\n"
8810 "Display routes matching the communities\n"
8811 "community number\n"
8812 "Do not send outside local AS (well-known community)\n"
8813 "Do not advertise to any peer (well-known community)\n"
8814 "Do not export to next AS (well-known community)\n"
8815 "community number\n"
8816 "Do not send outside local AS (well-known community)\n"
8817 "Do not advertise to any peer (well-known community)\n"
8818 "Do not export to next AS (well-known community)\n"
8819 "community number\n"
8820 "Do not send outside local AS (well-known community)\n"
8821 "Do not advertise to any peer (well-known community)\n"
8822 "Do not export to next AS (well-known community)\n"
8823 "Exact match of the communities")
8824
8825ALIAS (show_bgp_community_exact,
8826 show_bgp_community4_exact_cmd,
8827 "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",
8828 SHOW_STR
8829 BGP_STR
8830 "Display routes matching the communities\n"
8831 "community number\n"
8832 "Do not send outside local AS (well-known community)\n"
8833 "Do not advertise to any peer (well-known community)\n"
8834 "Do not export to next AS (well-known community)\n"
8835 "community number\n"
8836 "Do not send outside local AS (well-known community)\n"
8837 "Do not advertise to any peer (well-known community)\n"
8838 "Do not export to next AS (well-known community)\n"
8839 "community number\n"
8840 "Do not send outside local AS (well-known community)\n"
8841 "Do not advertise to any peer (well-known community)\n"
8842 "Do not export to next AS (well-known community)\n"
8843 "community number\n"
8844 "Do not send outside local AS (well-known community)\n"
8845 "Do not advertise to any peer (well-known community)\n"
8846 "Do not export to next AS (well-known community)\n"
8847 "Exact match of the communities")
8848
8849ALIAS (show_bgp_community_exact,
8850 show_bgp_ipv6_community4_exact_cmd,
8851 "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",
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 "community number\n"
8861 "Do not send outside local AS (well-known community)\n"
8862 "Do not advertise to any peer (well-known community)\n"
8863 "Do not export to next AS (well-known community)\n"
8864 "community number\n"
8865 "Do not send outside local AS (well-known community)\n"
8866 "Do not advertise to any peer (well-known community)\n"
8867 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8873
8874/* old command */
8875DEFUN (show_ipv6_bgp_community_exact,
8876 show_ipv6_bgp_community_exact_cmd,
8877 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8878 SHOW_STR
8879 IPV6_STR
8880 BGP_STR
8881 "Display routes matching the communities\n"
8882 "community number\n"
8883 "Do not send outside local AS (well-known community)\n"
8884 "Do not advertise to any peer (well-known community)\n"
8885 "Do not export to next AS (well-known community)\n"
8886 "Exact match of the communities")
8887{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008888 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008889}
8890
8891/* old command */
8892ALIAS (show_ipv6_bgp_community_exact,
8893 show_ipv6_bgp_community2_exact_cmd,
8894 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8895 SHOW_STR
8896 IPV6_STR
8897 BGP_STR
8898 "Display routes matching the communities\n"
8899 "community number\n"
8900 "Do not send outside local AS (well-known community)\n"
8901 "Do not advertise to any peer (well-known community)\n"
8902 "Do not export to next AS (well-known community)\n"
8903 "community number\n"
8904 "Do not send outside local AS (well-known community)\n"
8905 "Do not advertise to any peer (well-known community)\n"
8906 "Do not export to next AS (well-known community)\n"
8907 "Exact match of the communities")
8908
8909/* old command */
8910ALIAS (show_ipv6_bgp_community_exact,
8911 show_ipv6_bgp_community3_exact_cmd,
8912 "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",
8913 SHOW_STR
8914 IPV6_STR
8915 BGP_STR
8916 "Display routes matching the communities\n"
8917 "community number\n"
8918 "Do not send outside local AS (well-known community)\n"
8919 "Do not advertise to any peer (well-known community)\n"
8920 "Do not export to next AS (well-known community)\n"
8921 "community number\n"
8922 "Do not send outside local AS (well-known community)\n"
8923 "Do not advertise to any peer (well-known community)\n"
8924 "Do not export to next AS (well-known community)\n"
8925 "community number\n"
8926 "Do not send outside local AS (well-known community)\n"
8927 "Do not advertise to any peer (well-known community)\n"
8928 "Do not export to next AS (well-known community)\n"
8929 "Exact match of the communities")
8930
8931/* old command */
8932ALIAS (show_ipv6_bgp_community_exact,
8933 show_ipv6_bgp_community4_exact_cmd,
8934 "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",
8935 SHOW_STR
8936 IPV6_STR
8937 BGP_STR
8938 "Display routes matching the communities\n"
8939 "community number\n"
8940 "Do not send outside local AS (well-known community)\n"
8941 "Do not advertise to any peer (well-known community)\n"
8942 "Do not export to next AS (well-known community)\n"
8943 "community number\n"
8944 "Do not send outside local AS (well-known community)\n"
8945 "Do not advertise to any peer (well-known community)\n"
8946 "Do not export to next AS (well-known community)\n"
8947 "community number\n"
8948 "Do not send outside local AS (well-known community)\n"
8949 "Do not advertise to any peer (well-known community)\n"
8950 "Do not export to next AS (well-known community)\n"
8951 "community number\n"
8952 "Do not send outside local AS (well-known community)\n"
8953 "Do not advertise to any peer (well-known community)\n"
8954 "Do not export to next AS (well-known community)\n"
8955 "Exact match of the communities")
8956
8957/* old command */
8958DEFUN (show_ipv6_mbgp_community,
8959 show_ipv6_mbgp_community_cmd,
8960 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8961 SHOW_STR
8962 IPV6_STR
8963 MBGP_STR
8964 "Display routes matching the communities\n"
8965 "community number\n"
8966 "Do not send outside local AS (well-known community)\n"
8967 "Do not advertise to any peer (well-known community)\n"
8968 "Do not export to next AS (well-known community)\n")
8969{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008970 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008971}
8972
8973/* old command */
8974ALIAS (show_ipv6_mbgp_community,
8975 show_ipv6_mbgp_community2_cmd,
8976 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8977 SHOW_STR
8978 IPV6_STR
8979 MBGP_STR
8980 "Display routes matching the communities\n"
8981 "community number\n"
8982 "Do not send outside local AS (well-known community)\n"
8983 "Do not advertise to any peer (well-known community)\n"
8984 "Do not export to next AS (well-known community)\n"
8985 "community number\n"
8986 "Do not send outside local AS (well-known community)\n"
8987 "Do not advertise to any peer (well-known community)\n"
8988 "Do not export to next AS (well-known community)\n")
8989
8990/* old command */
8991ALIAS (show_ipv6_mbgp_community,
8992 show_ipv6_mbgp_community3_cmd,
8993 "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)",
8994 SHOW_STR
8995 IPV6_STR
8996 MBGP_STR
8997 "Display routes matching the communities\n"
8998 "community number\n"
8999 "Do not send outside local AS (well-known community)\n"
9000 "Do not advertise to any peer (well-known community)\n"
9001 "Do not export to next AS (well-known community)\n"
9002 "community number\n"
9003 "Do not send outside local AS (well-known community)\n"
9004 "Do not advertise to any peer (well-known community)\n"
9005 "Do not export to next AS (well-known community)\n"
9006 "community number\n"
9007 "Do not send outside local AS (well-known community)\n"
9008 "Do not advertise to any peer (well-known community)\n"
9009 "Do not export to next AS (well-known community)\n")
9010
9011/* old command */
9012ALIAS (show_ipv6_mbgp_community,
9013 show_ipv6_mbgp_community4_cmd,
9014 "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)",
9015 SHOW_STR
9016 IPV6_STR
9017 MBGP_STR
9018 "Display routes matching the communities\n"
9019 "community number\n"
9020 "Do not send outside local AS (well-known community)\n"
9021 "Do not advertise to any peer (well-known community)\n"
9022 "Do not export to next AS (well-known community)\n"
9023 "community number\n"
9024 "Do not send outside local AS (well-known community)\n"
9025 "Do not advertise to any peer (well-known community)\n"
9026 "Do not export to next AS (well-known community)\n"
9027 "community number\n"
9028 "Do not send outside local AS (well-known community)\n"
9029 "Do not advertise to any peer (well-known community)\n"
9030 "Do not export to next AS (well-known community)\n"
9031 "community number\n"
9032 "Do not send outside local AS (well-known community)\n"
9033 "Do not advertise to any peer (well-known community)\n"
9034 "Do not export to next AS (well-known community)\n")
9035
9036/* old command */
9037DEFUN (show_ipv6_mbgp_community_exact,
9038 show_ipv6_mbgp_community_exact_cmd,
9039 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
9040 SHOW_STR
9041 IPV6_STR
9042 MBGP_STR
9043 "Display routes matching the communities\n"
9044 "community number\n"
9045 "Do not send outside local AS (well-known community)\n"
9046 "Do not advertise to any peer (well-known community)\n"
9047 "Do not export to next AS (well-known community)\n"
9048 "Exact match of the communities")
9049{
Michael Lambert95cbbd22010-07-23 14:43:04 -04009050 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00009051}
9052
9053/* old command */
9054ALIAS (show_ipv6_mbgp_community_exact,
9055 show_ipv6_mbgp_community2_exact_cmd,
9056 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
9057 SHOW_STR
9058 IPV6_STR
9059 MBGP_STR
9060 "Display routes matching the communities\n"
9061 "community number\n"
9062 "Do not send outside local AS (well-known community)\n"
9063 "Do not advertise to any peer (well-known community)\n"
9064 "Do not export to next AS (well-known community)\n"
9065 "community number\n"
9066 "Do not send outside local AS (well-known community)\n"
9067 "Do not advertise to any peer (well-known community)\n"
9068 "Do not export to next AS (well-known community)\n"
9069 "Exact match of the communities")
9070
9071/* old command */
9072ALIAS (show_ipv6_mbgp_community_exact,
9073 show_ipv6_mbgp_community3_exact_cmd,
9074 "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",
9075 SHOW_STR
9076 IPV6_STR
9077 MBGP_STR
9078 "Display routes matching the communities\n"
9079 "community number\n"
9080 "Do not send outside local AS (well-known community)\n"
9081 "Do not advertise to any peer (well-known community)\n"
9082 "Do not export to next AS (well-known community)\n"
9083 "community number\n"
9084 "Do not send outside local AS (well-known community)\n"
9085 "Do not advertise to any peer (well-known community)\n"
9086 "Do not export to next AS (well-known community)\n"
9087 "community number\n"
9088 "Do not send outside local AS (well-known community)\n"
9089 "Do not advertise to any peer (well-known community)\n"
9090 "Do not export to next AS (well-known community)\n"
9091 "Exact match of the communities")
9092
9093/* old command */
9094ALIAS (show_ipv6_mbgp_community_exact,
9095 show_ipv6_mbgp_community4_exact_cmd,
9096 "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",
9097 SHOW_STR
9098 IPV6_STR
9099 MBGP_STR
9100 "Display routes matching the communities\n"
9101 "community number\n"
9102 "Do not send outside local AS (well-known community)\n"
9103 "Do not advertise to any peer (well-known community)\n"
9104 "Do not export to next AS (well-known community)\n"
9105 "community number\n"
9106 "Do not send outside local AS (well-known community)\n"
9107 "Do not advertise to any peer (well-known community)\n"
9108 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
9118#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009119
paul94f2b392005-06-28 12:44:16 +00009120static int
paulfd79ac92004-10-13 05:06:08 +00009121bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04009122 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00009123{
9124 struct community_list *list;
9125
hassofee6e4e2005-02-02 16:29:31 +00009126 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00009127 if (list == NULL)
9128 {
9129 vty_out (vty, "%% %s is not a valid community-list name%s", com,
9130 VTY_NEWLINE);
9131 return CMD_WARNING;
9132 }
9133
ajs5a646652004-11-05 01:25:55 +00009134 return bgp_show (vty, NULL, afi, safi,
9135 (exact ? bgp_show_type_community_list_exact :
9136 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00009137}
9138
9139DEFUN (show_ip_bgp_community_list,
9140 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009141 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009142 SHOW_STR
9143 IP_STR
9144 BGP_STR
9145 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009146 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009147 "community-list name\n")
9148{
9149 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
9150}
9151
9152DEFUN (show_ip_bgp_ipv4_community_list,
9153 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009154 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009155 SHOW_STR
9156 IP_STR
9157 BGP_STR
9158 "Address family\n"
9159 "Address Family modifier\n"
9160 "Address Family modifier\n"
9161 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009162 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009163 "community-list name\n")
9164{
9165 if (strncmp (argv[0], "m", 1) == 0)
9166 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
9167
9168 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
9169}
9170
9171DEFUN (show_ip_bgp_community_list_exact,
9172 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009173 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009174 SHOW_STR
9175 IP_STR
9176 BGP_STR
9177 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009178 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009179 "community-list name\n"
9180 "Exact match of the communities\n")
9181{
9182 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
9183}
9184
9185DEFUN (show_ip_bgp_ipv4_community_list_exact,
9186 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009187 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009188 SHOW_STR
9189 IP_STR
9190 BGP_STR
9191 "Address family\n"
9192 "Address Family modifier\n"
9193 "Address Family modifier\n"
9194 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009195 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009196 "community-list name\n"
9197 "Exact match of the communities\n")
9198{
9199 if (strncmp (argv[0], "m", 1) == 0)
9200 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
9201
9202 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
9203}
9204
9205#ifdef HAVE_IPV6
9206DEFUN (show_bgp_community_list,
9207 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009208 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009209 SHOW_STR
9210 BGP_STR
9211 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009212 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009213 "community-list name\n")
9214{
9215 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9216}
9217
9218ALIAS (show_bgp_community_list,
9219 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009220 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00009221 SHOW_STR
9222 BGP_STR
9223 "Address family\n"
9224 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009225 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00009226 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00009227
9228/* old command */
9229DEFUN (show_ipv6_bgp_community_list,
9230 show_ipv6_bgp_community_list_cmd,
9231 "show ipv6 bgp community-list WORD",
9232 SHOW_STR
9233 IPV6_STR
9234 BGP_STR
9235 "Display routes matching the community-list\n"
9236 "community-list name\n")
9237{
9238 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
9239}
9240
9241/* old command */
9242DEFUN (show_ipv6_mbgp_community_list,
9243 show_ipv6_mbgp_community_list_cmd,
9244 "show ipv6 mbgp community-list WORD",
9245 SHOW_STR
9246 IPV6_STR
9247 MBGP_STR
9248 "Display routes matching the community-list\n"
9249 "community-list name\n")
9250{
9251 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
9252}
9253
9254DEFUN (show_bgp_community_list_exact,
9255 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009256 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009257 SHOW_STR
9258 BGP_STR
9259 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009260 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009261 "community-list name\n"
9262 "Exact match of the communities\n")
9263{
9264 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9265}
9266
9267ALIAS (show_bgp_community_list_exact,
9268 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00009269 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00009270 SHOW_STR
9271 BGP_STR
9272 "Address family\n"
9273 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00009274 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00009275 "community-list name\n"
9276 "Exact match of the communities\n")
9277
9278/* old command */
9279DEFUN (show_ipv6_bgp_community_list_exact,
9280 show_ipv6_bgp_community_list_exact_cmd,
9281 "show ipv6 bgp community-list WORD exact-match",
9282 SHOW_STR
9283 IPV6_STR
9284 BGP_STR
9285 "Display routes matching the community-list\n"
9286 "community-list name\n"
9287 "Exact match of the communities\n")
9288{
9289 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9290}
9291
9292/* old command */
9293DEFUN (show_ipv6_mbgp_community_list_exact,
9294 show_ipv6_mbgp_community_list_exact_cmd,
9295 "show ipv6 mbgp community-list WORD exact-match",
9296 SHOW_STR
9297 IPV6_STR
9298 MBGP_STR
9299 "Display routes matching the community-list\n"
9300 "community-list name\n"
9301 "Exact match of the communities\n")
9302{
9303 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9304}
9305#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +02009306
paul94f2b392005-06-28 12:44:16 +00009307static int
paulfd79ac92004-10-13 05:06:08 +00009308bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009309 safi_t safi, enum bgp_show_type type)
9310{
9311 int ret;
9312 struct prefix *p;
9313
9314 p = prefix_new();
9315
9316 ret = str2prefix (prefix, p);
9317 if (! ret)
9318 {
9319 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9320 return CMD_WARNING;
9321 }
9322
ajs5a646652004-11-05 01:25:55 +00009323 ret = bgp_show (vty, NULL, afi, safi, type, p);
9324 prefix_free(p);
9325 return ret;
paul718e3742002-12-13 20:15:29 +00009326}
9327
9328DEFUN (show_ip_bgp_prefix_longer,
9329 show_ip_bgp_prefix_longer_cmd,
9330 "show ip bgp A.B.C.D/M longer-prefixes",
9331 SHOW_STR
9332 IP_STR
9333 BGP_STR
9334 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9335 "Display route and more specific routes\n")
9336{
9337 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9338 bgp_show_type_prefix_longer);
9339}
9340
9341DEFUN (show_ip_bgp_flap_prefix_longer,
9342 show_ip_bgp_flap_prefix_longer_cmd,
9343 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9344 SHOW_STR
9345 IP_STR
9346 BGP_STR
9347 "Display flap statistics of routes\n"
9348 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9349 "Display route and more specific routes\n")
9350{
9351 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9352 bgp_show_type_flap_prefix_longer);
9353}
9354
Balaji3921cc52015-05-16 23:12:17 +05309355ALIAS (show_ip_bgp_flap_prefix_longer,
9356 show_ip_bgp_damp_flap_prefix_longer_cmd,
9357 "show ip bgp dampening flap-statistics A.B.C.D/M longer-prefixes",
9358 SHOW_STR
9359 IP_STR
9360 BGP_STR
9361 "Display detailed information about dampening\n"
9362 "Display flap statistics of routes\n"
9363 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9364 "Display route and more specific routes\n")
9365
paul718e3742002-12-13 20:15:29 +00009366DEFUN (show_ip_bgp_ipv4_prefix_longer,
9367 show_ip_bgp_ipv4_prefix_longer_cmd,
9368 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9369 SHOW_STR
9370 IP_STR
9371 BGP_STR
9372 "Address family\n"
9373 "Address Family modifier\n"
9374 "Address Family modifier\n"
9375 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9376 "Display route and more specific routes\n")
9377{
9378 if (strncmp (argv[0], "m", 1) == 0)
9379 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9380 bgp_show_type_prefix_longer);
9381
9382 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9383 bgp_show_type_prefix_longer);
9384}
9385
9386DEFUN (show_ip_bgp_flap_address,
9387 show_ip_bgp_flap_address_cmd,
9388 "show ip bgp flap-statistics A.B.C.D",
9389 SHOW_STR
9390 IP_STR
9391 BGP_STR
9392 "Display flap statistics of routes\n"
9393 "Network in the BGP routing table to display\n")
9394{
9395 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9396 bgp_show_type_flap_address);
9397}
9398
Balaji3921cc52015-05-16 23:12:17 +05309399ALIAS (show_ip_bgp_flap_address,
9400 show_ip_bgp_damp_flap_address_cmd,
9401 "show ip bgp dampening flap-statistics A.B.C.D",
9402 SHOW_STR
9403 IP_STR
9404 BGP_STR
9405 "Display detailed information about dampening\n"
9406 "Display flap statistics of routes\n"
9407 "Network in the BGP routing table to display\n")
9408
paul718e3742002-12-13 20:15:29 +00009409DEFUN (show_ip_bgp_flap_prefix,
9410 show_ip_bgp_flap_prefix_cmd,
9411 "show ip bgp flap-statistics A.B.C.D/M",
9412 SHOW_STR
9413 IP_STR
9414 BGP_STR
9415 "Display flap statistics of routes\n"
9416 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9417{
9418 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9419 bgp_show_type_flap_prefix);
9420}
Balaji3921cc52015-05-16 23:12:17 +05309421
9422ALIAS (show_ip_bgp_flap_prefix,
9423 show_ip_bgp_damp_flap_prefix_cmd,
9424 "show ip bgp dampening flap-statistics A.B.C.D/M",
9425 SHOW_STR
9426 IP_STR
9427 BGP_STR
9428 "Display detailed information about dampening\n"
9429 "Display flap statistics of routes\n"
9430 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9431
paul718e3742002-12-13 20:15:29 +00009432#ifdef HAVE_IPV6
9433DEFUN (show_bgp_prefix_longer,
9434 show_bgp_prefix_longer_cmd,
9435 "show bgp X:X::X:X/M longer-prefixes",
9436 SHOW_STR
9437 BGP_STR
9438 "IPv6 prefix <network>/<length>\n"
9439 "Display route and more specific routes\n")
9440{
9441 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9442 bgp_show_type_prefix_longer);
9443}
9444
9445ALIAS (show_bgp_prefix_longer,
9446 show_bgp_ipv6_prefix_longer_cmd,
9447 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9448 SHOW_STR
9449 BGP_STR
9450 "Address family\n"
9451 "IPv6 prefix <network>/<length>\n"
9452 "Display route and more specific routes\n")
9453
9454/* old command */
9455DEFUN (show_ipv6_bgp_prefix_longer,
9456 show_ipv6_bgp_prefix_longer_cmd,
9457 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9458 SHOW_STR
9459 IPV6_STR
9460 BGP_STR
9461 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9462 "Display route and more specific routes\n")
9463{
9464 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9465 bgp_show_type_prefix_longer);
9466}
9467
9468/* old command */
9469DEFUN (show_ipv6_mbgp_prefix_longer,
9470 show_ipv6_mbgp_prefix_longer_cmd,
9471 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9472 SHOW_STR
9473 IPV6_STR
9474 MBGP_STR
9475 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9476 "Display route and more specific routes\n")
9477{
9478 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9479 bgp_show_type_prefix_longer);
9480}
9481#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009482
paul94f2b392005-06-28 12:44:16 +00009483static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009484peer_lookup_in_view (struct vty *vty, const char *view_name,
9485 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009486{
9487 int ret;
9488 struct bgp *bgp;
9489 struct peer *peer;
9490 union sockunion su;
9491
9492 /* BGP structure lookup. */
9493 if (view_name)
9494 {
9495 bgp = bgp_lookup_by_name (view_name);
9496 if (! bgp)
9497 {
9498 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9499 return NULL;
9500 }
9501 }
paul5228ad22004-06-04 17:58:18 +00009502 else
paulbb46e942003-10-24 19:02:03 +00009503 {
9504 bgp = bgp_get_default ();
9505 if (! bgp)
9506 {
9507 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9508 return NULL;
9509 }
9510 }
9511
9512 /* Get peer sockunion. */
9513 ret = str2sockunion (ip_str, &su);
9514 if (ret < 0)
9515 {
9516 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9517 return NULL;
9518 }
9519
9520 /* Peer structure lookup. */
9521 peer = peer_lookup (bgp, &su);
9522 if (! peer)
9523 {
9524 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9525 return NULL;
9526 }
9527
9528 return peer;
9529}
David Lamparter6b0655a2014-06-04 06:53:35 +02009530
Paul Jakma2815e612006-09-14 02:56:07 +00009531enum bgp_stats
9532{
9533 BGP_STATS_MAXBITLEN = 0,
9534 BGP_STATS_RIB,
9535 BGP_STATS_PREFIXES,
9536 BGP_STATS_TOTPLEN,
9537 BGP_STATS_UNAGGREGATEABLE,
9538 BGP_STATS_MAX_AGGREGATEABLE,
9539 BGP_STATS_AGGREGATES,
9540 BGP_STATS_SPACE,
9541 BGP_STATS_ASPATH_COUNT,
9542 BGP_STATS_ASPATH_MAXHOPS,
9543 BGP_STATS_ASPATH_TOTHOPS,
9544 BGP_STATS_ASPATH_MAXSIZE,
9545 BGP_STATS_ASPATH_TOTSIZE,
9546 BGP_STATS_ASN_HIGHEST,
9547 BGP_STATS_MAX,
9548};
paulbb46e942003-10-24 19:02:03 +00009549
Paul Jakma2815e612006-09-14 02:56:07 +00009550static const char *table_stats_strs[] =
9551{
9552 [BGP_STATS_PREFIXES] = "Total Prefixes",
9553 [BGP_STATS_TOTPLEN] = "Average prefix length",
9554 [BGP_STATS_RIB] = "Total Advertisements",
9555 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9556 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9557 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9558 [BGP_STATS_SPACE] = "Address space advertised",
9559 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9560 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9561 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9562 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9563 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9564 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9565 [BGP_STATS_MAX] = NULL,
9566};
9567
9568struct bgp_table_stats
9569{
9570 struct bgp_table *table;
9571 unsigned long long counts[BGP_STATS_MAX];
9572};
9573
9574#if 0
9575#define TALLY_SIGFIG 100000
9576static unsigned long
9577ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9578{
9579 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9580 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9581 unsigned long ret = newtot / count;
9582
9583 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9584 return ret + 1;
9585 else
9586 return ret;
9587}
9588#endif
9589
9590static int
9591bgp_table_stats_walker (struct thread *t)
9592{
9593 struct bgp_node *rn;
9594 struct bgp_node *top;
9595 struct bgp_table_stats *ts = THREAD_ARG (t);
9596 unsigned int space = 0;
9597
Paul Jakma53d9f672006-10-15 23:41:16 +00009598 if (!(top = bgp_table_top (ts->table)))
9599 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009600
9601 switch (top->p.family)
9602 {
9603 case AF_INET:
9604 space = IPV4_MAX_BITLEN;
9605 break;
9606 case AF_INET6:
9607 space = IPV6_MAX_BITLEN;
9608 break;
9609 }
9610
9611 ts->counts[BGP_STATS_MAXBITLEN] = space;
9612
9613 for (rn = top; rn; rn = bgp_route_next (rn))
9614 {
9615 struct bgp_info *ri;
Avneesh Sachdev67174042012-08-17 08:19:49 -07009616 struct bgp_node *prn = bgp_node_parent_nolock (rn);
Paul Jakma2815e612006-09-14 02:56:07 +00009617 unsigned int rinum = 0;
9618
9619 if (rn == top)
9620 continue;
9621
9622 if (!rn->info)
9623 continue;
9624
9625 ts->counts[BGP_STATS_PREFIXES]++;
9626 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9627
9628#if 0
9629 ts->counts[BGP_STATS_AVGPLEN]
9630 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9631 ts->counts[BGP_STATS_AVGPLEN],
9632 rn->p.prefixlen);
9633#endif
9634
9635 /* check if the prefix is included by any other announcements */
9636 while (prn && !prn->info)
Avneesh Sachdev67174042012-08-17 08:19:49 -07009637 prn = bgp_node_parent_nolock (prn);
Paul Jakma2815e612006-09-14 02:56:07 +00009638
9639 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009640 {
9641 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9642 /* announced address space */
9643 if (space)
9644 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9645 }
Paul Jakma2815e612006-09-14 02:56:07 +00009646 else if (prn->info)
9647 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9648
Paul Jakma2815e612006-09-14 02:56:07 +00009649 for (ri = rn->info; ri; ri = ri->next)
9650 {
9651 rinum++;
9652 ts->counts[BGP_STATS_RIB]++;
9653
9654 if (ri->attr &&
9655 (CHECK_FLAG (ri->attr->flag,
9656 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9657 ts->counts[BGP_STATS_AGGREGATES]++;
9658
9659 /* as-path stats */
9660 if (ri->attr && ri->attr->aspath)
9661 {
9662 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9663 unsigned int size = aspath_size (ri->attr->aspath);
9664 as_t highest = aspath_highest (ri->attr->aspath);
9665
9666 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9667
9668 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9669 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9670
9671 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9672 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9673
9674 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9675 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9676#if 0
9677 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9678 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9679 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9680 hops);
9681 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9682 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9683 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9684 size);
9685#endif
9686 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9687 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9688 }
9689 }
9690 }
9691 return 0;
9692}
9693
9694static int
9695bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9696{
9697 struct bgp_table_stats ts;
9698 unsigned int i;
9699
9700 if (!bgp->rib[afi][safi])
9701 {
9702 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9703 return CMD_WARNING;
9704 }
9705
9706 memset (&ts, 0, sizeof (ts));
9707 ts.table = bgp->rib[afi][safi];
9708 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9709
9710 vty_out (vty, "BGP %s RIB statistics%s%s",
9711 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9712
9713 for (i = 0; i < BGP_STATS_MAX; i++)
9714 {
9715 if (!table_stats_strs[i])
9716 continue;
9717
9718 switch (i)
9719 {
9720#if 0
9721 case BGP_STATS_ASPATH_AVGHOPS:
9722 case BGP_STATS_ASPATH_AVGSIZE:
9723 case BGP_STATS_AVGPLEN:
9724 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9725 vty_out (vty, "%12.2f",
9726 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9727 break;
9728#endif
9729 case BGP_STATS_ASPATH_TOTHOPS:
9730 case BGP_STATS_ASPATH_TOTSIZE:
9731 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9732 vty_out (vty, "%12.2f",
9733 ts.counts[i] ?
9734 (float)ts.counts[i] /
9735 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9736 : 0);
9737 break;
9738 case BGP_STATS_TOTPLEN:
9739 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9740 vty_out (vty, "%12.2f",
9741 ts.counts[i] ?
9742 (float)ts.counts[i] /
9743 (float)ts.counts[BGP_STATS_PREFIXES]
9744 : 0);
9745 break;
9746 case BGP_STATS_SPACE:
9747 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9748 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9749 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9750 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009751 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009752 vty_out (vty, "%12.2f%s",
9753 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009754 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009755 VTY_NEWLINE);
9756 vty_out (vty, "%30s: ", "/8 equivalent ");
9757 vty_out (vty, "%12.2f%s",
9758 (float)ts.counts[BGP_STATS_SPACE] /
9759 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9760 VTY_NEWLINE);
9761 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9762 break;
9763 vty_out (vty, "%30s: ", "/24 equivalent ");
9764 vty_out (vty, "%12.2f",
9765 (float)ts.counts[BGP_STATS_SPACE] /
9766 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9767 break;
9768 default:
9769 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9770 vty_out (vty, "%12llu", ts.counts[i]);
9771 }
9772
9773 vty_out (vty, "%s", VTY_NEWLINE);
9774 }
9775 return CMD_SUCCESS;
9776}
9777
9778static int
9779bgp_table_stats_vty (struct vty *vty, const char *name,
9780 const char *afi_str, const char *safi_str)
9781{
9782 struct bgp *bgp;
9783 afi_t afi;
9784 safi_t safi;
9785
9786 if (name)
9787 bgp = bgp_lookup_by_name (name);
9788 else
9789 bgp = bgp_get_default ();
9790
9791 if (!bgp)
9792 {
9793 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9794 return CMD_WARNING;
9795 }
9796 if (strncmp (afi_str, "ipv", 3) == 0)
9797 {
9798 if (strncmp (afi_str, "ipv4", 4) == 0)
9799 afi = AFI_IP;
9800 else if (strncmp (afi_str, "ipv6", 4) == 0)
9801 afi = AFI_IP6;
9802 else
9803 {
9804 vty_out (vty, "%% Invalid address family %s%s",
9805 afi_str, VTY_NEWLINE);
9806 return CMD_WARNING;
9807 }
Lou Berger298cc2f2016-01-12 13:42:02 -05009808 switch (safi_str[0]) {
9809 case 'm':
9810 safi = SAFI_MULTICAST;
9811 break;
9812 case 'u':
9813 safi = SAFI_UNICAST;
9814 break;
9815 case 'v':
9816 safi = SAFI_MPLS_LABELED_VPN;
9817 break;
9818 case 'e':
9819 safi = SAFI_ENCAP;
9820 break;
9821 default:
9822 vty_out (vty, "%% Invalid subsequent address family %s%s",
Paul Jakma2815e612006-09-14 02:56:07 +00009823 safi_str, VTY_NEWLINE);
Lou Berger298cc2f2016-01-12 13:42:02 -05009824 return CMD_WARNING;
9825 }
Paul Jakma2815e612006-09-14 02:56:07 +00009826 }
9827 else
9828 {
Lou Berger298cc2f2016-01-12 13:42:02 -05009829 vty_out (vty, "%% Invalid address family \"%s\"%s",
Paul Jakma2815e612006-09-14 02:56:07 +00009830 afi_str, VTY_NEWLINE);
9831 return CMD_WARNING;
9832 }
9833
Paul Jakma2815e612006-09-14 02:56:07 +00009834 return bgp_table_stats (vty, bgp, afi, safi);
9835}
9836
9837DEFUN (show_bgp_statistics,
9838 show_bgp_statistics_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -05009839 "show bgp (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009840 SHOW_STR
9841 BGP_STR
9842 "Address family\n"
9843 "Address family\n"
9844 "Address Family modifier\n"
9845 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -05009846 "Address Family modifier\n"
9847 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +00009848 "BGP RIB advertisement statistics\n")
9849{
9850 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9851}
9852
Paul Jakma2815e612006-09-14 02:56:07 +00009853DEFUN (show_bgp_statistics_view,
9854 show_bgp_statistics_view_cmd,
Lou Berger298cc2f2016-01-12 13:42:02 -05009855 "show bgp view WORD (ipv4|ipv6) (encap|multicast|unicast|vpn) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009856 SHOW_STR
9857 BGP_STR
9858 "BGP view\n"
9859 "Address family\n"
9860 "Address family\n"
9861 "Address Family modifier\n"
9862 "Address Family modifier\n"
Lou Berger298cc2f2016-01-12 13:42:02 -05009863 "Address Family modifier\n"
9864 "Address Family modifier\n"
Paul Jakma2815e612006-09-14 02:56:07 +00009865 "BGP RIB advertisement statistics\n")
9866{
9867 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9868}
9869
Lou Berger298cc2f2016-01-12 13:42:02 -05009870#if 0 /* added as options to above command */
Paul Jakma2815e612006-09-14 02:56:07 +00009871ALIAS (show_bgp_statistics_view,
Lou Berger298cc2f2016-01-12 13:42:02 -05009872 show_bgp_statistics_view_encap_cmd,
9873 "show bgp view WORD (ipv4) (encap) statistics",
Paul Jakma2815e612006-09-14 02:56:07 +00009874 SHOW_STR
9875 BGP_STR
9876 "BGP view\n"
9877 "Address family\n"
9878 "Address Family modifier\n"
9879 "BGP RIB advertisement statistics\n")
Lou Berger298cc2f2016-01-12 13:42:02 -05009880#endif
David Lamparter6b0655a2014-06-04 06:53:35 +02009881
Paul Jakmaff7924f2006-09-04 01:10:36 +00009882enum bgp_pcounts
9883{
9884 PCOUNT_ADJ_IN = 0,
9885 PCOUNT_DAMPED,
9886 PCOUNT_REMOVED,
9887 PCOUNT_HISTORY,
9888 PCOUNT_STALE,
9889 PCOUNT_VALID,
9890 PCOUNT_ALL,
9891 PCOUNT_COUNTED,
9892 PCOUNT_PFCNT, /* the figure we display to users */
9893 PCOUNT_MAX,
9894};
9895
9896static const char *pcount_strs[] =
9897{
9898 [PCOUNT_ADJ_IN] = "Adj-in",
9899 [PCOUNT_DAMPED] = "Damped",
9900 [PCOUNT_REMOVED] = "Removed",
9901 [PCOUNT_HISTORY] = "History",
9902 [PCOUNT_STALE] = "Stale",
9903 [PCOUNT_VALID] = "Valid",
9904 [PCOUNT_ALL] = "All RIB",
9905 [PCOUNT_COUNTED] = "PfxCt counted",
9906 [PCOUNT_PFCNT] = "Useable",
9907 [PCOUNT_MAX] = NULL,
9908};
9909
Paul Jakma2815e612006-09-14 02:56:07 +00009910struct peer_pcounts
9911{
9912 unsigned int count[PCOUNT_MAX];
9913 const struct peer *peer;
9914 const struct bgp_table *table;
9915};
9916
Paul Jakmaff7924f2006-09-04 01:10:36 +00009917static int
Paul Jakma2815e612006-09-14 02:56:07 +00009918bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009919{
9920 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009921 struct peer_pcounts *pc = THREAD_ARG (t);
9922 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009923
Paul Jakma2815e612006-09-14 02:56:07 +00009924 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009925 {
9926 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009927 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009928
9929 for (ain = rn->adj_in; ain; ain = ain->next)
9930 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009931 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009932
Paul Jakmaff7924f2006-09-04 01:10:36 +00009933 for (ri = rn->info; ri; ri = ri->next)
9934 {
9935 char buf[SU_ADDRSTRLEN];
9936
9937 if (ri->peer != peer)
9938 continue;
9939
Paul Jakma2815e612006-09-14 02:56:07 +00009940 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009941
9942 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009943 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009944 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009945 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009946 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009947 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009948 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009949 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009950 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009951 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009952 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009953 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009954
9955 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9956 {
Paul Jakma2815e612006-09-14 02:56:07 +00009957 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009958 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009959 plog_warn (peer->log,
9960 "%s [pcount] %s/%d is counted but flags 0x%x",
9961 peer->host,
9962 inet_ntop(rn->p.family, &rn->p.u.prefix,
9963 buf, SU_ADDRSTRLEN),
9964 rn->p.prefixlen,
9965 ri->flags);
9966 }
9967 else
9968 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009969 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009970 plog_warn (peer->log,
9971 "%s [pcount] %s/%d not counted but flags 0x%x",
9972 peer->host,
9973 inet_ntop(rn->p.family, &rn->p.u.prefix,
9974 buf, SU_ADDRSTRLEN),
9975 rn->p.prefixlen,
9976 ri->flags);
9977 }
9978 }
9979 }
Paul Jakma2815e612006-09-14 02:56:07 +00009980 return 0;
9981}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009982
Paul Jakma2815e612006-09-14 02:56:07 +00009983static int
9984bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9985{
9986 struct peer_pcounts pcounts = { .peer = peer };
9987 unsigned int i;
9988
9989 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9990 || !peer->bgp->rib[afi][safi])
9991 {
9992 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9993 return CMD_WARNING;
9994 }
9995
9996 memset (&pcounts, 0, sizeof(pcounts));
9997 pcounts.peer = peer;
9998 pcounts.table = peer->bgp->rib[afi][safi];
9999
10000 /* in-place call via thread subsystem so as to record execution time
10001 * stats for the thread-walk (i.e. ensure this can't be blamed on
10002 * on just vty_read()).
10003 */
10004 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
10005
Paul Jakmaff7924f2006-09-04 01:10:36 +000010006 vty_out (vty, "Prefix counts for %s, %s%s",
10007 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
10008 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
10009 vty_out (vty, "%sCounts from RIB table walk:%s%s",
10010 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
10011
10012 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +000010013 vty_out (vty, "%20s: %-10d%s",
10014 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +000010015
Paul Jakma2815e612006-09-14 02:56:07 +000010016 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +000010017 {
10018 vty_out (vty, "%s [pcount] PfxCt drift!%s",
10019 peer->host, VTY_NEWLINE);
10020 vty_out (vty, "Please report this bug, with the above command output%s",
10021 VTY_NEWLINE);
10022 }
10023
10024 return CMD_SUCCESS;
10025}
10026
10027DEFUN (show_ip_bgp_neighbor_prefix_counts,
10028 show_ip_bgp_neighbor_prefix_counts_cmd,
10029 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10030 SHOW_STR
10031 IP_STR
10032 BGP_STR
10033 "Detailed information on TCP and BGP neighbor connections\n"
10034 "Neighbor to display information about\n"
10035 "Neighbor to display information about\n"
10036 "Display detailed prefix count information\n")
10037{
10038 struct peer *peer;
10039
10040 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10041 if (! peer)
10042 return CMD_WARNING;
10043
10044 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10045}
10046
10047DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
10048 show_bgp_ipv6_neighbor_prefix_counts_cmd,
10049 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10050 SHOW_STR
10051 BGP_STR
10052 "Address family\n"
10053 "Detailed information on TCP and BGP neighbor connections\n"
10054 "Neighbor to display information about\n"
10055 "Neighbor to display information about\n"
10056 "Display detailed prefix count information\n")
10057{
10058 struct peer *peer;
10059
10060 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10061 if (! peer)
10062 return CMD_WARNING;
10063
10064 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
10065}
10066
10067DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
10068 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
10069 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10070 SHOW_STR
10071 IP_STR
10072 BGP_STR
10073 "Address family\n"
10074 "Address Family modifier\n"
10075 "Address Family modifier\n"
10076 "Detailed information on TCP and BGP neighbor connections\n"
10077 "Neighbor to display information about\n"
10078 "Neighbor to display information about\n"
10079 "Display detailed prefix count information\n")
10080{
10081 struct peer *peer;
10082
10083 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10084 if (! peer)
10085 return CMD_WARNING;
10086
10087 if (strncmp (argv[0], "m", 1) == 0)
10088 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
10089
10090 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
10091}
10092
10093DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
10094 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
10095 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
10096 SHOW_STR
10097 IP_STR
10098 BGP_STR
10099 "Address family\n"
10100 "Address Family modifier\n"
10101 "Address Family modifier\n"
10102 "Detailed information on TCP and BGP neighbor connections\n"
10103 "Neighbor to display information about\n"
10104 "Neighbor to display information about\n"
10105 "Display detailed prefix count information\n")
10106{
10107 struct peer *peer;
10108
10109 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10110 if (! peer)
10111 return CMD_WARNING;
10112
10113 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
10114}
10115
10116
paul94f2b392005-06-28 12:44:16 +000010117static void
paul718e3742002-12-13 20:15:29 +000010118show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
10119 int in)
10120{
10121 struct bgp_table *table;
10122 struct bgp_adj_in *ain;
10123 struct bgp_adj_out *adj;
10124 unsigned long output_count;
10125 struct bgp_node *rn;
10126 int header1 = 1;
10127 struct bgp *bgp;
10128 int header2 = 1;
10129
paulbb46e942003-10-24 19:02:03 +000010130 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +000010131
10132 if (! bgp)
10133 return;
10134
10135 table = bgp->rib[afi][safi];
10136
10137 output_count = 0;
10138
10139 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
10140 PEER_STATUS_DEFAULT_ORIGINATE))
10141 {
10142 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 +000010143 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10144 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010145
10146 vty_out (vty, "Originating default network 0.0.0.0%s%s",
10147 VTY_NEWLINE, VTY_NEWLINE);
10148 header1 = 0;
10149 }
10150
10151 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
10152 if (in)
10153 {
10154 for (ain = rn->adj_in; ain; ain = ain->next)
10155 if (ain->peer == peer)
10156 {
10157 if (header1)
10158 {
10159 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 +000010160 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10161 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010162 header1 = 0;
10163 }
10164 if (header2)
10165 {
10166 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10167 header2 = 0;
10168 }
10169 if (ain->attr)
10170 {
10171 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
10172 output_count++;
10173 }
10174 }
10175 }
10176 else
10177 {
10178 for (adj = rn->adj_out; adj; adj = adj->next)
10179 if (adj->peer == peer)
10180 {
10181 if (header1)
10182 {
10183 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 +000010184 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
10185 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010186 header1 = 0;
10187 }
10188 if (header2)
10189 {
10190 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
10191 header2 = 0;
10192 }
10193 if (adj->attr)
10194 {
10195 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
10196 output_count++;
10197 }
10198 }
10199 }
10200
10201 if (output_count != 0)
10202 vty_out (vty, "%sTotal number of prefixes %ld%s",
10203 VTY_NEWLINE, output_count, VTY_NEWLINE);
10204}
10205
paul94f2b392005-06-28 12:44:16 +000010206static int
paulbb46e942003-10-24 19:02:03 +000010207peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
10208{
paul718e3742002-12-13 20:15:29 +000010209 if (! peer || ! peer->afc[afi][safi])
10210 {
10211 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
10212 return CMD_WARNING;
10213 }
10214
10215 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
10216 {
10217 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
10218 VTY_NEWLINE);
10219 return CMD_WARNING;
10220 }
10221
10222 show_adj_route (vty, peer, afi, safi, in);
10223
10224 return CMD_SUCCESS;
10225}
10226
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010227DEFUN (show_ip_bgp_view_neighbor_advertised_route,
10228 show_ip_bgp_view_neighbor_advertised_route_cmd,
10229 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10230 SHOW_STR
10231 IP_STR
10232 BGP_STR
10233 "BGP view\n"
10234 "View name\n"
10235 "Detailed information on TCP and BGP neighbor connections\n"
10236 "Neighbor to display information about\n"
10237 "Neighbor to display information about\n"
10238 "Display the routes advertised to a BGP neighbor\n")
10239{
10240 struct peer *peer;
10241
10242 if (argc == 2)
10243 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10244 else
10245 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10246
10247 if (! peer)
10248 return CMD_WARNING;
10249
10250 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
10251}
10252
10253ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010254 show_ip_bgp_neighbor_advertised_route_cmd,
10255 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10256 SHOW_STR
10257 IP_STR
10258 BGP_STR
10259 "Detailed information on TCP and BGP neighbor connections\n"
10260 "Neighbor to display information about\n"
10261 "Neighbor to display information about\n"
10262 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +000010263
10264DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
10265 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
10266 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10267 SHOW_STR
10268 IP_STR
10269 BGP_STR
10270 "Address family\n"
10271 "Address Family modifier\n"
10272 "Address Family modifier\n"
10273 "Detailed information on TCP and BGP neighbor connections\n"
10274 "Neighbor to display information about\n"
10275 "Neighbor to display information about\n"
10276 "Display the routes advertised to a BGP neighbor\n")
10277{
paulbb46e942003-10-24 19:02:03 +000010278 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010279
paulbb46e942003-10-24 19:02:03 +000010280 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10281 if (! peer)
10282 return CMD_WARNING;
10283
10284 if (strncmp (argv[0], "m", 1) == 0)
10285 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
10286
10287 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +000010288}
10289
10290#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010291DEFUN (show_bgp_view_neighbor_advertised_route,
10292 show_bgp_view_neighbor_advertised_route_cmd,
10293 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10294 SHOW_STR
10295 BGP_STR
10296 "BGP view\n"
10297 "View name\n"
10298 "Detailed information on TCP and BGP neighbor connections\n"
10299 "Neighbor to display information about\n"
10300 "Neighbor to display information about\n"
10301 "Display the routes advertised to a BGP neighbor\n")
10302{
10303 struct peer *peer;
10304
10305 if (argc == 2)
10306 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10307 else
10308 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10309
10310 if (! peer)
10311 return CMD_WARNING;
10312
10313 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
10314}
10315
10316ALIAS (show_bgp_view_neighbor_advertised_route,
10317 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10318 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10319 SHOW_STR
10320 BGP_STR
10321 "BGP view\n"
10322 "View name\n"
10323 "Address family\n"
10324 "Detailed information on TCP and BGP neighbor connections\n"
10325 "Neighbor to display information about\n"
10326 "Neighbor to display information about\n"
10327 "Display the routes advertised to a BGP neighbor\n")
10328
10329DEFUN (show_bgp_view_neighbor_received_routes,
10330 show_bgp_view_neighbor_received_routes_cmd,
10331 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10332 SHOW_STR
10333 BGP_STR
10334 "BGP view\n"
10335 "View name\n"
10336 "Detailed information on TCP and BGP neighbor connections\n"
10337 "Neighbor to display information about\n"
10338 "Neighbor to display information about\n"
10339 "Display the received routes from neighbor\n")
10340{
10341 struct peer *peer;
10342
10343 if (argc == 2)
10344 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10345 else
10346 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10347
10348 if (! peer)
10349 return CMD_WARNING;
10350
10351 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10352}
10353
10354ALIAS (show_bgp_view_neighbor_received_routes,
10355 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10356 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10357 SHOW_STR
10358 BGP_STR
10359 "BGP view\n"
10360 "View name\n"
10361 "Address family\n"
10362 "Detailed information on TCP and BGP neighbor connections\n"
10363 "Neighbor to display information about\n"
10364 "Neighbor to display information about\n"
10365 "Display the received routes from neighbor\n")
10366
10367ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010368 show_bgp_neighbor_advertised_route_cmd,
10369 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10370 SHOW_STR
10371 BGP_STR
10372 "Detailed information on TCP and BGP neighbor connections\n"
10373 "Neighbor to display information about\n"
10374 "Neighbor to display information about\n"
10375 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010376
10377ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010378 show_bgp_ipv6_neighbor_advertised_route_cmd,
10379 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10380 SHOW_STR
10381 BGP_STR
10382 "Address family\n"
10383 "Detailed information on TCP and BGP neighbor connections\n"
10384 "Neighbor to display information about\n"
10385 "Neighbor to display information about\n"
10386 "Display the routes advertised to a BGP neighbor\n")
10387
10388/* old command */
paulbb46e942003-10-24 19:02:03 +000010389ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010390 ipv6_bgp_neighbor_advertised_route_cmd,
10391 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10392 SHOW_STR
10393 IPV6_STR
10394 BGP_STR
10395 "Detailed information on TCP and BGP neighbor connections\n"
10396 "Neighbor to display information about\n"
10397 "Neighbor to display information about\n"
10398 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010399
paul718e3742002-12-13 20:15:29 +000010400/* old command */
10401DEFUN (ipv6_mbgp_neighbor_advertised_route,
10402 ipv6_mbgp_neighbor_advertised_route_cmd,
10403 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10404 SHOW_STR
10405 IPV6_STR
10406 MBGP_STR
10407 "Detailed information on TCP and BGP neighbor connections\n"
10408 "Neighbor to display information about\n"
10409 "Neighbor to display information about\n"
10410 "Display the routes advertised to a BGP neighbor\n")
10411{
paulbb46e942003-10-24 19:02:03 +000010412 struct peer *peer;
10413
10414 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10415 if (! peer)
10416 return CMD_WARNING;
10417
10418 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010419}
10420#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010421
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010422DEFUN (show_ip_bgp_view_neighbor_received_routes,
10423 show_ip_bgp_view_neighbor_received_routes_cmd,
10424 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10425 SHOW_STR
10426 IP_STR
10427 BGP_STR
10428 "BGP view\n"
10429 "View name\n"
10430 "Detailed information on TCP and BGP neighbor connections\n"
10431 "Neighbor to display information about\n"
10432 "Neighbor to display information about\n"
10433 "Display the received routes from neighbor\n")
10434{
10435 struct peer *peer;
10436
10437 if (argc == 2)
10438 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10439 else
10440 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10441
10442 if (! peer)
10443 return CMD_WARNING;
10444
10445 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10446}
10447
10448ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010449 show_ip_bgp_neighbor_received_routes_cmd,
10450 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10451 SHOW_STR
10452 IP_STR
10453 BGP_STR
10454 "Detailed information on TCP and BGP neighbor connections\n"
10455 "Neighbor to display information about\n"
10456 "Neighbor to display information about\n"
10457 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010458
10459DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10460 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10461 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10462 SHOW_STR
10463 IP_STR
10464 BGP_STR
10465 "Address family\n"
10466 "Address Family modifier\n"
10467 "Address Family modifier\n"
10468 "Detailed information on TCP and BGP neighbor connections\n"
10469 "Neighbor to display information about\n"
10470 "Neighbor to display information about\n"
10471 "Display the received routes from neighbor\n")
10472{
paulbb46e942003-10-24 19:02:03 +000010473 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010474
paulbb46e942003-10-24 19:02:03 +000010475 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10476 if (! peer)
10477 return CMD_WARNING;
10478
10479 if (strncmp (argv[0], "m", 1) == 0)
10480 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10481
10482 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010483}
10484
Michael Lambert95cbbd22010-07-23 14:43:04 -040010485DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10486 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
Michael Lambert95cbbd22010-07-23 14:43:04 -040010487 "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 -040010488 SHOW_STR
10489 BGP_STR
10490 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010491 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010492 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010493 "Address family\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010494 "Address family modifier\n"
10495 "Address family modifier\n"
10496 "Detailed information on TCP and BGP neighbor connections\n"
10497 "Neighbor to display information about\n"
10498 "Neighbor to display information about\n"
10499 "Display the advertised routes to neighbor\n"
10500 "Display the received routes from neighbor\n")
10501{
10502 int afi;
10503 int safi;
10504 int in;
10505 struct peer *peer;
10506
David Lamparter94bad672015-03-03 08:52:22 +010010507 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
Michael Lambert95cbbd22010-07-23 14:43:04 -040010508
10509 if (! peer)
10510 return CMD_WARNING;
10511
Michael Lambert95cbbd22010-07-23 14:43:04 -040010512 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10513 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10514 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
Michael Lambert95cbbd22010-07-23 14:43:04 -040010515
10516 return peer_adj_routes (vty, peer, afi, safi, in);
10517}
10518
paul718e3742002-12-13 20:15:29 +000010519DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10520 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10521 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10522 SHOW_STR
10523 IP_STR
10524 BGP_STR
10525 "Detailed information on TCP and BGP neighbor connections\n"
10526 "Neighbor to display information about\n"
10527 "Neighbor to display information about\n"
10528 "Display information received from a BGP neighbor\n"
10529 "Display the prefixlist filter\n")
10530{
10531 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010532 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010533 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010534 int count, ret;
paul718e3742002-12-13 20:15:29 +000010535
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010536 ret = str2sockunion (argv[0], &su);
10537 if (ret < 0)
10538 {
10539 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10540 return CMD_WARNING;
10541 }
paul718e3742002-12-13 20:15:29 +000010542
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010543 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010544 if (! peer)
10545 return CMD_WARNING;
10546
10547 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10548 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10549 if (count)
10550 {
10551 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10552 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10553 }
10554
10555 return CMD_SUCCESS;
10556}
10557
10558DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10559 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10560 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10561 SHOW_STR
10562 IP_STR
10563 BGP_STR
10564 "Address family\n"
10565 "Address Family modifier\n"
10566 "Address Family modifier\n"
10567 "Detailed information on TCP and BGP neighbor connections\n"
10568 "Neighbor to display information about\n"
10569 "Neighbor to display information about\n"
10570 "Display information received from a BGP neighbor\n"
10571 "Display the prefixlist filter\n")
10572{
10573 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010574 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010575 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010576 int count, ret;
paul718e3742002-12-13 20:15:29 +000010577
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010578 ret = str2sockunion (argv[1], &su);
10579 if (ret < 0)
10580 {
10581 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10582 return CMD_WARNING;
10583 }
paul718e3742002-12-13 20:15:29 +000010584
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010585 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010586 if (! peer)
10587 return CMD_WARNING;
10588
10589 if (strncmp (argv[0], "m", 1) == 0)
10590 {
10591 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10592 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10593 if (count)
10594 {
10595 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10596 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10597 }
10598 }
10599 else
10600 {
10601 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10602 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10603 if (count)
10604 {
10605 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10606 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10607 }
10608 }
10609
10610 return CMD_SUCCESS;
10611}
10612
10613
10614#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010615ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010616 show_bgp_neighbor_received_routes_cmd,
10617 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10618 SHOW_STR
10619 BGP_STR
10620 "Detailed information on TCP and BGP neighbor connections\n"
10621 "Neighbor to display information about\n"
10622 "Neighbor to display information about\n"
10623 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010624
paulbb46e942003-10-24 19:02:03 +000010625ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010626 show_bgp_ipv6_neighbor_received_routes_cmd,
10627 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10628 SHOW_STR
10629 BGP_STR
10630 "Address family\n"
10631 "Detailed information on TCP and BGP neighbor connections\n"
10632 "Neighbor to display information about\n"
10633 "Neighbor to display information about\n"
10634 "Display the received routes from neighbor\n")
10635
10636DEFUN (show_bgp_neighbor_received_prefix_filter,
10637 show_bgp_neighbor_received_prefix_filter_cmd,
10638 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10639 SHOW_STR
10640 BGP_STR
10641 "Detailed information on TCP and BGP neighbor connections\n"
10642 "Neighbor to display information about\n"
10643 "Neighbor to display information about\n"
10644 "Display information received from a BGP neighbor\n"
10645 "Display the prefixlist filter\n")
10646{
10647 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010648 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010649 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010650 int count, ret;
paul718e3742002-12-13 20:15:29 +000010651
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010652 ret = str2sockunion (argv[0], &su);
10653 if (ret < 0)
10654 {
10655 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10656 return CMD_WARNING;
10657 }
paul718e3742002-12-13 20:15:29 +000010658
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010659 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010660 if (! peer)
10661 return CMD_WARNING;
10662
10663 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10664 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10665 if (count)
10666 {
10667 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10668 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10669 }
10670
10671 return CMD_SUCCESS;
10672}
10673
10674ALIAS (show_bgp_neighbor_received_prefix_filter,
10675 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10676 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10677 SHOW_STR
10678 BGP_STR
10679 "Address family\n"
10680 "Detailed information on TCP and BGP neighbor connections\n"
10681 "Neighbor to display information about\n"
10682 "Neighbor to display information about\n"
10683 "Display information received from a BGP neighbor\n"
10684 "Display the prefixlist filter\n")
10685
10686/* old command */
paulbb46e942003-10-24 19:02:03 +000010687ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010688 ipv6_bgp_neighbor_received_routes_cmd,
10689 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10690 SHOW_STR
10691 IPV6_STR
10692 BGP_STR
10693 "Detailed information on TCP and BGP neighbor connections\n"
10694 "Neighbor to display information about\n"
10695 "Neighbor to display information about\n"
10696 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010697
10698/* old command */
10699DEFUN (ipv6_mbgp_neighbor_received_routes,
10700 ipv6_mbgp_neighbor_received_routes_cmd,
10701 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10702 SHOW_STR
10703 IPV6_STR
10704 MBGP_STR
10705 "Detailed information on TCP and BGP neighbor connections\n"
10706 "Neighbor to display information about\n"
10707 "Neighbor to display information about\n"
10708 "Display the received routes from neighbor\n")
10709{
paulbb46e942003-10-24 19:02:03 +000010710 struct peer *peer;
10711
10712 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10713 if (! peer)
10714 return CMD_WARNING;
10715
10716 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010717}
paulbb46e942003-10-24 19:02:03 +000010718
10719DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10720 show_bgp_view_neighbor_received_prefix_filter_cmd,
10721 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10722 SHOW_STR
10723 BGP_STR
10724 "BGP view\n"
10725 "View name\n"
10726 "Detailed information on TCP and BGP neighbor connections\n"
10727 "Neighbor to display information about\n"
10728 "Neighbor to display information about\n"
10729 "Display information received from a BGP neighbor\n"
10730 "Display the prefixlist filter\n")
10731{
10732 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010733 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010734 struct peer *peer;
10735 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010736 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010737
10738 /* BGP structure lookup. */
10739 bgp = bgp_lookup_by_name (argv[0]);
10740 if (bgp == NULL)
10741 {
10742 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10743 return CMD_WARNING;
10744 }
10745
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010746 ret = str2sockunion (argv[1], &su);
10747 if (ret < 0)
10748 {
10749 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10750 return CMD_WARNING;
10751 }
paulbb46e942003-10-24 19:02:03 +000010752
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010753 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010754 if (! peer)
10755 return CMD_WARNING;
10756
10757 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10758 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10759 if (count)
10760 {
10761 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10762 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10763 }
10764
10765 return CMD_SUCCESS;
10766}
10767
10768ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10769 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10770 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10771 SHOW_STR
10772 BGP_STR
10773 "BGP view\n"
10774 "View name\n"
10775 "Address family\n"
10776 "Detailed information on TCP and BGP neighbor connections\n"
10777 "Neighbor to display information about\n"
10778 "Neighbor to display information about\n"
10779 "Display information received from a BGP neighbor\n"
10780 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010781#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020010782
paul94f2b392005-06-28 12:44:16 +000010783static int
paulbb46e942003-10-24 19:02:03 +000010784bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010785 safi_t safi, enum bgp_show_type type)
10786{
paul718e3742002-12-13 20:15:29 +000010787 if (! peer || ! peer->afc[afi][safi])
10788 {
10789 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010790 return CMD_WARNING;
10791 }
10792
ajs5a646652004-11-05 01:25:55 +000010793 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010794}
10795
10796DEFUN (show_ip_bgp_neighbor_routes,
10797 show_ip_bgp_neighbor_routes_cmd,
10798 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10799 SHOW_STR
10800 IP_STR
10801 BGP_STR
10802 "Detailed information on TCP and BGP neighbor connections\n"
10803 "Neighbor to display information about\n"
10804 "Neighbor to display information about\n"
10805 "Display routes learned from neighbor\n")
10806{
paulbb46e942003-10-24 19:02:03 +000010807 struct peer *peer;
10808
10809 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10810 if (! peer)
10811 return CMD_WARNING;
10812
10813 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010814 bgp_show_type_neighbor);
10815}
10816
10817DEFUN (show_ip_bgp_neighbor_flap,
10818 show_ip_bgp_neighbor_flap_cmd,
10819 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10820 SHOW_STR
10821 IP_STR
10822 BGP_STR
10823 "Detailed information on TCP and BGP neighbor connections\n"
10824 "Neighbor to display information about\n"
10825 "Neighbor to display information about\n"
10826 "Display flap statistics of the routes learned from neighbor\n")
10827{
paulbb46e942003-10-24 19:02:03 +000010828 struct peer *peer;
10829
10830 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10831 if (! peer)
10832 return CMD_WARNING;
10833
10834 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010835 bgp_show_type_flap_neighbor);
10836}
10837
10838DEFUN (show_ip_bgp_neighbor_damp,
10839 show_ip_bgp_neighbor_damp_cmd,
10840 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10841 SHOW_STR
10842 IP_STR
10843 BGP_STR
10844 "Detailed information on TCP and BGP neighbor connections\n"
10845 "Neighbor to display information about\n"
10846 "Neighbor to display information about\n"
10847 "Display the dampened routes received from neighbor\n")
10848{
paulbb46e942003-10-24 19:02:03 +000010849 struct peer *peer;
10850
10851 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10852 if (! peer)
10853 return CMD_WARNING;
10854
10855 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010856 bgp_show_type_damp_neighbor);
10857}
10858
10859DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10860 show_ip_bgp_ipv4_neighbor_routes_cmd,
10861 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10862 SHOW_STR
10863 IP_STR
10864 BGP_STR
10865 "Address family\n"
10866 "Address Family modifier\n"
10867 "Address Family modifier\n"
10868 "Detailed information on TCP and BGP neighbor connections\n"
10869 "Neighbor to display information about\n"
10870 "Neighbor to display information about\n"
10871 "Display routes learned from neighbor\n")
10872{
paulbb46e942003-10-24 19:02:03 +000010873 struct peer *peer;
10874
10875 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10876 if (! peer)
10877 return CMD_WARNING;
10878
paul718e3742002-12-13 20:15:29 +000010879 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010880 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010881 bgp_show_type_neighbor);
10882
paulbb46e942003-10-24 19:02:03 +000010883 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010884 bgp_show_type_neighbor);
10885}
paulbb46e942003-10-24 19:02:03 +000010886
paulfee0f4c2004-09-13 05:12:46 +000010887DEFUN (show_ip_bgp_view_rsclient,
10888 show_ip_bgp_view_rsclient_cmd,
10889 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10890 SHOW_STR
10891 IP_STR
10892 BGP_STR
10893 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010894 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000010895 "Information about Route Server Client\n"
10896 NEIGHBOR_ADDR_STR)
10897{
10898 struct bgp_table *table;
10899 struct peer *peer;
10900
10901 if (argc == 2)
10902 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10903 else
10904 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10905
10906 if (! peer)
10907 return CMD_WARNING;
10908
10909 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10910 {
10911 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10912 VTY_NEWLINE);
10913 return CMD_WARNING;
10914 }
10915
10916 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10917 PEER_FLAG_RSERVER_CLIENT))
10918 {
10919 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10920 VTY_NEWLINE);
10921 return CMD_WARNING;
10922 }
10923
10924 table = peer->rib[AFI_IP][SAFI_UNICAST];
10925
ajs5a646652004-11-05 01:25:55 +000010926 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010927}
10928
10929ALIAS (show_ip_bgp_view_rsclient,
10930 show_ip_bgp_rsclient_cmd,
10931 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10932 SHOW_STR
10933 IP_STR
10934 BGP_STR
10935 "Information about Route Server Client\n"
10936 NEIGHBOR_ADDR_STR)
10937
Michael Lambert95cbbd22010-07-23 14:43:04 -040010938DEFUN (show_bgp_view_ipv4_safi_rsclient,
10939 show_bgp_view_ipv4_safi_rsclient_cmd,
10940 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10941 SHOW_STR
10942 BGP_STR
10943 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000010944 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040010945 "Address family\n"
10946 "Address Family modifier\n"
10947 "Address Family modifier\n"
10948 "Information about Route Server Client\n"
10949 NEIGHBOR_ADDR_STR)
10950{
10951 struct bgp_table *table;
10952 struct peer *peer;
10953 safi_t safi;
10954
10955 if (argc == 3) {
10956 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10957 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10958 } else {
10959 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10960 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10961 }
10962
10963 if (! peer)
10964 return CMD_WARNING;
10965
10966 if (! peer->afc[AFI_IP][safi])
10967 {
10968 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10969 VTY_NEWLINE);
10970 return CMD_WARNING;
10971 }
10972
10973 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10974 PEER_FLAG_RSERVER_CLIENT))
10975 {
10976 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10977 VTY_NEWLINE);
10978 return CMD_WARNING;
10979 }
10980
10981 table = peer->rib[AFI_IP][safi];
10982
10983 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10984}
10985
10986ALIAS (show_bgp_view_ipv4_safi_rsclient,
10987 show_bgp_ipv4_safi_rsclient_cmd,
10988 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10989 SHOW_STR
10990 BGP_STR
10991 "Address family\n"
10992 "Address Family modifier\n"
10993 "Address Family modifier\n"
10994 "Information about Route Server Client\n"
10995 NEIGHBOR_ADDR_STR)
10996
paulfee0f4c2004-09-13 05:12:46 +000010997DEFUN (show_ip_bgp_view_rsclient_route,
10998 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010999 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000011000 SHOW_STR
11001 IP_STR
11002 BGP_STR
11003 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011004 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011005 "Information about Route Server Client\n"
11006 NEIGHBOR_ADDR_STR
11007 "Network in the BGP routing table to display\n")
11008{
11009 struct bgp *bgp;
11010 struct peer *peer;
11011
11012 /* BGP structure lookup. */
11013 if (argc == 3)
11014 {
11015 bgp = bgp_lookup_by_name (argv[0]);
11016 if (bgp == NULL)
11017 {
11018 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11019 return CMD_WARNING;
11020 }
11021 }
11022 else
11023 {
11024 bgp = bgp_get_default ();
11025 if (bgp == NULL)
11026 {
11027 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11028 return CMD_WARNING;
11029 }
11030 }
11031
11032 if (argc == 3)
11033 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11034 else
11035 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11036
11037 if (! peer)
11038 return CMD_WARNING;
11039
11040 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11041 {
11042 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11043 VTY_NEWLINE);
11044 return CMD_WARNING;
11045}
11046
11047 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11048 PEER_FLAG_RSERVER_CLIENT))
11049 {
11050 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11051 VTY_NEWLINE);
11052 return CMD_WARNING;
11053 }
11054
11055 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11056 (argc == 3) ? argv[2] : argv[1],
11057 AFI_IP, SAFI_UNICAST, NULL, 0);
11058}
11059
11060ALIAS (show_ip_bgp_view_rsclient_route,
11061 show_ip_bgp_rsclient_route_cmd,
11062 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11063 SHOW_STR
11064 IP_STR
11065 BGP_STR
11066 "Information about Route Server Client\n"
11067 NEIGHBOR_ADDR_STR
11068 "Network in the BGP routing table to display\n")
11069
Michael Lambert95cbbd22010-07-23 14:43:04 -040011070DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
11071 show_bgp_view_ipv4_safi_rsclient_route_cmd,
11072 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11073 SHOW_STR
11074 BGP_STR
11075 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011076 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011077 "Address family\n"
11078 "Address Family modifier\n"
11079 "Address Family modifier\n"
11080 "Information about Route Server Client\n"
11081 NEIGHBOR_ADDR_STR
11082 "Network in the BGP routing table to display\n")
11083{
11084 struct bgp *bgp;
11085 struct peer *peer;
11086 safi_t safi;
11087
11088 /* BGP structure lookup. */
11089 if (argc == 4)
11090 {
11091 bgp = bgp_lookup_by_name (argv[0]);
11092 if (bgp == NULL)
11093 {
11094 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11095 return CMD_WARNING;
11096 }
11097 }
11098 else
11099 {
11100 bgp = bgp_get_default ();
11101 if (bgp == NULL)
11102 {
11103 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11104 return CMD_WARNING;
11105 }
11106 }
11107
11108 if (argc == 4) {
11109 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11110 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11111 } else {
11112 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11113 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11114 }
11115
11116 if (! peer)
11117 return CMD_WARNING;
11118
11119 if (! peer->afc[AFI_IP][safi])
11120 {
11121 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11122 VTY_NEWLINE);
11123 return CMD_WARNING;
11124}
11125
11126 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11127 PEER_FLAG_RSERVER_CLIENT))
11128 {
11129 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11130 VTY_NEWLINE);
11131 return CMD_WARNING;
11132 }
11133
11134 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11135 (argc == 4) ? argv[3] : argv[2],
11136 AFI_IP, safi, NULL, 0);
11137}
11138
11139ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
11140 show_bgp_ipv4_safi_rsclient_route_cmd,
11141 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
11142 SHOW_STR
11143 BGP_STR
11144 "Address family\n"
11145 "Address Family modifier\n"
11146 "Address Family modifier\n"
11147 "Information about Route Server Client\n"
11148 NEIGHBOR_ADDR_STR
11149 "Network in the BGP routing table to display\n")
11150
paulfee0f4c2004-09-13 05:12:46 +000011151DEFUN (show_ip_bgp_view_rsclient_prefix,
11152 show_ip_bgp_view_rsclient_prefix_cmd,
11153 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11154 SHOW_STR
11155 IP_STR
11156 BGP_STR
11157 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011158 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011159 "Information about Route Server Client\n"
11160 NEIGHBOR_ADDR_STR
11161 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11162{
11163 struct bgp *bgp;
11164 struct peer *peer;
11165
11166 /* BGP structure lookup. */
11167 if (argc == 3)
11168 {
11169 bgp = bgp_lookup_by_name (argv[0]);
11170 if (bgp == NULL)
11171 {
11172 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11173 return CMD_WARNING;
11174 }
11175 }
11176 else
11177 {
11178 bgp = bgp_get_default ();
11179 if (bgp == NULL)
11180 {
11181 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11182 return CMD_WARNING;
11183 }
11184 }
11185
11186 if (argc == 3)
11187 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11188 else
11189 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11190
11191 if (! peer)
11192 return CMD_WARNING;
11193
11194 if (! peer->afc[AFI_IP][SAFI_UNICAST])
11195 {
11196 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11197 VTY_NEWLINE);
11198 return CMD_WARNING;
11199}
11200
11201 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
11202 PEER_FLAG_RSERVER_CLIENT))
11203{
11204 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11205 VTY_NEWLINE);
11206 return CMD_WARNING;
11207 }
11208
11209 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
11210 (argc == 3) ? argv[2] : argv[1],
11211 AFI_IP, SAFI_UNICAST, NULL, 1);
11212}
11213
11214ALIAS (show_ip_bgp_view_rsclient_prefix,
11215 show_ip_bgp_rsclient_prefix_cmd,
11216 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11217 SHOW_STR
11218 IP_STR
11219 BGP_STR
11220 "Information about Route Server Client\n"
11221 NEIGHBOR_ADDR_STR
11222 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11223
Michael Lambert95cbbd22010-07-23 14:43:04 -040011224DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
11225 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
11226 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11227 SHOW_STR
11228 BGP_STR
11229 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011230 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011231 "Address family\n"
11232 "Address Family modifier\n"
11233 "Address Family modifier\n"
11234 "Information about Route Server Client\n"
11235 NEIGHBOR_ADDR_STR
11236 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11237{
11238 struct bgp *bgp;
11239 struct peer *peer;
11240 safi_t safi;
11241
11242 /* BGP structure lookup. */
11243 if (argc == 4)
11244 {
11245 bgp = bgp_lookup_by_name (argv[0]);
11246 if (bgp == NULL)
11247 {
11248 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11249 return CMD_WARNING;
11250 }
11251 }
11252 else
11253 {
11254 bgp = bgp_get_default ();
11255 if (bgp == NULL)
11256 {
11257 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11258 return CMD_WARNING;
11259 }
11260 }
11261
11262 if (argc == 4) {
11263 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11264 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11265 } else {
11266 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11267 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11268 }
11269
11270 if (! peer)
11271 return CMD_WARNING;
11272
11273 if (! peer->afc[AFI_IP][safi])
11274 {
11275 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11276 VTY_NEWLINE);
11277 return CMD_WARNING;
11278}
11279
11280 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
11281 PEER_FLAG_RSERVER_CLIENT))
11282{
11283 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11284 VTY_NEWLINE);
11285 return CMD_WARNING;
11286 }
11287
11288 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
11289 (argc == 4) ? argv[3] : argv[2],
11290 AFI_IP, safi, NULL, 1);
11291}
11292
11293ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
11294 show_bgp_ipv4_safi_rsclient_prefix_cmd,
11295 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
11296 SHOW_STR
11297 BGP_STR
11298 "Address family\n"
11299 "Address Family modifier\n"
11300 "Address Family modifier\n"
11301 "Information about Route Server Client\n"
11302 NEIGHBOR_ADDR_STR
11303 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011304
paul718e3742002-12-13 20:15:29 +000011305#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011306DEFUN (show_bgp_view_neighbor_routes,
11307 show_bgp_view_neighbor_routes_cmd,
11308 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11309 SHOW_STR
11310 BGP_STR
11311 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011312 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011313 "Detailed information on TCP and BGP neighbor connections\n"
11314 "Neighbor to display information about\n"
11315 "Neighbor to display information about\n"
11316 "Display routes learned from neighbor\n")
11317{
11318 struct peer *peer;
11319
11320 if (argc == 2)
11321 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11322 else
11323 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11324
11325 if (! peer)
11326 return CMD_WARNING;
11327
11328 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11329 bgp_show_type_neighbor);
11330}
11331
11332ALIAS (show_bgp_view_neighbor_routes,
11333 show_bgp_view_ipv6_neighbor_routes_cmd,
11334 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11335 SHOW_STR
11336 BGP_STR
11337 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011338 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011339 "Address family\n"
11340 "Detailed information on TCP and BGP neighbor connections\n"
11341 "Neighbor to display information about\n"
11342 "Neighbor to display information about\n"
11343 "Display routes learned from neighbor\n")
11344
11345DEFUN (show_bgp_view_neighbor_damp,
11346 show_bgp_view_neighbor_damp_cmd,
11347 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11348 SHOW_STR
11349 BGP_STR
11350 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011351 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011352 "Detailed information on TCP and BGP neighbor connections\n"
11353 "Neighbor to display information about\n"
11354 "Neighbor to display information about\n"
11355 "Display the dampened routes received from neighbor\n")
11356{
11357 struct peer *peer;
11358
11359 if (argc == 2)
11360 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11361 else
11362 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11363
11364 if (! peer)
11365 return CMD_WARNING;
11366
11367 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11368 bgp_show_type_damp_neighbor);
11369}
11370
11371ALIAS (show_bgp_view_neighbor_damp,
11372 show_bgp_view_ipv6_neighbor_damp_cmd,
11373 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11374 SHOW_STR
11375 BGP_STR
11376 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011377 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011378 "Address family\n"
11379 "Detailed information on TCP and BGP neighbor connections\n"
11380 "Neighbor to display information about\n"
11381 "Neighbor to display information about\n"
11382 "Display the dampened routes received from neighbor\n")
11383
11384DEFUN (show_bgp_view_neighbor_flap,
11385 show_bgp_view_neighbor_flap_cmd,
11386 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11387 SHOW_STR
11388 BGP_STR
11389 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011390 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011391 "Detailed information on TCP and BGP neighbor connections\n"
11392 "Neighbor to display information about\n"
11393 "Neighbor to display information about\n"
11394 "Display flap statistics of the routes learned from neighbor\n")
11395{
11396 struct peer *peer;
11397
11398 if (argc == 2)
11399 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11400 else
11401 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11402
11403 if (! peer)
11404 return CMD_WARNING;
11405
11406 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11407 bgp_show_type_flap_neighbor);
11408}
11409
11410ALIAS (show_bgp_view_neighbor_flap,
11411 show_bgp_view_ipv6_neighbor_flap_cmd,
11412 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11413 SHOW_STR
11414 BGP_STR
11415 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011416 "View name\n"
paulbb46e942003-10-24 19:02:03 +000011417 "Address family\n"
11418 "Detailed information on TCP and BGP neighbor connections\n"
11419 "Neighbor to display information about\n"
11420 "Neighbor to display information about\n"
11421 "Display flap statistics of the routes learned from neighbor\n")
11422
11423ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011424 show_bgp_neighbor_routes_cmd,
11425 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11426 SHOW_STR
11427 BGP_STR
11428 "Detailed information on TCP and BGP neighbor connections\n"
11429 "Neighbor to display information about\n"
11430 "Neighbor to display information about\n"
11431 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011432
paulbb46e942003-10-24 19:02:03 +000011433
11434ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011435 show_bgp_ipv6_neighbor_routes_cmd,
11436 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11437 SHOW_STR
11438 BGP_STR
11439 "Address family\n"
11440 "Detailed information on TCP and BGP neighbor connections\n"
11441 "Neighbor to display information about\n"
11442 "Neighbor to display information about\n"
11443 "Display routes learned from neighbor\n")
11444
11445/* old command */
paulbb46e942003-10-24 19:02:03 +000011446ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011447 ipv6_bgp_neighbor_routes_cmd,
11448 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11449 SHOW_STR
11450 IPV6_STR
11451 BGP_STR
11452 "Detailed information on TCP and BGP neighbor connections\n"
11453 "Neighbor to display information about\n"
11454 "Neighbor to display information about\n"
11455 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011456
11457/* old command */
11458DEFUN (ipv6_mbgp_neighbor_routes,
11459 ipv6_mbgp_neighbor_routes_cmd,
11460 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11461 SHOW_STR
11462 IPV6_STR
11463 MBGP_STR
11464 "Detailed information on TCP and BGP neighbor connections\n"
11465 "Neighbor to display information about\n"
11466 "Neighbor to display information about\n"
11467 "Display routes learned from neighbor\n")
11468{
paulbb46e942003-10-24 19:02:03 +000011469 struct peer *peer;
11470
11471 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11472 if (! peer)
11473 return CMD_WARNING;
11474
11475 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011476 bgp_show_type_neighbor);
11477}
paulbb46e942003-10-24 19:02:03 +000011478
11479ALIAS (show_bgp_view_neighbor_flap,
11480 show_bgp_neighbor_flap_cmd,
11481 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11482 SHOW_STR
11483 BGP_STR
11484 "Detailed information on TCP and BGP neighbor connections\n"
11485 "Neighbor to display information about\n"
11486 "Neighbor to display information about\n"
11487 "Display flap statistics of the routes learned from neighbor\n")
11488
11489ALIAS (show_bgp_view_neighbor_flap,
11490 show_bgp_ipv6_neighbor_flap_cmd,
11491 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11492 SHOW_STR
11493 BGP_STR
11494 "Address family\n"
11495 "Detailed information on TCP and BGP neighbor connections\n"
11496 "Neighbor to display information about\n"
11497 "Neighbor to display information about\n"
11498 "Display flap statistics of the routes learned from neighbor\n")
11499
11500ALIAS (show_bgp_view_neighbor_damp,
11501 show_bgp_neighbor_damp_cmd,
11502 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11503 SHOW_STR
11504 BGP_STR
11505 "Detailed information on TCP and BGP neighbor connections\n"
11506 "Neighbor to display information about\n"
11507 "Neighbor to display information about\n"
11508 "Display the dampened routes received from neighbor\n")
11509
11510ALIAS (show_bgp_view_neighbor_damp,
11511 show_bgp_ipv6_neighbor_damp_cmd,
11512 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11513 SHOW_STR
11514 BGP_STR
11515 "Address family\n"
11516 "Detailed information on TCP and BGP neighbor connections\n"
11517 "Neighbor to display information about\n"
11518 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011519 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011520
11521DEFUN (show_bgp_view_rsclient,
11522 show_bgp_view_rsclient_cmd,
11523 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11524 SHOW_STR
11525 BGP_STR
11526 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011527 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011528 "Information about Route Server Client\n"
11529 NEIGHBOR_ADDR_STR)
11530{
11531 struct bgp_table *table;
11532 struct peer *peer;
11533
11534 if (argc == 2)
11535 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11536 else
11537 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11538
11539 if (! peer)
11540 return CMD_WARNING;
11541
11542 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11543 {
11544 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11545 VTY_NEWLINE);
11546 return CMD_WARNING;
11547 }
11548
11549 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11550 PEER_FLAG_RSERVER_CLIENT))
11551 {
11552 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11553 VTY_NEWLINE);
11554 return CMD_WARNING;
11555 }
11556
11557 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11558
ajs5a646652004-11-05 01:25:55 +000011559 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011560}
11561
11562ALIAS (show_bgp_view_rsclient,
11563 show_bgp_rsclient_cmd,
11564 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11565 SHOW_STR
11566 BGP_STR
11567 "Information about Route Server Client\n"
11568 NEIGHBOR_ADDR_STR)
11569
Michael Lambert95cbbd22010-07-23 14:43:04 -040011570DEFUN (show_bgp_view_ipv6_safi_rsclient,
11571 show_bgp_view_ipv6_safi_rsclient_cmd,
11572 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11573 SHOW_STR
11574 BGP_STR
11575 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011576 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011577 "Address family\n"
11578 "Address Family modifier\n"
11579 "Address Family modifier\n"
11580 "Information about Route Server Client\n"
11581 NEIGHBOR_ADDR_STR)
11582{
11583 struct bgp_table *table;
11584 struct peer *peer;
11585 safi_t safi;
11586
11587 if (argc == 3) {
11588 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11589 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11590 } else {
11591 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11592 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11593 }
11594
11595 if (! peer)
11596 return CMD_WARNING;
11597
11598 if (! peer->afc[AFI_IP6][safi])
11599 {
11600 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11601 VTY_NEWLINE);
11602 return CMD_WARNING;
11603 }
11604
11605 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11606 PEER_FLAG_RSERVER_CLIENT))
11607 {
11608 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11609 VTY_NEWLINE);
11610 return CMD_WARNING;
11611 }
11612
11613 table = peer->rib[AFI_IP6][safi];
11614
11615 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11616}
11617
11618ALIAS (show_bgp_view_ipv6_safi_rsclient,
11619 show_bgp_ipv6_safi_rsclient_cmd,
11620 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11621 SHOW_STR
11622 BGP_STR
11623 "Address family\n"
11624 "Address Family modifier\n"
11625 "Address Family modifier\n"
11626 "Information about Route Server Client\n"
11627 NEIGHBOR_ADDR_STR)
11628
paulfee0f4c2004-09-13 05:12:46 +000011629DEFUN (show_bgp_view_rsclient_route,
11630 show_bgp_view_rsclient_route_cmd,
11631 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11632 SHOW_STR
11633 BGP_STR
11634 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011635 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011636 "Information about Route Server Client\n"
11637 NEIGHBOR_ADDR_STR
11638 "Network in the BGP routing table to display\n")
11639{
11640 struct bgp *bgp;
11641 struct peer *peer;
11642
11643 /* BGP structure lookup. */
11644 if (argc == 3)
11645 {
11646 bgp = bgp_lookup_by_name (argv[0]);
11647 if (bgp == NULL)
11648 {
11649 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11650 return CMD_WARNING;
11651 }
11652 }
11653 else
11654 {
11655 bgp = bgp_get_default ();
11656 if (bgp == NULL)
11657 {
11658 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11659 return CMD_WARNING;
11660 }
11661 }
11662
11663 if (argc == 3)
11664 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11665 else
11666 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11667
11668 if (! peer)
11669 return CMD_WARNING;
11670
11671 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11672 {
11673 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11674 VTY_NEWLINE);
11675 return CMD_WARNING;
11676 }
11677
11678 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11679 PEER_FLAG_RSERVER_CLIENT))
11680 {
11681 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11682 VTY_NEWLINE);
11683 return CMD_WARNING;
11684 }
11685
11686 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11687 (argc == 3) ? argv[2] : argv[1],
11688 AFI_IP6, SAFI_UNICAST, NULL, 0);
11689}
11690
11691ALIAS (show_bgp_view_rsclient_route,
11692 show_bgp_rsclient_route_cmd,
11693 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11694 SHOW_STR
11695 BGP_STR
11696 "Information about Route Server Client\n"
11697 NEIGHBOR_ADDR_STR
11698 "Network in the BGP routing table to display\n")
11699
Michael Lambert95cbbd22010-07-23 14:43:04 -040011700DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11701 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11702 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11703 SHOW_STR
11704 BGP_STR
11705 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011706 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011707 "Address family\n"
11708 "Address Family modifier\n"
11709 "Address Family modifier\n"
11710 "Information about Route Server Client\n"
11711 NEIGHBOR_ADDR_STR
11712 "Network in the BGP routing table to display\n")
11713{
11714 struct bgp *bgp;
11715 struct peer *peer;
11716 safi_t safi;
11717
11718 /* BGP structure lookup. */
11719 if (argc == 4)
11720 {
11721 bgp = bgp_lookup_by_name (argv[0]);
11722 if (bgp == NULL)
11723 {
11724 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11725 return CMD_WARNING;
11726 }
11727 }
11728 else
11729 {
11730 bgp = bgp_get_default ();
11731 if (bgp == NULL)
11732 {
11733 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11734 return CMD_WARNING;
11735 }
11736 }
11737
11738 if (argc == 4) {
11739 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11740 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11741 } else {
11742 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11743 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11744 }
11745
11746 if (! peer)
11747 return CMD_WARNING;
11748
11749 if (! peer->afc[AFI_IP6][safi])
11750 {
11751 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11752 VTY_NEWLINE);
11753 return CMD_WARNING;
11754}
11755
11756 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11757 PEER_FLAG_RSERVER_CLIENT))
11758 {
11759 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11760 VTY_NEWLINE);
11761 return CMD_WARNING;
11762 }
11763
11764 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11765 (argc == 4) ? argv[3] : argv[2],
11766 AFI_IP6, safi, NULL, 0);
11767}
11768
11769ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11770 show_bgp_ipv6_safi_rsclient_route_cmd,
11771 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11772 SHOW_STR
11773 BGP_STR
11774 "Address family\n"
11775 "Address Family modifier\n"
11776 "Address Family modifier\n"
11777 "Information about Route Server Client\n"
11778 NEIGHBOR_ADDR_STR
11779 "Network in the BGP routing table to display\n")
11780
paulfee0f4c2004-09-13 05:12:46 +000011781DEFUN (show_bgp_view_rsclient_prefix,
11782 show_bgp_view_rsclient_prefix_cmd,
11783 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11784 SHOW_STR
11785 BGP_STR
11786 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011787 "View name\n"
paulfee0f4c2004-09-13 05:12:46 +000011788 "Information about Route Server Client\n"
11789 NEIGHBOR_ADDR_STR
11790 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11791{
11792 struct bgp *bgp;
11793 struct peer *peer;
11794
11795 /* BGP structure lookup. */
11796 if (argc == 3)
11797 {
11798 bgp = bgp_lookup_by_name (argv[0]);
11799 if (bgp == NULL)
11800 {
11801 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11802 return CMD_WARNING;
11803 }
11804 }
11805 else
11806 {
11807 bgp = bgp_get_default ();
11808 if (bgp == NULL)
11809 {
11810 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11811 return CMD_WARNING;
11812 }
11813 }
11814
11815 if (argc == 3)
11816 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11817 else
11818 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11819
11820 if (! peer)
11821 return CMD_WARNING;
11822
11823 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11824 {
11825 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11826 VTY_NEWLINE);
11827 return CMD_WARNING;
11828 }
11829
11830 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11831 PEER_FLAG_RSERVER_CLIENT))
11832 {
11833 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11834 VTY_NEWLINE);
11835 return CMD_WARNING;
11836 }
11837
11838 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11839 (argc == 3) ? argv[2] : argv[1],
11840 AFI_IP6, SAFI_UNICAST, NULL, 1);
11841}
11842
11843ALIAS (show_bgp_view_rsclient_prefix,
11844 show_bgp_rsclient_prefix_cmd,
11845 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11846 SHOW_STR
11847 BGP_STR
11848 "Information about Route Server Client\n"
11849 NEIGHBOR_ADDR_STR
11850 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11851
Michael Lambert95cbbd22010-07-23 14:43:04 -040011852DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11853 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11854 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11855 SHOW_STR
11856 BGP_STR
11857 "BGP view\n"
Christian Franke2b005152013-09-30 12:27:49 +000011858 "View name\n"
Michael Lambert95cbbd22010-07-23 14:43:04 -040011859 "Address family\n"
11860 "Address Family modifier\n"
11861 "Address Family modifier\n"
11862 "Information about Route Server Client\n"
11863 NEIGHBOR_ADDR_STR
11864 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11865{
11866 struct bgp *bgp;
11867 struct peer *peer;
11868 safi_t safi;
11869
11870 /* BGP structure lookup. */
11871 if (argc == 4)
11872 {
11873 bgp = bgp_lookup_by_name (argv[0]);
11874 if (bgp == NULL)
11875 {
11876 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11877 return CMD_WARNING;
11878 }
11879 }
11880 else
11881 {
11882 bgp = bgp_get_default ();
11883 if (bgp == NULL)
11884 {
11885 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11886 return CMD_WARNING;
11887 }
11888 }
11889
11890 if (argc == 4) {
11891 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11892 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11893 } else {
11894 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11895 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11896 }
11897
11898 if (! peer)
11899 return CMD_WARNING;
11900
11901 if (! peer->afc[AFI_IP6][safi])
11902 {
11903 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11904 VTY_NEWLINE);
11905 return CMD_WARNING;
11906}
11907
11908 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11909 PEER_FLAG_RSERVER_CLIENT))
11910{
11911 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11912 VTY_NEWLINE);
11913 return CMD_WARNING;
11914 }
11915
11916 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11917 (argc == 4) ? argv[3] : argv[2],
11918 AFI_IP6, safi, NULL, 1);
11919}
11920
11921ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11922 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11923 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11924 SHOW_STR
11925 BGP_STR
11926 "Address family\n"
11927 "Address Family modifier\n"
11928 "Address Family modifier\n"
11929 "Information about Route Server Client\n"
11930 NEIGHBOR_ADDR_STR
11931 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11932
paul718e3742002-12-13 20:15:29 +000011933#endif /* HAVE_IPV6 */
David Lamparter6b0655a2014-06-04 06:53:35 +020011934
paul718e3742002-12-13 20:15:29 +000011935struct bgp_table *bgp_distance_table;
11936
11937struct bgp_distance
11938{
11939 /* Distance value for the IP source prefix. */
11940 u_char distance;
11941
11942 /* Name of the access-list to be matched. */
11943 char *access_list;
11944};
11945
paul94f2b392005-06-28 12:44:16 +000011946static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011947bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011948{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011949 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011950}
11951
paul94f2b392005-06-28 12:44:16 +000011952static void
paul718e3742002-12-13 20:15:29 +000011953bgp_distance_free (struct bgp_distance *bdistance)
11954{
11955 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11956}
11957
paul94f2b392005-06-28 12:44:16 +000011958static int
paulfd79ac92004-10-13 05:06:08 +000011959bgp_distance_set (struct vty *vty, const char *distance_str,
11960 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011961{
11962 int ret;
11963 struct prefix_ipv4 p;
11964 u_char distance;
11965 struct bgp_node *rn;
11966 struct bgp_distance *bdistance;
11967
11968 ret = str2prefix_ipv4 (ip_str, &p);
11969 if (ret == 0)
11970 {
11971 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11972 return CMD_WARNING;
11973 }
11974
11975 distance = atoi (distance_str);
11976
11977 /* Get BGP distance node. */
11978 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11979 if (rn->info)
11980 {
11981 bdistance = rn->info;
11982 bgp_unlock_node (rn);
11983 }
11984 else
11985 {
11986 bdistance = bgp_distance_new ();
11987 rn->info = bdistance;
11988 }
11989
11990 /* Set distance value. */
11991 bdistance->distance = distance;
11992
11993 /* Reset access-list configuration. */
11994 if (bdistance->access_list)
11995 {
11996 free (bdistance->access_list);
11997 bdistance->access_list = NULL;
11998 }
11999 if (access_list_str)
12000 bdistance->access_list = strdup (access_list_str);
12001
12002 return CMD_SUCCESS;
12003}
12004
paul94f2b392005-06-28 12:44:16 +000012005static int
paulfd79ac92004-10-13 05:06:08 +000012006bgp_distance_unset (struct vty *vty, const char *distance_str,
12007 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000012008{
12009 int ret;
12010 struct prefix_ipv4 p;
12011 u_char distance;
12012 struct bgp_node *rn;
12013 struct bgp_distance *bdistance;
12014
12015 ret = str2prefix_ipv4 (ip_str, &p);
12016 if (ret == 0)
12017 {
12018 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
12019 return CMD_WARNING;
12020 }
12021
12022 distance = atoi (distance_str);
12023
12024 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
12025 if (! rn)
12026 {
12027 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
12028 return CMD_WARNING;
12029 }
12030
12031 bdistance = rn->info;
Paul Jakma7aa9dce2014-09-19 14:42:23 +010012032
12033 if (bdistance->distance != distance)
12034 {
12035 vty_out (vty, "Distance does not match configured%s", VTY_NEWLINE);
12036 return CMD_WARNING;
12037 }
12038
paul718e3742002-12-13 20:15:29 +000012039 if (bdistance->access_list)
12040 free (bdistance->access_list);
12041 bgp_distance_free (bdistance);
12042
12043 rn->info = NULL;
12044 bgp_unlock_node (rn);
12045 bgp_unlock_node (rn);
12046
12047 return CMD_SUCCESS;
12048}
12049
paul718e3742002-12-13 20:15:29 +000012050/* Apply BGP information to distance method. */
12051u_char
12052bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
12053{
12054 struct bgp_node *rn;
12055 struct prefix_ipv4 q;
12056 struct peer *peer;
12057 struct bgp_distance *bdistance;
12058 struct access_list *alist;
12059 struct bgp_static *bgp_static;
12060
12061 if (! bgp)
12062 return 0;
12063
12064 if (p->family != AF_INET)
12065 return 0;
12066
12067 peer = rinfo->peer;
12068
12069 if (peer->su.sa.sa_family != AF_INET)
12070 return 0;
12071
12072 memset (&q, 0, sizeof (struct prefix_ipv4));
12073 q.family = AF_INET;
12074 q.prefix = peer->su.sin.sin_addr;
12075 q.prefixlen = IPV4_MAX_BITLEN;
12076
12077 /* Check source address. */
12078 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
12079 if (rn)
12080 {
12081 bdistance = rn->info;
12082 bgp_unlock_node (rn);
12083
12084 if (bdistance->access_list)
12085 {
12086 alist = access_list_lookup (AFI_IP, bdistance->access_list);
12087 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
12088 return bdistance->distance;
12089 }
12090 else
12091 return bdistance->distance;
12092 }
12093
12094 /* Backdoor check. */
12095 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
12096 if (rn)
12097 {
12098 bgp_static = rn->info;
12099 bgp_unlock_node (rn);
12100
12101 if (bgp_static->backdoor)
12102 {
12103 if (bgp->distance_local)
12104 return bgp->distance_local;
12105 else
12106 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12107 }
12108 }
12109
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000012110 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000012111 {
12112 if (bgp->distance_ebgp)
12113 return bgp->distance_ebgp;
12114 return ZEBRA_EBGP_DISTANCE_DEFAULT;
12115 }
12116 else
12117 {
12118 if (bgp->distance_ibgp)
12119 return bgp->distance_ibgp;
12120 return ZEBRA_IBGP_DISTANCE_DEFAULT;
12121 }
12122}
12123
12124DEFUN (bgp_distance,
12125 bgp_distance_cmd,
12126 "distance bgp <1-255> <1-255> <1-255>",
12127 "Define an administrative distance\n"
12128 "BGP distance\n"
12129 "Distance for routes external to the AS\n"
12130 "Distance for routes internal to the AS\n"
12131 "Distance for local routes\n")
12132{
12133 struct bgp *bgp;
12134
12135 bgp = vty->index;
12136
12137 bgp->distance_ebgp = atoi (argv[0]);
12138 bgp->distance_ibgp = atoi (argv[1]);
12139 bgp->distance_local = atoi (argv[2]);
12140 return CMD_SUCCESS;
12141}
12142
12143DEFUN (no_bgp_distance,
12144 no_bgp_distance_cmd,
12145 "no distance bgp <1-255> <1-255> <1-255>",
12146 NO_STR
12147 "Define an administrative distance\n"
12148 "BGP distance\n"
12149 "Distance for routes external to the AS\n"
12150 "Distance for routes internal to the AS\n"
12151 "Distance for local routes\n")
12152{
12153 struct bgp *bgp;
12154
12155 bgp = vty->index;
12156
12157 bgp->distance_ebgp= 0;
12158 bgp->distance_ibgp = 0;
12159 bgp->distance_local = 0;
12160 return CMD_SUCCESS;
12161}
12162
12163ALIAS (no_bgp_distance,
12164 no_bgp_distance2_cmd,
12165 "no distance bgp",
12166 NO_STR
12167 "Define an administrative distance\n"
12168 "BGP distance\n")
12169
12170DEFUN (bgp_distance_source,
12171 bgp_distance_source_cmd,
12172 "distance <1-255> A.B.C.D/M",
12173 "Define an administrative distance\n"
12174 "Administrative distance\n"
12175 "IP source prefix\n")
12176{
12177 bgp_distance_set (vty, argv[0], argv[1], NULL);
12178 return CMD_SUCCESS;
12179}
12180
12181DEFUN (no_bgp_distance_source,
12182 no_bgp_distance_source_cmd,
12183 "no distance <1-255> A.B.C.D/M",
12184 NO_STR
12185 "Define an administrative distance\n"
12186 "Administrative distance\n"
12187 "IP source prefix\n")
12188{
12189 bgp_distance_unset (vty, argv[0], argv[1], NULL);
12190 return CMD_SUCCESS;
12191}
12192
12193DEFUN (bgp_distance_source_access_list,
12194 bgp_distance_source_access_list_cmd,
12195 "distance <1-255> A.B.C.D/M WORD",
12196 "Define an administrative distance\n"
12197 "Administrative distance\n"
12198 "IP source prefix\n"
12199 "Access list name\n")
12200{
12201 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
12202 return CMD_SUCCESS;
12203}
12204
12205DEFUN (no_bgp_distance_source_access_list,
12206 no_bgp_distance_source_access_list_cmd,
12207 "no distance <1-255> A.B.C.D/M WORD",
12208 NO_STR
12209 "Define an administrative distance\n"
12210 "Administrative distance\n"
12211 "IP source prefix\n"
12212 "Access list name\n")
12213{
12214 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
12215 return CMD_SUCCESS;
12216}
David Lamparter6b0655a2014-06-04 06:53:35 +020012217
paul718e3742002-12-13 20:15:29 +000012218DEFUN (bgp_damp_set,
12219 bgp_damp_set_cmd,
12220 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12221 "BGP Specific commands\n"
12222 "Enable route-flap dampening\n"
12223 "Half-life time for the penalty\n"
12224 "Value to start reusing a route\n"
12225 "Value to start suppressing a route\n"
12226 "Maximum duration to suppress a stable route\n")
12227{
12228 struct bgp *bgp;
12229 int half = DEFAULT_HALF_LIFE * 60;
12230 int reuse = DEFAULT_REUSE;
12231 int suppress = DEFAULT_SUPPRESS;
12232 int max = 4 * half;
12233
12234 if (argc == 4)
12235 {
12236 half = atoi (argv[0]) * 60;
12237 reuse = atoi (argv[1]);
12238 suppress = atoi (argv[2]);
12239 max = atoi (argv[3]) * 60;
12240 }
12241 else if (argc == 1)
12242 {
12243 half = atoi (argv[0]) * 60;
12244 max = 4 * half;
12245 }
12246
12247 bgp = vty->index;
Balajiaa7dbb12015-03-16 16:55:26 +000012248
12249 if (suppress < reuse)
12250 {
12251 vty_out (vty, "Suppress value cannot be less than reuse value %s",
12252 VTY_NEWLINE);
12253 return 0;
12254 }
12255
paul718e3742002-12-13 20:15:29 +000012256 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
12257 half, reuse, suppress, max);
12258}
12259
12260ALIAS (bgp_damp_set,
12261 bgp_damp_set2_cmd,
12262 "bgp dampening <1-45>",
12263 "BGP Specific commands\n"
12264 "Enable route-flap dampening\n"
12265 "Half-life time for the penalty\n")
12266
12267ALIAS (bgp_damp_set,
12268 bgp_damp_set3_cmd,
12269 "bgp dampening",
12270 "BGP Specific commands\n"
12271 "Enable route-flap dampening\n")
12272
12273DEFUN (bgp_damp_unset,
12274 bgp_damp_unset_cmd,
12275 "no bgp dampening",
12276 NO_STR
12277 "BGP Specific commands\n"
12278 "Enable route-flap dampening\n")
12279{
12280 struct bgp *bgp;
12281
12282 bgp = vty->index;
12283 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
12284}
12285
12286ALIAS (bgp_damp_unset,
12287 bgp_damp_unset2_cmd,
12288 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
12289 NO_STR
12290 "BGP Specific commands\n"
12291 "Enable route-flap dampening\n"
12292 "Half-life time for the penalty\n"
12293 "Value to start reusing a route\n"
12294 "Value to start suppressing a route\n"
12295 "Maximum duration to suppress a stable route\n")
12296
12297DEFUN (show_ip_bgp_dampened_paths,
12298 show_ip_bgp_dampened_paths_cmd,
12299 "show ip bgp dampened-paths",
12300 SHOW_STR
12301 IP_STR
12302 BGP_STR
12303 "Display paths suppressed due to dampening\n")
12304{
ajs5a646652004-11-05 01:25:55 +000012305 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
12306 NULL);
paul718e3742002-12-13 20:15:29 +000012307}
12308
Balaji3921cc52015-05-16 23:12:17 +053012309ALIAS (show_ip_bgp_dampened_paths,
12310 show_ip_bgp_damp_dampened_paths_cmd,
12311 "show ip bgp dampening dampened-paths",
12312 SHOW_STR
12313 IP_STR
12314 BGP_STR
12315 "Display detailed information about dampening\n"
12316 "Display paths suppressed due to dampening\n")
12317
paul718e3742002-12-13 20:15:29 +000012318DEFUN (show_ip_bgp_flap_statistics,
12319 show_ip_bgp_flap_statistics_cmd,
12320 "show ip bgp flap-statistics",
12321 SHOW_STR
12322 IP_STR
12323 BGP_STR
12324 "Display flap statistics of routes\n")
12325{
ajs5a646652004-11-05 01:25:55 +000012326 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12327 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012328}
David Lamparter6b0655a2014-06-04 06:53:35 +020012329
Balaji3921cc52015-05-16 23:12:17 +053012330ALIAS (show_ip_bgp_flap_statistics,
12331 show_ip_bgp_damp_flap_statistics_cmd,
12332 "show ip bgp dampening flap-statistics",
12333 SHOW_STR
12334 IP_STR
12335 BGP_STR
12336 "Display detailed information about dampening\n"
12337 "Display flap statistics of routes\n")
12338
paul718e3742002-12-13 20:15:29 +000012339/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012340static int
paulfd79ac92004-10-13 05:06:08 +000012341bgp_clear_damp_route (struct vty *vty, const char *view_name,
12342 const char *ip_str, afi_t afi, safi_t safi,
12343 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012344{
12345 int ret;
12346 struct prefix match;
12347 struct bgp_node *rn;
12348 struct bgp_node *rm;
12349 struct bgp_info *ri;
12350 struct bgp_info *ri_temp;
12351 struct bgp *bgp;
12352 struct bgp_table *table;
12353
12354 /* BGP structure lookup. */
12355 if (view_name)
12356 {
12357 bgp = bgp_lookup_by_name (view_name);
12358 if (bgp == NULL)
12359 {
12360 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12361 return CMD_WARNING;
12362 }
12363 }
12364 else
12365 {
12366 bgp = bgp_get_default ();
12367 if (bgp == NULL)
12368 {
12369 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12370 return CMD_WARNING;
12371 }
12372 }
12373
12374 /* Check IP address argument. */
12375 ret = str2prefix (ip_str, &match);
12376 if (! ret)
12377 {
12378 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12379 return CMD_WARNING;
12380 }
12381
12382 match.family = afi2family (afi);
12383
Lou Berger298cc2f2016-01-12 13:42:02 -050012384 if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP))
paul718e3742002-12-13 20:15:29 +000012385 {
Lou Berger298cc2f2016-01-12 13:42:02 -050012386 for (rn = bgp_table_top (bgp->rib[AFI_IP][safi]); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +000012387 {
12388 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12389 continue;
12390
12391 if ((table = rn->info) != NULL)
12392 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012393 {
12394 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12395 {
12396 ri = rm->info;
12397 while (ri)
12398 {
12399 if (ri->extra && ri->extra->damp_info)
12400 {
12401 ri_temp = ri->next;
12402 bgp_damp_info_free (ri->extra->damp_info, 1);
12403 ri = ri_temp;
12404 }
12405 else
12406 ri = ri->next;
12407 }
12408 }
12409
12410 bgp_unlock_node (rm);
12411 }
paul718e3742002-12-13 20:15:29 +000012412 }
12413 }
12414 else
12415 {
12416 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012417 {
12418 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12419 {
12420 ri = rn->info;
12421 while (ri)
12422 {
12423 if (ri->extra && ri->extra->damp_info)
12424 {
12425 ri_temp = ri->next;
12426 bgp_damp_info_free (ri->extra->damp_info, 1);
12427 ri = ri_temp;
12428 }
12429 else
12430 ri = ri->next;
12431 }
12432 }
12433
12434 bgp_unlock_node (rn);
12435 }
paul718e3742002-12-13 20:15:29 +000012436 }
12437
12438 return CMD_SUCCESS;
12439}
12440
12441DEFUN (clear_ip_bgp_dampening,
12442 clear_ip_bgp_dampening_cmd,
12443 "clear ip bgp dampening",
12444 CLEAR_STR
12445 IP_STR
12446 BGP_STR
12447 "Clear route flap dampening information\n")
12448{
12449 bgp_damp_info_clean ();
12450 return CMD_SUCCESS;
12451}
12452
12453DEFUN (clear_ip_bgp_dampening_prefix,
12454 clear_ip_bgp_dampening_prefix_cmd,
12455 "clear ip bgp dampening A.B.C.D/M",
12456 CLEAR_STR
12457 IP_STR
12458 BGP_STR
12459 "Clear route flap dampening information\n"
12460 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12461{
12462 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12463 SAFI_UNICAST, NULL, 1);
12464}
12465
12466DEFUN (clear_ip_bgp_dampening_address,
12467 clear_ip_bgp_dampening_address_cmd,
12468 "clear ip bgp dampening A.B.C.D",
12469 CLEAR_STR
12470 IP_STR
12471 BGP_STR
12472 "Clear route flap dampening information\n"
12473 "Network to clear damping information\n")
12474{
12475 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12476 SAFI_UNICAST, NULL, 0);
12477}
12478
12479DEFUN (clear_ip_bgp_dampening_address_mask,
12480 clear_ip_bgp_dampening_address_mask_cmd,
12481 "clear ip bgp dampening A.B.C.D A.B.C.D",
12482 CLEAR_STR
12483 IP_STR
12484 BGP_STR
12485 "Clear route flap dampening information\n"
12486 "Network to clear damping information\n"
12487 "Network mask\n")
12488{
12489 int ret;
12490 char prefix_str[BUFSIZ];
12491
12492 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12493 if (! ret)
12494 {
12495 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12496 return CMD_WARNING;
12497 }
12498
12499 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12500 SAFI_UNICAST, NULL, 0);
12501}
David Lamparter6b0655a2014-06-04 06:53:35 +020012502
Lou Berger298cc2f2016-01-12 13:42:02 -050012503/* also used for encap safi */
paul94f2b392005-06-28 12:44:16 +000012504static int
paul718e3742002-12-13 20:15:29 +000012505bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12506 afi_t afi, safi_t safi, int *write)
12507{
12508 struct bgp_node *prn;
12509 struct bgp_node *rn;
12510 struct bgp_table *table;
12511 struct prefix *p;
12512 struct prefix_rd *prd;
12513 struct bgp_static *bgp_static;
12514 u_int32_t label;
12515 char buf[SU_ADDRSTRLEN];
12516 char rdbuf[RD_ADDRSTRLEN];
12517
12518 /* Network configuration. */
12519 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12520 if ((table = prn->info) != NULL)
12521 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12522 if ((bgp_static = rn->info) != NULL)
12523 {
12524 p = &rn->p;
12525 prd = (struct prefix_rd *) &prn->p;
12526
12527 /* "address-family" display. */
12528 bgp_config_write_family_header (vty, afi, safi, write);
12529
12530 /* "network" configuration display. */
12531 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12532 label = decode_label (bgp_static->tag);
12533
12534 vty_out (vty, " network %s/%d rd %s tag %d",
12535 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12536 p->prefixlen,
12537 rdbuf, label);
12538 vty_out (vty, "%s", VTY_NEWLINE);
12539 }
12540 return 0;
12541}
12542
12543/* Configuration of static route announcement and aggregate
12544 information. */
12545int
12546bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12547 afi_t afi, safi_t safi, int *write)
12548{
12549 struct bgp_node *rn;
12550 struct prefix *p;
12551 struct bgp_static *bgp_static;
12552 struct bgp_aggregate *bgp_aggregate;
12553 char buf[SU_ADDRSTRLEN];
12554
Lou Berger298cc2f2016-01-12 13:42:02 -050012555 if (afi == AFI_IP && ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)))
paul718e3742002-12-13 20:15:29 +000012556 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12557
12558 /* Network configuration. */
12559 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12560 if ((bgp_static = rn->info) != NULL)
12561 {
12562 p = &rn->p;
12563
12564 /* "address-family" display. */
12565 bgp_config_write_family_header (vty, afi, safi, write);
12566
12567 /* "network" configuration display. */
12568 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12569 {
12570 u_int32_t destination;
12571 struct in_addr netmask;
12572
12573 destination = ntohl (p->u.prefix4.s_addr);
12574 masklen2ip (p->prefixlen, &netmask);
12575 vty_out (vty, " network %s",
12576 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12577
12578 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12579 || (IN_CLASSB (destination) && p->prefixlen == 16)
12580 || (IN_CLASSA (destination) && p->prefixlen == 8)
12581 || p->u.prefix4.s_addr == 0)
12582 {
12583 /* Natural mask is not display. */
12584 }
12585 else
12586 vty_out (vty, " mask %s", inet_ntoa (netmask));
12587 }
12588 else
12589 {
12590 vty_out (vty, " network %s/%d",
12591 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12592 p->prefixlen);
12593 }
12594
12595 if (bgp_static->rmap.name)
12596 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012597 else
12598 {
12599 if (bgp_static->backdoor)
12600 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012601 }
paul718e3742002-12-13 20:15:29 +000012602
12603 vty_out (vty, "%s", VTY_NEWLINE);
12604 }
12605
12606 /* Aggregate-address configuration. */
12607 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12608 if ((bgp_aggregate = rn->info) != NULL)
12609 {
12610 p = &rn->p;
12611
12612 /* "address-family" display. */
12613 bgp_config_write_family_header (vty, afi, safi, write);
12614
12615 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12616 {
12617 struct in_addr netmask;
12618
12619 masklen2ip (p->prefixlen, &netmask);
12620 vty_out (vty, " aggregate-address %s %s",
12621 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12622 inet_ntoa (netmask));
12623 }
12624 else
12625 {
12626 vty_out (vty, " aggregate-address %s/%d",
12627 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12628 p->prefixlen);
12629 }
12630
12631 if (bgp_aggregate->as_set)
12632 vty_out (vty, " as-set");
12633
12634 if (bgp_aggregate->summary_only)
12635 vty_out (vty, " summary-only");
12636
12637 vty_out (vty, "%s", VTY_NEWLINE);
12638 }
12639
12640 return 0;
12641}
12642
12643int
12644bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12645{
12646 struct bgp_node *rn;
12647 struct bgp_distance *bdistance;
12648
12649 /* Distance configuration. */
12650 if (bgp->distance_ebgp
12651 && bgp->distance_ibgp
12652 && bgp->distance_local
12653 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12654 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12655 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12656 vty_out (vty, " distance bgp %d %d %d%s",
12657 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12658 VTY_NEWLINE);
12659
12660 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12661 if ((bdistance = rn->info) != NULL)
12662 {
12663 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12664 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12665 bdistance->access_list ? bdistance->access_list : "",
12666 VTY_NEWLINE);
12667 }
12668
12669 return 0;
12670}
12671
12672/* Allocate routing table structure and install commands. */
12673void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012674bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012675{
12676 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012677 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012678
12679 /* IPv4 BGP commands. */
12680 install_element (BGP_NODE, &bgp_network_cmd);
12681 install_element (BGP_NODE, &bgp_network_mask_cmd);
12682 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12683 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12684 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12685 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12686 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12687 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12688 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12689 install_element (BGP_NODE, &no_bgp_network_cmd);
12690 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12691 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12692 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12693 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12694 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12695 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12696 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12697 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12698
12699 install_element (BGP_NODE, &aggregate_address_cmd);
12700 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12701 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12702 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12703 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12704 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12705 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12706 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12707 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12708 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12709 install_element (BGP_NODE, &no_aggregate_address_cmd);
12710 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12711 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12712 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12713 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12714 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12715 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12716 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12717 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12718 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12719
12720 /* IPv4 unicast configuration. */
12721 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12722 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12723 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12724 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12725 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12726 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012727 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012728 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12729 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12730 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12731 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12732 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012733
paul718e3742002-12-13 20:15:29 +000012734 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12735 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12736 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12737 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12738 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12739 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12740 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12741 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12742 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12743 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12744 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12745 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12746 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12747 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12748 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12749 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12750 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12751 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12752 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12753 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12754
12755 /* IPv4 multicast configuration. */
12756 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12757 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12758 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12759 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12760 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12761 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12762 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12763 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12764 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12765 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12766 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12767 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12768 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12769 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12770 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12771 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12772 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12773 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12774 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12775 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12776 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12777 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12778 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12779 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12780 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12781 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12782 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12783 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12784 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12785 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12786 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12787 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12788
12789 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12790 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012791 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012792 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12793 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012794 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012795 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12796 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12797 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12798 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012799 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012800 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12801 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12802 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12803 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12804 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12805 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12806 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12807 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12808 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12809 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12810 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12811 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12812 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12813 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12814 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12815 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12816 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12817 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12818 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12819 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12820 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12821 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12822 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12823 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12824 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012825 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12826 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12827 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12828 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12829 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012830 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12831 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12832 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12833 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12834 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12835 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12836 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12837 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12838 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12839 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12840 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12841 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12842 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12843 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12844 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12845 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12846 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12847 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012848 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012849 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12850 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12851 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12852 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012853 install_element (VIEW_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012854 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012855 install_element (VIEW_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012856 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012857 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000012858 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012859 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000012860 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12861 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012862 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000012863 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12864 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012865 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000012866 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012867 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000012868 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012869 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000012870 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012871 install_element (VIEW_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000012872 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12873 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012874 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012875 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012876 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012877 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012878 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012879 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012880 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12881 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012882 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012883 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012884 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012885 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012886 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012887 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012888
12889 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12890 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12891 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012892 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012893 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12894 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12895 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012896 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012897 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12898 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12899 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12900 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12901 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12902 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12903 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12904 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12905 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12906 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12907 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12908 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012909 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12910 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12911 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12912 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12913 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012914 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12915 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12916 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12917 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12918 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12919 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12920 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12921 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12922 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012923 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012924 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012925 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012926 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012927 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012928 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012929 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012930
12931 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12932 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012933 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012934 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12935 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012936 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012937 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12938 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12939 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12940 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012941 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012942 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12943 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12944 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12945 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12946 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12947 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12948 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12949 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12950 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12951 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12952 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12953 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12954 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12955 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12956 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12957 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12958 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12959 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12960 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12961 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12962 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12963 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12964 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12965 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12966 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012967 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12968 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12969 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12970 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12971 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012972 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12973 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12974 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12975 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12976 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12977 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12978 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12979 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12980 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12981 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12982 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12983 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12984 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12985 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12986 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12987 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12988 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12989 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012990 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012991 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12992 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12993 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12994 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012995 install_element (ENABLE_NODE, &show_ip_bgp_dampening_params_cmd);
paul718e3742002-12-13 20:15:29 +000012996 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012997 install_element (ENABLE_NODE, &show_ip_bgp_damp_dampened_paths_cmd);
paul718e3742002-12-13 20:15:29 +000012998 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
Balaji3921cc52015-05-16 23:12:17 +053012999 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_statistics_cmd);
paul718e3742002-12-13 20:15:29 +000013000 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013001 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_address_cmd);
paul718e3742002-12-13 20:15:29 +000013002 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
13003 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013004 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_cidr_only_cmd);
paul718e3742002-12-13 20:15:29 +000013005 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013006 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_regexp_cmd);
paul718e3742002-12-13 20:15:29 +000013007 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013008 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_filter_list_cmd);
paul718e3742002-12-13 20:15:29 +000013009 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013010 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
13011 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_list_cmd);
paul718e3742002-12-13 20:15:29 +000013012 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013013 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_prefix_longer_cmd);
paul718e3742002-12-13 20:15:29 +000013014 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
Balaji3921cc52015-05-16 23:12:17 +053013015 install_element (ENABLE_NODE, &show_ip_bgp_damp_flap_route_map_cmd);
paul718e3742002-12-13 20:15:29 +000013016 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
13017 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013018 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013019 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013020 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013021 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013022 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013023 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010013024 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
13025 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013026 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013027 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013028 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013029 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013030 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013031 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013032
13033 /* BGP dampening clear commands */
13034 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
13035 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
13036 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
13037 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
13038
Paul Jakmaff7924f2006-09-04 01:10:36 +000013039 /* prefix count */
13040 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
13041 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
13042 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000013043#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000013044 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
13045
paul718e3742002-12-13 20:15:29 +000013046 /* New config IPv6 BGP commands. */
13047 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
13048 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
13049 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
13050 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
13051
13052 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
13053 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
13054 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
13055 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
13056
G.Balaji73bfe0b2011-09-23 22:36:20 +053013057 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
13058 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
13059
paul718e3742002-12-13 20:15:29 +000013060 /* Old config IPv6 BGP commands. */
13061 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
13062 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
13063
13064 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
13065 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
13066 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
13067 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
13068
13069 install_element (VIEW_NODE, &show_bgp_cmd);
13070 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013071 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013072 install_element (VIEW_NODE, &show_bgp_route_cmd);
13073 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013074 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013075 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
13076 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013077 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013078 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
13079 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
13080 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
13081 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
13082 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
13083 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
13084 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
13085 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
13086 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
13087 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
13088 install_element (VIEW_NODE, &show_bgp_community_cmd);
13089 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
13090 install_element (VIEW_NODE, &show_bgp_community2_cmd);
13091 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
13092 install_element (VIEW_NODE, &show_bgp_community3_cmd);
13093 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
13094 install_element (VIEW_NODE, &show_bgp_community4_cmd);
13095 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
13096 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
13097 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
13098 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
13099 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
13100 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
13101 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
13102 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
13103 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
13104 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
13105 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
13106 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
13107 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13108 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
13109 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13110 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
13111 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13112 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
13113 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13114 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
13115 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13116 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13117 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013118 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
13119 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13120 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
13121 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013122 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013123 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013124 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013125 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013126 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013127 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013128 install_element (VIEW_NODE, &show_bgp_view_cmd);
13129 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
13130 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
13131 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
13132 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
13133 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
13134 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13135 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13136 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13137 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13138 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
13139 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13140 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13141 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13142 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
13143 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13144 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
13145 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013146 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013147 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013148 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013149 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013150 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013151 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013152
13153 /* Restricted:
13154 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
13155 */
13156 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
13157 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013158 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013159 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
13160 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013161 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013162 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
13163 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
13164 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
13165 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
13166 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
13167 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
13168 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
13169 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
13170 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
13171 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
13172 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
13173 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
13174 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
13175 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
13176 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
13177 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
13178 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013179 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013180 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013181 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013182 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
13183 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
13184 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
13185 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
13186 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13187 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13188 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013189 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010013190 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013191 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013192
13193 install_element (ENABLE_NODE, &show_bgp_cmd);
13194 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013195 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000013196 install_element (ENABLE_NODE, &show_bgp_route_cmd);
13197 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013198 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000013199 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
13200 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013201 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000013202 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
13203 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
13204 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
13205 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
13206 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
13207 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
13208 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
13209 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
13210 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
13211 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
13212 install_element (ENABLE_NODE, &show_bgp_community_cmd);
13213 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
13214 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
13215 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
13216 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
13217 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
13218 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
13219 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
13220 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
13221 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
13222 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
13223 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
13224 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
13225 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
13226 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
13227 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
13228 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
13229 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
13230 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
13231 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
13232 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
13233 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
13234 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
13235 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
13236 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
13237 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
13238 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
13239 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
13240 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
13241 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000013242 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
13243 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
13244 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
13245 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013246 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013247 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013248 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013249 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013250 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013251 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000013252 install_element (ENABLE_NODE, &show_bgp_view_cmd);
13253 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
13254 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
13255 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
13256 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
13257 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
13258 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
13259 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
13260 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
13261 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
13262 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
13263 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
13264 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
13265 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
13266 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
13267 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
13268 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
13269 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013270 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013271 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013272 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013273 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000013274 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040013275 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013276
13277 /* Statistics */
13278 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
Lou Berger298cc2f2016-01-12 13:42:02 -050013279 //install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013280 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
Lou Berger298cc2f2016-01-12 13:42:02 -050013281 //install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000013282
paul718e3742002-12-13 20:15:29 +000013283 /* old command */
13284 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
13285 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
13286 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
13287 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
13288 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
13289 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
13290 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
13291 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
13292 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
13293 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
13294 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
13295 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
13296 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
13297 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
13298 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
13299 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
13300 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13301 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13302 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
13303 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
13304 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
13305 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
13306 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13307 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
13308 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
13309 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
13310 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
13311 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
13312 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
13313 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
13314 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13315 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13316 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13317 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
13318 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13319 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000013320
paul718e3742002-12-13 20:15:29 +000013321 /* old command */
13322 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
13323 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
13324 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
13325 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
13326 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
13327 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
13328 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
13329 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
13330 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
13331 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
13332 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
13333 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
13334 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
13335 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
13336 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
13337 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
13338 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
13339 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
13340 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
13341 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
13342 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
13343 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
13344 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
13345 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
13346 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
13347 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
13348 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
13349 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
13350 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
13351 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
13352 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
13353 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13354 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13355 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13356 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13357 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13358
13359 /* old command */
13360 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13361 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13362 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13363 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13364
13365 /* old command */
13366 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13367 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13368 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13369 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13370
13371 /* old command */
13372 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13373 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13374 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13375 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13376#endif /* HAVE_IPV6 */
13377
13378 install_element (BGP_NODE, &bgp_distance_cmd);
13379 install_element (BGP_NODE, &no_bgp_distance_cmd);
13380 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13381 install_element (BGP_NODE, &bgp_distance_source_cmd);
13382 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13383 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13384 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13385
13386 install_element (BGP_NODE, &bgp_damp_set_cmd);
13387 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13388 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13389 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13390 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13391 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13392 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13393 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13394 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13395 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013396
13397 /* Deprecated AS-Pathlimit commands */
13398 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13399 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13400 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13401 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13402 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13403 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13404
13405 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13406 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13407 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13408 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13409 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13410 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13411
13412 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13413 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13414 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13415 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13416 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13417 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13418
13419 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13420 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13421 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13422 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13423 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13424 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13425
13426 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13427 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13428 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13429 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13430 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13431 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13432
13433 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13434 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13435 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13436 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13437 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13438 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013439
13440#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013441 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13442 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013443#endif
paul718e3742002-12-13 20:15:29 +000013444}
Chris Caputo228da422009-07-18 05:44:03 +000013445
13446void
13447bgp_route_finish (void)
13448{
13449 bgp_table_unlock (bgp_distance_table);
13450 bgp_distance_table = NULL;
13451}