blob: f80bcfa97912c464d2e3485f44650123d5a3d7b0 [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{
325 u_int32_t new_pref;
326 u_int32_t exist_pref;
327 u_int32_t new_med;
328 u_int32_t exist_med;
Paul Jakmafb982c22007-05-04 20:15:47 +0000329 u_int32_t new_weight = 0;
330 u_int32_t exist_weight = 0;
paul718e3742002-12-13 20:15:29 +0000331 struct in_addr new_id;
332 struct in_addr exist_id;
333 int new_cluster;
334 int exist_cluster;
335 int internal_as_route = 0;
336 int confed_as_route = 0;
337 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700338 uint32_t newm, existm;
339
340 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000341
342 /* 0. Null check. */
343 if (new == NULL)
344 return 0;
345 if (exist == NULL)
346 return 1;
347
348 /* 1. Weight check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000349 if (new->attr->extra)
350 new_weight = new->attr->extra->weight;
351 if (exist->attr->extra)
352 exist_weight = exist->attr->extra->weight;
353 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000354 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000355 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000356 return 0;
357
358 /* 2. Local preference check. */
359 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
360 new_pref = new->attr->local_pref;
361 else
362 new_pref = bgp->default_local_pref;
363
364 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
365 exist_pref = exist->attr->local_pref;
366 else
367 exist_pref = bgp->default_local_pref;
368
369 if (new_pref > exist_pref)
370 return 1;
371 if (new_pref < exist_pref)
372 return 0;
373
374 /* 3. Local route check. */
375 if (new->sub_type == BGP_ROUTE_STATIC)
376 return 1;
377 if (exist->sub_type == BGP_ROUTE_STATIC)
378 return 0;
379
380 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
381 return 1;
382 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
383 return 0;
384
385 if (new->sub_type == BGP_ROUTE_AGGREGATE)
386 return 1;
387 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
388 return 0;
389
390 /* 4. AS path length check. */
391 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
392 {
paulfe69a502005-09-10 16:55:02 +0000393 int exist_hops = aspath_count_hops (exist->attr->aspath);
394 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
395
hasso68118452005-04-08 15:40:36 +0000396 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
397 {
paulfe69a502005-09-10 16:55:02 +0000398 int aspath_hops;
399
400 aspath_hops = aspath_count_hops (new->attr->aspath);
401 aspath_hops += aspath_count_confeds (new->attr->aspath);
402
403 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000404 return 1;
paulfe69a502005-09-10 16:55:02 +0000405 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000406 return 0;
407 }
408 else
409 {
paulfe69a502005-09-10 16:55:02 +0000410 int newhops = aspath_count_hops (new->attr->aspath);
411
412 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000413 return 1;
paulfe69a502005-09-10 16:55:02 +0000414 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000415 return 0;
416 }
paul718e3742002-12-13 20:15:29 +0000417 }
418
419 /* 5. Origin check. */
420 if (new->attr->origin < exist->attr->origin)
421 return 1;
422 if (new->attr->origin > exist->attr->origin)
423 return 0;
424
425 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000426 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
427 && aspath_count_hops (exist->attr->aspath) == 0);
428 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
429 && aspath_count_confeds (exist->attr->aspath) > 0
430 && aspath_count_hops (new->attr->aspath) == 0
431 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000432
433 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
434 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
435 && confed_as_route)
436 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
437 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
438 || internal_as_route)
439 {
440 new_med = bgp_med_value (new->attr, bgp);
441 exist_med = bgp_med_value (exist->attr, bgp);
442
443 if (new_med < exist_med)
444 return 1;
445 if (new_med > exist_med)
446 return 0;
447 }
448
449 /* 7. Peer type check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000450 if (new->peer->sort == BGP_PEER_EBGP
451 && exist->peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000452 return 1;
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000453 if (new->peer->sort == BGP_PEER_EBGP
454 && exist->peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000455 return 1;
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000456 if (new->peer->sort == BGP_PEER_IBGP
457 && exist->peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000458 return 0;
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000459 if (new->peer->sort == BGP_PEER_CONFED
460 && exist->peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000461 return 0;
462
463 /* 8. IGP metric check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700464 newm = (new->extra ? new->extra->igpmetric : 0);
465 existm = (exist->extra ? exist->extra->igpmetric : 0);
466 if (newm < existm)
467 ret = 1;
468 if (newm > existm)
469 ret = 0;
paul718e3742002-12-13 20:15:29 +0000470
471 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700472 if (newm == existm)
473 {
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000474 if (new->peer->sort == BGP_PEER_IBGP)
Josh Bailey96450fa2011-07-20 20:45:12 -0700475 {
476 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
477 *paths_eq = 1;
478 }
479 else if (new->peer->as == exist->peer->as)
480 *paths_eq = 1;
481 }
482 else
483 {
484 /*
485 * TODO: If unequal cost ibgp multipath is enabled we can
486 * mark the paths as equal here instead of returning
487 */
488 return ret;
489 }
paul718e3742002-12-13 20:15:29 +0000490
491 /* 10. If both paths are external, prefer the path that was received
492 first (the oldest one). This step minimizes route-flap, since a
493 newer path won't displace an older one, even if it was the
494 preferred route based on the additional decision criteria below. */
495 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000496 && new->peer->sort == BGP_PEER_EBGP
497 && exist->peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +0000498 {
499 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
500 return 1;
501 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
502 return 0;
503 }
504
505 /* 11. Rourter-ID comparision. */
506 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000507 new_id.s_addr = new->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000508 else
509 new_id.s_addr = new->peer->remote_id.s_addr;
510 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000511 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000512 else
513 exist_id.s_addr = exist->peer->remote_id.s_addr;
514
515 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
516 return 1;
517 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
518 return 0;
519
520 /* 12. Cluster length comparision. */
521 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000522 new_cluster = new->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000523 else
524 new_cluster = 0;
525 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000526 exist_cluster = exist->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000527 else
528 exist_cluster = 0;
529
530 if (new_cluster < exist_cluster)
531 return 1;
532 if (new_cluster > exist_cluster)
533 return 0;
534
535 /* 13. Neighbor address comparision. */
536 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
537
538 if (ret == 1)
539 return 0;
540 if (ret == -1)
541 return 1;
542
543 return 1;
544}
545
paul94f2b392005-06-28 12:44:16 +0000546static enum filter_type
paul718e3742002-12-13 20:15:29 +0000547bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
548 afi_t afi, safi_t safi)
549{
550 struct bgp_filter *filter;
551
552 filter = &peer->filter[afi][safi];
553
Paul Jakma650f76c2009-06-25 18:06:31 +0100554#define FILTER_EXIST_WARN(F,f,filter) \
555 if (BGP_DEBUG (update, UPDATE_IN) \
556 && !(F ## _IN (filter))) \
557 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
558 peer->host, #f, F ## _IN_NAME(filter));
559
560 if (DISTRIBUTE_IN_NAME (filter)) {
561 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
562
paul718e3742002-12-13 20:15:29 +0000563 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
564 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100565 }
paul718e3742002-12-13 20:15:29 +0000566
Paul Jakma650f76c2009-06-25 18:06:31 +0100567 if (PREFIX_LIST_IN_NAME (filter)) {
568 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
569
paul718e3742002-12-13 20:15:29 +0000570 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
571 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100572 }
paul718e3742002-12-13 20:15:29 +0000573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574 if (FILTER_LIST_IN_NAME (filter)) {
575 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
576
paul718e3742002-12-13 20:15:29 +0000577 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
578 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100579 }
580
paul718e3742002-12-13 20:15:29 +0000581 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100582#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000583}
584
paul94f2b392005-06-28 12:44:16 +0000585static enum filter_type
paul718e3742002-12-13 20:15:29 +0000586bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
587 afi_t afi, safi_t safi)
588{
589 struct bgp_filter *filter;
590
591 filter = &peer->filter[afi][safi];
592
Paul Jakma650f76c2009-06-25 18:06:31 +0100593#define FILTER_EXIST_WARN(F,f,filter) \
594 if (BGP_DEBUG (update, UPDATE_OUT) \
595 && !(F ## _OUT (filter))) \
596 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
597 peer->host, #f, F ## _OUT_NAME(filter));
598
599 if (DISTRIBUTE_OUT_NAME (filter)) {
600 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
601
paul718e3742002-12-13 20:15:29 +0000602 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
603 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100604 }
paul718e3742002-12-13 20:15:29 +0000605
Paul Jakma650f76c2009-06-25 18:06:31 +0100606 if (PREFIX_LIST_OUT_NAME (filter)) {
607 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
608
paul718e3742002-12-13 20:15:29 +0000609 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
610 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 }
paul718e3742002-12-13 20:15:29 +0000612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613 if (FILTER_LIST_OUT_NAME (filter)) {
614 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
615
paul718e3742002-12-13 20:15:29 +0000616 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
617 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100618 }
paul718e3742002-12-13 20:15:29 +0000619
620 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100621#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000622}
623
624/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000625static int
paul718e3742002-12-13 20:15:29 +0000626bgp_community_filter (struct peer *peer, struct attr *attr)
627{
628 if (attr->community)
629 {
630 /* NO_ADVERTISE check. */
631 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
632 return 1;
633
634 /* NO_EXPORT check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000635 if (peer->sort == BGP_PEER_EBGP &&
paul718e3742002-12-13 20:15:29 +0000636 community_include (attr->community, COMMUNITY_NO_EXPORT))
637 return 1;
638
639 /* NO_EXPORT_SUBCONFED check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000640 if (peer->sort == BGP_PEER_EBGP
641 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000642 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
643 return 1;
644 }
645 return 0;
646}
647
648/* Route reflection loop check. */
649static int
650bgp_cluster_filter (struct peer *peer, struct attr *attr)
651{
652 struct in_addr cluster_id;
653
Paul Jakmafb982c22007-05-04 20:15:47 +0000654 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000655 {
656 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
657 cluster_id = peer->bgp->cluster_id;
658 else
659 cluster_id = peer->bgp->router_id;
660
Paul Jakmafb982c22007-05-04 20:15:47 +0000661 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000662 return 1;
663 }
664 return 0;
665}
666
paul94f2b392005-06-28 12:44:16 +0000667static int
paul718e3742002-12-13 20:15:29 +0000668bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
669 afi_t afi, safi_t safi)
670{
671 struct bgp_filter *filter;
672 struct bgp_info info;
673 route_map_result_t ret;
674
675 filter = &peer->filter[afi][safi];
676
677 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000678 if (peer->weight)
679 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000680
681 /* Route map apply. */
682 if (ROUTE_MAP_IN_NAME (filter))
683 {
684 /* Duplicate current value to new strucutre for modification. */
685 info.peer = peer;
686 info.attr = attr;
687
paulac41b2a2003-08-12 05:32:27 +0000688 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
689
paul718e3742002-12-13 20:15:29 +0000690 /* Apply BGP route map to the attribute. */
691 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000692
693 peer->rmap_type = 0;
694
paul718e3742002-12-13 20:15:29 +0000695 if (ret == RMAP_DENYMATCH)
696 {
697 /* Free newly generated AS path and community by route-map. */
698 bgp_attr_flush (attr);
699 return RMAP_DENY;
700 }
701 }
702 return RMAP_PERMIT;
703}
704
paul94f2b392005-06-28 12:44:16 +0000705static int
paulfee0f4c2004-09-13 05:12:46 +0000706bgp_export_modifier (struct peer *rsclient, struct peer *peer,
707 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
708{
709 struct bgp_filter *filter;
710 struct bgp_info info;
711 route_map_result_t ret;
712
713 filter = &peer->filter[afi][safi];
714
715 /* Route map apply. */
716 if (ROUTE_MAP_EXPORT_NAME (filter))
717 {
718 /* Duplicate current value to new strucutre for modification. */
719 info.peer = rsclient;
720 info.attr = attr;
721
722 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
723
724 /* Apply BGP route map to the attribute. */
725 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
726
727 rsclient->rmap_type = 0;
728
729 if (ret == RMAP_DENYMATCH)
730 {
731 /* Free newly generated AS path and community by route-map. */
732 bgp_attr_flush (attr);
733 return RMAP_DENY;
734 }
735 }
736 return RMAP_PERMIT;
737}
738
paul94f2b392005-06-28 12:44:16 +0000739static int
paulfee0f4c2004-09-13 05:12:46 +0000740bgp_import_modifier (struct peer *rsclient, struct peer *peer,
741 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
742{
743 struct bgp_filter *filter;
744 struct bgp_info info;
745 route_map_result_t ret;
746
747 filter = &rsclient->filter[afi][safi];
748
749 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000750 if (peer->weight)
751 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000752
753 /* Route map apply. */
754 if (ROUTE_MAP_IMPORT_NAME (filter))
755 {
756 /* Duplicate current value to new strucutre for modification. */
757 info.peer = peer;
758 info.attr = attr;
759
760 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
761
762 /* Apply BGP route map to the attribute. */
763 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
764
765 peer->rmap_type = 0;
766
767 if (ret == RMAP_DENYMATCH)
768 {
769 /* Free newly generated AS path and community by route-map. */
770 bgp_attr_flush (attr);
771 return RMAP_DENY;
772 }
773 }
774 return RMAP_PERMIT;
775}
776
paul94f2b392005-06-28 12:44:16 +0000777static int
paul718e3742002-12-13 20:15:29 +0000778bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
779 struct attr *attr, afi_t afi, safi_t safi)
780{
781 int ret;
782 char buf[SU_ADDRSTRLEN];
783 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000784 struct peer *from;
785 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000786 int transparent;
787 int reflect;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700788 struct attr *riattr;
paul718e3742002-12-13 20:15:29 +0000789
790 from = ri->peer;
791 filter = &peer->filter[afi][safi];
792 bgp = peer->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -0700793 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paul718e3742002-12-13 20:15:29 +0000794
Paul Jakma750e8142008-07-22 21:11:48 +0000795 if (DISABLE_BGP_ANNOUNCE)
796 return 0;
paul718e3742002-12-13 20:15:29 +0000797
paulfee0f4c2004-09-13 05:12:46 +0000798 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
799 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
800 return 0;
801
paul718e3742002-12-13 20:15:29 +0000802 /* Do not send back route to sender. */
803 if (from == peer)
804 return 0;
805
paul35be31b2004-05-01 18:17:04 +0000806 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
807 if (p->family == AF_INET
Josh Bailey0b597ef2011-07-20 20:49:11 -0700808 && IPV4_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000809 return 0;
810#ifdef HAVE_IPV6
811 if (p->family == AF_INET6
Josh Bailey0b597ef2011-07-20 20:49:11 -0700812 && IPV6_ADDR_SAME(&peer->remote_id, &riattr->nexthop))
paul35be31b2004-05-01 18:17:04 +0000813 return 0;
814#endif
815
paul718e3742002-12-13 20:15:29 +0000816 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000817 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000818 if (! UNSUPPRESS_MAP_NAME (filter))
819 return 0;
820
821 /* Default route check. */
822 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
823 {
824 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
825 return 0;
826#ifdef HAVE_IPV6
827 else if (p->family == AF_INET6 && p->prefixlen == 0)
828 return 0;
829#endif /* HAVE_IPV6 */
830 }
831
paul286e1e72003-08-08 00:24:31 +0000832 /* Transparency check. */
833 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
834 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
835 transparent = 1;
836 else
837 transparent = 0;
838
paul718e3742002-12-13 20:15:29 +0000839 /* If community is not disabled check the no-export and local. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700840 if (! transparent && bgp_community_filter (peer, riattr))
paul718e3742002-12-13 20:15:29 +0000841 return 0;
842
843 /* If the attribute has originator-id and it is same as remote
844 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700845 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paul718e3742002-12-13 20:15:29 +0000846 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700847 if (IPV4_ADDR_SAME (&peer->remote_id, &riattr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000848 {
849 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000850 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000851 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
852 peer->host,
853 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
854 p->prefixlen);
855 return 0;
856 }
857 }
858
859 /* ORF prefix-list filter check */
860 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
861 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
862 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
863 if (peer->orf_plist[afi][safi])
864 {
865 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
866 return 0;
867 }
868
869 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700870 if (bgp_output_filter (peer, p, riattr, afi, safi) == FILTER_DENY)
paul718e3742002-12-13 20:15:29 +0000871 {
872 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000873 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000874 "%s [Update:SEND] %s/%d is filtered",
875 peer->host,
876 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
877 p->prefixlen);
878 return 0;
879 }
880
881#ifdef BGP_SEND_ASPATH_CHECK
882 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700883 if (aspath_loop_check (riattr->aspath, peer->as))
paul718e3742002-12-13 20:15:29 +0000884 {
885 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000886 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400887 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000888 peer->host, peer->as);
889 return 0;
890 }
891#endif /* BGP_SEND_ASPATH_CHECK */
892
893 /* If we're a CONFED we need to loop check the CONFED ID too */
894 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
895 {
Josh Bailey0b597ef2011-07-20 20:49:11 -0700896 if (aspath_loop_check(riattr->aspath, bgp->confed_id))
paul718e3742002-12-13 20:15:29 +0000897 {
898 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000899 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400900 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000901 peer->host,
902 bgp->confed_id);
903 return 0;
904 }
905 }
906
907 /* Route-Reflect check. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000908 if (from->sort == BGP_PEER_IBGP && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +0000909 reflect = 1;
910 else
911 reflect = 0;
912
913 /* IBGP reflection check. */
914 if (reflect)
915 {
916 /* A route from a Client peer. */
917 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
918 {
919 /* Reflect to all the Non-Client peers and also to the
920 Client peers other than the originator. Originator check
921 is already done. So there is noting to do. */
922 /* no bgp client-to-client reflection check. */
923 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
924 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
925 return 0;
926 }
927 else
928 {
929 /* A route from a Non-client peer. Reflect to all other
930 clients. */
931 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
932 return 0;
933 }
934 }
Paul Jakma41367172007-08-06 15:24:51 +0000935
paul718e3742002-12-13 20:15:29 +0000936 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -0700937 bgp_attr_dup (attr, riattr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000938
paul718e3742002-12-13 20:15:29 +0000939 /* If local-preference is not set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000940 if ((peer->sort == BGP_PEER_IBGP
941 || peer->sort == BGP_PEER_CONFED)
paul718e3742002-12-13 20:15:29 +0000942 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
943 {
944 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
945 attr->local_pref = bgp->default_local_pref;
946 }
947
paul718e3742002-12-13 20:15:29 +0000948 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000949 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000950 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
951 {
952 if (ri->peer != bgp->peer_self && ! transparent
953 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
954 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
955 }
956
957 /* next-hop-set */
958 if (transparent || reflect
959 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
960 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000961#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000962 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000963 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000964#endif /* HAVE_IPV6 */
965 )))
paul718e3742002-12-13 20:15:29 +0000966 {
967 /* NEXT-HOP Unchanged. */
968 }
969 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
970 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
971#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000972 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000973 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000974#endif /* HAVE_IPV6 */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +0000975 || (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +0000976 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
977 {
978 /* Set IPv4 nexthop. */
979 if (p->family == AF_INET)
980 {
981 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000982 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
983 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000984 else
985 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
986 }
987#ifdef HAVE_IPV6
988 /* Set IPv6 nexthop. */
989 if (p->family == AF_INET6)
990 {
991 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000992 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000993 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000994 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000995 }
996#endif /* HAVE_IPV6 */
997 }
998
999#ifdef HAVE_IPV6
1000 if (p->family == AF_INET6)
1001 {
paulfee0f4c2004-09-13 05:12:46 +00001002 /* Left nexthop_local unchanged if so configured. */
1003 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1004 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1005 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001006 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1007 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001008 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001009 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001010 }
1011
1012 /* Default nexthop_local treatment for non-RS-Clients */
1013 else
1014 {
paul718e3742002-12-13 20:15:29 +00001015 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001016 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001017
1018 /* Set link-local address for shared network peer. */
1019 if (peer->shared_network
1020 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1021 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001022 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001023 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001024 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001025 }
1026
1027 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1028 address.*/
1029 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001030 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001031
1032 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1033 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001034 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001035 }
paulfee0f4c2004-09-13 05:12:46 +00001036
1037 }
paul718e3742002-12-13 20:15:29 +00001038#endif /* HAVE_IPV6 */
1039
1040 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001041 if (peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00001042 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1043 && aspath_private_as_check (attr->aspath))
1044 attr->aspath = aspath_empty_get ();
1045
1046 /* Route map & unsuppress-map apply. */
1047 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001048 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001049 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001050 struct bgp_info info;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001051 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001052
paul718e3742002-12-13 20:15:29 +00001053 info.peer = peer;
1054 info.attr = attr;
1055
1056 /* The route reflector is not allowed to modify the attributes
1057 of the reflected IBGP routes. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001058 if (from->sort == BGP_PEER_IBGP
1059 && peer->sort == BGP_PEER_IBGP)
paul718e3742002-12-13 20:15:29 +00001060 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001061 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001062 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001063 }
paulac41b2a2003-08-12 05:32:27 +00001064
1065 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1066
Paul Jakmafb982c22007-05-04 20:15:47 +00001067 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001068 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1069 else
1070 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1071
paulac41b2a2003-08-12 05:32:27 +00001072 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001073
Paul Jakma9eda90c2007-08-30 13:36:17 +00001074 if (dummy_attr.extra)
1075 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001076
paul718e3742002-12-13 20:15:29 +00001077 if (ret == RMAP_DENYMATCH)
1078 {
1079 bgp_attr_flush (attr);
1080 return 0;
1081 }
1082 }
1083 return 1;
1084}
1085
paul94f2b392005-06-28 12:44:16 +00001086static int
paulfee0f4c2004-09-13 05:12:46 +00001087bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1088 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001089{
paulfee0f4c2004-09-13 05:12:46 +00001090 int ret;
1091 char buf[SU_ADDRSTRLEN];
1092 struct bgp_filter *filter;
1093 struct bgp_info info;
1094 struct peer *from;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001095 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001096
1097 from = ri->peer;
1098 filter = &rsclient->filter[afi][safi];
Josh Bailey0b597ef2011-07-20 20:49:11 -07001099 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001100
Paul Jakma750e8142008-07-22 21:11:48 +00001101 if (DISABLE_BGP_ANNOUNCE)
1102 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001103
1104 /* Do not send back route to sender. */
1105 if (from == rsclient)
1106 return 0;
1107
1108 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001109 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001110 if (! UNSUPPRESS_MAP_NAME (filter))
1111 return 0;
1112
1113 /* Default route check. */
1114 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1115 PEER_STATUS_DEFAULT_ORIGINATE))
1116 {
1117 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1118 return 0;
1119#ifdef HAVE_IPV6
1120 else if (p->family == AF_INET6 && p->prefixlen == 0)
1121 return 0;
1122#endif /* HAVE_IPV6 */
1123 }
1124
1125 /* If the attribute has originator-id and it is same as remote
1126 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001127 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001128 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001129 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001130 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001131 {
1132 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001133 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001134 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1135 rsclient->host,
1136 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1137 p->prefixlen);
1138 return 0;
1139 }
1140 }
1141
1142 /* ORF prefix-list filter check */
1143 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1144 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1145 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1146 if (rsclient->orf_plist[afi][safi])
1147 {
1148 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1149 return 0;
1150 }
1151
1152 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001153 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001154 {
1155 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001156 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001157 "%s [Update:SEND] %s/%d is filtered",
1158 rsclient->host,
1159 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1160 p->prefixlen);
1161 return 0;
1162 }
1163
1164#ifdef BGP_SEND_ASPATH_CHECK
1165 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001166 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001167 {
1168 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001169 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001170 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001171 rsclient->host, rsclient->as);
1172 return 0;
1173 }
1174#endif /* BGP_SEND_ASPATH_CHECK */
1175
1176 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001177 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001178
1179 /* next-hop-set */
1180 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1181#ifdef HAVE_IPV6
1182 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001183 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001184#endif /* HAVE_IPV6 */
1185 )
1186 {
1187 /* Set IPv4 nexthop. */
1188 if (p->family == AF_INET)
1189 {
1190 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001191 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001192 IPV4_MAX_BYTELEN);
1193 else
1194 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1195 }
1196#ifdef HAVE_IPV6
1197 /* Set IPv6 nexthop. */
1198 if (p->family == AF_INET6)
1199 {
1200 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001201 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001202 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001203 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001204 }
1205#endif /* HAVE_IPV6 */
1206 }
1207
1208#ifdef HAVE_IPV6
1209 if (p->family == AF_INET6)
1210 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001211 struct attr_extra *attre = attr->extra;
1212
1213 assert (attr->extra);
1214
paulfee0f4c2004-09-13 05:12:46 +00001215 /* Left nexthop_local unchanged if so configured. */
1216 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1217 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1218 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1220 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001221 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001222 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001223 }
1224
1225 /* Default nexthop_local treatment for RS-Clients */
1226 else
1227 {
1228 /* Announcer and RS-Client are both in the same network */
1229 if (rsclient->shared_network && from->shared_network &&
1230 (rsclient->ifindex == from->ifindex))
1231 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001232 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1233 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001234 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001235 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001236 }
1237
1238 /* Set link-local address for shared network peer. */
1239 else if (rsclient->shared_network
1240 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1241 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001242 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001243 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001245 }
1246
1247 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001248 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001249 }
1250
1251 }
1252#endif /* HAVE_IPV6 */
1253
1254
1255 /* If this is EBGP peer and remove-private-AS is set. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001256 if (rsclient->sort == BGP_PEER_EBGP
paulfee0f4c2004-09-13 05:12:46 +00001257 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1258 && aspath_private_as_check (attr->aspath))
1259 attr->aspath = aspath_empty_get ();
1260
1261 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001262 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001263 {
1264 info.peer = rsclient;
1265 info.attr = attr;
1266
1267 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1268
Paul Jakmafb982c22007-05-04 20:15:47 +00001269 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001270 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1271 else
1272 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1273
1274 rsclient->rmap_type = 0;
1275
1276 if (ret == RMAP_DENYMATCH)
1277 {
1278 bgp_attr_flush (attr);
1279 return 0;
1280 }
1281 }
1282
1283 return 1;
1284}
1285
1286struct bgp_info_pair
1287{
1288 struct bgp_info *old;
1289 struct bgp_info *new;
1290};
1291
paul94f2b392005-06-28 12:44:16 +00001292static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001293bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1294 struct bgp_maxpaths_cfg *mpath_cfg,
1295 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001296{
paul718e3742002-12-13 20:15:29 +00001297 struct bgp_info *new_select;
1298 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001299 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001300 struct bgp_info *ri1;
1301 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001302 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001303 int paths_eq, do_mpath;
1304 struct list mp_list;
1305
1306 bgp_mp_list_init (&mp_list);
1307 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1308 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1309
paul718e3742002-12-13 20:15:29 +00001310 /* bgp deterministic-med */
1311 new_select = NULL;
1312 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1313 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1314 {
1315 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1316 continue;
1317 if (BGP_INFO_HOLDDOWN (ri1))
1318 continue;
1319
1320 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001321 if (do_mpath)
1322 bgp_mp_list_add (&mp_list, ri1);
1323 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001324 if (ri1->next)
1325 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1326 {
1327 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1328 continue;
1329 if (BGP_INFO_HOLDDOWN (ri2))
1330 continue;
1331
1332 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1333 || aspath_cmp_left_confed (ri1->attr->aspath,
1334 ri2->attr->aspath))
1335 {
Josh Bailey6918e742011-07-20 20:48:20 -07001336 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1337 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001338 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001339 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001340 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001341 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001342 if (do_mpath && !paths_eq)
1343 {
1344 bgp_mp_list_clear (&mp_list);
1345 bgp_mp_list_add (&mp_list, ri2);
1346 }
paul718e3742002-12-13 20:15:29 +00001347 }
1348
Josh Bailey6918e742011-07-20 20:48:20 -07001349 if (do_mpath && paths_eq)
1350 bgp_mp_list_add (&mp_list, ri2);
1351
Paul Jakma1a392d42006-09-07 00:24:49 +00001352 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001353 }
1354 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001355 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1356 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001357
1358 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1359 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001360 }
1361
1362 /* Check old selected route and new selected route. */
1363 old_select = NULL;
1364 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001365 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001366 {
1367 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1368 old_select = ri;
1369
1370 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001371 {
1372 /* reap REMOVED routes, if needs be
1373 * selected route must stay for a while longer though
1374 */
1375 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1376 && (ri != old_select))
1377 bgp_info_reap (rn, ri);
1378
1379 continue;
1380 }
paul718e3742002-12-13 20:15:29 +00001381
1382 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1383 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1384 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001385 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001386 continue;
1387 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001388 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1389 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001390
Josh Bailey96450fa2011-07-20 20:45:12 -07001391 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1392 {
Josh Bailey6918e742011-07-20 20:48:20 -07001393 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1394 bgp_mp_dmed_deselect (new_select);
1395
Josh Bailey96450fa2011-07-20 20:45:12 -07001396 new_select = ri;
1397
1398 if (do_mpath && !paths_eq)
1399 {
1400 bgp_mp_list_clear (&mp_list);
1401 bgp_mp_list_add (&mp_list, ri);
1402 }
1403 }
Josh Bailey6918e742011-07-20 20:48:20 -07001404 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1405 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001406
1407 if (do_mpath && paths_eq)
1408 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001409 }
paulb40d9392005-08-22 22:34:41 +00001410
paulfee0f4c2004-09-13 05:12:46 +00001411
Josh Bailey6918e742011-07-20 20:48:20 -07001412 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1413 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001414
Josh Bailey0b597ef2011-07-20 20:49:11 -07001415 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001416 bgp_mp_list_clear (&mp_list);
1417
1418 result->old = old_select;
1419 result->new = new_select;
1420
1421 return;
paulfee0f4c2004-09-13 05:12:46 +00001422}
1423
paul94f2b392005-06-28 12:44:16 +00001424static int
paulfee0f4c2004-09-13 05:12:46 +00001425bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001426 struct bgp_node *rn, afi_t afi, safi_t safi)
1427{
paulfee0f4c2004-09-13 05:12:46 +00001428 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001429 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001430
1431 p = &rn->p;
1432
Paul Jakma9eda90c2007-08-30 13:36:17 +00001433 /* Announce route to Established peer. */
1434 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001435 return 0;
1436
Paul Jakma9eda90c2007-08-30 13:36:17 +00001437 /* Address family configuration check. */
1438 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001439 return 0;
1440
Paul Jakma9eda90c2007-08-30 13:36:17 +00001441 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001442 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1443 PEER_STATUS_ORF_WAIT_REFRESH))
1444 return 0;
1445
1446 switch (rn->table->type)
1447 {
1448 case BGP_TABLE_MAIN:
1449 /* Announcement to peer->conf. If the route is filtered,
1450 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001451 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1452 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001453 else
1454 bgp_adj_out_unset (rn, peer, p, afi, safi);
1455 break;
1456 case BGP_TABLE_RSCLIENT:
1457 /* Announcement to peer->conf. If the route is filtered,
1458 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001459 if (selected &&
1460 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1461 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1462 else
1463 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001464 break;
1465 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001466
1467 bgp_attr_extra_free (&attr);
1468
paulfee0f4c2004-09-13 05:12:46 +00001469 return 0;
paul200df112005-06-01 11:17:05 +00001470}
paulfee0f4c2004-09-13 05:12:46 +00001471
paul200df112005-06-01 11:17:05 +00001472struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001473{
paul200df112005-06-01 11:17:05 +00001474 struct bgp *bgp;
1475 struct bgp_node *rn;
1476 afi_t afi;
1477 safi_t safi;
1478};
1479
1480static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001481bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001482{
paul0fb58d52005-11-14 14:31:49 +00001483 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001484 struct bgp *bgp = pq->bgp;
1485 struct bgp_node *rn = pq->rn;
1486 afi_t afi = pq->afi;
1487 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001488 struct bgp_info *new_select;
1489 struct bgp_info *old_select;
1490 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001491 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001492 struct peer *rsclient = rn->table->owner;
1493
paulfee0f4c2004-09-13 05:12:46 +00001494 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001495 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001496 new_select = old_and_new.new;
1497 old_select = old_and_new.old;
1498
paul200df112005-06-01 11:17:05 +00001499 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1500 {
Chris Caputo228da422009-07-18 05:44:03 +00001501 if (rsclient->group)
1502 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1503 {
1504 /* Nothing to do. */
1505 if (old_select && old_select == new_select)
1506 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1507 continue;
paulfee0f4c2004-09-13 05:12:46 +00001508
Chris Caputo228da422009-07-18 05:44:03 +00001509 if (old_select)
1510 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1511 if (new_select)
1512 {
1513 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1514 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001515 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1516 }
paulfee0f4c2004-09-13 05:12:46 +00001517
Chris Caputo228da422009-07-18 05:44:03 +00001518 bgp_process_announce_selected (rsclient, new_select, rn,
1519 afi, safi);
1520 }
paul200df112005-06-01 11:17:05 +00001521 }
1522 else
1523 {
hassob7395792005-08-26 12:58:38 +00001524 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001525 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001526 if (new_select)
1527 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001528 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1529 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001530 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001531 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001532 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001533 }
paulfee0f4c2004-09-13 05:12:46 +00001534
paulb40d9392005-08-22 22:34:41 +00001535 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1536 bgp_info_reap (rn, old_select);
1537
paul200df112005-06-01 11:17:05 +00001538 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1539 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001540}
1541
paul200df112005-06-01 11:17:05 +00001542static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001543bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001544{
paul0fb58d52005-11-14 14:31:49 +00001545 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001546 struct bgp *bgp = pq->bgp;
1547 struct bgp_node *rn = pq->rn;
1548 afi_t afi = pq->afi;
1549 safi_t safi = pq->safi;
1550 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001551 struct bgp_info *new_select;
1552 struct bgp_info *old_select;
1553 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001554 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001555 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001556
paulfee0f4c2004-09-13 05:12:46 +00001557 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001558 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001559 old_select = old_and_new.old;
1560 new_select = old_and_new.new;
1561
1562 /* Nothing to do. */
1563 if (old_select && old_select == new_select)
1564 {
1565 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001566 {
Josh Bailey8196f132011-07-20 20:47:07 -07001567 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1568 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
G.Balaji5a616c02011-11-26 21:58:42 +04001569 bgp_zebra_announce (p, old_select, bgp, safi);
paul200df112005-06-01 11:17:05 +00001570
Josh Bailey8196f132011-07-20 20:47:07 -07001571 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001572 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1573 return WQ_SUCCESS;
1574 }
paulfee0f4c2004-09-13 05:12:46 +00001575 }
paul718e3742002-12-13 20:15:29 +00001576
hasso338b3422005-02-23 14:27:24 +00001577 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001578 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001579 if (new_select)
1580 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001581 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1582 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001583 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001584 }
1585
1586
paul718e3742002-12-13 20:15:29 +00001587 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001588 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001589 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001590 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001591 }
1592
1593 /* FIB update. */
G.Balaji5a616c02011-11-26 21:58:42 +04001594 if ((safi == SAFI_UNICAST || safi == SAFI_MULTICAST) && (! bgp->name &&
1595 ! bgp_option_check (BGP_OPT_NO_FIB)))
paul718e3742002-12-13 20:15:29 +00001596 {
1597 if (new_select
1598 && new_select->type == ZEBRA_ROUTE_BGP
1599 && new_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001600 bgp_zebra_announce (p, new_select, bgp, safi);
paul718e3742002-12-13 20:15:29 +00001601 else
1602 {
1603 /* Withdraw the route from the kernel. */
1604 if (old_select
1605 && old_select->type == ZEBRA_ROUTE_BGP
1606 && old_select->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04001607 bgp_zebra_withdraw (p, old_select, safi);
paul718e3742002-12-13 20:15:29 +00001608 }
1609 }
paulb40d9392005-08-22 22:34:41 +00001610
1611 /* Reap old select bgp_info, it it has been removed */
1612 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1613 bgp_info_reap (rn, old_select);
1614
paul200df112005-06-01 11:17:05 +00001615 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1616 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001617}
1618
paul200df112005-06-01 11:17:05 +00001619static void
paul0fb58d52005-11-14 14:31:49 +00001620bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001621{
paul0fb58d52005-11-14 14:31:49 +00001622 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001623 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001624
Chris Caputo228da422009-07-18 05:44:03 +00001625 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001626 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001627 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001628 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1629}
1630
1631static void
1632bgp_process_queue_init (void)
1633{
1634 bm->process_main_queue
1635 = work_queue_new (bm->master, "process_main_queue");
1636 bm->process_rsclient_queue
1637 = work_queue_new (bm->master, "process_rsclient_queue");
1638
1639 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1640 {
1641 zlog_err ("%s: Failed to allocate work queue", __func__);
1642 exit (1);
1643 }
1644
1645 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001646 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001647 bm->process_main_queue->spec.max_retries = 0;
1648 bm->process_main_queue->spec.hold = 50;
1649
1650 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1651 sizeof (struct work_queue *));
1652 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001653}
1654
1655void
paulfee0f4c2004-09-13 05:12:46 +00001656bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1657{
paul200df112005-06-01 11:17:05 +00001658 struct bgp_process_queue *pqnode;
1659
1660 /* already scheduled for processing? */
1661 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1662 return;
1663
1664 if ( (bm->process_main_queue == NULL) ||
1665 (bm->process_rsclient_queue == NULL) )
1666 bgp_process_queue_init ();
1667
1668 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1669 sizeof (struct bgp_process_queue));
1670 if (!pqnode)
1671 return;
Chris Caputo228da422009-07-18 05:44:03 +00001672
1673 /* all unlocked in bgp_processq_del */
1674 bgp_table_lock (rn->table);
1675 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001676 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001677 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001678 pqnode->afi = afi;
1679 pqnode->safi = safi;
1680
paulfee0f4c2004-09-13 05:12:46 +00001681 switch (rn->table->type)
1682 {
paul200df112005-06-01 11:17:05 +00001683 case BGP_TABLE_MAIN:
1684 work_queue_add (bm->process_main_queue, pqnode);
1685 break;
1686 case BGP_TABLE_RSCLIENT:
1687 work_queue_add (bm->process_rsclient_queue, pqnode);
1688 break;
paulfee0f4c2004-09-13 05:12:46 +00001689 }
paul200df112005-06-01 11:17:05 +00001690
1691 return;
paulfee0f4c2004-09-13 05:12:46 +00001692}
hasso0a486e52005-02-01 20:57:17 +00001693
paul94f2b392005-06-28 12:44:16 +00001694static int
hasso0a486e52005-02-01 20:57:17 +00001695bgp_maximum_prefix_restart_timer (struct thread *thread)
1696{
1697 struct peer *peer;
1698
1699 peer = THREAD_ARG (thread);
1700 peer->t_pmax_restart = NULL;
1701
1702 if (BGP_DEBUG (events, EVENTS))
1703 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1704 peer->host);
1705
1706 peer_clear (peer);
1707
1708 return 0;
1709}
1710
paulfee0f4c2004-09-13 05:12:46 +00001711int
paul5228ad22004-06-04 17:58:18 +00001712bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1713 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001714{
hassoe0701b72004-05-20 09:19:34 +00001715 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1716 return 0;
1717
1718 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001719 {
hassoe0701b72004-05-20 09:19:34 +00001720 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1721 && ! always)
1722 return 0;
paul718e3742002-12-13 20:15:29 +00001723
hassoe0701b72004-05-20 09:19:34 +00001724 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001725 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1726 "limit %ld", afi_safi_print (afi, safi), peer->host,
1727 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001728 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001729
hassoe0701b72004-05-20 09:19:34 +00001730 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1731 return 0;
paul718e3742002-12-13 20:15:29 +00001732
hassoe0701b72004-05-20 09:19:34 +00001733 {
paul5228ad22004-06-04 17:58:18 +00001734 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001735
1736 if (safi == SAFI_MPLS_VPN)
Denis Ovsienko42e6d742011-07-14 12:36:19 +04001737 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001738
1739 ndata[0] = (afi >> 8);
1740 ndata[1] = afi;
1741 ndata[2] = safi;
1742 ndata[3] = (peer->pmax[afi][safi] >> 24);
1743 ndata[4] = (peer->pmax[afi][safi] >> 16);
1744 ndata[5] = (peer->pmax[afi][safi] >> 8);
1745 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001746
1747 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1748 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1749 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1750 }
hasso0a486e52005-02-01 20:57:17 +00001751
1752 /* restart timer start */
1753 if (peer->pmax_restart[afi][safi])
1754 {
1755 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1756
1757 if (BGP_DEBUG (events, EVENTS))
1758 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1759 peer->host, peer->v_pmax_restart);
1760
1761 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1762 peer->v_pmax_restart);
1763 }
1764
hassoe0701b72004-05-20 09:19:34 +00001765 return 1;
paul718e3742002-12-13 20:15:29 +00001766 }
hassoe0701b72004-05-20 09:19:34 +00001767 else
1768 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1769
1770 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1771 {
1772 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1773 && ! always)
1774 return 0;
1775
1776 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001777 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1778 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1779 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001780 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1781 }
1782 else
1783 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001784 return 0;
1785}
1786
paulb40d9392005-08-22 22:34:41 +00001787/* Unconditionally remove the route from the RIB, without taking
1788 * damping into consideration (eg, because the session went down)
1789 */
paul94f2b392005-06-28 12:44:16 +00001790static void
paul718e3742002-12-13 20:15:29 +00001791bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1792 afi_t afi, safi_t safi)
1793{
paul902212c2006-02-05 17:51:19 +00001794 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1795
1796 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1797 bgp_info_delete (rn, ri); /* keep historical info */
1798
paulb40d9392005-08-22 22:34:41 +00001799 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001800}
1801
paul94f2b392005-06-28 12:44:16 +00001802static void
paul718e3742002-12-13 20:15:29 +00001803bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001804 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001805{
paul718e3742002-12-13 20:15:29 +00001806 int status = BGP_DAMP_NONE;
1807
paulb40d9392005-08-22 22:34:41 +00001808 /* apply dampening, if result is suppressed, we'll be retaining
1809 * the bgp_info in the RIB for historical reference.
1810 */
1811 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00001812 && peer->sort == BGP_PEER_EBGP)
paulb40d9392005-08-22 22:34:41 +00001813 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1814 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001815 {
paul902212c2006-02-05 17:51:19 +00001816 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1817 return;
1818 }
1819
1820 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001821}
1822
paul94f2b392005-06-28 12:44:16 +00001823static void
paulfee0f4c2004-09-13 05:12:46 +00001824bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1825 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1826 int sub_type, struct prefix_rd *prd, u_char *tag)
1827{
1828 struct bgp_node *rn;
1829 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001830 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001831 struct attr *attr_new;
1832 struct attr *attr_new2;
1833 struct bgp_info *ri;
1834 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001835 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001836 char buf[SU_ADDRSTRLEN];
1837
1838 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1839 if (peer == rsclient)
1840 return;
1841
1842 bgp = peer->bgp;
1843 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1844
1845 /* Check previously received route. */
1846 for (ri = rn->info; ri; ri = ri->next)
1847 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1848 break;
1849
1850 /* AS path loop check. */
1851 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1852 {
1853 reason = "as-path contains our own AS;";
1854 goto filtered;
1855 }
1856
1857 /* Route reflector originator ID check. */
1858 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001859 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001860 {
1861 reason = "originator is us;";
1862 goto filtered;
1863 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001864
1865 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001866
1867 /* Apply export policy. */
1868 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1869 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1870 {
1871 reason = "export-policy;";
1872 goto filtered;
1873 }
1874
1875 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001876
paulfee0f4c2004-09-13 05:12:46 +00001877 /* Apply import policy. */
1878 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1879 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001880 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001881
1882 reason = "import-policy;";
1883 goto filtered;
1884 }
1885
1886 attr_new = bgp_attr_intern (&new_attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001887 bgp_attr_unintern (&attr_new2);
paulfee0f4c2004-09-13 05:12:46 +00001888
1889 /* IPv4 unicast next hop check. */
G.Balaji5a616c02011-11-26 21:58:42 +04001890 if ((afi == AFI_IP) && ((safi == SAFI_UNICAST) || safi == SAFI_MULTICAST))
paulfee0f4c2004-09-13 05:12:46 +00001891 {
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001892 /* Next hop must not be 0.0.0.0 nor Class D/E address. */
paulfee0f4c2004-09-13 05:12:46 +00001893 if (new_attr.nexthop.s_addr == 0
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04001894 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr)))
paulfee0f4c2004-09-13 05:12:46 +00001895 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001896 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001897
1898 reason = "martian next-hop;";
1899 goto filtered;
1900 }
1901 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001902
1903 /* new_attr isn't passed to any functions after here */
1904 bgp_attr_extra_free (&new_attr);
1905
paulfee0f4c2004-09-13 05:12:46 +00001906 /* If the update is implicit withdraw. */
1907 if (ri)
1908 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001909 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001910
1911 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001912 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1913 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001914 {
1915
Paul Jakma1a392d42006-09-07 00:24:49 +00001916 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001917
1918 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001919 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001920 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1921 peer->host,
1922 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1923 p->prefixlen, rsclient->host);
1924
Chris Caputo228da422009-07-18 05:44:03 +00001925 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001926 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001927
Chris Caputo228da422009-07-18 05:44:03 +00001928 return;
paulfee0f4c2004-09-13 05:12:46 +00001929 }
1930
Paul Jakma16d2e242007-04-10 19:32:10 +00001931 /* Withdraw/Announce before we fully processed the withdraw */
1932 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1933 bgp_info_restore (rn, ri);
1934
paulfee0f4c2004-09-13 05:12:46 +00001935 /* Received Logging. */
1936 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001937 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001938 peer->host,
1939 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1940 p->prefixlen, rsclient->host);
1941
1942 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001943 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001944
1945 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00001946 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001947 ri->attr = attr_new;
1948
1949 /* Update MPLS tag. */
1950 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001951 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001952
Paul Jakma1a392d42006-09-07 00:24:49 +00001953 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001954
1955 /* Process change. */
1956 bgp_process (bgp, rn, afi, safi);
1957 bgp_unlock_node (rn);
1958
1959 return;
1960 }
1961
1962 /* Received Logging. */
1963 if (BGP_DEBUG (update, UPDATE_IN))
1964 {
ajsd2c1f162004-12-08 21:10:20 +00001965 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001966 peer->host,
1967 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1968 p->prefixlen, rsclient->host);
1969 }
1970
1971 /* Make new BGP info. */
1972 new = bgp_info_new ();
1973 new->type = type;
1974 new->sub_type = sub_type;
1975 new->peer = peer;
1976 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001977 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001978
1979 /* Update MPLS tag. */
1980 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001981 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001982
Paul Jakma1a392d42006-09-07 00:24:49 +00001983 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001984
1985 /* Register new BGP information. */
1986 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001987
1988 /* route_node_get lock */
1989 bgp_unlock_node (rn);
1990
paulfee0f4c2004-09-13 05:12:46 +00001991 /* Process change. */
1992 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001993
1994 bgp_attr_extra_free (&new_attr);
1995
paulfee0f4c2004-09-13 05:12:46 +00001996 return;
1997
1998 filtered:
1999
2000 /* This BGP update is filtered. Log the reason then update BGP entry. */
2001 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002002 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002003 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2004 peer->host,
2005 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2006 p->prefixlen, rsclient->host, reason);
2007
2008 if (ri)
paulb40d9392005-08-22 22:34:41 +00002009 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002010
2011 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002012
2013 if (new_attr.extra)
2014 bgp_attr_extra_free (&new_attr);
2015
paulfee0f4c2004-09-13 05:12:46 +00002016 return;
2017}
2018
paul94f2b392005-06-28 12:44:16 +00002019static void
paulfee0f4c2004-09-13 05:12:46 +00002020bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2021 struct peer *peer, struct prefix *p, int type, int sub_type,
2022 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002023{
paulfee0f4c2004-09-13 05:12:46 +00002024 struct bgp_node *rn;
2025 struct bgp_info *ri;
2026 char buf[SU_ADDRSTRLEN];
2027
2028 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002029 return;
paulfee0f4c2004-09-13 05:12:46 +00002030
2031 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2032
2033 /* Lookup withdrawn route. */
2034 for (ri = rn->info; ri; ri = ri->next)
2035 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2036 break;
2037
2038 /* Withdraw specified route from routing table. */
2039 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002040 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002041 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002042 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002043 "%s Can't find the route %s/%d", peer->host,
2044 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2045 p->prefixlen);
2046
2047 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002048 bgp_unlock_node (rn);
2049}
paulfee0f4c2004-09-13 05:12:46 +00002050
paul94f2b392005-06-28 12:44:16 +00002051static int
paulfee0f4c2004-09-13 05:12:46 +00002052bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002053 afi_t afi, safi_t safi, int type, int sub_type,
2054 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2055{
2056 int ret;
2057 int aspath_loop_count = 0;
2058 struct bgp_node *rn;
2059 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002060 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002061 struct attr *attr_new;
2062 struct bgp_info *ri;
2063 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002064 const char *reason;
paul718e3742002-12-13 20:15:29 +00002065 char buf[SU_ADDRSTRLEN];
2066
2067 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002068 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002069
paul718e3742002-12-13 20:15:29 +00002070 /* When peer's soft reconfiguration enabled. Record input packet in
2071 Adj-RIBs-In. */
2072 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2073 && peer != bgp->peer_self && ! soft_reconfig)
2074 bgp_adj_in_set (rn, peer, attr);
2075
2076 /* Check previously received route. */
2077 for (ri = rn->info; ri; ri = ri->next)
2078 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2079 break;
2080
2081 /* AS path local-as loop check. */
2082 if (peer->change_local_as)
2083 {
2084 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2085 aspath_loop_count = 1;
2086
2087 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2088 {
2089 reason = "as-path contains our own AS;";
2090 goto filtered;
2091 }
2092 }
2093
2094 /* AS path loop check. */
2095 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2096 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2097 && aspath_loop_check(attr->aspath, bgp->confed_id)
2098 > peer->allowas_in[afi][safi]))
2099 {
2100 reason = "as-path contains our own AS;";
2101 goto filtered;
2102 }
2103
2104 /* Route reflector originator ID check. */
2105 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002106 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002107 {
2108 reason = "originator is us;";
2109 goto filtered;
2110 }
2111
2112 /* Route reflector cluster ID check. */
2113 if (bgp_cluster_filter (peer, attr))
2114 {
2115 reason = "reflected from the same cluster;";
2116 goto filtered;
2117 }
2118
2119 /* Apply incoming filter. */
2120 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2121 {
2122 reason = "filter;";
2123 goto filtered;
2124 }
2125
2126 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002127 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002128
2129 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2130 {
2131 reason = "route-map;";
2132 goto filtered;
2133 }
2134
2135 /* IPv4 unicast next hop check. */
2136 if (afi == AFI_IP && safi == SAFI_UNICAST)
2137 {
2138 /* If the peer is EBGP and nexthop is not on connected route,
2139 discard it. */
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002140 if (peer->sort == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko8e80bdf2011-08-05 18:52:52 +04002141 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002142 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002143 {
2144 reason = "non-connected next-hop;";
2145 goto filtered;
2146 }
2147
Denis Ovsienko733cd9e2011-12-17 19:39:30 +04002148 /* Next hop must not be 0.0.0.0 nor Class D/E address. Next hop
paul718e3742002-12-13 20:15:29 +00002149 must not be my own address. */
Jorge Boncompte [DTI2]10f9bf32012-05-07 16:52:52 +00002150 if (new_attr.nexthop.s_addr == 0
2151 || IPV4_CLASS_DE (ntohl (new_attr.nexthop.s_addr))
2152 || bgp_nexthop_self (&new_attr))
paul718e3742002-12-13 20:15:29 +00002153 {
2154 reason = "martian next-hop;";
2155 goto filtered;
2156 }
2157 }
2158
2159 attr_new = bgp_attr_intern (&new_attr);
2160
2161 /* If the update is implicit withdraw. */
2162 if (ri)
2163 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002164 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002165
2166 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002167 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2168 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002169 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002170 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002171
2172 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002173 && peer->sort == BGP_PEER_EBGP
paul718e3742002-12-13 20:15:29 +00002174 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2175 {
2176 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002177 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002178 peer->host,
2179 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2180 p->prefixlen);
2181
paul902212c2006-02-05 17:51:19 +00002182 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2183 {
2184 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2185 bgp_process (bgp, rn, afi, safi);
2186 }
paul718e3742002-12-13 20:15:29 +00002187 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002188 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002189 {
2190 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002191 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002192 "%s rcvd %s/%d...duplicate ignored",
2193 peer->host,
2194 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2195 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002196
2197 /* graceful restart STALE flag unset. */
2198 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2199 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002200 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002201 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002202 }
paul718e3742002-12-13 20:15:29 +00002203 }
2204
2205 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002206 bgp_attr_unintern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002207 bgp_attr_extra_free (&new_attr);
2208
paul718e3742002-12-13 20:15:29 +00002209 return 0;
2210 }
2211
Paul Jakma16d2e242007-04-10 19:32:10 +00002212 /* Withdraw/Announce before we fully processed the withdraw */
2213 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2214 {
2215 if (BGP_DEBUG (update, UPDATE_IN))
2216 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2217 peer->host,
2218 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2219 p->prefixlen);
2220 bgp_info_restore (rn, ri);
2221 }
2222
paul718e3742002-12-13 20:15:29 +00002223 /* Received Logging. */
2224 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002225 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002226 peer->host,
2227 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2228 p->prefixlen);
2229
hasso93406d82005-02-02 14:40:33 +00002230 /* graceful restart STALE flag unset. */
2231 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002232 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002233
paul718e3742002-12-13 20:15:29 +00002234 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002235 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002236
2237 /* implicit withdraw, decrement aggregate and pcount here.
2238 * only if update is accepted, they'll increment below.
2239 */
paul902212c2006-02-05 17:51:19 +00002240 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2241
paul718e3742002-12-13 20:15:29 +00002242 /* Update bgp route dampening information. */
2243 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002244 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002245 {
2246 /* This is implicit withdraw so we should update dampening
2247 information. */
2248 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2249 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002250 }
2251
paul718e3742002-12-13 20:15:29 +00002252 /* Update to new attribute. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002253 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00002254 ri->attr = attr_new;
2255
2256 /* Update MPLS tag. */
2257 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002258 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002259
2260 /* Update bgp route dampening information. */
2261 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002262 && peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +00002263 {
2264 /* Now we do normal update dampening. */
2265 ret = bgp_damp_update (ri, rn, afi, safi);
2266 if (ret == BGP_DAMP_SUPPRESSED)
2267 {
2268 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002269 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002270 return 0;
2271 }
2272 }
2273
2274 /* Nexthop reachability check. */
2275 if ((afi == AFI_IP || afi == AFI_IP6)
2276 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002277 && (peer->sort == BGP_PEER_IBGP
2278 || peer->sort == BGP_PEER_CONFED
2279 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002280 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002281 {
2282 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002283 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002284 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002286 }
2287 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002288 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002289
2290 /* Process change. */
2291 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2292
2293 bgp_process (bgp, rn, afi, safi);
2294 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002295 bgp_attr_extra_free (&new_attr);
2296
paul718e3742002-12-13 20:15:29 +00002297 return 0;
2298 }
2299
2300 /* Received Logging. */
2301 if (BGP_DEBUG (update, UPDATE_IN))
2302 {
ajsd2c1f162004-12-08 21:10:20 +00002303 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002304 peer->host,
2305 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2306 p->prefixlen);
2307 }
2308
paul718e3742002-12-13 20:15:29 +00002309 /* Make new BGP info. */
2310 new = bgp_info_new ();
2311 new->type = type;
2312 new->sub_type = sub_type;
2313 new->peer = peer;
2314 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002315 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002316
2317 /* Update MPLS tag. */
2318 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002319 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002320
2321 /* Nexthop reachability check. */
2322 if ((afi == AFI_IP || afi == AFI_IP6)
2323 && safi == SAFI_UNICAST
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +00002324 && (peer->sort == BGP_PEER_IBGP
2325 || peer->sort == BGP_PEER_CONFED
2326 || (peer->sort == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002327 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002328 {
2329 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002330 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002331 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002332 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002333 }
2334 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002335 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002336
paul902212c2006-02-05 17:51:19 +00002337 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002338 bgp_aggregate_increment (bgp, p, new, afi, safi);
2339
2340 /* Register new BGP information. */
2341 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002342
2343 /* route_node_get lock */
2344 bgp_unlock_node (rn);
2345
Paul Jakmafb982c22007-05-04 20:15:47 +00002346 bgp_attr_extra_free (&new_attr);
2347
paul718e3742002-12-13 20:15:29 +00002348 /* If maximum prefix count is configured and current prefix
2349 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002350 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2351 return -1;
paul718e3742002-12-13 20:15:29 +00002352
2353 /* Process change. */
2354 bgp_process (bgp, rn, afi, safi);
2355
2356 return 0;
2357
2358 /* This BGP update is filtered. Log the reason then update BGP
2359 entry. */
2360 filtered:
2361 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002362 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002363 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2364 peer->host,
2365 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2366 p->prefixlen, reason);
2367
2368 if (ri)
paulb40d9392005-08-22 22:34:41 +00002369 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002370
2371 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002372
2373 bgp_attr_extra_free (&new_attr);
2374
paul718e3742002-12-13 20:15:29 +00002375 return 0;
2376}
2377
2378int
paulfee0f4c2004-09-13 05:12:46 +00002379bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2380 afi_t afi, safi_t safi, int type, int sub_type,
2381 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2382{
2383 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002384 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002385 struct bgp *bgp;
2386 int ret;
2387
2388 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2389 soft_reconfig);
2390
2391 bgp = peer->bgp;
2392
2393 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002394 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002395 {
2396 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2397 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2398 sub_type, prd, tag);
2399 }
2400
2401 return ret;
2402}
2403
2404int
paul718e3742002-12-13 20:15:29 +00002405bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002406 afi_t afi, safi_t safi, int type, int sub_type,
2407 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002408{
2409 struct bgp *bgp;
2410 char buf[SU_ADDRSTRLEN];
2411 struct bgp_node *rn;
2412 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002413 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002414 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002415
2416 bgp = peer->bgp;
2417
paulfee0f4c2004-09-13 05:12:46 +00002418 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002419 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002420 {
2421 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2422 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2423 }
2424
paul718e3742002-12-13 20:15:29 +00002425 /* Logging. */
2426 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002427 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002428 peer->host,
2429 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2430 p->prefixlen);
2431
2432 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002433 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002434
2435 /* If peer is soft reconfiguration enabled. Record input packet for
2436 further calculation. */
2437 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2438 && peer != bgp->peer_self)
2439 bgp_adj_in_unset (rn, peer);
2440
2441 /* Lookup withdrawn route. */
2442 for (ri = rn->info; ri; ri = ri->next)
2443 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2444 break;
2445
2446 /* Withdraw specified route from routing table. */
2447 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002448 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002449 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002450 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002451 "%s Can't find the route %s/%d", peer->host,
2452 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2453 p->prefixlen);
2454
2455 /* Unlock bgp_node_get() lock. */
2456 bgp_unlock_node (rn);
2457
2458 return 0;
2459}
2460
2461void
2462bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2463{
2464 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002465 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002466 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002467 struct prefix p;
2468 struct bgp_info binfo;
2469 struct peer *from;
2470 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002471
Paul Jakmab2497022007-06-14 11:17:58 +00002472 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002473 return;
2474
paul718e3742002-12-13 20:15:29 +00002475 bgp = peer->bgp;
2476 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002477
paul718e3742002-12-13 20:15:29 +00002478 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2479 aspath = attr.aspath;
2480 attr.local_pref = bgp->default_local_pref;
2481 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2482
2483 if (afi == AFI_IP)
2484 str2prefix ("0.0.0.0/0", &p);
2485#ifdef HAVE_IPV6
2486 else if (afi == AFI_IP6)
2487 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002488 struct attr_extra *ae;
2489 attr.extra = NULL;
2490
2491 ae = bgp_attr_extra_get (&attr);
2492 attr.extra = ae;
2493
paul718e3742002-12-13 20:15:29 +00002494 str2prefix ("::/0", &p);
2495
2496 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002497 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002498 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002499 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002500
2501 /* If the peer is on shared nextwork and we have link-local
2502 nexthop set it. */
2503 if (peer->shared_network
2504 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2505 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002506 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002507 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002508 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002509 }
2510 }
2511#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002512
2513 if (peer->default_rmap[afi][safi].name)
2514 {
2515 binfo.peer = bgp->peer_self;
2516 binfo.attr = &attr;
2517
paulfee0f4c2004-09-13 05:12:46 +00002518 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2519
paul718e3742002-12-13 20:15:29 +00002520 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2521 RMAP_BGP, &binfo);
2522
paulfee0f4c2004-09-13 05:12:46 +00002523 bgp->peer_self->rmap_type = 0;
2524
paul718e3742002-12-13 20:15:29 +00002525 if (ret == RMAP_DENYMATCH)
2526 {
2527 bgp_attr_flush (&attr);
2528 withdraw = 1;
2529 }
2530 }
2531
2532 if (withdraw)
2533 {
2534 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2535 bgp_default_withdraw_send (peer, afi, safi);
2536 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2537 }
2538 else
2539 {
2540 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2541 bgp_default_update_send (peer, &attr, afi, safi, from);
2542 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002543
2544 bgp_attr_extra_free (&attr);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00002545 aspath_unintern (&aspath);
paul718e3742002-12-13 20:15:29 +00002546}
2547
2548static void
2549bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002550 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002551{
2552 struct bgp_node *rn;
2553 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002554 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002555
paul718e3742002-12-13 20:15:29 +00002556 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002557 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002558
2559 if (safi != SAFI_MPLS_VPN
2560 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2561 bgp_default_originate (peer, afi, safi, 0);
2562
2563 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2564 for (ri = rn->info; ri; ri = ri->next)
2565 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2566 {
paulfee0f4c2004-09-13 05:12:46 +00002567 if ( (rsclient) ?
2568 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2569 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002570 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2571 else
2572 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002573
2574 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002575 }
2576}
2577
2578void
2579bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2580{
2581 struct bgp_node *rn;
2582 struct bgp_table *table;
2583
2584 if (peer->status != Established)
2585 return;
2586
2587 if (! peer->afc_nego[afi][safi])
2588 return;
2589
2590 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2591 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2592 return;
2593
2594 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002595 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002596 else
2597 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2598 rn = bgp_route_next(rn))
2599 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002600 bgp_announce_table (peer, afi, safi, table, 0);
2601
2602 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2603 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002604}
2605
2606void
2607bgp_announce_route_all (struct peer *peer)
2608{
2609 afi_t afi;
2610 safi_t safi;
2611
2612 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2613 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2614 bgp_announce_route (peer, afi, safi);
2615}
2616
2617static void
paulfee0f4c2004-09-13 05:12:46 +00002618bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002619 safi_t safi, struct bgp_table *table, struct prefix_rd *prd)
paulfee0f4c2004-09-13 05:12:46 +00002620{
2621 struct bgp_node *rn;
2622 struct bgp_adj_in *ain;
2623
2624 if (! table)
2625 table = rsclient->bgp->rib[afi][safi];
2626
2627 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2628 for (ain = rn->adj_in; ain; ain = ain->next)
2629 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002630 struct bgp_info *ri = rn->info;
2631
paulfee0f4c2004-09-13 05:12:46 +00002632 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002633 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, prd,
2634 (bgp_info_extra_get (ri))->tag);
paulfee0f4c2004-09-13 05:12:46 +00002635 }
2636}
2637
2638void
2639bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2640{
2641 struct bgp_table *table;
2642 struct bgp_node *rn;
2643
2644 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002645 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL, NULL);
paulfee0f4c2004-09-13 05:12:46 +00002646
2647 else
2648 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2649 rn = bgp_route_next (rn))
2650 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002651 {
2652 struct prefix_rd prd;
2653 prd.family = AF_UNSPEC;
2654 prd.prefixlen = 64;
2655 memcpy(&prd.val, rn->p.u.val, 8);
2656
2657 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table, &prd);
2658 }
paulfee0f4c2004-09-13 05:12:46 +00002659}
2660
2661static void
paul718e3742002-12-13 20:15:29 +00002662bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002663 struct bgp_table *table, struct prefix_rd *prd)
paul718e3742002-12-13 20:15:29 +00002664{
2665 int ret;
2666 struct bgp_node *rn;
2667 struct bgp_adj_in *ain;
2668
2669 if (! table)
2670 table = peer->bgp->rib[afi][safi];
2671
2672 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2673 for (ain = rn->adj_in; ain; ain = ain->next)
2674 {
2675 if (ain->peer == peer)
2676 {
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002677 struct bgp_info *ri = rn->info;
2678
paul718e3742002-12-13 20:15:29 +00002679 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2680 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002681 prd, (bgp_info_extra_get (ri))->tag, 1);
2682
paul718e3742002-12-13 20:15:29 +00002683 if (ret < 0)
2684 {
2685 bgp_unlock_node (rn);
2686 return;
2687 }
2688 continue;
2689 }
2690 }
2691}
2692
2693void
2694bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2695{
2696 struct bgp_node *rn;
2697 struct bgp_table *table;
2698
2699 if (peer->status != Established)
2700 return;
2701
2702 if (safi != SAFI_MPLS_VPN)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002703 bgp_soft_reconfig_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002704 else
2705 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2706 rn = bgp_route_next (rn))
2707 if ((table = rn->info) != NULL)
Jorge Boncompte [DTI2]8692c502012-05-07 15:17:34 +00002708 {
2709 struct prefix_rd prd;
2710 prd.family = AF_UNSPEC;
2711 prd.prefixlen = 64;
2712 memcpy(&prd.val, rn->p.u.val, 8);
2713
2714 bgp_soft_reconfig_table (peer, afi, safi, table, &prd);
2715 }
paul718e3742002-12-13 20:15:29 +00002716}
2717
Chris Caputo228da422009-07-18 05:44:03 +00002718
2719struct bgp_clear_node_queue
2720{
2721 struct bgp_node *rn;
2722 enum bgp_clear_route_type purpose;
2723};
2724
paul200df112005-06-01 11:17:05 +00002725static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002726bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002727{
Chris Caputo228da422009-07-18 05:44:03 +00002728 struct bgp_clear_node_queue *cnq = data;
2729 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002730 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002731 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002732 afi_t afi = rn->table->afi;
2733 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002734
Paul Jakma64e580a2006-02-21 01:09:01 +00002735 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002736
Paul Jakma64e580a2006-02-21 01:09:01 +00002737 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002738 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002739 {
2740 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002741 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2742 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002743 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002744 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2745 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002746 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002747 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002748 break;
2749 }
paul200df112005-06-01 11:17:05 +00002750 return WQ_SUCCESS;
2751}
2752
2753static void
paul0fb58d52005-11-14 14:31:49 +00002754bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002755{
Chris Caputo228da422009-07-18 05:44:03 +00002756 struct bgp_clear_node_queue *cnq = data;
2757 struct bgp_node *rn = cnq->rn;
2758 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002759
2760 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002761 bgp_table_unlock (table);
2762 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002763}
2764
2765static void
paul94f2b392005-06-28 12:44:16 +00002766bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002767{
Paul Jakma64e580a2006-02-21 01:09:01 +00002768 struct peer *peer = wq->spec.data;
2769
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002770 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002771 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002772
2773 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002774}
2775
2776static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002777bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002778{
Paul Jakmaa2943652009-07-21 14:02:04 +01002779 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002780
Paul Jakmaa2943652009-07-21 14:02:04 +01002781 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002782#undef CLEAR_QUEUE_NAME_LEN
2783
2784 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002785 {
2786 zlog_err ("%s: Failed to allocate work queue", __func__);
2787 exit (1);
2788 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002789 peer->clear_node_queue->spec.hold = 10;
2790 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2791 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2792 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2793 peer->clear_node_queue->spec.max_retries = 0;
2794
2795 /* we only 'lock' this peer reference when the queue is actually active */
2796 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002797}
2798
paul718e3742002-12-13 20:15:29 +00002799static void
2800bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002801 struct bgp_table *table, struct peer *rsclient,
2802 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002803{
2804 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002805
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002806
paul718e3742002-12-13 20:15:29 +00002807 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002808 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002809
hasso6cf159b2005-03-21 10:28:14 +00002810 /* If still no table => afi/safi isn't configured at all or smth. */
2811 if (! table)
2812 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002813
2814 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2815 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002816 struct bgp_info *ri;
2817 struct bgp_adj_in *ain;
2818 struct bgp_adj_out *aout;
2819
Paul Jakma65ca75e2006-05-04 08:08:15 +00002820 if (rn->info == NULL)
2821 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002822
2823 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2824 * queued for every clearing peer, regardless of whether it is
2825 * relevant to the peer at hand.
2826 *
2827 * Overview: There are 3 different indices which need to be
2828 * scrubbed, potentially, when a peer is removed:
2829 *
2830 * 1 peer's routes visible via the RIB (ie accepted routes)
2831 * 2 peer's routes visible by the (optional) peer's adj-in index
2832 * 3 other routes visible by the peer's adj-out index
2833 *
2834 * 3 there is no hurry in scrubbing, once the struct peer is
2835 * removed from bgp->peer, we could just GC such deleted peer's
2836 * adj-outs at our leisure.
2837 *
2838 * 1 and 2 must be 'scrubbed' in some way, at least made
2839 * invisible via RIB index before peer session is allowed to be
2840 * brought back up. So one needs to know when such a 'search' is
2841 * complete.
2842 *
2843 * Ideally:
2844 *
2845 * - there'd be a single global queue or a single RIB walker
2846 * - rather than tracking which route_nodes still need to be
2847 * examined on a peer basis, we'd track which peers still
2848 * aren't cleared
2849 *
2850 * Given that our per-peer prefix-counts now should be reliable,
2851 * this may actually be achievable. It doesn't seem to be a huge
2852 * problem at this time,
2853 */
2854 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002855 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002856 {
Chris Caputo228da422009-07-18 05:44:03 +00002857 struct bgp_clear_node_queue *cnq;
2858
2859 /* both unlocked in bgp_clear_node_queue_del */
2860 bgp_table_lock (rn->table);
2861 bgp_lock_node (rn);
2862 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2863 sizeof (struct bgp_clear_node_queue));
2864 cnq->rn = rn;
2865 cnq->purpose = purpose;
2866 work_queue_add (peer->clear_node_queue, cnq);
2867 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002868 }
2869
2870 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002871 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002872 {
2873 bgp_adj_in_remove (rn, ain);
2874 bgp_unlock_node (rn);
2875 break;
2876 }
2877 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002878 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002879 {
2880 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2881 bgp_unlock_node (rn);
2882 break;
2883 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002884 }
2885 return;
2886}
2887
2888void
Chris Caputo228da422009-07-18 05:44:03 +00002889bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2890 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002891{
2892 struct bgp_node *rn;
2893 struct bgp_table *table;
2894 struct peer *rsclient;
2895 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002896
Paul Jakma64e580a2006-02-21 01:09:01 +00002897 if (peer->clear_node_queue == NULL)
2898 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002899
Paul Jakmaca058a32006-09-14 02:58:49 +00002900 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2901 * Idle until it receives a Clearing_Completed event. This protects
2902 * against peers which flap faster than we can we clear, which could
2903 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002904 *
2905 * a) race with routes from the new session being installed before
2906 * clear_route_node visits the node (to delete the route of that
2907 * peer)
2908 * b) resource exhaustion, clear_route_node likely leads to an entry
2909 * on the process_main queue. Fast-flapping could cause that queue
2910 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002911 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002912 if (!peer->clear_node_queue->thread)
2913 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002914
Chris Caputo228da422009-07-18 05:44:03 +00002915 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002916 {
Chris Caputo228da422009-07-18 05:44:03 +00002917 case BGP_CLEAR_ROUTE_NORMAL:
2918 if (safi != SAFI_MPLS_VPN)
2919 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2920 else
2921 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2922 rn = bgp_route_next (rn))
2923 if ((table = rn->info) != NULL)
2924 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2925
2926 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2927 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2928 PEER_FLAG_RSERVER_CLIENT))
2929 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2930 break;
2931
2932 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2933 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2934 break;
2935
2936 default:
2937 assert (0);
2938 break;
paulfee0f4c2004-09-13 05:12:46 +00002939 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002940
Paul Jakmaca058a32006-09-14 02:58:49 +00002941 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002942 * completion function won't be run by workqueue code - call it here.
2943 * XXX: Actually, this assumption doesn't hold, see
2944 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002945 *
2946 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002947 * really needed if peer state is Established - peers in
2948 * pre-Established states shouldn't have any route-update state
2949 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002950 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002951 * We still can get here in pre-Established though, through
2952 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2953 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002954 *
2955 * At some future point, this check could be move to the top of the
2956 * function, and do a quick early-return when state is
2957 * pre-Established, avoiding above list and table scans. Once we're
2958 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002959 */
2960 if (!peer->clear_node_queue->thread)
2961 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002962}
2963
2964void
2965bgp_clear_route_all (struct peer *peer)
2966{
2967 afi_t afi;
2968 safi_t safi;
2969
2970 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2971 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002972 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002973}
2974
2975void
2976bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2977{
2978 struct bgp_table *table;
2979 struct bgp_node *rn;
2980 struct bgp_adj_in *ain;
2981
2982 table = peer->bgp->rib[afi][safi];
2983
2984 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2985 for (ain = rn->adj_in; ain ; ain = ain->next)
2986 if (ain->peer == peer)
2987 {
2988 bgp_adj_in_remove (rn, ain);
2989 bgp_unlock_node (rn);
2990 break;
2991 }
2992}
hasso93406d82005-02-02 14:40:33 +00002993
2994void
2995bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2996{
2997 struct bgp_node *rn;
2998 struct bgp_info *ri;
2999 struct bgp_table *table;
3000
3001 table = peer->bgp->rib[afi][safi];
3002
3003 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3004 {
3005 for (ri = rn->info; ri; ri = ri->next)
3006 if (ri->peer == peer)
3007 {
3008 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
3009 bgp_rib_remove (rn, ri, peer, afi, safi);
3010 break;
3011 }
3012 }
3013}
paul718e3742002-12-13 20:15:29 +00003014
3015/* Delete all kernel routes. */
3016void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003017bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003018{
3019 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003020 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003021 struct bgp_node *rn;
3022 struct bgp_table *table;
3023 struct bgp_info *ri;
3024
paul1eb8ef22005-04-07 07:30:20 +00003025 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003026 {
3027 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3028
3029 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3030 for (ri = rn->info; ri; ri = ri->next)
3031 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3032 && ri->type == ZEBRA_ROUTE_BGP
3033 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003034 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003035
3036 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3037
3038 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3039 for (ri = rn->info; ri; ri = ri->next)
3040 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3041 && ri->type == ZEBRA_ROUTE_BGP
3042 && ri->sub_type == BGP_ROUTE_NORMAL)
G.Balaji5a616c02011-11-26 21:58:42 +04003043 bgp_zebra_withdraw (&rn->p, ri,SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00003044 }
3045}
3046
3047void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003048bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003049{
3050 vty_reset ();
3051 bgp_zclient_reset ();
3052 access_list_reset ();
3053 prefix_list_reset ();
3054}
3055
3056/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3057 value. */
3058int
3059bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3060{
3061 u_char *pnt;
3062 u_char *lim;
3063 struct prefix p;
3064 int psize;
3065 int ret;
3066
3067 /* Check peer status. */
3068 if (peer->status != Established)
3069 return 0;
3070
3071 pnt = packet->nlri;
3072 lim = pnt + packet->length;
3073
3074 for (; pnt < lim; pnt += psize)
3075 {
3076 /* Clear prefix structure. */
3077 memset (&p, 0, sizeof (struct prefix));
3078
3079 /* Fetch prefix length. */
3080 p.prefixlen = *pnt++;
3081 p.family = afi2family (packet->afi);
3082
3083 /* Already checked in nlri_sanity_check(). We do double check
3084 here. */
3085 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3086 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3087 return -1;
3088
3089 /* Packet size overflow check. */
3090 psize = PSIZE (p.prefixlen);
3091
3092 /* When packet overflow occur return immediately. */
3093 if (pnt + psize > lim)
3094 return -1;
3095
3096 /* Fetch prefix from NLRI packet. */
3097 memcpy (&p.u.prefix, pnt, psize);
3098
3099 /* Check address. */
3100 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3101 {
3102 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3103 {
paulf5ba3872004-07-09 12:11:31 +00003104 /*
3105 * From draft-ietf-idr-bgp4-22, Section 6.3:
3106 * If a BGP router receives an UPDATE message with a
3107 * semantically incorrect NLRI field, in which a prefix is
3108 * semantically incorrect (eg. an unexpected multicast IP
3109 * address), it should ignore the prefix.
3110 */
paul718e3742002-12-13 20:15:29 +00003111 zlog (peer->log, LOG_ERR,
3112 "IPv4 unicast NLRI is multicast address %s",
3113 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003114
paul718e3742002-12-13 20:15:29 +00003115 return -1;
3116 }
3117 }
3118
3119#ifdef HAVE_IPV6
3120 /* Check address. */
3121 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3122 {
3123 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3124 {
3125 char buf[BUFSIZ];
3126
3127 zlog (peer->log, LOG_WARNING,
3128 "IPv6 link-local NLRI received %s ignore this NLRI",
3129 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3130
3131 continue;
3132 }
3133 }
3134#endif /* HAVE_IPV6 */
3135
3136 /* Normal process. */
3137 if (attr)
3138 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3139 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3140 else
3141 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3142 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3143
3144 /* Address family configuration mismatch or maximum-prefix count
3145 overflow. */
3146 if (ret < 0)
3147 return -1;
3148 }
3149
3150 /* Packet length consistency check. */
3151 if (pnt != lim)
3152 return -1;
3153
3154 return 0;
3155}
3156
3157/* NLRI encode syntax check routine. */
3158int
3159bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3160 bgp_size_t length)
3161{
3162 u_char *end;
3163 u_char prefixlen;
3164 int psize;
3165
3166 end = pnt + length;
3167
3168 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3169 syntactic validity. If the field is syntactically incorrect,
3170 then the Error Subcode is set to Invalid Network Field. */
3171
3172 while (pnt < end)
3173 {
3174 prefixlen = *pnt++;
3175
3176 /* Prefix length check. */
3177 if ((afi == AFI_IP && prefixlen > 32)
3178 || (afi == AFI_IP6 && prefixlen > 128))
3179 {
3180 plog_err (peer->log,
3181 "%s [Error] Update packet error (wrong prefix length %d)",
3182 peer->host, prefixlen);
3183 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3184 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3185 return -1;
3186 }
3187
3188 /* Packet size overflow check. */
3189 psize = PSIZE (prefixlen);
3190
3191 if (pnt + psize > end)
3192 {
3193 plog_err (peer->log,
3194 "%s [Error] Update packet error"
3195 " (prefix data overflow prefix size is %d)",
3196 peer->host, psize);
3197 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3198 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3199 return -1;
3200 }
3201
3202 pnt += psize;
3203 }
3204
3205 /* Packet length consistency check. */
3206 if (pnt != end)
3207 {
3208 plog_err (peer->log,
3209 "%s [Error] Update packet error"
3210 " (prefix length mismatch with total length)",
3211 peer->host);
3212 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3213 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3214 return -1;
3215 }
3216 return 0;
3217}
3218
paul94f2b392005-06-28 12:44:16 +00003219static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003220bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003221{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003222 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003223}
3224
paul94f2b392005-06-28 12:44:16 +00003225static void
paul718e3742002-12-13 20:15:29 +00003226bgp_static_free (struct bgp_static *bgp_static)
3227{
3228 if (bgp_static->rmap.name)
3229 free (bgp_static->rmap.name);
3230 XFREE (MTYPE_BGP_STATIC, bgp_static);
3231}
3232
paul94f2b392005-06-28 12:44:16 +00003233static void
paulfee0f4c2004-09-13 05:12:46 +00003234bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3235 struct prefix *p, afi_t afi, safi_t safi)
3236{
3237 struct bgp_node *rn;
3238 struct bgp_info *ri;
3239
3240 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3241
3242 /* Check selected route and self inserted route. */
3243 for (ri = rn->info; ri; ri = ri->next)
3244 if (ri->peer == bgp->peer_self
3245 && ri->type == ZEBRA_ROUTE_BGP
3246 && ri->sub_type == BGP_ROUTE_STATIC)
3247 break;
3248
3249 /* Withdraw static BGP route from routing table. */
3250 if (ri)
3251 {
paulfee0f4c2004-09-13 05:12:46 +00003252 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003253 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003254 }
3255
3256 /* Unlock bgp_node_lookup. */
3257 bgp_unlock_node (rn);
3258}
3259
paul94f2b392005-06-28 12:44:16 +00003260static void
paulfee0f4c2004-09-13 05:12:46 +00003261bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003262 struct bgp_static *bgp_static,
3263 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003264{
3265 struct bgp_node *rn;
3266 struct bgp_info *ri;
3267 struct bgp_info *new;
3268 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003269 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003270 struct attr attr = {0 };
3271 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003272 struct bgp *bgp;
3273 int ret;
3274 char buf[SU_ADDRSTRLEN];
3275
3276 bgp = rsclient->bgp;
3277
Paul Jakma06e110f2006-05-12 23:29:22 +00003278 assert (bgp_static);
3279 if (!bgp_static)
3280 return;
3281
paulfee0f4c2004-09-13 05:12:46 +00003282 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3283
3284 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003285
3286 attr.nexthop = bgp_static->igpnexthop;
3287 attr.med = bgp_static->igpmetric;
3288 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003289
Paul Jakma41367172007-08-06 15:24:51 +00003290 if (bgp_static->atomic)
3291 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3292
paulfee0f4c2004-09-13 05:12:46 +00003293 /* Apply network route-map for export to this rsclient. */
3294 if (bgp_static->rmap.name)
3295 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003296 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003297 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003298 info.attr = &attr_tmp;
3299
paulfee0f4c2004-09-13 05:12:46 +00003300 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3301 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3302
3303 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3304
3305 rsclient->rmap_type = 0;
3306
3307 if (ret == RMAP_DENYMATCH)
3308 {
3309 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003310 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003311
3312 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003313 aspath_unintern (&attr.aspath);
paulfee0f4c2004-09-13 05:12:46 +00003314 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003315 bgp_attr_extra_free (&attr);
3316
paulfee0f4c2004-09-13 05:12:46 +00003317 return;
3318 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003319 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003320 }
3321 else
3322 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003323
Stephen Hemminger7badc262010-08-05 10:26:31 -07003324 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003325
paulfee0f4c2004-09-13 05:12:46 +00003326 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3327
Paul Jakmafb982c22007-05-04 20:15:47 +00003328 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3329 == RMAP_DENY)
3330 {
paulfee0f4c2004-09-13 05:12:46 +00003331 /* This BGP update is filtered. Log the reason then update BGP entry. */
3332 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003333 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003334 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3335 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3336 p->prefixlen, rsclient->host);
3337
3338 bgp->peer_self->rmap_type = 0;
3339
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003340 bgp_attr_unintern (&attr_new);
3341 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003342 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003343
3344 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3345
3346 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003347 }
paulfee0f4c2004-09-13 05:12:46 +00003348
3349 bgp->peer_self->rmap_type = 0;
3350
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003351 bgp_attr_unintern (&attr_new);
paulfee0f4c2004-09-13 05:12:46 +00003352 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003353 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003354
3355 for (ri = rn->info; ri; ri = ri->next)
3356 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3357 && ri->sub_type == BGP_ROUTE_STATIC)
3358 break;
3359
3360 if (ri)
3361 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003362 if (attrhash_cmp (ri->attr, attr_new) &&
3363 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003364 {
3365 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003366 bgp_attr_unintern (&attr_new);
3367 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003368 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003369 return;
3370 }
3371 else
3372 {
3373 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003374 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003375
3376 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003377 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3378 bgp_info_restore(rn, ri);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003379 bgp_attr_unintern (&ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00003380 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003381 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003382
3383 /* Process change. */
3384 bgp_process (bgp, rn, afi, safi);
3385 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003386 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003387 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003388 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003389 }
paulfee0f4c2004-09-13 05:12:46 +00003390 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003391
paulfee0f4c2004-09-13 05:12:46 +00003392 /* Make new BGP info. */
3393 new = bgp_info_new ();
3394 new->type = ZEBRA_ROUTE_BGP;
3395 new->sub_type = BGP_ROUTE_STATIC;
3396 new->peer = bgp->peer_self;
3397 SET_FLAG (new->flags, BGP_INFO_VALID);
3398 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003399 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003400
3401 /* Register new BGP information. */
3402 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003403
3404 /* route_node_get lock */
3405 bgp_unlock_node (rn);
3406
paulfee0f4c2004-09-13 05:12:46 +00003407 /* Process change. */
3408 bgp_process (bgp, rn, afi, safi);
3409
3410 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003411 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003412 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003413}
3414
paul94f2b392005-06-28 12:44:16 +00003415static void
paulfee0f4c2004-09-13 05:12:46 +00003416bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003417 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3418{
3419 struct bgp_node *rn;
3420 struct bgp_info *ri;
3421 struct bgp_info *new;
3422 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003423 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003424 struct attr *attr_new;
3425 int ret;
3426
Paul Jakmadd8103a2006-05-12 23:27:30 +00003427 assert (bgp_static);
3428 if (!bgp_static)
3429 return;
3430
paulfee0f4c2004-09-13 05:12:46 +00003431 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003432
3433 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003434
3435 attr.nexthop = bgp_static->igpnexthop;
3436 attr.med = bgp_static->igpmetric;
3437 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003438
Paul Jakma41367172007-08-06 15:24:51 +00003439 if (bgp_static->atomic)
3440 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3441
paul718e3742002-12-13 20:15:29 +00003442 /* Apply route-map. */
3443 if (bgp_static->rmap.name)
3444 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003445 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003446 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003447 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003448
paulfee0f4c2004-09-13 05:12:46 +00003449 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3450
paul718e3742002-12-13 20:15:29 +00003451 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003452
paulfee0f4c2004-09-13 05:12:46 +00003453 bgp->peer_self->rmap_type = 0;
3454
paul718e3742002-12-13 20:15:29 +00003455 if (ret == RMAP_DENYMATCH)
3456 {
3457 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003458 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003459
3460 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003461 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003462 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003463 bgp_static_withdraw (bgp, p, afi, safi);
3464 return;
3465 }
paul286e1e72003-08-08 00:24:31 +00003466 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003467 }
paul286e1e72003-08-08 00:24:31 +00003468 else
3469 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003470
3471 for (ri = rn->info; ri; ri = ri->next)
3472 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3473 && ri->sub_type == BGP_ROUTE_STATIC)
3474 break;
3475
3476 if (ri)
3477 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003478 if (attrhash_cmp (ri->attr, attr_new) &&
3479 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003480 {
3481 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003482 bgp_attr_unintern (&attr_new);
3483 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003484 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003485 return;
3486 }
3487 else
3488 {
3489 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003490 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003491
3492 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003493 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3494 bgp_info_restore(rn, ri);
3495 else
3496 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003497 bgp_attr_unintern (&ri->attr);
paul718e3742002-12-13 20:15:29 +00003498 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003499 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003500
3501 /* Process change. */
3502 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3503 bgp_process (bgp, rn, afi, safi);
3504 bgp_unlock_node (rn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003505 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003506 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003507 return;
3508 }
3509 }
3510
3511 /* Make new BGP info. */
3512 new = bgp_info_new ();
3513 new->type = ZEBRA_ROUTE_BGP;
3514 new->sub_type = BGP_ROUTE_STATIC;
3515 new->peer = bgp->peer_self;
3516 SET_FLAG (new->flags, BGP_INFO_VALID);
3517 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003518 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003519
3520 /* Aggregate address increment. */
3521 bgp_aggregate_increment (bgp, p, new, afi, safi);
3522
3523 /* Register new BGP information. */
3524 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003525
3526 /* route_node_get lock */
3527 bgp_unlock_node (rn);
3528
paul718e3742002-12-13 20:15:29 +00003529 /* Process change. */
3530 bgp_process (bgp, rn, afi, safi);
3531
3532 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00003533 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003534 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003535}
3536
3537void
paulfee0f4c2004-09-13 05:12:46 +00003538bgp_static_update (struct bgp *bgp, struct prefix *p,
3539 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3540{
3541 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003542 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003543
3544 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3545
paul1eb8ef22005-04-07 07:30:20 +00003546 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003547 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003548 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3549 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003550 }
3551}
3552
paul94f2b392005-06-28 12:44:16 +00003553static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003554bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3555 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003556{
3557 struct bgp_node *rn;
3558 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003559
paulfee0f4c2004-09-13 05:12:46 +00003560 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003561
3562 /* Make new BGP info. */
3563 new = bgp_info_new ();
3564 new->type = ZEBRA_ROUTE_BGP;
3565 new->sub_type = BGP_ROUTE_STATIC;
3566 new->peer = bgp->peer_self;
3567 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3568 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003569 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003570 new->extra = bgp_info_extra_new();
3571 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003572
3573 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003574 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003575
3576 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003577 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003578
paul200df112005-06-01 11:17:05 +00003579 /* route_node_get lock */
3580 bgp_unlock_node (rn);
3581
paul718e3742002-12-13 20:15:29 +00003582 /* Process change. */
3583 bgp_process (bgp, rn, afi, safi);
3584}
3585
3586void
3587bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3588 safi_t safi)
3589{
3590 struct bgp_node *rn;
3591 struct bgp_info *ri;
3592
paulfee0f4c2004-09-13 05:12:46 +00003593 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003594
3595 /* Check selected route and self inserted route. */
3596 for (ri = rn->info; ri; ri = ri->next)
3597 if (ri->peer == bgp->peer_self
3598 && ri->type == ZEBRA_ROUTE_BGP
3599 && ri->sub_type == BGP_ROUTE_STATIC)
3600 break;
3601
3602 /* Withdraw static BGP route from routing table. */
3603 if (ri)
3604 {
3605 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003606 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003607 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003608 }
3609
3610 /* Unlock bgp_node_lookup. */
3611 bgp_unlock_node (rn);
3612}
3613
3614void
paulfee0f4c2004-09-13 05:12:46 +00003615bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3616{
3617 struct bgp_static *bgp_static;
3618 struct bgp *bgp;
3619 struct bgp_node *rn;
3620 struct prefix *p;
3621
3622 bgp = rsclient->bgp;
3623
3624 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3625 if ((bgp_static = rn->info) != NULL)
3626 {
3627 p = &rn->p;
3628
3629 bgp_static_update_rsclient (rsclient, p, bgp_static,
3630 afi, safi);
3631 }
3632}
3633
paul94f2b392005-06-28 12:44:16 +00003634static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003635bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3636 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003637{
3638 struct bgp_node *rn;
3639 struct bgp_info *ri;
3640
paulfee0f4c2004-09-13 05:12:46 +00003641 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003642
3643 /* Check selected route and self inserted route. */
3644 for (ri = rn->info; ri; ri = ri->next)
3645 if (ri->peer == bgp->peer_self
3646 && ri->type == ZEBRA_ROUTE_BGP
3647 && ri->sub_type == BGP_ROUTE_STATIC)
3648 break;
3649
3650 /* Withdraw static BGP route from routing table. */
3651 if (ri)
3652 {
3653 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003654 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003655 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003656 }
3657
3658 /* Unlock bgp_node_lookup. */
3659 bgp_unlock_node (rn);
3660}
3661
3662/* Configure static BGP network. When user don't run zebra, static
3663 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003664static int
paulfd79ac92004-10-13 05:06:08 +00003665bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003666 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003667{
3668 int ret;
3669 struct prefix p;
3670 struct bgp_static *bgp_static;
3671 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003672 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003673
3674 /* Convert IP prefix string to struct prefix. */
3675 ret = str2prefix (ip_str, &p);
3676 if (! ret)
3677 {
3678 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3679 return CMD_WARNING;
3680 }
3681#ifdef HAVE_IPV6
3682 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3683 {
3684 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3685 VTY_NEWLINE);
3686 return CMD_WARNING;
3687 }
3688#endif /* HAVE_IPV6 */
3689
3690 apply_mask (&p);
3691
3692 /* Set BGP static route configuration. */
3693 rn = bgp_node_get (bgp->route[afi][safi], &p);
3694
3695 if (rn->info)
3696 {
3697 /* Configuration change. */
3698 bgp_static = rn->info;
3699
3700 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003701 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3702 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003703
paul718e3742002-12-13 20:15:29 +00003704 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003705
paul718e3742002-12-13 20:15:29 +00003706 if (rmap)
3707 {
3708 if (bgp_static->rmap.name)
3709 free (bgp_static->rmap.name);
3710 bgp_static->rmap.name = strdup (rmap);
3711 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3712 }
3713 else
3714 {
3715 if (bgp_static->rmap.name)
3716 free (bgp_static->rmap.name);
3717 bgp_static->rmap.name = NULL;
3718 bgp_static->rmap.map = NULL;
3719 bgp_static->valid = 0;
3720 }
3721 bgp_unlock_node (rn);
3722 }
3723 else
3724 {
3725 /* New configuration. */
3726 bgp_static = bgp_static_new ();
3727 bgp_static->backdoor = backdoor;
3728 bgp_static->valid = 0;
3729 bgp_static->igpmetric = 0;
3730 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003731
paul718e3742002-12-13 20:15:29 +00003732 if (rmap)
3733 {
3734 if (bgp_static->rmap.name)
3735 free (bgp_static->rmap.name);
3736 bgp_static->rmap.name = strdup (rmap);
3737 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3738 }
3739 rn->info = bgp_static;
3740 }
3741
3742 /* If BGP scan is not enabled, we should install this route here. */
3743 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3744 {
3745 bgp_static->valid = 1;
3746
3747 if (need_update)
3748 bgp_static_withdraw (bgp, &p, afi, safi);
3749
3750 if (! bgp_static->backdoor)
3751 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3752 }
3753
3754 return CMD_SUCCESS;
3755}
3756
3757/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003758static int
paulfd79ac92004-10-13 05:06:08 +00003759bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003760 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003761{
3762 int ret;
3763 struct prefix p;
3764 struct bgp_static *bgp_static;
3765 struct bgp_node *rn;
3766
3767 /* Convert IP prefix string to struct prefix. */
3768 ret = str2prefix (ip_str, &p);
3769 if (! ret)
3770 {
3771 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3772 return CMD_WARNING;
3773 }
3774#ifdef HAVE_IPV6
3775 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3776 {
3777 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3778 VTY_NEWLINE);
3779 return CMD_WARNING;
3780 }
3781#endif /* HAVE_IPV6 */
3782
3783 apply_mask (&p);
3784
3785 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3786 if (! rn)
3787 {
3788 vty_out (vty, "%% Can't find specified static route configuration.%s",
3789 VTY_NEWLINE);
3790 return CMD_WARNING;
3791 }
3792
3793 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003794
paul718e3742002-12-13 20:15:29 +00003795 /* Update BGP RIB. */
3796 if (! bgp_static->backdoor)
3797 bgp_static_withdraw (bgp, &p, afi, safi);
3798
3799 /* Clear configuration. */
3800 bgp_static_free (bgp_static);
3801 rn->info = NULL;
3802 bgp_unlock_node (rn);
3803 bgp_unlock_node (rn);
3804
3805 return CMD_SUCCESS;
3806}
3807
3808/* Called from bgp_delete(). Delete all static routes from the BGP
3809 instance. */
3810void
3811bgp_static_delete (struct bgp *bgp)
3812{
3813 afi_t afi;
3814 safi_t safi;
3815 struct bgp_node *rn;
3816 struct bgp_node *rm;
3817 struct bgp_table *table;
3818 struct bgp_static *bgp_static;
3819
3820 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3821 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3822 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3823 if (rn->info != NULL)
3824 {
3825 if (safi == SAFI_MPLS_VPN)
3826 {
3827 table = rn->info;
3828
3829 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3830 {
3831 bgp_static = rn->info;
3832 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3833 AFI_IP, SAFI_MPLS_VPN,
3834 (struct prefix_rd *)&rn->p,
3835 bgp_static->tag);
3836 bgp_static_free (bgp_static);
3837 rn->info = NULL;
3838 bgp_unlock_node (rn);
3839 }
3840 }
3841 else
3842 {
3843 bgp_static = rn->info;
3844 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3845 bgp_static_free (bgp_static);
3846 rn->info = NULL;
3847 bgp_unlock_node (rn);
3848 }
3849 }
3850}
3851
3852int
paulfd79ac92004-10-13 05:06:08 +00003853bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3854 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003855{
3856 int ret;
3857 struct prefix p;
3858 struct prefix_rd prd;
3859 struct bgp *bgp;
3860 struct bgp_node *prn;
3861 struct bgp_node *rn;
3862 struct bgp_table *table;
3863 struct bgp_static *bgp_static;
3864 u_char tag[3];
3865
3866 bgp = vty->index;
3867
3868 ret = str2prefix (ip_str, &p);
3869 if (! ret)
3870 {
3871 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3872 return CMD_WARNING;
3873 }
3874 apply_mask (&p);
3875
3876 ret = str2prefix_rd (rd_str, &prd);
3877 if (! ret)
3878 {
3879 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3880 return CMD_WARNING;
3881 }
3882
3883 ret = str2tag (tag_str, tag);
3884 if (! ret)
3885 {
3886 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3887 return CMD_WARNING;
3888 }
3889
3890 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3891 (struct prefix *)&prd);
3892 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003893 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003894 else
3895 bgp_unlock_node (prn);
3896 table = prn->info;
3897
3898 rn = bgp_node_get (table, &p);
3899
3900 if (rn->info)
3901 {
3902 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3903 bgp_unlock_node (rn);
3904 }
3905 else
3906 {
3907 /* New configuration. */
3908 bgp_static = bgp_static_new ();
3909 bgp_static->valid = 1;
3910 memcpy (bgp_static->tag, tag, 3);
3911 rn->info = bgp_static;
3912
3913 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3914 }
3915
3916 return CMD_SUCCESS;
3917}
3918
3919/* Configure static BGP network. */
3920int
paulfd79ac92004-10-13 05:06:08 +00003921bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3922 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003923{
3924 int ret;
3925 struct bgp *bgp;
3926 struct prefix p;
3927 struct prefix_rd prd;
3928 struct bgp_node *prn;
3929 struct bgp_node *rn;
3930 struct bgp_table *table;
3931 struct bgp_static *bgp_static;
3932 u_char tag[3];
3933
3934 bgp = vty->index;
3935
3936 /* Convert IP prefix string to struct prefix. */
3937 ret = str2prefix (ip_str, &p);
3938 if (! ret)
3939 {
3940 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3941 return CMD_WARNING;
3942 }
3943 apply_mask (&p);
3944
3945 ret = str2prefix_rd (rd_str, &prd);
3946 if (! ret)
3947 {
3948 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3949 return CMD_WARNING;
3950 }
3951
3952 ret = str2tag (tag_str, tag);
3953 if (! ret)
3954 {
3955 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3956 return CMD_WARNING;
3957 }
3958
3959 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3960 (struct prefix *)&prd);
3961 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003962 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003963 else
3964 bgp_unlock_node (prn);
3965 table = prn->info;
3966
3967 rn = bgp_node_lookup (table, &p);
3968
3969 if (rn)
3970 {
3971 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3972
3973 bgp_static = rn->info;
3974 bgp_static_free (bgp_static);
3975 rn->info = NULL;
3976 bgp_unlock_node (rn);
3977 bgp_unlock_node (rn);
3978 }
3979 else
3980 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3981
3982 return CMD_SUCCESS;
3983}
3984
3985DEFUN (bgp_network,
3986 bgp_network_cmd,
3987 "network A.B.C.D/M",
3988 "Specify a network to announce via BGP\n"
3989 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3990{
3991 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003992 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003993}
3994
3995DEFUN (bgp_network_route_map,
3996 bgp_network_route_map_cmd,
3997 "network A.B.C.D/M route-map WORD",
3998 "Specify a network to announce via BGP\n"
3999 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4000 "Route-map to modify the attributes\n"
4001 "Name of the route map\n")
4002{
4003 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004004 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004005}
4006
4007DEFUN (bgp_network_backdoor,
4008 bgp_network_backdoor_cmd,
4009 "network A.B.C.D/M backdoor",
4010 "Specify a network to announce via BGP\n"
4011 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4012 "Specify a BGP backdoor route\n")
4013{
Paul Jakma41367172007-08-06 15:24:51 +00004014 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004015 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004016}
4017
4018DEFUN (bgp_network_mask,
4019 bgp_network_mask_cmd,
4020 "network A.B.C.D mask A.B.C.D",
4021 "Specify a network to announce via BGP\n"
4022 "Network number\n"
4023 "Network mask\n"
4024 "Network mask\n")
4025{
4026 int ret;
4027 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004028
paul718e3742002-12-13 20:15:29 +00004029 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4030 if (! ret)
4031 {
4032 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4033 return CMD_WARNING;
4034 }
4035
4036 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004037 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004038}
4039
4040DEFUN (bgp_network_mask_route_map,
4041 bgp_network_mask_route_map_cmd,
4042 "network A.B.C.D mask A.B.C.D route-map WORD",
4043 "Specify a network to announce via BGP\n"
4044 "Network number\n"
4045 "Network mask\n"
4046 "Network mask\n"
4047 "Route-map to modify the attributes\n"
4048 "Name of the route map\n")
4049{
4050 int ret;
4051 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004052
paul718e3742002-12-13 20:15:29 +00004053 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4054 if (! ret)
4055 {
4056 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4057 return CMD_WARNING;
4058 }
4059
4060 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004061 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004062}
4063
4064DEFUN (bgp_network_mask_backdoor,
4065 bgp_network_mask_backdoor_cmd,
4066 "network A.B.C.D mask A.B.C.D backdoor",
4067 "Specify a network to announce via BGP\n"
4068 "Network number\n"
4069 "Network mask\n"
4070 "Network mask\n"
4071 "Specify a BGP backdoor route\n")
4072{
4073 int ret;
4074 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004075
paul718e3742002-12-13 20:15:29 +00004076 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4077 if (! ret)
4078 {
4079 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4080 return CMD_WARNING;
4081 }
4082
Paul Jakma41367172007-08-06 15:24:51 +00004083 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004084 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004085}
4086
4087DEFUN (bgp_network_mask_natural,
4088 bgp_network_mask_natural_cmd,
4089 "network A.B.C.D",
4090 "Specify a network to announce via BGP\n"
4091 "Network number\n")
4092{
4093 int ret;
4094 char prefix_str[BUFSIZ];
4095
4096 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4097 if (! ret)
4098 {
4099 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4100 return CMD_WARNING;
4101 }
4102
4103 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004104 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004105}
4106
4107DEFUN (bgp_network_mask_natural_route_map,
4108 bgp_network_mask_natural_route_map_cmd,
4109 "network A.B.C.D route-map WORD",
4110 "Specify a network to announce via BGP\n"
4111 "Network number\n"
4112 "Route-map to modify the attributes\n"
4113 "Name of the route map\n")
4114{
4115 int ret;
4116 char prefix_str[BUFSIZ];
4117
4118 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4119 if (! ret)
4120 {
4121 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4122 return CMD_WARNING;
4123 }
4124
4125 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004126 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004127}
4128
4129DEFUN (bgp_network_mask_natural_backdoor,
4130 bgp_network_mask_natural_backdoor_cmd,
4131 "network A.B.C.D backdoor",
4132 "Specify a network to announce via BGP\n"
4133 "Network number\n"
4134 "Specify a BGP backdoor route\n")
4135{
4136 int ret;
4137 char prefix_str[BUFSIZ];
4138
4139 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4140 if (! ret)
4141 {
4142 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4143 return CMD_WARNING;
4144 }
4145
Paul Jakma41367172007-08-06 15:24:51 +00004146 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004147 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004148}
4149
4150DEFUN (no_bgp_network,
4151 no_bgp_network_cmd,
4152 "no network A.B.C.D/M",
4153 NO_STR
4154 "Specify a network to announce via BGP\n"
4155 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4156{
4157 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4158 bgp_node_safi (vty));
4159}
4160
4161ALIAS (no_bgp_network,
4162 no_bgp_network_route_map_cmd,
4163 "no network A.B.C.D/M route-map WORD",
4164 NO_STR
4165 "Specify a network to announce via BGP\n"
4166 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4167 "Route-map to modify the attributes\n"
4168 "Name of the route map\n")
4169
4170ALIAS (no_bgp_network,
4171 no_bgp_network_backdoor_cmd,
4172 "no network A.B.C.D/M backdoor",
4173 NO_STR
4174 "Specify a network to announce via BGP\n"
4175 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4176 "Specify a BGP backdoor route\n")
4177
4178DEFUN (no_bgp_network_mask,
4179 no_bgp_network_mask_cmd,
4180 "no network A.B.C.D mask A.B.C.D",
4181 NO_STR
4182 "Specify a network to announce via BGP\n"
4183 "Network number\n"
4184 "Network mask\n"
4185 "Network mask\n")
4186{
4187 int ret;
4188 char prefix_str[BUFSIZ];
4189
4190 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4191 if (! ret)
4192 {
4193 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4194 return CMD_WARNING;
4195 }
4196
4197 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4198 bgp_node_safi (vty));
4199}
4200
4201ALIAS (no_bgp_network_mask,
4202 no_bgp_network_mask_route_map_cmd,
4203 "no network A.B.C.D mask A.B.C.D route-map WORD",
4204 NO_STR
4205 "Specify a network to announce via BGP\n"
4206 "Network number\n"
4207 "Network mask\n"
4208 "Network mask\n"
4209 "Route-map to modify the attributes\n"
4210 "Name of the route map\n")
4211
4212ALIAS (no_bgp_network_mask,
4213 no_bgp_network_mask_backdoor_cmd,
4214 "no network A.B.C.D mask A.B.C.D backdoor",
4215 NO_STR
4216 "Specify a network to announce via BGP\n"
4217 "Network number\n"
4218 "Network mask\n"
4219 "Network mask\n"
4220 "Specify a BGP backdoor route\n")
4221
4222DEFUN (no_bgp_network_mask_natural,
4223 no_bgp_network_mask_natural_cmd,
4224 "no network A.B.C.D",
4225 NO_STR
4226 "Specify a network to announce via BGP\n"
4227 "Network number\n")
4228{
4229 int ret;
4230 char prefix_str[BUFSIZ];
4231
4232 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4233 if (! ret)
4234 {
4235 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4236 return CMD_WARNING;
4237 }
4238
4239 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4240 bgp_node_safi (vty));
4241}
4242
4243ALIAS (no_bgp_network_mask_natural,
4244 no_bgp_network_mask_natural_route_map_cmd,
4245 "no network A.B.C.D route-map WORD",
4246 NO_STR
4247 "Specify a network to announce via BGP\n"
4248 "Network number\n"
4249 "Route-map to modify the attributes\n"
4250 "Name of the route map\n")
4251
4252ALIAS (no_bgp_network_mask_natural,
4253 no_bgp_network_mask_natural_backdoor_cmd,
4254 "no network A.B.C.D backdoor",
4255 NO_STR
4256 "Specify a network to announce via BGP\n"
4257 "Network number\n"
4258 "Specify a BGP backdoor route\n")
4259
4260#ifdef HAVE_IPV6
4261DEFUN (ipv6_bgp_network,
4262 ipv6_bgp_network_cmd,
4263 "network X:X::X:X/M",
4264 "Specify a network to announce via BGP\n"
4265 "IPv6 prefix <network>/<length>\n")
4266{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304267 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty),
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004268 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004269}
4270
4271DEFUN (ipv6_bgp_network_route_map,
4272 ipv6_bgp_network_route_map_cmd,
4273 "network X:X::X:X/M route-map WORD",
4274 "Specify a network to announce via BGP\n"
4275 "IPv6 prefix <network>/<length>\n"
4276 "Route-map to modify the attributes\n"
4277 "Name of the route map\n")
4278{
4279 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004280 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004281}
4282
4283DEFUN (no_ipv6_bgp_network,
4284 no_ipv6_bgp_network_cmd,
4285 "no network X:X::X:X/M",
4286 NO_STR
4287 "Specify a network to announce via BGP\n"
4288 "IPv6 prefix <network>/<length>\n")
4289{
G.Balaji73bfe0b2011-09-23 22:36:20 +05304290 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, bgp_node_safi(vty));
paul718e3742002-12-13 20:15:29 +00004291}
4292
4293ALIAS (no_ipv6_bgp_network,
4294 no_ipv6_bgp_network_route_map_cmd,
4295 "no network X:X::X:X/M route-map WORD",
4296 NO_STR
4297 "Specify a network to announce via BGP\n"
4298 "IPv6 prefix <network>/<length>\n"
4299 "Route-map to modify the attributes\n"
4300 "Name of the route map\n")
4301
4302ALIAS (ipv6_bgp_network,
4303 old_ipv6_bgp_network_cmd,
4304 "ipv6 bgp network X:X::X:X/M",
4305 IPV6_STR
4306 BGP_STR
4307 "Specify a network to announce via BGP\n"
4308 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4309
4310ALIAS (no_ipv6_bgp_network,
4311 old_no_ipv6_bgp_network_cmd,
4312 "no ipv6 bgp network X:X::X:X/M",
4313 NO_STR
4314 IPV6_STR
4315 BGP_STR
4316 "Specify a network to announce via BGP\n"
4317 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4318#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004319
4320/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4321ALIAS_DEPRECATED (bgp_network,
4322 bgp_network_ttl_cmd,
4323 "network A.B.C.D/M pathlimit <0-255>",
4324 "Specify a network to announce via BGP\n"
4325 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4326 "AS-Path hopcount limit attribute\n"
4327 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4328ALIAS_DEPRECATED (bgp_network_backdoor,
4329 bgp_network_backdoor_ttl_cmd,
4330 "network A.B.C.D/M backdoor pathlimit <0-255>",
4331 "Specify a network to announce via BGP\n"
4332 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4333 "Specify a BGP backdoor route\n"
4334 "AS-Path hopcount limit attribute\n"
4335 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4336ALIAS_DEPRECATED (bgp_network_mask,
4337 bgp_network_mask_ttl_cmd,
4338 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4339 "Specify a network to announce via BGP\n"
4340 "Network number\n"
4341 "Network mask\n"
4342 "Network mask\n"
4343 "AS-Path hopcount limit attribute\n"
4344 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4345ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4346 bgp_network_mask_backdoor_ttl_cmd,
4347 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4348 "Specify a network to announce via BGP\n"
4349 "Network number\n"
4350 "Network mask\n"
4351 "Network mask\n"
4352 "Specify a BGP backdoor route\n"
4353 "AS-Path hopcount limit attribute\n"
4354 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4355ALIAS_DEPRECATED (bgp_network_mask_natural,
4356 bgp_network_mask_natural_ttl_cmd,
4357 "network A.B.C.D pathlimit <0-255>",
4358 "Specify a network to announce via BGP\n"
4359 "Network number\n"
4360 "AS-Path hopcount limit attribute\n"
4361 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4362ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4363 bgp_network_mask_natural_backdoor_ttl_cmd,
4364 "network A.B.C.D backdoor pathlimit (1-255>",
4365 "Specify a network to announce via BGP\n"
4366 "Network number\n"
4367 "Specify a BGP backdoor route\n"
4368 "AS-Path hopcount limit attribute\n"
4369 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4370ALIAS_DEPRECATED (no_bgp_network,
4371 no_bgp_network_ttl_cmd,
4372 "no network A.B.C.D/M pathlimit <0-255>",
4373 NO_STR
4374 "Specify a network to announce via BGP\n"
4375 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4376 "AS-Path hopcount limit attribute\n"
4377 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4378ALIAS_DEPRECATED (no_bgp_network,
4379 no_bgp_network_backdoor_ttl_cmd,
4380 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4381 NO_STR
4382 "Specify a network to announce via BGP\n"
4383 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4384 "Specify a BGP backdoor route\n"
4385 "AS-Path hopcount limit attribute\n"
4386 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4387ALIAS_DEPRECATED (no_bgp_network,
4388 no_bgp_network_mask_ttl_cmd,
4389 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4390 NO_STR
4391 "Specify a network to announce via BGP\n"
4392 "Network number\n"
4393 "Network mask\n"
4394 "Network mask\n"
4395 "AS-Path hopcount limit attribute\n"
4396 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4397ALIAS_DEPRECATED (no_bgp_network_mask,
4398 no_bgp_network_mask_backdoor_ttl_cmd,
4399 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4400 NO_STR
4401 "Specify a network to announce via BGP\n"
4402 "Network number\n"
4403 "Network mask\n"
4404 "Network mask\n"
4405 "Specify a BGP backdoor route\n"
4406 "AS-Path hopcount limit attribute\n"
4407 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4408ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4409 no_bgp_network_mask_natural_ttl_cmd,
4410 "no network A.B.C.D pathlimit <0-255>",
4411 NO_STR
4412 "Specify a network to announce via BGP\n"
4413 "Network number\n"
4414 "AS-Path hopcount limit attribute\n"
4415 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4416ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4417 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4418 "no network A.B.C.D backdoor pathlimit <0-255>",
4419 NO_STR
4420 "Specify a network to announce via BGP\n"
4421 "Network number\n"
4422 "Specify a BGP backdoor route\n"
4423 "AS-Path hopcount limit attribute\n"
4424 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004425#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004426ALIAS_DEPRECATED (ipv6_bgp_network,
4427 ipv6_bgp_network_ttl_cmd,
4428 "network X:X::X:X/M pathlimit <0-255>",
4429 "Specify a network to announce via BGP\n"
4430 "IPv6 prefix <network>/<length>\n"
4431 "AS-Path hopcount limit attribute\n"
4432 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4433ALIAS_DEPRECATED (no_ipv6_bgp_network,
4434 no_ipv6_bgp_network_ttl_cmd,
4435 "no network X:X::X:X/M pathlimit <0-255>",
4436 NO_STR
4437 "Specify a network to announce via BGP\n"
4438 "IPv6 prefix <network>/<length>\n"
4439 "AS-Path hopcount limit attribute\n"
4440 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004441#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004442
4443/* Aggreagete address:
4444
4445 advertise-map Set condition to advertise attribute
4446 as-set Generate AS set path information
4447 attribute-map Set attributes of aggregate
4448 route-map Set parameters of aggregate
4449 summary-only Filter more specific routes from updates
4450 suppress-map Conditionally filter more specific routes from updates
4451 <cr>
4452 */
4453struct bgp_aggregate
4454{
4455 /* Summary-only flag. */
4456 u_char summary_only;
4457
4458 /* AS set generation. */
4459 u_char as_set;
4460
4461 /* Route-map for aggregated route. */
4462 struct route_map *map;
4463
4464 /* Suppress-count. */
4465 unsigned long count;
4466
4467 /* SAFI configuration. */
4468 safi_t safi;
4469};
4470
paul94f2b392005-06-28 12:44:16 +00004471static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004472bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004473{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004474 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004475}
4476
paul94f2b392005-06-28 12:44:16 +00004477static void
paul718e3742002-12-13 20:15:29 +00004478bgp_aggregate_free (struct bgp_aggregate *aggregate)
4479{
4480 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4481}
4482
paul94f2b392005-06-28 12:44:16 +00004483static void
paul718e3742002-12-13 20:15:29 +00004484bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4485 afi_t afi, safi_t safi, struct bgp_info *del,
4486 struct bgp_aggregate *aggregate)
4487{
4488 struct bgp_table *table;
4489 struct bgp_node *top;
4490 struct bgp_node *rn;
4491 u_char origin;
4492 struct aspath *aspath = NULL;
4493 struct aspath *asmerge = NULL;
4494 struct community *community = NULL;
4495 struct community *commerge = NULL;
4496 struct in_addr nexthop;
4497 u_int32_t med = 0;
4498 struct bgp_info *ri;
4499 struct bgp_info *new;
4500 int first = 1;
4501 unsigned long match = 0;
4502
4503 /* Record adding route's nexthop and med. */
4504 if (rinew)
4505 {
4506 nexthop = rinew->attr->nexthop;
4507 med = rinew->attr->med;
4508 }
4509
4510 /* ORIGIN attribute: If at least one route among routes that are
4511 aggregated has ORIGIN with the value INCOMPLETE, then the
4512 aggregated route must have the ORIGIN attribute with the value
4513 INCOMPLETE. Otherwise, if at least one route among routes that
4514 are aggregated has ORIGIN with the value EGP, then the aggregated
4515 route must have the origin attribute with the value EGP. In all
4516 other case the value of the ORIGIN attribute of the aggregated
4517 route is INTERNAL. */
4518 origin = BGP_ORIGIN_IGP;
4519
4520 table = bgp->rib[afi][safi];
4521
4522 top = bgp_node_get (table, p);
4523 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4524 if (rn->p.prefixlen > p->prefixlen)
4525 {
4526 match = 0;
4527
4528 for (ri = rn->info; ri; ri = ri->next)
4529 {
4530 if (BGP_INFO_HOLDDOWN (ri))
4531 continue;
4532
4533 if (del && ri == del)
4534 continue;
4535
4536 if (! rinew && first)
4537 {
4538 nexthop = ri->attr->nexthop;
4539 med = ri->attr->med;
4540 first = 0;
4541 }
4542
4543#ifdef AGGREGATE_NEXTHOP_CHECK
4544 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4545 || ri->attr->med != med)
4546 {
4547 if (aspath)
4548 aspath_free (aspath);
4549 if (community)
4550 community_free (community);
4551 bgp_unlock_node (rn);
4552 bgp_unlock_node (top);
4553 return;
4554 }
4555#endif /* AGGREGATE_NEXTHOP_CHECK */
4556
4557 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4558 {
4559 if (aggregate->summary_only)
4560 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004561 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004562 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004563 match++;
4564 }
4565
4566 aggregate->count++;
4567
4568 if (aggregate->as_set)
4569 {
4570 if (origin < ri->attr->origin)
4571 origin = ri->attr->origin;
4572
4573 if (aspath)
4574 {
4575 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4576 aspath_free (aspath);
4577 aspath = asmerge;
4578 }
4579 else
4580 aspath = aspath_dup (ri->attr->aspath);
4581
4582 if (ri->attr->community)
4583 {
4584 if (community)
4585 {
4586 commerge = community_merge (community,
4587 ri->attr->community);
4588 community = community_uniq_sort (commerge);
4589 community_free (commerge);
4590 }
4591 else
4592 community = community_dup (ri->attr->community);
4593 }
4594 }
4595 }
4596 }
4597 if (match)
4598 bgp_process (bgp, rn, afi, safi);
4599 }
4600 bgp_unlock_node (top);
4601
4602 if (rinew)
4603 {
4604 aggregate->count++;
4605
4606 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004607 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004608
4609 if (aggregate->as_set)
4610 {
4611 if (origin < rinew->attr->origin)
4612 origin = rinew->attr->origin;
4613
4614 if (aspath)
4615 {
4616 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4617 aspath_free (aspath);
4618 aspath = asmerge;
4619 }
4620 else
4621 aspath = aspath_dup (rinew->attr->aspath);
4622
4623 if (rinew->attr->community)
4624 {
4625 if (community)
4626 {
4627 commerge = community_merge (community,
4628 rinew->attr->community);
4629 community = community_uniq_sort (commerge);
4630 community_free (commerge);
4631 }
4632 else
4633 community = community_dup (rinew->attr->community);
4634 }
4635 }
4636 }
4637
4638 if (aggregate->count > 0)
4639 {
4640 rn = bgp_node_get (table, p);
4641 new = bgp_info_new ();
4642 new->type = ZEBRA_ROUTE_BGP;
4643 new->sub_type = BGP_ROUTE_AGGREGATE;
4644 new->peer = bgp->peer_self;
4645 SET_FLAG (new->flags, BGP_INFO_VALID);
4646 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004647 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004648
4649 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004650 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004651 bgp_process (bgp, rn, afi, safi);
4652 }
4653 else
4654 {
4655 if (aspath)
4656 aspath_free (aspath);
4657 if (community)
4658 community_free (community);
4659 }
4660}
4661
4662void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4663 struct bgp_aggregate *);
4664
4665void
4666bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4667 struct bgp_info *ri, afi_t afi, safi_t safi)
4668{
4669 struct bgp_node *child;
4670 struct bgp_node *rn;
4671 struct bgp_aggregate *aggregate;
4672
4673 /* MPLS-VPN aggregation is not yet supported. */
4674 if (safi == SAFI_MPLS_VPN)
4675 return;
4676
4677 if (p->prefixlen == 0)
4678 return;
4679
4680 if (BGP_INFO_HOLDDOWN (ri))
4681 return;
4682
4683 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4684
4685 /* Aggregate address configuration check. */
4686 for (rn = child; rn; rn = rn->parent)
4687 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4688 {
4689 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004690 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004691 }
4692 bgp_unlock_node (child);
4693}
4694
4695void
4696bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4697 struct bgp_info *del, afi_t afi, safi_t safi)
4698{
4699 struct bgp_node *child;
4700 struct bgp_node *rn;
4701 struct bgp_aggregate *aggregate;
4702
4703 /* MPLS-VPN aggregation is not yet supported. */
4704 if (safi == SAFI_MPLS_VPN)
4705 return;
4706
4707 if (p->prefixlen == 0)
4708 return;
4709
4710 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4711
4712 /* Aggregate address configuration check. */
4713 for (rn = child; rn; rn = rn->parent)
4714 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4715 {
4716 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004717 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004718 }
4719 bgp_unlock_node (child);
4720}
4721
paul94f2b392005-06-28 12:44:16 +00004722static void
paul718e3742002-12-13 20:15:29 +00004723bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4724 struct bgp_aggregate *aggregate)
4725{
4726 struct bgp_table *table;
4727 struct bgp_node *top;
4728 struct bgp_node *rn;
4729 struct bgp_info *new;
4730 struct bgp_info *ri;
4731 unsigned long match;
4732 u_char origin = BGP_ORIGIN_IGP;
4733 struct aspath *aspath = NULL;
4734 struct aspath *asmerge = NULL;
4735 struct community *community = NULL;
4736 struct community *commerge = NULL;
4737
4738 table = bgp->rib[afi][safi];
4739
4740 /* Sanity check. */
4741 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4742 return;
4743 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4744 return;
4745
4746 /* If routes exists below this node, generate aggregate routes. */
4747 top = bgp_node_get (table, p);
4748 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4749 if (rn->p.prefixlen > p->prefixlen)
4750 {
4751 match = 0;
4752
4753 for (ri = rn->info; ri; ri = ri->next)
4754 {
4755 if (BGP_INFO_HOLDDOWN (ri))
4756 continue;
4757
4758 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4759 {
4760 /* summary-only aggregate route suppress aggregated
4761 route announcement. */
4762 if (aggregate->summary_only)
4763 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004764 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004765 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004766 match++;
4767 }
4768 /* as-set aggregate route generate origin, as path,
4769 community aggregation. */
4770 if (aggregate->as_set)
4771 {
4772 if (origin < ri->attr->origin)
4773 origin = ri->attr->origin;
4774
4775 if (aspath)
4776 {
4777 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4778 aspath_free (aspath);
4779 aspath = asmerge;
4780 }
4781 else
4782 aspath = aspath_dup (ri->attr->aspath);
4783
4784 if (ri->attr->community)
4785 {
4786 if (community)
4787 {
4788 commerge = community_merge (community,
4789 ri->attr->community);
4790 community = community_uniq_sort (commerge);
4791 community_free (commerge);
4792 }
4793 else
4794 community = community_dup (ri->attr->community);
4795 }
4796 }
4797 aggregate->count++;
4798 }
4799 }
4800
4801 /* If this node is suppressed, process the change. */
4802 if (match)
4803 bgp_process (bgp, rn, afi, safi);
4804 }
4805 bgp_unlock_node (top);
4806
4807 /* Add aggregate route to BGP table. */
4808 if (aggregate->count)
4809 {
4810 rn = bgp_node_get (table, p);
4811
4812 new = bgp_info_new ();
4813 new->type = ZEBRA_ROUTE_BGP;
4814 new->sub_type = BGP_ROUTE_AGGREGATE;
4815 new->peer = bgp->peer_self;
4816 SET_FLAG (new->flags, BGP_INFO_VALID);
4817 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004818 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004819
4820 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004821 bgp_unlock_node (rn);
4822
paul718e3742002-12-13 20:15:29 +00004823 /* Process change. */
4824 bgp_process (bgp, rn, afi, safi);
4825 }
4826}
4827
4828void
4829bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4830 safi_t safi, struct bgp_aggregate *aggregate)
4831{
4832 struct bgp_table *table;
4833 struct bgp_node *top;
4834 struct bgp_node *rn;
4835 struct bgp_info *ri;
4836 unsigned long match;
4837
4838 table = bgp->rib[afi][safi];
4839
4840 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4841 return;
4842 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4843 return;
4844
4845 /* If routes exists below this node, generate aggregate routes. */
4846 top = bgp_node_get (table, p);
4847 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4848 if (rn->p.prefixlen > p->prefixlen)
4849 {
4850 match = 0;
4851
4852 for (ri = rn->info; ri; ri = ri->next)
4853 {
4854 if (BGP_INFO_HOLDDOWN (ri))
4855 continue;
4856
4857 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4858 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004859 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004860 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004861 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004862
Paul Jakmafb982c22007-05-04 20:15:47 +00004863 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004864 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004865 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004866 match++;
4867 }
4868 }
4869 aggregate->count--;
4870 }
4871 }
4872
Paul Jakmafb982c22007-05-04 20:15:47 +00004873 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004874 if (match)
4875 bgp_process (bgp, rn, afi, safi);
4876 }
4877 bgp_unlock_node (top);
4878
4879 /* Delete aggregate route from BGP table. */
4880 rn = bgp_node_get (table, p);
4881
4882 for (ri = rn->info; ri; ri = ri->next)
4883 if (ri->peer == bgp->peer_self
4884 && ri->type == ZEBRA_ROUTE_BGP
4885 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4886 break;
4887
4888 /* Withdraw static BGP route from routing table. */
4889 if (ri)
4890 {
paul718e3742002-12-13 20:15:29 +00004891 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004892 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004893 }
4894
4895 /* Unlock bgp_node_lookup. */
4896 bgp_unlock_node (rn);
4897}
4898
4899/* Aggregate route attribute. */
4900#define AGGREGATE_SUMMARY_ONLY 1
4901#define AGGREGATE_AS_SET 1
4902
paul94f2b392005-06-28 12:44:16 +00004903static int
Robert Baysf6269b42010-08-05 10:26:28 -07004904bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4905 afi_t afi, safi_t safi)
4906{
4907 int ret;
4908 struct prefix p;
4909 struct bgp_node *rn;
4910 struct bgp *bgp;
4911 struct bgp_aggregate *aggregate;
4912
4913 /* Convert string to prefix structure. */
4914 ret = str2prefix (prefix_str, &p);
4915 if (!ret)
4916 {
4917 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4918 return CMD_WARNING;
4919 }
4920 apply_mask (&p);
4921
4922 /* Get BGP structure. */
4923 bgp = vty->index;
4924
4925 /* Old configuration check. */
4926 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4927 if (! rn)
4928 {
4929 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4930 VTY_NEWLINE);
4931 return CMD_WARNING;
4932 }
4933
4934 aggregate = rn->info;
4935 if (aggregate->safi & SAFI_UNICAST)
4936 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4937 if (aggregate->safi & SAFI_MULTICAST)
4938 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4939
4940 /* Unlock aggregate address configuration. */
4941 rn->info = NULL;
4942 bgp_aggregate_free (aggregate);
4943 bgp_unlock_node (rn);
4944 bgp_unlock_node (rn);
4945
4946 return CMD_SUCCESS;
4947}
4948
4949static int
4950bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004951 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004952 u_char summary_only, u_char as_set)
4953{
4954 int ret;
4955 struct prefix p;
4956 struct bgp_node *rn;
4957 struct bgp *bgp;
4958 struct bgp_aggregate *aggregate;
4959
4960 /* Convert string to prefix structure. */
4961 ret = str2prefix (prefix_str, &p);
4962 if (!ret)
4963 {
4964 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4965 return CMD_WARNING;
4966 }
4967 apply_mask (&p);
4968
4969 /* Get BGP structure. */
4970 bgp = vty->index;
4971
4972 /* Old configuration check. */
4973 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4974
4975 if (rn->info)
4976 {
4977 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004978 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004979 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4980 if (ret)
4981 {
Robert Bays368473f2010-08-05 10:26:29 -07004982 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4983 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004984 return CMD_WARNING;
4985 }
paul718e3742002-12-13 20:15:29 +00004986 }
4987
4988 /* Make aggregate address structure. */
4989 aggregate = bgp_aggregate_new ();
4990 aggregate->summary_only = summary_only;
4991 aggregate->as_set = as_set;
4992 aggregate->safi = safi;
4993 rn->info = aggregate;
4994
4995 /* Aggregate address insert into BGP routing table. */
4996 if (safi & SAFI_UNICAST)
4997 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4998 if (safi & SAFI_MULTICAST)
4999 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5000
5001 return CMD_SUCCESS;
5002}
5003
paul718e3742002-12-13 20:15:29 +00005004DEFUN (aggregate_address,
5005 aggregate_address_cmd,
5006 "aggregate-address A.B.C.D/M",
5007 "Configure BGP aggregate entries\n"
5008 "Aggregate prefix\n")
5009{
5010 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5011}
5012
5013DEFUN (aggregate_address_mask,
5014 aggregate_address_mask_cmd,
5015 "aggregate-address A.B.C.D A.B.C.D",
5016 "Configure BGP aggregate entries\n"
5017 "Aggregate address\n"
5018 "Aggregate mask\n")
5019{
5020 int ret;
5021 char prefix_str[BUFSIZ];
5022
5023 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5024
5025 if (! ret)
5026 {
5027 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5028 return CMD_WARNING;
5029 }
5030
5031 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5032 0, 0);
5033}
5034
5035DEFUN (aggregate_address_summary_only,
5036 aggregate_address_summary_only_cmd,
5037 "aggregate-address A.B.C.D/M summary-only",
5038 "Configure BGP aggregate entries\n"
5039 "Aggregate prefix\n"
5040 "Filter more specific routes from updates\n")
5041{
5042 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5043 AGGREGATE_SUMMARY_ONLY, 0);
5044}
5045
5046DEFUN (aggregate_address_mask_summary_only,
5047 aggregate_address_mask_summary_only_cmd,
5048 "aggregate-address A.B.C.D A.B.C.D summary-only",
5049 "Configure BGP aggregate entries\n"
5050 "Aggregate address\n"
5051 "Aggregate mask\n"
5052 "Filter more specific routes from updates\n")
5053{
5054 int ret;
5055 char prefix_str[BUFSIZ];
5056
5057 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5058
5059 if (! ret)
5060 {
5061 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5062 return CMD_WARNING;
5063 }
5064
5065 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5066 AGGREGATE_SUMMARY_ONLY, 0);
5067}
5068
5069DEFUN (aggregate_address_as_set,
5070 aggregate_address_as_set_cmd,
5071 "aggregate-address A.B.C.D/M as-set",
5072 "Configure BGP aggregate entries\n"
5073 "Aggregate prefix\n"
5074 "Generate AS set path information\n")
5075{
5076 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5077 0, AGGREGATE_AS_SET);
5078}
5079
5080DEFUN (aggregate_address_mask_as_set,
5081 aggregate_address_mask_as_set_cmd,
5082 "aggregate-address A.B.C.D A.B.C.D as-set",
5083 "Configure BGP aggregate entries\n"
5084 "Aggregate address\n"
5085 "Aggregate mask\n"
5086 "Generate AS set path information\n")
5087{
5088 int ret;
5089 char prefix_str[BUFSIZ];
5090
5091 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5092
5093 if (! ret)
5094 {
5095 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5096 return CMD_WARNING;
5097 }
5098
5099 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5100 0, AGGREGATE_AS_SET);
5101}
5102
5103
5104DEFUN (aggregate_address_as_set_summary,
5105 aggregate_address_as_set_summary_cmd,
5106 "aggregate-address A.B.C.D/M as-set summary-only",
5107 "Configure BGP aggregate entries\n"
5108 "Aggregate prefix\n"
5109 "Generate AS set path information\n"
5110 "Filter more specific routes from updates\n")
5111{
5112 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5113 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5114}
5115
5116ALIAS (aggregate_address_as_set_summary,
5117 aggregate_address_summary_as_set_cmd,
5118 "aggregate-address A.B.C.D/M summary-only as-set",
5119 "Configure BGP aggregate entries\n"
5120 "Aggregate prefix\n"
5121 "Filter more specific routes from updates\n"
5122 "Generate AS set path information\n")
5123
5124DEFUN (aggregate_address_mask_as_set_summary,
5125 aggregate_address_mask_as_set_summary_cmd,
5126 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5127 "Configure BGP aggregate entries\n"
5128 "Aggregate address\n"
5129 "Aggregate mask\n"
5130 "Generate AS set path information\n"
5131 "Filter more specific routes from updates\n")
5132{
5133 int ret;
5134 char prefix_str[BUFSIZ];
5135
5136 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5137
5138 if (! ret)
5139 {
5140 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5141 return CMD_WARNING;
5142 }
5143
5144 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5145 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5146}
5147
5148ALIAS (aggregate_address_mask_as_set_summary,
5149 aggregate_address_mask_summary_as_set_cmd,
5150 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5151 "Configure BGP aggregate entries\n"
5152 "Aggregate address\n"
5153 "Aggregate mask\n"
5154 "Filter more specific routes from updates\n"
5155 "Generate AS set path information\n")
5156
5157DEFUN (no_aggregate_address,
5158 no_aggregate_address_cmd,
5159 "no aggregate-address A.B.C.D/M",
5160 NO_STR
5161 "Configure BGP aggregate entries\n"
5162 "Aggregate prefix\n")
5163{
5164 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5165}
5166
5167ALIAS (no_aggregate_address,
5168 no_aggregate_address_summary_only_cmd,
5169 "no aggregate-address A.B.C.D/M summary-only",
5170 NO_STR
5171 "Configure BGP aggregate entries\n"
5172 "Aggregate prefix\n"
5173 "Filter more specific routes from updates\n")
5174
5175ALIAS (no_aggregate_address,
5176 no_aggregate_address_as_set_cmd,
5177 "no aggregate-address A.B.C.D/M as-set",
5178 NO_STR
5179 "Configure BGP aggregate entries\n"
5180 "Aggregate prefix\n"
5181 "Generate AS set path information\n")
5182
5183ALIAS (no_aggregate_address,
5184 no_aggregate_address_as_set_summary_cmd,
5185 "no aggregate-address A.B.C.D/M as-set summary-only",
5186 NO_STR
5187 "Configure BGP aggregate entries\n"
5188 "Aggregate prefix\n"
5189 "Generate AS set path information\n"
5190 "Filter more specific routes from updates\n")
5191
5192ALIAS (no_aggregate_address,
5193 no_aggregate_address_summary_as_set_cmd,
5194 "no aggregate-address A.B.C.D/M summary-only as-set",
5195 NO_STR
5196 "Configure BGP aggregate entries\n"
5197 "Aggregate prefix\n"
5198 "Filter more specific routes from updates\n"
5199 "Generate AS set path information\n")
5200
5201DEFUN (no_aggregate_address_mask,
5202 no_aggregate_address_mask_cmd,
5203 "no aggregate-address A.B.C.D A.B.C.D",
5204 NO_STR
5205 "Configure BGP aggregate entries\n"
5206 "Aggregate address\n"
5207 "Aggregate mask\n")
5208{
5209 int ret;
5210 char prefix_str[BUFSIZ];
5211
5212 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5213
5214 if (! ret)
5215 {
5216 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5217 return CMD_WARNING;
5218 }
5219
5220 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5221}
5222
5223ALIAS (no_aggregate_address_mask,
5224 no_aggregate_address_mask_summary_only_cmd,
5225 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5226 NO_STR
5227 "Configure BGP aggregate entries\n"
5228 "Aggregate address\n"
5229 "Aggregate mask\n"
5230 "Filter more specific routes from updates\n")
5231
5232ALIAS (no_aggregate_address_mask,
5233 no_aggregate_address_mask_as_set_cmd,
5234 "no aggregate-address A.B.C.D A.B.C.D as-set",
5235 NO_STR
5236 "Configure BGP aggregate entries\n"
5237 "Aggregate address\n"
5238 "Aggregate mask\n"
5239 "Generate AS set path information\n")
5240
5241ALIAS (no_aggregate_address_mask,
5242 no_aggregate_address_mask_as_set_summary_cmd,
5243 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5244 NO_STR
5245 "Configure BGP aggregate entries\n"
5246 "Aggregate address\n"
5247 "Aggregate mask\n"
5248 "Generate AS set path information\n"
5249 "Filter more specific routes from updates\n")
5250
5251ALIAS (no_aggregate_address_mask,
5252 no_aggregate_address_mask_summary_as_set_cmd,
5253 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5254 NO_STR
5255 "Configure BGP aggregate entries\n"
5256 "Aggregate address\n"
5257 "Aggregate mask\n"
5258 "Filter more specific routes from updates\n"
5259 "Generate AS set path information\n")
5260
5261#ifdef HAVE_IPV6
5262DEFUN (ipv6_aggregate_address,
5263 ipv6_aggregate_address_cmd,
5264 "aggregate-address X:X::X:X/M",
5265 "Configure BGP aggregate entries\n"
5266 "Aggregate prefix\n")
5267{
5268 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5269}
5270
5271DEFUN (ipv6_aggregate_address_summary_only,
5272 ipv6_aggregate_address_summary_only_cmd,
5273 "aggregate-address X:X::X:X/M summary-only",
5274 "Configure BGP aggregate entries\n"
5275 "Aggregate prefix\n"
5276 "Filter more specific routes from updates\n")
5277{
5278 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5279 AGGREGATE_SUMMARY_ONLY, 0);
5280}
5281
5282DEFUN (no_ipv6_aggregate_address,
5283 no_ipv6_aggregate_address_cmd,
5284 "no aggregate-address X:X::X:X/M",
5285 NO_STR
5286 "Configure BGP aggregate entries\n"
5287 "Aggregate prefix\n")
5288{
5289 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5290}
5291
5292DEFUN (no_ipv6_aggregate_address_summary_only,
5293 no_ipv6_aggregate_address_summary_only_cmd,
5294 "no aggregate-address X:X::X:X/M summary-only",
5295 NO_STR
5296 "Configure BGP aggregate entries\n"
5297 "Aggregate prefix\n"
5298 "Filter more specific routes from updates\n")
5299{
5300 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5301}
5302
5303ALIAS (ipv6_aggregate_address,
5304 old_ipv6_aggregate_address_cmd,
5305 "ipv6 bgp aggregate-address X:X::X:X/M",
5306 IPV6_STR
5307 BGP_STR
5308 "Configure BGP aggregate entries\n"
5309 "Aggregate prefix\n")
5310
5311ALIAS (ipv6_aggregate_address_summary_only,
5312 old_ipv6_aggregate_address_summary_only_cmd,
5313 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5314 IPV6_STR
5315 BGP_STR
5316 "Configure BGP aggregate entries\n"
5317 "Aggregate prefix\n"
5318 "Filter more specific routes from updates\n")
5319
5320ALIAS (no_ipv6_aggregate_address,
5321 old_no_ipv6_aggregate_address_cmd,
5322 "no ipv6 bgp aggregate-address X:X::X:X/M",
5323 NO_STR
5324 IPV6_STR
5325 BGP_STR
5326 "Configure BGP aggregate entries\n"
5327 "Aggregate prefix\n")
5328
5329ALIAS (no_ipv6_aggregate_address_summary_only,
5330 old_no_ipv6_aggregate_address_summary_only_cmd,
5331 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5332 NO_STR
5333 IPV6_STR
5334 BGP_STR
5335 "Configure BGP aggregate entries\n"
5336 "Aggregate prefix\n"
5337 "Filter more specific routes from updates\n")
5338#endif /* HAVE_IPV6 */
5339
5340/* Redistribute route treatment. */
5341void
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005342bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5343 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005344 u_int32_t metric, u_char type)
5345{
5346 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005347 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005348 struct bgp_info *new;
5349 struct bgp_info *bi;
5350 struct bgp_info info;
5351 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005352 struct attr attr = { 0 };
5353 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005354 struct attr *new_attr;
5355 afi_t afi;
5356 int ret;
5357
5358 /* Make default attribute. */
5359 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5360 if (nexthop)
5361 attr.nexthop = *nexthop;
5362
Stephen Hemmingerf04a80a2011-12-06 14:51:10 +04005363#ifdef HAVE_IPV6
5364 if (nexthop6)
5365 {
5366 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5367 extra->mp_nexthop_global = *nexthop6;
5368 extra->mp_nexthop_len = 16;
5369 }
5370#endif
5371
paul718e3742002-12-13 20:15:29 +00005372 attr.med = metric;
5373 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5374
paul1eb8ef22005-04-07 07:30:20 +00005375 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005376 {
5377 afi = family2afi (p->family);
5378
5379 if (bgp->redist[afi][type])
5380 {
5381 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005382 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005383
5384 if (bgp->redist_metric_flag[afi][type])
5385 attr_new.med = bgp->redist_metric[afi][type];
5386
5387 /* Apply route-map. */
5388 if (bgp->rmap[afi][type].map)
5389 {
5390 info.peer = bgp->peer_self;
5391 info.attr = &attr_new;
5392
paulfee0f4c2004-09-13 05:12:46 +00005393 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5394
paul718e3742002-12-13 20:15:29 +00005395 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5396 &info);
paulfee0f4c2004-09-13 05:12:46 +00005397
5398 bgp->peer_self->rmap_type = 0;
5399
paul718e3742002-12-13 20:15:29 +00005400 if (ret == RMAP_DENYMATCH)
5401 {
5402 /* Free uninterned attribute. */
5403 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005404 bgp_attr_extra_free (&attr_new);
5405
paul718e3742002-12-13 20:15:29 +00005406 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005407 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005408 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005409 bgp_redistribute_delete (p, type);
5410 return;
5411 }
5412 }
5413
Paul Jakmafb982c22007-05-04 20:15:47 +00005414 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5415 afi, SAFI_UNICAST, p, NULL);
5416
paul718e3742002-12-13 20:15:29 +00005417 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005418 bgp_attr_extra_free (&attr_new);
5419
paul718e3742002-12-13 20:15:29 +00005420 for (bi = bn->info; bi; bi = bi->next)
5421 if (bi->peer == bgp->peer_self
5422 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5423 break;
5424
5425 if (bi)
5426 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005427 if (attrhash_cmp (bi->attr, new_attr) &&
5428 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005429 {
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005430 bgp_attr_unintern (&new_attr);
5431 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005432 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005433 bgp_unlock_node (bn);
5434 return;
5435 }
5436 else
5437 {
5438 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005439 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005440
5441 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005442 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5443 bgp_info_restore(bn, bi);
5444 else
5445 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005446 bgp_attr_unintern (&bi->attr);
paul718e3742002-12-13 20:15:29 +00005447 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005448 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005449
5450 /* Process change. */
5451 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5452 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5453 bgp_unlock_node (bn);
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005454 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005455 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005456 return;
5457 }
5458 }
5459
5460 new = bgp_info_new ();
5461 new->type = type;
5462 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5463 new->peer = bgp->peer_self;
5464 SET_FLAG (new->flags, BGP_INFO_VALID);
5465 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005466 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005467
5468 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5469 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005470 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005471 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5472 }
5473 }
5474
5475 /* Unintern original. */
Paul Jakmaf6f434b2010-11-23 21:28:03 +00005476 aspath_unintern (&attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005477 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005478}
5479
5480void
5481bgp_redistribute_delete (struct prefix *p, u_char type)
5482{
5483 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005484 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005485 afi_t afi;
5486 struct bgp_node *rn;
5487 struct bgp_info *ri;
5488
paul1eb8ef22005-04-07 07:30:20 +00005489 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005490 {
5491 afi = family2afi (p->family);
5492
5493 if (bgp->redist[afi][type])
5494 {
paulfee0f4c2004-09-13 05:12:46 +00005495 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005496
5497 for (ri = rn->info; ri; ri = ri->next)
5498 if (ri->peer == bgp->peer_self
5499 && ri->type == type)
5500 break;
5501
5502 if (ri)
5503 {
5504 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005505 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005506 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005507 }
5508 bgp_unlock_node (rn);
5509 }
5510 }
5511}
5512
5513/* Withdraw specified route type's route. */
5514void
5515bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5516{
5517 struct bgp_node *rn;
5518 struct bgp_info *ri;
5519 struct bgp_table *table;
5520
5521 table = bgp->rib[afi][SAFI_UNICAST];
5522
5523 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5524 {
5525 for (ri = rn->info; ri; ri = ri->next)
5526 if (ri->peer == bgp->peer_self
5527 && ri->type == type)
5528 break;
5529
5530 if (ri)
5531 {
5532 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005533 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005534 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005535 }
5536 }
5537}
5538
5539/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005540static void
paul718e3742002-12-13 20:15:29 +00005541route_vty_out_route (struct prefix *p, struct vty *vty)
5542{
5543 int len;
5544 u_int32_t destination;
5545 char buf[BUFSIZ];
5546
5547 if (p->family == AF_INET)
5548 {
5549 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5550 destination = ntohl (p->u.prefix4.s_addr);
5551
5552 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5553 || (IN_CLASSB (destination) && p->prefixlen == 16)
5554 || (IN_CLASSA (destination) && p->prefixlen == 8)
5555 || p->u.prefix4.s_addr == 0)
5556 {
5557 /* When mask is natural, mask is not displayed. */
5558 }
5559 else
5560 len += vty_out (vty, "/%d", p->prefixlen);
5561 }
5562 else
5563 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5564 p->prefixlen);
5565
5566 len = 17 - len;
5567 if (len < 1)
5568 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5569 else
5570 vty_out (vty, "%*s", len, " ");
5571}
5572
paul718e3742002-12-13 20:15:29 +00005573enum bgp_display_type
5574{
5575 normal_list,
5576};
5577
paulb40d9392005-08-22 22:34:41 +00005578/* Print the short form route status for a bgp_info */
5579static void
5580route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005581{
paulb40d9392005-08-22 22:34:41 +00005582 /* Route status display. */
5583 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5584 vty_out (vty, "R");
5585 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005586 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005587 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005588 vty_out (vty, "s");
5589 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5590 vty_out (vty, "*");
5591 else
5592 vty_out (vty, " ");
5593
5594 /* Selected */
5595 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5596 vty_out (vty, "h");
5597 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5598 vty_out (vty, "d");
5599 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5600 vty_out (vty, ">");
5601 else
5602 vty_out (vty, " ");
5603
5604 /* Internal route. */
5605 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5606 vty_out (vty, "i");
5607 else
paulb40d9392005-08-22 22:34:41 +00005608 vty_out (vty, " ");
5609}
5610
5611/* called from terminal list command */
5612void
5613route_vty_out (struct vty *vty, struct prefix *p,
5614 struct bgp_info *binfo, int display, safi_t safi)
5615{
5616 struct attr *attr;
5617
5618 /* short status lead text */
5619 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005620
5621 /* print prefix and mask */
5622 if (! display)
5623 route_vty_out_route (p, vty);
5624 else
5625 vty_out (vty, "%*s", 17, " ");
5626
5627 /* Print attribute */
5628 attr = binfo->attr;
5629 if (attr)
5630 {
5631 if (p->family == AF_INET)
5632 {
5633 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005634 vty_out (vty, "%-16s",
5635 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005636 else
5637 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5638 }
5639#ifdef HAVE_IPV6
5640 else if (p->family == AF_INET6)
5641 {
5642 int len;
5643 char buf[BUFSIZ];
5644
5645 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005646 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5647 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005648 len = 16 - len;
5649 if (len < 1)
5650 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5651 else
5652 vty_out (vty, "%*s", len, " ");
5653 }
5654#endif /* HAVE_IPV6 */
5655
5656 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005657 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005658 else
5659 vty_out (vty, " ");
5660
5661 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005662 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005663 else
5664 vty_out (vty, " ");
5665
Paul Jakmafb982c22007-05-04 20:15:47 +00005666 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005667
Paul Jakmab2518c12006-05-12 23:48:40 +00005668 /* Print aspath */
5669 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005670 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005671
Paul Jakmab2518c12006-05-12 23:48:40 +00005672 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005673 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005674 }
paul718e3742002-12-13 20:15:29 +00005675 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005676}
5677
5678/* called from terminal list command */
5679void
5680route_vty_out_tmp (struct vty *vty, struct prefix *p,
5681 struct attr *attr, safi_t safi)
5682{
5683 /* Route status display. */
5684 vty_out (vty, "*");
5685 vty_out (vty, ">");
5686 vty_out (vty, " ");
5687
5688 /* print prefix and mask */
5689 route_vty_out_route (p, vty);
5690
5691 /* Print attribute */
5692 if (attr)
5693 {
5694 if (p->family == AF_INET)
5695 {
5696 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005697 vty_out (vty, "%-16s",
5698 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005699 else
5700 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5701 }
5702#ifdef HAVE_IPV6
5703 else if (p->family == AF_INET6)
5704 {
5705 int len;
5706 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005707
5708 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005709
5710 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005711 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5712 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005713 len = 16 - len;
5714 if (len < 1)
5715 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5716 else
5717 vty_out (vty, "%*s", len, " ");
5718 }
5719#endif /* HAVE_IPV6 */
5720
5721 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005722 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005723 else
5724 vty_out (vty, " ");
5725
5726 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005727 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005728 else
5729 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005730
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005731 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005732
Paul Jakmab2518c12006-05-12 23:48:40 +00005733 /* Print aspath */
5734 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005735 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005736
Paul Jakmab2518c12006-05-12 23:48:40 +00005737 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005738 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005739 }
paul718e3742002-12-13 20:15:29 +00005740
5741 vty_out (vty, "%s", VTY_NEWLINE);
5742}
5743
ajs5a646652004-11-05 01:25:55 +00005744void
paul718e3742002-12-13 20:15:29 +00005745route_vty_out_tag (struct vty *vty, struct prefix *p,
5746 struct bgp_info *binfo, int display, safi_t safi)
5747{
5748 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005749 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005750
5751 if (!binfo->extra)
5752 return;
5753
paulb40d9392005-08-22 22:34:41 +00005754 /* short status lead text */
5755 route_vty_short_status_out (vty, binfo);
5756
paul718e3742002-12-13 20:15:29 +00005757 /* print prefix and mask */
5758 if (! display)
5759 route_vty_out_route (p, vty);
5760 else
5761 vty_out (vty, "%*s", 17, " ");
5762
5763 /* Print attribute */
5764 attr = binfo->attr;
5765 if (attr)
5766 {
5767 if (p->family == AF_INET)
5768 {
5769 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005770 vty_out (vty, "%-16s",
5771 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005772 else
5773 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5774 }
5775#ifdef HAVE_IPV6
5776 else if (p->family == AF_INET6)
5777 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005778 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005779 char buf[BUFSIZ];
5780 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005781 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005782 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005783 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5784 buf, BUFSIZ));
5785 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005786 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005787 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5788 buf, BUFSIZ),
5789 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5790 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005791
5792 }
5793#endif /* HAVE_IPV6 */
5794 }
5795
Paul Jakmafb982c22007-05-04 20:15:47 +00005796 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005797
5798 vty_out (vty, "notag/%d", label);
5799
5800 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005801}
5802
5803/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005804static void
paul718e3742002-12-13 20:15:29 +00005805damp_route_vty_out (struct vty *vty, struct prefix *p,
5806 struct bgp_info *binfo, int display, safi_t safi)
5807{
5808 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005809 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005810 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005811
paulb40d9392005-08-22 22:34:41 +00005812 /* short status lead text */
5813 route_vty_short_status_out (vty, binfo);
5814
paul718e3742002-12-13 20:15:29 +00005815 /* print prefix and mask */
5816 if (! display)
5817 route_vty_out_route (p, vty);
5818 else
5819 vty_out (vty, "%*s", 17, " ");
5820
5821 len = vty_out (vty, "%s", binfo->peer->host);
5822 len = 17 - len;
5823 if (len < 1)
5824 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5825 else
5826 vty_out (vty, "%*s", len, " ");
5827
Chris Caputo50aef6f2009-06-23 06:06:49 +00005828 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005829
5830 /* Print attribute */
5831 attr = binfo->attr;
5832 if (attr)
5833 {
5834 /* Print aspath */
5835 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005836 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005837
5838 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005839 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005840 }
5841 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005842}
5843
paul718e3742002-12-13 20:15:29 +00005844/* flap route */
ajs5a646652004-11-05 01:25:55 +00005845static void
paul718e3742002-12-13 20:15:29 +00005846flap_route_vty_out (struct vty *vty, struct prefix *p,
5847 struct bgp_info *binfo, int display, safi_t safi)
5848{
5849 struct attr *attr;
5850 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005851 char timebuf[BGP_UPTIME_LEN];
5852 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005853
5854 if (!binfo->extra)
5855 return;
5856
5857 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005858
paulb40d9392005-08-22 22:34:41 +00005859 /* short status lead text */
5860 route_vty_short_status_out (vty, binfo);
5861
paul718e3742002-12-13 20:15:29 +00005862 /* print prefix and mask */
5863 if (! display)
5864 route_vty_out_route (p, vty);
5865 else
5866 vty_out (vty, "%*s", 17, " ");
5867
5868 len = vty_out (vty, "%s", binfo->peer->host);
5869 len = 16 - len;
5870 if (len < 1)
5871 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5872 else
5873 vty_out (vty, "%*s", len, " ");
5874
5875 len = vty_out (vty, "%d", bdi->flap);
5876 len = 5 - len;
5877 if (len < 1)
5878 vty_out (vty, " ");
5879 else
5880 vty_out (vty, "%*s ", len, " ");
5881
5882 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5883 timebuf, BGP_UPTIME_LEN));
5884
5885 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5886 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005887 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005888 else
5889 vty_out (vty, "%*s ", 8, " ");
5890
5891 /* Print attribute */
5892 attr = binfo->attr;
5893 if (attr)
5894 {
5895 /* Print aspath */
5896 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005897 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005898
5899 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005900 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005901 }
5902 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005903}
5904
paul94f2b392005-06-28 12:44:16 +00005905static void
paul718e3742002-12-13 20:15:29 +00005906route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5907 struct bgp_info *binfo, afi_t afi, safi_t safi)
5908{
5909 char buf[INET6_ADDRSTRLEN];
5910 char buf1[BUFSIZ];
5911 struct attr *attr;
5912 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005913#ifdef HAVE_CLOCK_MONOTONIC
5914 time_t tbuf;
5915#endif
paul718e3742002-12-13 20:15:29 +00005916
5917 attr = binfo->attr;
5918
5919 if (attr)
5920 {
5921 /* Line1 display AS-path, Aggregator */
5922 if (attr->aspath)
5923 {
5924 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005925 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005926 vty_out (vty, "Local");
5927 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005928 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005929 }
5930
paulb40d9392005-08-22 22:34:41 +00005931 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5932 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005933 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5934 vty_out (vty, ", (stale)");
5935 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005936 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005937 attr->extra->aggregator_as,
5938 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005939 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5940 vty_out (vty, ", (Received from a RR-client)");
5941 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5942 vty_out (vty, ", (Received from a RS-client)");
5943 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5944 vty_out (vty, ", (history entry)");
5945 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5946 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005947 vty_out (vty, "%s", VTY_NEWLINE);
5948
5949 /* Line2 display Next-hop, Neighbor, Router-id */
5950 if (p->family == AF_INET)
5951 {
5952 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005953 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005954 inet_ntoa (attr->nexthop));
5955 }
5956#ifdef HAVE_IPV6
5957 else
5958 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005959 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005960 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005961 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005962 buf, INET6_ADDRSTRLEN));
5963 }
5964#endif /* HAVE_IPV6 */
5965
5966 if (binfo->peer == bgp->peer_self)
5967 {
5968 vty_out (vty, " from %s ",
5969 p->family == AF_INET ? "0.0.0.0" : "::");
5970 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5971 }
5972 else
5973 {
5974 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5975 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005976 else if (binfo->extra && binfo->extra->igpmetric)
Jorge Boncompte [DTI2]ddc943d2012-04-13 13:46:07 +02005977 vty_out (vty, " (metric %u)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005978 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005979 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005980 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005981 else
5982 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5983 }
5984 vty_out (vty, "%s", VTY_NEWLINE);
5985
5986#ifdef HAVE_IPV6
5987 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005988 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005989 {
5990 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005991 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005992 buf, INET6_ADDRSTRLEN),
5993 VTY_NEWLINE);
5994 }
5995#endif /* HAVE_IPV6 */
5996
5997 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5998 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5999
6000 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006001 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00006002
6003 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006004 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00006005 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006006 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00006007
Paul Jakmafb982c22007-05-04 20:15:47 +00006008 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07006009 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006010
6011 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6012 vty_out (vty, ", valid");
6013
6014 if (binfo->peer != bgp->peer_self)
6015 {
6016 if (binfo->peer->as == binfo->peer->local_as)
6017 vty_out (vty, ", internal");
6018 else
6019 vty_out (vty, ", %s",
6020 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6021 }
6022 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6023 vty_out (vty, ", aggregated, local");
6024 else if (binfo->type != ZEBRA_ROUTE_BGP)
6025 vty_out (vty, ", sourced");
6026 else
6027 vty_out (vty, ", sourced, local");
6028
6029 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6030 vty_out (vty, ", atomic-aggregate");
6031
Josh Baileyde8d5df2011-07-20 20:46:01 -07006032 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6033 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6034 bgp_info_mpath_count (binfo)))
6035 vty_out (vty, ", multipath");
6036
paul718e3742002-12-13 20:15:29 +00006037 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6038 vty_out (vty, ", best");
6039
6040 vty_out (vty, "%s", VTY_NEWLINE);
6041
6042 /* Line 4 display Community */
6043 if (attr->community)
6044 vty_out (vty, " Community: %s%s", attr->community->str,
6045 VTY_NEWLINE);
6046
6047 /* Line 5 display Extended-community */
6048 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006049 vty_out (vty, " Extended Community: %s%s",
6050 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006051
6052 /* Line 6 display Originator, Cluster-id */
6053 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6054 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6055 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006056 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006057 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006058 vty_out (vty, " Originator: %s",
6059 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006060
6061 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6062 {
6063 int i;
6064 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006065 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6066 vty_out (vty, "%s ",
6067 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006068 }
6069 vty_out (vty, "%s", VTY_NEWLINE);
6070 }
Paul Jakma41367172007-08-06 15:24:51 +00006071
Paul Jakmafb982c22007-05-04 20:15:47 +00006072 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006073 bgp_damp_info_vty (vty, binfo);
6074
6075 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006076#ifdef HAVE_CLOCK_MONOTONIC
6077 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006078 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006079#else
6080 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6081#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006082 }
6083 vty_out (vty, "%s", VTY_NEWLINE);
6084}
6085
paulb40d9392005-08-22 22:34:41 +00006086#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 +00006087#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006088#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6089#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6090#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6091
6092enum bgp_show_type
6093{
6094 bgp_show_type_normal,
6095 bgp_show_type_regexp,
6096 bgp_show_type_prefix_list,
6097 bgp_show_type_filter_list,
6098 bgp_show_type_route_map,
6099 bgp_show_type_neighbor,
6100 bgp_show_type_cidr_only,
6101 bgp_show_type_prefix_longer,
6102 bgp_show_type_community_all,
6103 bgp_show_type_community,
6104 bgp_show_type_community_exact,
6105 bgp_show_type_community_list,
6106 bgp_show_type_community_list_exact,
6107 bgp_show_type_flap_statistics,
6108 bgp_show_type_flap_address,
6109 bgp_show_type_flap_prefix,
6110 bgp_show_type_flap_cidr_only,
6111 bgp_show_type_flap_regexp,
6112 bgp_show_type_flap_filter_list,
6113 bgp_show_type_flap_prefix_list,
6114 bgp_show_type_flap_prefix_longer,
6115 bgp_show_type_flap_route_map,
6116 bgp_show_type_flap_neighbor,
6117 bgp_show_type_dampend_paths,
6118 bgp_show_type_damp_neighbor
6119};
6120
ajs5a646652004-11-05 01:25:55 +00006121static int
paulfee0f4c2004-09-13 05:12:46 +00006122bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006123 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006124{
paul718e3742002-12-13 20:15:29 +00006125 struct bgp_info *ri;
6126 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006127 int header = 1;
paul718e3742002-12-13 20:15:29 +00006128 int display;
ajs5a646652004-11-05 01:25:55 +00006129 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006130
6131 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006132 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006133
paul718e3742002-12-13 20:15:29 +00006134 /* Start processing of routes. */
6135 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6136 if (rn->info != NULL)
6137 {
6138 display = 0;
6139
6140 for (ri = rn->info; ri; ri = ri->next)
6141 {
ajs5a646652004-11-05 01:25:55 +00006142 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006143 || type == bgp_show_type_flap_address
6144 || type == bgp_show_type_flap_prefix
6145 || type == bgp_show_type_flap_cidr_only
6146 || type == bgp_show_type_flap_regexp
6147 || type == bgp_show_type_flap_filter_list
6148 || type == bgp_show_type_flap_prefix_list
6149 || type == bgp_show_type_flap_prefix_longer
6150 || type == bgp_show_type_flap_route_map
6151 || type == bgp_show_type_flap_neighbor
6152 || type == bgp_show_type_dampend_paths
6153 || type == bgp_show_type_damp_neighbor)
6154 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006155 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006156 continue;
6157 }
6158 if (type == bgp_show_type_regexp
6159 || type == bgp_show_type_flap_regexp)
6160 {
ajs5a646652004-11-05 01:25:55 +00006161 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006162
6163 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6164 continue;
6165 }
6166 if (type == bgp_show_type_prefix_list
6167 || type == bgp_show_type_flap_prefix_list)
6168 {
ajs5a646652004-11-05 01:25:55 +00006169 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006170
6171 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6172 continue;
6173 }
6174 if (type == bgp_show_type_filter_list
6175 || type == bgp_show_type_flap_filter_list)
6176 {
ajs5a646652004-11-05 01:25:55 +00006177 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006178
6179 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6180 continue;
6181 }
6182 if (type == bgp_show_type_route_map
6183 || type == bgp_show_type_flap_route_map)
6184 {
ajs5a646652004-11-05 01:25:55 +00006185 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006186 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006187 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006188 int ret;
6189
Paul Jakmafb982c22007-05-04 20:15:47 +00006190 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006191 binfo.peer = ri->peer;
6192 binfo.attr = &dummy_attr;
6193
6194 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006195
6196 bgp_attr_extra_free (&dummy_attr);
6197
paul718e3742002-12-13 20:15:29 +00006198 if (ret == RMAP_DENYMATCH)
6199 continue;
6200 }
6201 if (type == bgp_show_type_neighbor
6202 || type == bgp_show_type_flap_neighbor
6203 || type == bgp_show_type_damp_neighbor)
6204 {
ajs5a646652004-11-05 01:25:55 +00006205 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006206
6207 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6208 continue;
6209 }
6210 if (type == bgp_show_type_cidr_only
6211 || type == bgp_show_type_flap_cidr_only)
6212 {
6213 u_int32_t destination;
6214
6215 destination = ntohl (rn->p.u.prefix4.s_addr);
6216 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6217 continue;
6218 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6219 continue;
6220 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6221 continue;
6222 }
6223 if (type == bgp_show_type_prefix_longer
6224 || type == bgp_show_type_flap_prefix_longer)
6225 {
ajs5a646652004-11-05 01:25:55 +00006226 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006227
6228 if (! prefix_match (p, &rn->p))
6229 continue;
6230 }
6231 if (type == bgp_show_type_community_all)
6232 {
6233 if (! ri->attr->community)
6234 continue;
6235 }
6236 if (type == bgp_show_type_community)
6237 {
ajs5a646652004-11-05 01:25:55 +00006238 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006239
6240 if (! ri->attr->community ||
6241 ! community_match (ri->attr->community, com))
6242 continue;
6243 }
6244 if (type == bgp_show_type_community_exact)
6245 {
ajs5a646652004-11-05 01:25:55 +00006246 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006247
6248 if (! ri->attr->community ||
6249 ! community_cmp (ri->attr->community, com))
6250 continue;
6251 }
6252 if (type == bgp_show_type_community_list)
6253 {
ajs5a646652004-11-05 01:25:55 +00006254 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006255
6256 if (! community_list_match (ri->attr->community, list))
6257 continue;
6258 }
6259 if (type == bgp_show_type_community_list_exact)
6260 {
ajs5a646652004-11-05 01:25:55 +00006261 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006262
6263 if (! community_list_exact_match (ri->attr->community, list))
6264 continue;
6265 }
6266 if (type == bgp_show_type_flap_address
6267 || type == bgp_show_type_flap_prefix)
6268 {
ajs5a646652004-11-05 01:25:55 +00006269 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006270
6271 if (! prefix_match (&rn->p, p))
6272 continue;
6273
6274 if (type == bgp_show_type_flap_prefix)
6275 if (p->prefixlen != rn->p.prefixlen)
6276 continue;
6277 }
6278 if (type == bgp_show_type_dampend_paths
6279 || type == bgp_show_type_damp_neighbor)
6280 {
6281 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6282 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6283 continue;
6284 }
6285
6286 if (header)
6287 {
hasso93406d82005-02-02 14:40:33 +00006288 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6289 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6290 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006291 if (type == bgp_show_type_dampend_paths
6292 || type == bgp_show_type_damp_neighbor)
6293 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6294 else if (type == bgp_show_type_flap_statistics
6295 || type == bgp_show_type_flap_address
6296 || type == bgp_show_type_flap_prefix
6297 || type == bgp_show_type_flap_cidr_only
6298 || type == bgp_show_type_flap_regexp
6299 || type == bgp_show_type_flap_filter_list
6300 || type == bgp_show_type_flap_prefix_list
6301 || type == bgp_show_type_flap_prefix_longer
6302 || type == bgp_show_type_flap_route_map
6303 || type == bgp_show_type_flap_neighbor)
6304 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6305 else
6306 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006307 header = 0;
6308 }
6309
6310 if (type == bgp_show_type_dampend_paths
6311 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006312 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006313 else if (type == bgp_show_type_flap_statistics
6314 || type == bgp_show_type_flap_address
6315 || type == bgp_show_type_flap_prefix
6316 || type == bgp_show_type_flap_cidr_only
6317 || type == bgp_show_type_flap_regexp
6318 || type == bgp_show_type_flap_filter_list
6319 || type == bgp_show_type_flap_prefix_list
6320 || type == bgp_show_type_flap_prefix_longer
6321 || type == bgp_show_type_flap_route_map
6322 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006323 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006324 else
ajs5a646652004-11-05 01:25:55 +00006325 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006326 display++;
6327 }
6328 if (display)
ajs5a646652004-11-05 01:25:55 +00006329 output_count++;
paul718e3742002-12-13 20:15:29 +00006330 }
6331
6332 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006333 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006334 {
6335 if (type == bgp_show_type_normal)
6336 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6337 }
6338 else
6339 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006340 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006341
6342 return CMD_SUCCESS;
6343}
6344
ajs5a646652004-11-05 01:25:55 +00006345static int
paulfee0f4c2004-09-13 05:12:46 +00006346bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006347 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006348{
6349 struct bgp_table *table;
6350
6351 if (bgp == NULL) {
6352 bgp = bgp_get_default ();
6353 }
6354
6355 if (bgp == NULL)
6356 {
6357 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6358 return CMD_WARNING;
6359 }
6360
6361
6362 table = bgp->rib[afi][safi];
6363
ajs5a646652004-11-05 01:25:55 +00006364 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006365}
6366
paul718e3742002-12-13 20:15:29 +00006367/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006368static void
paul718e3742002-12-13 20:15:29 +00006369route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6370 struct bgp_node *rn,
6371 struct prefix_rd *prd, afi_t afi, safi_t safi)
6372{
6373 struct bgp_info *ri;
6374 struct prefix *p;
6375 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006376 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006377 char buf1[INET6_ADDRSTRLEN];
6378 char buf2[INET6_ADDRSTRLEN];
6379 int count = 0;
6380 int best = 0;
6381 int suppress = 0;
6382 int no_export = 0;
6383 int no_advertise = 0;
6384 int local_as = 0;
6385 int first = 0;
6386
6387 p = &rn->p;
6388 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6389 (safi == SAFI_MPLS_VPN ?
6390 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6391 safi == SAFI_MPLS_VPN ? ":" : "",
6392 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6393 p->prefixlen, VTY_NEWLINE);
6394
6395 for (ri = rn->info; ri; ri = ri->next)
6396 {
6397 count++;
6398 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6399 {
6400 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006401 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006402 suppress = 1;
6403 if (ri->attr->community != NULL)
6404 {
6405 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6406 no_advertise = 1;
6407 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6408 no_export = 1;
6409 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6410 local_as = 1;
6411 }
6412 }
6413 }
6414
6415 vty_out (vty, "Paths: (%d available", count);
6416 if (best)
6417 {
6418 vty_out (vty, ", best #%d", best);
6419 if (safi == SAFI_UNICAST)
6420 vty_out (vty, ", table Default-IP-Routing-Table");
6421 }
6422 else
6423 vty_out (vty, ", no best path");
6424 if (no_advertise)
6425 vty_out (vty, ", not advertised to any peer");
6426 else if (no_export)
6427 vty_out (vty, ", not advertised to EBGP peer");
6428 else if (local_as)
6429 vty_out (vty, ", not advertised outside local AS");
6430 if (suppress)
6431 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6432 vty_out (vty, ")%s", VTY_NEWLINE);
6433
6434 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006435 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006436 {
6437 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6438 {
6439 if (! first)
6440 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6441 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6442 first = 1;
6443 }
6444 }
6445 if (! first)
6446 vty_out (vty, " Not advertised to any peer");
6447 vty_out (vty, "%s", VTY_NEWLINE);
6448}
6449
6450/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006451static int
paulfee0f4c2004-09-13 05:12:46 +00006452bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006453 struct bgp_table *rib, const char *ip_str,
6454 afi_t afi, safi_t safi, struct prefix_rd *prd,
6455 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006456{
6457 int ret;
6458 int header;
6459 int display = 0;
6460 struct prefix match;
6461 struct bgp_node *rn;
6462 struct bgp_node *rm;
6463 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006464 struct bgp_table *table;
6465
paul718e3742002-12-13 20:15:29 +00006466 /* Check IP address argument. */
6467 ret = str2prefix (ip_str, &match);
6468 if (! ret)
6469 {
6470 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6471 return CMD_WARNING;
6472 }
6473
6474 match.family = afi2family (afi);
6475
6476 if (safi == SAFI_MPLS_VPN)
6477 {
paulfee0f4c2004-09-13 05:12:46 +00006478 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006479 {
6480 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6481 continue;
6482
6483 if ((table = rn->info) != NULL)
6484 {
6485 header = 1;
6486
6487 if ((rm = bgp_node_match (table, &match)) != NULL)
6488 {
6489 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006490 {
6491 bgp_unlock_node (rm);
6492 continue;
6493 }
paul718e3742002-12-13 20:15:29 +00006494
6495 for (ri = rm->info; ri; ri = ri->next)
6496 {
6497 if (header)
6498 {
6499 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6500 AFI_IP, SAFI_MPLS_VPN);
6501
6502 header = 0;
6503 }
6504 display++;
6505 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6506 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006507
6508 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006509 }
6510 }
6511 }
6512 }
6513 else
6514 {
6515 header = 1;
6516
paulfee0f4c2004-09-13 05:12:46 +00006517 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006518 {
6519 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6520 {
6521 for (ri = rn->info; ri; ri = ri->next)
6522 {
6523 if (header)
6524 {
6525 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6526 header = 0;
6527 }
6528 display++;
6529 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6530 }
6531 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006532
6533 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006534 }
6535 }
6536
6537 if (! display)
6538 {
6539 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6540 return CMD_WARNING;
6541 }
6542
6543 return CMD_SUCCESS;
6544}
6545
paulfee0f4c2004-09-13 05:12:46 +00006546/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006547static int
paulfd79ac92004-10-13 05:06:08 +00006548bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006549 afi_t afi, safi_t safi, struct prefix_rd *prd,
6550 int prefix_check)
6551{
6552 struct bgp *bgp;
6553
6554 /* BGP structure lookup. */
6555 if (view_name)
6556 {
6557 bgp = bgp_lookup_by_name (view_name);
6558 if (bgp == NULL)
6559 {
6560 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6561 return CMD_WARNING;
6562 }
6563 }
6564 else
6565 {
6566 bgp = bgp_get_default ();
6567 if (bgp == NULL)
6568 {
6569 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6570 return CMD_WARNING;
6571 }
6572 }
6573
6574 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6575 afi, safi, prd, prefix_check);
6576}
6577
paul718e3742002-12-13 20:15:29 +00006578/* BGP route print out function. */
6579DEFUN (show_ip_bgp,
6580 show_ip_bgp_cmd,
6581 "show ip bgp",
6582 SHOW_STR
6583 IP_STR
6584 BGP_STR)
6585{
ajs5a646652004-11-05 01:25:55 +00006586 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006587}
6588
6589DEFUN (show_ip_bgp_ipv4,
6590 show_ip_bgp_ipv4_cmd,
6591 "show ip bgp ipv4 (unicast|multicast)",
6592 SHOW_STR
6593 IP_STR
6594 BGP_STR
6595 "Address family\n"
6596 "Address Family modifier\n"
6597 "Address Family modifier\n")
6598{
6599 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006600 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6601 NULL);
paul718e3742002-12-13 20:15:29 +00006602
ajs5a646652004-11-05 01:25:55 +00006603 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006604}
6605
Michael Lambert95cbbd22010-07-23 14:43:04 -04006606ALIAS (show_ip_bgp_ipv4,
6607 show_bgp_ipv4_safi_cmd,
6608 "show bgp ipv4 (unicast|multicast)",
6609 SHOW_STR
6610 BGP_STR
6611 "Address family\n"
6612 "Address Family modifier\n"
6613 "Address Family modifier\n")
6614
paul718e3742002-12-13 20:15:29 +00006615DEFUN (show_ip_bgp_route,
6616 show_ip_bgp_route_cmd,
6617 "show ip bgp A.B.C.D",
6618 SHOW_STR
6619 IP_STR
6620 BGP_STR
6621 "Network in the BGP routing table to display\n")
6622{
6623 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6624}
6625
6626DEFUN (show_ip_bgp_ipv4_route,
6627 show_ip_bgp_ipv4_route_cmd,
6628 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6629 SHOW_STR
6630 IP_STR
6631 BGP_STR
6632 "Address family\n"
6633 "Address Family modifier\n"
6634 "Address Family modifier\n"
6635 "Network in the BGP routing table to display\n")
6636{
6637 if (strncmp (argv[0], "m", 1) == 0)
6638 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6639
6640 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6641}
6642
Michael Lambert95cbbd22010-07-23 14:43:04 -04006643ALIAS (show_ip_bgp_ipv4_route,
6644 show_bgp_ipv4_safi_route_cmd,
6645 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6646 SHOW_STR
6647 BGP_STR
6648 "Address family\n"
6649 "Address Family modifier\n"
6650 "Address Family modifier\n"
6651 "Network in the BGP routing table to display\n")
6652
paul718e3742002-12-13 20:15:29 +00006653DEFUN (show_ip_bgp_vpnv4_all_route,
6654 show_ip_bgp_vpnv4_all_route_cmd,
6655 "show ip bgp vpnv4 all A.B.C.D",
6656 SHOW_STR
6657 IP_STR
6658 BGP_STR
6659 "Display VPNv4 NLRI specific information\n"
6660 "Display information about all VPNv4 NLRIs\n"
6661 "Network in the BGP routing table to display\n")
6662{
6663 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6664}
6665
6666DEFUN (show_ip_bgp_vpnv4_rd_route,
6667 show_ip_bgp_vpnv4_rd_route_cmd,
6668 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6669 SHOW_STR
6670 IP_STR
6671 BGP_STR
6672 "Display VPNv4 NLRI specific information\n"
6673 "Display information for a route distinguisher\n"
6674 "VPN Route Distinguisher\n"
6675 "Network in the BGP routing table to display\n")
6676{
6677 int ret;
6678 struct prefix_rd prd;
6679
6680 ret = str2prefix_rd (argv[0], &prd);
6681 if (! ret)
6682 {
6683 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6684 return CMD_WARNING;
6685 }
6686 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6687}
6688
6689DEFUN (show_ip_bgp_prefix,
6690 show_ip_bgp_prefix_cmd,
6691 "show ip bgp A.B.C.D/M",
6692 SHOW_STR
6693 IP_STR
6694 BGP_STR
6695 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6696{
6697 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6698}
6699
6700DEFUN (show_ip_bgp_ipv4_prefix,
6701 show_ip_bgp_ipv4_prefix_cmd,
6702 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6703 SHOW_STR
6704 IP_STR
6705 BGP_STR
6706 "Address family\n"
6707 "Address Family modifier\n"
6708 "Address Family modifier\n"
6709 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6710{
6711 if (strncmp (argv[0], "m", 1) == 0)
6712 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6713
6714 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6715}
6716
Michael Lambert95cbbd22010-07-23 14:43:04 -04006717ALIAS (show_ip_bgp_ipv4_prefix,
6718 show_bgp_ipv4_safi_prefix_cmd,
6719 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6720 SHOW_STR
6721 BGP_STR
6722 "Address family\n"
6723 "Address Family modifier\n"
6724 "Address Family modifier\n"
6725 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6726
paul718e3742002-12-13 20:15:29 +00006727DEFUN (show_ip_bgp_vpnv4_all_prefix,
6728 show_ip_bgp_vpnv4_all_prefix_cmd,
6729 "show ip bgp vpnv4 all A.B.C.D/M",
6730 SHOW_STR
6731 IP_STR
6732 BGP_STR
6733 "Display VPNv4 NLRI specific information\n"
6734 "Display information about all VPNv4 NLRIs\n"
6735 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6736{
6737 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6738}
6739
6740DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6741 show_ip_bgp_vpnv4_rd_prefix_cmd,
6742 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6743 SHOW_STR
6744 IP_STR
6745 BGP_STR
6746 "Display VPNv4 NLRI specific information\n"
6747 "Display information for a route distinguisher\n"
6748 "VPN Route Distinguisher\n"
6749 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6750{
6751 int ret;
6752 struct prefix_rd prd;
6753
6754 ret = str2prefix_rd (argv[0], &prd);
6755 if (! ret)
6756 {
6757 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6758 return CMD_WARNING;
6759 }
6760 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6761}
6762
6763DEFUN (show_ip_bgp_view,
6764 show_ip_bgp_view_cmd,
6765 "show ip bgp view WORD",
6766 SHOW_STR
6767 IP_STR
6768 BGP_STR
6769 "BGP view\n"
6770 "BGP view name\n")
6771{
paulbb46e942003-10-24 19:02:03 +00006772 struct bgp *bgp;
6773
6774 /* BGP structure lookup. */
6775 bgp = bgp_lookup_by_name (argv[0]);
6776 if (bgp == NULL)
6777 {
6778 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6779 return CMD_WARNING;
6780 }
6781
ajs5a646652004-11-05 01:25:55 +00006782 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006783}
6784
6785DEFUN (show_ip_bgp_view_route,
6786 show_ip_bgp_view_route_cmd,
6787 "show ip bgp view WORD A.B.C.D",
6788 SHOW_STR
6789 IP_STR
6790 BGP_STR
6791 "BGP view\n"
6792 "BGP view name\n"
6793 "Network in the BGP routing table to display\n")
6794{
6795 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6796}
6797
6798DEFUN (show_ip_bgp_view_prefix,
6799 show_ip_bgp_view_prefix_cmd,
6800 "show ip bgp view WORD A.B.C.D/M",
6801 SHOW_STR
6802 IP_STR
6803 BGP_STR
6804 "BGP view\n"
6805 "BGP view name\n"
6806 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6807{
6808 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6809}
6810
6811#ifdef HAVE_IPV6
6812DEFUN (show_bgp,
6813 show_bgp_cmd,
6814 "show bgp",
6815 SHOW_STR
6816 BGP_STR)
6817{
ajs5a646652004-11-05 01:25:55 +00006818 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6819 NULL);
paul718e3742002-12-13 20:15:29 +00006820}
6821
6822ALIAS (show_bgp,
6823 show_bgp_ipv6_cmd,
6824 "show bgp ipv6",
6825 SHOW_STR
6826 BGP_STR
6827 "Address family\n")
6828
Michael Lambert95cbbd22010-07-23 14:43:04 -04006829DEFUN (show_bgp_ipv6_safi,
6830 show_bgp_ipv6_safi_cmd,
6831 "show bgp ipv6 (unicast|multicast)",
6832 SHOW_STR
6833 BGP_STR
6834 "Address family\n"
6835 "Address Family modifier\n"
6836 "Address Family modifier\n")
6837{
6838 if (strncmp (argv[0], "m", 1) == 0)
6839 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6840 NULL);
6841
6842 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6843}
6844
paul718e3742002-12-13 20:15:29 +00006845/* old command */
6846DEFUN (show_ipv6_bgp,
6847 show_ipv6_bgp_cmd,
6848 "show ipv6 bgp",
6849 SHOW_STR
6850 IP_STR
6851 BGP_STR)
6852{
ajs5a646652004-11-05 01:25:55 +00006853 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6854 NULL);
paul718e3742002-12-13 20:15:29 +00006855}
6856
6857DEFUN (show_bgp_route,
6858 show_bgp_route_cmd,
6859 "show bgp X:X::X:X",
6860 SHOW_STR
6861 BGP_STR
6862 "Network in the BGP routing table to display\n")
6863{
6864 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6865}
6866
6867ALIAS (show_bgp_route,
6868 show_bgp_ipv6_route_cmd,
6869 "show bgp ipv6 X:X::X:X",
6870 SHOW_STR
6871 BGP_STR
6872 "Address family\n"
6873 "Network in the BGP routing table to display\n")
6874
Michael Lambert95cbbd22010-07-23 14:43:04 -04006875DEFUN (show_bgp_ipv6_safi_route,
6876 show_bgp_ipv6_safi_route_cmd,
6877 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6878 SHOW_STR
6879 BGP_STR
6880 "Address family\n"
6881 "Address Family modifier\n"
6882 "Address Family modifier\n"
6883 "Network in the BGP routing table to display\n")
6884{
6885 if (strncmp (argv[0], "m", 1) == 0)
6886 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6887
6888 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6889}
6890
paul718e3742002-12-13 20:15:29 +00006891/* old command */
6892DEFUN (show_ipv6_bgp_route,
6893 show_ipv6_bgp_route_cmd,
6894 "show ipv6 bgp X:X::X:X",
6895 SHOW_STR
6896 IP_STR
6897 BGP_STR
6898 "Network in the BGP routing table to display\n")
6899{
6900 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6901}
6902
6903DEFUN (show_bgp_prefix,
6904 show_bgp_prefix_cmd,
6905 "show bgp X:X::X:X/M",
6906 SHOW_STR
6907 BGP_STR
6908 "IPv6 prefix <network>/<length>\n")
6909{
6910 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6911}
6912
6913ALIAS (show_bgp_prefix,
6914 show_bgp_ipv6_prefix_cmd,
6915 "show bgp ipv6 X:X::X:X/M",
6916 SHOW_STR
6917 BGP_STR
6918 "Address family\n"
6919 "IPv6 prefix <network>/<length>\n")
6920
Michael Lambert95cbbd22010-07-23 14:43:04 -04006921DEFUN (show_bgp_ipv6_safi_prefix,
6922 show_bgp_ipv6_safi_prefix_cmd,
6923 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6924 SHOW_STR
6925 BGP_STR
6926 "Address family\n"
6927 "Address Family modifier\n"
6928 "Address Family modifier\n"
6929 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6930{
6931 if (strncmp (argv[0], "m", 1) == 0)
6932 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6933
6934 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6935}
6936
paul718e3742002-12-13 20:15:29 +00006937/* old command */
6938DEFUN (show_ipv6_bgp_prefix,
6939 show_ipv6_bgp_prefix_cmd,
6940 "show ipv6 bgp X:X::X:X/M",
6941 SHOW_STR
6942 IP_STR
6943 BGP_STR
6944 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6945{
6946 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6947}
6948
paulbb46e942003-10-24 19:02:03 +00006949DEFUN (show_bgp_view,
6950 show_bgp_view_cmd,
6951 "show bgp view WORD",
6952 SHOW_STR
6953 BGP_STR
6954 "BGP view\n"
6955 "View name\n")
6956{
6957 struct bgp *bgp;
6958
6959 /* BGP structure lookup. */
6960 bgp = bgp_lookup_by_name (argv[0]);
6961 if (bgp == NULL)
6962 {
6963 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6964 return CMD_WARNING;
6965 }
6966
ajs5a646652004-11-05 01:25:55 +00006967 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006968}
6969
6970ALIAS (show_bgp_view,
6971 show_bgp_view_ipv6_cmd,
6972 "show bgp view WORD ipv6",
6973 SHOW_STR
6974 BGP_STR
6975 "BGP view\n"
6976 "View name\n"
6977 "Address family\n")
6978
6979DEFUN (show_bgp_view_route,
6980 show_bgp_view_route_cmd,
6981 "show bgp view WORD X:X::X:X",
6982 SHOW_STR
6983 BGP_STR
6984 "BGP view\n"
6985 "View name\n"
6986 "Network in the BGP routing table to display\n")
6987{
6988 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6989}
6990
6991ALIAS (show_bgp_view_route,
6992 show_bgp_view_ipv6_route_cmd,
6993 "show bgp view WORD ipv6 X:X::X:X",
6994 SHOW_STR
6995 BGP_STR
6996 "BGP view\n"
6997 "View name\n"
6998 "Address family\n"
6999 "Network in the BGP routing table to display\n")
7000
7001DEFUN (show_bgp_view_prefix,
7002 show_bgp_view_prefix_cmd,
7003 "show bgp view WORD X:X::X:X/M",
7004 SHOW_STR
7005 BGP_STR
7006 "BGP view\n"
7007 "View name\n"
7008 "IPv6 prefix <network>/<length>\n")
7009{
7010 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
7011}
7012
7013ALIAS (show_bgp_view_prefix,
7014 show_bgp_view_ipv6_prefix_cmd,
7015 "show bgp view WORD ipv6 X:X::X:X/M",
7016 SHOW_STR
7017 BGP_STR
7018 "BGP view\n"
7019 "View name\n"
7020 "Address family\n"
7021 "IPv6 prefix <network>/<length>\n")
7022
paul718e3742002-12-13 20:15:29 +00007023/* old command */
7024DEFUN (show_ipv6_mbgp,
7025 show_ipv6_mbgp_cmd,
7026 "show ipv6 mbgp",
7027 SHOW_STR
7028 IP_STR
7029 MBGP_STR)
7030{
ajs5a646652004-11-05 01:25:55 +00007031 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7032 NULL);
paul718e3742002-12-13 20:15:29 +00007033}
7034
7035/* old command */
7036DEFUN (show_ipv6_mbgp_route,
7037 show_ipv6_mbgp_route_cmd,
7038 "show ipv6 mbgp X:X::X:X",
7039 SHOW_STR
7040 IP_STR
7041 MBGP_STR
7042 "Network in the MBGP routing table to display\n")
7043{
7044 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7045}
7046
7047/* old command */
7048DEFUN (show_ipv6_mbgp_prefix,
7049 show_ipv6_mbgp_prefix_cmd,
7050 "show ipv6 mbgp X:X::X:X/M",
7051 SHOW_STR
7052 IP_STR
7053 MBGP_STR
7054 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7055{
7056 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7057}
7058#endif
7059
paul718e3742002-12-13 20:15:29 +00007060
paul94f2b392005-06-28 12:44:16 +00007061static int
paulfd79ac92004-10-13 05:06:08 +00007062bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007063 safi_t safi, enum bgp_show_type type)
7064{
7065 int i;
7066 struct buffer *b;
7067 char *regstr;
7068 int first;
7069 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007070 int rc;
paul718e3742002-12-13 20:15:29 +00007071
7072 first = 0;
7073 b = buffer_new (1024);
7074 for (i = 0; i < argc; i++)
7075 {
7076 if (first)
7077 buffer_putc (b, ' ');
7078 else
7079 {
7080 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7081 continue;
7082 first = 1;
7083 }
7084
7085 buffer_putstr (b, argv[i]);
7086 }
7087 buffer_putc (b, '\0');
7088
7089 regstr = buffer_getstr (b);
7090 buffer_free (b);
7091
7092 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007093 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007094 if (! regex)
7095 {
7096 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7097 VTY_NEWLINE);
7098 return CMD_WARNING;
7099 }
7100
ajs5a646652004-11-05 01:25:55 +00007101 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7102 bgp_regex_free (regex);
7103 return rc;
paul718e3742002-12-13 20:15:29 +00007104}
7105
7106DEFUN (show_ip_bgp_regexp,
7107 show_ip_bgp_regexp_cmd,
7108 "show ip bgp regexp .LINE",
7109 SHOW_STR
7110 IP_STR
7111 BGP_STR
7112 "Display routes matching the AS path regular expression\n"
7113 "A regular-expression to match the BGP AS paths\n")
7114{
7115 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7116 bgp_show_type_regexp);
7117}
7118
7119DEFUN (show_ip_bgp_flap_regexp,
7120 show_ip_bgp_flap_regexp_cmd,
7121 "show ip bgp flap-statistics regexp .LINE",
7122 SHOW_STR
7123 IP_STR
7124 BGP_STR
7125 "Display flap statistics of routes\n"
7126 "Display routes matching the AS path regular expression\n"
7127 "A regular-expression to match the BGP AS paths\n")
7128{
7129 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7130 bgp_show_type_flap_regexp);
7131}
7132
7133DEFUN (show_ip_bgp_ipv4_regexp,
7134 show_ip_bgp_ipv4_regexp_cmd,
7135 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7136 SHOW_STR
7137 IP_STR
7138 BGP_STR
7139 "Address family\n"
7140 "Address Family modifier\n"
7141 "Address Family modifier\n"
7142 "Display routes matching the AS path regular expression\n"
7143 "A regular-expression to match the BGP AS paths\n")
7144{
7145 if (strncmp (argv[0], "m", 1) == 0)
7146 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7147 bgp_show_type_regexp);
7148
7149 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7150 bgp_show_type_regexp);
7151}
7152
7153#ifdef HAVE_IPV6
7154DEFUN (show_bgp_regexp,
7155 show_bgp_regexp_cmd,
7156 "show bgp regexp .LINE",
7157 SHOW_STR
7158 BGP_STR
7159 "Display routes matching the AS path regular expression\n"
7160 "A regular-expression to match the BGP AS paths\n")
7161{
7162 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7163 bgp_show_type_regexp);
7164}
7165
7166ALIAS (show_bgp_regexp,
7167 show_bgp_ipv6_regexp_cmd,
7168 "show bgp ipv6 regexp .LINE",
7169 SHOW_STR
7170 BGP_STR
7171 "Address family\n"
7172 "Display routes matching the AS path regular expression\n"
7173 "A regular-expression to match the BGP AS paths\n")
7174
7175/* old command */
7176DEFUN (show_ipv6_bgp_regexp,
7177 show_ipv6_bgp_regexp_cmd,
7178 "show ipv6 bgp regexp .LINE",
7179 SHOW_STR
7180 IP_STR
7181 BGP_STR
7182 "Display routes matching the AS path regular expression\n"
7183 "A regular-expression to match the BGP AS paths\n")
7184{
7185 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7186 bgp_show_type_regexp);
7187}
7188
7189/* old command */
7190DEFUN (show_ipv6_mbgp_regexp,
7191 show_ipv6_mbgp_regexp_cmd,
7192 "show ipv6 mbgp regexp .LINE",
7193 SHOW_STR
7194 IP_STR
7195 BGP_STR
7196 "Display routes matching the AS path regular expression\n"
7197 "A regular-expression to match the MBGP AS paths\n")
7198{
7199 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7200 bgp_show_type_regexp);
7201}
7202#endif /* HAVE_IPV6 */
7203
paul94f2b392005-06-28 12:44:16 +00007204static int
paulfd79ac92004-10-13 05:06:08 +00007205bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007206 safi_t safi, enum bgp_show_type type)
7207{
7208 struct prefix_list *plist;
7209
7210 plist = prefix_list_lookup (afi, prefix_list_str);
7211 if (plist == NULL)
7212 {
7213 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7214 prefix_list_str, VTY_NEWLINE);
7215 return CMD_WARNING;
7216 }
7217
ajs5a646652004-11-05 01:25:55 +00007218 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007219}
7220
7221DEFUN (show_ip_bgp_prefix_list,
7222 show_ip_bgp_prefix_list_cmd,
7223 "show ip bgp prefix-list WORD",
7224 SHOW_STR
7225 IP_STR
7226 BGP_STR
7227 "Display routes conforming to the prefix-list\n"
7228 "IP prefix-list name\n")
7229{
7230 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7231 bgp_show_type_prefix_list);
7232}
7233
7234DEFUN (show_ip_bgp_flap_prefix_list,
7235 show_ip_bgp_flap_prefix_list_cmd,
7236 "show ip bgp flap-statistics prefix-list WORD",
7237 SHOW_STR
7238 IP_STR
7239 BGP_STR
7240 "Display flap statistics of routes\n"
7241 "Display routes conforming to the prefix-list\n"
7242 "IP prefix-list name\n")
7243{
7244 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7245 bgp_show_type_flap_prefix_list);
7246}
7247
7248DEFUN (show_ip_bgp_ipv4_prefix_list,
7249 show_ip_bgp_ipv4_prefix_list_cmd,
7250 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7251 SHOW_STR
7252 IP_STR
7253 BGP_STR
7254 "Address family\n"
7255 "Address Family modifier\n"
7256 "Address Family modifier\n"
7257 "Display routes conforming to the prefix-list\n"
7258 "IP prefix-list name\n")
7259{
7260 if (strncmp (argv[0], "m", 1) == 0)
7261 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7262 bgp_show_type_prefix_list);
7263
7264 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7265 bgp_show_type_prefix_list);
7266}
7267
7268#ifdef HAVE_IPV6
7269DEFUN (show_bgp_prefix_list,
7270 show_bgp_prefix_list_cmd,
7271 "show bgp prefix-list WORD",
7272 SHOW_STR
7273 BGP_STR
7274 "Display routes conforming to the prefix-list\n"
7275 "IPv6 prefix-list name\n")
7276{
7277 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7278 bgp_show_type_prefix_list);
7279}
7280
7281ALIAS (show_bgp_prefix_list,
7282 show_bgp_ipv6_prefix_list_cmd,
7283 "show bgp ipv6 prefix-list WORD",
7284 SHOW_STR
7285 BGP_STR
7286 "Address family\n"
7287 "Display routes conforming to the prefix-list\n"
7288 "IPv6 prefix-list name\n")
7289
7290/* old command */
7291DEFUN (show_ipv6_bgp_prefix_list,
7292 show_ipv6_bgp_prefix_list_cmd,
7293 "show ipv6 bgp prefix-list WORD",
7294 SHOW_STR
7295 IPV6_STR
7296 BGP_STR
7297 "Display routes matching the prefix-list\n"
7298 "IPv6 prefix-list name\n")
7299{
7300 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7301 bgp_show_type_prefix_list);
7302}
7303
7304/* old command */
7305DEFUN (show_ipv6_mbgp_prefix_list,
7306 show_ipv6_mbgp_prefix_list_cmd,
7307 "show ipv6 mbgp prefix-list WORD",
7308 SHOW_STR
7309 IPV6_STR
7310 MBGP_STR
7311 "Display routes matching the prefix-list\n"
7312 "IPv6 prefix-list name\n")
7313{
7314 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7315 bgp_show_type_prefix_list);
7316}
7317#endif /* HAVE_IPV6 */
7318
paul94f2b392005-06-28 12:44:16 +00007319static int
paulfd79ac92004-10-13 05:06:08 +00007320bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007321 safi_t safi, enum bgp_show_type type)
7322{
7323 struct as_list *as_list;
7324
7325 as_list = as_list_lookup (filter);
7326 if (as_list == NULL)
7327 {
7328 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7329 return CMD_WARNING;
7330 }
7331
ajs5a646652004-11-05 01:25:55 +00007332 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007333}
7334
7335DEFUN (show_ip_bgp_filter_list,
7336 show_ip_bgp_filter_list_cmd,
7337 "show ip bgp filter-list WORD",
7338 SHOW_STR
7339 IP_STR
7340 BGP_STR
7341 "Display routes conforming to the filter-list\n"
7342 "Regular expression access list name\n")
7343{
7344 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7345 bgp_show_type_filter_list);
7346}
7347
7348DEFUN (show_ip_bgp_flap_filter_list,
7349 show_ip_bgp_flap_filter_list_cmd,
7350 "show ip bgp flap-statistics filter-list WORD",
7351 SHOW_STR
7352 IP_STR
7353 BGP_STR
7354 "Display flap statistics of routes\n"
7355 "Display routes conforming to the filter-list\n"
7356 "Regular expression access list name\n")
7357{
7358 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7359 bgp_show_type_flap_filter_list);
7360}
7361
7362DEFUN (show_ip_bgp_ipv4_filter_list,
7363 show_ip_bgp_ipv4_filter_list_cmd,
7364 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7365 SHOW_STR
7366 IP_STR
7367 BGP_STR
7368 "Address family\n"
7369 "Address Family modifier\n"
7370 "Address Family modifier\n"
7371 "Display routes conforming to the filter-list\n"
7372 "Regular expression access list name\n")
7373{
7374 if (strncmp (argv[0], "m", 1) == 0)
7375 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7376 bgp_show_type_filter_list);
7377
7378 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7379 bgp_show_type_filter_list);
7380}
7381
7382#ifdef HAVE_IPV6
7383DEFUN (show_bgp_filter_list,
7384 show_bgp_filter_list_cmd,
7385 "show bgp filter-list WORD",
7386 SHOW_STR
7387 BGP_STR
7388 "Display routes conforming to the filter-list\n"
7389 "Regular expression access list name\n")
7390{
7391 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7392 bgp_show_type_filter_list);
7393}
7394
7395ALIAS (show_bgp_filter_list,
7396 show_bgp_ipv6_filter_list_cmd,
7397 "show bgp ipv6 filter-list WORD",
7398 SHOW_STR
7399 BGP_STR
7400 "Address family\n"
7401 "Display routes conforming to the filter-list\n"
7402 "Regular expression access list name\n")
7403
7404/* old command */
7405DEFUN (show_ipv6_bgp_filter_list,
7406 show_ipv6_bgp_filter_list_cmd,
7407 "show ipv6 bgp filter-list WORD",
7408 SHOW_STR
7409 IPV6_STR
7410 BGP_STR
7411 "Display routes conforming to the filter-list\n"
7412 "Regular expression access list name\n")
7413{
7414 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7415 bgp_show_type_filter_list);
7416}
7417
7418/* old command */
7419DEFUN (show_ipv6_mbgp_filter_list,
7420 show_ipv6_mbgp_filter_list_cmd,
7421 "show ipv6 mbgp filter-list WORD",
7422 SHOW_STR
7423 IPV6_STR
7424 MBGP_STR
7425 "Display routes conforming to the filter-list\n"
7426 "Regular expression access list name\n")
7427{
7428 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7429 bgp_show_type_filter_list);
7430}
7431#endif /* HAVE_IPV6 */
7432
paul94f2b392005-06-28 12:44:16 +00007433static int
paulfd79ac92004-10-13 05:06:08 +00007434bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007435 safi_t safi, enum bgp_show_type type)
7436{
7437 struct route_map *rmap;
7438
7439 rmap = route_map_lookup_by_name (rmap_str);
7440 if (! rmap)
7441 {
7442 vty_out (vty, "%% %s is not a valid route-map name%s",
7443 rmap_str, VTY_NEWLINE);
7444 return CMD_WARNING;
7445 }
7446
ajs5a646652004-11-05 01:25:55 +00007447 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007448}
7449
7450DEFUN (show_ip_bgp_route_map,
7451 show_ip_bgp_route_map_cmd,
7452 "show ip bgp route-map WORD",
7453 SHOW_STR
7454 IP_STR
7455 BGP_STR
7456 "Display routes matching the route-map\n"
7457 "A route-map to match on\n")
7458{
7459 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7460 bgp_show_type_route_map);
7461}
7462
7463DEFUN (show_ip_bgp_flap_route_map,
7464 show_ip_bgp_flap_route_map_cmd,
7465 "show ip bgp flap-statistics route-map WORD",
7466 SHOW_STR
7467 IP_STR
7468 BGP_STR
7469 "Display flap statistics of routes\n"
7470 "Display routes matching the route-map\n"
7471 "A route-map to match on\n")
7472{
7473 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7474 bgp_show_type_flap_route_map);
7475}
7476
7477DEFUN (show_ip_bgp_ipv4_route_map,
7478 show_ip_bgp_ipv4_route_map_cmd,
7479 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7480 SHOW_STR
7481 IP_STR
7482 BGP_STR
7483 "Address family\n"
7484 "Address Family modifier\n"
7485 "Address Family modifier\n"
7486 "Display routes matching the route-map\n"
7487 "A route-map to match on\n")
7488{
7489 if (strncmp (argv[0], "m", 1) == 0)
7490 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7491 bgp_show_type_route_map);
7492
7493 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7494 bgp_show_type_route_map);
7495}
7496
7497DEFUN (show_bgp_route_map,
7498 show_bgp_route_map_cmd,
7499 "show bgp route-map WORD",
7500 SHOW_STR
7501 BGP_STR
7502 "Display routes matching the route-map\n"
7503 "A route-map to match on\n")
7504{
7505 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7506 bgp_show_type_route_map);
7507}
7508
7509ALIAS (show_bgp_route_map,
7510 show_bgp_ipv6_route_map_cmd,
7511 "show bgp ipv6 route-map WORD",
7512 SHOW_STR
7513 BGP_STR
7514 "Address family\n"
7515 "Display routes matching the route-map\n"
7516 "A route-map to match on\n")
7517
7518DEFUN (show_ip_bgp_cidr_only,
7519 show_ip_bgp_cidr_only_cmd,
7520 "show ip bgp cidr-only",
7521 SHOW_STR
7522 IP_STR
7523 BGP_STR
7524 "Display only routes with non-natural netmasks\n")
7525{
7526 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007527 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007528}
7529
7530DEFUN (show_ip_bgp_flap_cidr_only,
7531 show_ip_bgp_flap_cidr_only_cmd,
7532 "show ip bgp flap-statistics cidr-only",
7533 SHOW_STR
7534 IP_STR
7535 BGP_STR
7536 "Display flap statistics of routes\n"
7537 "Display only routes with non-natural netmasks\n")
7538{
7539 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007540 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007541}
7542
7543DEFUN (show_ip_bgp_ipv4_cidr_only,
7544 show_ip_bgp_ipv4_cidr_only_cmd,
7545 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7546 SHOW_STR
7547 IP_STR
7548 BGP_STR
7549 "Address family\n"
7550 "Address Family modifier\n"
7551 "Address Family modifier\n"
7552 "Display only routes with non-natural netmasks\n")
7553{
7554 if (strncmp (argv[0], "m", 1) == 0)
7555 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007556 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007557
7558 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007559 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007560}
7561
7562DEFUN (show_ip_bgp_community_all,
7563 show_ip_bgp_community_all_cmd,
7564 "show ip bgp community",
7565 SHOW_STR
7566 IP_STR
7567 BGP_STR
7568 "Display routes matching the communities\n")
7569{
7570 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007571 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007572}
7573
7574DEFUN (show_ip_bgp_ipv4_community_all,
7575 show_ip_bgp_ipv4_community_all_cmd,
7576 "show ip bgp ipv4 (unicast|multicast) community",
7577 SHOW_STR
7578 IP_STR
7579 BGP_STR
7580 "Address family\n"
7581 "Address Family modifier\n"
7582 "Address Family modifier\n"
7583 "Display routes matching the communities\n")
7584{
7585 if (strncmp (argv[0], "m", 1) == 0)
7586 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007587 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007588
7589 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007590 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007591}
7592
7593#ifdef HAVE_IPV6
7594DEFUN (show_bgp_community_all,
7595 show_bgp_community_all_cmd,
7596 "show bgp community",
7597 SHOW_STR
7598 BGP_STR
7599 "Display routes matching the communities\n")
7600{
7601 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007602 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007603}
7604
7605ALIAS (show_bgp_community_all,
7606 show_bgp_ipv6_community_all_cmd,
7607 "show bgp ipv6 community",
7608 SHOW_STR
7609 BGP_STR
7610 "Address family\n"
7611 "Display routes matching the communities\n")
7612
7613/* old command */
7614DEFUN (show_ipv6_bgp_community_all,
7615 show_ipv6_bgp_community_all_cmd,
7616 "show ipv6 bgp community",
7617 SHOW_STR
7618 IPV6_STR
7619 BGP_STR
7620 "Display routes matching the communities\n")
7621{
7622 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007623 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007624}
7625
7626/* old command */
7627DEFUN (show_ipv6_mbgp_community_all,
7628 show_ipv6_mbgp_community_all_cmd,
7629 "show ipv6 mbgp community",
7630 SHOW_STR
7631 IPV6_STR
7632 MBGP_STR
7633 "Display routes matching the communities\n")
7634{
7635 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007636 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007637}
7638#endif /* HAVE_IPV6 */
7639
paul94f2b392005-06-28 12:44:16 +00007640static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007641bgp_show_community (struct vty *vty, const char *view_name, int argc,
7642 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007643{
7644 struct community *com;
7645 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007646 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007647 int i;
7648 char *str;
7649 int first = 0;
7650
Michael Lambert95cbbd22010-07-23 14:43:04 -04007651 /* BGP structure lookup */
7652 if (view_name)
7653 {
7654 bgp = bgp_lookup_by_name (view_name);
7655 if (bgp == NULL)
7656 {
7657 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7658 return CMD_WARNING;
7659 }
7660 }
7661 else
7662 {
7663 bgp = bgp_get_default ();
7664 if (bgp == NULL)
7665 {
7666 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7667 return CMD_WARNING;
7668 }
7669 }
7670
paul718e3742002-12-13 20:15:29 +00007671 b = buffer_new (1024);
7672 for (i = 0; i < argc; i++)
7673 {
7674 if (first)
7675 buffer_putc (b, ' ');
7676 else
7677 {
7678 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7679 continue;
7680 first = 1;
7681 }
7682
7683 buffer_putstr (b, argv[i]);
7684 }
7685 buffer_putc (b, '\0');
7686
7687 str = buffer_getstr (b);
7688 buffer_free (b);
7689
7690 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007691 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007692 if (! com)
7693 {
7694 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7695 return CMD_WARNING;
7696 }
7697
Michael Lambert95cbbd22010-07-23 14:43:04 -04007698 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007699 (exact ? bgp_show_type_community_exact :
7700 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007701}
7702
7703DEFUN (show_ip_bgp_community,
7704 show_ip_bgp_community_cmd,
7705 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7706 SHOW_STR
7707 IP_STR
7708 BGP_STR
7709 "Display routes matching the communities\n"
7710 "community number\n"
7711 "Do not send outside local AS (well-known community)\n"
7712 "Do not advertise to any peer (well-known community)\n"
7713 "Do not export to next AS (well-known community)\n")
7714{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007715 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007716}
7717
7718ALIAS (show_ip_bgp_community,
7719 show_ip_bgp_community2_cmd,
7720 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7721 SHOW_STR
7722 IP_STR
7723 BGP_STR
7724 "Display routes matching the communities\n"
7725 "community number\n"
7726 "Do not send outside local AS (well-known community)\n"
7727 "Do not advertise to any peer (well-known community)\n"
7728 "Do not export to next AS (well-known community)\n"
7729 "community number\n"
7730 "Do not send outside local AS (well-known community)\n"
7731 "Do not advertise to any peer (well-known community)\n"
7732 "Do not export to next AS (well-known community)\n")
7733
7734ALIAS (show_ip_bgp_community,
7735 show_ip_bgp_community3_cmd,
7736 "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)",
7737 SHOW_STR
7738 IP_STR
7739 BGP_STR
7740 "Display routes matching the communities\n"
7741 "community number\n"
7742 "Do not send outside local AS (well-known community)\n"
7743 "Do not advertise to any peer (well-known community)\n"
7744 "Do not export to next AS (well-known community)\n"
7745 "community number\n"
7746 "Do not send outside local AS (well-known community)\n"
7747 "Do not advertise to any peer (well-known community)\n"
7748 "Do not export to next AS (well-known community)\n"
7749 "community number\n"
7750 "Do not send outside local AS (well-known community)\n"
7751 "Do not advertise to any peer (well-known community)\n"
7752 "Do not export to next AS (well-known community)\n")
7753
7754ALIAS (show_ip_bgp_community,
7755 show_ip_bgp_community4_cmd,
7756 "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)",
7757 SHOW_STR
7758 IP_STR
7759 BGP_STR
7760 "Display routes matching the communities\n"
7761 "community number\n"
7762 "Do not send outside local AS (well-known community)\n"
7763 "Do not advertise to any peer (well-known community)\n"
7764 "Do not export to next AS (well-known community)\n"
7765 "community number\n"
7766 "Do not send outside local AS (well-known community)\n"
7767 "Do not advertise to any peer (well-known community)\n"
7768 "Do not export to next AS (well-known community)\n"
7769 "community number\n"
7770 "Do not send outside local AS (well-known community)\n"
7771 "Do not advertise to any peer (well-known community)\n"
7772 "Do not export to next AS (well-known community)\n"
7773 "community number\n"
7774 "Do not send outside local AS (well-known community)\n"
7775 "Do not advertise to any peer (well-known community)\n"
7776 "Do not export to next AS (well-known community)\n")
7777
7778DEFUN (show_ip_bgp_ipv4_community,
7779 show_ip_bgp_ipv4_community_cmd,
7780 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7781 SHOW_STR
7782 IP_STR
7783 BGP_STR
7784 "Address family\n"
7785 "Address Family modifier\n"
7786 "Address Family modifier\n"
7787 "Display routes matching the communities\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n")
7792{
7793 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007794 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007795
Michael Lambert95cbbd22010-07-23 14:43:04 -04007796 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007797}
7798
7799ALIAS (show_ip_bgp_ipv4_community,
7800 show_ip_bgp_ipv4_community2_cmd,
7801 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7802 SHOW_STR
7803 IP_STR
7804 BGP_STR
7805 "Address family\n"
7806 "Address Family modifier\n"
7807 "Address Family modifier\n"
7808 "Display routes matching the communities\n"
7809 "community number\n"
7810 "Do not send outside local AS (well-known community)\n"
7811 "Do not advertise to any peer (well-known community)\n"
7812 "Do not export to next AS (well-known community)\n"
7813 "community number\n"
7814 "Do not send outside local AS (well-known community)\n"
7815 "Do not advertise to any peer (well-known community)\n"
7816 "Do not export to next AS (well-known community)\n")
7817
7818ALIAS (show_ip_bgp_ipv4_community,
7819 show_ip_bgp_ipv4_community3_cmd,
7820 "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)",
7821 SHOW_STR
7822 IP_STR
7823 BGP_STR
7824 "Address family\n"
7825 "Address Family modifier\n"
7826 "Address Family modifier\n"
7827 "Display routes matching the communities\n"
7828 "community number\n"
7829 "Do not send outside local AS (well-known community)\n"
7830 "Do not advertise to any peer (well-known community)\n"
7831 "Do not export to next AS (well-known community)\n"
7832 "community number\n"
7833 "Do not send outside local AS (well-known community)\n"
7834 "Do not advertise to any peer (well-known community)\n"
7835 "Do not export to next AS (well-known community)\n"
7836 "community number\n"
7837 "Do not send outside local AS (well-known community)\n"
7838 "Do not advertise to any peer (well-known community)\n"
7839 "Do not export to next AS (well-known community)\n")
7840
7841ALIAS (show_ip_bgp_ipv4_community,
7842 show_ip_bgp_ipv4_community4_cmd,
7843 "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)",
7844 SHOW_STR
7845 IP_STR
7846 BGP_STR
7847 "Address family\n"
7848 "Address Family modifier\n"
7849 "Address Family modifier\n"
7850 "Display routes matching the communities\n"
7851 "community number\n"
7852 "Do not send outside local AS (well-known community)\n"
7853 "Do not advertise to any peer (well-known community)\n"
7854 "Do not export to next AS (well-known community)\n"
7855 "community number\n"
7856 "Do not send outside local AS (well-known community)\n"
7857 "Do not advertise to any peer (well-known community)\n"
7858 "Do not export to next AS (well-known community)\n"
7859 "community number\n"
7860 "Do not send outside local AS (well-known community)\n"
7861 "Do not advertise to any peer (well-known community)\n"
7862 "Do not export to next AS (well-known community)\n"
7863 "community number\n"
7864 "Do not send outside local AS (well-known community)\n"
7865 "Do not advertise to any peer (well-known community)\n"
7866 "Do not export to next AS (well-known community)\n")
7867
Michael Lambert95cbbd22010-07-23 14:43:04 -04007868DEFUN (show_bgp_view_afi_safi_community_all,
7869 show_bgp_view_afi_safi_community_all_cmd,
7870#ifdef HAVE_IPV6
7871 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7872#else
7873 "show bgp view WORD ipv4 (unicast|multicast) community",
7874#endif
7875 SHOW_STR
7876 BGP_STR
7877 "BGP view\n"
7878 "BGP view name\n"
7879 "Address family\n"
7880#ifdef HAVE_IPV6
7881 "Address family\n"
7882#endif
7883 "Address Family modifier\n"
7884 "Address Family modifier\n"
7885 "Display routes containing communities\n")
7886{
7887 int afi;
7888 int safi;
7889 struct bgp *bgp;
7890
7891 /* BGP structure lookup. */
7892 bgp = bgp_lookup_by_name (argv[0]);
7893 if (bgp == NULL)
7894 {
7895 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7896 return CMD_WARNING;
7897 }
7898
7899#ifdef HAVE_IPV6
7900 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7901 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7902#else
7903 afi = AFI_IP;
7904 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7905#endif
7906 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7907}
7908
7909DEFUN (show_bgp_view_afi_safi_community,
7910 show_bgp_view_afi_safi_community_cmd,
7911#ifdef HAVE_IPV6
7912 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7913#else
7914 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7915#endif
7916 SHOW_STR
7917 BGP_STR
7918 "BGP view\n"
7919 "BGP view name\n"
7920 "Address family\n"
7921#ifdef HAVE_IPV6
7922 "Address family\n"
7923#endif
7924 "Address family modifier\n"
7925 "Address family modifier\n"
7926 "Display routes matching the communities\n"
7927 "community number\n"
7928 "Do not send outside local AS (well-known community)\n"
7929 "Do not advertise to any peer (well-known community)\n"
7930 "Do not export to next AS (well-known community)\n")
7931{
7932 int afi;
7933 int safi;
7934
7935#ifdef HAVE_IPV6
7936 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7937 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7938 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7939#else
7940 afi = AFI_IP;
7941 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7942 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7943#endif
7944}
7945
7946ALIAS (show_bgp_view_afi_safi_community,
7947 show_bgp_view_afi_safi_community2_cmd,
7948#ifdef HAVE_IPV6
7949 "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)",
7950#else
7951 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7952#endif
7953 SHOW_STR
7954 BGP_STR
7955 "BGP view\n"
7956 "BGP view name\n"
7957 "Address family\n"
7958#ifdef HAVE_IPV6
7959 "Address family\n"
7960#endif
7961 "Address family modifier\n"
7962 "Address family modifier\n"
7963 "Display routes matching the communities\n"
7964 "community number\n"
7965 "Do not send outside local AS (well-known community)\n"
7966 "Do not advertise to any peer (well-known community)\n"
7967 "Do not export to next AS (well-known community)\n"
7968 "community number\n"
7969 "Do not send outside local AS (well-known community)\n"
7970 "Do not advertise to any peer (well-known community)\n"
7971 "Do not export to next AS (well-known community)\n")
7972
7973ALIAS (show_bgp_view_afi_safi_community,
7974 show_bgp_view_afi_safi_community3_cmd,
7975#ifdef HAVE_IPV6
7976 "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)",
7977#else
7978 "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)",
7979#endif
7980 SHOW_STR
7981 BGP_STR
7982 "BGP view\n"
7983 "BGP view name\n"
7984 "Address family\n"
7985#ifdef HAVE_IPV6
7986 "Address family\n"
7987#endif
7988 "Address family modifier\n"
7989 "Address family modifier\n"
7990 "Display routes matching the communities\n"
7991 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n"
7995 "community number\n"
7996 "Do not send outside local AS (well-known community)\n"
7997 "Do not advertise to any peer (well-known community)\n"
7998 "Do not export to next AS (well-known community)\n"
7999 "community number\n"
8000 "Do not send outside local AS (well-known community)\n"
8001 "Do not advertise to any peer (well-known community)\n"
8002 "Do not export to next AS (well-known community)\n")
8003
8004ALIAS (show_bgp_view_afi_safi_community,
8005 show_bgp_view_afi_safi_community4_cmd,
8006#ifdef HAVE_IPV6
8007 "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)",
8008#else
8009 "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)",
8010#endif
8011 SHOW_STR
8012 BGP_STR
8013 "BGP view\n"
8014 "BGP view name\n"
8015 "Address family\n"
8016#ifdef HAVE_IPV6
8017 "Address family\n"
8018#endif
8019 "Address family modifier\n"
8020 "Address family modifier\n"
8021 "Display routes matching the communities\n"
8022 "community number\n"
8023 "Do not send outside local AS (well-known community)\n"
8024 "Do not advertise to any peer (well-known community)\n"
8025 "Do not export to next AS (well-known community)\n"
8026 "community number\n"
8027 "Do not send outside local AS (well-known community)\n"
8028 "Do not advertise to any peer (well-known community)\n"
8029 "Do not export to next AS (well-known community)\n"
8030 "community number\n"
8031 "Do not send outside local AS (well-known community)\n"
8032 "Do not advertise to any peer (well-known community)\n"
8033 "Do not export to next AS (well-known community)\n"
8034 "community number\n"
8035 "Do not send outside local AS (well-known community)\n"
8036 "Do not advertise to any peer (well-known community)\n"
8037 "Do not export to next AS (well-known community)\n")
8038
paul718e3742002-12-13 20:15:29 +00008039DEFUN (show_ip_bgp_community_exact,
8040 show_ip_bgp_community_exact_cmd,
8041 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8042 SHOW_STR
8043 IP_STR
8044 BGP_STR
8045 "Display routes matching the communities\n"
8046 "community number\n"
8047 "Do not send outside local AS (well-known community)\n"
8048 "Do not advertise to any peer (well-known community)\n"
8049 "Do not export to next AS (well-known community)\n"
8050 "Exact match of the communities")
8051{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008052 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008053}
8054
8055ALIAS (show_ip_bgp_community_exact,
8056 show_ip_bgp_community2_exact_cmd,
8057 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8058 SHOW_STR
8059 IP_STR
8060 BGP_STR
8061 "Display routes matching the communities\n"
8062 "community number\n"
8063 "Do not send outside local AS (well-known community)\n"
8064 "Do not advertise to any peer (well-known community)\n"
8065 "Do not export to next AS (well-known community)\n"
8066 "community number\n"
8067 "Do not send outside local AS (well-known community)\n"
8068 "Do not advertise to any peer (well-known community)\n"
8069 "Do not export to next AS (well-known community)\n"
8070 "Exact match of the communities")
8071
8072ALIAS (show_ip_bgp_community_exact,
8073 show_ip_bgp_community3_exact_cmd,
8074 "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",
8075 SHOW_STR
8076 IP_STR
8077 BGP_STR
8078 "Display routes matching the communities\n"
8079 "community number\n"
8080 "Do not send outside local AS (well-known community)\n"
8081 "Do not advertise to any peer (well-known community)\n"
8082 "Do not export to next AS (well-known community)\n"
8083 "community number\n"
8084 "Do not send outside local AS (well-known community)\n"
8085 "Do not advertise to any peer (well-known community)\n"
8086 "Do not export to next AS (well-known community)\n"
8087 "community number\n"
8088 "Do not send outside local AS (well-known community)\n"
8089 "Do not advertise to any peer (well-known community)\n"
8090 "Do not export to next AS (well-known community)\n"
8091 "Exact match of the communities")
8092
8093ALIAS (show_ip_bgp_community_exact,
8094 show_ip_bgp_community4_exact_cmd,
8095 "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",
8096 SHOW_STR
8097 IP_STR
8098 BGP_STR
8099 "Display routes matching the communities\n"
8100 "community number\n"
8101 "Do not send outside local AS (well-known community)\n"
8102 "Do not advertise to any peer (well-known community)\n"
8103 "Do not export to next AS (well-known community)\n"
8104 "community number\n"
8105 "Do not send outside local AS (well-known community)\n"
8106 "Do not advertise to any peer (well-known community)\n"
8107 "Do not export to next AS (well-known community)\n"
8108 "community number\n"
8109 "Do not send outside local AS (well-known community)\n"
8110 "Do not advertise to any peer (well-known community)\n"
8111 "Do not export to next AS (well-known community)\n"
8112 "community number\n"
8113 "Do not send outside local AS (well-known community)\n"
8114 "Do not advertise to any peer (well-known community)\n"
8115 "Do not export to next AS (well-known community)\n"
8116 "Exact match of the communities")
8117
8118DEFUN (show_ip_bgp_ipv4_community_exact,
8119 show_ip_bgp_ipv4_community_exact_cmd,
8120 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8121 SHOW_STR
8122 IP_STR
8123 BGP_STR
8124 "Address family\n"
8125 "Address Family modifier\n"
8126 "Address Family modifier\n"
8127 "Display routes matching the communities\n"
8128 "community number\n"
8129 "Do not send outside local AS (well-known community)\n"
8130 "Do not advertise to any peer (well-known community)\n"
8131 "Do not export to next AS (well-known community)\n"
8132 "Exact match of the communities")
8133{
8134 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008135 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008136
Michael Lambert95cbbd22010-07-23 14:43:04 -04008137 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008138}
8139
8140ALIAS (show_ip_bgp_ipv4_community_exact,
8141 show_ip_bgp_ipv4_community2_exact_cmd,
8142 "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",
8143 SHOW_STR
8144 IP_STR
8145 BGP_STR
8146 "Address family\n"
8147 "Address Family modifier\n"
8148 "Address Family modifier\n"
8149 "Display routes matching the communities\n"
8150 "community number\n"
8151 "Do not send outside local AS (well-known community)\n"
8152 "Do not advertise to any peer (well-known community)\n"
8153 "Do not export to next AS (well-known community)\n"
8154 "community number\n"
8155 "Do not send outside local AS (well-known community)\n"
8156 "Do not advertise to any peer (well-known community)\n"
8157 "Do not export to next AS (well-known community)\n"
8158 "Exact match of the communities")
8159
8160ALIAS (show_ip_bgp_ipv4_community_exact,
8161 show_ip_bgp_ipv4_community3_exact_cmd,
8162 "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",
8163 SHOW_STR
8164 IP_STR
8165 BGP_STR
8166 "Address family\n"
8167 "Address Family modifier\n"
8168 "Address Family modifier\n"
8169 "Display routes matching the communities\n"
8170 "community number\n"
8171 "Do not send outside local AS (well-known community)\n"
8172 "Do not advertise to any peer (well-known community)\n"
8173 "Do not export to next AS (well-known community)\n"
8174 "community number\n"
8175 "Do not send outside local AS (well-known community)\n"
8176 "Do not advertise to any peer (well-known community)\n"
8177 "Do not export to next AS (well-known community)\n"
8178 "community number\n"
8179 "Do not send outside local AS (well-known community)\n"
8180 "Do not advertise to any peer (well-known community)\n"
8181 "Do not export to next AS (well-known community)\n"
8182 "Exact match of the communities")
8183
8184ALIAS (show_ip_bgp_ipv4_community_exact,
8185 show_ip_bgp_ipv4_community4_exact_cmd,
8186 "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",
8187 SHOW_STR
8188 IP_STR
8189 BGP_STR
8190 "Address family\n"
8191 "Address Family modifier\n"
8192 "Address Family modifier\n"
8193 "Display routes matching the communities\n"
8194 "community number\n"
8195 "Do not send outside local AS (well-known community)\n"
8196 "Do not advertise to any peer (well-known community)\n"
8197 "Do not export to next AS (well-known community)\n"
8198 "community number\n"
8199 "Do not send outside local AS (well-known community)\n"
8200 "Do not advertise to any peer (well-known community)\n"
8201 "Do not export to next AS (well-known community)\n"
8202 "community number\n"
8203 "Do not send outside local AS (well-known community)\n"
8204 "Do not advertise to any peer (well-known community)\n"
8205 "Do not export to next AS (well-known community)\n"
8206 "community number\n"
8207 "Do not send outside local AS (well-known community)\n"
8208 "Do not advertise to any peer (well-known community)\n"
8209 "Do not export to next AS (well-known community)\n"
8210 "Exact match of the communities")
8211
8212#ifdef HAVE_IPV6
8213DEFUN (show_bgp_community,
8214 show_bgp_community_cmd,
8215 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8216 SHOW_STR
8217 BGP_STR
8218 "Display routes matching the communities\n"
8219 "community number\n"
8220 "Do not send outside local AS (well-known community)\n"
8221 "Do not advertise to any peer (well-known community)\n"
8222 "Do not export to next AS (well-known community)\n")
8223{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008224 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008225}
8226
8227ALIAS (show_bgp_community,
8228 show_bgp_ipv6_community_cmd,
8229 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8230 SHOW_STR
8231 BGP_STR
8232 "Address family\n"
8233 "Display routes matching the communities\n"
8234 "community number\n"
8235 "Do not send outside local AS (well-known community)\n"
8236 "Do not advertise to any peer (well-known community)\n"
8237 "Do not export to next AS (well-known community)\n")
8238
8239ALIAS (show_bgp_community,
8240 show_bgp_community2_cmd,
8241 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8242 SHOW_STR
8243 BGP_STR
8244 "Display routes matching the communities\n"
8245 "community number\n"
8246 "Do not send outside local AS (well-known community)\n"
8247 "Do not advertise to any peer (well-known community)\n"
8248 "Do not export to next AS (well-known community)\n"
8249 "community number\n"
8250 "Do not send outside local AS (well-known community)\n"
8251 "Do not advertise to any peer (well-known community)\n"
8252 "Do not export to next AS (well-known community)\n")
8253
8254ALIAS (show_bgp_community,
8255 show_bgp_ipv6_community2_cmd,
8256 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8257 SHOW_STR
8258 BGP_STR
8259 "Address family\n"
8260 "Display routes matching the communities\n"
8261 "community number\n"
8262 "Do not send outside local AS (well-known community)\n"
8263 "Do not advertise to any peer (well-known community)\n"
8264 "Do not export to next AS (well-known community)\n"
8265 "community number\n"
8266 "Do not send outside local AS (well-known community)\n"
8267 "Do not advertise to any peer (well-known community)\n"
8268 "Do not export to next AS (well-known community)\n")
8269
8270ALIAS (show_bgp_community,
8271 show_bgp_community3_cmd,
8272 "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)",
8273 SHOW_STR
8274 BGP_STR
8275 "Display routes matching the communities\n"
8276 "community number\n"
8277 "Do not send outside local AS (well-known community)\n"
8278 "Do not advertise to any peer (well-known community)\n"
8279 "Do not export to next AS (well-known community)\n"
8280 "community number\n"
8281 "Do not send outside local AS (well-known community)\n"
8282 "Do not advertise to any peer (well-known community)\n"
8283 "Do not export to next AS (well-known community)\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n")
8288
8289ALIAS (show_bgp_community,
8290 show_bgp_ipv6_community3_cmd,
8291 "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)",
8292 SHOW_STR
8293 BGP_STR
8294 "Address family\n"
8295 "Display routes matching the communities\n"
8296 "community number\n"
8297 "Do not send outside local AS (well-known community)\n"
8298 "Do not advertise to any peer (well-known community)\n"
8299 "Do not export to next AS (well-known community)\n"
8300 "community number\n"
8301 "Do not send outside local AS (well-known community)\n"
8302 "Do not advertise to any peer (well-known community)\n"
8303 "Do not export to next AS (well-known community)\n"
8304 "community number\n"
8305 "Do not send outside local AS (well-known community)\n"
8306 "Do not advertise to any peer (well-known community)\n"
8307 "Do not export to next AS (well-known community)\n")
8308
8309ALIAS (show_bgp_community,
8310 show_bgp_community4_cmd,
8311 "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)",
8312 SHOW_STR
8313 BGP_STR
8314 "Display routes matching the communities\n"
8315 "community number\n"
8316 "Do not send outside local AS (well-known community)\n"
8317 "Do not advertise to any peer (well-known community)\n"
8318 "Do not export to next AS (well-known community)\n"
8319 "community number\n"
8320 "Do not send outside local AS (well-known community)\n"
8321 "Do not advertise to any peer (well-known community)\n"
8322 "Do not export to next AS (well-known community)\n"
8323 "community number\n"
8324 "Do not send outside local AS (well-known community)\n"
8325 "Do not advertise to any peer (well-known community)\n"
8326 "Do not export to next AS (well-known community)\n"
8327 "community number\n"
8328 "Do not send outside local AS (well-known community)\n"
8329 "Do not advertise to any peer (well-known community)\n"
8330 "Do not export to next AS (well-known community)\n")
8331
8332ALIAS (show_bgp_community,
8333 show_bgp_ipv6_community4_cmd,
8334 "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)",
8335 SHOW_STR
8336 BGP_STR
8337 "Address family\n"
8338 "Display routes matching the communities\n"
8339 "community number\n"
8340 "Do not send outside local AS (well-known community)\n"
8341 "Do not advertise to any peer (well-known community)\n"
8342 "Do not export to next AS (well-known community)\n"
8343 "community number\n"
8344 "Do not send outside local AS (well-known community)\n"
8345 "Do not advertise to any peer (well-known community)\n"
8346 "Do not export to next AS (well-known community)\n"
8347 "community number\n"
8348 "Do not send outside local AS (well-known community)\n"
8349 "Do not advertise to any peer (well-known community)\n"
8350 "Do not export to next AS (well-known community)\n"
8351 "community number\n"
8352 "Do not send outside local AS (well-known community)\n"
8353 "Do not advertise to any peer (well-known community)\n"
8354 "Do not export to next AS (well-known community)\n")
8355
8356/* old command */
8357DEFUN (show_ipv6_bgp_community,
8358 show_ipv6_bgp_community_cmd,
8359 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8360 SHOW_STR
8361 IPV6_STR
8362 BGP_STR
8363 "Display routes matching the communities\n"
8364 "community number\n"
8365 "Do not send outside local AS (well-known community)\n"
8366 "Do not advertise to any peer (well-known community)\n"
8367 "Do not export to next AS (well-known community)\n")
8368{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008369 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008370}
8371
8372/* old command */
8373ALIAS (show_ipv6_bgp_community,
8374 show_ipv6_bgp_community2_cmd,
8375 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8376 SHOW_STR
8377 IPV6_STR
8378 BGP_STR
8379 "Display routes matching the communities\n"
8380 "community number\n"
8381 "Do not send outside local AS (well-known community)\n"
8382 "Do not advertise to any peer (well-known community)\n"
8383 "Do not export to next AS (well-known community)\n"
8384 "community number\n"
8385 "Do not send outside local AS (well-known community)\n"
8386 "Do not advertise to any peer (well-known community)\n"
8387 "Do not export to next AS (well-known community)\n")
8388
8389/* old command */
8390ALIAS (show_ipv6_bgp_community,
8391 show_ipv6_bgp_community3_cmd,
8392 "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)",
8393 SHOW_STR
8394 IPV6_STR
8395 BGP_STR
8396 "Display routes matching the communities\n"
8397 "community number\n"
8398 "Do not send outside local AS (well-known community)\n"
8399 "Do not advertise to any peer (well-known community)\n"
8400 "Do not export to next AS (well-known community)\n"
8401 "community number\n"
8402 "Do not send outside local AS (well-known community)\n"
8403 "Do not advertise to any peer (well-known community)\n"
8404 "Do not export to next AS (well-known community)\n"
8405 "community number\n"
8406 "Do not send outside local AS (well-known community)\n"
8407 "Do not advertise to any peer (well-known community)\n"
8408 "Do not export to next AS (well-known community)\n")
8409
8410/* old command */
8411ALIAS (show_ipv6_bgp_community,
8412 show_ipv6_bgp_community4_cmd,
8413 "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)",
8414 SHOW_STR
8415 IPV6_STR
8416 BGP_STR
8417 "Display routes matching the communities\n"
8418 "community number\n"
8419 "Do not send outside local AS (well-known community)\n"
8420 "Do not advertise to any peer (well-known community)\n"
8421 "Do not export to next AS (well-known community)\n"
8422 "community number\n"
8423 "Do not send outside local AS (well-known community)\n"
8424 "Do not advertise to any peer (well-known community)\n"
8425 "Do not export to next AS (well-known community)\n"
8426 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n")
8434
8435DEFUN (show_bgp_community_exact,
8436 show_bgp_community_exact_cmd,
8437 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8438 SHOW_STR
8439 BGP_STR
8440 "Display routes matching the communities\n"
8441 "community number\n"
8442 "Do not send outside local AS (well-known community)\n"
8443 "Do not advertise to any peer (well-known community)\n"
8444 "Do not export to next AS (well-known community)\n"
8445 "Exact match of the communities")
8446{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008447 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008448}
8449
8450ALIAS (show_bgp_community_exact,
8451 show_bgp_ipv6_community_exact_cmd,
8452 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8453 SHOW_STR
8454 BGP_STR
8455 "Address family\n"
8456 "Display routes matching the communities\n"
8457 "community number\n"
8458 "Do not send outside local AS (well-known community)\n"
8459 "Do not advertise to any peer (well-known community)\n"
8460 "Do not export to next AS (well-known community)\n"
8461 "Exact match of the communities")
8462
8463ALIAS (show_bgp_community_exact,
8464 show_bgp_community2_exact_cmd,
8465 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8466 SHOW_STR
8467 BGP_STR
8468 "Display routes matching the communities\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n"
8473 "community number\n"
8474 "Do not send outside local AS (well-known community)\n"
8475 "Do not advertise to any peer (well-known community)\n"
8476 "Do not export to next AS (well-known community)\n"
8477 "Exact match of the communities")
8478
8479ALIAS (show_bgp_community_exact,
8480 show_bgp_ipv6_community2_exact_cmd,
8481 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8482 SHOW_STR
8483 BGP_STR
8484 "Address family\n"
8485 "Display routes matching the communities\n"
8486 "community number\n"
8487 "Do not send outside local AS (well-known community)\n"
8488 "Do not advertise to any peer (well-known community)\n"
8489 "Do not export to next AS (well-known community)\n"
8490 "community number\n"
8491 "Do not send outside local AS (well-known community)\n"
8492 "Do not advertise to any peer (well-known community)\n"
8493 "Do not export to next AS (well-known community)\n"
8494 "Exact match of the communities")
8495
8496ALIAS (show_bgp_community_exact,
8497 show_bgp_community3_exact_cmd,
8498 "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",
8499 SHOW_STR
8500 BGP_STR
8501 "Display routes matching the communities\n"
8502 "community number\n"
8503 "Do not send outside local AS (well-known community)\n"
8504 "Do not advertise to any peer (well-known community)\n"
8505 "Do not export to next AS (well-known community)\n"
8506 "community number\n"
8507 "Do not send outside local AS (well-known community)\n"
8508 "Do not advertise to any peer (well-known community)\n"
8509 "Do not export to next AS (well-known community)\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n"
8514 "Exact match of the communities")
8515
8516ALIAS (show_bgp_community_exact,
8517 show_bgp_ipv6_community3_exact_cmd,
8518 "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",
8519 SHOW_STR
8520 BGP_STR
8521 "Address family\n"
8522 "Display routes matching the communities\n"
8523 "community number\n"
8524 "Do not send outside local AS (well-known community)\n"
8525 "Do not advertise to any peer (well-known community)\n"
8526 "Do not export to next AS (well-known community)\n"
8527 "community number\n"
8528 "Do not send outside local AS (well-known community)\n"
8529 "Do not advertise to any peer (well-known community)\n"
8530 "Do not export to next AS (well-known community)\n"
8531 "community number\n"
8532 "Do not send outside local AS (well-known community)\n"
8533 "Do not advertise to any peer (well-known community)\n"
8534 "Do not export to next AS (well-known community)\n"
8535 "Exact match of the communities")
8536
8537ALIAS (show_bgp_community_exact,
8538 show_bgp_community4_exact_cmd,
8539 "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",
8540 SHOW_STR
8541 BGP_STR
8542 "Display routes matching the communities\n"
8543 "community number\n"
8544 "Do not send outside local AS (well-known community)\n"
8545 "Do not advertise to any peer (well-known community)\n"
8546 "Do not export to next AS (well-known community)\n"
8547 "community number\n"
8548 "Do not send outside local AS (well-known community)\n"
8549 "Do not advertise to any peer (well-known community)\n"
8550 "Do not export to next AS (well-known community)\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "Exact match of the communities")
8560
8561ALIAS (show_bgp_community_exact,
8562 show_bgp_ipv6_community4_exact_cmd,
8563 "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",
8564 SHOW_STR
8565 BGP_STR
8566 "Address family\n"
8567 "Display routes matching the communities\n"
8568 "community number\n"
8569 "Do not send outside local AS (well-known community)\n"
8570 "Do not advertise to any peer (well-known community)\n"
8571 "Do not export to next AS (well-known community)\n"
8572 "community number\n"
8573 "Do not send outside local AS (well-known community)\n"
8574 "Do not advertise to any peer (well-known community)\n"
8575 "Do not export to next AS (well-known community)\n"
8576 "community number\n"
8577 "Do not send outside local AS (well-known community)\n"
8578 "Do not advertise to any peer (well-known community)\n"
8579 "Do not export to next AS (well-known community)\n"
8580 "community number\n"
8581 "Do not send outside local AS (well-known community)\n"
8582 "Do not advertise to any peer (well-known community)\n"
8583 "Do not export to next AS (well-known community)\n"
8584 "Exact match of the communities")
8585
8586/* old command */
8587DEFUN (show_ipv6_bgp_community_exact,
8588 show_ipv6_bgp_community_exact_cmd,
8589 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8590 SHOW_STR
8591 IPV6_STR
8592 BGP_STR
8593 "Display routes matching the communities\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "Exact match of the communities")
8599{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008600 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008601}
8602
8603/* old command */
8604ALIAS (show_ipv6_bgp_community_exact,
8605 show_ipv6_bgp_community2_exact_cmd,
8606 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8607 SHOW_STR
8608 IPV6_STR
8609 BGP_STR
8610 "Display routes matching the communities\n"
8611 "community number\n"
8612 "Do not send outside local AS (well-known community)\n"
8613 "Do not advertise to any peer (well-known community)\n"
8614 "Do not export to next AS (well-known community)\n"
8615 "community number\n"
8616 "Do not send outside local AS (well-known community)\n"
8617 "Do not advertise to any peer (well-known community)\n"
8618 "Do not export to next AS (well-known community)\n"
8619 "Exact match of the communities")
8620
8621/* old command */
8622ALIAS (show_ipv6_bgp_community_exact,
8623 show_ipv6_bgp_community3_exact_cmd,
8624 "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",
8625 SHOW_STR
8626 IPV6_STR
8627 BGP_STR
8628 "Display routes matching the communities\n"
8629 "community number\n"
8630 "Do not send outside local AS (well-known community)\n"
8631 "Do not advertise to any peer (well-known community)\n"
8632 "Do not export to next AS (well-known community)\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\n"
8641 "Exact match of the communities")
8642
8643/* old command */
8644ALIAS (show_ipv6_bgp_community_exact,
8645 show_ipv6_bgp_community4_exact_cmd,
8646 "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",
8647 SHOW_STR
8648 IPV6_STR
8649 BGP_STR
8650 "Display routes matching the communities\n"
8651 "community number\n"
8652 "Do not send outside local AS (well-known community)\n"
8653 "Do not advertise to any peer (well-known community)\n"
8654 "Do not export to next AS (well-known community)\n"
8655 "community number\n"
8656 "Do not send outside local AS (well-known community)\n"
8657 "Do not advertise to any peer (well-known community)\n"
8658 "Do not export to next AS (well-known community)\n"
8659 "community number\n"
8660 "Do not send outside local AS (well-known community)\n"
8661 "Do not advertise to any peer (well-known community)\n"
8662 "Do not export to next AS (well-known community)\n"
8663 "community number\n"
8664 "Do not send outside local AS (well-known community)\n"
8665 "Do not advertise to any peer (well-known community)\n"
8666 "Do not export to next AS (well-known community)\n"
8667 "Exact match of the communities")
8668
8669/* old command */
8670DEFUN (show_ipv6_mbgp_community,
8671 show_ipv6_mbgp_community_cmd,
8672 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8673 SHOW_STR
8674 IPV6_STR
8675 MBGP_STR
8676 "Display routes matching the communities\n"
8677 "community number\n"
8678 "Do not send outside local AS (well-known community)\n"
8679 "Do not advertise to any peer (well-known community)\n"
8680 "Do not export to next AS (well-known community)\n")
8681{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008682 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008683}
8684
8685/* old command */
8686ALIAS (show_ipv6_mbgp_community,
8687 show_ipv6_mbgp_community2_cmd,
8688 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8689 SHOW_STR
8690 IPV6_STR
8691 MBGP_STR
8692 "Display routes matching the communities\n"
8693 "community number\n"
8694 "Do not send outside local AS (well-known community)\n"
8695 "Do not advertise to any peer (well-known community)\n"
8696 "Do not export to next AS (well-known community)\n"
8697 "community number\n"
8698 "Do not send outside local AS (well-known community)\n"
8699 "Do not advertise to any peer (well-known community)\n"
8700 "Do not export to next AS (well-known community)\n")
8701
8702/* old command */
8703ALIAS (show_ipv6_mbgp_community,
8704 show_ipv6_mbgp_community3_cmd,
8705 "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)",
8706 SHOW_STR
8707 IPV6_STR
8708 MBGP_STR
8709 "Display routes matching the communities\n"
8710 "community number\n"
8711 "Do not send outside local AS (well-known community)\n"
8712 "Do not advertise to any peer (well-known community)\n"
8713 "Do not export to next AS (well-known community)\n"
8714 "community number\n"
8715 "Do not send outside local AS (well-known community)\n"
8716 "Do not advertise to any peer (well-known community)\n"
8717 "Do not export to next AS (well-known community)\n"
8718 "community number\n"
8719 "Do not send outside local AS (well-known community)\n"
8720 "Do not advertise to any peer (well-known community)\n"
8721 "Do not export to next AS (well-known community)\n")
8722
8723/* old command */
8724ALIAS (show_ipv6_mbgp_community,
8725 show_ipv6_mbgp_community4_cmd,
8726 "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)",
8727 SHOW_STR
8728 IPV6_STR
8729 MBGP_STR
8730 "Display routes matching the communities\n"
8731 "community number\n"
8732 "Do not send outside local AS (well-known community)\n"
8733 "Do not advertise to any peer (well-known community)\n"
8734 "Do not export to next AS (well-known community)\n"
8735 "community number\n"
8736 "Do not send outside local AS (well-known community)\n"
8737 "Do not advertise to any peer (well-known community)\n"
8738 "Do not export to next AS (well-known community)\n"
8739 "community number\n"
8740 "Do not send outside local AS (well-known community)\n"
8741 "Do not advertise to any peer (well-known community)\n"
8742 "Do not export to next AS (well-known community)\n"
8743 "community number\n"
8744 "Do not send outside local AS (well-known community)\n"
8745 "Do not advertise to any peer (well-known community)\n"
8746 "Do not export to next AS (well-known community)\n")
8747
8748/* old command */
8749DEFUN (show_ipv6_mbgp_community_exact,
8750 show_ipv6_mbgp_community_exact_cmd,
8751 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8752 SHOW_STR
8753 IPV6_STR
8754 MBGP_STR
8755 "Display routes matching the communities\n"
8756 "community number\n"
8757 "Do not send outside local AS (well-known community)\n"
8758 "Do not advertise to any peer (well-known community)\n"
8759 "Do not export to next AS (well-known community)\n"
8760 "Exact match of the communities")
8761{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008762 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008763}
8764
8765/* old command */
8766ALIAS (show_ipv6_mbgp_community_exact,
8767 show_ipv6_mbgp_community2_exact_cmd,
8768 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8769 SHOW_STR
8770 IPV6_STR
8771 MBGP_STR
8772 "Display routes matching the communities\n"
8773 "community number\n"
8774 "Do not send outside local AS (well-known community)\n"
8775 "Do not advertise to any peer (well-known community)\n"
8776 "Do not export to next AS (well-known community)\n"
8777 "community number\n"
8778 "Do not send outside local AS (well-known community)\n"
8779 "Do not advertise to any peer (well-known community)\n"
8780 "Do not export to next AS (well-known community)\n"
8781 "Exact match of the communities")
8782
8783/* old command */
8784ALIAS (show_ipv6_mbgp_community_exact,
8785 show_ipv6_mbgp_community3_exact_cmd,
8786 "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",
8787 SHOW_STR
8788 IPV6_STR
8789 MBGP_STR
8790 "Display routes matching the communities\n"
8791 "community number\n"
8792 "Do not send outside local AS (well-known community)\n"
8793 "Do not advertise to any peer (well-known community)\n"
8794 "Do not export to next AS (well-known community)\n"
8795 "community number\n"
8796 "Do not send outside local AS (well-known community)\n"
8797 "Do not advertise to any peer (well-known community)\n"
8798 "Do not export to next AS (well-known community)\n"
8799 "community number\n"
8800 "Do not send outside local AS (well-known community)\n"
8801 "Do not advertise to any peer (well-known community)\n"
8802 "Do not export to next AS (well-known community)\n"
8803 "Exact match of the communities")
8804
8805/* old command */
8806ALIAS (show_ipv6_mbgp_community_exact,
8807 show_ipv6_mbgp_community4_exact_cmd,
8808 "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",
8809 SHOW_STR
8810 IPV6_STR
8811 MBGP_STR
8812 "Display routes matching the communities\n"
8813 "community number\n"
8814 "Do not send outside local AS (well-known community)\n"
8815 "Do not advertise to any peer (well-known community)\n"
8816 "Do not export to next AS (well-known community)\n"
8817 "community number\n"
8818 "Do not send outside local AS (well-known community)\n"
8819 "Do not advertise to any peer (well-known community)\n"
8820 "Do not export to next AS (well-known community)\n"
8821 "community number\n"
8822 "Do not send outside local AS (well-known community)\n"
8823 "Do not advertise to any peer (well-known community)\n"
8824 "Do not export to next AS (well-known community)\n"
8825 "community number\n"
8826 "Do not send outside local AS (well-known community)\n"
8827 "Do not advertise to any peer (well-known community)\n"
8828 "Do not export to next AS (well-known community)\n"
8829 "Exact match of the communities")
8830#endif /* HAVE_IPV6 */
8831
paul94f2b392005-06-28 12:44:16 +00008832static int
paulfd79ac92004-10-13 05:06:08 +00008833bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008834 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008835{
8836 struct community_list *list;
8837
hassofee6e4e2005-02-02 16:29:31 +00008838 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008839 if (list == NULL)
8840 {
8841 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8842 VTY_NEWLINE);
8843 return CMD_WARNING;
8844 }
8845
ajs5a646652004-11-05 01:25:55 +00008846 return bgp_show (vty, NULL, afi, safi,
8847 (exact ? bgp_show_type_community_list_exact :
8848 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008849}
8850
8851DEFUN (show_ip_bgp_community_list,
8852 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008853 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008854 SHOW_STR
8855 IP_STR
8856 BGP_STR
8857 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008858 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008859 "community-list name\n")
8860{
8861 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8862}
8863
8864DEFUN (show_ip_bgp_ipv4_community_list,
8865 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008866 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008867 SHOW_STR
8868 IP_STR
8869 BGP_STR
8870 "Address family\n"
8871 "Address Family modifier\n"
8872 "Address Family modifier\n"
8873 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008874 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008875 "community-list name\n")
8876{
8877 if (strncmp (argv[0], "m", 1) == 0)
8878 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8879
8880 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8881}
8882
8883DEFUN (show_ip_bgp_community_list_exact,
8884 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008885 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008886 SHOW_STR
8887 IP_STR
8888 BGP_STR
8889 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008890 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008891 "community-list name\n"
8892 "Exact match of the communities\n")
8893{
8894 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8895}
8896
8897DEFUN (show_ip_bgp_ipv4_community_list_exact,
8898 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008899 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008900 SHOW_STR
8901 IP_STR
8902 BGP_STR
8903 "Address family\n"
8904 "Address Family modifier\n"
8905 "Address Family modifier\n"
8906 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008907 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008908 "community-list name\n"
8909 "Exact match of the communities\n")
8910{
8911 if (strncmp (argv[0], "m", 1) == 0)
8912 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8913
8914 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8915}
8916
8917#ifdef HAVE_IPV6
8918DEFUN (show_bgp_community_list,
8919 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008920 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008921 SHOW_STR
8922 BGP_STR
8923 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008924 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008925 "community-list name\n")
8926{
8927 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8928}
8929
8930ALIAS (show_bgp_community_list,
8931 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008932 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008933 SHOW_STR
8934 BGP_STR
8935 "Address family\n"
8936 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008937 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008938 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008939
8940/* old command */
8941DEFUN (show_ipv6_bgp_community_list,
8942 show_ipv6_bgp_community_list_cmd,
8943 "show ipv6 bgp community-list WORD",
8944 SHOW_STR
8945 IPV6_STR
8946 BGP_STR
8947 "Display routes matching the community-list\n"
8948 "community-list name\n")
8949{
8950 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8951}
8952
8953/* old command */
8954DEFUN (show_ipv6_mbgp_community_list,
8955 show_ipv6_mbgp_community_list_cmd,
8956 "show ipv6 mbgp community-list WORD",
8957 SHOW_STR
8958 IPV6_STR
8959 MBGP_STR
8960 "Display routes matching the community-list\n"
8961 "community-list name\n")
8962{
8963 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8964}
8965
8966DEFUN (show_bgp_community_list_exact,
8967 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008968 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008969 SHOW_STR
8970 BGP_STR
8971 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008972 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008973 "community-list name\n"
8974 "Exact match of the communities\n")
8975{
8976 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8977}
8978
8979ALIAS (show_bgp_community_list_exact,
8980 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008981 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008982 SHOW_STR
8983 BGP_STR
8984 "Address family\n"
8985 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008986 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008987 "community-list name\n"
8988 "Exact match of the communities\n")
8989
8990/* old command */
8991DEFUN (show_ipv6_bgp_community_list_exact,
8992 show_ipv6_bgp_community_list_exact_cmd,
8993 "show ipv6 bgp community-list WORD exact-match",
8994 SHOW_STR
8995 IPV6_STR
8996 BGP_STR
8997 "Display routes matching the community-list\n"
8998 "community-list name\n"
8999 "Exact match of the communities\n")
9000{
9001 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
9002}
9003
9004/* old command */
9005DEFUN (show_ipv6_mbgp_community_list_exact,
9006 show_ipv6_mbgp_community_list_exact_cmd,
9007 "show ipv6 mbgp community-list WORD exact-match",
9008 SHOW_STR
9009 IPV6_STR
9010 MBGP_STR
9011 "Display routes matching the community-list\n"
9012 "community-list name\n"
9013 "Exact match of the communities\n")
9014{
9015 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
9016}
9017#endif /* HAVE_IPV6 */
9018
paul94f2b392005-06-28 12:44:16 +00009019static int
paulfd79ac92004-10-13 05:06:08 +00009020bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00009021 safi_t safi, enum bgp_show_type type)
9022{
9023 int ret;
9024 struct prefix *p;
9025
9026 p = prefix_new();
9027
9028 ret = str2prefix (prefix, p);
9029 if (! ret)
9030 {
9031 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9032 return CMD_WARNING;
9033 }
9034
ajs5a646652004-11-05 01:25:55 +00009035 ret = bgp_show (vty, NULL, afi, safi, type, p);
9036 prefix_free(p);
9037 return ret;
paul718e3742002-12-13 20:15:29 +00009038}
9039
9040DEFUN (show_ip_bgp_prefix_longer,
9041 show_ip_bgp_prefix_longer_cmd,
9042 "show ip bgp A.B.C.D/M longer-prefixes",
9043 SHOW_STR
9044 IP_STR
9045 BGP_STR
9046 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9047 "Display route and more specific routes\n")
9048{
9049 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9050 bgp_show_type_prefix_longer);
9051}
9052
9053DEFUN (show_ip_bgp_flap_prefix_longer,
9054 show_ip_bgp_flap_prefix_longer_cmd,
9055 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9056 SHOW_STR
9057 IP_STR
9058 BGP_STR
9059 "Display flap statistics of routes\n"
9060 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9061 "Display route and more specific routes\n")
9062{
9063 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9064 bgp_show_type_flap_prefix_longer);
9065}
9066
9067DEFUN (show_ip_bgp_ipv4_prefix_longer,
9068 show_ip_bgp_ipv4_prefix_longer_cmd,
9069 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9070 SHOW_STR
9071 IP_STR
9072 BGP_STR
9073 "Address family\n"
9074 "Address Family modifier\n"
9075 "Address Family modifier\n"
9076 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9077 "Display route and more specific routes\n")
9078{
9079 if (strncmp (argv[0], "m", 1) == 0)
9080 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9081 bgp_show_type_prefix_longer);
9082
9083 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9084 bgp_show_type_prefix_longer);
9085}
9086
9087DEFUN (show_ip_bgp_flap_address,
9088 show_ip_bgp_flap_address_cmd,
9089 "show ip bgp flap-statistics A.B.C.D",
9090 SHOW_STR
9091 IP_STR
9092 BGP_STR
9093 "Display flap statistics of routes\n"
9094 "Network in the BGP routing table to display\n")
9095{
9096 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9097 bgp_show_type_flap_address);
9098}
9099
9100DEFUN (show_ip_bgp_flap_prefix,
9101 show_ip_bgp_flap_prefix_cmd,
9102 "show ip bgp flap-statistics A.B.C.D/M",
9103 SHOW_STR
9104 IP_STR
9105 BGP_STR
9106 "Display flap statistics of routes\n"
9107 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9108{
9109 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9110 bgp_show_type_flap_prefix);
9111}
9112#ifdef HAVE_IPV6
9113DEFUN (show_bgp_prefix_longer,
9114 show_bgp_prefix_longer_cmd,
9115 "show bgp X:X::X:X/M longer-prefixes",
9116 SHOW_STR
9117 BGP_STR
9118 "IPv6 prefix <network>/<length>\n"
9119 "Display route and more specific routes\n")
9120{
9121 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9122 bgp_show_type_prefix_longer);
9123}
9124
9125ALIAS (show_bgp_prefix_longer,
9126 show_bgp_ipv6_prefix_longer_cmd,
9127 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9128 SHOW_STR
9129 BGP_STR
9130 "Address family\n"
9131 "IPv6 prefix <network>/<length>\n"
9132 "Display route and more specific routes\n")
9133
9134/* old command */
9135DEFUN (show_ipv6_bgp_prefix_longer,
9136 show_ipv6_bgp_prefix_longer_cmd,
9137 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9138 SHOW_STR
9139 IPV6_STR
9140 BGP_STR
9141 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9142 "Display route and more specific routes\n")
9143{
9144 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9145 bgp_show_type_prefix_longer);
9146}
9147
9148/* old command */
9149DEFUN (show_ipv6_mbgp_prefix_longer,
9150 show_ipv6_mbgp_prefix_longer_cmd,
9151 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9152 SHOW_STR
9153 IPV6_STR
9154 MBGP_STR
9155 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9156 "Display route and more specific routes\n")
9157{
9158 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9159 bgp_show_type_prefix_longer);
9160}
9161#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009162
paul94f2b392005-06-28 12:44:16 +00009163static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009164peer_lookup_in_view (struct vty *vty, const char *view_name,
9165 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009166{
9167 int ret;
9168 struct bgp *bgp;
9169 struct peer *peer;
9170 union sockunion su;
9171
9172 /* BGP structure lookup. */
9173 if (view_name)
9174 {
9175 bgp = bgp_lookup_by_name (view_name);
9176 if (! bgp)
9177 {
9178 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9179 return NULL;
9180 }
9181 }
paul5228ad22004-06-04 17:58:18 +00009182 else
paulbb46e942003-10-24 19:02:03 +00009183 {
9184 bgp = bgp_get_default ();
9185 if (! bgp)
9186 {
9187 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9188 return NULL;
9189 }
9190 }
9191
9192 /* Get peer sockunion. */
9193 ret = str2sockunion (ip_str, &su);
9194 if (ret < 0)
9195 {
9196 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9197 return NULL;
9198 }
9199
9200 /* Peer structure lookup. */
9201 peer = peer_lookup (bgp, &su);
9202 if (! peer)
9203 {
9204 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9205 return NULL;
9206 }
9207
9208 return peer;
9209}
Paul Jakma2815e612006-09-14 02:56:07 +00009210
9211enum bgp_stats
9212{
9213 BGP_STATS_MAXBITLEN = 0,
9214 BGP_STATS_RIB,
9215 BGP_STATS_PREFIXES,
9216 BGP_STATS_TOTPLEN,
9217 BGP_STATS_UNAGGREGATEABLE,
9218 BGP_STATS_MAX_AGGREGATEABLE,
9219 BGP_STATS_AGGREGATES,
9220 BGP_STATS_SPACE,
9221 BGP_STATS_ASPATH_COUNT,
9222 BGP_STATS_ASPATH_MAXHOPS,
9223 BGP_STATS_ASPATH_TOTHOPS,
9224 BGP_STATS_ASPATH_MAXSIZE,
9225 BGP_STATS_ASPATH_TOTSIZE,
9226 BGP_STATS_ASN_HIGHEST,
9227 BGP_STATS_MAX,
9228};
paulbb46e942003-10-24 19:02:03 +00009229
Paul Jakma2815e612006-09-14 02:56:07 +00009230static const char *table_stats_strs[] =
9231{
9232 [BGP_STATS_PREFIXES] = "Total Prefixes",
9233 [BGP_STATS_TOTPLEN] = "Average prefix length",
9234 [BGP_STATS_RIB] = "Total Advertisements",
9235 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9236 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9237 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9238 [BGP_STATS_SPACE] = "Address space advertised",
9239 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9240 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9241 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9242 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9243 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9244 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9245 [BGP_STATS_MAX] = NULL,
9246};
9247
9248struct bgp_table_stats
9249{
9250 struct bgp_table *table;
9251 unsigned long long counts[BGP_STATS_MAX];
9252};
9253
9254#if 0
9255#define TALLY_SIGFIG 100000
9256static unsigned long
9257ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9258{
9259 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9260 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9261 unsigned long ret = newtot / count;
9262
9263 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9264 return ret + 1;
9265 else
9266 return ret;
9267}
9268#endif
9269
9270static int
9271bgp_table_stats_walker (struct thread *t)
9272{
9273 struct bgp_node *rn;
9274 struct bgp_node *top;
9275 struct bgp_table_stats *ts = THREAD_ARG (t);
9276 unsigned int space = 0;
9277
Paul Jakma53d9f672006-10-15 23:41:16 +00009278 if (!(top = bgp_table_top (ts->table)))
9279 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009280
9281 switch (top->p.family)
9282 {
9283 case AF_INET:
9284 space = IPV4_MAX_BITLEN;
9285 break;
9286 case AF_INET6:
9287 space = IPV6_MAX_BITLEN;
9288 break;
9289 }
9290
9291 ts->counts[BGP_STATS_MAXBITLEN] = space;
9292
9293 for (rn = top; rn; rn = bgp_route_next (rn))
9294 {
9295 struct bgp_info *ri;
9296 struct bgp_node *prn = rn->parent;
9297 unsigned int rinum = 0;
9298
9299 if (rn == top)
9300 continue;
9301
9302 if (!rn->info)
9303 continue;
9304
9305 ts->counts[BGP_STATS_PREFIXES]++;
9306 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9307
9308#if 0
9309 ts->counts[BGP_STATS_AVGPLEN]
9310 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9311 ts->counts[BGP_STATS_AVGPLEN],
9312 rn->p.prefixlen);
9313#endif
9314
9315 /* check if the prefix is included by any other announcements */
9316 while (prn && !prn->info)
9317 prn = prn->parent;
9318
9319 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009320 {
9321 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9322 /* announced address space */
9323 if (space)
9324 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9325 }
Paul Jakma2815e612006-09-14 02:56:07 +00009326 else if (prn->info)
9327 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9328
Paul Jakma2815e612006-09-14 02:56:07 +00009329 for (ri = rn->info; ri; ri = ri->next)
9330 {
9331 rinum++;
9332 ts->counts[BGP_STATS_RIB]++;
9333
9334 if (ri->attr &&
9335 (CHECK_FLAG (ri->attr->flag,
9336 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9337 ts->counts[BGP_STATS_AGGREGATES]++;
9338
9339 /* as-path stats */
9340 if (ri->attr && ri->attr->aspath)
9341 {
9342 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9343 unsigned int size = aspath_size (ri->attr->aspath);
9344 as_t highest = aspath_highest (ri->attr->aspath);
9345
9346 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9347
9348 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9349 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9350
9351 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9352 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9353
9354 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9355 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9356#if 0
9357 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9358 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9359 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9360 hops);
9361 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9362 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9363 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9364 size);
9365#endif
9366 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9367 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9368 }
9369 }
9370 }
9371 return 0;
9372}
9373
9374static int
9375bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9376{
9377 struct bgp_table_stats ts;
9378 unsigned int i;
9379
9380 if (!bgp->rib[afi][safi])
9381 {
9382 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9383 return CMD_WARNING;
9384 }
9385
9386 memset (&ts, 0, sizeof (ts));
9387 ts.table = bgp->rib[afi][safi];
9388 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9389
9390 vty_out (vty, "BGP %s RIB statistics%s%s",
9391 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9392
9393 for (i = 0; i < BGP_STATS_MAX; i++)
9394 {
9395 if (!table_stats_strs[i])
9396 continue;
9397
9398 switch (i)
9399 {
9400#if 0
9401 case BGP_STATS_ASPATH_AVGHOPS:
9402 case BGP_STATS_ASPATH_AVGSIZE:
9403 case BGP_STATS_AVGPLEN:
9404 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9405 vty_out (vty, "%12.2f",
9406 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9407 break;
9408#endif
9409 case BGP_STATS_ASPATH_TOTHOPS:
9410 case BGP_STATS_ASPATH_TOTSIZE:
9411 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9412 vty_out (vty, "%12.2f",
9413 ts.counts[i] ?
9414 (float)ts.counts[i] /
9415 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9416 : 0);
9417 break;
9418 case BGP_STATS_TOTPLEN:
9419 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9420 vty_out (vty, "%12.2f",
9421 ts.counts[i] ?
9422 (float)ts.counts[i] /
9423 (float)ts.counts[BGP_STATS_PREFIXES]
9424 : 0);
9425 break;
9426 case BGP_STATS_SPACE:
9427 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9428 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9429 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9430 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009431 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009432 vty_out (vty, "%12.2f%s",
9433 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009434 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009435 VTY_NEWLINE);
9436 vty_out (vty, "%30s: ", "/8 equivalent ");
9437 vty_out (vty, "%12.2f%s",
9438 (float)ts.counts[BGP_STATS_SPACE] /
9439 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9440 VTY_NEWLINE);
9441 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9442 break;
9443 vty_out (vty, "%30s: ", "/24 equivalent ");
9444 vty_out (vty, "%12.2f",
9445 (float)ts.counts[BGP_STATS_SPACE] /
9446 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9447 break;
9448 default:
9449 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9450 vty_out (vty, "%12llu", ts.counts[i]);
9451 }
9452
9453 vty_out (vty, "%s", VTY_NEWLINE);
9454 }
9455 return CMD_SUCCESS;
9456}
9457
9458static int
9459bgp_table_stats_vty (struct vty *vty, const char *name,
9460 const char *afi_str, const char *safi_str)
9461{
9462 struct bgp *bgp;
9463 afi_t afi;
9464 safi_t safi;
9465
9466 if (name)
9467 bgp = bgp_lookup_by_name (name);
9468 else
9469 bgp = bgp_get_default ();
9470
9471 if (!bgp)
9472 {
9473 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9474 return CMD_WARNING;
9475 }
9476 if (strncmp (afi_str, "ipv", 3) == 0)
9477 {
9478 if (strncmp (afi_str, "ipv4", 4) == 0)
9479 afi = AFI_IP;
9480 else if (strncmp (afi_str, "ipv6", 4) == 0)
9481 afi = AFI_IP6;
9482 else
9483 {
9484 vty_out (vty, "%% Invalid address family %s%s",
9485 afi_str, VTY_NEWLINE);
9486 return CMD_WARNING;
9487 }
9488 if (strncmp (safi_str, "m", 1) == 0)
9489 safi = SAFI_MULTICAST;
9490 else if (strncmp (safi_str, "u", 1) == 0)
9491 safi = SAFI_UNICAST;
Denis Ovsienko42e6d742011-07-14 12:36:19 +04009492 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9493 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009494 else
9495 {
9496 vty_out (vty, "%% Invalid subsequent address family %s%s",
9497 safi_str, VTY_NEWLINE);
9498 return CMD_WARNING;
9499 }
9500 }
9501 else
9502 {
9503 vty_out (vty, "%% Invalid address family %s%s",
9504 afi_str, VTY_NEWLINE);
9505 return CMD_WARNING;
9506 }
9507
Paul Jakma2815e612006-09-14 02:56:07 +00009508 return bgp_table_stats (vty, bgp, afi, safi);
9509}
9510
9511DEFUN (show_bgp_statistics,
9512 show_bgp_statistics_cmd,
9513 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9514 SHOW_STR
9515 BGP_STR
9516 "Address family\n"
9517 "Address family\n"
9518 "Address Family modifier\n"
9519 "Address Family modifier\n"
9520 "BGP RIB advertisement statistics\n")
9521{
9522 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9523}
9524
9525ALIAS (show_bgp_statistics,
9526 show_bgp_statistics_vpnv4_cmd,
9527 "show bgp (ipv4) (vpnv4) statistics",
9528 SHOW_STR
9529 BGP_STR
9530 "Address family\n"
9531 "Address Family modifier\n"
9532 "BGP RIB advertisement statistics\n")
9533
9534DEFUN (show_bgp_statistics_view,
9535 show_bgp_statistics_view_cmd,
9536 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9537 SHOW_STR
9538 BGP_STR
9539 "BGP view\n"
9540 "Address family\n"
9541 "Address family\n"
9542 "Address Family modifier\n"
9543 "Address Family modifier\n"
9544 "BGP RIB advertisement statistics\n")
9545{
9546 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9547}
9548
9549ALIAS (show_bgp_statistics_view,
9550 show_bgp_statistics_view_vpnv4_cmd,
9551 "show bgp view WORD (ipv4) (vpnv4) statistics",
9552 SHOW_STR
9553 BGP_STR
9554 "BGP view\n"
9555 "Address family\n"
9556 "Address Family modifier\n"
9557 "BGP RIB advertisement statistics\n")
9558
Paul Jakmaff7924f2006-09-04 01:10:36 +00009559enum bgp_pcounts
9560{
9561 PCOUNT_ADJ_IN = 0,
9562 PCOUNT_DAMPED,
9563 PCOUNT_REMOVED,
9564 PCOUNT_HISTORY,
9565 PCOUNT_STALE,
9566 PCOUNT_VALID,
9567 PCOUNT_ALL,
9568 PCOUNT_COUNTED,
9569 PCOUNT_PFCNT, /* the figure we display to users */
9570 PCOUNT_MAX,
9571};
9572
9573static const char *pcount_strs[] =
9574{
9575 [PCOUNT_ADJ_IN] = "Adj-in",
9576 [PCOUNT_DAMPED] = "Damped",
9577 [PCOUNT_REMOVED] = "Removed",
9578 [PCOUNT_HISTORY] = "History",
9579 [PCOUNT_STALE] = "Stale",
9580 [PCOUNT_VALID] = "Valid",
9581 [PCOUNT_ALL] = "All RIB",
9582 [PCOUNT_COUNTED] = "PfxCt counted",
9583 [PCOUNT_PFCNT] = "Useable",
9584 [PCOUNT_MAX] = NULL,
9585};
9586
Paul Jakma2815e612006-09-14 02:56:07 +00009587struct peer_pcounts
9588{
9589 unsigned int count[PCOUNT_MAX];
9590 const struct peer *peer;
9591 const struct bgp_table *table;
9592};
9593
Paul Jakmaff7924f2006-09-04 01:10:36 +00009594static int
Paul Jakma2815e612006-09-14 02:56:07 +00009595bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009596{
9597 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009598 struct peer_pcounts *pc = THREAD_ARG (t);
9599 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009600
Paul Jakma2815e612006-09-14 02:56:07 +00009601 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009602 {
9603 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009604 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009605
9606 for (ain = rn->adj_in; ain; ain = ain->next)
9607 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009608 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009609
Paul Jakmaff7924f2006-09-04 01:10:36 +00009610 for (ri = rn->info; ri; ri = ri->next)
9611 {
9612 char buf[SU_ADDRSTRLEN];
9613
9614 if (ri->peer != peer)
9615 continue;
9616
Paul Jakma2815e612006-09-14 02:56:07 +00009617 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009618
9619 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009620 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009621 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009622 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009623 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009624 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009625 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009626 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009627 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009628 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009629 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009630 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009631
9632 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9633 {
Paul Jakma2815e612006-09-14 02:56:07 +00009634 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009635 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009636 plog_warn (peer->log,
9637 "%s [pcount] %s/%d is counted but flags 0x%x",
9638 peer->host,
9639 inet_ntop(rn->p.family, &rn->p.u.prefix,
9640 buf, SU_ADDRSTRLEN),
9641 rn->p.prefixlen,
9642 ri->flags);
9643 }
9644 else
9645 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009646 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009647 plog_warn (peer->log,
9648 "%s [pcount] %s/%d not counted but flags 0x%x",
9649 peer->host,
9650 inet_ntop(rn->p.family, &rn->p.u.prefix,
9651 buf, SU_ADDRSTRLEN),
9652 rn->p.prefixlen,
9653 ri->flags);
9654 }
9655 }
9656 }
Paul Jakma2815e612006-09-14 02:56:07 +00009657 return 0;
9658}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009659
Paul Jakma2815e612006-09-14 02:56:07 +00009660static int
9661bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9662{
9663 struct peer_pcounts pcounts = { .peer = peer };
9664 unsigned int i;
9665
9666 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9667 || !peer->bgp->rib[afi][safi])
9668 {
9669 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9670 return CMD_WARNING;
9671 }
9672
9673 memset (&pcounts, 0, sizeof(pcounts));
9674 pcounts.peer = peer;
9675 pcounts.table = peer->bgp->rib[afi][safi];
9676
9677 /* in-place call via thread subsystem so as to record execution time
9678 * stats for the thread-walk (i.e. ensure this can't be blamed on
9679 * on just vty_read()).
9680 */
9681 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9682
Paul Jakmaff7924f2006-09-04 01:10:36 +00009683 vty_out (vty, "Prefix counts for %s, %s%s",
9684 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9685 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9686 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9687 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9688
9689 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009690 vty_out (vty, "%20s: %-10d%s",
9691 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009692
Paul Jakma2815e612006-09-14 02:56:07 +00009693 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009694 {
9695 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9696 peer->host, VTY_NEWLINE);
9697 vty_out (vty, "Please report this bug, with the above command output%s",
9698 VTY_NEWLINE);
9699 }
9700
9701 return CMD_SUCCESS;
9702}
9703
9704DEFUN (show_ip_bgp_neighbor_prefix_counts,
9705 show_ip_bgp_neighbor_prefix_counts_cmd,
9706 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9707 SHOW_STR
9708 IP_STR
9709 BGP_STR
9710 "Detailed information on TCP and BGP neighbor connections\n"
9711 "Neighbor to display information about\n"
9712 "Neighbor to display information about\n"
9713 "Display detailed prefix count information\n")
9714{
9715 struct peer *peer;
9716
9717 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9718 if (! peer)
9719 return CMD_WARNING;
9720
9721 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9722}
9723
9724DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9725 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9726 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9727 SHOW_STR
9728 BGP_STR
9729 "Address family\n"
9730 "Detailed information on TCP and BGP neighbor connections\n"
9731 "Neighbor to display information about\n"
9732 "Neighbor to display information about\n"
9733 "Display detailed prefix count information\n")
9734{
9735 struct peer *peer;
9736
9737 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9738 if (! peer)
9739 return CMD_WARNING;
9740
9741 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9742}
9743
9744DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9745 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9746 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9747 SHOW_STR
9748 IP_STR
9749 BGP_STR
9750 "Address family\n"
9751 "Address Family modifier\n"
9752 "Address Family modifier\n"
9753 "Detailed information on TCP and BGP neighbor connections\n"
9754 "Neighbor to display information about\n"
9755 "Neighbor to display information about\n"
9756 "Display detailed prefix count information\n")
9757{
9758 struct peer *peer;
9759
9760 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9761 if (! peer)
9762 return CMD_WARNING;
9763
9764 if (strncmp (argv[0], "m", 1) == 0)
9765 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9766
9767 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9768}
9769
9770DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9771 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9772 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9773 SHOW_STR
9774 IP_STR
9775 BGP_STR
9776 "Address family\n"
9777 "Address Family modifier\n"
9778 "Address Family modifier\n"
9779 "Detailed information on TCP and BGP neighbor connections\n"
9780 "Neighbor to display information about\n"
9781 "Neighbor to display information about\n"
9782 "Display detailed prefix count information\n")
9783{
9784 struct peer *peer;
9785
9786 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9787 if (! peer)
9788 return CMD_WARNING;
9789
9790 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9791}
9792
9793
paul94f2b392005-06-28 12:44:16 +00009794static void
paul718e3742002-12-13 20:15:29 +00009795show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9796 int in)
9797{
9798 struct bgp_table *table;
9799 struct bgp_adj_in *ain;
9800 struct bgp_adj_out *adj;
9801 unsigned long output_count;
9802 struct bgp_node *rn;
9803 int header1 = 1;
9804 struct bgp *bgp;
9805 int header2 = 1;
9806
paulbb46e942003-10-24 19:02:03 +00009807 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009808
9809 if (! bgp)
9810 return;
9811
9812 table = bgp->rib[afi][safi];
9813
9814 output_count = 0;
9815
9816 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9817 PEER_STATUS_DEFAULT_ORIGINATE))
9818 {
9819 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 +00009820 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9821 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009822
9823 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9824 VTY_NEWLINE, VTY_NEWLINE);
9825 header1 = 0;
9826 }
9827
9828 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9829 if (in)
9830 {
9831 for (ain = rn->adj_in; ain; ain = ain->next)
9832 if (ain->peer == peer)
9833 {
9834 if (header1)
9835 {
9836 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 +00009837 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9838 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009839 header1 = 0;
9840 }
9841 if (header2)
9842 {
9843 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9844 header2 = 0;
9845 }
9846 if (ain->attr)
9847 {
9848 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9849 output_count++;
9850 }
9851 }
9852 }
9853 else
9854 {
9855 for (adj = rn->adj_out; adj; adj = adj->next)
9856 if (adj->peer == peer)
9857 {
9858 if (header1)
9859 {
9860 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 +00009861 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9862 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009863 header1 = 0;
9864 }
9865 if (header2)
9866 {
9867 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9868 header2 = 0;
9869 }
9870 if (adj->attr)
9871 {
9872 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9873 output_count++;
9874 }
9875 }
9876 }
9877
9878 if (output_count != 0)
9879 vty_out (vty, "%sTotal number of prefixes %ld%s",
9880 VTY_NEWLINE, output_count, VTY_NEWLINE);
9881}
9882
paul94f2b392005-06-28 12:44:16 +00009883static int
paulbb46e942003-10-24 19:02:03 +00009884peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9885{
paul718e3742002-12-13 20:15:29 +00009886 if (! peer || ! peer->afc[afi][safi])
9887 {
9888 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9889 return CMD_WARNING;
9890 }
9891
9892 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9893 {
9894 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9895 VTY_NEWLINE);
9896 return CMD_WARNING;
9897 }
9898
9899 show_adj_route (vty, peer, afi, safi, in);
9900
9901 return CMD_SUCCESS;
9902}
9903
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009904DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9905 show_ip_bgp_view_neighbor_advertised_route_cmd,
9906 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9907 SHOW_STR
9908 IP_STR
9909 BGP_STR
9910 "BGP view\n"
9911 "View name\n"
9912 "Detailed information on TCP and BGP neighbor connections\n"
9913 "Neighbor to display information about\n"
9914 "Neighbor to display information about\n"
9915 "Display the routes advertised to a BGP neighbor\n")
9916{
9917 struct peer *peer;
9918
9919 if (argc == 2)
9920 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9921 else
9922 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9923
9924 if (! peer)
9925 return CMD_WARNING;
9926
9927 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9928}
9929
9930ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009931 show_ip_bgp_neighbor_advertised_route_cmd,
9932 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9933 SHOW_STR
9934 IP_STR
9935 BGP_STR
9936 "Detailed information on TCP and BGP neighbor connections\n"
9937 "Neighbor to display information about\n"
9938 "Neighbor to display information about\n"
9939 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009940
9941DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9942 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9943 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9944 SHOW_STR
9945 IP_STR
9946 BGP_STR
9947 "Address family\n"
9948 "Address Family modifier\n"
9949 "Address Family modifier\n"
9950 "Detailed information on TCP and BGP neighbor connections\n"
9951 "Neighbor to display information about\n"
9952 "Neighbor to display information about\n"
9953 "Display the routes advertised to a BGP neighbor\n")
9954{
paulbb46e942003-10-24 19:02:03 +00009955 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009956
paulbb46e942003-10-24 19:02:03 +00009957 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9958 if (! peer)
9959 return CMD_WARNING;
9960
9961 if (strncmp (argv[0], "m", 1) == 0)
9962 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9963
9964 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009965}
9966
9967#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009968DEFUN (show_bgp_view_neighbor_advertised_route,
9969 show_bgp_view_neighbor_advertised_route_cmd,
9970 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9971 SHOW_STR
9972 BGP_STR
9973 "BGP view\n"
9974 "View name\n"
9975 "Detailed information on TCP and BGP neighbor connections\n"
9976 "Neighbor to display information about\n"
9977 "Neighbor to display information about\n"
9978 "Display the routes advertised to a BGP neighbor\n")
9979{
9980 struct peer *peer;
9981
9982 if (argc == 2)
9983 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9984 else
9985 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9986
9987 if (! peer)
9988 return CMD_WARNING;
9989
9990 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9991}
9992
9993ALIAS (show_bgp_view_neighbor_advertised_route,
9994 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9995 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9996 SHOW_STR
9997 BGP_STR
9998 "BGP view\n"
9999 "View name\n"
10000 "Address family\n"
10001 "Detailed information on TCP and BGP neighbor connections\n"
10002 "Neighbor to display information about\n"
10003 "Neighbor to display information about\n"
10004 "Display the routes advertised to a BGP neighbor\n")
10005
10006DEFUN (show_bgp_view_neighbor_received_routes,
10007 show_bgp_view_neighbor_received_routes_cmd,
10008 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10009 SHOW_STR
10010 BGP_STR
10011 "BGP view\n"
10012 "View name\n"
10013 "Detailed information on TCP and BGP neighbor connections\n"
10014 "Neighbor to display information about\n"
10015 "Neighbor to display information about\n"
10016 "Display the received routes from neighbor\n")
10017{
10018 struct peer *peer;
10019
10020 if (argc == 2)
10021 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10022 else
10023 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10024
10025 if (! peer)
10026 return CMD_WARNING;
10027
10028 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10029}
10030
10031ALIAS (show_bgp_view_neighbor_received_routes,
10032 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10033 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10034 SHOW_STR
10035 BGP_STR
10036 "BGP view\n"
10037 "View name\n"
10038 "Address family\n"
10039 "Detailed information on TCP and BGP neighbor connections\n"
10040 "Neighbor to display information about\n"
10041 "Neighbor to display information about\n"
10042 "Display the received routes from neighbor\n")
10043
10044ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010045 show_bgp_neighbor_advertised_route_cmd,
10046 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10047 SHOW_STR
10048 BGP_STR
10049 "Detailed information on TCP and BGP neighbor connections\n"
10050 "Neighbor to display information about\n"
10051 "Neighbor to display information about\n"
10052 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010053
10054ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010055 show_bgp_ipv6_neighbor_advertised_route_cmd,
10056 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10057 SHOW_STR
10058 BGP_STR
10059 "Address family\n"
10060 "Detailed information on TCP and BGP neighbor connections\n"
10061 "Neighbor to display information about\n"
10062 "Neighbor to display information about\n"
10063 "Display the routes advertised to a BGP neighbor\n")
10064
10065/* old command */
paulbb46e942003-10-24 19:02:03 +000010066ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010067 ipv6_bgp_neighbor_advertised_route_cmd,
10068 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10069 SHOW_STR
10070 IPV6_STR
10071 BGP_STR
10072 "Detailed information on TCP and BGP neighbor connections\n"
10073 "Neighbor to display information about\n"
10074 "Neighbor to display information about\n"
10075 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010076
paul718e3742002-12-13 20:15:29 +000010077/* old command */
10078DEFUN (ipv6_mbgp_neighbor_advertised_route,
10079 ipv6_mbgp_neighbor_advertised_route_cmd,
10080 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10081 SHOW_STR
10082 IPV6_STR
10083 MBGP_STR
10084 "Detailed information on TCP and BGP neighbor connections\n"
10085 "Neighbor to display information about\n"
10086 "Neighbor to display information about\n"
10087 "Display the routes advertised to a BGP neighbor\n")
10088{
paulbb46e942003-10-24 19:02:03 +000010089 struct peer *peer;
10090
10091 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10092 if (! peer)
10093 return CMD_WARNING;
10094
10095 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010096}
10097#endif /* HAVE_IPV6 */
10098
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010099DEFUN (show_ip_bgp_view_neighbor_received_routes,
10100 show_ip_bgp_view_neighbor_received_routes_cmd,
10101 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10102 SHOW_STR
10103 IP_STR
10104 BGP_STR
10105 "BGP view\n"
10106 "View name\n"
10107 "Detailed information on TCP and BGP neighbor connections\n"
10108 "Neighbor to display information about\n"
10109 "Neighbor to display information about\n"
10110 "Display the received routes from neighbor\n")
10111{
10112 struct peer *peer;
10113
10114 if (argc == 2)
10115 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10116 else
10117 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10118
10119 if (! peer)
10120 return CMD_WARNING;
10121
10122 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10123}
10124
10125ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010126 show_ip_bgp_neighbor_received_routes_cmd,
10127 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10128 SHOW_STR
10129 IP_STR
10130 BGP_STR
10131 "Detailed information on TCP and BGP neighbor connections\n"
10132 "Neighbor to display information about\n"
10133 "Neighbor to display information about\n"
10134 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010135
10136DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10137 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10138 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10139 SHOW_STR
10140 IP_STR
10141 BGP_STR
10142 "Address family\n"
10143 "Address Family modifier\n"
10144 "Address Family modifier\n"
10145 "Detailed information on TCP and BGP neighbor connections\n"
10146 "Neighbor to display information about\n"
10147 "Neighbor to display information about\n"
10148 "Display the received routes from neighbor\n")
10149{
paulbb46e942003-10-24 19:02:03 +000010150 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010151
paulbb46e942003-10-24 19:02:03 +000010152 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10153 if (! peer)
10154 return CMD_WARNING;
10155
10156 if (strncmp (argv[0], "m", 1) == 0)
10157 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10158
10159 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010160}
10161
Michael Lambert95cbbd22010-07-23 14:43:04 -040010162DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10163 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10164#ifdef HAVE_IPV6
10165 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10166#else
10167 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10168#endif
10169 SHOW_STR
10170 BGP_STR
10171 "BGP view\n"
10172 "BGP view name\n"
10173 "Address family\n"
10174#ifdef HAVE_IPV6
10175 "Address family\n"
10176#endif
10177 "Address family modifier\n"
10178 "Address family modifier\n"
10179 "Detailed information on TCP and BGP neighbor connections\n"
10180 "Neighbor to display information about\n"
10181 "Neighbor to display information about\n"
10182 "Display the advertised routes to neighbor\n"
10183 "Display the received routes from neighbor\n")
10184{
10185 int afi;
10186 int safi;
10187 int in;
10188 struct peer *peer;
10189
10190#ifdef HAVE_IPV6
10191 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10192#else
10193 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10194#endif
10195
10196 if (! peer)
10197 return CMD_WARNING;
10198
10199#ifdef HAVE_IPV6
10200 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10201 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10202 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10203#else
10204 afi = AFI_IP;
10205 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10206 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10207#endif
10208
10209 return peer_adj_routes (vty, peer, afi, safi, in);
10210}
10211
paul718e3742002-12-13 20:15:29 +000010212DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10213 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10214 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10215 SHOW_STR
10216 IP_STR
10217 BGP_STR
10218 "Detailed information on TCP and BGP neighbor connections\n"
10219 "Neighbor to display information about\n"
10220 "Neighbor to display information about\n"
10221 "Display information received from a BGP neighbor\n"
10222 "Display the prefixlist filter\n")
10223{
10224 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010225 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010226 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010227 int count, ret;
paul718e3742002-12-13 20:15:29 +000010228
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010229 ret = str2sockunion (argv[0], &su);
10230 if (ret < 0)
10231 {
10232 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10233 return CMD_WARNING;
10234 }
paul718e3742002-12-13 20:15:29 +000010235
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010236 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010237 if (! peer)
10238 return CMD_WARNING;
10239
10240 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10241 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10242 if (count)
10243 {
10244 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10245 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10246 }
10247
10248 return CMD_SUCCESS;
10249}
10250
10251DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10252 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10253 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10254 SHOW_STR
10255 IP_STR
10256 BGP_STR
10257 "Address family\n"
10258 "Address Family modifier\n"
10259 "Address Family modifier\n"
10260 "Detailed information on TCP and BGP neighbor connections\n"
10261 "Neighbor to display information about\n"
10262 "Neighbor to display information about\n"
10263 "Display information received from a BGP neighbor\n"
10264 "Display the prefixlist filter\n")
10265{
10266 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010267 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010268 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010269 int count, ret;
paul718e3742002-12-13 20:15:29 +000010270
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010271 ret = str2sockunion (argv[1], &su);
10272 if (ret < 0)
10273 {
10274 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10275 return CMD_WARNING;
10276 }
paul718e3742002-12-13 20:15:29 +000010277
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010278 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010279 if (! peer)
10280 return CMD_WARNING;
10281
10282 if (strncmp (argv[0], "m", 1) == 0)
10283 {
10284 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10285 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10286 if (count)
10287 {
10288 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10289 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10290 }
10291 }
10292 else
10293 {
10294 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10295 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10296 if (count)
10297 {
10298 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10299 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10300 }
10301 }
10302
10303 return CMD_SUCCESS;
10304}
10305
10306
10307#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010308ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010309 show_bgp_neighbor_received_routes_cmd,
10310 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10311 SHOW_STR
10312 BGP_STR
10313 "Detailed information on TCP and BGP neighbor connections\n"
10314 "Neighbor to display information about\n"
10315 "Neighbor to display information about\n"
10316 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010317
paulbb46e942003-10-24 19:02:03 +000010318ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010319 show_bgp_ipv6_neighbor_received_routes_cmd,
10320 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10321 SHOW_STR
10322 BGP_STR
10323 "Address family\n"
10324 "Detailed information on TCP and BGP neighbor connections\n"
10325 "Neighbor to display information about\n"
10326 "Neighbor to display information about\n"
10327 "Display the received routes from neighbor\n")
10328
10329DEFUN (show_bgp_neighbor_received_prefix_filter,
10330 show_bgp_neighbor_received_prefix_filter_cmd,
10331 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10332 SHOW_STR
10333 BGP_STR
10334 "Detailed information on TCP and BGP neighbor connections\n"
10335 "Neighbor to display information about\n"
10336 "Neighbor to display information about\n"
10337 "Display information received from a BGP neighbor\n"
10338 "Display the prefixlist filter\n")
10339{
10340 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010341 union sockunion su;
paul718e3742002-12-13 20:15:29 +000010342 struct peer *peer;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010343 int count, ret;
paul718e3742002-12-13 20:15:29 +000010344
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010345 ret = str2sockunion (argv[0], &su);
10346 if (ret < 0)
10347 {
10348 vty_out (vty, "Malformed address: %s%s", argv[0], VTY_NEWLINE);
10349 return CMD_WARNING;
10350 }
paul718e3742002-12-13 20:15:29 +000010351
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010352 peer = peer_lookup (NULL, &su);
paul718e3742002-12-13 20:15:29 +000010353 if (! peer)
10354 return CMD_WARNING;
10355
10356 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10357 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10358 if (count)
10359 {
10360 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10361 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10362 }
10363
10364 return CMD_SUCCESS;
10365}
10366
10367ALIAS (show_bgp_neighbor_received_prefix_filter,
10368 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10369 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10370 SHOW_STR
10371 BGP_STR
10372 "Address family\n"
10373 "Detailed information on TCP and BGP neighbor connections\n"
10374 "Neighbor to display information about\n"
10375 "Neighbor to display information about\n"
10376 "Display information received from a BGP neighbor\n"
10377 "Display the prefixlist filter\n")
10378
10379/* old command */
paulbb46e942003-10-24 19:02:03 +000010380ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010381 ipv6_bgp_neighbor_received_routes_cmd,
10382 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10383 SHOW_STR
10384 IPV6_STR
10385 BGP_STR
10386 "Detailed information on TCP and BGP neighbor connections\n"
10387 "Neighbor to display information about\n"
10388 "Neighbor to display information about\n"
10389 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010390
10391/* old command */
10392DEFUN (ipv6_mbgp_neighbor_received_routes,
10393 ipv6_mbgp_neighbor_received_routes_cmd,
10394 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10395 SHOW_STR
10396 IPV6_STR
10397 MBGP_STR
10398 "Detailed information on TCP and BGP neighbor connections\n"
10399 "Neighbor to display information about\n"
10400 "Neighbor to display information about\n"
10401 "Display the received routes from neighbor\n")
10402{
paulbb46e942003-10-24 19:02:03 +000010403 struct peer *peer;
10404
10405 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10406 if (! peer)
10407 return CMD_WARNING;
10408
10409 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010410}
paulbb46e942003-10-24 19:02:03 +000010411
10412DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10413 show_bgp_view_neighbor_received_prefix_filter_cmd,
10414 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10415 SHOW_STR
10416 BGP_STR
10417 "BGP view\n"
10418 "View name\n"
10419 "Detailed information on TCP and BGP neighbor connections\n"
10420 "Neighbor to display information about\n"
10421 "Neighbor to display information about\n"
10422 "Display information received from a BGP neighbor\n"
10423 "Display the prefixlist filter\n")
10424{
10425 char name[BUFSIZ];
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010426 union sockunion su;
paulbb46e942003-10-24 19:02:03 +000010427 struct peer *peer;
10428 struct bgp *bgp;
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010429 int count, ret;
paulbb46e942003-10-24 19:02:03 +000010430
10431 /* BGP structure lookup. */
10432 bgp = bgp_lookup_by_name (argv[0]);
10433 if (bgp == NULL)
10434 {
10435 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10436 return CMD_WARNING;
10437 }
10438
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010439 ret = str2sockunion (argv[1], &su);
10440 if (ret < 0)
10441 {
10442 vty_out (vty, "Malformed address: %s%s", argv[1], VTY_NEWLINE);
10443 return CMD_WARNING;
10444 }
paulbb46e942003-10-24 19:02:03 +000010445
Jorge Boncompte [DTI2]c63b83f2012-04-10 16:57:24 +020010446 peer = peer_lookup (bgp, &su);
paulbb46e942003-10-24 19:02:03 +000010447 if (! peer)
10448 return CMD_WARNING;
10449
10450 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10451 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10452 if (count)
10453 {
10454 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10455 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10456 }
10457
10458 return CMD_SUCCESS;
10459}
10460
10461ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10462 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10463 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10464 SHOW_STR
10465 BGP_STR
10466 "BGP view\n"
10467 "View name\n"
10468 "Address family\n"
10469 "Detailed information on TCP and BGP neighbor connections\n"
10470 "Neighbor to display information about\n"
10471 "Neighbor to display information about\n"
10472 "Display information received from a BGP neighbor\n"
10473 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010474#endif /* HAVE_IPV6 */
10475
paul94f2b392005-06-28 12:44:16 +000010476static int
paulbb46e942003-10-24 19:02:03 +000010477bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010478 safi_t safi, enum bgp_show_type type)
10479{
paul718e3742002-12-13 20:15:29 +000010480 if (! peer || ! peer->afc[afi][safi])
10481 {
10482 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010483 return CMD_WARNING;
10484 }
10485
ajs5a646652004-11-05 01:25:55 +000010486 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010487}
10488
10489DEFUN (show_ip_bgp_neighbor_routes,
10490 show_ip_bgp_neighbor_routes_cmd,
10491 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10492 SHOW_STR
10493 IP_STR
10494 BGP_STR
10495 "Detailed information on TCP and BGP neighbor connections\n"
10496 "Neighbor to display information about\n"
10497 "Neighbor to display information about\n"
10498 "Display routes learned from neighbor\n")
10499{
paulbb46e942003-10-24 19:02:03 +000010500 struct peer *peer;
10501
10502 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10503 if (! peer)
10504 return CMD_WARNING;
10505
10506 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010507 bgp_show_type_neighbor);
10508}
10509
10510DEFUN (show_ip_bgp_neighbor_flap,
10511 show_ip_bgp_neighbor_flap_cmd,
10512 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10513 SHOW_STR
10514 IP_STR
10515 BGP_STR
10516 "Detailed information on TCP and BGP neighbor connections\n"
10517 "Neighbor to display information about\n"
10518 "Neighbor to display information about\n"
10519 "Display flap statistics of the routes learned from neighbor\n")
10520{
paulbb46e942003-10-24 19:02:03 +000010521 struct peer *peer;
10522
10523 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10524 if (! peer)
10525 return CMD_WARNING;
10526
10527 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010528 bgp_show_type_flap_neighbor);
10529}
10530
10531DEFUN (show_ip_bgp_neighbor_damp,
10532 show_ip_bgp_neighbor_damp_cmd,
10533 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10534 SHOW_STR
10535 IP_STR
10536 BGP_STR
10537 "Detailed information on TCP and BGP neighbor connections\n"
10538 "Neighbor to display information about\n"
10539 "Neighbor to display information about\n"
10540 "Display the dampened routes received from neighbor\n")
10541{
paulbb46e942003-10-24 19:02:03 +000010542 struct peer *peer;
10543
10544 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10545 if (! peer)
10546 return CMD_WARNING;
10547
10548 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010549 bgp_show_type_damp_neighbor);
10550}
10551
10552DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10553 show_ip_bgp_ipv4_neighbor_routes_cmd,
10554 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10555 SHOW_STR
10556 IP_STR
10557 BGP_STR
10558 "Address family\n"
10559 "Address Family modifier\n"
10560 "Address Family modifier\n"
10561 "Detailed information on TCP and BGP neighbor connections\n"
10562 "Neighbor to display information about\n"
10563 "Neighbor to display information about\n"
10564 "Display routes learned from neighbor\n")
10565{
paulbb46e942003-10-24 19:02:03 +000010566 struct peer *peer;
10567
10568 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10569 if (! peer)
10570 return CMD_WARNING;
10571
paul718e3742002-12-13 20:15:29 +000010572 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010573 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010574 bgp_show_type_neighbor);
10575
paulbb46e942003-10-24 19:02:03 +000010576 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010577 bgp_show_type_neighbor);
10578}
paulbb46e942003-10-24 19:02:03 +000010579
paulfee0f4c2004-09-13 05:12:46 +000010580DEFUN (show_ip_bgp_view_rsclient,
10581 show_ip_bgp_view_rsclient_cmd,
10582 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10583 SHOW_STR
10584 IP_STR
10585 BGP_STR
10586 "BGP view\n"
10587 "BGP view name\n"
10588 "Information about Route Server Client\n"
10589 NEIGHBOR_ADDR_STR)
10590{
10591 struct bgp_table *table;
10592 struct peer *peer;
10593
10594 if (argc == 2)
10595 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10596 else
10597 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10598
10599 if (! peer)
10600 return CMD_WARNING;
10601
10602 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10603 {
10604 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10605 VTY_NEWLINE);
10606 return CMD_WARNING;
10607 }
10608
10609 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10610 PEER_FLAG_RSERVER_CLIENT))
10611 {
10612 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10613 VTY_NEWLINE);
10614 return CMD_WARNING;
10615 }
10616
10617 table = peer->rib[AFI_IP][SAFI_UNICAST];
10618
ajs5a646652004-11-05 01:25:55 +000010619 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010620}
10621
10622ALIAS (show_ip_bgp_view_rsclient,
10623 show_ip_bgp_rsclient_cmd,
10624 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10625 SHOW_STR
10626 IP_STR
10627 BGP_STR
10628 "Information about Route Server Client\n"
10629 NEIGHBOR_ADDR_STR)
10630
Michael Lambert95cbbd22010-07-23 14:43:04 -040010631DEFUN (show_bgp_view_ipv4_safi_rsclient,
10632 show_bgp_view_ipv4_safi_rsclient_cmd,
10633 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10634 SHOW_STR
10635 BGP_STR
10636 "BGP view\n"
10637 "BGP view name\n"
10638 "Address family\n"
10639 "Address Family modifier\n"
10640 "Address Family modifier\n"
10641 "Information about Route Server Client\n"
10642 NEIGHBOR_ADDR_STR)
10643{
10644 struct bgp_table *table;
10645 struct peer *peer;
10646 safi_t safi;
10647
10648 if (argc == 3) {
10649 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10650 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10651 } else {
10652 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10653 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10654 }
10655
10656 if (! peer)
10657 return CMD_WARNING;
10658
10659 if (! peer->afc[AFI_IP][safi])
10660 {
10661 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10662 VTY_NEWLINE);
10663 return CMD_WARNING;
10664 }
10665
10666 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10667 PEER_FLAG_RSERVER_CLIENT))
10668 {
10669 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10670 VTY_NEWLINE);
10671 return CMD_WARNING;
10672 }
10673
10674 table = peer->rib[AFI_IP][safi];
10675
10676 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10677}
10678
10679ALIAS (show_bgp_view_ipv4_safi_rsclient,
10680 show_bgp_ipv4_safi_rsclient_cmd,
10681 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10682 SHOW_STR
10683 BGP_STR
10684 "Address family\n"
10685 "Address Family modifier\n"
10686 "Address Family modifier\n"
10687 "Information about Route Server Client\n"
10688 NEIGHBOR_ADDR_STR)
10689
paulfee0f4c2004-09-13 05:12:46 +000010690DEFUN (show_ip_bgp_view_rsclient_route,
10691 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010692 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010693 SHOW_STR
10694 IP_STR
10695 BGP_STR
10696 "BGP view\n"
10697 "BGP view name\n"
10698 "Information about Route Server Client\n"
10699 NEIGHBOR_ADDR_STR
10700 "Network in the BGP routing table to display\n")
10701{
10702 struct bgp *bgp;
10703 struct peer *peer;
10704
10705 /* BGP structure lookup. */
10706 if (argc == 3)
10707 {
10708 bgp = bgp_lookup_by_name (argv[0]);
10709 if (bgp == NULL)
10710 {
10711 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10712 return CMD_WARNING;
10713 }
10714 }
10715 else
10716 {
10717 bgp = bgp_get_default ();
10718 if (bgp == NULL)
10719 {
10720 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10721 return CMD_WARNING;
10722 }
10723 }
10724
10725 if (argc == 3)
10726 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10727 else
10728 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10729
10730 if (! peer)
10731 return CMD_WARNING;
10732
10733 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10734 {
10735 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10736 VTY_NEWLINE);
10737 return CMD_WARNING;
10738}
10739
10740 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10741 PEER_FLAG_RSERVER_CLIENT))
10742 {
10743 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10744 VTY_NEWLINE);
10745 return CMD_WARNING;
10746 }
10747
10748 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10749 (argc == 3) ? argv[2] : argv[1],
10750 AFI_IP, SAFI_UNICAST, NULL, 0);
10751}
10752
10753ALIAS (show_ip_bgp_view_rsclient_route,
10754 show_ip_bgp_rsclient_route_cmd,
10755 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10756 SHOW_STR
10757 IP_STR
10758 BGP_STR
10759 "Information about Route Server Client\n"
10760 NEIGHBOR_ADDR_STR
10761 "Network in the BGP routing table to display\n")
10762
Michael Lambert95cbbd22010-07-23 14:43:04 -040010763DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10764 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10765 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10766 SHOW_STR
10767 BGP_STR
10768 "BGP view\n"
10769 "BGP view name\n"
10770 "Address family\n"
10771 "Address Family modifier\n"
10772 "Address Family modifier\n"
10773 "Information about Route Server Client\n"
10774 NEIGHBOR_ADDR_STR
10775 "Network in the BGP routing table to display\n")
10776{
10777 struct bgp *bgp;
10778 struct peer *peer;
10779 safi_t safi;
10780
10781 /* BGP structure lookup. */
10782 if (argc == 4)
10783 {
10784 bgp = bgp_lookup_by_name (argv[0]);
10785 if (bgp == NULL)
10786 {
10787 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10788 return CMD_WARNING;
10789 }
10790 }
10791 else
10792 {
10793 bgp = bgp_get_default ();
10794 if (bgp == NULL)
10795 {
10796 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10797 return CMD_WARNING;
10798 }
10799 }
10800
10801 if (argc == 4) {
10802 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10803 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10804 } else {
10805 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10806 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10807 }
10808
10809 if (! peer)
10810 return CMD_WARNING;
10811
10812 if (! peer->afc[AFI_IP][safi])
10813 {
10814 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10815 VTY_NEWLINE);
10816 return CMD_WARNING;
10817}
10818
10819 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10820 PEER_FLAG_RSERVER_CLIENT))
10821 {
10822 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10823 VTY_NEWLINE);
10824 return CMD_WARNING;
10825 }
10826
10827 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10828 (argc == 4) ? argv[3] : argv[2],
10829 AFI_IP, safi, NULL, 0);
10830}
10831
10832ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10833 show_bgp_ipv4_safi_rsclient_route_cmd,
10834 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10835 SHOW_STR
10836 BGP_STR
10837 "Address family\n"
10838 "Address Family modifier\n"
10839 "Address Family modifier\n"
10840 "Information about Route Server Client\n"
10841 NEIGHBOR_ADDR_STR
10842 "Network in the BGP routing table to display\n")
10843
paulfee0f4c2004-09-13 05:12:46 +000010844DEFUN (show_ip_bgp_view_rsclient_prefix,
10845 show_ip_bgp_view_rsclient_prefix_cmd,
10846 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10847 SHOW_STR
10848 IP_STR
10849 BGP_STR
10850 "BGP view\n"
10851 "BGP view name\n"
10852 "Information about Route Server Client\n"
10853 NEIGHBOR_ADDR_STR
10854 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10855{
10856 struct bgp *bgp;
10857 struct peer *peer;
10858
10859 /* BGP structure lookup. */
10860 if (argc == 3)
10861 {
10862 bgp = bgp_lookup_by_name (argv[0]);
10863 if (bgp == NULL)
10864 {
10865 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10866 return CMD_WARNING;
10867 }
10868 }
10869 else
10870 {
10871 bgp = bgp_get_default ();
10872 if (bgp == NULL)
10873 {
10874 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10875 return CMD_WARNING;
10876 }
10877 }
10878
10879 if (argc == 3)
10880 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10881 else
10882 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10883
10884 if (! peer)
10885 return CMD_WARNING;
10886
10887 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10888 {
10889 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10890 VTY_NEWLINE);
10891 return CMD_WARNING;
10892}
10893
10894 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10895 PEER_FLAG_RSERVER_CLIENT))
10896{
10897 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10898 VTY_NEWLINE);
10899 return CMD_WARNING;
10900 }
10901
10902 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10903 (argc == 3) ? argv[2] : argv[1],
10904 AFI_IP, SAFI_UNICAST, NULL, 1);
10905}
10906
10907ALIAS (show_ip_bgp_view_rsclient_prefix,
10908 show_ip_bgp_rsclient_prefix_cmd,
10909 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10910 SHOW_STR
10911 IP_STR
10912 BGP_STR
10913 "Information about Route Server Client\n"
10914 NEIGHBOR_ADDR_STR
10915 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10916
Michael Lambert95cbbd22010-07-23 14:43:04 -040010917DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10918 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10919 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10920 SHOW_STR
10921 BGP_STR
10922 "BGP view\n"
10923 "BGP view name\n"
10924 "Address family\n"
10925 "Address Family modifier\n"
10926 "Address Family modifier\n"
10927 "Information about Route Server Client\n"
10928 NEIGHBOR_ADDR_STR
10929 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10930{
10931 struct bgp *bgp;
10932 struct peer *peer;
10933 safi_t safi;
10934
10935 /* BGP structure lookup. */
10936 if (argc == 4)
10937 {
10938 bgp = bgp_lookup_by_name (argv[0]);
10939 if (bgp == NULL)
10940 {
10941 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10942 return CMD_WARNING;
10943 }
10944 }
10945 else
10946 {
10947 bgp = bgp_get_default ();
10948 if (bgp == NULL)
10949 {
10950 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10951 return CMD_WARNING;
10952 }
10953 }
10954
10955 if (argc == 4) {
10956 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10957 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10958 } else {
10959 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10960 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10961 }
10962
10963 if (! peer)
10964 return CMD_WARNING;
10965
10966 if (! peer->afc[AFI_IP][safi])
10967 {
10968 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10969 VTY_NEWLINE);
10970 return CMD_WARNING;
10971}
10972
10973 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10974 PEER_FLAG_RSERVER_CLIENT))
10975{
10976 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10977 VTY_NEWLINE);
10978 return CMD_WARNING;
10979 }
10980
10981 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10982 (argc == 4) ? argv[3] : argv[2],
10983 AFI_IP, safi, NULL, 1);
10984}
10985
10986ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10987 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10988 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10989 SHOW_STR
10990 BGP_STR
10991 "Address family\n"
10992 "Address Family modifier\n"
10993 "Address Family modifier\n"
10994 "Information about Route Server Client\n"
10995 NEIGHBOR_ADDR_STR
10996 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010997
paul718e3742002-12-13 20:15:29 +000010998#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010999DEFUN (show_bgp_view_neighbor_routes,
11000 show_bgp_view_neighbor_routes_cmd,
11001 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
11002 SHOW_STR
11003 BGP_STR
11004 "BGP view\n"
11005 "BGP view name\n"
11006 "Detailed information on TCP and BGP neighbor connections\n"
11007 "Neighbor to display information about\n"
11008 "Neighbor to display information about\n"
11009 "Display routes learned from neighbor\n")
11010{
11011 struct peer *peer;
11012
11013 if (argc == 2)
11014 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11015 else
11016 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11017
11018 if (! peer)
11019 return CMD_WARNING;
11020
11021 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11022 bgp_show_type_neighbor);
11023}
11024
11025ALIAS (show_bgp_view_neighbor_routes,
11026 show_bgp_view_ipv6_neighbor_routes_cmd,
11027 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11028 SHOW_STR
11029 BGP_STR
11030 "BGP view\n"
11031 "BGP view name\n"
11032 "Address family\n"
11033 "Detailed information on TCP and BGP neighbor connections\n"
11034 "Neighbor to display information about\n"
11035 "Neighbor to display information about\n"
11036 "Display routes learned from neighbor\n")
11037
11038DEFUN (show_bgp_view_neighbor_damp,
11039 show_bgp_view_neighbor_damp_cmd,
11040 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11041 SHOW_STR
11042 BGP_STR
11043 "BGP view\n"
11044 "BGP view name\n"
11045 "Detailed information on TCP and BGP neighbor connections\n"
11046 "Neighbor to display information about\n"
11047 "Neighbor to display information about\n"
11048 "Display the dampened routes received from neighbor\n")
11049{
11050 struct peer *peer;
11051
11052 if (argc == 2)
11053 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11054 else
11055 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11056
11057 if (! peer)
11058 return CMD_WARNING;
11059
11060 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11061 bgp_show_type_damp_neighbor);
11062}
11063
11064ALIAS (show_bgp_view_neighbor_damp,
11065 show_bgp_view_ipv6_neighbor_damp_cmd,
11066 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11067 SHOW_STR
11068 BGP_STR
11069 "BGP view\n"
11070 "BGP view name\n"
11071 "Address family\n"
11072 "Detailed information on TCP and BGP neighbor connections\n"
11073 "Neighbor to display information about\n"
11074 "Neighbor to display information about\n"
11075 "Display the dampened routes received from neighbor\n")
11076
11077DEFUN (show_bgp_view_neighbor_flap,
11078 show_bgp_view_neighbor_flap_cmd,
11079 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11080 SHOW_STR
11081 BGP_STR
11082 "BGP view\n"
11083 "BGP view name\n"
11084 "Detailed information on TCP and BGP neighbor connections\n"
11085 "Neighbor to display information about\n"
11086 "Neighbor to display information about\n"
11087 "Display flap statistics of the routes learned from neighbor\n")
11088{
11089 struct peer *peer;
11090
11091 if (argc == 2)
11092 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11093 else
11094 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11095
11096 if (! peer)
11097 return CMD_WARNING;
11098
11099 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11100 bgp_show_type_flap_neighbor);
11101}
11102
11103ALIAS (show_bgp_view_neighbor_flap,
11104 show_bgp_view_ipv6_neighbor_flap_cmd,
11105 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11106 SHOW_STR
11107 BGP_STR
11108 "BGP view\n"
11109 "BGP view name\n"
11110 "Address family\n"
11111 "Detailed information on TCP and BGP neighbor connections\n"
11112 "Neighbor to display information about\n"
11113 "Neighbor to display information about\n"
11114 "Display flap statistics of the routes learned from neighbor\n")
11115
11116ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011117 show_bgp_neighbor_routes_cmd,
11118 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11119 SHOW_STR
11120 BGP_STR
11121 "Detailed information on TCP and BGP neighbor connections\n"
11122 "Neighbor to display information about\n"
11123 "Neighbor to display information about\n"
11124 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011125
paulbb46e942003-10-24 19:02:03 +000011126
11127ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011128 show_bgp_ipv6_neighbor_routes_cmd,
11129 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11130 SHOW_STR
11131 BGP_STR
11132 "Address family\n"
11133 "Detailed information on TCP and BGP neighbor connections\n"
11134 "Neighbor to display information about\n"
11135 "Neighbor to display information about\n"
11136 "Display routes learned from neighbor\n")
11137
11138/* old command */
paulbb46e942003-10-24 19:02:03 +000011139ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011140 ipv6_bgp_neighbor_routes_cmd,
11141 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11142 SHOW_STR
11143 IPV6_STR
11144 BGP_STR
11145 "Detailed information on TCP and BGP neighbor connections\n"
11146 "Neighbor to display information about\n"
11147 "Neighbor to display information about\n"
11148 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011149
11150/* old command */
11151DEFUN (ipv6_mbgp_neighbor_routes,
11152 ipv6_mbgp_neighbor_routes_cmd,
11153 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11154 SHOW_STR
11155 IPV6_STR
11156 MBGP_STR
11157 "Detailed information on TCP and BGP neighbor connections\n"
11158 "Neighbor to display information about\n"
11159 "Neighbor to display information about\n"
11160 "Display routes learned from neighbor\n")
11161{
paulbb46e942003-10-24 19:02:03 +000011162 struct peer *peer;
11163
11164 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11165 if (! peer)
11166 return CMD_WARNING;
11167
11168 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011169 bgp_show_type_neighbor);
11170}
paulbb46e942003-10-24 19:02:03 +000011171
11172ALIAS (show_bgp_view_neighbor_flap,
11173 show_bgp_neighbor_flap_cmd,
11174 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11175 SHOW_STR
11176 BGP_STR
11177 "Detailed information on TCP and BGP neighbor connections\n"
11178 "Neighbor to display information about\n"
11179 "Neighbor to display information about\n"
11180 "Display flap statistics of the routes learned from neighbor\n")
11181
11182ALIAS (show_bgp_view_neighbor_flap,
11183 show_bgp_ipv6_neighbor_flap_cmd,
11184 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11185 SHOW_STR
11186 BGP_STR
11187 "Address family\n"
11188 "Detailed information on TCP and BGP neighbor connections\n"
11189 "Neighbor to display information about\n"
11190 "Neighbor to display information about\n"
11191 "Display flap statistics of the routes learned from neighbor\n")
11192
11193ALIAS (show_bgp_view_neighbor_damp,
11194 show_bgp_neighbor_damp_cmd,
11195 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11196 SHOW_STR
11197 BGP_STR
11198 "Detailed information on TCP and BGP neighbor connections\n"
11199 "Neighbor to display information about\n"
11200 "Neighbor to display information about\n"
11201 "Display the dampened routes received from neighbor\n")
11202
11203ALIAS (show_bgp_view_neighbor_damp,
11204 show_bgp_ipv6_neighbor_damp_cmd,
11205 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11206 SHOW_STR
11207 BGP_STR
11208 "Address family\n"
11209 "Detailed information on TCP and BGP neighbor connections\n"
11210 "Neighbor to display information about\n"
11211 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011212 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011213
11214DEFUN (show_bgp_view_rsclient,
11215 show_bgp_view_rsclient_cmd,
11216 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11217 SHOW_STR
11218 BGP_STR
11219 "BGP view\n"
11220 "BGP view name\n"
11221 "Information about Route Server Client\n"
11222 NEIGHBOR_ADDR_STR)
11223{
11224 struct bgp_table *table;
11225 struct peer *peer;
11226
11227 if (argc == 2)
11228 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11229 else
11230 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11231
11232 if (! peer)
11233 return CMD_WARNING;
11234
11235 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11236 {
11237 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11238 VTY_NEWLINE);
11239 return CMD_WARNING;
11240 }
11241
11242 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11243 PEER_FLAG_RSERVER_CLIENT))
11244 {
11245 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11246 VTY_NEWLINE);
11247 return CMD_WARNING;
11248 }
11249
11250 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11251
ajs5a646652004-11-05 01:25:55 +000011252 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011253}
11254
11255ALIAS (show_bgp_view_rsclient,
11256 show_bgp_rsclient_cmd,
11257 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11258 SHOW_STR
11259 BGP_STR
11260 "Information about Route Server Client\n"
11261 NEIGHBOR_ADDR_STR)
11262
Michael Lambert95cbbd22010-07-23 14:43:04 -040011263DEFUN (show_bgp_view_ipv6_safi_rsclient,
11264 show_bgp_view_ipv6_safi_rsclient_cmd,
11265 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11266 SHOW_STR
11267 BGP_STR
11268 "BGP view\n"
11269 "BGP view name\n"
11270 "Address family\n"
11271 "Address Family modifier\n"
11272 "Address Family modifier\n"
11273 "Information about Route Server Client\n"
11274 NEIGHBOR_ADDR_STR)
11275{
11276 struct bgp_table *table;
11277 struct peer *peer;
11278 safi_t safi;
11279
11280 if (argc == 3) {
11281 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11282 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11283 } else {
11284 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11285 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11286 }
11287
11288 if (! peer)
11289 return CMD_WARNING;
11290
11291 if (! peer->afc[AFI_IP6][safi])
11292 {
11293 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11294 VTY_NEWLINE);
11295 return CMD_WARNING;
11296 }
11297
11298 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11299 PEER_FLAG_RSERVER_CLIENT))
11300 {
11301 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11302 VTY_NEWLINE);
11303 return CMD_WARNING;
11304 }
11305
11306 table = peer->rib[AFI_IP6][safi];
11307
11308 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11309}
11310
11311ALIAS (show_bgp_view_ipv6_safi_rsclient,
11312 show_bgp_ipv6_safi_rsclient_cmd,
11313 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11314 SHOW_STR
11315 BGP_STR
11316 "Address family\n"
11317 "Address Family modifier\n"
11318 "Address Family modifier\n"
11319 "Information about Route Server Client\n"
11320 NEIGHBOR_ADDR_STR)
11321
paulfee0f4c2004-09-13 05:12:46 +000011322DEFUN (show_bgp_view_rsclient_route,
11323 show_bgp_view_rsclient_route_cmd,
11324 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11325 SHOW_STR
11326 BGP_STR
11327 "BGP view\n"
11328 "BGP view name\n"
11329 "Information about Route Server Client\n"
11330 NEIGHBOR_ADDR_STR
11331 "Network in the BGP routing table to display\n")
11332{
11333 struct bgp *bgp;
11334 struct peer *peer;
11335
11336 /* BGP structure lookup. */
11337 if (argc == 3)
11338 {
11339 bgp = bgp_lookup_by_name (argv[0]);
11340 if (bgp == NULL)
11341 {
11342 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11343 return CMD_WARNING;
11344 }
11345 }
11346 else
11347 {
11348 bgp = bgp_get_default ();
11349 if (bgp == NULL)
11350 {
11351 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11352 return CMD_WARNING;
11353 }
11354 }
11355
11356 if (argc == 3)
11357 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11358 else
11359 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11360
11361 if (! peer)
11362 return CMD_WARNING;
11363
11364 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11365 {
11366 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11367 VTY_NEWLINE);
11368 return CMD_WARNING;
11369 }
11370
11371 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11372 PEER_FLAG_RSERVER_CLIENT))
11373 {
11374 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11375 VTY_NEWLINE);
11376 return CMD_WARNING;
11377 }
11378
11379 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11380 (argc == 3) ? argv[2] : argv[1],
11381 AFI_IP6, SAFI_UNICAST, NULL, 0);
11382}
11383
11384ALIAS (show_bgp_view_rsclient_route,
11385 show_bgp_rsclient_route_cmd,
11386 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11387 SHOW_STR
11388 BGP_STR
11389 "Information about Route Server Client\n"
11390 NEIGHBOR_ADDR_STR
11391 "Network in the BGP routing table to display\n")
11392
Michael Lambert95cbbd22010-07-23 14:43:04 -040011393DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11394 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11395 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11396 SHOW_STR
11397 BGP_STR
11398 "BGP view\n"
11399 "BGP view name\n"
11400 "Address family\n"
11401 "Address Family modifier\n"
11402 "Address Family modifier\n"
11403 "Information about Route Server Client\n"
11404 NEIGHBOR_ADDR_STR
11405 "Network in the BGP routing table to display\n")
11406{
11407 struct bgp *bgp;
11408 struct peer *peer;
11409 safi_t safi;
11410
11411 /* BGP structure lookup. */
11412 if (argc == 4)
11413 {
11414 bgp = bgp_lookup_by_name (argv[0]);
11415 if (bgp == NULL)
11416 {
11417 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11418 return CMD_WARNING;
11419 }
11420 }
11421 else
11422 {
11423 bgp = bgp_get_default ();
11424 if (bgp == NULL)
11425 {
11426 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11427 return CMD_WARNING;
11428 }
11429 }
11430
11431 if (argc == 4) {
11432 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11433 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11434 } else {
11435 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11436 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11437 }
11438
11439 if (! peer)
11440 return CMD_WARNING;
11441
11442 if (! peer->afc[AFI_IP6][safi])
11443 {
11444 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11445 VTY_NEWLINE);
11446 return CMD_WARNING;
11447}
11448
11449 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11450 PEER_FLAG_RSERVER_CLIENT))
11451 {
11452 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11453 VTY_NEWLINE);
11454 return CMD_WARNING;
11455 }
11456
11457 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11458 (argc == 4) ? argv[3] : argv[2],
11459 AFI_IP6, safi, NULL, 0);
11460}
11461
11462ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11463 show_bgp_ipv6_safi_rsclient_route_cmd,
11464 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11465 SHOW_STR
11466 BGP_STR
11467 "Address family\n"
11468 "Address Family modifier\n"
11469 "Address Family modifier\n"
11470 "Information about Route Server Client\n"
11471 NEIGHBOR_ADDR_STR
11472 "Network in the BGP routing table to display\n")
11473
paulfee0f4c2004-09-13 05:12:46 +000011474DEFUN (show_bgp_view_rsclient_prefix,
11475 show_bgp_view_rsclient_prefix_cmd,
11476 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11477 SHOW_STR
11478 BGP_STR
11479 "BGP view\n"
11480 "BGP view name\n"
11481 "Information about Route Server Client\n"
11482 NEIGHBOR_ADDR_STR
11483 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11484{
11485 struct bgp *bgp;
11486 struct peer *peer;
11487
11488 /* BGP structure lookup. */
11489 if (argc == 3)
11490 {
11491 bgp = bgp_lookup_by_name (argv[0]);
11492 if (bgp == NULL)
11493 {
11494 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11495 return CMD_WARNING;
11496 }
11497 }
11498 else
11499 {
11500 bgp = bgp_get_default ();
11501 if (bgp == NULL)
11502 {
11503 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11504 return CMD_WARNING;
11505 }
11506 }
11507
11508 if (argc == 3)
11509 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11510 else
11511 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11512
11513 if (! peer)
11514 return CMD_WARNING;
11515
11516 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11517 {
11518 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11519 VTY_NEWLINE);
11520 return CMD_WARNING;
11521 }
11522
11523 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11524 PEER_FLAG_RSERVER_CLIENT))
11525 {
11526 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11527 VTY_NEWLINE);
11528 return CMD_WARNING;
11529 }
11530
11531 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11532 (argc == 3) ? argv[2] : argv[1],
11533 AFI_IP6, SAFI_UNICAST, NULL, 1);
11534}
11535
11536ALIAS (show_bgp_view_rsclient_prefix,
11537 show_bgp_rsclient_prefix_cmd,
11538 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11539 SHOW_STR
11540 BGP_STR
11541 "Information about Route Server Client\n"
11542 NEIGHBOR_ADDR_STR
11543 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11544
Michael Lambert95cbbd22010-07-23 14:43:04 -040011545DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11546 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11547 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11548 SHOW_STR
11549 BGP_STR
11550 "BGP view\n"
11551 "BGP view name\n"
11552 "Address family\n"
11553 "Address Family modifier\n"
11554 "Address Family modifier\n"
11555 "Information about Route Server Client\n"
11556 NEIGHBOR_ADDR_STR
11557 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11558{
11559 struct bgp *bgp;
11560 struct peer *peer;
11561 safi_t safi;
11562
11563 /* BGP structure lookup. */
11564 if (argc == 4)
11565 {
11566 bgp = bgp_lookup_by_name (argv[0]);
11567 if (bgp == NULL)
11568 {
11569 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11570 return CMD_WARNING;
11571 }
11572 }
11573 else
11574 {
11575 bgp = bgp_get_default ();
11576 if (bgp == NULL)
11577 {
11578 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11579 return CMD_WARNING;
11580 }
11581 }
11582
11583 if (argc == 4) {
11584 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11585 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11586 } else {
11587 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11588 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11589 }
11590
11591 if (! peer)
11592 return CMD_WARNING;
11593
11594 if (! peer->afc[AFI_IP6][safi])
11595 {
11596 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11597 VTY_NEWLINE);
11598 return CMD_WARNING;
11599}
11600
11601 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11602 PEER_FLAG_RSERVER_CLIENT))
11603{
11604 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11605 VTY_NEWLINE);
11606 return CMD_WARNING;
11607 }
11608
11609 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11610 (argc == 4) ? argv[3] : argv[2],
11611 AFI_IP6, safi, NULL, 1);
11612}
11613
11614ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11615 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11616 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11617 SHOW_STR
11618 BGP_STR
11619 "Address family\n"
11620 "Address Family modifier\n"
11621 "Address Family modifier\n"
11622 "Information about Route Server Client\n"
11623 NEIGHBOR_ADDR_STR
11624 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11625
paul718e3742002-12-13 20:15:29 +000011626#endif /* HAVE_IPV6 */
11627
11628struct bgp_table *bgp_distance_table;
11629
11630struct bgp_distance
11631{
11632 /* Distance value for the IP source prefix. */
11633 u_char distance;
11634
11635 /* Name of the access-list to be matched. */
11636 char *access_list;
11637};
11638
paul94f2b392005-06-28 12:44:16 +000011639static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011640bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011641{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011642 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011643}
11644
paul94f2b392005-06-28 12:44:16 +000011645static void
paul718e3742002-12-13 20:15:29 +000011646bgp_distance_free (struct bgp_distance *bdistance)
11647{
11648 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11649}
11650
paul94f2b392005-06-28 12:44:16 +000011651static int
paulfd79ac92004-10-13 05:06:08 +000011652bgp_distance_set (struct vty *vty, const char *distance_str,
11653 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011654{
11655 int ret;
11656 struct prefix_ipv4 p;
11657 u_char distance;
11658 struct bgp_node *rn;
11659 struct bgp_distance *bdistance;
11660
11661 ret = str2prefix_ipv4 (ip_str, &p);
11662 if (ret == 0)
11663 {
11664 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11665 return CMD_WARNING;
11666 }
11667
11668 distance = atoi (distance_str);
11669
11670 /* Get BGP distance node. */
11671 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11672 if (rn->info)
11673 {
11674 bdistance = rn->info;
11675 bgp_unlock_node (rn);
11676 }
11677 else
11678 {
11679 bdistance = bgp_distance_new ();
11680 rn->info = bdistance;
11681 }
11682
11683 /* Set distance value. */
11684 bdistance->distance = distance;
11685
11686 /* Reset access-list configuration. */
11687 if (bdistance->access_list)
11688 {
11689 free (bdistance->access_list);
11690 bdistance->access_list = NULL;
11691 }
11692 if (access_list_str)
11693 bdistance->access_list = strdup (access_list_str);
11694
11695 return CMD_SUCCESS;
11696}
11697
paul94f2b392005-06-28 12:44:16 +000011698static int
paulfd79ac92004-10-13 05:06:08 +000011699bgp_distance_unset (struct vty *vty, const char *distance_str,
11700 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011701{
11702 int ret;
11703 struct prefix_ipv4 p;
11704 u_char distance;
11705 struct bgp_node *rn;
11706 struct bgp_distance *bdistance;
11707
11708 ret = str2prefix_ipv4 (ip_str, &p);
11709 if (ret == 0)
11710 {
11711 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11712 return CMD_WARNING;
11713 }
11714
11715 distance = atoi (distance_str);
11716
11717 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11718 if (! rn)
11719 {
11720 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11721 return CMD_WARNING;
11722 }
11723
11724 bdistance = rn->info;
11725
11726 if (bdistance->access_list)
11727 free (bdistance->access_list);
11728 bgp_distance_free (bdistance);
11729
11730 rn->info = NULL;
11731 bgp_unlock_node (rn);
11732 bgp_unlock_node (rn);
11733
11734 return CMD_SUCCESS;
11735}
11736
paul718e3742002-12-13 20:15:29 +000011737/* Apply BGP information to distance method. */
11738u_char
11739bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11740{
11741 struct bgp_node *rn;
11742 struct prefix_ipv4 q;
11743 struct peer *peer;
11744 struct bgp_distance *bdistance;
11745 struct access_list *alist;
11746 struct bgp_static *bgp_static;
11747
11748 if (! bgp)
11749 return 0;
11750
11751 if (p->family != AF_INET)
11752 return 0;
11753
11754 peer = rinfo->peer;
11755
11756 if (peer->su.sa.sa_family != AF_INET)
11757 return 0;
11758
11759 memset (&q, 0, sizeof (struct prefix_ipv4));
11760 q.family = AF_INET;
11761 q.prefix = peer->su.sin.sin_addr;
11762 q.prefixlen = IPV4_MAX_BITLEN;
11763
11764 /* Check source address. */
11765 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11766 if (rn)
11767 {
11768 bdistance = rn->info;
11769 bgp_unlock_node (rn);
11770
11771 if (bdistance->access_list)
11772 {
11773 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11774 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11775 return bdistance->distance;
11776 }
11777 else
11778 return bdistance->distance;
11779 }
11780
11781 /* Backdoor check. */
11782 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11783 if (rn)
11784 {
11785 bgp_static = rn->info;
11786 bgp_unlock_node (rn);
11787
11788 if (bgp_static->backdoor)
11789 {
11790 if (bgp->distance_local)
11791 return bgp->distance_local;
11792 else
11793 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11794 }
11795 }
11796
Jorge Boncompte [DTI2]6d85b152012-05-07 16:52:54 +000011797 if (peer->sort == BGP_PEER_EBGP)
paul718e3742002-12-13 20:15:29 +000011798 {
11799 if (bgp->distance_ebgp)
11800 return bgp->distance_ebgp;
11801 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11802 }
11803 else
11804 {
11805 if (bgp->distance_ibgp)
11806 return bgp->distance_ibgp;
11807 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11808 }
11809}
11810
11811DEFUN (bgp_distance,
11812 bgp_distance_cmd,
11813 "distance bgp <1-255> <1-255> <1-255>",
11814 "Define an administrative distance\n"
11815 "BGP distance\n"
11816 "Distance for routes external to the AS\n"
11817 "Distance for routes internal to the AS\n"
11818 "Distance for local routes\n")
11819{
11820 struct bgp *bgp;
11821
11822 bgp = vty->index;
11823
11824 bgp->distance_ebgp = atoi (argv[0]);
11825 bgp->distance_ibgp = atoi (argv[1]);
11826 bgp->distance_local = atoi (argv[2]);
11827 return CMD_SUCCESS;
11828}
11829
11830DEFUN (no_bgp_distance,
11831 no_bgp_distance_cmd,
11832 "no distance bgp <1-255> <1-255> <1-255>",
11833 NO_STR
11834 "Define an administrative distance\n"
11835 "BGP distance\n"
11836 "Distance for routes external to the AS\n"
11837 "Distance for routes internal to the AS\n"
11838 "Distance for local routes\n")
11839{
11840 struct bgp *bgp;
11841
11842 bgp = vty->index;
11843
11844 bgp->distance_ebgp= 0;
11845 bgp->distance_ibgp = 0;
11846 bgp->distance_local = 0;
11847 return CMD_SUCCESS;
11848}
11849
11850ALIAS (no_bgp_distance,
11851 no_bgp_distance2_cmd,
11852 "no distance bgp",
11853 NO_STR
11854 "Define an administrative distance\n"
11855 "BGP distance\n")
11856
11857DEFUN (bgp_distance_source,
11858 bgp_distance_source_cmd,
11859 "distance <1-255> A.B.C.D/M",
11860 "Define an administrative distance\n"
11861 "Administrative distance\n"
11862 "IP source prefix\n")
11863{
11864 bgp_distance_set (vty, argv[0], argv[1], NULL);
11865 return CMD_SUCCESS;
11866}
11867
11868DEFUN (no_bgp_distance_source,
11869 no_bgp_distance_source_cmd,
11870 "no distance <1-255> A.B.C.D/M",
11871 NO_STR
11872 "Define an administrative distance\n"
11873 "Administrative distance\n"
11874 "IP source prefix\n")
11875{
11876 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11877 return CMD_SUCCESS;
11878}
11879
11880DEFUN (bgp_distance_source_access_list,
11881 bgp_distance_source_access_list_cmd,
11882 "distance <1-255> A.B.C.D/M WORD",
11883 "Define an administrative distance\n"
11884 "Administrative distance\n"
11885 "IP source prefix\n"
11886 "Access list name\n")
11887{
11888 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11889 return CMD_SUCCESS;
11890}
11891
11892DEFUN (no_bgp_distance_source_access_list,
11893 no_bgp_distance_source_access_list_cmd,
11894 "no distance <1-255> A.B.C.D/M WORD",
11895 NO_STR
11896 "Define an administrative distance\n"
11897 "Administrative distance\n"
11898 "IP source prefix\n"
11899 "Access list name\n")
11900{
11901 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11902 return CMD_SUCCESS;
11903}
11904
11905DEFUN (bgp_damp_set,
11906 bgp_damp_set_cmd,
11907 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11908 "BGP Specific commands\n"
11909 "Enable route-flap dampening\n"
11910 "Half-life time for the penalty\n"
11911 "Value to start reusing a route\n"
11912 "Value to start suppressing a route\n"
11913 "Maximum duration to suppress a stable route\n")
11914{
11915 struct bgp *bgp;
11916 int half = DEFAULT_HALF_LIFE * 60;
11917 int reuse = DEFAULT_REUSE;
11918 int suppress = DEFAULT_SUPPRESS;
11919 int max = 4 * half;
11920
11921 if (argc == 4)
11922 {
11923 half = atoi (argv[0]) * 60;
11924 reuse = atoi (argv[1]);
11925 suppress = atoi (argv[2]);
11926 max = atoi (argv[3]) * 60;
11927 }
11928 else if (argc == 1)
11929 {
11930 half = atoi (argv[0]) * 60;
11931 max = 4 * half;
11932 }
11933
11934 bgp = vty->index;
11935 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11936 half, reuse, suppress, max);
11937}
11938
11939ALIAS (bgp_damp_set,
11940 bgp_damp_set2_cmd,
11941 "bgp dampening <1-45>",
11942 "BGP Specific commands\n"
11943 "Enable route-flap dampening\n"
11944 "Half-life time for the penalty\n")
11945
11946ALIAS (bgp_damp_set,
11947 bgp_damp_set3_cmd,
11948 "bgp dampening",
11949 "BGP Specific commands\n"
11950 "Enable route-flap dampening\n")
11951
11952DEFUN (bgp_damp_unset,
11953 bgp_damp_unset_cmd,
11954 "no bgp dampening",
11955 NO_STR
11956 "BGP Specific commands\n"
11957 "Enable route-flap dampening\n")
11958{
11959 struct bgp *bgp;
11960
11961 bgp = vty->index;
11962 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11963}
11964
11965ALIAS (bgp_damp_unset,
11966 bgp_damp_unset2_cmd,
11967 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11968 NO_STR
11969 "BGP Specific commands\n"
11970 "Enable route-flap dampening\n"
11971 "Half-life time for the penalty\n"
11972 "Value to start reusing a route\n"
11973 "Value to start suppressing a route\n"
11974 "Maximum duration to suppress a stable route\n")
11975
11976DEFUN (show_ip_bgp_dampened_paths,
11977 show_ip_bgp_dampened_paths_cmd,
11978 "show ip bgp dampened-paths",
11979 SHOW_STR
11980 IP_STR
11981 BGP_STR
11982 "Display paths suppressed due to dampening\n")
11983{
ajs5a646652004-11-05 01:25:55 +000011984 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11985 NULL);
paul718e3742002-12-13 20:15:29 +000011986}
11987
11988DEFUN (show_ip_bgp_flap_statistics,
11989 show_ip_bgp_flap_statistics_cmd,
11990 "show ip bgp flap-statistics",
11991 SHOW_STR
11992 IP_STR
11993 BGP_STR
11994 "Display flap statistics of routes\n")
11995{
ajs5a646652004-11-05 01:25:55 +000011996 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11997 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011998}
11999
12000/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000012001static int
paulfd79ac92004-10-13 05:06:08 +000012002bgp_clear_damp_route (struct vty *vty, const char *view_name,
12003 const char *ip_str, afi_t afi, safi_t safi,
12004 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000012005{
12006 int ret;
12007 struct prefix match;
12008 struct bgp_node *rn;
12009 struct bgp_node *rm;
12010 struct bgp_info *ri;
12011 struct bgp_info *ri_temp;
12012 struct bgp *bgp;
12013 struct bgp_table *table;
12014
12015 /* BGP structure lookup. */
12016 if (view_name)
12017 {
12018 bgp = bgp_lookup_by_name (view_name);
12019 if (bgp == NULL)
12020 {
12021 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
12022 return CMD_WARNING;
12023 }
12024 }
12025 else
12026 {
12027 bgp = bgp_get_default ();
12028 if (bgp == NULL)
12029 {
12030 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12031 return CMD_WARNING;
12032 }
12033 }
12034
12035 /* Check IP address argument. */
12036 ret = str2prefix (ip_str, &match);
12037 if (! ret)
12038 {
12039 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12040 return CMD_WARNING;
12041 }
12042
12043 match.family = afi2family (afi);
12044
12045 if (safi == SAFI_MPLS_VPN)
12046 {
12047 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12048 {
12049 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12050 continue;
12051
12052 if ((table = rn->info) != NULL)
12053 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012054 {
12055 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12056 {
12057 ri = rm->info;
12058 while (ri)
12059 {
12060 if (ri->extra && ri->extra->damp_info)
12061 {
12062 ri_temp = ri->next;
12063 bgp_damp_info_free (ri->extra->damp_info, 1);
12064 ri = ri_temp;
12065 }
12066 else
12067 ri = ri->next;
12068 }
12069 }
12070
12071 bgp_unlock_node (rm);
12072 }
paul718e3742002-12-13 20:15:29 +000012073 }
12074 }
12075 else
12076 {
12077 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012078 {
12079 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12080 {
12081 ri = rn->info;
12082 while (ri)
12083 {
12084 if (ri->extra && ri->extra->damp_info)
12085 {
12086 ri_temp = ri->next;
12087 bgp_damp_info_free (ri->extra->damp_info, 1);
12088 ri = ri_temp;
12089 }
12090 else
12091 ri = ri->next;
12092 }
12093 }
12094
12095 bgp_unlock_node (rn);
12096 }
paul718e3742002-12-13 20:15:29 +000012097 }
12098
12099 return CMD_SUCCESS;
12100}
12101
12102DEFUN (clear_ip_bgp_dampening,
12103 clear_ip_bgp_dampening_cmd,
12104 "clear ip bgp dampening",
12105 CLEAR_STR
12106 IP_STR
12107 BGP_STR
12108 "Clear route flap dampening information\n")
12109{
12110 bgp_damp_info_clean ();
12111 return CMD_SUCCESS;
12112}
12113
12114DEFUN (clear_ip_bgp_dampening_prefix,
12115 clear_ip_bgp_dampening_prefix_cmd,
12116 "clear ip bgp dampening A.B.C.D/M",
12117 CLEAR_STR
12118 IP_STR
12119 BGP_STR
12120 "Clear route flap dampening information\n"
12121 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12122{
12123 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12124 SAFI_UNICAST, NULL, 1);
12125}
12126
12127DEFUN (clear_ip_bgp_dampening_address,
12128 clear_ip_bgp_dampening_address_cmd,
12129 "clear ip bgp dampening A.B.C.D",
12130 CLEAR_STR
12131 IP_STR
12132 BGP_STR
12133 "Clear route flap dampening information\n"
12134 "Network to clear damping information\n")
12135{
12136 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12137 SAFI_UNICAST, NULL, 0);
12138}
12139
12140DEFUN (clear_ip_bgp_dampening_address_mask,
12141 clear_ip_bgp_dampening_address_mask_cmd,
12142 "clear ip bgp dampening A.B.C.D A.B.C.D",
12143 CLEAR_STR
12144 IP_STR
12145 BGP_STR
12146 "Clear route flap dampening information\n"
12147 "Network to clear damping information\n"
12148 "Network mask\n")
12149{
12150 int ret;
12151 char prefix_str[BUFSIZ];
12152
12153 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12154 if (! ret)
12155 {
12156 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12157 return CMD_WARNING;
12158 }
12159
12160 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12161 SAFI_UNICAST, NULL, 0);
12162}
12163
paul94f2b392005-06-28 12:44:16 +000012164static int
paul718e3742002-12-13 20:15:29 +000012165bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12166 afi_t afi, safi_t safi, int *write)
12167{
12168 struct bgp_node *prn;
12169 struct bgp_node *rn;
12170 struct bgp_table *table;
12171 struct prefix *p;
12172 struct prefix_rd *prd;
12173 struct bgp_static *bgp_static;
12174 u_int32_t label;
12175 char buf[SU_ADDRSTRLEN];
12176 char rdbuf[RD_ADDRSTRLEN];
12177
12178 /* Network configuration. */
12179 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12180 if ((table = prn->info) != NULL)
12181 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12182 if ((bgp_static = rn->info) != NULL)
12183 {
12184 p = &rn->p;
12185 prd = (struct prefix_rd *) &prn->p;
12186
12187 /* "address-family" display. */
12188 bgp_config_write_family_header (vty, afi, safi, write);
12189
12190 /* "network" configuration display. */
12191 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12192 label = decode_label (bgp_static->tag);
12193
12194 vty_out (vty, " network %s/%d rd %s tag %d",
12195 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12196 p->prefixlen,
12197 rdbuf, label);
12198 vty_out (vty, "%s", VTY_NEWLINE);
12199 }
12200 return 0;
12201}
12202
12203/* Configuration of static route announcement and aggregate
12204 information. */
12205int
12206bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12207 afi_t afi, safi_t safi, int *write)
12208{
12209 struct bgp_node *rn;
12210 struct prefix *p;
12211 struct bgp_static *bgp_static;
12212 struct bgp_aggregate *bgp_aggregate;
12213 char buf[SU_ADDRSTRLEN];
12214
12215 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12216 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12217
12218 /* Network configuration. */
12219 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12220 if ((bgp_static = rn->info) != NULL)
12221 {
12222 p = &rn->p;
12223
12224 /* "address-family" display. */
12225 bgp_config_write_family_header (vty, afi, safi, write);
12226
12227 /* "network" configuration display. */
12228 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12229 {
12230 u_int32_t destination;
12231 struct in_addr netmask;
12232
12233 destination = ntohl (p->u.prefix4.s_addr);
12234 masklen2ip (p->prefixlen, &netmask);
12235 vty_out (vty, " network %s",
12236 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12237
12238 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12239 || (IN_CLASSB (destination) && p->prefixlen == 16)
12240 || (IN_CLASSA (destination) && p->prefixlen == 8)
12241 || p->u.prefix4.s_addr == 0)
12242 {
12243 /* Natural mask is not display. */
12244 }
12245 else
12246 vty_out (vty, " mask %s", inet_ntoa (netmask));
12247 }
12248 else
12249 {
12250 vty_out (vty, " network %s/%d",
12251 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12252 p->prefixlen);
12253 }
12254
12255 if (bgp_static->rmap.name)
12256 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012257 else
12258 {
12259 if (bgp_static->backdoor)
12260 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012261 }
paul718e3742002-12-13 20:15:29 +000012262
12263 vty_out (vty, "%s", VTY_NEWLINE);
12264 }
12265
12266 /* Aggregate-address configuration. */
12267 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12268 if ((bgp_aggregate = rn->info) != NULL)
12269 {
12270 p = &rn->p;
12271
12272 /* "address-family" display. */
12273 bgp_config_write_family_header (vty, afi, safi, write);
12274
12275 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12276 {
12277 struct in_addr netmask;
12278
12279 masklen2ip (p->prefixlen, &netmask);
12280 vty_out (vty, " aggregate-address %s %s",
12281 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12282 inet_ntoa (netmask));
12283 }
12284 else
12285 {
12286 vty_out (vty, " aggregate-address %s/%d",
12287 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12288 p->prefixlen);
12289 }
12290
12291 if (bgp_aggregate->as_set)
12292 vty_out (vty, " as-set");
12293
12294 if (bgp_aggregate->summary_only)
12295 vty_out (vty, " summary-only");
12296
12297 vty_out (vty, "%s", VTY_NEWLINE);
12298 }
12299
12300 return 0;
12301}
12302
12303int
12304bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12305{
12306 struct bgp_node *rn;
12307 struct bgp_distance *bdistance;
12308
12309 /* Distance configuration. */
12310 if (bgp->distance_ebgp
12311 && bgp->distance_ibgp
12312 && bgp->distance_local
12313 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12314 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12315 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12316 vty_out (vty, " distance bgp %d %d %d%s",
12317 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12318 VTY_NEWLINE);
12319
12320 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12321 if ((bdistance = rn->info) != NULL)
12322 {
12323 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12324 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12325 bdistance->access_list ? bdistance->access_list : "",
12326 VTY_NEWLINE);
12327 }
12328
12329 return 0;
12330}
12331
12332/* Allocate routing table structure and install commands. */
12333void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012334bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012335{
12336 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012337 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012338
12339 /* IPv4 BGP commands. */
12340 install_element (BGP_NODE, &bgp_network_cmd);
12341 install_element (BGP_NODE, &bgp_network_mask_cmd);
12342 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12343 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12344 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12345 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12346 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12347 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12348 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12349 install_element (BGP_NODE, &no_bgp_network_cmd);
12350 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12351 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12352 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12353 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12354 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12355 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12356 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12357 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12358
12359 install_element (BGP_NODE, &aggregate_address_cmd);
12360 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12361 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12362 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12363 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12364 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12365 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12366 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12367 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12368 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12369 install_element (BGP_NODE, &no_aggregate_address_cmd);
12370 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12371 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12372 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12373 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12374 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12375 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12376 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12377 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12378 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12379
12380 /* IPv4 unicast configuration. */
12381 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12382 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12383 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12384 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12385 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12386 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012387 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012388 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12389 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12390 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12391 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12392 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012393
paul718e3742002-12-13 20:15:29 +000012394 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12395 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12396 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12397 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12398 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12399 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12400 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12401 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12402 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12403 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12404 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12405 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12406 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12407 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12408 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12409 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12410 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12411 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12412 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12413 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12414
12415 /* IPv4 multicast configuration. */
12416 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12417 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12418 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12419 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12420 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12421 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12422 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12423 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12424 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12425 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12426 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12427 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12428 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12429 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12430 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12431 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12432 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12433 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12434 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12435 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12436 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12437 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12438 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12439 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12440 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12441 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12442 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12443 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12444 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12445 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12446 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12447 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12448
12449 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12450 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012451 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012452 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12453 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012454 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012455 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12456 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12457 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12458 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012459 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012460 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12462 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12463 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12466 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12467 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12468 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012485 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12486 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12487 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12488 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12489 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012490 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12493 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12494 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12495 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12497 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12498 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12499 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12500 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12502 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12503 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12504 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12505 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12506 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12507 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012508 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012509 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12510 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12511 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12512 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12513 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12514 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12515 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12516 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12517 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12518 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12519 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12520 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12521 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12522 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12523 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12524 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012525 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012526 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012527 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012528 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012529 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012530 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012531 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12532 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012533 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012534 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012535 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012536 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012537 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012538 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012539
12540 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12541 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12542 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012543 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012544 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12545 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12546 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012547 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012548 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12549 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12550 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12551 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12552 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12553 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12554 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12555 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12556 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12557 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12558 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12559 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012560 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12561 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12562 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12563 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12564 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012565 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12566 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12567 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12568 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12569 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12570 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12571 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12572 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12573 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012574 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012575 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012576 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012577 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012578 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012579 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012580 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012581
12582 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12583 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012584 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012585 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12586 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012587 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012588 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12589 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12590 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012592 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012593 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12595 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12596 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12600 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12601 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012618 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12619 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12620 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12621 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12622 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012623 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12626 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12627 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12628 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12630 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12631 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12632 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12633 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12635 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12636 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12637 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12638 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012641 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012642 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12643 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12644 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12647 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12648 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12649 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12652 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12653 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12654 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12655 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12656 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12657 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012658 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012659 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012660 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012661 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012662 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012663 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012664 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12665 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012666 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012667 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012668 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012669 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012670 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012671 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012672
12673 /* BGP dampening clear commands */
12674 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12675 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12676 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12677 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12678
Paul Jakmaff7924f2006-09-04 01:10:36 +000012679 /* prefix count */
12680 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12681 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12682 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012683#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012684 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12685
paul718e3742002-12-13 20:15:29 +000012686 /* New config IPv6 BGP commands. */
12687 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12688 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12689 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12690 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12691
12692 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12693 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12694 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12695 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12696
G.Balaji73bfe0b2011-09-23 22:36:20 +053012697 install_element (BGP_IPV6M_NODE, &ipv6_bgp_network_cmd);
12698 install_element (BGP_IPV6M_NODE, &no_ipv6_bgp_network_cmd);
12699
paul718e3742002-12-13 20:15:29 +000012700 /* Old config IPv6 BGP commands. */
12701 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12702 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12703
12704 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12705 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12706 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12707 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12708
12709 install_element (VIEW_NODE, &show_bgp_cmd);
12710 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012711 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012712 install_element (VIEW_NODE, &show_bgp_route_cmd);
12713 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012714 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012715 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12716 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012717 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012718 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12719 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12720 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12721 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12722 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12723 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12724 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12725 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12726 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12727 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12728 install_element (VIEW_NODE, &show_bgp_community_cmd);
12729 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12730 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12731 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12732 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12733 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12734 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12735 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12736 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12737 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12738 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12739 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12740 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12741 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12742 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12743 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12744 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12745 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12746 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12747 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12748 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12749 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12750 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12751 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12752 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12753 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12754 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12755 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12756 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12757 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012758 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12759 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12760 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12761 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012762 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012763 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012764 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012765 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012766 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012767 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012768 install_element (VIEW_NODE, &show_bgp_view_cmd);
12769 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12770 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12771 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12772 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12773 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12774 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12775 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12776 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12777 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12778 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12779 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12780 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12781 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12782 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12783 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12784 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12785 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012786 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012787 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012788 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012789 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012790 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012791 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012792
12793 /* Restricted:
12794 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12795 */
12796 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12797 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012798 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012799 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12800 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012801 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012802 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12803 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12804 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12805 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12806 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12807 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12808 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12809 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12810 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12811 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12812 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12813 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12814 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12815 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12816 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12817 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12818 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012819 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012820 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012821 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012822 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12823 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12824 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12825 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12826 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12827 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12828 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012829 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012830 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012831 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012832
12833 install_element (ENABLE_NODE, &show_bgp_cmd);
12834 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012835 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012836 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12837 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012838 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012839 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12840 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012841 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012842 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12843 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12844 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12845 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12846 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12847 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12848 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12849 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12850 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12852 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12877 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12878 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12879 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012882 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12883 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12884 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012886 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012887 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012888 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012889 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012890 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012891 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012892 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12893 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12894 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12895 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12896 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12897 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12898 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12899 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12900 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12901 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12902 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12903 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12904 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12905 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12906 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12907 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12908 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12909 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012910 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012911 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012912 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012913 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012914 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012915 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012916
12917 /* Statistics */
12918 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12919 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12920 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12921 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12922
paul718e3742002-12-13 20:15:29 +000012923 /* old command */
12924 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12925 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12926 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12927 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12928 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12929 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12930 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12931 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12932 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12933 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12934 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12935 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12936 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12937 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12938 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12939 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12940 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12941 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12942 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12943 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12944 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12945 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12946 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12947 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12948 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12949 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12950 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12951 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12952 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12953 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12954 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12955 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12956 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12957 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12958 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12959 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012960
paul718e3742002-12-13 20:15:29 +000012961 /* old command */
12962 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12963 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12964 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12965 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12966 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12967 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12968 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12969 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12970 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12971 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12972 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12973 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12974 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12975 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12976 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12977 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12978 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12979 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12980 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12981 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12982 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12983 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12984 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12985 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12986 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12987 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12988 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12989 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12990 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12991 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12992 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12993 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12994 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12995 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12996 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12997 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12998
12999 /* old command */
13000 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13001 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
13002 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13003 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
13004
13005 /* old command */
13006 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13007 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
13008 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13009 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
13010
13011 /* old command */
13012 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
13013 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
13014 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13015 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
13016#endif /* HAVE_IPV6 */
13017
13018 install_element (BGP_NODE, &bgp_distance_cmd);
13019 install_element (BGP_NODE, &no_bgp_distance_cmd);
13020 install_element (BGP_NODE, &no_bgp_distance2_cmd);
13021 install_element (BGP_NODE, &bgp_distance_source_cmd);
13022 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
13023 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
13024 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
13025
13026 install_element (BGP_NODE, &bgp_damp_set_cmd);
13027 install_element (BGP_NODE, &bgp_damp_set2_cmd);
13028 install_element (BGP_NODE, &bgp_damp_set3_cmd);
13029 install_element (BGP_NODE, &bgp_damp_unset_cmd);
13030 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
13031 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
13032 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
13033 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13034 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13035 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013036
13037 /* Deprecated AS-Pathlimit commands */
13038 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13039 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13040 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13041 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13042 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13043 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13044
13045 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13046 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13047 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13048 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13049 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13050 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13051
13052 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13053 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13054 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13055 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13056 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13057 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13058
13059 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13060 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13061 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13062 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13063 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13064 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13065
13066 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13067 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13068 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13069 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13070 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13071 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13072
13073 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13074 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13075 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13076 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13077 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13078 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013079
13080#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013081 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13082 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013083#endif
paul718e3742002-12-13 20:15:29 +000013084}
Chris Caputo228da422009-07-18 05:44:03 +000013085
13086void
13087bgp_route_finish (void)
13088{
13089 bgp_table_unlock (bgp_distance_table);
13090 bgp_distance_table = NULL;
13091}