blob: cb15c152ae386f6ac113e5fae0641b8b2ef460b6 [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;
Chris Caputo228da422009-07-18 05:44:03 +00002468 struct attr attr = { 0 };
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 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002491 struct attr_extra *ae;
2492 attr.extra = NULL;
2493
2494 ae = bgp_attr_extra_get (&attr);
2495 attr.extra = ae;
2496
paul718e3742002-12-13 20:15:29 +00002497 str2prefix ("::/0", &p);
2498
2499 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002500 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002501 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002502 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002503
2504 /* If the peer is on shared nextwork and we have link-local
2505 nexthop set it. */
2506 if (peer->shared_network
2507 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2508 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002509 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002510 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002511 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002512 }
2513 }
2514#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002515
2516 if (peer->default_rmap[afi][safi].name)
2517 {
2518 binfo.peer = bgp->peer_self;
2519 binfo.attr = &attr;
2520
paulfee0f4c2004-09-13 05:12:46 +00002521 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2522
paul718e3742002-12-13 20:15:29 +00002523 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2524 RMAP_BGP, &binfo);
2525
paulfee0f4c2004-09-13 05:12:46 +00002526 bgp->peer_self->rmap_type = 0;
2527
paul718e3742002-12-13 20:15:29 +00002528 if (ret == RMAP_DENYMATCH)
2529 {
2530 bgp_attr_flush (&attr);
2531 withdraw = 1;
2532 }
2533 }
2534
2535 if (withdraw)
2536 {
2537 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2538 bgp_default_withdraw_send (peer, afi, safi);
2539 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2540 }
2541 else
2542 {
2543 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2544 bgp_default_update_send (peer, &attr, afi, safi, from);
2545 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002546
2547 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002548 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002549}
2550
2551static void
2552bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002553 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002554{
2555 struct bgp_node *rn;
2556 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002557 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002558
paul718e3742002-12-13 20:15:29 +00002559 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002560 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002561
2562 if (safi != SAFI_MPLS_VPN
2563 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2564 bgp_default_originate (peer, afi, safi, 0);
2565
2566 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2567 for (ri = rn->info; ri; ri = ri->next)
2568 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2569 {
paulfee0f4c2004-09-13 05:12:46 +00002570 if ( (rsclient) ?
2571 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2572 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002573 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2574 else
2575 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002576
2577 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002578 }
2579}
2580
2581void
2582bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2583{
2584 struct bgp_node *rn;
2585 struct bgp_table *table;
2586
2587 if (peer->status != Established)
2588 return;
2589
2590 if (! peer->afc_nego[afi][safi])
2591 return;
2592
2593 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2594 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2595 return;
2596
2597 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002598 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002599 else
2600 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2601 rn = bgp_route_next(rn))
2602 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002603 bgp_announce_table (peer, afi, safi, table, 0);
2604
2605 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2606 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002607}
2608
2609void
2610bgp_announce_route_all (struct peer *peer)
2611{
2612 afi_t afi;
2613 safi_t safi;
2614
2615 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2616 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2617 bgp_announce_route (peer, afi, safi);
2618}
2619
2620static void
paulfee0f4c2004-09-13 05:12:46 +00002621bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002622 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002623{
2624 struct bgp_node *rn;
2625 struct bgp_adj_in *ain;
2626
2627 if (! table)
2628 table = rsclient->bgp->rib[afi][safi];
2629
2630 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2631 for (ain = rn->adj_in; ain; ain = ain->next)
2632 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002633 struct bgp_info *ri = rn->info;
2634
paulfee0f4c2004-09-13 05:12:46 +00002635 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002636 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd,
2637 (bgp_info_extra_get (ri))->tag);
paulfee0f4c2004-09-13 05:12:46 +00002638 }
2639}
2640
2641void
2642bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2643{
2644 struct bgp_table *table;
2645 struct bgp_node *rn;
2646
2647 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002648 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002649
2650 else
2651 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2652 rn = bgp_route_next (rn))
2653 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002654 {
2655 struct prefix_rd prd;
2656 prd.family = AF_UNSPEC;
2657 prd.prefixlen = 64;
2658 memcpy(&prd.val, rn->p.u.val, 8);
2659
2660 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2661 }
paulfee0f4c2004-09-13 05:12:46 +00002662}
2663
2664static void
paul718e3742002-12-13 20:15:29 +00002665bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002666 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002667{
2668 int ret;
2669 struct bgp_node *rn;
2670 struct bgp_adj_in *ain;
2671
2672 if (! table)
2673 table = peer->bgp->rib[afi][safi];
2674
2675 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2676 for (ain = rn->adj_in; ain; ain = ain->next)
2677 {
2678 if (ain->peer == peer)
2679 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002680 struct bgp_info *ri = rn->info;
2681
paul718e3742002-12-13 20:15:29 +00002682 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2683 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002684 prd, (bgp_info_extra_get (ri))->tag, 1);
2685
paul718e3742002-12-13 20:15:29 +00002686 if (ret < 0)
2687 {
2688 bgp_unlock_node (rn);
2689 return;
2690 }
2691 continue;
2692 }
2693 }
2694}
2695
2696void
2697bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2698{
2699 struct bgp_node *rn;
2700 struct bgp_table *table;
2701
2702 if (peer->status != Established)
2703 return;
2704
2705 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002706 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002707 else
2708 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2709 rn = bgp_route_next (rn))
2710 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002711 {
2712 struct prefix_rd prd;
2713 prd.family = AF_UNSPEC;
2714 prd.prefixlen = 64;
2715 memcpy(&prd.val, rn->p.u.val, 8);
2716
2717 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2718 }
paul718e3742002-12-13 20:15:29 +00002719}
2720
Chris Caputo228da422009-07-18 05:44:03 +00002721
2722struct bgp_clear_node_queue
2723{
2724 struct bgp_node *rn;
2725 enum bgp_clear_route_type purpose;
2726};
2727
paul200df112005-06-01 11:17:05 +00002728static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002729bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002730{
Chris Caputo228da422009-07-18 05:44:03 +00002731 struct bgp_clear_node_queue *cnq = data;
2732 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002733 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002734 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002735 afi_t afi = rn->table->afi;
2736 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002737
Paul Jakma64e580a2006-02-21 01:09:01 +00002738 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002739
Paul Jakma64e580a2006-02-21 01:09:01 +00002740 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002741 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002742 {
2743 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002744 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2745 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002746 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002747 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2748 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002749 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002750 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002751 break;
2752 }
paul200df112005-06-01 11:17:05 +00002753 return WQ_SUCCESS;
2754}
2755
2756static void
paul0fb58d52005-11-14 14:31:49 +00002757bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002758{
Chris Caputo228da422009-07-18 05:44:03 +00002759 struct bgp_clear_node_queue *cnq = data;
2760 struct bgp_node *rn = cnq->rn;
2761 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002762
2763 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002764 bgp_table_unlock (table);
2765 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002766}
2767
2768static void
paul94f2b392005-06-28 12:44:16 +00002769bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002770{
Paul Jakma64e580a2006-02-21 01:09:01 +00002771 struct peer *peer = wq->spec.data;
2772
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002773 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002774 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002775
2776 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002777}
2778
2779static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002780bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002781{
Paul Jakmaa2943652009-07-21 14:02:04 +01002782 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002783
Paul Jakmaa2943652009-07-21 14:02:04 +01002784 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002785#undef CLEAR_QUEUE_NAME_LEN
2786
2787 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002788 {
2789 zlog_err ("%s: Failed to allocate work queue", __func__);
2790 exit (1);
2791 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002792 peer->clear_node_queue->spec.hold = 10;
2793 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2794 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2795 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2796 peer->clear_node_queue->spec.max_retries = 0;
2797
2798 /* we only 'lock' this peer reference when the queue is actually active */
2799 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002800}
2801
paul718e3742002-12-13 20:15:29 +00002802static void
2803bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002804 struct bgp_table *table, struct peer *rsclient,
2805 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002806{
2807 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002808
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002809
paul718e3742002-12-13 20:15:29 +00002810 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002811 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002812
hasso6cf159b2005-03-21 10:28:14 +00002813 /* If still no table => afi/safi isn't configured at all or smth. */
2814 if (! table)
2815 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002816
2817 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2818 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002819 struct bgp_info *ri;
2820 struct bgp_adj_in *ain;
2821 struct bgp_adj_out *aout;
2822
Paul Jakma65ca75e2006-05-04 08:08:15 +00002823 if (rn->info == NULL)
2824 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002825
2826 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2827 * queued for every clearing peer, regardless of whether it is
2828 * relevant to the peer at hand.
2829 *
2830 * Overview: There are 3 different indices which need to be
2831 * scrubbed, potentially, when a peer is removed:
2832 *
2833 * 1 peer's routes visible via the RIB (ie accepted routes)
2834 * 2 peer's routes visible by the (optional) peer's adj-in index
2835 * 3 other routes visible by the peer's adj-out index
2836 *
2837 * 3 there is no hurry in scrubbing, once the struct peer is
2838 * removed from bgp->peer, we could just GC such deleted peer's
2839 * adj-outs at our leisure.
2840 *
2841 * 1 and 2 must be 'scrubbed' in some way, at least made
2842 * invisible via RIB index before peer session is allowed to be
2843 * brought back up. So one needs to know when such a 'search' is
2844 * complete.
2845 *
2846 * Ideally:
2847 *
2848 * - there'd be a single global queue or a single RIB walker
2849 * - rather than tracking which route_nodes still need to be
2850 * examined on a peer basis, we'd track which peers still
2851 * aren't cleared
2852 *
2853 * Given that our per-peer prefix-counts now should be reliable,
2854 * this may actually be achievable. It doesn't seem to be a huge
2855 * problem at this time,
2856 */
2857 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002858 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002859 {
Chris Caputo228da422009-07-18 05:44:03 +00002860 struct bgp_clear_node_queue *cnq;
2861
2862 /* both unlocked in bgp_clear_node_queue_del */
2863 bgp_table_lock (rn->table);
2864 bgp_lock_node (rn);
2865 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2866 sizeof (struct bgp_clear_node_queue));
2867 cnq->rn = rn;
2868 cnq->purpose = purpose;
2869 work_queue_add (peer->clear_node_queue, cnq);
2870 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002871 }
2872
2873 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002874 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002875 {
2876 bgp_adj_in_remove (rn, ain);
2877 bgp_unlock_node (rn);
2878 break;
2879 }
2880 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002881 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002882 {
2883 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2884 bgp_unlock_node (rn);
2885 break;
2886 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002887 }
2888 return;
2889}
2890
2891void
Chris Caputo228da422009-07-18 05:44:03 +00002892bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2893 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002894{
2895 struct bgp_node *rn;
2896 struct bgp_table *table;
2897 struct peer *rsclient;
2898 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002899
Paul Jakma64e580a2006-02-21 01:09:01 +00002900 if (peer->clear_node_queue == NULL)
2901 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002902
Paul Jakmaca058a32006-09-14 02:58:49 +00002903 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2904 * Idle until it receives a Clearing_Completed event. This protects
2905 * against peers which flap faster than we can we clear, which could
2906 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002907 *
2908 * a) race with routes from the new session being installed before
2909 * clear_route_node visits the node (to delete the route of that
2910 * peer)
2911 * b) resource exhaustion, clear_route_node likely leads to an entry
2912 * on the process_main queue. Fast-flapping could cause that queue
2913 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002914 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002915 if (!peer->clear_node_queue->thread)
2916 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002917
Chris Caputo228da422009-07-18 05:44:03 +00002918 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002919 {
Chris Caputo228da422009-07-18 05:44:03 +00002920 case BGP_CLEAR_ROUTE_NORMAL:
2921 if (safi != SAFI_MPLS_VPN)
2922 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2923 else
2924 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2925 rn = bgp_route_next (rn))
2926 if ((table = rn->info) != NULL)
2927 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2928
2929 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2930 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2931 PEER_FLAG_RSERVER_CLIENT))
2932 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2933 break;
2934
2935 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2936 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2937 break;
2938
2939 default:
2940 assert (0);
2941 break;
paulfee0f4c2004-09-13 05:12:46 +00002942 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002943
Paul Jakmaca058a32006-09-14 02:58:49 +00002944 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002945 * completion function won't be run by workqueue code - call it here.
2946 * XXX: Actually, this assumption doesn't hold, see
2947 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002948 *
2949 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002950 * really needed if peer state is Established - peers in
2951 * pre-Established states shouldn't have any route-update state
2952 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002953 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002954 * We still can get here in pre-Established though, through
2955 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2956 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002957 *
2958 * At some future point, this check could be move to the top of the
2959 * function, and do a quick early-return when state is
2960 * pre-Established, avoiding above list and table scans. Once we're
2961 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002962 */
2963 if (!peer->clear_node_queue->thread)
2964 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002965}
2966
2967void
2968bgp_clear_route_all (struct peer *peer)
2969{
2970 afi_t afi;
2971 safi_t safi;
2972
2973 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2974 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002975 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002976}
2977
2978void
2979bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2980{
2981 struct bgp_table *table;
2982 struct bgp_node *rn;
2983 struct bgp_adj_in *ain;
2984
2985 table = peer->bgp->rib[afi][safi];
2986
2987 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2988 for (ain = rn->adj_in; ain ; ain = ain->next)
2989 if (ain->peer == peer)
2990 {
2991 bgp_adj_in_remove (rn, ain);
2992 bgp_unlock_node (rn);
2993 break;
2994 }
2995}
hasso93406d82005-02-02 14:40:33 +00002996
2997void
2998bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2999{
3000 struct bgp_node *rn;
3001 struct bgp_info *ri;
3002 struct bgp_table *table;
3003
3004 table = peer->bgp->rib[afi][safi];
3005
3006 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3007 {
3008 for (ri = rn->info; ri; ri = ri->next)
3009 if (ri->peer == peer)
3010 {
3011 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3012 bgp_rib_remove (rn, ri, peer, afi, safi);
3013 break;
3014 }
3015 }
3016}
paul718e3742002-12-13 20:15:29 +00003017
3018/* Delete all kernel routes. */
3019void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003020bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003021{
3022 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003023 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003024 struct bgp_node *rn;
3025 struct bgp_table *table;
3026 struct bgp_info *ri;
3027
paul1eb8ef22005-04-07 07:30:20 +00003028 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003029 {
3030 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3031
3032 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3033 for (ri = rn->info; ri; ri = ri->next)
3034 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3035 && ri->type == ZEBRA_ROUTE_BGP
3036 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003037 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003038
3039 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3040
3041 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3042 for (ri = rn->info; ri; ri = ri->next)
3043 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3044 && ri->type == ZEBRA_ROUTE_BGP
3045 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003046 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003047 }
3048}
3049
3050void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003051bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003052{
3053 vty_reset ();
3054 bgp_zclient_reset ();
3055 access_list_reset ();
3056 prefix_list_reset ();
3057}
3058
3059/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3060 value. */
3061int
3062bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3063{
3064 u_char *pnt;
3065 u_char *lim;
3066 struct prefix p;
3067 int psize;
3068 int ret;
3069
3070 /* Check peer status. */
3071 if (peer->status != Established)
3072 return 0;
3073
3074 pnt = packet->nlri;
3075 lim = pnt + packet->length;
3076
3077 for (; pnt < lim; pnt += psize)
3078 {
3079 /* Clear prefix structure. */
3080 memset (&p, 0, sizeof (struct prefix));
3081
3082 /* Fetch prefix length. */
3083 p.prefixlen = *pnt++;
3084 p.family = afi2family (packet->afi);
3085
3086 /* Already checked in nlri_sanity_check(). We do double check
3087 here. */
3088 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3089 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3090 return -1;
3091
3092 /* Packet size overflow check. */
3093 psize = PSIZE (p.prefixlen);
3094
3095 /* When packet overflow occur return immediately. */
3096 if (pnt + psize > lim)
3097 return -1;
3098
3099 /* Fetch prefix from NLRI packet. */
3100 memcpy (&p.u.prefix, pnt, psize);
3101
3102 /* Check address. */
3103 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3104 {
3105 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3106 {
paulf5ba3872004-07-09 12:11:31 +00003107 /*
3108 * From draft-ietf-idr-bgp4-22, Section 6.3:
3109 * If a BGP router receives an UPDATE message with a
3110 * semantically incorrect NLRI field, in which a prefix is
3111 * semantically incorrect (eg. an unexpected multicast IP
3112 * address), it should ignore the prefix.
3113 */
paul718e3742002-12-13 20:15:29 +00003114 zlog (peer->log, LOG_ERR,
3115 "IPv4 unicast NLRI is multicast address %s",
3116 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003117
paul718e3742002-12-13 20:15:29 +00003118 return -1;
3119 }
3120 }
3121
3122#ifdef HAVE_IPV6
3123 /* Check address. */
3124 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3125 {
3126 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3127 {
3128 char buf[BUFSIZ];
3129
3130 zlog (peer->log, LOG_WARNING,
3131 "IPv6 link-local NLRI received %s ignore this NLRI",
3132 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3133
3134 continue;
3135 }
3136 }
3137#endif /* HAVE_IPV6 */
3138
3139 /* Normal process. */
3140 if (attr)
3141 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3142 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3143 else
3144 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3145 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3146
3147 /* Address family configuration mismatch or maximum-prefix count
3148 overflow. */
3149 if (ret < 0)
3150 return -1;
3151 }
3152
3153 /* Packet length consistency check. */
3154 if (pnt != lim)
3155 return -1;
3156
3157 return 0;
3158}
3159
3160/* NLRI encode syntax check routine. */
3161int
3162bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3163 bgp_size_t length)
3164{
3165 u_char *end;
3166 u_char prefixlen;
3167 int psize;
3168
3169 end = pnt + length;
3170
3171 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3172 syntactic validity. If the field is syntactically incorrect,
3173 then the Error Subcode is set to Invalid Network Field. */
3174
3175 while (pnt < end)
3176 {
3177 prefixlen = *pnt++;
3178
3179 /* Prefix length check. */
3180 if ((afi == AFI_IP && prefixlen > 32)
3181 || (afi == AFI_IP6 && prefixlen > 128))
3182 {
3183 plog_err (peer->log,
3184 "%s [Error] Update packet error (wrong prefix length %d)",
3185 peer->host, prefixlen);
3186 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3187 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3188 return -1;
3189 }
3190
3191 /* Packet size overflow check. */
3192 psize = PSIZE (prefixlen);
3193
3194 if (pnt + psize > end)
3195 {
3196 plog_err (peer->log,
3197 "%s [Error] Update packet error"
3198 " (prefix data overflow prefix size is %d)",
3199 peer->host, psize);
3200 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3201 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3202 return -1;
3203 }
3204
3205 pnt += psize;
3206 }
3207
3208 /* Packet length consistency check. */
3209 if (pnt != end)
3210 {
3211 plog_err (peer->log,
3212 "%s [Error] Update packet error"
3213 " (prefix length mismatch with total length)",
3214 peer->host);
3215 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3216 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3217 return -1;
3218 }
3219 return 0;
3220}
3221
paul94f2b392005-06-28 12:44:16 +00003222static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003223bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003224{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003225 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003226}
3227
paul94f2b392005-06-28 12:44:16 +00003228static void
paul718e3742002-12-13 20:15:29 +00003229bgp_static_free (struct bgp_static *bgp_static)
3230{
3231 if (bgp_static->rmap.name)
3232 free (bgp_static->rmap.name);
3233 XFREE (MTYPE_BGP_STATIC, bgp_static);
3234}
3235
paul94f2b392005-06-28 12:44:16 +00003236static void
paulfee0f4c2004-09-13 05:12:46 +00003237bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3238 struct prefix *p, afi_t afi, safi_t safi)
3239{
3240 struct bgp_node *rn;
3241 struct bgp_info *ri;
3242
3243 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3244
3245 /* Check selected route and self inserted route. */
3246 for (ri = rn->info; ri; ri = ri->next)
3247 if (ri->peer == bgp->peer_self
3248 && ri->type == ZEBRA_ROUTE_BGP
3249 && ri->sub_type == BGP_ROUTE_STATIC)
3250 break;
3251
3252 /* Withdraw static BGP route from routing table. */
3253 if (ri)
3254 {
paulfee0f4c2004-09-13 05:12:46 +00003255 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003256 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003257 }
3258
3259 /* Unlock bgp_node_lookup. */
3260 bgp_unlock_node (rn);
3261}
3262
paul94f2b392005-06-28 12:44:16 +00003263static void
paulfee0f4c2004-09-13 05:12:46 +00003264bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003265 struct bgp_static *bgp_static,
3266 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003267{
3268 struct bgp_node *rn;
3269 struct bgp_info *ri;
3270 struct bgp_info *new;
3271 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003272 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003273 struct attr attr = {0 };
3274 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003275 struct bgp *bgp;
3276 int ret;
3277 char buf[SU_ADDRSTRLEN];
3278
3279 bgp = rsclient->bgp;
3280
Paul Jakma06e110f2006-05-12 23:29:22 +00003281 assert (bgp_static);
3282 if (!bgp_static)
3283 return;
3284
paulfee0f4c2004-09-13 05:12:46 +00003285 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3286
3287 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003288
3289 attr.nexthop = bgp_static->igpnexthop;
3290 attr.med = bgp_static->igpmetric;
3291 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003292
Paul Jakma41367172007-08-06 15:24:51 +00003293 if (bgp_static->atomic)
3294 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3295
paulfee0f4c2004-09-13 05:12:46 +00003296 /* Apply network route-map for export to this rsclient. */
3297 if (bgp_static->rmap.name)
3298 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003299 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003300 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003301 info.attr = &attr_tmp;
3302
paulfee0f4c2004-09-13 05:12:46 +00003303 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3304 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3305
3306 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3307
3308 rsclient->rmap_type = 0;
3309
3310 if (ret == RMAP_DENYMATCH)
3311 {
3312 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003313 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003314
3315 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003316 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003317 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003318 bgp_attr_extra_free (&attr);
3319
paulfee0f4c2004-09-13 05:12:46 +00003320 return;
3321 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003322 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003323 }
3324 else
3325 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003326
Stephen Hemminger7badc262010-08-05 10:26:31 -07003327 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003328
paulfee0f4c2004-09-13 05:12:46 +00003329 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3330
Paul Jakmafb982c22007-05-04 20:15:47 +00003331 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3332 == RMAP_DENY)
3333 {
paulfee0f4c2004-09-13 05:12:46 +00003334 /* This BGP update is filtered. Log the reason then update BGP entry. */
3335 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003336 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003337 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3338 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3339 p->prefixlen, rsclient->host);
3340
3341 bgp->peer_self->rmap_type = 0;
3342
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003343 bgp_attr_unintern (&attr_new);
3344 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003345 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003346
3347 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3348
3349 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003350 }
paulfee0f4c2004-09-13 05:12:46 +00003351
3352 bgp->peer_self->rmap_type = 0;
3353
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003354 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003355 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003356 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003357
3358 for (ri = rn->info; ri; ri = ri->next)
3359 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3360 && ri->sub_type == BGP_ROUTE_STATIC)
3361 break;
3362
3363 if (ri)
3364 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003365 if (attrhash_cmp (ri->attr, attr_new) &&
3366 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003367 {
3368 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003369 bgp_attr_unintern (&attr_new);
3370 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003371 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003372 return;
3373 }
3374 else
3375 {
3376 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003377 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003378
3379 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003380 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3381 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003382 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003383 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003384 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003385
3386 /* Process change. */
3387 bgp_process (bgp, rn, afi, safi);
3388 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003389 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003390 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003391 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003392 }
paulfee0f4c2004-09-13 05:12:46 +00003393 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003394
paulfee0f4c2004-09-13 05:12:46 +00003395 /* Make new BGP info. */
3396 new = bgp_info_new ();
3397 new->type = ZEBRA_ROUTE_BGP;
3398 new->sub_type = BGP_ROUTE_STATIC;
3399 new->peer = bgp->peer_self;
3400 SET_FLAG (new->flags, BGP_INFO_VALID);
3401 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003402 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003403
3404 /* Register new BGP information. */
3405 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003406
3407 /* route_node_get lock */
3408 bgp_unlock_node (rn);
3409
paulfee0f4c2004-09-13 05:12:46 +00003410 /* Process change. */
3411 bgp_process (bgp, rn, afi, safi);
3412
3413 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003414 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003415 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003416}
3417
paul94f2b392005-06-28 12:44:16 +00003418static void
paulfee0f4c2004-09-13 05:12:46 +00003419bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003420 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3421{
3422 struct bgp_node *rn;
3423 struct bgp_info *ri;
3424 struct bgp_info *new;
3425 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003426 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003427 struct attr *attr_new;
3428 int ret;
3429
Paul Jakmadd8103a2006-05-12 23:27:30 +00003430 assert (bgp_static);
3431 if (!bgp_static)
3432 return;
3433
paulfee0f4c2004-09-13 05:12:46 +00003434 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003435
3436 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003437
3438 attr.nexthop = bgp_static->igpnexthop;
3439 attr.med = bgp_static->igpmetric;
3440 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003441
Paul Jakma41367172007-08-06 15:24:51 +00003442 if (bgp_static->atomic)
3443 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3444
paul718e3742002-12-13 20:15:29 +00003445 /* Apply route-map. */
3446 if (bgp_static->rmap.name)
3447 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003448 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003449 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003450 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003451
paulfee0f4c2004-09-13 05:12:46 +00003452 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3453
paul718e3742002-12-13 20:15:29 +00003454 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003455
paulfee0f4c2004-09-13 05:12:46 +00003456 bgp->peer_self->rmap_type = 0;
3457
paul718e3742002-12-13 20:15:29 +00003458 if (ret == RMAP_DENYMATCH)
3459 {
3460 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003461 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003462
3463 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003464 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003465 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003466 bgp_static_withdraw (bgp, p, afi, safi);
3467 return;
3468 }
paul286e1e72003-08-08 00:24:31 +00003469 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003470 }
paul286e1e72003-08-08 00:24:31 +00003471 else
3472 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003473
3474 for (ri = rn->info; ri; ri = ri->next)
3475 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3476 && ri->sub_type == BGP_ROUTE_STATIC)
3477 break;
3478
3479 if (ri)
3480 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003481 if (attrhash_cmp (ri->attr, attr_new) &&
3482 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003483 {
3484 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003485 bgp_attr_unintern (&attr_new);
3486 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003487 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003488 return;
3489 }
3490 else
3491 {
3492 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003493 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003494
3495 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003496 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3497 bgp_info_restore(rn, ri);
3498 else
3499 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003500 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003501 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003502 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003503
3504 /* Process change. */
3505 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3506 bgp_process (bgp, rn, afi, safi);
3507 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003508 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003509 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003510 return;
3511 }
3512 }
3513
3514 /* Make new BGP info. */
3515 new = bgp_info_new ();
3516 new->type = ZEBRA_ROUTE_BGP;
3517 new->sub_type = BGP_ROUTE_STATIC;
3518 new->peer = bgp->peer_self;
3519 SET_FLAG (new->flags, BGP_INFO_VALID);
3520 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003521 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003522
3523 /* Aggregate address increment. */
3524 bgp_aggregate_increment (bgp, p, new, afi, safi);
3525
3526 /* Register new BGP information. */
3527 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003528
3529 /* route_node_get lock */
3530 bgp_unlock_node (rn);
3531
paul718e3742002-12-13 20:15:29 +00003532 /* Process change. */
3533 bgp_process (bgp, rn, afi, safi);
3534
3535 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003536 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003537 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003538}
3539
3540void
paulfee0f4c2004-09-13 05:12:46 +00003541bgp_static_update (struct bgp *bgp, struct prefix *p,
3542 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3543{
3544 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003545 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003546
3547 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3548
paul1eb8ef22005-04-07 07:30:20 +00003549 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003550 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003551 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3552 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003553 }
3554}
3555
paul94f2b392005-06-28 12:44:16 +00003556static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003557bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3558 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003559{
3560 struct bgp_node *rn;
3561 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003562
paulfee0f4c2004-09-13 05:12:46 +00003563 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003564
3565 /* Make new BGP info. */
3566 new = bgp_info_new ();
3567 new->type = ZEBRA_ROUTE_BGP;
3568 new->sub_type = BGP_ROUTE_STATIC;
3569 new->peer = bgp->peer_self;
3570 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3571 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003572 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003573 new->extra = bgp_info_extra_new();
3574 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003575
3576 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003577 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003578
3579 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003580 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003581
paul200df112005-06-01 11:17:05 +00003582 /* route_node_get lock */
3583 bgp_unlock_node (rn);
3584
paul718e3742002-12-13 20:15:29 +00003585 /* Process change. */
3586 bgp_process (bgp, rn, afi, safi);
3587}
3588
3589void
3590bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3591 safi_t safi)
3592{
3593 struct bgp_node *rn;
3594 struct bgp_info *ri;
3595
paulfee0f4c2004-09-13 05:12:46 +00003596 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003597
3598 /* Check selected route and self inserted route. */
3599 for (ri = rn->info; ri; ri = ri->next)
3600 if (ri->peer == bgp->peer_self
3601 && ri->type == ZEBRA_ROUTE_BGP
3602 && ri->sub_type == BGP_ROUTE_STATIC)
3603 break;
3604
3605 /* Withdraw static BGP route from routing table. */
3606 if (ri)
3607 {
3608 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003609 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003610 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003611 }
3612
3613 /* Unlock bgp_node_lookup. */
3614 bgp_unlock_node (rn);
3615}
3616
3617void
paulfee0f4c2004-09-13 05:12:46 +00003618bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3619{
3620 struct bgp_static *bgp_static;
3621 struct bgp *bgp;
3622 struct bgp_node *rn;
3623 struct prefix *p;
3624
3625 bgp = rsclient->bgp;
3626
3627 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3628 if ((bgp_static = rn->info) != NULL)
3629 {
3630 p = &rn->p;
3631
3632 bgp_static_update_rsclient (rsclient, p, bgp_static,
3633 afi, safi);
3634 }
3635}
3636
paul94f2b392005-06-28 12:44:16 +00003637static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003638bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3639 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003640{
3641 struct bgp_node *rn;
3642 struct bgp_info *ri;
3643
paulfee0f4c2004-09-13 05:12:46 +00003644 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003645
3646 /* Check selected route and self inserted route. */
3647 for (ri = rn->info; ri; ri = ri->next)
3648 if (ri->peer == bgp->peer_self
3649 && ri->type == ZEBRA_ROUTE_BGP
3650 && ri->sub_type == BGP_ROUTE_STATIC)
3651 break;
3652
3653 /* Withdraw static BGP route from routing table. */
3654 if (ri)
3655 {
3656 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003657 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003658 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003659 }
3660
3661 /* Unlock bgp_node_lookup. */
3662 bgp_unlock_node (rn);
3663}
3664
3665/* Configure static BGP network. When user don't run zebra, static
3666 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003667static int
paulfd79ac92004-10-13 05:06:08 +00003668bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003669 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003670{
3671 int ret;
3672 struct prefix p;
3673 struct bgp_static *bgp_static;
3674 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003675 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003676
3677 /* Convert IP prefix string to struct prefix. */
3678 ret = str2prefix (ip_str, &p);
3679 if (! ret)
3680 {
3681 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3682 return CMD_WARNING;
3683 }
3684#ifdef HAVE_IPV6
3685 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3686 {
3687 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3688 VTY_NEWLINE);
3689 return CMD_WARNING;
3690 }
3691#endif /* HAVE_IPV6 */
3692
3693 apply_mask (&p);
3694
3695 /* Set BGP static route configuration. */
3696 rn = bgp_node_get (bgp->route[afi][safi], &p);
3697
3698 if (rn->info)
3699 {
3700 /* Configuration change. */
3701 bgp_static = rn->info;
3702
3703 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003704 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3705 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003706
paul718e3742002-12-13 20:15:29 +00003707 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003708
paul718e3742002-12-13 20:15:29 +00003709 if (rmap)
3710 {
3711 if (bgp_static->rmap.name)
3712 free (bgp_static->rmap.name);
3713 bgp_static->rmap.name = strdup (rmap);
3714 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3715 }
3716 else
3717 {
3718 if (bgp_static->rmap.name)
3719 free (bgp_static->rmap.name);
3720 bgp_static->rmap.name = NULL;
3721 bgp_static->rmap.map = NULL;
3722 bgp_static->valid = 0;
3723 }
3724 bgp_unlock_node (rn);
3725 }
3726 else
3727 {
3728 /* New configuration. */
3729 bgp_static = bgp_static_new ();
3730 bgp_static->backdoor = backdoor;
3731 bgp_static->valid = 0;
3732 bgp_static->igpmetric = 0;
3733 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003734
paul718e3742002-12-13 20:15:29 +00003735 if (rmap)
3736 {
3737 if (bgp_static->rmap.name)
3738 free (bgp_static->rmap.name);
3739 bgp_static->rmap.name = strdup (rmap);
3740 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3741 }
3742 rn->info = bgp_static;
3743 }
3744
3745 /* If BGP scan is not enabled, we should install this route here. */
3746 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3747 {
3748 bgp_static->valid = 1;
3749
3750 if (need_update)
3751 bgp_static_withdraw (bgp, &p, afi, safi);
3752
3753 if (! bgp_static->backdoor)
3754 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3755 }
3756
3757 return CMD_SUCCESS;
3758}
3759
3760/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003761static int
paulfd79ac92004-10-13 05:06:08 +00003762bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003763 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003764{
3765 int ret;
3766 struct prefix p;
3767 struct bgp_static *bgp_static;
3768 struct bgp_node *rn;
3769
3770 /* Convert IP prefix string to struct prefix. */
3771 ret = str2prefix (ip_str, &p);
3772 if (! ret)
3773 {
3774 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3775 return CMD_WARNING;
3776 }
3777#ifdef HAVE_IPV6
3778 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3779 {
3780 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3781 VTY_NEWLINE);
3782 return CMD_WARNING;
3783 }
3784#endif /* HAVE_IPV6 */
3785
3786 apply_mask (&p);
3787
3788 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3789 if (! rn)
3790 {
3791 vty_out (vty, "%% Can't find specified static route configuration.%s",
3792 VTY_NEWLINE);
3793 return CMD_WARNING;
3794 }
3795
3796 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003797
paul718e3742002-12-13 20:15:29 +00003798 /* Update BGP RIB. */
3799 if (! bgp_static->backdoor)
3800 bgp_static_withdraw (bgp, &p, afi, safi);
3801
3802 /* Clear configuration. */
3803 bgp_static_free (bgp_static);
3804 rn->info = NULL;
3805 bgp_unlock_node (rn);
3806 bgp_unlock_node (rn);
3807
3808 return CMD_SUCCESS;
3809}
3810
3811/* Called from bgp_delete(). Delete all static routes from the BGP
3812 instance. */
3813void
3814bgp_static_delete (struct bgp *bgp)
3815{
3816 afi_t afi;
3817 safi_t safi;
3818 struct bgp_node *rn;
3819 struct bgp_node *rm;
3820 struct bgp_table *table;
3821 struct bgp_static *bgp_static;
3822
3823 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3824 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3825 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3826 if (rn->info != NULL)
3827 {
3828 if (safi == SAFI_MPLS_VPN)
3829 {
3830 table = rn->info;
3831
3832 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3833 {
3834 bgp_static = rn->info;
3835 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3836 AFI_IP, SAFI_MPLS_VPN,
3837 (struct prefix_rd *)&rn->p,
3838 bgp_static->tag);
3839 bgp_static_free (bgp_static);
3840 rn->info = NULL;
3841 bgp_unlock_node (rn);
3842 }
3843 }
3844 else
3845 {
3846 bgp_static = rn->info;
3847 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3848 bgp_static_free (bgp_static);
3849 rn->info = NULL;
3850 bgp_unlock_node (rn);
3851 }
3852 }
3853}
3854
3855int
paulfd79ac92004-10-13 05:06:08 +00003856bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3857 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003858{
3859 int ret;
3860 struct prefix p;
3861 struct prefix_rd prd;
3862 struct bgp *bgp;
3863 struct bgp_node *prn;
3864 struct bgp_node *rn;
3865 struct bgp_table *table;
3866 struct bgp_static *bgp_static;
3867 u_char tag[3];
3868
3869 bgp = vty->index;
3870
3871 ret = str2prefix (ip_str, &p);
3872 if (! ret)
3873 {
3874 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3875 return CMD_WARNING;
3876 }
3877 apply_mask (&p);
3878
3879 ret = str2prefix_rd (rd_str, &prd);
3880 if (! ret)
3881 {
3882 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3883 return CMD_WARNING;
3884 }
3885
3886 ret = str2tag (tag_str, tag);
3887 if (! ret)
3888 {
3889 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3890 return CMD_WARNING;
3891 }
3892
3893 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3894 (struct prefix *)&prd);
3895 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003896 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003897 else
3898 bgp_unlock_node (prn);
3899 table = prn->info;
3900
3901 rn = bgp_node_get (table, &p);
3902
3903 if (rn->info)
3904 {
3905 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3906 bgp_unlock_node (rn);
3907 }
3908 else
3909 {
3910 /* New configuration. */
3911 bgp_static = bgp_static_new ();
3912 bgp_static->valid = 1;
3913 memcpy (bgp_static->tag, tag, 3);
3914 rn->info = bgp_static;
3915
3916 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3917 }
3918
3919 return CMD_SUCCESS;
3920}
3921
3922/* Configure static BGP network. */
3923int
paulfd79ac92004-10-13 05:06:08 +00003924bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3925 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003926{
3927 int ret;
3928 struct bgp *bgp;
3929 struct prefix p;
3930 struct prefix_rd prd;
3931 struct bgp_node *prn;
3932 struct bgp_node *rn;
3933 struct bgp_table *table;
3934 struct bgp_static *bgp_static;
3935 u_char tag[3];
3936
3937 bgp = vty->index;
3938
3939 /* Convert IP prefix string to struct prefix. */
3940 ret = str2prefix (ip_str, &p);
3941 if (! ret)
3942 {
3943 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3944 return CMD_WARNING;
3945 }
3946 apply_mask (&p);
3947
3948 ret = str2prefix_rd (rd_str, &prd);
3949 if (! ret)
3950 {
3951 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3952 return CMD_WARNING;
3953 }
3954
3955 ret = str2tag (tag_str, tag);
3956 if (! ret)
3957 {
3958 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3959 return CMD_WARNING;
3960 }
3961
3962 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3963 (struct prefix *)&prd);
3964 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003965 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003966 else
3967 bgp_unlock_node (prn);
3968 table = prn->info;
3969
3970 rn = bgp_node_lookup (table, &p);
3971
3972 if (rn)
3973 {
3974 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3975
3976 bgp_static = rn->info;
3977 bgp_static_free (bgp_static);
3978 rn->info = NULL;
3979 bgp_unlock_node (rn);
3980 bgp_unlock_node (rn);
3981 }
3982 else
3983 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3984
3985 return CMD_SUCCESS;
3986}
3987
3988DEFUN (bgp_network,
3989 bgp_network_cmd,
3990 "network A.B.C.D/M",
3991 "Specify a network to announce via BGP\n"
3992 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3993{
3994 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003995 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003996}
3997
3998DEFUN (bgp_network_route_map,
3999 bgp_network_route_map_cmd,
4000 "network A.B.C.D/M route-map WORD",
4001 "Specify a network to announce via BGP\n"
4002 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4003 "Route-map to modify the attributes\n"
4004 "Name of the route map\n")
4005{
4006 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004007 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004008}
4009
4010DEFUN (bgp_network_backdoor,
4011 bgp_network_backdoor_cmd,
4012 "network A.B.C.D/M backdoor",
4013 "Specify a network to announce via BGP\n"
4014 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4015 "Specify a BGP backdoor route\n")
4016{
Paul Jakma41367172007-08-06 15:24:51 +00004017 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004018 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004019}
4020
4021DEFUN (bgp_network_mask,
4022 bgp_network_mask_cmd,
4023 "network A.B.C.D mask A.B.C.D",
4024 "Specify a network to announce via BGP\n"
4025 "Network number\n"
4026 "Network mask\n"
4027 "Network mask\n")
4028{
4029 int ret;
4030 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004031
paul718e3742002-12-13 20:15:29 +00004032 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4033 if (! ret)
4034 {
4035 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4036 return CMD_WARNING;
4037 }
4038
4039 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004040 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004041}
4042
4043DEFUN (bgp_network_mask_route_map,
4044 bgp_network_mask_route_map_cmd,
4045 "network A.B.C.D mask A.B.C.D route-map WORD",
4046 "Specify a network to announce via BGP\n"
4047 "Network number\n"
4048 "Network mask\n"
4049 "Network mask\n"
4050 "Route-map to modify the attributes\n"
4051 "Name of the route map\n")
4052{
4053 int ret;
4054 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004055
paul718e3742002-12-13 20:15:29 +00004056 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4057 if (! ret)
4058 {
4059 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4060 return CMD_WARNING;
4061 }
4062
4063 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004064 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004065}
4066
4067DEFUN (bgp_network_mask_backdoor,
4068 bgp_network_mask_backdoor_cmd,
4069 "network A.B.C.D mask A.B.C.D backdoor",
4070 "Specify a network to announce via BGP\n"
4071 "Network number\n"
4072 "Network mask\n"
4073 "Network mask\n"
4074 "Specify a BGP backdoor route\n")
4075{
4076 int ret;
4077 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004078
paul718e3742002-12-13 20:15:29 +00004079 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4080 if (! ret)
4081 {
4082 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4083 return CMD_WARNING;
4084 }
4085
Paul Jakma41367172007-08-06 15:24:51 +00004086 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004087 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004088}
4089
4090DEFUN (bgp_network_mask_natural,
4091 bgp_network_mask_natural_cmd,
4092 "network A.B.C.D",
4093 "Specify a network to announce via BGP\n"
4094 "Network number\n")
4095{
4096 int ret;
4097 char prefix_str[BUFSIZ];
4098
4099 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4100 if (! ret)
4101 {
4102 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4103 return CMD_WARNING;
4104 }
4105
4106 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004107 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004108}
4109
4110DEFUN (bgp_network_mask_natural_route_map,
4111 bgp_network_mask_natural_route_map_cmd,
4112 "network A.B.C.D route-map WORD",
4113 "Specify a network to announce via BGP\n"
4114 "Network number\n"
4115 "Route-map to modify the attributes\n"
4116 "Name of the route map\n")
4117{
4118 int ret;
4119 char prefix_str[BUFSIZ];
4120
4121 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4122 if (! ret)
4123 {
4124 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4125 return CMD_WARNING;
4126 }
4127
4128 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004129 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004130}
4131
4132DEFUN (bgp_network_mask_natural_backdoor,
4133 bgp_network_mask_natural_backdoor_cmd,
4134 "network A.B.C.D backdoor",
4135 "Specify a network to announce via BGP\n"
4136 "Network number\n"
4137 "Specify a BGP backdoor route\n")
4138{
4139 int ret;
4140 char prefix_str[BUFSIZ];
4141
4142 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4143 if (! ret)
4144 {
4145 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4146 return CMD_WARNING;
4147 }
4148
Paul Jakma41367172007-08-06 15:24:51 +00004149 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004150 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004151}
4152
4153DEFUN (no_bgp_network,
4154 no_bgp_network_cmd,
4155 "no network A.B.C.D/M",
4156 NO_STR
4157 "Specify a network to announce via BGP\n"
4158 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4159{
4160 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4161 bgp_node_safi (vty));
4162}
4163
4164ALIAS (no_bgp_network,
4165 no_bgp_network_route_map_cmd,
4166 "no network A.B.C.D/M route-map WORD",
4167 NO_STR
4168 "Specify a network to announce via BGP\n"
4169 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4170 "Route-map to modify the attributes\n"
4171 "Name of the route map\n")
4172
4173ALIAS (no_bgp_network,
4174 no_bgp_network_backdoor_cmd,
4175 "no network A.B.C.D/M backdoor",
4176 NO_STR
4177 "Specify a network to announce via BGP\n"
4178 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4179 "Specify a BGP backdoor route\n")
4180
4181DEFUN (no_bgp_network_mask,
4182 no_bgp_network_mask_cmd,
4183 "no network A.B.C.D mask A.B.C.D",
4184 NO_STR
4185 "Specify a network to announce via BGP\n"
4186 "Network number\n"
4187 "Network mask\n"
4188 "Network mask\n")
4189{
4190 int ret;
4191 char prefix_str[BUFSIZ];
4192
4193 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4194 if (! ret)
4195 {
4196 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4197 return CMD_WARNING;
4198 }
4199
4200 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4201 bgp_node_safi (vty));
4202}
4203
4204ALIAS (no_bgp_network_mask,
4205 no_bgp_network_mask_route_map_cmd,
4206 "no network A.B.C.D mask A.B.C.D route-map WORD",
4207 NO_STR
4208 "Specify a network to announce via BGP\n"
4209 "Network number\n"
4210 "Network mask\n"
4211 "Network mask\n"
4212 "Route-map to modify the attributes\n"
4213 "Name of the route map\n")
4214
4215ALIAS (no_bgp_network_mask,
4216 no_bgp_network_mask_backdoor_cmd,
4217 "no network A.B.C.D mask A.B.C.D backdoor",
4218 NO_STR
4219 "Specify a network to announce via BGP\n"
4220 "Network number\n"
4221 "Network mask\n"
4222 "Network mask\n"
4223 "Specify a BGP backdoor route\n")
4224
4225DEFUN (no_bgp_network_mask_natural,
4226 no_bgp_network_mask_natural_cmd,
4227 "no network A.B.C.D",
4228 NO_STR
4229 "Specify a network to announce via BGP\n"
4230 "Network number\n")
4231{
4232 int ret;
4233 char prefix_str[BUFSIZ];
4234
4235 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4236 if (! ret)
4237 {
4238 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4239 return CMD_WARNING;
4240 }
4241
4242 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4243 bgp_node_safi (vty));
4244}
4245
4246ALIAS (no_bgp_network_mask_natural,
4247 no_bgp_network_mask_natural_route_map_cmd,
4248 "no network A.B.C.D route-map WORD",
4249 NO_STR
4250 "Specify a network to announce via BGP\n"
4251 "Network number\n"
4252 "Route-map to modify the attributes\n"
4253 "Name of the route map\n")
4254
4255ALIAS (no_bgp_network_mask_natural,
4256 no_bgp_network_mask_natural_backdoor_cmd,
4257 "no network A.B.C.D backdoor",
4258 NO_STR
4259 "Specify a network to announce via BGP\n"
4260 "Network number\n"
4261 "Specify a BGP backdoor route\n")
4262
4263#ifdef HAVE_IPV6
4264DEFUN (ipv6_bgp_network,
4265 ipv6_bgp_network_cmd,
4266 "network X:X::X:X/M",
4267 "Specify a network to announce via BGP\n"
4268 "IPv6 prefix <network>/<length>\n")
4269{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304270 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004271 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004272}
4273
4274DEFUN (ipv6_bgp_network_route_map,
4275 ipv6_bgp_network_route_map_cmd,
4276 "network X:X::X:X/M route-map WORD",
4277 "Specify a network to announce via BGP\n"
4278 "IPv6 prefix <network>/<length>\n"
4279 "Route-map to modify the attributes\n"
4280 "Name of the route map\n")
4281{
4282 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004283 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004284}
4285
4286DEFUN (no_ipv6_bgp_network,
4287 no_ipv6_bgp_network_cmd,
4288 "no network X:X::X:X/M",
4289 NO_STR
4290 "Specify a network to announce via BGP\n"
4291 "IPv6 prefix <network>/<length>\n")
4292{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304293 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004294}
4295
4296ALIAS (no_ipv6_bgp_network,
4297 no_ipv6_bgp_network_route_map_cmd,
4298 "no network X:X::X:X/M route-map WORD",
4299 NO_STR
4300 "Specify a network to announce via BGP\n"
4301 "IPv6 prefix <network>/<length>\n"
4302 "Route-map to modify the attributes\n"
4303 "Name of the route map\n")
4304
4305ALIAS (ipv6_bgp_network,
4306 old_ipv6_bgp_network_cmd,
4307 "ipv6 bgp network X:X::X:X/M",
4308 IPV6_STR
4309 BGP_STR
4310 "Specify a network to announce via BGP\n"
4311 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4312
4313ALIAS (no_ipv6_bgp_network,
4314 old_no_ipv6_bgp_network_cmd,
4315 "no ipv6 bgp network X:X::X:X/M",
4316 NO_STR
4317 IPV6_STR
4318 BGP_STR
4319 "Specify a network to announce via BGP\n"
4320 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4321#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004322
4323/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4324ALIAS_DEPRECATED (bgp_network,
4325 bgp_network_ttl_cmd,
4326 "network A.B.C.D/M pathlimit <0-255>",
4327 "Specify a network to announce via BGP\n"
4328 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4329 "AS-Path hopcount limit attribute\n"
4330 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4331ALIAS_DEPRECATED (bgp_network_backdoor,
4332 bgp_network_backdoor_ttl_cmd,
4333 "network A.B.C.D/M backdoor pathlimit <0-255>",
4334 "Specify a network to announce via BGP\n"
4335 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4336 "Specify a BGP backdoor route\n"
4337 "AS-Path hopcount limit attribute\n"
4338 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4339ALIAS_DEPRECATED (bgp_network_mask,
4340 bgp_network_mask_ttl_cmd,
4341 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4342 "Specify a network to announce via BGP\n"
4343 "Network number\n"
4344 "Network mask\n"
4345 "Network mask\n"
4346 "AS-Path hopcount limit attribute\n"
4347 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4348ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4349 bgp_network_mask_backdoor_ttl_cmd,
4350 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4351 "Specify a network to announce via BGP\n"
4352 "Network number\n"
4353 "Network mask\n"
4354 "Network mask\n"
4355 "Specify a BGP backdoor route\n"
4356 "AS-Path hopcount limit attribute\n"
4357 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4358ALIAS_DEPRECATED (bgp_network_mask_natural,
4359 bgp_network_mask_natural_ttl_cmd,
4360 "network A.B.C.D pathlimit <0-255>",
4361 "Specify a network to announce via BGP\n"
4362 "Network number\n"
4363 "AS-Path hopcount limit attribute\n"
4364 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4365ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4366 bgp_network_mask_natural_backdoor_ttl_cmd,
4367 "network A.B.C.D backdoor pathlimit (1-255>",
4368 "Specify a network to announce via BGP\n"
4369 "Network number\n"
4370 "Specify a BGP backdoor route\n"
4371 "AS-Path hopcount limit attribute\n"
4372 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4373ALIAS_DEPRECATED (no_bgp_network,
4374 no_bgp_network_ttl_cmd,
4375 "no network A.B.C.D/M pathlimit <0-255>",
4376 NO_STR
4377 "Specify a network to announce via BGP\n"
4378 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4379 "AS-Path hopcount limit attribute\n"
4380 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4381ALIAS_DEPRECATED (no_bgp_network,
4382 no_bgp_network_backdoor_ttl_cmd,
4383 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4384 NO_STR
4385 "Specify a network to announce via BGP\n"
4386 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4387 "Specify a BGP backdoor route\n"
4388 "AS-Path hopcount limit attribute\n"
4389 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4390ALIAS_DEPRECATED (no_bgp_network,
4391 no_bgp_network_mask_ttl_cmd,
4392 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4393 NO_STR
4394 "Specify a network to announce via BGP\n"
4395 "Network number\n"
4396 "Network mask\n"
4397 "Network mask\n"
4398 "AS-Path hopcount limit attribute\n"
4399 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4400ALIAS_DEPRECATED (no_bgp_network_mask,
4401 no_bgp_network_mask_backdoor_ttl_cmd,
4402 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4403 NO_STR
4404 "Specify a network to announce via BGP\n"
4405 "Network number\n"
4406 "Network mask\n"
4407 "Network mask\n"
4408 "Specify a BGP backdoor route\n"
4409 "AS-Path hopcount limit attribute\n"
4410 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4411ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4412 no_bgp_network_mask_natural_ttl_cmd,
4413 "no network A.B.C.D pathlimit <0-255>",
4414 NO_STR
4415 "Specify a network to announce via BGP\n"
4416 "Network number\n"
4417 "AS-Path hopcount limit attribute\n"
4418 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4419ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4420 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4421 "no network A.B.C.D backdoor pathlimit <0-255>",
4422 NO_STR
4423 "Specify a network to announce via BGP\n"
4424 "Network number\n"
4425 "Specify a BGP backdoor route\n"
4426 "AS-Path hopcount limit attribute\n"
4427 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004428#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004429ALIAS_DEPRECATED (ipv6_bgp_network,
4430 ipv6_bgp_network_ttl_cmd,
4431 "network X:X::X:X/M pathlimit <0-255>",
4432 "Specify a network to announce via BGP\n"
4433 "IPv6 prefix <network>/<length>\n"
4434 "AS-Path hopcount limit attribute\n"
4435 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4436ALIAS_DEPRECATED (no_ipv6_bgp_network,
4437 no_ipv6_bgp_network_ttl_cmd,
4438 "no network X:X::X:X/M pathlimit <0-255>",
4439 NO_STR
4440 "Specify a network to announce via BGP\n"
4441 "IPv6 prefix <network>/<length>\n"
4442 "AS-Path hopcount limit attribute\n"
4443 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004444#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004445
4446/* Aggreagete address:
4447
4448 advertise-map Set condition to advertise attribute
4449 as-set Generate AS set path information
4450 attribute-map Set attributes of aggregate
4451 route-map Set parameters of aggregate
4452 summary-only Filter more specific routes from updates
4453 suppress-map Conditionally filter more specific routes from updates
4454 <cr>
4455 */
4456struct bgp_aggregate
4457{
4458 /* Summary-only flag. */
4459 u_char summary_only;
4460
4461 /* AS set generation. */
4462 u_char as_set;
4463
4464 /* Route-map for aggregated route. */
4465 struct route_map *map;
4466
4467 /* Suppress-count. */
4468 unsigned long count;
4469
4470 /* SAFI configuration. */
4471 safi_t safi;
4472};
4473
paul94f2b392005-06-28 12:44:16 +00004474static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004475bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004476{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004477 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004478}
4479
paul94f2b392005-06-28 12:44:16 +00004480static void
paul718e3742002-12-13 20:15:29 +00004481bgp_aggregate_free (struct bgp_aggregate *aggregate)
4482{
4483 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4484}
4485
paul94f2b392005-06-28 12:44:16 +00004486static void
paul718e3742002-12-13 20:15:29 +00004487bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4488 afi_t afi, safi_t safi, struct bgp_info *del,
4489 struct bgp_aggregate *aggregate)
4490{
4491 struct bgp_table *table;
4492 struct bgp_node *top;
4493 struct bgp_node *rn;
4494 u_char origin;
4495 struct aspath *aspath = NULL;
4496 struct aspath *asmerge = NULL;
4497 struct community *community = NULL;
4498 struct community *commerge = NULL;
4499 struct in_addr nexthop;
4500 u_int32_t med = 0;
4501 struct bgp_info *ri;
4502 struct bgp_info *new;
4503 int first = 1;
4504 unsigned long match = 0;
4505
4506 /* Record adding route's nexthop and med. */
4507 if (rinew)
4508 {
4509 nexthop = rinew->attr->nexthop;
4510 med = rinew->attr->med;
4511 }
4512
4513 /* ORIGIN attribute: If at least one route among routes that are
4514 aggregated has ORIGIN with the value INCOMPLETE, then the
4515 aggregated route must have the ORIGIN attribute with the value
4516 INCOMPLETE. Otherwise, if at least one route among routes that
4517 are aggregated has ORIGIN with the value EGP, then the aggregated
4518 route must have the origin attribute with the value EGP. In all
4519 other case the value of the ORIGIN attribute of the aggregated
4520 route is INTERNAL. */
4521 origin = BGP_ORIGIN_IGP;
4522
4523 table = bgp->rib[afi][safi];
4524
4525 top = bgp_node_get (table, p);
4526 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4527 if (rn->p.prefixlen > p->prefixlen)
4528 {
4529 match = 0;
4530
4531 for (ri = rn->info; ri; ri = ri->next)
4532 {
4533 if (BGP_INFO_HOLDDOWN (ri))
4534 continue;
4535
4536 if (del && ri == del)
4537 continue;
4538
4539 if (! rinew && first)
4540 {
4541 nexthop = ri->attr->nexthop;
4542 med = ri->attr->med;
4543 first = 0;
4544 }
4545
4546#ifdef AGGREGATE_NEXTHOP_CHECK
4547 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4548 || ri->attr->med != med)
4549 {
4550 if (aspath)
4551 aspath_free (aspath);
4552 if (community)
4553 community_free (community);
4554 bgp_unlock_node (rn);
4555 bgp_unlock_node (top);
4556 return;
4557 }
4558#endif /* AGGREGATE_NEXTHOP_CHECK */
4559
4560 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4561 {
4562 if (aggregate->summary_only)
4563 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004564 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004565 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004566 match++;
4567 }
4568
4569 aggregate->count++;
4570
4571 if (aggregate->as_set)
4572 {
4573 if (origin < ri->attr->origin)
4574 origin = ri->attr->origin;
4575
4576 if (aspath)
4577 {
4578 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4579 aspath_free (aspath);
4580 aspath = asmerge;
4581 }
4582 else
4583 aspath = aspath_dup (ri->attr->aspath);
4584
4585 if (ri->attr->community)
4586 {
4587 if (community)
4588 {
4589 commerge = community_merge (community,
4590 ri->attr->community);
4591 community = community_uniq_sort (commerge);
4592 community_free (commerge);
4593 }
4594 else
4595 community = community_dup (ri->attr->community);
4596 }
4597 }
4598 }
4599 }
4600 if (match)
4601 bgp_process (bgp, rn, afi, safi);
4602 }
4603 bgp_unlock_node (top);
4604
4605 if (rinew)
4606 {
4607 aggregate->count++;
4608
4609 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004610 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004611
4612 if (aggregate->as_set)
4613 {
4614 if (origin < rinew->attr->origin)
4615 origin = rinew->attr->origin;
4616
4617 if (aspath)
4618 {
4619 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4620 aspath_free (aspath);
4621 aspath = asmerge;
4622 }
4623 else
4624 aspath = aspath_dup (rinew->attr->aspath);
4625
4626 if (rinew->attr->community)
4627 {
4628 if (community)
4629 {
4630 commerge = community_merge (community,
4631 rinew->attr->community);
4632 community = community_uniq_sort (commerge);
4633 community_free (commerge);
4634 }
4635 else
4636 community = community_dup (rinew->attr->community);
4637 }
4638 }
4639 }
4640
4641 if (aggregate->count > 0)
4642 {
4643 rn = bgp_node_get (table, p);
4644 new = bgp_info_new ();
4645 new->type = ZEBRA_ROUTE_BGP;
4646 new->sub_type = BGP_ROUTE_AGGREGATE;
4647 new->peer = bgp->peer_self;
4648 SET_FLAG (new->flags, BGP_INFO_VALID);
4649 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004650 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004651
4652 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004653 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004654 bgp_process (bgp, rn, afi, safi);
4655 }
4656 else
4657 {
4658 if (aspath)
4659 aspath_free (aspath);
4660 if (community)
4661 community_free (community);
4662 }
4663}
4664
4665void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4666 struct bgp_aggregate *);
4667
4668void
4669bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4670 struct bgp_info *ri, afi_t afi, safi_t safi)
4671{
4672 struct bgp_node *child;
4673 struct bgp_node *rn;
4674 struct bgp_aggregate *aggregate;
4675
4676 /* MPLS-VPN aggregation is not yet supported. */
4677 if (safi == SAFI_MPLS_VPN)
4678 return;
4679
4680 if (p->prefixlen == 0)
4681 return;
4682
4683 if (BGP_INFO_HOLDDOWN (ri))
4684 return;
4685
4686 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4687
4688 /* Aggregate address configuration check. */
4689 for (rn = child; rn; rn = rn->parent)
4690 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4691 {
4692 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004693 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004694 }
4695 bgp_unlock_node (child);
4696}
4697
4698void
4699bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4700 struct bgp_info *del, afi_t afi, safi_t safi)
4701{
4702 struct bgp_node *child;
4703 struct bgp_node *rn;
4704 struct bgp_aggregate *aggregate;
4705
4706 /* MPLS-VPN aggregation is not yet supported. */
4707 if (safi == SAFI_MPLS_VPN)
4708 return;
4709
4710 if (p->prefixlen == 0)
4711 return;
4712
4713 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4714
4715 /* Aggregate address configuration check. */
4716 for (rn = child; rn; rn = rn->parent)
4717 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4718 {
4719 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004720 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004721 }
4722 bgp_unlock_node (child);
4723}
4724
paul94f2b392005-06-28 12:44:16 +00004725static void
paul718e3742002-12-13 20:15:29 +00004726bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4727 struct bgp_aggregate *aggregate)
4728{
4729 struct bgp_table *table;
4730 struct bgp_node *top;
4731 struct bgp_node *rn;
4732 struct bgp_info *new;
4733 struct bgp_info *ri;
4734 unsigned long match;
4735 u_char origin = BGP_ORIGIN_IGP;
4736 struct aspath *aspath = NULL;
4737 struct aspath *asmerge = NULL;
4738 struct community *community = NULL;
4739 struct community *commerge = NULL;
4740
4741 table = bgp->rib[afi][safi];
4742
4743 /* Sanity check. */
4744 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4745 return;
4746 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4747 return;
4748
4749 /* If routes exists below this node, generate aggregate routes. */
4750 top = bgp_node_get (table, p);
4751 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4752 if (rn->p.prefixlen > p->prefixlen)
4753 {
4754 match = 0;
4755
4756 for (ri = rn->info; ri; ri = ri->next)
4757 {
4758 if (BGP_INFO_HOLDDOWN (ri))
4759 continue;
4760
4761 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4762 {
4763 /* summary-only aggregate route suppress aggregated
4764 route announcement. */
4765 if (aggregate->summary_only)
4766 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004767 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004768 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004769 match++;
4770 }
4771 /* as-set aggregate route generate origin, as path,
4772 community aggregation. */
4773 if (aggregate->as_set)
4774 {
4775 if (origin < ri->attr->origin)
4776 origin = ri->attr->origin;
4777
4778 if (aspath)
4779 {
4780 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4781 aspath_free (aspath);
4782 aspath = asmerge;
4783 }
4784 else
4785 aspath = aspath_dup (ri->attr->aspath);
4786
4787 if (ri->attr->community)
4788 {
4789 if (community)
4790 {
4791 commerge = community_merge (community,
4792 ri->attr->community);
4793 community = community_uniq_sort (commerge);
4794 community_free (commerge);
4795 }
4796 else
4797 community = community_dup (ri->attr->community);
4798 }
4799 }
4800 aggregate->count++;
4801 }
4802 }
4803
4804 /* If this node is suppressed, process the change. */
4805 if (match)
4806 bgp_process (bgp, rn, afi, safi);
4807 }
4808 bgp_unlock_node (top);
4809
4810 /* Add aggregate route to BGP table. */
4811 if (aggregate->count)
4812 {
4813 rn = bgp_node_get (table, p);
4814
4815 new = bgp_info_new ();
4816 new->type = ZEBRA_ROUTE_BGP;
4817 new->sub_type = BGP_ROUTE_AGGREGATE;
4818 new->peer = bgp->peer_self;
4819 SET_FLAG (new->flags, BGP_INFO_VALID);
4820 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004821 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004822
4823 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004824 bgp_unlock_node (rn);
4825
paul718e3742002-12-13 20:15:29 +00004826 /* Process change. */
4827 bgp_process (bgp, rn, afi, safi);
4828 }
4829}
4830
4831void
4832bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4833 safi_t safi, struct bgp_aggregate *aggregate)
4834{
4835 struct bgp_table *table;
4836 struct bgp_node *top;
4837 struct bgp_node *rn;
4838 struct bgp_info *ri;
4839 unsigned long match;
4840
4841 table = bgp->rib[afi][safi];
4842
4843 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4844 return;
4845 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4846 return;
4847
4848 /* If routes exists below this node, generate aggregate routes. */
4849 top = bgp_node_get (table, p);
4850 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4851 if (rn->p.prefixlen > p->prefixlen)
4852 {
4853 match = 0;
4854
4855 for (ri = rn->info; ri; ri = ri->next)
4856 {
4857 if (BGP_INFO_HOLDDOWN (ri))
4858 continue;
4859
4860 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4861 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004862 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004863 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004864 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004865
Paul Jakmafb982c22007-05-04 20:15:47 +00004866 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004867 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004868 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004869 match++;
4870 }
4871 }
4872 aggregate->count--;
4873 }
4874 }
4875
Paul Jakmafb982c22007-05-04 20:15:47 +00004876 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004877 if (match)
4878 bgp_process (bgp, rn, afi, safi);
4879 }
4880 bgp_unlock_node (top);
4881
4882 /* Delete aggregate route from BGP table. */
4883 rn = bgp_node_get (table, p);
4884
4885 for (ri = rn->info; ri; ri = ri->next)
4886 if (ri->peer == bgp->peer_self
4887 && ri->type == ZEBRA_ROUTE_BGP
4888 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4889 break;
4890
4891 /* Withdraw static BGP route from routing table. */
4892 if (ri)
4893 {
paul718e3742002-12-13 20:15:29 +00004894 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004895 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004896 }
4897
4898 /* Unlock bgp_node_lookup. */
4899 bgp_unlock_node (rn);
4900}
4901
4902/* Aggregate route attribute. */
4903#define AGGREGATE_SUMMARY_ONLY 1
4904#define AGGREGATE_AS_SET 1
4905
paul94f2b392005-06-28 12:44:16 +00004906static int
Robert Baysf6269b42010-08-05 10:26:28 -07004907bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4908 afi_t afi, safi_t safi)
4909{
4910 int ret;
4911 struct prefix p;
4912 struct bgp_node *rn;
4913 struct bgp *bgp;
4914 struct bgp_aggregate *aggregate;
4915
4916 /* Convert string to prefix structure. */
4917 ret = str2prefix (prefix_str, &p);
4918 if (!ret)
4919 {
4920 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4921 return CMD_WARNING;
4922 }
4923 apply_mask (&p);
4924
4925 /* Get BGP structure. */
4926 bgp = vty->index;
4927
4928 /* Old configuration check. */
4929 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4930 if (! rn)
4931 {
4932 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4933 VTY_NEWLINE);
4934 return CMD_WARNING;
4935 }
4936
4937 aggregate = rn->info;
4938 if (aggregate->safi & SAFI_UNICAST)
4939 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4940 if (aggregate->safi & SAFI_MULTICAST)
4941 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4942
4943 /* Unlock aggregate address configuration. */
4944 rn->info = NULL;
4945 bgp_aggregate_free (aggregate);
4946 bgp_unlock_node (rn);
4947 bgp_unlock_node (rn);
4948
4949 return CMD_SUCCESS;
4950}
4951
4952static int
4953bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004954 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004955 u_char summary_only, u_char as_set)
4956{
4957 int ret;
4958 struct prefix p;
4959 struct bgp_node *rn;
4960 struct bgp *bgp;
4961 struct bgp_aggregate *aggregate;
4962
4963 /* Convert string to prefix structure. */
4964 ret = str2prefix (prefix_str, &p);
4965 if (!ret)
4966 {
4967 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4968 return CMD_WARNING;
4969 }
4970 apply_mask (&p);
4971
4972 /* Get BGP structure. */
4973 bgp = vty->index;
4974
4975 /* Old configuration check. */
4976 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4977
4978 if (rn->info)
4979 {
4980 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004981 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004982 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4983 if (ret)
4984 {
Robert Bays368473f2010-08-05 10:26:29 -07004985 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4986 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004987 return CMD_WARNING;
4988 }
paul718e3742002-12-13 20:15:29 +00004989 }
4990
4991 /* Make aggregate address structure. */
4992 aggregate = bgp_aggregate_new ();
4993 aggregate->summary_only = summary_only;
4994 aggregate->as_set = as_set;
4995 aggregate->safi = safi;
4996 rn->info = aggregate;
4997
4998 /* Aggregate address insert into BGP routing table. */
4999 if (safi & SAFI_UNICAST)
5000 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
5001 if (safi & SAFI_MULTICAST)
5002 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5003
5004 return CMD_SUCCESS;
5005}
5006
paul718e3742002-12-13 20:15:29 +00005007DEFUN (aggregate_address,
5008 aggregate_address_cmd,
5009 "aggregate-address A.B.C.D/M",
5010 "Configure BGP aggregate entries\n"
5011 "Aggregate prefix\n")
5012{
5013 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5014}
5015
5016DEFUN (aggregate_address_mask,
5017 aggregate_address_mask_cmd,
5018 "aggregate-address A.B.C.D A.B.C.D",
5019 "Configure BGP aggregate entries\n"
5020 "Aggregate address\n"
5021 "Aggregate mask\n")
5022{
5023 int ret;
5024 char prefix_str[BUFSIZ];
5025
5026 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5027
5028 if (! ret)
5029 {
5030 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5031 return CMD_WARNING;
5032 }
5033
5034 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5035 0, 0);
5036}
5037
5038DEFUN (aggregate_address_summary_only,
5039 aggregate_address_summary_only_cmd,
5040 "aggregate-address A.B.C.D/M summary-only",
5041 "Configure BGP aggregate entries\n"
5042 "Aggregate prefix\n"
5043 "Filter more specific routes from updates\n")
5044{
5045 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5046 AGGREGATE_SUMMARY_ONLY, 0);
5047}
5048
5049DEFUN (aggregate_address_mask_summary_only,
5050 aggregate_address_mask_summary_only_cmd,
5051 "aggregate-address A.B.C.D A.B.C.D summary-only",
5052 "Configure BGP aggregate entries\n"
5053 "Aggregate address\n"
5054 "Aggregate mask\n"
5055 "Filter more specific routes from updates\n")
5056{
5057 int ret;
5058 char prefix_str[BUFSIZ];
5059
5060 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5061
5062 if (! ret)
5063 {
5064 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5065 return CMD_WARNING;
5066 }
5067
5068 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5069 AGGREGATE_SUMMARY_ONLY, 0);
5070}
5071
5072DEFUN (aggregate_address_as_set,
5073 aggregate_address_as_set_cmd,
5074 "aggregate-address A.B.C.D/M as-set",
5075 "Configure BGP aggregate entries\n"
5076 "Aggregate prefix\n"
5077 "Generate AS set path information\n")
5078{
5079 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5080 0, AGGREGATE_AS_SET);
5081}
5082
5083DEFUN (aggregate_address_mask_as_set,
5084 aggregate_address_mask_as_set_cmd,
5085 "aggregate-address A.B.C.D A.B.C.D as-set",
5086 "Configure BGP aggregate entries\n"
5087 "Aggregate address\n"
5088 "Aggregate mask\n"
5089 "Generate AS set path information\n")
5090{
5091 int ret;
5092 char prefix_str[BUFSIZ];
5093
5094 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5095
5096 if (! ret)
5097 {
5098 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5099 return CMD_WARNING;
5100 }
5101
5102 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5103 0, AGGREGATE_AS_SET);
5104}
5105
5106
5107DEFUN (aggregate_address_as_set_summary,
5108 aggregate_address_as_set_summary_cmd,
5109 "aggregate-address A.B.C.D/M as-set summary-only",
5110 "Configure BGP aggregate entries\n"
5111 "Aggregate prefix\n"
5112 "Generate AS set path information\n"
5113 "Filter more specific routes from updates\n")
5114{
5115 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5116 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5117}
5118
5119ALIAS (aggregate_address_as_set_summary,
5120 aggregate_address_summary_as_set_cmd,
5121 "aggregate-address A.B.C.D/M summary-only as-set",
5122 "Configure BGP aggregate entries\n"
5123 "Aggregate prefix\n"
5124 "Filter more specific routes from updates\n"
5125 "Generate AS set path information\n")
5126
5127DEFUN (aggregate_address_mask_as_set_summary,
5128 aggregate_address_mask_as_set_summary_cmd,
5129 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5130 "Configure BGP aggregate entries\n"
5131 "Aggregate address\n"
5132 "Aggregate mask\n"
5133 "Generate AS set path information\n"
5134 "Filter more specific routes from updates\n")
5135{
5136 int ret;
5137 char prefix_str[BUFSIZ];
5138
5139 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5140
5141 if (! ret)
5142 {
5143 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5144 return CMD_WARNING;
5145 }
5146
5147 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5148 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5149}
5150
5151ALIAS (aggregate_address_mask_as_set_summary,
5152 aggregate_address_mask_summary_as_set_cmd,
5153 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5154 "Configure BGP aggregate entries\n"
5155 "Aggregate address\n"
5156 "Aggregate mask\n"
5157 "Filter more specific routes from updates\n"
5158 "Generate AS set path information\n")
5159
5160DEFUN (no_aggregate_address,
5161 no_aggregate_address_cmd,
5162 "no aggregate-address A.B.C.D/M",
5163 NO_STR
5164 "Configure BGP aggregate entries\n"
5165 "Aggregate prefix\n")
5166{
5167 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5168}
5169
5170ALIAS (no_aggregate_address,
5171 no_aggregate_address_summary_only_cmd,
5172 "no aggregate-address A.B.C.D/M summary-only",
5173 NO_STR
5174 "Configure BGP aggregate entries\n"
5175 "Aggregate prefix\n"
5176 "Filter more specific routes from updates\n")
5177
5178ALIAS (no_aggregate_address,
5179 no_aggregate_address_as_set_cmd,
5180 "no aggregate-address A.B.C.D/M as-set",
5181 NO_STR
5182 "Configure BGP aggregate entries\n"
5183 "Aggregate prefix\n"
5184 "Generate AS set path information\n")
5185
5186ALIAS (no_aggregate_address,
5187 no_aggregate_address_as_set_summary_cmd,
5188 "no aggregate-address A.B.C.D/M as-set summary-only",
5189 NO_STR
5190 "Configure BGP aggregate entries\n"
5191 "Aggregate prefix\n"
5192 "Generate AS set path information\n"
5193 "Filter more specific routes from updates\n")
5194
5195ALIAS (no_aggregate_address,
5196 no_aggregate_address_summary_as_set_cmd,
5197 "no aggregate-address A.B.C.D/M summary-only as-set",
5198 NO_STR
5199 "Configure BGP aggregate entries\n"
5200 "Aggregate prefix\n"
5201 "Filter more specific routes from updates\n"
5202 "Generate AS set path information\n")
5203
5204DEFUN (no_aggregate_address_mask,
5205 no_aggregate_address_mask_cmd,
5206 "no aggregate-address A.B.C.D A.B.C.D",
5207 NO_STR
5208 "Configure BGP aggregate entries\n"
5209 "Aggregate address\n"
5210 "Aggregate mask\n")
5211{
5212 int ret;
5213 char prefix_str[BUFSIZ];
5214
5215 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5216
5217 if (! ret)
5218 {
5219 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5220 return CMD_WARNING;
5221 }
5222
5223 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5224}
5225
5226ALIAS (no_aggregate_address_mask,
5227 no_aggregate_address_mask_summary_only_cmd,
5228 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5229 NO_STR
5230 "Configure BGP aggregate entries\n"
5231 "Aggregate address\n"
5232 "Aggregate mask\n"
5233 "Filter more specific routes from updates\n")
5234
5235ALIAS (no_aggregate_address_mask,
5236 no_aggregate_address_mask_as_set_cmd,
5237 "no aggregate-address A.B.C.D A.B.C.D as-set",
5238 NO_STR
5239 "Configure BGP aggregate entries\n"
5240 "Aggregate address\n"
5241 "Aggregate mask\n"
5242 "Generate AS set path information\n")
5243
5244ALIAS (no_aggregate_address_mask,
5245 no_aggregate_address_mask_as_set_summary_cmd,
5246 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5247 NO_STR
5248 "Configure BGP aggregate entries\n"
5249 "Aggregate address\n"
5250 "Aggregate mask\n"
5251 "Generate AS set path information\n"
5252 "Filter more specific routes from updates\n")
5253
5254ALIAS (no_aggregate_address_mask,
5255 no_aggregate_address_mask_summary_as_set_cmd,
5256 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5257 NO_STR
5258 "Configure BGP aggregate entries\n"
5259 "Aggregate address\n"
5260 "Aggregate mask\n"
5261 "Filter more specific routes from updates\n"
5262 "Generate AS set path information\n")
5263
5264#ifdef HAVE_IPV6
5265DEFUN (ipv6_aggregate_address,
5266 ipv6_aggregate_address_cmd,
5267 "aggregate-address X:X::X:X/M",
5268 "Configure BGP aggregate entries\n"
5269 "Aggregate prefix\n")
5270{
5271 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5272}
5273
5274DEFUN (ipv6_aggregate_address_summary_only,
5275 ipv6_aggregate_address_summary_only_cmd,
5276 "aggregate-address X:X::X:X/M summary-only",
5277 "Configure BGP aggregate entries\n"
5278 "Aggregate prefix\n"
5279 "Filter more specific routes from updates\n")
5280{
5281 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5282 AGGREGATE_SUMMARY_ONLY, 0);
5283}
5284
5285DEFUN (no_ipv6_aggregate_address,
5286 no_ipv6_aggregate_address_cmd,
5287 "no aggregate-address X:X::X:X/M",
5288 NO_STR
5289 "Configure BGP aggregate entries\n"
5290 "Aggregate prefix\n")
5291{
5292 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5293}
5294
5295DEFUN (no_ipv6_aggregate_address_summary_only,
5296 no_ipv6_aggregate_address_summary_only_cmd,
5297 "no aggregate-address X:X::X:X/M summary-only",
5298 NO_STR
5299 "Configure BGP aggregate entries\n"
5300 "Aggregate prefix\n"
5301 "Filter more specific routes from updates\n")
5302{
5303 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5304}
5305
5306ALIAS (ipv6_aggregate_address,
5307 old_ipv6_aggregate_address_cmd,
5308 "ipv6 bgp aggregate-address X:X::X:X/M",
5309 IPV6_STR
5310 BGP_STR
5311 "Configure BGP aggregate entries\n"
5312 "Aggregate prefix\n")
5313
5314ALIAS (ipv6_aggregate_address_summary_only,
5315 old_ipv6_aggregate_address_summary_only_cmd,
5316 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5317 IPV6_STR
5318 BGP_STR
5319 "Configure BGP aggregate entries\n"
5320 "Aggregate prefix\n"
5321 "Filter more specific routes from updates\n")
5322
5323ALIAS (no_ipv6_aggregate_address,
5324 old_no_ipv6_aggregate_address_cmd,
5325 "no ipv6 bgp aggregate-address X:X::X:X/M",
5326 NO_STR
5327 IPV6_STR
5328 BGP_STR
5329 "Configure BGP aggregate entries\n"
5330 "Aggregate prefix\n")
5331
5332ALIAS (no_ipv6_aggregate_address_summary_only,
5333 old_no_ipv6_aggregate_address_summary_only_cmd,
5334 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5335 NO_STR
5336 IPV6_STR
5337 BGP_STR
5338 "Configure BGP aggregate entries\n"
5339 "Aggregate prefix\n"
5340 "Filter more specific routes from updates\n")
5341#endif /* HAVE_IPV6 */
5342
5343/* Redistribute route treatment. */
5344void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005345bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5346 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005347 u_int32_t metric, u_char type)
5348{
5349 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005350 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005351 struct bgp_info *new;
5352 struct bgp_info *bi;
5353 struct bgp_info info;
5354 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005355 struct attr attr = { 0 };
5356 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005357 struct attr *new_attr;
5358 afi_t afi;
5359 int ret;
5360
5361 /* Make default attribute. */
5362 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5363 if (nexthop)
5364 attr.nexthop = *nexthop;
5365
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005366#ifdef HAVE_IPV6
5367 if (nexthop6)
5368 {
5369 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5370 extra->mp_nexthop_global = *nexthop6;
5371 extra->mp_nexthop_len = 16;
5372 }
5373#endif
5374
paul718e3742002-12-13 20:15:29 +00005375 attr.med = metric;
5376 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5377
paul1eb8ef22005-04-07 07:30:20 +00005378 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005379 {
5380 afi = family2afi (p->family);
5381
5382 if (bgp->redist[afi][type])
5383 {
5384 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005385 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005386
5387 if (bgp->redist_metric_flag[afi][type])
5388 attr_new.med = bgp->redist_metric[afi][type];
5389
5390 /* Apply route-map. */
5391 if (bgp->rmap[afi][type].map)
5392 {
5393 info.peer = bgp->peer_self;
5394 info.attr = &attr_new;
5395
paulfee0f4c2004-09-13 05:12:46 +00005396 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5397
paul718e3742002-12-13 20:15:29 +00005398 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5399 &info);
paulfee0f4c2004-09-13 05:12:46 +00005400
5401 bgp->peer_self->rmap_type = 0;
5402
paul718e3742002-12-13 20:15:29 +00005403 if (ret == RMAP_DENYMATCH)
5404 {
5405 /* Free uninterned attribute. */
5406 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005407 bgp_attr_extra_free (&attr_new);
5408
paul718e3742002-12-13 20:15:29 +00005409 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005410 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005411 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005412 bgp_redistribute_delete (p, type);
5413 return;
5414 }
5415 }
5416
Paul Jakmafb982c22007-05-04 20:15:47 +00005417 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5418 afi, SAFI_UNICAST, p, NULL);
5419
paul718e3742002-12-13 20:15:29 +00005420 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005421 bgp_attr_extra_free (&attr_new);
5422
paul718e3742002-12-13 20:15:29 +00005423 for (bi = bn->info; bi; bi = bi->next)
5424 if (bi->peer == bgp->peer_self
5425 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5426 break;
5427
5428 if (bi)
5429 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005430 if (attrhash_cmp (bi->attr, new_attr) &&
5431 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005432 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005433 bgp_attr_unintern (&new_attr);
5434 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005435 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005436 bgp_unlock_node (bn);
5437 return;
5438 }
5439 else
5440 {
5441 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005442 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005443
5444 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005445 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5446 bgp_info_restore(bn, bi);
5447 else
5448 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005449 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005450 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005451 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005452
5453 /* Process change. */
5454 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5455 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5456 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005457 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005458 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005459 return;
5460 }
5461 }
5462
5463 new = bgp_info_new ();
5464 new->type = type;
5465 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5466 new->peer = bgp->peer_self;
5467 SET_FLAG (new->flags, BGP_INFO_VALID);
5468 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005469 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005470
5471 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5472 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005473 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005474 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5475 }
5476 }
5477
5478 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005479 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005480 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005481}
5482
5483void
5484bgp_redistribute_delete (struct prefix *p, u_char type)
5485{
5486 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005487 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005488 afi_t afi;
5489 struct bgp_node *rn;
5490 struct bgp_info *ri;
5491
paul1eb8ef22005-04-07 07:30:20 +00005492 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005493 {
5494 afi = family2afi (p->family);
5495
5496 if (bgp->redist[afi][type])
5497 {
paulfee0f4c2004-09-13 05:12:46 +00005498 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005499
5500 for (ri = rn->info; ri; ri = ri->next)
5501 if (ri->peer == bgp->peer_self
5502 && ri->type == type)
5503 break;
5504
5505 if (ri)
5506 {
5507 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005508 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005509 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005510 }
5511 bgp_unlock_node (rn);
5512 }
5513 }
5514}
5515
5516/* Withdraw specified route type's route. */
5517void
5518bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5519{
5520 struct bgp_node *rn;
5521 struct bgp_info *ri;
5522 struct bgp_table *table;
5523
5524 table = bgp->rib[afi][SAFI_UNICAST];
5525
5526 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5527 {
5528 for (ri = rn->info; ri; ri = ri->next)
5529 if (ri->peer == bgp->peer_self
5530 && ri->type == type)
5531 break;
5532
5533 if (ri)
5534 {
5535 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005536 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005537 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005538 }
5539 }
5540}
5541
5542/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005543static void
paul718e3742002-12-13 20:15:29 +00005544route_vty_out_route (struct prefix *p, struct vty *vty)
5545{
5546 int len;
5547 u_int32_t destination;
5548 char buf[BUFSIZ];
5549
5550 if (p->family == AF_INET)
5551 {
5552 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5553 destination = ntohl (p->u.prefix4.s_addr);
5554
5555 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5556 || (IN_CLASSB (destination) && p->prefixlen == 16)
5557 || (IN_CLASSA (destination) && p->prefixlen == 8)
5558 || p->u.prefix4.s_addr == 0)
5559 {
5560 /* When mask is natural, mask is not displayed. */
5561 }
5562 else
5563 len += vty_out (vty, "/%d", p->prefixlen);
5564 }
5565 else
5566 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5567 p->prefixlen);
5568
5569 len = 17 - len;
5570 if (len < 1)
5571 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5572 else
5573 vty_out (vty, "%*s", len, " ");
5574}
5575
paul718e3742002-12-13 20:15:29 +00005576enum bgp_display_type
5577{
5578 normal_list,
5579};
5580
paulb40d9392005-08-22 22:34:41 +00005581/* Print the short form route status for a bgp_info */
5582static void
5583route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005584{
paulb40d9392005-08-22 22:34:41 +00005585 /* Route status display. */
5586 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5587 vty_out (vty, "R");
5588 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005589 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005590 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005591 vty_out (vty, "s");
5592 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5593 vty_out (vty, "*");
5594 else
5595 vty_out (vty, " ");
5596
5597 /* Selected */
5598 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5599 vty_out (vty, "h");
5600 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5601 vty_out (vty, "d");
5602 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5603 vty_out (vty, ">");
5604 else
5605 vty_out (vty, " ");
5606
5607 /* Internal route. */
5608 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5609 vty_out (vty, "i");
5610 else
paulb40d9392005-08-22 22:34:41 +00005611 vty_out (vty, " ");
5612}
5613
5614/* called from terminal list command */
5615void
5616route_vty_out (struct vty *vty, struct prefix *p,
5617 struct bgp_info *binfo, int display, safi_t safi)
5618{
5619 struct attr *attr;
5620
5621 /* short status lead text */
5622 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005623
5624 /* print prefix and mask */
5625 if (! display)
5626 route_vty_out_route (p, vty);
5627 else
5628 vty_out (vty, "%*s", 17, " ");
5629
5630 /* Print attribute */
5631 attr = binfo->attr;
5632 if (attr)
5633 {
5634 if (p->family == AF_INET)
5635 {
5636 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005637 vty_out (vty, "%-16s",
5638 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005639 else
5640 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5641 }
5642#ifdef HAVE_IPV6
5643 else if (p->family == AF_INET6)
5644 {
5645 int len;
5646 char buf[BUFSIZ];
5647
5648 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005649 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5650 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005651 len = 16 - len;
5652 if (len < 1)
5653 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5654 else
5655 vty_out (vty, "%*s", len, " ");
5656 }
5657#endif /* HAVE_IPV6 */
5658
5659 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005660 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005661 else
5662 vty_out (vty, " ");
5663
5664 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005665 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005666 else
5667 vty_out (vty, " ");
5668
Paul Jakmafb982c22007-05-04 20:15:47 +00005669 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005670
Paul Jakmab2518c12006-05-12 23:48:40 +00005671 /* Print aspath */
5672 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005673 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005674
Paul Jakmab2518c12006-05-12 23:48:40 +00005675 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005676 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005677 }
paul718e3742002-12-13 20:15:29 +00005678 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005679}
5680
5681/* called from terminal list command */
5682void
5683route_vty_out_tmp (struct vty *vty, struct prefix *p,
5684 struct attr *attr, safi_t safi)
5685{
5686 /* Route status display. */
5687 vty_out (vty, "*");
5688 vty_out (vty, ">");
5689 vty_out (vty, " ");
5690
5691 /* print prefix and mask */
5692 route_vty_out_route (p, vty);
5693
5694 /* Print attribute */
5695 if (attr)
5696 {
5697 if (p->family == AF_INET)
5698 {
5699 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005700 vty_out (vty, "%-16s",
5701 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005702 else
5703 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5704 }
5705#ifdef HAVE_IPV6
5706 else if (p->family == AF_INET6)
5707 {
5708 int len;
5709 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005710
5711 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005712
5713 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005714 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5715 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005716 len = 16 - len;
5717 if (len < 1)
5718 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5719 else
5720 vty_out (vty, "%*s", len, " ");
5721 }
5722#endif /* HAVE_IPV6 */
5723
5724 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005725 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005726 else
5727 vty_out (vty, " ");
5728
5729 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005730 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005731 else
5732 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005733
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005734 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005735
Paul Jakmab2518c12006-05-12 23:48:40 +00005736 /* Print aspath */
5737 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005738 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005739
Paul Jakmab2518c12006-05-12 23:48:40 +00005740 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005741 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005742 }
paul718e3742002-12-13 20:15:29 +00005743
5744 vty_out (vty, "%s", VTY_NEWLINE);
5745}
5746
ajs5a646652004-11-05 01:25:55 +00005747void
paul718e3742002-12-13 20:15:29 +00005748route_vty_out_tag (struct vty *vty, struct prefix *p,
5749 struct bgp_info *binfo, int display, safi_t safi)
5750{
5751 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005752 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005753
5754 if (!binfo->extra)
5755 return;
5756
paulb40d9392005-08-22 22:34:41 +00005757 /* short status lead text */
5758 route_vty_short_status_out (vty, binfo);
5759
paul718e3742002-12-13 20:15:29 +00005760 /* print prefix and mask */
5761 if (! display)
5762 route_vty_out_route (p, vty);
5763 else
5764 vty_out (vty, "%*s", 17, " ");
5765
5766 /* Print attribute */
5767 attr = binfo->attr;
5768 if (attr)
5769 {
5770 if (p->family == AF_INET)
5771 {
5772 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005773 vty_out (vty, "%-16s",
5774 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005775 else
5776 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5777 }
5778#ifdef HAVE_IPV6
5779 else if (p->family == AF_INET6)
5780 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005781 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005782 char buf[BUFSIZ];
5783 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005784 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005785 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005786 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5787 buf, BUFSIZ));
5788 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005789 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005790 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5791 buf, BUFSIZ),
5792 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5793 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005794
5795 }
5796#endif /* HAVE_IPV6 */
5797 }
5798
Paul Jakmafb982c22007-05-04 20:15:47 +00005799 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005800
5801 vty_out (vty, "notag/%d", label);
5802
5803 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005804}
5805
5806/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005807static void
paul718e3742002-12-13 20:15:29 +00005808damp_route_vty_out (struct vty *vty, struct prefix *p,
5809 struct bgp_info *binfo, int display, safi_t safi)
5810{
5811 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005812 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005813 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005814
paulb40d9392005-08-22 22:34:41 +00005815 /* short status lead text */
5816 route_vty_short_status_out (vty, binfo);
5817
paul718e3742002-12-13 20:15:29 +00005818 /* print prefix and mask */
5819 if (! display)
5820 route_vty_out_route (p, vty);
5821 else
5822 vty_out (vty, "%*s", 17, " ");
5823
5824 len = vty_out (vty, "%s", binfo->peer->host);
5825 len = 17 - len;
5826 if (len < 1)
5827 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5828 else
5829 vty_out (vty, "%*s", len, " ");
5830
Chris Caputo50aef6f2009-06-23 06:06:49 +00005831 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005832
5833 /* Print attribute */
5834 attr = binfo->attr;
5835 if (attr)
5836 {
5837 /* Print aspath */
5838 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005839 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005840
5841 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005842 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005843 }
5844 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005845}
5846
paul718e3742002-12-13 20:15:29 +00005847/* flap route */
ajs5a646652004-11-05 01:25:55 +00005848static void
paul718e3742002-12-13 20:15:29 +00005849flap_route_vty_out (struct vty *vty, struct prefix *p,
5850 struct bgp_info *binfo, int display, safi_t safi)
5851{
5852 struct attr *attr;
5853 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005854 char timebuf[BGP_UPTIME_LEN];
5855 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005856
5857 if (!binfo->extra)
5858 return;
5859
5860 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005861
paulb40d9392005-08-22 22:34:41 +00005862 /* short status lead text */
5863 route_vty_short_status_out (vty, binfo);
5864
paul718e3742002-12-13 20:15:29 +00005865 /* print prefix and mask */
5866 if (! display)
5867 route_vty_out_route (p, vty);
5868 else
5869 vty_out (vty, "%*s", 17, " ");
5870
5871 len = vty_out (vty, "%s", binfo->peer->host);
5872 len = 16 - len;
5873 if (len < 1)
5874 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5875 else
5876 vty_out (vty, "%*s", len, " ");
5877
5878 len = vty_out (vty, "%d", bdi->flap);
5879 len = 5 - len;
5880 if (len < 1)
5881 vty_out (vty, " ");
5882 else
5883 vty_out (vty, "%*s ", len, " ");
5884
5885 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5886 timebuf, BGP_UPTIME_LEN));
5887
5888 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5889 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005890 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005891 else
5892 vty_out (vty, "%*s ", 8, " ");
5893
5894 /* Print attribute */
5895 attr = binfo->attr;
5896 if (attr)
5897 {
5898 /* Print aspath */
5899 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005900 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005901
5902 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005903 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005904 }
5905 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005906}
5907
paul94f2b392005-06-28 12:44:16 +00005908static void
paul718e3742002-12-13 20:15:29 +00005909route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5910 struct bgp_info *binfo, afi_t afi, safi_t safi)
5911{
5912 char buf[INET6_ADDRSTRLEN];
5913 char buf1[BUFSIZ];
5914 struct attr *attr;
5915 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005916#ifdef HAVE_CLOCK_MONOTONIC
5917 time_t tbuf;
5918#endif
paul718e3742002-12-13 20:15:29 +00005919
5920 attr = binfo->attr;
5921
5922 if (attr)
5923 {
5924 /* Line1 display AS-path, Aggregator */
5925 if (attr->aspath)
5926 {
5927 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005928 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005929 vty_out (vty, "Local");
5930 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005931 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005932 }
5933
paulb40d9392005-08-22 22:34:41 +00005934 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5935 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005936 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5937 vty_out (vty, ", (stale)");
5938 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005939 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005940 attr->extra->aggregator_as,
5941 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005942 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5943 vty_out (vty, ", (Received from a RR-client)");
5944 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5945 vty_out (vty, ", (Received from a RS-client)");
5946 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5947 vty_out (vty, ", (history entry)");
5948 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5949 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005950 vty_out (vty, "%s", VTY_NEWLINE);
5951
5952 /* Line2 display Next-hop, Neighbor, Router-id */
5953 if (p->family == AF_INET)
5954 {
5955 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005956 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005957 inet_ntoa (attr->nexthop));
5958 }
5959#ifdef HAVE_IPV6
5960 else
5961 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005962 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005963 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005964 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005965 buf, INET6_ADDRSTRLEN));
5966 }
5967#endif /* HAVE_IPV6 */
5968
5969 if (binfo->peer == bgp->peer_self)
5970 {
5971 vty_out (vty, " from %s ",
5972 p->family == AF_INET ? "0.0.0.0" : "::");
5973 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5974 }
5975 else
5976 {
5977 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5978 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005979 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02005980 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005981 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005982 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005983 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005984 else
5985 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5986 }
5987 vty_out (vty, "%s", VTY_NEWLINE);
5988
5989#ifdef HAVE_IPV6
5990 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005991 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005992 {
5993 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005994 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005995 buf, INET6_ADDRSTRLEN),
5996 VTY_NEWLINE);
5997 }
5998#endif /* HAVE_IPV6 */
5999
6000 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6001 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6002
6003 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006004 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006005
6006 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006007 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006008 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006009 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006010
Paul Jakmafb982c22007-05-04 20:15:47 +00006011 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006012 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006013
6014 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6015 vty_out (vty, ", valid");
6016
6017 if (binfo->peer != bgp->peer_self)
6018 {
6019 if (binfo->peer->as == binfo->peer->local_as)
6020 vty_out (vty, ", internal");
6021 else
6022 vty_out (vty, ", %s",
6023 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6024 }
6025 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6026 vty_out (vty, ", aggregated, local");
6027 else if (binfo->type != ZEBRA_ROUTE_BGP)
6028 vty_out (vty, ", sourced");
6029 else
6030 vty_out (vty, ", sourced, local");
6031
6032 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6033 vty_out (vty, ", atomic-aggregate");
6034
Josh Baileyde8d5df2011-07-20 20:46:01 -07006035 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6036 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6037 bgp_info_mpath_count (binfo)))
6038 vty_out (vty, ", multipath");
6039
paul718e3742002-12-13 20:15:29 +00006040 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6041 vty_out (vty, ", best");
6042
6043 vty_out (vty, "%s", VTY_NEWLINE);
6044
6045 /* Line 4 display Community */
6046 if (attr->community)
6047 vty_out (vty, " Community: %s%s", attr->community->str,
6048 VTY_NEWLINE);
6049
6050 /* Line 5 display Extended-community */
6051 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006052 vty_out (vty, " Extended Community: %s%s",
6053 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006054
6055 /* Line 6 display Originator, Cluster-id */
6056 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6057 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6058 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006059 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006060 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006061 vty_out (vty, " Originator: %s",
6062 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006063
6064 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6065 {
6066 int i;
6067 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006068 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6069 vty_out (vty, "%s ",
6070 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006071 }
6072 vty_out (vty, "%s", VTY_NEWLINE);
6073 }
Paul Jakma41367172007-08-06 15:24:51 +00006074
Paul Jakmafb982c22007-05-04 20:15:47 +00006075 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006076 bgp_damp_info_vty (vty, binfo);
6077
6078 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006079#ifdef HAVE_CLOCK_MONOTONIC
6080 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006081 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006082#else
6083 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6084#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006085 }
6086 vty_out (vty, "%s", VTY_NEWLINE);
6087}
6088
paulb40d9392005-08-22 22:34:41 +00006089#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 +00006090#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006091#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6092#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6093#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6094
6095enum bgp_show_type
6096{
6097 bgp_show_type_normal,
6098 bgp_show_type_regexp,
6099 bgp_show_type_prefix_list,
6100 bgp_show_type_filter_list,
6101 bgp_show_type_route_map,
6102 bgp_show_type_neighbor,
6103 bgp_show_type_cidr_only,
6104 bgp_show_type_prefix_longer,
6105 bgp_show_type_community_all,
6106 bgp_show_type_community,
6107 bgp_show_type_community_exact,
6108 bgp_show_type_community_list,
6109 bgp_show_type_community_list_exact,
6110 bgp_show_type_flap_statistics,
6111 bgp_show_type_flap_address,
6112 bgp_show_type_flap_prefix,
6113 bgp_show_type_flap_cidr_only,
6114 bgp_show_type_flap_regexp,
6115 bgp_show_type_flap_filter_list,
6116 bgp_show_type_flap_prefix_list,
6117 bgp_show_type_flap_prefix_longer,
6118 bgp_show_type_flap_route_map,
6119 bgp_show_type_flap_neighbor,
6120 bgp_show_type_dampend_paths,
6121 bgp_show_type_damp_neighbor
6122};
6123
ajs5a646652004-11-05 01:25:55 +00006124static int
paulfee0f4c2004-09-13 05:12:46 +00006125bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006126 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006127{
paul718e3742002-12-13 20:15:29 +00006128 struct bgp_info *ri;
6129 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006130 int header = 1;
paul718e3742002-12-13 20:15:29 +00006131 int display;
ajs5a646652004-11-05 01:25:55 +00006132 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006133
6134 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006135 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006136
paul718e3742002-12-13 20:15:29 +00006137 /* Start processing of routes. */
6138 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6139 if (rn->info != NULL)
6140 {
6141 display = 0;
6142
6143 for (ri = rn->info; ri; ri = ri->next)
6144 {
ajs5a646652004-11-05 01:25:55 +00006145 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006146 || type == bgp_show_type_flap_address
6147 || type == bgp_show_type_flap_prefix
6148 || type == bgp_show_type_flap_cidr_only
6149 || type == bgp_show_type_flap_regexp
6150 || type == bgp_show_type_flap_filter_list
6151 || type == bgp_show_type_flap_prefix_list
6152 || type == bgp_show_type_flap_prefix_longer
6153 || type == bgp_show_type_flap_route_map
6154 || type == bgp_show_type_flap_neighbor
6155 || type == bgp_show_type_dampend_paths
6156 || type == bgp_show_type_damp_neighbor)
6157 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006158 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006159 continue;
6160 }
6161 if (type == bgp_show_type_regexp
6162 || type == bgp_show_type_flap_regexp)
6163 {
ajs5a646652004-11-05 01:25:55 +00006164 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006165
6166 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6167 continue;
6168 }
6169 if (type == bgp_show_type_prefix_list
6170 || type == bgp_show_type_flap_prefix_list)
6171 {
ajs5a646652004-11-05 01:25:55 +00006172 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006173
6174 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6175 continue;
6176 }
6177 if (type == bgp_show_type_filter_list
6178 || type == bgp_show_type_flap_filter_list)
6179 {
ajs5a646652004-11-05 01:25:55 +00006180 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006181
6182 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6183 continue;
6184 }
6185 if (type == bgp_show_type_route_map
6186 || type == bgp_show_type_flap_route_map)
6187 {
ajs5a646652004-11-05 01:25:55 +00006188 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006189 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006190 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006191 int ret;
6192
Paul Jakmafb982c22007-05-04 20:15:47 +00006193 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006194 binfo.peer = ri->peer;
6195 binfo.attr = &dummy_attr;
6196
6197 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006198
6199 bgp_attr_extra_free (&dummy_attr);
6200
paul718e3742002-12-13 20:15:29 +00006201 if (ret == RMAP_DENYMATCH)
6202 continue;
6203 }
6204 if (type == bgp_show_type_neighbor
6205 || type == bgp_show_type_flap_neighbor
6206 || type == bgp_show_type_damp_neighbor)
6207 {
ajs5a646652004-11-05 01:25:55 +00006208 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006209
6210 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6211 continue;
6212 }
6213 if (type == bgp_show_type_cidr_only
6214 || type == bgp_show_type_flap_cidr_only)
6215 {
6216 u_int32_t destination;
6217
6218 destination = ntohl (rn->p.u.prefix4.s_addr);
6219 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6220 continue;
6221 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6222 continue;
6223 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6224 continue;
6225 }
6226 if (type == bgp_show_type_prefix_longer
6227 || type == bgp_show_type_flap_prefix_longer)
6228 {
ajs5a646652004-11-05 01:25:55 +00006229 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006230
6231 if (! prefix_match (p, &rn->p))
6232 continue;
6233 }
6234 if (type == bgp_show_type_community_all)
6235 {
6236 if (! ri->attr->community)
6237 continue;
6238 }
6239 if (type == bgp_show_type_community)
6240 {
ajs5a646652004-11-05 01:25:55 +00006241 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006242
6243 if (! ri->attr->community ||
6244 ! community_match (ri->attr->community, com))
6245 continue;
6246 }
6247 if (type == bgp_show_type_community_exact)
6248 {
ajs5a646652004-11-05 01:25:55 +00006249 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006250
6251 if (! ri->attr->community ||
6252 ! community_cmp (ri->attr->community, com))
6253 continue;
6254 }
6255 if (type == bgp_show_type_community_list)
6256 {
ajs5a646652004-11-05 01:25:55 +00006257 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006258
6259 if (! community_list_match (ri->attr->community, list))
6260 continue;
6261 }
6262 if (type == bgp_show_type_community_list_exact)
6263 {
ajs5a646652004-11-05 01:25:55 +00006264 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006265
6266 if (! community_list_exact_match (ri->attr->community, list))
6267 continue;
6268 }
6269 if (type == bgp_show_type_flap_address
6270 || type == bgp_show_type_flap_prefix)
6271 {
ajs5a646652004-11-05 01:25:55 +00006272 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006273
6274 if (! prefix_match (&rn->p, p))
6275 continue;
6276
6277 if (type == bgp_show_type_flap_prefix)
6278 if (p->prefixlen != rn->p.prefixlen)
6279 continue;
6280 }
6281 if (type == bgp_show_type_dampend_paths
6282 || type == bgp_show_type_damp_neighbor)
6283 {
6284 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6285 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6286 continue;
6287 }
6288
6289 if (header)
6290 {
hasso93406d82005-02-02 14:40:33 +00006291 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6292 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6293 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006294 if (type == bgp_show_type_dampend_paths
6295 || type == bgp_show_type_damp_neighbor)
6296 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6297 else if (type == bgp_show_type_flap_statistics
6298 || type == bgp_show_type_flap_address
6299 || type == bgp_show_type_flap_prefix
6300 || type == bgp_show_type_flap_cidr_only
6301 || type == bgp_show_type_flap_regexp
6302 || type == bgp_show_type_flap_filter_list
6303 || type == bgp_show_type_flap_prefix_list
6304 || type == bgp_show_type_flap_prefix_longer
6305 || type == bgp_show_type_flap_route_map
6306 || type == bgp_show_type_flap_neighbor)
6307 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6308 else
6309 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006310 header = 0;
6311 }
6312
6313 if (type == bgp_show_type_dampend_paths
6314 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006315 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006316 else if (type == bgp_show_type_flap_statistics
6317 || type == bgp_show_type_flap_address
6318 || type == bgp_show_type_flap_prefix
6319 || type == bgp_show_type_flap_cidr_only
6320 || type == bgp_show_type_flap_regexp
6321 || type == bgp_show_type_flap_filter_list
6322 || type == bgp_show_type_flap_prefix_list
6323 || type == bgp_show_type_flap_prefix_longer
6324 || type == bgp_show_type_flap_route_map
6325 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006326 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006327 else
ajs5a646652004-11-05 01:25:55 +00006328 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006329 display++;
6330 }
6331 if (display)
ajs5a646652004-11-05 01:25:55 +00006332 output_count++;
paul718e3742002-12-13 20:15:29 +00006333 }
6334
6335 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006336 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006337 {
6338 if (type == bgp_show_type_normal)
6339 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6340 }
6341 else
6342 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006343 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006344
6345 return CMD_SUCCESS;
6346}
6347
ajs5a646652004-11-05 01:25:55 +00006348static int
paulfee0f4c2004-09-13 05:12:46 +00006349bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006350 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006351{
6352 struct bgp_table *table;
6353
6354 if (bgp == NULL) {
6355 bgp = bgp_get_default ();
6356 }
6357
6358 if (bgp == NULL)
6359 {
6360 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6361 return CMD_WARNING;
6362 }
6363
6364
6365 table = bgp->rib[afi][safi];
6366
ajs5a646652004-11-05 01:25:55 +00006367 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006368}
6369
paul718e3742002-12-13 20:15:29 +00006370/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006371static void
paul718e3742002-12-13 20:15:29 +00006372route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6373 struct bgp_node *rn,
6374 struct prefix_rd *prd, afi_t afi, safi_t safi)
6375{
6376 struct bgp_info *ri;
6377 struct prefix *p;
6378 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006379 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006380 char buf1[INET6_ADDRSTRLEN];
6381 char buf2[INET6_ADDRSTRLEN];
6382 int count = 0;
6383 int best = 0;
6384 int suppress = 0;
6385 int no_export = 0;
6386 int no_advertise = 0;
6387 int local_as = 0;
6388 int first = 0;
6389
6390 p = &rn->p;
6391 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6392 (safi == SAFI_MPLS_VPN ?
6393 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6394 safi == SAFI_MPLS_VPN ? ":" : "",
6395 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6396 p->prefixlen, VTY_NEWLINE);
6397
6398 for (ri = rn->info; ri; ri = ri->next)
6399 {
6400 count++;
6401 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6402 {
6403 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006404 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006405 suppress = 1;
6406 if (ri->attr->community != NULL)
6407 {
6408 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6409 no_advertise = 1;
6410 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6411 no_export = 1;
6412 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6413 local_as = 1;
6414 }
6415 }
6416 }
6417
6418 vty_out (vty, "Paths: (%d available", count);
6419 if (best)
6420 {
6421 vty_out (vty, ", best #%d", best);
6422 if (safi == SAFI_UNICAST)
6423 vty_out (vty, ", table Default-IP-Routing-Table");
6424 }
6425 else
6426 vty_out (vty, ", no best path");
6427 if (no_advertise)
6428 vty_out (vty, ", not advertised to any peer");
6429 else if (no_export)
6430 vty_out (vty, ", not advertised to EBGP peer");
6431 else if (local_as)
6432 vty_out (vty, ", not advertised outside local AS");
6433 if (suppress)
6434 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6435 vty_out (vty, ")%s", VTY_NEWLINE);
6436
6437 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006438 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006439 {
6440 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6441 {
6442 if (! first)
6443 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6444 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6445 first = 1;
6446 }
6447 }
6448 if (! first)
6449 vty_out (vty, " Not advertised to any peer");
6450 vty_out (vty, "%s", VTY_NEWLINE);
6451}
6452
6453/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006454static int
paulfee0f4c2004-09-13 05:12:46 +00006455bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006456 struct bgp_table *rib, const char *ip_str,
6457 afi_t afi, safi_t safi, struct prefix_rd *prd,
6458 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006459{
6460 int ret;
6461 int header;
6462 int display = 0;
6463 struct prefix match;
6464 struct bgp_node *rn;
6465 struct bgp_node *rm;
6466 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006467 struct bgp_table *table;
6468
paul718e3742002-12-13 20:15:29 +00006469 /* Check IP address argument. */
6470 ret = str2prefix (ip_str, &match);
6471 if (! ret)
6472 {
6473 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6474 return CMD_WARNING;
6475 }
6476
6477 match.family = afi2family (afi);
6478
6479 if (safi == SAFI_MPLS_VPN)
6480 {
paulfee0f4c2004-09-13 05:12:46 +00006481 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006482 {
6483 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6484 continue;
6485
6486 if ((table = rn->info) != NULL)
6487 {
6488 header = 1;
6489
6490 if ((rm = bgp_node_match (table, &match)) != NULL)
6491 {
6492 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006493 {
6494 bgp_unlock_node (rm);
6495 continue;
6496 }
paul718e3742002-12-13 20:15:29 +00006497
6498 for (ri = rm->info; ri; ri = ri->next)
6499 {
6500 if (header)
6501 {
6502 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6503 AFI_IP, SAFI_MPLS_VPN);
6504
6505 header = 0;
6506 }
6507 display++;
6508 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6509 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006510
6511 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006512 }
6513 }
6514 }
6515 }
6516 else
6517 {
6518 header = 1;
6519
paulfee0f4c2004-09-13 05:12:46 +00006520 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006521 {
6522 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6523 {
6524 for (ri = rn->info; ri; ri = ri->next)
6525 {
6526 if (header)
6527 {
6528 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6529 header = 0;
6530 }
6531 display++;
6532 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6533 }
6534 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006535
6536 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006537 }
6538 }
6539
6540 if (! display)
6541 {
6542 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6543 return CMD_WARNING;
6544 }
6545
6546 return CMD_SUCCESS;
6547}
6548
paulfee0f4c2004-09-13 05:12:46 +00006549/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006550static int
paulfd79ac92004-10-13 05:06:08 +00006551bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006552 afi_t afi, safi_t safi, struct prefix_rd *prd,
6553 int prefix_check)
6554{
6555 struct bgp *bgp;
6556
6557 /* BGP structure lookup. */
6558 if (view_name)
6559 {
6560 bgp = bgp_lookup_by_name (view_name);
6561 if (bgp == NULL)
6562 {
6563 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6564 return CMD_WARNING;
6565 }
6566 }
6567 else
6568 {
6569 bgp = bgp_get_default ();
6570 if (bgp == NULL)
6571 {
6572 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6573 return CMD_WARNING;
6574 }
6575 }
6576
6577 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6578 afi, safi, prd, prefix_check);
6579}
6580
paul718e3742002-12-13 20:15:29 +00006581/* BGP route print out function. */
6582DEFUN (show_ip_bgp,
6583 show_ip_bgp_cmd,
6584 "show ip bgp",
6585 SHOW_STR
6586 IP_STR
6587 BGP_STR)
6588{
ajs5a646652004-11-05 01:25:55 +00006589 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006590}
6591
6592DEFUN (show_ip_bgp_ipv4,
6593 show_ip_bgp_ipv4_cmd,
6594 "show ip bgp ipv4 (unicast|multicast)",
6595 SHOW_STR
6596 IP_STR
6597 BGP_STR
6598 "Address family\n"
6599 "Address Family modifier\n"
6600 "Address Family modifier\n")
6601{
6602 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006603 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6604 NULL);
paul718e3742002-12-13 20:15:29 +00006605
ajs5a646652004-11-05 01:25:55 +00006606 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006607}
6608
Michael Lambert95cbbd22010-07-23 14:43:04 -04006609ALIAS (show_ip_bgp_ipv4,
6610 show_bgp_ipv4_safi_cmd,
6611 "show bgp ipv4 (unicast|multicast)",
6612 SHOW_STR
6613 BGP_STR
6614 "Address family\n"
6615 "Address Family modifier\n"
6616 "Address Family modifier\n")
6617
paul718e3742002-12-13 20:15:29 +00006618DEFUN (show_ip_bgp_route,
6619 show_ip_bgp_route_cmd,
6620 "show ip bgp A.B.C.D",
6621 SHOW_STR
6622 IP_STR
6623 BGP_STR
6624 "Network in the BGP routing table to display\n")
6625{
6626 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6627}
6628
6629DEFUN (show_ip_bgp_ipv4_route,
6630 show_ip_bgp_ipv4_route_cmd,
6631 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6632 SHOW_STR
6633 IP_STR
6634 BGP_STR
6635 "Address family\n"
6636 "Address Family modifier\n"
6637 "Address Family modifier\n"
6638 "Network in the BGP routing table to display\n")
6639{
6640 if (strncmp (argv[0], "m", 1) == 0)
6641 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6642
6643 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6644}
6645
Michael Lambert95cbbd22010-07-23 14:43:04 -04006646ALIAS (show_ip_bgp_ipv4_route,
6647 show_bgp_ipv4_safi_route_cmd,
6648 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6649 SHOW_STR
6650 BGP_STR
6651 "Address family\n"
6652 "Address Family modifier\n"
6653 "Address Family modifier\n"
6654 "Network in the BGP routing table to display\n")
6655
paul718e3742002-12-13 20:15:29 +00006656DEFUN (show_ip_bgp_vpnv4_all_route,
6657 show_ip_bgp_vpnv4_all_route_cmd,
6658 "show ip bgp vpnv4 all A.B.C.D",
6659 SHOW_STR
6660 IP_STR
6661 BGP_STR
6662 "Display VPNv4 NLRI specific information\n"
6663 "Display information about all VPNv4 NLRIs\n"
6664 "Network in the BGP routing table to display\n")
6665{
6666 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6667}
6668
6669DEFUN (show_ip_bgp_vpnv4_rd_route,
6670 show_ip_bgp_vpnv4_rd_route_cmd,
6671 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6672 SHOW_STR
6673 IP_STR
6674 BGP_STR
6675 "Display VPNv4 NLRI specific information\n"
6676 "Display information for a route distinguisher\n"
6677 "VPN Route Distinguisher\n"
6678 "Network in the BGP routing table to display\n")
6679{
6680 int ret;
6681 struct prefix_rd prd;
6682
6683 ret = str2prefix_rd (argv[0], &prd);
6684 if (! ret)
6685 {
6686 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6687 return CMD_WARNING;
6688 }
6689 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6690}
6691
6692DEFUN (show_ip_bgp_prefix,
6693 show_ip_bgp_prefix_cmd,
6694 "show ip bgp A.B.C.D/M",
6695 SHOW_STR
6696 IP_STR
6697 BGP_STR
6698 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6699{
6700 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6701}
6702
6703DEFUN (show_ip_bgp_ipv4_prefix,
6704 show_ip_bgp_ipv4_prefix_cmd,
6705 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6706 SHOW_STR
6707 IP_STR
6708 BGP_STR
6709 "Address family\n"
6710 "Address Family modifier\n"
6711 "Address Family modifier\n"
6712 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6713{
6714 if (strncmp (argv[0], "m", 1) == 0)
6715 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6716
6717 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6718}
6719
Michael Lambert95cbbd22010-07-23 14:43:04 -04006720ALIAS (show_ip_bgp_ipv4_prefix,
6721 show_bgp_ipv4_safi_prefix_cmd,
6722 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6723 SHOW_STR
6724 BGP_STR
6725 "Address family\n"
6726 "Address Family modifier\n"
6727 "Address Family modifier\n"
6728 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6729
paul718e3742002-12-13 20:15:29 +00006730DEFUN (show_ip_bgp_vpnv4_all_prefix,
6731 show_ip_bgp_vpnv4_all_prefix_cmd,
6732 "show ip bgp vpnv4 all A.B.C.D/M",
6733 SHOW_STR
6734 IP_STR
6735 BGP_STR
6736 "Display VPNv4 NLRI specific information\n"
6737 "Display information about all VPNv4 NLRIs\n"
6738 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6739{
6740 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6741}
6742
6743DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6744 show_ip_bgp_vpnv4_rd_prefix_cmd,
6745 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6746 SHOW_STR
6747 IP_STR
6748 BGP_STR
6749 "Display VPNv4 NLRI specific information\n"
6750 "Display information for a route distinguisher\n"
6751 "VPN Route Distinguisher\n"
6752 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6753{
6754 int ret;
6755 struct prefix_rd prd;
6756
6757 ret = str2prefix_rd (argv[0], &prd);
6758 if (! ret)
6759 {
6760 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6761 return CMD_WARNING;
6762 }
6763 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6764}
6765
6766DEFUN (show_ip_bgp_view,
6767 show_ip_bgp_view_cmd,
6768 "show ip bgp view WORD",
6769 SHOW_STR
6770 IP_STR
6771 BGP_STR
6772 "BGP view\n"
6773 "BGP view name\n")
6774{
paulbb46e942003-10-24 19:02:03 +00006775 struct bgp *bgp;
6776
6777 /* BGP structure lookup. */
6778 bgp = bgp_lookup_by_name (argv[0]);
6779 if (bgp == NULL)
6780 {
6781 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6782 return CMD_WARNING;
6783 }
6784
ajs5a646652004-11-05 01:25:55 +00006785 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006786}
6787
6788DEFUN (show_ip_bgp_view_route,
6789 show_ip_bgp_view_route_cmd,
6790 "show ip bgp view WORD A.B.C.D",
6791 SHOW_STR
6792 IP_STR
6793 BGP_STR
6794 "BGP view\n"
6795 "BGP view name\n"
6796 "Network in the BGP routing table to display\n")
6797{
6798 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6799}
6800
6801DEFUN (show_ip_bgp_view_prefix,
6802 show_ip_bgp_view_prefix_cmd,
6803 "show ip bgp view WORD A.B.C.D/M",
6804 SHOW_STR
6805 IP_STR
6806 BGP_STR
6807 "BGP view\n"
6808 "BGP view name\n"
6809 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6810{
6811 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6812}
6813
6814#ifdef HAVE_IPV6
6815DEFUN (show_bgp,
6816 show_bgp_cmd,
6817 "show bgp",
6818 SHOW_STR
6819 BGP_STR)
6820{
ajs5a646652004-11-05 01:25:55 +00006821 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6822 NULL);
paul718e3742002-12-13 20:15:29 +00006823}
6824
6825ALIAS (show_bgp,
6826 show_bgp_ipv6_cmd,
6827 "show bgp ipv6",
6828 SHOW_STR
6829 BGP_STR
6830 "Address family\n")
6831
Michael Lambert95cbbd22010-07-23 14:43:04 -04006832DEFUN (show_bgp_ipv6_safi,
6833 show_bgp_ipv6_safi_cmd,
6834 "show bgp ipv6 (unicast|multicast)",
6835 SHOW_STR
6836 BGP_STR
6837 "Address family\n"
6838 "Address Family modifier\n"
6839 "Address Family modifier\n")
6840{
6841 if (strncmp (argv[0], "m", 1) == 0)
6842 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6843 NULL);
6844
6845 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6846}
6847
paul718e3742002-12-13 20:15:29 +00006848/* old command */
6849DEFUN (show_ipv6_bgp,
6850 show_ipv6_bgp_cmd,
6851 "show ipv6 bgp",
6852 SHOW_STR
6853 IP_STR
6854 BGP_STR)
6855{
ajs5a646652004-11-05 01:25:55 +00006856 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6857 NULL);
paul718e3742002-12-13 20:15:29 +00006858}
6859
6860DEFUN (show_bgp_route,
6861 show_bgp_route_cmd,
6862 "show bgp X:X::X:X",
6863 SHOW_STR
6864 BGP_STR
6865 "Network in the BGP routing table to display\n")
6866{
6867 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6868}
6869
6870ALIAS (show_bgp_route,
6871 show_bgp_ipv6_route_cmd,
6872 "show bgp ipv6 X:X::X:X",
6873 SHOW_STR
6874 BGP_STR
6875 "Address family\n"
6876 "Network in the BGP routing table to display\n")
6877
Michael Lambert95cbbd22010-07-23 14:43:04 -04006878DEFUN (show_bgp_ipv6_safi_route,
6879 show_bgp_ipv6_safi_route_cmd,
6880 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6881 SHOW_STR
6882 BGP_STR
6883 "Address family\n"
6884 "Address Family modifier\n"
6885 "Address Family modifier\n"
6886 "Network in the BGP routing table to display\n")
6887{
6888 if (strncmp (argv[0], "m", 1) == 0)
6889 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6890
6891 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6892}
6893
paul718e3742002-12-13 20:15:29 +00006894/* old command */
6895DEFUN (show_ipv6_bgp_route,
6896 show_ipv6_bgp_route_cmd,
6897 "show ipv6 bgp X:X::X:X",
6898 SHOW_STR
6899 IP_STR
6900 BGP_STR
6901 "Network in the BGP routing table to display\n")
6902{
6903 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6904}
6905
6906DEFUN (show_bgp_prefix,
6907 show_bgp_prefix_cmd,
6908 "show bgp X:X::X:X/M",
6909 SHOW_STR
6910 BGP_STR
6911 "IPv6 prefix <network>/<length>\n")
6912{
6913 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6914}
6915
6916ALIAS (show_bgp_prefix,
6917 show_bgp_ipv6_prefix_cmd,
6918 "show bgp ipv6 X:X::X:X/M",
6919 SHOW_STR
6920 BGP_STR
6921 "Address family\n"
6922 "IPv6 prefix <network>/<length>\n")
6923
Michael Lambert95cbbd22010-07-23 14:43:04 -04006924DEFUN (show_bgp_ipv6_safi_prefix,
6925 show_bgp_ipv6_safi_prefix_cmd,
6926 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6927 SHOW_STR
6928 BGP_STR
6929 "Address family\n"
6930 "Address Family modifier\n"
6931 "Address Family modifier\n"
6932 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6933{
6934 if (strncmp (argv[0], "m", 1) == 0)
6935 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6936
6937 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6938}
6939
paul718e3742002-12-13 20:15:29 +00006940/* old command */
6941DEFUN (show_ipv6_bgp_prefix,
6942 show_ipv6_bgp_prefix_cmd,
6943 "show ipv6 bgp X:X::X:X/M",
6944 SHOW_STR
6945 IP_STR
6946 BGP_STR
6947 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6948{
6949 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6950}
6951
paulbb46e942003-10-24 19:02:03 +00006952DEFUN (show_bgp_view,
6953 show_bgp_view_cmd,
6954 "show bgp view WORD",
6955 SHOW_STR
6956 BGP_STR
6957 "BGP view\n"
6958 "View name\n")
6959{
6960 struct bgp *bgp;
6961
6962 /* BGP structure lookup. */
6963 bgp = bgp_lookup_by_name (argv[0]);
6964 if (bgp == NULL)
6965 {
6966 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6967 return CMD_WARNING;
6968 }
6969
ajs5a646652004-11-05 01:25:55 +00006970 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006971}
6972
6973ALIAS (show_bgp_view,
6974 show_bgp_view_ipv6_cmd,
6975 "show bgp view WORD ipv6",
6976 SHOW_STR
6977 BGP_STR
6978 "BGP view\n"
6979 "View name\n"
6980 "Address family\n")
6981
6982DEFUN (show_bgp_view_route,
6983 show_bgp_view_route_cmd,
6984 "show bgp view WORD X:X::X:X",
6985 SHOW_STR
6986 BGP_STR
6987 "BGP view\n"
6988 "View name\n"
6989 "Network in the BGP routing table to display\n")
6990{
6991 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6992}
6993
6994ALIAS (show_bgp_view_route,
6995 show_bgp_view_ipv6_route_cmd,
6996 "show bgp view WORD ipv6 X:X::X:X",
6997 SHOW_STR
6998 BGP_STR
6999 "BGP view\n"
7000 "View name\n"
7001 "Address family\n"
7002 "Network in the BGP routing table to display\n")
7003
7004DEFUN (show_bgp_view_prefix,
7005 show_bgp_view_prefix_cmd,
7006 "show bgp view WORD X:X::X:X/M",
7007 SHOW_STR
7008 BGP_STR
7009 "BGP view\n"
7010 "View name\n"
7011 "IPv6 prefix <network>/<length>\n")
7012{
7013 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7014}
7015
7016ALIAS (show_bgp_view_prefix,
7017 show_bgp_view_ipv6_prefix_cmd,
7018 "show bgp view WORD ipv6 X:X::X:X/M",
7019 SHOW_STR
7020 BGP_STR
7021 "BGP view\n"
7022 "View name\n"
7023 "Address family\n"
7024 "IPv6 prefix <network>/<length>\n")
7025
paul718e3742002-12-13 20:15:29 +00007026/* old command */
7027DEFUN (show_ipv6_mbgp,
7028 show_ipv6_mbgp_cmd,
7029 "show ipv6 mbgp",
7030 SHOW_STR
7031 IP_STR
7032 MBGP_STR)
7033{
ajs5a646652004-11-05 01:25:55 +00007034 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7035 NULL);
paul718e3742002-12-13 20:15:29 +00007036}
7037
7038/* old command */
7039DEFUN (show_ipv6_mbgp_route,
7040 show_ipv6_mbgp_route_cmd,
7041 "show ipv6 mbgp X:X::X:X",
7042 SHOW_STR
7043 IP_STR
7044 MBGP_STR
7045 "Network in the MBGP routing table to display\n")
7046{
7047 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7048}
7049
7050/* old command */
7051DEFUN (show_ipv6_mbgp_prefix,
7052 show_ipv6_mbgp_prefix_cmd,
7053 "show ipv6 mbgp X:X::X:X/M",
7054 SHOW_STR
7055 IP_STR
7056 MBGP_STR
7057 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7058{
7059 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7060}
7061#endif
7062
paul718e3742002-12-13 20:15:29 +00007063
paul94f2b392005-06-28 12:44:16 +00007064static int
paulfd79ac92004-10-13 05:06:08 +00007065bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007066 safi_t safi, enum bgp_show_type type)
7067{
7068 int i;
7069 struct buffer *b;
7070 char *regstr;
7071 int first;
7072 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007073 int rc;
paul718e3742002-12-13 20:15:29 +00007074
7075 first = 0;
7076 b = buffer_new (1024);
7077 for (i = 0; i < argc; i++)
7078 {
7079 if (first)
7080 buffer_putc (b, ' ');
7081 else
7082 {
7083 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7084 continue;
7085 first = 1;
7086 }
7087
7088 buffer_putstr (b, argv[i]);
7089 }
7090 buffer_putc (b, '\0');
7091
7092 regstr = buffer_getstr (b);
7093 buffer_free (b);
7094
7095 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007096 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007097 if (! regex)
7098 {
7099 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7100 VTY_NEWLINE);
7101 return CMD_WARNING;
7102 }
7103
ajs5a646652004-11-05 01:25:55 +00007104 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7105 bgp_regex_free (regex);
7106 return rc;
paul718e3742002-12-13 20:15:29 +00007107}
7108
7109DEFUN (show_ip_bgp_regexp,
7110 show_ip_bgp_regexp_cmd,
7111 "show ip bgp regexp .LINE",
7112 SHOW_STR
7113 IP_STR
7114 BGP_STR
7115 "Display routes matching the AS path regular expression\n"
7116 "A regular-expression to match the BGP AS paths\n")
7117{
7118 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7119 bgp_show_type_regexp);
7120}
7121
7122DEFUN (show_ip_bgp_flap_regexp,
7123 show_ip_bgp_flap_regexp_cmd,
7124 "show ip bgp flap-statistics regexp .LINE",
7125 SHOW_STR
7126 IP_STR
7127 BGP_STR
7128 "Display flap statistics of routes\n"
7129 "Display routes matching the AS path regular expression\n"
7130 "A regular-expression to match the BGP AS paths\n")
7131{
7132 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7133 bgp_show_type_flap_regexp);
7134}
7135
7136DEFUN (show_ip_bgp_ipv4_regexp,
7137 show_ip_bgp_ipv4_regexp_cmd,
7138 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7139 SHOW_STR
7140 IP_STR
7141 BGP_STR
7142 "Address family\n"
7143 "Address Family modifier\n"
7144 "Address Family modifier\n"
7145 "Display routes matching the AS path regular expression\n"
7146 "A regular-expression to match the BGP AS paths\n")
7147{
7148 if (strncmp (argv[0], "m", 1) == 0)
7149 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7150 bgp_show_type_regexp);
7151
7152 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7153 bgp_show_type_regexp);
7154}
7155
7156#ifdef HAVE_IPV6
7157DEFUN (show_bgp_regexp,
7158 show_bgp_regexp_cmd,
7159 "show bgp regexp .LINE",
7160 SHOW_STR
7161 BGP_STR
7162 "Display routes matching the AS path regular expression\n"
7163 "A regular-expression to match the BGP AS paths\n")
7164{
7165 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7166 bgp_show_type_regexp);
7167}
7168
7169ALIAS (show_bgp_regexp,
7170 show_bgp_ipv6_regexp_cmd,
7171 "show bgp ipv6 regexp .LINE",
7172 SHOW_STR
7173 BGP_STR
7174 "Address family\n"
7175 "Display routes matching the AS path regular expression\n"
7176 "A regular-expression to match the BGP AS paths\n")
7177
7178/* old command */
7179DEFUN (show_ipv6_bgp_regexp,
7180 show_ipv6_bgp_regexp_cmd,
7181 "show ipv6 bgp regexp .LINE",
7182 SHOW_STR
7183 IP_STR
7184 BGP_STR
7185 "Display routes matching the AS path regular expression\n"
7186 "A regular-expression to match the BGP AS paths\n")
7187{
7188 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7189 bgp_show_type_regexp);
7190}
7191
7192/* old command */
7193DEFUN (show_ipv6_mbgp_regexp,
7194 show_ipv6_mbgp_regexp_cmd,
7195 "show ipv6 mbgp regexp .LINE",
7196 SHOW_STR
7197 IP_STR
7198 BGP_STR
7199 "Display routes matching the AS path regular expression\n"
7200 "A regular-expression to match the MBGP AS paths\n")
7201{
7202 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7203 bgp_show_type_regexp);
7204}
7205#endif /* HAVE_IPV6 */
7206
paul94f2b392005-06-28 12:44:16 +00007207static int
paulfd79ac92004-10-13 05:06:08 +00007208bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007209 safi_t safi, enum bgp_show_type type)
7210{
7211 struct prefix_list *plist;
7212
7213 plist = prefix_list_lookup (afi, prefix_list_str);
7214 if (plist == NULL)
7215 {
7216 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7217 prefix_list_str, VTY_NEWLINE);
7218 return CMD_WARNING;
7219 }
7220
ajs5a646652004-11-05 01:25:55 +00007221 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007222}
7223
7224DEFUN (show_ip_bgp_prefix_list,
7225 show_ip_bgp_prefix_list_cmd,
7226 "show ip bgp prefix-list WORD",
7227 SHOW_STR
7228 IP_STR
7229 BGP_STR
7230 "Display routes conforming to the prefix-list\n"
7231 "IP prefix-list name\n")
7232{
7233 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7234 bgp_show_type_prefix_list);
7235}
7236
7237DEFUN (show_ip_bgp_flap_prefix_list,
7238 show_ip_bgp_flap_prefix_list_cmd,
7239 "show ip bgp flap-statistics prefix-list WORD",
7240 SHOW_STR
7241 IP_STR
7242 BGP_STR
7243 "Display flap statistics of routes\n"
7244 "Display routes conforming to the prefix-list\n"
7245 "IP prefix-list name\n")
7246{
7247 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7248 bgp_show_type_flap_prefix_list);
7249}
7250
7251DEFUN (show_ip_bgp_ipv4_prefix_list,
7252 show_ip_bgp_ipv4_prefix_list_cmd,
7253 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7254 SHOW_STR
7255 IP_STR
7256 BGP_STR
7257 "Address family\n"
7258 "Address Family modifier\n"
7259 "Address Family modifier\n"
7260 "Display routes conforming to the prefix-list\n"
7261 "IP prefix-list name\n")
7262{
7263 if (strncmp (argv[0], "m", 1) == 0)
7264 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7265 bgp_show_type_prefix_list);
7266
7267 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7268 bgp_show_type_prefix_list);
7269}
7270
7271#ifdef HAVE_IPV6
7272DEFUN (show_bgp_prefix_list,
7273 show_bgp_prefix_list_cmd,
7274 "show bgp prefix-list WORD",
7275 SHOW_STR
7276 BGP_STR
7277 "Display routes conforming to the prefix-list\n"
7278 "IPv6 prefix-list name\n")
7279{
7280 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7281 bgp_show_type_prefix_list);
7282}
7283
7284ALIAS (show_bgp_prefix_list,
7285 show_bgp_ipv6_prefix_list_cmd,
7286 "show bgp ipv6 prefix-list WORD",
7287 SHOW_STR
7288 BGP_STR
7289 "Address family\n"
7290 "Display routes conforming to the prefix-list\n"
7291 "IPv6 prefix-list name\n")
7292
7293/* old command */
7294DEFUN (show_ipv6_bgp_prefix_list,
7295 show_ipv6_bgp_prefix_list_cmd,
7296 "show ipv6 bgp prefix-list WORD",
7297 SHOW_STR
7298 IPV6_STR
7299 BGP_STR
7300 "Display routes matching the prefix-list\n"
7301 "IPv6 prefix-list name\n")
7302{
7303 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7304 bgp_show_type_prefix_list);
7305}
7306
7307/* old command */
7308DEFUN (show_ipv6_mbgp_prefix_list,
7309 show_ipv6_mbgp_prefix_list_cmd,
7310 "show ipv6 mbgp prefix-list WORD",
7311 SHOW_STR
7312 IPV6_STR
7313 MBGP_STR
7314 "Display routes matching the prefix-list\n"
7315 "IPv6 prefix-list name\n")
7316{
7317 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7318 bgp_show_type_prefix_list);
7319}
7320#endif /* HAVE_IPV6 */
7321
paul94f2b392005-06-28 12:44:16 +00007322static int
paulfd79ac92004-10-13 05:06:08 +00007323bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007324 safi_t safi, enum bgp_show_type type)
7325{
7326 struct as_list *as_list;
7327
7328 as_list = as_list_lookup (filter);
7329 if (as_list == NULL)
7330 {
7331 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7332 return CMD_WARNING;
7333 }
7334
ajs5a646652004-11-05 01:25:55 +00007335 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007336}
7337
7338DEFUN (show_ip_bgp_filter_list,
7339 show_ip_bgp_filter_list_cmd,
7340 "show ip bgp filter-list WORD",
7341 SHOW_STR
7342 IP_STR
7343 BGP_STR
7344 "Display routes conforming to the filter-list\n"
7345 "Regular expression access list name\n")
7346{
7347 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7348 bgp_show_type_filter_list);
7349}
7350
7351DEFUN (show_ip_bgp_flap_filter_list,
7352 show_ip_bgp_flap_filter_list_cmd,
7353 "show ip bgp flap-statistics filter-list WORD",
7354 SHOW_STR
7355 IP_STR
7356 BGP_STR
7357 "Display flap statistics of routes\n"
7358 "Display routes conforming to the filter-list\n"
7359 "Regular expression access list name\n")
7360{
7361 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7362 bgp_show_type_flap_filter_list);
7363}
7364
7365DEFUN (show_ip_bgp_ipv4_filter_list,
7366 show_ip_bgp_ipv4_filter_list_cmd,
7367 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7368 SHOW_STR
7369 IP_STR
7370 BGP_STR
7371 "Address family\n"
7372 "Address Family modifier\n"
7373 "Address Family modifier\n"
7374 "Display routes conforming to the filter-list\n"
7375 "Regular expression access list name\n")
7376{
7377 if (strncmp (argv[0], "m", 1) == 0)
7378 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7379 bgp_show_type_filter_list);
7380
7381 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7382 bgp_show_type_filter_list);
7383}
7384
7385#ifdef HAVE_IPV6
7386DEFUN (show_bgp_filter_list,
7387 show_bgp_filter_list_cmd,
7388 "show bgp filter-list WORD",
7389 SHOW_STR
7390 BGP_STR
7391 "Display routes conforming to the filter-list\n"
7392 "Regular expression access list name\n")
7393{
7394 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7395 bgp_show_type_filter_list);
7396}
7397
7398ALIAS (show_bgp_filter_list,
7399 show_bgp_ipv6_filter_list_cmd,
7400 "show bgp ipv6 filter-list WORD",
7401 SHOW_STR
7402 BGP_STR
7403 "Address family\n"
7404 "Display routes conforming to the filter-list\n"
7405 "Regular expression access list name\n")
7406
7407/* old command */
7408DEFUN (show_ipv6_bgp_filter_list,
7409 show_ipv6_bgp_filter_list_cmd,
7410 "show ipv6 bgp filter-list WORD",
7411 SHOW_STR
7412 IPV6_STR
7413 BGP_STR
7414 "Display routes conforming to the filter-list\n"
7415 "Regular expression access list name\n")
7416{
7417 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7418 bgp_show_type_filter_list);
7419}
7420
7421/* old command */
7422DEFUN (show_ipv6_mbgp_filter_list,
7423 show_ipv6_mbgp_filter_list_cmd,
7424 "show ipv6 mbgp filter-list WORD",
7425 SHOW_STR
7426 IPV6_STR
7427 MBGP_STR
7428 "Display routes conforming to the filter-list\n"
7429 "Regular expression access list name\n")
7430{
7431 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7432 bgp_show_type_filter_list);
7433}
7434#endif /* HAVE_IPV6 */
7435
paul94f2b392005-06-28 12:44:16 +00007436static int
paulfd79ac92004-10-13 05:06:08 +00007437bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007438 safi_t safi, enum bgp_show_type type)
7439{
7440 struct route_map *rmap;
7441
7442 rmap = route_map_lookup_by_name (rmap_str);
7443 if (! rmap)
7444 {
7445 vty_out (vty, "%% %s is not a valid route-map name%s",
7446 rmap_str, VTY_NEWLINE);
7447 return CMD_WARNING;
7448 }
7449
ajs5a646652004-11-05 01:25:55 +00007450 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007451}
7452
7453DEFUN (show_ip_bgp_route_map,
7454 show_ip_bgp_route_map_cmd,
7455 "show ip bgp route-map WORD",
7456 SHOW_STR
7457 IP_STR
7458 BGP_STR
7459 "Display routes matching the route-map\n"
7460 "A route-map to match on\n")
7461{
7462 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7463 bgp_show_type_route_map);
7464}
7465
7466DEFUN (show_ip_bgp_flap_route_map,
7467 show_ip_bgp_flap_route_map_cmd,
7468 "show ip bgp flap-statistics route-map WORD",
7469 SHOW_STR
7470 IP_STR
7471 BGP_STR
7472 "Display flap statistics of routes\n"
7473 "Display routes matching the route-map\n"
7474 "A route-map to match on\n")
7475{
7476 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7477 bgp_show_type_flap_route_map);
7478}
7479
7480DEFUN (show_ip_bgp_ipv4_route_map,
7481 show_ip_bgp_ipv4_route_map_cmd,
7482 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7483 SHOW_STR
7484 IP_STR
7485 BGP_STR
7486 "Address family\n"
7487 "Address Family modifier\n"
7488 "Address Family modifier\n"
7489 "Display routes matching the route-map\n"
7490 "A route-map to match on\n")
7491{
7492 if (strncmp (argv[0], "m", 1) == 0)
7493 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7494 bgp_show_type_route_map);
7495
7496 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7497 bgp_show_type_route_map);
7498}
7499
7500DEFUN (show_bgp_route_map,
7501 show_bgp_route_map_cmd,
7502 "show bgp route-map WORD",
7503 SHOW_STR
7504 BGP_STR
7505 "Display routes matching the route-map\n"
7506 "A route-map to match on\n")
7507{
7508 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7509 bgp_show_type_route_map);
7510}
7511
7512ALIAS (show_bgp_route_map,
7513 show_bgp_ipv6_route_map_cmd,
7514 "show bgp ipv6 route-map WORD",
7515 SHOW_STR
7516 BGP_STR
7517 "Address family\n"
7518 "Display routes matching the route-map\n"
7519 "A route-map to match on\n")
7520
7521DEFUN (show_ip_bgp_cidr_only,
7522 show_ip_bgp_cidr_only_cmd,
7523 "show ip bgp cidr-only",
7524 SHOW_STR
7525 IP_STR
7526 BGP_STR
7527 "Display only routes with non-natural netmasks\n")
7528{
7529 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007530 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007531}
7532
7533DEFUN (show_ip_bgp_flap_cidr_only,
7534 show_ip_bgp_flap_cidr_only_cmd,
7535 "show ip bgp flap-statistics cidr-only",
7536 SHOW_STR
7537 IP_STR
7538 BGP_STR
7539 "Display flap statistics of routes\n"
7540 "Display only routes with non-natural netmasks\n")
7541{
7542 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007543 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007544}
7545
7546DEFUN (show_ip_bgp_ipv4_cidr_only,
7547 show_ip_bgp_ipv4_cidr_only_cmd,
7548 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7549 SHOW_STR
7550 IP_STR
7551 BGP_STR
7552 "Address family\n"
7553 "Address Family modifier\n"
7554 "Address Family modifier\n"
7555 "Display only routes with non-natural netmasks\n")
7556{
7557 if (strncmp (argv[0], "m", 1) == 0)
7558 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007559 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007560
7561 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007562 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007563}
7564
7565DEFUN (show_ip_bgp_community_all,
7566 show_ip_bgp_community_all_cmd,
7567 "show ip bgp community",
7568 SHOW_STR
7569 IP_STR
7570 BGP_STR
7571 "Display routes matching the communities\n")
7572{
7573 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007574 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007575}
7576
7577DEFUN (show_ip_bgp_ipv4_community_all,
7578 show_ip_bgp_ipv4_community_all_cmd,
7579 "show ip bgp ipv4 (unicast|multicast) community",
7580 SHOW_STR
7581 IP_STR
7582 BGP_STR
7583 "Address family\n"
7584 "Address Family modifier\n"
7585 "Address Family modifier\n"
7586 "Display routes matching the communities\n")
7587{
7588 if (strncmp (argv[0], "m", 1) == 0)
7589 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007590 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007591
7592 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007593 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007594}
7595
7596#ifdef HAVE_IPV6
7597DEFUN (show_bgp_community_all,
7598 show_bgp_community_all_cmd,
7599 "show bgp community",
7600 SHOW_STR
7601 BGP_STR
7602 "Display routes matching the communities\n")
7603{
7604 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007605 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007606}
7607
7608ALIAS (show_bgp_community_all,
7609 show_bgp_ipv6_community_all_cmd,
7610 "show bgp ipv6 community",
7611 SHOW_STR
7612 BGP_STR
7613 "Address family\n"
7614 "Display routes matching the communities\n")
7615
7616/* old command */
7617DEFUN (show_ipv6_bgp_community_all,
7618 show_ipv6_bgp_community_all_cmd,
7619 "show ipv6 bgp community",
7620 SHOW_STR
7621 IPV6_STR
7622 BGP_STR
7623 "Display routes matching the communities\n")
7624{
7625 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007626 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007627}
7628
7629/* old command */
7630DEFUN (show_ipv6_mbgp_community_all,
7631 show_ipv6_mbgp_community_all_cmd,
7632 "show ipv6 mbgp community",
7633 SHOW_STR
7634 IPV6_STR
7635 MBGP_STR
7636 "Display routes matching the communities\n")
7637{
7638 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007639 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007640}
7641#endif /* HAVE_IPV6 */
7642
paul94f2b392005-06-28 12:44:16 +00007643static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007644bgp_show_community (struct vty *vty, const char *view_name, int argc,
7645 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007646{
7647 struct community *com;
7648 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007649 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007650 int i;
7651 char *str;
7652 int first = 0;
7653
Michael Lambert95cbbd22010-07-23 14:43:04 -04007654 /* BGP structure lookup */
7655 if (view_name)
7656 {
7657 bgp = bgp_lookup_by_name (view_name);
7658 if (bgp == NULL)
7659 {
7660 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7661 return CMD_WARNING;
7662 }
7663 }
7664 else
7665 {
7666 bgp = bgp_get_default ();
7667 if (bgp == NULL)
7668 {
7669 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7670 return CMD_WARNING;
7671 }
7672 }
7673
paul718e3742002-12-13 20:15:29 +00007674 b = buffer_new (1024);
7675 for (i = 0; i < argc; i++)
7676 {
7677 if (first)
7678 buffer_putc (b, ' ');
7679 else
7680 {
7681 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7682 continue;
7683 first = 1;
7684 }
7685
7686 buffer_putstr (b, argv[i]);
7687 }
7688 buffer_putc (b, '\0');
7689
7690 str = buffer_getstr (b);
7691 buffer_free (b);
7692
7693 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007694 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007695 if (! com)
7696 {
7697 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7698 return CMD_WARNING;
7699 }
7700
Michael Lambert95cbbd22010-07-23 14:43:04 -04007701 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007702 (exact ? bgp_show_type_community_exact :
7703 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007704}
7705
7706DEFUN (show_ip_bgp_community,
7707 show_ip_bgp_community_cmd,
7708 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7709 SHOW_STR
7710 IP_STR
7711 BGP_STR
7712 "Display routes matching the communities\n"
7713 "community number\n"
7714 "Do not send outside local AS (well-known community)\n"
7715 "Do not advertise to any peer (well-known community)\n"
7716 "Do not export to next AS (well-known community)\n")
7717{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007718 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007719}
7720
7721ALIAS (show_ip_bgp_community,
7722 show_ip_bgp_community2_cmd,
7723 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7724 SHOW_STR
7725 IP_STR
7726 BGP_STR
7727 "Display routes matching the communities\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 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\n")
7736
7737ALIAS (show_ip_bgp_community,
7738 show_ip_bgp_community3_cmd,
7739 "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)",
7740 SHOW_STR
7741 IP_STR
7742 BGP_STR
7743 "Display routes matching the communities\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 "community number\n"
7753 "Do not send outside local AS (well-known community)\n"
7754 "Do not advertise to any peer (well-known community)\n"
7755 "Do not export to next AS (well-known community)\n")
7756
7757ALIAS (show_ip_bgp_community,
7758 show_ip_bgp_community4_cmd,
7759 "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)",
7760 SHOW_STR
7761 IP_STR
7762 BGP_STR
7763 "Display routes matching the communities\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 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n")
7780
7781DEFUN (show_ip_bgp_ipv4_community,
7782 show_ip_bgp_ipv4_community_cmd,
7783 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7784 SHOW_STR
7785 IP_STR
7786 BGP_STR
7787 "Address family\n"
7788 "Address Family modifier\n"
7789 "Address Family modifier\n"
7790 "Display routes matching the communities\n"
7791 "community number\n"
7792 "Do not send outside local AS (well-known community)\n"
7793 "Do not advertise to any peer (well-known community)\n"
7794 "Do not export to next AS (well-known community)\n")
7795{
7796 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007797 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007798
Michael Lambert95cbbd22010-07-23 14:43:04 -04007799 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007800}
7801
7802ALIAS (show_ip_bgp_ipv4_community,
7803 show_ip_bgp_ipv4_community2_cmd,
7804 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7805 SHOW_STR
7806 IP_STR
7807 BGP_STR
7808 "Address family\n"
7809 "Address Family modifier\n"
7810 "Address Family modifier\n"
7811 "Display routes matching the communities\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 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n")
7820
7821ALIAS (show_ip_bgp_ipv4_community,
7822 show_ip_bgp_ipv4_community3_cmd,
7823 "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)",
7824 SHOW_STR
7825 IP_STR
7826 BGP_STR
7827 "Address family\n"
7828 "Address Family modifier\n"
7829 "Address Family modifier\n"
7830 "Display routes matching the communities\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 "community number\n"
7840 "Do not send outside local AS (well-known community)\n"
7841 "Do not advertise to any peer (well-known community)\n"
7842 "Do not export to next AS (well-known community)\n")
7843
7844ALIAS (show_ip_bgp_ipv4_community,
7845 show_ip_bgp_ipv4_community4_cmd,
7846 "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)",
7847 SHOW_STR
7848 IP_STR
7849 BGP_STR
7850 "Address family\n"
7851 "Address Family modifier\n"
7852 "Address Family modifier\n"
7853 "Display routes matching the communities\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 "community number\n"
7867 "Do not send outside local AS (well-known community)\n"
7868 "Do not advertise to any peer (well-known community)\n"
7869 "Do not export to next AS (well-known community)\n")
7870
Michael Lambert95cbbd22010-07-23 14:43:04 -04007871DEFUN (show_bgp_view_afi_safi_community_all,
7872 show_bgp_view_afi_safi_community_all_cmd,
7873#ifdef HAVE_IPV6
7874 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7875#else
7876 "show bgp view WORD ipv4 (unicast|multicast) community",
7877#endif
7878 SHOW_STR
7879 BGP_STR
7880 "BGP view\n"
7881 "BGP view name\n"
7882 "Address family\n"
7883#ifdef HAVE_IPV6
7884 "Address family\n"
7885#endif
7886 "Address Family modifier\n"
7887 "Address Family modifier\n"
7888 "Display routes containing communities\n")
7889{
7890 int afi;
7891 int safi;
7892 struct bgp *bgp;
7893
7894 /* BGP structure lookup. */
7895 bgp = bgp_lookup_by_name (argv[0]);
7896 if (bgp == NULL)
7897 {
7898 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7899 return CMD_WARNING;
7900 }
7901
7902#ifdef HAVE_IPV6
7903 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7904 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7905#else
7906 afi = AFI_IP;
7907 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7908#endif
7909 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7910}
7911
7912DEFUN (show_bgp_view_afi_safi_community,
7913 show_bgp_view_afi_safi_community_cmd,
7914#ifdef HAVE_IPV6
7915 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7916#else
7917 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7918#endif
7919 SHOW_STR
7920 BGP_STR
7921 "BGP view\n"
7922 "BGP view name\n"
7923 "Address family\n"
7924#ifdef HAVE_IPV6
7925 "Address family\n"
7926#endif
7927 "Address family modifier\n"
7928 "Address family modifier\n"
7929 "Display routes matching the communities\n"
7930 "community number\n"
7931 "Do not send outside local AS (well-known community)\n"
7932 "Do not advertise to any peer (well-known community)\n"
7933 "Do not export to next AS (well-known community)\n")
7934{
7935 int afi;
7936 int safi;
7937
7938#ifdef HAVE_IPV6
7939 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7940 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7941 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7942#else
7943 afi = AFI_IP;
7944 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7945 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7946#endif
7947}
7948
7949ALIAS (show_bgp_view_afi_safi_community,
7950 show_bgp_view_afi_safi_community2_cmd,
7951#ifdef HAVE_IPV6
7952 "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)",
7953#else
7954 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7955#endif
7956 SHOW_STR
7957 BGP_STR
7958 "BGP view\n"
7959 "BGP view name\n"
7960 "Address family\n"
7961#ifdef HAVE_IPV6
7962 "Address family\n"
7963#endif
7964 "Address family modifier\n"
7965 "Address family modifier\n"
7966 "Display routes matching the communities\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 "community number\n"
7972 "Do not send outside local AS (well-known community)\n"
7973 "Do not advertise to any peer (well-known community)\n"
7974 "Do not export to next AS (well-known community)\n")
7975
7976ALIAS (show_bgp_view_afi_safi_community,
7977 show_bgp_view_afi_safi_community3_cmd,
7978#ifdef HAVE_IPV6
7979 "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)",
7980#else
7981 "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)",
7982#endif
7983 SHOW_STR
7984 BGP_STR
7985 "BGP view\n"
7986 "BGP view name\n"
7987 "Address family\n"
7988#ifdef HAVE_IPV6
7989 "Address family\n"
7990#endif
7991 "Address family modifier\n"
7992 "Address family modifier\n"
7993 "Display routes matching the communities\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 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n")
8006
8007ALIAS (show_bgp_view_afi_safi_community,
8008 show_bgp_view_afi_safi_community4_cmd,
8009#ifdef HAVE_IPV6
8010 "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)",
8011#else
8012 "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)",
8013#endif
8014 SHOW_STR
8015 BGP_STR
8016 "BGP view\n"
8017 "BGP view name\n"
8018 "Address family\n"
8019#ifdef HAVE_IPV6
8020 "Address family\n"
8021#endif
8022 "Address family modifier\n"
8023 "Address family modifier\n"
8024 "Display routes matching the communities\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 "community number\n"
8038 "Do not send outside local AS (well-known community)\n"
8039 "Do not advertise to any peer (well-known community)\n"
8040 "Do not export to next AS (well-known community)\n")
8041
paul718e3742002-12-13 20:15:29 +00008042DEFUN (show_ip_bgp_community_exact,
8043 show_ip_bgp_community_exact_cmd,
8044 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8045 SHOW_STR
8046 IP_STR
8047 BGP_STR
8048 "Display routes matching the communities\n"
8049 "community number\n"
8050 "Do not send outside local AS (well-known community)\n"
8051 "Do not advertise to any peer (well-known community)\n"
8052 "Do not export to next AS (well-known community)\n"
8053 "Exact match of the communities")
8054{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008055 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008056}
8057
8058ALIAS (show_ip_bgp_community_exact,
8059 show_ip_bgp_community2_exact_cmd,
8060 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8061 SHOW_STR
8062 IP_STR
8063 BGP_STR
8064 "Display routes matching the communities\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 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n"
8073 "Exact match of the communities")
8074
8075ALIAS (show_ip_bgp_community_exact,
8076 show_ip_bgp_community3_exact_cmd,
8077 "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",
8078 SHOW_STR
8079 IP_STR
8080 BGP_STR
8081 "Display routes matching the communities\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 "community number\n"
8091 "Do not send outside local AS (well-known community)\n"
8092 "Do not advertise to any peer (well-known community)\n"
8093 "Do not export to next AS (well-known community)\n"
8094 "Exact match of the communities")
8095
8096ALIAS (show_ip_bgp_community_exact,
8097 show_ip_bgp_community4_exact_cmd,
8098 "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",
8099 SHOW_STR
8100 IP_STR
8101 BGP_STR
8102 "Display routes matching the communities\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 "community number\n"
8116 "Do not send outside local AS (well-known community)\n"
8117 "Do not advertise to any peer (well-known community)\n"
8118 "Do not export to next AS (well-known community)\n"
8119 "Exact match of the communities")
8120
8121DEFUN (show_ip_bgp_ipv4_community_exact,
8122 show_ip_bgp_ipv4_community_exact_cmd,
8123 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8124 SHOW_STR
8125 IP_STR
8126 BGP_STR
8127 "Address family\n"
8128 "Address Family modifier\n"
8129 "Address Family modifier\n"
8130 "Display routes matching the communities\n"
8131 "community number\n"
8132 "Do not send outside local AS (well-known community)\n"
8133 "Do not advertise to any peer (well-known community)\n"
8134 "Do not export to next AS (well-known community)\n"
8135 "Exact match of the communities")
8136{
8137 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008138 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008139
Michael Lambert95cbbd22010-07-23 14:43:04 -04008140 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008141}
8142
8143ALIAS (show_ip_bgp_ipv4_community_exact,
8144 show_ip_bgp_ipv4_community2_exact_cmd,
8145 "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",
8146 SHOW_STR
8147 IP_STR
8148 BGP_STR
8149 "Address family\n"
8150 "Address Family modifier\n"
8151 "Address Family modifier\n"
8152 "Display routes matching the communities\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 "community number\n"
8158 "Do not send outside local AS (well-known community)\n"
8159 "Do not advertise to any peer (well-known community)\n"
8160 "Do not export to next AS (well-known community)\n"
8161 "Exact match of the communities")
8162
8163ALIAS (show_ip_bgp_ipv4_community_exact,
8164 show_ip_bgp_ipv4_community3_exact_cmd,
8165 "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",
8166 SHOW_STR
8167 IP_STR
8168 BGP_STR
8169 "Address family\n"
8170 "Address Family modifier\n"
8171 "Address Family modifier\n"
8172 "Display routes matching the communities\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 "community number\n"
8182 "Do not send outside local AS (well-known community)\n"
8183 "Do not advertise to any peer (well-known community)\n"
8184 "Do not export to next AS (well-known community)\n"
8185 "Exact match of the communities")
8186
8187ALIAS (show_ip_bgp_ipv4_community_exact,
8188 show_ip_bgp_ipv4_community4_exact_cmd,
8189 "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",
8190 SHOW_STR
8191 IP_STR
8192 BGP_STR
8193 "Address family\n"
8194 "Address Family modifier\n"
8195 "Address Family modifier\n"
8196 "Display routes matching the communities\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 "community number\n"
8210 "Do not send outside local AS (well-known community)\n"
8211 "Do not advertise to any peer (well-known community)\n"
8212 "Do not export to next AS (well-known community)\n"
8213 "Exact match of the communities")
8214
8215#ifdef HAVE_IPV6
8216DEFUN (show_bgp_community,
8217 show_bgp_community_cmd,
8218 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8219 SHOW_STR
8220 BGP_STR
8221 "Display routes matching the communities\n"
8222 "community number\n"
8223 "Do not send outside local AS (well-known community)\n"
8224 "Do not advertise to any peer (well-known community)\n"
8225 "Do not export to next AS (well-known community)\n")
8226{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008227 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008228}
8229
8230ALIAS (show_bgp_community,
8231 show_bgp_ipv6_community_cmd,
8232 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8233 SHOW_STR
8234 BGP_STR
8235 "Address family\n"
8236 "Display routes matching the communities\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n")
8241
8242ALIAS (show_bgp_community,
8243 show_bgp_community2_cmd,
8244 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8245 SHOW_STR
8246 BGP_STR
8247 "Display routes matching the communities\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 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n")
8256
8257ALIAS (show_bgp_community,
8258 show_bgp_ipv6_community2_cmd,
8259 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8260 SHOW_STR
8261 BGP_STR
8262 "Address family\n"
8263 "Display routes matching the communities\n"
8264 "community number\n"
8265 "Do not send outside local AS (well-known community)\n"
8266 "Do not advertise to any peer (well-known community)\n"
8267 "Do not export to next AS (well-known community)\n"
8268 "community number\n"
8269 "Do not send outside local AS (well-known community)\n"
8270 "Do not advertise to any peer (well-known community)\n"
8271 "Do not export to next AS (well-known community)\n")
8272
8273ALIAS (show_bgp_community,
8274 show_bgp_community3_cmd,
8275 "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)",
8276 SHOW_STR
8277 BGP_STR
8278 "Display routes matching the communities\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 "community number\n"
8288 "Do not send outside local AS (well-known community)\n"
8289 "Do not advertise to any peer (well-known community)\n"
8290 "Do not export to next AS (well-known community)\n")
8291
8292ALIAS (show_bgp_community,
8293 show_bgp_ipv6_community3_cmd,
8294 "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)",
8295 SHOW_STR
8296 BGP_STR
8297 "Address family\n"
8298 "Display routes matching the communities\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 "community number\n"
8308 "Do not send outside local AS (well-known community)\n"
8309 "Do not advertise to any peer (well-known community)\n"
8310 "Do not export to next AS (well-known community)\n")
8311
8312ALIAS (show_bgp_community,
8313 show_bgp_community4_cmd,
8314 "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)",
8315 SHOW_STR
8316 BGP_STR
8317 "Display routes matching the communities\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 "community number\n"
8331 "Do not send outside local AS (well-known community)\n"
8332 "Do not advertise to any peer (well-known community)\n"
8333 "Do not export to next AS (well-known community)\n")
8334
8335ALIAS (show_bgp_community,
8336 show_bgp_ipv6_community4_cmd,
8337 "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)",
8338 SHOW_STR
8339 BGP_STR
8340 "Address family\n"
8341 "Display routes matching the communities\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 "community number\n"
8355 "Do not send outside local AS (well-known community)\n"
8356 "Do not advertise to any peer (well-known community)\n"
8357 "Do not export to next AS (well-known community)\n")
8358
8359/* old command */
8360DEFUN (show_ipv6_bgp_community,
8361 show_ipv6_bgp_community_cmd,
8362 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8363 SHOW_STR
8364 IPV6_STR
8365 BGP_STR
8366 "Display routes matching the communities\n"
8367 "community number\n"
8368 "Do not send outside local AS (well-known community)\n"
8369 "Do not advertise to any peer (well-known community)\n"
8370 "Do not export to next AS (well-known community)\n")
8371{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008372 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008373}
8374
8375/* old command */
8376ALIAS (show_ipv6_bgp_community,
8377 show_ipv6_bgp_community2_cmd,
8378 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8379 SHOW_STR
8380 IPV6_STR
8381 BGP_STR
8382 "Display routes matching the communities\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 "community number\n"
8388 "Do not send outside local AS (well-known community)\n"
8389 "Do not advertise to any peer (well-known community)\n"
8390 "Do not export to next AS (well-known community)\n")
8391
8392/* old command */
8393ALIAS (show_ipv6_bgp_community,
8394 show_ipv6_bgp_community3_cmd,
8395 "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)",
8396 SHOW_STR
8397 IPV6_STR
8398 BGP_STR
8399 "Display routes matching the communities\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 "community number\n"
8409 "Do not send outside local AS (well-known community)\n"
8410 "Do not advertise to any peer (well-known community)\n"
8411 "Do not export to next AS (well-known community)\n")
8412
8413/* old command */
8414ALIAS (show_ipv6_bgp_community,
8415 show_ipv6_bgp_community4_cmd,
8416 "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)",
8417 SHOW_STR
8418 IPV6_STR
8419 BGP_STR
8420 "Display routes matching the communities\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "community number\n"
8434 "Do not send outside local AS (well-known community)\n"
8435 "Do not advertise to any peer (well-known community)\n"
8436 "Do not export to next AS (well-known community)\n")
8437
8438DEFUN (show_bgp_community_exact,
8439 show_bgp_community_exact_cmd,
8440 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8441 SHOW_STR
8442 BGP_STR
8443 "Display routes matching the communities\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n"
8448 "Exact match of the communities")
8449{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008450 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008451}
8452
8453ALIAS (show_bgp_community_exact,
8454 show_bgp_ipv6_community_exact_cmd,
8455 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8456 SHOW_STR
8457 BGP_STR
8458 "Address family\n"
8459 "Display routes matching the communities\n"
8460 "community number\n"
8461 "Do not send outside local AS (well-known community)\n"
8462 "Do not advertise to any peer (well-known community)\n"
8463 "Do not export to next AS (well-known community)\n"
8464 "Exact match of the communities")
8465
8466ALIAS (show_bgp_community_exact,
8467 show_bgp_community2_exact_cmd,
8468 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8469 SHOW_STR
8470 BGP_STR
8471 "Display routes matching the communities\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 "community number\n"
8477 "Do not send outside local AS (well-known community)\n"
8478 "Do not advertise to any peer (well-known community)\n"
8479 "Do not export to next AS (well-known community)\n"
8480 "Exact match of the communities")
8481
8482ALIAS (show_bgp_community_exact,
8483 show_bgp_ipv6_community2_exact_cmd,
8484 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8485 SHOW_STR
8486 BGP_STR
8487 "Address family\n"
8488 "Display routes matching the communities\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 "community number\n"
8494 "Do not send outside local AS (well-known community)\n"
8495 "Do not advertise to any peer (well-known community)\n"
8496 "Do not export to next AS (well-known community)\n"
8497 "Exact match of the communities")
8498
8499ALIAS (show_bgp_community_exact,
8500 show_bgp_community3_exact_cmd,
8501 "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",
8502 SHOW_STR
8503 BGP_STR
8504 "Display routes matching the communities\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 "community number\n"
8514 "Do not send outside local AS (well-known community)\n"
8515 "Do not advertise to any peer (well-known community)\n"
8516 "Do not export to next AS (well-known community)\n"
8517 "Exact match of the communities")
8518
8519ALIAS (show_bgp_community_exact,
8520 show_bgp_ipv6_community3_exact_cmd,
8521 "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",
8522 SHOW_STR
8523 BGP_STR
8524 "Address family\n"
8525 "Display routes matching the communities\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 "community number\n"
8535 "Do not send outside local AS (well-known community)\n"
8536 "Do not advertise to any peer (well-known community)\n"
8537 "Do not export to next AS (well-known community)\n"
8538 "Exact match of the communities")
8539
8540ALIAS (show_bgp_community_exact,
8541 show_bgp_community4_exact_cmd,
8542 "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",
8543 SHOW_STR
8544 BGP_STR
8545 "Display routes matching the communities\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 "community number\n"
8559 "Do not send outside local AS (well-known community)\n"
8560 "Do not advertise to any peer (well-known community)\n"
8561 "Do not export to next AS (well-known community)\n"
8562 "Exact match of the communities")
8563
8564ALIAS (show_bgp_community_exact,
8565 show_bgp_ipv6_community4_exact_cmd,
8566 "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",
8567 SHOW_STR
8568 BGP_STR
8569 "Address family\n"
8570 "Display routes matching the communities\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 "community number\n"
8584 "Do not send outside local AS (well-known community)\n"
8585 "Do not advertise to any peer (well-known community)\n"
8586 "Do not export to next AS (well-known community)\n"
8587 "Exact match of the communities")
8588
8589/* old command */
8590DEFUN (show_ipv6_bgp_community_exact,
8591 show_ipv6_bgp_community_exact_cmd,
8592 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8593 SHOW_STR
8594 IPV6_STR
8595 BGP_STR
8596 "Display routes matching the communities\n"
8597 "community number\n"
8598 "Do not send outside local AS (well-known community)\n"
8599 "Do not advertise to any peer (well-known community)\n"
8600 "Do not export to next AS (well-known community)\n"
8601 "Exact match of the communities")
8602{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008603 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008604}
8605
8606/* old command */
8607ALIAS (show_ipv6_bgp_community_exact,
8608 show_ipv6_bgp_community2_exact_cmd,
8609 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8610 SHOW_STR
8611 IPV6_STR
8612 BGP_STR
8613 "Display routes matching the communities\n"
8614 "community number\n"
8615 "Do not send outside local AS (well-known community)\n"
8616 "Do not advertise to any peer (well-known community)\n"
8617 "Do not export to next AS (well-known community)\n"
8618 "community number\n"
8619 "Do not send outside local AS (well-known community)\n"
8620 "Do not advertise to any peer (well-known community)\n"
8621 "Do not export to next AS (well-known community)\n"
8622 "Exact match of the communities")
8623
8624/* old command */
8625ALIAS (show_ipv6_bgp_community_exact,
8626 show_ipv6_bgp_community3_exact_cmd,
8627 "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",
8628 SHOW_STR
8629 IPV6_STR
8630 BGP_STR
8631 "Display routes matching the communities\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 "community number\n"
8641 "Do not send outside local AS (well-known community)\n"
8642 "Do not advertise to any peer (well-known community)\n"
8643 "Do not export to next AS (well-known community)\n"
8644 "Exact match of the communities")
8645
8646/* old command */
8647ALIAS (show_ipv6_bgp_community_exact,
8648 show_ipv6_bgp_community4_exact_cmd,
8649 "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",
8650 SHOW_STR
8651 IPV6_STR
8652 BGP_STR
8653 "Display routes matching the communities\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 "community number\n"
8667 "Do not send outside local AS (well-known community)\n"
8668 "Do not advertise to any peer (well-known community)\n"
8669 "Do not export to next AS (well-known community)\n"
8670 "Exact match of the communities")
8671
8672/* old command */
8673DEFUN (show_ipv6_mbgp_community,
8674 show_ipv6_mbgp_community_cmd,
8675 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8676 SHOW_STR
8677 IPV6_STR
8678 MBGP_STR
8679 "Display routes matching the communities\n"
8680 "community number\n"
8681 "Do not send outside local AS (well-known community)\n"
8682 "Do not advertise to any peer (well-known community)\n"
8683 "Do not export to next AS (well-known community)\n")
8684{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008685 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008686}
8687
8688/* old command */
8689ALIAS (show_ipv6_mbgp_community,
8690 show_ipv6_mbgp_community2_cmd,
8691 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8692 SHOW_STR
8693 IPV6_STR
8694 MBGP_STR
8695 "Display routes matching the communities\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 "community number\n"
8701 "Do not send outside local AS (well-known community)\n"
8702 "Do not advertise to any peer (well-known community)\n"
8703 "Do not export to next AS (well-known community)\n")
8704
8705/* old command */
8706ALIAS (show_ipv6_mbgp_community,
8707 show_ipv6_mbgp_community3_cmd,
8708 "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)",
8709 SHOW_STR
8710 IPV6_STR
8711 MBGP_STR
8712 "Display routes matching the communities\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 "community number\n"
8722 "Do not send outside local AS (well-known community)\n"
8723 "Do not advertise to any peer (well-known community)\n"
8724 "Do not export to next AS (well-known community)\n")
8725
8726/* old command */
8727ALIAS (show_ipv6_mbgp_community,
8728 show_ipv6_mbgp_community4_cmd,
8729 "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)",
8730 SHOW_STR
8731 IPV6_STR
8732 MBGP_STR
8733 "Display routes matching the communities\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 "community number\n"
8747 "Do not send outside local AS (well-known community)\n"
8748 "Do not advertise to any peer (well-known community)\n"
8749 "Do not export to next AS (well-known community)\n")
8750
8751/* old command */
8752DEFUN (show_ipv6_mbgp_community_exact,
8753 show_ipv6_mbgp_community_exact_cmd,
8754 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8755 SHOW_STR
8756 IPV6_STR
8757 MBGP_STR
8758 "Display routes matching the communities\n"
8759 "community number\n"
8760 "Do not send outside local AS (well-known community)\n"
8761 "Do not advertise to any peer (well-known community)\n"
8762 "Do not export to next AS (well-known community)\n"
8763 "Exact match of the communities")
8764{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008765 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008766}
8767
8768/* old command */
8769ALIAS (show_ipv6_mbgp_community_exact,
8770 show_ipv6_mbgp_community2_exact_cmd,
8771 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8772 SHOW_STR
8773 IPV6_STR
8774 MBGP_STR
8775 "Display routes matching the communities\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 "community number\n"
8781 "Do not send outside local AS (well-known community)\n"
8782 "Do not advertise to any peer (well-known community)\n"
8783 "Do not export to next AS (well-known community)\n"
8784 "Exact match of the communities")
8785
8786/* old command */
8787ALIAS (show_ipv6_mbgp_community_exact,
8788 show_ipv6_mbgp_community3_exact_cmd,
8789 "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",
8790 SHOW_STR
8791 IPV6_STR
8792 MBGP_STR
8793 "Display routes matching the communities\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 "community number\n"
8803 "Do not send outside local AS (well-known community)\n"
8804 "Do not advertise to any peer (well-known community)\n"
8805 "Do not export to next AS (well-known community)\n"
8806 "Exact match of the communities")
8807
8808/* old command */
8809ALIAS (show_ipv6_mbgp_community_exact,
8810 show_ipv6_mbgp_community4_exact_cmd,
8811 "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",
8812 SHOW_STR
8813 IPV6_STR
8814 MBGP_STR
8815 "Display routes matching the communities\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 "community number\n"
8829 "Do not send outside local AS (well-known community)\n"
8830 "Do not advertise to any peer (well-known community)\n"
8831 "Do not export to next AS (well-known community)\n"
8832 "Exact match of the communities")
8833#endif /* HAVE_IPV6 */
8834
paul94f2b392005-06-28 12:44:16 +00008835static int
paulfd79ac92004-10-13 05:06:08 +00008836bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008837 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008838{
8839 struct community_list *list;
8840
hassofee6e4e2005-02-02 16:29:31 +00008841 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008842 if (list == NULL)
8843 {
8844 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8845 VTY_NEWLINE);
8846 return CMD_WARNING;
8847 }
8848
ajs5a646652004-11-05 01:25:55 +00008849 return bgp_show (vty, NULL, afi, safi,
8850 (exact ? bgp_show_type_community_list_exact :
8851 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008852}
8853
8854DEFUN (show_ip_bgp_community_list,
8855 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008856 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008857 SHOW_STR
8858 IP_STR
8859 BGP_STR
8860 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008861 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008862 "community-list name\n")
8863{
8864 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8865}
8866
8867DEFUN (show_ip_bgp_ipv4_community_list,
8868 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008869 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008870 SHOW_STR
8871 IP_STR
8872 BGP_STR
8873 "Address family\n"
8874 "Address Family modifier\n"
8875 "Address Family modifier\n"
8876 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008877 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008878 "community-list name\n")
8879{
8880 if (strncmp (argv[0], "m", 1) == 0)
8881 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8882
8883 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8884}
8885
8886DEFUN (show_ip_bgp_community_list_exact,
8887 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008888 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008889 SHOW_STR
8890 IP_STR
8891 BGP_STR
8892 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008893 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008894 "community-list name\n"
8895 "Exact match of the communities\n")
8896{
8897 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8898}
8899
8900DEFUN (show_ip_bgp_ipv4_community_list_exact,
8901 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008902 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008903 SHOW_STR
8904 IP_STR
8905 BGP_STR
8906 "Address family\n"
8907 "Address Family modifier\n"
8908 "Address Family modifier\n"
8909 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008910 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008911 "community-list name\n"
8912 "Exact match of the communities\n")
8913{
8914 if (strncmp (argv[0], "m", 1) == 0)
8915 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8916
8917 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8918}
8919
8920#ifdef HAVE_IPV6
8921DEFUN (show_bgp_community_list,
8922 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008923 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008924 SHOW_STR
8925 BGP_STR
8926 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008927 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008928 "community-list name\n")
8929{
8930 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8931}
8932
8933ALIAS (show_bgp_community_list,
8934 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008935 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008936 SHOW_STR
8937 BGP_STR
8938 "Address family\n"
8939 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008940 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008941 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008942
8943/* old command */
8944DEFUN (show_ipv6_bgp_community_list,
8945 show_ipv6_bgp_community_list_cmd,
8946 "show ipv6 bgp community-list WORD",
8947 SHOW_STR
8948 IPV6_STR
8949 BGP_STR
8950 "Display routes matching the community-list\n"
8951 "community-list name\n")
8952{
8953 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8954}
8955
8956/* old command */
8957DEFUN (show_ipv6_mbgp_community_list,
8958 show_ipv6_mbgp_community_list_cmd,
8959 "show ipv6 mbgp community-list WORD",
8960 SHOW_STR
8961 IPV6_STR
8962 MBGP_STR
8963 "Display routes matching the community-list\n"
8964 "community-list name\n")
8965{
8966 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8967}
8968
8969DEFUN (show_bgp_community_list_exact,
8970 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008971 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008972 SHOW_STR
8973 BGP_STR
8974 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008975 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008976 "community-list name\n"
8977 "Exact match of the communities\n")
8978{
8979 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8980}
8981
8982ALIAS (show_bgp_community_list_exact,
8983 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008984 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008985 SHOW_STR
8986 BGP_STR
8987 "Address family\n"
8988 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008989 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008990 "community-list name\n"
8991 "Exact match of the communities\n")
8992
8993/* old command */
8994DEFUN (show_ipv6_bgp_community_list_exact,
8995 show_ipv6_bgp_community_list_exact_cmd,
8996 "show ipv6 bgp community-list WORD exact-match",
8997 SHOW_STR
8998 IPV6_STR
8999 BGP_STR
9000 "Display routes matching the community-list\n"
9001 "community-list name\n"
9002 "Exact match of the communities\n")
9003{
9004 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9005}
9006
9007/* old command */
9008DEFUN (show_ipv6_mbgp_community_list_exact,
9009 show_ipv6_mbgp_community_list_exact_cmd,
9010 "show ipv6 mbgp community-list WORD exact-match",
9011 SHOW_STR
9012 IPV6_STR
9013 MBGP_STR
9014 "Display routes matching the community-list\n"
9015 "community-list name\n"
9016 "Exact match of the communities\n")
9017{
9018 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9019}
9020#endif /* HAVE_IPV6 */
9021
paul94f2b392005-06-28 12:44:16 +00009022static int
paulfd79ac92004-10-13 05:06:08 +00009023bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009024 safi_t safi, enum bgp_show_type type)
9025{
9026 int ret;
9027 struct prefix *p;
9028
9029 p = prefix_new();
9030
9031 ret = str2prefix (prefix, p);
9032 if (! ret)
9033 {
9034 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9035 return CMD_WARNING;
9036 }
9037
ajs5a646652004-11-05 01:25:55 +00009038 ret = bgp_show (vty, NULL, afi, safi, type, p);
9039 prefix_free(p);
9040 return ret;
paul718e3742002-12-13 20:15:29 +00009041}
9042
9043DEFUN (show_ip_bgp_prefix_longer,
9044 show_ip_bgp_prefix_longer_cmd,
9045 "show ip bgp A.B.C.D/M longer-prefixes",
9046 SHOW_STR
9047 IP_STR
9048 BGP_STR
9049 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9050 "Display route and more specific routes\n")
9051{
9052 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9053 bgp_show_type_prefix_longer);
9054}
9055
9056DEFUN (show_ip_bgp_flap_prefix_longer,
9057 show_ip_bgp_flap_prefix_longer_cmd,
9058 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9059 SHOW_STR
9060 IP_STR
9061 BGP_STR
9062 "Display flap statistics of routes\n"
9063 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9064 "Display route and more specific routes\n")
9065{
9066 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9067 bgp_show_type_flap_prefix_longer);
9068}
9069
9070DEFUN (show_ip_bgp_ipv4_prefix_longer,
9071 show_ip_bgp_ipv4_prefix_longer_cmd,
9072 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9073 SHOW_STR
9074 IP_STR
9075 BGP_STR
9076 "Address family\n"
9077 "Address Family modifier\n"
9078 "Address Family modifier\n"
9079 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9080 "Display route and more specific routes\n")
9081{
9082 if (strncmp (argv[0], "m", 1) == 0)
9083 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9084 bgp_show_type_prefix_longer);
9085
9086 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9087 bgp_show_type_prefix_longer);
9088}
9089
9090DEFUN (show_ip_bgp_flap_address,
9091 show_ip_bgp_flap_address_cmd,
9092 "show ip bgp flap-statistics A.B.C.D",
9093 SHOW_STR
9094 IP_STR
9095 BGP_STR
9096 "Display flap statistics of routes\n"
9097 "Network in the BGP routing table to display\n")
9098{
9099 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9100 bgp_show_type_flap_address);
9101}
9102
9103DEFUN (show_ip_bgp_flap_prefix,
9104 show_ip_bgp_flap_prefix_cmd,
9105 "show ip bgp flap-statistics A.B.C.D/M",
9106 SHOW_STR
9107 IP_STR
9108 BGP_STR
9109 "Display flap statistics of routes\n"
9110 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9111{
9112 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9113 bgp_show_type_flap_prefix);
9114}
9115#ifdef HAVE_IPV6
9116DEFUN (show_bgp_prefix_longer,
9117 show_bgp_prefix_longer_cmd,
9118 "show bgp X:X::X:X/M longer-prefixes",
9119 SHOW_STR
9120 BGP_STR
9121 "IPv6 prefix <network>/<length>\n"
9122 "Display route and more specific routes\n")
9123{
9124 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9125 bgp_show_type_prefix_longer);
9126}
9127
9128ALIAS (show_bgp_prefix_longer,
9129 show_bgp_ipv6_prefix_longer_cmd,
9130 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9131 SHOW_STR
9132 BGP_STR
9133 "Address family\n"
9134 "IPv6 prefix <network>/<length>\n"
9135 "Display route and more specific routes\n")
9136
9137/* old command */
9138DEFUN (show_ipv6_bgp_prefix_longer,
9139 show_ipv6_bgp_prefix_longer_cmd,
9140 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9141 SHOW_STR
9142 IPV6_STR
9143 BGP_STR
9144 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9145 "Display route and more specific routes\n")
9146{
9147 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9148 bgp_show_type_prefix_longer);
9149}
9150
9151/* old command */
9152DEFUN (show_ipv6_mbgp_prefix_longer,
9153 show_ipv6_mbgp_prefix_longer_cmd,
9154 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9155 SHOW_STR
9156 IPV6_STR
9157 MBGP_STR
9158 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9159 "Display route and more specific routes\n")
9160{
9161 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9162 bgp_show_type_prefix_longer);
9163}
9164#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009165
paul94f2b392005-06-28 12:44:16 +00009166static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009167peer_lookup_in_view (struct vty *vty, const char *view_name,
9168 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009169{
9170 int ret;
9171 struct bgp *bgp;
9172 struct peer *peer;
9173 union sockunion su;
9174
9175 /* BGP structure lookup. */
9176 if (view_name)
9177 {
9178 bgp = bgp_lookup_by_name (view_name);
9179 if (! bgp)
9180 {
9181 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9182 return NULL;
9183 }
9184 }
paul5228ad22004-06-04 17:58:18 +00009185 else
paulbb46e942003-10-24 19:02:03 +00009186 {
9187 bgp = bgp_get_default ();
9188 if (! bgp)
9189 {
9190 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9191 return NULL;
9192 }
9193 }
9194
9195 /* Get peer sockunion. */
9196 ret = str2sockunion (ip_str, &su);
9197 if (ret < 0)
9198 {
9199 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9200 return NULL;
9201 }
9202
9203 /* Peer structure lookup. */
9204 peer = peer_lookup (bgp, &su);
9205 if (! peer)
9206 {
9207 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9208 return NULL;
9209 }
9210
9211 return peer;
9212}
Paul Jakma2815e612006-09-14 02:56:07 +00009213
9214enum bgp_stats
9215{
9216 BGP_STATS_MAXBITLEN = 0,
9217 BGP_STATS_RIB,
9218 BGP_STATS_PREFIXES,
9219 BGP_STATS_TOTPLEN,
9220 BGP_STATS_UNAGGREGATEABLE,
9221 BGP_STATS_MAX_AGGREGATEABLE,
9222 BGP_STATS_AGGREGATES,
9223 BGP_STATS_SPACE,
9224 BGP_STATS_ASPATH_COUNT,
9225 BGP_STATS_ASPATH_MAXHOPS,
9226 BGP_STATS_ASPATH_TOTHOPS,
9227 BGP_STATS_ASPATH_MAXSIZE,
9228 BGP_STATS_ASPATH_TOTSIZE,
9229 BGP_STATS_ASN_HIGHEST,
9230 BGP_STATS_MAX,
9231};
paulbb46e942003-10-24 19:02:03 +00009232
Paul Jakma2815e612006-09-14 02:56:07 +00009233static const char *table_stats_strs[] =
9234{
9235 [BGP_STATS_PREFIXES] = "Total Prefixes",
9236 [BGP_STATS_TOTPLEN] = "Average prefix length",
9237 [BGP_STATS_RIB] = "Total Advertisements",
9238 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9239 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9240 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9241 [BGP_STATS_SPACE] = "Address space advertised",
9242 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9243 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9244 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9245 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9246 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9247 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9248 [BGP_STATS_MAX] = NULL,
9249};
9250
9251struct bgp_table_stats
9252{
9253 struct bgp_table *table;
9254 unsigned long long counts[BGP_STATS_MAX];
9255};
9256
9257#if 0
9258#define TALLY_SIGFIG 100000
9259static unsigned long
9260ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9261{
9262 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9263 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9264 unsigned long ret = newtot / count;
9265
9266 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9267 return ret + 1;
9268 else
9269 return ret;
9270}
9271#endif
9272
9273static int
9274bgp_table_stats_walker (struct thread *t)
9275{
9276 struct bgp_node *rn;
9277 struct bgp_node *top;
9278 struct bgp_table_stats *ts = THREAD_ARG (t);
9279 unsigned int space = 0;
9280
Paul Jakma53d9f672006-10-15 23:41:16 +00009281 if (!(top = bgp_table_top (ts->table)))
9282 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009283
9284 switch (top->p.family)
9285 {
9286 case AF_INET:
9287 space = IPV4_MAX_BITLEN;
9288 break;
9289 case AF_INET6:
9290 space = IPV6_MAX_BITLEN;
9291 break;
9292 }
9293
9294 ts->counts[BGP_STATS_MAXBITLEN] = space;
9295
9296 for (rn = top; rn; rn = bgp_route_next (rn))
9297 {
9298 struct bgp_info *ri;
9299 struct bgp_node *prn = rn->parent;
9300 unsigned int rinum = 0;
9301
9302 if (rn == top)
9303 continue;
9304
9305 if (!rn->info)
9306 continue;
9307
9308 ts->counts[BGP_STATS_PREFIXES]++;
9309 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9310
9311#if 0
9312 ts->counts[BGP_STATS_AVGPLEN]
9313 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9314 ts->counts[BGP_STATS_AVGPLEN],
9315 rn->p.prefixlen);
9316#endif
9317
9318 /* check if the prefix is included by any other announcements */
9319 while (prn && !prn->info)
9320 prn = prn->parent;
9321
9322 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009323 {
9324 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9325 /* announced address space */
9326 if (space)
9327 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9328 }
Paul Jakma2815e612006-09-14 02:56:07 +00009329 else if (prn->info)
9330 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9331
Paul Jakma2815e612006-09-14 02:56:07 +00009332 for (ri = rn->info; ri; ri = ri->next)
9333 {
9334 rinum++;
9335 ts->counts[BGP_STATS_RIB]++;
9336
9337 if (ri->attr &&
9338 (CHECK_FLAG (ri->attr->flag,
9339 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9340 ts->counts[BGP_STATS_AGGREGATES]++;
9341
9342 /* as-path stats */
9343 if (ri->attr && ri->attr->aspath)
9344 {
9345 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9346 unsigned int size = aspath_size (ri->attr->aspath);
9347 as_t highest = aspath_highest (ri->attr->aspath);
9348
9349 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9350
9351 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9352 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9353
9354 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9355 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9356
9357 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9358 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9359#if 0
9360 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9361 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9362 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9363 hops);
9364 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9365 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9366 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9367 size);
9368#endif
9369 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9370 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9371 }
9372 }
9373 }
9374 return 0;
9375}
9376
9377static int
9378bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9379{
9380 struct bgp_table_stats ts;
9381 unsigned int i;
9382
9383 if (!bgp->rib[afi][safi])
9384 {
9385 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9386 return CMD_WARNING;
9387 }
9388
9389 memset (&ts, 0, sizeof (ts));
9390 ts.table = bgp->rib[afi][safi];
9391 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9392
9393 vty_out (vty, "BGP %s RIB statistics%s%s",
9394 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9395
9396 for (i = 0; i < BGP_STATS_MAX; i++)
9397 {
9398 if (!table_stats_strs[i])
9399 continue;
9400
9401 switch (i)
9402 {
9403#if 0
9404 case BGP_STATS_ASPATH_AVGHOPS:
9405 case BGP_STATS_ASPATH_AVGSIZE:
9406 case BGP_STATS_AVGPLEN:
9407 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9408 vty_out (vty, "%12.2f",
9409 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9410 break;
9411#endif
9412 case BGP_STATS_ASPATH_TOTHOPS:
9413 case BGP_STATS_ASPATH_TOTSIZE:
9414 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9415 vty_out (vty, "%12.2f",
9416 ts.counts[i] ?
9417 (float)ts.counts[i] /
9418 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9419 : 0);
9420 break;
9421 case BGP_STATS_TOTPLEN:
9422 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9423 vty_out (vty, "%12.2f",
9424 ts.counts[i] ?
9425 (float)ts.counts[i] /
9426 (float)ts.counts[BGP_STATS_PREFIXES]
9427 : 0);
9428 break;
9429 case BGP_STATS_SPACE:
9430 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9431 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9432 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9433 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009434 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009435 vty_out (vty, "%12.2f%s",
9436 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009437 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009438 VTY_NEWLINE);
9439 vty_out (vty, "%30s: ", "/8 equivalent ");
9440 vty_out (vty, "%12.2f%s",
9441 (float)ts.counts[BGP_STATS_SPACE] /
9442 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9443 VTY_NEWLINE);
9444 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9445 break;
9446 vty_out (vty, "%30s: ", "/24 equivalent ");
9447 vty_out (vty, "%12.2f",
9448 (float)ts.counts[BGP_STATS_SPACE] /
9449 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9450 break;
9451 default:
9452 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9453 vty_out (vty, "%12llu", ts.counts[i]);
9454 }
9455
9456 vty_out (vty, "%s", VTY_NEWLINE);
9457 }
9458 return CMD_SUCCESS;
9459}
9460
9461static int
9462bgp_table_stats_vty (struct vty *vty, const char *name,
9463 const char *afi_str, const char *safi_str)
9464{
9465 struct bgp *bgp;
9466 afi_t afi;
9467 safi_t safi;
9468
9469 if (name)
9470 bgp = bgp_lookup_by_name (name);
9471 else
9472 bgp = bgp_get_default ();
9473
9474 if (!bgp)
9475 {
9476 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9477 return CMD_WARNING;
9478 }
9479 if (strncmp (afi_str, "ipv", 3) == 0)
9480 {
9481 if (strncmp (afi_str, "ipv4", 4) == 0)
9482 afi = AFI_IP;
9483 else if (strncmp (afi_str, "ipv6", 4) == 0)
9484 afi = AFI_IP6;
9485 else
9486 {
9487 vty_out (vty, "%% Invalid address family %s%s",
9488 afi_str, VTY_NEWLINE);
9489 return CMD_WARNING;
9490 }
9491 if (strncmp (safi_str, "m", 1) == 0)
9492 safi = SAFI_MULTICAST;
9493 else if (strncmp (safi_str, "u", 1) == 0)
9494 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009495 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9496 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009497 else
9498 {
9499 vty_out (vty, "%% Invalid subsequent address family %s%s",
9500 safi_str, VTY_NEWLINE);
9501 return CMD_WARNING;
9502 }
9503 }
9504 else
9505 {
9506 vty_out (vty, "%% Invalid address family %s%s",
9507 afi_str, VTY_NEWLINE);
9508 return CMD_WARNING;
9509 }
9510
Paul Jakma2815e612006-09-14 02:56:07 +00009511 return bgp_table_stats (vty, bgp, afi, safi);
9512}
9513
9514DEFUN (show_bgp_statistics,
9515 show_bgp_statistics_cmd,
9516 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9517 SHOW_STR
9518 BGP_STR
9519 "Address family\n"
9520 "Address family\n"
9521 "Address Family modifier\n"
9522 "Address Family modifier\n"
9523 "BGP RIB advertisement statistics\n")
9524{
9525 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9526}
9527
9528ALIAS (show_bgp_statistics,
9529 show_bgp_statistics_vpnv4_cmd,
9530 "show bgp (ipv4) (vpnv4) statistics",
9531 SHOW_STR
9532 BGP_STR
9533 "Address family\n"
9534 "Address Family modifier\n"
9535 "BGP RIB advertisement statistics\n")
9536
9537DEFUN (show_bgp_statistics_view,
9538 show_bgp_statistics_view_cmd,
9539 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9540 SHOW_STR
9541 BGP_STR
9542 "BGP view\n"
9543 "Address family\n"
9544 "Address family\n"
9545 "Address Family modifier\n"
9546 "Address Family modifier\n"
9547 "BGP RIB advertisement statistics\n")
9548{
9549 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9550}
9551
9552ALIAS (show_bgp_statistics_view,
9553 show_bgp_statistics_view_vpnv4_cmd,
9554 "show bgp view WORD (ipv4) (vpnv4) statistics",
9555 SHOW_STR
9556 BGP_STR
9557 "BGP view\n"
9558 "Address family\n"
9559 "Address Family modifier\n"
9560 "BGP RIB advertisement statistics\n")
9561
Paul Jakmaff7924f2006-09-04 01:10:36 +00009562enum bgp_pcounts
9563{
9564 PCOUNT_ADJ_IN = 0,
9565 PCOUNT_DAMPED,
9566 PCOUNT_REMOVED,
9567 PCOUNT_HISTORY,
9568 PCOUNT_STALE,
9569 PCOUNT_VALID,
9570 PCOUNT_ALL,
9571 PCOUNT_COUNTED,
9572 PCOUNT_PFCNT, /* the figure we display to users */
9573 PCOUNT_MAX,
9574};
9575
9576static const char *pcount_strs[] =
9577{
9578 [PCOUNT_ADJ_IN] = "Adj-in",
9579 [PCOUNT_DAMPED] = "Damped",
9580 [PCOUNT_REMOVED] = "Removed",
9581 [PCOUNT_HISTORY] = "History",
9582 [PCOUNT_STALE] = "Stale",
9583 [PCOUNT_VALID] = "Valid",
9584 [PCOUNT_ALL] = "All RIB",
9585 [PCOUNT_COUNTED] = "PfxCt counted",
9586 [PCOUNT_PFCNT] = "Useable",
9587 [PCOUNT_MAX] = NULL,
9588};
9589
Paul Jakma2815e612006-09-14 02:56:07 +00009590struct peer_pcounts
9591{
9592 unsigned int count[PCOUNT_MAX];
9593 const struct peer *peer;
9594 const struct bgp_table *table;
9595};
9596
Paul Jakmaff7924f2006-09-04 01:10:36 +00009597static int
Paul Jakma2815e612006-09-14 02:56:07 +00009598bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009599{
9600 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009601 struct peer_pcounts *pc = THREAD_ARG (t);
9602 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009603
Paul Jakma2815e612006-09-14 02:56:07 +00009604 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009605 {
9606 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009607 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009608
9609 for (ain = rn->adj_in; ain; ain = ain->next)
9610 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009611 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009612
Paul Jakmaff7924f2006-09-04 01:10:36 +00009613 for (ri = rn->info; ri; ri = ri->next)
9614 {
9615 char buf[SU_ADDRSTRLEN];
9616
9617 if (ri->peer != peer)
9618 continue;
9619
Paul Jakma2815e612006-09-14 02:56:07 +00009620 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009621
9622 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009623 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009624 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009625 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009626 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009627 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009628 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009629 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009630 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009631 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009632 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009633 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009634
9635 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9636 {
Paul Jakma2815e612006-09-14 02:56:07 +00009637 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009638 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009639 plog_warn (peer->log,
9640 "%s [pcount] %s/%d is counted but flags 0x%x",
9641 peer->host,
9642 inet_ntop(rn->p.family, &rn->p.u.prefix,
9643 buf, SU_ADDRSTRLEN),
9644 rn->p.prefixlen,
9645 ri->flags);
9646 }
9647 else
9648 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009649 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009650 plog_warn (peer->log,
9651 "%s [pcount] %s/%d not counted but flags 0x%x",
9652 peer->host,
9653 inet_ntop(rn->p.family, &rn->p.u.prefix,
9654 buf, SU_ADDRSTRLEN),
9655 rn->p.prefixlen,
9656 ri->flags);
9657 }
9658 }
9659 }
Paul Jakma2815e612006-09-14 02:56:07 +00009660 return 0;
9661}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009662
Paul Jakma2815e612006-09-14 02:56:07 +00009663static int
9664bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9665{
9666 struct peer_pcounts pcounts = { .peer = peer };
9667 unsigned int i;
9668
9669 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9670 || !peer->bgp->rib[afi][safi])
9671 {
9672 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9673 return CMD_WARNING;
9674 }
9675
9676 memset (&pcounts, 0, sizeof(pcounts));
9677 pcounts.peer = peer;
9678 pcounts.table = peer->bgp->rib[afi][safi];
9679
9680 /* in-place call via thread subsystem so as to record execution time
9681 * stats for the thread-walk (i.e. ensure this can't be blamed on
9682 * on just vty_read()).
9683 */
9684 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9685
Paul Jakmaff7924f2006-09-04 01:10:36 +00009686 vty_out (vty, "Prefix counts for %s, %s%s",
9687 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9688 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9689 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9690 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9691
9692 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009693 vty_out (vty, "%20s: %-10d%s",
9694 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009695
Paul Jakma2815e612006-09-14 02:56:07 +00009696 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009697 {
9698 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9699 peer->host, VTY_NEWLINE);
9700 vty_out (vty, "Please report this bug, with the above command output%s",
9701 VTY_NEWLINE);
9702 }
9703
9704 return CMD_SUCCESS;
9705}
9706
9707DEFUN (show_ip_bgp_neighbor_prefix_counts,
9708 show_ip_bgp_neighbor_prefix_counts_cmd,
9709 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9710 SHOW_STR
9711 IP_STR
9712 BGP_STR
9713 "Detailed information on TCP and BGP neighbor connections\n"
9714 "Neighbor to display information about\n"
9715 "Neighbor to display information about\n"
9716 "Display detailed prefix count information\n")
9717{
9718 struct peer *peer;
9719
9720 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9721 if (! peer)
9722 return CMD_WARNING;
9723
9724 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9725}
9726
9727DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9728 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9729 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9730 SHOW_STR
9731 BGP_STR
9732 "Address family\n"
9733 "Detailed information on TCP and BGP neighbor connections\n"
9734 "Neighbor to display information about\n"
9735 "Neighbor to display information about\n"
9736 "Display detailed prefix count information\n")
9737{
9738 struct peer *peer;
9739
9740 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9741 if (! peer)
9742 return CMD_WARNING;
9743
9744 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9745}
9746
9747DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9748 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9749 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9750 SHOW_STR
9751 IP_STR
9752 BGP_STR
9753 "Address family\n"
9754 "Address Family modifier\n"
9755 "Address Family modifier\n"
9756 "Detailed information on TCP and BGP neighbor connections\n"
9757 "Neighbor to display information about\n"
9758 "Neighbor to display information about\n"
9759 "Display detailed prefix count information\n")
9760{
9761 struct peer *peer;
9762
9763 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9764 if (! peer)
9765 return CMD_WARNING;
9766
9767 if (strncmp (argv[0], "m", 1) == 0)
9768 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9769
9770 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9771}
9772
9773DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9774 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9775 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9776 SHOW_STR
9777 IP_STR
9778 BGP_STR
9779 "Address family\n"
9780 "Address Family modifier\n"
9781 "Address Family modifier\n"
9782 "Detailed information on TCP and BGP neighbor connections\n"
9783 "Neighbor to display information about\n"
9784 "Neighbor to display information about\n"
9785 "Display detailed prefix count information\n")
9786{
9787 struct peer *peer;
9788
9789 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9790 if (! peer)
9791 return CMD_WARNING;
9792
9793 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9794}
9795
9796
paul94f2b392005-06-28 12:44:16 +00009797static void
paul718e3742002-12-13 20:15:29 +00009798show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9799 int in)
9800{
9801 struct bgp_table *table;
9802 struct bgp_adj_in *ain;
9803 struct bgp_adj_out *adj;
9804 unsigned long output_count;
9805 struct bgp_node *rn;
9806 int header1 = 1;
9807 struct bgp *bgp;
9808 int header2 = 1;
9809
paulbb46e942003-10-24 19:02:03 +00009810 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009811
9812 if (! bgp)
9813 return;
9814
9815 table = bgp->rib[afi][safi];
9816
9817 output_count = 0;
9818
9819 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9820 PEER_STATUS_DEFAULT_ORIGINATE))
9821 {
9822 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 +00009823 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9824 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009825
9826 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9827 VTY_NEWLINE, VTY_NEWLINE);
9828 header1 = 0;
9829 }
9830
9831 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9832 if (in)
9833 {
9834 for (ain = rn->adj_in; ain; ain = ain->next)
9835 if (ain->peer == peer)
9836 {
9837 if (header1)
9838 {
9839 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 +00009840 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9841 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009842 header1 = 0;
9843 }
9844 if (header2)
9845 {
9846 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9847 header2 = 0;
9848 }
9849 if (ain->attr)
9850 {
9851 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9852 output_count++;
9853 }
9854 }
9855 }
9856 else
9857 {
9858 for (adj = rn->adj_out; adj; adj = adj->next)
9859 if (adj->peer == peer)
9860 {
9861 if (header1)
9862 {
9863 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 +00009864 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9865 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009866 header1 = 0;
9867 }
9868 if (header2)
9869 {
9870 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9871 header2 = 0;
9872 }
9873 if (adj->attr)
9874 {
9875 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9876 output_count++;
9877 }
9878 }
9879 }
9880
9881 if (output_count != 0)
9882 vty_out (vty, "%sTotal number of prefixes %ld%s",
9883 VTY_NEWLINE, output_count, VTY_NEWLINE);
9884}
9885
paul94f2b392005-06-28 12:44:16 +00009886static int
paulbb46e942003-10-24 19:02:03 +00009887peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9888{
paul718e3742002-12-13 20:15:29 +00009889 if (! peer || ! peer->afc[afi][safi])
9890 {
9891 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9892 return CMD_WARNING;
9893 }
9894
9895 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9896 {
9897 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9898 VTY_NEWLINE);
9899 return CMD_WARNING;
9900 }
9901
9902 show_adj_route (vty, peer, afi, safi, in);
9903
9904 return CMD_SUCCESS;
9905}
9906
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009907DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9908 show_ip_bgp_view_neighbor_advertised_route_cmd,
9909 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9910 SHOW_STR
9911 IP_STR
9912 BGP_STR
9913 "BGP view\n"
9914 "View name\n"
9915 "Detailed information on TCP and BGP neighbor connections\n"
9916 "Neighbor to display information about\n"
9917 "Neighbor to display information about\n"
9918 "Display the routes advertised to a BGP neighbor\n")
9919{
9920 struct peer *peer;
9921
9922 if (argc == 2)
9923 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9924 else
9925 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9926
9927 if (! peer)
9928 return CMD_WARNING;
9929
9930 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9931}
9932
9933ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009934 show_ip_bgp_neighbor_advertised_route_cmd,
9935 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9936 SHOW_STR
9937 IP_STR
9938 BGP_STR
9939 "Detailed information on TCP and BGP neighbor connections\n"
9940 "Neighbor to display information about\n"
9941 "Neighbor to display information about\n"
9942 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009943
9944DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9945 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9946 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9947 SHOW_STR
9948 IP_STR
9949 BGP_STR
9950 "Address family\n"
9951 "Address Family modifier\n"
9952 "Address Family modifier\n"
9953 "Detailed information on TCP and BGP neighbor connections\n"
9954 "Neighbor to display information about\n"
9955 "Neighbor to display information about\n"
9956 "Display the routes advertised to a BGP neighbor\n")
9957{
paulbb46e942003-10-24 19:02:03 +00009958 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009959
paulbb46e942003-10-24 19:02:03 +00009960 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9961 if (! peer)
9962 return CMD_WARNING;
9963
9964 if (strncmp (argv[0], "m", 1) == 0)
9965 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9966
9967 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009968}
9969
9970#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009971DEFUN (show_bgp_view_neighbor_advertised_route,
9972 show_bgp_view_neighbor_advertised_route_cmd,
9973 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9974 SHOW_STR
9975 BGP_STR
9976 "BGP view\n"
9977 "View name\n"
9978 "Detailed information on TCP and BGP neighbor connections\n"
9979 "Neighbor to display information about\n"
9980 "Neighbor to display information about\n"
9981 "Display the routes advertised to a BGP neighbor\n")
9982{
9983 struct peer *peer;
9984
9985 if (argc == 2)
9986 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9987 else
9988 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9989
9990 if (! peer)
9991 return CMD_WARNING;
9992
9993 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9994}
9995
9996ALIAS (show_bgp_view_neighbor_advertised_route,
9997 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9998 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9999 SHOW_STR
10000 BGP_STR
10001 "BGP view\n"
10002 "View name\n"
10003 "Address family\n"
10004 "Detailed information on TCP and BGP neighbor connections\n"
10005 "Neighbor to display information about\n"
10006 "Neighbor to display information about\n"
10007 "Display the routes advertised to a BGP neighbor\n")
10008
10009DEFUN (show_bgp_view_neighbor_received_routes,
10010 show_bgp_view_neighbor_received_routes_cmd,
10011 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10012 SHOW_STR
10013 BGP_STR
10014 "BGP view\n"
10015 "View name\n"
10016 "Detailed information on TCP and BGP neighbor connections\n"
10017 "Neighbor to display information about\n"
10018 "Neighbor to display information about\n"
10019 "Display the received routes from neighbor\n")
10020{
10021 struct peer *peer;
10022
10023 if (argc == 2)
10024 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10025 else
10026 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10027
10028 if (! peer)
10029 return CMD_WARNING;
10030
10031 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10032}
10033
10034ALIAS (show_bgp_view_neighbor_received_routes,
10035 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10036 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10037 SHOW_STR
10038 BGP_STR
10039 "BGP view\n"
10040 "View name\n"
10041 "Address family\n"
10042 "Detailed information on TCP and BGP neighbor connections\n"
10043 "Neighbor to display information about\n"
10044 "Neighbor to display information about\n"
10045 "Display the received routes from neighbor\n")
10046
10047ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010048 show_bgp_neighbor_advertised_route_cmd,
10049 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10050 SHOW_STR
10051 BGP_STR
10052 "Detailed information on TCP and BGP neighbor connections\n"
10053 "Neighbor to display information about\n"
10054 "Neighbor to display information about\n"
10055 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010056
10057ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010058 show_bgp_ipv6_neighbor_advertised_route_cmd,
10059 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10060 SHOW_STR
10061 BGP_STR
10062 "Address family\n"
10063 "Detailed information on TCP and BGP neighbor connections\n"
10064 "Neighbor to display information about\n"
10065 "Neighbor to display information about\n"
10066 "Display the routes advertised to a BGP neighbor\n")
10067
10068/* old command */
paulbb46e942003-10-24 19:02:03 +000010069ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010070 ipv6_bgp_neighbor_advertised_route_cmd,
10071 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10072 SHOW_STR
10073 IPV6_STR
10074 BGP_STR
10075 "Detailed information on TCP and BGP neighbor connections\n"
10076 "Neighbor to display information about\n"
10077 "Neighbor to display information about\n"
10078 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010079
paul718e3742002-12-13 20:15:29 +000010080/* old command */
10081DEFUN (ipv6_mbgp_neighbor_advertised_route,
10082 ipv6_mbgp_neighbor_advertised_route_cmd,
10083 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10084 SHOW_STR
10085 IPV6_STR
10086 MBGP_STR
10087 "Detailed information on TCP and BGP neighbor connections\n"
10088 "Neighbor to display information about\n"
10089 "Neighbor to display information about\n"
10090 "Display the routes advertised to a BGP neighbor\n")
10091{
paulbb46e942003-10-24 19:02:03 +000010092 struct peer *peer;
10093
10094 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10095 if (! peer)
10096 return CMD_WARNING;
10097
10098 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010099}
10100#endif /* HAVE_IPV6 */
10101
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010102DEFUN (show_ip_bgp_view_neighbor_received_routes,
10103 show_ip_bgp_view_neighbor_received_routes_cmd,
10104 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10105 SHOW_STR
10106 IP_STR
10107 BGP_STR
10108 "BGP view\n"
10109 "View name\n"
10110 "Detailed information on TCP and BGP neighbor connections\n"
10111 "Neighbor to display information about\n"
10112 "Neighbor to display information about\n"
10113 "Display the received routes from neighbor\n")
10114{
10115 struct peer *peer;
10116
10117 if (argc == 2)
10118 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10119 else
10120 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10121
10122 if (! peer)
10123 return CMD_WARNING;
10124
10125 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10126}
10127
10128ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010129 show_ip_bgp_neighbor_received_routes_cmd,
10130 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10131 SHOW_STR
10132 IP_STR
10133 BGP_STR
10134 "Detailed information on TCP and BGP neighbor connections\n"
10135 "Neighbor to display information about\n"
10136 "Neighbor to display information about\n"
10137 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010138
10139DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10140 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10141 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10142 SHOW_STR
10143 IP_STR
10144 BGP_STR
10145 "Address family\n"
10146 "Address Family modifier\n"
10147 "Address Family modifier\n"
10148 "Detailed information on TCP and BGP neighbor connections\n"
10149 "Neighbor to display information about\n"
10150 "Neighbor to display information about\n"
10151 "Display the received routes from neighbor\n")
10152{
paulbb46e942003-10-24 19:02:03 +000010153 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010154
paulbb46e942003-10-24 19:02:03 +000010155 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10156 if (! peer)
10157 return CMD_WARNING;
10158
10159 if (strncmp (argv[0], "m", 1) == 0)
10160 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10161
10162 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010163}
10164
Michael Lambert95cbbd22010-07-23 14:43:04 -040010165DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10166 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10167#ifdef HAVE_IPV6
10168 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10169#else
10170 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10171#endif
10172 SHOW_STR
10173 BGP_STR
10174 "BGP view\n"
10175 "BGP view name\n"
10176 "Address family\n"
10177#ifdef HAVE_IPV6
10178 "Address family\n"
10179#endif
10180 "Address family modifier\n"
10181 "Address family modifier\n"
10182 "Detailed information on TCP and BGP neighbor connections\n"
10183 "Neighbor to display information about\n"
10184 "Neighbor to display information about\n"
10185 "Display the advertised routes to neighbor\n"
10186 "Display the received routes from neighbor\n")
10187{
10188 int afi;
10189 int safi;
10190 int in;
10191 struct peer *peer;
10192
10193#ifdef HAVE_IPV6
10194 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10195#else
10196 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10197#endif
10198
10199 if (! peer)
10200 return CMD_WARNING;
10201
10202#ifdef HAVE_IPV6
10203 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10204 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10205 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10206#else
10207 afi = AFI_IP;
10208 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10209 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10210#endif
10211
10212 return peer_adj_routes (vty, peer, afi, safi, in);
10213}
10214
paul718e3742002-12-13 20:15:29 +000010215DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10216 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10217 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10218 SHOW_STR
10219 IP_STR
10220 BGP_STR
10221 "Detailed information on TCP and BGP neighbor connections\n"
10222 "Neighbor to display information about\n"
10223 "Neighbor to display information about\n"
10224 "Display information received from a BGP neighbor\n"
10225 "Display the prefixlist filter\n")
10226{
10227 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010228 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010229 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010230 int count, ret;
paul718e3742002-12-13 20:15:29 +000010231
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010232 ret = str2sockunion (argv[0], &su);
10233 if (ret < 0)
10234 {
10235 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10236 return CMD_WARNING;
10237 }
paul718e3742002-12-13 20:15:29 +000010238
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010239 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010240 if (! peer)
10241 return CMD_WARNING;
10242
10243 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10244 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10245 if (count)
10246 {
10247 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10248 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10249 }
10250
10251 return CMD_SUCCESS;
10252}
10253
10254DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10255 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10256 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10257 SHOW_STR
10258 IP_STR
10259 BGP_STR
10260 "Address family\n"
10261 "Address Family modifier\n"
10262 "Address Family modifier\n"
10263 "Detailed information on TCP and BGP neighbor connections\n"
10264 "Neighbor to display information about\n"
10265 "Neighbor to display information about\n"
10266 "Display information received from a BGP neighbor\n"
10267 "Display the prefixlist filter\n")
10268{
10269 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010270 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010271 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010272 int count, ret;
paul718e3742002-12-13 20:15:29 +000010273
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010274 ret = str2sockunion (argv[1], &su);
10275 if (ret < 0)
10276 {
10277 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10278 return CMD_WARNING;
10279 }
paul718e3742002-12-13 20:15:29 +000010280
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010281 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010282 if (! peer)
10283 return CMD_WARNING;
10284
10285 if (strncmp (argv[0], "m", 1) == 0)
10286 {
10287 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10288 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10289 if (count)
10290 {
10291 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10292 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10293 }
10294 }
10295 else
10296 {
10297 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10298 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10299 if (count)
10300 {
10301 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10302 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10303 }
10304 }
10305
10306 return CMD_SUCCESS;
10307}
10308
10309
10310#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010311ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010312 show_bgp_neighbor_received_routes_cmd,
10313 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10314 SHOW_STR
10315 BGP_STR
10316 "Detailed information on TCP and BGP neighbor connections\n"
10317 "Neighbor to display information about\n"
10318 "Neighbor to display information about\n"
10319 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010320
paulbb46e942003-10-24 19:02:03 +000010321ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010322 show_bgp_ipv6_neighbor_received_routes_cmd,
10323 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10324 SHOW_STR
10325 BGP_STR
10326 "Address family\n"
10327 "Detailed information on TCP and BGP neighbor connections\n"
10328 "Neighbor to display information about\n"
10329 "Neighbor to display information about\n"
10330 "Display the received routes from neighbor\n")
10331
10332DEFUN (show_bgp_neighbor_received_prefix_filter,
10333 show_bgp_neighbor_received_prefix_filter_cmd,
10334 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10335 SHOW_STR
10336 BGP_STR
10337 "Detailed information on TCP and BGP neighbor connections\n"
10338 "Neighbor to display information about\n"
10339 "Neighbor to display information about\n"
10340 "Display information received from a BGP neighbor\n"
10341 "Display the prefixlist filter\n")
10342{
10343 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010344 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010345 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010346 int count, ret;
paul718e3742002-12-13 20:15:29 +000010347
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010348 ret = str2sockunion (argv[0], &su);
10349 if (ret < 0)
10350 {
10351 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10352 return CMD_WARNING;
10353 }
paul718e3742002-12-13 20:15:29 +000010354
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010355 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010356 if (! peer)
10357 return CMD_WARNING;
10358
10359 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10360 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10361 if (count)
10362 {
10363 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10364 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10365 }
10366
10367 return CMD_SUCCESS;
10368}
10369
10370ALIAS (show_bgp_neighbor_received_prefix_filter,
10371 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10372 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10373 SHOW_STR
10374 BGP_STR
10375 "Address family\n"
10376 "Detailed information on TCP and BGP neighbor connections\n"
10377 "Neighbor to display information about\n"
10378 "Neighbor to display information about\n"
10379 "Display information received from a BGP neighbor\n"
10380 "Display the prefixlist filter\n")
10381
10382/* old command */
paulbb46e942003-10-24 19:02:03 +000010383ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010384 ipv6_bgp_neighbor_received_routes_cmd,
10385 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10386 SHOW_STR
10387 IPV6_STR
10388 BGP_STR
10389 "Detailed information on TCP and BGP neighbor connections\n"
10390 "Neighbor to display information about\n"
10391 "Neighbor to display information about\n"
10392 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010393
10394/* old command */
10395DEFUN (ipv6_mbgp_neighbor_received_routes,
10396 ipv6_mbgp_neighbor_received_routes_cmd,
10397 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10398 SHOW_STR
10399 IPV6_STR
10400 MBGP_STR
10401 "Detailed information on TCP and BGP neighbor connections\n"
10402 "Neighbor to display information about\n"
10403 "Neighbor to display information about\n"
10404 "Display the received routes from neighbor\n")
10405{
paulbb46e942003-10-24 19:02:03 +000010406 struct peer *peer;
10407
10408 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10409 if (! peer)
10410 return CMD_WARNING;
10411
10412 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010413}
paulbb46e942003-10-24 19:02:03 +000010414
10415DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10416 show_bgp_view_neighbor_received_prefix_filter_cmd,
10417 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10418 SHOW_STR
10419 BGP_STR
10420 "BGP view\n"
10421 "View name\n"
10422 "Detailed information on TCP and BGP neighbor connections\n"
10423 "Neighbor to display information about\n"
10424 "Neighbor to display information about\n"
10425 "Display information received from a BGP neighbor\n"
10426 "Display the prefixlist filter\n")
10427{
10428 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010429 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010430 struct peer *peer;
10431 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010432 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010433
10434 /* BGP structure lookup. */
10435 bgp = bgp_lookup_by_name (argv[0]);
10436 if (bgp == NULL)
10437 {
10438 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10439 return CMD_WARNING;
10440 }
10441
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010442 ret = str2sockunion (argv[1], &su);
10443 if (ret < 0)
10444 {
10445 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10446 return CMD_WARNING;
10447 }
paulbb46e942003-10-24 19:02:03 +000010448
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010449 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010450 if (! peer)
10451 return CMD_WARNING;
10452
10453 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10454 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10455 if (count)
10456 {
10457 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10458 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10459 }
10460
10461 return CMD_SUCCESS;
10462}
10463
10464ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10465 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10466 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10467 SHOW_STR
10468 BGP_STR
10469 "BGP view\n"
10470 "View name\n"
10471 "Address family\n"
10472 "Detailed information on TCP and BGP neighbor connections\n"
10473 "Neighbor to display information about\n"
10474 "Neighbor to display information about\n"
10475 "Display information received from a BGP neighbor\n"
10476 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010477#endif /* HAVE_IPV6 */
10478
paul94f2b392005-06-28 12:44:16 +000010479static int
paulbb46e942003-10-24 19:02:03 +000010480bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010481 safi_t safi, enum bgp_show_type type)
10482{
paul718e3742002-12-13 20:15:29 +000010483 if (! peer || ! peer->afc[afi][safi])
10484 {
10485 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010486 return CMD_WARNING;
10487 }
10488
ajs5a646652004-11-05 01:25:55 +000010489 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010490}
10491
10492DEFUN (show_ip_bgp_neighbor_routes,
10493 show_ip_bgp_neighbor_routes_cmd,
10494 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10495 SHOW_STR
10496 IP_STR
10497 BGP_STR
10498 "Detailed information on TCP and BGP neighbor connections\n"
10499 "Neighbor to display information about\n"
10500 "Neighbor to display information about\n"
10501 "Display routes learned from neighbor\n")
10502{
paulbb46e942003-10-24 19:02:03 +000010503 struct peer *peer;
10504
10505 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10506 if (! peer)
10507 return CMD_WARNING;
10508
10509 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010510 bgp_show_type_neighbor);
10511}
10512
10513DEFUN (show_ip_bgp_neighbor_flap,
10514 show_ip_bgp_neighbor_flap_cmd,
10515 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10516 SHOW_STR
10517 IP_STR
10518 BGP_STR
10519 "Detailed information on TCP and BGP neighbor connections\n"
10520 "Neighbor to display information about\n"
10521 "Neighbor to display information about\n"
10522 "Display flap statistics of the routes learned from neighbor\n")
10523{
paulbb46e942003-10-24 19:02:03 +000010524 struct peer *peer;
10525
10526 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10527 if (! peer)
10528 return CMD_WARNING;
10529
10530 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010531 bgp_show_type_flap_neighbor);
10532}
10533
10534DEFUN (show_ip_bgp_neighbor_damp,
10535 show_ip_bgp_neighbor_damp_cmd,
10536 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10537 SHOW_STR
10538 IP_STR
10539 BGP_STR
10540 "Detailed information on TCP and BGP neighbor connections\n"
10541 "Neighbor to display information about\n"
10542 "Neighbor to display information about\n"
10543 "Display the dampened routes received from neighbor\n")
10544{
paulbb46e942003-10-24 19:02:03 +000010545 struct peer *peer;
10546
10547 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10548 if (! peer)
10549 return CMD_WARNING;
10550
10551 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010552 bgp_show_type_damp_neighbor);
10553}
10554
10555DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10556 show_ip_bgp_ipv4_neighbor_routes_cmd,
10557 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10558 SHOW_STR
10559 IP_STR
10560 BGP_STR
10561 "Address family\n"
10562 "Address Family modifier\n"
10563 "Address Family modifier\n"
10564 "Detailed information on TCP and BGP neighbor connections\n"
10565 "Neighbor to display information about\n"
10566 "Neighbor to display information about\n"
10567 "Display routes learned from neighbor\n")
10568{
paulbb46e942003-10-24 19:02:03 +000010569 struct peer *peer;
10570
10571 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10572 if (! peer)
10573 return CMD_WARNING;
10574
paul718e3742002-12-13 20:15:29 +000010575 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010576 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010577 bgp_show_type_neighbor);
10578
paulbb46e942003-10-24 19:02:03 +000010579 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010580 bgp_show_type_neighbor);
10581}
paulbb46e942003-10-24 19:02:03 +000010582
paulfee0f4c2004-09-13 05:12:46 +000010583DEFUN (show_ip_bgp_view_rsclient,
10584 show_ip_bgp_view_rsclient_cmd,
10585 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10586 SHOW_STR
10587 IP_STR
10588 BGP_STR
10589 "BGP view\n"
10590 "BGP view name\n"
10591 "Information about Route Server Client\n"
10592 NEIGHBOR_ADDR_STR)
10593{
10594 struct bgp_table *table;
10595 struct peer *peer;
10596
10597 if (argc == 2)
10598 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10599 else
10600 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10601
10602 if (! peer)
10603 return CMD_WARNING;
10604
10605 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10606 {
10607 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10608 VTY_NEWLINE);
10609 return CMD_WARNING;
10610 }
10611
10612 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10613 PEER_FLAG_RSERVER_CLIENT))
10614 {
10615 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10616 VTY_NEWLINE);
10617 return CMD_WARNING;
10618 }
10619
10620 table = peer->rib[AFI_IP][SAFI_UNICAST];
10621
ajs5a646652004-11-05 01:25:55 +000010622 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010623}
10624
10625ALIAS (show_ip_bgp_view_rsclient,
10626 show_ip_bgp_rsclient_cmd,
10627 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10628 SHOW_STR
10629 IP_STR
10630 BGP_STR
10631 "Information about Route Server Client\n"
10632 NEIGHBOR_ADDR_STR)
10633
Michael Lambert95cbbd22010-07-23 14:43:04 -040010634DEFUN (show_bgp_view_ipv4_safi_rsclient,
10635 show_bgp_view_ipv4_safi_rsclient_cmd,
10636 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10637 SHOW_STR
10638 BGP_STR
10639 "BGP view\n"
10640 "BGP view name\n"
10641 "Address family\n"
10642 "Address Family modifier\n"
10643 "Address Family modifier\n"
10644 "Information about Route Server Client\n"
10645 NEIGHBOR_ADDR_STR)
10646{
10647 struct bgp_table *table;
10648 struct peer *peer;
10649 safi_t safi;
10650
10651 if (argc == 3) {
10652 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10653 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10654 } else {
10655 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10656 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10657 }
10658
10659 if (! peer)
10660 return CMD_WARNING;
10661
10662 if (! peer->afc[AFI_IP][safi])
10663 {
10664 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10665 VTY_NEWLINE);
10666 return CMD_WARNING;
10667 }
10668
10669 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10670 PEER_FLAG_RSERVER_CLIENT))
10671 {
10672 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10673 VTY_NEWLINE);
10674 return CMD_WARNING;
10675 }
10676
10677 table = peer->rib[AFI_IP][safi];
10678
10679 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10680}
10681
10682ALIAS (show_bgp_view_ipv4_safi_rsclient,
10683 show_bgp_ipv4_safi_rsclient_cmd,
10684 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10685 SHOW_STR
10686 BGP_STR
10687 "Address family\n"
10688 "Address Family modifier\n"
10689 "Address Family modifier\n"
10690 "Information about Route Server Client\n"
10691 NEIGHBOR_ADDR_STR)
10692
paulfee0f4c2004-09-13 05:12:46 +000010693DEFUN (show_ip_bgp_view_rsclient_route,
10694 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010695 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010696 SHOW_STR
10697 IP_STR
10698 BGP_STR
10699 "BGP view\n"
10700 "BGP view name\n"
10701 "Information about Route Server Client\n"
10702 NEIGHBOR_ADDR_STR
10703 "Network in the BGP routing table to display\n")
10704{
10705 struct bgp *bgp;
10706 struct peer *peer;
10707
10708 /* BGP structure lookup. */
10709 if (argc == 3)
10710 {
10711 bgp = bgp_lookup_by_name (argv[0]);
10712 if (bgp == NULL)
10713 {
10714 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10715 return CMD_WARNING;
10716 }
10717 }
10718 else
10719 {
10720 bgp = bgp_get_default ();
10721 if (bgp == NULL)
10722 {
10723 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10724 return CMD_WARNING;
10725 }
10726 }
10727
10728 if (argc == 3)
10729 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10730 else
10731 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10732
10733 if (! peer)
10734 return CMD_WARNING;
10735
10736 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10737 {
10738 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10739 VTY_NEWLINE);
10740 return CMD_WARNING;
10741}
10742
10743 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10744 PEER_FLAG_RSERVER_CLIENT))
10745 {
10746 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10747 VTY_NEWLINE);
10748 return CMD_WARNING;
10749 }
10750
10751 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10752 (argc == 3) ? argv[2] : argv[1],
10753 AFI_IP, SAFI_UNICAST, NULL, 0);
10754}
10755
10756ALIAS (show_ip_bgp_view_rsclient_route,
10757 show_ip_bgp_rsclient_route_cmd,
10758 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10759 SHOW_STR
10760 IP_STR
10761 BGP_STR
10762 "Information about Route Server Client\n"
10763 NEIGHBOR_ADDR_STR
10764 "Network in the BGP routing table to display\n")
10765
Michael Lambert95cbbd22010-07-23 14:43:04 -040010766DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10767 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10768 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10769 SHOW_STR
10770 BGP_STR
10771 "BGP view\n"
10772 "BGP view name\n"
10773 "Address family\n"
10774 "Address Family modifier\n"
10775 "Address Family modifier\n"
10776 "Information about Route Server Client\n"
10777 NEIGHBOR_ADDR_STR
10778 "Network in the BGP routing table to display\n")
10779{
10780 struct bgp *bgp;
10781 struct peer *peer;
10782 safi_t safi;
10783
10784 /* BGP structure lookup. */
10785 if (argc == 4)
10786 {
10787 bgp = bgp_lookup_by_name (argv[0]);
10788 if (bgp == NULL)
10789 {
10790 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10791 return CMD_WARNING;
10792 }
10793 }
10794 else
10795 {
10796 bgp = bgp_get_default ();
10797 if (bgp == NULL)
10798 {
10799 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10800 return CMD_WARNING;
10801 }
10802 }
10803
10804 if (argc == 4) {
10805 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10806 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10807 } else {
10808 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10809 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10810 }
10811
10812 if (! peer)
10813 return CMD_WARNING;
10814
10815 if (! peer->afc[AFI_IP][safi])
10816 {
10817 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10818 VTY_NEWLINE);
10819 return CMD_WARNING;
10820}
10821
10822 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10823 PEER_FLAG_RSERVER_CLIENT))
10824 {
10825 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10826 VTY_NEWLINE);
10827 return CMD_WARNING;
10828 }
10829
10830 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10831 (argc == 4) ? argv[3] : argv[2],
10832 AFI_IP, safi, NULL, 0);
10833}
10834
10835ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10836 show_bgp_ipv4_safi_rsclient_route_cmd,
10837 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10838 SHOW_STR
10839 BGP_STR
10840 "Address family\n"
10841 "Address Family modifier\n"
10842 "Address Family modifier\n"
10843 "Information about Route Server Client\n"
10844 NEIGHBOR_ADDR_STR
10845 "Network in the BGP routing table to display\n")
10846
paulfee0f4c2004-09-13 05:12:46 +000010847DEFUN (show_ip_bgp_view_rsclient_prefix,
10848 show_ip_bgp_view_rsclient_prefix_cmd,
10849 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10850 SHOW_STR
10851 IP_STR
10852 BGP_STR
10853 "BGP view\n"
10854 "BGP view name\n"
10855 "Information about Route Server Client\n"
10856 NEIGHBOR_ADDR_STR
10857 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10858{
10859 struct bgp *bgp;
10860 struct peer *peer;
10861
10862 /* BGP structure lookup. */
10863 if (argc == 3)
10864 {
10865 bgp = bgp_lookup_by_name (argv[0]);
10866 if (bgp == NULL)
10867 {
10868 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10869 return CMD_WARNING;
10870 }
10871 }
10872 else
10873 {
10874 bgp = bgp_get_default ();
10875 if (bgp == NULL)
10876 {
10877 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10878 return CMD_WARNING;
10879 }
10880 }
10881
10882 if (argc == 3)
10883 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10884 else
10885 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10886
10887 if (! peer)
10888 return CMD_WARNING;
10889
10890 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10891 {
10892 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10893 VTY_NEWLINE);
10894 return CMD_WARNING;
10895}
10896
10897 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10898 PEER_FLAG_RSERVER_CLIENT))
10899{
10900 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10901 VTY_NEWLINE);
10902 return CMD_WARNING;
10903 }
10904
10905 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10906 (argc == 3) ? argv[2] : argv[1],
10907 AFI_IP, SAFI_UNICAST, NULL, 1);
10908}
10909
10910ALIAS (show_ip_bgp_view_rsclient_prefix,
10911 show_ip_bgp_rsclient_prefix_cmd,
10912 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10913 SHOW_STR
10914 IP_STR
10915 BGP_STR
10916 "Information about Route Server Client\n"
10917 NEIGHBOR_ADDR_STR
10918 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10919
Michael Lambert95cbbd22010-07-23 14:43:04 -040010920DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10921 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10922 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10923 SHOW_STR
10924 BGP_STR
10925 "BGP view\n"
10926 "BGP view name\n"
10927 "Address family\n"
10928 "Address Family modifier\n"
10929 "Address Family modifier\n"
10930 "Information about Route Server Client\n"
10931 NEIGHBOR_ADDR_STR
10932 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10933{
10934 struct bgp *bgp;
10935 struct peer *peer;
10936 safi_t safi;
10937
10938 /* BGP structure lookup. */
10939 if (argc == 4)
10940 {
10941 bgp = bgp_lookup_by_name (argv[0]);
10942 if (bgp == NULL)
10943 {
10944 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10945 return CMD_WARNING;
10946 }
10947 }
10948 else
10949 {
10950 bgp = bgp_get_default ();
10951 if (bgp == NULL)
10952 {
10953 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10954 return CMD_WARNING;
10955 }
10956 }
10957
10958 if (argc == 4) {
10959 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10960 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10961 } else {
10962 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10963 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10964 }
10965
10966 if (! peer)
10967 return CMD_WARNING;
10968
10969 if (! peer->afc[AFI_IP][safi])
10970 {
10971 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10972 VTY_NEWLINE);
10973 return CMD_WARNING;
10974}
10975
10976 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10977 PEER_FLAG_RSERVER_CLIENT))
10978{
10979 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10980 VTY_NEWLINE);
10981 return CMD_WARNING;
10982 }
10983
10984 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10985 (argc == 4) ? argv[3] : argv[2],
10986 AFI_IP, safi, NULL, 1);
10987}
10988
10989ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10990 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10991 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10992 SHOW_STR
10993 BGP_STR
10994 "Address family\n"
10995 "Address Family modifier\n"
10996 "Address Family modifier\n"
10997 "Information about Route Server Client\n"
10998 NEIGHBOR_ADDR_STR
10999 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000011000
paul718e3742002-12-13 20:15:29 +000011001#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000011002DEFUN (show_bgp_view_neighbor_routes,
11003 show_bgp_view_neighbor_routes_cmd,
11004 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11005 SHOW_STR
11006 BGP_STR
11007 "BGP view\n"
11008 "BGP view name\n"
11009 "Detailed information on TCP and BGP neighbor connections\n"
11010 "Neighbor to display information about\n"
11011 "Neighbor to display information about\n"
11012 "Display routes learned from neighbor\n")
11013{
11014 struct peer *peer;
11015
11016 if (argc == 2)
11017 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11018 else
11019 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11020
11021 if (! peer)
11022 return CMD_WARNING;
11023
11024 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11025 bgp_show_type_neighbor);
11026}
11027
11028ALIAS (show_bgp_view_neighbor_routes,
11029 show_bgp_view_ipv6_neighbor_routes_cmd,
11030 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11031 SHOW_STR
11032 BGP_STR
11033 "BGP view\n"
11034 "BGP view name\n"
11035 "Address family\n"
11036 "Detailed information on TCP and BGP neighbor connections\n"
11037 "Neighbor to display information about\n"
11038 "Neighbor to display information about\n"
11039 "Display routes learned from neighbor\n")
11040
11041DEFUN (show_bgp_view_neighbor_damp,
11042 show_bgp_view_neighbor_damp_cmd,
11043 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11044 SHOW_STR
11045 BGP_STR
11046 "BGP view\n"
11047 "BGP view name\n"
11048 "Detailed information on TCP and BGP neighbor connections\n"
11049 "Neighbor to display information about\n"
11050 "Neighbor to display information about\n"
11051 "Display the dampened routes received from neighbor\n")
11052{
11053 struct peer *peer;
11054
11055 if (argc == 2)
11056 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11057 else
11058 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11059
11060 if (! peer)
11061 return CMD_WARNING;
11062
11063 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11064 bgp_show_type_damp_neighbor);
11065}
11066
11067ALIAS (show_bgp_view_neighbor_damp,
11068 show_bgp_view_ipv6_neighbor_damp_cmd,
11069 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11070 SHOW_STR
11071 BGP_STR
11072 "BGP view\n"
11073 "BGP view name\n"
11074 "Address family\n"
11075 "Detailed information on TCP and BGP neighbor connections\n"
11076 "Neighbor to display information about\n"
11077 "Neighbor to display information about\n"
11078 "Display the dampened routes received from neighbor\n")
11079
11080DEFUN (show_bgp_view_neighbor_flap,
11081 show_bgp_view_neighbor_flap_cmd,
11082 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11083 SHOW_STR
11084 BGP_STR
11085 "BGP view\n"
11086 "BGP view name\n"
11087 "Detailed information on TCP and BGP neighbor connections\n"
11088 "Neighbor to display information about\n"
11089 "Neighbor to display information about\n"
11090 "Display flap statistics of the routes learned from neighbor\n")
11091{
11092 struct peer *peer;
11093
11094 if (argc == 2)
11095 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11096 else
11097 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11098
11099 if (! peer)
11100 return CMD_WARNING;
11101
11102 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11103 bgp_show_type_flap_neighbor);
11104}
11105
11106ALIAS (show_bgp_view_neighbor_flap,
11107 show_bgp_view_ipv6_neighbor_flap_cmd,
11108 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11109 SHOW_STR
11110 BGP_STR
11111 "BGP view\n"
11112 "BGP view name\n"
11113 "Address family\n"
11114 "Detailed information on TCP and BGP neighbor connections\n"
11115 "Neighbor to display information about\n"
11116 "Neighbor to display information about\n"
11117 "Display flap statistics of the routes learned from neighbor\n")
11118
11119ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011120 show_bgp_neighbor_routes_cmd,
11121 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11122 SHOW_STR
11123 BGP_STR
11124 "Detailed information on TCP and BGP neighbor connections\n"
11125 "Neighbor to display information about\n"
11126 "Neighbor to display information about\n"
11127 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011128
paulbb46e942003-10-24 19:02:03 +000011129
11130ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011131 show_bgp_ipv6_neighbor_routes_cmd,
11132 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11133 SHOW_STR
11134 BGP_STR
11135 "Address family\n"
11136 "Detailed information on TCP and BGP neighbor connections\n"
11137 "Neighbor to display information about\n"
11138 "Neighbor to display information about\n"
11139 "Display routes learned from neighbor\n")
11140
11141/* old command */
paulbb46e942003-10-24 19:02:03 +000011142ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011143 ipv6_bgp_neighbor_routes_cmd,
11144 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11145 SHOW_STR
11146 IPV6_STR
11147 BGP_STR
11148 "Detailed information on TCP and BGP neighbor connections\n"
11149 "Neighbor to display information about\n"
11150 "Neighbor to display information about\n"
11151 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011152
11153/* old command */
11154DEFUN (ipv6_mbgp_neighbor_routes,
11155 ipv6_mbgp_neighbor_routes_cmd,
11156 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11157 SHOW_STR
11158 IPV6_STR
11159 MBGP_STR
11160 "Detailed information on TCP and BGP neighbor connections\n"
11161 "Neighbor to display information about\n"
11162 "Neighbor to display information about\n"
11163 "Display routes learned from neighbor\n")
11164{
paulbb46e942003-10-24 19:02:03 +000011165 struct peer *peer;
11166
11167 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11168 if (! peer)
11169 return CMD_WARNING;
11170
11171 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011172 bgp_show_type_neighbor);
11173}
paulbb46e942003-10-24 19:02:03 +000011174
11175ALIAS (show_bgp_view_neighbor_flap,
11176 show_bgp_neighbor_flap_cmd,
11177 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11178 SHOW_STR
11179 BGP_STR
11180 "Detailed information on TCP and BGP neighbor connections\n"
11181 "Neighbor to display information about\n"
11182 "Neighbor to display information about\n"
11183 "Display flap statistics of the routes learned from neighbor\n")
11184
11185ALIAS (show_bgp_view_neighbor_flap,
11186 show_bgp_ipv6_neighbor_flap_cmd,
11187 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11188 SHOW_STR
11189 BGP_STR
11190 "Address family\n"
11191 "Detailed information on TCP and BGP neighbor connections\n"
11192 "Neighbor to display information about\n"
11193 "Neighbor to display information about\n"
11194 "Display flap statistics of the routes learned from neighbor\n")
11195
11196ALIAS (show_bgp_view_neighbor_damp,
11197 show_bgp_neighbor_damp_cmd,
11198 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11199 SHOW_STR
11200 BGP_STR
11201 "Detailed information on TCP and BGP neighbor connections\n"
11202 "Neighbor to display information about\n"
11203 "Neighbor to display information about\n"
11204 "Display the dampened routes received from neighbor\n")
11205
11206ALIAS (show_bgp_view_neighbor_damp,
11207 show_bgp_ipv6_neighbor_damp_cmd,
11208 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11209 SHOW_STR
11210 BGP_STR
11211 "Address family\n"
11212 "Detailed information on TCP and BGP neighbor connections\n"
11213 "Neighbor to display information about\n"
11214 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011215 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011216
11217DEFUN (show_bgp_view_rsclient,
11218 show_bgp_view_rsclient_cmd,
11219 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11220 SHOW_STR
11221 BGP_STR
11222 "BGP view\n"
11223 "BGP view name\n"
11224 "Information about Route Server Client\n"
11225 NEIGHBOR_ADDR_STR)
11226{
11227 struct bgp_table *table;
11228 struct peer *peer;
11229
11230 if (argc == 2)
11231 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11232 else
11233 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11234
11235 if (! peer)
11236 return CMD_WARNING;
11237
11238 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11239 {
11240 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11241 VTY_NEWLINE);
11242 return CMD_WARNING;
11243 }
11244
11245 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11246 PEER_FLAG_RSERVER_CLIENT))
11247 {
11248 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11249 VTY_NEWLINE);
11250 return CMD_WARNING;
11251 }
11252
11253 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11254
ajs5a646652004-11-05 01:25:55 +000011255 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011256}
11257
11258ALIAS (show_bgp_view_rsclient,
11259 show_bgp_rsclient_cmd,
11260 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11261 SHOW_STR
11262 BGP_STR
11263 "Information about Route Server Client\n"
11264 NEIGHBOR_ADDR_STR)
11265
Michael Lambert95cbbd22010-07-23 14:43:04 -040011266DEFUN (show_bgp_view_ipv6_safi_rsclient,
11267 show_bgp_view_ipv6_safi_rsclient_cmd,
11268 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11269 SHOW_STR
11270 BGP_STR
11271 "BGP view\n"
11272 "BGP view name\n"
11273 "Address family\n"
11274 "Address Family modifier\n"
11275 "Address Family modifier\n"
11276 "Information about Route Server Client\n"
11277 NEIGHBOR_ADDR_STR)
11278{
11279 struct bgp_table *table;
11280 struct peer *peer;
11281 safi_t safi;
11282
11283 if (argc == 3) {
11284 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11285 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11286 } else {
11287 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11288 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11289 }
11290
11291 if (! peer)
11292 return CMD_WARNING;
11293
11294 if (! peer->afc[AFI_IP6][safi])
11295 {
11296 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11297 VTY_NEWLINE);
11298 return CMD_WARNING;
11299 }
11300
11301 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11302 PEER_FLAG_RSERVER_CLIENT))
11303 {
11304 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11305 VTY_NEWLINE);
11306 return CMD_WARNING;
11307 }
11308
11309 table = peer->rib[AFI_IP6][safi];
11310
11311 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11312}
11313
11314ALIAS (show_bgp_view_ipv6_safi_rsclient,
11315 show_bgp_ipv6_safi_rsclient_cmd,
11316 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11317 SHOW_STR
11318 BGP_STR
11319 "Address family\n"
11320 "Address Family modifier\n"
11321 "Address Family modifier\n"
11322 "Information about Route Server Client\n"
11323 NEIGHBOR_ADDR_STR)
11324
paulfee0f4c2004-09-13 05:12:46 +000011325DEFUN (show_bgp_view_rsclient_route,
11326 show_bgp_view_rsclient_route_cmd,
11327 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11328 SHOW_STR
11329 BGP_STR
11330 "BGP view\n"
11331 "BGP view name\n"
11332 "Information about Route Server Client\n"
11333 NEIGHBOR_ADDR_STR
11334 "Network in the BGP routing table to display\n")
11335{
11336 struct bgp *bgp;
11337 struct peer *peer;
11338
11339 /* BGP structure lookup. */
11340 if (argc == 3)
11341 {
11342 bgp = bgp_lookup_by_name (argv[0]);
11343 if (bgp == NULL)
11344 {
11345 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11346 return CMD_WARNING;
11347 }
11348 }
11349 else
11350 {
11351 bgp = bgp_get_default ();
11352 if (bgp == NULL)
11353 {
11354 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11355 return CMD_WARNING;
11356 }
11357 }
11358
11359 if (argc == 3)
11360 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11361 else
11362 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11363
11364 if (! peer)
11365 return CMD_WARNING;
11366
11367 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11368 {
11369 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11370 VTY_NEWLINE);
11371 return CMD_WARNING;
11372 }
11373
11374 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11375 PEER_FLAG_RSERVER_CLIENT))
11376 {
11377 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11378 VTY_NEWLINE);
11379 return CMD_WARNING;
11380 }
11381
11382 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11383 (argc == 3) ? argv[2] : argv[1],
11384 AFI_IP6, SAFI_UNICAST, NULL, 0);
11385}
11386
11387ALIAS (show_bgp_view_rsclient_route,
11388 show_bgp_rsclient_route_cmd,
11389 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11390 SHOW_STR
11391 BGP_STR
11392 "Information about Route Server Client\n"
11393 NEIGHBOR_ADDR_STR
11394 "Network in the BGP routing table to display\n")
11395
Michael Lambert95cbbd22010-07-23 14:43:04 -040011396DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11397 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11398 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11399 SHOW_STR
11400 BGP_STR
11401 "BGP view\n"
11402 "BGP view name\n"
11403 "Address family\n"
11404 "Address Family modifier\n"
11405 "Address Family modifier\n"
11406 "Information about Route Server Client\n"
11407 NEIGHBOR_ADDR_STR
11408 "Network in the BGP routing table to display\n")
11409{
11410 struct bgp *bgp;
11411 struct peer *peer;
11412 safi_t safi;
11413
11414 /* BGP structure lookup. */
11415 if (argc == 4)
11416 {
11417 bgp = bgp_lookup_by_name (argv[0]);
11418 if (bgp == NULL)
11419 {
11420 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11421 return CMD_WARNING;
11422 }
11423 }
11424 else
11425 {
11426 bgp = bgp_get_default ();
11427 if (bgp == NULL)
11428 {
11429 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11430 return CMD_WARNING;
11431 }
11432 }
11433
11434 if (argc == 4) {
11435 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11436 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11437 } else {
11438 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11439 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11440 }
11441
11442 if (! peer)
11443 return CMD_WARNING;
11444
11445 if (! peer->afc[AFI_IP6][safi])
11446 {
11447 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11448 VTY_NEWLINE);
11449 return CMD_WARNING;
11450}
11451
11452 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11453 PEER_FLAG_RSERVER_CLIENT))
11454 {
11455 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11456 VTY_NEWLINE);
11457 return CMD_WARNING;
11458 }
11459
11460 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11461 (argc == 4) ? argv[3] : argv[2],
11462 AFI_IP6, safi, NULL, 0);
11463}
11464
11465ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11466 show_bgp_ipv6_safi_rsclient_route_cmd,
11467 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11468 SHOW_STR
11469 BGP_STR
11470 "Address family\n"
11471 "Address Family modifier\n"
11472 "Address Family modifier\n"
11473 "Information about Route Server Client\n"
11474 NEIGHBOR_ADDR_STR
11475 "Network in the BGP routing table to display\n")
11476
paulfee0f4c2004-09-13 05:12:46 +000011477DEFUN (show_bgp_view_rsclient_prefix,
11478 show_bgp_view_rsclient_prefix_cmd,
11479 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11480 SHOW_STR
11481 BGP_STR
11482 "BGP view\n"
11483 "BGP view name\n"
11484 "Information about Route Server Client\n"
11485 NEIGHBOR_ADDR_STR
11486 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11487{
11488 struct bgp *bgp;
11489 struct peer *peer;
11490
11491 /* BGP structure lookup. */
11492 if (argc == 3)
11493 {
11494 bgp = bgp_lookup_by_name (argv[0]);
11495 if (bgp == NULL)
11496 {
11497 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11498 return CMD_WARNING;
11499 }
11500 }
11501 else
11502 {
11503 bgp = bgp_get_default ();
11504 if (bgp == NULL)
11505 {
11506 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11507 return CMD_WARNING;
11508 }
11509 }
11510
11511 if (argc == 3)
11512 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11513 else
11514 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11515
11516 if (! peer)
11517 return CMD_WARNING;
11518
11519 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11520 {
11521 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11522 VTY_NEWLINE);
11523 return CMD_WARNING;
11524 }
11525
11526 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11527 PEER_FLAG_RSERVER_CLIENT))
11528 {
11529 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11530 VTY_NEWLINE);
11531 return CMD_WARNING;
11532 }
11533
11534 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11535 (argc == 3) ? argv[2] : argv[1],
11536 AFI_IP6, SAFI_UNICAST, NULL, 1);
11537}
11538
11539ALIAS (show_bgp_view_rsclient_prefix,
11540 show_bgp_rsclient_prefix_cmd,
11541 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11542 SHOW_STR
11543 BGP_STR
11544 "Information about Route Server Client\n"
11545 NEIGHBOR_ADDR_STR
11546 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11547
Michael Lambert95cbbd22010-07-23 14:43:04 -040011548DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11549 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11550 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11551 SHOW_STR
11552 BGP_STR
11553 "BGP view\n"
11554 "BGP view name\n"
11555 "Address family\n"
11556 "Address Family modifier\n"
11557 "Address Family modifier\n"
11558 "Information about Route Server Client\n"
11559 NEIGHBOR_ADDR_STR
11560 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11561{
11562 struct bgp *bgp;
11563 struct peer *peer;
11564 safi_t safi;
11565
11566 /* BGP structure lookup. */
11567 if (argc == 4)
11568 {
11569 bgp = bgp_lookup_by_name (argv[0]);
11570 if (bgp == NULL)
11571 {
11572 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11573 return CMD_WARNING;
11574 }
11575 }
11576 else
11577 {
11578 bgp = bgp_get_default ();
11579 if (bgp == NULL)
11580 {
11581 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11582 return CMD_WARNING;
11583 }
11584 }
11585
11586 if (argc == 4) {
11587 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11588 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11589 } else {
11590 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11591 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11592 }
11593
11594 if (! peer)
11595 return CMD_WARNING;
11596
11597 if (! peer->afc[AFI_IP6][safi])
11598 {
11599 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11600 VTY_NEWLINE);
11601 return CMD_WARNING;
11602}
11603
11604 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11605 PEER_FLAG_RSERVER_CLIENT))
11606{
11607 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11608 VTY_NEWLINE);
11609 return CMD_WARNING;
11610 }
11611
11612 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11613 (argc == 4) ? argv[3] : argv[2],
11614 AFI_IP6, safi, NULL, 1);
11615}
11616
11617ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11618 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11619 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11620 SHOW_STR
11621 BGP_STR
11622 "Address family\n"
11623 "Address Family modifier\n"
11624 "Address Family modifier\n"
11625 "Information about Route Server Client\n"
11626 NEIGHBOR_ADDR_STR
11627 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11628
paul718e3742002-12-13 20:15:29 +000011629#endif /* HAVE_IPV6 */
11630
11631struct bgp_table *bgp_distance_table;
11632
11633struct bgp_distance
11634{
11635 /* Distance value for the IP source prefix. */
11636 u_char distance;
11637
11638 /* Name of the access-list to be matched. */
11639 char *access_list;
11640};
11641
paul94f2b392005-06-28 12:44:16 +000011642static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011643bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011644{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011645 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011646}
11647
paul94f2b392005-06-28 12:44:16 +000011648static void
paul718e3742002-12-13 20:15:29 +000011649bgp_distance_free (struct bgp_distance *bdistance)
11650{
11651 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11652}
11653
paul94f2b392005-06-28 12:44:16 +000011654static int
paulfd79ac92004-10-13 05:06:08 +000011655bgp_distance_set (struct vty *vty, const char *distance_str,
11656 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011657{
11658 int ret;
11659 struct prefix_ipv4 p;
11660 u_char distance;
11661 struct bgp_node *rn;
11662 struct bgp_distance *bdistance;
11663
11664 ret = str2prefix_ipv4 (ip_str, &p);
11665 if (ret == 0)
11666 {
11667 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11668 return CMD_WARNING;
11669 }
11670
11671 distance = atoi (distance_str);
11672
11673 /* Get BGP distance node. */
11674 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11675 if (rn->info)
11676 {
11677 bdistance = rn->info;
11678 bgp_unlock_node (rn);
11679 }
11680 else
11681 {
11682 bdistance = bgp_distance_new ();
11683 rn->info = bdistance;
11684 }
11685
11686 /* Set distance value. */
11687 bdistance->distance = distance;
11688
11689 /* Reset access-list configuration. */
11690 if (bdistance->access_list)
11691 {
11692 free (bdistance->access_list);
11693 bdistance->access_list = NULL;
11694 }
11695 if (access_list_str)
11696 bdistance->access_list = strdup (access_list_str);
11697
11698 return CMD_SUCCESS;
11699}
11700
paul94f2b392005-06-28 12:44:16 +000011701static int
paulfd79ac92004-10-13 05:06:08 +000011702bgp_distance_unset (struct vty *vty, const char *distance_str,
11703 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011704{
11705 int ret;
11706 struct prefix_ipv4 p;
11707 u_char distance;
11708 struct bgp_node *rn;
11709 struct bgp_distance *bdistance;
11710
11711 ret = str2prefix_ipv4 (ip_str, &p);
11712 if (ret == 0)
11713 {
11714 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11715 return CMD_WARNING;
11716 }
11717
11718 distance = atoi (distance_str);
11719
11720 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11721 if (! rn)
11722 {
11723 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11724 return CMD_WARNING;
11725 }
11726
11727 bdistance = rn->info;
11728
11729 if (bdistance->access_list)
11730 free (bdistance->access_list);
11731 bgp_distance_free (bdistance);
11732
11733 rn->info = NULL;
11734 bgp_unlock_node (rn);
11735 bgp_unlock_node (rn);
11736
11737 return CMD_SUCCESS;
11738}
11739
paul718e3742002-12-13 20:15:29 +000011740/* Apply BGP information to distance method. */
11741u_char
11742bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11743{
11744 struct bgp_node *rn;
11745 struct prefix_ipv4 q;
11746 struct peer *peer;
11747 struct bgp_distance *bdistance;
11748 struct access_list *alist;
11749 struct bgp_static *bgp_static;
11750
11751 if (! bgp)
11752 return 0;
11753
11754 if (p->family != AF_INET)
11755 return 0;
11756
11757 peer = rinfo->peer;
11758
11759 if (peer->su.sa.sa_family != AF_INET)
11760 return 0;
11761
11762 memset (&q, 0, sizeof (struct prefix_ipv4));
11763 q.family = AF_INET;
11764 q.prefix = peer->su.sin.sin_addr;
11765 q.prefixlen = IPV4_MAX_BITLEN;
11766
11767 /* Check source address. */
11768 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11769 if (rn)
11770 {
11771 bdistance = rn->info;
11772 bgp_unlock_node (rn);
11773
11774 if (bdistance->access_list)
11775 {
11776 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11777 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11778 return bdistance->distance;
11779 }
11780 else
11781 return bdistance->distance;
11782 }
11783
11784 /* Backdoor check. */
11785 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11786 if (rn)
11787 {
11788 bgp_static = rn->info;
11789 bgp_unlock_node (rn);
11790
11791 if (bgp_static->backdoor)
11792 {
11793 if (bgp->distance_local)
11794 return bgp->distance_local;
11795 else
11796 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11797 }
11798 }
11799
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011800 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011801 {
11802 if (bgp->distance_ebgp)
11803 return bgp->distance_ebgp;
11804 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11805 }
11806 else
11807 {
11808 if (bgp->distance_ibgp)
11809 return bgp->distance_ibgp;
11810 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11811 }
11812}
11813
11814DEFUN (bgp_distance,
11815 bgp_distance_cmd,
11816 "distance bgp <1-255> <1-255> <1-255>",
11817 "Define an administrative distance\n"
11818 "BGP distance\n"
11819 "Distance for routes external to the AS\n"
11820 "Distance for routes internal to the AS\n"
11821 "Distance for local routes\n")
11822{
11823 struct bgp *bgp;
11824
11825 bgp = vty->index;
11826
11827 bgp->distance_ebgp = atoi (argv[0]);
11828 bgp->distance_ibgp = atoi (argv[1]);
11829 bgp->distance_local = atoi (argv[2]);
11830 return CMD_SUCCESS;
11831}
11832
11833DEFUN (no_bgp_distance,
11834 no_bgp_distance_cmd,
11835 "no distance bgp <1-255> <1-255> <1-255>",
11836 NO_STR
11837 "Define an administrative distance\n"
11838 "BGP distance\n"
11839 "Distance for routes external to the AS\n"
11840 "Distance for routes internal to the AS\n"
11841 "Distance for local routes\n")
11842{
11843 struct bgp *bgp;
11844
11845 bgp = vty->index;
11846
11847 bgp->distance_ebgp= 0;
11848 bgp->distance_ibgp = 0;
11849 bgp->distance_local = 0;
11850 return CMD_SUCCESS;
11851}
11852
11853ALIAS (no_bgp_distance,
11854 no_bgp_distance2_cmd,
11855 "no distance bgp",
11856 NO_STR
11857 "Define an administrative distance\n"
11858 "BGP distance\n")
11859
11860DEFUN (bgp_distance_source,
11861 bgp_distance_source_cmd,
11862 "distance <1-255> A.B.C.D/M",
11863 "Define an administrative distance\n"
11864 "Administrative distance\n"
11865 "IP source prefix\n")
11866{
11867 bgp_distance_set (vty, argv[0], argv[1], NULL);
11868 return CMD_SUCCESS;
11869}
11870
11871DEFUN (no_bgp_distance_source,
11872 no_bgp_distance_source_cmd,
11873 "no distance <1-255> A.B.C.D/M",
11874 NO_STR
11875 "Define an administrative distance\n"
11876 "Administrative distance\n"
11877 "IP source prefix\n")
11878{
11879 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11880 return CMD_SUCCESS;
11881}
11882
11883DEFUN (bgp_distance_source_access_list,
11884 bgp_distance_source_access_list_cmd,
11885 "distance <1-255> A.B.C.D/M WORD",
11886 "Define an administrative distance\n"
11887 "Administrative distance\n"
11888 "IP source prefix\n"
11889 "Access list name\n")
11890{
11891 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11892 return CMD_SUCCESS;
11893}
11894
11895DEFUN (no_bgp_distance_source_access_list,
11896 no_bgp_distance_source_access_list_cmd,
11897 "no distance <1-255> A.B.C.D/M WORD",
11898 NO_STR
11899 "Define an administrative distance\n"
11900 "Administrative distance\n"
11901 "IP source prefix\n"
11902 "Access list name\n")
11903{
11904 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11905 return CMD_SUCCESS;
11906}
11907
11908DEFUN (bgp_damp_set,
11909 bgp_damp_set_cmd,
11910 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11911 "BGP Specific commands\n"
11912 "Enable route-flap dampening\n"
11913 "Half-life time for the penalty\n"
11914 "Value to start reusing a route\n"
11915 "Value to start suppressing a route\n"
11916 "Maximum duration to suppress a stable route\n")
11917{
11918 struct bgp *bgp;
11919 int half = DEFAULT_HALF_LIFE * 60;
11920 int reuse = DEFAULT_REUSE;
11921 int suppress = DEFAULT_SUPPRESS;
11922 int max = 4 * half;
11923
11924 if (argc == 4)
11925 {
11926 half = atoi (argv[0]) * 60;
11927 reuse = atoi (argv[1]);
11928 suppress = atoi (argv[2]);
11929 max = atoi (argv[3]) * 60;
11930 }
11931 else if (argc == 1)
11932 {
11933 half = atoi (argv[0]) * 60;
11934 max = 4 * half;
11935 }
11936
11937 bgp = vty->index;
11938 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11939 half, reuse, suppress, max);
11940}
11941
11942ALIAS (bgp_damp_set,
11943 bgp_damp_set2_cmd,
11944 "bgp dampening <1-45>",
11945 "BGP Specific commands\n"
11946 "Enable route-flap dampening\n"
11947 "Half-life time for the penalty\n")
11948
11949ALIAS (bgp_damp_set,
11950 bgp_damp_set3_cmd,
11951 "bgp dampening",
11952 "BGP Specific commands\n"
11953 "Enable route-flap dampening\n")
11954
11955DEFUN (bgp_damp_unset,
11956 bgp_damp_unset_cmd,
11957 "no bgp dampening",
11958 NO_STR
11959 "BGP Specific commands\n"
11960 "Enable route-flap dampening\n")
11961{
11962 struct bgp *bgp;
11963
11964 bgp = vty->index;
11965 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11966}
11967
11968ALIAS (bgp_damp_unset,
11969 bgp_damp_unset2_cmd,
11970 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11971 NO_STR
11972 "BGP Specific commands\n"
11973 "Enable route-flap dampening\n"
11974 "Half-life time for the penalty\n"
11975 "Value to start reusing a route\n"
11976 "Value to start suppressing a route\n"
11977 "Maximum duration to suppress a stable route\n")
11978
11979DEFUN (show_ip_bgp_dampened_paths,
11980 show_ip_bgp_dampened_paths_cmd,
11981 "show ip bgp dampened-paths",
11982 SHOW_STR
11983 IP_STR
11984 BGP_STR
11985 "Display paths suppressed due to dampening\n")
11986{
ajs5a646652004-11-05 01:25:55 +000011987 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11988 NULL);
paul718e3742002-12-13 20:15:29 +000011989}
11990
11991DEFUN (show_ip_bgp_flap_statistics,
11992 show_ip_bgp_flap_statistics_cmd,
11993 "show ip bgp flap-statistics",
11994 SHOW_STR
11995 IP_STR
11996 BGP_STR
11997 "Display flap statistics of routes\n")
11998{
ajs5a646652004-11-05 01:25:55 +000011999 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
12000 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000012001}
12002
12003/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012004static int
paulfd79ac92004-10-13 05:06:08 +000012005bgp_clear_damp_route (struct vty *vty, const char *view_name,
12006 const char *ip_str, afi_t afi, safi_t safi,
12007 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012008{
12009 int ret;
12010 struct prefix match;
12011 struct bgp_node *rn;
12012 struct bgp_node *rm;
12013 struct bgp_info *ri;
12014 struct bgp_info *ri_temp;
12015 struct bgp *bgp;
12016 struct bgp_table *table;
12017
12018 /* BGP structure lookup. */
12019 if (view_name)
12020 {
12021 bgp = bgp_lookup_by_name (view_name);
12022 if (bgp == NULL)
12023 {
12024 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12025 return CMD_WARNING;
12026 }
12027 }
12028 else
12029 {
12030 bgp = bgp_get_default ();
12031 if (bgp == NULL)
12032 {
12033 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12034 return CMD_WARNING;
12035 }
12036 }
12037
12038 /* Check IP address argument. */
12039 ret = str2prefix (ip_str, &match);
12040 if (! ret)
12041 {
12042 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12043 return CMD_WARNING;
12044 }
12045
12046 match.family = afi2family (afi);
12047
12048 if (safi == SAFI_MPLS_VPN)
12049 {
12050 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12051 {
12052 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12053 continue;
12054
12055 if ((table = rn->info) != NULL)
12056 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012057 {
12058 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12059 {
12060 ri = rm->info;
12061 while (ri)
12062 {
12063 if (ri->extra && ri->extra->damp_info)
12064 {
12065 ri_temp = ri->next;
12066 bgp_damp_info_free (ri->extra->damp_info, 1);
12067 ri = ri_temp;
12068 }
12069 else
12070 ri = ri->next;
12071 }
12072 }
12073
12074 bgp_unlock_node (rm);
12075 }
paul718e3742002-12-13 20:15:29 +000012076 }
12077 }
12078 else
12079 {
12080 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012081 {
12082 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12083 {
12084 ri = rn->info;
12085 while (ri)
12086 {
12087 if (ri->extra && ri->extra->damp_info)
12088 {
12089 ri_temp = ri->next;
12090 bgp_damp_info_free (ri->extra->damp_info, 1);
12091 ri = ri_temp;
12092 }
12093 else
12094 ri = ri->next;
12095 }
12096 }
12097
12098 bgp_unlock_node (rn);
12099 }
paul718e3742002-12-13 20:15:29 +000012100 }
12101
12102 return CMD_SUCCESS;
12103}
12104
12105DEFUN (clear_ip_bgp_dampening,
12106 clear_ip_bgp_dampening_cmd,
12107 "clear ip bgp dampening",
12108 CLEAR_STR
12109 IP_STR
12110 BGP_STR
12111 "Clear route flap dampening information\n")
12112{
12113 bgp_damp_info_clean ();
12114 return CMD_SUCCESS;
12115}
12116
12117DEFUN (clear_ip_bgp_dampening_prefix,
12118 clear_ip_bgp_dampening_prefix_cmd,
12119 "clear ip bgp dampening A.B.C.D/M",
12120 CLEAR_STR
12121 IP_STR
12122 BGP_STR
12123 "Clear route flap dampening information\n"
12124 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12125{
12126 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12127 SAFI_UNICAST, NULL, 1);
12128}
12129
12130DEFUN (clear_ip_bgp_dampening_address,
12131 clear_ip_bgp_dampening_address_cmd,
12132 "clear ip bgp dampening A.B.C.D",
12133 CLEAR_STR
12134 IP_STR
12135 BGP_STR
12136 "Clear route flap dampening information\n"
12137 "Network to clear damping information\n")
12138{
12139 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12140 SAFI_UNICAST, NULL, 0);
12141}
12142
12143DEFUN (clear_ip_bgp_dampening_address_mask,
12144 clear_ip_bgp_dampening_address_mask_cmd,
12145 "clear ip bgp dampening A.B.C.D A.B.C.D",
12146 CLEAR_STR
12147 IP_STR
12148 BGP_STR
12149 "Clear route flap dampening information\n"
12150 "Network to clear damping information\n"
12151 "Network mask\n")
12152{
12153 int ret;
12154 char prefix_str[BUFSIZ];
12155
12156 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12157 if (! ret)
12158 {
12159 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12160 return CMD_WARNING;
12161 }
12162
12163 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12164 SAFI_UNICAST, NULL, 0);
12165}
12166
paul94f2b392005-06-28 12:44:16 +000012167static int
paul718e3742002-12-13 20:15:29 +000012168bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12169 afi_t afi, safi_t safi, int *write)
12170{
12171 struct bgp_node *prn;
12172 struct bgp_node *rn;
12173 struct bgp_table *table;
12174 struct prefix *p;
12175 struct prefix_rd *prd;
12176 struct bgp_static *bgp_static;
12177 u_int32_t label;
12178 char buf[SU_ADDRSTRLEN];
12179 char rdbuf[RD_ADDRSTRLEN];
12180
12181 /* Network configuration. */
12182 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12183 if ((table = prn->info) != NULL)
12184 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12185 if ((bgp_static = rn->info) != NULL)
12186 {
12187 p = &rn->p;
12188 prd = (struct prefix_rd *) &prn->p;
12189
12190 /* "address-family" display. */
12191 bgp_config_write_family_header (vty, afi, safi, write);
12192
12193 /* "network" configuration display. */
12194 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12195 label = decode_label (bgp_static->tag);
12196
12197 vty_out (vty, " network %s/%d rd %s tag %d",
12198 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12199 p->prefixlen,
12200 rdbuf, label);
12201 vty_out (vty, "%s", VTY_NEWLINE);
12202 }
12203 return 0;
12204}
12205
12206/* Configuration of static route announcement and aggregate
12207 information. */
12208int
12209bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12210 afi_t afi, safi_t safi, int *write)
12211{
12212 struct bgp_node *rn;
12213 struct prefix *p;
12214 struct bgp_static *bgp_static;
12215 struct bgp_aggregate *bgp_aggregate;
12216 char buf[SU_ADDRSTRLEN];
12217
12218 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12219 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12220
12221 /* Network configuration. */
12222 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12223 if ((bgp_static = rn->info) != NULL)
12224 {
12225 p = &rn->p;
12226
12227 /* "address-family" display. */
12228 bgp_config_write_family_header (vty, afi, safi, write);
12229
12230 /* "network" configuration display. */
12231 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12232 {
12233 u_int32_t destination;
12234 struct in_addr netmask;
12235
12236 destination = ntohl (p->u.prefix4.s_addr);
12237 masklen2ip (p->prefixlen, &netmask);
12238 vty_out (vty, " network %s",
12239 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12240
12241 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12242 || (IN_CLASSB (destination) && p->prefixlen == 16)
12243 || (IN_CLASSA (destination) && p->prefixlen == 8)
12244 || p->u.prefix4.s_addr == 0)
12245 {
12246 /* Natural mask is not display. */
12247 }
12248 else
12249 vty_out (vty, " mask %s", inet_ntoa (netmask));
12250 }
12251 else
12252 {
12253 vty_out (vty, " network %s/%d",
12254 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12255 p->prefixlen);
12256 }
12257
12258 if (bgp_static->rmap.name)
12259 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012260 else
12261 {
12262 if (bgp_static->backdoor)
12263 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012264 }
paul718e3742002-12-13 20:15:29 +000012265
12266 vty_out (vty, "%s", VTY_NEWLINE);
12267 }
12268
12269 /* Aggregate-address configuration. */
12270 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12271 if ((bgp_aggregate = rn->info) != NULL)
12272 {
12273 p = &rn->p;
12274
12275 /* "address-family" display. */
12276 bgp_config_write_family_header (vty, afi, safi, write);
12277
12278 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12279 {
12280 struct in_addr netmask;
12281
12282 masklen2ip (p->prefixlen, &netmask);
12283 vty_out (vty, " aggregate-address %s %s",
12284 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12285 inet_ntoa (netmask));
12286 }
12287 else
12288 {
12289 vty_out (vty, " aggregate-address %s/%d",
12290 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12291 p->prefixlen);
12292 }
12293
12294 if (bgp_aggregate->as_set)
12295 vty_out (vty, " as-set");
12296
12297 if (bgp_aggregate->summary_only)
12298 vty_out (vty, " summary-only");
12299
12300 vty_out (vty, "%s", VTY_NEWLINE);
12301 }
12302
12303 return 0;
12304}
12305
12306int
12307bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12308{
12309 struct bgp_node *rn;
12310 struct bgp_distance *bdistance;
12311
12312 /* Distance configuration. */
12313 if (bgp->distance_ebgp
12314 && bgp->distance_ibgp
12315 && bgp->distance_local
12316 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12317 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12318 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12319 vty_out (vty, " distance bgp %d %d %d%s",
12320 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12321 VTY_NEWLINE);
12322
12323 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12324 if ((bdistance = rn->info) != NULL)
12325 {
12326 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12327 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12328 bdistance->access_list ? bdistance->access_list : "",
12329 VTY_NEWLINE);
12330 }
12331
12332 return 0;
12333}
12334
12335/* Allocate routing table structure and install commands. */
12336void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012337bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012338{
12339 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012340 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012341
12342 /* IPv4 BGP commands. */
12343 install_element (BGP_NODE, &bgp_network_cmd);
12344 install_element (BGP_NODE, &bgp_network_mask_cmd);
12345 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12346 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12347 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12348 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12349 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12350 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12351 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12352 install_element (BGP_NODE, &no_bgp_network_cmd);
12353 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12354 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12355 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12356 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12357 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12358 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12359 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12360 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12361
12362 install_element (BGP_NODE, &aggregate_address_cmd);
12363 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12364 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12365 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12366 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12367 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12368 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12369 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12370 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12371 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12372 install_element (BGP_NODE, &no_aggregate_address_cmd);
12373 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12374 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12375 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12376 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12377 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12378 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12379 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12380 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12381 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12382
12383 /* IPv4 unicast configuration. */
12384 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12385 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12386 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12387 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12388 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12389 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012390 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012391 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12392 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12393 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12394 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12395 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012396
paul718e3742002-12-13 20:15:29 +000012397 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12398 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12399 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12400 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12401 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12402 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12403 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12404 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12405 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12406 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12407 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12408 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12409 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12410 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12411 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12412 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12413 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12414 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12415 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12416 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12417
12418 /* IPv4 multicast configuration. */
12419 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12420 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12421 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12422 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12423 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12424 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12425 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12426 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12427 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12428 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12429 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12430 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12431 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12432 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12433 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12434 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12435 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12436 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12437 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12438 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12439 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12440 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12441 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12442 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12443 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12444 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12445 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12446 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12447 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12448 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12449 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12450 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12451
12452 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12453 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012454 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012455 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12456 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012457 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012458 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12459 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12460 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012462 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012463 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12466 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12467 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12468 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012488 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12489 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12490 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12491 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12492 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012493 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12494 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12508 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12509 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012511 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012512 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12525 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12526 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12527 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012528 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012529 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012530 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012531 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012532 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012533 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012534 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12535 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012536 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012537 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012538 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012539 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012540 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012541 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012542
12543 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12544 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12545 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012546 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012547 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12548 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12549 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012550 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012551 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12552 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12553 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12554 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12555 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12556 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12557 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12558 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12559 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12560 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12561 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12562 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012563 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12564 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12565 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12566 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12567 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012568 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12569 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12570 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12571 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12572 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12573 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12574 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12575 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12576 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012577 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012578 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012579 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012580 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012581 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012582 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012583 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012584
12585 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12586 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012587 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012588 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12589 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012590 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012591 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12592 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12593 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012595 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012596 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12599 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12600 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12601 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012621 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12622 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12623 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12624 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12625 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012626 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12627 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12641 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12642 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012644 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012645 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12658 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12659 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12660 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012661 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012662 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012663 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012664 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012665 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012666 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012667 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12668 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012669 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012670 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012671 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012672 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012673 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012674 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012675
12676 /* BGP dampening clear commands */
12677 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12678 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12679 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12680 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12681
Paul Jakmaff7924f2006-09-04 01:10:36 +000012682 /* prefix count */
12683 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12684 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12685 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012686#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012687 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12688
paul718e3742002-12-13 20:15:29 +000012689 /* New config IPv6 BGP commands. */
12690 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12691 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12692 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12693 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12694
12695 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12696 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12697 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12698 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12699
G.Balaji73bfe0b2011-09-23 22:36:20 +053012700 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12701 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12702
paul718e3742002-12-13 20:15:29 +000012703 /* Old config IPv6 BGP commands. */
12704 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12705 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12706
12707 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12708 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12709 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12710 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12711
12712 install_element (VIEW_NODE, &show_bgp_cmd);
12713 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012714 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012715 install_element (VIEW_NODE, &show_bgp_route_cmd);
12716 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012717 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012718 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12719 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012720 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012721 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12722 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12723 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12724 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12725 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12726 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12727 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12728 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12729 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12730 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12731 install_element (VIEW_NODE, &show_bgp_community_cmd);
12732 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12733 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12734 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12735 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12736 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12737 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12738 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12739 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12740 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12741 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12742 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12743 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12744 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12745 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12746 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12747 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12748 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12749 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12750 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12751 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12752 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12753 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12754 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12755 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12756 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12757 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12758 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12759 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12760 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012761 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12762 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12763 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12764 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012765 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012766 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012767 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012768 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012769 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012770 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012771 install_element (VIEW_NODE, &show_bgp_view_cmd);
12772 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12773 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12774 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12775 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12776 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12777 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12778 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12779 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12780 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12781 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12782 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12783 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12784 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12785 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12786 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12787 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12788 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012789 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012790 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012791 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012792 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012793 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012794 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012795
12796 /* Restricted:
12797 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12798 */
12799 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12800 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012801 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012802 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12803 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012804 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012805 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12806 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12807 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12808 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12809 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12810 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12811 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12812 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12813 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12814 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12815 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12816 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12817 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12818 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12819 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12820 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12821 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012822 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012823 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012824 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012825 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12826 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12827 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12828 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12829 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12830 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12831 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012832 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012833 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012834 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012835
12836 install_element (ENABLE_NODE, &show_bgp_cmd);
12837 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012838 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012839 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12840 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012841 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012842 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12843 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012844 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012845 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12846 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12847 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12848 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12849 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12850 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12852 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012885 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12888 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012889 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012890 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012891 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012892 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012893 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012894 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012895 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12910 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12911 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12912 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012913 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012914 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012915 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012916 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012917 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012918 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012919
12920 /* Statistics */
12921 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12922 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12923 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12924 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12925
paul718e3742002-12-13 20:15:29 +000012926 /* old command */
12927 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12928 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12929 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12930 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12931 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12932 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12933 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12934 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12935 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12936 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12937 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12938 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12939 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12940 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12941 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12942 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12943 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12944 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12945 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12946 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12948 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12949 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12950 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12951 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12960 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12961 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12962 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012963
paul718e3742002-12-13 20:15:29 +000012964 /* old command */
12965 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12966 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12967 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12968 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12969 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12970 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12971 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12972 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12973 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12974 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12975 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12976 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12977 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12978 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12979 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12980 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12981 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12982 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12983 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12984 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12986 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12987 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12988 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12989 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12998 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12999 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
13000 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
13001
13002 /* old command */
13003 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13004 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13005 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13006 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13007
13008 /* old command */
13009 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13010 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13011 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13012 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13013
13014 /* old command */
13015 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13016 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13017 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13018 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13019#endif /* HAVE_IPV6 */
13020
13021 install_element (BGP_NODE, &bgp_distance_cmd);
13022 install_element (BGP_NODE, &no_bgp_distance_cmd);
13023 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13024 install_element (BGP_NODE, &bgp_distance_source_cmd);
13025 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13026 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13027 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13028
13029 install_element (BGP_NODE, &bgp_damp_set_cmd);
13030 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13031 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13032 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13033 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13034 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13035 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13036 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13037 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13038 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013039
13040 /* Deprecated AS-Pathlimit commands */
13041 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13042 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13043 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13044 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13045 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13046 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13047
13048 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13049 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13050 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13051 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13052 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13053 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13054
13055 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13056 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13057 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13058 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13059 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13060 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13061
13062 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13063 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13064 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13065 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13066 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13067 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13068
13069 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13070 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13071 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13072 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13073 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13074 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13075
13076 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13077 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13078 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13079 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13080 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13081 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013082
13083#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013084 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13085 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013086#endif
paul718e3742002-12-13 20:15:29 +000013087}
Chris Caputo228da422009-07-18 05:44:03 +000013088
13089void
13090bgp_route_finish (void)
13091{
13092 bgp_table_unlock (bgp_distance_table);
13093 bgp_distance_table = NULL;
13094}