blob: a421fd7ceaaff1e0f1759967231fa7e7cedb5402 [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;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001054 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001055
paul718e3742002-12-13 20:15:29 +00001056 info.peer = peer;
1057 info.attr = attr;
1058
1059 /* The route reflector is not allowed to modify the attributes
1060 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001061 if (from->sort == BGP_PEER_IBGP
1062 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001063 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001064 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001065 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001066 }
paulac41b2a2003-08-12 05:32:27 +00001067
1068 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1069
Paul Jakmafb982c22007-05-04 20:15:47 +00001070 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001071 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1072 else
1073 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1074
paulac41b2a2003-08-12 05:32:27 +00001075 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001076
Paul Jakma9eda90c2007-08-30 13:36:17 +00001077 if (dummy_attr.extra)
1078 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +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;
1215
1216 assert (attr->extra);
1217
paulfee0f4c2004-09-13 05:12:46 +00001218 /* Left nexthop_local unchanged if so configured. */
1219 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1220 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1221 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001222 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1223 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001224 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001225 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001226 }
1227
1228 /* Default nexthop_local treatment for RS-Clients */
1229 else
1230 {
1231 /* Announcer and RS-Client are both in the same network */
1232 if (rsclient->shared_network && from->shared_network &&
1233 (rsclient->ifindex == from->ifindex))
1234 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001235 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1236 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001237 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001238 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001239 }
1240
1241 /* Set link-local address for shared network peer. */
1242 else if (rsclient->shared_network
1243 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1244 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001245 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001246 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001248 }
1249
1250 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001251 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001252 }
1253
1254 }
1255#endif /* HAVE_IPV6 */
1256
1257
1258 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001259 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001260 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1261 && aspath_private_as_check (attr->aspath))
1262 attr->aspath = aspath_empty_get ();
1263
1264 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001265 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001266 {
1267 info.peer = rsclient;
1268 info.attr = attr;
1269
1270 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1271
Paul Jakmafb982c22007-05-04 20:15:47 +00001272 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001273 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1274 else
1275 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1276
1277 rsclient->rmap_type = 0;
1278
1279 if (ret == RMAP_DENYMATCH)
1280 {
1281 bgp_attr_flush (attr);
1282 return 0;
1283 }
1284 }
1285
1286 return 1;
1287}
1288
1289struct bgp_info_pair
1290{
1291 struct bgp_info *old;
1292 struct bgp_info *new;
1293};
1294
paul94f2b392005-06-28 12:44:16 +00001295static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001296bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1297 struct bgp_maxpaths_cfg *mpath_cfg,
1298 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001299{
paul718e3742002-12-13 20:15:29 +00001300 struct bgp_info *new_select;
1301 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001302 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001303 struct bgp_info *ri1;
1304 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001305 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001306 int paths_eq, do_mpath;
1307 struct list mp_list;
1308
1309 bgp_mp_list_init (&mp_list);
1310 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1311 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1312
paul718e3742002-12-13 20:15:29 +00001313 /* bgp deterministic-med */
1314 new_select = NULL;
1315 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1316 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1317 {
1318 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1319 continue;
1320 if (BGP_INFO_HOLDDOWN (ri1))
1321 continue;
1322
1323 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001324 if (do_mpath)
1325 bgp_mp_list_add (&mp_list, ri1);
1326 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001327 if (ri1->next)
1328 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1329 {
1330 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1331 continue;
1332 if (BGP_INFO_HOLDDOWN (ri2))
1333 continue;
1334
1335 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1336 || aspath_cmp_left_confed (ri1->attr->aspath,
1337 ri2->attr->aspath))
1338 {
Josh Bailey6918e742011-07-20 20:48:20 -07001339 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1340 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001341 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001342 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001343 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001344 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001345 if (do_mpath && !paths_eq)
1346 {
1347 bgp_mp_list_clear (&mp_list);
1348 bgp_mp_list_add (&mp_list, ri2);
1349 }
paul718e3742002-12-13 20:15:29 +00001350 }
1351
Josh Bailey6918e742011-07-20 20:48:20 -07001352 if (do_mpath && paths_eq)
1353 bgp_mp_list_add (&mp_list, ri2);
1354
Paul Jakma1a392d42006-09-07 00:24:49 +00001355 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001356 }
1357 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001358 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1359 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001360
1361 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1362 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001363 }
1364
1365 /* Check old selected route and new selected route. */
1366 old_select = NULL;
1367 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001368 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001369 {
1370 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1371 old_select = ri;
1372
1373 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001374 {
1375 /* reap REMOVED routes, if needs be
1376 * selected route must stay for a while longer though
1377 */
1378 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1379 && (ri != old_select))
1380 bgp_info_reap (rn, ri);
1381
1382 continue;
1383 }
paul718e3742002-12-13 20:15:29 +00001384
1385 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1386 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1387 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001388 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001389 continue;
1390 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001391 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1392 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001393
Josh Bailey96450fa2011-07-20 20:45:12 -07001394 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1395 {
Josh Bailey6918e742011-07-20 20:48:20 -07001396 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1397 bgp_mp_dmed_deselect (new_select);
1398
Josh Bailey96450fa2011-07-20 20:45:12 -07001399 new_select = ri;
1400
1401 if (do_mpath && !paths_eq)
1402 {
1403 bgp_mp_list_clear (&mp_list);
1404 bgp_mp_list_add (&mp_list, ri);
1405 }
1406 }
Josh Bailey6918e742011-07-20 20:48:20 -07001407 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1408 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001409
1410 if (do_mpath && paths_eq)
1411 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001412 }
paulb40d9392005-08-22 22:34:41 +00001413
paulfee0f4c2004-09-13 05:12:46 +00001414
Josh Bailey6918e742011-07-20 20:48:20 -07001415 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1416 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001417
Josh Bailey0b597ef2011-07-20 20:49:11 -07001418 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001419 bgp_mp_list_clear (&mp_list);
1420
1421 result->old = old_select;
1422 result->new = new_select;
1423
1424 return;
paulfee0f4c2004-09-13 05:12:46 +00001425}
1426
paul94f2b392005-06-28 12:44:16 +00001427static int
paulfee0f4c2004-09-13 05:12:46 +00001428bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001429 struct bgp_node *rn, afi_t afi, safi_t safi)
1430{
paulfee0f4c2004-09-13 05:12:46 +00001431 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001432 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001433
1434 p = &rn->p;
1435
Paul Jakma9eda90c2007-08-30 13:36:17 +00001436 /* Announce route to Established peer. */
1437 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001438 return 0;
1439
Paul Jakma9eda90c2007-08-30 13:36:17 +00001440 /* Address family configuration check. */
1441 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001442 return 0;
1443
Paul Jakma9eda90c2007-08-30 13:36:17 +00001444 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001445 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1446 PEER_STATUS_ORF_WAIT_REFRESH))
1447 return 0;
1448
1449 switch (rn->table->type)
1450 {
1451 case BGP_TABLE_MAIN:
1452 /* Announcement to peer->conf. If the route is filtered,
1453 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001454 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1455 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001456 else
1457 bgp_adj_out_unset (rn, peer, p, afi, safi);
1458 break;
1459 case BGP_TABLE_RSCLIENT:
1460 /* Announcement to peer->conf. If the route is filtered,
1461 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001462 if (selected &&
1463 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1464 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1465 else
1466 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001467 break;
1468 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001469
1470 bgp_attr_extra_free (&attr);
1471
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;
Paul Jakmafb982c22007-05-04 20:15:47 +00001833 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001834 struct attr *attr_new;
1835 struct attr *attr_new2;
1836 struct bgp_info *ri;
1837 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001838 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001839 char buf[SU_ADDRSTRLEN];
1840
1841 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1842 if (peer == rsclient)
1843 return;
1844
1845 bgp = peer->bgp;
1846 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1847
1848 /* Check previously received route. */
1849 for (ri = rn->info; ri; ri = ri->next)
1850 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1851 break;
1852
1853 /* AS path loop check. */
1854 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1855 {
1856 reason = "as-path contains our own AS;";
1857 goto filtered;
1858 }
1859
1860 /* Route reflector originator ID check. */
1861 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001862 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001863 {
1864 reason = "originator is us;";
1865 goto filtered;
1866 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001867
1868 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001869
1870 /* Apply export policy. */
1871 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1872 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1873 {
1874 reason = "export-policy;";
1875 goto filtered;
1876 }
1877
1878 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001879
paulfee0f4c2004-09-13 05:12:46 +00001880 /* Apply import policy. */
1881 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1882 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001883 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001884
1885 reason = "import-policy;";
1886 goto filtered;
1887 }
1888
1889 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001890 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001891
1892 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001893 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001894 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001895 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001896 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001897 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001898 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001899 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001900
1901 reason = "martian next-hop;";
1902 goto filtered;
1903 }
1904 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001905
1906 /* new_attr isn't passed to any functions after here */
1907 bgp_attr_extra_free (&new_attr);
1908
paulfee0f4c2004-09-13 05:12:46 +00001909 /* If the update is implicit withdraw. */
1910 if (ri)
1911 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001912 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001913
1914 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001915 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1916 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001917 {
1918
Paul Jakma1a392d42006-09-07 00:24:49 +00001919 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001920
1921 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001922 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001923 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1924 peer->host,
1925 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1926 p->prefixlen, rsclient->host);
1927
Chris Caputo228da422009-07-18 05:44:03 +00001928 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001929 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001930
Chris Caputo228da422009-07-18 05:44:03 +00001931 return;
paulfee0f4c2004-09-13 05:12:46 +00001932 }
1933
Paul Jakma16d2e242007-04-10 19:32:10 +00001934 /* Withdraw/Announce before we fully processed the withdraw */
1935 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1936 bgp_info_restore (rn, ri);
1937
paulfee0f4c2004-09-13 05:12:46 +00001938 /* Received Logging. */
1939 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001940 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001941 peer->host,
1942 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1943 p->prefixlen, rsclient->host);
1944
1945 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001946 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001947
1948 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001949 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001950 ri->attr = attr_new;
1951
1952 /* Update MPLS tag. */
1953 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001954 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001955
Paul Jakma1a392d42006-09-07 00:24:49 +00001956 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001957
1958 /* Process change. */
1959 bgp_process (bgp, rn, afi, safi);
1960 bgp_unlock_node (rn);
1961
1962 return;
1963 }
1964
1965 /* Received Logging. */
1966 if (BGP_DEBUG (update, UPDATE_IN))
1967 {
ajsd2c1f162004-12-08 21:10:20 +00001968 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001969 peer->host,
1970 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1971 p->prefixlen, rsclient->host);
1972 }
1973
1974 /* Make new BGP info. */
1975 new = bgp_info_new ();
1976 new->type = type;
1977 new->sub_type = sub_type;
1978 new->peer = peer;
1979 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001980 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001981
1982 /* Update MPLS tag. */
1983 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001984 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001985
Paul Jakma1a392d42006-09-07 00:24:49 +00001986 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001987
1988 /* Register new BGP information. */
1989 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001990
1991 /* route_node_get lock */
1992 bgp_unlock_node (rn);
1993
paulfee0f4c2004-09-13 05:12:46 +00001994 /* Process change. */
1995 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001996
1997 bgp_attr_extra_free (&new_attr);
1998
paulfee0f4c2004-09-13 05:12:46 +00001999 return;
2000
2001 filtered:
2002
2003 /* This BGP update is filtered. Log the reason then update BGP entry. */
2004 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002005 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002006 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2007 peer->host,
2008 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2009 p->prefixlen, rsclient->host, reason);
2010
2011 if (ri)
paulb40d9392005-08-22 22:34:41 +00002012 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002013
2014 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002015
2016 if (new_attr.extra)
2017 bgp_attr_extra_free (&new_attr);
2018
paulfee0f4c2004-09-13 05:12:46 +00002019 return;
2020}
2021
paul94f2b392005-06-28 12:44:16 +00002022static void
paulfee0f4c2004-09-13 05:12:46 +00002023bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2024 struct peer *peer, struct prefix *p, int type, int sub_type,
2025 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002026{
paulfee0f4c2004-09-13 05:12:46 +00002027 struct bgp_node *rn;
2028 struct bgp_info *ri;
2029 char buf[SU_ADDRSTRLEN];
2030
2031 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002032 return;
paulfee0f4c2004-09-13 05:12:46 +00002033
2034 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2035
2036 /* Lookup withdrawn route. */
2037 for (ri = rn->info; ri; ri = ri->next)
2038 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2039 break;
2040
2041 /* Withdraw specified route from routing table. */
2042 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002043 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002044 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002045 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002046 "%s Can't find the route %s/%d", peer->host,
2047 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2048 p->prefixlen);
2049
2050 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002051 bgp_unlock_node (rn);
2052}
paulfee0f4c2004-09-13 05:12:46 +00002053
paul94f2b392005-06-28 12:44:16 +00002054static int
paulfee0f4c2004-09-13 05:12:46 +00002055bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002056 afi_t afi, safi_t safi, int type, int sub_type,
2057 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2058{
2059 int ret;
2060 int aspath_loop_count = 0;
2061 struct bgp_node *rn;
2062 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002063 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002064 struct attr *attr_new;
2065 struct bgp_info *ri;
2066 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002067 const char *reason;
paul718e3742002-12-13 20:15:29 +00002068 char buf[SU_ADDRSTRLEN];
2069
2070 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002071 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002072
paul718e3742002-12-13 20:15:29 +00002073 /* When peer's soft reconfiguration enabled. Record input packet in
2074 Adj-RIBs-In. */
2075 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2076 && peer != bgp->peer_self && ! soft_reconfig)
2077 bgp_adj_in_set (rn, peer, attr);
2078
2079 /* Check previously received route. */
2080 for (ri = rn->info; ri; ri = ri->next)
2081 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2082 break;
2083
2084 /* AS path local-as loop check. */
2085 if (peer->change_local_as)
2086 {
2087 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2088 aspath_loop_count = 1;
2089
2090 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2091 {
2092 reason = "as-path contains our own AS;";
2093 goto filtered;
2094 }
2095 }
2096
2097 /* AS path loop check. */
2098 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2099 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2100 && aspath_loop_check(attr->aspath, bgp->confed_id)
2101 > peer->allowas_in[afi][safi]))
2102 {
2103 reason = "as-path contains our own AS;";
2104 goto filtered;
2105 }
2106
2107 /* Route reflector originator ID check. */
2108 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002109 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002110 {
2111 reason = "originator is us;";
2112 goto filtered;
2113 }
2114
2115 /* Route reflector cluster ID check. */
2116 if (bgp_cluster_filter (peer, attr))
2117 {
2118 reason = "reflected from the same cluster;";
2119 goto filtered;
2120 }
2121
2122 /* Apply incoming filter. */
2123 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2124 {
2125 reason = "filter;";
2126 goto filtered;
2127 }
2128
2129 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002130 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002131
2132 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2133 {
2134 reason = "route-map;";
2135 goto filtered;
2136 }
2137
2138 /* IPv4 unicast next hop check. */
2139 if (afi == AFI_IP && safi == SAFI_UNICAST)
2140 {
2141 /* If the peer is EBGP and nexthop is not on connected route,
2142 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002143 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002144 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002145 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002146 {
2147 reason = "non-connected next-hop;";
2148 goto filtered;
2149 }
2150
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002151 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002152 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002153 if (new_attr.nexthop.s_addr == 0
2154 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2155 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002156 {
2157 reason = "martian next-hop;";
2158 goto filtered;
2159 }
2160 }
2161
2162 attr_new = bgp_attr_intern (&new_attr);
2163
2164 /* If the update is implicit withdraw. */
2165 if (ri)
2166 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002167 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002168
2169 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002170 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2171 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002172 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002173 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002174
2175 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002176 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002177 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2178 {
2179 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002180 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002181 peer->host,
2182 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2183 p->prefixlen);
2184
paul902212c2006-02-05 17:51:19 +00002185 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2186 {
2187 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2188 bgp_process (bgp, rn, afi, safi);
2189 }
paul718e3742002-12-13 20:15:29 +00002190 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002191 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002192 {
2193 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002194 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002195 "%s rcvd %s/%d...duplicate ignored",
2196 peer->host,
2197 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2198 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002199
2200 /* graceful restart STALE flag unset. */
2201 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2202 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002203 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002204 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002205 }
paul718e3742002-12-13 20:15:29 +00002206 }
2207
2208 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002209 bgp_attr_unintern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002210 bgp_attr_extra_free (&new_attr);
2211
paul718e3742002-12-13 20:15:29 +00002212 return 0;
2213 }
2214
Paul Jakma16d2e242007-04-10 19:32:10 +00002215 /* Withdraw/Announce before we fully processed the withdraw */
2216 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2217 {
2218 if (BGP_DEBUG (update, UPDATE_IN))
2219 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2220 peer->host,
2221 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2222 p->prefixlen);
2223 bgp_info_restore (rn, ri);
2224 }
2225
paul718e3742002-12-13 20:15:29 +00002226 /* Received Logging. */
2227 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002228 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002229 peer->host,
2230 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2231 p->prefixlen);
2232
hasso93406d82005-02-02 14:40:33 +00002233 /* graceful restart STALE flag unset. */
2234 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002235 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002236
paul718e3742002-12-13 20:15:29 +00002237 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002238 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002239
2240 /* implicit withdraw, decrement aggregate and pcount here.
2241 * only if update is accepted, they'll increment below.
2242 */
paul902212c2006-02-05 17:51:19 +00002243 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2244
paul718e3742002-12-13 20:15:29 +00002245 /* Update bgp route dampening information. */
2246 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002247 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002248 {
2249 /* This is implicit withdraw so we should update dampening
2250 information. */
2251 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2252 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002253 }
2254
paul718e3742002-12-13 20:15:29 +00002255 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002256 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002257 ri->attr = attr_new;
2258
2259 /* Update MPLS tag. */
2260 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002261 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002262
2263 /* Update bgp route dampening information. */
2264 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002265 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002266 {
2267 /* Now we do normal update dampening. */
2268 ret = bgp_damp_update (ri, rn, afi, safi);
2269 if (ret == BGP_DAMP_SUPPRESSED)
2270 {
2271 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002272 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002273 return 0;
2274 }
2275 }
2276
2277 /* Nexthop reachability check. */
2278 if ((afi == AFI_IP || afi == AFI_IP6)
2279 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002280 && (peer->sort == BGP_PEER_IBGP
2281 || peer->sort == BGP_PEER_CONFED
2282 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002283 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002284 {
2285 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002286 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002287 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002288 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002289 }
2290 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002291 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002292
2293 /* Process change. */
2294 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2295
2296 bgp_process (bgp, rn, afi, safi);
2297 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002298 bgp_attr_extra_free (&new_attr);
2299
paul718e3742002-12-13 20:15:29 +00002300 return 0;
2301 }
2302
2303 /* Received Logging. */
2304 if (BGP_DEBUG (update, UPDATE_IN))
2305 {
ajsd2c1f162004-12-08 21:10:20 +00002306 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002307 peer->host,
2308 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2309 p->prefixlen);
2310 }
2311
paul718e3742002-12-13 20:15:29 +00002312 /* Make new BGP info. */
2313 new = bgp_info_new ();
2314 new->type = type;
2315 new->sub_type = sub_type;
2316 new->peer = peer;
2317 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002318 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002319
2320 /* Update MPLS tag. */
2321 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002322 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002323
2324 /* Nexthop reachability check. */
2325 if ((afi == AFI_IP || afi == AFI_IP6)
2326 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002327 && (peer->sort == BGP_PEER_IBGP
2328 || peer->sort == BGP_PEER_CONFED
2329 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002330 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002331 {
2332 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002333 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002334 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002335 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002336 }
2337 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002338 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002339
paul902212c2006-02-05 17:51:19 +00002340 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002341 bgp_aggregate_increment (bgp, p, new, afi, safi);
2342
2343 /* Register new BGP information. */
2344 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002345
2346 /* route_node_get lock */
2347 bgp_unlock_node (rn);
2348
Paul Jakmafb982c22007-05-04 20:15:47 +00002349 bgp_attr_extra_free (&new_attr);
2350
paul718e3742002-12-13 20:15:29 +00002351 /* If maximum prefix count is configured and current prefix
2352 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002353 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2354 return -1;
paul718e3742002-12-13 20:15:29 +00002355
2356 /* Process change. */
2357 bgp_process (bgp, rn, afi, safi);
2358
2359 return 0;
2360
2361 /* This BGP update is filtered. Log the reason then update BGP
2362 entry. */
2363 filtered:
2364 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002365 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002366 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2367 peer->host,
2368 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2369 p->prefixlen, reason);
2370
2371 if (ri)
paulb40d9392005-08-22 22:34:41 +00002372 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002373
2374 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002375
2376 bgp_attr_extra_free (&new_attr);
2377
paul718e3742002-12-13 20:15:29 +00002378 return 0;
2379}
2380
2381int
paulfee0f4c2004-09-13 05:12:46 +00002382bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2383 afi_t afi, safi_t safi, int type, int sub_type,
2384 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2385{
2386 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002387 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002388 struct bgp *bgp;
2389 int ret;
2390
2391 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2392 soft_reconfig);
2393
2394 bgp = peer->bgp;
2395
2396 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002397 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002398 {
2399 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2400 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2401 sub_type, prd, tag);
2402 }
2403
2404 return ret;
2405}
2406
2407int
paul718e3742002-12-13 20:15:29 +00002408bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002409 afi_t afi, safi_t safi, int type, int sub_type,
2410 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002411{
2412 struct bgp *bgp;
2413 char buf[SU_ADDRSTRLEN];
2414 struct bgp_node *rn;
2415 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002416 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002417 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002418
2419 bgp = peer->bgp;
2420
paulfee0f4c2004-09-13 05:12:46 +00002421 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002422 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002423 {
2424 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2425 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2426 }
2427
paul718e3742002-12-13 20:15:29 +00002428 /* Logging. */
2429 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002430 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002431 peer->host,
2432 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2433 p->prefixlen);
2434
2435 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002436 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002437
2438 /* If peer is soft reconfiguration enabled. Record input packet for
2439 further calculation. */
2440 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2441 && peer != bgp->peer_self)
2442 bgp_adj_in_unset (rn, peer);
2443
2444 /* Lookup withdrawn route. */
2445 for (ri = rn->info; ri; ri = ri->next)
2446 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2447 break;
2448
2449 /* Withdraw specified route from routing table. */
2450 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002451 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002452 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002453 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002454 "%s Can't find the route %s/%d", peer->host,
2455 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2456 p->prefixlen);
2457
2458 /* Unlock bgp_node_get() lock. */
2459 bgp_unlock_node (rn);
2460
2461 return 0;
2462}
2463
2464void
2465bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2466{
2467 struct bgp *bgp;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00002468 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002469 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002470 struct prefix p;
2471 struct bgp_info binfo;
2472 struct peer *from;
2473 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002474
Paul Jakmab2497022007-06-14 11:17:58 +00002475 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002476 return;
2477
paul718e3742002-12-13 20:15:29 +00002478 bgp = peer->bgp;
2479 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002480
paul718e3742002-12-13 20:15:29 +00002481 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2482 aspath = attr.aspath;
2483 attr.local_pref = bgp->default_local_pref;
2484 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2485
2486 if (afi == AFI_IP)
2487 str2prefix ("0.0.0.0/0", &p);
2488#ifdef HAVE_IPV6
2489 else if (afi == AFI_IP6)
2490 {
Jorge Boncompte [DTI2]6182d652012-05-07 16:53:02 +00002491 struct attr_extra *ae = attr.extra;
2492
paul718e3742002-12-13 20:15:29 +00002493 str2prefix ("::/0", &p);
2494
2495 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002496 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002497 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002498 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002499
2500 /* If the peer is on shared nextwork and we have link-local
2501 nexthop set it. */
2502 if (peer->shared_network
2503 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2504 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002505 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002506 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002507 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002508 }
2509 }
2510#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002511
2512 if (peer->default_rmap[afi][safi].name)
2513 {
2514 binfo.peer = bgp->peer_self;
2515 binfo.attr = &attr;
2516
paulfee0f4c2004-09-13 05:12:46 +00002517 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2518
paul718e3742002-12-13 20:15:29 +00002519 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2520 RMAP_BGP, &binfo);
2521
paulfee0f4c2004-09-13 05:12:46 +00002522 bgp->peer_self->rmap_type = 0;
2523
paul718e3742002-12-13 20:15:29 +00002524 if (ret == RMAP_DENYMATCH)
2525 {
2526 bgp_attr_flush (&attr);
2527 withdraw = 1;
2528 }
2529 }
2530
2531 if (withdraw)
2532 {
2533 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2534 bgp_default_withdraw_send (peer, afi, safi);
2535 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2536 }
2537 else
2538 {
2539 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2540 bgp_default_update_send (peer, &attr, afi, safi, from);
2541 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002542
2543 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002544 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002545}
2546
2547static void
2548bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002549 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002550{
2551 struct bgp_node *rn;
2552 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002553 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002554
paul718e3742002-12-13 20:15:29 +00002555 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002556 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002557
2558 if (safi != SAFI_MPLS_VPN
2559 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2560 bgp_default_originate (peer, afi, safi, 0);
2561
2562 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2563 for (ri = rn->info; ri; ri = ri->next)
2564 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2565 {
paulfee0f4c2004-09-13 05:12:46 +00002566 if ( (rsclient) ?
2567 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2568 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002569 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2570 else
2571 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002572
2573 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002574 }
2575}
2576
2577void
2578bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2579{
2580 struct bgp_node *rn;
2581 struct bgp_table *table;
2582
2583 if (peer->status != Established)
2584 return;
2585
2586 if (! peer->afc_nego[afi][safi])
2587 return;
2588
2589 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2590 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2591 return;
2592
2593 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002594 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002595 else
2596 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2597 rn = bgp_route_next(rn))
2598 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002599 bgp_announce_table (peer, afi, safi, table, 0);
2600
2601 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2602 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002603}
2604
2605void
2606bgp_announce_route_all (struct peer *peer)
2607{
2608 afi_t afi;
2609 safi_t safi;
2610
2611 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2612 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2613 bgp_announce_route (peer, afi, safi);
2614}
2615
2616static void
paulfee0f4c2004-09-13 05:12:46 +00002617bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002618 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002619{
2620 struct bgp_node *rn;
2621 struct bgp_adj_in *ain;
2622
2623 if (! table)
2624 table = rsclient->bgp->rib[afi][safi];
2625
2626 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2627 for (ain = rn->adj_in; ain; ain = ain->next)
2628 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002629 struct bgp_info *ri = rn->info;
2630
paulfee0f4c2004-09-13 05:12:46 +00002631 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002632 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd,
2633 (bgp_info_extra_get (ri))->tag);
paulfee0f4c2004-09-13 05:12:46 +00002634 }
2635}
2636
2637void
2638bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2639{
2640 struct bgp_table *table;
2641 struct bgp_node *rn;
2642
2643 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002644 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002645
2646 else
2647 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2648 rn = bgp_route_next (rn))
2649 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002650 {
2651 struct prefix_rd prd;
2652 prd.family = AF_UNSPEC;
2653 prd.prefixlen = 64;
2654 memcpy(&prd.val, rn->p.u.val, 8);
2655
2656 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2657 }
paulfee0f4c2004-09-13 05:12:46 +00002658}
2659
2660static void
paul718e3742002-12-13 20:15:29 +00002661bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002662 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002663{
2664 int ret;
2665 struct bgp_node *rn;
2666 struct bgp_adj_in *ain;
2667
2668 if (! table)
2669 table = peer->bgp->rib[afi][safi];
2670
2671 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2672 for (ain = rn->adj_in; ain; ain = ain->next)
2673 {
2674 if (ain->peer == peer)
2675 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002676 struct bgp_info *ri = rn->info;
2677
paul718e3742002-12-13 20:15:29 +00002678 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2679 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002680 prd, (bgp_info_extra_get (ri))->tag, 1);
2681
paul718e3742002-12-13 20:15:29 +00002682 if (ret < 0)
2683 {
2684 bgp_unlock_node (rn);
2685 return;
2686 }
2687 continue;
2688 }
2689 }
2690}
2691
2692void
2693bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2694{
2695 struct bgp_node *rn;
2696 struct bgp_table *table;
2697
2698 if (peer->status != Established)
2699 return;
2700
2701 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002702 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002703 else
2704 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2705 rn = bgp_route_next (rn))
2706 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002707 {
2708 struct prefix_rd prd;
2709 prd.family = AF_UNSPEC;
2710 prd.prefixlen = 64;
2711 memcpy(&prd.val, rn->p.u.val, 8);
2712
2713 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2714 }
paul718e3742002-12-13 20:15:29 +00002715}
2716
Chris Caputo228da422009-07-18 05:44:03 +00002717
2718struct bgp_clear_node_queue
2719{
2720 struct bgp_node *rn;
2721 enum bgp_clear_route_type purpose;
2722};
2723
paul200df112005-06-01 11:17:05 +00002724static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002725bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002726{
Chris Caputo228da422009-07-18 05:44:03 +00002727 struct bgp_clear_node_queue *cnq = data;
2728 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002729 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002730 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002731 afi_t afi = rn->table->afi;
2732 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002733
Paul Jakma64e580a2006-02-21 01:09:01 +00002734 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002735
Paul Jakma64e580a2006-02-21 01:09:01 +00002736 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002737 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002738 {
2739 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002740 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2741 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002742 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002743 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2744 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002745 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002746 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002747 break;
2748 }
paul200df112005-06-01 11:17:05 +00002749 return WQ_SUCCESS;
2750}
2751
2752static void
paul0fb58d52005-11-14 14:31:49 +00002753bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002754{
Chris Caputo228da422009-07-18 05:44:03 +00002755 struct bgp_clear_node_queue *cnq = data;
2756 struct bgp_node *rn = cnq->rn;
2757 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002758
2759 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002760 bgp_table_unlock (table);
2761 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002762}
2763
2764static void
paul94f2b392005-06-28 12:44:16 +00002765bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002766{
Paul Jakma64e580a2006-02-21 01:09:01 +00002767 struct peer *peer = wq->spec.data;
2768
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002769 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002770 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002771
2772 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002773}
2774
2775static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002776bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002777{
Paul Jakmaa2943652009-07-21 14:02:04 +01002778 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002779
Paul Jakmaa2943652009-07-21 14:02:04 +01002780 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002781#undef CLEAR_QUEUE_NAME_LEN
2782
2783 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002784 {
2785 zlog_err ("%s: Failed to allocate work queue", __func__);
2786 exit (1);
2787 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002788 peer->clear_node_queue->spec.hold = 10;
2789 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2790 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2791 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2792 peer->clear_node_queue->spec.max_retries = 0;
2793
2794 /* we only 'lock' this peer reference when the queue is actually active */
2795 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002796}
2797
paul718e3742002-12-13 20:15:29 +00002798static void
2799bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002800 struct bgp_table *table, struct peer *rsclient,
2801 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002802{
2803 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002804
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002805
paul718e3742002-12-13 20:15:29 +00002806 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002807 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002808
hasso6cf159b2005-03-21 10:28:14 +00002809 /* If still no table => afi/safi isn't configured at all or smth. */
2810 if (! table)
2811 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002812
2813 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2814 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002815 struct bgp_info *ri;
2816 struct bgp_adj_in *ain;
2817 struct bgp_adj_out *aout;
2818
Paul Jakma65ca75e2006-05-04 08:08:15 +00002819 if (rn->info == NULL)
2820 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002821
2822 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2823 * queued for every clearing peer, regardless of whether it is
2824 * relevant to the peer at hand.
2825 *
2826 * Overview: There are 3 different indices which need to be
2827 * scrubbed, potentially, when a peer is removed:
2828 *
2829 * 1 peer's routes visible via the RIB (ie accepted routes)
2830 * 2 peer's routes visible by the (optional) peer's adj-in index
2831 * 3 other routes visible by the peer's adj-out index
2832 *
2833 * 3 there is no hurry in scrubbing, once the struct peer is
2834 * removed from bgp->peer, we could just GC such deleted peer's
2835 * adj-outs at our leisure.
2836 *
2837 * 1 and 2 must be 'scrubbed' in some way, at least made
2838 * invisible via RIB index before peer session is allowed to be
2839 * brought back up. So one needs to know when such a 'search' is
2840 * complete.
2841 *
2842 * Ideally:
2843 *
2844 * - there'd be a single global queue or a single RIB walker
2845 * - rather than tracking which route_nodes still need to be
2846 * examined on a peer basis, we'd track which peers still
2847 * aren't cleared
2848 *
2849 * Given that our per-peer prefix-counts now should be reliable,
2850 * this may actually be achievable. It doesn't seem to be a huge
2851 * problem at this time,
2852 */
2853 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002854 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002855 {
Chris Caputo228da422009-07-18 05:44:03 +00002856 struct bgp_clear_node_queue *cnq;
2857
2858 /* both unlocked in bgp_clear_node_queue_del */
2859 bgp_table_lock (rn->table);
2860 bgp_lock_node (rn);
2861 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2862 sizeof (struct bgp_clear_node_queue));
2863 cnq->rn = rn;
2864 cnq->purpose = purpose;
2865 work_queue_add (peer->clear_node_queue, cnq);
2866 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002867 }
2868
2869 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002870 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002871 {
2872 bgp_adj_in_remove (rn, ain);
2873 bgp_unlock_node (rn);
2874 break;
2875 }
2876 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002877 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002878 {
2879 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2880 bgp_unlock_node (rn);
2881 break;
2882 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002883 }
2884 return;
2885}
2886
2887void
Chris Caputo228da422009-07-18 05:44:03 +00002888bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2889 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002890{
2891 struct bgp_node *rn;
2892 struct bgp_table *table;
2893 struct peer *rsclient;
2894 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002895
Paul Jakma64e580a2006-02-21 01:09:01 +00002896 if (peer->clear_node_queue == NULL)
2897 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002898
Paul Jakmaca058a32006-09-14 02:58:49 +00002899 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2900 * Idle until it receives a Clearing_Completed event. This protects
2901 * against peers which flap faster than we can we clear, which could
2902 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002903 *
2904 * a) race with routes from the new session being installed before
2905 * clear_route_node visits the node (to delete the route of that
2906 * peer)
2907 * b) resource exhaustion, clear_route_node likely leads to an entry
2908 * on the process_main queue. Fast-flapping could cause that queue
2909 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002910 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002911 if (!peer->clear_node_queue->thread)
2912 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002913
Chris Caputo228da422009-07-18 05:44:03 +00002914 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002915 {
Chris Caputo228da422009-07-18 05:44:03 +00002916 case BGP_CLEAR_ROUTE_NORMAL:
2917 if (safi != SAFI_MPLS_VPN)
2918 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2919 else
2920 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2921 rn = bgp_route_next (rn))
2922 if ((table = rn->info) != NULL)
2923 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2924
2925 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2926 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2927 PEER_FLAG_RSERVER_CLIENT))
2928 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2929 break;
2930
2931 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2932 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2933 break;
2934
2935 default:
2936 assert (0);
2937 break;
paulfee0f4c2004-09-13 05:12:46 +00002938 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002939
Paul Jakmaca058a32006-09-14 02:58:49 +00002940 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002941 * completion function won't be run by workqueue code - call it here.
2942 * XXX: Actually, this assumption doesn't hold, see
2943 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002944 *
2945 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002946 * really needed if peer state is Established - peers in
2947 * pre-Established states shouldn't have any route-update state
2948 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002949 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002950 * We still can get here in pre-Established though, through
2951 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2952 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002953 *
2954 * At some future point, this check could be move to the top of the
2955 * function, and do a quick early-return when state is
2956 * pre-Established, avoiding above list and table scans. Once we're
2957 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002958 */
2959 if (!peer->clear_node_queue->thread)
2960 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002961}
2962
2963void
2964bgp_clear_route_all (struct peer *peer)
2965{
2966 afi_t afi;
2967 safi_t safi;
2968
2969 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2970 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002971 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002972}
2973
2974void
2975bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2976{
2977 struct bgp_table *table;
2978 struct bgp_node *rn;
2979 struct bgp_adj_in *ain;
2980
2981 table = peer->bgp->rib[afi][safi];
2982
2983 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2984 for (ain = rn->adj_in; ain ; ain = ain->next)
2985 if (ain->peer == peer)
2986 {
2987 bgp_adj_in_remove (rn, ain);
2988 bgp_unlock_node (rn);
2989 break;
2990 }
2991}
hasso93406d82005-02-02 14:40:33 +00002992
2993void
2994bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2995{
2996 struct bgp_node *rn;
2997 struct bgp_info *ri;
2998 struct bgp_table *table;
2999
3000 table = peer->bgp->rib[afi][safi];
3001
3002 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3003 {
3004 for (ri = rn->info; ri; ri = ri->next)
3005 if (ri->peer == peer)
3006 {
3007 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3008 bgp_rib_remove (rn, ri, peer, afi, safi);
3009 break;
3010 }
3011 }
3012}
paul718e3742002-12-13 20:15:29 +00003013
3014/* Delete all kernel routes. */
3015void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003016bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003017{
3018 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003019 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003020 struct bgp_node *rn;
3021 struct bgp_table *table;
3022 struct bgp_info *ri;
3023
paul1eb8ef22005-04-07 07:30:20 +00003024 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003025 {
3026 table = bgp->rib[AFI_IP][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 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3036
3037 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3038 for (ri = rn->info; ri; ri = ri->next)
3039 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3040 && ri->type == ZEBRA_ROUTE_BGP
3041 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003042 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003043 }
3044}
3045
3046void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003047bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003048{
3049 vty_reset ();
3050 bgp_zclient_reset ();
3051 access_list_reset ();
3052 prefix_list_reset ();
3053}
3054
3055/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3056 value. */
3057int
3058bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3059{
3060 u_char *pnt;
3061 u_char *lim;
3062 struct prefix p;
3063 int psize;
3064 int ret;
3065
3066 /* Check peer status. */
3067 if (peer->status != Established)
3068 return 0;
3069
3070 pnt = packet->nlri;
3071 lim = pnt + packet->length;
3072
3073 for (; pnt < lim; pnt += psize)
3074 {
3075 /* Clear prefix structure. */
3076 memset (&p, 0, sizeof (struct prefix));
3077
3078 /* Fetch prefix length. */
3079 p.prefixlen = *pnt++;
3080 p.family = afi2family (packet->afi);
3081
3082 /* Already checked in nlri_sanity_check(). We do double check
3083 here. */
3084 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3085 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3086 return -1;
3087
3088 /* Packet size overflow check. */
3089 psize = PSIZE (p.prefixlen);
3090
3091 /* When packet overflow occur return immediately. */
3092 if (pnt + psize > lim)
3093 return -1;
3094
3095 /* Fetch prefix from NLRI packet. */
3096 memcpy (&p.u.prefix, pnt, psize);
3097
3098 /* Check address. */
3099 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3100 {
3101 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3102 {
paulf5ba3872004-07-09 12:11:31 +00003103 /*
3104 * From draft-ietf-idr-bgp4-22, Section 6.3:
3105 * If a BGP router receives an UPDATE message with a
3106 * semantically incorrect NLRI field, in which a prefix is
3107 * semantically incorrect (eg. an unexpected multicast IP
3108 * address), it should ignore the prefix.
3109 */
paul718e3742002-12-13 20:15:29 +00003110 zlog (peer->log, LOG_ERR,
3111 "IPv4 unicast NLRI is multicast address %s",
3112 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003113
paul718e3742002-12-13 20:15:29 +00003114 return -1;
3115 }
3116 }
3117
3118#ifdef HAVE_IPV6
3119 /* Check address. */
3120 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3121 {
3122 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3123 {
3124 char buf[BUFSIZ];
3125
3126 zlog (peer->log, LOG_WARNING,
3127 "IPv6 link-local NLRI received %s ignore this NLRI",
3128 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3129
3130 continue;
3131 }
3132 }
3133#endif /* HAVE_IPV6 */
3134
3135 /* Normal process. */
3136 if (attr)
3137 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3138 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3139 else
3140 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3141 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3142
3143 /* Address family configuration mismatch or maximum-prefix count
3144 overflow. */
3145 if (ret < 0)
3146 return -1;
3147 }
3148
3149 /* Packet length consistency check. */
3150 if (pnt != lim)
3151 return -1;
3152
3153 return 0;
3154}
3155
3156/* NLRI encode syntax check routine. */
3157int
3158bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3159 bgp_size_t length)
3160{
3161 u_char *end;
3162 u_char prefixlen;
3163 int psize;
3164
3165 end = pnt + length;
3166
3167 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3168 syntactic validity. If the field is syntactically incorrect,
3169 then the Error Subcode is set to Invalid Network Field. */
3170
3171 while (pnt < end)
3172 {
3173 prefixlen = *pnt++;
3174
3175 /* Prefix length check. */
3176 if ((afi == AFI_IP && prefixlen > 32)
3177 || (afi == AFI_IP6 && prefixlen > 128))
3178 {
3179 plog_err (peer->log,
3180 "%s [Error] Update packet error (wrong prefix length %d)",
3181 peer->host, prefixlen);
3182 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3183 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3184 return -1;
3185 }
3186
3187 /* Packet size overflow check. */
3188 psize = PSIZE (prefixlen);
3189
3190 if (pnt + psize > end)
3191 {
3192 plog_err (peer->log,
3193 "%s [Error] Update packet error"
3194 " (prefix data overflow prefix size is %d)",
3195 peer->host, psize);
3196 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3197 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3198 return -1;
3199 }
3200
3201 pnt += psize;
3202 }
3203
3204 /* Packet length consistency check. */
3205 if (pnt != end)
3206 {
3207 plog_err (peer->log,
3208 "%s [Error] Update packet error"
3209 " (prefix length mismatch with total length)",
3210 peer->host);
3211 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3212 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3213 return -1;
3214 }
3215 return 0;
3216}
3217
paul94f2b392005-06-28 12:44:16 +00003218static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003219bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003220{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003221 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003222}
3223
paul94f2b392005-06-28 12:44:16 +00003224static void
paul718e3742002-12-13 20:15:29 +00003225bgp_static_free (struct bgp_static *bgp_static)
3226{
3227 if (bgp_static->rmap.name)
3228 free (bgp_static->rmap.name);
3229 XFREE (MTYPE_BGP_STATIC, bgp_static);
3230}
3231
paul94f2b392005-06-28 12:44:16 +00003232static void
paulfee0f4c2004-09-13 05:12:46 +00003233bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3234 struct prefix *p, afi_t afi, safi_t safi)
3235{
3236 struct bgp_node *rn;
3237 struct bgp_info *ri;
3238
3239 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3240
3241 /* Check selected route and self inserted route. */
3242 for (ri = rn->info; ri; ri = ri->next)
3243 if (ri->peer == bgp->peer_self
3244 && ri->type == ZEBRA_ROUTE_BGP
3245 && ri->sub_type == BGP_ROUTE_STATIC)
3246 break;
3247
3248 /* Withdraw static BGP route from routing table. */
3249 if (ri)
3250 {
paulfee0f4c2004-09-13 05:12:46 +00003251 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003252 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003253 }
3254
3255 /* Unlock bgp_node_lookup. */
3256 bgp_unlock_node (rn);
3257}
3258
paul94f2b392005-06-28 12:44:16 +00003259static void
paulfee0f4c2004-09-13 05:12:46 +00003260bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003261 struct bgp_static *bgp_static,
3262 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003263{
3264 struct bgp_node *rn;
3265 struct bgp_info *ri;
3266 struct bgp_info *new;
3267 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003268 struct attr *attr_new;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003269 struct attr attr;
3270 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00003271 struct bgp *bgp;
3272 int ret;
3273 char buf[SU_ADDRSTRLEN];
3274
3275 bgp = rsclient->bgp;
3276
Paul Jakma06e110f2006-05-12 23:29:22 +00003277 assert (bgp_static);
3278 if (!bgp_static)
3279 return;
3280
paulfee0f4c2004-09-13 05:12:46 +00003281 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3282
3283 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003284
3285 attr.nexthop = bgp_static->igpnexthop;
3286 attr.med = bgp_static->igpmetric;
3287 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003288
Paul Jakma41367172007-08-06 15:24:51 +00003289 if (bgp_static->atomic)
3290 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3291
paulfee0f4c2004-09-13 05:12:46 +00003292 /* Apply network route-map for export to this rsclient. */
3293 if (bgp_static->rmap.name)
3294 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003295 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003296 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003297 info.attr = &attr_tmp;
3298
paulfee0f4c2004-09-13 05:12:46 +00003299 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3300 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3301
3302 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3303
3304 rsclient->rmap_type = 0;
3305
3306 if (ret == RMAP_DENYMATCH)
3307 {
3308 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003309 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003310
3311 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003312 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003313 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003314 bgp_attr_extra_free (&attr);
3315
paulfee0f4c2004-09-13 05:12:46 +00003316 return;
3317 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003318 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003319 }
3320 else
3321 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003322
Stephen Hemminger7badc262010-08-05 10:26:31 -07003323 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003324
paulfee0f4c2004-09-13 05:12:46 +00003325 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3326
Paul Jakmafb982c22007-05-04 20:15:47 +00003327 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3328 == RMAP_DENY)
3329 {
paulfee0f4c2004-09-13 05:12:46 +00003330 /* This BGP update is filtered. Log the reason then update BGP entry. */
3331 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003332 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003333 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3334 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3335 p->prefixlen, rsclient->host);
3336
3337 bgp->peer_self->rmap_type = 0;
3338
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003339 bgp_attr_unintern (&attr_new);
3340 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003341 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003342
3343 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3344
3345 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003346 }
paulfee0f4c2004-09-13 05:12:46 +00003347
3348 bgp->peer_self->rmap_type = 0;
3349
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003350 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003351 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003352 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003353
3354 for (ri = rn->info; ri; ri = ri->next)
3355 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3356 && ri->sub_type == BGP_ROUTE_STATIC)
3357 break;
3358
3359 if (ri)
3360 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003361 if (attrhash_cmp (ri->attr, attr_new) &&
3362 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003363 {
3364 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003365 bgp_attr_unintern (&attr_new);
3366 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003367 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003368 return;
3369 }
3370 else
3371 {
3372 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003373 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003374
3375 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003376 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3377 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003378 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003379 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003380 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003381
3382 /* Process change. */
3383 bgp_process (bgp, rn, afi, safi);
3384 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003385 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003386 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003387 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003388 }
paulfee0f4c2004-09-13 05:12:46 +00003389 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003390
paulfee0f4c2004-09-13 05:12:46 +00003391 /* Make new BGP info. */
3392 new = bgp_info_new ();
3393 new->type = ZEBRA_ROUTE_BGP;
3394 new->sub_type = BGP_ROUTE_STATIC;
3395 new->peer = bgp->peer_self;
3396 SET_FLAG (new->flags, BGP_INFO_VALID);
3397 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003398 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003399
3400 /* Register new BGP information. */
3401 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003402
3403 /* route_node_get lock */
3404 bgp_unlock_node (rn);
3405
paulfee0f4c2004-09-13 05:12:46 +00003406 /* Process change. */
3407 bgp_process (bgp, rn, afi, safi);
3408
3409 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003410 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003411 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003412}
3413
paul94f2b392005-06-28 12:44:16 +00003414static void
paulfee0f4c2004-09-13 05:12:46 +00003415bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003416 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3417{
3418 struct bgp_node *rn;
3419 struct bgp_info *ri;
3420 struct bgp_info *new;
3421 struct bgp_info info;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00003422 struct attr attr;
paul718e3742002-12-13 20:15:29 +00003423 struct attr *attr_new;
3424 int ret;
3425
Paul Jakmadd8103a2006-05-12 23:27:30 +00003426 assert (bgp_static);
3427 if (!bgp_static)
3428 return;
3429
paulfee0f4c2004-09-13 05:12:46 +00003430 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003431
3432 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003433
3434 attr.nexthop = bgp_static->igpnexthop;
3435 attr.med = bgp_static->igpmetric;
3436 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003437
Paul Jakma41367172007-08-06 15:24:51 +00003438 if (bgp_static->atomic)
3439 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3440
paul718e3742002-12-13 20:15:29 +00003441 /* Apply route-map. */
3442 if (bgp_static->rmap.name)
3443 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003444 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003445 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003446 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003447
paulfee0f4c2004-09-13 05:12:46 +00003448 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3449
paul718e3742002-12-13 20:15:29 +00003450 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003451
paulfee0f4c2004-09-13 05:12:46 +00003452 bgp->peer_self->rmap_type = 0;
3453
paul718e3742002-12-13 20:15:29 +00003454 if (ret == RMAP_DENYMATCH)
3455 {
3456 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003457 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003458
3459 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003460 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003461 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003462 bgp_static_withdraw (bgp, p, afi, safi);
3463 return;
3464 }
paul286e1e72003-08-08 00:24:31 +00003465 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003466 }
paul286e1e72003-08-08 00:24:31 +00003467 else
3468 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003469
3470 for (ri = rn->info; ri; ri = ri->next)
3471 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3472 && ri->sub_type == BGP_ROUTE_STATIC)
3473 break;
3474
3475 if (ri)
3476 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003477 if (attrhash_cmp (ri->attr, attr_new) &&
3478 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003479 {
3480 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003481 bgp_attr_unintern (&attr_new);
3482 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003483 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003484 return;
3485 }
3486 else
3487 {
3488 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003489 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003490
3491 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003492 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3493 bgp_info_restore(rn, ri);
3494 else
3495 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003496 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003497 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003498 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003499
3500 /* Process change. */
3501 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3502 bgp_process (bgp, rn, afi, safi);
3503 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003504 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003505 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003506 return;
3507 }
3508 }
3509
3510 /* Make new BGP info. */
3511 new = bgp_info_new ();
3512 new->type = ZEBRA_ROUTE_BGP;
3513 new->sub_type = BGP_ROUTE_STATIC;
3514 new->peer = bgp->peer_self;
3515 SET_FLAG (new->flags, BGP_INFO_VALID);
3516 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003517 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003518
3519 /* Aggregate address increment. */
3520 bgp_aggregate_increment (bgp, p, new, afi, safi);
3521
3522 /* Register new BGP information. */
3523 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003524
3525 /* route_node_get lock */
3526 bgp_unlock_node (rn);
3527
paul718e3742002-12-13 20:15:29 +00003528 /* Process change. */
3529 bgp_process (bgp, rn, afi, safi);
3530
3531 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003532 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003533 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003534}
3535
3536void
paulfee0f4c2004-09-13 05:12:46 +00003537bgp_static_update (struct bgp *bgp, struct prefix *p,
3538 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3539{
3540 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003541 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003542
3543 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3544
paul1eb8ef22005-04-07 07:30:20 +00003545 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003546 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003547 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3548 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003549 }
3550}
3551
paul94f2b392005-06-28 12:44:16 +00003552static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003553bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3554 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003555{
3556 struct bgp_node *rn;
3557 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003558
paulfee0f4c2004-09-13 05:12:46 +00003559 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003560
3561 /* Make new BGP info. */
3562 new = bgp_info_new ();
3563 new->type = ZEBRA_ROUTE_BGP;
3564 new->sub_type = BGP_ROUTE_STATIC;
3565 new->peer = bgp->peer_self;
3566 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3567 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003568 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003569 new->extra = bgp_info_extra_new();
3570 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003571
3572 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003573 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003574
3575 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003576 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003577
paul200df112005-06-01 11:17:05 +00003578 /* route_node_get lock */
3579 bgp_unlock_node (rn);
3580
paul718e3742002-12-13 20:15:29 +00003581 /* Process change. */
3582 bgp_process (bgp, rn, afi, safi);
3583}
3584
3585void
3586bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3587 safi_t safi)
3588{
3589 struct bgp_node *rn;
3590 struct bgp_info *ri;
3591
paulfee0f4c2004-09-13 05:12:46 +00003592 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003593
3594 /* Check selected route and self inserted route. */
3595 for (ri = rn->info; ri; ri = ri->next)
3596 if (ri->peer == bgp->peer_self
3597 && ri->type == ZEBRA_ROUTE_BGP
3598 && ri->sub_type == BGP_ROUTE_STATIC)
3599 break;
3600
3601 /* Withdraw static BGP route from routing table. */
3602 if (ri)
3603 {
3604 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003605 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003606 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003607 }
3608
3609 /* Unlock bgp_node_lookup. */
3610 bgp_unlock_node (rn);
3611}
3612
3613void
paulfee0f4c2004-09-13 05:12:46 +00003614bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3615{
3616 struct bgp_static *bgp_static;
3617 struct bgp *bgp;
3618 struct bgp_node *rn;
3619 struct prefix *p;
3620
3621 bgp = rsclient->bgp;
3622
3623 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3624 if ((bgp_static = rn->info) != NULL)
3625 {
3626 p = &rn->p;
3627
3628 bgp_static_update_rsclient (rsclient, p, bgp_static,
3629 afi, safi);
3630 }
3631}
3632
paul94f2b392005-06-28 12:44:16 +00003633static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003634bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3635 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003636{
3637 struct bgp_node *rn;
3638 struct bgp_info *ri;
3639
paulfee0f4c2004-09-13 05:12:46 +00003640 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003641
3642 /* Check selected route and self inserted route. */
3643 for (ri = rn->info; ri; ri = ri->next)
3644 if (ri->peer == bgp->peer_self
3645 && ri->type == ZEBRA_ROUTE_BGP
3646 && ri->sub_type == BGP_ROUTE_STATIC)
3647 break;
3648
3649 /* Withdraw static BGP route from routing table. */
3650 if (ri)
3651 {
3652 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003653 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003654 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003655 }
3656
3657 /* Unlock bgp_node_lookup. */
3658 bgp_unlock_node (rn);
3659}
3660
3661/* Configure static BGP network. When user don't run zebra, static
3662 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003663static int
paulfd79ac92004-10-13 05:06:08 +00003664bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003665 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003666{
3667 int ret;
3668 struct prefix p;
3669 struct bgp_static *bgp_static;
3670 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003671 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003672
3673 /* Convert IP prefix string to struct prefix. */
3674 ret = str2prefix (ip_str, &p);
3675 if (! ret)
3676 {
3677 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3678 return CMD_WARNING;
3679 }
3680#ifdef HAVE_IPV6
3681 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3682 {
3683 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3684 VTY_NEWLINE);
3685 return CMD_WARNING;
3686 }
3687#endif /* HAVE_IPV6 */
3688
3689 apply_mask (&p);
3690
3691 /* Set BGP static route configuration. */
3692 rn = bgp_node_get (bgp->route[afi][safi], &p);
3693
3694 if (rn->info)
3695 {
3696 /* Configuration change. */
3697 bgp_static = rn->info;
3698
3699 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003700 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3701 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003702
paul718e3742002-12-13 20:15:29 +00003703 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003704
paul718e3742002-12-13 20:15:29 +00003705 if (rmap)
3706 {
3707 if (bgp_static->rmap.name)
3708 free (bgp_static->rmap.name);
3709 bgp_static->rmap.name = strdup (rmap);
3710 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3711 }
3712 else
3713 {
3714 if (bgp_static->rmap.name)
3715 free (bgp_static->rmap.name);
3716 bgp_static->rmap.name = NULL;
3717 bgp_static->rmap.map = NULL;
3718 bgp_static->valid = 0;
3719 }
3720 bgp_unlock_node (rn);
3721 }
3722 else
3723 {
3724 /* New configuration. */
3725 bgp_static = bgp_static_new ();
3726 bgp_static->backdoor = backdoor;
3727 bgp_static->valid = 0;
3728 bgp_static->igpmetric = 0;
3729 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003730
paul718e3742002-12-13 20:15:29 +00003731 if (rmap)
3732 {
3733 if (bgp_static->rmap.name)
3734 free (bgp_static->rmap.name);
3735 bgp_static->rmap.name = strdup (rmap);
3736 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3737 }
3738 rn->info = bgp_static;
3739 }
3740
3741 /* If BGP scan is not enabled, we should install this route here. */
3742 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3743 {
3744 bgp_static->valid = 1;
3745
3746 if (need_update)
3747 bgp_static_withdraw (bgp, &p, afi, safi);
3748
3749 if (! bgp_static->backdoor)
3750 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3751 }
3752
3753 return CMD_SUCCESS;
3754}
3755
3756/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003757static int
paulfd79ac92004-10-13 05:06:08 +00003758bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003759 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003760{
3761 int ret;
3762 struct prefix p;
3763 struct bgp_static *bgp_static;
3764 struct bgp_node *rn;
3765
3766 /* Convert IP prefix string to struct prefix. */
3767 ret = str2prefix (ip_str, &p);
3768 if (! ret)
3769 {
3770 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3771 return CMD_WARNING;
3772 }
3773#ifdef HAVE_IPV6
3774 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3775 {
3776 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3777 VTY_NEWLINE);
3778 return CMD_WARNING;
3779 }
3780#endif /* HAVE_IPV6 */
3781
3782 apply_mask (&p);
3783
3784 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3785 if (! rn)
3786 {
3787 vty_out (vty, "%% Can't find specified static route configuration.%s",
3788 VTY_NEWLINE);
3789 return CMD_WARNING;
3790 }
3791
3792 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003793
paul718e3742002-12-13 20:15:29 +00003794 /* Update BGP RIB. */
3795 if (! bgp_static->backdoor)
3796 bgp_static_withdraw (bgp, &p, afi, safi);
3797
3798 /* Clear configuration. */
3799 bgp_static_free (bgp_static);
3800 rn->info = NULL;
3801 bgp_unlock_node (rn);
3802 bgp_unlock_node (rn);
3803
3804 return CMD_SUCCESS;
3805}
3806
3807/* Called from bgp_delete(). Delete all static routes from the BGP
3808 instance. */
3809void
3810bgp_static_delete (struct bgp *bgp)
3811{
3812 afi_t afi;
3813 safi_t safi;
3814 struct bgp_node *rn;
3815 struct bgp_node *rm;
3816 struct bgp_table *table;
3817 struct bgp_static *bgp_static;
3818
3819 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3820 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3821 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3822 if (rn->info != NULL)
3823 {
3824 if (safi == SAFI_MPLS_VPN)
3825 {
3826 table = rn->info;
3827
3828 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3829 {
3830 bgp_static = rn->info;
3831 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3832 AFI_IP, SAFI_MPLS_VPN,
3833 (struct prefix_rd *)&rn->p,
3834 bgp_static->tag);
3835 bgp_static_free (bgp_static);
3836 rn->info = NULL;
3837 bgp_unlock_node (rn);
3838 }
3839 }
3840 else
3841 {
3842 bgp_static = rn->info;
3843 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3844 bgp_static_free (bgp_static);
3845 rn->info = NULL;
3846 bgp_unlock_node (rn);
3847 }
3848 }
3849}
3850
3851int
paulfd79ac92004-10-13 05:06:08 +00003852bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3853 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003854{
3855 int ret;
3856 struct prefix p;
3857 struct prefix_rd prd;
3858 struct bgp *bgp;
3859 struct bgp_node *prn;
3860 struct bgp_node *rn;
3861 struct bgp_table *table;
3862 struct bgp_static *bgp_static;
3863 u_char tag[3];
3864
3865 bgp = vty->index;
3866
3867 ret = str2prefix (ip_str, &p);
3868 if (! ret)
3869 {
3870 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3871 return CMD_WARNING;
3872 }
3873 apply_mask (&p);
3874
3875 ret = str2prefix_rd (rd_str, &prd);
3876 if (! ret)
3877 {
3878 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3879 return CMD_WARNING;
3880 }
3881
3882 ret = str2tag (tag_str, tag);
3883 if (! ret)
3884 {
3885 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3886 return CMD_WARNING;
3887 }
3888
3889 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3890 (struct prefix *)&prd);
3891 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003892 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003893 else
3894 bgp_unlock_node (prn);
3895 table = prn->info;
3896
3897 rn = bgp_node_get (table, &p);
3898
3899 if (rn->info)
3900 {
3901 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3902 bgp_unlock_node (rn);
3903 }
3904 else
3905 {
3906 /* New configuration. */
3907 bgp_static = bgp_static_new ();
3908 bgp_static->valid = 1;
3909 memcpy (bgp_static->tag, tag, 3);
3910 rn->info = bgp_static;
3911
3912 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3913 }
3914
3915 return CMD_SUCCESS;
3916}
3917
3918/* Configure static BGP network. */
3919int
paulfd79ac92004-10-13 05:06:08 +00003920bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3921 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003922{
3923 int ret;
3924 struct bgp *bgp;
3925 struct prefix p;
3926 struct prefix_rd prd;
3927 struct bgp_node *prn;
3928 struct bgp_node *rn;
3929 struct bgp_table *table;
3930 struct bgp_static *bgp_static;
3931 u_char tag[3];
3932
3933 bgp = vty->index;
3934
3935 /* Convert IP prefix string to struct prefix. */
3936 ret = str2prefix (ip_str, &p);
3937 if (! ret)
3938 {
3939 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3940 return CMD_WARNING;
3941 }
3942 apply_mask (&p);
3943
3944 ret = str2prefix_rd (rd_str, &prd);
3945 if (! ret)
3946 {
3947 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3948 return CMD_WARNING;
3949 }
3950
3951 ret = str2tag (tag_str, tag);
3952 if (! ret)
3953 {
3954 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3955 return CMD_WARNING;
3956 }
3957
3958 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3959 (struct prefix *)&prd);
3960 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003961 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003962 else
3963 bgp_unlock_node (prn);
3964 table = prn->info;
3965
3966 rn = bgp_node_lookup (table, &p);
3967
3968 if (rn)
3969 {
3970 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3971
3972 bgp_static = rn->info;
3973 bgp_static_free (bgp_static);
3974 rn->info = NULL;
3975 bgp_unlock_node (rn);
3976 bgp_unlock_node (rn);
3977 }
3978 else
3979 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3980
3981 return CMD_SUCCESS;
3982}
3983
3984DEFUN (bgp_network,
3985 bgp_network_cmd,
3986 "network A.B.C.D/M",
3987 "Specify a network to announce via BGP\n"
3988 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3989{
3990 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003991 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003992}
3993
3994DEFUN (bgp_network_route_map,
3995 bgp_network_route_map_cmd,
3996 "network A.B.C.D/M route-map WORD",
3997 "Specify a network to announce via BGP\n"
3998 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3999 "Route-map to modify the attributes\n"
4000 "Name of the route map\n")
4001{
4002 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004003 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004004}
4005
4006DEFUN (bgp_network_backdoor,
4007 bgp_network_backdoor_cmd,
4008 "network A.B.C.D/M backdoor",
4009 "Specify a network to announce via BGP\n"
4010 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4011 "Specify a BGP backdoor route\n")
4012{
Paul Jakma41367172007-08-06 15:24:51 +00004013 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004014 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004015}
4016
4017DEFUN (bgp_network_mask,
4018 bgp_network_mask_cmd,
4019 "network A.B.C.D mask A.B.C.D",
4020 "Specify a network to announce via BGP\n"
4021 "Network number\n"
4022 "Network mask\n"
4023 "Network mask\n")
4024{
4025 int ret;
4026 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004027
paul718e3742002-12-13 20:15:29 +00004028 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4029 if (! ret)
4030 {
4031 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4032 return CMD_WARNING;
4033 }
4034
4035 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004036 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004037}
4038
4039DEFUN (bgp_network_mask_route_map,
4040 bgp_network_mask_route_map_cmd,
4041 "network A.B.C.D mask A.B.C.D route-map WORD",
4042 "Specify a network to announce via BGP\n"
4043 "Network number\n"
4044 "Network mask\n"
4045 "Network mask\n"
4046 "Route-map to modify the attributes\n"
4047 "Name of the route map\n")
4048{
4049 int ret;
4050 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004051
paul718e3742002-12-13 20:15:29 +00004052 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4053 if (! ret)
4054 {
4055 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4056 return CMD_WARNING;
4057 }
4058
4059 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004060 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004061}
4062
4063DEFUN (bgp_network_mask_backdoor,
4064 bgp_network_mask_backdoor_cmd,
4065 "network A.B.C.D mask A.B.C.D backdoor",
4066 "Specify a network to announce via BGP\n"
4067 "Network number\n"
4068 "Network mask\n"
4069 "Network mask\n"
4070 "Specify a BGP backdoor route\n")
4071{
4072 int ret;
4073 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004074
paul718e3742002-12-13 20:15:29 +00004075 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4076 if (! ret)
4077 {
4078 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4079 return CMD_WARNING;
4080 }
4081
Paul Jakma41367172007-08-06 15:24:51 +00004082 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004083 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004084}
4085
4086DEFUN (bgp_network_mask_natural,
4087 bgp_network_mask_natural_cmd,
4088 "network A.B.C.D",
4089 "Specify a network to announce via BGP\n"
4090 "Network number\n")
4091{
4092 int ret;
4093 char prefix_str[BUFSIZ];
4094
4095 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4096 if (! ret)
4097 {
4098 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4099 return CMD_WARNING;
4100 }
4101
4102 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004103 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004104}
4105
4106DEFUN (bgp_network_mask_natural_route_map,
4107 bgp_network_mask_natural_route_map_cmd,
4108 "network A.B.C.D route-map WORD",
4109 "Specify a network to announce via BGP\n"
4110 "Network number\n"
4111 "Route-map to modify the attributes\n"
4112 "Name of the route map\n")
4113{
4114 int ret;
4115 char prefix_str[BUFSIZ];
4116
4117 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4118 if (! ret)
4119 {
4120 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4121 return CMD_WARNING;
4122 }
4123
4124 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004125 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004126}
4127
4128DEFUN (bgp_network_mask_natural_backdoor,
4129 bgp_network_mask_natural_backdoor_cmd,
4130 "network A.B.C.D backdoor",
4131 "Specify a network to announce via BGP\n"
4132 "Network number\n"
4133 "Specify a BGP backdoor route\n")
4134{
4135 int ret;
4136 char prefix_str[BUFSIZ];
4137
4138 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4139 if (! ret)
4140 {
4141 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4142 return CMD_WARNING;
4143 }
4144
Paul Jakma41367172007-08-06 15:24:51 +00004145 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004146 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004147}
4148
4149DEFUN (no_bgp_network,
4150 no_bgp_network_cmd,
4151 "no network A.B.C.D/M",
4152 NO_STR
4153 "Specify a network to announce via BGP\n"
4154 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4155{
4156 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4157 bgp_node_safi (vty));
4158}
4159
4160ALIAS (no_bgp_network,
4161 no_bgp_network_route_map_cmd,
4162 "no network A.B.C.D/M route-map WORD",
4163 NO_STR
4164 "Specify a network to announce via BGP\n"
4165 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4166 "Route-map to modify the attributes\n"
4167 "Name of the route map\n")
4168
4169ALIAS (no_bgp_network,
4170 no_bgp_network_backdoor_cmd,
4171 "no network A.B.C.D/M backdoor",
4172 NO_STR
4173 "Specify a network to announce via BGP\n"
4174 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4175 "Specify a BGP backdoor route\n")
4176
4177DEFUN (no_bgp_network_mask,
4178 no_bgp_network_mask_cmd,
4179 "no network A.B.C.D mask A.B.C.D",
4180 NO_STR
4181 "Specify a network to announce via BGP\n"
4182 "Network number\n"
4183 "Network mask\n"
4184 "Network mask\n")
4185{
4186 int ret;
4187 char prefix_str[BUFSIZ];
4188
4189 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4190 if (! ret)
4191 {
4192 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4193 return CMD_WARNING;
4194 }
4195
4196 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4197 bgp_node_safi (vty));
4198}
4199
4200ALIAS (no_bgp_network_mask,
4201 no_bgp_network_mask_route_map_cmd,
4202 "no network A.B.C.D mask A.B.C.D route-map WORD",
4203 NO_STR
4204 "Specify a network to announce via BGP\n"
4205 "Network number\n"
4206 "Network mask\n"
4207 "Network mask\n"
4208 "Route-map to modify the attributes\n"
4209 "Name of the route map\n")
4210
4211ALIAS (no_bgp_network_mask,
4212 no_bgp_network_mask_backdoor_cmd,
4213 "no network A.B.C.D mask A.B.C.D backdoor",
4214 NO_STR
4215 "Specify a network to announce via BGP\n"
4216 "Network number\n"
4217 "Network mask\n"
4218 "Network mask\n"
4219 "Specify a BGP backdoor route\n")
4220
4221DEFUN (no_bgp_network_mask_natural,
4222 no_bgp_network_mask_natural_cmd,
4223 "no network A.B.C.D",
4224 NO_STR
4225 "Specify a network to announce via BGP\n"
4226 "Network number\n")
4227{
4228 int ret;
4229 char prefix_str[BUFSIZ];
4230
4231 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4232 if (! ret)
4233 {
4234 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4235 return CMD_WARNING;
4236 }
4237
4238 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4239 bgp_node_safi (vty));
4240}
4241
4242ALIAS (no_bgp_network_mask_natural,
4243 no_bgp_network_mask_natural_route_map_cmd,
4244 "no network A.B.C.D route-map WORD",
4245 NO_STR
4246 "Specify a network to announce via BGP\n"
4247 "Network number\n"
4248 "Route-map to modify the attributes\n"
4249 "Name of the route map\n")
4250
4251ALIAS (no_bgp_network_mask_natural,
4252 no_bgp_network_mask_natural_backdoor_cmd,
4253 "no network A.B.C.D backdoor",
4254 NO_STR
4255 "Specify a network to announce via BGP\n"
4256 "Network number\n"
4257 "Specify a BGP backdoor route\n")
4258
4259#ifdef HAVE_IPV6
4260DEFUN (ipv6_bgp_network,
4261 ipv6_bgp_network_cmd,
4262 "network X:X::X:X/M",
4263 "Specify a network to announce via BGP\n"
4264 "IPv6 prefix <network>/<length>\n")
4265{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304266 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004267 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004268}
4269
4270DEFUN (ipv6_bgp_network_route_map,
4271 ipv6_bgp_network_route_map_cmd,
4272 "network X:X::X:X/M route-map WORD",
4273 "Specify a network to announce via BGP\n"
4274 "IPv6 prefix <network>/<length>\n"
4275 "Route-map to modify the attributes\n"
4276 "Name of the route map\n")
4277{
4278 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004279 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004280}
4281
4282DEFUN (no_ipv6_bgp_network,
4283 no_ipv6_bgp_network_cmd,
4284 "no network X:X::X:X/M",
4285 NO_STR
4286 "Specify a network to announce via BGP\n"
4287 "IPv6 prefix <network>/<length>\n")
4288{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304289 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004290}
4291
4292ALIAS (no_ipv6_bgp_network,
4293 no_ipv6_bgp_network_route_map_cmd,
4294 "no network X:X::X:X/M route-map WORD",
4295 NO_STR
4296 "Specify a network to announce via BGP\n"
4297 "IPv6 prefix <network>/<length>\n"
4298 "Route-map to modify the attributes\n"
4299 "Name of the route map\n")
4300
4301ALIAS (ipv6_bgp_network,
4302 old_ipv6_bgp_network_cmd,
4303 "ipv6 bgp network X:X::X:X/M",
4304 IPV6_STR
4305 BGP_STR
4306 "Specify a network to announce via BGP\n"
4307 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4308
4309ALIAS (no_ipv6_bgp_network,
4310 old_no_ipv6_bgp_network_cmd,
4311 "no ipv6 bgp network X:X::X:X/M",
4312 NO_STR
4313 IPV6_STR
4314 BGP_STR
4315 "Specify a network to announce via BGP\n"
4316 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4317#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004318
4319/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4320ALIAS_DEPRECATED (bgp_network,
4321 bgp_network_ttl_cmd,
4322 "network A.B.C.D/M pathlimit <0-255>",
4323 "Specify a network to announce via BGP\n"
4324 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4325 "AS-Path hopcount limit attribute\n"
4326 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4327ALIAS_DEPRECATED (bgp_network_backdoor,
4328 bgp_network_backdoor_ttl_cmd,
4329 "network A.B.C.D/M backdoor pathlimit <0-255>",
4330 "Specify a network to announce via BGP\n"
4331 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4332 "Specify a BGP backdoor route\n"
4333 "AS-Path hopcount limit attribute\n"
4334 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4335ALIAS_DEPRECATED (bgp_network_mask,
4336 bgp_network_mask_ttl_cmd,
4337 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4338 "Specify a network to announce via BGP\n"
4339 "Network number\n"
4340 "Network mask\n"
4341 "Network mask\n"
4342 "AS-Path hopcount limit attribute\n"
4343 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4344ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4345 bgp_network_mask_backdoor_ttl_cmd,
4346 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4347 "Specify a network to announce via BGP\n"
4348 "Network number\n"
4349 "Network mask\n"
4350 "Network mask\n"
4351 "Specify a BGP backdoor route\n"
4352 "AS-Path hopcount limit attribute\n"
4353 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4354ALIAS_DEPRECATED (bgp_network_mask_natural,
4355 bgp_network_mask_natural_ttl_cmd,
4356 "network A.B.C.D pathlimit <0-255>",
4357 "Specify a network to announce via BGP\n"
4358 "Network number\n"
4359 "AS-Path hopcount limit attribute\n"
4360 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4361ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4362 bgp_network_mask_natural_backdoor_ttl_cmd,
4363 "network A.B.C.D backdoor pathlimit (1-255>",
4364 "Specify a network to announce via BGP\n"
4365 "Network number\n"
4366 "Specify a BGP backdoor route\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_ttl_cmd,
4371 "no network A.B.C.D/M 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 "AS-Path hopcount limit attribute\n"
4376 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4377ALIAS_DEPRECATED (no_bgp_network,
4378 no_bgp_network_backdoor_ttl_cmd,
4379 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4380 NO_STR
4381 "Specify a network to announce via BGP\n"
4382 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4383 "Specify a BGP backdoor route\n"
4384 "AS-Path hopcount limit attribute\n"
4385 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4386ALIAS_DEPRECATED (no_bgp_network,
4387 no_bgp_network_mask_ttl_cmd,
4388 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4389 NO_STR
4390 "Specify a network to announce via BGP\n"
4391 "Network number\n"
4392 "Network mask\n"
4393 "Network mask\n"
4394 "AS-Path hopcount limit attribute\n"
4395 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4396ALIAS_DEPRECATED (no_bgp_network_mask,
4397 no_bgp_network_mask_backdoor_ttl_cmd,
4398 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4399 NO_STR
4400 "Specify a network to announce via BGP\n"
4401 "Network number\n"
4402 "Network mask\n"
4403 "Network mask\n"
4404 "Specify a BGP backdoor route\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_ttl_cmd,
4409 "no network A.B.C.D pathlimit <0-255>",
4410 NO_STR
4411 "Specify a network to announce via BGP\n"
4412 "Network number\n"
4413 "AS-Path hopcount limit attribute\n"
4414 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4415ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4416 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4417 "no network A.B.C.D backdoor pathlimit <0-255>",
4418 NO_STR
4419 "Specify a network to announce via BGP\n"
4420 "Network number\n"
4421 "Specify a BGP backdoor route\n"
4422 "AS-Path hopcount limit attribute\n"
4423 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004424#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004425ALIAS_DEPRECATED (ipv6_bgp_network,
4426 ipv6_bgp_network_ttl_cmd,
4427 "network X:X::X:X/M pathlimit <0-255>",
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")
4432ALIAS_DEPRECATED (no_ipv6_bgp_network,
4433 no_ipv6_bgp_network_ttl_cmd,
4434 "no network X:X::X:X/M pathlimit <0-255>",
4435 NO_STR
4436 "Specify a network to announce via BGP\n"
4437 "IPv6 prefix <network>/<length>\n"
4438 "AS-Path hopcount limit attribute\n"
4439 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004440#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004441
4442/* Aggreagete address:
4443
4444 advertise-map Set condition to advertise attribute
4445 as-set Generate AS set path information
4446 attribute-map Set attributes of aggregate
4447 route-map Set parameters of aggregate
4448 summary-only Filter more specific routes from updates
4449 suppress-map Conditionally filter more specific routes from updates
4450 <cr>
4451 */
4452struct bgp_aggregate
4453{
4454 /* Summary-only flag. */
4455 u_char summary_only;
4456
4457 /* AS set generation. */
4458 u_char as_set;
4459
4460 /* Route-map for aggregated route. */
4461 struct route_map *map;
4462
4463 /* Suppress-count. */
4464 unsigned long count;
4465
4466 /* SAFI configuration. */
4467 safi_t safi;
4468};
4469
paul94f2b392005-06-28 12:44:16 +00004470static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004471bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004472{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004473 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004474}
4475
paul94f2b392005-06-28 12:44:16 +00004476static void
paul718e3742002-12-13 20:15:29 +00004477bgp_aggregate_free (struct bgp_aggregate *aggregate)
4478{
4479 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4480}
4481
paul94f2b392005-06-28 12:44:16 +00004482static void
paul718e3742002-12-13 20:15:29 +00004483bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4484 afi_t afi, safi_t safi, struct bgp_info *del,
4485 struct bgp_aggregate *aggregate)
4486{
4487 struct bgp_table *table;
4488 struct bgp_node *top;
4489 struct bgp_node *rn;
4490 u_char origin;
4491 struct aspath *aspath = NULL;
4492 struct aspath *asmerge = NULL;
4493 struct community *community = NULL;
4494 struct community *commerge = NULL;
4495 struct in_addr nexthop;
4496 u_int32_t med = 0;
4497 struct bgp_info *ri;
4498 struct bgp_info *new;
4499 int first = 1;
4500 unsigned long match = 0;
4501
4502 /* Record adding route's nexthop and med. */
4503 if (rinew)
4504 {
4505 nexthop = rinew->attr->nexthop;
4506 med = rinew->attr->med;
4507 }
4508
4509 /* ORIGIN attribute: If at least one route among routes that are
4510 aggregated has ORIGIN with the value INCOMPLETE, then the
4511 aggregated route must have the ORIGIN attribute with the value
4512 INCOMPLETE. Otherwise, if at least one route among routes that
4513 are aggregated has ORIGIN with the value EGP, then the aggregated
4514 route must have the origin attribute with the value EGP. In all
4515 other case the value of the ORIGIN attribute of the aggregated
4516 route is INTERNAL. */
4517 origin = BGP_ORIGIN_IGP;
4518
4519 table = bgp->rib[afi][safi];
4520
4521 top = bgp_node_get (table, p);
4522 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4523 if (rn->p.prefixlen > p->prefixlen)
4524 {
4525 match = 0;
4526
4527 for (ri = rn->info; ri; ri = ri->next)
4528 {
4529 if (BGP_INFO_HOLDDOWN (ri))
4530 continue;
4531
4532 if (del && ri == del)
4533 continue;
4534
4535 if (! rinew && first)
4536 {
4537 nexthop = ri->attr->nexthop;
4538 med = ri->attr->med;
4539 first = 0;
4540 }
4541
4542#ifdef AGGREGATE_NEXTHOP_CHECK
4543 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4544 || ri->attr->med != med)
4545 {
4546 if (aspath)
4547 aspath_free (aspath);
4548 if (community)
4549 community_free (community);
4550 bgp_unlock_node (rn);
4551 bgp_unlock_node (top);
4552 return;
4553 }
4554#endif /* AGGREGATE_NEXTHOP_CHECK */
4555
4556 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4557 {
4558 if (aggregate->summary_only)
4559 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004560 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004561 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004562 match++;
4563 }
4564
4565 aggregate->count++;
4566
4567 if (aggregate->as_set)
4568 {
4569 if (origin < ri->attr->origin)
4570 origin = ri->attr->origin;
4571
4572 if (aspath)
4573 {
4574 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4575 aspath_free (aspath);
4576 aspath = asmerge;
4577 }
4578 else
4579 aspath = aspath_dup (ri->attr->aspath);
4580
4581 if (ri->attr->community)
4582 {
4583 if (community)
4584 {
4585 commerge = community_merge (community,
4586 ri->attr->community);
4587 community = community_uniq_sort (commerge);
4588 community_free (commerge);
4589 }
4590 else
4591 community = community_dup (ri->attr->community);
4592 }
4593 }
4594 }
4595 }
4596 if (match)
4597 bgp_process (bgp, rn, afi, safi);
4598 }
4599 bgp_unlock_node (top);
4600
4601 if (rinew)
4602 {
4603 aggregate->count++;
4604
4605 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004606 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004607
4608 if (aggregate->as_set)
4609 {
4610 if (origin < rinew->attr->origin)
4611 origin = rinew->attr->origin;
4612
4613 if (aspath)
4614 {
4615 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4616 aspath_free (aspath);
4617 aspath = asmerge;
4618 }
4619 else
4620 aspath = aspath_dup (rinew->attr->aspath);
4621
4622 if (rinew->attr->community)
4623 {
4624 if (community)
4625 {
4626 commerge = community_merge (community,
4627 rinew->attr->community);
4628 community = community_uniq_sort (commerge);
4629 community_free (commerge);
4630 }
4631 else
4632 community = community_dup (rinew->attr->community);
4633 }
4634 }
4635 }
4636
4637 if (aggregate->count > 0)
4638 {
4639 rn = bgp_node_get (table, p);
4640 new = bgp_info_new ();
4641 new->type = ZEBRA_ROUTE_BGP;
4642 new->sub_type = BGP_ROUTE_AGGREGATE;
4643 new->peer = bgp->peer_self;
4644 SET_FLAG (new->flags, BGP_INFO_VALID);
4645 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004646 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004647
4648 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004649 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004650 bgp_process (bgp, rn, afi, safi);
4651 }
4652 else
4653 {
4654 if (aspath)
4655 aspath_free (aspath);
4656 if (community)
4657 community_free (community);
4658 }
4659}
4660
4661void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4662 struct bgp_aggregate *);
4663
4664void
4665bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4666 struct bgp_info *ri, afi_t afi, safi_t safi)
4667{
4668 struct bgp_node *child;
4669 struct bgp_node *rn;
4670 struct bgp_aggregate *aggregate;
4671
4672 /* MPLS-VPN aggregation is not yet supported. */
4673 if (safi == SAFI_MPLS_VPN)
4674 return;
4675
4676 if (p->prefixlen == 0)
4677 return;
4678
4679 if (BGP_INFO_HOLDDOWN (ri))
4680 return;
4681
4682 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4683
4684 /* Aggregate address configuration check. */
4685 for (rn = child; rn; rn = rn->parent)
4686 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4687 {
4688 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004689 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004690 }
4691 bgp_unlock_node (child);
4692}
4693
4694void
4695bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4696 struct bgp_info *del, afi_t afi, safi_t safi)
4697{
4698 struct bgp_node *child;
4699 struct bgp_node *rn;
4700 struct bgp_aggregate *aggregate;
4701
4702 /* MPLS-VPN aggregation is not yet supported. */
4703 if (safi == SAFI_MPLS_VPN)
4704 return;
4705
4706 if (p->prefixlen == 0)
4707 return;
4708
4709 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4710
4711 /* Aggregate address configuration check. */
4712 for (rn = child; rn; rn = rn->parent)
4713 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4714 {
4715 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004716 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004717 }
4718 bgp_unlock_node (child);
4719}
4720
paul94f2b392005-06-28 12:44:16 +00004721static void
paul718e3742002-12-13 20:15:29 +00004722bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4723 struct bgp_aggregate *aggregate)
4724{
4725 struct bgp_table *table;
4726 struct bgp_node *top;
4727 struct bgp_node *rn;
4728 struct bgp_info *new;
4729 struct bgp_info *ri;
4730 unsigned long match;
4731 u_char origin = BGP_ORIGIN_IGP;
4732 struct aspath *aspath = NULL;
4733 struct aspath *asmerge = NULL;
4734 struct community *community = NULL;
4735 struct community *commerge = NULL;
4736
4737 table = bgp->rib[afi][safi];
4738
4739 /* Sanity check. */
4740 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4741 return;
4742 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4743 return;
4744
4745 /* If routes exists below this node, generate aggregate routes. */
4746 top = bgp_node_get (table, p);
4747 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4748 if (rn->p.prefixlen > p->prefixlen)
4749 {
4750 match = 0;
4751
4752 for (ri = rn->info; ri; ri = ri->next)
4753 {
4754 if (BGP_INFO_HOLDDOWN (ri))
4755 continue;
4756
4757 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4758 {
4759 /* summary-only aggregate route suppress aggregated
4760 route announcement. */
4761 if (aggregate->summary_only)
4762 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004763 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004764 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004765 match++;
4766 }
4767 /* as-set aggregate route generate origin, as path,
4768 community aggregation. */
4769 if (aggregate->as_set)
4770 {
4771 if (origin < ri->attr->origin)
4772 origin = ri->attr->origin;
4773
4774 if (aspath)
4775 {
4776 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4777 aspath_free (aspath);
4778 aspath = asmerge;
4779 }
4780 else
4781 aspath = aspath_dup (ri->attr->aspath);
4782
4783 if (ri->attr->community)
4784 {
4785 if (community)
4786 {
4787 commerge = community_merge (community,
4788 ri->attr->community);
4789 community = community_uniq_sort (commerge);
4790 community_free (commerge);
4791 }
4792 else
4793 community = community_dup (ri->attr->community);
4794 }
4795 }
4796 aggregate->count++;
4797 }
4798 }
4799
4800 /* If this node is suppressed, process the change. */
4801 if (match)
4802 bgp_process (bgp, rn, afi, safi);
4803 }
4804 bgp_unlock_node (top);
4805
4806 /* Add aggregate route to BGP table. */
4807 if (aggregate->count)
4808 {
4809 rn = bgp_node_get (table, p);
4810
4811 new = bgp_info_new ();
4812 new->type = ZEBRA_ROUTE_BGP;
4813 new->sub_type = BGP_ROUTE_AGGREGATE;
4814 new->peer = bgp->peer_self;
4815 SET_FLAG (new->flags, BGP_INFO_VALID);
4816 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004817 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004818
4819 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004820 bgp_unlock_node (rn);
4821
paul718e3742002-12-13 20:15:29 +00004822 /* Process change. */
4823 bgp_process (bgp, rn, afi, safi);
4824 }
4825}
4826
4827void
4828bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4829 safi_t safi, struct bgp_aggregate *aggregate)
4830{
4831 struct bgp_table *table;
4832 struct bgp_node *top;
4833 struct bgp_node *rn;
4834 struct bgp_info *ri;
4835 unsigned long match;
4836
4837 table = bgp->rib[afi][safi];
4838
4839 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4840 return;
4841 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4842 return;
4843
4844 /* If routes exists below this node, generate aggregate routes. */
4845 top = bgp_node_get (table, p);
4846 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4847 if (rn->p.prefixlen > p->prefixlen)
4848 {
4849 match = 0;
4850
4851 for (ri = rn->info; ri; ri = ri->next)
4852 {
4853 if (BGP_INFO_HOLDDOWN (ri))
4854 continue;
4855
4856 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4857 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004858 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004859 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004860 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004861
Paul Jakmafb982c22007-05-04 20:15:47 +00004862 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004863 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004864 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004865 match++;
4866 }
4867 }
4868 aggregate->count--;
4869 }
4870 }
4871
Paul Jakmafb982c22007-05-04 20:15:47 +00004872 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004873 if (match)
4874 bgp_process (bgp, rn, afi, safi);
4875 }
4876 bgp_unlock_node (top);
4877
4878 /* Delete aggregate route from BGP table. */
4879 rn = bgp_node_get (table, p);
4880
4881 for (ri = rn->info; ri; ri = ri->next)
4882 if (ri->peer == bgp->peer_self
4883 && ri->type == ZEBRA_ROUTE_BGP
4884 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4885 break;
4886
4887 /* Withdraw static BGP route from routing table. */
4888 if (ri)
4889 {
paul718e3742002-12-13 20:15:29 +00004890 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004891 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004892 }
4893
4894 /* Unlock bgp_node_lookup. */
4895 bgp_unlock_node (rn);
4896}
4897
4898/* Aggregate route attribute. */
4899#define AGGREGATE_SUMMARY_ONLY 1
4900#define AGGREGATE_AS_SET 1
4901
paul94f2b392005-06-28 12:44:16 +00004902static int
Robert Baysf6269b42010-08-05 10:26:28 -07004903bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4904 afi_t afi, safi_t safi)
4905{
4906 int ret;
4907 struct prefix p;
4908 struct bgp_node *rn;
4909 struct bgp *bgp;
4910 struct bgp_aggregate *aggregate;
4911
4912 /* Convert string to prefix structure. */
4913 ret = str2prefix (prefix_str, &p);
4914 if (!ret)
4915 {
4916 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4917 return CMD_WARNING;
4918 }
4919 apply_mask (&p);
4920
4921 /* Get BGP structure. */
4922 bgp = vty->index;
4923
4924 /* Old configuration check. */
4925 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4926 if (! rn)
4927 {
4928 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4929 VTY_NEWLINE);
4930 return CMD_WARNING;
4931 }
4932
4933 aggregate = rn->info;
4934 if (aggregate->safi & SAFI_UNICAST)
4935 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4936 if (aggregate->safi & SAFI_MULTICAST)
4937 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4938
4939 /* Unlock aggregate address configuration. */
4940 rn->info = NULL;
4941 bgp_aggregate_free (aggregate);
4942 bgp_unlock_node (rn);
4943 bgp_unlock_node (rn);
4944
4945 return CMD_SUCCESS;
4946}
4947
4948static int
4949bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004950 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004951 u_char summary_only, u_char as_set)
4952{
4953 int ret;
4954 struct prefix p;
4955 struct bgp_node *rn;
4956 struct bgp *bgp;
4957 struct bgp_aggregate *aggregate;
4958
4959 /* Convert string to prefix structure. */
4960 ret = str2prefix (prefix_str, &p);
4961 if (!ret)
4962 {
4963 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4964 return CMD_WARNING;
4965 }
4966 apply_mask (&p);
4967
4968 /* Get BGP structure. */
4969 bgp = vty->index;
4970
4971 /* Old configuration check. */
4972 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4973
4974 if (rn->info)
4975 {
4976 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004977 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004978 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4979 if (ret)
4980 {
Robert Bays368473f2010-08-05 10:26:29 -07004981 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4982 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004983 return CMD_WARNING;
4984 }
paul718e3742002-12-13 20:15:29 +00004985 }
4986
4987 /* Make aggregate address structure. */
4988 aggregate = bgp_aggregate_new ();
4989 aggregate->summary_only = summary_only;
4990 aggregate->as_set = as_set;
4991 aggregate->safi = safi;
4992 rn->info = aggregate;
4993
4994 /* Aggregate address insert into BGP routing table. */
4995 if (safi & SAFI_UNICAST)
4996 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4997 if (safi & SAFI_MULTICAST)
4998 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4999
5000 return CMD_SUCCESS;
5001}
5002
paul718e3742002-12-13 20:15:29 +00005003DEFUN (aggregate_address,
5004 aggregate_address_cmd,
5005 "aggregate-address A.B.C.D/M",
5006 "Configure BGP aggregate entries\n"
5007 "Aggregate prefix\n")
5008{
5009 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5010}
5011
5012DEFUN (aggregate_address_mask,
5013 aggregate_address_mask_cmd,
5014 "aggregate-address A.B.C.D A.B.C.D",
5015 "Configure BGP aggregate entries\n"
5016 "Aggregate address\n"
5017 "Aggregate mask\n")
5018{
5019 int ret;
5020 char prefix_str[BUFSIZ];
5021
5022 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5023
5024 if (! ret)
5025 {
5026 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5027 return CMD_WARNING;
5028 }
5029
5030 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5031 0, 0);
5032}
5033
5034DEFUN (aggregate_address_summary_only,
5035 aggregate_address_summary_only_cmd,
5036 "aggregate-address A.B.C.D/M summary-only",
5037 "Configure BGP aggregate entries\n"
5038 "Aggregate prefix\n"
5039 "Filter more specific routes from updates\n")
5040{
5041 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5042 AGGREGATE_SUMMARY_ONLY, 0);
5043}
5044
5045DEFUN (aggregate_address_mask_summary_only,
5046 aggregate_address_mask_summary_only_cmd,
5047 "aggregate-address A.B.C.D A.B.C.D summary-only",
5048 "Configure BGP aggregate entries\n"
5049 "Aggregate address\n"
5050 "Aggregate mask\n"
5051 "Filter more specific routes from updates\n")
5052{
5053 int ret;
5054 char prefix_str[BUFSIZ];
5055
5056 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5057
5058 if (! ret)
5059 {
5060 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5061 return CMD_WARNING;
5062 }
5063
5064 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5065 AGGREGATE_SUMMARY_ONLY, 0);
5066}
5067
5068DEFUN (aggregate_address_as_set,
5069 aggregate_address_as_set_cmd,
5070 "aggregate-address A.B.C.D/M as-set",
5071 "Configure BGP aggregate entries\n"
5072 "Aggregate prefix\n"
5073 "Generate AS set path information\n")
5074{
5075 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5076 0, AGGREGATE_AS_SET);
5077}
5078
5079DEFUN (aggregate_address_mask_as_set,
5080 aggregate_address_mask_as_set_cmd,
5081 "aggregate-address A.B.C.D A.B.C.D as-set",
5082 "Configure BGP aggregate entries\n"
5083 "Aggregate address\n"
5084 "Aggregate mask\n"
5085 "Generate AS set path information\n")
5086{
5087 int ret;
5088 char prefix_str[BUFSIZ];
5089
5090 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5091
5092 if (! ret)
5093 {
5094 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5095 return CMD_WARNING;
5096 }
5097
5098 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5099 0, AGGREGATE_AS_SET);
5100}
5101
5102
5103DEFUN (aggregate_address_as_set_summary,
5104 aggregate_address_as_set_summary_cmd,
5105 "aggregate-address A.B.C.D/M as-set summary-only",
5106 "Configure BGP aggregate entries\n"
5107 "Aggregate prefix\n"
5108 "Generate AS set path information\n"
5109 "Filter more specific routes from updates\n")
5110{
5111 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5112 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5113}
5114
5115ALIAS (aggregate_address_as_set_summary,
5116 aggregate_address_summary_as_set_cmd,
5117 "aggregate-address A.B.C.D/M summary-only as-set",
5118 "Configure BGP aggregate entries\n"
5119 "Aggregate prefix\n"
5120 "Filter more specific routes from updates\n"
5121 "Generate AS set path information\n")
5122
5123DEFUN (aggregate_address_mask_as_set_summary,
5124 aggregate_address_mask_as_set_summary_cmd,
5125 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate address\n"
5128 "Aggregate mask\n"
5129 "Generate AS set path information\n"
5130 "Filter more specific routes from updates\n")
5131{
5132 int ret;
5133 char prefix_str[BUFSIZ];
5134
5135 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5136
5137 if (! ret)
5138 {
5139 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5140 return CMD_WARNING;
5141 }
5142
5143 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5144 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5145}
5146
5147ALIAS (aggregate_address_mask_as_set_summary,
5148 aggregate_address_mask_summary_as_set_cmd,
5149 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5150 "Configure BGP aggregate entries\n"
5151 "Aggregate address\n"
5152 "Aggregate mask\n"
5153 "Filter more specific routes from updates\n"
5154 "Generate AS set path information\n")
5155
5156DEFUN (no_aggregate_address,
5157 no_aggregate_address_cmd,
5158 "no aggregate-address A.B.C.D/M",
5159 NO_STR
5160 "Configure BGP aggregate entries\n"
5161 "Aggregate prefix\n")
5162{
5163 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5164}
5165
5166ALIAS (no_aggregate_address,
5167 no_aggregate_address_summary_only_cmd,
5168 "no aggregate-address A.B.C.D/M summary-only",
5169 NO_STR
5170 "Configure BGP aggregate entries\n"
5171 "Aggregate prefix\n"
5172 "Filter more specific routes from updates\n")
5173
5174ALIAS (no_aggregate_address,
5175 no_aggregate_address_as_set_cmd,
5176 "no aggregate-address A.B.C.D/M as-set",
5177 NO_STR
5178 "Configure BGP aggregate entries\n"
5179 "Aggregate prefix\n"
5180 "Generate AS set path information\n")
5181
5182ALIAS (no_aggregate_address,
5183 no_aggregate_address_as_set_summary_cmd,
5184 "no aggregate-address A.B.C.D/M as-set summary-only",
5185 NO_STR
5186 "Configure BGP aggregate entries\n"
5187 "Aggregate prefix\n"
5188 "Generate AS set path information\n"
5189 "Filter more specific routes from updates\n")
5190
5191ALIAS (no_aggregate_address,
5192 no_aggregate_address_summary_as_set_cmd,
5193 "no aggregate-address A.B.C.D/M summary-only as-set",
5194 NO_STR
5195 "Configure BGP aggregate entries\n"
5196 "Aggregate prefix\n"
5197 "Filter more specific routes from updates\n"
5198 "Generate AS set path information\n")
5199
5200DEFUN (no_aggregate_address_mask,
5201 no_aggregate_address_mask_cmd,
5202 "no aggregate-address A.B.C.D A.B.C.D",
5203 NO_STR
5204 "Configure BGP aggregate entries\n"
5205 "Aggregate address\n"
5206 "Aggregate mask\n")
5207{
5208 int ret;
5209 char prefix_str[BUFSIZ];
5210
5211 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5212
5213 if (! ret)
5214 {
5215 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5216 return CMD_WARNING;
5217 }
5218
5219 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5220}
5221
5222ALIAS (no_aggregate_address_mask,
5223 no_aggregate_address_mask_summary_only_cmd,
5224 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5225 NO_STR
5226 "Configure BGP aggregate entries\n"
5227 "Aggregate address\n"
5228 "Aggregate mask\n"
5229 "Filter more specific routes from updates\n")
5230
5231ALIAS (no_aggregate_address_mask,
5232 no_aggregate_address_mask_as_set_cmd,
5233 "no aggregate-address A.B.C.D A.B.C.D as-set",
5234 NO_STR
5235 "Configure BGP aggregate entries\n"
5236 "Aggregate address\n"
5237 "Aggregate mask\n"
5238 "Generate AS set path information\n")
5239
5240ALIAS (no_aggregate_address_mask,
5241 no_aggregate_address_mask_as_set_summary_cmd,
5242 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5243 NO_STR
5244 "Configure BGP aggregate entries\n"
5245 "Aggregate address\n"
5246 "Aggregate mask\n"
5247 "Generate AS set path information\n"
5248 "Filter more specific routes from updates\n")
5249
5250ALIAS (no_aggregate_address_mask,
5251 no_aggregate_address_mask_summary_as_set_cmd,
5252 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5253 NO_STR
5254 "Configure BGP aggregate entries\n"
5255 "Aggregate address\n"
5256 "Aggregate mask\n"
5257 "Filter more specific routes from updates\n"
5258 "Generate AS set path information\n")
5259
5260#ifdef HAVE_IPV6
5261DEFUN (ipv6_aggregate_address,
5262 ipv6_aggregate_address_cmd,
5263 "aggregate-address X:X::X:X/M",
5264 "Configure BGP aggregate entries\n"
5265 "Aggregate prefix\n")
5266{
5267 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5268}
5269
5270DEFUN (ipv6_aggregate_address_summary_only,
5271 ipv6_aggregate_address_summary_only_cmd,
5272 "aggregate-address X:X::X:X/M summary-only",
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate prefix\n"
5275 "Filter more specific routes from updates\n")
5276{
5277 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5278 AGGREGATE_SUMMARY_ONLY, 0);
5279}
5280
5281DEFUN (no_ipv6_aggregate_address,
5282 no_ipv6_aggregate_address_cmd,
5283 "no aggregate-address X:X::X:X/M",
5284 NO_STR
5285 "Configure BGP aggregate entries\n"
5286 "Aggregate prefix\n")
5287{
5288 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5289}
5290
5291DEFUN (no_ipv6_aggregate_address_summary_only,
5292 no_ipv6_aggregate_address_summary_only_cmd,
5293 "no aggregate-address X:X::X:X/M summary-only",
5294 NO_STR
5295 "Configure BGP aggregate entries\n"
5296 "Aggregate prefix\n"
5297 "Filter more specific routes from updates\n")
5298{
5299 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5300}
5301
5302ALIAS (ipv6_aggregate_address,
5303 old_ipv6_aggregate_address_cmd,
5304 "ipv6 bgp aggregate-address X:X::X:X/M",
5305 IPV6_STR
5306 BGP_STR
5307 "Configure BGP aggregate entries\n"
5308 "Aggregate prefix\n")
5309
5310ALIAS (ipv6_aggregate_address_summary_only,
5311 old_ipv6_aggregate_address_summary_only_cmd,
5312 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5313 IPV6_STR
5314 BGP_STR
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate prefix\n"
5317 "Filter more specific routes from updates\n")
5318
5319ALIAS (no_ipv6_aggregate_address,
5320 old_no_ipv6_aggregate_address_cmd,
5321 "no ipv6 bgp aggregate-address X:X::X:X/M",
5322 NO_STR
5323 IPV6_STR
5324 BGP_STR
5325 "Configure BGP aggregate entries\n"
5326 "Aggregate prefix\n")
5327
5328ALIAS (no_ipv6_aggregate_address_summary_only,
5329 old_no_ipv6_aggregate_address_summary_only_cmd,
5330 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5331 NO_STR
5332 IPV6_STR
5333 BGP_STR
5334 "Configure BGP aggregate entries\n"
5335 "Aggregate prefix\n"
5336 "Filter more specific routes from updates\n")
5337#endif /* HAVE_IPV6 */
5338
5339/* Redistribute route treatment. */
5340void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005341bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5342 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005343 u_int32_t metric, u_char type)
5344{
5345 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005346 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005347 struct bgp_info *new;
5348 struct bgp_info *bi;
5349 struct bgp_info info;
5350 struct bgp_node *bn;
Jorge Boncompte [DTI2]e16a4132012-05-07 16:52:57 +00005351 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00005352 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005353 struct attr *new_attr;
5354 afi_t afi;
5355 int ret;
5356
5357 /* Make default attribute. */
5358 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5359 if (nexthop)
5360 attr.nexthop = *nexthop;
5361
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005362#ifdef HAVE_IPV6
5363 if (nexthop6)
5364 {
5365 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5366 extra->mp_nexthop_global = *nexthop6;
5367 extra->mp_nexthop_len = 16;
5368 }
5369#endif
5370
paul718e3742002-12-13 20:15:29 +00005371 attr.med = metric;
5372 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5373
paul1eb8ef22005-04-07 07:30:20 +00005374 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005375 {
5376 afi = family2afi (p->family);
5377
5378 if (bgp->redist[afi][type])
5379 {
5380 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005381 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005382
5383 if (bgp->redist_metric_flag[afi][type])
5384 attr_new.med = bgp->redist_metric[afi][type];
5385
5386 /* Apply route-map. */
5387 if (bgp->rmap[afi][type].map)
5388 {
5389 info.peer = bgp->peer_self;
5390 info.attr = &attr_new;
5391
paulfee0f4c2004-09-13 05:12:46 +00005392 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5393
paul718e3742002-12-13 20:15:29 +00005394 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5395 &info);
paulfee0f4c2004-09-13 05:12:46 +00005396
5397 bgp->peer_self->rmap_type = 0;
5398
paul718e3742002-12-13 20:15:29 +00005399 if (ret == RMAP_DENYMATCH)
5400 {
5401 /* Free uninterned attribute. */
5402 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005403 bgp_attr_extra_free (&attr_new);
5404
paul718e3742002-12-13 20:15:29 +00005405 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005406 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005407 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005408 bgp_redistribute_delete (p, type);
5409 return;
5410 }
5411 }
5412
Paul Jakmafb982c22007-05-04 20:15:47 +00005413 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5414 afi, SAFI_UNICAST, p, NULL);
5415
paul718e3742002-12-13 20:15:29 +00005416 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005417 bgp_attr_extra_free (&attr_new);
5418
paul718e3742002-12-13 20:15:29 +00005419 for (bi = bn->info; bi; bi = bi->next)
5420 if (bi->peer == bgp->peer_self
5421 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5422 break;
5423
5424 if (bi)
5425 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005426 if (attrhash_cmp (bi->attr, new_attr) &&
5427 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005428 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005429 bgp_attr_unintern (&new_attr);
5430 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005431 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005432 bgp_unlock_node (bn);
5433 return;
5434 }
5435 else
5436 {
5437 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005438 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005439
5440 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005441 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5442 bgp_info_restore(bn, bi);
5443 else
5444 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005445 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005446 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005447 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005448
5449 /* Process change. */
5450 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5451 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5452 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005453 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005454 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005455 return;
5456 }
5457 }
5458
5459 new = bgp_info_new ();
5460 new->type = type;
5461 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5462 new->peer = bgp->peer_self;
5463 SET_FLAG (new->flags, BGP_INFO_VALID);
5464 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005465 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005466
5467 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5468 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005469 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005470 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5471 }
5472 }
5473
5474 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005475 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005476 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005477}
5478
5479void
5480bgp_redistribute_delete (struct prefix *p, u_char type)
5481{
5482 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005483 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005484 afi_t afi;
5485 struct bgp_node *rn;
5486 struct bgp_info *ri;
5487
paul1eb8ef22005-04-07 07:30:20 +00005488 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005489 {
5490 afi = family2afi (p->family);
5491
5492 if (bgp->redist[afi][type])
5493 {
paulfee0f4c2004-09-13 05:12:46 +00005494 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005495
5496 for (ri = rn->info; ri; ri = ri->next)
5497 if (ri->peer == bgp->peer_self
5498 && ri->type == type)
5499 break;
5500
5501 if (ri)
5502 {
5503 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005504 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005505 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005506 }
5507 bgp_unlock_node (rn);
5508 }
5509 }
5510}
5511
5512/* Withdraw specified route type's route. */
5513void
5514bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5515{
5516 struct bgp_node *rn;
5517 struct bgp_info *ri;
5518 struct bgp_table *table;
5519
5520 table = bgp->rib[afi][SAFI_UNICAST];
5521
5522 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5523 {
5524 for (ri = rn->info; ri; ri = ri->next)
5525 if (ri->peer == bgp->peer_self
5526 && ri->type == type)
5527 break;
5528
5529 if (ri)
5530 {
5531 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005532 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005533 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005534 }
5535 }
5536}
5537
5538/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005539static void
paul718e3742002-12-13 20:15:29 +00005540route_vty_out_route (struct prefix *p, struct vty *vty)
5541{
5542 int len;
5543 u_int32_t destination;
5544 char buf[BUFSIZ];
5545
5546 if (p->family == AF_INET)
5547 {
5548 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5549 destination = ntohl (p->u.prefix4.s_addr);
5550
5551 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5552 || (IN_CLASSB (destination) && p->prefixlen == 16)
5553 || (IN_CLASSA (destination) && p->prefixlen == 8)
5554 || p->u.prefix4.s_addr == 0)
5555 {
5556 /* When mask is natural, mask is not displayed. */
5557 }
5558 else
5559 len += vty_out (vty, "/%d", p->prefixlen);
5560 }
5561 else
5562 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5563 p->prefixlen);
5564
5565 len = 17 - len;
5566 if (len < 1)
5567 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5568 else
5569 vty_out (vty, "%*s", len, " ");
5570}
5571
paul718e3742002-12-13 20:15:29 +00005572enum bgp_display_type
5573{
5574 normal_list,
5575};
5576
paulb40d9392005-08-22 22:34:41 +00005577/* Print the short form route status for a bgp_info */
5578static void
5579route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005580{
paulb40d9392005-08-22 22:34:41 +00005581 /* Route status display. */
5582 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5583 vty_out (vty, "R");
5584 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005585 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005586 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005587 vty_out (vty, "s");
5588 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5589 vty_out (vty, "*");
5590 else
5591 vty_out (vty, " ");
5592
5593 /* Selected */
5594 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5595 vty_out (vty, "h");
5596 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5597 vty_out (vty, "d");
5598 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5599 vty_out (vty, ">");
5600 else
5601 vty_out (vty, " ");
5602
5603 /* Internal route. */
5604 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5605 vty_out (vty, "i");
5606 else
paulb40d9392005-08-22 22:34:41 +00005607 vty_out (vty, " ");
5608}
5609
5610/* called from terminal list command */
5611void
5612route_vty_out (struct vty *vty, struct prefix *p,
5613 struct bgp_info *binfo, int display, safi_t safi)
5614{
5615 struct attr *attr;
5616
5617 /* short status lead text */
5618 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005619
5620 /* print prefix and mask */
5621 if (! display)
5622 route_vty_out_route (p, vty);
5623 else
5624 vty_out (vty, "%*s", 17, " ");
5625
5626 /* Print attribute */
5627 attr = binfo->attr;
5628 if (attr)
5629 {
5630 if (p->family == AF_INET)
5631 {
5632 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005633 vty_out (vty, "%-16s",
5634 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005635 else
5636 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5637 }
5638#ifdef HAVE_IPV6
5639 else if (p->family == AF_INET6)
5640 {
5641 int len;
5642 char buf[BUFSIZ];
5643
5644 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005645 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5646 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005647 len = 16 - len;
5648 if (len < 1)
5649 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5650 else
5651 vty_out (vty, "%*s", len, " ");
5652 }
5653#endif /* HAVE_IPV6 */
5654
5655 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005656 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005657 else
5658 vty_out (vty, " ");
5659
5660 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005661 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005662 else
5663 vty_out (vty, " ");
5664
Paul Jakmafb982c22007-05-04 20:15:47 +00005665 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005666
Paul Jakmab2518c12006-05-12 23:48:40 +00005667 /* Print aspath */
5668 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005669 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005670
Paul Jakmab2518c12006-05-12 23:48:40 +00005671 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005672 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005673 }
paul718e3742002-12-13 20:15:29 +00005674 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005675}
5676
5677/* called from terminal list command */
5678void
5679route_vty_out_tmp (struct vty *vty, struct prefix *p,
5680 struct attr *attr, safi_t safi)
5681{
5682 /* Route status display. */
5683 vty_out (vty, "*");
5684 vty_out (vty, ">");
5685 vty_out (vty, " ");
5686
5687 /* print prefix and mask */
5688 route_vty_out_route (p, vty);
5689
5690 /* Print attribute */
5691 if (attr)
5692 {
5693 if (p->family == AF_INET)
5694 {
5695 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005696 vty_out (vty, "%-16s",
5697 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005698 else
5699 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5700 }
5701#ifdef HAVE_IPV6
5702 else if (p->family == AF_INET6)
5703 {
5704 int len;
5705 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005706
5707 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005708
5709 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005710 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5711 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005712 len = 16 - len;
5713 if (len < 1)
5714 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5715 else
5716 vty_out (vty, "%*s", len, " ");
5717 }
5718#endif /* HAVE_IPV6 */
5719
5720 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005721 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005722 else
5723 vty_out (vty, " ");
5724
5725 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005726 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005727 else
5728 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005729
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005730 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005731
Paul Jakmab2518c12006-05-12 23:48:40 +00005732 /* Print aspath */
5733 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005734 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005735
Paul Jakmab2518c12006-05-12 23:48:40 +00005736 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005737 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005738 }
paul718e3742002-12-13 20:15:29 +00005739
5740 vty_out (vty, "%s", VTY_NEWLINE);
5741}
5742
ajs5a646652004-11-05 01:25:55 +00005743void
paul718e3742002-12-13 20:15:29 +00005744route_vty_out_tag (struct vty *vty, struct prefix *p,
5745 struct bgp_info *binfo, int display, safi_t safi)
5746{
5747 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005748 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005749
5750 if (!binfo->extra)
5751 return;
5752
paulb40d9392005-08-22 22:34:41 +00005753 /* short status lead text */
5754 route_vty_short_status_out (vty, binfo);
5755
paul718e3742002-12-13 20:15:29 +00005756 /* print prefix and mask */
5757 if (! display)
5758 route_vty_out_route (p, vty);
5759 else
5760 vty_out (vty, "%*s", 17, " ");
5761
5762 /* Print attribute */
5763 attr = binfo->attr;
5764 if (attr)
5765 {
5766 if (p->family == AF_INET)
5767 {
5768 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005769 vty_out (vty, "%-16s",
5770 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005771 else
5772 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5773 }
5774#ifdef HAVE_IPV6
5775 else if (p->family == AF_INET6)
5776 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005777 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005778 char buf[BUFSIZ];
5779 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005780 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005781 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005782 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5783 buf, BUFSIZ));
5784 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005785 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005786 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5787 buf, BUFSIZ),
5788 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5789 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005790
5791 }
5792#endif /* HAVE_IPV6 */
5793 }
5794
Paul Jakmafb982c22007-05-04 20:15:47 +00005795 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005796
5797 vty_out (vty, "notag/%d", label);
5798
5799 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005800}
5801
5802/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005803static void
paul718e3742002-12-13 20:15:29 +00005804damp_route_vty_out (struct vty *vty, struct prefix *p,
5805 struct bgp_info *binfo, int display, safi_t safi)
5806{
5807 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005808 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005809 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005810
paulb40d9392005-08-22 22:34:41 +00005811 /* short status lead text */
5812 route_vty_short_status_out (vty, binfo);
5813
paul718e3742002-12-13 20:15:29 +00005814 /* print prefix and mask */
5815 if (! display)
5816 route_vty_out_route (p, vty);
5817 else
5818 vty_out (vty, "%*s", 17, " ");
5819
5820 len = vty_out (vty, "%s", binfo->peer->host);
5821 len = 17 - len;
5822 if (len < 1)
5823 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5824 else
5825 vty_out (vty, "%*s", len, " ");
5826
Chris Caputo50aef6f2009-06-23 06:06:49 +00005827 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005828
5829 /* Print attribute */
5830 attr = binfo->attr;
5831 if (attr)
5832 {
5833 /* Print aspath */
5834 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005835 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005836
5837 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005838 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005839 }
5840 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005841}
5842
paul718e3742002-12-13 20:15:29 +00005843/* flap route */
ajs5a646652004-11-05 01:25:55 +00005844static void
paul718e3742002-12-13 20:15:29 +00005845flap_route_vty_out (struct vty *vty, struct prefix *p,
5846 struct bgp_info *binfo, int display, safi_t safi)
5847{
5848 struct attr *attr;
5849 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005850 char timebuf[BGP_UPTIME_LEN];
5851 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005852
5853 if (!binfo->extra)
5854 return;
5855
5856 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005857
paulb40d9392005-08-22 22:34:41 +00005858 /* short status lead text */
5859 route_vty_short_status_out (vty, binfo);
5860
paul718e3742002-12-13 20:15:29 +00005861 /* print prefix and mask */
5862 if (! display)
5863 route_vty_out_route (p, vty);
5864 else
5865 vty_out (vty, "%*s", 17, " ");
5866
5867 len = vty_out (vty, "%s", binfo->peer->host);
5868 len = 16 - len;
5869 if (len < 1)
5870 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5871 else
5872 vty_out (vty, "%*s", len, " ");
5873
5874 len = vty_out (vty, "%d", bdi->flap);
5875 len = 5 - len;
5876 if (len < 1)
5877 vty_out (vty, " ");
5878 else
5879 vty_out (vty, "%*s ", len, " ");
5880
5881 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5882 timebuf, BGP_UPTIME_LEN));
5883
5884 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5885 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005886 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005887 else
5888 vty_out (vty, "%*s ", 8, " ");
5889
5890 /* Print attribute */
5891 attr = binfo->attr;
5892 if (attr)
5893 {
5894 /* Print aspath */
5895 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005896 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005897
5898 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005899 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005900 }
5901 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005902}
5903
paul94f2b392005-06-28 12:44:16 +00005904static void
paul718e3742002-12-13 20:15:29 +00005905route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5906 struct bgp_info *binfo, afi_t afi, safi_t safi)
5907{
5908 char buf[INET6_ADDRSTRLEN];
5909 char buf1[BUFSIZ];
5910 struct attr *attr;
5911 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005912#ifdef HAVE_CLOCK_MONOTONIC
5913 time_t tbuf;
5914#endif
paul718e3742002-12-13 20:15:29 +00005915
5916 attr = binfo->attr;
5917
5918 if (attr)
5919 {
5920 /* Line1 display AS-path, Aggregator */
5921 if (attr->aspath)
5922 {
5923 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005924 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005925 vty_out (vty, "Local");
5926 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005927 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005928 }
5929
paulb40d9392005-08-22 22:34:41 +00005930 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5931 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005932 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5933 vty_out (vty, ", (stale)");
5934 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005935 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005936 attr->extra->aggregator_as,
5937 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005938 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5939 vty_out (vty, ", (Received from a RR-client)");
5940 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5941 vty_out (vty, ", (Received from a RS-client)");
5942 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5943 vty_out (vty, ", (history entry)");
5944 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5945 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005946 vty_out (vty, "%s", VTY_NEWLINE);
5947
5948 /* Line2 display Next-hop, Neighbor, Router-id */
5949 if (p->family == AF_INET)
5950 {
5951 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005952 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005953 inet_ntoa (attr->nexthop));
5954 }
5955#ifdef HAVE_IPV6
5956 else
5957 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005958 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005959 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005960 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005961 buf, INET6_ADDRSTRLEN));
5962 }
5963#endif /* HAVE_IPV6 */
5964
5965 if (binfo->peer == bgp->peer_self)
5966 {
5967 vty_out (vty, " from %s ",
5968 p->family == AF_INET ? "0.0.0.0" : "::");
5969 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5970 }
5971 else
5972 {
5973 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5974 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005975 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02005976 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005977 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005978 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005979 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005980 else
5981 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5982 }
5983 vty_out (vty, "%s", VTY_NEWLINE);
5984
5985#ifdef HAVE_IPV6
5986 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005987 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005988 {
5989 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005990 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005991 buf, INET6_ADDRSTRLEN),
5992 VTY_NEWLINE);
5993 }
5994#endif /* HAVE_IPV6 */
5995
5996 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5997 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5998
5999 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006000 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006001
6002 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006003 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006004 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006005 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006006
Paul Jakmafb982c22007-05-04 20:15:47 +00006007 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006008 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006009
6010 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6011 vty_out (vty, ", valid");
6012
6013 if (binfo->peer != bgp->peer_self)
6014 {
6015 if (binfo->peer->as == binfo->peer->local_as)
6016 vty_out (vty, ", internal");
6017 else
6018 vty_out (vty, ", %s",
6019 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6020 }
6021 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6022 vty_out (vty, ", aggregated, local");
6023 else if (binfo->type != ZEBRA_ROUTE_BGP)
6024 vty_out (vty, ", sourced");
6025 else
6026 vty_out (vty, ", sourced, local");
6027
6028 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6029 vty_out (vty, ", atomic-aggregate");
6030
Josh Baileyde8d5df2011-07-20 20:46:01 -07006031 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6032 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6033 bgp_info_mpath_count (binfo)))
6034 vty_out (vty, ", multipath");
6035
paul718e3742002-12-13 20:15:29 +00006036 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6037 vty_out (vty, ", best");
6038
6039 vty_out (vty, "%s", VTY_NEWLINE);
6040
6041 /* Line 4 display Community */
6042 if (attr->community)
6043 vty_out (vty, " Community: %s%s", attr->community->str,
6044 VTY_NEWLINE);
6045
6046 /* Line 5 display Extended-community */
6047 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006048 vty_out (vty, " Extended Community: %s%s",
6049 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006050
6051 /* Line 6 display Originator, Cluster-id */
6052 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6053 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6054 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006055 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006056 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006057 vty_out (vty, " Originator: %s",
6058 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006059
6060 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6061 {
6062 int i;
6063 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006064 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6065 vty_out (vty, "%s ",
6066 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006067 }
6068 vty_out (vty, "%s", VTY_NEWLINE);
6069 }
Paul Jakma41367172007-08-06 15:24:51 +00006070
Paul Jakmafb982c22007-05-04 20:15:47 +00006071 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006072 bgp_damp_info_vty (vty, binfo);
6073
6074 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006075#ifdef HAVE_CLOCK_MONOTONIC
6076 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006077 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006078#else
6079 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6080#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006081 }
6082 vty_out (vty, "%s", VTY_NEWLINE);
6083}
6084
paulb40d9392005-08-22 22:34:41 +00006085#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 +00006086#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006087#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6088#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6089#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6090
6091enum bgp_show_type
6092{
6093 bgp_show_type_normal,
6094 bgp_show_type_regexp,
6095 bgp_show_type_prefix_list,
6096 bgp_show_type_filter_list,
6097 bgp_show_type_route_map,
6098 bgp_show_type_neighbor,
6099 bgp_show_type_cidr_only,
6100 bgp_show_type_prefix_longer,
6101 bgp_show_type_community_all,
6102 bgp_show_type_community,
6103 bgp_show_type_community_exact,
6104 bgp_show_type_community_list,
6105 bgp_show_type_community_list_exact,
6106 bgp_show_type_flap_statistics,
6107 bgp_show_type_flap_address,
6108 bgp_show_type_flap_prefix,
6109 bgp_show_type_flap_cidr_only,
6110 bgp_show_type_flap_regexp,
6111 bgp_show_type_flap_filter_list,
6112 bgp_show_type_flap_prefix_list,
6113 bgp_show_type_flap_prefix_longer,
6114 bgp_show_type_flap_route_map,
6115 bgp_show_type_flap_neighbor,
6116 bgp_show_type_dampend_paths,
6117 bgp_show_type_damp_neighbor
6118};
6119
ajs5a646652004-11-05 01:25:55 +00006120static int
paulfee0f4c2004-09-13 05:12:46 +00006121bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006122 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006123{
paul718e3742002-12-13 20:15:29 +00006124 struct bgp_info *ri;
6125 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006126 int header = 1;
paul718e3742002-12-13 20:15:29 +00006127 int display;
ajs5a646652004-11-05 01:25:55 +00006128 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006129
6130 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006131 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006132
paul718e3742002-12-13 20:15:29 +00006133 /* Start processing of routes. */
6134 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6135 if (rn->info != NULL)
6136 {
6137 display = 0;
6138
6139 for (ri = rn->info; ri; ri = ri->next)
6140 {
ajs5a646652004-11-05 01:25:55 +00006141 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006142 || type == bgp_show_type_flap_address
6143 || type == bgp_show_type_flap_prefix
6144 || type == bgp_show_type_flap_cidr_only
6145 || type == bgp_show_type_flap_regexp
6146 || type == bgp_show_type_flap_filter_list
6147 || type == bgp_show_type_flap_prefix_list
6148 || type == bgp_show_type_flap_prefix_longer
6149 || type == bgp_show_type_flap_route_map
6150 || type == bgp_show_type_flap_neighbor
6151 || type == bgp_show_type_dampend_paths
6152 || type == bgp_show_type_damp_neighbor)
6153 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006154 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006155 continue;
6156 }
6157 if (type == bgp_show_type_regexp
6158 || type == bgp_show_type_flap_regexp)
6159 {
ajs5a646652004-11-05 01:25:55 +00006160 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006161
6162 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6163 continue;
6164 }
6165 if (type == bgp_show_type_prefix_list
6166 || type == bgp_show_type_flap_prefix_list)
6167 {
ajs5a646652004-11-05 01:25:55 +00006168 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006169
6170 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6171 continue;
6172 }
6173 if (type == bgp_show_type_filter_list
6174 || type == bgp_show_type_flap_filter_list)
6175 {
ajs5a646652004-11-05 01:25:55 +00006176 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006177
6178 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6179 continue;
6180 }
6181 if (type == bgp_show_type_route_map
6182 || type == bgp_show_type_flap_route_map)
6183 {
ajs5a646652004-11-05 01:25:55 +00006184 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006185 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006186 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006187 int ret;
6188
Paul Jakmafb982c22007-05-04 20:15:47 +00006189 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006190 binfo.peer = ri->peer;
6191 binfo.attr = &dummy_attr;
6192
6193 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006194
6195 bgp_attr_extra_free (&dummy_attr);
6196
paul718e3742002-12-13 20:15:29 +00006197 if (ret == RMAP_DENYMATCH)
6198 continue;
6199 }
6200 if (type == bgp_show_type_neighbor
6201 || type == bgp_show_type_flap_neighbor
6202 || type == bgp_show_type_damp_neighbor)
6203 {
ajs5a646652004-11-05 01:25:55 +00006204 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006205
6206 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6207 continue;
6208 }
6209 if (type == bgp_show_type_cidr_only
6210 || type == bgp_show_type_flap_cidr_only)
6211 {
6212 u_int32_t destination;
6213
6214 destination = ntohl (rn->p.u.prefix4.s_addr);
6215 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6216 continue;
6217 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6218 continue;
6219 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6220 continue;
6221 }
6222 if (type == bgp_show_type_prefix_longer
6223 || type == bgp_show_type_flap_prefix_longer)
6224 {
ajs5a646652004-11-05 01:25:55 +00006225 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006226
6227 if (! prefix_match (p, &rn->p))
6228 continue;
6229 }
6230 if (type == bgp_show_type_community_all)
6231 {
6232 if (! ri->attr->community)
6233 continue;
6234 }
6235 if (type == bgp_show_type_community)
6236 {
ajs5a646652004-11-05 01:25:55 +00006237 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006238
6239 if (! ri->attr->community ||
6240 ! community_match (ri->attr->community, com))
6241 continue;
6242 }
6243 if (type == bgp_show_type_community_exact)
6244 {
ajs5a646652004-11-05 01:25:55 +00006245 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006246
6247 if (! ri->attr->community ||
6248 ! community_cmp (ri->attr->community, com))
6249 continue;
6250 }
6251 if (type == bgp_show_type_community_list)
6252 {
ajs5a646652004-11-05 01:25:55 +00006253 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006254
6255 if (! community_list_match (ri->attr->community, list))
6256 continue;
6257 }
6258 if (type == bgp_show_type_community_list_exact)
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_exact_match (ri->attr->community, list))
6263 continue;
6264 }
6265 if (type == bgp_show_type_flap_address
6266 || type == bgp_show_type_flap_prefix)
6267 {
ajs5a646652004-11-05 01:25:55 +00006268 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006269
6270 if (! prefix_match (&rn->p, p))
6271 continue;
6272
6273 if (type == bgp_show_type_flap_prefix)
6274 if (p->prefixlen != rn->p.prefixlen)
6275 continue;
6276 }
6277 if (type == bgp_show_type_dampend_paths
6278 || type == bgp_show_type_damp_neighbor)
6279 {
6280 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6281 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6282 continue;
6283 }
6284
6285 if (header)
6286 {
hasso93406d82005-02-02 14:40:33 +00006287 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6288 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6289 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006290 if (type == bgp_show_type_dampend_paths
6291 || type == bgp_show_type_damp_neighbor)
6292 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6293 else if (type == bgp_show_type_flap_statistics
6294 || type == bgp_show_type_flap_address
6295 || type == bgp_show_type_flap_prefix
6296 || type == bgp_show_type_flap_cidr_only
6297 || type == bgp_show_type_flap_regexp
6298 || type == bgp_show_type_flap_filter_list
6299 || type == bgp_show_type_flap_prefix_list
6300 || type == bgp_show_type_flap_prefix_longer
6301 || type == bgp_show_type_flap_route_map
6302 || type == bgp_show_type_flap_neighbor)
6303 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6304 else
6305 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006306 header = 0;
6307 }
6308
6309 if (type == bgp_show_type_dampend_paths
6310 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006311 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006312 else if (type == bgp_show_type_flap_statistics
6313 || type == bgp_show_type_flap_address
6314 || type == bgp_show_type_flap_prefix
6315 || type == bgp_show_type_flap_cidr_only
6316 || type == bgp_show_type_flap_regexp
6317 || type == bgp_show_type_flap_filter_list
6318 || type == bgp_show_type_flap_prefix_list
6319 || type == bgp_show_type_flap_prefix_longer
6320 || type == bgp_show_type_flap_route_map
6321 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006322 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006323 else
ajs5a646652004-11-05 01:25:55 +00006324 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006325 display++;
6326 }
6327 if (display)
ajs5a646652004-11-05 01:25:55 +00006328 output_count++;
paul718e3742002-12-13 20:15:29 +00006329 }
6330
6331 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006332 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006333 {
6334 if (type == bgp_show_type_normal)
6335 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6336 }
6337 else
6338 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006339 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006340
6341 return CMD_SUCCESS;
6342}
6343
ajs5a646652004-11-05 01:25:55 +00006344static int
paulfee0f4c2004-09-13 05:12:46 +00006345bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006346 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006347{
6348 struct bgp_table *table;
6349
6350 if (bgp == NULL) {
6351 bgp = bgp_get_default ();
6352 }
6353
6354 if (bgp == NULL)
6355 {
6356 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6357 return CMD_WARNING;
6358 }
6359
6360
6361 table = bgp->rib[afi][safi];
6362
ajs5a646652004-11-05 01:25:55 +00006363 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006364}
6365
paul718e3742002-12-13 20:15:29 +00006366/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006367static void
paul718e3742002-12-13 20:15:29 +00006368route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6369 struct bgp_node *rn,
6370 struct prefix_rd *prd, afi_t afi, safi_t safi)
6371{
6372 struct bgp_info *ri;
6373 struct prefix *p;
6374 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006375 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006376 char buf1[INET6_ADDRSTRLEN];
6377 char buf2[INET6_ADDRSTRLEN];
6378 int count = 0;
6379 int best = 0;
6380 int suppress = 0;
6381 int no_export = 0;
6382 int no_advertise = 0;
6383 int local_as = 0;
6384 int first = 0;
6385
6386 p = &rn->p;
6387 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6388 (safi == SAFI_MPLS_VPN ?
6389 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6390 safi == SAFI_MPLS_VPN ? ":" : "",
6391 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6392 p->prefixlen, VTY_NEWLINE);
6393
6394 for (ri = rn->info; ri; ri = ri->next)
6395 {
6396 count++;
6397 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6398 {
6399 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006400 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006401 suppress = 1;
6402 if (ri->attr->community != NULL)
6403 {
6404 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6405 no_advertise = 1;
6406 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6407 no_export = 1;
6408 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6409 local_as = 1;
6410 }
6411 }
6412 }
6413
6414 vty_out (vty, "Paths: (%d available", count);
6415 if (best)
6416 {
6417 vty_out (vty, ", best #%d", best);
6418 if (safi == SAFI_UNICAST)
6419 vty_out (vty, ", table Default-IP-Routing-Table");
6420 }
6421 else
6422 vty_out (vty, ", no best path");
6423 if (no_advertise)
6424 vty_out (vty, ", not advertised to any peer");
6425 else if (no_export)
6426 vty_out (vty, ", not advertised to EBGP peer");
6427 else if (local_as)
6428 vty_out (vty, ", not advertised outside local AS");
6429 if (suppress)
6430 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6431 vty_out (vty, ")%s", VTY_NEWLINE);
6432
6433 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006434 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006435 {
6436 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6437 {
6438 if (! first)
6439 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6440 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6441 first = 1;
6442 }
6443 }
6444 if (! first)
6445 vty_out (vty, " Not advertised to any peer");
6446 vty_out (vty, "%s", VTY_NEWLINE);
6447}
6448
6449/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006450static int
paulfee0f4c2004-09-13 05:12:46 +00006451bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006452 struct bgp_table *rib, const char *ip_str,
6453 afi_t afi, safi_t safi, struct prefix_rd *prd,
6454 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006455{
6456 int ret;
6457 int header;
6458 int display = 0;
6459 struct prefix match;
6460 struct bgp_node *rn;
6461 struct bgp_node *rm;
6462 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006463 struct bgp_table *table;
6464
paul718e3742002-12-13 20:15:29 +00006465 /* Check IP address argument. */
6466 ret = str2prefix (ip_str, &match);
6467 if (! ret)
6468 {
6469 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6470 return CMD_WARNING;
6471 }
6472
6473 match.family = afi2family (afi);
6474
6475 if (safi == SAFI_MPLS_VPN)
6476 {
paulfee0f4c2004-09-13 05:12:46 +00006477 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006478 {
6479 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6480 continue;
6481
6482 if ((table = rn->info) != NULL)
6483 {
6484 header = 1;
6485
6486 if ((rm = bgp_node_match (table, &match)) != NULL)
6487 {
6488 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006489 {
6490 bgp_unlock_node (rm);
6491 continue;
6492 }
paul718e3742002-12-13 20:15:29 +00006493
6494 for (ri = rm->info; ri; ri = ri->next)
6495 {
6496 if (header)
6497 {
6498 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6499 AFI_IP, SAFI_MPLS_VPN);
6500
6501 header = 0;
6502 }
6503 display++;
6504 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6505 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006506
6507 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006508 }
6509 }
6510 }
6511 }
6512 else
6513 {
6514 header = 1;
6515
paulfee0f4c2004-09-13 05:12:46 +00006516 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006517 {
6518 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6519 {
6520 for (ri = rn->info; ri; ri = ri->next)
6521 {
6522 if (header)
6523 {
6524 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6525 header = 0;
6526 }
6527 display++;
6528 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6529 }
6530 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006531
6532 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006533 }
6534 }
6535
6536 if (! display)
6537 {
6538 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6539 return CMD_WARNING;
6540 }
6541
6542 return CMD_SUCCESS;
6543}
6544
paulfee0f4c2004-09-13 05:12:46 +00006545/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006546static int
paulfd79ac92004-10-13 05:06:08 +00006547bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006548 afi_t afi, safi_t safi, struct prefix_rd *prd,
6549 int prefix_check)
6550{
6551 struct bgp *bgp;
6552
6553 /* BGP structure lookup. */
6554 if (view_name)
6555 {
6556 bgp = bgp_lookup_by_name (view_name);
6557 if (bgp == NULL)
6558 {
6559 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6560 return CMD_WARNING;
6561 }
6562 }
6563 else
6564 {
6565 bgp = bgp_get_default ();
6566 if (bgp == NULL)
6567 {
6568 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6569 return CMD_WARNING;
6570 }
6571 }
6572
6573 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6574 afi, safi, prd, prefix_check);
6575}
6576
paul718e3742002-12-13 20:15:29 +00006577/* BGP route print out function. */
6578DEFUN (show_ip_bgp,
6579 show_ip_bgp_cmd,
6580 "show ip bgp",
6581 SHOW_STR
6582 IP_STR
6583 BGP_STR)
6584{
ajs5a646652004-11-05 01:25:55 +00006585 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006586}
6587
6588DEFUN (show_ip_bgp_ipv4,
6589 show_ip_bgp_ipv4_cmd,
6590 "show ip bgp ipv4 (unicast|multicast)",
6591 SHOW_STR
6592 IP_STR
6593 BGP_STR
6594 "Address family\n"
6595 "Address Family modifier\n"
6596 "Address Family modifier\n")
6597{
6598 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006599 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6600 NULL);
paul718e3742002-12-13 20:15:29 +00006601
ajs5a646652004-11-05 01:25:55 +00006602 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006603}
6604
Michael Lambert95cbbd22010-07-23 14:43:04 -04006605ALIAS (show_ip_bgp_ipv4,
6606 show_bgp_ipv4_safi_cmd,
6607 "show bgp ipv4 (unicast|multicast)",
6608 SHOW_STR
6609 BGP_STR
6610 "Address family\n"
6611 "Address Family modifier\n"
6612 "Address Family modifier\n")
6613
paul718e3742002-12-13 20:15:29 +00006614DEFUN (show_ip_bgp_route,
6615 show_ip_bgp_route_cmd,
6616 "show ip bgp A.B.C.D",
6617 SHOW_STR
6618 IP_STR
6619 BGP_STR
6620 "Network in the BGP routing table to display\n")
6621{
6622 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6623}
6624
6625DEFUN (show_ip_bgp_ipv4_route,
6626 show_ip_bgp_ipv4_route_cmd,
6627 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6628 SHOW_STR
6629 IP_STR
6630 BGP_STR
6631 "Address family\n"
6632 "Address Family modifier\n"
6633 "Address Family modifier\n"
6634 "Network in the BGP routing table to display\n")
6635{
6636 if (strncmp (argv[0], "m", 1) == 0)
6637 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6638
6639 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6640}
6641
Michael Lambert95cbbd22010-07-23 14:43:04 -04006642ALIAS (show_ip_bgp_ipv4_route,
6643 show_bgp_ipv4_safi_route_cmd,
6644 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6645 SHOW_STR
6646 BGP_STR
6647 "Address family\n"
6648 "Address Family modifier\n"
6649 "Address Family modifier\n"
6650 "Network in the BGP routing table to display\n")
6651
paul718e3742002-12-13 20:15:29 +00006652DEFUN (show_ip_bgp_vpnv4_all_route,
6653 show_ip_bgp_vpnv4_all_route_cmd,
6654 "show ip bgp vpnv4 all A.B.C.D",
6655 SHOW_STR
6656 IP_STR
6657 BGP_STR
6658 "Display VPNv4 NLRI specific information\n"
6659 "Display information about all VPNv4 NLRIs\n"
6660 "Network in the BGP routing table to display\n")
6661{
6662 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6663}
6664
6665DEFUN (show_ip_bgp_vpnv4_rd_route,
6666 show_ip_bgp_vpnv4_rd_route_cmd,
6667 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6668 SHOW_STR
6669 IP_STR
6670 BGP_STR
6671 "Display VPNv4 NLRI specific information\n"
6672 "Display information for a route distinguisher\n"
6673 "VPN Route Distinguisher\n"
6674 "Network in the BGP routing table to display\n")
6675{
6676 int ret;
6677 struct prefix_rd prd;
6678
6679 ret = str2prefix_rd (argv[0], &prd);
6680 if (! ret)
6681 {
6682 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6683 return CMD_WARNING;
6684 }
6685 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6686}
6687
6688DEFUN (show_ip_bgp_prefix,
6689 show_ip_bgp_prefix_cmd,
6690 "show ip bgp A.B.C.D/M",
6691 SHOW_STR
6692 IP_STR
6693 BGP_STR
6694 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6695{
6696 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6697}
6698
6699DEFUN (show_ip_bgp_ipv4_prefix,
6700 show_ip_bgp_ipv4_prefix_cmd,
6701 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6702 SHOW_STR
6703 IP_STR
6704 BGP_STR
6705 "Address family\n"
6706 "Address Family modifier\n"
6707 "Address Family modifier\n"
6708 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6709{
6710 if (strncmp (argv[0], "m", 1) == 0)
6711 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6712
6713 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6714}
6715
Michael Lambert95cbbd22010-07-23 14:43:04 -04006716ALIAS (show_ip_bgp_ipv4_prefix,
6717 show_bgp_ipv4_safi_prefix_cmd,
6718 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6719 SHOW_STR
6720 BGP_STR
6721 "Address family\n"
6722 "Address Family modifier\n"
6723 "Address Family modifier\n"
6724 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6725
paul718e3742002-12-13 20:15:29 +00006726DEFUN (show_ip_bgp_vpnv4_all_prefix,
6727 show_ip_bgp_vpnv4_all_prefix_cmd,
6728 "show ip bgp vpnv4 all A.B.C.D/M",
6729 SHOW_STR
6730 IP_STR
6731 BGP_STR
6732 "Display VPNv4 NLRI specific information\n"
6733 "Display information about all VPNv4 NLRIs\n"
6734 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6735{
6736 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6737}
6738
6739DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6740 show_ip_bgp_vpnv4_rd_prefix_cmd,
6741 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6742 SHOW_STR
6743 IP_STR
6744 BGP_STR
6745 "Display VPNv4 NLRI specific information\n"
6746 "Display information for a route distinguisher\n"
6747 "VPN Route Distinguisher\n"
6748 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6749{
6750 int ret;
6751 struct prefix_rd prd;
6752
6753 ret = str2prefix_rd (argv[0], &prd);
6754 if (! ret)
6755 {
6756 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6757 return CMD_WARNING;
6758 }
6759 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6760}
6761
6762DEFUN (show_ip_bgp_view,
6763 show_ip_bgp_view_cmd,
6764 "show ip bgp view WORD",
6765 SHOW_STR
6766 IP_STR
6767 BGP_STR
6768 "BGP view\n"
6769 "BGP view name\n")
6770{
paulbb46e942003-10-24 19:02:03 +00006771 struct bgp *bgp;
6772
6773 /* BGP structure lookup. */
6774 bgp = bgp_lookup_by_name (argv[0]);
6775 if (bgp == NULL)
6776 {
6777 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6778 return CMD_WARNING;
6779 }
6780
ajs5a646652004-11-05 01:25:55 +00006781 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006782}
6783
6784DEFUN (show_ip_bgp_view_route,
6785 show_ip_bgp_view_route_cmd,
6786 "show ip bgp view WORD A.B.C.D",
6787 SHOW_STR
6788 IP_STR
6789 BGP_STR
6790 "BGP view\n"
6791 "BGP view name\n"
6792 "Network in the BGP routing table to display\n")
6793{
6794 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6795}
6796
6797DEFUN (show_ip_bgp_view_prefix,
6798 show_ip_bgp_view_prefix_cmd,
6799 "show ip bgp view WORD A.B.C.D/M",
6800 SHOW_STR
6801 IP_STR
6802 BGP_STR
6803 "BGP view\n"
6804 "BGP view name\n"
6805 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6806{
6807 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6808}
6809
6810#ifdef HAVE_IPV6
6811DEFUN (show_bgp,
6812 show_bgp_cmd,
6813 "show bgp",
6814 SHOW_STR
6815 BGP_STR)
6816{
ajs5a646652004-11-05 01:25:55 +00006817 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6818 NULL);
paul718e3742002-12-13 20:15:29 +00006819}
6820
6821ALIAS (show_bgp,
6822 show_bgp_ipv6_cmd,
6823 "show bgp ipv6",
6824 SHOW_STR
6825 BGP_STR
6826 "Address family\n")
6827
Michael Lambert95cbbd22010-07-23 14:43:04 -04006828DEFUN (show_bgp_ipv6_safi,
6829 show_bgp_ipv6_safi_cmd,
6830 "show bgp ipv6 (unicast|multicast)",
6831 SHOW_STR
6832 BGP_STR
6833 "Address family\n"
6834 "Address Family modifier\n"
6835 "Address Family modifier\n")
6836{
6837 if (strncmp (argv[0], "m", 1) == 0)
6838 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6839 NULL);
6840
6841 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6842}
6843
paul718e3742002-12-13 20:15:29 +00006844/* old command */
6845DEFUN (show_ipv6_bgp,
6846 show_ipv6_bgp_cmd,
6847 "show ipv6 bgp",
6848 SHOW_STR
6849 IP_STR
6850 BGP_STR)
6851{
ajs5a646652004-11-05 01:25:55 +00006852 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6853 NULL);
paul718e3742002-12-13 20:15:29 +00006854}
6855
6856DEFUN (show_bgp_route,
6857 show_bgp_route_cmd,
6858 "show bgp X:X::X:X",
6859 SHOW_STR
6860 BGP_STR
6861 "Network in the BGP routing table to display\n")
6862{
6863 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6864}
6865
6866ALIAS (show_bgp_route,
6867 show_bgp_ipv6_route_cmd,
6868 "show bgp ipv6 X:X::X:X",
6869 SHOW_STR
6870 BGP_STR
6871 "Address family\n"
6872 "Network in the BGP routing table to display\n")
6873
Michael Lambert95cbbd22010-07-23 14:43:04 -04006874DEFUN (show_bgp_ipv6_safi_route,
6875 show_bgp_ipv6_safi_route_cmd,
6876 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6877 SHOW_STR
6878 BGP_STR
6879 "Address family\n"
6880 "Address Family modifier\n"
6881 "Address Family modifier\n"
6882 "Network in the BGP routing table to display\n")
6883{
6884 if (strncmp (argv[0], "m", 1) == 0)
6885 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6886
6887 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6888}
6889
paul718e3742002-12-13 20:15:29 +00006890/* old command */
6891DEFUN (show_ipv6_bgp_route,
6892 show_ipv6_bgp_route_cmd,
6893 "show ipv6 bgp X:X::X:X",
6894 SHOW_STR
6895 IP_STR
6896 BGP_STR
6897 "Network in the BGP routing table to display\n")
6898{
6899 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6900}
6901
6902DEFUN (show_bgp_prefix,
6903 show_bgp_prefix_cmd,
6904 "show bgp X:X::X:X/M",
6905 SHOW_STR
6906 BGP_STR
6907 "IPv6 prefix <network>/<length>\n")
6908{
6909 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6910}
6911
6912ALIAS (show_bgp_prefix,
6913 show_bgp_ipv6_prefix_cmd,
6914 "show bgp ipv6 X:X::X:X/M",
6915 SHOW_STR
6916 BGP_STR
6917 "Address family\n"
6918 "IPv6 prefix <network>/<length>\n")
6919
Michael Lambert95cbbd22010-07-23 14:43:04 -04006920DEFUN (show_bgp_ipv6_safi_prefix,
6921 show_bgp_ipv6_safi_prefix_cmd,
6922 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6923 SHOW_STR
6924 BGP_STR
6925 "Address family\n"
6926 "Address Family modifier\n"
6927 "Address Family modifier\n"
6928 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6929{
6930 if (strncmp (argv[0], "m", 1) == 0)
6931 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6932
6933 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6934}
6935
paul718e3742002-12-13 20:15:29 +00006936/* old command */
6937DEFUN (show_ipv6_bgp_prefix,
6938 show_ipv6_bgp_prefix_cmd,
6939 "show ipv6 bgp X:X::X:X/M",
6940 SHOW_STR
6941 IP_STR
6942 BGP_STR
6943 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6944{
6945 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6946}
6947
paulbb46e942003-10-24 19:02:03 +00006948DEFUN (show_bgp_view,
6949 show_bgp_view_cmd,
6950 "show bgp view WORD",
6951 SHOW_STR
6952 BGP_STR
6953 "BGP view\n"
6954 "View name\n")
6955{
6956 struct bgp *bgp;
6957
6958 /* BGP structure lookup. */
6959 bgp = bgp_lookup_by_name (argv[0]);
6960 if (bgp == NULL)
6961 {
6962 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6963 return CMD_WARNING;
6964 }
6965
ajs5a646652004-11-05 01:25:55 +00006966 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006967}
6968
6969ALIAS (show_bgp_view,
6970 show_bgp_view_ipv6_cmd,
6971 "show bgp view WORD ipv6",
6972 SHOW_STR
6973 BGP_STR
6974 "BGP view\n"
6975 "View name\n"
6976 "Address family\n")
6977
6978DEFUN (show_bgp_view_route,
6979 show_bgp_view_route_cmd,
6980 "show bgp view WORD X:X::X:X",
6981 SHOW_STR
6982 BGP_STR
6983 "BGP view\n"
6984 "View name\n"
6985 "Network in the BGP routing table to display\n")
6986{
6987 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6988}
6989
6990ALIAS (show_bgp_view_route,
6991 show_bgp_view_ipv6_route_cmd,
6992 "show bgp view WORD ipv6 X:X::X:X",
6993 SHOW_STR
6994 BGP_STR
6995 "BGP view\n"
6996 "View name\n"
6997 "Address family\n"
6998 "Network in the BGP routing table to display\n")
6999
7000DEFUN (show_bgp_view_prefix,
7001 show_bgp_view_prefix_cmd,
7002 "show bgp view WORD X:X::X:X/M",
7003 SHOW_STR
7004 BGP_STR
7005 "BGP view\n"
7006 "View name\n"
7007 "IPv6 prefix <network>/<length>\n")
7008{
7009 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7010}
7011
7012ALIAS (show_bgp_view_prefix,
7013 show_bgp_view_ipv6_prefix_cmd,
7014 "show bgp view WORD ipv6 X:X::X:X/M",
7015 SHOW_STR
7016 BGP_STR
7017 "BGP view\n"
7018 "View name\n"
7019 "Address family\n"
7020 "IPv6 prefix <network>/<length>\n")
7021
paul718e3742002-12-13 20:15:29 +00007022/* old command */
7023DEFUN (show_ipv6_mbgp,
7024 show_ipv6_mbgp_cmd,
7025 "show ipv6 mbgp",
7026 SHOW_STR
7027 IP_STR
7028 MBGP_STR)
7029{
ajs5a646652004-11-05 01:25:55 +00007030 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7031 NULL);
paul718e3742002-12-13 20:15:29 +00007032}
7033
7034/* old command */
7035DEFUN (show_ipv6_mbgp_route,
7036 show_ipv6_mbgp_route_cmd,
7037 "show ipv6 mbgp X:X::X:X",
7038 SHOW_STR
7039 IP_STR
7040 MBGP_STR
7041 "Network in the MBGP routing table to display\n")
7042{
7043 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7044}
7045
7046/* old command */
7047DEFUN (show_ipv6_mbgp_prefix,
7048 show_ipv6_mbgp_prefix_cmd,
7049 "show ipv6 mbgp X:X::X:X/M",
7050 SHOW_STR
7051 IP_STR
7052 MBGP_STR
7053 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7054{
7055 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7056}
7057#endif
7058
paul718e3742002-12-13 20:15:29 +00007059
paul94f2b392005-06-28 12:44:16 +00007060static int
paulfd79ac92004-10-13 05:06:08 +00007061bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007062 safi_t safi, enum bgp_show_type type)
7063{
7064 int i;
7065 struct buffer *b;
7066 char *regstr;
7067 int first;
7068 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007069 int rc;
paul718e3742002-12-13 20:15:29 +00007070
7071 first = 0;
7072 b = buffer_new (1024);
7073 for (i = 0; i < argc; i++)
7074 {
7075 if (first)
7076 buffer_putc (b, ' ');
7077 else
7078 {
7079 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7080 continue;
7081 first = 1;
7082 }
7083
7084 buffer_putstr (b, argv[i]);
7085 }
7086 buffer_putc (b, '\0');
7087
7088 regstr = buffer_getstr (b);
7089 buffer_free (b);
7090
7091 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007092 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007093 if (! regex)
7094 {
7095 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7096 VTY_NEWLINE);
7097 return CMD_WARNING;
7098 }
7099
ajs5a646652004-11-05 01:25:55 +00007100 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7101 bgp_regex_free (regex);
7102 return rc;
paul718e3742002-12-13 20:15:29 +00007103}
7104
7105DEFUN (show_ip_bgp_regexp,
7106 show_ip_bgp_regexp_cmd,
7107 "show ip bgp regexp .LINE",
7108 SHOW_STR
7109 IP_STR
7110 BGP_STR
7111 "Display routes matching the AS path regular expression\n"
7112 "A regular-expression to match the BGP AS paths\n")
7113{
7114 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7115 bgp_show_type_regexp);
7116}
7117
7118DEFUN (show_ip_bgp_flap_regexp,
7119 show_ip_bgp_flap_regexp_cmd,
7120 "show ip bgp flap-statistics regexp .LINE",
7121 SHOW_STR
7122 IP_STR
7123 BGP_STR
7124 "Display flap statistics of routes\n"
7125 "Display routes matching the AS path regular expression\n"
7126 "A regular-expression to match the BGP AS paths\n")
7127{
7128 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7129 bgp_show_type_flap_regexp);
7130}
7131
7132DEFUN (show_ip_bgp_ipv4_regexp,
7133 show_ip_bgp_ipv4_regexp_cmd,
7134 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7135 SHOW_STR
7136 IP_STR
7137 BGP_STR
7138 "Address family\n"
7139 "Address Family modifier\n"
7140 "Address Family modifier\n"
7141 "Display routes matching the AS path regular expression\n"
7142 "A regular-expression to match the BGP AS paths\n")
7143{
7144 if (strncmp (argv[0], "m", 1) == 0)
7145 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7146 bgp_show_type_regexp);
7147
7148 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7149 bgp_show_type_regexp);
7150}
7151
7152#ifdef HAVE_IPV6
7153DEFUN (show_bgp_regexp,
7154 show_bgp_regexp_cmd,
7155 "show bgp regexp .LINE",
7156 SHOW_STR
7157 BGP_STR
7158 "Display routes matching the AS path regular expression\n"
7159 "A regular-expression to match the BGP AS paths\n")
7160{
7161 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7162 bgp_show_type_regexp);
7163}
7164
7165ALIAS (show_bgp_regexp,
7166 show_bgp_ipv6_regexp_cmd,
7167 "show bgp ipv6 regexp .LINE",
7168 SHOW_STR
7169 BGP_STR
7170 "Address family\n"
7171 "Display routes matching the AS path regular expression\n"
7172 "A regular-expression to match the BGP AS paths\n")
7173
7174/* old command */
7175DEFUN (show_ipv6_bgp_regexp,
7176 show_ipv6_bgp_regexp_cmd,
7177 "show ipv6 bgp regexp .LINE",
7178 SHOW_STR
7179 IP_STR
7180 BGP_STR
7181 "Display routes matching the AS path regular expression\n"
7182 "A regular-expression to match the BGP AS paths\n")
7183{
7184 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7185 bgp_show_type_regexp);
7186}
7187
7188/* old command */
7189DEFUN (show_ipv6_mbgp_regexp,
7190 show_ipv6_mbgp_regexp_cmd,
7191 "show ipv6 mbgp regexp .LINE",
7192 SHOW_STR
7193 IP_STR
7194 BGP_STR
7195 "Display routes matching the AS path regular expression\n"
7196 "A regular-expression to match the MBGP AS paths\n")
7197{
7198 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7199 bgp_show_type_regexp);
7200}
7201#endif /* HAVE_IPV6 */
7202
paul94f2b392005-06-28 12:44:16 +00007203static int
paulfd79ac92004-10-13 05:06:08 +00007204bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007205 safi_t safi, enum bgp_show_type type)
7206{
7207 struct prefix_list *plist;
7208
7209 plist = prefix_list_lookup (afi, prefix_list_str);
7210 if (plist == NULL)
7211 {
7212 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7213 prefix_list_str, VTY_NEWLINE);
7214 return CMD_WARNING;
7215 }
7216
ajs5a646652004-11-05 01:25:55 +00007217 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007218}
7219
7220DEFUN (show_ip_bgp_prefix_list,
7221 show_ip_bgp_prefix_list_cmd,
7222 "show ip bgp prefix-list WORD",
7223 SHOW_STR
7224 IP_STR
7225 BGP_STR
7226 "Display routes conforming to the prefix-list\n"
7227 "IP prefix-list name\n")
7228{
7229 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7230 bgp_show_type_prefix_list);
7231}
7232
7233DEFUN (show_ip_bgp_flap_prefix_list,
7234 show_ip_bgp_flap_prefix_list_cmd,
7235 "show ip bgp flap-statistics prefix-list WORD",
7236 SHOW_STR
7237 IP_STR
7238 BGP_STR
7239 "Display flap statistics of routes\n"
7240 "Display routes conforming to the prefix-list\n"
7241 "IP prefix-list name\n")
7242{
7243 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7244 bgp_show_type_flap_prefix_list);
7245}
7246
7247DEFUN (show_ip_bgp_ipv4_prefix_list,
7248 show_ip_bgp_ipv4_prefix_list_cmd,
7249 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7250 SHOW_STR
7251 IP_STR
7252 BGP_STR
7253 "Address family\n"
7254 "Address Family modifier\n"
7255 "Address Family modifier\n"
7256 "Display routes conforming to the prefix-list\n"
7257 "IP prefix-list name\n")
7258{
7259 if (strncmp (argv[0], "m", 1) == 0)
7260 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7261 bgp_show_type_prefix_list);
7262
7263 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7264 bgp_show_type_prefix_list);
7265}
7266
7267#ifdef HAVE_IPV6
7268DEFUN (show_bgp_prefix_list,
7269 show_bgp_prefix_list_cmd,
7270 "show bgp prefix-list WORD",
7271 SHOW_STR
7272 BGP_STR
7273 "Display routes conforming to the prefix-list\n"
7274 "IPv6 prefix-list name\n")
7275{
7276 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7277 bgp_show_type_prefix_list);
7278}
7279
7280ALIAS (show_bgp_prefix_list,
7281 show_bgp_ipv6_prefix_list_cmd,
7282 "show bgp ipv6 prefix-list WORD",
7283 SHOW_STR
7284 BGP_STR
7285 "Address family\n"
7286 "Display routes conforming to the prefix-list\n"
7287 "IPv6 prefix-list name\n")
7288
7289/* old command */
7290DEFUN (show_ipv6_bgp_prefix_list,
7291 show_ipv6_bgp_prefix_list_cmd,
7292 "show ipv6 bgp prefix-list WORD",
7293 SHOW_STR
7294 IPV6_STR
7295 BGP_STR
7296 "Display routes matching the prefix-list\n"
7297 "IPv6 prefix-list name\n")
7298{
7299 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7300 bgp_show_type_prefix_list);
7301}
7302
7303/* old command */
7304DEFUN (show_ipv6_mbgp_prefix_list,
7305 show_ipv6_mbgp_prefix_list_cmd,
7306 "show ipv6 mbgp prefix-list WORD",
7307 SHOW_STR
7308 IPV6_STR
7309 MBGP_STR
7310 "Display routes matching the prefix-list\n"
7311 "IPv6 prefix-list name\n")
7312{
7313 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7314 bgp_show_type_prefix_list);
7315}
7316#endif /* HAVE_IPV6 */
7317
paul94f2b392005-06-28 12:44:16 +00007318static int
paulfd79ac92004-10-13 05:06:08 +00007319bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007320 safi_t safi, enum bgp_show_type type)
7321{
7322 struct as_list *as_list;
7323
7324 as_list = as_list_lookup (filter);
7325 if (as_list == NULL)
7326 {
7327 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7328 return CMD_WARNING;
7329 }
7330
ajs5a646652004-11-05 01:25:55 +00007331 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007332}
7333
7334DEFUN (show_ip_bgp_filter_list,
7335 show_ip_bgp_filter_list_cmd,
7336 "show ip bgp filter-list WORD",
7337 SHOW_STR
7338 IP_STR
7339 BGP_STR
7340 "Display routes conforming to the filter-list\n"
7341 "Regular expression access list name\n")
7342{
7343 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7344 bgp_show_type_filter_list);
7345}
7346
7347DEFUN (show_ip_bgp_flap_filter_list,
7348 show_ip_bgp_flap_filter_list_cmd,
7349 "show ip bgp flap-statistics filter-list WORD",
7350 SHOW_STR
7351 IP_STR
7352 BGP_STR
7353 "Display flap statistics of routes\n"
7354 "Display routes conforming to the filter-list\n"
7355 "Regular expression access list name\n")
7356{
7357 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7358 bgp_show_type_flap_filter_list);
7359}
7360
7361DEFUN (show_ip_bgp_ipv4_filter_list,
7362 show_ip_bgp_ipv4_filter_list_cmd,
7363 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7364 SHOW_STR
7365 IP_STR
7366 BGP_STR
7367 "Address family\n"
7368 "Address Family modifier\n"
7369 "Address Family modifier\n"
7370 "Display routes conforming to the filter-list\n"
7371 "Regular expression access list name\n")
7372{
7373 if (strncmp (argv[0], "m", 1) == 0)
7374 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7375 bgp_show_type_filter_list);
7376
7377 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7378 bgp_show_type_filter_list);
7379}
7380
7381#ifdef HAVE_IPV6
7382DEFUN (show_bgp_filter_list,
7383 show_bgp_filter_list_cmd,
7384 "show bgp filter-list WORD",
7385 SHOW_STR
7386 BGP_STR
7387 "Display routes conforming to the filter-list\n"
7388 "Regular expression access list name\n")
7389{
7390 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7391 bgp_show_type_filter_list);
7392}
7393
7394ALIAS (show_bgp_filter_list,
7395 show_bgp_ipv6_filter_list_cmd,
7396 "show bgp ipv6 filter-list WORD",
7397 SHOW_STR
7398 BGP_STR
7399 "Address family\n"
7400 "Display routes conforming to the filter-list\n"
7401 "Regular expression access list name\n")
7402
7403/* old command */
7404DEFUN (show_ipv6_bgp_filter_list,
7405 show_ipv6_bgp_filter_list_cmd,
7406 "show ipv6 bgp filter-list WORD",
7407 SHOW_STR
7408 IPV6_STR
7409 BGP_STR
7410 "Display routes conforming to the filter-list\n"
7411 "Regular expression access list name\n")
7412{
7413 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7414 bgp_show_type_filter_list);
7415}
7416
7417/* old command */
7418DEFUN (show_ipv6_mbgp_filter_list,
7419 show_ipv6_mbgp_filter_list_cmd,
7420 "show ipv6 mbgp filter-list WORD",
7421 SHOW_STR
7422 IPV6_STR
7423 MBGP_STR
7424 "Display routes conforming to the filter-list\n"
7425 "Regular expression access list name\n")
7426{
7427 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7428 bgp_show_type_filter_list);
7429}
7430#endif /* HAVE_IPV6 */
7431
paul94f2b392005-06-28 12:44:16 +00007432static int
paulfd79ac92004-10-13 05:06:08 +00007433bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007434 safi_t safi, enum bgp_show_type type)
7435{
7436 struct route_map *rmap;
7437
7438 rmap = route_map_lookup_by_name (rmap_str);
7439 if (! rmap)
7440 {
7441 vty_out (vty, "%% %s is not a valid route-map name%s",
7442 rmap_str, VTY_NEWLINE);
7443 return CMD_WARNING;
7444 }
7445
ajs5a646652004-11-05 01:25:55 +00007446 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007447}
7448
7449DEFUN (show_ip_bgp_route_map,
7450 show_ip_bgp_route_map_cmd,
7451 "show ip bgp route-map WORD",
7452 SHOW_STR
7453 IP_STR
7454 BGP_STR
7455 "Display routes matching the route-map\n"
7456 "A route-map to match on\n")
7457{
7458 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7459 bgp_show_type_route_map);
7460}
7461
7462DEFUN (show_ip_bgp_flap_route_map,
7463 show_ip_bgp_flap_route_map_cmd,
7464 "show ip bgp flap-statistics route-map WORD",
7465 SHOW_STR
7466 IP_STR
7467 BGP_STR
7468 "Display flap statistics of routes\n"
7469 "Display routes matching the route-map\n"
7470 "A route-map to match on\n")
7471{
7472 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7473 bgp_show_type_flap_route_map);
7474}
7475
7476DEFUN (show_ip_bgp_ipv4_route_map,
7477 show_ip_bgp_ipv4_route_map_cmd,
7478 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7479 SHOW_STR
7480 IP_STR
7481 BGP_STR
7482 "Address family\n"
7483 "Address Family modifier\n"
7484 "Address Family modifier\n"
7485 "Display routes matching the route-map\n"
7486 "A route-map to match on\n")
7487{
7488 if (strncmp (argv[0], "m", 1) == 0)
7489 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7490 bgp_show_type_route_map);
7491
7492 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7493 bgp_show_type_route_map);
7494}
7495
7496DEFUN (show_bgp_route_map,
7497 show_bgp_route_map_cmd,
7498 "show bgp route-map WORD",
7499 SHOW_STR
7500 BGP_STR
7501 "Display routes matching the route-map\n"
7502 "A route-map to match on\n")
7503{
7504 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7505 bgp_show_type_route_map);
7506}
7507
7508ALIAS (show_bgp_route_map,
7509 show_bgp_ipv6_route_map_cmd,
7510 "show bgp ipv6 route-map WORD",
7511 SHOW_STR
7512 BGP_STR
7513 "Address family\n"
7514 "Display routes matching the route-map\n"
7515 "A route-map to match on\n")
7516
7517DEFUN (show_ip_bgp_cidr_only,
7518 show_ip_bgp_cidr_only_cmd,
7519 "show ip bgp cidr-only",
7520 SHOW_STR
7521 IP_STR
7522 BGP_STR
7523 "Display only routes with non-natural netmasks\n")
7524{
7525 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007526 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007527}
7528
7529DEFUN (show_ip_bgp_flap_cidr_only,
7530 show_ip_bgp_flap_cidr_only_cmd,
7531 "show ip bgp flap-statistics cidr-only",
7532 SHOW_STR
7533 IP_STR
7534 BGP_STR
7535 "Display flap statistics of routes\n"
7536 "Display only routes with non-natural netmasks\n")
7537{
7538 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007539 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007540}
7541
7542DEFUN (show_ip_bgp_ipv4_cidr_only,
7543 show_ip_bgp_ipv4_cidr_only_cmd,
7544 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7545 SHOW_STR
7546 IP_STR
7547 BGP_STR
7548 "Address family\n"
7549 "Address Family modifier\n"
7550 "Address Family modifier\n"
7551 "Display only routes with non-natural netmasks\n")
7552{
7553 if (strncmp (argv[0], "m", 1) == 0)
7554 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007555 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007556
7557 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007558 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007559}
7560
7561DEFUN (show_ip_bgp_community_all,
7562 show_ip_bgp_community_all_cmd,
7563 "show ip bgp community",
7564 SHOW_STR
7565 IP_STR
7566 BGP_STR
7567 "Display routes matching the communities\n")
7568{
7569 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007570 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007571}
7572
7573DEFUN (show_ip_bgp_ipv4_community_all,
7574 show_ip_bgp_ipv4_community_all_cmd,
7575 "show ip bgp ipv4 (unicast|multicast) community",
7576 SHOW_STR
7577 IP_STR
7578 BGP_STR
7579 "Address family\n"
7580 "Address Family modifier\n"
7581 "Address Family modifier\n"
7582 "Display routes matching the communities\n")
7583{
7584 if (strncmp (argv[0], "m", 1) == 0)
7585 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007586 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007587
7588 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007589 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007590}
7591
7592#ifdef HAVE_IPV6
7593DEFUN (show_bgp_community_all,
7594 show_bgp_community_all_cmd,
7595 "show bgp community",
7596 SHOW_STR
7597 BGP_STR
7598 "Display routes matching the communities\n")
7599{
7600 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007601 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007602}
7603
7604ALIAS (show_bgp_community_all,
7605 show_bgp_ipv6_community_all_cmd,
7606 "show bgp ipv6 community",
7607 SHOW_STR
7608 BGP_STR
7609 "Address family\n"
7610 "Display routes matching the communities\n")
7611
7612/* old command */
7613DEFUN (show_ipv6_bgp_community_all,
7614 show_ipv6_bgp_community_all_cmd,
7615 "show ipv6 bgp community",
7616 SHOW_STR
7617 IPV6_STR
7618 BGP_STR
7619 "Display routes matching the communities\n")
7620{
7621 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007622 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007623}
7624
7625/* old command */
7626DEFUN (show_ipv6_mbgp_community_all,
7627 show_ipv6_mbgp_community_all_cmd,
7628 "show ipv6 mbgp community",
7629 SHOW_STR
7630 IPV6_STR
7631 MBGP_STR
7632 "Display routes matching the communities\n")
7633{
7634 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007635 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007636}
7637#endif /* HAVE_IPV6 */
7638
paul94f2b392005-06-28 12:44:16 +00007639static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007640bgp_show_community (struct vty *vty, const char *view_name, int argc,
7641 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007642{
7643 struct community *com;
7644 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007645 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007646 int i;
7647 char *str;
7648 int first = 0;
7649
Michael Lambert95cbbd22010-07-23 14:43:04 -04007650 /* BGP structure lookup */
7651 if (view_name)
7652 {
7653 bgp = bgp_lookup_by_name (view_name);
7654 if (bgp == NULL)
7655 {
7656 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7657 return CMD_WARNING;
7658 }
7659 }
7660 else
7661 {
7662 bgp = bgp_get_default ();
7663 if (bgp == NULL)
7664 {
7665 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7666 return CMD_WARNING;
7667 }
7668 }
7669
paul718e3742002-12-13 20:15:29 +00007670 b = buffer_new (1024);
7671 for (i = 0; i < argc; i++)
7672 {
7673 if (first)
7674 buffer_putc (b, ' ');
7675 else
7676 {
7677 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7678 continue;
7679 first = 1;
7680 }
7681
7682 buffer_putstr (b, argv[i]);
7683 }
7684 buffer_putc (b, '\0');
7685
7686 str = buffer_getstr (b);
7687 buffer_free (b);
7688
7689 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007690 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007691 if (! com)
7692 {
7693 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7694 return CMD_WARNING;
7695 }
7696
Michael Lambert95cbbd22010-07-23 14:43:04 -04007697 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007698 (exact ? bgp_show_type_community_exact :
7699 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007700}
7701
7702DEFUN (show_ip_bgp_community,
7703 show_ip_bgp_community_cmd,
7704 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7705 SHOW_STR
7706 IP_STR
7707 BGP_STR
7708 "Display routes matching the communities\n"
7709 "community number\n"
7710 "Do not send outside local AS (well-known community)\n"
7711 "Do not advertise to any peer (well-known community)\n"
7712 "Do not export to next AS (well-known community)\n")
7713{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007714 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007715}
7716
7717ALIAS (show_ip_bgp_community,
7718 show_ip_bgp_community2_cmd,
7719 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7720 SHOW_STR
7721 IP_STR
7722 BGP_STR
7723 "Display routes matching the communities\n"
7724 "community number\n"
7725 "Do not send outside local AS (well-known community)\n"
7726 "Do not advertise to any peer (well-known community)\n"
7727 "Do not export to next AS (well-known community)\n"
7728 "community number\n"
7729 "Do not send outside local AS (well-known community)\n"
7730 "Do not advertise to any peer (well-known community)\n"
7731 "Do not export to next AS (well-known community)\n")
7732
7733ALIAS (show_ip_bgp_community,
7734 show_ip_bgp_community3_cmd,
7735 "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)",
7736 SHOW_STR
7737 IP_STR
7738 BGP_STR
7739 "Display routes matching the communities\n"
7740 "community number\n"
7741 "Do not send outside local AS (well-known community)\n"
7742 "Do not advertise to any peer (well-known community)\n"
7743 "Do not export to next AS (well-known community)\n"
7744 "community number\n"
7745 "Do not send outside local AS (well-known community)\n"
7746 "Do not advertise to any peer (well-known community)\n"
7747 "Do not export to next AS (well-known community)\n"
7748 "community number\n"
7749 "Do not send outside local AS (well-known community)\n"
7750 "Do not advertise to any peer (well-known community)\n"
7751 "Do not export to next AS (well-known community)\n")
7752
7753ALIAS (show_ip_bgp_community,
7754 show_ip_bgp_community4_cmd,
7755 "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)",
7756 SHOW_STR
7757 IP_STR
7758 BGP_STR
7759 "Display routes matching the communities\n"
7760 "community number\n"
7761 "Do not send outside local AS (well-known community)\n"
7762 "Do not advertise to any peer (well-known community)\n"
7763 "Do not export to next AS (well-known community)\n"
7764 "community number\n"
7765 "Do not send outside local AS (well-known community)\n"
7766 "Do not advertise to any peer (well-known community)\n"
7767 "Do not export to next AS (well-known community)\n"
7768 "community number\n"
7769 "Do not send outside local AS (well-known community)\n"
7770 "Do not advertise to any peer (well-known community)\n"
7771 "Do not export to next AS (well-known community)\n"
7772 "community number\n"
7773 "Do not send outside local AS (well-known community)\n"
7774 "Do not advertise to any peer (well-known community)\n"
7775 "Do not export to next AS (well-known community)\n")
7776
7777DEFUN (show_ip_bgp_ipv4_community,
7778 show_ip_bgp_ipv4_community_cmd,
7779 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7780 SHOW_STR
7781 IP_STR
7782 BGP_STR
7783 "Address family\n"
7784 "Address Family modifier\n"
7785 "Address Family modifier\n"
7786 "Display routes matching the communities\n"
7787 "community number\n"
7788 "Do not send outside local AS (well-known community)\n"
7789 "Do not advertise to any peer (well-known community)\n"
7790 "Do not export to next AS (well-known community)\n")
7791{
7792 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007793 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007794
Michael Lambert95cbbd22010-07-23 14:43:04 -04007795 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007796}
7797
7798ALIAS (show_ip_bgp_ipv4_community,
7799 show_ip_bgp_ipv4_community2_cmd,
7800 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7801 SHOW_STR
7802 IP_STR
7803 BGP_STR
7804 "Address family\n"
7805 "Address Family modifier\n"
7806 "Address Family modifier\n"
7807 "Display routes matching the communities\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n")
7816
7817ALIAS (show_ip_bgp_ipv4_community,
7818 show_ip_bgp_ipv4_community3_cmd,
7819 "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)",
7820 SHOW_STR
7821 IP_STR
7822 BGP_STR
7823 "Address family\n"
7824 "Address Family modifier\n"
7825 "Address Family modifier\n"
7826 "Display routes matching the communities\n"
7827 "community number\n"
7828 "Do not send outside local AS (well-known community)\n"
7829 "Do not advertise to any peer (well-known community)\n"
7830 "Do not export to next AS (well-known community)\n"
7831 "community number\n"
7832 "Do not send outside local AS (well-known community)\n"
7833 "Do not advertise to any peer (well-known community)\n"
7834 "Do not export to next AS (well-known community)\n"
7835 "community number\n"
7836 "Do not send outside local AS (well-known community)\n"
7837 "Do not advertise to any peer (well-known community)\n"
7838 "Do not export to next AS (well-known community)\n")
7839
7840ALIAS (show_ip_bgp_ipv4_community,
7841 show_ip_bgp_ipv4_community4_cmd,
7842 "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)",
7843 SHOW_STR
7844 IP_STR
7845 BGP_STR
7846 "Address family\n"
7847 "Address Family modifier\n"
7848 "Address Family modifier\n"
7849 "Display routes matching the communities\n"
7850 "community number\n"
7851 "Do not send outside local AS (well-known community)\n"
7852 "Do not advertise to any peer (well-known community)\n"
7853 "Do not export to next AS (well-known community)\n"
7854 "community number\n"
7855 "Do not send outside local AS (well-known community)\n"
7856 "Do not advertise to any peer (well-known community)\n"
7857 "Do not export to next AS (well-known community)\n"
7858 "community number\n"
7859 "Do not send outside local AS (well-known community)\n"
7860 "Do not advertise to any peer (well-known community)\n"
7861 "Do not export to next AS (well-known community)\n"
7862 "community number\n"
7863 "Do not send outside local AS (well-known community)\n"
7864 "Do not advertise to any peer (well-known community)\n"
7865 "Do not export to next AS (well-known community)\n")
7866
Michael Lambert95cbbd22010-07-23 14:43:04 -04007867DEFUN (show_bgp_view_afi_safi_community_all,
7868 show_bgp_view_afi_safi_community_all_cmd,
7869#ifdef HAVE_IPV6
7870 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7871#else
7872 "show bgp view WORD ipv4 (unicast|multicast) community",
7873#endif
7874 SHOW_STR
7875 BGP_STR
7876 "BGP view\n"
7877 "BGP view name\n"
7878 "Address family\n"
7879#ifdef HAVE_IPV6
7880 "Address family\n"
7881#endif
7882 "Address Family modifier\n"
7883 "Address Family modifier\n"
7884 "Display routes containing communities\n")
7885{
7886 int afi;
7887 int safi;
7888 struct bgp *bgp;
7889
7890 /* BGP structure lookup. */
7891 bgp = bgp_lookup_by_name (argv[0]);
7892 if (bgp == NULL)
7893 {
7894 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7895 return CMD_WARNING;
7896 }
7897
7898#ifdef HAVE_IPV6
7899 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7900 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7901#else
7902 afi = AFI_IP;
7903 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7904#endif
7905 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7906}
7907
7908DEFUN (show_bgp_view_afi_safi_community,
7909 show_bgp_view_afi_safi_community_cmd,
7910#ifdef HAVE_IPV6
7911 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7912#else
7913 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7914#endif
7915 SHOW_STR
7916 BGP_STR
7917 "BGP view\n"
7918 "BGP view name\n"
7919 "Address family\n"
7920#ifdef HAVE_IPV6
7921 "Address family\n"
7922#endif
7923 "Address family modifier\n"
7924 "Address family modifier\n"
7925 "Display routes matching the communities\n"
7926 "community number\n"
7927 "Do not send outside local AS (well-known community)\n"
7928 "Do not advertise to any peer (well-known community)\n"
7929 "Do not export to next AS (well-known community)\n")
7930{
7931 int afi;
7932 int safi;
7933
7934#ifdef HAVE_IPV6
7935 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7936 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7937 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7938#else
7939 afi = AFI_IP;
7940 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7941 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7942#endif
7943}
7944
7945ALIAS (show_bgp_view_afi_safi_community,
7946 show_bgp_view_afi_safi_community2_cmd,
7947#ifdef HAVE_IPV6
7948 "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)",
7949#else
7950 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7951#endif
7952 SHOW_STR
7953 BGP_STR
7954 "BGP view\n"
7955 "BGP view name\n"
7956 "Address family\n"
7957#ifdef HAVE_IPV6
7958 "Address family\n"
7959#endif
7960 "Address family modifier\n"
7961 "Address family modifier\n"
7962 "Display routes matching the communities\n"
7963 "community number\n"
7964 "Do not send outside local AS (well-known community)\n"
7965 "Do not advertise to any peer (well-known community)\n"
7966 "Do not export to next AS (well-known community)\n"
7967 "community number\n"
7968 "Do not send outside local AS (well-known community)\n"
7969 "Do not advertise to any peer (well-known community)\n"
7970 "Do not export to next AS (well-known community)\n")
7971
7972ALIAS (show_bgp_view_afi_safi_community,
7973 show_bgp_view_afi_safi_community3_cmd,
7974#ifdef HAVE_IPV6
7975 "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)",
7976#else
7977 "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)",
7978#endif
7979 SHOW_STR
7980 BGP_STR
7981 "BGP view\n"
7982 "BGP view name\n"
7983 "Address family\n"
7984#ifdef HAVE_IPV6
7985 "Address family\n"
7986#endif
7987 "Address family modifier\n"
7988 "Address family modifier\n"
7989 "Display routes matching the communities\n"
7990 "community number\n"
7991 "Do not send outside local AS (well-known community)\n"
7992 "Do not advertise to any peer (well-known community)\n"
7993 "Do not export to next AS (well-known community)\n"
7994 "community number\n"
7995 "Do not send outside local AS (well-known community)\n"
7996 "Do not advertise to any peer (well-known community)\n"
7997 "Do not export to next AS (well-known community)\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n")
8002
8003ALIAS (show_bgp_view_afi_safi_community,
8004 show_bgp_view_afi_safi_community4_cmd,
8005#ifdef HAVE_IPV6
8006 "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)",
8007#else
8008 "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)",
8009#endif
8010 SHOW_STR
8011 BGP_STR
8012 "BGP view\n"
8013 "BGP view name\n"
8014 "Address family\n"
8015#ifdef HAVE_IPV6
8016 "Address family\n"
8017#endif
8018 "Address family modifier\n"
8019 "Address family modifier\n"
8020 "Display routes matching the communities\n"
8021 "community number\n"
8022 "Do not send outside local AS (well-known community)\n"
8023 "Do not advertise to any peer (well-known community)\n"
8024 "Do not export to next AS (well-known community)\n"
8025 "community number\n"
8026 "Do not send outside local AS (well-known community)\n"
8027 "Do not advertise to any peer (well-known community)\n"
8028 "Do not export to next AS (well-known community)\n"
8029 "community number\n"
8030 "Do not send outside local AS (well-known community)\n"
8031 "Do not advertise to any peer (well-known community)\n"
8032 "Do not export to next AS (well-known community)\n"
8033 "community number\n"
8034 "Do not send outside local AS (well-known community)\n"
8035 "Do not advertise to any peer (well-known community)\n"
8036 "Do not export to next AS (well-known community)\n")
8037
paul718e3742002-12-13 20:15:29 +00008038DEFUN (show_ip_bgp_community_exact,
8039 show_ip_bgp_community_exact_cmd,
8040 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8041 SHOW_STR
8042 IP_STR
8043 BGP_STR
8044 "Display routes matching the communities\n"
8045 "community number\n"
8046 "Do not send outside local AS (well-known community)\n"
8047 "Do not advertise to any peer (well-known community)\n"
8048 "Do not export to next AS (well-known community)\n"
8049 "Exact match of the communities")
8050{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008051 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008052}
8053
8054ALIAS (show_ip_bgp_community_exact,
8055 show_ip_bgp_community2_exact_cmd,
8056 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8057 SHOW_STR
8058 IP_STR
8059 BGP_STR
8060 "Display routes matching the communities\n"
8061 "community number\n"
8062 "Do not send outside local AS (well-known community)\n"
8063 "Do not advertise to any peer (well-known community)\n"
8064 "Do not export to next AS (well-known community)\n"
8065 "community number\n"
8066 "Do not send outside local AS (well-known community)\n"
8067 "Do not advertise to any peer (well-known community)\n"
8068 "Do not export to next AS (well-known community)\n"
8069 "Exact match of the communities")
8070
8071ALIAS (show_ip_bgp_community_exact,
8072 show_ip_bgp_community3_exact_cmd,
8073 "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",
8074 SHOW_STR
8075 IP_STR
8076 BGP_STR
8077 "Display routes matching the communities\n"
8078 "community number\n"
8079 "Do not send outside local AS (well-known community)\n"
8080 "Do not advertise to any peer (well-known community)\n"
8081 "Do not export to next AS (well-known community)\n"
8082 "community number\n"
8083 "Do not send outside local AS (well-known community)\n"
8084 "Do not advertise to any peer (well-known community)\n"
8085 "Do not export to next AS (well-known community)\n"
8086 "community number\n"
8087 "Do not send outside local AS (well-known community)\n"
8088 "Do not advertise to any peer (well-known community)\n"
8089 "Do not export to next AS (well-known community)\n"
8090 "Exact match of the communities")
8091
8092ALIAS (show_ip_bgp_community_exact,
8093 show_ip_bgp_community4_exact_cmd,
8094 "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",
8095 SHOW_STR
8096 IP_STR
8097 BGP_STR
8098 "Display routes matching the communities\n"
8099 "community number\n"
8100 "Do not send outside local AS (well-known community)\n"
8101 "Do not advertise to any peer (well-known community)\n"
8102 "Do not export to next AS (well-known community)\n"
8103 "community number\n"
8104 "Do not send outside local AS (well-known community)\n"
8105 "Do not advertise to any peer (well-known community)\n"
8106 "Do not export to next AS (well-known community)\n"
8107 "community number\n"
8108 "Do not send outside local AS (well-known community)\n"
8109 "Do not advertise to any peer (well-known community)\n"
8110 "Do not export to next AS (well-known community)\n"
8111 "community number\n"
8112 "Do not send outside local AS (well-known community)\n"
8113 "Do not advertise to any peer (well-known community)\n"
8114 "Do not export to next AS (well-known community)\n"
8115 "Exact match of the communities")
8116
8117DEFUN (show_ip_bgp_ipv4_community_exact,
8118 show_ip_bgp_ipv4_community_exact_cmd,
8119 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8120 SHOW_STR
8121 IP_STR
8122 BGP_STR
8123 "Address family\n"
8124 "Address Family modifier\n"
8125 "Address Family modifier\n"
8126 "Display routes matching the communities\n"
8127 "community number\n"
8128 "Do not send outside local AS (well-known community)\n"
8129 "Do not advertise to any peer (well-known community)\n"
8130 "Do not export to next AS (well-known community)\n"
8131 "Exact match of the communities")
8132{
8133 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008134 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008135
Michael Lambert95cbbd22010-07-23 14:43:04 -04008136 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008137}
8138
8139ALIAS (show_ip_bgp_ipv4_community_exact,
8140 show_ip_bgp_ipv4_community2_exact_cmd,
8141 "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",
8142 SHOW_STR
8143 IP_STR
8144 BGP_STR
8145 "Address family\n"
8146 "Address Family modifier\n"
8147 "Address Family modifier\n"
8148 "Display routes matching the communities\n"
8149 "community number\n"
8150 "Do not send outside local AS (well-known community)\n"
8151 "Do not advertise to any peer (well-known community)\n"
8152 "Do not export to next AS (well-known community)\n"
8153 "community number\n"
8154 "Do not send outside local AS (well-known community)\n"
8155 "Do not advertise to any peer (well-known community)\n"
8156 "Do not export to next AS (well-known community)\n"
8157 "Exact match of the communities")
8158
8159ALIAS (show_ip_bgp_ipv4_community_exact,
8160 show_ip_bgp_ipv4_community3_exact_cmd,
8161 "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",
8162 SHOW_STR
8163 IP_STR
8164 BGP_STR
8165 "Address family\n"
8166 "Address Family modifier\n"
8167 "Address Family modifier\n"
8168 "Display routes matching the communities\n"
8169 "community number\n"
8170 "Do not send outside local AS (well-known community)\n"
8171 "Do not advertise to any peer (well-known community)\n"
8172 "Do not export to next AS (well-known community)\n"
8173 "community number\n"
8174 "Do not send outside local AS (well-known community)\n"
8175 "Do not advertise to any peer (well-known community)\n"
8176 "Do not export to next AS (well-known community)\n"
8177 "community number\n"
8178 "Do not send outside local AS (well-known community)\n"
8179 "Do not advertise to any peer (well-known community)\n"
8180 "Do not export to next AS (well-known community)\n"
8181 "Exact match of the communities")
8182
8183ALIAS (show_ip_bgp_ipv4_community_exact,
8184 show_ip_bgp_ipv4_community4_exact_cmd,
8185 "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",
8186 SHOW_STR
8187 IP_STR
8188 BGP_STR
8189 "Address family\n"
8190 "Address Family modifier\n"
8191 "Address Family modifier\n"
8192 "Display routes matching the communities\n"
8193 "community number\n"
8194 "Do not send outside local AS (well-known community)\n"
8195 "Do not advertise to any peer (well-known community)\n"
8196 "Do not export to next AS (well-known community)\n"
8197 "community number\n"
8198 "Do not send outside local AS (well-known community)\n"
8199 "Do not advertise to any peer (well-known community)\n"
8200 "Do not export to next AS (well-known community)\n"
8201 "community number\n"
8202 "Do not send outside local AS (well-known community)\n"
8203 "Do not advertise to any peer (well-known community)\n"
8204 "Do not export to next AS (well-known community)\n"
8205 "community number\n"
8206 "Do not send outside local AS (well-known community)\n"
8207 "Do not advertise to any peer (well-known community)\n"
8208 "Do not export to next AS (well-known community)\n"
8209 "Exact match of the communities")
8210
8211#ifdef HAVE_IPV6
8212DEFUN (show_bgp_community,
8213 show_bgp_community_cmd,
8214 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8215 SHOW_STR
8216 BGP_STR
8217 "Display routes matching the communities\n"
8218 "community number\n"
8219 "Do not send outside local AS (well-known community)\n"
8220 "Do not advertise to any peer (well-known community)\n"
8221 "Do not export to next AS (well-known community)\n")
8222{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008223 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008224}
8225
8226ALIAS (show_bgp_community,
8227 show_bgp_ipv6_community_cmd,
8228 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8229 SHOW_STR
8230 BGP_STR
8231 "Address family\n"
8232 "Display routes matching the communities\n"
8233 "community number\n"
8234 "Do not send outside local AS (well-known community)\n"
8235 "Do not advertise to any peer (well-known community)\n"
8236 "Do not export to next AS (well-known community)\n")
8237
8238ALIAS (show_bgp_community,
8239 show_bgp_community2_cmd,
8240 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8241 SHOW_STR
8242 BGP_STR
8243 "Display routes matching the communities\n"
8244 "community number\n"
8245 "Do not send outside local AS (well-known community)\n"
8246 "Do not advertise to any peer (well-known community)\n"
8247 "Do not export to next AS (well-known community)\n"
8248 "community number\n"
8249 "Do not send outside local AS (well-known community)\n"
8250 "Do not advertise to any peer (well-known community)\n"
8251 "Do not export to next AS (well-known community)\n")
8252
8253ALIAS (show_bgp_community,
8254 show_bgp_ipv6_community2_cmd,
8255 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8256 SHOW_STR
8257 BGP_STR
8258 "Address family\n"
8259 "Display routes matching the communities\n"
8260 "community number\n"
8261 "Do not send outside local AS (well-known community)\n"
8262 "Do not advertise to any peer (well-known community)\n"
8263 "Do not export to next AS (well-known community)\n"
8264 "community number\n"
8265 "Do not send outside local AS (well-known community)\n"
8266 "Do not advertise to any peer (well-known community)\n"
8267 "Do not export to next AS (well-known community)\n")
8268
8269ALIAS (show_bgp_community,
8270 show_bgp_community3_cmd,
8271 "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)",
8272 SHOW_STR
8273 BGP_STR
8274 "Display routes matching the communities\n"
8275 "community number\n"
8276 "Do not send outside local AS (well-known community)\n"
8277 "Do not advertise to any peer (well-known community)\n"
8278 "Do not export to next AS (well-known community)\n"
8279 "community number\n"
8280 "Do not send outside local AS (well-known community)\n"
8281 "Do not advertise to any peer (well-known community)\n"
8282 "Do not export to next AS (well-known community)\n"
8283 "community number\n"
8284 "Do not send outside local AS (well-known community)\n"
8285 "Do not advertise to any peer (well-known community)\n"
8286 "Do not export to next AS (well-known community)\n")
8287
8288ALIAS (show_bgp_community,
8289 show_bgp_ipv6_community3_cmd,
8290 "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)",
8291 SHOW_STR
8292 BGP_STR
8293 "Address family\n"
8294 "Display routes matching the communities\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n"
8299 "community number\n"
8300 "Do not send outside local AS (well-known community)\n"
8301 "Do not advertise to any peer (well-known community)\n"
8302 "Do not export to next AS (well-known community)\n"
8303 "community number\n"
8304 "Do not send outside local AS (well-known community)\n"
8305 "Do not advertise to any peer (well-known community)\n"
8306 "Do not export to next AS (well-known community)\n")
8307
8308ALIAS (show_bgp_community,
8309 show_bgp_community4_cmd,
8310 "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)",
8311 SHOW_STR
8312 BGP_STR
8313 "Display routes matching the communities\n"
8314 "community number\n"
8315 "Do not send outside local AS (well-known community)\n"
8316 "Do not advertise to any peer (well-known community)\n"
8317 "Do not export to next AS (well-known community)\n"
8318 "community number\n"
8319 "Do not send outside local AS (well-known community)\n"
8320 "Do not advertise to any peer (well-known community)\n"
8321 "Do not export to next AS (well-known community)\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n"
8326 "community number\n"
8327 "Do not send outside local AS (well-known community)\n"
8328 "Do not advertise to any peer (well-known community)\n"
8329 "Do not export to next AS (well-known community)\n")
8330
8331ALIAS (show_bgp_community,
8332 show_bgp_ipv6_community4_cmd,
8333 "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)",
8334 SHOW_STR
8335 BGP_STR
8336 "Address family\n"
8337 "Display routes matching the communities\n"
8338 "community number\n"
8339 "Do not send outside local AS (well-known community)\n"
8340 "Do not advertise to any peer (well-known community)\n"
8341 "Do not export to next AS (well-known community)\n"
8342 "community number\n"
8343 "Do not send outside local AS (well-known community)\n"
8344 "Do not advertise to any peer (well-known community)\n"
8345 "Do not export to next AS (well-known community)\n"
8346 "community number\n"
8347 "Do not send outside local AS (well-known community)\n"
8348 "Do not advertise to any peer (well-known community)\n"
8349 "Do not export to next AS (well-known community)\n"
8350 "community number\n"
8351 "Do not send outside local AS (well-known community)\n"
8352 "Do not advertise to any peer (well-known community)\n"
8353 "Do not export to next AS (well-known community)\n")
8354
8355/* old command */
8356DEFUN (show_ipv6_bgp_community,
8357 show_ipv6_bgp_community_cmd,
8358 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8359 SHOW_STR
8360 IPV6_STR
8361 BGP_STR
8362 "Display routes matching the communities\n"
8363 "community number\n"
8364 "Do not send outside local AS (well-known community)\n"
8365 "Do not advertise to any peer (well-known community)\n"
8366 "Do not export to next AS (well-known community)\n")
8367{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008368 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008369}
8370
8371/* old command */
8372ALIAS (show_ipv6_bgp_community,
8373 show_ipv6_bgp_community2_cmd,
8374 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8375 SHOW_STR
8376 IPV6_STR
8377 BGP_STR
8378 "Display routes matching the communities\n"
8379 "community number\n"
8380 "Do not send outside local AS (well-known community)\n"
8381 "Do not advertise to any peer (well-known community)\n"
8382 "Do not export to next AS (well-known community)\n"
8383 "community number\n"
8384 "Do not send outside local AS (well-known community)\n"
8385 "Do not advertise to any peer (well-known community)\n"
8386 "Do not export to next AS (well-known community)\n")
8387
8388/* old command */
8389ALIAS (show_ipv6_bgp_community,
8390 show_ipv6_bgp_community3_cmd,
8391 "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)",
8392 SHOW_STR
8393 IPV6_STR
8394 BGP_STR
8395 "Display routes matching the communities\n"
8396 "community number\n"
8397 "Do not send outside local AS (well-known community)\n"
8398 "Do not advertise to any peer (well-known community)\n"
8399 "Do not export to next AS (well-known community)\n"
8400 "community number\n"
8401 "Do not send outside local AS (well-known community)\n"
8402 "Do not advertise to any peer (well-known community)\n"
8403 "Do not export to next AS (well-known community)\n"
8404 "community number\n"
8405 "Do not send outside local AS (well-known community)\n"
8406 "Do not advertise to any peer (well-known community)\n"
8407 "Do not export to next AS (well-known community)\n")
8408
8409/* old command */
8410ALIAS (show_ipv6_bgp_community,
8411 show_ipv6_bgp_community4_cmd,
8412 "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)",
8413 SHOW_STR
8414 IPV6_STR
8415 BGP_STR
8416 "Display routes matching the communities\n"
8417 "community number\n"
8418 "Do not send outside local AS (well-known community)\n"
8419 "Do not advertise to any peer (well-known community)\n"
8420 "Do not export to next AS (well-known community)\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n")
8433
8434DEFUN (show_bgp_community_exact,
8435 show_bgp_community_exact_cmd,
8436 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8437 SHOW_STR
8438 BGP_STR
8439 "Display routes matching the communities\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "Exact match of the communities")
8445{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008446 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008447}
8448
8449ALIAS (show_bgp_community_exact,
8450 show_bgp_ipv6_community_exact_cmd,
8451 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8452 SHOW_STR
8453 BGP_STR
8454 "Address family\n"
8455 "Display routes matching the communities\n"
8456 "community number\n"
8457 "Do not send outside local AS (well-known community)\n"
8458 "Do not advertise to any peer (well-known community)\n"
8459 "Do not export to next AS (well-known community)\n"
8460 "Exact match of the communities")
8461
8462ALIAS (show_bgp_community_exact,
8463 show_bgp_community2_exact_cmd,
8464 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8465 SHOW_STR
8466 BGP_STR
8467 "Display routes matching the communities\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n"
8476 "Exact match of the communities")
8477
8478ALIAS (show_bgp_community_exact,
8479 show_bgp_ipv6_community2_exact_cmd,
8480 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8481 SHOW_STR
8482 BGP_STR
8483 "Address family\n"
8484 "Display routes matching the communities\n"
8485 "community number\n"
8486 "Do not send outside local AS (well-known community)\n"
8487 "Do not advertise to any peer (well-known community)\n"
8488 "Do not export to next AS (well-known community)\n"
8489 "community number\n"
8490 "Do not send outside local AS (well-known community)\n"
8491 "Do not advertise to any peer (well-known community)\n"
8492 "Do not export to next AS (well-known community)\n"
8493 "Exact match of the communities")
8494
8495ALIAS (show_bgp_community_exact,
8496 show_bgp_community3_exact_cmd,
8497 "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",
8498 SHOW_STR
8499 BGP_STR
8500 "Display routes matching the communities\n"
8501 "community number\n"
8502 "Do not send outside local AS (well-known community)\n"
8503 "Do not advertise to any peer (well-known community)\n"
8504 "Do not export to next AS (well-known community)\n"
8505 "community number\n"
8506 "Do not send outside local AS (well-known community)\n"
8507 "Do not advertise to any peer (well-known community)\n"
8508 "Do not export to next AS (well-known community)\n"
8509 "community number\n"
8510 "Do not send outside local AS (well-known community)\n"
8511 "Do not advertise to any peer (well-known community)\n"
8512 "Do not export to next AS (well-known community)\n"
8513 "Exact match of the communities")
8514
8515ALIAS (show_bgp_community_exact,
8516 show_bgp_ipv6_community3_exact_cmd,
8517 "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",
8518 SHOW_STR
8519 BGP_STR
8520 "Address family\n"
8521 "Display routes matching the communities\n"
8522 "community number\n"
8523 "Do not send outside local AS (well-known community)\n"
8524 "Do not advertise to any peer (well-known community)\n"
8525 "Do not export to next AS (well-known community)\n"
8526 "community number\n"
8527 "Do not send outside local AS (well-known community)\n"
8528 "Do not advertise to any peer (well-known community)\n"
8529 "Do not export to next AS (well-known community)\n"
8530 "community number\n"
8531 "Do not send outside local AS (well-known community)\n"
8532 "Do not advertise to any peer (well-known community)\n"
8533 "Do not export to next AS (well-known community)\n"
8534 "Exact match of the communities")
8535
8536ALIAS (show_bgp_community_exact,
8537 show_bgp_community4_exact_cmd,
8538 "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",
8539 SHOW_STR
8540 BGP_STR
8541 "Display routes matching the communities\n"
8542 "community number\n"
8543 "Do not send outside local AS (well-known community)\n"
8544 "Do not advertise to any peer (well-known community)\n"
8545 "Do not export to next AS (well-known community)\n"
8546 "community number\n"
8547 "Do not send outside local AS (well-known community)\n"
8548 "Do not advertise to any peer (well-known community)\n"
8549 "Do not export to next AS (well-known community)\n"
8550 "community number\n"
8551 "Do not send outside local AS (well-known community)\n"
8552 "Do not advertise to any peer (well-known community)\n"
8553 "Do not export to next AS (well-known community)\n"
8554 "community number\n"
8555 "Do not send outside local AS (well-known community)\n"
8556 "Do not advertise to any peer (well-known community)\n"
8557 "Do not export to next AS (well-known community)\n"
8558 "Exact match of the communities")
8559
8560ALIAS (show_bgp_community_exact,
8561 show_bgp_ipv6_community4_exact_cmd,
8562 "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",
8563 SHOW_STR
8564 BGP_STR
8565 "Address family\n"
8566 "Display routes matching the communities\n"
8567 "community number\n"
8568 "Do not send outside local AS (well-known community)\n"
8569 "Do not advertise to any peer (well-known community)\n"
8570 "Do not export to next AS (well-known community)\n"
8571 "community number\n"
8572 "Do not send outside local AS (well-known community)\n"
8573 "Do not advertise to any peer (well-known community)\n"
8574 "Do not export to next AS (well-known community)\n"
8575 "community number\n"
8576 "Do not send outside local AS (well-known community)\n"
8577 "Do not advertise to any peer (well-known community)\n"
8578 "Do not export to next AS (well-known community)\n"
8579 "community number\n"
8580 "Do not send outside local AS (well-known community)\n"
8581 "Do not advertise to any peer (well-known community)\n"
8582 "Do not export to next AS (well-known community)\n"
8583 "Exact match of the communities")
8584
8585/* old command */
8586DEFUN (show_ipv6_bgp_community_exact,
8587 show_ipv6_bgp_community_exact_cmd,
8588 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8589 SHOW_STR
8590 IPV6_STR
8591 BGP_STR
8592 "Display routes matching the communities\n"
8593 "community number\n"
8594 "Do not send outside local AS (well-known community)\n"
8595 "Do not advertise to any peer (well-known community)\n"
8596 "Do not export to next AS (well-known community)\n"
8597 "Exact match of the communities")
8598{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008599 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008600}
8601
8602/* old command */
8603ALIAS (show_ipv6_bgp_community_exact,
8604 show_ipv6_bgp_community2_exact_cmd,
8605 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8606 SHOW_STR
8607 IPV6_STR
8608 BGP_STR
8609 "Display routes matching the communities\n"
8610 "community number\n"
8611 "Do not send outside local AS (well-known community)\n"
8612 "Do not advertise to any peer (well-known community)\n"
8613 "Do not export to next AS (well-known community)\n"
8614 "community number\n"
8615 "Do not send outside local AS (well-known community)\n"
8616 "Do not advertise to any peer (well-known community)\n"
8617 "Do not export to next AS (well-known community)\n"
8618 "Exact match of the communities")
8619
8620/* old command */
8621ALIAS (show_ipv6_bgp_community_exact,
8622 show_ipv6_bgp_community3_exact_cmd,
8623 "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",
8624 SHOW_STR
8625 IPV6_STR
8626 BGP_STR
8627 "Display routes matching the communities\n"
8628 "community number\n"
8629 "Do not send outside local AS (well-known community)\n"
8630 "Do not advertise to any peer (well-known community)\n"
8631 "Do not export to next AS (well-known community)\n"
8632 "community number\n"
8633 "Do not send outside local AS (well-known community)\n"
8634 "Do not advertise to any peer (well-known community)\n"
8635 "Do not export to next AS (well-known community)\n"
8636 "community number\n"
8637 "Do not send outside local AS (well-known community)\n"
8638 "Do not advertise to any peer (well-known community)\n"
8639 "Do not export to next AS (well-known community)\n"
8640 "Exact match of the communities")
8641
8642/* old command */
8643ALIAS (show_ipv6_bgp_community_exact,
8644 show_ipv6_bgp_community4_exact_cmd,
8645 "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",
8646 SHOW_STR
8647 IPV6_STR
8648 BGP_STR
8649 "Display routes matching the communities\n"
8650 "community number\n"
8651 "Do not send outside local AS (well-known community)\n"
8652 "Do not advertise to any peer (well-known community)\n"
8653 "Do not export to next AS (well-known community)\n"
8654 "community number\n"
8655 "Do not send outside local AS (well-known community)\n"
8656 "Do not advertise to any peer (well-known community)\n"
8657 "Do not export to next AS (well-known community)\n"
8658 "community number\n"
8659 "Do not send outside local AS (well-known community)\n"
8660 "Do not advertise to any peer (well-known community)\n"
8661 "Do not export to next AS (well-known community)\n"
8662 "community number\n"
8663 "Do not send outside local AS (well-known community)\n"
8664 "Do not advertise to any peer (well-known community)\n"
8665 "Do not export to next AS (well-known community)\n"
8666 "Exact match of the communities")
8667
8668/* old command */
8669DEFUN (show_ipv6_mbgp_community,
8670 show_ipv6_mbgp_community_cmd,
8671 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8672 SHOW_STR
8673 IPV6_STR
8674 MBGP_STR
8675 "Display routes matching the communities\n"
8676 "community number\n"
8677 "Do not send outside local AS (well-known community)\n"
8678 "Do not advertise to any peer (well-known community)\n"
8679 "Do not export to next AS (well-known community)\n")
8680{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008681 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008682}
8683
8684/* old command */
8685ALIAS (show_ipv6_mbgp_community,
8686 show_ipv6_mbgp_community2_cmd,
8687 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8688 SHOW_STR
8689 IPV6_STR
8690 MBGP_STR
8691 "Display routes matching the communities\n"
8692 "community number\n"
8693 "Do not send outside local AS (well-known community)\n"
8694 "Do not advertise to any peer (well-known community)\n"
8695 "Do not export to next AS (well-known community)\n"
8696 "community number\n"
8697 "Do not send outside local AS (well-known community)\n"
8698 "Do not advertise to any peer (well-known community)\n"
8699 "Do not export to next AS (well-known community)\n")
8700
8701/* old command */
8702ALIAS (show_ipv6_mbgp_community,
8703 show_ipv6_mbgp_community3_cmd,
8704 "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)",
8705 SHOW_STR
8706 IPV6_STR
8707 MBGP_STR
8708 "Display routes matching the communities\n"
8709 "community number\n"
8710 "Do not send outside local AS (well-known community)\n"
8711 "Do not advertise to any peer (well-known community)\n"
8712 "Do not export to next AS (well-known community)\n"
8713 "community number\n"
8714 "Do not send outside local AS (well-known community)\n"
8715 "Do not advertise to any peer (well-known community)\n"
8716 "Do not export to next AS (well-known community)\n"
8717 "community number\n"
8718 "Do not send outside local AS (well-known community)\n"
8719 "Do not advertise to any peer (well-known community)\n"
8720 "Do not export to next AS (well-known community)\n")
8721
8722/* old command */
8723ALIAS (show_ipv6_mbgp_community,
8724 show_ipv6_mbgp_community4_cmd,
8725 "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)",
8726 SHOW_STR
8727 IPV6_STR
8728 MBGP_STR
8729 "Display routes matching the communities\n"
8730 "community number\n"
8731 "Do not send outside local AS (well-known community)\n"
8732 "Do not advertise to any peer (well-known community)\n"
8733 "Do not export to next AS (well-known community)\n"
8734 "community number\n"
8735 "Do not send outside local AS (well-known community)\n"
8736 "Do not advertise to any peer (well-known community)\n"
8737 "Do not export to next AS (well-known community)\n"
8738 "community number\n"
8739 "Do not send outside local AS (well-known community)\n"
8740 "Do not advertise to any peer (well-known community)\n"
8741 "Do not export to next AS (well-known community)\n"
8742 "community number\n"
8743 "Do not send outside local AS (well-known community)\n"
8744 "Do not advertise to any peer (well-known community)\n"
8745 "Do not export to next AS (well-known community)\n")
8746
8747/* old command */
8748DEFUN (show_ipv6_mbgp_community_exact,
8749 show_ipv6_mbgp_community_exact_cmd,
8750 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8751 SHOW_STR
8752 IPV6_STR
8753 MBGP_STR
8754 "Display routes matching the communities\n"
8755 "community number\n"
8756 "Do not send outside local AS (well-known community)\n"
8757 "Do not advertise to any peer (well-known community)\n"
8758 "Do not export to next AS (well-known community)\n"
8759 "Exact match of the communities")
8760{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008761 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008762}
8763
8764/* old command */
8765ALIAS (show_ipv6_mbgp_community_exact,
8766 show_ipv6_mbgp_community2_exact_cmd,
8767 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8768 SHOW_STR
8769 IPV6_STR
8770 MBGP_STR
8771 "Display routes matching the communities\n"
8772 "community number\n"
8773 "Do not send outside local AS (well-known community)\n"
8774 "Do not advertise to any peer (well-known community)\n"
8775 "Do not export to next AS (well-known community)\n"
8776 "community number\n"
8777 "Do not send outside local AS (well-known community)\n"
8778 "Do not advertise to any peer (well-known community)\n"
8779 "Do not export to next AS (well-known community)\n"
8780 "Exact match of the communities")
8781
8782/* old command */
8783ALIAS (show_ipv6_mbgp_community_exact,
8784 show_ipv6_mbgp_community3_exact_cmd,
8785 "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",
8786 SHOW_STR
8787 IPV6_STR
8788 MBGP_STR
8789 "Display routes matching the communities\n"
8790 "community number\n"
8791 "Do not send outside local AS (well-known community)\n"
8792 "Do not advertise to any peer (well-known community)\n"
8793 "Do not export to next AS (well-known community)\n"
8794 "community number\n"
8795 "Do not send outside local AS (well-known community)\n"
8796 "Do not advertise to any peer (well-known community)\n"
8797 "Do not export to next AS (well-known community)\n"
8798 "community number\n"
8799 "Do not send outside local AS (well-known community)\n"
8800 "Do not advertise to any peer (well-known community)\n"
8801 "Do not export to next AS (well-known community)\n"
8802 "Exact match of the communities")
8803
8804/* old command */
8805ALIAS (show_ipv6_mbgp_community_exact,
8806 show_ipv6_mbgp_community4_exact_cmd,
8807 "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",
8808 SHOW_STR
8809 IPV6_STR
8810 MBGP_STR
8811 "Display routes matching the communities\n"
8812 "community number\n"
8813 "Do not send outside local AS (well-known community)\n"
8814 "Do not advertise to any peer (well-known community)\n"
8815 "Do not export to next AS (well-known community)\n"
8816 "community number\n"
8817 "Do not send outside local AS (well-known community)\n"
8818 "Do not advertise to any peer (well-known community)\n"
8819 "Do not export to next AS (well-known community)\n"
8820 "community number\n"
8821 "Do not send outside local AS (well-known community)\n"
8822 "Do not advertise to any peer (well-known community)\n"
8823 "Do not export to next AS (well-known community)\n"
8824 "community number\n"
8825 "Do not send outside local AS (well-known community)\n"
8826 "Do not advertise to any peer (well-known community)\n"
8827 "Do not export to next AS (well-known community)\n"
8828 "Exact match of the communities")
8829#endif /* HAVE_IPV6 */
8830
paul94f2b392005-06-28 12:44:16 +00008831static int
paulfd79ac92004-10-13 05:06:08 +00008832bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008833 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008834{
8835 struct community_list *list;
8836
hassofee6e4e2005-02-02 16:29:31 +00008837 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008838 if (list == NULL)
8839 {
8840 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8841 VTY_NEWLINE);
8842 return CMD_WARNING;
8843 }
8844
ajs5a646652004-11-05 01:25:55 +00008845 return bgp_show (vty, NULL, afi, safi,
8846 (exact ? bgp_show_type_community_list_exact :
8847 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008848}
8849
8850DEFUN (show_ip_bgp_community_list,
8851 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008852 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008853 SHOW_STR
8854 IP_STR
8855 BGP_STR
8856 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008857 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008858 "community-list name\n")
8859{
8860 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8861}
8862
8863DEFUN (show_ip_bgp_ipv4_community_list,
8864 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008865 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008866 SHOW_STR
8867 IP_STR
8868 BGP_STR
8869 "Address family\n"
8870 "Address Family modifier\n"
8871 "Address Family modifier\n"
8872 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008873 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008874 "community-list name\n")
8875{
8876 if (strncmp (argv[0], "m", 1) == 0)
8877 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8878
8879 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8880}
8881
8882DEFUN (show_ip_bgp_community_list_exact,
8883 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008884 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008885 SHOW_STR
8886 IP_STR
8887 BGP_STR
8888 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008889 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008890 "community-list name\n"
8891 "Exact match of the communities\n")
8892{
8893 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8894}
8895
8896DEFUN (show_ip_bgp_ipv4_community_list_exact,
8897 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008898 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008899 SHOW_STR
8900 IP_STR
8901 BGP_STR
8902 "Address family\n"
8903 "Address Family modifier\n"
8904 "Address Family modifier\n"
8905 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008906 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008907 "community-list name\n"
8908 "Exact match of the communities\n")
8909{
8910 if (strncmp (argv[0], "m", 1) == 0)
8911 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8912
8913 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8914}
8915
8916#ifdef HAVE_IPV6
8917DEFUN (show_bgp_community_list,
8918 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008919 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008920 SHOW_STR
8921 BGP_STR
8922 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008923 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008924 "community-list name\n")
8925{
8926 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8927}
8928
8929ALIAS (show_bgp_community_list,
8930 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008931 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008932 SHOW_STR
8933 BGP_STR
8934 "Address family\n"
8935 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008936 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008937 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008938
8939/* old command */
8940DEFUN (show_ipv6_bgp_community_list,
8941 show_ipv6_bgp_community_list_cmd,
8942 "show ipv6 bgp community-list WORD",
8943 SHOW_STR
8944 IPV6_STR
8945 BGP_STR
8946 "Display routes matching the community-list\n"
8947 "community-list name\n")
8948{
8949 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8950}
8951
8952/* old command */
8953DEFUN (show_ipv6_mbgp_community_list,
8954 show_ipv6_mbgp_community_list_cmd,
8955 "show ipv6 mbgp community-list WORD",
8956 SHOW_STR
8957 IPV6_STR
8958 MBGP_STR
8959 "Display routes matching the community-list\n"
8960 "community-list name\n")
8961{
8962 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8963}
8964
8965DEFUN (show_bgp_community_list_exact,
8966 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008967 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008968 SHOW_STR
8969 BGP_STR
8970 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008971 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008972 "community-list name\n"
8973 "Exact match of the communities\n")
8974{
8975 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8976}
8977
8978ALIAS (show_bgp_community_list_exact,
8979 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008980 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008981 SHOW_STR
8982 BGP_STR
8983 "Address family\n"
8984 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008985 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008986 "community-list name\n"
8987 "Exact match of the communities\n")
8988
8989/* old command */
8990DEFUN (show_ipv6_bgp_community_list_exact,
8991 show_ipv6_bgp_community_list_exact_cmd,
8992 "show ipv6 bgp community-list WORD exact-match",
8993 SHOW_STR
8994 IPV6_STR
8995 BGP_STR
8996 "Display routes matching the community-list\n"
8997 "community-list name\n"
8998 "Exact match of the communities\n")
8999{
9000 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9001}
9002
9003/* old command */
9004DEFUN (show_ipv6_mbgp_community_list_exact,
9005 show_ipv6_mbgp_community_list_exact_cmd,
9006 "show ipv6 mbgp community-list WORD exact-match",
9007 SHOW_STR
9008 IPV6_STR
9009 MBGP_STR
9010 "Display routes matching the community-list\n"
9011 "community-list name\n"
9012 "Exact match of the communities\n")
9013{
9014 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9015}
9016#endif /* HAVE_IPV6 */
9017
paul94f2b392005-06-28 12:44:16 +00009018static int
paulfd79ac92004-10-13 05:06:08 +00009019bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009020 safi_t safi, enum bgp_show_type type)
9021{
9022 int ret;
9023 struct prefix *p;
9024
9025 p = prefix_new();
9026
9027 ret = str2prefix (prefix, p);
9028 if (! ret)
9029 {
9030 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9031 return CMD_WARNING;
9032 }
9033
ajs5a646652004-11-05 01:25:55 +00009034 ret = bgp_show (vty, NULL, afi, safi, type, p);
9035 prefix_free(p);
9036 return ret;
paul718e3742002-12-13 20:15:29 +00009037}
9038
9039DEFUN (show_ip_bgp_prefix_longer,
9040 show_ip_bgp_prefix_longer_cmd,
9041 "show ip bgp A.B.C.D/M longer-prefixes",
9042 SHOW_STR
9043 IP_STR
9044 BGP_STR
9045 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9046 "Display route and more specific routes\n")
9047{
9048 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9049 bgp_show_type_prefix_longer);
9050}
9051
9052DEFUN (show_ip_bgp_flap_prefix_longer,
9053 show_ip_bgp_flap_prefix_longer_cmd,
9054 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9055 SHOW_STR
9056 IP_STR
9057 BGP_STR
9058 "Display flap statistics of routes\n"
9059 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9060 "Display route and more specific routes\n")
9061{
9062 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9063 bgp_show_type_flap_prefix_longer);
9064}
9065
9066DEFUN (show_ip_bgp_ipv4_prefix_longer,
9067 show_ip_bgp_ipv4_prefix_longer_cmd,
9068 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9069 SHOW_STR
9070 IP_STR
9071 BGP_STR
9072 "Address family\n"
9073 "Address Family modifier\n"
9074 "Address Family modifier\n"
9075 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9076 "Display route and more specific routes\n")
9077{
9078 if (strncmp (argv[0], "m", 1) == 0)
9079 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9080 bgp_show_type_prefix_longer);
9081
9082 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9083 bgp_show_type_prefix_longer);
9084}
9085
9086DEFUN (show_ip_bgp_flap_address,
9087 show_ip_bgp_flap_address_cmd,
9088 "show ip bgp flap-statistics A.B.C.D",
9089 SHOW_STR
9090 IP_STR
9091 BGP_STR
9092 "Display flap statistics of routes\n"
9093 "Network in the BGP routing table to display\n")
9094{
9095 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9096 bgp_show_type_flap_address);
9097}
9098
9099DEFUN (show_ip_bgp_flap_prefix,
9100 show_ip_bgp_flap_prefix_cmd,
9101 "show ip bgp flap-statistics A.B.C.D/M",
9102 SHOW_STR
9103 IP_STR
9104 BGP_STR
9105 "Display flap statistics of routes\n"
9106 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9107{
9108 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9109 bgp_show_type_flap_prefix);
9110}
9111#ifdef HAVE_IPV6
9112DEFUN (show_bgp_prefix_longer,
9113 show_bgp_prefix_longer_cmd,
9114 "show bgp X:X::X:X/M longer-prefixes",
9115 SHOW_STR
9116 BGP_STR
9117 "IPv6 prefix <network>/<length>\n"
9118 "Display route and more specific routes\n")
9119{
9120 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9121 bgp_show_type_prefix_longer);
9122}
9123
9124ALIAS (show_bgp_prefix_longer,
9125 show_bgp_ipv6_prefix_longer_cmd,
9126 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9127 SHOW_STR
9128 BGP_STR
9129 "Address family\n"
9130 "IPv6 prefix <network>/<length>\n"
9131 "Display route and more specific routes\n")
9132
9133/* old command */
9134DEFUN (show_ipv6_bgp_prefix_longer,
9135 show_ipv6_bgp_prefix_longer_cmd,
9136 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9137 SHOW_STR
9138 IPV6_STR
9139 BGP_STR
9140 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9141 "Display route and more specific routes\n")
9142{
9143 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9144 bgp_show_type_prefix_longer);
9145}
9146
9147/* old command */
9148DEFUN (show_ipv6_mbgp_prefix_longer,
9149 show_ipv6_mbgp_prefix_longer_cmd,
9150 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9151 SHOW_STR
9152 IPV6_STR
9153 MBGP_STR
9154 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9155 "Display route and more specific routes\n")
9156{
9157 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9158 bgp_show_type_prefix_longer);
9159}
9160#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009161
paul94f2b392005-06-28 12:44:16 +00009162static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009163peer_lookup_in_view (struct vty *vty, const char *view_name,
9164 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009165{
9166 int ret;
9167 struct bgp *bgp;
9168 struct peer *peer;
9169 union sockunion su;
9170
9171 /* BGP structure lookup. */
9172 if (view_name)
9173 {
9174 bgp = bgp_lookup_by_name (view_name);
9175 if (! bgp)
9176 {
9177 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9178 return NULL;
9179 }
9180 }
paul5228ad22004-06-04 17:58:18 +00009181 else
paulbb46e942003-10-24 19:02:03 +00009182 {
9183 bgp = bgp_get_default ();
9184 if (! bgp)
9185 {
9186 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9187 return NULL;
9188 }
9189 }
9190
9191 /* Get peer sockunion. */
9192 ret = str2sockunion (ip_str, &su);
9193 if (ret < 0)
9194 {
9195 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9196 return NULL;
9197 }
9198
9199 /* Peer structure lookup. */
9200 peer = peer_lookup (bgp, &su);
9201 if (! peer)
9202 {
9203 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9204 return NULL;
9205 }
9206
9207 return peer;
9208}
Paul Jakma2815e612006-09-14 02:56:07 +00009209
9210enum bgp_stats
9211{
9212 BGP_STATS_MAXBITLEN = 0,
9213 BGP_STATS_RIB,
9214 BGP_STATS_PREFIXES,
9215 BGP_STATS_TOTPLEN,
9216 BGP_STATS_UNAGGREGATEABLE,
9217 BGP_STATS_MAX_AGGREGATEABLE,
9218 BGP_STATS_AGGREGATES,
9219 BGP_STATS_SPACE,
9220 BGP_STATS_ASPATH_COUNT,
9221 BGP_STATS_ASPATH_MAXHOPS,
9222 BGP_STATS_ASPATH_TOTHOPS,
9223 BGP_STATS_ASPATH_MAXSIZE,
9224 BGP_STATS_ASPATH_TOTSIZE,
9225 BGP_STATS_ASN_HIGHEST,
9226 BGP_STATS_MAX,
9227};
paulbb46e942003-10-24 19:02:03 +00009228
Paul Jakma2815e612006-09-14 02:56:07 +00009229static const char *table_stats_strs[] =
9230{
9231 [BGP_STATS_PREFIXES] = "Total Prefixes",
9232 [BGP_STATS_TOTPLEN] = "Average prefix length",
9233 [BGP_STATS_RIB] = "Total Advertisements",
9234 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9235 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9236 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9237 [BGP_STATS_SPACE] = "Address space advertised",
9238 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9239 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9240 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9241 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9242 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9243 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9244 [BGP_STATS_MAX] = NULL,
9245};
9246
9247struct bgp_table_stats
9248{
9249 struct bgp_table *table;
9250 unsigned long long counts[BGP_STATS_MAX];
9251};
9252
9253#if 0
9254#define TALLY_SIGFIG 100000
9255static unsigned long
9256ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9257{
9258 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9259 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9260 unsigned long ret = newtot / count;
9261
9262 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9263 return ret + 1;
9264 else
9265 return ret;
9266}
9267#endif
9268
9269static int
9270bgp_table_stats_walker (struct thread *t)
9271{
9272 struct bgp_node *rn;
9273 struct bgp_node *top;
9274 struct bgp_table_stats *ts = THREAD_ARG (t);
9275 unsigned int space = 0;
9276
Paul Jakma53d9f672006-10-15 23:41:16 +00009277 if (!(top = bgp_table_top (ts->table)))
9278 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009279
9280 switch (top->p.family)
9281 {
9282 case AF_INET:
9283 space = IPV4_MAX_BITLEN;
9284 break;
9285 case AF_INET6:
9286 space = IPV6_MAX_BITLEN;
9287 break;
9288 }
9289
9290 ts->counts[BGP_STATS_MAXBITLEN] = space;
9291
9292 for (rn = top; rn; rn = bgp_route_next (rn))
9293 {
9294 struct bgp_info *ri;
9295 struct bgp_node *prn = rn->parent;
9296 unsigned int rinum = 0;
9297
9298 if (rn == top)
9299 continue;
9300
9301 if (!rn->info)
9302 continue;
9303
9304 ts->counts[BGP_STATS_PREFIXES]++;
9305 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9306
9307#if 0
9308 ts->counts[BGP_STATS_AVGPLEN]
9309 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9310 ts->counts[BGP_STATS_AVGPLEN],
9311 rn->p.prefixlen);
9312#endif
9313
9314 /* check if the prefix is included by any other announcements */
9315 while (prn && !prn->info)
9316 prn = prn->parent;
9317
9318 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009319 {
9320 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9321 /* announced address space */
9322 if (space)
9323 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9324 }
Paul Jakma2815e612006-09-14 02:56:07 +00009325 else if (prn->info)
9326 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9327
Paul Jakma2815e612006-09-14 02:56:07 +00009328 for (ri = rn->info; ri; ri = ri->next)
9329 {
9330 rinum++;
9331 ts->counts[BGP_STATS_RIB]++;
9332
9333 if (ri->attr &&
9334 (CHECK_FLAG (ri->attr->flag,
9335 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9336 ts->counts[BGP_STATS_AGGREGATES]++;
9337
9338 /* as-path stats */
9339 if (ri->attr && ri->attr->aspath)
9340 {
9341 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9342 unsigned int size = aspath_size (ri->attr->aspath);
9343 as_t highest = aspath_highest (ri->attr->aspath);
9344
9345 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9346
9347 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9348 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9349
9350 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9351 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9352
9353 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9354 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9355#if 0
9356 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9357 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9358 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9359 hops);
9360 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9361 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9362 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9363 size);
9364#endif
9365 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9366 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9367 }
9368 }
9369 }
9370 return 0;
9371}
9372
9373static int
9374bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9375{
9376 struct bgp_table_stats ts;
9377 unsigned int i;
9378
9379 if (!bgp->rib[afi][safi])
9380 {
9381 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9382 return CMD_WARNING;
9383 }
9384
9385 memset (&ts, 0, sizeof (ts));
9386 ts.table = bgp->rib[afi][safi];
9387 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9388
9389 vty_out (vty, "BGP %s RIB statistics%s%s",
9390 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9391
9392 for (i = 0; i < BGP_STATS_MAX; i++)
9393 {
9394 if (!table_stats_strs[i])
9395 continue;
9396
9397 switch (i)
9398 {
9399#if 0
9400 case BGP_STATS_ASPATH_AVGHOPS:
9401 case BGP_STATS_ASPATH_AVGSIZE:
9402 case BGP_STATS_AVGPLEN:
9403 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9404 vty_out (vty, "%12.2f",
9405 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9406 break;
9407#endif
9408 case BGP_STATS_ASPATH_TOTHOPS:
9409 case BGP_STATS_ASPATH_TOTSIZE:
9410 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9411 vty_out (vty, "%12.2f",
9412 ts.counts[i] ?
9413 (float)ts.counts[i] /
9414 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9415 : 0);
9416 break;
9417 case BGP_STATS_TOTPLEN:
9418 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9419 vty_out (vty, "%12.2f",
9420 ts.counts[i] ?
9421 (float)ts.counts[i] /
9422 (float)ts.counts[BGP_STATS_PREFIXES]
9423 : 0);
9424 break;
9425 case BGP_STATS_SPACE:
9426 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9427 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9428 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9429 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009430 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009431 vty_out (vty, "%12.2f%s",
9432 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009433 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009434 VTY_NEWLINE);
9435 vty_out (vty, "%30s: ", "/8 equivalent ");
9436 vty_out (vty, "%12.2f%s",
9437 (float)ts.counts[BGP_STATS_SPACE] /
9438 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9439 VTY_NEWLINE);
9440 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9441 break;
9442 vty_out (vty, "%30s: ", "/24 equivalent ");
9443 vty_out (vty, "%12.2f",
9444 (float)ts.counts[BGP_STATS_SPACE] /
9445 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9446 break;
9447 default:
9448 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9449 vty_out (vty, "%12llu", ts.counts[i]);
9450 }
9451
9452 vty_out (vty, "%s", VTY_NEWLINE);
9453 }
9454 return CMD_SUCCESS;
9455}
9456
9457static int
9458bgp_table_stats_vty (struct vty *vty, const char *name,
9459 const char *afi_str, const char *safi_str)
9460{
9461 struct bgp *bgp;
9462 afi_t afi;
9463 safi_t safi;
9464
9465 if (name)
9466 bgp = bgp_lookup_by_name (name);
9467 else
9468 bgp = bgp_get_default ();
9469
9470 if (!bgp)
9471 {
9472 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9473 return CMD_WARNING;
9474 }
9475 if (strncmp (afi_str, "ipv", 3) == 0)
9476 {
9477 if (strncmp (afi_str, "ipv4", 4) == 0)
9478 afi = AFI_IP;
9479 else if (strncmp (afi_str, "ipv6", 4) == 0)
9480 afi = AFI_IP6;
9481 else
9482 {
9483 vty_out (vty, "%% Invalid address family %s%s",
9484 afi_str, VTY_NEWLINE);
9485 return CMD_WARNING;
9486 }
9487 if (strncmp (safi_str, "m", 1) == 0)
9488 safi = SAFI_MULTICAST;
9489 else if (strncmp (safi_str, "u", 1) == 0)
9490 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009491 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9492 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009493 else
9494 {
9495 vty_out (vty, "%% Invalid subsequent address family %s%s",
9496 safi_str, VTY_NEWLINE);
9497 return CMD_WARNING;
9498 }
9499 }
9500 else
9501 {
9502 vty_out (vty, "%% Invalid address family %s%s",
9503 afi_str, VTY_NEWLINE);
9504 return CMD_WARNING;
9505 }
9506
Paul Jakma2815e612006-09-14 02:56:07 +00009507 return bgp_table_stats (vty, bgp, afi, safi);
9508}
9509
9510DEFUN (show_bgp_statistics,
9511 show_bgp_statistics_cmd,
9512 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9513 SHOW_STR
9514 BGP_STR
9515 "Address family\n"
9516 "Address family\n"
9517 "Address Family modifier\n"
9518 "Address Family modifier\n"
9519 "BGP RIB advertisement statistics\n")
9520{
9521 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9522}
9523
9524ALIAS (show_bgp_statistics,
9525 show_bgp_statistics_vpnv4_cmd,
9526 "show bgp (ipv4) (vpnv4) statistics",
9527 SHOW_STR
9528 BGP_STR
9529 "Address family\n"
9530 "Address Family modifier\n"
9531 "BGP RIB advertisement statistics\n")
9532
9533DEFUN (show_bgp_statistics_view,
9534 show_bgp_statistics_view_cmd,
9535 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9536 SHOW_STR
9537 BGP_STR
9538 "BGP view\n"
9539 "Address family\n"
9540 "Address family\n"
9541 "Address Family modifier\n"
9542 "Address Family modifier\n"
9543 "BGP RIB advertisement statistics\n")
9544{
9545 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9546}
9547
9548ALIAS (show_bgp_statistics_view,
9549 show_bgp_statistics_view_vpnv4_cmd,
9550 "show bgp view WORD (ipv4) (vpnv4) statistics",
9551 SHOW_STR
9552 BGP_STR
9553 "BGP view\n"
9554 "Address family\n"
9555 "Address Family modifier\n"
9556 "BGP RIB advertisement statistics\n")
9557
Paul Jakmaff7924f2006-09-04 01:10:36 +00009558enum bgp_pcounts
9559{
9560 PCOUNT_ADJ_IN = 0,
9561 PCOUNT_DAMPED,
9562 PCOUNT_REMOVED,
9563 PCOUNT_HISTORY,
9564 PCOUNT_STALE,
9565 PCOUNT_VALID,
9566 PCOUNT_ALL,
9567 PCOUNT_COUNTED,
9568 PCOUNT_PFCNT, /* the figure we display to users */
9569 PCOUNT_MAX,
9570};
9571
9572static const char *pcount_strs[] =
9573{
9574 [PCOUNT_ADJ_IN] = "Adj-in",
9575 [PCOUNT_DAMPED] = "Damped",
9576 [PCOUNT_REMOVED] = "Removed",
9577 [PCOUNT_HISTORY] = "History",
9578 [PCOUNT_STALE] = "Stale",
9579 [PCOUNT_VALID] = "Valid",
9580 [PCOUNT_ALL] = "All RIB",
9581 [PCOUNT_COUNTED] = "PfxCt counted",
9582 [PCOUNT_PFCNT] = "Useable",
9583 [PCOUNT_MAX] = NULL,
9584};
9585
Paul Jakma2815e612006-09-14 02:56:07 +00009586struct peer_pcounts
9587{
9588 unsigned int count[PCOUNT_MAX];
9589 const struct peer *peer;
9590 const struct bgp_table *table;
9591};
9592
Paul Jakmaff7924f2006-09-04 01:10:36 +00009593static int
Paul Jakma2815e612006-09-14 02:56:07 +00009594bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009595{
9596 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009597 struct peer_pcounts *pc = THREAD_ARG (t);
9598 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009599
Paul Jakma2815e612006-09-14 02:56:07 +00009600 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009601 {
9602 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009603 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009604
9605 for (ain = rn->adj_in; ain; ain = ain->next)
9606 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009607 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009608
Paul Jakmaff7924f2006-09-04 01:10:36 +00009609 for (ri = rn->info; ri; ri = ri->next)
9610 {
9611 char buf[SU_ADDRSTRLEN];
9612
9613 if (ri->peer != peer)
9614 continue;
9615
Paul Jakma2815e612006-09-14 02:56:07 +00009616 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009617
9618 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009619 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009620 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009621 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009622 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009623 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009624 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009625 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009626 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009627 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009628 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009629 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009630
9631 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9632 {
Paul Jakma2815e612006-09-14 02:56:07 +00009633 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009634 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009635 plog_warn (peer->log,
9636 "%s [pcount] %s/%d is counted but flags 0x%x",
9637 peer->host,
9638 inet_ntop(rn->p.family, &rn->p.u.prefix,
9639 buf, SU_ADDRSTRLEN),
9640 rn->p.prefixlen,
9641 ri->flags);
9642 }
9643 else
9644 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009645 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009646 plog_warn (peer->log,
9647 "%s [pcount] %s/%d not counted but flags 0x%x",
9648 peer->host,
9649 inet_ntop(rn->p.family, &rn->p.u.prefix,
9650 buf, SU_ADDRSTRLEN),
9651 rn->p.prefixlen,
9652 ri->flags);
9653 }
9654 }
9655 }
Paul Jakma2815e612006-09-14 02:56:07 +00009656 return 0;
9657}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009658
Paul Jakma2815e612006-09-14 02:56:07 +00009659static int
9660bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9661{
9662 struct peer_pcounts pcounts = { .peer = peer };
9663 unsigned int i;
9664
9665 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9666 || !peer->bgp->rib[afi][safi])
9667 {
9668 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9669 return CMD_WARNING;
9670 }
9671
9672 memset (&pcounts, 0, sizeof(pcounts));
9673 pcounts.peer = peer;
9674 pcounts.table = peer->bgp->rib[afi][safi];
9675
9676 /* in-place call via thread subsystem so as to record execution time
9677 * stats for the thread-walk (i.e. ensure this can't be blamed on
9678 * on just vty_read()).
9679 */
9680 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9681
Paul Jakmaff7924f2006-09-04 01:10:36 +00009682 vty_out (vty, "Prefix counts for %s, %s%s",
9683 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9684 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9685 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9686 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9687
9688 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009689 vty_out (vty, "%20s: %-10d%s",
9690 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009691
Paul Jakma2815e612006-09-14 02:56:07 +00009692 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009693 {
9694 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9695 peer->host, VTY_NEWLINE);
9696 vty_out (vty, "Please report this bug, with the above command output%s",
9697 VTY_NEWLINE);
9698 }
9699
9700 return CMD_SUCCESS;
9701}
9702
9703DEFUN (show_ip_bgp_neighbor_prefix_counts,
9704 show_ip_bgp_neighbor_prefix_counts_cmd,
9705 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9706 SHOW_STR
9707 IP_STR
9708 BGP_STR
9709 "Detailed information on TCP and BGP neighbor connections\n"
9710 "Neighbor to display information about\n"
9711 "Neighbor to display information about\n"
9712 "Display detailed prefix count information\n")
9713{
9714 struct peer *peer;
9715
9716 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9717 if (! peer)
9718 return CMD_WARNING;
9719
9720 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9721}
9722
9723DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9724 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9725 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9726 SHOW_STR
9727 BGP_STR
9728 "Address family\n"
9729 "Detailed information on TCP and BGP neighbor connections\n"
9730 "Neighbor to display information about\n"
9731 "Neighbor to display information about\n"
9732 "Display detailed prefix count information\n")
9733{
9734 struct peer *peer;
9735
9736 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9737 if (! peer)
9738 return CMD_WARNING;
9739
9740 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9741}
9742
9743DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9744 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9745 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9746 SHOW_STR
9747 IP_STR
9748 BGP_STR
9749 "Address family\n"
9750 "Address Family modifier\n"
9751 "Address Family modifier\n"
9752 "Detailed information on TCP and BGP neighbor connections\n"
9753 "Neighbor to display information about\n"
9754 "Neighbor to display information about\n"
9755 "Display detailed prefix count information\n")
9756{
9757 struct peer *peer;
9758
9759 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9760 if (! peer)
9761 return CMD_WARNING;
9762
9763 if (strncmp (argv[0], "m", 1) == 0)
9764 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9765
9766 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9767}
9768
9769DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9770 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9771 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9772 SHOW_STR
9773 IP_STR
9774 BGP_STR
9775 "Address family\n"
9776 "Address Family modifier\n"
9777 "Address Family modifier\n"
9778 "Detailed information on TCP and BGP neighbor connections\n"
9779 "Neighbor to display information about\n"
9780 "Neighbor to display information about\n"
9781 "Display detailed prefix count information\n")
9782{
9783 struct peer *peer;
9784
9785 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9786 if (! peer)
9787 return CMD_WARNING;
9788
9789 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9790}
9791
9792
paul94f2b392005-06-28 12:44:16 +00009793static void
paul718e3742002-12-13 20:15:29 +00009794show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9795 int in)
9796{
9797 struct bgp_table *table;
9798 struct bgp_adj_in *ain;
9799 struct bgp_adj_out *adj;
9800 unsigned long output_count;
9801 struct bgp_node *rn;
9802 int header1 = 1;
9803 struct bgp *bgp;
9804 int header2 = 1;
9805
paulbb46e942003-10-24 19:02:03 +00009806 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009807
9808 if (! bgp)
9809 return;
9810
9811 table = bgp->rib[afi][safi];
9812
9813 output_count = 0;
9814
9815 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9816 PEER_STATUS_DEFAULT_ORIGINATE))
9817 {
9818 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 +00009819 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9820 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009821
9822 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9823 VTY_NEWLINE, VTY_NEWLINE);
9824 header1 = 0;
9825 }
9826
9827 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9828 if (in)
9829 {
9830 for (ain = rn->adj_in; ain; ain = ain->next)
9831 if (ain->peer == peer)
9832 {
9833 if (header1)
9834 {
9835 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 +00009836 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9837 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009838 header1 = 0;
9839 }
9840 if (header2)
9841 {
9842 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9843 header2 = 0;
9844 }
9845 if (ain->attr)
9846 {
9847 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9848 output_count++;
9849 }
9850 }
9851 }
9852 else
9853 {
9854 for (adj = rn->adj_out; adj; adj = adj->next)
9855 if (adj->peer == peer)
9856 {
9857 if (header1)
9858 {
9859 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 +00009860 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9861 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009862 header1 = 0;
9863 }
9864 if (header2)
9865 {
9866 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9867 header2 = 0;
9868 }
9869 if (adj->attr)
9870 {
9871 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9872 output_count++;
9873 }
9874 }
9875 }
9876
9877 if (output_count != 0)
9878 vty_out (vty, "%sTotal number of prefixes %ld%s",
9879 VTY_NEWLINE, output_count, VTY_NEWLINE);
9880}
9881
paul94f2b392005-06-28 12:44:16 +00009882static int
paulbb46e942003-10-24 19:02:03 +00009883peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9884{
paul718e3742002-12-13 20:15:29 +00009885 if (! peer || ! peer->afc[afi][safi])
9886 {
9887 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9888 return CMD_WARNING;
9889 }
9890
9891 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9892 {
9893 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9894 VTY_NEWLINE);
9895 return CMD_WARNING;
9896 }
9897
9898 show_adj_route (vty, peer, afi, safi, in);
9899
9900 return CMD_SUCCESS;
9901}
9902
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009903DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9904 show_ip_bgp_view_neighbor_advertised_route_cmd,
9905 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9906 SHOW_STR
9907 IP_STR
9908 BGP_STR
9909 "BGP view\n"
9910 "View name\n"
9911 "Detailed information on TCP and BGP neighbor connections\n"
9912 "Neighbor to display information about\n"
9913 "Neighbor to display information about\n"
9914 "Display the routes advertised to a BGP neighbor\n")
9915{
9916 struct peer *peer;
9917
9918 if (argc == 2)
9919 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9920 else
9921 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9922
9923 if (! peer)
9924 return CMD_WARNING;
9925
9926 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9927}
9928
9929ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009930 show_ip_bgp_neighbor_advertised_route_cmd,
9931 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9932 SHOW_STR
9933 IP_STR
9934 BGP_STR
9935 "Detailed information on TCP and BGP neighbor connections\n"
9936 "Neighbor to display information about\n"
9937 "Neighbor to display information about\n"
9938 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009939
9940DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9941 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9942 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9943 SHOW_STR
9944 IP_STR
9945 BGP_STR
9946 "Address family\n"
9947 "Address Family modifier\n"
9948 "Address Family modifier\n"
9949 "Detailed information on TCP and BGP neighbor connections\n"
9950 "Neighbor to display information about\n"
9951 "Neighbor to display information about\n"
9952 "Display the routes advertised to a BGP neighbor\n")
9953{
paulbb46e942003-10-24 19:02:03 +00009954 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009955
paulbb46e942003-10-24 19:02:03 +00009956 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9957 if (! peer)
9958 return CMD_WARNING;
9959
9960 if (strncmp (argv[0], "m", 1) == 0)
9961 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9962
9963 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009964}
9965
9966#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009967DEFUN (show_bgp_view_neighbor_advertised_route,
9968 show_bgp_view_neighbor_advertised_route_cmd,
9969 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9970 SHOW_STR
9971 BGP_STR
9972 "BGP view\n"
9973 "View name\n"
9974 "Detailed information on TCP and BGP neighbor connections\n"
9975 "Neighbor to display information about\n"
9976 "Neighbor to display information about\n"
9977 "Display the routes advertised to a BGP neighbor\n")
9978{
9979 struct peer *peer;
9980
9981 if (argc == 2)
9982 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9983 else
9984 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9985
9986 if (! peer)
9987 return CMD_WARNING;
9988
9989 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9990}
9991
9992ALIAS (show_bgp_view_neighbor_advertised_route,
9993 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9994 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9995 SHOW_STR
9996 BGP_STR
9997 "BGP view\n"
9998 "View name\n"
9999 "Address family\n"
10000 "Detailed information on TCP and BGP neighbor connections\n"
10001 "Neighbor to display information about\n"
10002 "Neighbor to display information about\n"
10003 "Display the routes advertised to a BGP neighbor\n")
10004
10005DEFUN (show_bgp_view_neighbor_received_routes,
10006 show_bgp_view_neighbor_received_routes_cmd,
10007 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10008 SHOW_STR
10009 BGP_STR
10010 "BGP view\n"
10011 "View name\n"
10012 "Detailed information on TCP and BGP neighbor connections\n"
10013 "Neighbor to display information about\n"
10014 "Neighbor to display information about\n"
10015 "Display the received routes from neighbor\n")
10016{
10017 struct peer *peer;
10018
10019 if (argc == 2)
10020 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10021 else
10022 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10023
10024 if (! peer)
10025 return CMD_WARNING;
10026
10027 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10028}
10029
10030ALIAS (show_bgp_view_neighbor_received_routes,
10031 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10032 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10033 SHOW_STR
10034 BGP_STR
10035 "BGP view\n"
10036 "View name\n"
10037 "Address family\n"
10038 "Detailed information on TCP and BGP neighbor connections\n"
10039 "Neighbor to display information about\n"
10040 "Neighbor to display information about\n"
10041 "Display the received routes from neighbor\n")
10042
10043ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010044 show_bgp_neighbor_advertised_route_cmd,
10045 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10046 SHOW_STR
10047 BGP_STR
10048 "Detailed information on TCP and BGP neighbor connections\n"
10049 "Neighbor to display information about\n"
10050 "Neighbor to display information about\n"
10051 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010052
10053ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010054 show_bgp_ipv6_neighbor_advertised_route_cmd,
10055 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10056 SHOW_STR
10057 BGP_STR
10058 "Address family\n"
10059 "Detailed information on TCP and BGP neighbor connections\n"
10060 "Neighbor to display information about\n"
10061 "Neighbor to display information about\n"
10062 "Display the routes advertised to a BGP neighbor\n")
10063
10064/* old command */
paulbb46e942003-10-24 19:02:03 +000010065ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010066 ipv6_bgp_neighbor_advertised_route_cmd,
10067 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10068 SHOW_STR
10069 IPV6_STR
10070 BGP_STR
10071 "Detailed information on TCP and BGP neighbor connections\n"
10072 "Neighbor to display information about\n"
10073 "Neighbor to display information about\n"
10074 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010075
paul718e3742002-12-13 20:15:29 +000010076/* old command */
10077DEFUN (ipv6_mbgp_neighbor_advertised_route,
10078 ipv6_mbgp_neighbor_advertised_route_cmd,
10079 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10080 SHOW_STR
10081 IPV6_STR
10082 MBGP_STR
10083 "Detailed information on TCP and BGP neighbor connections\n"
10084 "Neighbor to display information about\n"
10085 "Neighbor to display information about\n"
10086 "Display the routes advertised to a BGP neighbor\n")
10087{
paulbb46e942003-10-24 19:02:03 +000010088 struct peer *peer;
10089
10090 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10091 if (! peer)
10092 return CMD_WARNING;
10093
10094 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010095}
10096#endif /* HAVE_IPV6 */
10097
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010098DEFUN (show_ip_bgp_view_neighbor_received_routes,
10099 show_ip_bgp_view_neighbor_received_routes_cmd,
10100 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10101 SHOW_STR
10102 IP_STR
10103 BGP_STR
10104 "BGP view\n"
10105 "View name\n"
10106 "Detailed information on TCP and BGP neighbor connections\n"
10107 "Neighbor to display information about\n"
10108 "Neighbor to display information about\n"
10109 "Display the received routes from neighbor\n")
10110{
10111 struct peer *peer;
10112
10113 if (argc == 2)
10114 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10115 else
10116 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10117
10118 if (! peer)
10119 return CMD_WARNING;
10120
10121 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10122}
10123
10124ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010125 show_ip_bgp_neighbor_received_routes_cmd,
10126 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10127 SHOW_STR
10128 IP_STR
10129 BGP_STR
10130 "Detailed information on TCP and BGP neighbor connections\n"
10131 "Neighbor to display information about\n"
10132 "Neighbor to display information about\n"
10133 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010134
10135DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10136 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10137 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10138 SHOW_STR
10139 IP_STR
10140 BGP_STR
10141 "Address family\n"
10142 "Address Family modifier\n"
10143 "Address Family modifier\n"
10144 "Detailed information on TCP and BGP neighbor connections\n"
10145 "Neighbor to display information about\n"
10146 "Neighbor to display information about\n"
10147 "Display the received routes from neighbor\n")
10148{
paulbb46e942003-10-24 19:02:03 +000010149 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010150
paulbb46e942003-10-24 19:02:03 +000010151 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10152 if (! peer)
10153 return CMD_WARNING;
10154
10155 if (strncmp (argv[0], "m", 1) == 0)
10156 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10157
10158 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010159}
10160
Michael Lambert95cbbd22010-07-23 14:43:04 -040010161DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10162 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10163#ifdef HAVE_IPV6
10164 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10165#else
10166 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10167#endif
10168 SHOW_STR
10169 BGP_STR
10170 "BGP view\n"
10171 "BGP view name\n"
10172 "Address family\n"
10173#ifdef HAVE_IPV6
10174 "Address family\n"
10175#endif
10176 "Address family modifier\n"
10177 "Address family modifier\n"
10178 "Detailed information on TCP and BGP neighbor connections\n"
10179 "Neighbor to display information about\n"
10180 "Neighbor to display information about\n"
10181 "Display the advertised routes to neighbor\n"
10182 "Display the received routes from neighbor\n")
10183{
10184 int afi;
10185 int safi;
10186 int in;
10187 struct peer *peer;
10188
10189#ifdef HAVE_IPV6
10190 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10191#else
10192 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10193#endif
10194
10195 if (! peer)
10196 return CMD_WARNING;
10197
10198#ifdef HAVE_IPV6
10199 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10200 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10201 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10202#else
10203 afi = AFI_IP;
10204 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10205 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10206#endif
10207
10208 return peer_adj_routes (vty, peer, afi, safi, in);
10209}
10210
paul718e3742002-12-13 20:15:29 +000010211DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10212 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10213 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10214 SHOW_STR
10215 IP_STR
10216 BGP_STR
10217 "Detailed information on TCP and BGP neighbor connections\n"
10218 "Neighbor to display information about\n"
10219 "Neighbor to display information about\n"
10220 "Display information received from a BGP neighbor\n"
10221 "Display the prefixlist filter\n")
10222{
10223 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010224 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010225 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010226 int count, ret;
paul718e3742002-12-13 20:15:29 +000010227
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010228 ret = str2sockunion (argv[0], &su);
10229 if (ret < 0)
10230 {
10231 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10232 return CMD_WARNING;
10233 }
paul718e3742002-12-13 20:15:29 +000010234
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010235 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010236 if (! peer)
10237 return CMD_WARNING;
10238
10239 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10240 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10241 if (count)
10242 {
10243 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10244 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10245 }
10246
10247 return CMD_SUCCESS;
10248}
10249
10250DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10251 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10252 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10253 SHOW_STR
10254 IP_STR
10255 BGP_STR
10256 "Address family\n"
10257 "Address Family modifier\n"
10258 "Address Family modifier\n"
10259 "Detailed information on TCP and BGP neighbor connections\n"
10260 "Neighbor to display information about\n"
10261 "Neighbor to display information about\n"
10262 "Display information received from a BGP neighbor\n"
10263 "Display the prefixlist filter\n")
10264{
10265 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010266 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010267 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010268 int count, ret;
paul718e3742002-12-13 20:15:29 +000010269
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010270 ret = str2sockunion (argv[1], &su);
10271 if (ret < 0)
10272 {
10273 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10274 return CMD_WARNING;
10275 }
paul718e3742002-12-13 20:15:29 +000010276
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010277 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010278 if (! peer)
10279 return CMD_WARNING;
10280
10281 if (strncmp (argv[0], "m", 1) == 0)
10282 {
10283 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10284 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10285 if (count)
10286 {
10287 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10288 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10289 }
10290 }
10291 else
10292 {
10293 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10294 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10295 if (count)
10296 {
10297 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10298 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10299 }
10300 }
10301
10302 return CMD_SUCCESS;
10303}
10304
10305
10306#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010307ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010308 show_bgp_neighbor_received_routes_cmd,
10309 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10310 SHOW_STR
10311 BGP_STR
10312 "Detailed information on TCP and BGP neighbor connections\n"
10313 "Neighbor to display information about\n"
10314 "Neighbor to display information about\n"
10315 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010316
paulbb46e942003-10-24 19:02:03 +000010317ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010318 show_bgp_ipv6_neighbor_received_routes_cmd,
10319 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10320 SHOW_STR
10321 BGP_STR
10322 "Address family\n"
10323 "Detailed information on TCP and BGP neighbor connections\n"
10324 "Neighbor to display information about\n"
10325 "Neighbor to display information about\n"
10326 "Display the received routes from neighbor\n")
10327
10328DEFUN (show_bgp_neighbor_received_prefix_filter,
10329 show_bgp_neighbor_received_prefix_filter_cmd,
10330 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10331 SHOW_STR
10332 BGP_STR
10333 "Detailed information on TCP and BGP neighbor connections\n"
10334 "Neighbor to display information about\n"
10335 "Neighbor to display information about\n"
10336 "Display information received from a BGP neighbor\n"
10337 "Display the prefixlist filter\n")
10338{
10339 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010340 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010341 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010342 int count, ret;
paul718e3742002-12-13 20:15:29 +000010343
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010344 ret = str2sockunion (argv[0], &su);
10345 if (ret < 0)
10346 {
10347 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10348 return CMD_WARNING;
10349 }
paul718e3742002-12-13 20:15:29 +000010350
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010351 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010352 if (! peer)
10353 return CMD_WARNING;
10354
10355 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10356 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10357 if (count)
10358 {
10359 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10360 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10361 }
10362
10363 return CMD_SUCCESS;
10364}
10365
10366ALIAS (show_bgp_neighbor_received_prefix_filter,
10367 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10368 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10369 SHOW_STR
10370 BGP_STR
10371 "Address family\n"
10372 "Detailed information on TCP and BGP neighbor connections\n"
10373 "Neighbor to display information about\n"
10374 "Neighbor to display information about\n"
10375 "Display information received from a BGP neighbor\n"
10376 "Display the prefixlist filter\n")
10377
10378/* old command */
paulbb46e942003-10-24 19:02:03 +000010379ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010380 ipv6_bgp_neighbor_received_routes_cmd,
10381 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10382 SHOW_STR
10383 IPV6_STR
10384 BGP_STR
10385 "Detailed information on TCP and BGP neighbor connections\n"
10386 "Neighbor to display information about\n"
10387 "Neighbor to display information about\n"
10388 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010389
10390/* old command */
10391DEFUN (ipv6_mbgp_neighbor_received_routes,
10392 ipv6_mbgp_neighbor_received_routes_cmd,
10393 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10394 SHOW_STR
10395 IPV6_STR
10396 MBGP_STR
10397 "Detailed information on TCP and BGP neighbor connections\n"
10398 "Neighbor to display information about\n"
10399 "Neighbor to display information about\n"
10400 "Display the received routes from neighbor\n")
10401{
paulbb46e942003-10-24 19:02:03 +000010402 struct peer *peer;
10403
10404 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10405 if (! peer)
10406 return CMD_WARNING;
10407
10408 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010409}
paulbb46e942003-10-24 19:02:03 +000010410
10411DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10412 show_bgp_view_neighbor_received_prefix_filter_cmd,
10413 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10414 SHOW_STR
10415 BGP_STR
10416 "BGP view\n"
10417 "View name\n"
10418 "Detailed information on TCP and BGP neighbor connections\n"
10419 "Neighbor to display information about\n"
10420 "Neighbor to display information about\n"
10421 "Display information received from a BGP neighbor\n"
10422 "Display the prefixlist filter\n")
10423{
10424 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010425 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010426 struct peer *peer;
10427 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010428 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010429
10430 /* BGP structure lookup. */
10431 bgp = bgp_lookup_by_name (argv[0]);
10432 if (bgp == NULL)
10433 {
10434 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10435 return CMD_WARNING;
10436 }
10437
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010438 ret = str2sockunion (argv[1], &su);
10439 if (ret < 0)
10440 {
10441 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10442 return CMD_WARNING;
10443 }
paulbb46e942003-10-24 19:02:03 +000010444
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010445 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010446 if (! peer)
10447 return CMD_WARNING;
10448
10449 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10450 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10451 if (count)
10452 {
10453 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10454 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10455 }
10456
10457 return CMD_SUCCESS;
10458}
10459
10460ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10461 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10462 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10463 SHOW_STR
10464 BGP_STR
10465 "BGP view\n"
10466 "View name\n"
10467 "Address family\n"
10468 "Detailed information on TCP and BGP neighbor connections\n"
10469 "Neighbor to display information about\n"
10470 "Neighbor to display information about\n"
10471 "Display information received from a BGP neighbor\n"
10472 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010473#endif /* HAVE_IPV6 */
10474
paul94f2b392005-06-28 12:44:16 +000010475static int
paulbb46e942003-10-24 19:02:03 +000010476bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010477 safi_t safi, enum bgp_show_type type)
10478{
paul718e3742002-12-13 20:15:29 +000010479 if (! peer || ! peer->afc[afi][safi])
10480 {
10481 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010482 return CMD_WARNING;
10483 }
10484
ajs5a646652004-11-05 01:25:55 +000010485 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010486}
10487
10488DEFUN (show_ip_bgp_neighbor_routes,
10489 show_ip_bgp_neighbor_routes_cmd,
10490 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10491 SHOW_STR
10492 IP_STR
10493 BGP_STR
10494 "Detailed information on TCP and BGP neighbor connections\n"
10495 "Neighbor to display information about\n"
10496 "Neighbor to display information about\n"
10497 "Display routes learned from neighbor\n")
10498{
paulbb46e942003-10-24 19:02:03 +000010499 struct peer *peer;
10500
10501 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10502 if (! peer)
10503 return CMD_WARNING;
10504
10505 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010506 bgp_show_type_neighbor);
10507}
10508
10509DEFUN (show_ip_bgp_neighbor_flap,
10510 show_ip_bgp_neighbor_flap_cmd,
10511 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10512 SHOW_STR
10513 IP_STR
10514 BGP_STR
10515 "Detailed information on TCP and BGP neighbor connections\n"
10516 "Neighbor to display information about\n"
10517 "Neighbor to display information about\n"
10518 "Display flap statistics of the routes learned from neighbor\n")
10519{
paulbb46e942003-10-24 19:02:03 +000010520 struct peer *peer;
10521
10522 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10523 if (! peer)
10524 return CMD_WARNING;
10525
10526 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010527 bgp_show_type_flap_neighbor);
10528}
10529
10530DEFUN (show_ip_bgp_neighbor_damp,
10531 show_ip_bgp_neighbor_damp_cmd,
10532 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10533 SHOW_STR
10534 IP_STR
10535 BGP_STR
10536 "Detailed information on TCP and BGP neighbor connections\n"
10537 "Neighbor to display information about\n"
10538 "Neighbor to display information about\n"
10539 "Display the dampened routes received from neighbor\n")
10540{
paulbb46e942003-10-24 19:02:03 +000010541 struct peer *peer;
10542
10543 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10544 if (! peer)
10545 return CMD_WARNING;
10546
10547 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010548 bgp_show_type_damp_neighbor);
10549}
10550
10551DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10552 show_ip_bgp_ipv4_neighbor_routes_cmd,
10553 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10554 SHOW_STR
10555 IP_STR
10556 BGP_STR
10557 "Address family\n"
10558 "Address Family modifier\n"
10559 "Address Family modifier\n"
10560 "Detailed information on TCP and BGP neighbor connections\n"
10561 "Neighbor to display information about\n"
10562 "Neighbor to display information about\n"
10563 "Display routes learned from neighbor\n")
10564{
paulbb46e942003-10-24 19:02:03 +000010565 struct peer *peer;
10566
10567 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10568 if (! peer)
10569 return CMD_WARNING;
10570
paul718e3742002-12-13 20:15:29 +000010571 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010572 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010573 bgp_show_type_neighbor);
10574
paulbb46e942003-10-24 19:02:03 +000010575 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010576 bgp_show_type_neighbor);
10577}
paulbb46e942003-10-24 19:02:03 +000010578
paulfee0f4c2004-09-13 05:12:46 +000010579DEFUN (show_ip_bgp_view_rsclient,
10580 show_ip_bgp_view_rsclient_cmd,
10581 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10582 SHOW_STR
10583 IP_STR
10584 BGP_STR
10585 "BGP view\n"
10586 "BGP view name\n"
10587 "Information about Route Server Client\n"
10588 NEIGHBOR_ADDR_STR)
10589{
10590 struct bgp_table *table;
10591 struct peer *peer;
10592
10593 if (argc == 2)
10594 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10595 else
10596 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10597
10598 if (! peer)
10599 return CMD_WARNING;
10600
10601 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10602 {
10603 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10604 VTY_NEWLINE);
10605 return CMD_WARNING;
10606 }
10607
10608 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10609 PEER_FLAG_RSERVER_CLIENT))
10610 {
10611 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10612 VTY_NEWLINE);
10613 return CMD_WARNING;
10614 }
10615
10616 table = peer->rib[AFI_IP][SAFI_UNICAST];
10617
ajs5a646652004-11-05 01:25:55 +000010618 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010619}
10620
10621ALIAS (show_ip_bgp_view_rsclient,
10622 show_ip_bgp_rsclient_cmd,
10623 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10624 SHOW_STR
10625 IP_STR
10626 BGP_STR
10627 "Information about Route Server Client\n"
10628 NEIGHBOR_ADDR_STR)
10629
Michael Lambert95cbbd22010-07-23 14:43:04 -040010630DEFUN (show_bgp_view_ipv4_safi_rsclient,
10631 show_bgp_view_ipv4_safi_rsclient_cmd,
10632 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10633 SHOW_STR
10634 BGP_STR
10635 "BGP view\n"
10636 "BGP view name\n"
10637 "Address family\n"
10638 "Address Family modifier\n"
10639 "Address Family modifier\n"
10640 "Information about Route Server Client\n"
10641 NEIGHBOR_ADDR_STR)
10642{
10643 struct bgp_table *table;
10644 struct peer *peer;
10645 safi_t safi;
10646
10647 if (argc == 3) {
10648 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10649 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10650 } else {
10651 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10652 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10653 }
10654
10655 if (! peer)
10656 return CMD_WARNING;
10657
10658 if (! peer->afc[AFI_IP][safi])
10659 {
10660 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10661 VTY_NEWLINE);
10662 return CMD_WARNING;
10663 }
10664
10665 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10666 PEER_FLAG_RSERVER_CLIENT))
10667 {
10668 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10669 VTY_NEWLINE);
10670 return CMD_WARNING;
10671 }
10672
10673 table = peer->rib[AFI_IP][safi];
10674
10675 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10676}
10677
10678ALIAS (show_bgp_view_ipv4_safi_rsclient,
10679 show_bgp_ipv4_safi_rsclient_cmd,
10680 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10681 SHOW_STR
10682 BGP_STR
10683 "Address family\n"
10684 "Address Family modifier\n"
10685 "Address Family modifier\n"
10686 "Information about Route Server Client\n"
10687 NEIGHBOR_ADDR_STR)
10688
paulfee0f4c2004-09-13 05:12:46 +000010689DEFUN (show_ip_bgp_view_rsclient_route,
10690 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010691 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010692 SHOW_STR
10693 IP_STR
10694 BGP_STR
10695 "BGP view\n"
10696 "BGP view name\n"
10697 "Information about Route Server Client\n"
10698 NEIGHBOR_ADDR_STR
10699 "Network in the BGP routing table to display\n")
10700{
10701 struct bgp *bgp;
10702 struct peer *peer;
10703
10704 /* BGP structure lookup. */
10705 if (argc == 3)
10706 {
10707 bgp = bgp_lookup_by_name (argv[0]);
10708 if (bgp == NULL)
10709 {
10710 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10711 return CMD_WARNING;
10712 }
10713 }
10714 else
10715 {
10716 bgp = bgp_get_default ();
10717 if (bgp == NULL)
10718 {
10719 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10720 return CMD_WARNING;
10721 }
10722 }
10723
10724 if (argc == 3)
10725 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10726 else
10727 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10728
10729 if (! peer)
10730 return CMD_WARNING;
10731
10732 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10733 {
10734 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10735 VTY_NEWLINE);
10736 return CMD_WARNING;
10737}
10738
10739 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10740 PEER_FLAG_RSERVER_CLIENT))
10741 {
10742 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10743 VTY_NEWLINE);
10744 return CMD_WARNING;
10745 }
10746
10747 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10748 (argc == 3) ? argv[2] : argv[1],
10749 AFI_IP, SAFI_UNICAST, NULL, 0);
10750}
10751
10752ALIAS (show_ip_bgp_view_rsclient_route,
10753 show_ip_bgp_rsclient_route_cmd,
10754 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10755 SHOW_STR
10756 IP_STR
10757 BGP_STR
10758 "Information about Route Server Client\n"
10759 NEIGHBOR_ADDR_STR
10760 "Network in the BGP routing table to display\n")
10761
Michael Lambert95cbbd22010-07-23 14:43:04 -040010762DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10763 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10764 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10765 SHOW_STR
10766 BGP_STR
10767 "BGP view\n"
10768 "BGP view name\n"
10769 "Address family\n"
10770 "Address Family modifier\n"
10771 "Address Family modifier\n"
10772 "Information about Route Server Client\n"
10773 NEIGHBOR_ADDR_STR
10774 "Network in the BGP routing table to display\n")
10775{
10776 struct bgp *bgp;
10777 struct peer *peer;
10778 safi_t safi;
10779
10780 /* BGP structure lookup. */
10781 if (argc == 4)
10782 {
10783 bgp = bgp_lookup_by_name (argv[0]);
10784 if (bgp == NULL)
10785 {
10786 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10787 return CMD_WARNING;
10788 }
10789 }
10790 else
10791 {
10792 bgp = bgp_get_default ();
10793 if (bgp == NULL)
10794 {
10795 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10796 return CMD_WARNING;
10797 }
10798 }
10799
10800 if (argc == 4) {
10801 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10802 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10803 } else {
10804 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10805 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10806 }
10807
10808 if (! peer)
10809 return CMD_WARNING;
10810
10811 if (! peer->afc[AFI_IP][safi])
10812 {
10813 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10814 VTY_NEWLINE);
10815 return CMD_WARNING;
10816}
10817
10818 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10819 PEER_FLAG_RSERVER_CLIENT))
10820 {
10821 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10822 VTY_NEWLINE);
10823 return CMD_WARNING;
10824 }
10825
10826 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10827 (argc == 4) ? argv[3] : argv[2],
10828 AFI_IP, safi, NULL, 0);
10829}
10830
10831ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10832 show_bgp_ipv4_safi_rsclient_route_cmd,
10833 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10834 SHOW_STR
10835 BGP_STR
10836 "Address family\n"
10837 "Address Family modifier\n"
10838 "Address Family modifier\n"
10839 "Information about Route Server Client\n"
10840 NEIGHBOR_ADDR_STR
10841 "Network in the BGP routing table to display\n")
10842
paulfee0f4c2004-09-13 05:12:46 +000010843DEFUN (show_ip_bgp_view_rsclient_prefix,
10844 show_ip_bgp_view_rsclient_prefix_cmd,
10845 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10846 SHOW_STR
10847 IP_STR
10848 BGP_STR
10849 "BGP view\n"
10850 "BGP view name\n"
10851 "Information about Route Server Client\n"
10852 NEIGHBOR_ADDR_STR
10853 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10854{
10855 struct bgp *bgp;
10856 struct peer *peer;
10857
10858 /* BGP structure lookup. */
10859 if (argc == 3)
10860 {
10861 bgp = bgp_lookup_by_name (argv[0]);
10862 if (bgp == NULL)
10863 {
10864 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10865 return CMD_WARNING;
10866 }
10867 }
10868 else
10869 {
10870 bgp = bgp_get_default ();
10871 if (bgp == NULL)
10872 {
10873 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10874 return CMD_WARNING;
10875 }
10876 }
10877
10878 if (argc == 3)
10879 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10880 else
10881 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10882
10883 if (! peer)
10884 return CMD_WARNING;
10885
10886 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10887 {
10888 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10889 VTY_NEWLINE);
10890 return CMD_WARNING;
10891}
10892
10893 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10894 PEER_FLAG_RSERVER_CLIENT))
10895{
10896 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10897 VTY_NEWLINE);
10898 return CMD_WARNING;
10899 }
10900
10901 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10902 (argc == 3) ? argv[2] : argv[1],
10903 AFI_IP, SAFI_UNICAST, NULL, 1);
10904}
10905
10906ALIAS (show_ip_bgp_view_rsclient_prefix,
10907 show_ip_bgp_rsclient_prefix_cmd,
10908 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10909 SHOW_STR
10910 IP_STR
10911 BGP_STR
10912 "Information about Route Server Client\n"
10913 NEIGHBOR_ADDR_STR
10914 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10915
Michael Lambert95cbbd22010-07-23 14:43:04 -040010916DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10917 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10918 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10919 SHOW_STR
10920 BGP_STR
10921 "BGP view\n"
10922 "BGP view name\n"
10923 "Address family\n"
10924 "Address Family modifier\n"
10925 "Address Family modifier\n"
10926 "Information about Route Server Client\n"
10927 NEIGHBOR_ADDR_STR
10928 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10929{
10930 struct bgp *bgp;
10931 struct peer *peer;
10932 safi_t safi;
10933
10934 /* BGP structure lookup. */
10935 if (argc == 4)
10936 {
10937 bgp = bgp_lookup_by_name (argv[0]);
10938 if (bgp == NULL)
10939 {
10940 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10941 return CMD_WARNING;
10942 }
10943 }
10944 else
10945 {
10946 bgp = bgp_get_default ();
10947 if (bgp == NULL)
10948 {
10949 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10950 return CMD_WARNING;
10951 }
10952 }
10953
10954 if (argc == 4) {
10955 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10956 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10957 } else {
10958 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10959 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10960 }
10961
10962 if (! peer)
10963 return CMD_WARNING;
10964
10965 if (! peer->afc[AFI_IP][safi])
10966 {
10967 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10968 VTY_NEWLINE);
10969 return CMD_WARNING;
10970}
10971
10972 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10973 PEER_FLAG_RSERVER_CLIENT))
10974{
10975 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10976 VTY_NEWLINE);
10977 return CMD_WARNING;
10978 }
10979
10980 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10981 (argc == 4) ? argv[3] : argv[2],
10982 AFI_IP, safi, NULL, 1);
10983}
10984
10985ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10986 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10987 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10988 SHOW_STR
10989 BGP_STR
10990 "Address family\n"
10991 "Address Family modifier\n"
10992 "Address Family modifier\n"
10993 "Information about Route Server Client\n"
10994 NEIGHBOR_ADDR_STR
10995 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010996
paul718e3742002-12-13 20:15:29 +000010997#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010998DEFUN (show_bgp_view_neighbor_routes,
10999 show_bgp_view_neighbor_routes_cmd,
11000 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11001 SHOW_STR
11002 BGP_STR
11003 "BGP view\n"
11004 "BGP view name\n"
11005 "Detailed information on TCP and BGP neighbor connections\n"
11006 "Neighbor to display information about\n"
11007 "Neighbor to display information about\n"
11008 "Display routes learned from neighbor\n")
11009{
11010 struct peer *peer;
11011
11012 if (argc == 2)
11013 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11014 else
11015 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11016
11017 if (! peer)
11018 return CMD_WARNING;
11019
11020 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11021 bgp_show_type_neighbor);
11022}
11023
11024ALIAS (show_bgp_view_neighbor_routes,
11025 show_bgp_view_ipv6_neighbor_routes_cmd,
11026 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11027 SHOW_STR
11028 BGP_STR
11029 "BGP view\n"
11030 "BGP view name\n"
11031 "Address family\n"
11032 "Detailed information on TCP and BGP neighbor connections\n"
11033 "Neighbor to display information about\n"
11034 "Neighbor to display information about\n"
11035 "Display routes learned from neighbor\n")
11036
11037DEFUN (show_bgp_view_neighbor_damp,
11038 show_bgp_view_neighbor_damp_cmd,
11039 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11040 SHOW_STR
11041 BGP_STR
11042 "BGP view\n"
11043 "BGP view name\n"
11044 "Detailed information on TCP and BGP neighbor connections\n"
11045 "Neighbor to display information about\n"
11046 "Neighbor to display information about\n"
11047 "Display the dampened routes received from neighbor\n")
11048{
11049 struct peer *peer;
11050
11051 if (argc == 2)
11052 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11053 else
11054 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11055
11056 if (! peer)
11057 return CMD_WARNING;
11058
11059 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11060 bgp_show_type_damp_neighbor);
11061}
11062
11063ALIAS (show_bgp_view_neighbor_damp,
11064 show_bgp_view_ipv6_neighbor_damp_cmd,
11065 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11066 SHOW_STR
11067 BGP_STR
11068 "BGP view\n"
11069 "BGP view name\n"
11070 "Address family\n"
11071 "Detailed information on TCP and BGP neighbor connections\n"
11072 "Neighbor to display information about\n"
11073 "Neighbor to display information about\n"
11074 "Display the dampened routes received from neighbor\n")
11075
11076DEFUN (show_bgp_view_neighbor_flap,
11077 show_bgp_view_neighbor_flap_cmd,
11078 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11079 SHOW_STR
11080 BGP_STR
11081 "BGP view\n"
11082 "BGP view name\n"
11083 "Detailed information on TCP and BGP neighbor connections\n"
11084 "Neighbor to display information about\n"
11085 "Neighbor to display information about\n"
11086 "Display flap statistics of the routes learned from neighbor\n")
11087{
11088 struct peer *peer;
11089
11090 if (argc == 2)
11091 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11092 else
11093 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11094
11095 if (! peer)
11096 return CMD_WARNING;
11097
11098 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11099 bgp_show_type_flap_neighbor);
11100}
11101
11102ALIAS (show_bgp_view_neighbor_flap,
11103 show_bgp_view_ipv6_neighbor_flap_cmd,
11104 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11105 SHOW_STR
11106 BGP_STR
11107 "BGP view\n"
11108 "BGP view name\n"
11109 "Address family\n"
11110 "Detailed information on TCP and BGP neighbor connections\n"
11111 "Neighbor to display information about\n"
11112 "Neighbor to display information about\n"
11113 "Display flap statistics of the routes learned from neighbor\n")
11114
11115ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011116 show_bgp_neighbor_routes_cmd,
11117 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11118 SHOW_STR
11119 BGP_STR
11120 "Detailed information on TCP and BGP neighbor connections\n"
11121 "Neighbor to display information about\n"
11122 "Neighbor to display information about\n"
11123 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011124
paulbb46e942003-10-24 19:02:03 +000011125
11126ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011127 show_bgp_ipv6_neighbor_routes_cmd,
11128 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11129 SHOW_STR
11130 BGP_STR
11131 "Address family\n"
11132 "Detailed information on TCP and BGP neighbor connections\n"
11133 "Neighbor to display information about\n"
11134 "Neighbor to display information about\n"
11135 "Display routes learned from neighbor\n")
11136
11137/* old command */
paulbb46e942003-10-24 19:02:03 +000011138ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011139 ipv6_bgp_neighbor_routes_cmd,
11140 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11141 SHOW_STR
11142 IPV6_STR
11143 BGP_STR
11144 "Detailed information on TCP and BGP neighbor connections\n"
11145 "Neighbor to display information about\n"
11146 "Neighbor to display information about\n"
11147 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011148
11149/* old command */
11150DEFUN (ipv6_mbgp_neighbor_routes,
11151 ipv6_mbgp_neighbor_routes_cmd,
11152 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11153 SHOW_STR
11154 IPV6_STR
11155 MBGP_STR
11156 "Detailed information on TCP and BGP neighbor connections\n"
11157 "Neighbor to display information about\n"
11158 "Neighbor to display information about\n"
11159 "Display routes learned from neighbor\n")
11160{
paulbb46e942003-10-24 19:02:03 +000011161 struct peer *peer;
11162
11163 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11164 if (! peer)
11165 return CMD_WARNING;
11166
11167 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011168 bgp_show_type_neighbor);
11169}
paulbb46e942003-10-24 19:02:03 +000011170
11171ALIAS (show_bgp_view_neighbor_flap,
11172 show_bgp_neighbor_flap_cmd,
11173 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11174 SHOW_STR
11175 BGP_STR
11176 "Detailed information on TCP and BGP neighbor connections\n"
11177 "Neighbor to display information about\n"
11178 "Neighbor to display information about\n"
11179 "Display flap statistics of the routes learned from neighbor\n")
11180
11181ALIAS (show_bgp_view_neighbor_flap,
11182 show_bgp_ipv6_neighbor_flap_cmd,
11183 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11184 SHOW_STR
11185 BGP_STR
11186 "Address family\n"
11187 "Detailed information on TCP and BGP neighbor connections\n"
11188 "Neighbor to display information about\n"
11189 "Neighbor to display information about\n"
11190 "Display flap statistics of the routes learned from neighbor\n")
11191
11192ALIAS (show_bgp_view_neighbor_damp,
11193 show_bgp_neighbor_damp_cmd,
11194 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11195 SHOW_STR
11196 BGP_STR
11197 "Detailed information on TCP and BGP neighbor connections\n"
11198 "Neighbor to display information about\n"
11199 "Neighbor to display information about\n"
11200 "Display the dampened routes received from neighbor\n")
11201
11202ALIAS (show_bgp_view_neighbor_damp,
11203 show_bgp_ipv6_neighbor_damp_cmd,
11204 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11205 SHOW_STR
11206 BGP_STR
11207 "Address family\n"
11208 "Detailed information on TCP and BGP neighbor connections\n"
11209 "Neighbor to display information about\n"
11210 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011211 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011212
11213DEFUN (show_bgp_view_rsclient,
11214 show_bgp_view_rsclient_cmd,
11215 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11216 SHOW_STR
11217 BGP_STR
11218 "BGP view\n"
11219 "BGP view name\n"
11220 "Information about Route Server Client\n"
11221 NEIGHBOR_ADDR_STR)
11222{
11223 struct bgp_table *table;
11224 struct peer *peer;
11225
11226 if (argc == 2)
11227 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11228 else
11229 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11230
11231 if (! peer)
11232 return CMD_WARNING;
11233
11234 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11235 {
11236 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11237 VTY_NEWLINE);
11238 return CMD_WARNING;
11239 }
11240
11241 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11242 PEER_FLAG_RSERVER_CLIENT))
11243 {
11244 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11245 VTY_NEWLINE);
11246 return CMD_WARNING;
11247 }
11248
11249 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11250
ajs5a646652004-11-05 01:25:55 +000011251 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011252}
11253
11254ALIAS (show_bgp_view_rsclient,
11255 show_bgp_rsclient_cmd,
11256 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11257 SHOW_STR
11258 BGP_STR
11259 "Information about Route Server Client\n"
11260 NEIGHBOR_ADDR_STR)
11261
Michael Lambert95cbbd22010-07-23 14:43:04 -040011262DEFUN (show_bgp_view_ipv6_safi_rsclient,
11263 show_bgp_view_ipv6_safi_rsclient_cmd,
11264 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11265 SHOW_STR
11266 BGP_STR
11267 "BGP view\n"
11268 "BGP view name\n"
11269 "Address family\n"
11270 "Address Family modifier\n"
11271 "Address Family modifier\n"
11272 "Information about Route Server Client\n"
11273 NEIGHBOR_ADDR_STR)
11274{
11275 struct bgp_table *table;
11276 struct peer *peer;
11277 safi_t safi;
11278
11279 if (argc == 3) {
11280 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11281 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11282 } else {
11283 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11284 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11285 }
11286
11287 if (! peer)
11288 return CMD_WARNING;
11289
11290 if (! peer->afc[AFI_IP6][safi])
11291 {
11292 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11293 VTY_NEWLINE);
11294 return CMD_WARNING;
11295 }
11296
11297 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11298 PEER_FLAG_RSERVER_CLIENT))
11299 {
11300 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11301 VTY_NEWLINE);
11302 return CMD_WARNING;
11303 }
11304
11305 table = peer->rib[AFI_IP6][safi];
11306
11307 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11308}
11309
11310ALIAS (show_bgp_view_ipv6_safi_rsclient,
11311 show_bgp_ipv6_safi_rsclient_cmd,
11312 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11313 SHOW_STR
11314 BGP_STR
11315 "Address family\n"
11316 "Address Family modifier\n"
11317 "Address Family modifier\n"
11318 "Information about Route Server Client\n"
11319 NEIGHBOR_ADDR_STR)
11320
paulfee0f4c2004-09-13 05:12:46 +000011321DEFUN (show_bgp_view_rsclient_route,
11322 show_bgp_view_rsclient_route_cmd,
11323 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11324 SHOW_STR
11325 BGP_STR
11326 "BGP view\n"
11327 "BGP view name\n"
11328 "Information about Route Server Client\n"
11329 NEIGHBOR_ADDR_STR
11330 "Network in the BGP routing table to display\n")
11331{
11332 struct bgp *bgp;
11333 struct peer *peer;
11334
11335 /* BGP structure lookup. */
11336 if (argc == 3)
11337 {
11338 bgp = bgp_lookup_by_name (argv[0]);
11339 if (bgp == NULL)
11340 {
11341 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11342 return CMD_WARNING;
11343 }
11344 }
11345 else
11346 {
11347 bgp = bgp_get_default ();
11348 if (bgp == NULL)
11349 {
11350 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11351 return CMD_WARNING;
11352 }
11353 }
11354
11355 if (argc == 3)
11356 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11357 else
11358 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11359
11360 if (! peer)
11361 return CMD_WARNING;
11362
11363 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11364 {
11365 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11366 VTY_NEWLINE);
11367 return CMD_WARNING;
11368 }
11369
11370 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11371 PEER_FLAG_RSERVER_CLIENT))
11372 {
11373 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11374 VTY_NEWLINE);
11375 return CMD_WARNING;
11376 }
11377
11378 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11379 (argc == 3) ? argv[2] : argv[1],
11380 AFI_IP6, SAFI_UNICAST, NULL, 0);
11381}
11382
11383ALIAS (show_bgp_view_rsclient_route,
11384 show_bgp_rsclient_route_cmd,
11385 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11386 SHOW_STR
11387 BGP_STR
11388 "Information about Route Server Client\n"
11389 NEIGHBOR_ADDR_STR
11390 "Network in the BGP routing table to display\n")
11391
Michael Lambert95cbbd22010-07-23 14:43:04 -040011392DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11393 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11394 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11395 SHOW_STR
11396 BGP_STR
11397 "BGP view\n"
11398 "BGP view name\n"
11399 "Address family\n"
11400 "Address Family modifier\n"
11401 "Address Family modifier\n"
11402 "Information about Route Server Client\n"
11403 NEIGHBOR_ADDR_STR
11404 "Network in the BGP routing table to display\n")
11405{
11406 struct bgp *bgp;
11407 struct peer *peer;
11408 safi_t safi;
11409
11410 /* BGP structure lookup. */
11411 if (argc == 4)
11412 {
11413 bgp = bgp_lookup_by_name (argv[0]);
11414 if (bgp == NULL)
11415 {
11416 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11417 return CMD_WARNING;
11418 }
11419 }
11420 else
11421 {
11422 bgp = bgp_get_default ();
11423 if (bgp == NULL)
11424 {
11425 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11426 return CMD_WARNING;
11427 }
11428 }
11429
11430 if (argc == 4) {
11431 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11432 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11433 } else {
11434 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11435 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11436 }
11437
11438 if (! peer)
11439 return CMD_WARNING;
11440
11441 if (! peer->afc[AFI_IP6][safi])
11442 {
11443 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11444 VTY_NEWLINE);
11445 return CMD_WARNING;
11446}
11447
11448 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11449 PEER_FLAG_RSERVER_CLIENT))
11450 {
11451 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11452 VTY_NEWLINE);
11453 return CMD_WARNING;
11454 }
11455
11456 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11457 (argc == 4) ? argv[3] : argv[2],
11458 AFI_IP6, safi, NULL, 0);
11459}
11460
11461ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11462 show_bgp_ipv6_safi_rsclient_route_cmd,
11463 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11464 SHOW_STR
11465 BGP_STR
11466 "Address family\n"
11467 "Address Family modifier\n"
11468 "Address Family modifier\n"
11469 "Information about Route Server Client\n"
11470 NEIGHBOR_ADDR_STR
11471 "Network in the BGP routing table to display\n")
11472
paulfee0f4c2004-09-13 05:12:46 +000011473DEFUN (show_bgp_view_rsclient_prefix,
11474 show_bgp_view_rsclient_prefix_cmd,
11475 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11476 SHOW_STR
11477 BGP_STR
11478 "BGP view\n"
11479 "BGP view name\n"
11480 "Information about Route Server Client\n"
11481 NEIGHBOR_ADDR_STR
11482 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11483{
11484 struct bgp *bgp;
11485 struct peer *peer;
11486
11487 /* BGP structure lookup. */
11488 if (argc == 3)
11489 {
11490 bgp = bgp_lookup_by_name (argv[0]);
11491 if (bgp == NULL)
11492 {
11493 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11494 return CMD_WARNING;
11495 }
11496 }
11497 else
11498 {
11499 bgp = bgp_get_default ();
11500 if (bgp == NULL)
11501 {
11502 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11503 return CMD_WARNING;
11504 }
11505 }
11506
11507 if (argc == 3)
11508 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11509 else
11510 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11511
11512 if (! peer)
11513 return CMD_WARNING;
11514
11515 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11516 {
11517 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11518 VTY_NEWLINE);
11519 return CMD_WARNING;
11520 }
11521
11522 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11523 PEER_FLAG_RSERVER_CLIENT))
11524 {
11525 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11526 VTY_NEWLINE);
11527 return CMD_WARNING;
11528 }
11529
11530 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11531 (argc == 3) ? argv[2] : argv[1],
11532 AFI_IP6, SAFI_UNICAST, NULL, 1);
11533}
11534
11535ALIAS (show_bgp_view_rsclient_prefix,
11536 show_bgp_rsclient_prefix_cmd,
11537 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11538 SHOW_STR
11539 BGP_STR
11540 "Information about Route Server Client\n"
11541 NEIGHBOR_ADDR_STR
11542 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11543
Michael Lambert95cbbd22010-07-23 14:43:04 -040011544DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11545 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11546 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11547 SHOW_STR
11548 BGP_STR
11549 "BGP view\n"
11550 "BGP view name\n"
11551 "Address family\n"
11552 "Address Family modifier\n"
11553 "Address Family modifier\n"
11554 "Information about Route Server Client\n"
11555 NEIGHBOR_ADDR_STR
11556 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11557{
11558 struct bgp *bgp;
11559 struct peer *peer;
11560 safi_t safi;
11561
11562 /* BGP structure lookup. */
11563 if (argc == 4)
11564 {
11565 bgp = bgp_lookup_by_name (argv[0]);
11566 if (bgp == NULL)
11567 {
11568 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11569 return CMD_WARNING;
11570 }
11571 }
11572 else
11573 {
11574 bgp = bgp_get_default ();
11575 if (bgp == NULL)
11576 {
11577 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11578 return CMD_WARNING;
11579 }
11580 }
11581
11582 if (argc == 4) {
11583 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11584 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11585 } else {
11586 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11587 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11588 }
11589
11590 if (! peer)
11591 return CMD_WARNING;
11592
11593 if (! peer->afc[AFI_IP6][safi])
11594 {
11595 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11596 VTY_NEWLINE);
11597 return CMD_WARNING;
11598}
11599
11600 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11601 PEER_FLAG_RSERVER_CLIENT))
11602{
11603 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11604 VTY_NEWLINE);
11605 return CMD_WARNING;
11606 }
11607
11608 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11609 (argc == 4) ? argv[3] : argv[2],
11610 AFI_IP6, safi, NULL, 1);
11611}
11612
11613ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11614 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11615 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11616 SHOW_STR
11617 BGP_STR
11618 "Address family\n"
11619 "Address Family modifier\n"
11620 "Address Family modifier\n"
11621 "Information about Route Server Client\n"
11622 NEIGHBOR_ADDR_STR
11623 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11624
paul718e3742002-12-13 20:15:29 +000011625#endif /* HAVE_IPV6 */
11626
11627struct bgp_table *bgp_distance_table;
11628
11629struct bgp_distance
11630{
11631 /* Distance value for the IP source prefix. */
11632 u_char distance;
11633
11634 /* Name of the access-list to be matched. */
11635 char *access_list;
11636};
11637
paul94f2b392005-06-28 12:44:16 +000011638static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011639bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011640{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011641 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011642}
11643
paul94f2b392005-06-28 12:44:16 +000011644static void
paul718e3742002-12-13 20:15:29 +000011645bgp_distance_free (struct bgp_distance *bdistance)
11646{
11647 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11648}
11649
paul94f2b392005-06-28 12:44:16 +000011650static int
paulfd79ac92004-10-13 05:06:08 +000011651bgp_distance_set (struct vty *vty, const char *distance_str,
11652 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011653{
11654 int ret;
11655 struct prefix_ipv4 p;
11656 u_char distance;
11657 struct bgp_node *rn;
11658 struct bgp_distance *bdistance;
11659
11660 ret = str2prefix_ipv4 (ip_str, &p);
11661 if (ret == 0)
11662 {
11663 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11664 return CMD_WARNING;
11665 }
11666
11667 distance = atoi (distance_str);
11668
11669 /* Get BGP distance node. */
11670 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11671 if (rn->info)
11672 {
11673 bdistance = rn->info;
11674 bgp_unlock_node (rn);
11675 }
11676 else
11677 {
11678 bdistance = bgp_distance_new ();
11679 rn->info = bdistance;
11680 }
11681
11682 /* Set distance value. */
11683 bdistance->distance = distance;
11684
11685 /* Reset access-list configuration. */
11686 if (bdistance->access_list)
11687 {
11688 free (bdistance->access_list);
11689 bdistance->access_list = NULL;
11690 }
11691 if (access_list_str)
11692 bdistance->access_list = strdup (access_list_str);
11693
11694 return CMD_SUCCESS;
11695}
11696
paul94f2b392005-06-28 12:44:16 +000011697static int
paulfd79ac92004-10-13 05:06:08 +000011698bgp_distance_unset (struct vty *vty, const char *distance_str,
11699 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011700{
11701 int ret;
11702 struct prefix_ipv4 p;
11703 u_char distance;
11704 struct bgp_node *rn;
11705 struct bgp_distance *bdistance;
11706
11707 ret = str2prefix_ipv4 (ip_str, &p);
11708 if (ret == 0)
11709 {
11710 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11711 return CMD_WARNING;
11712 }
11713
11714 distance = atoi (distance_str);
11715
11716 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11717 if (! rn)
11718 {
11719 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11720 return CMD_WARNING;
11721 }
11722
11723 bdistance = rn->info;
11724
11725 if (bdistance->access_list)
11726 free (bdistance->access_list);
11727 bgp_distance_free (bdistance);
11728
11729 rn->info = NULL;
11730 bgp_unlock_node (rn);
11731 bgp_unlock_node (rn);
11732
11733 return CMD_SUCCESS;
11734}
11735
paul718e3742002-12-13 20:15:29 +000011736/* Apply BGP information to distance method. */
11737u_char
11738bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11739{
11740 struct bgp_node *rn;
11741 struct prefix_ipv4 q;
11742 struct peer *peer;
11743 struct bgp_distance *bdistance;
11744 struct access_list *alist;
11745 struct bgp_static *bgp_static;
11746
11747 if (! bgp)
11748 return 0;
11749
11750 if (p->family != AF_INET)
11751 return 0;
11752
11753 peer = rinfo->peer;
11754
11755 if (peer->su.sa.sa_family != AF_INET)
11756 return 0;
11757
11758 memset (&q, 0, sizeof (struct prefix_ipv4));
11759 q.family = AF_INET;
11760 q.prefix = peer->su.sin.sin_addr;
11761 q.prefixlen = IPV4_MAX_BITLEN;
11762
11763 /* Check source address. */
11764 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11765 if (rn)
11766 {
11767 bdistance = rn->info;
11768 bgp_unlock_node (rn);
11769
11770 if (bdistance->access_list)
11771 {
11772 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11773 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11774 return bdistance->distance;
11775 }
11776 else
11777 return bdistance->distance;
11778 }
11779
11780 /* Backdoor check. */
11781 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11782 if (rn)
11783 {
11784 bgp_static = rn->info;
11785 bgp_unlock_node (rn);
11786
11787 if (bgp_static->backdoor)
11788 {
11789 if (bgp->distance_local)
11790 return bgp->distance_local;
11791 else
11792 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11793 }
11794 }
11795
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011796 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011797 {
11798 if (bgp->distance_ebgp)
11799 return bgp->distance_ebgp;
11800 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11801 }
11802 else
11803 {
11804 if (bgp->distance_ibgp)
11805 return bgp->distance_ibgp;
11806 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11807 }
11808}
11809
11810DEFUN (bgp_distance,
11811 bgp_distance_cmd,
11812 "distance bgp <1-255> <1-255> <1-255>",
11813 "Define an administrative distance\n"
11814 "BGP distance\n"
11815 "Distance for routes external to the AS\n"
11816 "Distance for routes internal to the AS\n"
11817 "Distance for local routes\n")
11818{
11819 struct bgp *bgp;
11820
11821 bgp = vty->index;
11822
11823 bgp->distance_ebgp = atoi (argv[0]);
11824 bgp->distance_ibgp = atoi (argv[1]);
11825 bgp->distance_local = atoi (argv[2]);
11826 return CMD_SUCCESS;
11827}
11828
11829DEFUN (no_bgp_distance,
11830 no_bgp_distance_cmd,
11831 "no distance bgp <1-255> <1-255> <1-255>",
11832 NO_STR
11833 "Define an administrative distance\n"
11834 "BGP distance\n"
11835 "Distance for routes external to the AS\n"
11836 "Distance for routes internal to the AS\n"
11837 "Distance for local routes\n")
11838{
11839 struct bgp *bgp;
11840
11841 bgp = vty->index;
11842
11843 bgp->distance_ebgp= 0;
11844 bgp->distance_ibgp = 0;
11845 bgp->distance_local = 0;
11846 return CMD_SUCCESS;
11847}
11848
11849ALIAS (no_bgp_distance,
11850 no_bgp_distance2_cmd,
11851 "no distance bgp",
11852 NO_STR
11853 "Define an administrative distance\n"
11854 "BGP distance\n")
11855
11856DEFUN (bgp_distance_source,
11857 bgp_distance_source_cmd,
11858 "distance <1-255> A.B.C.D/M",
11859 "Define an administrative distance\n"
11860 "Administrative distance\n"
11861 "IP source prefix\n")
11862{
11863 bgp_distance_set (vty, argv[0], argv[1], NULL);
11864 return CMD_SUCCESS;
11865}
11866
11867DEFUN (no_bgp_distance_source,
11868 no_bgp_distance_source_cmd,
11869 "no distance <1-255> A.B.C.D/M",
11870 NO_STR
11871 "Define an administrative distance\n"
11872 "Administrative distance\n"
11873 "IP source prefix\n")
11874{
11875 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11876 return CMD_SUCCESS;
11877}
11878
11879DEFUN (bgp_distance_source_access_list,
11880 bgp_distance_source_access_list_cmd,
11881 "distance <1-255> A.B.C.D/M WORD",
11882 "Define an administrative distance\n"
11883 "Administrative distance\n"
11884 "IP source prefix\n"
11885 "Access list name\n")
11886{
11887 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11888 return CMD_SUCCESS;
11889}
11890
11891DEFUN (no_bgp_distance_source_access_list,
11892 no_bgp_distance_source_access_list_cmd,
11893 "no distance <1-255> A.B.C.D/M WORD",
11894 NO_STR
11895 "Define an administrative distance\n"
11896 "Administrative distance\n"
11897 "IP source prefix\n"
11898 "Access list name\n")
11899{
11900 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11901 return CMD_SUCCESS;
11902}
11903
11904DEFUN (bgp_damp_set,
11905 bgp_damp_set_cmd,
11906 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11907 "BGP Specific commands\n"
11908 "Enable route-flap dampening\n"
11909 "Half-life time for the penalty\n"
11910 "Value to start reusing a route\n"
11911 "Value to start suppressing a route\n"
11912 "Maximum duration to suppress a stable route\n")
11913{
11914 struct bgp *bgp;
11915 int half = DEFAULT_HALF_LIFE * 60;
11916 int reuse = DEFAULT_REUSE;
11917 int suppress = DEFAULT_SUPPRESS;
11918 int max = 4 * half;
11919
11920 if (argc == 4)
11921 {
11922 half = atoi (argv[0]) * 60;
11923 reuse = atoi (argv[1]);
11924 suppress = atoi (argv[2]);
11925 max = atoi (argv[3]) * 60;
11926 }
11927 else if (argc == 1)
11928 {
11929 half = atoi (argv[0]) * 60;
11930 max = 4 * half;
11931 }
11932
11933 bgp = vty->index;
11934 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11935 half, reuse, suppress, max);
11936}
11937
11938ALIAS (bgp_damp_set,
11939 bgp_damp_set2_cmd,
11940 "bgp dampening <1-45>",
11941 "BGP Specific commands\n"
11942 "Enable route-flap dampening\n"
11943 "Half-life time for the penalty\n")
11944
11945ALIAS (bgp_damp_set,
11946 bgp_damp_set3_cmd,
11947 "bgp dampening",
11948 "BGP Specific commands\n"
11949 "Enable route-flap dampening\n")
11950
11951DEFUN (bgp_damp_unset,
11952 bgp_damp_unset_cmd,
11953 "no bgp dampening",
11954 NO_STR
11955 "BGP Specific commands\n"
11956 "Enable route-flap dampening\n")
11957{
11958 struct bgp *bgp;
11959
11960 bgp = vty->index;
11961 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11962}
11963
11964ALIAS (bgp_damp_unset,
11965 bgp_damp_unset2_cmd,
11966 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11967 NO_STR
11968 "BGP Specific commands\n"
11969 "Enable route-flap dampening\n"
11970 "Half-life time for the penalty\n"
11971 "Value to start reusing a route\n"
11972 "Value to start suppressing a route\n"
11973 "Maximum duration to suppress a stable route\n")
11974
11975DEFUN (show_ip_bgp_dampened_paths,
11976 show_ip_bgp_dampened_paths_cmd,
11977 "show ip bgp dampened-paths",
11978 SHOW_STR
11979 IP_STR
11980 BGP_STR
11981 "Display paths suppressed due to dampening\n")
11982{
ajs5a646652004-11-05 01:25:55 +000011983 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11984 NULL);
paul718e3742002-12-13 20:15:29 +000011985}
11986
11987DEFUN (show_ip_bgp_flap_statistics,
11988 show_ip_bgp_flap_statistics_cmd,
11989 "show ip bgp flap-statistics",
11990 SHOW_STR
11991 IP_STR
11992 BGP_STR
11993 "Display flap statistics of routes\n")
11994{
ajs5a646652004-11-05 01:25:55 +000011995 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11996 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011997}
11998
11999/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012000static int
paulfd79ac92004-10-13 05:06:08 +000012001bgp_clear_damp_route (struct vty *vty, const char *view_name,
12002 const char *ip_str, afi_t afi, safi_t safi,
12003 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012004{
12005 int ret;
12006 struct prefix match;
12007 struct bgp_node *rn;
12008 struct bgp_node *rm;
12009 struct bgp_info *ri;
12010 struct bgp_info *ri_temp;
12011 struct bgp *bgp;
12012 struct bgp_table *table;
12013
12014 /* BGP structure lookup. */
12015 if (view_name)
12016 {
12017 bgp = bgp_lookup_by_name (view_name);
12018 if (bgp == NULL)
12019 {
12020 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12021 return CMD_WARNING;
12022 }
12023 }
12024 else
12025 {
12026 bgp = bgp_get_default ();
12027 if (bgp == NULL)
12028 {
12029 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12030 return CMD_WARNING;
12031 }
12032 }
12033
12034 /* Check IP address argument. */
12035 ret = str2prefix (ip_str, &match);
12036 if (! ret)
12037 {
12038 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12039 return CMD_WARNING;
12040 }
12041
12042 match.family = afi2family (afi);
12043
12044 if (safi == SAFI_MPLS_VPN)
12045 {
12046 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12047 {
12048 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12049 continue;
12050
12051 if ((table = rn->info) != NULL)
12052 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012053 {
12054 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12055 {
12056 ri = rm->info;
12057 while (ri)
12058 {
12059 if (ri->extra && ri->extra->damp_info)
12060 {
12061 ri_temp = ri->next;
12062 bgp_damp_info_free (ri->extra->damp_info, 1);
12063 ri = ri_temp;
12064 }
12065 else
12066 ri = ri->next;
12067 }
12068 }
12069
12070 bgp_unlock_node (rm);
12071 }
paul718e3742002-12-13 20:15:29 +000012072 }
12073 }
12074 else
12075 {
12076 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012077 {
12078 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12079 {
12080 ri = rn->info;
12081 while (ri)
12082 {
12083 if (ri->extra && ri->extra->damp_info)
12084 {
12085 ri_temp = ri->next;
12086 bgp_damp_info_free (ri->extra->damp_info, 1);
12087 ri = ri_temp;
12088 }
12089 else
12090 ri = ri->next;
12091 }
12092 }
12093
12094 bgp_unlock_node (rn);
12095 }
paul718e3742002-12-13 20:15:29 +000012096 }
12097
12098 return CMD_SUCCESS;
12099}
12100
12101DEFUN (clear_ip_bgp_dampening,
12102 clear_ip_bgp_dampening_cmd,
12103 "clear ip bgp dampening",
12104 CLEAR_STR
12105 IP_STR
12106 BGP_STR
12107 "Clear route flap dampening information\n")
12108{
12109 bgp_damp_info_clean ();
12110 return CMD_SUCCESS;
12111}
12112
12113DEFUN (clear_ip_bgp_dampening_prefix,
12114 clear_ip_bgp_dampening_prefix_cmd,
12115 "clear ip bgp dampening A.B.C.D/M",
12116 CLEAR_STR
12117 IP_STR
12118 BGP_STR
12119 "Clear route flap dampening information\n"
12120 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12121{
12122 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12123 SAFI_UNICAST, NULL, 1);
12124}
12125
12126DEFUN (clear_ip_bgp_dampening_address,
12127 clear_ip_bgp_dampening_address_cmd,
12128 "clear ip bgp dampening A.B.C.D",
12129 CLEAR_STR
12130 IP_STR
12131 BGP_STR
12132 "Clear route flap dampening information\n"
12133 "Network to clear damping information\n")
12134{
12135 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12136 SAFI_UNICAST, NULL, 0);
12137}
12138
12139DEFUN (clear_ip_bgp_dampening_address_mask,
12140 clear_ip_bgp_dampening_address_mask_cmd,
12141 "clear ip bgp dampening A.B.C.D A.B.C.D",
12142 CLEAR_STR
12143 IP_STR
12144 BGP_STR
12145 "Clear route flap dampening information\n"
12146 "Network to clear damping information\n"
12147 "Network mask\n")
12148{
12149 int ret;
12150 char prefix_str[BUFSIZ];
12151
12152 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12153 if (! ret)
12154 {
12155 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12156 return CMD_WARNING;
12157 }
12158
12159 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12160 SAFI_UNICAST, NULL, 0);
12161}
12162
paul94f2b392005-06-28 12:44:16 +000012163static int
paul718e3742002-12-13 20:15:29 +000012164bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12165 afi_t afi, safi_t safi, int *write)
12166{
12167 struct bgp_node *prn;
12168 struct bgp_node *rn;
12169 struct bgp_table *table;
12170 struct prefix *p;
12171 struct prefix_rd *prd;
12172 struct bgp_static *bgp_static;
12173 u_int32_t label;
12174 char buf[SU_ADDRSTRLEN];
12175 char rdbuf[RD_ADDRSTRLEN];
12176
12177 /* Network configuration. */
12178 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12179 if ((table = prn->info) != NULL)
12180 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12181 if ((bgp_static = rn->info) != NULL)
12182 {
12183 p = &rn->p;
12184 prd = (struct prefix_rd *) &prn->p;
12185
12186 /* "address-family" display. */
12187 bgp_config_write_family_header (vty, afi, safi, write);
12188
12189 /* "network" configuration display. */
12190 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12191 label = decode_label (bgp_static->tag);
12192
12193 vty_out (vty, " network %s/%d rd %s tag %d",
12194 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12195 p->prefixlen,
12196 rdbuf, label);
12197 vty_out (vty, "%s", VTY_NEWLINE);
12198 }
12199 return 0;
12200}
12201
12202/* Configuration of static route announcement and aggregate
12203 information. */
12204int
12205bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12206 afi_t afi, safi_t safi, int *write)
12207{
12208 struct bgp_node *rn;
12209 struct prefix *p;
12210 struct bgp_static *bgp_static;
12211 struct bgp_aggregate *bgp_aggregate;
12212 char buf[SU_ADDRSTRLEN];
12213
12214 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12215 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12216
12217 /* Network configuration. */
12218 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12219 if ((bgp_static = rn->info) != NULL)
12220 {
12221 p = &rn->p;
12222
12223 /* "address-family" display. */
12224 bgp_config_write_family_header (vty, afi, safi, write);
12225
12226 /* "network" configuration display. */
12227 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12228 {
12229 u_int32_t destination;
12230 struct in_addr netmask;
12231
12232 destination = ntohl (p->u.prefix4.s_addr);
12233 masklen2ip (p->prefixlen, &netmask);
12234 vty_out (vty, " network %s",
12235 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12236
12237 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12238 || (IN_CLASSB (destination) && p->prefixlen == 16)
12239 || (IN_CLASSA (destination) && p->prefixlen == 8)
12240 || p->u.prefix4.s_addr == 0)
12241 {
12242 /* Natural mask is not display. */
12243 }
12244 else
12245 vty_out (vty, " mask %s", inet_ntoa (netmask));
12246 }
12247 else
12248 {
12249 vty_out (vty, " network %s/%d",
12250 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12251 p->prefixlen);
12252 }
12253
12254 if (bgp_static->rmap.name)
12255 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012256 else
12257 {
12258 if (bgp_static->backdoor)
12259 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012260 }
paul718e3742002-12-13 20:15:29 +000012261
12262 vty_out (vty, "%s", VTY_NEWLINE);
12263 }
12264
12265 /* Aggregate-address configuration. */
12266 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12267 if ((bgp_aggregate = rn->info) != NULL)
12268 {
12269 p = &rn->p;
12270
12271 /* "address-family" display. */
12272 bgp_config_write_family_header (vty, afi, safi, write);
12273
12274 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12275 {
12276 struct in_addr netmask;
12277
12278 masklen2ip (p->prefixlen, &netmask);
12279 vty_out (vty, " aggregate-address %s %s",
12280 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12281 inet_ntoa (netmask));
12282 }
12283 else
12284 {
12285 vty_out (vty, " aggregate-address %s/%d",
12286 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12287 p->prefixlen);
12288 }
12289
12290 if (bgp_aggregate->as_set)
12291 vty_out (vty, " as-set");
12292
12293 if (bgp_aggregate->summary_only)
12294 vty_out (vty, " summary-only");
12295
12296 vty_out (vty, "%s", VTY_NEWLINE);
12297 }
12298
12299 return 0;
12300}
12301
12302int
12303bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12304{
12305 struct bgp_node *rn;
12306 struct bgp_distance *bdistance;
12307
12308 /* Distance configuration. */
12309 if (bgp->distance_ebgp
12310 && bgp->distance_ibgp
12311 && bgp->distance_local
12312 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12313 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12314 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12315 vty_out (vty, " distance bgp %d %d %d%s",
12316 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12317 VTY_NEWLINE);
12318
12319 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12320 if ((bdistance = rn->info) != NULL)
12321 {
12322 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12323 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12324 bdistance->access_list ? bdistance->access_list : "",
12325 VTY_NEWLINE);
12326 }
12327
12328 return 0;
12329}
12330
12331/* Allocate routing table structure and install commands. */
12332void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012333bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012334{
12335 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012336 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012337
12338 /* IPv4 BGP commands. */
12339 install_element (BGP_NODE, &bgp_network_cmd);
12340 install_element (BGP_NODE, &bgp_network_mask_cmd);
12341 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12342 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12343 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12344 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12345 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12346 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12347 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12348 install_element (BGP_NODE, &no_bgp_network_cmd);
12349 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12350 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12351 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12352 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12353 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12354 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12355 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12356 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12357
12358 install_element (BGP_NODE, &aggregate_address_cmd);
12359 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12360 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12361 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12362 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12363 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12364 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12365 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12366 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12367 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12368 install_element (BGP_NODE, &no_aggregate_address_cmd);
12369 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12370 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12371 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12372 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12373 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12374 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12375 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12376 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12377 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12378
12379 /* IPv4 unicast configuration. */
12380 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12381 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12382 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12383 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12384 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12385 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012386 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012387 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12388 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12389 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12390 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12391 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012392
paul718e3742002-12-13 20:15:29 +000012393 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12394 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12395 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12396 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12397 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12398 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12399 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12400 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12401 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12402 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12403 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12404 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12405 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12406 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12407 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12408 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12409 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12410 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12411 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12412 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12413
12414 /* IPv4 multicast configuration. */
12415 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12416 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12417 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12418 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12419 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12420 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12421 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12422 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12423 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12424 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12425 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12426 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12427 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12428 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12429 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12430 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12431 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12432 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12433 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12434 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12435 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12436 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12437 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12438 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12439 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12440 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12441 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12442 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12443 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12444 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12445 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12446 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12447
12448 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12449 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012450 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012451 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12452 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012453 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012454 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12455 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12456 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12457 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012458 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012459 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12460 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12462 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12463 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12466 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12467 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12468 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012484 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12485 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12486 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12487 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12488 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012489 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12493 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12494 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012507 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012508 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012524 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012525 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012526 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012527 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012528 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012529 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012530 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12531 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012532 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012533 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012534 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012535 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012536 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012537 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012538
12539 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12540 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12541 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012542 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012543 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12544 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12545 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012546 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012547 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12548 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12549 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12550 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12551 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12552 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12553 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12554 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12555 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12556 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12557 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12558 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012559 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12560 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12561 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12562 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12563 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012564 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12565 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12566 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12567 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12568 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12569 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12570 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12571 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12572 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012573 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012574 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012575 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012576 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012577 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012578 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012579 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012580
12581 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12582 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012583 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012584 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12585 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012586 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012587 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12588 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12589 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12590 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012591 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012592 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12593 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12595 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12596 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12599 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12601 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012617 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12618 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12619 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12620 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12621 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012622 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12626 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012640 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012641 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012657 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012658 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012659 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012660 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012661 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012662 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012663 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12664 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012665 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012666 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012667 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012668 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012669 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012670 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012671
12672 /* BGP dampening clear commands */
12673 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12674 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12675 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12676 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12677
Paul Jakmaff7924f2006-09-04 01:10:36 +000012678 /* prefix count */
12679 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12680 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012682#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012683 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12684
paul718e3742002-12-13 20:15:29 +000012685 /* New config IPv6 BGP commands. */
12686 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12687 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12688 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12689 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12690
12691 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12692 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12693 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12694 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12695
G.Balaji73bfe0b2011-09-23 22:36:20 +053012696 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12697 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12698
paul718e3742002-12-13 20:15:29 +000012699 /* Old config IPv6 BGP commands. */
12700 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12701 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12702
12703 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12704 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12705 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12706 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12707
12708 install_element (VIEW_NODE, &show_bgp_cmd);
12709 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012710 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012711 install_element (VIEW_NODE, &show_bgp_route_cmd);
12712 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012713 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012714 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12715 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012716 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012717 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12718 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12719 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12720 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12721 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12722 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12723 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12724 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12725 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12726 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12727 install_element (VIEW_NODE, &show_bgp_community_cmd);
12728 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12729 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12730 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12731 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12732 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12733 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12734 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12735 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12736 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12737 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12738 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12739 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12740 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12741 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12742 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12743 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12744 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12745 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12746 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12747 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12748 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12749 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12750 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12751 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12752 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12753 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12754 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12755 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12756 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012757 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12759 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012761 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012762 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012763 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012764 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012765 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012766 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012767 install_element (VIEW_NODE, &show_bgp_view_cmd);
12768 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12769 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12770 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12771 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12772 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12773 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12774 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12775 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12776 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12777 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12778 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12779 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12780 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12781 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12782 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12783 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12784 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012785 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012786 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012787 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012788 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012789 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012790 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012791
12792 /* Restricted:
12793 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12794 */
12795 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12796 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012797 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012798 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12799 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012800 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012801 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12802 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12803 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12804 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12805 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12806 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12807 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12808 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12809 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12810 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12811 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12812 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12813 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12814 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12815 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12816 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12817 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012818 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012819 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012820 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012821 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12822 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12823 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12824 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12825 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12826 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12827 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012828 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012829 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012830 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012831
12832 install_element (ENABLE_NODE, &show_bgp_cmd);
12833 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012834 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012835 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12836 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012837 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012838 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12839 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012840 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012841 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12842 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12843 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12844 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12845 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12846 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12847 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12848 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12849 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12850 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12852 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012881 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012885 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012886 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012887 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012888 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012889 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012890 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012891 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12892 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012909 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012910 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012911 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012912 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012913 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012914 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012915
12916 /* Statistics */
12917 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12918 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12921
paul718e3742002-12-13 20:15:29 +000012922 /* old command */
12923 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12924 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12925 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12926 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12927 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12928 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12929 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12930 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12931 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12932 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12933 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12934 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12935 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12936 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12937 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12938 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12939 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12940 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12941 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12942 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12943 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12944 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12945 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12946 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12948 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12949 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12950 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12951 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012959
paul718e3742002-12-13 20:15:29 +000012960 /* old command */
12961 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12962 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12963 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12964 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12965 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12966 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12967 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12968 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12969 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12970 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12971 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12972 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12973 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12974 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12975 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12976 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12977 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12978 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12979 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12980 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12981 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12982 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12983 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12984 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12986 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12987 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12988 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12989 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12997
12998 /* old command */
12999 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13000 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13001 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13002 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13003
13004 /* old command */
13005 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13006 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13007 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13008 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13009
13010 /* old command */
13011 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13012 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13013 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13014 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13015#endif /* HAVE_IPV6 */
13016
13017 install_element (BGP_NODE, &bgp_distance_cmd);
13018 install_element (BGP_NODE, &no_bgp_distance_cmd);
13019 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13020 install_element (BGP_NODE, &bgp_distance_source_cmd);
13021 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13022 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13023 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13024
13025 install_element (BGP_NODE, &bgp_damp_set_cmd);
13026 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13027 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13028 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13029 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13030 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13031 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13032 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13033 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13034 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013035
13036 /* Deprecated AS-Pathlimit commands */
13037 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13038 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13039 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13040 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13041 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13042 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13043
13044 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13045 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13046 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13047 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13048 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13049 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13050
13051 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13052 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13053 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13054 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13055 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13056 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13057
13058 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13059 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13060 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13061 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13062 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13063 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13064
13065 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13066 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13067 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13068 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13069 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13070 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13071
13072 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13073 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13074 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13075 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13076 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13077 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013078
13079#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013080 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13081 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013082#endif
paul718e3742002-12-13 20:15:29 +000013083}
Chris Caputo228da422009-07-18 05:44:03 +000013084
13085void
13086bgp_route_finish (void)
13087{
13088 bgp_table_unlock (bgp_distance_table);
13089 bgp_distance_table = NULL;
13090}