blob: 0337224ad9129a70da5b72e10c7e54d13b7cade8 [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[];
paul718e3742002-12-13 20:15:29 +000062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
92
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{
Paul Jakma6f585442006-10-22 19:13:07 +0000243 assert (rn && rn->table);
244 assert (ri && ri->peer && ri->peer->bgp);
245
Paul Jakma1a392d42006-09-07 00:24:49 +0000246 /* Ignore 'pcount' for RS-client tables */
247 if (rn->table->type != BGP_TABLE_MAIN
248 || ri->peer == ri->peer->bgp->peer_self)
249 return;
250
251 if (BGP_INFO_HOLDDOWN (ri)
252 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
253 {
254
255 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
256
257 /* slight hack, but more robust against errors. */
258 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
259 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
260 else
261 {
262 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
263 __func__, ri->peer->host);
264 zlog_backtrace (LOG_WARNING);
265 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
266 }
267 }
268 else if (!BGP_INFO_HOLDDOWN (ri)
269 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
270 {
271 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
272 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
273 }
274}
275
276
277/* Set/unset bgp_info flags, adjusting any other state as needed.
278 * This is here primarily to keep prefix-count in check.
279 */
280void
281bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
282{
283 SET_FLAG (ri->flags, flag);
284
285 /* early bath if we know it's not a flag that changes useability state */
286 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
287 return;
288
289 bgp_pcount_adjust (rn, ri);
290}
291
292void
293bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
294{
295 UNSET_FLAG (ri->flags, flag);
296
297 /* early bath if we know it's not a flag that changes useability state */
298 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
299 return;
300
301 bgp_pcount_adjust (rn, ri);
302}
303
paul718e3742002-12-13 20:15:29 +0000304/* Get MED value. If MED value is missing and "bgp bestpath
305 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000306static u_int32_t
paul718e3742002-12-13 20:15:29 +0000307bgp_med_value (struct attr *attr, struct bgp *bgp)
308{
309 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
310 return attr->med;
311 else
312 {
313 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000314 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000315 else
316 return 0;
317 }
318}
319
320/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000321static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700322bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
323 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000324{
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000325 struct attr *newattr, *existattr;
326 struct attr_extra *newattre, *existattre;
327 bgp_peer_sort_t new_sort;
328 bgp_peer_sort_t exist_sort;
paul718e3742002-12-13 20:15:29 +0000329 u_int32_t new_pref;
330 u_int32_t exist_pref;
331 u_int32_t new_med;
332 u_int32_t exist_med;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000333 u_int32_t new_weight;
334 u_int32_t exist_weight;
335 uint32_t newm, existm;
paul718e3742002-12-13 20:15:29 +0000336 struct in_addr new_id;
337 struct in_addr exist_id;
338 int new_cluster;
339 int exist_cluster;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000340 int internal_as_route;
341 int confed_as_route;
paul718e3742002-12-13 20:15:29 +0000342 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700343
344 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000345
346 /* 0. Null check. */
347 if (new == NULL)
348 return 0;
349 if (exist == NULL)
350 return 1;
351
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000352 newattr = new->attr;
353 existattr = exist->attr;
354 newattre = newattr->extra;
355 existattre = existattr->extra;
356
paul718e3742002-12-13 20:15:29 +0000357 /* 1. Weight check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000358 new_weight = exist_weight = 0;
359
360 if (newattre)
361 new_weight = newattre->weight;
362 if (existattre)
363 exist_weight = existattre->weight;
364
Paul Jakmafb982c22007-05-04 20:15:47 +0000365 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000366 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000367 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000368 return 0;
369
370 /* 2. Local preference check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000371 new_pref = exist_pref = bgp->default_local_pref;
paul718e3742002-12-13 20:15:29 +0000372
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000373 if (newattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
374 new_pref = newattr->local_pref;
375 if (existattr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
376 exist_pref = existattr->local_pref;
377
paul718e3742002-12-13 20:15:29 +0000378 if (new_pref > exist_pref)
379 return 1;
380 if (new_pref < exist_pref)
381 return 0;
382
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000383 /* 3. Local route check. We prefer:
384 * - BGP_ROUTE_STATIC
385 * - BGP_ROUTE_AGGREGATE
386 * - BGP_ROUTE_REDISTRIBUTE
387 */
388 if (! (new->sub_type == BGP_ROUTE_NORMAL))
389 return 1;
390 if (! (exist->sub_type == BGP_ROUTE_NORMAL))
391 return 0;
paul718e3742002-12-13 20:15:29 +0000392
393 /* 4. AS path length check. */
394 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
395 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000396 int exist_hops = aspath_count_hops (existattr->aspath);
397 int exist_confeds = aspath_count_confeds (existattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000398
hasso68118452005-04-08 15:40:36 +0000399 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
400 {
paulfe69a502005-09-10 16:55:02 +0000401 int aspath_hops;
402
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000403 aspath_hops = aspath_count_hops (newattr->aspath);
404 aspath_hops += aspath_count_confeds (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000405
406 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000407 return 1;
paulfe69a502005-09-10 16:55:02 +0000408 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000409 return 0;
410 }
411 else
412 {
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000413 int newhops = aspath_count_hops (newattr->aspath);
paulfe69a502005-09-10 16:55:02 +0000414
415 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000416 return 1;
paulfe69a502005-09-10 16:55:02 +0000417 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000418 return 0;
419 }
paul718e3742002-12-13 20:15:29 +0000420 }
421
422 /* 5. Origin check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000423 if (newattr->origin < existattr->origin)
paul718e3742002-12-13 20:15:29 +0000424 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000425 if (newattr->origin > existattr->origin)
paul718e3742002-12-13 20:15:29 +0000426 return 0;
427
428 /* 6. MED check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000429 internal_as_route = (aspath_count_hops (newattr->aspath) == 0
430 && aspath_count_hops (existattr->aspath) == 0);
431 confed_as_route = (aspath_count_confeds (newattr->aspath) > 0
432 && aspath_count_confeds (existattr->aspath) > 0
433 && aspath_count_hops (newattr->aspath) == 0
434 && aspath_count_hops (existattr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000435
436 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
437 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
438 && confed_as_route)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000439 || aspath_cmp_left (newattr->aspath, existattr->aspath)
440 || aspath_cmp_left_confed (newattr->aspath, existattr->aspath)
paul718e3742002-12-13 20:15:29 +0000441 || internal_as_route)
442 {
443 new_med = bgp_med_value (new->attr, bgp);
444 exist_med = bgp_med_value (exist->attr, bgp);
445
446 if (new_med < exist_med)
447 return 1;
448 if (new_med > exist_med)
449 return 0;
450 }
451
452 /* 7. Peer type check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000453 new_sort = new->peer->sort;
454 exist_sort = exist->peer->sort;
455
456 if (new_sort == BGP_PEER_EBGP
457 && (exist_sort == BGP_PEER_IBGP || exist_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000458 return 1;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000459 if (exist_sort == BGP_PEER_EBGP
460 && (new_sort == BGP_PEER_IBGP || new_sort == BGP_PEER_CONFED))
paul718e3742002-12-13 20:15:29 +0000461 return 0;
462
463 /* 8. IGP metric check. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000464 newm = existm = 0;
465
466 if (new->extra)
467 newm = new->extra->igpmetric;
468 if (exist->extra)
469 existm = exist->extra->igpmetric;
470
Josh Bailey96450fa2011-07-20 20:45:12 -0700471 if (newm < existm)
472 ret = 1;
473 if (newm > existm)
474 ret = 0;
paul718e3742002-12-13 20:15:29 +0000475
476 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700477 if (newm == existm)
478 {
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000479 if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700480 {
481 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
482 *paths_eq = 1;
483 }
484 else if (new->peer->as == exist->peer->as)
485 *paths_eq = 1;
486 }
487 else
488 {
489 /*
490 * TODO: If unequal cost ibgp multipath is enabled we can
491 * mark the paths as equal here instead of returning
492 */
493 return ret;
494 }
paul718e3742002-12-13 20:15:29 +0000495
496 /* 10. If both paths are external, prefer the path that was received
497 first (the oldest one). This step minimizes route-flap, since a
498 newer path won't displace an older one, even if it was the
499 preferred route based on the additional decision criteria below. */
500 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000501 && new_sort == BGP_PEER_EBGP
502 && exist_sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000503 {
504 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
505 return 1;
506 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
507 return 0;
508 }
509
510 /* 11. Rourter-ID comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000511 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
512 new_id.s_addr = newattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000513 else
514 new_id.s_addr = new->peer->remote_id.s_addr;
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000515 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
516 exist_id.s_addr = existattre->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000517 else
518 exist_id.s_addr = exist->peer->remote_id.s_addr;
519
520 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
521 return 1;
522 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
523 return 0;
524
525 /* 12. Cluster length comparision. */
Jorge Boncompte [DTI2]8ff56312012-05-07 16:52:56 +0000526 new_cluster = exist_cluster = 0;
527
528 if (newattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
529 new_cluster = newattre->cluster->length;
530 if (existattr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
531 exist_cluster = existattre->cluster->length;
paul718e3742002-12-13 20:15:29 +0000532
533 if (new_cluster < exist_cluster)
534 return 1;
535 if (new_cluster > exist_cluster)
536 return 0;
537
538 /* 13. Neighbor address comparision. */
539 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
540
541 if (ret == 1)
542 return 0;
543 if (ret == -1)
544 return 1;
545
546 return 1;
547}
548
paul94f2b392005-06-28 12:44:16 +0000549static enum filter_type
paul718e3742002-12-13 20:15:29 +0000550bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
551 afi_t afi, safi_t safi)
552{
553 struct bgp_filter *filter;
554
555 filter = &peer->filter[afi][safi];
556
Paul Jakma650f76c2009-06-25 18:06:31 +0100557#define FILTER_EXIST_WARN(F,f,filter) \
558 if (BGP_DEBUG (update, UPDATE_IN) \
559 && !(F ## _IN (filter))) \
560 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
561 peer->host, #f, F ## _IN_NAME(filter));
562
563 if (DISTRIBUTE_IN_NAME (filter)) {
564 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
565
paul718e3742002-12-13 20:15:29 +0000566 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
567 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100568 }
paul718e3742002-12-13 20:15:29 +0000569
Paul Jakma650f76c2009-06-25 18:06:31 +0100570 if (PREFIX_LIST_IN_NAME (filter)) {
571 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
572
paul718e3742002-12-13 20:15:29 +0000573 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
574 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100575 }
paul718e3742002-12-13 20:15:29 +0000576
Paul Jakma650f76c2009-06-25 18:06:31 +0100577 if (FILTER_LIST_IN_NAME (filter)) {
578 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
579
paul718e3742002-12-13 20:15:29 +0000580 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
581 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100582 }
583
paul718e3742002-12-13 20:15:29 +0000584 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100585#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000586}
587
paul94f2b392005-06-28 12:44:16 +0000588static enum filter_type
paul718e3742002-12-13 20:15:29 +0000589bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
590 afi_t afi, safi_t safi)
591{
592 struct bgp_filter *filter;
593
594 filter = &peer->filter[afi][safi];
595
Paul Jakma650f76c2009-06-25 18:06:31 +0100596#define FILTER_EXIST_WARN(F,f,filter) \
597 if (BGP_DEBUG (update, UPDATE_OUT) \
598 && !(F ## _OUT (filter))) \
599 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
600 peer->host, #f, F ## _OUT_NAME(filter));
601
602 if (DISTRIBUTE_OUT_NAME (filter)) {
603 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
604
paul718e3742002-12-13 20:15:29 +0000605 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
606 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100607 }
paul718e3742002-12-13 20:15:29 +0000608
Paul Jakma650f76c2009-06-25 18:06:31 +0100609 if (PREFIX_LIST_OUT_NAME (filter)) {
610 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
611
paul718e3742002-12-13 20:15:29 +0000612 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
613 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100614 }
paul718e3742002-12-13 20:15:29 +0000615
Paul Jakma650f76c2009-06-25 18:06:31 +0100616 if (FILTER_LIST_OUT_NAME (filter)) {
617 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
618
paul718e3742002-12-13 20:15:29 +0000619 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
620 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100621 }
paul718e3742002-12-13 20:15:29 +0000622
623 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100624#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000625}
626
627/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000628static int
paul718e3742002-12-13 20:15:29 +0000629bgp_community_filter (struct peer *peer, struct attr *attr)
630{
631 if (attr->community)
632 {
633 /* NO_ADVERTISE check. */
634 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
635 return 1;
636
637 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000638 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000639 community_include (attr->community, COMMUNITY_NO_EXPORT))
640 return 1;
641
642 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000643 if (peer->sort == BGP_PEER_EBGP
644 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000645 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
646 return 1;
647 }
648 return 0;
649}
650
651/* Route reflection loop check. */
652static int
653bgp_cluster_filter (struct peer *peer, struct attr *attr)
654{
655 struct in_addr cluster_id;
656
Paul Jakmafb982c22007-05-04 20:15:47 +0000657 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000658 {
659 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
660 cluster_id = peer->bgp->cluster_id;
661 else
662 cluster_id = peer->bgp->router_id;
663
Paul Jakmafb982c22007-05-04 20:15:47 +0000664 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000665 return 1;
666 }
667 return 0;
668}
669
paul94f2b392005-06-28 12:44:16 +0000670static int
paul718e3742002-12-13 20:15:29 +0000671bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
672 afi_t afi, safi_t safi)
673{
674 struct bgp_filter *filter;
675 struct bgp_info info;
676 route_map_result_t ret;
677
678 filter = &peer->filter[afi][safi];
679
680 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000681 if (peer->weight)
682 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000683
684 /* Route map apply. */
685 if (ROUTE_MAP_IN_NAME (filter))
686 {
687 /* Duplicate current value to new strucutre for modification. */
688 info.peer = peer;
689 info.attr = attr;
690
paulac41b2a2003-08-12 05:32:27 +0000691 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
692
paul718e3742002-12-13 20:15:29 +0000693 /* Apply BGP route map to the attribute. */
694 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000695
696 peer->rmap_type = 0;
697
paul718e3742002-12-13 20:15:29 +0000698 if (ret == RMAP_DENYMATCH)
699 {
700 /* Free newly generated AS path and community by route-map. */
701 bgp_attr_flush (attr);
702 return RMAP_DENY;
703 }
704 }
705 return RMAP_PERMIT;
706}
707
paul94f2b392005-06-28 12:44:16 +0000708static int
paulfee0f4c2004-09-13 05:12:46 +0000709bgp_export_modifier (struct peer *rsclient, struct peer *peer,
710 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
711{
712 struct bgp_filter *filter;
713 struct bgp_info info;
714 route_map_result_t ret;
715
716 filter = &peer->filter[afi][safi];
717
718 /* Route map apply. */
719 if (ROUTE_MAP_EXPORT_NAME (filter))
720 {
721 /* Duplicate current value to new strucutre for modification. */
722 info.peer = rsclient;
723 info.attr = attr;
724
725 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
726
727 /* Apply BGP route map to the attribute. */
728 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
729
730 rsclient->rmap_type = 0;
731
732 if (ret == RMAP_DENYMATCH)
733 {
734 /* Free newly generated AS path and community by route-map. */
735 bgp_attr_flush (attr);
736 return RMAP_DENY;
737 }
738 }
739 return RMAP_PERMIT;
740}
741
paul94f2b392005-06-28 12:44:16 +0000742static int
paulfee0f4c2004-09-13 05:12:46 +0000743bgp_import_modifier (struct peer *rsclient, struct peer *peer,
744 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
745{
746 struct bgp_filter *filter;
747 struct bgp_info info;
748 route_map_result_t ret;
749
750 filter = &rsclient->filter[afi][safi];
751
752 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000753 if (peer->weight)
754 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000755
756 /* Route map apply. */
757 if (ROUTE_MAP_IMPORT_NAME (filter))
758 {
759 /* Duplicate current value to new strucutre for modification. */
760 info.peer = peer;
761 info.attr = attr;
762
763 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
764
765 /* Apply BGP route map to the attribute. */
766 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
767
768 peer->rmap_type = 0;
769
770 if (ret == RMAP_DENYMATCH)
771 {
772 /* Free newly generated AS path and community by route-map. */
773 bgp_attr_flush (attr);
774 return RMAP_DENY;
775 }
776 }
777 return RMAP_PERMIT;
778}
779
paul94f2b392005-06-28 12:44:16 +0000780static int
paul718e3742002-12-13 20:15:29 +0000781bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
782 struct attr *attr, afi_t afi, safi_t safi)
783{
784 int ret;
785 char buf[SU_ADDRSTRLEN];
786 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000787 struct peer *from;
788 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000789 int transparent;
790 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700791 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000792
793 from = ri->peer;
794 filter = &peer->filter[afi][safi];
795 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700796 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000797
Paul Jakma750e8142008-07-22 21:11:48 +0000798 if (DISABLE_BGP_ANNOUNCE)
799 return 0;
paul718e3742002-12-13 20:15:29 +0000800
paulfee0f4c2004-09-13 05:12:46 +0000801 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
802 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
803 return 0;
804
paul718e3742002-12-13 20:15:29 +0000805 /* Do not send back route to sender. */
806 if (from == peer)
807 return 0;
808
paul35be31b2004-05-01 18:17:04 +0000809 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
810 if (p->family == AF_INET
Josh Bailey0b597ef2011-07-20 20:49:11 -0700811 && IPV4_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000812 return 0;
813#ifdef HAVE_IPV6
814 if (p->family == AF_INET6
Josh Bailey0b597ef2011-07-20 20:49:11 -0700815 && IPV6_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000816 return 0;
817#endif
818
paul718e3742002-12-13 20:15:29 +0000819 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000820 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000821 if (! UNSUPPRESS_MAP_NAME (filter))
822 return 0;
823
824 /* Default route check. */
825 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
826 {
827 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
828 return 0;
829#ifdef HAVE_IPV6
830 else if (p->family == AF_INET6 && p->prefixlen == 0)
831 return 0;
832#endif /* HAVE_IPV6 */
833 }
834
paul286e1e72003-08-08 00:24:31 +0000835 /* Transparency check. */
836 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
837 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
838 transparent = 1;
839 else
840 transparent = 0;
841
paul718e3742002-12-13 20:15:29 +0000842 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700843 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000844 return 0;
845
846 /* If the attribute has originator-id and it is same as remote
847 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700848 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000849 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700850 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000851 {
852 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000853 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000854 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
855 peer->host,
856 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
857 p->prefixlen);
858 return 0;
859 }
860 }
861
862 /* ORF prefix-list filter check */
863 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
864 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
865 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
866 if (peer->orf_plist[afi][safi])
867 {
868 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
869 return 0;
870 }
871
872 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700873 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000874 {
875 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000876 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000877 "%s [Update:SEND] %s/%d is filtered",
878 peer->host,
879 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
880 p->prefixlen);
881 return 0;
882 }
883
884#ifdef BGP_SEND_ASPATH_CHECK
885 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700886 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000887 {
888 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000889 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400890 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000891 peer->host, peer->as);
892 return 0;
893 }
894#endif /* BGP_SEND_ASPATH_CHECK */
895
896 /* If we're a CONFED we need to loop check the CONFED ID too */
897 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
898 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700899 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000900 {
901 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000902 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400903 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000904 peer->host,
905 bgp->confed_id);
906 return 0;
907 }
908 }
909
910 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000911 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000912 reflect = 1;
913 else
914 reflect = 0;
915
916 /* IBGP reflection check. */
917 if (reflect)
918 {
919 /* A route from a Client peer. */
920 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
921 {
922 /* Reflect to all the Non-Client peers and also to the
923 Client peers other than the originator. Originator check
924 is already done. So there is noting to do. */
925 /* no bgp client-to-client reflection check. */
926 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
927 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
928 return 0;
929 }
930 else
931 {
932 /* A route from a Non-client peer. Reflect to all other
933 clients. */
934 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
935 return 0;
936 }
937 }
Paul Jakma41367172007-08-06 15:24:51 +0000938
paul718e3742002-12-13 20:15:29 +0000939 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700940 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000941
paul718e3742002-12-13 20:15:29 +0000942 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000943 if ((peer->sort == BGP_PEER_IBGP
944 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000945 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
946 {
947 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
948 attr->local_pref = bgp->default_local_pref;
949 }
950
paul718e3742002-12-13 20:15:29 +0000951 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000952 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000953 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
954 {
955 if (ri->peer != bgp->peer_self && ! transparent
956 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
957 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
958 }
959
960 /* next-hop-set */
961 if (transparent || reflect
962 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
963 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000964#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000965 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000966 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000967#endif /* HAVE_IPV6 */
968 )))
paul718e3742002-12-13 20:15:29 +0000969 {
970 /* NEXT-HOP Unchanged. */
971 }
972 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
973 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
974#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000975 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000976 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000977#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000978 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000979 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
980 {
981 /* Set IPv4 nexthop. */
982 if (p->family == AF_INET)
983 {
984 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000985 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
986 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000987 else
988 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
989 }
990#ifdef HAVE_IPV6
991 /* Set IPv6 nexthop. */
992 if (p->family == AF_INET6)
993 {
994 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000995 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000996 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000997 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000998 }
999#endif /* HAVE_IPV6 */
1000 }
1001
1002#ifdef HAVE_IPV6
1003 if (p->family == AF_INET6)
1004 {
paulfee0f4c2004-09-13 05:12:46 +00001005 /* Left nexthop_local unchanged if so configured. */
1006 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1007 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1008 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001009 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1010 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001011 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001012 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001013 }
1014
1015 /* Default nexthop_local treatment for non-RS-Clients */
1016 else
1017 {
paul718e3742002-12-13 20:15:29 +00001018 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001019 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001020
1021 /* Set link-local address for shared network peer. */
1022 if (peer->shared_network
1023 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1024 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001025 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001026 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001027 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001028 }
1029
1030 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1031 address.*/
1032 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001033 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001034
1035 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1036 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001037 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001038 }
paulfee0f4c2004-09-13 05:12:46 +00001039
1040 }
paul718e3742002-12-13 20:15:29 +00001041#endif /* HAVE_IPV6 */
1042
1043 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001044 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001045 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1046 && aspath_private_as_check (attr->aspath))
1047 attr->aspath = aspath_empty_get ();
1048
1049 /* Route map & unsuppress-map apply. */
1050 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001051 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001052 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001053 struct bgp_info info;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001054 struct attr dummy_attr;
1055 struct attr_extra dummy_extra;
1056
1057 dummy_attr.extra = &dummy_extra;
1058
paul718e3742002-12-13 20:15:29 +00001059 info.peer = peer;
1060 info.attr = attr;
1061
1062 /* The route reflector is not allowed to modify the attributes
1063 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001064 if (from->sort == BGP_PEER_IBGP
1065 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001066 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001067 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001068 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001069 }
paulac41b2a2003-08-12 05:32:27 +00001070
1071 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1072
Paul Jakmafb982c22007-05-04 20:15:47 +00001073 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001074 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1075 else
1076 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1077
paulac41b2a2003-08-12 05:32:27 +00001078 peer->rmap_type = 0;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001079
paul718e3742002-12-13 20:15:29 +00001080 if (ret == RMAP_DENYMATCH)
1081 {
1082 bgp_attr_flush (attr);
1083 return 0;
1084 }
1085 }
1086 return 1;
1087}
1088
paul94f2b392005-06-28 12:44:16 +00001089static int
paulfee0f4c2004-09-13 05:12:46 +00001090bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1091 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001092{
paulfee0f4c2004-09-13 05:12:46 +00001093 int ret;
1094 char buf[SU_ADDRSTRLEN];
1095 struct bgp_filter *filter;
1096 struct bgp_info info;
1097 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001098 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001099
1100 from = ri->peer;
1101 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001102 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001103
Paul Jakma750e8142008-07-22 21:11:48 +00001104 if (DISABLE_BGP_ANNOUNCE)
1105 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001106
1107 /* Do not send back route to sender. */
1108 if (from == rsclient)
1109 return 0;
1110
1111 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001112 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001113 if (! UNSUPPRESS_MAP_NAME (filter))
1114 return 0;
1115
1116 /* Default route check. */
1117 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1118 PEER_STATUS_DEFAULT_ORIGINATE))
1119 {
1120 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1121 return 0;
1122#ifdef HAVE_IPV6
1123 else if (p->family == AF_INET6 && p->prefixlen == 0)
1124 return 0;
1125#endif /* HAVE_IPV6 */
1126 }
1127
1128 /* If the attribute has originator-id and it is same as remote
1129 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001130 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001131 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001132 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001133 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001134 {
1135 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001136 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001137 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1138 rsclient->host,
1139 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1140 p->prefixlen);
1141 return 0;
1142 }
1143 }
1144
1145 /* ORF prefix-list filter check */
1146 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1147 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1148 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1149 if (rsclient->orf_plist[afi][safi])
1150 {
1151 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1152 return 0;
1153 }
1154
1155 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001156 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001157 {
1158 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001159 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001160 "%s [Update:SEND] %s/%d is filtered",
1161 rsclient->host,
1162 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1163 p->prefixlen);
1164 return 0;
1165 }
1166
1167#ifdef BGP_SEND_ASPATH_CHECK
1168 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001169 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001170 {
1171 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001172 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001173 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001174 rsclient->host, rsclient->as);
1175 return 0;
1176 }
1177#endif /* BGP_SEND_ASPATH_CHECK */
1178
1179 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001180 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001181
1182 /* next-hop-set */
1183 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1184#ifdef HAVE_IPV6
1185 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001186 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001187#endif /* HAVE_IPV6 */
1188 )
1189 {
1190 /* Set IPv4 nexthop. */
1191 if (p->family == AF_INET)
1192 {
1193 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001194 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001195 IPV4_MAX_BYTELEN);
1196 else
1197 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1198 }
1199#ifdef HAVE_IPV6
1200 /* Set IPv6 nexthop. */
1201 if (p->family == AF_INET6)
1202 {
1203 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001204 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001205 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001206 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001207 }
1208#endif /* HAVE_IPV6 */
1209 }
1210
1211#ifdef HAVE_IPV6
1212 if (p->family == AF_INET6)
1213 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001214 struct attr_extra *attre = attr->extra;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001215
paulfee0f4c2004-09-13 05:12:46 +00001216 /* Left nexthop_local unchanged if so configured. */
1217 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1218 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1219 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001220 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1221 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001222 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001223 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001224 }
1225
1226 /* Default nexthop_local treatment for RS-Clients */
1227 else
1228 {
1229 /* Announcer and RS-Client are both in the same network */
1230 if (rsclient->shared_network && from->shared_network &&
1231 (rsclient->ifindex == from->ifindex))
1232 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001233 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1234 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001235 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001236 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001237 }
1238
1239 /* Set link-local address for shared network peer. */
1240 else if (rsclient->shared_network
1241 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1242 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001243 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001244 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001245 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001246 }
1247
1248 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001249 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001250 }
1251
1252 }
1253#endif /* HAVE_IPV6 */
1254
1255
1256 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001257 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001258 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1259 && aspath_private_as_check (attr->aspath))
1260 attr->aspath = aspath_empty_get ();
1261
1262 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001263 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001264 {
1265 info.peer = rsclient;
1266 info.attr = attr;
1267
1268 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1269
Paul Jakmafb982c22007-05-04 20:15:47 +00001270 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001271 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1272 else
1273 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1274
1275 rsclient->rmap_type = 0;
1276
1277 if (ret == RMAP_DENYMATCH)
1278 {
1279 bgp_attr_flush (attr);
1280 return 0;
1281 }
1282 }
1283
1284 return 1;
1285}
1286
1287struct bgp_info_pair
1288{
1289 struct bgp_info *old;
1290 struct bgp_info *new;
1291};
1292
paul94f2b392005-06-28 12:44:16 +00001293static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001294bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1295 struct bgp_maxpaths_cfg *mpath_cfg,
1296 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001297{
paul718e3742002-12-13 20:15:29 +00001298 struct bgp_info *new_select;
1299 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001300 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001301 struct bgp_info *ri1;
1302 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001303 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001304 int paths_eq, do_mpath;
1305 struct list mp_list;
1306
1307 bgp_mp_list_init (&mp_list);
1308 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1309 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1310
paul718e3742002-12-13 20:15:29 +00001311 /* bgp deterministic-med */
1312 new_select = NULL;
1313 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1314 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1315 {
1316 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1317 continue;
1318 if (BGP_INFO_HOLDDOWN (ri1))
1319 continue;
1320
1321 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001322 if (do_mpath)
1323 bgp_mp_list_add (&mp_list, ri1);
1324 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001325 if (ri1->next)
1326 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1327 {
1328 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1329 continue;
1330 if (BGP_INFO_HOLDDOWN (ri2))
1331 continue;
1332
1333 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1334 || aspath_cmp_left_confed (ri1->attr->aspath,
1335 ri2->attr->aspath))
1336 {
Josh Bailey6918e742011-07-20 20:48:20 -07001337 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1338 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001339 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001340 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001341 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001342 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001343 if (do_mpath && !paths_eq)
1344 {
1345 bgp_mp_list_clear (&mp_list);
1346 bgp_mp_list_add (&mp_list, ri2);
1347 }
paul718e3742002-12-13 20:15:29 +00001348 }
1349
Josh Bailey6918e742011-07-20 20:48:20 -07001350 if (do_mpath && paths_eq)
1351 bgp_mp_list_add (&mp_list, ri2);
1352
Paul Jakma1a392d42006-09-07 00:24:49 +00001353 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001354 }
1355 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001356 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1357 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001358
1359 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1360 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001361 }
1362
1363 /* Check old selected route and new selected route. */
1364 old_select = NULL;
1365 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001366 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001367 {
1368 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1369 old_select = ri;
1370
1371 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001372 {
1373 /* reap REMOVED routes, if needs be
1374 * selected route must stay for a while longer though
1375 */
1376 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1377 && (ri != old_select))
1378 bgp_info_reap (rn, ri);
1379
1380 continue;
1381 }
paul718e3742002-12-13 20:15:29 +00001382
1383 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1384 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1385 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001386 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001387 continue;
1388 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001389 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1390 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001391
Josh Bailey96450fa2011-07-20 20:45:12 -07001392 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1393 {
Josh Bailey6918e742011-07-20 20:48:20 -07001394 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1395 bgp_mp_dmed_deselect (new_select);
1396
Josh Bailey96450fa2011-07-20 20:45:12 -07001397 new_select = ri;
1398
1399 if (do_mpath && !paths_eq)
1400 {
1401 bgp_mp_list_clear (&mp_list);
1402 bgp_mp_list_add (&mp_list, ri);
1403 }
1404 }
Josh Bailey6918e742011-07-20 20:48:20 -07001405 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1406 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001407
1408 if (do_mpath && paths_eq)
1409 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001410 }
paulb40d9392005-08-22 22:34:41 +00001411
paulfee0f4c2004-09-13 05:12:46 +00001412
Josh Bailey6918e742011-07-20 20:48:20 -07001413 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1414 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001415
Josh Bailey0b597ef2011-07-20 20:49:11 -07001416 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001417 bgp_mp_list_clear (&mp_list);
1418
1419 result->old = old_select;
1420 result->new = new_select;
1421
1422 return;
paulfee0f4c2004-09-13 05:12:46 +00001423}
1424
paul94f2b392005-06-28 12:44:16 +00001425static int
paulfee0f4c2004-09-13 05:12:46 +00001426bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001427 struct bgp_node *rn, afi_t afi, safi_t safi)
1428{
paulfee0f4c2004-09-13 05:12:46 +00001429 struct prefix *p;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001430 struct attr attr;
1431 struct attr_extra extra;
paulfee0f4c2004-09-13 05:12:46 +00001432
1433 p = &rn->p;
1434
Paul Jakma9eda90c2007-08-30 13:36:17 +00001435 /* Announce route to Established peer. */
1436 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001437 return 0;
1438
Paul Jakma9eda90c2007-08-30 13:36:17 +00001439 /* Address family configuration check. */
1440 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001441 return 0;
1442
Paul Jakma9eda90c2007-08-30 13:36:17 +00001443 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001444 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1445 PEER_STATUS_ORF_WAIT_REFRESH))
1446 return 0;
1447
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001448 /* It's initialized in bgp_announce_[check|check_rsclient]() */
1449 attr.extra = &extra;
1450
paulfee0f4c2004-09-13 05:12:46 +00001451 switch (rn->table->type)
1452 {
1453 case BGP_TABLE_MAIN:
1454 /* Announcement to peer->conf. If the route is filtered,
1455 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001456 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1457 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001458 else
1459 bgp_adj_out_unset (rn, peer, p, afi, safi);
1460 break;
1461 case BGP_TABLE_RSCLIENT:
1462 /* Announcement to peer->conf. If the route is filtered,
1463 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001464 if (selected &&
1465 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1466 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1467 else
1468 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001469 break;
1470 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001471
paulfee0f4c2004-09-13 05:12:46 +00001472 return 0;
paul200df112005-06-01 11:17:05 +00001473}
paulfee0f4c2004-09-13 05:12:46 +00001474
paul200df112005-06-01 11:17:05 +00001475struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001476{
paul200df112005-06-01 11:17:05 +00001477 struct bgp *bgp;
1478 struct bgp_node *rn;
1479 afi_t afi;
1480 safi_t safi;
1481};
1482
1483static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001484bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001485{
paul0fb58d52005-11-14 14:31:49 +00001486 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001487 struct bgp *bgp = pq->bgp;
1488 struct bgp_node *rn = pq->rn;
1489 afi_t afi = pq->afi;
1490 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001491 struct bgp_info *new_select;
1492 struct bgp_info *old_select;
1493 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001494 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001495 struct peer *rsclient = rn->table->owner;
1496
paulfee0f4c2004-09-13 05:12:46 +00001497 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001498 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001499 new_select = old_and_new.new;
1500 old_select = old_and_new.old;
1501
paul200df112005-06-01 11:17:05 +00001502 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1503 {
Chris Caputo228da422009-07-18 05:44:03 +00001504 if (rsclient->group)
1505 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1506 {
1507 /* Nothing to do. */
1508 if (old_select && old_select == new_select)
1509 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1510 continue;
paulfee0f4c2004-09-13 05:12:46 +00001511
Chris Caputo228da422009-07-18 05:44:03 +00001512 if (old_select)
1513 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1514 if (new_select)
1515 {
1516 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1517 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001518 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1519 }
paulfee0f4c2004-09-13 05:12:46 +00001520
Chris Caputo228da422009-07-18 05:44:03 +00001521 bgp_process_announce_selected (rsclient, new_select, rn,
1522 afi, safi);
1523 }
paul200df112005-06-01 11:17:05 +00001524 }
1525 else
1526 {
hassob7395792005-08-26 12:58:38 +00001527 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001528 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001529 if (new_select)
1530 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001531 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1532 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001533 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001534 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001535 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001536 }
paulfee0f4c2004-09-13 05:12:46 +00001537
paulb40d9392005-08-22 22:34:41 +00001538 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1539 bgp_info_reap (rn, old_select);
1540
paul200df112005-06-01 11:17:05 +00001541 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1542 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001543}
1544
paul200df112005-06-01 11:17:05 +00001545static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001546bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001547{
paul0fb58d52005-11-14 14:31:49 +00001548 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001549 struct bgp *bgp = pq->bgp;
1550 struct bgp_node *rn = pq->rn;
1551 afi_t afi = pq->afi;
1552 safi_t safi = pq->safi;
1553 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001554 struct bgp_info *new_select;
1555 struct bgp_info *old_select;
1556 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001557 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001558 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001559
paulfee0f4c2004-09-13 05:12:46 +00001560 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001561 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001562 old_select = old_and_new.old;
1563 new_select = old_and_new.new;
1564
1565 /* Nothing to do. */
1566 if (old_select && old_select == new_select)
1567 {
1568 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001569 {
Josh Bailey8196f132011-07-20 20:47:07 -07001570 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1571 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001572 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001573
Josh Bailey8196f132011-07-20 20:47:07 -07001574 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001575 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1576 return WQ_SUCCESS;
1577 }
paulfee0f4c2004-09-13 05:12:46 +00001578 }
paul718e3742002-12-13 20:15:29 +00001579
hasso338b3422005-02-23 14:27:24 +00001580 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001581 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001582 if (new_select)
1583 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001584 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1585 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001586 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001587 }
1588
1589
paul718e3742002-12-13 20:15:29 +00001590 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001591 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001592 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001593 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001594 }
1595
1596 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001597 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1598 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001599 {
1600 if (new_select
1601 && new_select->type == ZEBRA_ROUTE_BGP
1602 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001603 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001604 else
1605 {
1606 /* Withdraw the route from the kernel. */
1607 if (old_select
1608 && old_select->type == ZEBRA_ROUTE_BGP
1609 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001610 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001611 }
1612 }
paulb40d9392005-08-22 22:34:41 +00001613
1614 /* Reap old select bgp_info, it it has been removed */
1615 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1616 bgp_info_reap (rn, old_select);
1617
paul200df112005-06-01 11:17:05 +00001618 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1619 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001620}
1621
paul200df112005-06-01 11:17:05 +00001622static void
paul0fb58d52005-11-14 14:31:49 +00001623bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001624{
paul0fb58d52005-11-14 14:31:49 +00001625 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001626 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001627
Chris Caputo228da422009-07-18 05:44:03 +00001628 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001629 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001630 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001631 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1632}
1633
1634static void
1635bgp_process_queue_init (void)
1636{
1637 bm->process_main_queue
1638 = work_queue_new (bm->master, "process_main_queue");
1639 bm->process_rsclient_queue
1640 = work_queue_new (bm->master, "process_rsclient_queue");
1641
1642 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1643 {
1644 zlog_err ("%s: Failed to allocate work queue", __func__);
1645 exit (1);
1646 }
1647
1648 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001649 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001650 bm->process_main_queue->spec.max_retries = 0;
1651 bm->process_main_queue->spec.hold = 50;
1652
1653 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1654 sizeof (struct work_queue *));
1655 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001656}
1657
1658void
paulfee0f4c2004-09-13 05:12:46 +00001659bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1660{
paul200df112005-06-01 11:17:05 +00001661 struct bgp_process_queue *pqnode;
1662
1663 /* already scheduled for processing? */
1664 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1665 return;
1666
1667 if ( (bm->process_main_queue == NULL) ||
1668 (bm->process_rsclient_queue == NULL) )
1669 bgp_process_queue_init ();
1670
1671 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1672 sizeof (struct bgp_process_queue));
1673 if (!pqnode)
1674 return;
Chris Caputo228da422009-07-18 05:44:03 +00001675
1676 /* all unlocked in bgp_processq_del */
1677 bgp_table_lock (rn->table);
1678 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001679 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001680 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001681 pqnode->afi = afi;
1682 pqnode->safi = safi;
1683
paulfee0f4c2004-09-13 05:12:46 +00001684 switch (rn->table->type)
1685 {
paul200df112005-06-01 11:17:05 +00001686 case BGP_TABLE_MAIN:
1687 work_queue_add (bm->process_main_queue, pqnode);
1688 break;
1689 case BGP_TABLE_RSCLIENT:
1690 work_queue_add (bm->process_rsclient_queue, pqnode);
1691 break;
paulfee0f4c2004-09-13 05:12:46 +00001692 }
paul200df112005-06-01 11:17:05 +00001693
1694 return;
paulfee0f4c2004-09-13 05:12:46 +00001695}
hasso0a486e52005-02-01 20:57:17 +00001696
paul94f2b392005-06-28 12:44:16 +00001697static int
hasso0a486e52005-02-01 20:57:17 +00001698bgp_maximum_prefix_restart_timer (struct thread *thread)
1699{
1700 struct peer *peer;
1701
1702 peer = THREAD_ARG (thread);
1703 peer->t_pmax_restart = NULL;
1704
1705 if (BGP_DEBUG (events, EVENTS))
1706 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1707 peer->host);
1708
1709 peer_clear (peer);
1710
1711 return 0;
1712}
1713
paulfee0f4c2004-09-13 05:12:46 +00001714int
paul5228ad22004-06-04 17:58:18 +00001715bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1716 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001717{
hassoe0701b72004-05-20 09:19:34 +00001718 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1719 return 0;
1720
1721 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001722 {
hassoe0701b72004-05-20 09:19:34 +00001723 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1724 && ! always)
1725 return 0;
paul718e3742002-12-13 20:15:29 +00001726
hassoe0701b72004-05-20 09:19:34 +00001727 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001728 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1729 "limit %ld", afi_safi_print (afi, safi), peer->host,
1730 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001731 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001732
hassoe0701b72004-05-20 09:19:34 +00001733 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1734 return 0;
paul718e3742002-12-13 20:15:29 +00001735
hassoe0701b72004-05-20 09:19:34 +00001736 {
paul5228ad22004-06-04 17:58:18 +00001737 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001738
1739 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001740 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001741
1742 ndata[0] = (afi >> 8);
1743 ndata[1] = afi;
1744 ndata[2] = safi;
1745 ndata[3] = (peer->pmax[afi][safi] >> 24);
1746 ndata[4] = (peer->pmax[afi][safi] >> 16);
1747 ndata[5] = (peer->pmax[afi][safi] >> 8);
1748 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001749
1750 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1751 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1752 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1753 }
hasso0a486e52005-02-01 20:57:17 +00001754
1755 /* restart timer start */
1756 if (peer->pmax_restart[afi][safi])
1757 {
1758 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1759
1760 if (BGP_DEBUG (events, EVENTS))
1761 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1762 peer->host, peer->v_pmax_restart);
1763
1764 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1765 peer->v_pmax_restart);
1766 }
1767
hassoe0701b72004-05-20 09:19:34 +00001768 return 1;
paul718e3742002-12-13 20:15:29 +00001769 }
hassoe0701b72004-05-20 09:19:34 +00001770 else
1771 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1772
1773 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1774 {
1775 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1776 && ! always)
1777 return 0;
1778
1779 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001780 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1781 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1782 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001783 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1784 }
1785 else
1786 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001787 return 0;
1788}
1789
paulb40d9392005-08-22 22:34:41 +00001790/* Unconditionally remove the route from the RIB, without taking
1791 * damping into consideration (eg, because the session went down)
1792 */
paul94f2b392005-06-28 12:44:16 +00001793static void
paul718e3742002-12-13 20:15:29 +00001794bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1795 afi_t afi, safi_t safi)
1796{
paul902212c2006-02-05 17:51:19 +00001797 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1798
1799 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1800 bgp_info_delete (rn, ri); /* keep historical info */
1801
paulb40d9392005-08-22 22:34:41 +00001802 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001803}
1804
paul94f2b392005-06-28 12:44:16 +00001805static void
paul718e3742002-12-13 20:15:29 +00001806bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001807 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001808{
paul718e3742002-12-13 20:15:29 +00001809 int status = BGP_DAMP_NONE;
1810
paulb40d9392005-08-22 22:34:41 +00001811 /* apply dampening, if result is suppressed, we'll be retaining
1812 * the bgp_info in the RIB for historical reference.
1813 */
1814 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001815 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001816 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1817 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001818 {
paul902212c2006-02-05 17:51:19 +00001819 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1820 return;
1821 }
1822
1823 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001824}
1825
paul94f2b392005-06-28 12:44:16 +00001826static void
paulfee0f4c2004-09-13 05:12:46 +00001827bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1828 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1829 int sub_type, struct prefix_rd *prd, u_char *tag)
1830{
1831 struct bgp_node *rn;
1832 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001833 struct attr new_attr;
1834 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00001835 struct attr *attr_new;
1836 struct attr *attr_new2;
1837 struct bgp_info *ri;
1838 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001839 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001840 char buf[SU_ADDRSTRLEN];
1841
1842 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1843 if (peer == rsclient)
1844 return;
1845
1846 bgp = peer->bgp;
1847 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1848
1849 /* Check previously received route. */
1850 for (ri = rn->info; ri; ri = ri->next)
1851 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1852 break;
1853
1854 /* AS path loop check. */
1855 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1856 {
1857 reason = "as-path contains our own AS;";
1858 goto filtered;
1859 }
1860
1861 /* Route reflector originator ID check. */
1862 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001863 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001864 {
1865 reason = "originator is us;";
1866 goto filtered;
1867 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001868
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001869 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00001870 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001871
1872 /* Apply export policy. */
1873 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1874 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1875 {
1876 reason = "export-policy;";
1877 goto filtered;
1878 }
1879
1880 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001881
paulfee0f4c2004-09-13 05:12:46 +00001882 /* Apply import policy. */
1883 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1884 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001885 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001886
1887 reason = "import-policy;";
1888 goto filtered;
1889 }
1890
1891 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001892 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001893
1894 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001895 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001896 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001897 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001898 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001899 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001900 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001901 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001902
1903 reason = "martian next-hop;";
1904 goto filtered;
1905 }
1906 }
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001907
paulfee0f4c2004-09-13 05:12:46 +00001908 /* If the update is implicit withdraw. */
1909 if (ri)
1910 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001911 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001912
1913 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001914 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1915 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001916 {
1917
Paul Jakma1a392d42006-09-07 00:24:49 +00001918 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001919
1920 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001921 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001922 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1923 peer->host,
1924 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1925 p->prefixlen, rsclient->host);
1926
Chris Caputo228da422009-07-18 05:44:03 +00001927 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001928 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001929
Chris Caputo228da422009-07-18 05:44:03 +00001930 return;
paulfee0f4c2004-09-13 05:12:46 +00001931 }
1932
Paul Jakma16d2e242007-04-10 19:32:10 +00001933 /* Withdraw/Announce before we fully processed the withdraw */
1934 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1935 bgp_info_restore (rn, ri);
1936
paulfee0f4c2004-09-13 05:12:46 +00001937 /* Received Logging. */
1938 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001939 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001940 peer->host,
1941 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1942 p->prefixlen, rsclient->host);
1943
1944 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001945 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001946
1947 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001948 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001949 ri->attr = attr_new;
1950
1951 /* Update MPLS tag. */
1952 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001953 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001954
Paul Jakma1a392d42006-09-07 00:24:49 +00001955 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001956
1957 /* Process change. */
1958 bgp_process (bgp, rn, afi, safi);
1959 bgp_unlock_node (rn);
1960
1961 return;
1962 }
1963
1964 /* Received Logging. */
1965 if (BGP_DEBUG (update, UPDATE_IN))
1966 {
ajsd2c1f162004-12-08 21:10:20 +00001967 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001968 peer->host,
1969 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1970 p->prefixlen, rsclient->host);
1971 }
1972
1973 /* Make new BGP info. */
1974 new = bgp_info_new ();
1975 new->type = type;
1976 new->sub_type = sub_type;
1977 new->peer = peer;
1978 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001979 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001980
1981 /* Update MPLS tag. */
1982 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001983 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001984
Paul Jakma1a392d42006-09-07 00:24:49 +00001985 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001986
1987 /* Register new BGP information. */
1988 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001989
1990 /* route_node_get lock */
1991 bgp_unlock_node (rn);
1992
paulfee0f4c2004-09-13 05:12:46 +00001993 /* Process change. */
1994 bgp_process (bgp, rn, afi, safi);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00001995
paulfee0f4c2004-09-13 05:12:46 +00001996 return;
1997
1998 filtered:
1999
2000 /* This BGP update is filtered. Log the reason then update BGP entry. */
2001 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002002 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002003 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2004 peer->host,
2005 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2006 p->prefixlen, rsclient->host, reason);
2007
2008 if (ri)
paulb40d9392005-08-22 22:34:41 +00002009 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002010
2011 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002012
paulfee0f4c2004-09-13 05:12:46 +00002013 return;
2014}
2015
paul94f2b392005-06-28 12:44:16 +00002016static void
paulfee0f4c2004-09-13 05:12:46 +00002017bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2018 struct peer *peer, struct prefix *p, int type, int sub_type,
2019 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002020{
paulfee0f4c2004-09-13 05:12:46 +00002021 struct bgp_node *rn;
2022 struct bgp_info *ri;
2023 char buf[SU_ADDRSTRLEN];
2024
2025 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002026 return;
paulfee0f4c2004-09-13 05:12:46 +00002027
2028 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2029
2030 /* Lookup withdrawn route. */
2031 for (ri = rn->info; ri; ri = ri->next)
2032 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2033 break;
2034
2035 /* Withdraw specified route from routing table. */
2036 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002037 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002038 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002039 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002040 "%s Can't find the route %s/%d", peer->host,
2041 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2042 p->prefixlen);
2043
2044 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002045 bgp_unlock_node (rn);
2046}
paulfee0f4c2004-09-13 05:12:46 +00002047
paul94f2b392005-06-28 12:44:16 +00002048static int
paulfee0f4c2004-09-13 05:12:46 +00002049bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002050 afi_t afi, safi_t safi, int type, int sub_type,
2051 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2052{
2053 int ret;
2054 int aspath_loop_count = 0;
2055 struct bgp_node *rn;
2056 struct bgp *bgp;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002057 struct attr new_attr;
2058 struct attr_extra new_extra;
paul718e3742002-12-13 20:15:29 +00002059 struct attr *attr_new;
2060 struct bgp_info *ri;
2061 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002062 const char *reason;
paul718e3742002-12-13 20:15:29 +00002063 char buf[SU_ADDRSTRLEN];
2064
2065 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002066 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002067
paul718e3742002-12-13 20:15:29 +00002068 /* When peer's soft reconfiguration enabled. Record input packet in
2069 Adj-RIBs-In. */
Jorge Boncompte [DTI2]343aa822012-05-07 16:53:08 +00002070 if (! soft_reconfig && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2071 && peer != bgp->peer_self)
paul718e3742002-12-13 20:15:29 +00002072 bgp_adj_in_set (rn, peer, attr);
2073
2074 /* Check previously received route. */
2075 for (ri = rn->info; ri; ri = ri->next)
2076 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2077 break;
2078
2079 /* AS path local-as loop check. */
2080 if (peer->change_local_as)
2081 {
2082 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2083 aspath_loop_count = 1;
2084
2085 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2086 {
2087 reason = "as-path contains our own AS;";
2088 goto filtered;
2089 }
2090 }
2091
2092 /* AS path loop check. */
2093 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2094 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2095 && aspath_loop_check(attr->aspath, bgp->confed_id)
2096 > peer->allowas_in[afi][safi]))
2097 {
2098 reason = "as-path contains our own AS;";
2099 goto filtered;
2100 }
2101
2102 /* Route reflector originator ID check. */
2103 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002104 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002105 {
2106 reason = "originator is us;";
2107 goto filtered;
2108 }
2109
2110 /* Route reflector cluster ID check. */
2111 if (bgp_cluster_filter (peer, attr))
2112 {
2113 reason = "reflected from the same cluster;";
2114 goto filtered;
2115 }
2116
2117 /* Apply incoming filter. */
2118 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2119 {
2120 reason = "filter;";
2121 goto filtered;
2122 }
2123
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002124 new_attr.extra = &new_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00002125 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002126
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002127 /* Apply incoming route-map. */
paul718e3742002-12-13 20:15:29 +00002128 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2129 {
2130 reason = "route-map;";
2131 goto filtered;
2132 }
2133
2134 /* IPv4 unicast next hop check. */
2135 if (afi == AFI_IP && safi == SAFI_UNICAST)
2136 {
2137 /* If the peer is EBGP and nexthop is not on connected route,
2138 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002139 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002140 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002141 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002142 {
2143 reason = "non-connected next-hop;";
2144 goto filtered;
2145 }
2146
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002147 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002148 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002149 if (new_attr.nexthop.s_addr == 0
2150 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2151 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002152 {
2153 reason = "martian next-hop;";
2154 goto filtered;
2155 }
2156 }
2157
2158 attr_new = bgp_attr_intern (&new_attr);
2159
2160 /* If the update is implicit withdraw. */
2161 if (ri)
2162 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002163 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002164
2165 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002166 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2167 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002168 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002169 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002170
2171 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002172 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002173 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2174 {
2175 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002176 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002177 peer->host,
2178 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2179 p->prefixlen);
2180
paul902212c2006-02-05 17:51:19 +00002181 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2182 {
2183 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2184 bgp_process (bgp, rn, afi, safi);
2185 }
paul718e3742002-12-13 20:15:29 +00002186 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002187 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002188 {
2189 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002190 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002191 "%s rcvd %s/%d...duplicate ignored",
2192 peer->host,
2193 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2194 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002195
2196 /* graceful restart STALE flag unset. */
2197 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2198 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002199 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002200 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002201 }
paul718e3742002-12-13 20:15:29 +00002202 }
2203
2204 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002205 bgp_attr_unintern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002206
paul718e3742002-12-13 20:15:29 +00002207 return 0;
2208 }
2209
Paul Jakma16d2e242007-04-10 19:32:10 +00002210 /* Withdraw/Announce before we fully processed the withdraw */
2211 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2212 {
2213 if (BGP_DEBUG (update, UPDATE_IN))
2214 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2215 peer->host,
2216 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2217 p->prefixlen);
2218 bgp_info_restore (rn, ri);
2219 }
2220
paul718e3742002-12-13 20:15:29 +00002221 /* Received Logging. */
2222 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002223 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002224 peer->host,
2225 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2226 p->prefixlen);
2227
hasso93406d82005-02-02 14:40:33 +00002228 /* graceful restart STALE flag unset. */
2229 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002230 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002231
paul718e3742002-12-13 20:15:29 +00002232 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002233 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002234
2235 /* implicit withdraw, decrement aggregate and pcount here.
2236 * only if update is accepted, they'll increment below.
2237 */
paul902212c2006-02-05 17:51:19 +00002238 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2239
paul718e3742002-12-13 20:15:29 +00002240 /* Update bgp route dampening information. */
2241 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002242 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002243 {
2244 /* This is implicit withdraw so we should update dampening
2245 information. */
2246 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2247 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002248 }
2249
paul718e3742002-12-13 20:15:29 +00002250 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002251 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002252 ri->attr = attr_new;
2253
2254 /* Update MPLS tag. */
2255 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002256 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002257
2258 /* Update bgp route dampening information. */
2259 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002260 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002261 {
2262 /* Now we do normal update dampening. */
2263 ret = bgp_damp_update (ri, rn, afi, safi);
2264 if (ret == BGP_DAMP_SUPPRESSED)
2265 {
2266 bgp_unlock_node (rn);
2267 return 0;
2268 }
2269 }
2270
2271 /* Nexthop reachability check. */
2272 if ((afi == AFI_IP || afi == AFI_IP6)
2273 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002274 && (peer->sort == BGP_PEER_IBGP
2275 || peer->sort == BGP_PEER_CONFED
2276 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002277 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002278 {
2279 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002280 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002281 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002282 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002283 }
2284 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002286
2287 /* Process change. */
2288 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2289
2290 bgp_process (bgp, rn, afi, safi);
2291 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002292
paul718e3742002-12-13 20:15:29 +00002293 return 0;
2294 }
2295
2296 /* Received Logging. */
2297 if (BGP_DEBUG (update, UPDATE_IN))
2298 {
ajsd2c1f162004-12-08 21:10:20 +00002299 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002300 peer->host,
2301 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2302 p->prefixlen);
2303 }
2304
paul718e3742002-12-13 20:15:29 +00002305 /* Make new BGP info. */
2306 new = bgp_info_new ();
2307 new->type = type;
2308 new->sub_type = sub_type;
2309 new->peer = peer;
2310 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002311 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002312
2313 /* Update MPLS tag. */
2314 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002315 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002316
2317 /* Nexthop reachability check. */
2318 if ((afi == AFI_IP || afi == AFI_IP6)
2319 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002320 && (peer->sort == BGP_PEER_IBGP
2321 || peer->sort == BGP_PEER_CONFED
2322 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002323 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002324 {
2325 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002326 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002327 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002328 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002329 }
2330 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002331 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002332
paul902212c2006-02-05 17:51:19 +00002333 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002334 bgp_aggregate_increment (bgp, p, new, afi, safi);
2335
2336 /* Register new BGP information. */
2337 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002338
2339 /* route_node_get lock */
2340 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002341
paul718e3742002-12-13 20:15:29 +00002342 /* If maximum prefix count is configured and current prefix
2343 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002344 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2345 return -1;
paul718e3742002-12-13 20:15:29 +00002346
2347 /* Process change. */
2348 bgp_process (bgp, rn, afi, safi);
2349
2350 return 0;
2351
2352 /* This BGP update is filtered. Log the reason then update BGP
2353 entry. */
2354 filtered:
2355 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002356 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002357 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2358 peer->host,
2359 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2360 p->prefixlen, reason);
2361
2362 if (ri)
paulb40d9392005-08-22 22:34:41 +00002363 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002364
2365 bgp_unlock_node (rn);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002366
paul718e3742002-12-13 20:15:29 +00002367 return 0;
2368}
2369
2370int
paulfee0f4c2004-09-13 05:12:46 +00002371bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2372 afi_t afi, safi_t safi, int type, int sub_type,
2373 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2374{
2375 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002376 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002377 struct bgp *bgp;
2378 int ret;
2379
2380 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2381 soft_reconfig);
2382
2383 bgp = peer->bgp;
2384
2385 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002386 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002387 {
2388 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2389 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2390 sub_type, prd, tag);
2391 }
2392
2393 return ret;
2394}
2395
2396int
paul718e3742002-12-13 20:15:29 +00002397bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002398 afi_t afi, safi_t safi, int type, int sub_type,
2399 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002400{
2401 struct bgp *bgp;
2402 char buf[SU_ADDRSTRLEN];
2403 struct bgp_node *rn;
2404 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002405 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002406 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002407
2408 bgp = peer->bgp;
2409
paulfee0f4c2004-09-13 05:12:46 +00002410 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002411 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002412 {
2413 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2414 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2415 }
2416
paul718e3742002-12-13 20:15:29 +00002417 /* Logging. */
2418 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002419 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002420 peer->host,
2421 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2422 p->prefixlen);
2423
2424 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002425 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002426
2427 /* If peer is soft reconfiguration enabled. Record input packet for
2428 further calculation. */
2429 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2430 && peer != bgp->peer_self)
2431 bgp_adj_in_unset (rn, peer);
2432
2433 /* Lookup withdrawn route. */
2434 for (ri = rn->info; ri; ri = ri->next)
2435 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2436 break;
2437
2438 /* Withdraw specified route from routing table. */
2439 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002440 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002441 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002442 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002443 "%s Can't find the route %s/%d", peer->host,
2444 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2445 p->prefixlen);
2446
2447 /* Unlock bgp_node_get() lock. */
2448 bgp_unlock_node (rn);
2449
2450 return 0;
2451}
2452
2453void
2454bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2455{
2456 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002457 struct attr attr;
Jorge Boncompte [DTI2]577ac572012-05-07 16:53:06 +00002458 struct aspath *aspath;
paul718e3742002-12-13 20:15:29 +00002459 struct prefix p;
2460 struct bgp_info binfo;
2461 struct peer *from;
2462 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002463
Paul Jakmab2497022007-06-14 11:17:58 +00002464 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002465 return;
2466
paul718e3742002-12-13 20:15:29 +00002467 bgp = peer->bgp;
2468 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002469
paul718e3742002-12-13 20:15:29 +00002470 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2471 aspath = attr.aspath;
2472 attr.local_pref = bgp->default_local_pref;
2473 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2474
2475 if (afi == AFI_IP)
2476 str2prefix ("0.0.0.0/0", &p);
2477#ifdef HAVE_IPV6
2478 else if (afi == AFI_IP6)
2479 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002480 struct attr_extra *ae = attr.extra;
2481
paul718e3742002-12-13 20:15:29 +00002482 str2prefix ("::/0", &p);
2483
2484 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002485 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002486 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002487 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002488
2489 /* If the peer is on shared nextwork and we have link-local
2490 nexthop set it. */
2491 if (peer->shared_network
2492 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2493 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002494 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002495 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002496 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002497 }
2498 }
2499#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002500
2501 if (peer->default_rmap[afi][safi].name)
2502 {
2503 binfo.peer = bgp->peer_self;
2504 binfo.attr = &attr;
2505
paulfee0f4c2004-09-13 05:12:46 +00002506 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2507
paul718e3742002-12-13 20:15:29 +00002508 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2509 RMAP_BGP, &binfo);
2510
paulfee0f4c2004-09-13 05:12:46 +00002511 bgp->peer_self->rmap_type = 0;
2512
paul718e3742002-12-13 20:15:29 +00002513 if (ret == RMAP_DENYMATCH)
2514 {
2515 bgp_attr_flush (&attr);
2516 withdraw = 1;
2517 }
2518 }
2519
2520 if (withdraw)
2521 {
2522 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2523 bgp_default_withdraw_send (peer, afi, safi);
2524 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2525 }
2526 else
2527 {
2528 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2529 bgp_default_update_send (peer, &attr, afi, safi, from);
2530 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002531
2532 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002533 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002534}
2535
2536static void
2537bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002538 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002539{
2540 struct bgp_node *rn;
2541 struct bgp_info *ri;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002542 struct attr attr;
2543 struct attr_extra extra;
2544
paul718e3742002-12-13 20:15:29 +00002545 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002546 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002547
2548 if (safi != SAFI_MPLS_VPN
2549 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2550 bgp_default_originate (peer, afi, safi, 0);
2551
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00002552 /* It's initialized in bgp_announce_[check|check_rsclient]() */
2553 attr.extra = &extra;
2554
paul718e3742002-12-13 20:15:29 +00002555 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2556 for (ri = rn->info; ri; ri = ri->next)
2557 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2558 {
paulfee0f4c2004-09-13 05:12:46 +00002559 if ( (rsclient) ?
2560 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2561 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002562 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2563 else
2564 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
2565 }
2566}
2567
2568void
2569bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2570{
2571 struct bgp_node *rn;
2572 struct bgp_table *table;
2573
2574 if (peer->status != Established)
2575 return;
2576
2577 if (! peer->afc_nego[afi][safi])
2578 return;
2579
2580 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2581 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2582 return;
2583
2584 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002585 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002586 else
2587 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2588 rn = bgp_route_next(rn))
2589 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002590 bgp_announce_table (peer, afi, safi, table, 0);
2591
2592 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2593 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002594}
2595
2596void
2597bgp_announce_route_all (struct peer *peer)
2598{
2599 afi_t afi;
2600 safi_t safi;
2601
2602 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2603 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2604 bgp_announce_route (peer, afi, safi);
2605}
2606
2607static void
paulfee0f4c2004-09-13 05:12:46 +00002608bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002609 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002610{
2611 struct bgp_node *rn;
2612 struct bgp_adj_in *ain;
2613
2614 if (! table)
2615 table = rsclient->bgp->rib[afi][safi];
2616
2617 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2618 for (ain = rn->adj_in; ain; ain = ain->next)
2619 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002620 struct bgp_info *ri = rn->info;
2621
paulfee0f4c2004-09-13 05:12:46 +00002622 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002623 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd,
2624 (bgp_info_extra_get (ri))->tag);
paulfee0f4c2004-09-13 05:12:46 +00002625 }
2626}
2627
2628void
2629bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2630{
2631 struct bgp_table *table;
2632 struct bgp_node *rn;
2633
2634 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002635 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002636
2637 else
2638 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2639 rn = bgp_route_next (rn))
2640 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002641 {
2642 struct prefix_rd prd;
2643 prd.family = AF_UNSPEC;
2644 prd.prefixlen = 64;
2645 memcpy(&prd.val, rn->p.u.val, 8);
2646
2647 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2648 }
paulfee0f4c2004-09-13 05:12:46 +00002649}
2650
2651static void
paul718e3742002-12-13 20:15:29 +00002652bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002653 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002654{
2655 int ret;
2656 struct bgp_node *rn;
2657 struct bgp_adj_in *ain;
2658
2659 if (! table)
2660 table = peer->bgp->rib[afi][safi];
2661
2662 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2663 for (ain = rn->adj_in; ain; ain = ain->next)
2664 {
2665 if (ain->peer == peer)
2666 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002667 struct bgp_info *ri = rn->info;
2668
paul718e3742002-12-13 20:15:29 +00002669 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2670 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002671 prd, (bgp_info_extra_get (ri))->tag, 1);
2672
paul718e3742002-12-13 20:15:29 +00002673 if (ret < 0)
2674 {
2675 bgp_unlock_node (rn);
2676 return;
2677 }
2678 continue;
2679 }
2680 }
2681}
2682
2683void
2684bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2685{
2686 struct bgp_node *rn;
2687 struct bgp_table *table;
2688
2689 if (peer->status != Established)
2690 return;
2691
2692 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002693 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002694 else
2695 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2696 rn = bgp_route_next (rn))
2697 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002698 {
2699 struct prefix_rd prd;
2700 prd.family = AF_UNSPEC;
2701 prd.prefixlen = 64;
2702 memcpy(&prd.val, rn->p.u.val, 8);
2703
2704 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2705 }
paul718e3742002-12-13 20:15:29 +00002706}
2707
Chris Caputo228da422009-07-18 05:44:03 +00002708
2709struct bgp_clear_node_queue
2710{
2711 struct bgp_node *rn;
2712 enum bgp_clear_route_type purpose;
2713};
2714
paul200df112005-06-01 11:17:05 +00002715static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002716bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002717{
Chris Caputo228da422009-07-18 05:44:03 +00002718 struct bgp_clear_node_queue *cnq = data;
2719 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002720 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002721 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002722 afi_t afi = rn->table->afi;
2723 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002724
Paul Jakma64e580a2006-02-21 01:09:01 +00002725 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002726
Paul Jakma64e580a2006-02-21 01:09:01 +00002727 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002728 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002729 {
2730 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002731 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2732 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002733 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002734 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2735 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002736 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002737 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002738 break;
2739 }
paul200df112005-06-01 11:17:05 +00002740 return WQ_SUCCESS;
2741}
2742
2743static void
paul0fb58d52005-11-14 14:31:49 +00002744bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002745{
Chris Caputo228da422009-07-18 05:44:03 +00002746 struct bgp_clear_node_queue *cnq = data;
2747 struct bgp_node *rn = cnq->rn;
2748 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002749
2750 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002751 bgp_table_unlock (table);
2752 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002753}
2754
2755static void
paul94f2b392005-06-28 12:44:16 +00002756bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002757{
Paul Jakma64e580a2006-02-21 01:09:01 +00002758 struct peer *peer = wq->spec.data;
2759
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002760 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002761 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002762
2763 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002764}
2765
2766static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002767bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002768{
Paul Jakmaa2943652009-07-21 14:02:04 +01002769 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002770
Paul Jakmaa2943652009-07-21 14:02:04 +01002771 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002772#undef CLEAR_QUEUE_NAME_LEN
2773
2774 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002775 {
2776 zlog_err ("%s: Failed to allocate work queue", __func__);
2777 exit (1);
2778 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002779 peer->clear_node_queue->spec.hold = 10;
2780 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2781 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2782 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2783 peer->clear_node_queue->spec.max_retries = 0;
2784
2785 /* we only 'lock' this peer reference when the queue is actually active */
2786 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002787}
2788
paul718e3742002-12-13 20:15:29 +00002789static void
2790bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002791 struct bgp_table *table, struct peer *rsclient,
2792 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002793{
2794 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002795
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002796
paul718e3742002-12-13 20:15:29 +00002797 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002798 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002799
hasso6cf159b2005-03-21 10:28:14 +00002800 /* If still no table => afi/safi isn't configured at all or smth. */
2801 if (! table)
2802 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002803
2804 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2805 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002806 struct bgp_info *ri;
2807 struct bgp_adj_in *ain;
2808 struct bgp_adj_out *aout;
2809
Paul Jakma65ca75e2006-05-04 08:08:15 +00002810 if (rn->info == NULL)
2811 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002812
2813 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2814 * queued for every clearing peer, regardless of whether it is
2815 * relevant to the peer at hand.
2816 *
2817 * Overview: There are 3 different indices which need to be
2818 * scrubbed, potentially, when a peer is removed:
2819 *
2820 * 1 peer's routes visible via the RIB (ie accepted routes)
2821 * 2 peer's routes visible by the (optional) peer's adj-in index
2822 * 3 other routes visible by the peer's adj-out index
2823 *
2824 * 3 there is no hurry in scrubbing, once the struct peer is
2825 * removed from bgp->peer, we could just GC such deleted peer's
2826 * adj-outs at our leisure.
2827 *
2828 * 1 and 2 must be 'scrubbed' in some way, at least made
2829 * invisible via RIB index before peer session is allowed to be
2830 * brought back up. So one needs to know when such a 'search' is
2831 * complete.
2832 *
2833 * Ideally:
2834 *
2835 * - there'd be a single global queue or a single RIB walker
2836 * - rather than tracking which route_nodes still need to be
2837 * examined on a peer basis, we'd track which peers still
2838 * aren't cleared
2839 *
2840 * Given that our per-peer prefix-counts now should be reliable,
2841 * this may actually be achievable. It doesn't seem to be a huge
2842 * problem at this time,
2843 */
2844 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002845 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002846 {
Chris Caputo228da422009-07-18 05:44:03 +00002847 struct bgp_clear_node_queue *cnq;
2848
2849 /* both unlocked in bgp_clear_node_queue_del */
2850 bgp_table_lock (rn->table);
2851 bgp_lock_node (rn);
2852 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2853 sizeof (struct bgp_clear_node_queue));
2854 cnq->rn = rn;
2855 cnq->purpose = purpose;
2856 work_queue_add (peer->clear_node_queue, cnq);
2857 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002858 }
2859
2860 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002861 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002862 {
2863 bgp_adj_in_remove (rn, ain);
2864 bgp_unlock_node (rn);
2865 break;
2866 }
2867 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002868 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002869 {
2870 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2871 bgp_unlock_node (rn);
2872 break;
2873 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002874 }
2875 return;
2876}
2877
2878void
Chris Caputo228da422009-07-18 05:44:03 +00002879bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2880 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002881{
2882 struct bgp_node *rn;
2883 struct bgp_table *table;
2884 struct peer *rsclient;
2885 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002886
Paul Jakma64e580a2006-02-21 01:09:01 +00002887 if (peer->clear_node_queue == NULL)
2888 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002889
Paul Jakmaca058a32006-09-14 02:58:49 +00002890 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2891 * Idle until it receives a Clearing_Completed event. This protects
2892 * against peers which flap faster than we can we clear, which could
2893 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002894 *
2895 * a) race with routes from the new session being installed before
2896 * clear_route_node visits the node (to delete the route of that
2897 * peer)
2898 * b) resource exhaustion, clear_route_node likely leads to an entry
2899 * on the process_main queue. Fast-flapping could cause that queue
2900 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002901 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002902 if (!peer->clear_node_queue->thread)
2903 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002904
Chris Caputo228da422009-07-18 05:44:03 +00002905 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002906 {
Chris Caputo228da422009-07-18 05:44:03 +00002907 case BGP_CLEAR_ROUTE_NORMAL:
2908 if (safi != SAFI_MPLS_VPN)
2909 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2910 else
2911 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2912 rn = bgp_route_next (rn))
2913 if ((table = rn->info) != NULL)
2914 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2915
2916 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2917 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2918 PEER_FLAG_RSERVER_CLIENT))
2919 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2920 break;
2921
2922 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2923 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2924 break;
2925
2926 default:
2927 assert (0);
2928 break;
paulfee0f4c2004-09-13 05:12:46 +00002929 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002930
Paul Jakmaca058a32006-09-14 02:58:49 +00002931 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002932 * completion function won't be run by workqueue code - call it here.
2933 * XXX: Actually, this assumption doesn't hold, see
2934 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002935 *
2936 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002937 * really needed if peer state is Established - peers in
2938 * pre-Established states shouldn't have any route-update state
2939 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002940 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002941 * We still can get here in pre-Established though, through
2942 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2943 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002944 *
2945 * At some future point, this check could be move to the top of the
2946 * function, and do a quick early-return when state is
2947 * pre-Established, avoiding above list and table scans. Once we're
2948 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002949 */
2950 if (!peer->clear_node_queue->thread)
2951 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002952}
2953
2954void
2955bgp_clear_route_all (struct peer *peer)
2956{
2957 afi_t afi;
2958 safi_t safi;
2959
2960 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2961 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002962 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002963}
2964
2965void
2966bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2967{
2968 struct bgp_table *table;
2969 struct bgp_node *rn;
2970 struct bgp_adj_in *ain;
2971
2972 table = peer->bgp->rib[afi][safi];
2973
2974 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2975 for (ain = rn->adj_in; ain ; ain = ain->next)
2976 if (ain->peer == peer)
2977 {
2978 bgp_adj_in_remove (rn, ain);
2979 bgp_unlock_node (rn);
2980 break;
2981 }
2982}
hasso93406d82005-02-02 14:40:33 +00002983
2984void
2985bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2986{
2987 struct bgp_node *rn;
2988 struct bgp_info *ri;
2989 struct bgp_table *table;
2990
2991 table = peer->bgp->rib[afi][safi];
2992
2993 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2994 {
2995 for (ri = rn->info; ri; ri = ri->next)
2996 if (ri->peer == peer)
2997 {
2998 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2999 bgp_rib_remove (rn, ri, peer, afi, safi);
3000 break;
3001 }
3002 }
3003}
paul718e3742002-12-13 20:15:29 +00003004
3005/* Delete all kernel routes. */
3006void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003007bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003008{
3009 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003010 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003011 struct bgp_node *rn;
3012 struct bgp_table *table;
3013 struct bgp_info *ri;
3014
paul1eb8ef22005-04-07 07:30:20 +00003015 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003016 {
3017 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3018
3019 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3020 for (ri = rn->info; ri; ri = ri->next)
3021 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3022 && ri->type == ZEBRA_ROUTE_BGP
3023 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003024 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003025
3026 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3027
3028 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3029 for (ri = rn->info; ri; ri = ri->next)
3030 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3031 && ri->type == ZEBRA_ROUTE_BGP
3032 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003033 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003034 }
3035}
3036
3037void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003038bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003039{
3040 vty_reset ();
3041 bgp_zclient_reset ();
3042 access_list_reset ();
3043 prefix_list_reset ();
3044}
3045
3046/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3047 value. */
3048int
3049bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3050{
3051 u_char *pnt;
3052 u_char *lim;
3053 struct prefix p;
3054 int psize;
3055 int ret;
3056
3057 /* Check peer status. */
3058 if (peer->status != Established)
3059 return 0;
3060
3061 pnt = packet->nlri;
3062 lim = pnt + packet->length;
3063
3064 for (; pnt < lim; pnt += psize)
3065 {
3066 /* Clear prefix structure. */
3067 memset (&p, 0, sizeof (struct prefix));
3068
3069 /* Fetch prefix length. */
3070 p.prefixlen = *pnt++;
3071 p.family = afi2family (packet->afi);
3072
3073 /* Already checked in nlri_sanity_check(). We do double check
3074 here. */
3075 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3076 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3077 return -1;
3078
3079 /* Packet size overflow check. */
3080 psize = PSIZE (p.prefixlen);
3081
3082 /* When packet overflow occur return immediately. */
3083 if (pnt + psize > lim)
3084 return -1;
3085
3086 /* Fetch prefix from NLRI packet. */
3087 memcpy (&p.u.prefix, pnt, psize);
3088
3089 /* Check address. */
3090 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3091 {
3092 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3093 {
paulf5ba3872004-07-09 12:11:31 +00003094 /*
3095 * From draft-ietf-idr-bgp4-22, Section 6.3:
3096 * If a BGP router receives an UPDATE message with a
3097 * semantically incorrect NLRI field, in which a prefix is
3098 * semantically incorrect (eg. an unexpected multicast IP
3099 * address), it should ignore the prefix.
3100 */
paul718e3742002-12-13 20:15:29 +00003101 zlog (peer->log, LOG_ERR,
3102 "IPv4 unicast NLRI is multicast address %s",
3103 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003104
paul718e3742002-12-13 20:15:29 +00003105 return -1;
3106 }
3107 }
3108
3109#ifdef HAVE_IPV6
3110 /* Check address. */
3111 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3112 {
3113 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3114 {
3115 char buf[BUFSIZ];
3116
3117 zlog (peer->log, LOG_WARNING,
3118 "IPv6 link-local NLRI received %s ignore this NLRI",
3119 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3120
3121 continue;
3122 }
3123 }
3124#endif /* HAVE_IPV6 */
3125
3126 /* Normal process. */
3127 if (attr)
3128 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3129 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3130 else
3131 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3132 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3133
3134 /* Address family configuration mismatch or maximum-prefix count
3135 overflow. */
3136 if (ret < 0)
3137 return -1;
3138 }
3139
3140 /* Packet length consistency check. */
3141 if (pnt != lim)
3142 return -1;
3143
3144 return 0;
3145}
3146
3147/* NLRI encode syntax check routine. */
3148int
3149bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3150 bgp_size_t length)
3151{
3152 u_char *end;
3153 u_char prefixlen;
3154 int psize;
3155
3156 end = pnt + length;
3157
3158 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3159 syntactic validity. If the field is syntactically incorrect,
3160 then the Error Subcode is set to Invalid Network Field. */
3161
3162 while (pnt < end)
3163 {
3164 prefixlen = *pnt++;
3165
3166 /* Prefix length check. */
3167 if ((afi == AFI_IP && prefixlen > 32)
3168 || (afi == AFI_IP6 && prefixlen > 128))
3169 {
3170 plog_err (peer->log,
3171 "%s [Error] Update packet error (wrong prefix length %d)",
3172 peer->host, prefixlen);
3173 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3174 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3175 return -1;
3176 }
3177
3178 /* Packet size overflow check. */
3179 psize = PSIZE (prefixlen);
3180
3181 if (pnt + psize > end)
3182 {
3183 plog_err (peer->log,
3184 "%s [Error] Update packet error"
3185 " (prefix data overflow prefix size is %d)",
3186 peer->host, psize);
3187 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3188 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3189 return -1;
3190 }
3191
3192 pnt += psize;
3193 }
3194
3195 /* Packet length consistency check. */
3196 if (pnt != end)
3197 {
3198 plog_err (peer->log,
3199 "%s [Error] Update packet error"
3200 " (prefix length mismatch with total length)",
3201 peer->host);
3202 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3203 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3204 return -1;
3205 }
3206 return 0;
3207}
3208
paul94f2b392005-06-28 12:44:16 +00003209static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003210bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003211{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003212 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003213}
3214
paul94f2b392005-06-28 12:44:16 +00003215static void
paul718e3742002-12-13 20:15:29 +00003216bgp_static_free (struct bgp_static *bgp_static)
3217{
3218 if (bgp_static->rmap.name)
3219 free (bgp_static->rmap.name);
3220 XFREE (MTYPE_BGP_STATIC, bgp_static);
3221}
3222
paul94f2b392005-06-28 12:44:16 +00003223static void
paulfee0f4c2004-09-13 05:12:46 +00003224bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3225 struct prefix *p, afi_t afi, safi_t safi)
3226{
3227 struct bgp_node *rn;
3228 struct bgp_info *ri;
3229
3230 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3231
3232 /* Check selected route and self inserted route. */
3233 for (ri = rn->info; ri; ri = ri->next)
3234 if (ri->peer == bgp->peer_self
3235 && ri->type == ZEBRA_ROUTE_BGP
3236 && ri->sub_type == BGP_ROUTE_STATIC)
3237 break;
3238
3239 /* Withdraw static BGP route from routing table. */
3240 if (ri)
3241 {
paulfee0f4c2004-09-13 05:12:46 +00003242 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003243 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003244 }
3245
3246 /* Unlock bgp_node_lookup. */
3247 bgp_unlock_node (rn);
3248}
3249
paul94f2b392005-06-28 12:44:16 +00003250static void
paulfee0f4c2004-09-13 05:12:46 +00003251bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003252 struct bgp_static *bgp_static,
3253 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003254{
3255 struct bgp_node *rn;
3256 struct bgp_info *ri;
3257 struct bgp_info *new;
3258 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003259 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003260 struct attr attr;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003261 struct attr new_attr;
3262 struct attr_extra new_extra;
paulfee0f4c2004-09-13 05:12:46 +00003263 struct bgp *bgp;
3264 int ret;
3265 char buf[SU_ADDRSTRLEN];
3266
3267 bgp = rsclient->bgp;
3268
Paul Jakma06e110f2006-05-12 23:29:22 +00003269 assert (bgp_static);
3270 if (!bgp_static)
3271 return;
3272
paulfee0f4c2004-09-13 05:12:46 +00003273 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3274
3275 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003276
3277 attr.nexthop = bgp_static->igpnexthop;
3278 attr.med = bgp_static->igpmetric;
3279 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003280
Paul Jakma41367172007-08-06 15:24:51 +00003281 if (bgp_static->atomic)
3282 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3283
paulfee0f4c2004-09-13 05:12:46 +00003284 /* Apply network route-map for export to this rsclient. */
3285 if (bgp_static->rmap.name)
3286 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003287 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003288 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003289 info.attr = &attr_tmp;
3290
paulfee0f4c2004-09-13 05:12:46 +00003291 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3292 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3293
3294 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3295
3296 rsclient->rmap_type = 0;
3297
3298 if (ret == RMAP_DENYMATCH)
3299 {
3300 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003301 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003302
3303 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003304 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003305 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003306 bgp_attr_extra_free (&attr);
3307
paulfee0f4c2004-09-13 05:12:46 +00003308 return;
3309 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003310 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003311 }
3312 else
3313 attr_new = bgp_attr_intern (&attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00003314
3315 new_attr.extra = &new_extra;
Stephen Hemminger7badc262010-08-05 10:26:31 -07003316 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003317
paulfee0f4c2004-09-13 05:12:46 +00003318 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3319
Paul Jakmafb982c22007-05-04 20:15:47 +00003320 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3321 == RMAP_DENY)
3322 {
paulfee0f4c2004-09-13 05:12:46 +00003323 /* This BGP update is filtered. Log the reason then update BGP entry. */
3324 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003325 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003326 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3327 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3328 p->prefixlen, rsclient->host);
3329
3330 bgp->peer_self->rmap_type = 0;
3331
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003332 bgp_attr_unintern (&attr_new);
3333 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003334 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003335
3336 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3337
3338 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003339 }
paulfee0f4c2004-09-13 05:12:46 +00003340
3341 bgp->peer_self->rmap_type = 0;
3342
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003343 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003344 attr_new = bgp_attr_intern (&new_attr);
3345
3346 for (ri = rn->info; ri; ri = ri->next)
3347 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3348 && ri->sub_type == BGP_ROUTE_STATIC)
3349 break;
3350
3351 if (ri)
3352 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003353 if (attrhash_cmp (ri->attr, attr_new) &&
3354 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003355 {
3356 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003357 bgp_attr_unintern (&attr_new);
3358 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003359 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003360 return;
3361 }
3362 else
3363 {
3364 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003365 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003366
3367 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003368 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3369 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003370 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003371 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003372 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003373
3374 /* Process change. */
3375 bgp_process (bgp, rn, afi, safi);
3376 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003377 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003378 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003379 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003380 }
paulfee0f4c2004-09-13 05:12:46 +00003381 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003382
paulfee0f4c2004-09-13 05:12:46 +00003383 /* Make new BGP info. */
3384 new = bgp_info_new ();
3385 new->type = ZEBRA_ROUTE_BGP;
3386 new->sub_type = BGP_ROUTE_STATIC;
3387 new->peer = bgp->peer_self;
3388 SET_FLAG (new->flags, BGP_INFO_VALID);
3389 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003390 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003391
3392 /* Register new BGP information. */
3393 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003394
3395 /* route_node_get lock */
3396 bgp_unlock_node (rn);
3397
paulfee0f4c2004-09-13 05:12:46 +00003398 /* Process change. */
3399 bgp_process (bgp, rn, afi, safi);
3400
3401 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003402 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003403 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003404}
3405
paul94f2b392005-06-28 12:44:16 +00003406static void
paulfee0f4c2004-09-13 05:12:46 +00003407bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003408 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3409{
3410 struct bgp_node *rn;
3411 struct bgp_info *ri;
3412 struct bgp_info *new;
3413 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003414 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003415 struct attr *attr_new;
3416 int ret;
3417
Paul Jakmadd8103a2006-05-12 23:27:30 +00003418 assert (bgp_static);
3419 if (!bgp_static)
3420 return;
3421
paulfee0f4c2004-09-13 05:12:46 +00003422 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003423
3424 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003425
3426 attr.nexthop = bgp_static->igpnexthop;
3427 attr.med = bgp_static->igpmetric;
3428 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003429
Paul Jakma41367172007-08-06 15:24:51 +00003430 if (bgp_static->atomic)
3431 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3432
paul718e3742002-12-13 20:15:29 +00003433 /* Apply route-map. */
3434 if (bgp_static->rmap.name)
3435 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003436 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003437 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003438 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003439
paulfee0f4c2004-09-13 05:12:46 +00003440 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3441
paul718e3742002-12-13 20:15:29 +00003442 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003443
paulfee0f4c2004-09-13 05:12:46 +00003444 bgp->peer_self->rmap_type = 0;
3445
paul718e3742002-12-13 20:15:29 +00003446 if (ret == RMAP_DENYMATCH)
3447 {
3448 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003449 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003450
3451 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003452 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003453 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003454 bgp_static_withdraw (bgp, p, afi, safi);
3455 return;
3456 }
paul286e1e72003-08-08 00:24:31 +00003457 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003458 }
paul286e1e72003-08-08 00:24:31 +00003459 else
3460 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003461
3462 for (ri = rn->info; ri; ri = ri->next)
3463 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3464 && ri->sub_type == BGP_ROUTE_STATIC)
3465 break;
3466
3467 if (ri)
3468 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003469 if (attrhash_cmp (ri->attr, attr_new) &&
3470 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003471 {
3472 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003473 bgp_attr_unintern (&attr_new);
3474 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003475 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003476 return;
3477 }
3478 else
3479 {
3480 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003481 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003482
3483 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003484 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3485 bgp_info_restore(rn, ri);
3486 else
3487 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003488 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003489 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003490 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003491
3492 /* Process change. */
3493 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3494 bgp_process (bgp, rn, afi, safi);
3495 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003496 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003497 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003498 return;
3499 }
3500 }
3501
3502 /* Make new BGP info. */
3503 new = bgp_info_new ();
3504 new->type = ZEBRA_ROUTE_BGP;
3505 new->sub_type = BGP_ROUTE_STATIC;
3506 new->peer = bgp->peer_self;
3507 SET_FLAG (new->flags, BGP_INFO_VALID);
3508 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003509 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003510
3511 /* Aggregate address increment. */
3512 bgp_aggregate_increment (bgp, p, new, afi, safi);
3513
3514 /* Register new BGP information. */
3515 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003516
3517 /* route_node_get lock */
3518 bgp_unlock_node (rn);
3519
paul718e3742002-12-13 20:15:29 +00003520 /* Process change. */
3521 bgp_process (bgp, rn, afi, safi);
3522
3523 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003524 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003525 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003526}
3527
3528void
paulfee0f4c2004-09-13 05:12:46 +00003529bgp_static_update (struct bgp *bgp, struct prefix *p,
3530 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3531{
3532 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003533 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003534
3535 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3536
paul1eb8ef22005-04-07 07:30:20 +00003537 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003538 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003539 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3540 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003541 }
3542}
3543
paul94f2b392005-06-28 12:44:16 +00003544static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003545bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3546 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003547{
3548 struct bgp_node *rn;
3549 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003550
paulfee0f4c2004-09-13 05:12:46 +00003551 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003552
3553 /* Make new BGP info. */
3554 new = bgp_info_new ();
3555 new->type = ZEBRA_ROUTE_BGP;
3556 new->sub_type = BGP_ROUTE_STATIC;
3557 new->peer = bgp->peer_self;
3558 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3559 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003560 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003561 new->extra = bgp_info_extra_new();
3562 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003563
3564 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003565 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003566
3567 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003568 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003569
paul200df112005-06-01 11:17:05 +00003570 /* route_node_get lock */
3571 bgp_unlock_node (rn);
3572
paul718e3742002-12-13 20:15:29 +00003573 /* Process change. */
3574 bgp_process (bgp, rn, afi, safi);
3575}
3576
3577void
3578bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3579 safi_t safi)
3580{
3581 struct bgp_node *rn;
3582 struct bgp_info *ri;
3583
paulfee0f4c2004-09-13 05:12:46 +00003584 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003585
3586 /* Check selected route and self inserted route. */
3587 for (ri = rn->info; ri; ri = ri->next)
3588 if (ri->peer == bgp->peer_self
3589 && ri->type == ZEBRA_ROUTE_BGP
3590 && ri->sub_type == BGP_ROUTE_STATIC)
3591 break;
3592
3593 /* Withdraw static BGP route from routing table. */
3594 if (ri)
3595 {
3596 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003597 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003598 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003599 }
3600
3601 /* Unlock bgp_node_lookup. */
3602 bgp_unlock_node (rn);
3603}
3604
3605void
paulfee0f4c2004-09-13 05:12:46 +00003606bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3607{
3608 struct bgp_static *bgp_static;
3609 struct bgp *bgp;
3610 struct bgp_node *rn;
3611 struct prefix *p;
3612
3613 bgp = rsclient->bgp;
3614
3615 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3616 if ((bgp_static = rn->info) != NULL)
3617 {
3618 p = &rn->p;
3619
3620 bgp_static_update_rsclient (rsclient, p, bgp_static,
3621 afi, safi);
3622 }
3623}
3624
paul94f2b392005-06-28 12:44:16 +00003625static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003626bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3627 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003628{
3629 struct bgp_node *rn;
3630 struct bgp_info *ri;
3631
paulfee0f4c2004-09-13 05:12:46 +00003632 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003633
3634 /* Check selected route and self inserted route. */
3635 for (ri = rn->info; ri; ri = ri->next)
3636 if (ri->peer == bgp->peer_self
3637 && ri->type == ZEBRA_ROUTE_BGP
3638 && ri->sub_type == BGP_ROUTE_STATIC)
3639 break;
3640
3641 /* Withdraw static BGP route from routing table. */
3642 if (ri)
3643 {
3644 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003645 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003646 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003647 }
3648
3649 /* Unlock bgp_node_lookup. */
3650 bgp_unlock_node (rn);
3651}
3652
3653/* Configure static BGP network. When user don't run zebra, static
3654 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003655static int
paulfd79ac92004-10-13 05:06:08 +00003656bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003657 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003658{
3659 int ret;
3660 struct prefix p;
3661 struct bgp_static *bgp_static;
3662 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003663 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003664
3665 /* Convert IP prefix string to struct prefix. */
3666 ret = str2prefix (ip_str, &p);
3667 if (! ret)
3668 {
3669 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3670 return CMD_WARNING;
3671 }
3672#ifdef HAVE_IPV6
3673 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3674 {
3675 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3676 VTY_NEWLINE);
3677 return CMD_WARNING;
3678 }
3679#endif /* HAVE_IPV6 */
3680
3681 apply_mask (&p);
3682
3683 /* Set BGP static route configuration. */
3684 rn = bgp_node_get (bgp->route[afi][safi], &p);
3685
3686 if (rn->info)
3687 {
3688 /* Configuration change. */
3689 bgp_static = rn->info;
3690
3691 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003692 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3693 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003694
paul718e3742002-12-13 20:15:29 +00003695 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003696
paul718e3742002-12-13 20:15:29 +00003697 if (rmap)
3698 {
3699 if (bgp_static->rmap.name)
3700 free (bgp_static->rmap.name);
3701 bgp_static->rmap.name = strdup (rmap);
3702 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3703 }
3704 else
3705 {
3706 if (bgp_static->rmap.name)
3707 free (bgp_static->rmap.name);
3708 bgp_static->rmap.name = NULL;
3709 bgp_static->rmap.map = NULL;
3710 bgp_static->valid = 0;
3711 }
3712 bgp_unlock_node (rn);
3713 }
3714 else
3715 {
3716 /* New configuration. */
3717 bgp_static = bgp_static_new ();
3718 bgp_static->backdoor = backdoor;
3719 bgp_static->valid = 0;
3720 bgp_static->igpmetric = 0;
3721 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003722
paul718e3742002-12-13 20:15:29 +00003723 if (rmap)
3724 {
3725 if (bgp_static->rmap.name)
3726 free (bgp_static->rmap.name);
3727 bgp_static->rmap.name = strdup (rmap);
3728 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3729 }
3730 rn->info = bgp_static;
3731 }
3732
3733 /* If BGP scan is not enabled, we should install this route here. */
3734 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3735 {
3736 bgp_static->valid = 1;
3737
3738 if (need_update)
3739 bgp_static_withdraw (bgp, &p, afi, safi);
3740
3741 if (! bgp_static->backdoor)
3742 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3743 }
3744
3745 return CMD_SUCCESS;
3746}
3747
3748/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003749static int
paulfd79ac92004-10-13 05:06:08 +00003750bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003751 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003752{
3753 int ret;
3754 struct prefix p;
3755 struct bgp_static *bgp_static;
3756 struct bgp_node *rn;
3757
3758 /* Convert IP prefix string to struct prefix. */
3759 ret = str2prefix (ip_str, &p);
3760 if (! ret)
3761 {
3762 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3763 return CMD_WARNING;
3764 }
3765#ifdef HAVE_IPV6
3766 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3767 {
3768 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3769 VTY_NEWLINE);
3770 return CMD_WARNING;
3771 }
3772#endif /* HAVE_IPV6 */
3773
3774 apply_mask (&p);
3775
3776 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3777 if (! rn)
3778 {
3779 vty_out (vty, "%% Can't find specified static route configuration.%s",
3780 VTY_NEWLINE);
3781 return CMD_WARNING;
3782 }
3783
3784 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003785
paul718e3742002-12-13 20:15:29 +00003786 /* Update BGP RIB. */
3787 if (! bgp_static->backdoor)
3788 bgp_static_withdraw (bgp, &p, afi, safi);
3789
3790 /* Clear configuration. */
3791 bgp_static_free (bgp_static);
3792 rn->info = NULL;
3793 bgp_unlock_node (rn);
3794 bgp_unlock_node (rn);
3795
3796 return CMD_SUCCESS;
3797}
3798
3799/* Called from bgp_delete(). Delete all static routes from the BGP
3800 instance. */
3801void
3802bgp_static_delete (struct bgp *bgp)
3803{
3804 afi_t afi;
3805 safi_t safi;
3806 struct bgp_node *rn;
3807 struct bgp_node *rm;
3808 struct bgp_table *table;
3809 struct bgp_static *bgp_static;
3810
3811 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3812 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3813 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3814 if (rn->info != NULL)
3815 {
3816 if (safi == SAFI_MPLS_VPN)
3817 {
3818 table = rn->info;
3819
3820 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3821 {
3822 bgp_static = rn->info;
3823 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3824 AFI_IP, SAFI_MPLS_VPN,
3825 (struct prefix_rd *)&rn->p,
3826 bgp_static->tag);
3827 bgp_static_free (bgp_static);
3828 rn->info = NULL;
3829 bgp_unlock_node (rn);
3830 }
3831 }
3832 else
3833 {
3834 bgp_static = rn->info;
3835 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3836 bgp_static_free (bgp_static);
3837 rn->info = NULL;
3838 bgp_unlock_node (rn);
3839 }
3840 }
3841}
3842
3843int
paulfd79ac92004-10-13 05:06:08 +00003844bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3845 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003846{
3847 int ret;
3848 struct prefix p;
3849 struct prefix_rd prd;
3850 struct bgp *bgp;
3851 struct bgp_node *prn;
3852 struct bgp_node *rn;
3853 struct bgp_table *table;
3854 struct bgp_static *bgp_static;
3855 u_char tag[3];
3856
3857 bgp = vty->index;
3858
3859 ret = str2prefix (ip_str, &p);
3860 if (! ret)
3861 {
3862 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3863 return CMD_WARNING;
3864 }
3865 apply_mask (&p);
3866
3867 ret = str2prefix_rd (rd_str, &prd);
3868 if (! ret)
3869 {
3870 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3871 return CMD_WARNING;
3872 }
3873
3874 ret = str2tag (tag_str, tag);
3875 if (! ret)
3876 {
3877 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3878 return CMD_WARNING;
3879 }
3880
3881 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3882 (struct prefix *)&prd);
3883 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003884 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003885 else
3886 bgp_unlock_node (prn);
3887 table = prn->info;
3888
3889 rn = bgp_node_get (table, &p);
3890
3891 if (rn->info)
3892 {
3893 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3894 bgp_unlock_node (rn);
3895 }
3896 else
3897 {
3898 /* New configuration. */
3899 bgp_static = bgp_static_new ();
3900 bgp_static->valid = 1;
3901 memcpy (bgp_static->tag, tag, 3);
3902 rn->info = bgp_static;
3903
3904 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3905 }
3906
3907 return CMD_SUCCESS;
3908}
3909
3910/* Configure static BGP network. */
3911int
paulfd79ac92004-10-13 05:06:08 +00003912bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3913 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003914{
3915 int ret;
3916 struct bgp *bgp;
3917 struct prefix p;
3918 struct prefix_rd prd;
3919 struct bgp_node *prn;
3920 struct bgp_node *rn;
3921 struct bgp_table *table;
3922 struct bgp_static *bgp_static;
3923 u_char tag[3];
3924
3925 bgp = vty->index;
3926
3927 /* Convert IP prefix string to struct prefix. */
3928 ret = str2prefix (ip_str, &p);
3929 if (! ret)
3930 {
3931 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3932 return CMD_WARNING;
3933 }
3934 apply_mask (&p);
3935
3936 ret = str2prefix_rd (rd_str, &prd);
3937 if (! ret)
3938 {
3939 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3940 return CMD_WARNING;
3941 }
3942
3943 ret = str2tag (tag_str, tag);
3944 if (! ret)
3945 {
3946 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3947 return CMD_WARNING;
3948 }
3949
3950 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3951 (struct prefix *)&prd);
3952 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003953 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003954 else
3955 bgp_unlock_node (prn);
3956 table = prn->info;
3957
3958 rn = bgp_node_lookup (table, &p);
3959
3960 if (rn)
3961 {
3962 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3963
3964 bgp_static = rn->info;
3965 bgp_static_free (bgp_static);
3966 rn->info = NULL;
3967 bgp_unlock_node (rn);
3968 bgp_unlock_node (rn);
3969 }
3970 else
3971 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3972
3973 return CMD_SUCCESS;
3974}
3975
3976DEFUN (bgp_network,
3977 bgp_network_cmd,
3978 "network A.B.C.D/M",
3979 "Specify a network to announce via BGP\n"
3980 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3981{
3982 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003983 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003984}
3985
3986DEFUN (bgp_network_route_map,
3987 bgp_network_route_map_cmd,
3988 "network A.B.C.D/M route-map WORD",
3989 "Specify a network to announce via BGP\n"
3990 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3991 "Route-map to modify the attributes\n"
3992 "Name of the route map\n")
3993{
3994 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003995 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003996}
3997
3998DEFUN (bgp_network_backdoor,
3999 bgp_network_backdoor_cmd,
4000 "network A.B.C.D/M backdoor",
4001 "Specify a network to announce via BGP\n"
4002 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4003 "Specify a BGP backdoor route\n")
4004{
Paul Jakma41367172007-08-06 15:24:51 +00004005 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004006 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004007}
4008
4009DEFUN (bgp_network_mask,
4010 bgp_network_mask_cmd,
4011 "network A.B.C.D mask A.B.C.D",
4012 "Specify a network to announce via BGP\n"
4013 "Network number\n"
4014 "Network mask\n"
4015 "Network mask\n")
4016{
4017 int ret;
4018 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004019
paul718e3742002-12-13 20:15:29 +00004020 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4021 if (! ret)
4022 {
4023 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4024 return CMD_WARNING;
4025 }
4026
4027 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004028 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004029}
4030
4031DEFUN (bgp_network_mask_route_map,
4032 bgp_network_mask_route_map_cmd,
4033 "network A.B.C.D mask A.B.C.D route-map WORD",
4034 "Specify a network to announce via BGP\n"
4035 "Network number\n"
4036 "Network mask\n"
4037 "Network mask\n"
4038 "Route-map to modify the attributes\n"
4039 "Name of the route map\n")
4040{
4041 int ret;
4042 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004043
paul718e3742002-12-13 20:15:29 +00004044 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4045 if (! ret)
4046 {
4047 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4048 return CMD_WARNING;
4049 }
4050
4051 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004052 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004053}
4054
4055DEFUN (bgp_network_mask_backdoor,
4056 bgp_network_mask_backdoor_cmd,
4057 "network A.B.C.D mask A.B.C.D backdoor",
4058 "Specify a network to announce via BGP\n"
4059 "Network number\n"
4060 "Network mask\n"
4061 "Network mask\n"
4062 "Specify a BGP backdoor route\n")
4063{
4064 int ret;
4065 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004066
paul718e3742002-12-13 20:15:29 +00004067 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4068 if (! ret)
4069 {
4070 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4071 return CMD_WARNING;
4072 }
4073
Paul Jakma41367172007-08-06 15:24:51 +00004074 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004075 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004076}
4077
4078DEFUN (bgp_network_mask_natural,
4079 bgp_network_mask_natural_cmd,
4080 "network A.B.C.D",
4081 "Specify a network to announce via BGP\n"
4082 "Network number\n")
4083{
4084 int ret;
4085 char prefix_str[BUFSIZ];
4086
4087 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4088 if (! ret)
4089 {
4090 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4091 return CMD_WARNING;
4092 }
4093
4094 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004095 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004096}
4097
4098DEFUN (bgp_network_mask_natural_route_map,
4099 bgp_network_mask_natural_route_map_cmd,
4100 "network A.B.C.D route-map WORD",
4101 "Specify a network to announce via BGP\n"
4102 "Network number\n"
4103 "Route-map to modify the attributes\n"
4104 "Name of the route map\n")
4105{
4106 int ret;
4107 char prefix_str[BUFSIZ];
4108
4109 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4110 if (! ret)
4111 {
4112 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4113 return CMD_WARNING;
4114 }
4115
4116 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004117 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004118}
4119
4120DEFUN (bgp_network_mask_natural_backdoor,
4121 bgp_network_mask_natural_backdoor_cmd,
4122 "network A.B.C.D backdoor",
4123 "Specify a network to announce via BGP\n"
4124 "Network number\n"
4125 "Specify a BGP backdoor route\n")
4126{
4127 int ret;
4128 char prefix_str[BUFSIZ];
4129
4130 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4131 if (! ret)
4132 {
4133 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4134 return CMD_WARNING;
4135 }
4136
Paul Jakma41367172007-08-06 15:24:51 +00004137 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004138 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004139}
4140
4141DEFUN (no_bgp_network,
4142 no_bgp_network_cmd,
4143 "no network A.B.C.D/M",
4144 NO_STR
4145 "Specify a network to announce via BGP\n"
4146 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4147{
4148 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4149 bgp_node_safi (vty));
4150}
4151
4152ALIAS (no_bgp_network,
4153 no_bgp_network_route_map_cmd,
4154 "no network A.B.C.D/M route-map WORD",
4155 NO_STR
4156 "Specify a network to announce via BGP\n"
4157 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4158 "Route-map to modify the attributes\n"
4159 "Name of the route map\n")
4160
4161ALIAS (no_bgp_network,
4162 no_bgp_network_backdoor_cmd,
4163 "no network A.B.C.D/M backdoor",
4164 NO_STR
4165 "Specify a network to announce via BGP\n"
4166 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4167 "Specify a BGP backdoor route\n")
4168
4169DEFUN (no_bgp_network_mask,
4170 no_bgp_network_mask_cmd,
4171 "no network A.B.C.D mask A.B.C.D",
4172 NO_STR
4173 "Specify a network to announce via BGP\n"
4174 "Network number\n"
4175 "Network mask\n"
4176 "Network mask\n")
4177{
4178 int ret;
4179 char prefix_str[BUFSIZ];
4180
4181 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4182 if (! ret)
4183 {
4184 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4185 return CMD_WARNING;
4186 }
4187
4188 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4189 bgp_node_safi (vty));
4190}
4191
4192ALIAS (no_bgp_network_mask,
4193 no_bgp_network_mask_route_map_cmd,
4194 "no network A.B.C.D mask A.B.C.D route-map WORD",
4195 NO_STR
4196 "Specify a network to announce via BGP\n"
4197 "Network number\n"
4198 "Network mask\n"
4199 "Network mask\n"
4200 "Route-map to modify the attributes\n"
4201 "Name of the route map\n")
4202
4203ALIAS (no_bgp_network_mask,
4204 no_bgp_network_mask_backdoor_cmd,
4205 "no network A.B.C.D mask A.B.C.D backdoor",
4206 NO_STR
4207 "Specify a network to announce via BGP\n"
4208 "Network number\n"
4209 "Network mask\n"
4210 "Network mask\n"
4211 "Specify a BGP backdoor route\n")
4212
4213DEFUN (no_bgp_network_mask_natural,
4214 no_bgp_network_mask_natural_cmd,
4215 "no network A.B.C.D",
4216 NO_STR
4217 "Specify a network to announce via BGP\n"
4218 "Network number\n")
4219{
4220 int ret;
4221 char prefix_str[BUFSIZ];
4222
4223 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4224 if (! ret)
4225 {
4226 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4227 return CMD_WARNING;
4228 }
4229
4230 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4231 bgp_node_safi (vty));
4232}
4233
4234ALIAS (no_bgp_network_mask_natural,
4235 no_bgp_network_mask_natural_route_map_cmd,
4236 "no network A.B.C.D route-map WORD",
4237 NO_STR
4238 "Specify a network to announce via BGP\n"
4239 "Network number\n"
4240 "Route-map to modify the attributes\n"
4241 "Name of the route map\n")
4242
4243ALIAS (no_bgp_network_mask_natural,
4244 no_bgp_network_mask_natural_backdoor_cmd,
4245 "no network A.B.C.D backdoor",
4246 NO_STR
4247 "Specify a network to announce via BGP\n"
4248 "Network number\n"
4249 "Specify a BGP backdoor route\n")
4250
4251#ifdef HAVE_IPV6
4252DEFUN (ipv6_bgp_network,
4253 ipv6_bgp_network_cmd,
4254 "network X:X::X:X/M",
4255 "Specify a network to announce via BGP\n"
4256 "IPv6 prefix <network>/<length>\n")
4257{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304258 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004259 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004260}
4261
4262DEFUN (ipv6_bgp_network_route_map,
4263 ipv6_bgp_network_route_map_cmd,
4264 "network X:X::X:X/M route-map WORD",
4265 "Specify a network to announce via BGP\n"
4266 "IPv6 prefix <network>/<length>\n"
4267 "Route-map to modify the attributes\n"
4268 "Name of the route map\n")
4269{
4270 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004271 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004272}
4273
4274DEFUN (no_ipv6_bgp_network,
4275 no_ipv6_bgp_network_cmd,
4276 "no network X:X::X:X/M",
4277 NO_STR
4278 "Specify a network to announce via BGP\n"
4279 "IPv6 prefix <network>/<length>\n")
4280{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304281 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004282}
4283
4284ALIAS (no_ipv6_bgp_network,
4285 no_ipv6_bgp_network_route_map_cmd,
4286 "no network X:X::X:X/M route-map WORD",
4287 NO_STR
4288 "Specify a network to announce via BGP\n"
4289 "IPv6 prefix <network>/<length>\n"
4290 "Route-map to modify the attributes\n"
4291 "Name of the route map\n")
4292
4293ALIAS (ipv6_bgp_network,
4294 old_ipv6_bgp_network_cmd,
4295 "ipv6 bgp network X:X::X:X/M",
4296 IPV6_STR
4297 BGP_STR
4298 "Specify a network to announce via BGP\n"
4299 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4300
4301ALIAS (no_ipv6_bgp_network,
4302 old_no_ipv6_bgp_network_cmd,
4303 "no ipv6 bgp network X:X::X:X/M",
4304 NO_STR
4305 IPV6_STR
4306 BGP_STR
4307 "Specify a network to announce via BGP\n"
4308 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4309#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004310
4311/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4312ALIAS_DEPRECATED (bgp_network,
4313 bgp_network_ttl_cmd,
4314 "network A.B.C.D/M pathlimit <0-255>",
4315 "Specify a network to announce via BGP\n"
4316 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4317 "AS-Path hopcount limit attribute\n"
4318 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4319ALIAS_DEPRECATED (bgp_network_backdoor,
4320 bgp_network_backdoor_ttl_cmd,
4321 "network A.B.C.D/M backdoor pathlimit <0-255>",
4322 "Specify a network to announce via BGP\n"
4323 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4324 "Specify a BGP backdoor route\n"
4325 "AS-Path hopcount limit attribute\n"
4326 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4327ALIAS_DEPRECATED (bgp_network_mask,
4328 bgp_network_mask_ttl_cmd,
4329 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4330 "Specify a network to announce via BGP\n"
4331 "Network number\n"
4332 "Network mask\n"
4333 "Network mask\n"
4334 "AS-Path hopcount limit attribute\n"
4335 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4336ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4337 bgp_network_mask_backdoor_ttl_cmd,
4338 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4339 "Specify a network to announce via BGP\n"
4340 "Network number\n"
4341 "Network mask\n"
4342 "Network mask\n"
4343 "Specify a BGP backdoor route\n"
4344 "AS-Path hopcount limit attribute\n"
4345 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4346ALIAS_DEPRECATED (bgp_network_mask_natural,
4347 bgp_network_mask_natural_ttl_cmd,
4348 "network A.B.C.D pathlimit <0-255>",
4349 "Specify a network to announce via BGP\n"
4350 "Network number\n"
4351 "AS-Path hopcount limit attribute\n"
4352 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4353ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4354 bgp_network_mask_natural_backdoor_ttl_cmd,
4355 "network A.B.C.D backdoor pathlimit (1-255>",
4356 "Specify a network to announce via BGP\n"
4357 "Network number\n"
4358 "Specify a BGP backdoor route\n"
4359 "AS-Path hopcount limit attribute\n"
4360 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4361ALIAS_DEPRECATED (no_bgp_network,
4362 no_bgp_network_ttl_cmd,
4363 "no network A.B.C.D/M pathlimit <0-255>",
4364 NO_STR
4365 "Specify a network to announce via BGP\n"
4366 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4367 "AS-Path hopcount limit attribute\n"
4368 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4369ALIAS_DEPRECATED (no_bgp_network,
4370 no_bgp_network_backdoor_ttl_cmd,
4371 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4372 NO_STR
4373 "Specify a network to announce via BGP\n"
4374 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4375 "Specify a BGP backdoor route\n"
4376 "AS-Path hopcount limit attribute\n"
4377 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4378ALIAS_DEPRECATED (no_bgp_network,
4379 no_bgp_network_mask_ttl_cmd,
4380 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4381 NO_STR
4382 "Specify a network to announce via BGP\n"
4383 "Network number\n"
4384 "Network mask\n"
4385 "Network mask\n"
4386 "AS-Path hopcount limit attribute\n"
4387 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4388ALIAS_DEPRECATED (no_bgp_network_mask,
4389 no_bgp_network_mask_backdoor_ttl_cmd,
4390 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4391 NO_STR
4392 "Specify a network to announce via BGP\n"
4393 "Network number\n"
4394 "Network mask\n"
4395 "Network mask\n"
4396 "Specify a BGP backdoor route\n"
4397 "AS-Path hopcount limit attribute\n"
4398 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4399ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4400 no_bgp_network_mask_natural_ttl_cmd,
4401 "no network A.B.C.D pathlimit <0-255>",
4402 NO_STR
4403 "Specify a network to announce via BGP\n"
4404 "Network number\n"
4405 "AS-Path hopcount limit attribute\n"
4406 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4407ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4408 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4409 "no network A.B.C.D backdoor pathlimit <0-255>",
4410 NO_STR
4411 "Specify a network to announce via BGP\n"
4412 "Network number\n"
4413 "Specify a BGP backdoor route\n"
4414 "AS-Path hopcount limit attribute\n"
4415 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004416#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004417ALIAS_DEPRECATED (ipv6_bgp_network,
4418 ipv6_bgp_network_ttl_cmd,
4419 "network X:X::X:X/M pathlimit <0-255>",
4420 "Specify a network to announce via BGP\n"
4421 "IPv6 prefix <network>/<length>\n"
4422 "AS-Path hopcount limit attribute\n"
4423 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4424ALIAS_DEPRECATED (no_ipv6_bgp_network,
4425 no_ipv6_bgp_network_ttl_cmd,
4426 "no network X:X::X:X/M pathlimit <0-255>",
4427 NO_STR
4428 "Specify a network to announce via BGP\n"
4429 "IPv6 prefix <network>/<length>\n"
4430 "AS-Path hopcount limit attribute\n"
4431 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004432#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004433
4434/* Aggreagete address:
4435
4436 advertise-map Set condition to advertise attribute
4437 as-set Generate AS set path information
4438 attribute-map Set attributes of aggregate
4439 route-map Set parameters of aggregate
4440 summary-only Filter more specific routes from updates
4441 suppress-map Conditionally filter more specific routes from updates
4442 <cr>
4443 */
4444struct bgp_aggregate
4445{
4446 /* Summary-only flag. */
4447 u_char summary_only;
4448
4449 /* AS set generation. */
4450 u_char as_set;
4451
4452 /* Route-map for aggregated route. */
4453 struct route_map *map;
4454
4455 /* Suppress-count. */
4456 unsigned long count;
4457
4458 /* SAFI configuration. */
4459 safi_t safi;
4460};
4461
paul94f2b392005-06-28 12:44:16 +00004462static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004463bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004464{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004465 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004466}
4467
paul94f2b392005-06-28 12:44:16 +00004468static void
paul718e3742002-12-13 20:15:29 +00004469bgp_aggregate_free (struct bgp_aggregate *aggregate)
4470{
4471 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4472}
4473
paul94f2b392005-06-28 12:44:16 +00004474static void
paul718e3742002-12-13 20:15:29 +00004475bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4476 afi_t afi, safi_t safi, struct bgp_info *del,
4477 struct bgp_aggregate *aggregate)
4478{
4479 struct bgp_table *table;
4480 struct bgp_node *top;
4481 struct bgp_node *rn;
4482 u_char origin;
4483 struct aspath *aspath = NULL;
4484 struct aspath *asmerge = NULL;
4485 struct community *community = NULL;
4486 struct community *commerge = NULL;
4487 struct in_addr nexthop;
4488 u_int32_t med = 0;
4489 struct bgp_info *ri;
4490 struct bgp_info *new;
4491 int first = 1;
4492 unsigned long match = 0;
4493
4494 /* Record adding route's nexthop and med. */
4495 if (rinew)
4496 {
4497 nexthop = rinew->attr->nexthop;
4498 med = rinew->attr->med;
4499 }
4500
4501 /* ORIGIN attribute: If at least one route among routes that are
4502 aggregated has ORIGIN with the value INCOMPLETE, then the
4503 aggregated route must have the ORIGIN attribute with the value
4504 INCOMPLETE. Otherwise, if at least one route among routes that
4505 are aggregated has ORIGIN with the value EGP, then the aggregated
4506 route must have the origin attribute with the value EGP. In all
4507 other case the value of the ORIGIN attribute of the aggregated
4508 route is INTERNAL. */
4509 origin = BGP_ORIGIN_IGP;
4510
4511 table = bgp->rib[afi][safi];
4512
4513 top = bgp_node_get (table, p);
4514 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4515 if (rn->p.prefixlen > p->prefixlen)
4516 {
4517 match = 0;
4518
4519 for (ri = rn->info; ri; ri = ri->next)
4520 {
4521 if (BGP_INFO_HOLDDOWN (ri))
4522 continue;
4523
4524 if (del && ri == del)
4525 continue;
4526
4527 if (! rinew && first)
4528 {
4529 nexthop = ri->attr->nexthop;
4530 med = ri->attr->med;
4531 first = 0;
4532 }
4533
4534#ifdef AGGREGATE_NEXTHOP_CHECK
4535 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4536 || ri->attr->med != med)
4537 {
4538 if (aspath)
4539 aspath_free (aspath);
4540 if (community)
4541 community_free (community);
4542 bgp_unlock_node (rn);
4543 bgp_unlock_node (top);
4544 return;
4545 }
4546#endif /* AGGREGATE_NEXTHOP_CHECK */
4547
4548 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4549 {
4550 if (aggregate->summary_only)
4551 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004552 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004553 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004554 match++;
4555 }
4556
4557 aggregate->count++;
4558
4559 if (aggregate->as_set)
4560 {
4561 if (origin < ri->attr->origin)
4562 origin = ri->attr->origin;
4563
4564 if (aspath)
4565 {
4566 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4567 aspath_free (aspath);
4568 aspath = asmerge;
4569 }
4570 else
4571 aspath = aspath_dup (ri->attr->aspath);
4572
4573 if (ri->attr->community)
4574 {
4575 if (community)
4576 {
4577 commerge = community_merge (community,
4578 ri->attr->community);
4579 community = community_uniq_sort (commerge);
4580 community_free (commerge);
4581 }
4582 else
4583 community = community_dup (ri->attr->community);
4584 }
4585 }
4586 }
4587 }
4588 if (match)
4589 bgp_process (bgp, rn, afi, safi);
4590 }
4591 bgp_unlock_node (top);
4592
4593 if (rinew)
4594 {
4595 aggregate->count++;
4596
4597 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004598 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004599
4600 if (aggregate->as_set)
4601 {
4602 if (origin < rinew->attr->origin)
4603 origin = rinew->attr->origin;
4604
4605 if (aspath)
4606 {
4607 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4608 aspath_free (aspath);
4609 aspath = asmerge;
4610 }
4611 else
4612 aspath = aspath_dup (rinew->attr->aspath);
4613
4614 if (rinew->attr->community)
4615 {
4616 if (community)
4617 {
4618 commerge = community_merge (community,
4619 rinew->attr->community);
4620 community = community_uniq_sort (commerge);
4621 community_free (commerge);
4622 }
4623 else
4624 community = community_dup (rinew->attr->community);
4625 }
4626 }
4627 }
4628
4629 if (aggregate->count > 0)
4630 {
4631 rn = bgp_node_get (table, p);
4632 new = bgp_info_new ();
4633 new->type = ZEBRA_ROUTE_BGP;
4634 new->sub_type = BGP_ROUTE_AGGREGATE;
4635 new->peer = bgp->peer_self;
4636 SET_FLAG (new->flags, BGP_INFO_VALID);
4637 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004638 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004639
4640 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004641 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004642 bgp_process (bgp, rn, afi, safi);
4643 }
4644 else
4645 {
4646 if (aspath)
4647 aspath_free (aspath);
4648 if (community)
4649 community_free (community);
4650 }
4651}
4652
4653void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4654 struct bgp_aggregate *);
4655
4656void
4657bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4658 struct bgp_info *ri, afi_t afi, safi_t safi)
4659{
4660 struct bgp_node *child;
4661 struct bgp_node *rn;
4662 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004663 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004664
4665 /* MPLS-VPN aggregation is not yet supported. */
4666 if (safi == SAFI_MPLS_VPN)
4667 return;
4668
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004669 table = bgp->aggregate[afi][safi];
4670
4671 /* No aggregates configured. */
4672 if (table->top == NULL)
4673 return;
4674
paul718e3742002-12-13 20:15:29 +00004675 if (p->prefixlen == 0)
4676 return;
4677
4678 if (BGP_INFO_HOLDDOWN (ri))
4679 return;
4680
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004681 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004682
4683 /* Aggregate address configuration check. */
4684 for (rn = child; rn; rn = rn->parent)
4685 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4686 {
4687 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004688 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004689 }
4690 bgp_unlock_node (child);
4691}
4692
4693void
4694bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4695 struct bgp_info *del, afi_t afi, safi_t safi)
4696{
4697 struct bgp_node *child;
4698 struct bgp_node *rn;
4699 struct bgp_aggregate *aggregate;
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004700 struct bgp_table *table;
paul718e3742002-12-13 20:15:29 +00004701
4702 /* MPLS-VPN aggregation is not yet supported. */
4703 if (safi == SAFI_MPLS_VPN)
4704 return;
4705
Jorge Boncompte [DTI2]f018db82012-05-07 16:53:10 +00004706 table = bgp->aggregate[afi][safi];
4707
4708 /* No aggregates configured. */
4709 if (table->top == NULL)
4710 return;
4711
paul718e3742002-12-13 20:15:29 +00004712 if (p->prefixlen == 0)
4713 return;
4714
Jorge Boncompte [DTI2]bb782fb2012-06-20 16:34:01 +02004715 child = bgp_node_get (table, p);
paul718e3742002-12-13 20:15:29 +00004716
4717 /* Aggregate address configuration check. */
4718 for (rn = child; rn; rn = rn->parent)
4719 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4720 {
4721 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004722 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004723 }
4724 bgp_unlock_node (child);
4725}
4726
paul94f2b392005-06-28 12:44:16 +00004727static void
paul718e3742002-12-13 20:15:29 +00004728bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4729 struct bgp_aggregate *aggregate)
4730{
4731 struct bgp_table *table;
4732 struct bgp_node *top;
4733 struct bgp_node *rn;
4734 struct bgp_info *new;
4735 struct bgp_info *ri;
4736 unsigned long match;
4737 u_char origin = BGP_ORIGIN_IGP;
4738 struct aspath *aspath = NULL;
4739 struct aspath *asmerge = NULL;
4740 struct community *community = NULL;
4741 struct community *commerge = NULL;
4742
4743 table = bgp->rib[afi][safi];
4744
4745 /* Sanity check. */
4746 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4747 return;
4748 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4749 return;
4750
4751 /* If routes exists below this node, generate aggregate routes. */
4752 top = bgp_node_get (table, p);
4753 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4754 if (rn->p.prefixlen > p->prefixlen)
4755 {
4756 match = 0;
4757
4758 for (ri = rn->info; ri; ri = ri->next)
4759 {
4760 if (BGP_INFO_HOLDDOWN (ri))
4761 continue;
4762
4763 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4764 {
4765 /* summary-only aggregate route suppress aggregated
4766 route announcement. */
4767 if (aggregate->summary_only)
4768 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004769 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004770 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004771 match++;
4772 }
4773 /* as-set aggregate route generate origin, as path,
4774 community aggregation. */
4775 if (aggregate->as_set)
4776 {
4777 if (origin < ri->attr->origin)
4778 origin = ri->attr->origin;
4779
4780 if (aspath)
4781 {
4782 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4783 aspath_free (aspath);
4784 aspath = asmerge;
4785 }
4786 else
4787 aspath = aspath_dup (ri->attr->aspath);
4788
4789 if (ri->attr->community)
4790 {
4791 if (community)
4792 {
4793 commerge = community_merge (community,
4794 ri->attr->community);
4795 community = community_uniq_sort (commerge);
4796 community_free (commerge);
4797 }
4798 else
4799 community = community_dup (ri->attr->community);
4800 }
4801 }
4802 aggregate->count++;
4803 }
4804 }
4805
4806 /* If this node is suppressed, process the change. */
4807 if (match)
4808 bgp_process (bgp, rn, afi, safi);
4809 }
4810 bgp_unlock_node (top);
4811
4812 /* Add aggregate route to BGP table. */
4813 if (aggregate->count)
4814 {
4815 rn = bgp_node_get (table, p);
4816
4817 new = bgp_info_new ();
4818 new->type = ZEBRA_ROUTE_BGP;
4819 new->sub_type = BGP_ROUTE_AGGREGATE;
4820 new->peer = bgp->peer_self;
4821 SET_FLAG (new->flags, BGP_INFO_VALID);
4822 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004823 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004824
4825 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004826 bgp_unlock_node (rn);
4827
paul718e3742002-12-13 20:15:29 +00004828 /* Process change. */
4829 bgp_process (bgp, rn, afi, safi);
4830 }
4831}
4832
4833void
4834bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4835 safi_t safi, struct bgp_aggregate *aggregate)
4836{
4837 struct bgp_table *table;
4838 struct bgp_node *top;
4839 struct bgp_node *rn;
4840 struct bgp_info *ri;
4841 unsigned long match;
4842
4843 table = bgp->rib[afi][safi];
4844
4845 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4846 return;
4847 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4848 return;
4849
4850 /* If routes exists below this node, generate aggregate routes. */
4851 top = bgp_node_get (table, p);
4852 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4853 if (rn->p.prefixlen > p->prefixlen)
4854 {
4855 match = 0;
4856
4857 for (ri = rn->info; ri; ri = ri->next)
4858 {
4859 if (BGP_INFO_HOLDDOWN (ri))
4860 continue;
4861
4862 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4863 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004864 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004865 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004866 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004867
Paul Jakmafb982c22007-05-04 20:15:47 +00004868 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004869 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004870 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004871 match++;
4872 }
4873 }
4874 aggregate->count--;
4875 }
4876 }
4877
Paul Jakmafb982c22007-05-04 20:15:47 +00004878 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004879 if (match)
4880 bgp_process (bgp, rn, afi, safi);
4881 }
4882 bgp_unlock_node (top);
4883
4884 /* Delete aggregate route from BGP table. */
4885 rn = bgp_node_get (table, p);
4886
4887 for (ri = rn->info; ri; ri = ri->next)
4888 if (ri->peer == bgp->peer_self
4889 && ri->type == ZEBRA_ROUTE_BGP
4890 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4891 break;
4892
4893 /* Withdraw static BGP route from routing table. */
4894 if (ri)
4895 {
paul718e3742002-12-13 20:15:29 +00004896 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004897 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004898 }
4899
4900 /* Unlock bgp_node_lookup. */
4901 bgp_unlock_node (rn);
4902}
4903
4904/* Aggregate route attribute. */
4905#define AGGREGATE_SUMMARY_ONLY 1
4906#define AGGREGATE_AS_SET 1
4907
paul94f2b392005-06-28 12:44:16 +00004908static int
Robert Baysf6269b42010-08-05 10:26:28 -07004909bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4910 afi_t afi, safi_t safi)
4911{
4912 int ret;
4913 struct prefix p;
4914 struct bgp_node *rn;
4915 struct bgp *bgp;
4916 struct bgp_aggregate *aggregate;
4917
4918 /* Convert string to prefix structure. */
4919 ret = str2prefix (prefix_str, &p);
4920 if (!ret)
4921 {
4922 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4923 return CMD_WARNING;
4924 }
4925 apply_mask (&p);
4926
4927 /* Get BGP structure. */
4928 bgp = vty->index;
4929
4930 /* Old configuration check. */
4931 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4932 if (! rn)
4933 {
4934 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4935 VTY_NEWLINE);
4936 return CMD_WARNING;
4937 }
4938
4939 aggregate = rn->info;
4940 if (aggregate->safi & SAFI_UNICAST)
4941 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4942 if (aggregate->safi & SAFI_MULTICAST)
4943 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4944
4945 /* Unlock aggregate address configuration. */
4946 rn->info = NULL;
4947 bgp_aggregate_free (aggregate);
4948 bgp_unlock_node (rn);
4949 bgp_unlock_node (rn);
4950
4951 return CMD_SUCCESS;
4952}
4953
4954static int
4955bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004956 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004957 u_char summary_only, u_char as_set)
4958{
4959 int ret;
4960 struct prefix p;
4961 struct bgp_node *rn;
4962 struct bgp *bgp;
4963 struct bgp_aggregate *aggregate;
4964
4965 /* Convert string to prefix structure. */
4966 ret = str2prefix (prefix_str, &p);
4967 if (!ret)
4968 {
4969 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4970 return CMD_WARNING;
4971 }
4972 apply_mask (&p);
4973
4974 /* Get BGP structure. */
4975 bgp = vty->index;
4976
4977 /* Old configuration check. */
4978 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4979
4980 if (rn->info)
4981 {
4982 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004983 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004984 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4985 if (ret)
4986 {
Robert Bays368473f2010-08-05 10:26:29 -07004987 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4988 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004989 return CMD_WARNING;
4990 }
paul718e3742002-12-13 20:15:29 +00004991 }
4992
4993 /* Make aggregate address structure. */
4994 aggregate = bgp_aggregate_new ();
4995 aggregate->summary_only = summary_only;
4996 aggregate->as_set = as_set;
4997 aggregate->safi = safi;
4998 rn->info = aggregate;
4999
5000 /* Aggregate address insert into BGP routing table. */
5001 if (safi & SAFI_UNICAST)
5002 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5003 if (safi & SAFI_MULTICAST)
5004 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5005
5006 return CMD_SUCCESS;
5007}
5008
paul718e3742002-12-13 20:15:29 +00005009DEFUN (aggregate_address,
5010 aggregate_address_cmd,
5011 "aggregate-address A.B.C.D/M",
5012 "Configure BGP aggregate entries\n"
5013 "Aggregate prefix\n")
5014{
5015 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5016}
5017
5018DEFUN (aggregate_address_mask,
5019 aggregate_address_mask_cmd,
5020 "aggregate-address A.B.C.D A.B.C.D",
5021 "Configure BGP aggregate entries\n"
5022 "Aggregate address\n"
5023 "Aggregate mask\n")
5024{
5025 int ret;
5026 char prefix_str[BUFSIZ];
5027
5028 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5029
5030 if (! ret)
5031 {
5032 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5033 return CMD_WARNING;
5034 }
5035
5036 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5037 0, 0);
5038}
5039
5040DEFUN (aggregate_address_summary_only,
5041 aggregate_address_summary_only_cmd,
5042 "aggregate-address A.B.C.D/M summary-only",
5043 "Configure BGP aggregate entries\n"
5044 "Aggregate prefix\n"
5045 "Filter more specific routes from updates\n")
5046{
5047 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5048 AGGREGATE_SUMMARY_ONLY, 0);
5049}
5050
5051DEFUN (aggregate_address_mask_summary_only,
5052 aggregate_address_mask_summary_only_cmd,
5053 "aggregate-address A.B.C.D A.B.C.D summary-only",
5054 "Configure BGP aggregate entries\n"
5055 "Aggregate address\n"
5056 "Aggregate mask\n"
5057 "Filter more specific routes from updates\n")
5058{
5059 int ret;
5060 char prefix_str[BUFSIZ];
5061
5062 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5063
5064 if (! ret)
5065 {
5066 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5067 return CMD_WARNING;
5068 }
5069
5070 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5071 AGGREGATE_SUMMARY_ONLY, 0);
5072}
5073
5074DEFUN (aggregate_address_as_set,
5075 aggregate_address_as_set_cmd,
5076 "aggregate-address A.B.C.D/M as-set",
5077 "Configure BGP aggregate entries\n"
5078 "Aggregate prefix\n"
5079 "Generate AS set path information\n")
5080{
5081 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5082 0, AGGREGATE_AS_SET);
5083}
5084
5085DEFUN (aggregate_address_mask_as_set,
5086 aggregate_address_mask_as_set_cmd,
5087 "aggregate-address A.B.C.D A.B.C.D as-set",
5088 "Configure BGP aggregate entries\n"
5089 "Aggregate address\n"
5090 "Aggregate mask\n"
5091 "Generate AS set path information\n")
5092{
5093 int ret;
5094 char prefix_str[BUFSIZ];
5095
5096 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5097
5098 if (! ret)
5099 {
5100 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5101 return CMD_WARNING;
5102 }
5103
5104 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5105 0, AGGREGATE_AS_SET);
5106}
5107
5108
5109DEFUN (aggregate_address_as_set_summary,
5110 aggregate_address_as_set_summary_cmd,
5111 "aggregate-address A.B.C.D/M as-set summary-only",
5112 "Configure BGP aggregate entries\n"
5113 "Aggregate prefix\n"
5114 "Generate AS set path information\n"
5115 "Filter more specific routes from updates\n")
5116{
5117 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5118 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5119}
5120
5121ALIAS (aggregate_address_as_set_summary,
5122 aggregate_address_summary_as_set_cmd,
5123 "aggregate-address A.B.C.D/M summary-only as-set",
5124 "Configure BGP aggregate entries\n"
5125 "Aggregate prefix\n"
5126 "Filter more specific routes from updates\n"
5127 "Generate AS set path information\n")
5128
5129DEFUN (aggregate_address_mask_as_set_summary,
5130 aggregate_address_mask_as_set_summary_cmd,
5131 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5132 "Configure BGP aggregate entries\n"
5133 "Aggregate address\n"
5134 "Aggregate mask\n"
5135 "Generate AS set path information\n"
5136 "Filter more specific routes from updates\n")
5137{
5138 int ret;
5139 char prefix_str[BUFSIZ];
5140
5141 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5142
5143 if (! ret)
5144 {
5145 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5146 return CMD_WARNING;
5147 }
5148
5149 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5150 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5151}
5152
5153ALIAS (aggregate_address_mask_as_set_summary,
5154 aggregate_address_mask_summary_as_set_cmd,
5155 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5156 "Configure BGP aggregate entries\n"
5157 "Aggregate address\n"
5158 "Aggregate mask\n"
5159 "Filter more specific routes from updates\n"
5160 "Generate AS set path information\n")
5161
5162DEFUN (no_aggregate_address,
5163 no_aggregate_address_cmd,
5164 "no aggregate-address A.B.C.D/M",
5165 NO_STR
5166 "Configure BGP aggregate entries\n"
5167 "Aggregate prefix\n")
5168{
5169 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5170}
5171
5172ALIAS (no_aggregate_address,
5173 no_aggregate_address_summary_only_cmd,
5174 "no aggregate-address A.B.C.D/M summary-only",
5175 NO_STR
5176 "Configure BGP aggregate entries\n"
5177 "Aggregate prefix\n"
5178 "Filter more specific routes from updates\n")
5179
5180ALIAS (no_aggregate_address,
5181 no_aggregate_address_as_set_cmd,
5182 "no aggregate-address A.B.C.D/M as-set",
5183 NO_STR
5184 "Configure BGP aggregate entries\n"
5185 "Aggregate prefix\n"
5186 "Generate AS set path information\n")
5187
5188ALIAS (no_aggregate_address,
5189 no_aggregate_address_as_set_summary_cmd,
5190 "no aggregate-address A.B.C.D/M as-set summary-only",
5191 NO_STR
5192 "Configure BGP aggregate entries\n"
5193 "Aggregate prefix\n"
5194 "Generate AS set path information\n"
5195 "Filter more specific routes from updates\n")
5196
5197ALIAS (no_aggregate_address,
5198 no_aggregate_address_summary_as_set_cmd,
5199 "no aggregate-address A.B.C.D/M summary-only as-set",
5200 NO_STR
5201 "Configure BGP aggregate entries\n"
5202 "Aggregate prefix\n"
5203 "Filter more specific routes from updates\n"
5204 "Generate AS set path information\n")
5205
5206DEFUN (no_aggregate_address_mask,
5207 no_aggregate_address_mask_cmd,
5208 "no aggregate-address A.B.C.D A.B.C.D",
5209 NO_STR
5210 "Configure BGP aggregate entries\n"
5211 "Aggregate address\n"
5212 "Aggregate mask\n")
5213{
5214 int ret;
5215 char prefix_str[BUFSIZ];
5216
5217 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5218
5219 if (! ret)
5220 {
5221 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5222 return CMD_WARNING;
5223 }
5224
5225 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5226}
5227
5228ALIAS (no_aggregate_address_mask,
5229 no_aggregate_address_mask_summary_only_cmd,
5230 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5231 NO_STR
5232 "Configure BGP aggregate entries\n"
5233 "Aggregate address\n"
5234 "Aggregate mask\n"
5235 "Filter more specific routes from updates\n")
5236
5237ALIAS (no_aggregate_address_mask,
5238 no_aggregate_address_mask_as_set_cmd,
5239 "no aggregate-address A.B.C.D A.B.C.D as-set",
5240 NO_STR
5241 "Configure BGP aggregate entries\n"
5242 "Aggregate address\n"
5243 "Aggregate mask\n"
5244 "Generate AS set path information\n")
5245
5246ALIAS (no_aggregate_address_mask,
5247 no_aggregate_address_mask_as_set_summary_cmd,
5248 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5249 NO_STR
5250 "Configure BGP aggregate entries\n"
5251 "Aggregate address\n"
5252 "Aggregate mask\n"
5253 "Generate AS set path information\n"
5254 "Filter more specific routes from updates\n")
5255
5256ALIAS (no_aggregate_address_mask,
5257 no_aggregate_address_mask_summary_as_set_cmd,
5258 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5259 NO_STR
5260 "Configure BGP aggregate entries\n"
5261 "Aggregate address\n"
5262 "Aggregate mask\n"
5263 "Filter more specific routes from updates\n"
5264 "Generate AS set path information\n")
5265
5266#ifdef HAVE_IPV6
5267DEFUN (ipv6_aggregate_address,
5268 ipv6_aggregate_address_cmd,
5269 "aggregate-address X:X::X:X/M",
5270 "Configure BGP aggregate entries\n"
5271 "Aggregate prefix\n")
5272{
5273 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5274}
5275
5276DEFUN (ipv6_aggregate_address_summary_only,
5277 ipv6_aggregate_address_summary_only_cmd,
5278 "aggregate-address X:X::X:X/M summary-only",
5279 "Configure BGP aggregate entries\n"
5280 "Aggregate prefix\n"
5281 "Filter more specific routes from updates\n")
5282{
5283 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5284 AGGREGATE_SUMMARY_ONLY, 0);
5285}
5286
5287DEFUN (no_ipv6_aggregate_address,
5288 no_ipv6_aggregate_address_cmd,
5289 "no aggregate-address X:X::X:X/M",
5290 NO_STR
5291 "Configure BGP aggregate entries\n"
5292 "Aggregate prefix\n")
5293{
5294 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5295}
5296
5297DEFUN (no_ipv6_aggregate_address_summary_only,
5298 no_ipv6_aggregate_address_summary_only_cmd,
5299 "no aggregate-address X:X::X:X/M summary-only",
5300 NO_STR
5301 "Configure BGP aggregate entries\n"
5302 "Aggregate prefix\n"
5303 "Filter more specific routes from updates\n")
5304{
5305 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5306}
5307
5308ALIAS (ipv6_aggregate_address,
5309 old_ipv6_aggregate_address_cmd,
5310 "ipv6 bgp aggregate-address X:X::X:X/M",
5311 IPV6_STR
5312 BGP_STR
5313 "Configure BGP aggregate entries\n"
5314 "Aggregate prefix\n")
5315
5316ALIAS (ipv6_aggregate_address_summary_only,
5317 old_ipv6_aggregate_address_summary_only_cmd,
5318 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5319 IPV6_STR
5320 BGP_STR
5321 "Configure BGP aggregate entries\n"
5322 "Aggregate prefix\n"
5323 "Filter more specific routes from updates\n")
5324
5325ALIAS (no_ipv6_aggregate_address,
5326 old_no_ipv6_aggregate_address_cmd,
5327 "no ipv6 bgp aggregate-address X:X::X:X/M",
5328 NO_STR
5329 IPV6_STR
5330 BGP_STR
5331 "Configure BGP aggregate entries\n"
5332 "Aggregate prefix\n")
5333
5334ALIAS (no_ipv6_aggregate_address_summary_only,
5335 old_no_ipv6_aggregate_address_summary_only_cmd,
5336 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5337 NO_STR
5338 IPV6_STR
5339 BGP_STR
5340 "Configure BGP aggregate entries\n"
5341 "Aggregate prefix\n"
5342 "Filter more specific routes from updates\n")
5343#endif /* HAVE_IPV6 */
5344
5345/* Redistribute route treatment. */
5346void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005347bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5348 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005349 u_int32_t metric, u_char type)
5350{
5351 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005352 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005353 struct bgp_info *new;
5354 struct bgp_info *bi;
5355 struct bgp_info info;
5356 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005357 struct attr attr;
paul718e3742002-12-13 20:15:29 +00005358 struct attr *new_attr;
5359 afi_t afi;
5360 int ret;
5361
5362 /* Make default attribute. */
5363 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5364 if (nexthop)
5365 attr.nexthop = *nexthop;
5366
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005367#ifdef HAVE_IPV6
5368 if (nexthop6)
5369 {
5370 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5371 extra->mp_nexthop_global = *nexthop6;
5372 extra->mp_nexthop_len = 16;
5373 }
5374#endif
5375
paul718e3742002-12-13 20:15:29 +00005376 attr.med = metric;
5377 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5378
paul1eb8ef22005-04-07 07:30:20 +00005379 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005380 {
5381 afi = family2afi (p->family);
5382
5383 if (bgp->redist[afi][type])
5384 {
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005385 struct attr attr_new;
5386 struct attr_extra extra_new;
5387
paul718e3742002-12-13 20:15:29 +00005388 /* Copy attribute for modification. */
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005389 attr_new.extra = &extra_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00005390 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005391
5392 if (bgp->redist_metric_flag[afi][type])
5393 attr_new.med = bgp->redist_metric[afi][type];
5394
5395 /* Apply route-map. */
5396 if (bgp->rmap[afi][type].map)
5397 {
5398 info.peer = bgp->peer_self;
5399 info.attr = &attr_new;
5400
paulfee0f4c2004-09-13 05:12:46 +00005401 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5402
paul718e3742002-12-13 20:15:29 +00005403 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5404 &info);
paulfee0f4c2004-09-13 05:12:46 +00005405
5406 bgp->peer_self->rmap_type = 0;
5407
paul718e3742002-12-13 20:15:29 +00005408 if (ret == RMAP_DENYMATCH)
5409 {
5410 /* Free uninterned attribute. */
5411 bgp_attr_flush (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005412
paul718e3742002-12-13 20:15:29 +00005413 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005414 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005415 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005416 bgp_redistribute_delete (p, type);
5417 return;
5418 }
5419 }
5420
Paul Jakmafb982c22007-05-04 20:15:47 +00005421 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5422 afi, SAFI_UNICAST, p, NULL);
5423
paul718e3742002-12-13 20:15:29 +00005424 new_attr = bgp_attr_intern (&attr_new);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00005425
paul718e3742002-12-13 20:15:29 +00005426 for (bi = bn->info; bi; bi = bi->next)
5427 if (bi->peer == bgp->peer_self
5428 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5429 break;
5430
5431 if (bi)
5432 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005433 if (attrhash_cmp (bi->attr, new_attr) &&
5434 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005435 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005436 bgp_attr_unintern (&new_attr);
5437 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005438 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005439 bgp_unlock_node (bn);
5440 return;
5441 }
5442 else
5443 {
5444 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005445 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005446
5447 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005448 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5449 bgp_info_restore(bn, bi);
5450 else
5451 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005452 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005453 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005454 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005455
5456 /* Process change. */
5457 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5458 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5459 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005460 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005461 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005462 return;
5463 }
5464 }
5465
5466 new = bgp_info_new ();
5467 new->type = type;
5468 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5469 new->peer = bgp->peer_self;
5470 SET_FLAG (new->flags, BGP_INFO_VALID);
5471 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005472 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005473
5474 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5475 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005476 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005477 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5478 }
5479 }
5480
5481 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005482 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005483 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005484}
5485
5486void
5487bgp_redistribute_delete (struct prefix *p, u_char type)
5488{
5489 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005490 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005491 afi_t afi;
5492 struct bgp_node *rn;
5493 struct bgp_info *ri;
5494
paul1eb8ef22005-04-07 07:30:20 +00005495 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005496 {
5497 afi = family2afi (p->family);
5498
5499 if (bgp->redist[afi][type])
5500 {
paulfee0f4c2004-09-13 05:12:46 +00005501 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005502
5503 for (ri = rn->info; ri; ri = ri->next)
5504 if (ri->peer == bgp->peer_self
5505 && ri->type == type)
5506 break;
5507
5508 if (ri)
5509 {
5510 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005511 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005512 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005513 }
5514 bgp_unlock_node (rn);
5515 }
5516 }
5517}
5518
5519/* Withdraw specified route type's route. */
5520void
5521bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5522{
5523 struct bgp_node *rn;
5524 struct bgp_info *ri;
5525 struct bgp_table *table;
5526
5527 table = bgp->rib[afi][SAFI_UNICAST];
5528
5529 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5530 {
5531 for (ri = rn->info; ri; ri = ri->next)
5532 if (ri->peer == bgp->peer_self
5533 && ri->type == type)
5534 break;
5535
5536 if (ri)
5537 {
5538 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005539 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005540 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005541 }
5542 }
5543}
5544
5545/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005546static void
paul718e3742002-12-13 20:15:29 +00005547route_vty_out_route (struct prefix *p, struct vty *vty)
5548{
5549 int len;
5550 u_int32_t destination;
5551 char buf[BUFSIZ];
5552
5553 if (p->family == AF_INET)
5554 {
5555 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5556 destination = ntohl (p->u.prefix4.s_addr);
5557
5558 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5559 || (IN_CLASSB (destination) && p->prefixlen == 16)
5560 || (IN_CLASSA (destination) && p->prefixlen == 8)
5561 || p->u.prefix4.s_addr == 0)
5562 {
5563 /* When mask is natural, mask is not displayed. */
5564 }
5565 else
5566 len += vty_out (vty, "/%d", p->prefixlen);
5567 }
5568 else
5569 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5570 p->prefixlen);
5571
5572 len = 17 - len;
5573 if (len < 1)
5574 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5575 else
5576 vty_out (vty, "%*s", len, " ");
5577}
5578
paul718e3742002-12-13 20:15:29 +00005579enum bgp_display_type
5580{
5581 normal_list,
5582};
5583
paulb40d9392005-08-22 22:34:41 +00005584/* Print the short form route status for a bgp_info */
5585static void
5586route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005587{
paulb40d9392005-08-22 22:34:41 +00005588 /* Route status display. */
5589 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5590 vty_out (vty, "R");
5591 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005592 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005593 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005594 vty_out (vty, "s");
5595 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5596 vty_out (vty, "*");
5597 else
5598 vty_out (vty, " ");
5599
5600 /* Selected */
5601 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5602 vty_out (vty, "h");
5603 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5604 vty_out (vty, "d");
5605 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5606 vty_out (vty, ">");
5607 else
5608 vty_out (vty, " ");
5609
5610 /* Internal route. */
5611 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5612 vty_out (vty, "i");
5613 else
paulb40d9392005-08-22 22:34:41 +00005614 vty_out (vty, " ");
5615}
5616
5617/* called from terminal list command */
5618void
5619route_vty_out (struct vty *vty, struct prefix *p,
5620 struct bgp_info *binfo, int display, safi_t safi)
5621{
5622 struct attr *attr;
5623
5624 /* short status lead text */
5625 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005626
5627 /* print prefix and mask */
5628 if (! display)
5629 route_vty_out_route (p, vty);
5630 else
5631 vty_out (vty, "%*s", 17, " ");
5632
5633 /* Print attribute */
5634 attr = binfo->attr;
5635 if (attr)
5636 {
5637 if (p->family == AF_INET)
5638 {
5639 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005640 vty_out (vty, "%-16s",
5641 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005642 else
5643 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5644 }
5645#ifdef HAVE_IPV6
5646 else if (p->family == AF_INET6)
5647 {
5648 int len;
5649 char buf[BUFSIZ];
5650
5651 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005652 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5653 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005654 len = 16 - len;
5655 if (len < 1)
5656 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5657 else
5658 vty_out (vty, "%*s", len, " ");
5659 }
5660#endif /* HAVE_IPV6 */
5661
5662 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005663 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005664 else
5665 vty_out (vty, " ");
5666
5667 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005668 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005669 else
5670 vty_out (vty, " ");
5671
Paul Jakmafb982c22007-05-04 20:15:47 +00005672 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005673
Paul Jakmab2518c12006-05-12 23:48:40 +00005674 /* Print aspath */
5675 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005676 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005677
Paul Jakmab2518c12006-05-12 23:48:40 +00005678 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005679 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005680 }
paul718e3742002-12-13 20:15:29 +00005681 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005682}
5683
5684/* called from terminal list command */
5685void
5686route_vty_out_tmp (struct vty *vty, struct prefix *p,
5687 struct attr *attr, safi_t safi)
5688{
5689 /* Route status display. */
5690 vty_out (vty, "*");
5691 vty_out (vty, ">");
5692 vty_out (vty, " ");
5693
5694 /* print prefix and mask */
5695 route_vty_out_route (p, vty);
5696
5697 /* Print attribute */
5698 if (attr)
5699 {
5700 if (p->family == AF_INET)
5701 {
5702 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005703 vty_out (vty, "%-16s",
5704 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005705 else
5706 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5707 }
5708#ifdef HAVE_IPV6
5709 else if (p->family == AF_INET6)
5710 {
5711 int len;
5712 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005713
5714 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005715
5716 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005717 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5718 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005719 len = 16 - len;
5720 if (len < 1)
5721 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5722 else
5723 vty_out (vty, "%*s", len, " ");
5724 }
5725#endif /* HAVE_IPV6 */
5726
5727 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005728 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005729 else
5730 vty_out (vty, " ");
5731
5732 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005733 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005734 else
5735 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005736
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005737 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005738
Paul Jakmab2518c12006-05-12 23:48:40 +00005739 /* Print aspath */
5740 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005741 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005742
Paul Jakmab2518c12006-05-12 23:48:40 +00005743 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005744 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005745 }
paul718e3742002-12-13 20:15:29 +00005746
5747 vty_out (vty, "%s", VTY_NEWLINE);
5748}
5749
ajs5a646652004-11-05 01:25:55 +00005750void
paul718e3742002-12-13 20:15:29 +00005751route_vty_out_tag (struct vty *vty, struct prefix *p,
5752 struct bgp_info *binfo, int display, safi_t safi)
5753{
5754 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005755 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005756
5757 if (!binfo->extra)
5758 return;
5759
paulb40d9392005-08-22 22:34:41 +00005760 /* short status lead text */
5761 route_vty_short_status_out (vty, binfo);
5762
paul718e3742002-12-13 20:15:29 +00005763 /* print prefix and mask */
5764 if (! display)
5765 route_vty_out_route (p, vty);
5766 else
5767 vty_out (vty, "%*s", 17, " ");
5768
5769 /* Print attribute */
5770 attr = binfo->attr;
5771 if (attr)
5772 {
5773 if (p->family == AF_INET)
5774 {
5775 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005776 vty_out (vty, "%-16s",
5777 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005778 else
5779 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5780 }
5781#ifdef HAVE_IPV6
5782 else if (p->family == AF_INET6)
5783 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005784 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005785 char buf[BUFSIZ];
5786 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005787 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005788 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005789 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5790 buf, BUFSIZ));
5791 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005792 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005793 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5794 buf, BUFSIZ),
5795 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5796 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005797
5798 }
5799#endif /* HAVE_IPV6 */
5800 }
5801
Paul Jakmafb982c22007-05-04 20:15:47 +00005802 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005803
5804 vty_out (vty, "notag/%d", label);
5805
5806 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005807}
5808
5809/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005810static void
paul718e3742002-12-13 20:15:29 +00005811damp_route_vty_out (struct vty *vty, struct prefix *p,
5812 struct bgp_info *binfo, int display, safi_t safi)
5813{
5814 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005815 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005816 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005817
paulb40d9392005-08-22 22:34:41 +00005818 /* short status lead text */
5819 route_vty_short_status_out (vty, binfo);
5820
paul718e3742002-12-13 20:15:29 +00005821 /* print prefix and mask */
5822 if (! display)
5823 route_vty_out_route (p, vty);
5824 else
5825 vty_out (vty, "%*s", 17, " ");
5826
5827 len = vty_out (vty, "%s", binfo->peer->host);
5828 len = 17 - len;
5829 if (len < 1)
5830 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5831 else
5832 vty_out (vty, "%*s", len, " ");
5833
Chris Caputo50aef6f2009-06-23 06:06:49 +00005834 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005835
5836 /* Print attribute */
5837 attr = binfo->attr;
5838 if (attr)
5839 {
5840 /* Print aspath */
5841 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005842 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005843
5844 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005845 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005846 }
5847 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005848}
5849
paul718e3742002-12-13 20:15:29 +00005850/* flap route */
ajs5a646652004-11-05 01:25:55 +00005851static void
paul718e3742002-12-13 20:15:29 +00005852flap_route_vty_out (struct vty *vty, struct prefix *p,
5853 struct bgp_info *binfo, int display, safi_t safi)
5854{
5855 struct attr *attr;
5856 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005857 char timebuf[BGP_UPTIME_LEN];
5858 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005859
5860 if (!binfo->extra)
5861 return;
5862
5863 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005864
paulb40d9392005-08-22 22:34:41 +00005865 /* short status lead text */
5866 route_vty_short_status_out (vty, binfo);
5867
paul718e3742002-12-13 20:15:29 +00005868 /* print prefix and mask */
5869 if (! display)
5870 route_vty_out_route (p, vty);
5871 else
5872 vty_out (vty, "%*s", 17, " ");
5873
5874 len = vty_out (vty, "%s", binfo->peer->host);
5875 len = 16 - len;
5876 if (len < 1)
5877 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5878 else
5879 vty_out (vty, "%*s", len, " ");
5880
5881 len = vty_out (vty, "%d", bdi->flap);
5882 len = 5 - len;
5883 if (len < 1)
5884 vty_out (vty, " ");
5885 else
5886 vty_out (vty, "%*s ", len, " ");
5887
5888 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5889 timebuf, BGP_UPTIME_LEN));
5890
5891 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5892 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005893 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005894 else
5895 vty_out (vty, "%*s ", 8, " ");
5896
5897 /* Print attribute */
5898 attr = binfo->attr;
5899 if (attr)
5900 {
5901 /* Print aspath */
5902 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005903 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005904
5905 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005906 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005907 }
5908 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005909}
5910
paul94f2b392005-06-28 12:44:16 +00005911static void
paul718e3742002-12-13 20:15:29 +00005912route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5913 struct bgp_info *binfo, afi_t afi, safi_t safi)
5914{
5915 char buf[INET6_ADDRSTRLEN];
5916 char buf1[BUFSIZ];
5917 struct attr *attr;
5918 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005919#ifdef HAVE_CLOCK_MONOTONIC
5920 time_t tbuf;
5921#endif
paul718e3742002-12-13 20:15:29 +00005922
5923 attr = binfo->attr;
5924
5925 if (attr)
5926 {
5927 /* Line1 display AS-path, Aggregator */
5928 if (attr->aspath)
5929 {
5930 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005931 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005932 vty_out (vty, "Local");
5933 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005934 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005935 }
5936
paulb40d9392005-08-22 22:34:41 +00005937 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5938 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005939 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5940 vty_out (vty, ", (stale)");
5941 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005942 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005943 attr->extra->aggregator_as,
5944 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005945 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5946 vty_out (vty, ", (Received from a RR-client)");
5947 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5948 vty_out (vty, ", (Received from a RS-client)");
5949 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5950 vty_out (vty, ", (history entry)");
5951 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5952 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005953 vty_out (vty, "%s", VTY_NEWLINE);
5954
5955 /* Line2 display Next-hop, Neighbor, Router-id */
5956 if (p->family == AF_INET)
5957 {
5958 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005959 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005960 inet_ntoa (attr->nexthop));
5961 }
5962#ifdef HAVE_IPV6
5963 else
5964 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005965 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005966 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005967 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005968 buf, INET6_ADDRSTRLEN));
5969 }
5970#endif /* HAVE_IPV6 */
5971
5972 if (binfo->peer == bgp->peer_self)
5973 {
5974 vty_out (vty, " from %s ",
5975 p->family == AF_INET ? "0.0.0.0" : "::");
5976 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5977 }
5978 else
5979 {
5980 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5981 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005982 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02005983 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005984 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005985 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005986 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005987 else
5988 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5989 }
5990 vty_out (vty, "%s", VTY_NEWLINE);
5991
5992#ifdef HAVE_IPV6
5993 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005994 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005995 {
5996 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005997 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005998 buf, INET6_ADDRSTRLEN),
5999 VTY_NEWLINE);
6000 }
6001#endif /* HAVE_IPV6 */
6002
6003 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6004 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6005
6006 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006007 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006008
6009 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006010 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006011 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006012 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006013
Paul Jakmafb982c22007-05-04 20:15:47 +00006014 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006015 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006016
6017 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6018 vty_out (vty, ", valid");
6019
6020 if (binfo->peer != bgp->peer_self)
6021 {
6022 if (binfo->peer->as == binfo->peer->local_as)
6023 vty_out (vty, ", internal");
6024 else
6025 vty_out (vty, ", %s",
6026 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6027 }
6028 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6029 vty_out (vty, ", aggregated, local");
6030 else if (binfo->type != ZEBRA_ROUTE_BGP)
6031 vty_out (vty, ", sourced");
6032 else
6033 vty_out (vty, ", sourced, local");
6034
6035 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6036 vty_out (vty, ", atomic-aggregate");
6037
Josh Baileyde8d5df2011-07-20 20:46:01 -07006038 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6039 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6040 bgp_info_mpath_count (binfo)))
6041 vty_out (vty, ", multipath");
6042
paul718e3742002-12-13 20:15:29 +00006043 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6044 vty_out (vty, ", best");
6045
6046 vty_out (vty, "%s", VTY_NEWLINE);
6047
6048 /* Line 4 display Community */
6049 if (attr->community)
6050 vty_out (vty, " Community: %s%s", attr->community->str,
6051 VTY_NEWLINE);
6052
6053 /* Line 5 display Extended-community */
6054 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006055 vty_out (vty, " Extended Community: %s%s",
6056 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006057
6058 /* Line 6 display Originator, Cluster-id */
6059 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6060 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6061 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006062 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006063 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006064 vty_out (vty, " Originator: %s",
6065 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006066
6067 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6068 {
6069 int i;
6070 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006071 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6072 vty_out (vty, "%s ",
6073 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006074 }
6075 vty_out (vty, "%s", VTY_NEWLINE);
6076 }
Paul Jakma41367172007-08-06 15:24:51 +00006077
Paul Jakmafb982c22007-05-04 20:15:47 +00006078 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006079 bgp_damp_info_vty (vty, binfo);
6080
6081 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006082#ifdef HAVE_CLOCK_MONOTONIC
6083 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006084 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006085#else
6086 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6087#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006088 }
6089 vty_out (vty, "%s", VTY_NEWLINE);
6090}
6091
paulb40d9392005-08-22 22:34:41 +00006092#define BGP_SHOW_SCODE_HEADER "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,%s r RIB-failure, S Stale, R Removed%s"
hasso93406d82005-02-02 14:40:33 +00006093#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006094#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6095#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6096#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6097
6098enum bgp_show_type
6099{
6100 bgp_show_type_normal,
6101 bgp_show_type_regexp,
6102 bgp_show_type_prefix_list,
6103 bgp_show_type_filter_list,
6104 bgp_show_type_route_map,
6105 bgp_show_type_neighbor,
6106 bgp_show_type_cidr_only,
6107 bgp_show_type_prefix_longer,
6108 bgp_show_type_community_all,
6109 bgp_show_type_community,
6110 bgp_show_type_community_exact,
6111 bgp_show_type_community_list,
6112 bgp_show_type_community_list_exact,
6113 bgp_show_type_flap_statistics,
6114 bgp_show_type_flap_address,
6115 bgp_show_type_flap_prefix,
6116 bgp_show_type_flap_cidr_only,
6117 bgp_show_type_flap_regexp,
6118 bgp_show_type_flap_filter_list,
6119 bgp_show_type_flap_prefix_list,
6120 bgp_show_type_flap_prefix_longer,
6121 bgp_show_type_flap_route_map,
6122 bgp_show_type_flap_neighbor,
6123 bgp_show_type_dampend_paths,
6124 bgp_show_type_damp_neighbor
6125};
6126
ajs5a646652004-11-05 01:25:55 +00006127static int
paulfee0f4c2004-09-13 05:12:46 +00006128bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006129 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006130{
paul718e3742002-12-13 20:15:29 +00006131 struct bgp_info *ri;
6132 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006133 int header = 1;
paul718e3742002-12-13 20:15:29 +00006134 int display;
ajs5a646652004-11-05 01:25:55 +00006135 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006136
6137 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006138 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006139
paul718e3742002-12-13 20:15:29 +00006140 /* Start processing of routes. */
6141 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6142 if (rn->info != NULL)
6143 {
6144 display = 0;
6145
6146 for (ri = rn->info; ri; ri = ri->next)
6147 {
ajs5a646652004-11-05 01:25:55 +00006148 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006149 || type == bgp_show_type_flap_address
6150 || type == bgp_show_type_flap_prefix
6151 || type == bgp_show_type_flap_cidr_only
6152 || type == bgp_show_type_flap_regexp
6153 || type == bgp_show_type_flap_filter_list
6154 || type == bgp_show_type_flap_prefix_list
6155 || type == bgp_show_type_flap_prefix_longer
6156 || type == bgp_show_type_flap_route_map
6157 || type == bgp_show_type_flap_neighbor
6158 || type == bgp_show_type_dampend_paths
6159 || type == bgp_show_type_damp_neighbor)
6160 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006161 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006162 continue;
6163 }
6164 if (type == bgp_show_type_regexp
6165 || type == bgp_show_type_flap_regexp)
6166 {
ajs5a646652004-11-05 01:25:55 +00006167 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006168
6169 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6170 continue;
6171 }
6172 if (type == bgp_show_type_prefix_list
6173 || type == bgp_show_type_flap_prefix_list)
6174 {
ajs5a646652004-11-05 01:25:55 +00006175 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006176
6177 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6178 continue;
6179 }
6180 if (type == bgp_show_type_filter_list
6181 || type == bgp_show_type_flap_filter_list)
6182 {
ajs5a646652004-11-05 01:25:55 +00006183 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006184
6185 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6186 continue;
6187 }
6188 if (type == bgp_show_type_route_map
6189 || type == bgp_show_type_flap_route_map)
6190 {
ajs5a646652004-11-05 01:25:55 +00006191 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006192 struct bgp_info binfo;
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006193 struct attr dummy_attr;
6194 struct attr_extra dummy_extra;
paul718e3742002-12-13 20:15:29 +00006195 int ret;
6196
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006197 dummy_attr.extra = &dummy_extra;
Paul Jakmafb982c22007-05-04 20:15:47 +00006198 bgp_attr_dup (&dummy_attr, ri->attr);
Jorge Boncompte [DTI2]558d1fe2012-05-07 16:53:05 +00006199
paul718e3742002-12-13 20:15:29 +00006200 binfo.peer = ri->peer;
6201 binfo.attr = &dummy_attr;
6202
6203 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
paul718e3742002-12-13 20:15:29 +00006204 if (ret == RMAP_DENYMATCH)
6205 continue;
6206 }
6207 if (type == bgp_show_type_neighbor
6208 || type == bgp_show_type_flap_neighbor
6209 || type == bgp_show_type_damp_neighbor)
6210 {
ajs5a646652004-11-05 01:25:55 +00006211 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006212
6213 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6214 continue;
6215 }
6216 if (type == bgp_show_type_cidr_only
6217 || type == bgp_show_type_flap_cidr_only)
6218 {
6219 u_int32_t destination;
6220
6221 destination = ntohl (rn->p.u.prefix4.s_addr);
6222 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6223 continue;
6224 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6225 continue;
6226 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6227 continue;
6228 }
6229 if (type == bgp_show_type_prefix_longer
6230 || type == bgp_show_type_flap_prefix_longer)
6231 {
ajs5a646652004-11-05 01:25:55 +00006232 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006233
6234 if (! prefix_match (p, &rn->p))
6235 continue;
6236 }
6237 if (type == bgp_show_type_community_all)
6238 {
6239 if (! ri->attr->community)
6240 continue;
6241 }
6242 if (type == bgp_show_type_community)
6243 {
ajs5a646652004-11-05 01:25:55 +00006244 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006245
6246 if (! ri->attr->community ||
6247 ! community_match (ri->attr->community, com))
6248 continue;
6249 }
6250 if (type == bgp_show_type_community_exact)
6251 {
ajs5a646652004-11-05 01:25:55 +00006252 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006253
6254 if (! ri->attr->community ||
6255 ! community_cmp (ri->attr->community, com))
6256 continue;
6257 }
6258 if (type == bgp_show_type_community_list)
6259 {
ajs5a646652004-11-05 01:25:55 +00006260 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006261
6262 if (! community_list_match (ri->attr->community, list))
6263 continue;
6264 }
6265 if (type == bgp_show_type_community_list_exact)
6266 {
ajs5a646652004-11-05 01:25:55 +00006267 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006268
6269 if (! community_list_exact_match (ri->attr->community, list))
6270 continue;
6271 }
6272 if (type == bgp_show_type_flap_address
6273 || type == bgp_show_type_flap_prefix)
6274 {
ajs5a646652004-11-05 01:25:55 +00006275 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006276
6277 if (! prefix_match (&rn->p, p))
6278 continue;
6279
6280 if (type == bgp_show_type_flap_prefix)
6281 if (p->prefixlen != rn->p.prefixlen)
6282 continue;
6283 }
6284 if (type == bgp_show_type_dampend_paths
6285 || type == bgp_show_type_damp_neighbor)
6286 {
6287 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6288 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6289 continue;
6290 }
6291
6292 if (header)
6293 {
hasso93406d82005-02-02 14:40:33 +00006294 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6295 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6296 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006297 if (type == bgp_show_type_dampend_paths
6298 || type == bgp_show_type_damp_neighbor)
6299 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6300 else if (type == bgp_show_type_flap_statistics
6301 || type == bgp_show_type_flap_address
6302 || type == bgp_show_type_flap_prefix
6303 || type == bgp_show_type_flap_cidr_only
6304 || type == bgp_show_type_flap_regexp
6305 || type == bgp_show_type_flap_filter_list
6306 || type == bgp_show_type_flap_prefix_list
6307 || type == bgp_show_type_flap_prefix_longer
6308 || type == bgp_show_type_flap_route_map
6309 || type == bgp_show_type_flap_neighbor)
6310 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6311 else
6312 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006313 header = 0;
6314 }
6315
6316 if (type == bgp_show_type_dampend_paths
6317 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006318 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006319 else if (type == bgp_show_type_flap_statistics
6320 || type == bgp_show_type_flap_address
6321 || type == bgp_show_type_flap_prefix
6322 || type == bgp_show_type_flap_cidr_only
6323 || type == bgp_show_type_flap_regexp
6324 || type == bgp_show_type_flap_filter_list
6325 || type == bgp_show_type_flap_prefix_list
6326 || type == bgp_show_type_flap_prefix_longer
6327 || type == bgp_show_type_flap_route_map
6328 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006329 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006330 else
ajs5a646652004-11-05 01:25:55 +00006331 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006332 display++;
6333 }
6334 if (display)
ajs5a646652004-11-05 01:25:55 +00006335 output_count++;
paul718e3742002-12-13 20:15:29 +00006336 }
6337
6338 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006339 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006340 {
6341 if (type == bgp_show_type_normal)
6342 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6343 }
6344 else
6345 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006346 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006347
6348 return CMD_SUCCESS;
6349}
6350
ajs5a646652004-11-05 01:25:55 +00006351static int
paulfee0f4c2004-09-13 05:12:46 +00006352bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006353 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006354{
6355 struct bgp_table *table;
6356
6357 if (bgp == NULL) {
6358 bgp = bgp_get_default ();
6359 }
6360
6361 if (bgp == NULL)
6362 {
6363 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6364 return CMD_WARNING;
6365 }
6366
6367
6368 table = bgp->rib[afi][safi];
6369
ajs5a646652004-11-05 01:25:55 +00006370 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006371}
6372
paul718e3742002-12-13 20:15:29 +00006373/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006374static void
paul718e3742002-12-13 20:15:29 +00006375route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6376 struct bgp_node *rn,
6377 struct prefix_rd *prd, afi_t afi, safi_t safi)
6378{
6379 struct bgp_info *ri;
6380 struct prefix *p;
6381 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006382 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006383 char buf1[INET6_ADDRSTRLEN];
6384 char buf2[INET6_ADDRSTRLEN];
6385 int count = 0;
6386 int best = 0;
6387 int suppress = 0;
6388 int no_export = 0;
6389 int no_advertise = 0;
6390 int local_as = 0;
6391 int first = 0;
6392
6393 p = &rn->p;
6394 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6395 (safi == SAFI_MPLS_VPN ?
6396 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6397 safi == SAFI_MPLS_VPN ? ":" : "",
6398 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6399 p->prefixlen, VTY_NEWLINE);
6400
6401 for (ri = rn->info; ri; ri = ri->next)
6402 {
6403 count++;
6404 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6405 {
6406 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006407 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006408 suppress = 1;
6409 if (ri->attr->community != NULL)
6410 {
6411 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6412 no_advertise = 1;
6413 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6414 no_export = 1;
6415 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6416 local_as = 1;
6417 }
6418 }
6419 }
6420
6421 vty_out (vty, "Paths: (%d available", count);
6422 if (best)
6423 {
6424 vty_out (vty, ", best #%d", best);
6425 if (safi == SAFI_UNICAST)
6426 vty_out (vty, ", table Default-IP-Routing-Table");
6427 }
6428 else
6429 vty_out (vty, ", no best path");
6430 if (no_advertise)
6431 vty_out (vty, ", not advertised to any peer");
6432 else if (no_export)
6433 vty_out (vty, ", not advertised to EBGP peer");
6434 else if (local_as)
6435 vty_out (vty, ", not advertised outside local AS");
6436 if (suppress)
6437 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6438 vty_out (vty, ")%s", VTY_NEWLINE);
6439
6440 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006441 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006442 {
6443 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6444 {
6445 if (! first)
6446 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6447 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6448 first = 1;
6449 }
6450 }
6451 if (! first)
6452 vty_out (vty, " Not advertised to any peer");
6453 vty_out (vty, "%s", VTY_NEWLINE);
6454}
6455
6456/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006457static int
paulfee0f4c2004-09-13 05:12:46 +00006458bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006459 struct bgp_table *rib, const char *ip_str,
6460 afi_t afi, safi_t safi, struct prefix_rd *prd,
6461 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006462{
6463 int ret;
6464 int header;
6465 int display = 0;
6466 struct prefix match;
6467 struct bgp_node *rn;
6468 struct bgp_node *rm;
6469 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006470 struct bgp_table *table;
6471
paul718e3742002-12-13 20:15:29 +00006472 /* Check IP address argument. */
6473 ret = str2prefix (ip_str, &match);
6474 if (! ret)
6475 {
6476 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6477 return CMD_WARNING;
6478 }
6479
6480 match.family = afi2family (afi);
6481
6482 if (safi == SAFI_MPLS_VPN)
6483 {
paulfee0f4c2004-09-13 05:12:46 +00006484 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006485 {
6486 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6487 continue;
6488
6489 if ((table = rn->info) != NULL)
6490 {
6491 header = 1;
6492
6493 if ((rm = bgp_node_match (table, &match)) != NULL)
6494 {
6495 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006496 {
6497 bgp_unlock_node (rm);
6498 continue;
6499 }
paul718e3742002-12-13 20:15:29 +00006500
6501 for (ri = rm->info; ri; ri = ri->next)
6502 {
6503 if (header)
6504 {
6505 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6506 AFI_IP, SAFI_MPLS_VPN);
6507
6508 header = 0;
6509 }
6510 display++;
6511 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6512 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006513
6514 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006515 }
6516 }
6517 }
6518 }
6519 else
6520 {
6521 header = 1;
6522
paulfee0f4c2004-09-13 05:12:46 +00006523 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006524 {
6525 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6526 {
6527 for (ri = rn->info; ri; ri = ri->next)
6528 {
6529 if (header)
6530 {
6531 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6532 header = 0;
6533 }
6534 display++;
6535 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6536 }
6537 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006538
6539 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006540 }
6541 }
6542
6543 if (! display)
6544 {
6545 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6546 return CMD_WARNING;
6547 }
6548
6549 return CMD_SUCCESS;
6550}
6551
paulfee0f4c2004-09-13 05:12:46 +00006552/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006553static int
paulfd79ac92004-10-13 05:06:08 +00006554bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006555 afi_t afi, safi_t safi, struct prefix_rd *prd,
6556 int prefix_check)
6557{
6558 struct bgp *bgp;
6559
6560 /* BGP structure lookup. */
6561 if (view_name)
6562 {
6563 bgp = bgp_lookup_by_name (view_name);
6564 if (bgp == NULL)
6565 {
6566 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6567 return CMD_WARNING;
6568 }
6569 }
6570 else
6571 {
6572 bgp = bgp_get_default ();
6573 if (bgp == NULL)
6574 {
6575 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6576 return CMD_WARNING;
6577 }
6578 }
6579
6580 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6581 afi, safi, prd, prefix_check);
6582}
6583
paul718e3742002-12-13 20:15:29 +00006584/* BGP route print out function. */
6585DEFUN (show_ip_bgp,
6586 show_ip_bgp_cmd,
6587 "show ip bgp",
6588 SHOW_STR
6589 IP_STR
6590 BGP_STR)
6591{
ajs5a646652004-11-05 01:25:55 +00006592 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006593}
6594
6595DEFUN (show_ip_bgp_ipv4,
6596 show_ip_bgp_ipv4_cmd,
6597 "show ip bgp ipv4 (unicast|multicast)",
6598 SHOW_STR
6599 IP_STR
6600 BGP_STR
6601 "Address family\n"
6602 "Address Family modifier\n"
6603 "Address Family modifier\n")
6604{
6605 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006606 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6607 NULL);
paul718e3742002-12-13 20:15:29 +00006608
ajs5a646652004-11-05 01:25:55 +00006609 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006610}
6611
Michael Lambert95cbbd22010-07-23 14:43:04 -04006612ALIAS (show_ip_bgp_ipv4,
6613 show_bgp_ipv4_safi_cmd,
6614 "show bgp ipv4 (unicast|multicast)",
6615 SHOW_STR
6616 BGP_STR
6617 "Address family\n"
6618 "Address Family modifier\n"
6619 "Address Family modifier\n")
6620
paul718e3742002-12-13 20:15:29 +00006621DEFUN (show_ip_bgp_route,
6622 show_ip_bgp_route_cmd,
6623 "show ip bgp A.B.C.D",
6624 SHOW_STR
6625 IP_STR
6626 BGP_STR
6627 "Network in the BGP routing table to display\n")
6628{
6629 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6630}
6631
6632DEFUN (show_ip_bgp_ipv4_route,
6633 show_ip_bgp_ipv4_route_cmd,
6634 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6635 SHOW_STR
6636 IP_STR
6637 BGP_STR
6638 "Address family\n"
6639 "Address Family modifier\n"
6640 "Address Family modifier\n"
6641 "Network in the BGP routing table to display\n")
6642{
6643 if (strncmp (argv[0], "m", 1) == 0)
6644 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6645
6646 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6647}
6648
Michael Lambert95cbbd22010-07-23 14:43:04 -04006649ALIAS (show_ip_bgp_ipv4_route,
6650 show_bgp_ipv4_safi_route_cmd,
6651 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6652 SHOW_STR
6653 BGP_STR
6654 "Address family\n"
6655 "Address Family modifier\n"
6656 "Address Family modifier\n"
6657 "Network in the BGP routing table to display\n")
6658
paul718e3742002-12-13 20:15:29 +00006659DEFUN (show_ip_bgp_vpnv4_all_route,
6660 show_ip_bgp_vpnv4_all_route_cmd,
6661 "show ip bgp vpnv4 all A.B.C.D",
6662 SHOW_STR
6663 IP_STR
6664 BGP_STR
6665 "Display VPNv4 NLRI specific information\n"
6666 "Display information about all VPNv4 NLRIs\n"
6667 "Network in the BGP routing table to display\n")
6668{
6669 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6670}
6671
6672DEFUN (show_ip_bgp_vpnv4_rd_route,
6673 show_ip_bgp_vpnv4_rd_route_cmd,
6674 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6675 SHOW_STR
6676 IP_STR
6677 BGP_STR
6678 "Display VPNv4 NLRI specific information\n"
6679 "Display information for a route distinguisher\n"
6680 "VPN Route Distinguisher\n"
6681 "Network in the BGP routing table to display\n")
6682{
6683 int ret;
6684 struct prefix_rd prd;
6685
6686 ret = str2prefix_rd (argv[0], &prd);
6687 if (! ret)
6688 {
6689 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6690 return CMD_WARNING;
6691 }
6692 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6693}
6694
6695DEFUN (show_ip_bgp_prefix,
6696 show_ip_bgp_prefix_cmd,
6697 "show ip bgp A.B.C.D/M",
6698 SHOW_STR
6699 IP_STR
6700 BGP_STR
6701 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6702{
6703 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6704}
6705
6706DEFUN (show_ip_bgp_ipv4_prefix,
6707 show_ip_bgp_ipv4_prefix_cmd,
6708 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6709 SHOW_STR
6710 IP_STR
6711 BGP_STR
6712 "Address family\n"
6713 "Address Family modifier\n"
6714 "Address Family modifier\n"
6715 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6716{
6717 if (strncmp (argv[0], "m", 1) == 0)
6718 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6719
6720 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6721}
6722
Michael Lambert95cbbd22010-07-23 14:43:04 -04006723ALIAS (show_ip_bgp_ipv4_prefix,
6724 show_bgp_ipv4_safi_prefix_cmd,
6725 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6726 SHOW_STR
6727 BGP_STR
6728 "Address family\n"
6729 "Address Family modifier\n"
6730 "Address Family modifier\n"
6731 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6732
paul718e3742002-12-13 20:15:29 +00006733DEFUN (show_ip_bgp_vpnv4_all_prefix,
6734 show_ip_bgp_vpnv4_all_prefix_cmd,
6735 "show ip bgp vpnv4 all A.B.C.D/M",
6736 SHOW_STR
6737 IP_STR
6738 BGP_STR
6739 "Display VPNv4 NLRI specific information\n"
6740 "Display information about all VPNv4 NLRIs\n"
6741 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6742{
6743 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6744}
6745
6746DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6747 show_ip_bgp_vpnv4_rd_prefix_cmd,
6748 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6749 SHOW_STR
6750 IP_STR
6751 BGP_STR
6752 "Display VPNv4 NLRI specific information\n"
6753 "Display information for a route distinguisher\n"
6754 "VPN Route Distinguisher\n"
6755 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6756{
6757 int ret;
6758 struct prefix_rd prd;
6759
6760 ret = str2prefix_rd (argv[0], &prd);
6761 if (! ret)
6762 {
6763 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6764 return CMD_WARNING;
6765 }
6766 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6767}
6768
6769DEFUN (show_ip_bgp_view,
6770 show_ip_bgp_view_cmd,
6771 "show ip bgp view WORD",
6772 SHOW_STR
6773 IP_STR
6774 BGP_STR
6775 "BGP view\n"
6776 "BGP view name\n")
6777{
paulbb46e942003-10-24 19:02:03 +00006778 struct bgp *bgp;
6779
6780 /* BGP structure lookup. */
6781 bgp = bgp_lookup_by_name (argv[0]);
6782 if (bgp == NULL)
6783 {
6784 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6785 return CMD_WARNING;
6786 }
6787
ajs5a646652004-11-05 01:25:55 +00006788 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006789}
6790
6791DEFUN (show_ip_bgp_view_route,
6792 show_ip_bgp_view_route_cmd,
6793 "show ip bgp view WORD A.B.C.D",
6794 SHOW_STR
6795 IP_STR
6796 BGP_STR
6797 "BGP view\n"
6798 "BGP view name\n"
6799 "Network in the BGP routing table to display\n")
6800{
6801 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6802}
6803
6804DEFUN (show_ip_bgp_view_prefix,
6805 show_ip_bgp_view_prefix_cmd,
6806 "show ip bgp view WORD A.B.C.D/M",
6807 SHOW_STR
6808 IP_STR
6809 BGP_STR
6810 "BGP view\n"
6811 "BGP view name\n"
6812 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6813{
6814 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6815}
6816
6817#ifdef HAVE_IPV6
6818DEFUN (show_bgp,
6819 show_bgp_cmd,
6820 "show bgp",
6821 SHOW_STR
6822 BGP_STR)
6823{
ajs5a646652004-11-05 01:25:55 +00006824 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6825 NULL);
paul718e3742002-12-13 20:15:29 +00006826}
6827
6828ALIAS (show_bgp,
6829 show_bgp_ipv6_cmd,
6830 "show bgp ipv6",
6831 SHOW_STR
6832 BGP_STR
6833 "Address family\n")
6834
Michael Lambert95cbbd22010-07-23 14:43:04 -04006835DEFUN (show_bgp_ipv6_safi,
6836 show_bgp_ipv6_safi_cmd,
6837 "show bgp ipv6 (unicast|multicast)",
6838 SHOW_STR
6839 BGP_STR
6840 "Address family\n"
6841 "Address Family modifier\n"
6842 "Address Family modifier\n")
6843{
6844 if (strncmp (argv[0], "m", 1) == 0)
6845 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6846 NULL);
6847
6848 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6849}
6850
paul718e3742002-12-13 20:15:29 +00006851/* old command */
6852DEFUN (show_ipv6_bgp,
6853 show_ipv6_bgp_cmd,
6854 "show ipv6 bgp",
6855 SHOW_STR
6856 IP_STR
6857 BGP_STR)
6858{
ajs5a646652004-11-05 01:25:55 +00006859 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6860 NULL);
paul718e3742002-12-13 20:15:29 +00006861}
6862
6863DEFUN (show_bgp_route,
6864 show_bgp_route_cmd,
6865 "show bgp X:X::X:X",
6866 SHOW_STR
6867 BGP_STR
6868 "Network in the BGP routing table to display\n")
6869{
6870 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6871}
6872
6873ALIAS (show_bgp_route,
6874 show_bgp_ipv6_route_cmd,
6875 "show bgp ipv6 X:X::X:X",
6876 SHOW_STR
6877 BGP_STR
6878 "Address family\n"
6879 "Network in the BGP routing table to display\n")
6880
Michael Lambert95cbbd22010-07-23 14:43:04 -04006881DEFUN (show_bgp_ipv6_safi_route,
6882 show_bgp_ipv6_safi_route_cmd,
6883 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6884 SHOW_STR
6885 BGP_STR
6886 "Address family\n"
6887 "Address Family modifier\n"
6888 "Address Family modifier\n"
6889 "Network in the BGP routing table to display\n")
6890{
6891 if (strncmp (argv[0], "m", 1) == 0)
6892 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6893
6894 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6895}
6896
paul718e3742002-12-13 20:15:29 +00006897/* old command */
6898DEFUN (show_ipv6_bgp_route,
6899 show_ipv6_bgp_route_cmd,
6900 "show ipv6 bgp X:X::X:X",
6901 SHOW_STR
6902 IP_STR
6903 BGP_STR
6904 "Network in the BGP routing table to display\n")
6905{
6906 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6907}
6908
6909DEFUN (show_bgp_prefix,
6910 show_bgp_prefix_cmd,
6911 "show bgp X:X::X:X/M",
6912 SHOW_STR
6913 BGP_STR
6914 "IPv6 prefix <network>/<length>\n")
6915{
6916 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6917}
6918
6919ALIAS (show_bgp_prefix,
6920 show_bgp_ipv6_prefix_cmd,
6921 "show bgp ipv6 X:X::X:X/M",
6922 SHOW_STR
6923 BGP_STR
6924 "Address family\n"
6925 "IPv6 prefix <network>/<length>\n")
6926
Michael Lambert95cbbd22010-07-23 14:43:04 -04006927DEFUN (show_bgp_ipv6_safi_prefix,
6928 show_bgp_ipv6_safi_prefix_cmd,
6929 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6930 SHOW_STR
6931 BGP_STR
6932 "Address family\n"
6933 "Address Family modifier\n"
6934 "Address Family modifier\n"
6935 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6936{
6937 if (strncmp (argv[0], "m", 1) == 0)
6938 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6939
6940 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6941}
6942
paul718e3742002-12-13 20:15:29 +00006943/* old command */
6944DEFUN (show_ipv6_bgp_prefix,
6945 show_ipv6_bgp_prefix_cmd,
6946 "show ipv6 bgp X:X::X:X/M",
6947 SHOW_STR
6948 IP_STR
6949 BGP_STR
6950 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6951{
6952 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6953}
6954
paulbb46e942003-10-24 19:02:03 +00006955DEFUN (show_bgp_view,
6956 show_bgp_view_cmd,
6957 "show bgp view WORD",
6958 SHOW_STR
6959 BGP_STR
6960 "BGP view\n"
6961 "View name\n")
6962{
6963 struct bgp *bgp;
6964
6965 /* BGP structure lookup. */
6966 bgp = bgp_lookup_by_name (argv[0]);
6967 if (bgp == NULL)
6968 {
6969 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6970 return CMD_WARNING;
6971 }
6972
ajs5a646652004-11-05 01:25:55 +00006973 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006974}
6975
6976ALIAS (show_bgp_view,
6977 show_bgp_view_ipv6_cmd,
6978 "show bgp view WORD ipv6",
6979 SHOW_STR
6980 BGP_STR
6981 "BGP view\n"
6982 "View name\n"
6983 "Address family\n")
6984
6985DEFUN (show_bgp_view_route,
6986 show_bgp_view_route_cmd,
6987 "show bgp view WORD X:X::X:X",
6988 SHOW_STR
6989 BGP_STR
6990 "BGP view\n"
6991 "View name\n"
6992 "Network in the BGP routing table to display\n")
6993{
6994 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6995}
6996
6997ALIAS (show_bgp_view_route,
6998 show_bgp_view_ipv6_route_cmd,
6999 "show bgp view WORD ipv6 X:X::X:X",
7000 SHOW_STR
7001 BGP_STR
7002 "BGP view\n"
7003 "View name\n"
7004 "Address family\n"
7005 "Network in the BGP routing table to display\n")
7006
7007DEFUN (show_bgp_view_prefix,
7008 show_bgp_view_prefix_cmd,
7009 "show bgp view WORD X:X::X:X/M",
7010 SHOW_STR
7011 BGP_STR
7012 "BGP view\n"
7013 "View name\n"
7014 "IPv6 prefix <network>/<length>\n")
7015{
7016 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7017}
7018
7019ALIAS (show_bgp_view_prefix,
7020 show_bgp_view_ipv6_prefix_cmd,
7021 "show bgp view WORD ipv6 X:X::X:X/M",
7022 SHOW_STR
7023 BGP_STR
7024 "BGP view\n"
7025 "View name\n"
7026 "Address family\n"
7027 "IPv6 prefix <network>/<length>\n")
7028
paul718e3742002-12-13 20:15:29 +00007029/* old command */
7030DEFUN (show_ipv6_mbgp,
7031 show_ipv6_mbgp_cmd,
7032 "show ipv6 mbgp",
7033 SHOW_STR
7034 IP_STR
7035 MBGP_STR)
7036{
ajs5a646652004-11-05 01:25:55 +00007037 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7038 NULL);
paul718e3742002-12-13 20:15:29 +00007039}
7040
7041/* old command */
7042DEFUN (show_ipv6_mbgp_route,
7043 show_ipv6_mbgp_route_cmd,
7044 "show ipv6 mbgp X:X::X:X",
7045 SHOW_STR
7046 IP_STR
7047 MBGP_STR
7048 "Network in the MBGP routing table to display\n")
7049{
7050 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7051}
7052
7053/* old command */
7054DEFUN (show_ipv6_mbgp_prefix,
7055 show_ipv6_mbgp_prefix_cmd,
7056 "show ipv6 mbgp X:X::X:X/M",
7057 SHOW_STR
7058 IP_STR
7059 MBGP_STR
7060 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7061{
7062 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7063}
7064#endif
7065
paul718e3742002-12-13 20:15:29 +00007066
paul94f2b392005-06-28 12:44:16 +00007067static int
paulfd79ac92004-10-13 05:06:08 +00007068bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007069 safi_t safi, enum bgp_show_type type)
7070{
7071 int i;
7072 struct buffer *b;
7073 char *regstr;
7074 int first;
7075 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007076 int rc;
paul718e3742002-12-13 20:15:29 +00007077
7078 first = 0;
7079 b = buffer_new (1024);
7080 for (i = 0; i < argc; i++)
7081 {
7082 if (first)
7083 buffer_putc (b, ' ');
7084 else
7085 {
7086 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7087 continue;
7088 first = 1;
7089 }
7090
7091 buffer_putstr (b, argv[i]);
7092 }
7093 buffer_putc (b, '\0');
7094
7095 regstr = buffer_getstr (b);
7096 buffer_free (b);
7097
7098 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007099 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007100 if (! regex)
7101 {
7102 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7103 VTY_NEWLINE);
7104 return CMD_WARNING;
7105 }
7106
ajs5a646652004-11-05 01:25:55 +00007107 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7108 bgp_regex_free (regex);
7109 return rc;
paul718e3742002-12-13 20:15:29 +00007110}
7111
7112DEFUN (show_ip_bgp_regexp,
7113 show_ip_bgp_regexp_cmd,
7114 "show ip bgp regexp .LINE",
7115 SHOW_STR
7116 IP_STR
7117 BGP_STR
7118 "Display routes matching the AS path regular expression\n"
7119 "A regular-expression to match the BGP AS paths\n")
7120{
7121 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7122 bgp_show_type_regexp);
7123}
7124
7125DEFUN (show_ip_bgp_flap_regexp,
7126 show_ip_bgp_flap_regexp_cmd,
7127 "show ip bgp flap-statistics regexp .LINE",
7128 SHOW_STR
7129 IP_STR
7130 BGP_STR
7131 "Display flap statistics of routes\n"
7132 "Display routes matching the AS path regular expression\n"
7133 "A regular-expression to match the BGP AS paths\n")
7134{
7135 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7136 bgp_show_type_flap_regexp);
7137}
7138
7139DEFUN (show_ip_bgp_ipv4_regexp,
7140 show_ip_bgp_ipv4_regexp_cmd,
7141 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7142 SHOW_STR
7143 IP_STR
7144 BGP_STR
7145 "Address family\n"
7146 "Address Family modifier\n"
7147 "Address Family modifier\n"
7148 "Display routes matching the AS path regular expression\n"
7149 "A regular-expression to match the BGP AS paths\n")
7150{
7151 if (strncmp (argv[0], "m", 1) == 0)
7152 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7153 bgp_show_type_regexp);
7154
7155 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7156 bgp_show_type_regexp);
7157}
7158
7159#ifdef HAVE_IPV6
7160DEFUN (show_bgp_regexp,
7161 show_bgp_regexp_cmd,
7162 "show bgp regexp .LINE",
7163 SHOW_STR
7164 BGP_STR
7165 "Display routes matching the AS path regular expression\n"
7166 "A regular-expression to match the BGP AS paths\n")
7167{
7168 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7169 bgp_show_type_regexp);
7170}
7171
7172ALIAS (show_bgp_regexp,
7173 show_bgp_ipv6_regexp_cmd,
7174 "show bgp ipv6 regexp .LINE",
7175 SHOW_STR
7176 BGP_STR
7177 "Address family\n"
7178 "Display routes matching the AS path regular expression\n"
7179 "A regular-expression to match the BGP AS paths\n")
7180
7181/* old command */
7182DEFUN (show_ipv6_bgp_regexp,
7183 show_ipv6_bgp_regexp_cmd,
7184 "show ipv6 bgp regexp .LINE",
7185 SHOW_STR
7186 IP_STR
7187 BGP_STR
7188 "Display routes matching the AS path regular expression\n"
7189 "A regular-expression to match the BGP AS paths\n")
7190{
7191 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7192 bgp_show_type_regexp);
7193}
7194
7195/* old command */
7196DEFUN (show_ipv6_mbgp_regexp,
7197 show_ipv6_mbgp_regexp_cmd,
7198 "show ipv6 mbgp regexp .LINE",
7199 SHOW_STR
7200 IP_STR
7201 BGP_STR
7202 "Display routes matching the AS path regular expression\n"
7203 "A regular-expression to match the MBGP AS paths\n")
7204{
7205 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7206 bgp_show_type_regexp);
7207}
7208#endif /* HAVE_IPV6 */
7209
paul94f2b392005-06-28 12:44:16 +00007210static int
paulfd79ac92004-10-13 05:06:08 +00007211bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007212 safi_t safi, enum bgp_show_type type)
7213{
7214 struct prefix_list *plist;
7215
7216 plist = prefix_list_lookup (afi, prefix_list_str);
7217 if (plist == NULL)
7218 {
7219 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7220 prefix_list_str, VTY_NEWLINE);
7221 return CMD_WARNING;
7222 }
7223
ajs5a646652004-11-05 01:25:55 +00007224 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007225}
7226
7227DEFUN (show_ip_bgp_prefix_list,
7228 show_ip_bgp_prefix_list_cmd,
7229 "show ip bgp prefix-list WORD",
7230 SHOW_STR
7231 IP_STR
7232 BGP_STR
7233 "Display routes conforming to the prefix-list\n"
7234 "IP prefix-list name\n")
7235{
7236 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7237 bgp_show_type_prefix_list);
7238}
7239
7240DEFUN (show_ip_bgp_flap_prefix_list,
7241 show_ip_bgp_flap_prefix_list_cmd,
7242 "show ip bgp flap-statistics prefix-list WORD",
7243 SHOW_STR
7244 IP_STR
7245 BGP_STR
7246 "Display flap statistics of routes\n"
7247 "Display routes conforming to the prefix-list\n"
7248 "IP prefix-list name\n")
7249{
7250 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7251 bgp_show_type_flap_prefix_list);
7252}
7253
7254DEFUN (show_ip_bgp_ipv4_prefix_list,
7255 show_ip_bgp_ipv4_prefix_list_cmd,
7256 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7257 SHOW_STR
7258 IP_STR
7259 BGP_STR
7260 "Address family\n"
7261 "Address Family modifier\n"
7262 "Address Family modifier\n"
7263 "Display routes conforming to the prefix-list\n"
7264 "IP prefix-list name\n")
7265{
7266 if (strncmp (argv[0], "m", 1) == 0)
7267 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7268 bgp_show_type_prefix_list);
7269
7270 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7271 bgp_show_type_prefix_list);
7272}
7273
7274#ifdef HAVE_IPV6
7275DEFUN (show_bgp_prefix_list,
7276 show_bgp_prefix_list_cmd,
7277 "show bgp prefix-list WORD",
7278 SHOW_STR
7279 BGP_STR
7280 "Display routes conforming to the prefix-list\n"
7281 "IPv6 prefix-list name\n")
7282{
7283 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7284 bgp_show_type_prefix_list);
7285}
7286
7287ALIAS (show_bgp_prefix_list,
7288 show_bgp_ipv6_prefix_list_cmd,
7289 "show bgp ipv6 prefix-list WORD",
7290 SHOW_STR
7291 BGP_STR
7292 "Address family\n"
7293 "Display routes conforming to the prefix-list\n"
7294 "IPv6 prefix-list name\n")
7295
7296/* old command */
7297DEFUN (show_ipv6_bgp_prefix_list,
7298 show_ipv6_bgp_prefix_list_cmd,
7299 "show ipv6 bgp prefix-list WORD",
7300 SHOW_STR
7301 IPV6_STR
7302 BGP_STR
7303 "Display routes matching the prefix-list\n"
7304 "IPv6 prefix-list name\n")
7305{
7306 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7307 bgp_show_type_prefix_list);
7308}
7309
7310/* old command */
7311DEFUN (show_ipv6_mbgp_prefix_list,
7312 show_ipv6_mbgp_prefix_list_cmd,
7313 "show ipv6 mbgp prefix-list WORD",
7314 SHOW_STR
7315 IPV6_STR
7316 MBGP_STR
7317 "Display routes matching the prefix-list\n"
7318 "IPv6 prefix-list name\n")
7319{
7320 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7321 bgp_show_type_prefix_list);
7322}
7323#endif /* HAVE_IPV6 */
7324
paul94f2b392005-06-28 12:44:16 +00007325static int
paulfd79ac92004-10-13 05:06:08 +00007326bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007327 safi_t safi, enum bgp_show_type type)
7328{
7329 struct as_list *as_list;
7330
7331 as_list = as_list_lookup (filter);
7332 if (as_list == NULL)
7333 {
7334 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7335 return CMD_WARNING;
7336 }
7337
ajs5a646652004-11-05 01:25:55 +00007338 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007339}
7340
7341DEFUN (show_ip_bgp_filter_list,
7342 show_ip_bgp_filter_list_cmd,
7343 "show ip bgp filter-list WORD",
7344 SHOW_STR
7345 IP_STR
7346 BGP_STR
7347 "Display routes conforming to the filter-list\n"
7348 "Regular expression access list name\n")
7349{
7350 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7351 bgp_show_type_filter_list);
7352}
7353
7354DEFUN (show_ip_bgp_flap_filter_list,
7355 show_ip_bgp_flap_filter_list_cmd,
7356 "show ip bgp flap-statistics filter-list WORD",
7357 SHOW_STR
7358 IP_STR
7359 BGP_STR
7360 "Display flap statistics of routes\n"
7361 "Display routes conforming to the filter-list\n"
7362 "Regular expression access list name\n")
7363{
7364 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7365 bgp_show_type_flap_filter_list);
7366}
7367
7368DEFUN (show_ip_bgp_ipv4_filter_list,
7369 show_ip_bgp_ipv4_filter_list_cmd,
7370 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7371 SHOW_STR
7372 IP_STR
7373 BGP_STR
7374 "Address family\n"
7375 "Address Family modifier\n"
7376 "Address Family modifier\n"
7377 "Display routes conforming to the filter-list\n"
7378 "Regular expression access list name\n")
7379{
7380 if (strncmp (argv[0], "m", 1) == 0)
7381 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7382 bgp_show_type_filter_list);
7383
7384 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7385 bgp_show_type_filter_list);
7386}
7387
7388#ifdef HAVE_IPV6
7389DEFUN (show_bgp_filter_list,
7390 show_bgp_filter_list_cmd,
7391 "show bgp filter-list WORD",
7392 SHOW_STR
7393 BGP_STR
7394 "Display routes conforming to the filter-list\n"
7395 "Regular expression access list name\n")
7396{
7397 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7398 bgp_show_type_filter_list);
7399}
7400
7401ALIAS (show_bgp_filter_list,
7402 show_bgp_ipv6_filter_list_cmd,
7403 "show bgp ipv6 filter-list WORD",
7404 SHOW_STR
7405 BGP_STR
7406 "Address family\n"
7407 "Display routes conforming to the filter-list\n"
7408 "Regular expression access list name\n")
7409
7410/* old command */
7411DEFUN (show_ipv6_bgp_filter_list,
7412 show_ipv6_bgp_filter_list_cmd,
7413 "show ipv6 bgp filter-list WORD",
7414 SHOW_STR
7415 IPV6_STR
7416 BGP_STR
7417 "Display routes conforming to the filter-list\n"
7418 "Regular expression access list name\n")
7419{
7420 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7421 bgp_show_type_filter_list);
7422}
7423
7424/* old command */
7425DEFUN (show_ipv6_mbgp_filter_list,
7426 show_ipv6_mbgp_filter_list_cmd,
7427 "show ipv6 mbgp filter-list WORD",
7428 SHOW_STR
7429 IPV6_STR
7430 MBGP_STR
7431 "Display routes conforming to the filter-list\n"
7432 "Regular expression access list name\n")
7433{
7434 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7435 bgp_show_type_filter_list);
7436}
7437#endif /* HAVE_IPV6 */
7438
paul94f2b392005-06-28 12:44:16 +00007439static int
paulfd79ac92004-10-13 05:06:08 +00007440bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007441 safi_t safi, enum bgp_show_type type)
7442{
7443 struct route_map *rmap;
7444
7445 rmap = route_map_lookup_by_name (rmap_str);
7446 if (! rmap)
7447 {
7448 vty_out (vty, "%% %s is not a valid route-map name%s",
7449 rmap_str, VTY_NEWLINE);
7450 return CMD_WARNING;
7451 }
7452
ajs5a646652004-11-05 01:25:55 +00007453 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007454}
7455
7456DEFUN (show_ip_bgp_route_map,
7457 show_ip_bgp_route_map_cmd,
7458 "show ip bgp route-map WORD",
7459 SHOW_STR
7460 IP_STR
7461 BGP_STR
7462 "Display routes matching the route-map\n"
7463 "A route-map to match on\n")
7464{
7465 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7466 bgp_show_type_route_map);
7467}
7468
7469DEFUN (show_ip_bgp_flap_route_map,
7470 show_ip_bgp_flap_route_map_cmd,
7471 "show ip bgp flap-statistics route-map WORD",
7472 SHOW_STR
7473 IP_STR
7474 BGP_STR
7475 "Display flap statistics of routes\n"
7476 "Display routes matching the route-map\n"
7477 "A route-map to match on\n")
7478{
7479 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7480 bgp_show_type_flap_route_map);
7481}
7482
7483DEFUN (show_ip_bgp_ipv4_route_map,
7484 show_ip_bgp_ipv4_route_map_cmd,
7485 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7486 SHOW_STR
7487 IP_STR
7488 BGP_STR
7489 "Address family\n"
7490 "Address Family modifier\n"
7491 "Address Family modifier\n"
7492 "Display routes matching the route-map\n"
7493 "A route-map to match on\n")
7494{
7495 if (strncmp (argv[0], "m", 1) == 0)
7496 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7497 bgp_show_type_route_map);
7498
7499 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7500 bgp_show_type_route_map);
7501}
7502
7503DEFUN (show_bgp_route_map,
7504 show_bgp_route_map_cmd,
7505 "show bgp route-map WORD",
7506 SHOW_STR
7507 BGP_STR
7508 "Display routes matching the route-map\n"
7509 "A route-map to match on\n")
7510{
7511 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7512 bgp_show_type_route_map);
7513}
7514
7515ALIAS (show_bgp_route_map,
7516 show_bgp_ipv6_route_map_cmd,
7517 "show bgp ipv6 route-map WORD",
7518 SHOW_STR
7519 BGP_STR
7520 "Address family\n"
7521 "Display routes matching the route-map\n"
7522 "A route-map to match on\n")
7523
7524DEFUN (show_ip_bgp_cidr_only,
7525 show_ip_bgp_cidr_only_cmd,
7526 "show ip bgp cidr-only",
7527 SHOW_STR
7528 IP_STR
7529 BGP_STR
7530 "Display only routes with non-natural netmasks\n")
7531{
7532 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007533 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007534}
7535
7536DEFUN (show_ip_bgp_flap_cidr_only,
7537 show_ip_bgp_flap_cidr_only_cmd,
7538 "show ip bgp flap-statistics cidr-only",
7539 SHOW_STR
7540 IP_STR
7541 BGP_STR
7542 "Display flap statistics of routes\n"
7543 "Display only routes with non-natural netmasks\n")
7544{
7545 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007546 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007547}
7548
7549DEFUN (show_ip_bgp_ipv4_cidr_only,
7550 show_ip_bgp_ipv4_cidr_only_cmd,
7551 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7552 SHOW_STR
7553 IP_STR
7554 BGP_STR
7555 "Address family\n"
7556 "Address Family modifier\n"
7557 "Address Family modifier\n"
7558 "Display only routes with non-natural netmasks\n")
7559{
7560 if (strncmp (argv[0], "m", 1) == 0)
7561 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007562 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007563
7564 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007565 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007566}
7567
7568DEFUN (show_ip_bgp_community_all,
7569 show_ip_bgp_community_all_cmd,
7570 "show ip bgp community",
7571 SHOW_STR
7572 IP_STR
7573 BGP_STR
7574 "Display routes matching the communities\n")
7575{
7576 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007577 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007578}
7579
7580DEFUN (show_ip_bgp_ipv4_community_all,
7581 show_ip_bgp_ipv4_community_all_cmd,
7582 "show ip bgp ipv4 (unicast|multicast) community",
7583 SHOW_STR
7584 IP_STR
7585 BGP_STR
7586 "Address family\n"
7587 "Address Family modifier\n"
7588 "Address Family modifier\n"
7589 "Display routes matching the communities\n")
7590{
7591 if (strncmp (argv[0], "m", 1) == 0)
7592 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007593 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007594
7595 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007596 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007597}
7598
7599#ifdef HAVE_IPV6
7600DEFUN (show_bgp_community_all,
7601 show_bgp_community_all_cmd,
7602 "show bgp community",
7603 SHOW_STR
7604 BGP_STR
7605 "Display routes matching the communities\n")
7606{
7607 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007608 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007609}
7610
7611ALIAS (show_bgp_community_all,
7612 show_bgp_ipv6_community_all_cmd,
7613 "show bgp ipv6 community",
7614 SHOW_STR
7615 BGP_STR
7616 "Address family\n"
7617 "Display routes matching the communities\n")
7618
7619/* old command */
7620DEFUN (show_ipv6_bgp_community_all,
7621 show_ipv6_bgp_community_all_cmd,
7622 "show ipv6 bgp community",
7623 SHOW_STR
7624 IPV6_STR
7625 BGP_STR
7626 "Display routes matching the communities\n")
7627{
7628 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007629 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007630}
7631
7632/* old command */
7633DEFUN (show_ipv6_mbgp_community_all,
7634 show_ipv6_mbgp_community_all_cmd,
7635 "show ipv6 mbgp community",
7636 SHOW_STR
7637 IPV6_STR
7638 MBGP_STR
7639 "Display routes matching the communities\n")
7640{
7641 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007642 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007643}
7644#endif /* HAVE_IPV6 */
7645
paul94f2b392005-06-28 12:44:16 +00007646static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007647bgp_show_community (struct vty *vty, const char *view_name, int argc,
7648 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007649{
7650 struct community *com;
7651 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007652 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007653 int i;
7654 char *str;
7655 int first = 0;
7656
Michael Lambert95cbbd22010-07-23 14:43:04 -04007657 /* BGP structure lookup */
7658 if (view_name)
7659 {
7660 bgp = bgp_lookup_by_name (view_name);
7661 if (bgp == NULL)
7662 {
7663 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7664 return CMD_WARNING;
7665 }
7666 }
7667 else
7668 {
7669 bgp = bgp_get_default ();
7670 if (bgp == NULL)
7671 {
7672 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7673 return CMD_WARNING;
7674 }
7675 }
7676
paul718e3742002-12-13 20:15:29 +00007677 b = buffer_new (1024);
7678 for (i = 0; i < argc; i++)
7679 {
7680 if (first)
7681 buffer_putc (b, ' ');
7682 else
7683 {
7684 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7685 continue;
7686 first = 1;
7687 }
7688
7689 buffer_putstr (b, argv[i]);
7690 }
7691 buffer_putc (b, '\0');
7692
7693 str = buffer_getstr (b);
7694 buffer_free (b);
7695
7696 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007697 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007698 if (! com)
7699 {
7700 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7701 return CMD_WARNING;
7702 }
7703
Michael Lambert95cbbd22010-07-23 14:43:04 -04007704 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007705 (exact ? bgp_show_type_community_exact :
7706 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007707}
7708
7709DEFUN (show_ip_bgp_community,
7710 show_ip_bgp_community_cmd,
7711 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7712 SHOW_STR
7713 IP_STR
7714 BGP_STR
7715 "Display routes matching the communities\n"
7716 "community number\n"
7717 "Do not send outside local AS (well-known community)\n"
7718 "Do not advertise to any peer (well-known community)\n"
7719 "Do not export to next AS (well-known community)\n")
7720{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007721 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007722}
7723
7724ALIAS (show_ip_bgp_community,
7725 show_ip_bgp_community2_cmd,
7726 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7727 SHOW_STR
7728 IP_STR
7729 BGP_STR
7730 "Display routes matching the communities\n"
7731 "community number\n"
7732 "Do not send outside local AS (well-known community)\n"
7733 "Do not advertise to any peer (well-known community)\n"
7734 "Do not export to next AS (well-known community)\n"
7735 "community number\n"
7736 "Do not send outside local AS (well-known community)\n"
7737 "Do not advertise to any peer (well-known community)\n"
7738 "Do not export to next AS (well-known community)\n")
7739
7740ALIAS (show_ip_bgp_community,
7741 show_ip_bgp_community3_cmd,
7742 "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)",
7743 SHOW_STR
7744 IP_STR
7745 BGP_STR
7746 "Display routes matching the communities\n"
7747 "community number\n"
7748 "Do not send outside local AS (well-known community)\n"
7749 "Do not advertise to any peer (well-known community)\n"
7750 "Do not export to next AS (well-known community)\n"
7751 "community number\n"
7752 "Do not send outside local AS (well-known community)\n"
7753 "Do not advertise to any peer (well-known community)\n"
7754 "Do not export to next AS (well-known community)\n"
7755 "community number\n"
7756 "Do not send outside local AS (well-known community)\n"
7757 "Do not advertise to any peer (well-known community)\n"
7758 "Do not export to next AS (well-known community)\n")
7759
7760ALIAS (show_ip_bgp_community,
7761 show_ip_bgp_community4_cmd,
7762 "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)",
7763 SHOW_STR
7764 IP_STR
7765 BGP_STR
7766 "Display routes matching the communities\n"
7767 "community number\n"
7768 "Do not send outside local AS (well-known community)\n"
7769 "Do not advertise to any peer (well-known community)\n"
7770 "Do not export to next AS (well-known community)\n"
7771 "community number\n"
7772 "Do not send outside local AS (well-known community)\n"
7773 "Do not advertise to any peer (well-known community)\n"
7774 "Do not export to next AS (well-known community)\n"
7775 "community number\n"
7776 "Do not send outside local AS (well-known community)\n"
7777 "Do not advertise to any peer (well-known community)\n"
7778 "Do not export to next AS (well-known community)\n"
7779 "community number\n"
7780 "Do not send outside local AS (well-known community)\n"
7781 "Do not advertise to any peer (well-known community)\n"
7782 "Do not export to next AS (well-known community)\n")
7783
7784DEFUN (show_ip_bgp_ipv4_community,
7785 show_ip_bgp_ipv4_community_cmd,
7786 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7787 SHOW_STR
7788 IP_STR
7789 BGP_STR
7790 "Address family\n"
7791 "Address Family modifier\n"
7792 "Address Family modifier\n"
7793 "Display routes matching the communities\n"
7794 "community number\n"
7795 "Do not send outside local AS (well-known community)\n"
7796 "Do not advertise to any peer (well-known community)\n"
7797 "Do not export to next AS (well-known community)\n")
7798{
7799 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007800 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007801
Michael Lambert95cbbd22010-07-23 14:43:04 -04007802 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007803}
7804
7805ALIAS (show_ip_bgp_ipv4_community,
7806 show_ip_bgp_ipv4_community2_cmd,
7807 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7808 SHOW_STR
7809 IP_STR
7810 BGP_STR
7811 "Address family\n"
7812 "Address Family modifier\n"
7813 "Address Family modifier\n"
7814 "Display routes matching the communities\n"
7815 "community number\n"
7816 "Do not send outside local AS (well-known community)\n"
7817 "Do not advertise to any peer (well-known community)\n"
7818 "Do not export to next AS (well-known community)\n"
7819 "community number\n"
7820 "Do not send outside local AS (well-known community)\n"
7821 "Do not advertise to any peer (well-known community)\n"
7822 "Do not export to next AS (well-known community)\n")
7823
7824ALIAS (show_ip_bgp_ipv4_community,
7825 show_ip_bgp_ipv4_community3_cmd,
7826 "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)",
7827 SHOW_STR
7828 IP_STR
7829 BGP_STR
7830 "Address family\n"
7831 "Address Family modifier\n"
7832 "Address Family modifier\n"
7833 "Display routes matching the communities\n"
7834 "community number\n"
7835 "Do not send outside local AS (well-known community)\n"
7836 "Do not advertise to any peer (well-known community)\n"
7837 "Do not export to next AS (well-known community)\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n"
7842 "community number\n"
7843 "Do not send outside local AS (well-known community)\n"
7844 "Do not advertise to any peer (well-known community)\n"
7845 "Do not export to next AS (well-known community)\n")
7846
7847ALIAS (show_ip_bgp_ipv4_community,
7848 show_ip_bgp_ipv4_community4_cmd,
7849 "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)",
7850 SHOW_STR
7851 IP_STR
7852 BGP_STR
7853 "Address family\n"
7854 "Address Family modifier\n"
7855 "Address Family modifier\n"
7856 "Display routes matching the communities\n"
7857 "community number\n"
7858 "Do not send outside local AS (well-known community)\n"
7859 "Do not advertise to any peer (well-known community)\n"
7860 "Do not export to next AS (well-known community)\n"
7861 "community number\n"
7862 "Do not send outside local AS (well-known community)\n"
7863 "Do not advertise to any peer (well-known community)\n"
7864 "Do not export to next AS (well-known community)\n"
7865 "community number\n"
7866 "Do not send outside local AS (well-known community)\n"
7867 "Do not advertise to any peer (well-known community)\n"
7868 "Do not export to next AS (well-known community)\n"
7869 "community number\n"
7870 "Do not send outside local AS (well-known community)\n"
7871 "Do not advertise to any peer (well-known community)\n"
7872 "Do not export to next AS (well-known community)\n")
7873
Michael Lambert95cbbd22010-07-23 14:43:04 -04007874DEFUN (show_bgp_view_afi_safi_community_all,
7875 show_bgp_view_afi_safi_community_all_cmd,
7876#ifdef HAVE_IPV6
7877 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7878#else
7879 "show bgp view WORD ipv4 (unicast|multicast) community",
7880#endif
7881 SHOW_STR
7882 BGP_STR
7883 "BGP view\n"
7884 "BGP view name\n"
7885 "Address family\n"
7886#ifdef HAVE_IPV6
7887 "Address family\n"
7888#endif
7889 "Address Family modifier\n"
7890 "Address Family modifier\n"
7891 "Display routes containing communities\n")
7892{
7893 int afi;
7894 int safi;
7895 struct bgp *bgp;
7896
7897 /* BGP structure lookup. */
7898 bgp = bgp_lookup_by_name (argv[0]);
7899 if (bgp == NULL)
7900 {
7901 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7902 return CMD_WARNING;
7903 }
7904
7905#ifdef HAVE_IPV6
7906 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7907 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7908#else
7909 afi = AFI_IP;
7910 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7911#endif
7912 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7913}
7914
7915DEFUN (show_bgp_view_afi_safi_community,
7916 show_bgp_view_afi_safi_community_cmd,
7917#ifdef HAVE_IPV6
7918 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7919#else
7920 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7921#endif
7922 SHOW_STR
7923 BGP_STR
7924 "BGP view\n"
7925 "BGP view name\n"
7926 "Address family\n"
7927#ifdef HAVE_IPV6
7928 "Address family\n"
7929#endif
7930 "Address family modifier\n"
7931 "Address family modifier\n"
7932 "Display routes matching the communities\n"
7933 "community number\n"
7934 "Do not send outside local AS (well-known community)\n"
7935 "Do not advertise to any peer (well-known community)\n"
7936 "Do not export to next AS (well-known community)\n")
7937{
7938 int afi;
7939 int safi;
7940
7941#ifdef HAVE_IPV6
7942 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7943 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7944 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7945#else
7946 afi = AFI_IP;
7947 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7948 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7949#endif
7950}
7951
7952ALIAS (show_bgp_view_afi_safi_community,
7953 show_bgp_view_afi_safi_community2_cmd,
7954#ifdef HAVE_IPV6
7955 "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)",
7956#else
7957 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7958#endif
7959 SHOW_STR
7960 BGP_STR
7961 "BGP view\n"
7962 "BGP view name\n"
7963 "Address family\n"
7964#ifdef HAVE_IPV6
7965 "Address family\n"
7966#endif
7967 "Address family modifier\n"
7968 "Address family modifier\n"
7969 "Display routes matching the communities\n"
7970 "community number\n"
7971 "Do not send outside local AS (well-known community)\n"
7972 "Do not advertise to any peer (well-known community)\n"
7973 "Do not export to next AS (well-known community)\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n")
7978
7979ALIAS (show_bgp_view_afi_safi_community,
7980 show_bgp_view_afi_safi_community3_cmd,
7981#ifdef HAVE_IPV6
7982 "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)",
7983#else
7984 "show bgp view WORD 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)",
7985#endif
7986 SHOW_STR
7987 BGP_STR
7988 "BGP view\n"
7989 "BGP view name\n"
7990 "Address family\n"
7991#ifdef HAVE_IPV6
7992 "Address family\n"
7993#endif
7994 "Address family modifier\n"
7995 "Address family modifier\n"
7996 "Display routes matching the communities\n"
7997 "community number\n"
7998 "Do not send outside local AS (well-known community)\n"
7999 "Do not advertise to any peer (well-known community)\n"
8000 "Do not export to next AS (well-known community)\n"
8001 "community number\n"
8002 "Do not send outside local AS (well-known community)\n"
8003 "Do not advertise to any peer (well-known community)\n"
8004 "Do not export to next AS (well-known community)\n"
8005 "community number\n"
8006 "Do not send outside local AS (well-known community)\n"
8007 "Do not advertise to any peer (well-known community)\n"
8008 "Do not export to next AS (well-known community)\n")
8009
8010ALIAS (show_bgp_view_afi_safi_community,
8011 show_bgp_view_afi_safi_community4_cmd,
8012#ifdef HAVE_IPV6
8013 "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)",
8014#else
8015 "show bgp view WORD 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)",
8016#endif
8017 SHOW_STR
8018 BGP_STR
8019 "BGP view\n"
8020 "BGP view name\n"
8021 "Address family\n"
8022#ifdef HAVE_IPV6
8023 "Address family\n"
8024#endif
8025 "Address family modifier\n"
8026 "Address family modifier\n"
8027 "Display routes matching the communities\n"
8028 "community number\n"
8029 "Do not send outside local AS (well-known community)\n"
8030 "Do not advertise to any peer (well-known community)\n"
8031 "Do not export to next AS (well-known community)\n"
8032 "community number\n"
8033 "Do not send outside local AS (well-known community)\n"
8034 "Do not advertise to any peer (well-known community)\n"
8035 "Do not export to next AS (well-known community)\n"
8036 "community number\n"
8037 "Do not send outside local AS (well-known community)\n"
8038 "Do not advertise to any peer (well-known community)\n"
8039 "Do not export to next AS (well-known community)\n"
8040 "community number\n"
8041 "Do not send outside local AS (well-known community)\n"
8042 "Do not advertise to any peer (well-known community)\n"
8043 "Do not export to next AS (well-known community)\n")
8044
paul718e3742002-12-13 20:15:29 +00008045DEFUN (show_ip_bgp_community_exact,
8046 show_ip_bgp_community_exact_cmd,
8047 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8048 SHOW_STR
8049 IP_STR
8050 BGP_STR
8051 "Display routes matching the communities\n"
8052 "community number\n"
8053 "Do not send outside local AS (well-known community)\n"
8054 "Do not advertise to any peer (well-known community)\n"
8055 "Do not export to next AS (well-known community)\n"
8056 "Exact match of the communities")
8057{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008058 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008059}
8060
8061ALIAS (show_ip_bgp_community_exact,
8062 show_ip_bgp_community2_exact_cmd,
8063 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8064 SHOW_STR
8065 IP_STR
8066 BGP_STR
8067 "Display routes matching the communities\n"
8068 "community number\n"
8069 "Do not send outside local AS (well-known community)\n"
8070 "Do not advertise to any peer (well-known community)\n"
8071 "Do not export to next AS (well-known community)\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "Exact match of the communities")
8077
8078ALIAS (show_ip_bgp_community_exact,
8079 show_ip_bgp_community3_exact_cmd,
8080 "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",
8081 SHOW_STR
8082 IP_STR
8083 BGP_STR
8084 "Display routes matching the communities\n"
8085 "community number\n"
8086 "Do not send outside local AS (well-known community)\n"
8087 "Do not advertise to any peer (well-known community)\n"
8088 "Do not export to next AS (well-known community)\n"
8089 "community number\n"
8090 "Do not send outside local AS (well-known community)\n"
8091 "Do not advertise to any peer (well-known community)\n"
8092 "Do not export to next AS (well-known community)\n"
8093 "community number\n"
8094 "Do not send outside local AS (well-known community)\n"
8095 "Do not advertise to any peer (well-known community)\n"
8096 "Do not export to next AS (well-known community)\n"
8097 "Exact match of the communities")
8098
8099ALIAS (show_ip_bgp_community_exact,
8100 show_ip_bgp_community4_exact_cmd,
8101 "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",
8102 SHOW_STR
8103 IP_STR
8104 BGP_STR
8105 "Display routes matching the communities\n"
8106 "community number\n"
8107 "Do not send outside local AS (well-known community)\n"
8108 "Do not advertise to any peer (well-known community)\n"
8109 "Do not export to next AS (well-known community)\n"
8110 "community number\n"
8111 "Do not send outside local AS (well-known community)\n"
8112 "Do not advertise to any peer (well-known community)\n"
8113 "Do not export to next AS (well-known community)\n"
8114 "community number\n"
8115 "Do not send outside local AS (well-known community)\n"
8116 "Do not advertise to any peer (well-known community)\n"
8117 "Do not export to next AS (well-known community)\n"
8118 "community number\n"
8119 "Do not send outside local AS (well-known community)\n"
8120 "Do not advertise to any peer (well-known community)\n"
8121 "Do not export to next AS (well-known community)\n"
8122 "Exact match of the communities")
8123
8124DEFUN (show_ip_bgp_ipv4_community_exact,
8125 show_ip_bgp_ipv4_community_exact_cmd,
8126 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8127 SHOW_STR
8128 IP_STR
8129 BGP_STR
8130 "Address family\n"
8131 "Address Family modifier\n"
8132 "Address Family modifier\n"
8133 "Display routes matching the communities\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n"
8138 "Exact match of the communities")
8139{
8140 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008141 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008142
Michael Lambert95cbbd22010-07-23 14:43:04 -04008143 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008144}
8145
8146ALIAS (show_ip_bgp_ipv4_community_exact,
8147 show_ip_bgp_ipv4_community2_exact_cmd,
8148 "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",
8149 SHOW_STR
8150 IP_STR
8151 BGP_STR
8152 "Address family\n"
8153 "Address Family modifier\n"
8154 "Address Family modifier\n"
8155 "Display routes matching the communities\n"
8156 "community number\n"
8157 "Do not send outside local AS (well-known community)\n"
8158 "Do not advertise to any peer (well-known community)\n"
8159 "Do not export to next AS (well-known community)\n"
8160 "community number\n"
8161 "Do not send outside local AS (well-known community)\n"
8162 "Do not advertise to any peer (well-known community)\n"
8163 "Do not export to next AS (well-known community)\n"
8164 "Exact match of the communities")
8165
8166ALIAS (show_ip_bgp_ipv4_community_exact,
8167 show_ip_bgp_ipv4_community3_exact_cmd,
8168 "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",
8169 SHOW_STR
8170 IP_STR
8171 BGP_STR
8172 "Address family\n"
8173 "Address Family modifier\n"
8174 "Address Family modifier\n"
8175 "Display routes matching the communities\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n"
8180 "community number\n"
8181 "Do not send outside local AS (well-known community)\n"
8182 "Do not advertise to any peer (well-known community)\n"
8183 "Do not export to next AS (well-known community)\n"
8184 "community number\n"
8185 "Do not send outside local AS (well-known community)\n"
8186 "Do not advertise to any peer (well-known community)\n"
8187 "Do not export to next AS (well-known community)\n"
8188 "Exact match of the communities")
8189
8190ALIAS (show_ip_bgp_ipv4_community_exact,
8191 show_ip_bgp_ipv4_community4_exact_cmd,
8192 "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",
8193 SHOW_STR
8194 IP_STR
8195 BGP_STR
8196 "Address family\n"
8197 "Address Family modifier\n"
8198 "Address Family modifier\n"
8199 "Display routes matching the communities\n"
8200 "community number\n"
8201 "Do not send outside local AS (well-known community)\n"
8202 "Do not advertise to any peer (well-known community)\n"
8203 "Do not export to next AS (well-known community)\n"
8204 "community number\n"
8205 "Do not send outside local AS (well-known community)\n"
8206 "Do not advertise to any peer (well-known community)\n"
8207 "Do not export to next AS (well-known community)\n"
8208 "community number\n"
8209 "Do not send outside local AS (well-known community)\n"
8210 "Do not advertise to any peer (well-known community)\n"
8211 "Do not export to next AS (well-known community)\n"
8212 "community number\n"
8213 "Do not send outside local AS (well-known community)\n"
8214 "Do not advertise to any peer (well-known community)\n"
8215 "Do not export to next AS (well-known community)\n"
8216 "Exact match of the communities")
8217
8218#ifdef HAVE_IPV6
8219DEFUN (show_bgp_community,
8220 show_bgp_community_cmd,
8221 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8222 SHOW_STR
8223 BGP_STR
8224 "Display routes matching the communities\n"
8225 "community number\n"
8226 "Do not send outside local AS (well-known community)\n"
8227 "Do not advertise to any peer (well-known community)\n"
8228 "Do not export to next AS (well-known community)\n")
8229{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008230 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008231}
8232
8233ALIAS (show_bgp_community,
8234 show_bgp_ipv6_community_cmd,
8235 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8236 SHOW_STR
8237 BGP_STR
8238 "Address family\n"
8239 "Display routes matching the communities\n"
8240 "community number\n"
8241 "Do not send outside local AS (well-known community)\n"
8242 "Do not advertise to any peer (well-known community)\n"
8243 "Do not export to next AS (well-known community)\n")
8244
8245ALIAS (show_bgp_community,
8246 show_bgp_community2_cmd,
8247 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8248 SHOW_STR
8249 BGP_STR
8250 "Display routes matching the communities\n"
8251 "community number\n"
8252 "Do not send outside local AS (well-known community)\n"
8253 "Do not advertise to any peer (well-known community)\n"
8254 "Do not export to next AS (well-known community)\n"
8255 "community number\n"
8256 "Do not send outside local AS (well-known community)\n"
8257 "Do not advertise to any peer (well-known community)\n"
8258 "Do not export to next AS (well-known community)\n")
8259
8260ALIAS (show_bgp_community,
8261 show_bgp_ipv6_community2_cmd,
8262 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8263 SHOW_STR
8264 BGP_STR
8265 "Address family\n"
8266 "Display routes matching the communities\n"
8267 "community number\n"
8268 "Do not send outside local AS (well-known community)\n"
8269 "Do not advertise to any peer (well-known community)\n"
8270 "Do not export to next AS (well-known community)\n"
8271 "community number\n"
8272 "Do not send outside local AS (well-known community)\n"
8273 "Do not advertise to any peer (well-known community)\n"
8274 "Do not export to next AS (well-known community)\n")
8275
8276ALIAS (show_bgp_community,
8277 show_bgp_community3_cmd,
8278 "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)",
8279 SHOW_STR
8280 BGP_STR
8281 "Display routes matching the communities\n"
8282 "community number\n"
8283 "Do not send outside local AS (well-known community)\n"
8284 "Do not advertise to any peer (well-known community)\n"
8285 "Do not export to next AS (well-known community)\n"
8286 "community number\n"
8287 "Do not send outside local AS (well-known community)\n"
8288 "Do not advertise to any peer (well-known community)\n"
8289 "Do not export to next AS (well-known community)\n"
8290 "community number\n"
8291 "Do not send outside local AS (well-known community)\n"
8292 "Do not advertise to any peer (well-known community)\n"
8293 "Do not export to next AS (well-known community)\n")
8294
8295ALIAS (show_bgp_community,
8296 show_bgp_ipv6_community3_cmd,
8297 "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)",
8298 SHOW_STR
8299 BGP_STR
8300 "Address family\n"
8301 "Display routes matching the communities\n"
8302 "community number\n"
8303 "Do not send outside local AS (well-known community)\n"
8304 "Do not advertise to any peer (well-known community)\n"
8305 "Do not export to next AS (well-known community)\n"
8306 "community number\n"
8307 "Do not send outside local AS (well-known community)\n"
8308 "Do not advertise to any peer (well-known community)\n"
8309 "Do not export to next AS (well-known community)\n"
8310 "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
8315ALIAS (show_bgp_community,
8316 show_bgp_community4_cmd,
8317 "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)",
8318 SHOW_STR
8319 BGP_STR
8320 "Display routes matching the communities\n"
8321 "community number\n"
8322 "Do not send outside local AS (well-known community)\n"
8323 "Do not advertise to any peer (well-known community)\n"
8324 "Do not export to next AS (well-known community)\n"
8325 "community number\n"
8326 "Do not send outside local AS (well-known community)\n"
8327 "Do not advertise to any peer (well-known community)\n"
8328 "Do not export to next AS (well-known community)\n"
8329 "community number\n"
8330 "Do not send outside local AS (well-known community)\n"
8331 "Do not advertise to any peer (well-known community)\n"
8332 "Do not export to next AS (well-known community)\n"
8333 "community number\n"
8334 "Do not send outside local AS (well-known community)\n"
8335 "Do not advertise to any peer (well-known community)\n"
8336 "Do not export to next AS (well-known community)\n")
8337
8338ALIAS (show_bgp_community,
8339 show_bgp_ipv6_community4_cmd,
8340 "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)",
8341 SHOW_STR
8342 BGP_STR
8343 "Address family\n"
8344 "Display routes matching the communities\n"
8345 "community number\n"
8346 "Do not send outside local AS (well-known community)\n"
8347 "Do not advertise to any peer (well-known community)\n"
8348 "Do not export to next AS (well-known community)\n"
8349 "community number\n"
8350 "Do not send outside local AS (well-known community)\n"
8351 "Do not advertise to any peer (well-known community)\n"
8352 "Do not export to next AS (well-known community)\n"
8353 "community number\n"
8354 "Do not send outside local AS (well-known community)\n"
8355 "Do not advertise to any peer (well-known community)\n"
8356 "Do not export to next AS (well-known community)\n"
8357 "community number\n"
8358 "Do not send outside local AS (well-known community)\n"
8359 "Do not advertise to any peer (well-known community)\n"
8360 "Do not export to next AS (well-known community)\n")
8361
8362/* old command */
8363DEFUN (show_ipv6_bgp_community,
8364 show_ipv6_bgp_community_cmd,
8365 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8366 SHOW_STR
8367 IPV6_STR
8368 BGP_STR
8369 "Display routes matching the communities\n"
8370 "community number\n"
8371 "Do not send outside local AS (well-known community)\n"
8372 "Do not advertise to any peer (well-known community)\n"
8373 "Do not export to next AS (well-known community)\n")
8374{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008375 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008376}
8377
8378/* old command */
8379ALIAS (show_ipv6_bgp_community,
8380 show_ipv6_bgp_community2_cmd,
8381 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8382 SHOW_STR
8383 IPV6_STR
8384 BGP_STR
8385 "Display routes matching the communities\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n"
8390 "community number\n"
8391 "Do not send outside local AS (well-known community)\n"
8392 "Do not advertise to any peer (well-known community)\n"
8393 "Do not export to next AS (well-known community)\n")
8394
8395/* old command */
8396ALIAS (show_ipv6_bgp_community,
8397 show_ipv6_bgp_community3_cmd,
8398 "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)",
8399 SHOW_STR
8400 IPV6_STR
8401 BGP_STR
8402 "Display routes matching the communities\n"
8403 "community number\n"
8404 "Do not send outside local AS (well-known community)\n"
8405 "Do not advertise to any peer (well-known community)\n"
8406 "Do not export to next AS (well-known community)\n"
8407 "community number\n"
8408 "Do not send outside local AS (well-known community)\n"
8409 "Do not advertise to any peer (well-known community)\n"
8410 "Do not export to next AS (well-known community)\n"
8411 "community number\n"
8412 "Do not send outside local AS (well-known community)\n"
8413 "Do not advertise to any peer (well-known community)\n"
8414 "Do not export to next AS (well-known community)\n")
8415
8416/* old command */
8417ALIAS (show_ipv6_bgp_community,
8418 show_ipv6_bgp_community4_cmd,
8419 "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)",
8420 SHOW_STR
8421 IPV6_STR
8422 BGP_STR
8423 "Display routes matching the communities\n"
8424 "community number\n"
8425 "Do not send outside local AS (well-known community)\n"
8426 "Do not advertise to any peer (well-known community)\n"
8427 "Do not export to next AS (well-known community)\n"
8428 "community number\n"
8429 "Do not send outside local AS (well-known community)\n"
8430 "Do not advertise to any peer (well-known community)\n"
8431 "Do not export to next AS (well-known community)\n"
8432 "community number\n"
8433 "Do not send outside local AS (well-known community)\n"
8434 "Do not advertise to any peer (well-known community)\n"
8435 "Do not export to next AS (well-known community)\n"
8436 "community number\n"
8437 "Do not send outside local AS (well-known community)\n"
8438 "Do not advertise to any peer (well-known community)\n"
8439 "Do not export to next AS (well-known community)\n")
8440
8441DEFUN (show_bgp_community_exact,
8442 show_bgp_community_exact_cmd,
8443 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8444 SHOW_STR
8445 BGP_STR
8446 "Display routes matching the communities\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "Exact match of the communities")
8452{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008453 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008454}
8455
8456ALIAS (show_bgp_community_exact,
8457 show_bgp_ipv6_community_exact_cmd,
8458 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8459 SHOW_STR
8460 BGP_STR
8461 "Address family\n"
8462 "Display routes matching the communities\n"
8463 "community number\n"
8464 "Do not send outside local AS (well-known community)\n"
8465 "Do not advertise to any peer (well-known community)\n"
8466 "Do not export to next AS (well-known community)\n"
8467 "Exact match of the communities")
8468
8469ALIAS (show_bgp_community_exact,
8470 show_bgp_community2_exact_cmd,
8471 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8472 SHOW_STR
8473 BGP_STR
8474 "Display routes matching the communities\n"
8475 "community number\n"
8476 "Do not send outside local AS (well-known community)\n"
8477 "Do not advertise to any peer (well-known community)\n"
8478 "Do not export to next AS (well-known community)\n"
8479 "community number\n"
8480 "Do not send outside local AS (well-known community)\n"
8481 "Do not advertise to any peer (well-known community)\n"
8482 "Do not export to next AS (well-known community)\n"
8483 "Exact match of the communities")
8484
8485ALIAS (show_bgp_community_exact,
8486 show_bgp_ipv6_community2_exact_cmd,
8487 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8488 SHOW_STR
8489 BGP_STR
8490 "Address family\n"
8491 "Display routes matching the communities\n"
8492 "community number\n"
8493 "Do not send outside local AS (well-known community)\n"
8494 "Do not advertise to any peer (well-known community)\n"
8495 "Do not export to next AS (well-known community)\n"
8496 "community number\n"
8497 "Do not send outside local AS (well-known community)\n"
8498 "Do not advertise to any peer (well-known community)\n"
8499 "Do not export to next AS (well-known community)\n"
8500 "Exact match of the communities")
8501
8502ALIAS (show_bgp_community_exact,
8503 show_bgp_community3_exact_cmd,
8504 "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",
8505 SHOW_STR
8506 BGP_STR
8507 "Display routes matching the communities\n"
8508 "community number\n"
8509 "Do not send outside local AS (well-known community)\n"
8510 "Do not advertise to any peer (well-known community)\n"
8511 "Do not export to next AS (well-known community)\n"
8512 "community number\n"
8513 "Do not send outside local AS (well-known community)\n"
8514 "Do not advertise to any peer (well-known community)\n"
8515 "Do not export to next AS (well-known community)\n"
8516 "community number\n"
8517 "Do not send outside local AS (well-known community)\n"
8518 "Do not advertise to any peer (well-known community)\n"
8519 "Do not export to next AS (well-known community)\n"
8520 "Exact match of the communities")
8521
8522ALIAS (show_bgp_community_exact,
8523 show_bgp_ipv6_community3_exact_cmd,
8524 "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",
8525 SHOW_STR
8526 BGP_STR
8527 "Address family\n"
8528 "Display routes matching the communities\n"
8529 "community number\n"
8530 "Do not send outside local AS (well-known community)\n"
8531 "Do not advertise to any peer (well-known community)\n"
8532 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8542
8543ALIAS (show_bgp_community_exact,
8544 show_bgp_community4_exact_cmd,
8545 "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",
8546 SHOW_STR
8547 BGP_STR
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 "community number\n"
8558 "Do not send outside local AS (well-known community)\n"
8559 "Do not advertise to any peer (well-known community)\n"
8560 "Do not export to next AS (well-known community)\n"
8561 "community number\n"
8562 "Do not send outside local AS (well-known community)\n"
8563 "Do not advertise to any peer (well-known community)\n"
8564 "Do not export to next AS (well-known community)\n"
8565 "Exact match of the communities")
8566
8567ALIAS (show_bgp_community_exact,
8568 show_bgp_ipv6_community4_exact_cmd,
8569 "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",
8570 SHOW_STR
8571 BGP_STR
8572 "Address family\n"
8573 "Display routes matching the communities\n"
8574 "community number\n"
8575 "Do not send outside local AS (well-known community)\n"
8576 "Do not advertise to any peer (well-known community)\n"
8577 "Do not export to next AS (well-known community)\n"
8578 "community number\n"
8579 "Do not send outside local AS (well-known community)\n"
8580 "Do not advertise to any peer (well-known community)\n"
8581 "Do not export to next AS (well-known community)\n"
8582 "community number\n"
8583 "Do not send outside local AS (well-known community)\n"
8584 "Do not advertise to any peer (well-known community)\n"
8585 "Do not export to next AS (well-known community)\n"
8586 "community number\n"
8587 "Do not send outside local AS (well-known community)\n"
8588 "Do not advertise to any peer (well-known community)\n"
8589 "Do not export to next AS (well-known community)\n"
8590 "Exact match of the communities")
8591
8592/* old command */
8593DEFUN (show_ipv6_bgp_community_exact,
8594 show_ipv6_bgp_community_exact_cmd,
8595 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8596 SHOW_STR
8597 IPV6_STR
8598 BGP_STR
8599 "Display routes matching the communities\n"
8600 "community number\n"
8601 "Do not send outside local AS (well-known community)\n"
8602 "Do not advertise to any peer (well-known community)\n"
8603 "Do not export to next AS (well-known community)\n"
8604 "Exact match of the communities")
8605{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008606 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008607}
8608
8609/* old command */
8610ALIAS (show_ipv6_bgp_community_exact,
8611 show_ipv6_bgp_community2_exact_cmd,
8612 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8613 SHOW_STR
8614 IPV6_STR
8615 BGP_STR
8616 "Display routes matching the communities\n"
8617 "community number\n"
8618 "Do not send outside local AS (well-known community)\n"
8619 "Do not advertise to any peer (well-known community)\n"
8620 "Do not export to next AS (well-known community)\n"
8621 "community number\n"
8622 "Do not send outside local AS (well-known community)\n"
8623 "Do not advertise to any peer (well-known community)\n"
8624 "Do not export to next AS (well-known community)\n"
8625 "Exact match of the communities")
8626
8627/* old command */
8628ALIAS (show_ipv6_bgp_community_exact,
8629 show_ipv6_bgp_community3_exact_cmd,
8630 "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",
8631 SHOW_STR
8632 IPV6_STR
8633 BGP_STR
8634 "Display routes matching the communities\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 "community number\n"
8644 "Do not send outside local AS (well-known community)\n"
8645 "Do not advertise to any peer (well-known community)\n"
8646 "Do not export to next AS (well-known community)\n"
8647 "Exact match of the communities")
8648
8649/* old command */
8650ALIAS (show_ipv6_bgp_community_exact,
8651 show_ipv6_bgp_community4_exact_cmd,
8652 "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",
8653 SHOW_STR
8654 IPV6_STR
8655 BGP_STR
8656 "Display routes matching the communities\n"
8657 "community number\n"
8658 "Do not send outside local AS (well-known community)\n"
8659 "Do not advertise to any peer (well-known community)\n"
8660 "Do not export to next AS (well-known community)\n"
8661 "community number\n"
8662 "Do not send outside local AS (well-known community)\n"
8663 "Do not advertise to any peer (well-known community)\n"
8664 "Do not export to next AS (well-known community)\n"
8665 "community number\n"
8666 "Do not send outside local AS (well-known community)\n"
8667 "Do not advertise to any peer (well-known community)\n"
8668 "Do not export to next AS (well-known community)\n"
8669 "community number\n"
8670 "Do not send outside local AS (well-known community)\n"
8671 "Do not advertise to any peer (well-known community)\n"
8672 "Do not export to next AS (well-known community)\n"
8673 "Exact match of the communities")
8674
8675/* old command */
8676DEFUN (show_ipv6_mbgp_community,
8677 show_ipv6_mbgp_community_cmd,
8678 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8679 SHOW_STR
8680 IPV6_STR
8681 MBGP_STR
8682 "Display routes matching the communities\n"
8683 "community number\n"
8684 "Do not send outside local AS (well-known community)\n"
8685 "Do not advertise to any peer (well-known community)\n"
8686 "Do not export to next AS (well-known community)\n")
8687{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008688 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008689}
8690
8691/* old command */
8692ALIAS (show_ipv6_mbgp_community,
8693 show_ipv6_mbgp_community2_cmd,
8694 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8695 SHOW_STR
8696 IPV6_STR
8697 MBGP_STR
8698 "Display routes matching the communities\n"
8699 "community number\n"
8700 "Do not send outside local AS (well-known community)\n"
8701 "Do not advertise to any peer (well-known community)\n"
8702 "Do not export to next AS (well-known community)\n"
8703 "community number\n"
8704 "Do not send outside local AS (well-known community)\n"
8705 "Do not advertise to any peer (well-known community)\n"
8706 "Do not export to next AS (well-known community)\n")
8707
8708/* old command */
8709ALIAS (show_ipv6_mbgp_community,
8710 show_ipv6_mbgp_community3_cmd,
8711 "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)",
8712 SHOW_STR
8713 IPV6_STR
8714 MBGP_STR
8715 "Display routes matching the communities\n"
8716 "community number\n"
8717 "Do not send outside local AS (well-known community)\n"
8718 "Do not advertise to any peer (well-known community)\n"
8719 "Do not export to next AS (well-known community)\n"
8720 "community number\n"
8721 "Do not send outside local AS (well-known community)\n"
8722 "Do not advertise to any peer (well-known community)\n"
8723 "Do not export to next AS (well-known community)\n"
8724 "community number\n"
8725 "Do not send outside local AS (well-known community)\n"
8726 "Do not advertise to any peer (well-known community)\n"
8727 "Do not export to next AS (well-known community)\n")
8728
8729/* old command */
8730ALIAS (show_ipv6_mbgp_community,
8731 show_ipv6_mbgp_community4_cmd,
8732 "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)",
8733 SHOW_STR
8734 IPV6_STR
8735 MBGP_STR
8736 "Display routes matching the communities\n"
8737 "community number\n"
8738 "Do not send outside local AS (well-known community)\n"
8739 "Do not advertise to any peer (well-known community)\n"
8740 "Do not export to next AS (well-known community)\n"
8741 "community number\n"
8742 "Do not send outside local AS (well-known community)\n"
8743 "Do not advertise to any peer (well-known community)\n"
8744 "Do not export to next AS (well-known community)\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 "community number\n"
8750 "Do not send outside local AS (well-known community)\n"
8751 "Do not advertise to any peer (well-known community)\n"
8752 "Do not export to next AS (well-known community)\n")
8753
8754/* old command */
8755DEFUN (show_ipv6_mbgp_community_exact,
8756 show_ipv6_mbgp_community_exact_cmd,
8757 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8758 SHOW_STR
8759 IPV6_STR
8760 MBGP_STR
8761 "Display routes matching the communities\n"
8762 "community number\n"
8763 "Do not send outside local AS (well-known community)\n"
8764 "Do not advertise to any peer (well-known community)\n"
8765 "Do not export to next AS (well-known community)\n"
8766 "Exact match of the communities")
8767{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008768 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008769}
8770
8771/* old command */
8772ALIAS (show_ipv6_mbgp_community_exact,
8773 show_ipv6_mbgp_community2_exact_cmd,
8774 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8775 SHOW_STR
8776 IPV6_STR
8777 MBGP_STR
8778 "Display routes matching the communities\n"
8779 "community number\n"
8780 "Do not send outside local AS (well-known community)\n"
8781 "Do not advertise to any peer (well-known community)\n"
8782 "Do not export to next AS (well-known community)\n"
8783 "community number\n"
8784 "Do not send outside local AS (well-known community)\n"
8785 "Do not advertise to any peer (well-known community)\n"
8786 "Do not export to next AS (well-known community)\n"
8787 "Exact match of the communities")
8788
8789/* old command */
8790ALIAS (show_ipv6_mbgp_community_exact,
8791 show_ipv6_mbgp_community3_exact_cmd,
8792 "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",
8793 SHOW_STR
8794 IPV6_STR
8795 MBGP_STR
8796 "Display routes matching the communities\n"
8797 "community number\n"
8798 "Do not send outside local AS (well-known community)\n"
8799 "Do not advertise to any peer (well-known community)\n"
8800 "Do not export to next AS (well-known community)\n"
8801 "community number\n"
8802 "Do not send outside local AS (well-known community)\n"
8803 "Do not advertise to any peer (well-known community)\n"
8804 "Do not export to next AS (well-known community)\n"
8805 "community number\n"
8806 "Do not send outside local AS (well-known community)\n"
8807 "Do not advertise to any peer (well-known community)\n"
8808 "Do not export to next AS (well-known community)\n"
8809 "Exact match of the communities")
8810
8811/* old command */
8812ALIAS (show_ipv6_mbgp_community_exact,
8813 show_ipv6_mbgp_community4_exact_cmd,
8814 "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",
8815 SHOW_STR
8816 IPV6_STR
8817 MBGP_STR
8818 "Display routes matching the communities\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 "community number\n"
8824 "Do not send outside local AS (well-known community)\n"
8825 "Do not advertise to any peer (well-known community)\n"
8826 "Do not export to next AS (well-known community)\n"
8827 "community number\n"
8828 "Do not send outside local AS (well-known community)\n"
8829 "Do not advertise to any peer (well-known community)\n"
8830 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8836#endif /* HAVE_IPV6 */
8837
paul94f2b392005-06-28 12:44:16 +00008838static int
paulfd79ac92004-10-13 05:06:08 +00008839bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008840 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008841{
8842 struct community_list *list;
8843
hassofee6e4e2005-02-02 16:29:31 +00008844 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008845 if (list == NULL)
8846 {
8847 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8848 VTY_NEWLINE);
8849 return CMD_WARNING;
8850 }
8851
ajs5a646652004-11-05 01:25:55 +00008852 return bgp_show (vty, NULL, afi, safi,
8853 (exact ? bgp_show_type_community_list_exact :
8854 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008855}
8856
8857DEFUN (show_ip_bgp_community_list,
8858 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008859 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008860 SHOW_STR
8861 IP_STR
8862 BGP_STR
8863 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008864 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008865 "community-list name\n")
8866{
8867 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8868}
8869
8870DEFUN (show_ip_bgp_ipv4_community_list,
8871 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008872 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008873 SHOW_STR
8874 IP_STR
8875 BGP_STR
8876 "Address family\n"
8877 "Address Family modifier\n"
8878 "Address Family modifier\n"
8879 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008880 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008881 "community-list name\n")
8882{
8883 if (strncmp (argv[0], "m", 1) == 0)
8884 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8885
8886 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8887}
8888
8889DEFUN (show_ip_bgp_community_list_exact,
8890 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008891 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008892 SHOW_STR
8893 IP_STR
8894 BGP_STR
8895 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008896 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008897 "community-list name\n"
8898 "Exact match of the communities\n")
8899{
8900 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8901}
8902
8903DEFUN (show_ip_bgp_ipv4_community_list_exact,
8904 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008905 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008906 SHOW_STR
8907 IP_STR
8908 BGP_STR
8909 "Address family\n"
8910 "Address Family modifier\n"
8911 "Address Family modifier\n"
8912 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008913 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008914 "community-list name\n"
8915 "Exact match of the communities\n")
8916{
8917 if (strncmp (argv[0], "m", 1) == 0)
8918 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8919
8920 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8921}
8922
8923#ifdef HAVE_IPV6
8924DEFUN (show_bgp_community_list,
8925 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008926 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008927 SHOW_STR
8928 BGP_STR
8929 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008930 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008931 "community-list name\n")
8932{
8933 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8934}
8935
8936ALIAS (show_bgp_community_list,
8937 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008938 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008939 SHOW_STR
8940 BGP_STR
8941 "Address family\n"
8942 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008943 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008944 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008945
8946/* old command */
8947DEFUN (show_ipv6_bgp_community_list,
8948 show_ipv6_bgp_community_list_cmd,
8949 "show ipv6 bgp community-list WORD",
8950 SHOW_STR
8951 IPV6_STR
8952 BGP_STR
8953 "Display routes matching the community-list\n"
8954 "community-list name\n")
8955{
8956 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8957}
8958
8959/* old command */
8960DEFUN (show_ipv6_mbgp_community_list,
8961 show_ipv6_mbgp_community_list_cmd,
8962 "show ipv6 mbgp community-list WORD",
8963 SHOW_STR
8964 IPV6_STR
8965 MBGP_STR
8966 "Display routes matching the community-list\n"
8967 "community-list name\n")
8968{
8969 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8970}
8971
8972DEFUN (show_bgp_community_list_exact,
8973 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008974 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008975 SHOW_STR
8976 BGP_STR
8977 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008978 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008979 "community-list name\n"
8980 "Exact match of the communities\n")
8981{
8982 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8983}
8984
8985ALIAS (show_bgp_community_list_exact,
8986 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008987 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008988 SHOW_STR
8989 BGP_STR
8990 "Address family\n"
8991 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008992 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008993 "community-list name\n"
8994 "Exact match of the communities\n")
8995
8996/* old command */
8997DEFUN (show_ipv6_bgp_community_list_exact,
8998 show_ipv6_bgp_community_list_exact_cmd,
8999 "show ipv6 bgp community-list WORD exact-match",
9000 SHOW_STR
9001 IPV6_STR
9002 BGP_STR
9003 "Display routes matching the community-list\n"
9004 "community-list name\n"
9005 "Exact match of the communities\n")
9006{
9007 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9008}
9009
9010/* old command */
9011DEFUN (show_ipv6_mbgp_community_list_exact,
9012 show_ipv6_mbgp_community_list_exact_cmd,
9013 "show ipv6 mbgp community-list WORD exact-match",
9014 SHOW_STR
9015 IPV6_STR
9016 MBGP_STR
9017 "Display routes matching the community-list\n"
9018 "community-list name\n"
9019 "Exact match of the communities\n")
9020{
9021 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9022}
9023#endif /* HAVE_IPV6 */
9024
paul94f2b392005-06-28 12:44:16 +00009025static int
paulfd79ac92004-10-13 05:06:08 +00009026bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009027 safi_t safi, enum bgp_show_type type)
9028{
9029 int ret;
9030 struct prefix *p;
9031
9032 p = prefix_new();
9033
9034 ret = str2prefix (prefix, p);
9035 if (! ret)
9036 {
9037 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9038 return CMD_WARNING;
9039 }
9040
ajs5a646652004-11-05 01:25:55 +00009041 ret = bgp_show (vty, NULL, afi, safi, type, p);
9042 prefix_free(p);
9043 return ret;
paul718e3742002-12-13 20:15:29 +00009044}
9045
9046DEFUN (show_ip_bgp_prefix_longer,
9047 show_ip_bgp_prefix_longer_cmd,
9048 "show ip bgp A.B.C.D/M longer-prefixes",
9049 SHOW_STR
9050 IP_STR
9051 BGP_STR
9052 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9053 "Display route and more specific routes\n")
9054{
9055 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9056 bgp_show_type_prefix_longer);
9057}
9058
9059DEFUN (show_ip_bgp_flap_prefix_longer,
9060 show_ip_bgp_flap_prefix_longer_cmd,
9061 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9062 SHOW_STR
9063 IP_STR
9064 BGP_STR
9065 "Display flap statistics of routes\n"
9066 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9067 "Display route and more specific routes\n")
9068{
9069 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9070 bgp_show_type_flap_prefix_longer);
9071}
9072
9073DEFUN (show_ip_bgp_ipv4_prefix_longer,
9074 show_ip_bgp_ipv4_prefix_longer_cmd,
9075 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9076 SHOW_STR
9077 IP_STR
9078 BGP_STR
9079 "Address family\n"
9080 "Address Family modifier\n"
9081 "Address Family modifier\n"
9082 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9083 "Display route and more specific routes\n")
9084{
9085 if (strncmp (argv[0], "m", 1) == 0)
9086 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9087 bgp_show_type_prefix_longer);
9088
9089 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9090 bgp_show_type_prefix_longer);
9091}
9092
9093DEFUN (show_ip_bgp_flap_address,
9094 show_ip_bgp_flap_address_cmd,
9095 "show ip bgp flap-statistics A.B.C.D",
9096 SHOW_STR
9097 IP_STR
9098 BGP_STR
9099 "Display flap statistics of routes\n"
9100 "Network in the BGP routing table to display\n")
9101{
9102 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9103 bgp_show_type_flap_address);
9104}
9105
9106DEFUN (show_ip_bgp_flap_prefix,
9107 show_ip_bgp_flap_prefix_cmd,
9108 "show ip bgp flap-statistics A.B.C.D/M",
9109 SHOW_STR
9110 IP_STR
9111 BGP_STR
9112 "Display flap statistics of routes\n"
9113 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9114{
9115 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9116 bgp_show_type_flap_prefix);
9117}
9118#ifdef HAVE_IPV6
9119DEFUN (show_bgp_prefix_longer,
9120 show_bgp_prefix_longer_cmd,
9121 "show bgp X:X::X:X/M longer-prefixes",
9122 SHOW_STR
9123 BGP_STR
9124 "IPv6 prefix <network>/<length>\n"
9125 "Display route and more specific routes\n")
9126{
9127 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9128 bgp_show_type_prefix_longer);
9129}
9130
9131ALIAS (show_bgp_prefix_longer,
9132 show_bgp_ipv6_prefix_longer_cmd,
9133 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9134 SHOW_STR
9135 BGP_STR
9136 "Address family\n"
9137 "IPv6 prefix <network>/<length>\n"
9138 "Display route and more specific routes\n")
9139
9140/* old command */
9141DEFUN (show_ipv6_bgp_prefix_longer,
9142 show_ipv6_bgp_prefix_longer_cmd,
9143 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9144 SHOW_STR
9145 IPV6_STR
9146 BGP_STR
9147 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9148 "Display route and more specific routes\n")
9149{
9150 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9151 bgp_show_type_prefix_longer);
9152}
9153
9154/* old command */
9155DEFUN (show_ipv6_mbgp_prefix_longer,
9156 show_ipv6_mbgp_prefix_longer_cmd,
9157 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9158 SHOW_STR
9159 IPV6_STR
9160 MBGP_STR
9161 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9162 "Display route and more specific routes\n")
9163{
9164 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9165 bgp_show_type_prefix_longer);
9166}
9167#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009168
paul94f2b392005-06-28 12:44:16 +00009169static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009170peer_lookup_in_view (struct vty *vty, const char *view_name,
9171 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009172{
9173 int ret;
9174 struct bgp *bgp;
9175 struct peer *peer;
9176 union sockunion su;
9177
9178 /* BGP structure lookup. */
9179 if (view_name)
9180 {
9181 bgp = bgp_lookup_by_name (view_name);
9182 if (! bgp)
9183 {
9184 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9185 return NULL;
9186 }
9187 }
paul5228ad22004-06-04 17:58:18 +00009188 else
paulbb46e942003-10-24 19:02:03 +00009189 {
9190 bgp = bgp_get_default ();
9191 if (! bgp)
9192 {
9193 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9194 return NULL;
9195 }
9196 }
9197
9198 /* Get peer sockunion. */
9199 ret = str2sockunion (ip_str, &su);
9200 if (ret < 0)
9201 {
9202 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9203 return NULL;
9204 }
9205
9206 /* Peer structure lookup. */
9207 peer = peer_lookup (bgp, &su);
9208 if (! peer)
9209 {
9210 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9211 return NULL;
9212 }
9213
9214 return peer;
9215}
Paul Jakma2815e612006-09-14 02:56:07 +00009216
9217enum bgp_stats
9218{
9219 BGP_STATS_MAXBITLEN = 0,
9220 BGP_STATS_RIB,
9221 BGP_STATS_PREFIXES,
9222 BGP_STATS_TOTPLEN,
9223 BGP_STATS_UNAGGREGATEABLE,
9224 BGP_STATS_MAX_AGGREGATEABLE,
9225 BGP_STATS_AGGREGATES,
9226 BGP_STATS_SPACE,
9227 BGP_STATS_ASPATH_COUNT,
9228 BGP_STATS_ASPATH_MAXHOPS,
9229 BGP_STATS_ASPATH_TOTHOPS,
9230 BGP_STATS_ASPATH_MAXSIZE,
9231 BGP_STATS_ASPATH_TOTSIZE,
9232 BGP_STATS_ASN_HIGHEST,
9233 BGP_STATS_MAX,
9234};
paulbb46e942003-10-24 19:02:03 +00009235
Paul Jakma2815e612006-09-14 02:56:07 +00009236static const char *table_stats_strs[] =
9237{
9238 [BGP_STATS_PREFIXES] = "Total Prefixes",
9239 [BGP_STATS_TOTPLEN] = "Average prefix length",
9240 [BGP_STATS_RIB] = "Total Advertisements",
9241 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9242 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9243 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9244 [BGP_STATS_SPACE] = "Address space advertised",
9245 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9246 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9247 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9248 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9249 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9250 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9251 [BGP_STATS_MAX] = NULL,
9252};
9253
9254struct bgp_table_stats
9255{
9256 struct bgp_table *table;
9257 unsigned long long counts[BGP_STATS_MAX];
9258};
9259
9260#if 0
9261#define TALLY_SIGFIG 100000
9262static unsigned long
9263ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9264{
9265 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9266 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9267 unsigned long ret = newtot / count;
9268
9269 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9270 return ret + 1;
9271 else
9272 return ret;
9273}
9274#endif
9275
9276static int
9277bgp_table_stats_walker (struct thread *t)
9278{
9279 struct bgp_node *rn;
9280 struct bgp_node *top;
9281 struct bgp_table_stats *ts = THREAD_ARG (t);
9282 unsigned int space = 0;
9283
Paul Jakma53d9f672006-10-15 23:41:16 +00009284 if (!(top = bgp_table_top (ts->table)))
9285 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009286
9287 switch (top->p.family)
9288 {
9289 case AF_INET:
9290 space = IPV4_MAX_BITLEN;
9291 break;
9292 case AF_INET6:
9293 space = IPV6_MAX_BITLEN;
9294 break;
9295 }
9296
9297 ts->counts[BGP_STATS_MAXBITLEN] = space;
9298
9299 for (rn = top; rn; rn = bgp_route_next (rn))
9300 {
9301 struct bgp_info *ri;
9302 struct bgp_node *prn = rn->parent;
9303 unsigned int rinum = 0;
9304
9305 if (rn == top)
9306 continue;
9307
9308 if (!rn->info)
9309 continue;
9310
9311 ts->counts[BGP_STATS_PREFIXES]++;
9312 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9313
9314#if 0
9315 ts->counts[BGP_STATS_AVGPLEN]
9316 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9317 ts->counts[BGP_STATS_AVGPLEN],
9318 rn->p.prefixlen);
9319#endif
9320
9321 /* check if the prefix is included by any other announcements */
9322 while (prn && !prn->info)
9323 prn = prn->parent;
9324
9325 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009326 {
9327 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9328 /* announced address space */
9329 if (space)
9330 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9331 }
Paul Jakma2815e612006-09-14 02:56:07 +00009332 else if (prn->info)
9333 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9334
Paul Jakma2815e612006-09-14 02:56:07 +00009335 for (ri = rn->info; ri; ri = ri->next)
9336 {
9337 rinum++;
9338 ts->counts[BGP_STATS_RIB]++;
9339
9340 if (ri->attr &&
9341 (CHECK_FLAG (ri->attr->flag,
9342 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9343 ts->counts[BGP_STATS_AGGREGATES]++;
9344
9345 /* as-path stats */
9346 if (ri->attr && ri->attr->aspath)
9347 {
9348 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9349 unsigned int size = aspath_size (ri->attr->aspath);
9350 as_t highest = aspath_highest (ri->attr->aspath);
9351
9352 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9353
9354 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9355 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9356
9357 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9358 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9359
9360 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9361 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9362#if 0
9363 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9364 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9365 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9366 hops);
9367 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9368 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9369 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9370 size);
9371#endif
9372 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9373 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9374 }
9375 }
9376 }
9377 return 0;
9378}
9379
9380static int
9381bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9382{
9383 struct bgp_table_stats ts;
9384 unsigned int i;
9385
9386 if (!bgp->rib[afi][safi])
9387 {
9388 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9389 return CMD_WARNING;
9390 }
9391
9392 memset (&ts, 0, sizeof (ts));
9393 ts.table = bgp->rib[afi][safi];
9394 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9395
9396 vty_out (vty, "BGP %s RIB statistics%s%s",
9397 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9398
9399 for (i = 0; i < BGP_STATS_MAX; i++)
9400 {
9401 if (!table_stats_strs[i])
9402 continue;
9403
9404 switch (i)
9405 {
9406#if 0
9407 case BGP_STATS_ASPATH_AVGHOPS:
9408 case BGP_STATS_ASPATH_AVGSIZE:
9409 case BGP_STATS_AVGPLEN:
9410 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9411 vty_out (vty, "%12.2f",
9412 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9413 break;
9414#endif
9415 case BGP_STATS_ASPATH_TOTHOPS:
9416 case BGP_STATS_ASPATH_TOTSIZE:
9417 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9418 vty_out (vty, "%12.2f",
9419 ts.counts[i] ?
9420 (float)ts.counts[i] /
9421 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9422 : 0);
9423 break;
9424 case BGP_STATS_TOTPLEN:
9425 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9426 vty_out (vty, "%12.2f",
9427 ts.counts[i] ?
9428 (float)ts.counts[i] /
9429 (float)ts.counts[BGP_STATS_PREFIXES]
9430 : 0);
9431 break;
9432 case BGP_STATS_SPACE:
9433 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9434 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9435 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9436 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009437 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009438 vty_out (vty, "%12.2f%s",
9439 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009440 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009441 VTY_NEWLINE);
9442 vty_out (vty, "%30s: ", "/8 equivalent ");
9443 vty_out (vty, "%12.2f%s",
9444 (float)ts.counts[BGP_STATS_SPACE] /
9445 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9446 VTY_NEWLINE);
9447 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9448 break;
9449 vty_out (vty, "%30s: ", "/24 equivalent ");
9450 vty_out (vty, "%12.2f",
9451 (float)ts.counts[BGP_STATS_SPACE] /
9452 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9453 break;
9454 default:
9455 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9456 vty_out (vty, "%12llu", ts.counts[i]);
9457 }
9458
9459 vty_out (vty, "%s", VTY_NEWLINE);
9460 }
9461 return CMD_SUCCESS;
9462}
9463
9464static int
9465bgp_table_stats_vty (struct vty *vty, const char *name,
9466 const char *afi_str, const char *safi_str)
9467{
9468 struct bgp *bgp;
9469 afi_t afi;
9470 safi_t safi;
9471
9472 if (name)
9473 bgp = bgp_lookup_by_name (name);
9474 else
9475 bgp = bgp_get_default ();
9476
9477 if (!bgp)
9478 {
9479 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9480 return CMD_WARNING;
9481 }
9482 if (strncmp (afi_str, "ipv", 3) == 0)
9483 {
9484 if (strncmp (afi_str, "ipv4", 4) == 0)
9485 afi = AFI_IP;
9486 else if (strncmp (afi_str, "ipv6", 4) == 0)
9487 afi = AFI_IP6;
9488 else
9489 {
9490 vty_out (vty, "%% Invalid address family %s%s",
9491 afi_str, VTY_NEWLINE);
9492 return CMD_WARNING;
9493 }
9494 if (strncmp (safi_str, "m", 1) == 0)
9495 safi = SAFI_MULTICAST;
9496 else if (strncmp (safi_str, "u", 1) == 0)
9497 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009498 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9499 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009500 else
9501 {
9502 vty_out (vty, "%% Invalid subsequent address family %s%s",
9503 safi_str, VTY_NEWLINE);
9504 return CMD_WARNING;
9505 }
9506 }
9507 else
9508 {
9509 vty_out (vty, "%% Invalid address family %s%s",
9510 afi_str, VTY_NEWLINE);
9511 return CMD_WARNING;
9512 }
9513
Paul Jakma2815e612006-09-14 02:56:07 +00009514 return bgp_table_stats (vty, bgp, afi, safi);
9515}
9516
9517DEFUN (show_bgp_statistics,
9518 show_bgp_statistics_cmd,
9519 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9520 SHOW_STR
9521 BGP_STR
9522 "Address family\n"
9523 "Address family\n"
9524 "Address Family modifier\n"
9525 "Address Family modifier\n"
9526 "BGP RIB advertisement statistics\n")
9527{
9528 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9529}
9530
9531ALIAS (show_bgp_statistics,
9532 show_bgp_statistics_vpnv4_cmd,
9533 "show bgp (ipv4) (vpnv4) statistics",
9534 SHOW_STR
9535 BGP_STR
9536 "Address family\n"
9537 "Address Family modifier\n"
9538 "BGP RIB advertisement statistics\n")
9539
9540DEFUN (show_bgp_statistics_view,
9541 show_bgp_statistics_view_cmd,
9542 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9543 SHOW_STR
9544 BGP_STR
9545 "BGP view\n"
9546 "Address family\n"
9547 "Address family\n"
9548 "Address Family modifier\n"
9549 "Address Family modifier\n"
9550 "BGP RIB advertisement statistics\n")
9551{
9552 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9553}
9554
9555ALIAS (show_bgp_statistics_view,
9556 show_bgp_statistics_view_vpnv4_cmd,
9557 "show bgp view WORD (ipv4) (vpnv4) statistics",
9558 SHOW_STR
9559 BGP_STR
9560 "BGP view\n"
9561 "Address family\n"
9562 "Address Family modifier\n"
9563 "BGP RIB advertisement statistics\n")
9564
Paul Jakmaff7924f2006-09-04 01:10:36 +00009565enum bgp_pcounts
9566{
9567 PCOUNT_ADJ_IN = 0,
9568 PCOUNT_DAMPED,
9569 PCOUNT_REMOVED,
9570 PCOUNT_HISTORY,
9571 PCOUNT_STALE,
9572 PCOUNT_VALID,
9573 PCOUNT_ALL,
9574 PCOUNT_COUNTED,
9575 PCOUNT_PFCNT, /* the figure we display to users */
9576 PCOUNT_MAX,
9577};
9578
9579static const char *pcount_strs[] =
9580{
9581 [PCOUNT_ADJ_IN] = "Adj-in",
9582 [PCOUNT_DAMPED] = "Damped",
9583 [PCOUNT_REMOVED] = "Removed",
9584 [PCOUNT_HISTORY] = "History",
9585 [PCOUNT_STALE] = "Stale",
9586 [PCOUNT_VALID] = "Valid",
9587 [PCOUNT_ALL] = "All RIB",
9588 [PCOUNT_COUNTED] = "PfxCt counted",
9589 [PCOUNT_PFCNT] = "Useable",
9590 [PCOUNT_MAX] = NULL,
9591};
9592
Paul Jakma2815e612006-09-14 02:56:07 +00009593struct peer_pcounts
9594{
9595 unsigned int count[PCOUNT_MAX];
9596 const struct peer *peer;
9597 const struct bgp_table *table;
9598};
9599
Paul Jakmaff7924f2006-09-04 01:10:36 +00009600static int
Paul Jakma2815e612006-09-14 02:56:07 +00009601bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009602{
9603 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009604 struct peer_pcounts *pc = THREAD_ARG (t);
9605 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009606
Paul Jakma2815e612006-09-14 02:56:07 +00009607 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009608 {
9609 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009610 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009611
9612 for (ain = rn->adj_in; ain; ain = ain->next)
9613 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009614 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009615
Paul Jakmaff7924f2006-09-04 01:10:36 +00009616 for (ri = rn->info; ri; ri = ri->next)
9617 {
9618 char buf[SU_ADDRSTRLEN];
9619
9620 if (ri->peer != peer)
9621 continue;
9622
Paul Jakma2815e612006-09-14 02:56:07 +00009623 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009624
9625 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009626 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009627 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009628 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009629 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009630 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009631 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009632 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009633 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009634 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009635 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009636 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009637
9638 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9639 {
Paul Jakma2815e612006-09-14 02:56:07 +00009640 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009641 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009642 plog_warn (peer->log,
9643 "%s [pcount] %s/%d is counted but flags 0x%x",
9644 peer->host,
9645 inet_ntop(rn->p.family, &rn->p.u.prefix,
9646 buf, SU_ADDRSTRLEN),
9647 rn->p.prefixlen,
9648 ri->flags);
9649 }
9650 else
9651 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009652 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009653 plog_warn (peer->log,
9654 "%s [pcount] %s/%d not counted but flags 0x%x",
9655 peer->host,
9656 inet_ntop(rn->p.family, &rn->p.u.prefix,
9657 buf, SU_ADDRSTRLEN),
9658 rn->p.prefixlen,
9659 ri->flags);
9660 }
9661 }
9662 }
Paul Jakma2815e612006-09-14 02:56:07 +00009663 return 0;
9664}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009665
Paul Jakma2815e612006-09-14 02:56:07 +00009666static int
9667bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9668{
9669 struct peer_pcounts pcounts = { .peer = peer };
9670 unsigned int i;
9671
9672 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9673 || !peer->bgp->rib[afi][safi])
9674 {
9675 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9676 return CMD_WARNING;
9677 }
9678
9679 memset (&pcounts, 0, sizeof(pcounts));
9680 pcounts.peer = peer;
9681 pcounts.table = peer->bgp->rib[afi][safi];
9682
9683 /* in-place call via thread subsystem so as to record execution time
9684 * stats for the thread-walk (i.e. ensure this can't be blamed on
9685 * on just vty_read()).
9686 */
9687 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9688
Paul Jakmaff7924f2006-09-04 01:10:36 +00009689 vty_out (vty, "Prefix counts for %s, %s%s",
9690 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9691 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9692 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9693 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9694
9695 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009696 vty_out (vty, "%20s: %-10d%s",
9697 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009698
Paul Jakma2815e612006-09-14 02:56:07 +00009699 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009700 {
9701 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9702 peer->host, VTY_NEWLINE);
9703 vty_out (vty, "Please report this bug, with the above command output%s",
9704 VTY_NEWLINE);
9705 }
9706
9707 return CMD_SUCCESS;
9708}
9709
9710DEFUN (show_ip_bgp_neighbor_prefix_counts,
9711 show_ip_bgp_neighbor_prefix_counts_cmd,
9712 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9713 SHOW_STR
9714 IP_STR
9715 BGP_STR
9716 "Detailed information on TCP and BGP neighbor connections\n"
9717 "Neighbor to display information about\n"
9718 "Neighbor to display information about\n"
9719 "Display detailed prefix count information\n")
9720{
9721 struct peer *peer;
9722
9723 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9724 if (! peer)
9725 return CMD_WARNING;
9726
9727 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9728}
9729
9730DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9731 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9732 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9733 SHOW_STR
9734 BGP_STR
9735 "Address family\n"
9736 "Detailed information on TCP and BGP neighbor connections\n"
9737 "Neighbor to display information about\n"
9738 "Neighbor to display information about\n"
9739 "Display detailed prefix count information\n")
9740{
9741 struct peer *peer;
9742
9743 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9744 if (! peer)
9745 return CMD_WARNING;
9746
9747 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9748}
9749
9750DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9751 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9752 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9753 SHOW_STR
9754 IP_STR
9755 BGP_STR
9756 "Address family\n"
9757 "Address Family modifier\n"
9758 "Address Family modifier\n"
9759 "Detailed information on TCP and BGP neighbor connections\n"
9760 "Neighbor to display information about\n"
9761 "Neighbor to display information about\n"
9762 "Display detailed prefix count information\n")
9763{
9764 struct peer *peer;
9765
9766 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9767 if (! peer)
9768 return CMD_WARNING;
9769
9770 if (strncmp (argv[0], "m", 1) == 0)
9771 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9772
9773 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9774}
9775
9776DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9777 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9778 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9779 SHOW_STR
9780 IP_STR
9781 BGP_STR
9782 "Address family\n"
9783 "Address Family modifier\n"
9784 "Address Family modifier\n"
9785 "Detailed information on TCP and BGP neighbor connections\n"
9786 "Neighbor to display information about\n"
9787 "Neighbor to display information about\n"
9788 "Display detailed prefix count information\n")
9789{
9790 struct peer *peer;
9791
9792 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9793 if (! peer)
9794 return CMD_WARNING;
9795
9796 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9797}
9798
9799
paul94f2b392005-06-28 12:44:16 +00009800static void
paul718e3742002-12-13 20:15:29 +00009801show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9802 int in)
9803{
9804 struct bgp_table *table;
9805 struct bgp_adj_in *ain;
9806 struct bgp_adj_out *adj;
9807 unsigned long output_count;
9808 struct bgp_node *rn;
9809 int header1 = 1;
9810 struct bgp *bgp;
9811 int header2 = 1;
9812
paulbb46e942003-10-24 19:02:03 +00009813 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009814
9815 if (! bgp)
9816 return;
9817
9818 table = bgp->rib[afi][safi];
9819
9820 output_count = 0;
9821
9822 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9823 PEER_STATUS_DEFAULT_ORIGINATE))
9824 {
9825 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 +00009826 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9827 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009828
9829 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9830 VTY_NEWLINE, VTY_NEWLINE);
9831 header1 = 0;
9832 }
9833
9834 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9835 if (in)
9836 {
9837 for (ain = rn->adj_in; ain; ain = ain->next)
9838 if (ain->peer == peer)
9839 {
9840 if (header1)
9841 {
9842 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 +00009843 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9844 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009845 header1 = 0;
9846 }
9847 if (header2)
9848 {
9849 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9850 header2 = 0;
9851 }
9852 if (ain->attr)
9853 {
9854 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9855 output_count++;
9856 }
9857 }
9858 }
9859 else
9860 {
9861 for (adj = rn->adj_out; adj; adj = adj->next)
9862 if (adj->peer == peer)
9863 {
9864 if (header1)
9865 {
9866 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 +00009867 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9868 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009869 header1 = 0;
9870 }
9871 if (header2)
9872 {
9873 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9874 header2 = 0;
9875 }
9876 if (adj->attr)
9877 {
9878 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9879 output_count++;
9880 }
9881 }
9882 }
9883
9884 if (output_count != 0)
9885 vty_out (vty, "%sTotal number of prefixes %ld%s",
9886 VTY_NEWLINE, output_count, VTY_NEWLINE);
9887}
9888
paul94f2b392005-06-28 12:44:16 +00009889static int
paulbb46e942003-10-24 19:02:03 +00009890peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9891{
paul718e3742002-12-13 20:15:29 +00009892 if (! peer || ! peer->afc[afi][safi])
9893 {
9894 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9895 return CMD_WARNING;
9896 }
9897
9898 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9899 {
9900 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9901 VTY_NEWLINE);
9902 return CMD_WARNING;
9903 }
9904
9905 show_adj_route (vty, peer, afi, safi, in);
9906
9907 return CMD_SUCCESS;
9908}
9909
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009910DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9911 show_ip_bgp_view_neighbor_advertised_route_cmd,
9912 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9913 SHOW_STR
9914 IP_STR
9915 BGP_STR
9916 "BGP view\n"
9917 "View name\n"
9918 "Detailed information on TCP and BGP neighbor connections\n"
9919 "Neighbor to display information about\n"
9920 "Neighbor to display information about\n"
9921 "Display the routes advertised to a BGP neighbor\n")
9922{
9923 struct peer *peer;
9924
9925 if (argc == 2)
9926 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9927 else
9928 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9929
9930 if (! peer)
9931 return CMD_WARNING;
9932
9933 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9934}
9935
9936ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009937 show_ip_bgp_neighbor_advertised_route_cmd,
9938 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9939 SHOW_STR
9940 IP_STR
9941 BGP_STR
9942 "Detailed information on TCP and BGP neighbor connections\n"
9943 "Neighbor to display information about\n"
9944 "Neighbor to display information about\n"
9945 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009946
9947DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9948 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9949 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9950 SHOW_STR
9951 IP_STR
9952 BGP_STR
9953 "Address family\n"
9954 "Address Family modifier\n"
9955 "Address Family modifier\n"
9956 "Detailed information on TCP and BGP neighbor connections\n"
9957 "Neighbor to display information about\n"
9958 "Neighbor to display information about\n"
9959 "Display the routes advertised to a BGP neighbor\n")
9960{
paulbb46e942003-10-24 19:02:03 +00009961 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009962
paulbb46e942003-10-24 19:02:03 +00009963 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9964 if (! peer)
9965 return CMD_WARNING;
9966
9967 if (strncmp (argv[0], "m", 1) == 0)
9968 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9969
9970 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009971}
9972
9973#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009974DEFUN (show_bgp_view_neighbor_advertised_route,
9975 show_bgp_view_neighbor_advertised_route_cmd,
9976 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9977 SHOW_STR
9978 BGP_STR
9979 "BGP view\n"
9980 "View name\n"
9981 "Detailed information on TCP and BGP neighbor connections\n"
9982 "Neighbor to display information about\n"
9983 "Neighbor to display information about\n"
9984 "Display the routes advertised to a BGP neighbor\n")
9985{
9986 struct peer *peer;
9987
9988 if (argc == 2)
9989 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9990 else
9991 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9992
9993 if (! peer)
9994 return CMD_WARNING;
9995
9996 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9997}
9998
9999ALIAS (show_bgp_view_neighbor_advertised_route,
10000 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
10001 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10002 SHOW_STR
10003 BGP_STR
10004 "BGP view\n"
10005 "View name\n"
10006 "Address family\n"
10007 "Detailed information on TCP and BGP neighbor connections\n"
10008 "Neighbor to display information about\n"
10009 "Neighbor to display information about\n"
10010 "Display the routes advertised to a BGP neighbor\n")
10011
10012DEFUN (show_bgp_view_neighbor_received_routes,
10013 show_bgp_view_neighbor_received_routes_cmd,
10014 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10015 SHOW_STR
10016 BGP_STR
10017 "BGP view\n"
10018 "View name\n"
10019 "Detailed information on TCP and BGP neighbor connections\n"
10020 "Neighbor to display information about\n"
10021 "Neighbor to display information about\n"
10022 "Display the received routes from neighbor\n")
10023{
10024 struct peer *peer;
10025
10026 if (argc == 2)
10027 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10028 else
10029 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10030
10031 if (! peer)
10032 return CMD_WARNING;
10033
10034 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10035}
10036
10037ALIAS (show_bgp_view_neighbor_received_routes,
10038 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10039 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10040 SHOW_STR
10041 BGP_STR
10042 "BGP view\n"
10043 "View name\n"
10044 "Address family\n"
10045 "Detailed information on TCP and BGP neighbor connections\n"
10046 "Neighbor to display information about\n"
10047 "Neighbor to display information about\n"
10048 "Display the received routes from neighbor\n")
10049
10050ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010051 show_bgp_neighbor_advertised_route_cmd,
10052 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10053 SHOW_STR
10054 BGP_STR
10055 "Detailed information on TCP and BGP neighbor connections\n"
10056 "Neighbor to display information about\n"
10057 "Neighbor to display information about\n"
10058 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010059
10060ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010061 show_bgp_ipv6_neighbor_advertised_route_cmd,
10062 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10063 SHOW_STR
10064 BGP_STR
10065 "Address family\n"
10066 "Detailed information on TCP and BGP neighbor connections\n"
10067 "Neighbor to display information about\n"
10068 "Neighbor to display information about\n"
10069 "Display the routes advertised to a BGP neighbor\n")
10070
10071/* old command */
paulbb46e942003-10-24 19:02:03 +000010072ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010073 ipv6_bgp_neighbor_advertised_route_cmd,
10074 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10075 SHOW_STR
10076 IPV6_STR
10077 BGP_STR
10078 "Detailed information on TCP and BGP neighbor connections\n"
10079 "Neighbor to display information about\n"
10080 "Neighbor to display information about\n"
10081 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010082
paul718e3742002-12-13 20:15:29 +000010083/* old command */
10084DEFUN (ipv6_mbgp_neighbor_advertised_route,
10085 ipv6_mbgp_neighbor_advertised_route_cmd,
10086 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10087 SHOW_STR
10088 IPV6_STR
10089 MBGP_STR
10090 "Detailed information on TCP and BGP neighbor connections\n"
10091 "Neighbor to display information about\n"
10092 "Neighbor to display information about\n"
10093 "Display the routes advertised to a BGP neighbor\n")
10094{
paulbb46e942003-10-24 19:02:03 +000010095 struct peer *peer;
10096
10097 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10098 if (! peer)
10099 return CMD_WARNING;
10100
10101 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010102}
10103#endif /* HAVE_IPV6 */
10104
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010105DEFUN (show_ip_bgp_view_neighbor_received_routes,
10106 show_ip_bgp_view_neighbor_received_routes_cmd,
10107 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10108 SHOW_STR
10109 IP_STR
10110 BGP_STR
10111 "BGP view\n"
10112 "View name\n"
10113 "Detailed information on TCP and BGP neighbor connections\n"
10114 "Neighbor to display information about\n"
10115 "Neighbor to display information about\n"
10116 "Display the received routes from neighbor\n")
10117{
10118 struct peer *peer;
10119
10120 if (argc == 2)
10121 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10122 else
10123 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10124
10125 if (! peer)
10126 return CMD_WARNING;
10127
10128 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10129}
10130
10131ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010132 show_ip_bgp_neighbor_received_routes_cmd,
10133 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10134 SHOW_STR
10135 IP_STR
10136 BGP_STR
10137 "Detailed information on TCP and BGP neighbor connections\n"
10138 "Neighbor to display information about\n"
10139 "Neighbor to display information about\n"
10140 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010141
10142DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10143 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10144 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10145 SHOW_STR
10146 IP_STR
10147 BGP_STR
10148 "Address family\n"
10149 "Address Family modifier\n"
10150 "Address Family modifier\n"
10151 "Detailed information on TCP and BGP neighbor connections\n"
10152 "Neighbor to display information about\n"
10153 "Neighbor to display information about\n"
10154 "Display the received routes from neighbor\n")
10155{
paulbb46e942003-10-24 19:02:03 +000010156 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010157
paulbb46e942003-10-24 19:02:03 +000010158 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10159 if (! peer)
10160 return CMD_WARNING;
10161
10162 if (strncmp (argv[0], "m", 1) == 0)
10163 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10164
10165 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010166}
10167
Michael Lambert95cbbd22010-07-23 14:43:04 -040010168DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10169 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10170#ifdef HAVE_IPV6
10171 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10172#else
10173 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10174#endif
10175 SHOW_STR
10176 BGP_STR
10177 "BGP view\n"
10178 "BGP view name\n"
10179 "Address family\n"
10180#ifdef HAVE_IPV6
10181 "Address family\n"
10182#endif
10183 "Address family modifier\n"
10184 "Address family modifier\n"
10185 "Detailed information on TCP and BGP neighbor connections\n"
10186 "Neighbor to display information about\n"
10187 "Neighbor to display information about\n"
10188 "Display the advertised routes to neighbor\n"
10189 "Display the received routes from neighbor\n")
10190{
10191 int afi;
10192 int safi;
10193 int in;
10194 struct peer *peer;
10195
10196#ifdef HAVE_IPV6
10197 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10198#else
10199 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10200#endif
10201
10202 if (! peer)
10203 return CMD_WARNING;
10204
10205#ifdef HAVE_IPV6
10206 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10207 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10208 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10209#else
10210 afi = AFI_IP;
10211 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10212 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10213#endif
10214
10215 return peer_adj_routes (vty, peer, afi, safi, in);
10216}
10217
paul718e3742002-12-13 20:15:29 +000010218DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10219 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10220 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10221 SHOW_STR
10222 IP_STR
10223 BGP_STR
10224 "Detailed information on TCP and BGP neighbor connections\n"
10225 "Neighbor to display information about\n"
10226 "Neighbor to display information about\n"
10227 "Display information received from a BGP neighbor\n"
10228 "Display the prefixlist filter\n")
10229{
10230 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010231 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010232 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010233 int count, ret;
paul718e3742002-12-13 20:15:29 +000010234
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010235 ret = str2sockunion (argv[0], &su);
10236 if (ret < 0)
10237 {
10238 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10239 return CMD_WARNING;
10240 }
paul718e3742002-12-13 20:15:29 +000010241
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010242 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010243 if (! peer)
10244 return CMD_WARNING;
10245
10246 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10247 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10248 if (count)
10249 {
10250 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10251 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10252 }
10253
10254 return CMD_SUCCESS;
10255}
10256
10257DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10258 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10259 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10260 SHOW_STR
10261 IP_STR
10262 BGP_STR
10263 "Address family\n"
10264 "Address Family modifier\n"
10265 "Address Family modifier\n"
10266 "Detailed information on TCP and BGP neighbor connections\n"
10267 "Neighbor to display information about\n"
10268 "Neighbor to display information about\n"
10269 "Display information received from a BGP neighbor\n"
10270 "Display the prefixlist filter\n")
10271{
10272 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010273 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010274 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010275 int count, ret;
paul718e3742002-12-13 20:15:29 +000010276
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010277 ret = str2sockunion (argv[1], &su);
10278 if (ret < 0)
10279 {
10280 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10281 return CMD_WARNING;
10282 }
paul718e3742002-12-13 20:15:29 +000010283
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010284 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010285 if (! peer)
10286 return CMD_WARNING;
10287
10288 if (strncmp (argv[0], "m", 1) == 0)
10289 {
10290 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10291 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10292 if (count)
10293 {
10294 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10295 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10296 }
10297 }
10298 else
10299 {
10300 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10301 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10302 if (count)
10303 {
10304 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10305 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10306 }
10307 }
10308
10309 return CMD_SUCCESS;
10310}
10311
10312
10313#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010314ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010315 show_bgp_neighbor_received_routes_cmd,
10316 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10317 SHOW_STR
10318 BGP_STR
10319 "Detailed information on TCP and BGP neighbor connections\n"
10320 "Neighbor to display information about\n"
10321 "Neighbor to display information about\n"
10322 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010323
paulbb46e942003-10-24 19:02:03 +000010324ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010325 show_bgp_ipv6_neighbor_received_routes_cmd,
10326 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10327 SHOW_STR
10328 BGP_STR
10329 "Address family\n"
10330 "Detailed information on TCP and BGP neighbor connections\n"
10331 "Neighbor to display information about\n"
10332 "Neighbor to display information about\n"
10333 "Display the received routes from neighbor\n")
10334
10335DEFUN (show_bgp_neighbor_received_prefix_filter,
10336 show_bgp_neighbor_received_prefix_filter_cmd,
10337 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10338 SHOW_STR
10339 BGP_STR
10340 "Detailed information on TCP and BGP neighbor connections\n"
10341 "Neighbor to display information about\n"
10342 "Neighbor to display information about\n"
10343 "Display information received from a BGP neighbor\n"
10344 "Display the prefixlist filter\n")
10345{
10346 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010347 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010348 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010349 int count, ret;
paul718e3742002-12-13 20:15:29 +000010350
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010351 ret = str2sockunion (argv[0], &su);
10352 if (ret < 0)
10353 {
10354 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10355 return CMD_WARNING;
10356 }
paul718e3742002-12-13 20:15:29 +000010357
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010358 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010359 if (! peer)
10360 return CMD_WARNING;
10361
10362 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10363 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10364 if (count)
10365 {
10366 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10367 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10368 }
10369
10370 return CMD_SUCCESS;
10371}
10372
10373ALIAS (show_bgp_neighbor_received_prefix_filter,
10374 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10375 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10376 SHOW_STR
10377 BGP_STR
10378 "Address family\n"
10379 "Detailed information on TCP and BGP neighbor connections\n"
10380 "Neighbor to display information about\n"
10381 "Neighbor to display information about\n"
10382 "Display information received from a BGP neighbor\n"
10383 "Display the prefixlist filter\n")
10384
10385/* old command */
paulbb46e942003-10-24 19:02:03 +000010386ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010387 ipv6_bgp_neighbor_received_routes_cmd,
10388 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10389 SHOW_STR
10390 IPV6_STR
10391 BGP_STR
10392 "Detailed information on TCP and BGP neighbor connections\n"
10393 "Neighbor to display information about\n"
10394 "Neighbor to display information about\n"
10395 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010396
10397/* old command */
10398DEFUN (ipv6_mbgp_neighbor_received_routes,
10399 ipv6_mbgp_neighbor_received_routes_cmd,
10400 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10401 SHOW_STR
10402 IPV6_STR
10403 MBGP_STR
10404 "Detailed information on TCP and BGP neighbor connections\n"
10405 "Neighbor to display information about\n"
10406 "Neighbor to display information about\n"
10407 "Display the received routes from neighbor\n")
10408{
paulbb46e942003-10-24 19:02:03 +000010409 struct peer *peer;
10410
10411 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10412 if (! peer)
10413 return CMD_WARNING;
10414
10415 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010416}
paulbb46e942003-10-24 19:02:03 +000010417
10418DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10419 show_bgp_view_neighbor_received_prefix_filter_cmd,
10420 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10421 SHOW_STR
10422 BGP_STR
10423 "BGP view\n"
10424 "View name\n"
10425 "Detailed information on TCP and BGP neighbor connections\n"
10426 "Neighbor to display information about\n"
10427 "Neighbor to display information about\n"
10428 "Display information received from a BGP neighbor\n"
10429 "Display the prefixlist filter\n")
10430{
10431 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010432 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010433 struct peer *peer;
10434 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010435 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010436
10437 /* BGP structure lookup. */
10438 bgp = bgp_lookup_by_name (argv[0]);
10439 if (bgp == NULL)
10440 {
10441 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10442 return CMD_WARNING;
10443 }
10444
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010445 ret = str2sockunion (argv[1], &su);
10446 if (ret < 0)
10447 {
10448 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10449 return CMD_WARNING;
10450 }
paulbb46e942003-10-24 19:02:03 +000010451
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010452 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010453 if (! peer)
10454 return CMD_WARNING;
10455
10456 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10457 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10458 if (count)
10459 {
10460 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10461 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10462 }
10463
10464 return CMD_SUCCESS;
10465}
10466
10467ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10468 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10469 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10470 SHOW_STR
10471 BGP_STR
10472 "BGP view\n"
10473 "View name\n"
10474 "Address family\n"
10475 "Detailed information on TCP and BGP neighbor connections\n"
10476 "Neighbor to display information about\n"
10477 "Neighbor to display information about\n"
10478 "Display information received from a BGP neighbor\n"
10479 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010480#endif /* HAVE_IPV6 */
10481
paul94f2b392005-06-28 12:44:16 +000010482static int
paulbb46e942003-10-24 19:02:03 +000010483bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010484 safi_t safi, enum bgp_show_type type)
10485{
paul718e3742002-12-13 20:15:29 +000010486 if (! peer || ! peer->afc[afi][safi])
10487 {
10488 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010489 return CMD_WARNING;
10490 }
10491
ajs5a646652004-11-05 01:25:55 +000010492 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010493}
10494
10495DEFUN (show_ip_bgp_neighbor_routes,
10496 show_ip_bgp_neighbor_routes_cmd,
10497 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10498 SHOW_STR
10499 IP_STR
10500 BGP_STR
10501 "Detailed information on TCP and BGP neighbor connections\n"
10502 "Neighbor to display information about\n"
10503 "Neighbor to display information about\n"
10504 "Display routes learned from neighbor\n")
10505{
paulbb46e942003-10-24 19:02:03 +000010506 struct peer *peer;
10507
10508 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10509 if (! peer)
10510 return CMD_WARNING;
10511
10512 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010513 bgp_show_type_neighbor);
10514}
10515
10516DEFUN (show_ip_bgp_neighbor_flap,
10517 show_ip_bgp_neighbor_flap_cmd,
10518 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10519 SHOW_STR
10520 IP_STR
10521 BGP_STR
10522 "Detailed information on TCP and BGP neighbor connections\n"
10523 "Neighbor to display information about\n"
10524 "Neighbor to display information about\n"
10525 "Display flap statistics of the routes learned from neighbor\n")
10526{
paulbb46e942003-10-24 19:02:03 +000010527 struct peer *peer;
10528
10529 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10530 if (! peer)
10531 return CMD_WARNING;
10532
10533 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010534 bgp_show_type_flap_neighbor);
10535}
10536
10537DEFUN (show_ip_bgp_neighbor_damp,
10538 show_ip_bgp_neighbor_damp_cmd,
10539 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10540 SHOW_STR
10541 IP_STR
10542 BGP_STR
10543 "Detailed information on TCP and BGP neighbor connections\n"
10544 "Neighbor to display information about\n"
10545 "Neighbor to display information about\n"
10546 "Display the dampened routes received from neighbor\n")
10547{
paulbb46e942003-10-24 19:02:03 +000010548 struct peer *peer;
10549
10550 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10551 if (! peer)
10552 return CMD_WARNING;
10553
10554 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010555 bgp_show_type_damp_neighbor);
10556}
10557
10558DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10559 show_ip_bgp_ipv4_neighbor_routes_cmd,
10560 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
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 routes learned from neighbor\n")
10571{
paulbb46e942003-10-24 19:02:03 +000010572 struct peer *peer;
10573
10574 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10575 if (! peer)
10576 return CMD_WARNING;
10577
paul718e3742002-12-13 20:15:29 +000010578 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010579 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010580 bgp_show_type_neighbor);
10581
paulbb46e942003-10-24 19:02:03 +000010582 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010583 bgp_show_type_neighbor);
10584}
paulbb46e942003-10-24 19:02:03 +000010585
paulfee0f4c2004-09-13 05:12:46 +000010586DEFUN (show_ip_bgp_view_rsclient,
10587 show_ip_bgp_view_rsclient_cmd,
10588 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10589 SHOW_STR
10590 IP_STR
10591 BGP_STR
10592 "BGP view\n"
10593 "BGP view name\n"
10594 "Information about Route Server Client\n"
10595 NEIGHBOR_ADDR_STR)
10596{
10597 struct bgp_table *table;
10598 struct peer *peer;
10599
10600 if (argc == 2)
10601 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10602 else
10603 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10604
10605 if (! peer)
10606 return CMD_WARNING;
10607
10608 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10609 {
10610 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10611 VTY_NEWLINE);
10612 return CMD_WARNING;
10613 }
10614
10615 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10616 PEER_FLAG_RSERVER_CLIENT))
10617 {
10618 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10619 VTY_NEWLINE);
10620 return CMD_WARNING;
10621 }
10622
10623 table = peer->rib[AFI_IP][SAFI_UNICAST];
10624
ajs5a646652004-11-05 01:25:55 +000010625 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010626}
10627
10628ALIAS (show_ip_bgp_view_rsclient,
10629 show_ip_bgp_rsclient_cmd,
10630 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10631 SHOW_STR
10632 IP_STR
10633 BGP_STR
10634 "Information about Route Server Client\n"
10635 NEIGHBOR_ADDR_STR)
10636
Michael Lambert95cbbd22010-07-23 14:43:04 -040010637DEFUN (show_bgp_view_ipv4_safi_rsclient,
10638 show_bgp_view_ipv4_safi_rsclient_cmd,
10639 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10640 SHOW_STR
10641 BGP_STR
10642 "BGP view\n"
10643 "BGP view name\n"
10644 "Address family\n"
10645 "Address Family modifier\n"
10646 "Address Family modifier\n"
10647 "Information about Route Server Client\n"
10648 NEIGHBOR_ADDR_STR)
10649{
10650 struct bgp_table *table;
10651 struct peer *peer;
10652 safi_t safi;
10653
10654 if (argc == 3) {
10655 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10656 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10657 } else {
10658 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10659 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10660 }
10661
10662 if (! peer)
10663 return CMD_WARNING;
10664
10665 if (! peer->afc[AFI_IP][safi])
10666 {
10667 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10668 VTY_NEWLINE);
10669 return CMD_WARNING;
10670 }
10671
10672 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10673 PEER_FLAG_RSERVER_CLIENT))
10674 {
10675 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10676 VTY_NEWLINE);
10677 return CMD_WARNING;
10678 }
10679
10680 table = peer->rib[AFI_IP][safi];
10681
10682 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10683}
10684
10685ALIAS (show_bgp_view_ipv4_safi_rsclient,
10686 show_bgp_ipv4_safi_rsclient_cmd,
10687 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10688 SHOW_STR
10689 BGP_STR
10690 "Address family\n"
10691 "Address Family modifier\n"
10692 "Address Family modifier\n"
10693 "Information about Route Server Client\n"
10694 NEIGHBOR_ADDR_STR)
10695
paulfee0f4c2004-09-13 05:12:46 +000010696DEFUN (show_ip_bgp_view_rsclient_route,
10697 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010698 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010699 SHOW_STR
10700 IP_STR
10701 BGP_STR
10702 "BGP view\n"
10703 "BGP view name\n"
10704 "Information about Route Server Client\n"
10705 NEIGHBOR_ADDR_STR
10706 "Network in the BGP routing table to display\n")
10707{
10708 struct bgp *bgp;
10709 struct peer *peer;
10710
10711 /* BGP structure lookup. */
10712 if (argc == 3)
10713 {
10714 bgp = bgp_lookup_by_name (argv[0]);
10715 if (bgp == NULL)
10716 {
10717 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10718 return CMD_WARNING;
10719 }
10720 }
10721 else
10722 {
10723 bgp = bgp_get_default ();
10724 if (bgp == NULL)
10725 {
10726 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10727 return CMD_WARNING;
10728 }
10729 }
10730
10731 if (argc == 3)
10732 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10733 else
10734 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10735
10736 if (! peer)
10737 return CMD_WARNING;
10738
10739 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10740 {
10741 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10742 VTY_NEWLINE);
10743 return CMD_WARNING;
10744}
10745
10746 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10747 PEER_FLAG_RSERVER_CLIENT))
10748 {
10749 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10750 VTY_NEWLINE);
10751 return CMD_WARNING;
10752 }
10753
10754 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10755 (argc == 3) ? argv[2] : argv[1],
10756 AFI_IP, SAFI_UNICAST, NULL, 0);
10757}
10758
10759ALIAS (show_ip_bgp_view_rsclient_route,
10760 show_ip_bgp_rsclient_route_cmd,
10761 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10762 SHOW_STR
10763 IP_STR
10764 BGP_STR
10765 "Information about Route Server Client\n"
10766 NEIGHBOR_ADDR_STR
10767 "Network in the BGP routing table to display\n")
10768
Michael Lambert95cbbd22010-07-23 14:43:04 -040010769DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10770 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10771 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10772 SHOW_STR
10773 BGP_STR
10774 "BGP view\n"
10775 "BGP view name\n"
10776 "Address family\n"
10777 "Address Family modifier\n"
10778 "Address Family modifier\n"
10779 "Information about Route Server Client\n"
10780 NEIGHBOR_ADDR_STR
10781 "Network in the BGP routing table to display\n")
10782{
10783 struct bgp *bgp;
10784 struct peer *peer;
10785 safi_t safi;
10786
10787 /* BGP structure lookup. */
10788 if (argc == 4)
10789 {
10790 bgp = bgp_lookup_by_name (argv[0]);
10791 if (bgp == NULL)
10792 {
10793 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10794 return CMD_WARNING;
10795 }
10796 }
10797 else
10798 {
10799 bgp = bgp_get_default ();
10800 if (bgp == NULL)
10801 {
10802 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10803 return CMD_WARNING;
10804 }
10805 }
10806
10807 if (argc == 4) {
10808 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10809 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10810 } else {
10811 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10812 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10813 }
10814
10815 if (! peer)
10816 return CMD_WARNING;
10817
10818 if (! peer->afc[AFI_IP][safi])
10819 {
10820 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10821 VTY_NEWLINE);
10822 return CMD_WARNING;
10823}
10824
10825 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10826 PEER_FLAG_RSERVER_CLIENT))
10827 {
10828 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10829 VTY_NEWLINE);
10830 return CMD_WARNING;
10831 }
10832
10833 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10834 (argc == 4) ? argv[3] : argv[2],
10835 AFI_IP, safi, NULL, 0);
10836}
10837
10838ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10839 show_bgp_ipv4_safi_rsclient_route_cmd,
10840 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10841 SHOW_STR
10842 BGP_STR
10843 "Address family\n"
10844 "Address Family modifier\n"
10845 "Address Family modifier\n"
10846 "Information about Route Server Client\n"
10847 NEIGHBOR_ADDR_STR
10848 "Network in the BGP routing table to display\n")
10849
paulfee0f4c2004-09-13 05:12:46 +000010850DEFUN (show_ip_bgp_view_rsclient_prefix,
10851 show_ip_bgp_view_rsclient_prefix_cmd,
10852 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10853 SHOW_STR
10854 IP_STR
10855 BGP_STR
10856 "BGP view\n"
10857 "BGP view name\n"
10858 "Information about Route Server Client\n"
10859 NEIGHBOR_ADDR_STR
10860 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10861{
10862 struct bgp *bgp;
10863 struct peer *peer;
10864
10865 /* BGP structure lookup. */
10866 if (argc == 3)
10867 {
10868 bgp = bgp_lookup_by_name (argv[0]);
10869 if (bgp == NULL)
10870 {
10871 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10872 return CMD_WARNING;
10873 }
10874 }
10875 else
10876 {
10877 bgp = bgp_get_default ();
10878 if (bgp == NULL)
10879 {
10880 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10881 return CMD_WARNING;
10882 }
10883 }
10884
10885 if (argc == 3)
10886 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10887 else
10888 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10889
10890 if (! peer)
10891 return CMD_WARNING;
10892
10893 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10894 {
10895 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10896 VTY_NEWLINE);
10897 return CMD_WARNING;
10898}
10899
10900 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10901 PEER_FLAG_RSERVER_CLIENT))
10902{
10903 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10904 VTY_NEWLINE);
10905 return CMD_WARNING;
10906 }
10907
10908 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10909 (argc == 3) ? argv[2] : argv[1],
10910 AFI_IP, SAFI_UNICAST, NULL, 1);
10911}
10912
10913ALIAS (show_ip_bgp_view_rsclient_prefix,
10914 show_ip_bgp_rsclient_prefix_cmd,
10915 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10916 SHOW_STR
10917 IP_STR
10918 BGP_STR
10919 "Information about Route Server Client\n"
10920 NEIGHBOR_ADDR_STR
10921 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10922
Michael Lambert95cbbd22010-07-23 14:43:04 -040010923DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10924 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10925 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10926 SHOW_STR
10927 BGP_STR
10928 "BGP view\n"
10929 "BGP view name\n"
10930 "Address family\n"
10931 "Address Family modifier\n"
10932 "Address Family modifier\n"
10933 "Information about Route Server Client\n"
10934 NEIGHBOR_ADDR_STR
10935 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10936{
10937 struct bgp *bgp;
10938 struct peer *peer;
10939 safi_t safi;
10940
10941 /* BGP structure lookup. */
10942 if (argc == 4)
10943 {
10944 bgp = bgp_lookup_by_name (argv[0]);
10945 if (bgp == NULL)
10946 {
10947 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10948 return CMD_WARNING;
10949 }
10950 }
10951 else
10952 {
10953 bgp = bgp_get_default ();
10954 if (bgp == NULL)
10955 {
10956 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10957 return CMD_WARNING;
10958 }
10959 }
10960
10961 if (argc == 4) {
10962 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10963 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10964 } else {
10965 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10966 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10967 }
10968
10969 if (! peer)
10970 return CMD_WARNING;
10971
10972 if (! peer->afc[AFI_IP][safi])
10973 {
10974 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10975 VTY_NEWLINE);
10976 return CMD_WARNING;
10977}
10978
10979 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10980 PEER_FLAG_RSERVER_CLIENT))
10981{
10982 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10983 VTY_NEWLINE);
10984 return CMD_WARNING;
10985 }
10986
10987 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10988 (argc == 4) ? argv[3] : argv[2],
10989 AFI_IP, safi, NULL, 1);
10990}
10991
10992ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10993 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10994 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10995 SHOW_STR
10996 BGP_STR
10997 "Address family\n"
10998 "Address Family modifier\n"
10999 "Address Family modifier\n"
11000 "Information about Route Server Client\n"
11001 NEIGHBOR_ADDR_STR
11002 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011003
paul718e3742002-12-13 20:15:29 +000011004#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011005DEFUN (show_bgp_view_neighbor_routes,
11006 show_bgp_view_neighbor_routes_cmd,
11007 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11008 SHOW_STR
11009 BGP_STR
11010 "BGP view\n"
11011 "BGP view name\n"
11012 "Detailed information on TCP and BGP neighbor connections\n"
11013 "Neighbor to display information about\n"
11014 "Neighbor to display information about\n"
11015 "Display routes learned from neighbor\n")
11016{
11017 struct peer *peer;
11018
11019 if (argc == 2)
11020 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11021 else
11022 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11023
11024 if (! peer)
11025 return CMD_WARNING;
11026
11027 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11028 bgp_show_type_neighbor);
11029}
11030
11031ALIAS (show_bgp_view_neighbor_routes,
11032 show_bgp_view_ipv6_neighbor_routes_cmd,
11033 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11034 SHOW_STR
11035 BGP_STR
11036 "BGP view\n"
11037 "BGP view name\n"
11038 "Address family\n"
11039 "Detailed information on TCP and BGP neighbor connections\n"
11040 "Neighbor to display information about\n"
11041 "Neighbor to display information about\n"
11042 "Display routes learned from neighbor\n")
11043
11044DEFUN (show_bgp_view_neighbor_damp,
11045 show_bgp_view_neighbor_damp_cmd,
11046 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11047 SHOW_STR
11048 BGP_STR
11049 "BGP view\n"
11050 "BGP view name\n"
11051 "Detailed information on TCP and BGP neighbor connections\n"
11052 "Neighbor to display information about\n"
11053 "Neighbor to display information about\n"
11054 "Display the dampened routes received from neighbor\n")
11055{
11056 struct peer *peer;
11057
11058 if (argc == 2)
11059 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11060 else
11061 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11062
11063 if (! peer)
11064 return CMD_WARNING;
11065
11066 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11067 bgp_show_type_damp_neighbor);
11068}
11069
11070ALIAS (show_bgp_view_neighbor_damp,
11071 show_bgp_view_ipv6_neighbor_damp_cmd,
11072 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11073 SHOW_STR
11074 BGP_STR
11075 "BGP view\n"
11076 "BGP view name\n"
11077 "Address family\n"
11078 "Detailed information on TCP and BGP neighbor connections\n"
11079 "Neighbor to display information about\n"
11080 "Neighbor to display information about\n"
11081 "Display the dampened routes received from neighbor\n")
11082
11083DEFUN (show_bgp_view_neighbor_flap,
11084 show_bgp_view_neighbor_flap_cmd,
11085 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11086 SHOW_STR
11087 BGP_STR
11088 "BGP view\n"
11089 "BGP view name\n"
11090 "Detailed information on TCP and BGP neighbor connections\n"
11091 "Neighbor to display information about\n"
11092 "Neighbor to display information about\n"
11093 "Display flap statistics of the routes learned from neighbor\n")
11094{
11095 struct peer *peer;
11096
11097 if (argc == 2)
11098 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11099 else
11100 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11101
11102 if (! peer)
11103 return CMD_WARNING;
11104
11105 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11106 bgp_show_type_flap_neighbor);
11107}
11108
11109ALIAS (show_bgp_view_neighbor_flap,
11110 show_bgp_view_ipv6_neighbor_flap_cmd,
11111 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11112 SHOW_STR
11113 BGP_STR
11114 "BGP view\n"
11115 "BGP view name\n"
11116 "Address family\n"
11117 "Detailed information on TCP and BGP neighbor connections\n"
11118 "Neighbor to display information about\n"
11119 "Neighbor to display information about\n"
11120 "Display flap statistics of the routes learned from neighbor\n")
11121
11122ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011123 show_bgp_neighbor_routes_cmd,
11124 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11125 SHOW_STR
11126 BGP_STR
11127 "Detailed information on TCP and BGP neighbor connections\n"
11128 "Neighbor to display information about\n"
11129 "Neighbor to display information about\n"
11130 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011131
paulbb46e942003-10-24 19:02:03 +000011132
11133ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011134 show_bgp_ipv6_neighbor_routes_cmd,
11135 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11136 SHOW_STR
11137 BGP_STR
11138 "Address family\n"
11139 "Detailed information on TCP and BGP neighbor connections\n"
11140 "Neighbor to display information about\n"
11141 "Neighbor to display information about\n"
11142 "Display routes learned from neighbor\n")
11143
11144/* old command */
paulbb46e942003-10-24 19:02:03 +000011145ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011146 ipv6_bgp_neighbor_routes_cmd,
11147 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11148 SHOW_STR
11149 IPV6_STR
11150 BGP_STR
11151 "Detailed information on TCP and BGP neighbor connections\n"
11152 "Neighbor to display information about\n"
11153 "Neighbor to display information about\n"
11154 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011155
11156/* old command */
11157DEFUN (ipv6_mbgp_neighbor_routes,
11158 ipv6_mbgp_neighbor_routes_cmd,
11159 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11160 SHOW_STR
11161 IPV6_STR
11162 MBGP_STR
11163 "Detailed information on TCP and BGP neighbor connections\n"
11164 "Neighbor to display information about\n"
11165 "Neighbor to display information about\n"
11166 "Display routes learned from neighbor\n")
11167{
paulbb46e942003-10-24 19:02:03 +000011168 struct peer *peer;
11169
11170 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11171 if (! peer)
11172 return CMD_WARNING;
11173
11174 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011175 bgp_show_type_neighbor);
11176}
paulbb46e942003-10-24 19:02:03 +000011177
11178ALIAS (show_bgp_view_neighbor_flap,
11179 show_bgp_neighbor_flap_cmd,
11180 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11181 SHOW_STR
11182 BGP_STR
11183 "Detailed information on TCP and BGP neighbor connections\n"
11184 "Neighbor to display information about\n"
11185 "Neighbor to display information about\n"
11186 "Display flap statistics of the routes learned from neighbor\n")
11187
11188ALIAS (show_bgp_view_neighbor_flap,
11189 show_bgp_ipv6_neighbor_flap_cmd,
11190 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11191 SHOW_STR
11192 BGP_STR
11193 "Address family\n"
11194 "Detailed information on TCP and BGP neighbor connections\n"
11195 "Neighbor to display information about\n"
11196 "Neighbor to display information about\n"
11197 "Display flap statistics of the routes learned from neighbor\n")
11198
11199ALIAS (show_bgp_view_neighbor_damp,
11200 show_bgp_neighbor_damp_cmd,
11201 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11202 SHOW_STR
11203 BGP_STR
11204 "Detailed information on TCP and BGP neighbor connections\n"
11205 "Neighbor to display information about\n"
11206 "Neighbor to display information about\n"
11207 "Display the dampened routes received from neighbor\n")
11208
11209ALIAS (show_bgp_view_neighbor_damp,
11210 show_bgp_ipv6_neighbor_damp_cmd,
11211 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11212 SHOW_STR
11213 BGP_STR
11214 "Address family\n"
11215 "Detailed information on TCP and BGP neighbor connections\n"
11216 "Neighbor to display information about\n"
11217 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011218 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011219
11220DEFUN (show_bgp_view_rsclient,
11221 show_bgp_view_rsclient_cmd,
11222 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11223 SHOW_STR
11224 BGP_STR
11225 "BGP view\n"
11226 "BGP view name\n"
11227 "Information about Route Server Client\n"
11228 NEIGHBOR_ADDR_STR)
11229{
11230 struct bgp_table *table;
11231 struct peer *peer;
11232
11233 if (argc == 2)
11234 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11235 else
11236 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11237
11238 if (! peer)
11239 return CMD_WARNING;
11240
11241 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11242 {
11243 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11244 VTY_NEWLINE);
11245 return CMD_WARNING;
11246 }
11247
11248 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11249 PEER_FLAG_RSERVER_CLIENT))
11250 {
11251 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11252 VTY_NEWLINE);
11253 return CMD_WARNING;
11254 }
11255
11256 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11257
ajs5a646652004-11-05 01:25:55 +000011258 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011259}
11260
11261ALIAS (show_bgp_view_rsclient,
11262 show_bgp_rsclient_cmd,
11263 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11264 SHOW_STR
11265 BGP_STR
11266 "Information about Route Server Client\n"
11267 NEIGHBOR_ADDR_STR)
11268
Michael Lambert95cbbd22010-07-23 14:43:04 -040011269DEFUN (show_bgp_view_ipv6_safi_rsclient,
11270 show_bgp_view_ipv6_safi_rsclient_cmd,
11271 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11272 SHOW_STR
11273 BGP_STR
11274 "BGP view\n"
11275 "BGP view name\n"
11276 "Address family\n"
11277 "Address Family modifier\n"
11278 "Address Family modifier\n"
11279 "Information about Route Server Client\n"
11280 NEIGHBOR_ADDR_STR)
11281{
11282 struct bgp_table *table;
11283 struct peer *peer;
11284 safi_t safi;
11285
11286 if (argc == 3) {
11287 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11288 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11289 } else {
11290 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11291 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11292 }
11293
11294 if (! peer)
11295 return CMD_WARNING;
11296
11297 if (! peer->afc[AFI_IP6][safi])
11298 {
11299 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11300 VTY_NEWLINE);
11301 return CMD_WARNING;
11302 }
11303
11304 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11305 PEER_FLAG_RSERVER_CLIENT))
11306 {
11307 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11308 VTY_NEWLINE);
11309 return CMD_WARNING;
11310 }
11311
11312 table = peer->rib[AFI_IP6][safi];
11313
11314 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11315}
11316
11317ALIAS (show_bgp_view_ipv6_safi_rsclient,
11318 show_bgp_ipv6_safi_rsclient_cmd,
11319 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11320 SHOW_STR
11321 BGP_STR
11322 "Address family\n"
11323 "Address Family modifier\n"
11324 "Address Family modifier\n"
11325 "Information about Route Server Client\n"
11326 NEIGHBOR_ADDR_STR)
11327
paulfee0f4c2004-09-13 05:12:46 +000011328DEFUN (show_bgp_view_rsclient_route,
11329 show_bgp_view_rsclient_route_cmd,
11330 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11331 SHOW_STR
11332 BGP_STR
11333 "BGP view\n"
11334 "BGP view name\n"
11335 "Information about Route Server Client\n"
11336 NEIGHBOR_ADDR_STR
11337 "Network in the BGP routing table to display\n")
11338{
11339 struct bgp *bgp;
11340 struct peer *peer;
11341
11342 /* BGP structure lookup. */
11343 if (argc == 3)
11344 {
11345 bgp = bgp_lookup_by_name (argv[0]);
11346 if (bgp == NULL)
11347 {
11348 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11349 return CMD_WARNING;
11350 }
11351 }
11352 else
11353 {
11354 bgp = bgp_get_default ();
11355 if (bgp == NULL)
11356 {
11357 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11358 return CMD_WARNING;
11359 }
11360 }
11361
11362 if (argc == 3)
11363 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11364 else
11365 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11366
11367 if (! peer)
11368 return CMD_WARNING;
11369
11370 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11371 {
11372 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11373 VTY_NEWLINE);
11374 return CMD_WARNING;
11375 }
11376
11377 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11378 PEER_FLAG_RSERVER_CLIENT))
11379 {
11380 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11381 VTY_NEWLINE);
11382 return CMD_WARNING;
11383 }
11384
11385 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11386 (argc == 3) ? argv[2] : argv[1],
11387 AFI_IP6, SAFI_UNICAST, NULL, 0);
11388}
11389
11390ALIAS (show_bgp_view_rsclient_route,
11391 show_bgp_rsclient_route_cmd,
11392 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11393 SHOW_STR
11394 BGP_STR
11395 "Information about Route Server Client\n"
11396 NEIGHBOR_ADDR_STR
11397 "Network in the BGP routing table to display\n")
11398
Michael Lambert95cbbd22010-07-23 14:43:04 -040011399DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11400 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11401 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11402 SHOW_STR
11403 BGP_STR
11404 "BGP view\n"
11405 "BGP view name\n"
11406 "Address family\n"
11407 "Address Family modifier\n"
11408 "Address Family modifier\n"
11409 "Information about Route Server Client\n"
11410 NEIGHBOR_ADDR_STR
11411 "Network in the BGP routing table to display\n")
11412{
11413 struct bgp *bgp;
11414 struct peer *peer;
11415 safi_t safi;
11416
11417 /* BGP structure lookup. */
11418 if (argc == 4)
11419 {
11420 bgp = bgp_lookup_by_name (argv[0]);
11421 if (bgp == NULL)
11422 {
11423 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11424 return CMD_WARNING;
11425 }
11426 }
11427 else
11428 {
11429 bgp = bgp_get_default ();
11430 if (bgp == NULL)
11431 {
11432 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11433 return CMD_WARNING;
11434 }
11435 }
11436
11437 if (argc == 4) {
11438 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11439 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11440 } else {
11441 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11442 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11443 }
11444
11445 if (! peer)
11446 return CMD_WARNING;
11447
11448 if (! peer->afc[AFI_IP6][safi])
11449 {
11450 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11451 VTY_NEWLINE);
11452 return CMD_WARNING;
11453}
11454
11455 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11456 PEER_FLAG_RSERVER_CLIENT))
11457 {
11458 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11459 VTY_NEWLINE);
11460 return CMD_WARNING;
11461 }
11462
11463 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11464 (argc == 4) ? argv[3] : argv[2],
11465 AFI_IP6, safi, NULL, 0);
11466}
11467
11468ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11469 show_bgp_ipv6_safi_rsclient_route_cmd,
11470 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11471 SHOW_STR
11472 BGP_STR
11473 "Address family\n"
11474 "Address Family modifier\n"
11475 "Address Family modifier\n"
11476 "Information about Route Server Client\n"
11477 NEIGHBOR_ADDR_STR
11478 "Network in the BGP routing table to display\n")
11479
paulfee0f4c2004-09-13 05:12:46 +000011480DEFUN (show_bgp_view_rsclient_prefix,
11481 show_bgp_view_rsclient_prefix_cmd,
11482 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11483 SHOW_STR
11484 BGP_STR
11485 "BGP view\n"
11486 "BGP view name\n"
11487 "Information about Route Server Client\n"
11488 NEIGHBOR_ADDR_STR
11489 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11490{
11491 struct bgp *bgp;
11492 struct peer *peer;
11493
11494 /* BGP structure lookup. */
11495 if (argc == 3)
11496 {
11497 bgp = bgp_lookup_by_name (argv[0]);
11498 if (bgp == NULL)
11499 {
11500 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11501 return CMD_WARNING;
11502 }
11503 }
11504 else
11505 {
11506 bgp = bgp_get_default ();
11507 if (bgp == NULL)
11508 {
11509 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11510 return CMD_WARNING;
11511 }
11512 }
11513
11514 if (argc == 3)
11515 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11516 else
11517 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11518
11519 if (! peer)
11520 return CMD_WARNING;
11521
11522 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11523 {
11524 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11525 VTY_NEWLINE);
11526 return CMD_WARNING;
11527 }
11528
11529 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11530 PEER_FLAG_RSERVER_CLIENT))
11531 {
11532 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11533 VTY_NEWLINE);
11534 return CMD_WARNING;
11535 }
11536
11537 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11538 (argc == 3) ? argv[2] : argv[1],
11539 AFI_IP6, SAFI_UNICAST, NULL, 1);
11540}
11541
11542ALIAS (show_bgp_view_rsclient_prefix,
11543 show_bgp_rsclient_prefix_cmd,
11544 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11545 SHOW_STR
11546 BGP_STR
11547 "Information about Route Server Client\n"
11548 NEIGHBOR_ADDR_STR
11549 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11550
Michael Lambert95cbbd22010-07-23 14:43:04 -040011551DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11552 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11553 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11554 SHOW_STR
11555 BGP_STR
11556 "BGP view\n"
11557 "BGP view name\n"
11558 "Address family\n"
11559 "Address Family modifier\n"
11560 "Address Family modifier\n"
11561 "Information about Route Server Client\n"
11562 NEIGHBOR_ADDR_STR
11563 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11564{
11565 struct bgp *bgp;
11566 struct peer *peer;
11567 safi_t safi;
11568
11569 /* BGP structure lookup. */
11570 if (argc == 4)
11571 {
11572 bgp = bgp_lookup_by_name (argv[0]);
11573 if (bgp == NULL)
11574 {
11575 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11576 return CMD_WARNING;
11577 }
11578 }
11579 else
11580 {
11581 bgp = bgp_get_default ();
11582 if (bgp == NULL)
11583 {
11584 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11585 return CMD_WARNING;
11586 }
11587 }
11588
11589 if (argc == 4) {
11590 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11591 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11592 } else {
11593 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11594 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11595 }
11596
11597 if (! peer)
11598 return CMD_WARNING;
11599
11600 if (! peer->afc[AFI_IP6][safi])
11601 {
11602 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11603 VTY_NEWLINE);
11604 return CMD_WARNING;
11605}
11606
11607 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11608 PEER_FLAG_RSERVER_CLIENT))
11609{
11610 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11611 VTY_NEWLINE);
11612 return CMD_WARNING;
11613 }
11614
11615 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11616 (argc == 4) ? argv[3] : argv[2],
11617 AFI_IP6, safi, NULL, 1);
11618}
11619
11620ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11621 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11622 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11623 SHOW_STR
11624 BGP_STR
11625 "Address family\n"
11626 "Address Family modifier\n"
11627 "Address Family modifier\n"
11628 "Information about Route Server Client\n"
11629 NEIGHBOR_ADDR_STR
11630 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11631
paul718e3742002-12-13 20:15:29 +000011632#endif /* HAVE_IPV6 */
11633
11634struct bgp_table *bgp_distance_table;
11635
11636struct bgp_distance
11637{
11638 /* Distance value for the IP source prefix. */
11639 u_char distance;
11640
11641 /* Name of the access-list to be matched. */
11642 char *access_list;
11643};
11644
paul94f2b392005-06-28 12:44:16 +000011645static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011646bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011647{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011648 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011649}
11650
paul94f2b392005-06-28 12:44:16 +000011651static void
paul718e3742002-12-13 20:15:29 +000011652bgp_distance_free (struct bgp_distance *bdistance)
11653{
11654 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11655}
11656
paul94f2b392005-06-28 12:44:16 +000011657static int
paulfd79ac92004-10-13 05:06:08 +000011658bgp_distance_set (struct vty *vty, const char *distance_str,
11659 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011660{
11661 int ret;
11662 struct prefix_ipv4 p;
11663 u_char distance;
11664 struct bgp_node *rn;
11665 struct bgp_distance *bdistance;
11666
11667 ret = str2prefix_ipv4 (ip_str, &p);
11668 if (ret == 0)
11669 {
11670 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11671 return CMD_WARNING;
11672 }
11673
11674 distance = atoi (distance_str);
11675
11676 /* Get BGP distance node. */
11677 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11678 if (rn->info)
11679 {
11680 bdistance = rn->info;
11681 bgp_unlock_node (rn);
11682 }
11683 else
11684 {
11685 bdistance = bgp_distance_new ();
11686 rn->info = bdistance;
11687 }
11688
11689 /* Set distance value. */
11690 bdistance->distance = distance;
11691
11692 /* Reset access-list configuration. */
11693 if (bdistance->access_list)
11694 {
11695 free (bdistance->access_list);
11696 bdistance->access_list = NULL;
11697 }
11698 if (access_list_str)
11699 bdistance->access_list = strdup (access_list_str);
11700
11701 return CMD_SUCCESS;
11702}
11703
paul94f2b392005-06-28 12:44:16 +000011704static int
paulfd79ac92004-10-13 05:06:08 +000011705bgp_distance_unset (struct vty *vty, const char *distance_str,
11706 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011707{
11708 int ret;
11709 struct prefix_ipv4 p;
11710 u_char distance;
11711 struct bgp_node *rn;
11712 struct bgp_distance *bdistance;
11713
11714 ret = str2prefix_ipv4 (ip_str, &p);
11715 if (ret == 0)
11716 {
11717 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11718 return CMD_WARNING;
11719 }
11720
11721 distance = atoi (distance_str);
11722
11723 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11724 if (! rn)
11725 {
11726 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11727 return CMD_WARNING;
11728 }
11729
11730 bdistance = rn->info;
11731
11732 if (bdistance->access_list)
11733 free (bdistance->access_list);
11734 bgp_distance_free (bdistance);
11735
11736 rn->info = NULL;
11737 bgp_unlock_node (rn);
11738 bgp_unlock_node (rn);
11739
11740 return CMD_SUCCESS;
11741}
11742
paul718e3742002-12-13 20:15:29 +000011743/* Apply BGP information to distance method. */
11744u_char
11745bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11746{
11747 struct bgp_node *rn;
11748 struct prefix_ipv4 q;
11749 struct peer *peer;
11750 struct bgp_distance *bdistance;
11751 struct access_list *alist;
11752 struct bgp_static *bgp_static;
11753
11754 if (! bgp)
11755 return 0;
11756
11757 if (p->family != AF_INET)
11758 return 0;
11759
11760 peer = rinfo->peer;
11761
11762 if (peer->su.sa.sa_family != AF_INET)
11763 return 0;
11764
11765 memset (&q, 0, sizeof (struct prefix_ipv4));
11766 q.family = AF_INET;
11767 q.prefix = peer->su.sin.sin_addr;
11768 q.prefixlen = IPV4_MAX_BITLEN;
11769
11770 /* Check source address. */
11771 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11772 if (rn)
11773 {
11774 bdistance = rn->info;
11775 bgp_unlock_node (rn);
11776
11777 if (bdistance->access_list)
11778 {
11779 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11780 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11781 return bdistance->distance;
11782 }
11783 else
11784 return bdistance->distance;
11785 }
11786
11787 /* Backdoor check. */
11788 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11789 if (rn)
11790 {
11791 bgp_static = rn->info;
11792 bgp_unlock_node (rn);
11793
11794 if (bgp_static->backdoor)
11795 {
11796 if (bgp->distance_local)
11797 return bgp->distance_local;
11798 else
11799 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11800 }
11801 }
11802
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011803 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011804 {
11805 if (bgp->distance_ebgp)
11806 return bgp->distance_ebgp;
11807 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11808 }
11809 else
11810 {
11811 if (bgp->distance_ibgp)
11812 return bgp->distance_ibgp;
11813 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11814 }
11815}
11816
11817DEFUN (bgp_distance,
11818 bgp_distance_cmd,
11819 "distance bgp <1-255> <1-255> <1-255>",
11820 "Define an administrative distance\n"
11821 "BGP distance\n"
11822 "Distance for routes external to the AS\n"
11823 "Distance for routes internal to the AS\n"
11824 "Distance for local routes\n")
11825{
11826 struct bgp *bgp;
11827
11828 bgp = vty->index;
11829
11830 bgp->distance_ebgp = atoi (argv[0]);
11831 bgp->distance_ibgp = atoi (argv[1]);
11832 bgp->distance_local = atoi (argv[2]);
11833 return CMD_SUCCESS;
11834}
11835
11836DEFUN (no_bgp_distance,
11837 no_bgp_distance_cmd,
11838 "no distance bgp <1-255> <1-255> <1-255>",
11839 NO_STR
11840 "Define an administrative distance\n"
11841 "BGP distance\n"
11842 "Distance for routes external to the AS\n"
11843 "Distance for routes internal to the AS\n"
11844 "Distance for local routes\n")
11845{
11846 struct bgp *bgp;
11847
11848 bgp = vty->index;
11849
11850 bgp->distance_ebgp= 0;
11851 bgp->distance_ibgp = 0;
11852 bgp->distance_local = 0;
11853 return CMD_SUCCESS;
11854}
11855
11856ALIAS (no_bgp_distance,
11857 no_bgp_distance2_cmd,
11858 "no distance bgp",
11859 NO_STR
11860 "Define an administrative distance\n"
11861 "BGP distance\n")
11862
11863DEFUN (bgp_distance_source,
11864 bgp_distance_source_cmd,
11865 "distance <1-255> A.B.C.D/M",
11866 "Define an administrative distance\n"
11867 "Administrative distance\n"
11868 "IP source prefix\n")
11869{
11870 bgp_distance_set (vty, argv[0], argv[1], NULL);
11871 return CMD_SUCCESS;
11872}
11873
11874DEFUN (no_bgp_distance_source,
11875 no_bgp_distance_source_cmd,
11876 "no distance <1-255> A.B.C.D/M",
11877 NO_STR
11878 "Define an administrative distance\n"
11879 "Administrative distance\n"
11880 "IP source prefix\n")
11881{
11882 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11883 return CMD_SUCCESS;
11884}
11885
11886DEFUN (bgp_distance_source_access_list,
11887 bgp_distance_source_access_list_cmd,
11888 "distance <1-255> A.B.C.D/M WORD",
11889 "Define an administrative distance\n"
11890 "Administrative distance\n"
11891 "IP source prefix\n"
11892 "Access list name\n")
11893{
11894 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11895 return CMD_SUCCESS;
11896}
11897
11898DEFUN (no_bgp_distance_source_access_list,
11899 no_bgp_distance_source_access_list_cmd,
11900 "no distance <1-255> A.B.C.D/M WORD",
11901 NO_STR
11902 "Define an administrative distance\n"
11903 "Administrative distance\n"
11904 "IP source prefix\n"
11905 "Access list name\n")
11906{
11907 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11908 return CMD_SUCCESS;
11909}
11910
11911DEFUN (bgp_damp_set,
11912 bgp_damp_set_cmd,
11913 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11914 "BGP Specific commands\n"
11915 "Enable route-flap dampening\n"
11916 "Half-life time for the penalty\n"
11917 "Value to start reusing a route\n"
11918 "Value to start suppressing a route\n"
11919 "Maximum duration to suppress a stable route\n")
11920{
11921 struct bgp *bgp;
11922 int half = DEFAULT_HALF_LIFE * 60;
11923 int reuse = DEFAULT_REUSE;
11924 int suppress = DEFAULT_SUPPRESS;
11925 int max = 4 * half;
11926
11927 if (argc == 4)
11928 {
11929 half = atoi (argv[0]) * 60;
11930 reuse = atoi (argv[1]);
11931 suppress = atoi (argv[2]);
11932 max = atoi (argv[3]) * 60;
11933 }
11934 else if (argc == 1)
11935 {
11936 half = atoi (argv[0]) * 60;
11937 max = 4 * half;
11938 }
11939
11940 bgp = vty->index;
11941 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11942 half, reuse, suppress, max);
11943}
11944
11945ALIAS (bgp_damp_set,
11946 bgp_damp_set2_cmd,
11947 "bgp dampening <1-45>",
11948 "BGP Specific commands\n"
11949 "Enable route-flap dampening\n"
11950 "Half-life time for the penalty\n")
11951
11952ALIAS (bgp_damp_set,
11953 bgp_damp_set3_cmd,
11954 "bgp dampening",
11955 "BGP Specific commands\n"
11956 "Enable route-flap dampening\n")
11957
11958DEFUN (bgp_damp_unset,
11959 bgp_damp_unset_cmd,
11960 "no bgp dampening",
11961 NO_STR
11962 "BGP Specific commands\n"
11963 "Enable route-flap dampening\n")
11964{
11965 struct bgp *bgp;
11966
11967 bgp = vty->index;
11968 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11969}
11970
11971ALIAS (bgp_damp_unset,
11972 bgp_damp_unset2_cmd,
11973 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11974 NO_STR
11975 "BGP Specific commands\n"
11976 "Enable route-flap dampening\n"
11977 "Half-life time for the penalty\n"
11978 "Value to start reusing a route\n"
11979 "Value to start suppressing a route\n"
11980 "Maximum duration to suppress a stable route\n")
11981
11982DEFUN (show_ip_bgp_dampened_paths,
11983 show_ip_bgp_dampened_paths_cmd,
11984 "show ip bgp dampened-paths",
11985 SHOW_STR
11986 IP_STR
11987 BGP_STR
11988 "Display paths suppressed due to dampening\n")
11989{
ajs5a646652004-11-05 01:25:55 +000011990 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11991 NULL);
paul718e3742002-12-13 20:15:29 +000011992}
11993
11994DEFUN (show_ip_bgp_flap_statistics,
11995 show_ip_bgp_flap_statistics_cmd,
11996 "show ip bgp flap-statistics",
11997 SHOW_STR
11998 IP_STR
11999 BGP_STR
12000 "Display flap statistics of routes\n")
12001{
ajs5a646652004-11-05 01:25:55 +000012002 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12003 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012004}
12005
12006/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012007static int
paulfd79ac92004-10-13 05:06:08 +000012008bgp_clear_damp_route (struct vty *vty, const char *view_name,
12009 const char *ip_str, afi_t afi, safi_t safi,
12010 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012011{
12012 int ret;
12013 struct prefix match;
12014 struct bgp_node *rn;
12015 struct bgp_node *rm;
12016 struct bgp_info *ri;
12017 struct bgp_info *ri_temp;
12018 struct bgp *bgp;
12019 struct bgp_table *table;
12020
12021 /* BGP structure lookup. */
12022 if (view_name)
12023 {
12024 bgp = bgp_lookup_by_name (view_name);
12025 if (bgp == NULL)
12026 {
12027 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12028 return CMD_WARNING;
12029 }
12030 }
12031 else
12032 {
12033 bgp = bgp_get_default ();
12034 if (bgp == NULL)
12035 {
12036 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12037 return CMD_WARNING;
12038 }
12039 }
12040
12041 /* Check IP address argument. */
12042 ret = str2prefix (ip_str, &match);
12043 if (! ret)
12044 {
12045 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12046 return CMD_WARNING;
12047 }
12048
12049 match.family = afi2family (afi);
12050
12051 if (safi == SAFI_MPLS_VPN)
12052 {
12053 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12054 {
12055 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12056 continue;
12057
12058 if ((table = rn->info) != NULL)
12059 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012060 {
12061 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12062 {
12063 ri = rm->info;
12064 while (ri)
12065 {
12066 if (ri->extra && ri->extra->damp_info)
12067 {
12068 ri_temp = ri->next;
12069 bgp_damp_info_free (ri->extra->damp_info, 1);
12070 ri = ri_temp;
12071 }
12072 else
12073 ri = ri->next;
12074 }
12075 }
12076
12077 bgp_unlock_node (rm);
12078 }
paul718e3742002-12-13 20:15:29 +000012079 }
12080 }
12081 else
12082 {
12083 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012084 {
12085 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12086 {
12087 ri = rn->info;
12088 while (ri)
12089 {
12090 if (ri->extra && ri->extra->damp_info)
12091 {
12092 ri_temp = ri->next;
12093 bgp_damp_info_free (ri->extra->damp_info, 1);
12094 ri = ri_temp;
12095 }
12096 else
12097 ri = ri->next;
12098 }
12099 }
12100
12101 bgp_unlock_node (rn);
12102 }
paul718e3742002-12-13 20:15:29 +000012103 }
12104
12105 return CMD_SUCCESS;
12106}
12107
12108DEFUN (clear_ip_bgp_dampening,
12109 clear_ip_bgp_dampening_cmd,
12110 "clear ip bgp dampening",
12111 CLEAR_STR
12112 IP_STR
12113 BGP_STR
12114 "Clear route flap dampening information\n")
12115{
12116 bgp_damp_info_clean ();
12117 return CMD_SUCCESS;
12118}
12119
12120DEFUN (clear_ip_bgp_dampening_prefix,
12121 clear_ip_bgp_dampening_prefix_cmd,
12122 "clear ip bgp dampening A.B.C.D/M",
12123 CLEAR_STR
12124 IP_STR
12125 BGP_STR
12126 "Clear route flap dampening information\n"
12127 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12128{
12129 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12130 SAFI_UNICAST, NULL, 1);
12131}
12132
12133DEFUN (clear_ip_bgp_dampening_address,
12134 clear_ip_bgp_dampening_address_cmd,
12135 "clear ip bgp dampening A.B.C.D",
12136 CLEAR_STR
12137 IP_STR
12138 BGP_STR
12139 "Clear route flap dampening information\n"
12140 "Network to clear damping information\n")
12141{
12142 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12143 SAFI_UNICAST, NULL, 0);
12144}
12145
12146DEFUN (clear_ip_bgp_dampening_address_mask,
12147 clear_ip_bgp_dampening_address_mask_cmd,
12148 "clear ip bgp dampening A.B.C.D A.B.C.D",
12149 CLEAR_STR
12150 IP_STR
12151 BGP_STR
12152 "Clear route flap dampening information\n"
12153 "Network to clear damping information\n"
12154 "Network mask\n")
12155{
12156 int ret;
12157 char prefix_str[BUFSIZ];
12158
12159 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12160 if (! ret)
12161 {
12162 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12163 return CMD_WARNING;
12164 }
12165
12166 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12167 SAFI_UNICAST, NULL, 0);
12168}
12169
paul94f2b392005-06-28 12:44:16 +000012170static int
paul718e3742002-12-13 20:15:29 +000012171bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12172 afi_t afi, safi_t safi, int *write)
12173{
12174 struct bgp_node *prn;
12175 struct bgp_node *rn;
12176 struct bgp_table *table;
12177 struct prefix *p;
12178 struct prefix_rd *prd;
12179 struct bgp_static *bgp_static;
12180 u_int32_t label;
12181 char buf[SU_ADDRSTRLEN];
12182 char rdbuf[RD_ADDRSTRLEN];
12183
12184 /* Network configuration. */
12185 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12186 if ((table = prn->info) != NULL)
12187 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12188 if ((bgp_static = rn->info) != NULL)
12189 {
12190 p = &rn->p;
12191 prd = (struct prefix_rd *) &prn->p;
12192
12193 /* "address-family" display. */
12194 bgp_config_write_family_header (vty, afi, safi, write);
12195
12196 /* "network" configuration display. */
12197 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12198 label = decode_label (bgp_static->tag);
12199
12200 vty_out (vty, " network %s/%d rd %s tag %d",
12201 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12202 p->prefixlen,
12203 rdbuf, label);
12204 vty_out (vty, "%s", VTY_NEWLINE);
12205 }
12206 return 0;
12207}
12208
12209/* Configuration of static route announcement and aggregate
12210 information. */
12211int
12212bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12213 afi_t afi, safi_t safi, int *write)
12214{
12215 struct bgp_node *rn;
12216 struct prefix *p;
12217 struct bgp_static *bgp_static;
12218 struct bgp_aggregate *bgp_aggregate;
12219 char buf[SU_ADDRSTRLEN];
12220
12221 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12222 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12223
12224 /* Network configuration. */
12225 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12226 if ((bgp_static = rn->info) != NULL)
12227 {
12228 p = &rn->p;
12229
12230 /* "address-family" display. */
12231 bgp_config_write_family_header (vty, afi, safi, write);
12232
12233 /* "network" configuration display. */
12234 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12235 {
12236 u_int32_t destination;
12237 struct in_addr netmask;
12238
12239 destination = ntohl (p->u.prefix4.s_addr);
12240 masklen2ip (p->prefixlen, &netmask);
12241 vty_out (vty, " network %s",
12242 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12243
12244 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12245 || (IN_CLASSB (destination) && p->prefixlen == 16)
12246 || (IN_CLASSA (destination) && p->prefixlen == 8)
12247 || p->u.prefix4.s_addr == 0)
12248 {
12249 /* Natural mask is not display. */
12250 }
12251 else
12252 vty_out (vty, " mask %s", inet_ntoa (netmask));
12253 }
12254 else
12255 {
12256 vty_out (vty, " network %s/%d",
12257 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12258 p->prefixlen);
12259 }
12260
12261 if (bgp_static->rmap.name)
12262 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012263 else
12264 {
12265 if (bgp_static->backdoor)
12266 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012267 }
paul718e3742002-12-13 20:15:29 +000012268
12269 vty_out (vty, "%s", VTY_NEWLINE);
12270 }
12271
12272 /* Aggregate-address configuration. */
12273 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12274 if ((bgp_aggregate = rn->info) != NULL)
12275 {
12276 p = &rn->p;
12277
12278 /* "address-family" display. */
12279 bgp_config_write_family_header (vty, afi, safi, write);
12280
12281 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12282 {
12283 struct in_addr netmask;
12284
12285 masklen2ip (p->prefixlen, &netmask);
12286 vty_out (vty, " aggregate-address %s %s",
12287 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12288 inet_ntoa (netmask));
12289 }
12290 else
12291 {
12292 vty_out (vty, " aggregate-address %s/%d",
12293 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12294 p->prefixlen);
12295 }
12296
12297 if (bgp_aggregate->as_set)
12298 vty_out (vty, " as-set");
12299
12300 if (bgp_aggregate->summary_only)
12301 vty_out (vty, " summary-only");
12302
12303 vty_out (vty, "%s", VTY_NEWLINE);
12304 }
12305
12306 return 0;
12307}
12308
12309int
12310bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12311{
12312 struct bgp_node *rn;
12313 struct bgp_distance *bdistance;
12314
12315 /* Distance configuration. */
12316 if (bgp->distance_ebgp
12317 && bgp->distance_ibgp
12318 && bgp->distance_local
12319 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12320 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12321 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12322 vty_out (vty, " distance bgp %d %d %d%s",
12323 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12324 VTY_NEWLINE);
12325
12326 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12327 if ((bdistance = rn->info) != NULL)
12328 {
12329 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12330 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12331 bdistance->access_list ? bdistance->access_list : "",
12332 VTY_NEWLINE);
12333 }
12334
12335 return 0;
12336}
12337
12338/* Allocate routing table structure and install commands. */
12339void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012340bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012341{
12342 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012343 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012344
12345 /* IPv4 BGP commands. */
12346 install_element (BGP_NODE, &bgp_network_cmd);
12347 install_element (BGP_NODE, &bgp_network_mask_cmd);
12348 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12349 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12350 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12351 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12352 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12353 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12354 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12355 install_element (BGP_NODE, &no_bgp_network_cmd);
12356 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12357 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12358 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12359 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12360 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12361 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12362 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12363 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12364
12365 install_element (BGP_NODE, &aggregate_address_cmd);
12366 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12367 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12368 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12369 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12370 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12371 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12372 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12373 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12374 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12375 install_element (BGP_NODE, &no_aggregate_address_cmd);
12376 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12377 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12378 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12379 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12380 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12381 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12382 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12383 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12384 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12385
12386 /* IPv4 unicast configuration. */
12387 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12388 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12389 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12390 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12391 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12392 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012393 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012394 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12395 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12396 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12397 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12398 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012399
paul718e3742002-12-13 20:15:29 +000012400 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12401 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12402 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12403 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12404 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12405 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12406 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12407 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12408 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12409 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12410 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12411 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12412 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12413 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12414 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12415 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12416 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12417 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12418 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12419 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12420
12421 /* IPv4 multicast configuration. */
12422 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12423 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12424 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12425 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12426 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12427 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12428 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12429 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12430 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12431 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12432 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12433 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12434 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12435 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12436 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12437 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12438 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12439 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12440 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12441 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12442 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12443 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12444 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12445 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12446 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12447 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12448 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12449 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12450 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12451 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12452 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12453 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12454
12455 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12456 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012457 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012458 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12459 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012460 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012461 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12462 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12463 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012465 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012466 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12467 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12468 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012491 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12492 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12493 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12494 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12495 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012496 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012514 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012515 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12528 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12529 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12530 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012531 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012532 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012533 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012534 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012535 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012536 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012537 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12538 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012539 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012540 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012541 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012542 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012543 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012544 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012545
12546 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12547 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12548 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012549 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012550 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12551 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12552 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012553 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012554 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12555 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12556 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12557 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12558 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12559 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12560 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12561 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12562 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12563 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12564 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12565 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012566 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12567 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12568 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12569 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12570 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012571 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12572 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12573 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12574 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12575 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12576 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12577 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12578 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12579 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012580 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012581 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012582 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012583 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012584 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012585 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012586 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012587
12588 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012590 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012591 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12592 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012593 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012594 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12595 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12596 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012598 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012599 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12600 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12601 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012624 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12625 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12626 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12627 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12628 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012629 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012647 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012648 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12661 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12662 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12663 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012664 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012665 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012666 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012667 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012668 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012669 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012670 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12671 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012672 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012673 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012674 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012675 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012676 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012677 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012678
12679 /* BGP dampening clear commands */
12680 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12681 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12682 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12683 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12684
Paul Jakmaff7924f2006-09-04 01:10:36 +000012685 /* prefix count */
12686 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12687 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12688 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012689#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012690 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12691
paul718e3742002-12-13 20:15:29 +000012692 /* New config IPv6 BGP commands. */
12693 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12694 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12695 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12696 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12697
12698 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12699 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12700 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12701 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12702
G.Balaji73bfe0b2011-09-23 22:36:20 +053012703 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12704 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12705
paul718e3742002-12-13 20:15:29 +000012706 /* Old config IPv6 BGP commands. */
12707 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12708 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12709
12710 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12711 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12712 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12713 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12714
12715 install_element (VIEW_NODE, &show_bgp_cmd);
12716 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012717 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012718 install_element (VIEW_NODE, &show_bgp_route_cmd);
12719 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012720 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012721 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12722 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012723 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012724 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12725 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12726 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12727 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12728 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12729 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12730 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12731 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12732 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12733 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12734 install_element (VIEW_NODE, &show_bgp_community_cmd);
12735 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12736 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12737 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12738 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12739 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12740 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12741 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12742 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12743 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12744 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12745 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12746 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12748 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12750 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12751 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12752 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12754 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12756 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12758 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12760 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12762 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12763 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012764 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12765 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12766 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12767 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012768 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012769 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012770 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012771 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012772 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012773 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012774 install_element (VIEW_NODE, &show_bgp_view_cmd);
12775 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12776 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12777 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12778 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12779 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12780 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12781 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12782 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12783 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12784 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12785 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12786 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12787 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12788 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12789 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12790 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12791 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012792 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012793 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012794 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012795 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012796 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012797 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012798
12799 /* Restricted:
12800 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12801 */
12802 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12803 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012804 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012805 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12806 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012807 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012808 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12809 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12810 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12811 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12812 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12813 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12814 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12815 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12816 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12817 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12818 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12820 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12821 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12822 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12823 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12824 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012825 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012826 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012827 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012828 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12829 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12830 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12832 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12833 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12834 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012835 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012836 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012837 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012838
12839 install_element (ENABLE_NODE, &show_bgp_cmd);
12840 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012841 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012842 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12843 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012844 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012845 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12846 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012847 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012848 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12849 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12850 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12852 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012888 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12889 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12890 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12891 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012892 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012893 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012894 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012895 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012896 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012897 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012898 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12913 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12914 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12915 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012916 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012917 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012918 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012919 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012920 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012921 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012922
12923 /* Statistics */
12924 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12925 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12926 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12927 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12928
paul718e3742002-12-13 20:15:29 +000012929 /* old command */
12930 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12931 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12932 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12933 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12934 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12935 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12936 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12937 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12938 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12939 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12940 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12941 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12942 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12943 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12944 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12945 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12946 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12948 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12949 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12950 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12951 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12963 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12964 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12965 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012966
paul718e3742002-12-13 20:15:29 +000012967 /* old command */
12968 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12969 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12970 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12971 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12972 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12973 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12974 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12975 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12976 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12977 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12978 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12979 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12980 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12981 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12982 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12983 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12984 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12986 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12987 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12988 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12989 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
13001 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
13002 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13003 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13004
13005 /* old command */
13006 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13007 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13008 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13009 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13010
13011 /* old command */
13012 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13013 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13014 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13015 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13016
13017 /* old command */
13018 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13019 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13020 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13021 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13022#endif /* HAVE_IPV6 */
13023
13024 install_element (BGP_NODE, &bgp_distance_cmd);
13025 install_element (BGP_NODE, &no_bgp_distance_cmd);
13026 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13027 install_element (BGP_NODE, &bgp_distance_source_cmd);
13028 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13029 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13030 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13031
13032 install_element (BGP_NODE, &bgp_damp_set_cmd);
13033 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13034 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13035 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13036 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13037 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13038 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13039 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13040 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13041 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013042
13043 /* Deprecated AS-Pathlimit commands */
13044 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13045 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13046 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13047 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13048 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13049 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13050
13051 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13052 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13053 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13054 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13055 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13056 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13057
13058 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13059 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13060 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13061 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13062 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13063 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13064
13065 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13066 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13067 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13068 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13069 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13070 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13071
13072 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13073 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13074 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13075 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13076 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13077 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13078
13079 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13080 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13081 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13082 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13083 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13084 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013085
13086#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013087 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13088 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013089#endif
paul718e3742002-12-13 20:15:29 +000013090}
Chris Caputo228da422009-07-18 05:44:03 +000013091
13092void
13093bgp_route_finish (void)
13094{
13095 bgp_table_unlock (bgp_distance_table);
13096 bgp_distance_table = NULL;
13097}