blob: a4923f57bb529d56e9ad2744d0c6e75e73ca4c35 [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)
141 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. */
450 if (peer_sort (new->peer) == BGP_PEER_EBGP
451 && peer_sort (exist->peer) == BGP_PEER_IBGP)
452 return 1;
453 if (peer_sort (new->peer) == BGP_PEER_EBGP
454 && peer_sort (exist->peer) == BGP_PEER_CONFED)
455 return 1;
456 if (peer_sort (new->peer) == BGP_PEER_IBGP
457 && peer_sort (exist->peer) == BGP_PEER_EBGP)
458 return 0;
459 if (peer_sort (new->peer) == BGP_PEER_CONFED
460 && peer_sort (exist->peer) == BGP_PEER_EBGP)
461 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 {
474 if ((peer_sort (new->peer) == BGP_PEER_IBGP))
475 {
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)
496 && peer_sort (new->peer) == BGP_PEER_EBGP
497 && peer_sort (exist->peer) == BGP_PEER_EBGP)
498 {
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. */
635 if (peer_sort (peer) == BGP_PEER_EBGP &&
636 community_include (attr->community, COMMUNITY_NO_EXPORT))
637 return 1;
638
639 /* NO_EXPORT_SUBCONFED check. */
640 if (peer_sort (peer) == BGP_PEER_EBGP
641 || peer_sort (peer) == BGP_PEER_CONFED)
642 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. */
908 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
909 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. */
940 if ((peer_sort (peer) == BGP_PEER_IBGP
941 || peer_sort (peer) == BGP_PEER_CONFED)
942 && (! (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 */
949 if (peer_sort (peer) == BGP_PEER_EBGP
950 && 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 */
975 || (peer_sort (peer) == BGP_PEER_EBGP
976 && 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. */
1041 if (peer_sort (peer) == BGP_PEER_EBGP
1042 && 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. */
1058 if (peer_sort (from) == BGP_PEER_IBGP
1059 && peer_sort (peer) == BGP_PEER_IBGP)
1060 {
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;
1095 struct bgp *bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001096 struct attr *riattr;
paulfee0f4c2004-09-13 05:12:46 +00001097
1098 from = ri->peer;
1099 filter = &rsclient->filter[afi][safi];
1100 bgp = rsclient->bgp;
Josh Bailey0b597ef2011-07-20 20:49:11 -07001101 riattr = bgp_info_mpath_count (ri) ? bgp_info_mpath_attr (ri) : ri->attr;
paulfee0f4c2004-09-13 05:12:46 +00001102
Paul Jakma750e8142008-07-22 21:11:48 +00001103 if (DISABLE_BGP_ANNOUNCE)
1104 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001105
1106 /* Do not send back route to sender. */
1107 if (from == rsclient)
1108 return 0;
1109
1110 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001111 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001112 if (! UNSUPPRESS_MAP_NAME (filter))
1113 return 0;
1114
1115 /* Default route check. */
1116 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1117 PEER_STATUS_DEFAULT_ORIGINATE))
1118 {
1119 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1120 return 0;
1121#ifdef HAVE_IPV6
1122 else if (p->family == AF_INET6 && p->prefixlen == 0)
1123 return 0;
1124#endif /* HAVE_IPV6 */
1125 }
1126
1127 /* If the attribute has originator-id and it is same as remote
1128 peer's id. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001129 if (riattr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
paulfee0f4c2004-09-13 05:12:46 +00001130 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001131 if (IPV4_ADDR_SAME (&rsclient->remote_id,
Josh Bailey0b597ef2011-07-20 20:49:11 -07001132 &riattr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001133 {
1134 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001135 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001136 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1137 rsclient->host,
1138 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1139 p->prefixlen);
1140 return 0;
1141 }
1142 }
1143
1144 /* ORF prefix-list filter check */
1145 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1146 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1147 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1148 if (rsclient->orf_plist[afi][safi])
1149 {
1150 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1151 return 0;
1152 }
1153
1154 /* Output filter check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001155 if (bgp_output_filter (rsclient, p, riattr, afi, safi) == FILTER_DENY)
paulfee0f4c2004-09-13 05:12:46 +00001156 {
1157 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001158 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001159 "%s [Update:SEND] %s/%d is filtered",
1160 rsclient->host,
1161 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1162 p->prefixlen);
1163 return 0;
1164 }
1165
1166#ifdef BGP_SEND_ASPATH_CHECK
1167 /* AS path loop check. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001168 if (aspath_loop_check (riattr->aspath, rsclient->as))
paulfee0f4c2004-09-13 05:12:46 +00001169 {
1170 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001171 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001172 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001173 rsclient->host, rsclient->as);
1174 return 0;
1175 }
1176#endif /* BGP_SEND_ASPATH_CHECK */
1177
1178 /* For modify attribute, copy it to temporary structure. */
Josh Bailey0b597ef2011-07-20 20:49:11 -07001179 bgp_attr_dup (attr, riattr);
paulfee0f4c2004-09-13 05:12:46 +00001180
1181 /* next-hop-set */
1182 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1183#ifdef HAVE_IPV6
1184 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001185 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001186#endif /* HAVE_IPV6 */
1187 )
1188 {
1189 /* Set IPv4 nexthop. */
1190 if (p->family == AF_INET)
1191 {
1192 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001193 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001194 IPV4_MAX_BYTELEN);
1195 else
1196 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1197 }
1198#ifdef HAVE_IPV6
1199 /* Set IPv6 nexthop. */
1200 if (p->family == AF_INET6)
1201 {
1202 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001203 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001204 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001205 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001206 }
1207#endif /* HAVE_IPV6 */
1208 }
1209
1210#ifdef HAVE_IPV6
1211 if (p->family == AF_INET6)
1212 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001213 struct attr_extra *attre = attr->extra;
1214
1215 assert (attr->extra);
1216
paulfee0f4c2004-09-13 05:12:46 +00001217 /* Left nexthop_local unchanged if so configured. */
1218 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1219 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1220 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001221 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1222 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001223 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001224 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001225 }
1226
1227 /* Default nexthop_local treatment for RS-Clients */
1228 else
1229 {
1230 /* Announcer and RS-Client are both in the same network */
1231 if (rsclient->shared_network && from->shared_network &&
1232 (rsclient->ifindex == from->ifindex))
1233 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1235 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001236 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001237 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001238 }
1239
1240 /* Set link-local address for shared network peer. */
1241 else if (rsclient->shared_network
1242 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1243 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001245 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001246 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001247 }
1248
1249 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001250 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001251 }
1252
1253 }
1254#endif /* HAVE_IPV6 */
1255
1256
1257 /* If this is EBGP peer and remove-private-AS is set. */
1258 if (peer_sort (rsclient) == BGP_PEER_EBGP
1259 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1260 && aspath_private_as_check (attr->aspath))
1261 attr->aspath = aspath_empty_get ();
1262
1263 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001264 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001265 {
1266 info.peer = rsclient;
1267 info.attr = attr;
1268
1269 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1270
Paul Jakmafb982c22007-05-04 20:15:47 +00001271 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001272 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1273 else
1274 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1275
1276 rsclient->rmap_type = 0;
1277
1278 if (ret == RMAP_DENYMATCH)
1279 {
1280 bgp_attr_flush (attr);
1281 return 0;
1282 }
1283 }
1284
1285 return 1;
1286}
1287
1288struct bgp_info_pair
1289{
1290 struct bgp_info *old;
1291 struct bgp_info *new;
1292};
1293
paul94f2b392005-06-28 12:44:16 +00001294static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001295bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1296 struct bgp_maxpaths_cfg *mpath_cfg,
1297 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001298{
paul718e3742002-12-13 20:15:29 +00001299 struct bgp_info *new_select;
1300 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001301 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001302 struct bgp_info *ri1;
1303 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001304 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001305 int paths_eq, do_mpath;
1306 struct list mp_list;
1307
1308 bgp_mp_list_init (&mp_list);
1309 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1310 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1311
paul718e3742002-12-13 20:15:29 +00001312 /* bgp deterministic-med */
1313 new_select = NULL;
1314 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1315 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1316 {
1317 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1318 continue;
1319 if (BGP_INFO_HOLDDOWN (ri1))
1320 continue;
1321
1322 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001323 if (do_mpath)
1324 bgp_mp_list_add (&mp_list, ri1);
1325 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001326 if (ri1->next)
1327 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1328 {
1329 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1330 continue;
1331 if (BGP_INFO_HOLDDOWN (ri2))
1332 continue;
1333
1334 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1335 || aspath_cmp_left_confed (ri1->attr->aspath,
1336 ri2->attr->aspath))
1337 {
Josh Bailey6918e742011-07-20 20:48:20 -07001338 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1339 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001340 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001341 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001342 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001343 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001344 if (do_mpath && !paths_eq)
1345 {
1346 bgp_mp_list_clear (&mp_list);
1347 bgp_mp_list_add (&mp_list, ri2);
1348 }
paul718e3742002-12-13 20:15:29 +00001349 }
1350
Josh Bailey6918e742011-07-20 20:48:20 -07001351 if (do_mpath && paths_eq)
1352 bgp_mp_list_add (&mp_list, ri2);
1353
Paul Jakma1a392d42006-09-07 00:24:49 +00001354 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001355 }
1356 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001357 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1358 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001359
1360 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1361 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001362 }
1363
1364 /* Check old selected route and new selected route. */
1365 old_select = NULL;
1366 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001367 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001368 {
1369 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1370 old_select = ri;
1371
1372 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001373 {
1374 /* reap REMOVED routes, if needs be
1375 * selected route must stay for a while longer though
1376 */
1377 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1378 && (ri != old_select))
1379 bgp_info_reap (rn, ri);
1380
1381 continue;
1382 }
paul718e3742002-12-13 20:15:29 +00001383
1384 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1385 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1386 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001387 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001388 continue;
1389 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001390 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1391 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001392
Josh Bailey96450fa2011-07-20 20:45:12 -07001393 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1394 {
Josh Bailey6918e742011-07-20 20:48:20 -07001395 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1396 bgp_mp_dmed_deselect (new_select);
1397
Josh Bailey96450fa2011-07-20 20:45:12 -07001398 new_select = ri;
1399
1400 if (do_mpath && !paths_eq)
1401 {
1402 bgp_mp_list_clear (&mp_list);
1403 bgp_mp_list_add (&mp_list, ri);
1404 }
1405 }
Josh Bailey6918e742011-07-20 20:48:20 -07001406 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1407 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001408
1409 if (do_mpath && paths_eq)
1410 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001411 }
paulb40d9392005-08-22 22:34:41 +00001412
paulfee0f4c2004-09-13 05:12:46 +00001413
Josh Bailey6918e742011-07-20 20:48:20 -07001414 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1415 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001416
Josh Bailey0b597ef2011-07-20 20:49:11 -07001417 bgp_info_mpath_aggregate_update (new_select, old_select);
Josh Bailey96450fa2011-07-20 20:45:12 -07001418 bgp_mp_list_clear (&mp_list);
1419
1420 result->old = old_select;
1421 result->new = new_select;
1422
1423 return;
paulfee0f4c2004-09-13 05:12:46 +00001424}
1425
paul94f2b392005-06-28 12:44:16 +00001426static int
paulfee0f4c2004-09-13 05:12:46 +00001427bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001428 struct bgp_node *rn, afi_t afi, safi_t safi)
1429{
paulfee0f4c2004-09-13 05:12:46 +00001430 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001431 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001432
1433 p = &rn->p;
1434
Paul Jakma9eda90c2007-08-30 13:36:17 +00001435 /* Announce route to Established peer. */
1436 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001437 return 0;
1438
Paul Jakma9eda90c2007-08-30 13:36:17 +00001439 /* Address family configuration check. */
1440 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001441 return 0;
1442
Paul Jakma9eda90c2007-08-30 13:36:17 +00001443 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001444 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1445 PEER_STATUS_ORF_WAIT_REFRESH))
1446 return 0;
1447
1448 switch (rn->table->type)
1449 {
1450 case BGP_TABLE_MAIN:
1451 /* Announcement to peer->conf. If the route is filtered,
1452 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001453 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1454 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001455 else
1456 bgp_adj_out_unset (rn, peer, p, afi, safi);
1457 break;
1458 case BGP_TABLE_RSCLIENT:
1459 /* Announcement to peer->conf. If the route is filtered,
1460 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001461 if (selected &&
1462 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1463 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1464 else
1465 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001466 break;
1467 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001468
1469 bgp_attr_extra_free (&attr);
1470
paulfee0f4c2004-09-13 05:12:46 +00001471 return 0;
paul200df112005-06-01 11:17:05 +00001472}
paulfee0f4c2004-09-13 05:12:46 +00001473
paul200df112005-06-01 11:17:05 +00001474struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001475{
paul200df112005-06-01 11:17:05 +00001476 struct bgp *bgp;
1477 struct bgp_node *rn;
1478 afi_t afi;
1479 safi_t safi;
1480};
1481
1482static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001483bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001484{
paul0fb58d52005-11-14 14:31:49 +00001485 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001486 struct bgp *bgp = pq->bgp;
1487 struct bgp_node *rn = pq->rn;
1488 afi_t afi = pq->afi;
1489 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001490 struct bgp_info *new_select;
1491 struct bgp_info *old_select;
1492 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001493 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001494 struct peer *rsclient = rn->table->owner;
1495
paulfee0f4c2004-09-13 05:12:46 +00001496 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001497 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001498 new_select = old_and_new.new;
1499 old_select = old_and_new.old;
1500
paul200df112005-06-01 11:17:05 +00001501 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1502 {
Chris Caputo228da422009-07-18 05:44:03 +00001503 if (rsclient->group)
1504 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1505 {
1506 /* Nothing to do. */
1507 if (old_select && old_select == new_select)
1508 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1509 continue;
paulfee0f4c2004-09-13 05:12:46 +00001510
Chris Caputo228da422009-07-18 05:44:03 +00001511 if (old_select)
1512 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1513 if (new_select)
1514 {
1515 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1516 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001517 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1518 }
paulfee0f4c2004-09-13 05:12:46 +00001519
Chris Caputo228da422009-07-18 05:44:03 +00001520 bgp_process_announce_selected (rsclient, new_select, rn,
1521 afi, safi);
1522 }
paul200df112005-06-01 11:17:05 +00001523 }
1524 else
1525 {
hassob7395792005-08-26 12:58:38 +00001526 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001527 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001528 if (new_select)
1529 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001530 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1531 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001532 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001533 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001534 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001535 }
paulfee0f4c2004-09-13 05:12:46 +00001536
paulb40d9392005-08-22 22:34:41 +00001537 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1538 bgp_info_reap (rn, old_select);
1539
paul200df112005-06-01 11:17:05 +00001540 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1541 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001542}
1543
paul200df112005-06-01 11:17:05 +00001544static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001545bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001546{
paul0fb58d52005-11-14 14:31:49 +00001547 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001548 struct bgp *bgp = pq->bgp;
1549 struct bgp_node *rn = pq->rn;
1550 afi_t afi = pq->afi;
1551 safi_t safi = pq->safi;
1552 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001553 struct bgp_info *new_select;
1554 struct bgp_info *old_select;
1555 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001556 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001557 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001558
paulfee0f4c2004-09-13 05:12:46 +00001559 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001560 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001561 old_select = old_and_new.old;
1562 new_select = old_and_new.new;
1563
1564 /* Nothing to do. */
1565 if (old_select && old_select == new_select)
1566 {
1567 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001568 {
Josh Bailey8196f132011-07-20 20:47:07 -07001569 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1570 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
paul200df112005-06-01 11:17:05 +00001571 bgp_zebra_announce (p, old_select, bgp);
1572
Josh Bailey8196f132011-07-20 20:47:07 -07001573 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001574 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1575 return WQ_SUCCESS;
1576 }
paulfee0f4c2004-09-13 05:12:46 +00001577 }
paul718e3742002-12-13 20:15:29 +00001578
hasso338b3422005-02-23 14:27:24 +00001579 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001580 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001581 if (new_select)
1582 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001583 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1584 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001585 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001586 }
1587
1588
paul718e3742002-12-13 20:15:29 +00001589 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001590 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001591 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001592 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001593 }
1594
1595 /* FIB update. */
1596 if (safi == SAFI_UNICAST && ! bgp->name &&
1597 ! bgp_option_check (BGP_OPT_NO_FIB))
1598 {
1599 if (new_select
1600 && new_select->type == ZEBRA_ROUTE_BGP
1601 && new_select->sub_type == BGP_ROUTE_NORMAL)
1602 bgp_zebra_announce (p, new_select, bgp);
1603 else
1604 {
1605 /* Withdraw the route from the kernel. */
1606 if (old_select
1607 && old_select->type == ZEBRA_ROUTE_BGP
1608 && old_select->sub_type == BGP_ROUTE_NORMAL)
1609 bgp_zebra_withdraw (p, old_select);
1610 }
1611 }
paulb40d9392005-08-22 22:34:41 +00001612
1613 /* Reap old select bgp_info, it it has been removed */
1614 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1615 bgp_info_reap (rn, old_select);
1616
paul200df112005-06-01 11:17:05 +00001617 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1618 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001619}
1620
paul200df112005-06-01 11:17:05 +00001621static void
paul0fb58d52005-11-14 14:31:49 +00001622bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001623{
paul0fb58d52005-11-14 14:31:49 +00001624 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001625 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001626
Chris Caputo228da422009-07-18 05:44:03 +00001627 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001628 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001629 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001630 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1631}
1632
1633static void
1634bgp_process_queue_init (void)
1635{
1636 bm->process_main_queue
1637 = work_queue_new (bm->master, "process_main_queue");
1638 bm->process_rsclient_queue
1639 = work_queue_new (bm->master, "process_rsclient_queue");
1640
1641 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1642 {
1643 zlog_err ("%s: Failed to allocate work queue", __func__);
1644 exit (1);
1645 }
1646
1647 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001648 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001649 bm->process_main_queue->spec.max_retries = 0;
1650 bm->process_main_queue->spec.hold = 50;
1651
1652 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1653 sizeof (struct work_queue *));
1654 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001655}
1656
1657void
paulfee0f4c2004-09-13 05:12:46 +00001658bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1659{
paul200df112005-06-01 11:17:05 +00001660 struct bgp_process_queue *pqnode;
1661
1662 /* already scheduled for processing? */
1663 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1664 return;
1665
1666 if ( (bm->process_main_queue == NULL) ||
1667 (bm->process_rsclient_queue == NULL) )
1668 bgp_process_queue_init ();
1669
1670 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1671 sizeof (struct bgp_process_queue));
1672 if (!pqnode)
1673 return;
Chris Caputo228da422009-07-18 05:44:03 +00001674
1675 /* all unlocked in bgp_processq_del */
1676 bgp_table_lock (rn->table);
1677 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001678 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001679 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001680 pqnode->afi = afi;
1681 pqnode->safi = safi;
1682
paulfee0f4c2004-09-13 05:12:46 +00001683 switch (rn->table->type)
1684 {
paul200df112005-06-01 11:17:05 +00001685 case BGP_TABLE_MAIN:
1686 work_queue_add (bm->process_main_queue, pqnode);
1687 break;
1688 case BGP_TABLE_RSCLIENT:
1689 work_queue_add (bm->process_rsclient_queue, pqnode);
1690 break;
paulfee0f4c2004-09-13 05:12:46 +00001691 }
paul200df112005-06-01 11:17:05 +00001692
1693 return;
paulfee0f4c2004-09-13 05:12:46 +00001694}
hasso0a486e52005-02-01 20:57:17 +00001695
paul94f2b392005-06-28 12:44:16 +00001696static int
hasso0a486e52005-02-01 20:57:17 +00001697bgp_maximum_prefix_restart_timer (struct thread *thread)
1698{
1699 struct peer *peer;
1700
1701 peer = THREAD_ARG (thread);
1702 peer->t_pmax_restart = NULL;
1703
1704 if (BGP_DEBUG (events, EVENTS))
1705 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1706 peer->host);
1707
1708 peer_clear (peer);
1709
1710 return 0;
1711}
1712
paulfee0f4c2004-09-13 05:12:46 +00001713int
paul5228ad22004-06-04 17:58:18 +00001714bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1715 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001716{
hassoe0701b72004-05-20 09:19:34 +00001717 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1718 return 0;
1719
1720 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001721 {
hassoe0701b72004-05-20 09:19:34 +00001722 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1723 && ! always)
1724 return 0;
paul718e3742002-12-13 20:15:29 +00001725
hassoe0701b72004-05-20 09:19:34 +00001726 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001727 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1728 "limit %ld", afi_safi_print (afi, safi), peer->host,
1729 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001730 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001731
hassoe0701b72004-05-20 09:19:34 +00001732 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1733 return 0;
paul718e3742002-12-13 20:15:29 +00001734
hassoe0701b72004-05-20 09:19:34 +00001735 {
paul5228ad22004-06-04 17:58:18 +00001736 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001737
1738 if (safi == SAFI_MPLS_VPN)
1739 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001740
1741 ndata[0] = (afi >> 8);
1742 ndata[1] = afi;
1743 ndata[2] = safi;
1744 ndata[3] = (peer->pmax[afi][safi] >> 24);
1745 ndata[4] = (peer->pmax[afi][safi] >> 16);
1746 ndata[5] = (peer->pmax[afi][safi] >> 8);
1747 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001748
1749 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1750 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1751 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1752 }
hasso0a486e52005-02-01 20:57:17 +00001753
1754 /* restart timer start */
1755 if (peer->pmax_restart[afi][safi])
1756 {
1757 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1758
1759 if (BGP_DEBUG (events, EVENTS))
1760 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1761 peer->host, peer->v_pmax_restart);
1762
1763 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1764 peer->v_pmax_restart);
1765 }
1766
hassoe0701b72004-05-20 09:19:34 +00001767 return 1;
paul718e3742002-12-13 20:15:29 +00001768 }
hassoe0701b72004-05-20 09:19:34 +00001769 else
1770 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1771
1772 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1773 {
1774 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1775 && ! always)
1776 return 0;
1777
1778 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001779 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1780 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1781 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001782 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1783 }
1784 else
1785 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001786 return 0;
1787}
1788
paulb40d9392005-08-22 22:34:41 +00001789/* Unconditionally remove the route from the RIB, without taking
1790 * damping into consideration (eg, because the session went down)
1791 */
paul94f2b392005-06-28 12:44:16 +00001792static void
paul718e3742002-12-13 20:15:29 +00001793bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1794 afi_t afi, safi_t safi)
1795{
paul902212c2006-02-05 17:51:19 +00001796 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1797
1798 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1799 bgp_info_delete (rn, ri); /* keep historical info */
1800
paulb40d9392005-08-22 22:34:41 +00001801 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001802}
1803
paul94f2b392005-06-28 12:44:16 +00001804static void
paul718e3742002-12-13 20:15:29 +00001805bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001806 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001807{
paul718e3742002-12-13 20:15:29 +00001808 int status = BGP_DAMP_NONE;
1809
paulb40d9392005-08-22 22:34:41 +00001810 /* apply dampening, if result is suppressed, we'll be retaining
1811 * the bgp_info in the RIB for historical reference.
1812 */
1813 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1814 && peer_sort (peer) == BGP_PEER_EBGP)
1815 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1816 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001817 {
paul902212c2006-02-05 17:51:19 +00001818 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1819 return;
1820 }
1821
1822 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001823}
1824
paul94f2b392005-06-28 12:44:16 +00001825static void
paulfee0f4c2004-09-13 05:12:46 +00001826bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1827 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1828 int sub_type, struct prefix_rd *prd, u_char *tag)
1829{
1830 struct bgp_node *rn;
1831 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001832 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001833 struct attr *attr_new;
1834 struct attr *attr_new2;
1835 struct bgp_info *ri;
1836 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001837 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001838 char buf[SU_ADDRSTRLEN];
1839
1840 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1841 if (peer == rsclient)
1842 return;
1843
1844 bgp = peer->bgp;
1845 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1846
1847 /* Check previously received route. */
1848 for (ri = rn->info; ri; ri = ri->next)
1849 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1850 break;
1851
1852 /* AS path loop check. */
1853 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1854 {
1855 reason = "as-path contains our own AS;";
1856 goto filtered;
1857 }
1858
1859 /* Route reflector originator ID check. */
1860 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001861 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001862 {
1863 reason = "originator is us;";
1864 goto filtered;
1865 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001866
1867 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001868
1869 /* Apply export policy. */
1870 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1871 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1872 {
1873 reason = "export-policy;";
1874 goto filtered;
1875 }
1876
1877 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001878
paulfee0f4c2004-09-13 05:12:46 +00001879 /* Apply import policy. */
1880 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1881 {
1882 bgp_attr_unintern (attr_new2);
1883
1884 reason = "import-policy;";
1885 goto filtered;
1886 }
1887
1888 attr_new = bgp_attr_intern (&new_attr);
1889 bgp_attr_unintern (attr_new2);
1890
1891 /* IPv4 unicast next hop check. */
1892 if (afi == AFI_IP && safi == SAFI_UNICAST)
1893 {
1894 /* Next hop must not be 0.0.0.0 nor Class E address. */
1895 if (new_attr.nexthop.s_addr == 0
1896 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1897 {
1898 bgp_attr_unintern (attr_new);
1899
1900 reason = "martian next-hop;";
1901 goto filtered;
1902 }
1903 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001904
1905 /* new_attr isn't passed to any functions after here */
1906 bgp_attr_extra_free (&new_attr);
1907
paulfee0f4c2004-09-13 05:12:46 +00001908 /* If the update is implicit withdraw. */
1909 if (ri)
1910 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001911 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001912
1913 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001914 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1915 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001916 {
1917
Paul Jakma1a392d42006-09-07 00:24:49 +00001918 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001919
1920 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001921 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001922 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1923 peer->host,
1924 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1925 p->prefixlen, rsclient->host);
1926
Chris Caputo228da422009-07-18 05:44:03 +00001927 bgp_unlock_node (rn);
1928 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001929
Chris Caputo228da422009-07-18 05:44:03 +00001930 return;
paulfee0f4c2004-09-13 05:12:46 +00001931 }
1932
Paul Jakma16d2e242007-04-10 19:32:10 +00001933 /* Withdraw/Announce before we fully processed the withdraw */
1934 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1935 bgp_info_restore (rn, ri);
1936
paulfee0f4c2004-09-13 05:12:46 +00001937 /* Received Logging. */
1938 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001939 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001940 peer->host,
1941 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1942 p->prefixlen, rsclient->host);
1943
1944 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001945 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001946
1947 /* Update to new attribute. */
1948 bgp_attr_unintern (ri->attr);
1949 ri->attr = attr_new;
1950
1951 /* Update MPLS tag. */
1952 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001953 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001954
Paul Jakma1a392d42006-09-07 00:24:49 +00001955 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001956
1957 /* Process change. */
1958 bgp_process (bgp, rn, afi, safi);
1959 bgp_unlock_node (rn);
1960
1961 return;
1962 }
1963
1964 /* Received Logging. */
1965 if (BGP_DEBUG (update, UPDATE_IN))
1966 {
ajsd2c1f162004-12-08 21:10:20 +00001967 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001968 peer->host,
1969 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1970 p->prefixlen, rsclient->host);
1971 }
1972
1973 /* Make new BGP info. */
1974 new = bgp_info_new ();
1975 new->type = type;
1976 new->sub_type = sub_type;
1977 new->peer = peer;
1978 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001979 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001980
1981 /* Update MPLS tag. */
1982 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001983 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001984
Paul Jakma1a392d42006-09-07 00:24:49 +00001985 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001986
1987 /* Register new BGP information. */
1988 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001989
1990 /* route_node_get lock */
1991 bgp_unlock_node (rn);
1992
paulfee0f4c2004-09-13 05:12:46 +00001993 /* Process change. */
1994 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001995
1996 bgp_attr_extra_free (&new_attr);
1997
paulfee0f4c2004-09-13 05:12:46 +00001998 return;
1999
2000 filtered:
2001
2002 /* This BGP update is filtered. Log the reason then update BGP entry. */
2003 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002004 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002005 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2006 peer->host,
2007 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2008 p->prefixlen, rsclient->host, reason);
2009
2010 if (ri)
paulb40d9392005-08-22 22:34:41 +00002011 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002012
2013 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002014
2015 if (new_attr.extra)
2016 bgp_attr_extra_free (&new_attr);
2017
paulfee0f4c2004-09-13 05:12:46 +00002018 return;
2019}
2020
paul94f2b392005-06-28 12:44:16 +00002021static void
paulfee0f4c2004-09-13 05:12:46 +00002022bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2023 struct peer *peer, struct prefix *p, int type, int sub_type,
2024 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002025{
paulfee0f4c2004-09-13 05:12:46 +00002026 struct bgp_node *rn;
2027 struct bgp_info *ri;
2028 char buf[SU_ADDRSTRLEN];
2029
2030 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002031 return;
paulfee0f4c2004-09-13 05:12:46 +00002032
2033 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2034
2035 /* Lookup withdrawn route. */
2036 for (ri = rn->info; ri; ri = ri->next)
2037 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2038 break;
2039
2040 /* Withdraw specified route from routing table. */
2041 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002042 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002043 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002044 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002045 "%s Can't find the route %s/%d", peer->host,
2046 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2047 p->prefixlen);
2048
2049 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002050 bgp_unlock_node (rn);
2051}
paulfee0f4c2004-09-13 05:12:46 +00002052
paul94f2b392005-06-28 12:44:16 +00002053static int
paulfee0f4c2004-09-13 05:12:46 +00002054bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002055 afi_t afi, safi_t safi, int type, int sub_type,
2056 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2057{
2058 int ret;
2059 int aspath_loop_count = 0;
2060 struct bgp_node *rn;
2061 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002062 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002063 struct attr *attr_new;
2064 struct bgp_info *ri;
2065 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002066 const char *reason;
paul718e3742002-12-13 20:15:29 +00002067 char buf[SU_ADDRSTRLEN];
2068
2069 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002070 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002071
paul718e3742002-12-13 20:15:29 +00002072 /* When peer's soft reconfiguration enabled. Record input packet in
2073 Adj-RIBs-In. */
2074 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2075 && peer != bgp->peer_self && ! soft_reconfig)
2076 bgp_adj_in_set (rn, peer, attr);
2077
2078 /* Check previously received route. */
2079 for (ri = rn->info; ri; ri = ri->next)
2080 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2081 break;
2082
2083 /* AS path local-as loop check. */
2084 if (peer->change_local_as)
2085 {
2086 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2087 aspath_loop_count = 1;
2088
2089 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2090 {
2091 reason = "as-path contains our own AS;";
2092 goto filtered;
2093 }
2094 }
2095
2096 /* AS path loop check. */
2097 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2098 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2099 && aspath_loop_check(attr->aspath, bgp->confed_id)
2100 > peer->allowas_in[afi][safi]))
2101 {
2102 reason = "as-path contains our own AS;";
2103 goto filtered;
2104 }
2105
2106 /* Route reflector originator ID check. */
2107 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002108 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002109 {
2110 reason = "originator is us;";
2111 goto filtered;
2112 }
2113
2114 /* Route reflector cluster ID check. */
2115 if (bgp_cluster_filter (peer, attr))
2116 {
2117 reason = "reflected from the same cluster;";
2118 goto filtered;
2119 }
2120
2121 /* Apply incoming filter. */
2122 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2123 {
2124 reason = "filter;";
2125 goto filtered;
2126 }
2127
2128 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002129 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002130
2131 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2132 {
2133 reason = "route-map;";
2134 goto filtered;
2135 }
2136
2137 /* IPv4 unicast next hop check. */
2138 if (afi == AFI_IP && safi == SAFI_UNICAST)
2139 {
2140 /* If the peer is EBGP and nexthop is not on connected route,
2141 discard it. */
2142 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2143 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002144 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002145 {
2146 reason = "non-connected next-hop;";
2147 goto filtered;
2148 }
2149
2150 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2151 must not be my own address. */
2152 if (bgp_nexthop_self (afi, &new_attr)
2153 || new_attr.nexthop.s_addr == 0
2154 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2155 {
2156 reason = "martian next-hop;";
2157 goto filtered;
2158 }
2159 }
2160
2161 attr_new = bgp_attr_intern (&new_attr);
2162
2163 /* If the update is implicit withdraw. */
2164 if (ri)
2165 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002166 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002167
2168 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002169 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2170 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002171 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002172 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002173
2174 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2175 && peer_sort (peer) == BGP_PEER_EBGP
2176 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2177 {
2178 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002179 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002180 peer->host,
2181 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2182 p->prefixlen);
2183
paul902212c2006-02-05 17:51:19 +00002184 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2185 {
2186 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2187 bgp_process (bgp, rn, afi, safi);
2188 }
paul718e3742002-12-13 20:15:29 +00002189 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002190 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002191 {
2192 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002193 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002194 "%s rcvd %s/%d...duplicate ignored",
2195 peer->host,
2196 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2197 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002198
2199 /* graceful restart STALE flag unset. */
2200 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2201 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002202 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002203 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002204 }
paul718e3742002-12-13 20:15:29 +00002205 }
2206
2207 bgp_unlock_node (rn);
2208 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002209 bgp_attr_extra_free (&new_attr);
2210
paul718e3742002-12-13 20:15:29 +00002211 return 0;
2212 }
2213
Paul Jakma16d2e242007-04-10 19:32:10 +00002214 /* Withdraw/Announce before we fully processed the withdraw */
2215 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2216 {
2217 if (BGP_DEBUG (update, UPDATE_IN))
2218 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2219 peer->host,
2220 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2221 p->prefixlen);
2222 bgp_info_restore (rn, ri);
2223 }
2224
paul718e3742002-12-13 20:15:29 +00002225 /* Received Logging. */
2226 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002227 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002228 peer->host,
2229 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2230 p->prefixlen);
2231
hasso93406d82005-02-02 14:40:33 +00002232 /* graceful restart STALE flag unset. */
2233 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002234 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002235
paul718e3742002-12-13 20:15:29 +00002236 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002237 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002238
2239 /* implicit withdraw, decrement aggregate and pcount here.
2240 * only if update is accepted, they'll increment below.
2241 */
paul902212c2006-02-05 17:51:19 +00002242 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2243
paul718e3742002-12-13 20:15:29 +00002244 /* Update bgp route dampening information. */
2245 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2246 && peer_sort (peer) == BGP_PEER_EBGP)
2247 {
2248 /* This is implicit withdraw so we should update dampening
2249 information. */
2250 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2251 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002252 }
2253
paul718e3742002-12-13 20:15:29 +00002254 /* Update to new attribute. */
2255 bgp_attr_unintern (ri->attr);
2256 ri->attr = attr_new;
2257
2258 /* Update MPLS tag. */
2259 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002260 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002261
2262 /* Update bgp route dampening information. */
2263 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2264 && peer_sort (peer) == BGP_PEER_EBGP)
2265 {
2266 /* Now we do normal update dampening. */
2267 ret = bgp_damp_update (ri, rn, afi, safi);
2268 if (ret == BGP_DAMP_SUPPRESSED)
2269 {
2270 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002271 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002272 return 0;
2273 }
2274 }
2275
2276 /* Nexthop reachability check. */
2277 if ((afi == AFI_IP || afi == AFI_IP6)
2278 && safi == SAFI_UNICAST
2279 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002280 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002281 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002282 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002283 {
2284 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002286 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002287 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002288 }
2289 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002290 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002291
2292 /* Process change. */
2293 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2294
2295 bgp_process (bgp, rn, afi, safi);
2296 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002297 bgp_attr_extra_free (&new_attr);
2298
paul718e3742002-12-13 20:15:29 +00002299 return 0;
2300 }
2301
2302 /* Received Logging. */
2303 if (BGP_DEBUG (update, UPDATE_IN))
2304 {
ajsd2c1f162004-12-08 21:10:20 +00002305 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002306 peer->host,
2307 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2308 p->prefixlen);
2309 }
2310
paul718e3742002-12-13 20:15:29 +00002311 /* Make new BGP info. */
2312 new = bgp_info_new ();
2313 new->type = type;
2314 new->sub_type = sub_type;
2315 new->peer = peer;
2316 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002317 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002318
2319 /* Update MPLS tag. */
2320 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002321 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002322
2323 /* Nexthop reachability check. */
2324 if ((afi == AFI_IP || afi == AFI_IP6)
2325 && safi == SAFI_UNICAST
2326 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002327 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002328 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002329 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002330 {
2331 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002332 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002333 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002334 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002335 }
2336 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002337 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002338
paul902212c2006-02-05 17:51:19 +00002339 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002340 bgp_aggregate_increment (bgp, p, new, afi, safi);
2341
2342 /* Register new BGP information. */
2343 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002344
2345 /* route_node_get lock */
2346 bgp_unlock_node (rn);
2347
Paul Jakmafb982c22007-05-04 20:15:47 +00002348 bgp_attr_extra_free (&new_attr);
2349
paul718e3742002-12-13 20:15:29 +00002350 /* If maximum prefix count is configured and current prefix
2351 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002352 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2353 return -1;
paul718e3742002-12-13 20:15:29 +00002354
2355 /* Process change. */
2356 bgp_process (bgp, rn, afi, safi);
2357
2358 return 0;
2359
2360 /* This BGP update is filtered. Log the reason then update BGP
2361 entry. */
2362 filtered:
2363 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002364 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002365 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2366 peer->host,
2367 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2368 p->prefixlen, reason);
2369
2370 if (ri)
paulb40d9392005-08-22 22:34:41 +00002371 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002372
2373 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002374
2375 bgp_attr_extra_free (&new_attr);
2376
paul718e3742002-12-13 20:15:29 +00002377 return 0;
2378}
2379
2380int
paulfee0f4c2004-09-13 05:12:46 +00002381bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2382 afi_t afi, safi_t safi, int type, int sub_type,
2383 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2384{
2385 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002386 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002387 struct bgp *bgp;
2388 int ret;
2389
2390 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2391 soft_reconfig);
2392
2393 bgp = peer->bgp;
2394
2395 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002396 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002397 {
2398 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2399 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2400 sub_type, prd, tag);
2401 }
2402
2403 return ret;
2404}
2405
2406int
paul718e3742002-12-13 20:15:29 +00002407bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002408 afi_t afi, safi_t safi, int type, int sub_type,
2409 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002410{
2411 struct bgp *bgp;
2412 char buf[SU_ADDRSTRLEN];
2413 struct bgp_node *rn;
2414 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002415 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002416 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002417
2418 bgp = peer->bgp;
2419
paulfee0f4c2004-09-13 05:12:46 +00002420 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002421 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002422 {
2423 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2424 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2425 }
2426
paul718e3742002-12-13 20:15:29 +00002427 /* Logging. */
2428 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002429 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002430 peer->host,
2431 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2432 p->prefixlen);
2433
2434 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002435 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002436
2437 /* If peer is soft reconfiguration enabled. Record input packet for
2438 further calculation. */
2439 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2440 && peer != bgp->peer_self)
2441 bgp_adj_in_unset (rn, peer);
2442
2443 /* Lookup withdrawn route. */
2444 for (ri = rn->info; ri; ri = ri->next)
2445 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2446 break;
2447
2448 /* Withdraw specified route from routing table. */
2449 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002450 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002451 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002452 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002453 "%s Can't find the route %s/%d", peer->host,
2454 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2455 p->prefixlen);
2456
2457 /* Unlock bgp_node_get() lock. */
2458 bgp_unlock_node (rn);
2459
2460 return 0;
2461}
2462
2463void
2464bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2465{
2466 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002467 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002468 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002469 struct prefix p;
2470 struct bgp_info binfo;
2471 struct peer *from;
2472 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002473
Paul Jakmab2497022007-06-14 11:17:58 +00002474 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002475 return;
2476
paul718e3742002-12-13 20:15:29 +00002477 bgp = peer->bgp;
2478 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002479
paul718e3742002-12-13 20:15:29 +00002480 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2481 aspath = attr.aspath;
2482 attr.local_pref = bgp->default_local_pref;
2483 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2484
2485 if (afi == AFI_IP)
2486 str2prefix ("0.0.0.0/0", &p);
2487#ifdef HAVE_IPV6
2488 else if (afi == AFI_IP6)
2489 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002490 struct attr_extra *ae;
2491 attr.extra = NULL;
2492
2493 ae = bgp_attr_extra_get (&attr);
2494 attr.extra = ae;
2495
paul718e3742002-12-13 20:15:29 +00002496 str2prefix ("::/0", &p);
2497
2498 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002499 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002500 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002501 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002502
2503 /* If the peer is on shared nextwork and we have link-local
2504 nexthop set it. */
2505 if (peer->shared_network
2506 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2507 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002508 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002509 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002510 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002511 }
2512 }
2513#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002514
2515 if (peer->default_rmap[afi][safi].name)
2516 {
2517 binfo.peer = bgp->peer_self;
2518 binfo.attr = &attr;
2519
paulfee0f4c2004-09-13 05:12:46 +00002520 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2521
paul718e3742002-12-13 20:15:29 +00002522 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2523 RMAP_BGP, &binfo);
2524
paulfee0f4c2004-09-13 05:12:46 +00002525 bgp->peer_self->rmap_type = 0;
2526
paul718e3742002-12-13 20:15:29 +00002527 if (ret == RMAP_DENYMATCH)
2528 {
2529 bgp_attr_flush (&attr);
2530 withdraw = 1;
2531 }
2532 }
2533
2534 if (withdraw)
2535 {
2536 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2537 bgp_default_withdraw_send (peer, afi, safi);
2538 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2539 }
2540 else
2541 {
2542 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2543 bgp_default_update_send (peer, &attr, afi, safi, from);
2544 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002545
2546 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002547 aspath_unintern (aspath);
2548}
2549
2550static void
2551bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002552 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002553{
2554 struct bgp_node *rn;
2555 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002556 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002557
paul718e3742002-12-13 20:15:29 +00002558 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002559 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002560
2561 if (safi != SAFI_MPLS_VPN
2562 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2563 bgp_default_originate (peer, afi, safi, 0);
2564
2565 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2566 for (ri = rn->info; ri; ri = ri->next)
2567 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2568 {
paulfee0f4c2004-09-13 05:12:46 +00002569 if ( (rsclient) ?
2570 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2571 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002572 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2573 else
2574 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002575
2576 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002577 }
2578}
2579
2580void
2581bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2582{
2583 struct bgp_node *rn;
2584 struct bgp_table *table;
2585
2586 if (peer->status != Established)
2587 return;
2588
2589 if (! peer->afc_nego[afi][safi])
2590 return;
2591
2592 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2593 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2594 return;
2595
2596 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002597 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002598 else
2599 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2600 rn = bgp_route_next(rn))
2601 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002602 bgp_announce_table (peer, afi, safi, table, 0);
2603
2604 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2605 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002606}
2607
2608void
2609bgp_announce_route_all (struct peer *peer)
2610{
2611 afi_t afi;
2612 safi_t safi;
2613
2614 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2615 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2616 bgp_announce_route (peer, afi, safi);
2617}
2618
2619static void
paulfee0f4c2004-09-13 05:12:46 +00002620bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2621 safi_t safi, struct bgp_table *table)
2622{
2623 struct bgp_node *rn;
2624 struct bgp_adj_in *ain;
2625
2626 if (! table)
2627 table = rsclient->bgp->rib[afi][safi];
2628
2629 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2630 for (ain = rn->adj_in; ain; ain = ain->next)
2631 {
2632 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2633 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2634 }
2635}
2636
2637void
2638bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2639{
2640 struct bgp_table *table;
2641 struct bgp_node *rn;
2642
2643 if (safi != SAFI_MPLS_VPN)
2644 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2645
2646 else
2647 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2648 rn = bgp_route_next (rn))
2649 if ((table = rn->info) != NULL)
2650 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2651}
2652
2653static void
paul718e3742002-12-13 20:15:29 +00002654bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2655 struct bgp_table *table)
2656{
2657 int ret;
2658 struct bgp_node *rn;
2659 struct bgp_adj_in *ain;
2660
2661 if (! table)
2662 table = peer->bgp->rib[afi][safi];
2663
2664 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2665 for (ain = rn->adj_in; ain; ain = ain->next)
2666 {
2667 if (ain->peer == peer)
2668 {
2669 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2670 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2671 NULL, NULL, 1);
2672 if (ret < 0)
2673 {
2674 bgp_unlock_node (rn);
2675 return;
2676 }
2677 continue;
2678 }
2679 }
2680}
2681
2682void
2683bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2684{
2685 struct bgp_node *rn;
2686 struct bgp_table *table;
2687
2688 if (peer->status != Established)
2689 return;
2690
2691 if (safi != SAFI_MPLS_VPN)
2692 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2693 else
2694 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2695 rn = bgp_route_next (rn))
2696 if ((table = rn->info) != NULL)
2697 bgp_soft_reconfig_table (peer, afi, safi, table);
2698}
2699
Chris Caputo228da422009-07-18 05:44:03 +00002700
2701struct bgp_clear_node_queue
2702{
2703 struct bgp_node *rn;
2704 enum bgp_clear_route_type purpose;
2705};
2706
paul200df112005-06-01 11:17:05 +00002707static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002708bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002709{
Chris Caputo228da422009-07-18 05:44:03 +00002710 struct bgp_clear_node_queue *cnq = data;
2711 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002712 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002713 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002714 afi_t afi = rn->table->afi;
2715 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002716
Paul Jakma64e580a2006-02-21 01:09:01 +00002717 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002718
Paul Jakma64e580a2006-02-21 01:09:01 +00002719 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002720 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002721 {
2722 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002723 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2724 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002725 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002726 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2727 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002728 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002729 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002730 break;
2731 }
paul200df112005-06-01 11:17:05 +00002732 return WQ_SUCCESS;
2733}
2734
2735static void
paul0fb58d52005-11-14 14:31:49 +00002736bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002737{
Chris Caputo228da422009-07-18 05:44:03 +00002738 struct bgp_clear_node_queue *cnq = data;
2739 struct bgp_node *rn = cnq->rn;
2740 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002741
2742 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002743 bgp_table_unlock (table);
2744 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002745}
2746
2747static void
paul94f2b392005-06-28 12:44:16 +00002748bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002749{
Paul Jakma64e580a2006-02-21 01:09:01 +00002750 struct peer *peer = wq->spec.data;
2751
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002752 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002753 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002754
2755 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002756}
2757
2758static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002759bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002760{
Paul Jakmaa2943652009-07-21 14:02:04 +01002761 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002762
Paul Jakmaa2943652009-07-21 14:02:04 +01002763 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002764#undef CLEAR_QUEUE_NAME_LEN
2765
2766 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002767 {
2768 zlog_err ("%s: Failed to allocate work queue", __func__);
2769 exit (1);
2770 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002771 peer->clear_node_queue->spec.hold = 10;
2772 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2773 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2774 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2775 peer->clear_node_queue->spec.max_retries = 0;
2776
2777 /* we only 'lock' this peer reference when the queue is actually active */
2778 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002779}
2780
paul718e3742002-12-13 20:15:29 +00002781static void
2782bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002783 struct bgp_table *table, struct peer *rsclient,
2784 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002785{
2786 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002787
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002788
paul718e3742002-12-13 20:15:29 +00002789 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002790 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002791
hasso6cf159b2005-03-21 10:28:14 +00002792 /* If still no table => afi/safi isn't configured at all or smth. */
2793 if (! table)
2794 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002795
2796 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2797 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002798 struct bgp_info *ri;
2799 struct bgp_adj_in *ain;
2800 struct bgp_adj_out *aout;
2801
Paul Jakma65ca75e2006-05-04 08:08:15 +00002802 if (rn->info == NULL)
2803 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002804
2805 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2806 * queued for every clearing peer, regardless of whether it is
2807 * relevant to the peer at hand.
2808 *
2809 * Overview: There are 3 different indices which need to be
2810 * scrubbed, potentially, when a peer is removed:
2811 *
2812 * 1 peer's routes visible via the RIB (ie accepted routes)
2813 * 2 peer's routes visible by the (optional) peer's adj-in index
2814 * 3 other routes visible by the peer's adj-out index
2815 *
2816 * 3 there is no hurry in scrubbing, once the struct peer is
2817 * removed from bgp->peer, we could just GC such deleted peer's
2818 * adj-outs at our leisure.
2819 *
2820 * 1 and 2 must be 'scrubbed' in some way, at least made
2821 * invisible via RIB index before peer session is allowed to be
2822 * brought back up. So one needs to know when such a 'search' is
2823 * complete.
2824 *
2825 * Ideally:
2826 *
2827 * - there'd be a single global queue or a single RIB walker
2828 * - rather than tracking which route_nodes still need to be
2829 * examined on a peer basis, we'd track which peers still
2830 * aren't cleared
2831 *
2832 * Given that our per-peer prefix-counts now should be reliable,
2833 * this may actually be achievable. It doesn't seem to be a huge
2834 * problem at this time,
2835 */
2836 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002837 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002838 {
Chris Caputo228da422009-07-18 05:44:03 +00002839 struct bgp_clear_node_queue *cnq;
2840
2841 /* both unlocked in bgp_clear_node_queue_del */
2842 bgp_table_lock (rn->table);
2843 bgp_lock_node (rn);
2844 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2845 sizeof (struct bgp_clear_node_queue));
2846 cnq->rn = rn;
2847 cnq->purpose = purpose;
2848 work_queue_add (peer->clear_node_queue, cnq);
2849 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002850 }
2851
2852 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002853 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002854 {
2855 bgp_adj_in_remove (rn, ain);
2856 bgp_unlock_node (rn);
2857 break;
2858 }
2859 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002860 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002861 {
2862 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2863 bgp_unlock_node (rn);
2864 break;
2865 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002866 }
2867 return;
2868}
2869
2870void
Chris Caputo228da422009-07-18 05:44:03 +00002871bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2872 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002873{
2874 struct bgp_node *rn;
2875 struct bgp_table *table;
2876 struct peer *rsclient;
2877 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002878
Paul Jakma64e580a2006-02-21 01:09:01 +00002879 if (peer->clear_node_queue == NULL)
2880 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002881
Paul Jakmaca058a32006-09-14 02:58:49 +00002882 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2883 * Idle until it receives a Clearing_Completed event. This protects
2884 * against peers which flap faster than we can we clear, which could
2885 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002886 *
2887 * a) race with routes from the new session being installed before
2888 * clear_route_node visits the node (to delete the route of that
2889 * peer)
2890 * b) resource exhaustion, clear_route_node likely leads to an entry
2891 * on the process_main queue. Fast-flapping could cause that queue
2892 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002893 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002894 if (!peer->clear_node_queue->thread)
2895 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002896
Chris Caputo228da422009-07-18 05:44:03 +00002897 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002898 {
Chris Caputo228da422009-07-18 05:44:03 +00002899 case BGP_CLEAR_ROUTE_NORMAL:
2900 if (safi != SAFI_MPLS_VPN)
2901 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2902 else
2903 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2904 rn = bgp_route_next (rn))
2905 if ((table = rn->info) != NULL)
2906 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2907
2908 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2909 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2910 PEER_FLAG_RSERVER_CLIENT))
2911 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2912 break;
2913
2914 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2915 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2916 break;
2917
2918 default:
2919 assert (0);
2920 break;
paulfee0f4c2004-09-13 05:12:46 +00002921 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002922
Paul Jakmaca058a32006-09-14 02:58:49 +00002923 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002924 * completion function won't be run by workqueue code - call it here.
2925 * XXX: Actually, this assumption doesn't hold, see
2926 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002927 *
2928 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002929 * really needed if peer state is Established - peers in
2930 * pre-Established states shouldn't have any route-update state
2931 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002932 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002933 * We still can get here in pre-Established though, through
2934 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2935 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002936 *
2937 * At some future point, this check could be move to the top of the
2938 * function, and do a quick early-return when state is
2939 * pre-Established, avoiding above list and table scans. Once we're
2940 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002941 */
2942 if (!peer->clear_node_queue->thread)
2943 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002944}
2945
2946void
2947bgp_clear_route_all (struct peer *peer)
2948{
2949 afi_t afi;
2950 safi_t safi;
2951
2952 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2953 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002954 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002955}
2956
2957void
2958bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2959{
2960 struct bgp_table *table;
2961 struct bgp_node *rn;
2962 struct bgp_adj_in *ain;
2963
2964 table = peer->bgp->rib[afi][safi];
2965
2966 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2967 for (ain = rn->adj_in; ain ; ain = ain->next)
2968 if (ain->peer == peer)
2969 {
2970 bgp_adj_in_remove (rn, ain);
2971 bgp_unlock_node (rn);
2972 break;
2973 }
2974}
hasso93406d82005-02-02 14:40:33 +00002975
2976void
2977bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2978{
2979 struct bgp_node *rn;
2980 struct bgp_info *ri;
2981 struct bgp_table *table;
2982
2983 table = peer->bgp->rib[afi][safi];
2984
2985 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2986 {
2987 for (ri = rn->info; ri; ri = ri->next)
2988 if (ri->peer == peer)
2989 {
2990 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2991 bgp_rib_remove (rn, ri, peer, afi, safi);
2992 break;
2993 }
2994 }
2995}
paul718e3742002-12-13 20:15:29 +00002996
2997/* Delete all kernel routes. */
2998void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002999bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00003000{
3001 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00003002 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00003003 struct bgp_node *rn;
3004 struct bgp_table *table;
3005 struct bgp_info *ri;
3006
paul1eb8ef22005-04-07 07:30:20 +00003007 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003008 {
3009 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3010
3011 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3012 for (ri = rn->info; ri; ri = ri->next)
3013 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3014 && ri->type == ZEBRA_ROUTE_BGP
3015 && ri->sub_type == BGP_ROUTE_NORMAL)
3016 bgp_zebra_withdraw (&rn->p, ri);
3017
3018 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3019
3020 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3021 for (ri = rn->info; ri; ri = ri->next)
3022 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3023 && ri->type == ZEBRA_ROUTE_BGP
3024 && ri->sub_type == BGP_ROUTE_NORMAL)
3025 bgp_zebra_withdraw (&rn->p, ri);
3026 }
3027}
3028
3029void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003030bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003031{
3032 vty_reset ();
3033 bgp_zclient_reset ();
3034 access_list_reset ();
3035 prefix_list_reset ();
3036}
3037
3038/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3039 value. */
3040int
3041bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3042{
3043 u_char *pnt;
3044 u_char *lim;
3045 struct prefix p;
3046 int psize;
3047 int ret;
3048
3049 /* Check peer status. */
3050 if (peer->status != Established)
3051 return 0;
3052
3053 pnt = packet->nlri;
3054 lim = pnt + packet->length;
3055
3056 for (; pnt < lim; pnt += psize)
3057 {
3058 /* Clear prefix structure. */
3059 memset (&p, 0, sizeof (struct prefix));
3060
3061 /* Fetch prefix length. */
3062 p.prefixlen = *pnt++;
3063 p.family = afi2family (packet->afi);
3064
3065 /* Already checked in nlri_sanity_check(). We do double check
3066 here. */
3067 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3068 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3069 return -1;
3070
3071 /* Packet size overflow check. */
3072 psize = PSIZE (p.prefixlen);
3073
3074 /* When packet overflow occur return immediately. */
3075 if (pnt + psize > lim)
3076 return -1;
3077
3078 /* Fetch prefix from NLRI packet. */
3079 memcpy (&p.u.prefix, pnt, psize);
3080
3081 /* Check address. */
3082 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3083 {
3084 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3085 {
paulf5ba3872004-07-09 12:11:31 +00003086 /*
3087 * From draft-ietf-idr-bgp4-22, Section 6.3:
3088 * If a BGP router receives an UPDATE message with a
3089 * semantically incorrect NLRI field, in which a prefix is
3090 * semantically incorrect (eg. an unexpected multicast IP
3091 * address), it should ignore the prefix.
3092 */
paul718e3742002-12-13 20:15:29 +00003093 zlog (peer->log, LOG_ERR,
3094 "IPv4 unicast NLRI is multicast address %s",
3095 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003096
paul718e3742002-12-13 20:15:29 +00003097 return -1;
3098 }
3099 }
3100
3101#ifdef HAVE_IPV6
3102 /* Check address. */
3103 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3104 {
3105 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3106 {
3107 char buf[BUFSIZ];
3108
3109 zlog (peer->log, LOG_WARNING,
3110 "IPv6 link-local NLRI received %s ignore this NLRI",
3111 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3112
3113 continue;
3114 }
3115 }
3116#endif /* HAVE_IPV6 */
3117
3118 /* Normal process. */
3119 if (attr)
3120 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3121 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3122 else
3123 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3124 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3125
3126 /* Address family configuration mismatch or maximum-prefix count
3127 overflow. */
3128 if (ret < 0)
3129 return -1;
3130 }
3131
3132 /* Packet length consistency check. */
3133 if (pnt != lim)
3134 return -1;
3135
3136 return 0;
3137}
3138
3139/* NLRI encode syntax check routine. */
3140int
3141bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3142 bgp_size_t length)
3143{
3144 u_char *end;
3145 u_char prefixlen;
3146 int psize;
3147
3148 end = pnt + length;
3149
3150 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3151 syntactic validity. If the field is syntactically incorrect,
3152 then the Error Subcode is set to Invalid Network Field. */
3153
3154 while (pnt < end)
3155 {
3156 prefixlen = *pnt++;
3157
3158 /* Prefix length check. */
3159 if ((afi == AFI_IP && prefixlen > 32)
3160 || (afi == AFI_IP6 && prefixlen > 128))
3161 {
3162 plog_err (peer->log,
3163 "%s [Error] Update packet error (wrong prefix length %d)",
3164 peer->host, prefixlen);
3165 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3166 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3167 return -1;
3168 }
3169
3170 /* Packet size overflow check. */
3171 psize = PSIZE (prefixlen);
3172
3173 if (pnt + psize > end)
3174 {
3175 plog_err (peer->log,
3176 "%s [Error] Update packet error"
3177 " (prefix data overflow prefix size is %d)",
3178 peer->host, psize);
3179 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3180 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3181 return -1;
3182 }
3183
3184 pnt += psize;
3185 }
3186
3187 /* Packet length consistency check. */
3188 if (pnt != end)
3189 {
3190 plog_err (peer->log,
3191 "%s [Error] Update packet error"
3192 " (prefix length mismatch with total length)",
3193 peer->host);
3194 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3195 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3196 return -1;
3197 }
3198 return 0;
3199}
3200
paul94f2b392005-06-28 12:44:16 +00003201static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003202bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003203{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003204 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003205}
3206
paul94f2b392005-06-28 12:44:16 +00003207static void
paul718e3742002-12-13 20:15:29 +00003208bgp_static_free (struct bgp_static *bgp_static)
3209{
3210 if (bgp_static->rmap.name)
3211 free (bgp_static->rmap.name);
3212 XFREE (MTYPE_BGP_STATIC, bgp_static);
3213}
3214
paul94f2b392005-06-28 12:44:16 +00003215static void
paulfee0f4c2004-09-13 05:12:46 +00003216bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3217 struct prefix *p, afi_t afi, safi_t safi)
3218{
3219 struct bgp_node *rn;
3220 struct bgp_info *ri;
3221
3222 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3223
3224 /* Check selected route and self inserted route. */
3225 for (ri = rn->info; ri; ri = ri->next)
3226 if (ri->peer == bgp->peer_self
3227 && ri->type == ZEBRA_ROUTE_BGP
3228 && ri->sub_type == BGP_ROUTE_STATIC)
3229 break;
3230
3231 /* Withdraw static BGP route from routing table. */
3232 if (ri)
3233 {
paulfee0f4c2004-09-13 05:12:46 +00003234 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003235 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003236 }
3237
3238 /* Unlock bgp_node_lookup. */
3239 bgp_unlock_node (rn);
3240}
3241
paul94f2b392005-06-28 12:44:16 +00003242static void
paulfee0f4c2004-09-13 05:12:46 +00003243bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003244 struct bgp_static *bgp_static,
3245 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003246{
3247 struct bgp_node *rn;
3248 struct bgp_info *ri;
3249 struct bgp_info *new;
3250 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003251 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003252 struct attr attr = {0 };
3253 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003254 struct bgp *bgp;
3255 int ret;
3256 char buf[SU_ADDRSTRLEN];
3257
3258 bgp = rsclient->bgp;
3259
Paul Jakma06e110f2006-05-12 23:29:22 +00003260 assert (bgp_static);
3261 if (!bgp_static)
3262 return;
3263
paulfee0f4c2004-09-13 05:12:46 +00003264 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3265
3266 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003267
3268 attr.nexthop = bgp_static->igpnexthop;
3269 attr.med = bgp_static->igpmetric;
3270 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003271
Paul Jakma41367172007-08-06 15:24:51 +00003272 if (bgp_static->atomic)
3273 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3274
paulfee0f4c2004-09-13 05:12:46 +00003275 /* Apply network route-map for export to this rsclient. */
3276 if (bgp_static->rmap.name)
3277 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003278 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003279 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003280 info.attr = &attr_tmp;
3281
paulfee0f4c2004-09-13 05:12:46 +00003282 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3283 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3284
3285 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3286
3287 rsclient->rmap_type = 0;
3288
3289 if (ret == RMAP_DENYMATCH)
3290 {
3291 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003292 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003293
3294 /* Unintern original. */
3295 aspath_unintern (attr.aspath);
3296 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003297 bgp_attr_extra_free (&attr);
3298
paulfee0f4c2004-09-13 05:12:46 +00003299 return;
3300 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003301 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003302 }
3303 else
3304 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003305
Stephen Hemminger7badc262010-08-05 10:26:31 -07003306 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003307
paulfee0f4c2004-09-13 05:12:46 +00003308 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3309
Paul Jakmafb982c22007-05-04 20:15:47 +00003310 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3311 == RMAP_DENY)
3312 {
paulfee0f4c2004-09-13 05:12:46 +00003313 /* This BGP update is filtered. Log the reason then update BGP entry. */
3314 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003315 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003316 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3317 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3318 p->prefixlen, rsclient->host);
3319
3320 bgp->peer_self->rmap_type = 0;
3321
3322 bgp_attr_unintern (attr_new);
3323 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003324 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003325
3326 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3327
3328 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003329 }
paulfee0f4c2004-09-13 05:12:46 +00003330
3331 bgp->peer_self->rmap_type = 0;
3332
3333 bgp_attr_unintern (attr_new);
3334 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003335 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003336
3337 for (ri = rn->info; ri; ri = ri->next)
3338 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3339 && ri->sub_type == BGP_ROUTE_STATIC)
3340 break;
3341
3342 if (ri)
3343 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003344 if (attrhash_cmp (ri->attr, attr_new) &&
3345 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003346 {
3347 bgp_unlock_node (rn);
3348 bgp_attr_unintern (attr_new);
3349 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003350 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003351 return;
3352 }
3353 else
3354 {
3355 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003356 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003357
3358 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003359 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3360 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003361 bgp_attr_unintern (ri->attr);
3362 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003363 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003364
3365 /* Process change. */
3366 bgp_process (bgp, rn, afi, safi);
3367 bgp_unlock_node (rn);
3368 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003369 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003370 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003371 }
paulfee0f4c2004-09-13 05:12:46 +00003372 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003373
paulfee0f4c2004-09-13 05:12:46 +00003374 /* Make new BGP info. */
3375 new = bgp_info_new ();
3376 new->type = ZEBRA_ROUTE_BGP;
3377 new->sub_type = BGP_ROUTE_STATIC;
3378 new->peer = bgp->peer_self;
3379 SET_FLAG (new->flags, BGP_INFO_VALID);
3380 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003381 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003382
3383 /* Register new BGP information. */
3384 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003385
3386 /* route_node_get lock */
3387 bgp_unlock_node (rn);
3388
paulfee0f4c2004-09-13 05:12:46 +00003389 /* Process change. */
3390 bgp_process (bgp, rn, afi, safi);
3391
3392 /* Unintern original. */
3393 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003394 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003395}
3396
paul94f2b392005-06-28 12:44:16 +00003397static void
paulfee0f4c2004-09-13 05:12:46 +00003398bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003399 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3400{
3401 struct bgp_node *rn;
3402 struct bgp_info *ri;
3403 struct bgp_info *new;
3404 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003405 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003406 struct attr *attr_new;
3407 int ret;
3408
Paul Jakmadd8103a2006-05-12 23:27:30 +00003409 assert (bgp_static);
3410 if (!bgp_static)
3411 return;
3412
paulfee0f4c2004-09-13 05:12:46 +00003413 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003414
3415 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003416
3417 attr.nexthop = bgp_static->igpnexthop;
3418 attr.med = bgp_static->igpmetric;
3419 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003420
Paul Jakma41367172007-08-06 15:24:51 +00003421 if (bgp_static->atomic)
3422 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3423
paul718e3742002-12-13 20:15:29 +00003424 /* Apply route-map. */
3425 if (bgp_static->rmap.name)
3426 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003427 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003428 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003429 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003430
paulfee0f4c2004-09-13 05:12:46 +00003431 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3432
paul718e3742002-12-13 20:15:29 +00003433 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003434
paulfee0f4c2004-09-13 05:12:46 +00003435 bgp->peer_self->rmap_type = 0;
3436
paul718e3742002-12-13 20:15:29 +00003437 if (ret == RMAP_DENYMATCH)
3438 {
3439 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003440 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003441
3442 /* Unintern original. */
3443 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003444 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003445 bgp_static_withdraw (bgp, p, afi, safi);
3446 return;
3447 }
paul286e1e72003-08-08 00:24:31 +00003448 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003449 }
paul286e1e72003-08-08 00:24:31 +00003450 else
3451 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003452
3453 for (ri = rn->info; ri; ri = ri->next)
3454 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3455 && ri->sub_type == BGP_ROUTE_STATIC)
3456 break;
3457
3458 if (ri)
3459 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003460 if (attrhash_cmp (ri->attr, attr_new) &&
3461 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003462 {
3463 bgp_unlock_node (rn);
3464 bgp_attr_unintern (attr_new);
3465 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003466 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003467 return;
3468 }
3469 else
3470 {
3471 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003472 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003473
3474 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003475 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3476 bgp_info_restore(rn, ri);
3477 else
3478 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003479 bgp_attr_unintern (ri->attr);
3480 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003481 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003482
3483 /* Process change. */
3484 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3485 bgp_process (bgp, rn, afi, safi);
3486 bgp_unlock_node (rn);
3487 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003488 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003489 return;
3490 }
3491 }
3492
3493 /* Make new BGP info. */
3494 new = bgp_info_new ();
3495 new->type = ZEBRA_ROUTE_BGP;
3496 new->sub_type = BGP_ROUTE_STATIC;
3497 new->peer = bgp->peer_self;
3498 SET_FLAG (new->flags, BGP_INFO_VALID);
3499 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003500 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003501
3502 /* Aggregate address increment. */
3503 bgp_aggregate_increment (bgp, p, new, afi, safi);
3504
3505 /* Register new BGP information. */
3506 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003507
3508 /* route_node_get lock */
3509 bgp_unlock_node (rn);
3510
paul718e3742002-12-13 20:15:29 +00003511 /* Process change. */
3512 bgp_process (bgp, rn, afi, safi);
3513
3514 /* Unintern original. */
3515 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003516 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003517}
3518
3519void
paulfee0f4c2004-09-13 05:12:46 +00003520bgp_static_update (struct bgp *bgp, struct prefix *p,
3521 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3522{
3523 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003524 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003525
3526 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3527
paul1eb8ef22005-04-07 07:30:20 +00003528 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003529 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003530 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3531 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003532 }
3533}
3534
paul94f2b392005-06-28 12:44:16 +00003535static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003536bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3537 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003538{
3539 struct bgp_node *rn;
3540 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003541
paulfee0f4c2004-09-13 05:12:46 +00003542 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003543
3544 /* Make new BGP info. */
3545 new = bgp_info_new ();
3546 new->type = ZEBRA_ROUTE_BGP;
3547 new->sub_type = BGP_ROUTE_STATIC;
3548 new->peer = bgp->peer_self;
3549 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3550 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003551 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003552 new->extra = bgp_info_extra_new();
3553 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003554
3555 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003556 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003557
3558 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003559 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003560
paul200df112005-06-01 11:17:05 +00003561 /* route_node_get lock */
3562 bgp_unlock_node (rn);
3563
paul718e3742002-12-13 20:15:29 +00003564 /* Process change. */
3565 bgp_process (bgp, rn, afi, safi);
3566}
3567
3568void
3569bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3570 safi_t safi)
3571{
3572 struct bgp_node *rn;
3573 struct bgp_info *ri;
3574
paulfee0f4c2004-09-13 05:12:46 +00003575 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003576
3577 /* Check selected route and self inserted route. */
3578 for (ri = rn->info; ri; ri = ri->next)
3579 if (ri->peer == bgp->peer_self
3580 && ri->type == ZEBRA_ROUTE_BGP
3581 && ri->sub_type == BGP_ROUTE_STATIC)
3582 break;
3583
3584 /* Withdraw static BGP route from routing table. */
3585 if (ri)
3586 {
3587 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003588 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003589 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003590 }
3591
3592 /* Unlock bgp_node_lookup. */
3593 bgp_unlock_node (rn);
3594}
3595
3596void
paulfee0f4c2004-09-13 05:12:46 +00003597bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3598{
3599 struct bgp_static *bgp_static;
3600 struct bgp *bgp;
3601 struct bgp_node *rn;
3602 struct prefix *p;
3603
3604 bgp = rsclient->bgp;
3605
3606 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3607 if ((bgp_static = rn->info) != NULL)
3608 {
3609 p = &rn->p;
3610
3611 bgp_static_update_rsclient (rsclient, p, bgp_static,
3612 afi, safi);
3613 }
3614}
3615
paul94f2b392005-06-28 12:44:16 +00003616static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003617bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3618 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003619{
3620 struct bgp_node *rn;
3621 struct bgp_info *ri;
3622
paulfee0f4c2004-09-13 05:12:46 +00003623 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003624
3625 /* Check selected route and self inserted route. */
3626 for (ri = rn->info; ri; ri = ri->next)
3627 if (ri->peer == bgp->peer_self
3628 && ri->type == ZEBRA_ROUTE_BGP
3629 && ri->sub_type == BGP_ROUTE_STATIC)
3630 break;
3631
3632 /* Withdraw static BGP route from routing table. */
3633 if (ri)
3634 {
3635 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003636 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003637 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003638 }
3639
3640 /* Unlock bgp_node_lookup. */
3641 bgp_unlock_node (rn);
3642}
3643
3644/* Configure static BGP network. When user don't run zebra, static
3645 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003646static int
paulfd79ac92004-10-13 05:06:08 +00003647bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003648 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003649{
3650 int ret;
3651 struct prefix p;
3652 struct bgp_static *bgp_static;
3653 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003654 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003655
3656 /* Convert IP prefix string to struct prefix. */
3657 ret = str2prefix (ip_str, &p);
3658 if (! ret)
3659 {
3660 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3661 return CMD_WARNING;
3662 }
3663#ifdef HAVE_IPV6
3664 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3665 {
3666 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3667 VTY_NEWLINE);
3668 return CMD_WARNING;
3669 }
3670#endif /* HAVE_IPV6 */
3671
3672 apply_mask (&p);
3673
3674 /* Set BGP static route configuration. */
3675 rn = bgp_node_get (bgp->route[afi][safi], &p);
3676
3677 if (rn->info)
3678 {
3679 /* Configuration change. */
3680 bgp_static = rn->info;
3681
3682 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003683 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3684 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003685
paul718e3742002-12-13 20:15:29 +00003686 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003687
paul718e3742002-12-13 20:15:29 +00003688 if (rmap)
3689 {
3690 if (bgp_static->rmap.name)
3691 free (bgp_static->rmap.name);
3692 bgp_static->rmap.name = strdup (rmap);
3693 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3694 }
3695 else
3696 {
3697 if (bgp_static->rmap.name)
3698 free (bgp_static->rmap.name);
3699 bgp_static->rmap.name = NULL;
3700 bgp_static->rmap.map = NULL;
3701 bgp_static->valid = 0;
3702 }
3703 bgp_unlock_node (rn);
3704 }
3705 else
3706 {
3707 /* New configuration. */
3708 bgp_static = bgp_static_new ();
3709 bgp_static->backdoor = backdoor;
3710 bgp_static->valid = 0;
3711 bgp_static->igpmetric = 0;
3712 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003713
paul718e3742002-12-13 20:15:29 +00003714 if (rmap)
3715 {
3716 if (bgp_static->rmap.name)
3717 free (bgp_static->rmap.name);
3718 bgp_static->rmap.name = strdup (rmap);
3719 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3720 }
3721 rn->info = bgp_static;
3722 }
3723
3724 /* If BGP scan is not enabled, we should install this route here. */
3725 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3726 {
3727 bgp_static->valid = 1;
3728
3729 if (need_update)
3730 bgp_static_withdraw (bgp, &p, afi, safi);
3731
3732 if (! bgp_static->backdoor)
3733 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3734 }
3735
3736 return CMD_SUCCESS;
3737}
3738
3739/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003740static int
paulfd79ac92004-10-13 05:06:08 +00003741bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003742 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003743{
3744 int ret;
3745 struct prefix p;
3746 struct bgp_static *bgp_static;
3747 struct bgp_node *rn;
3748
3749 /* Convert IP prefix string to struct prefix. */
3750 ret = str2prefix (ip_str, &p);
3751 if (! ret)
3752 {
3753 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3754 return CMD_WARNING;
3755 }
3756#ifdef HAVE_IPV6
3757 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3758 {
3759 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3760 VTY_NEWLINE);
3761 return CMD_WARNING;
3762 }
3763#endif /* HAVE_IPV6 */
3764
3765 apply_mask (&p);
3766
3767 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3768 if (! rn)
3769 {
3770 vty_out (vty, "%% Can't find specified static route configuration.%s",
3771 VTY_NEWLINE);
3772 return CMD_WARNING;
3773 }
3774
3775 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003776
paul718e3742002-12-13 20:15:29 +00003777 /* Update BGP RIB. */
3778 if (! bgp_static->backdoor)
3779 bgp_static_withdraw (bgp, &p, afi, safi);
3780
3781 /* Clear configuration. */
3782 bgp_static_free (bgp_static);
3783 rn->info = NULL;
3784 bgp_unlock_node (rn);
3785 bgp_unlock_node (rn);
3786
3787 return CMD_SUCCESS;
3788}
3789
3790/* Called from bgp_delete(). Delete all static routes from the BGP
3791 instance. */
3792void
3793bgp_static_delete (struct bgp *bgp)
3794{
3795 afi_t afi;
3796 safi_t safi;
3797 struct bgp_node *rn;
3798 struct bgp_node *rm;
3799 struct bgp_table *table;
3800 struct bgp_static *bgp_static;
3801
3802 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3803 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3804 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3805 if (rn->info != NULL)
3806 {
3807 if (safi == SAFI_MPLS_VPN)
3808 {
3809 table = rn->info;
3810
3811 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3812 {
3813 bgp_static = rn->info;
3814 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3815 AFI_IP, SAFI_MPLS_VPN,
3816 (struct prefix_rd *)&rn->p,
3817 bgp_static->tag);
3818 bgp_static_free (bgp_static);
3819 rn->info = NULL;
3820 bgp_unlock_node (rn);
3821 }
3822 }
3823 else
3824 {
3825 bgp_static = rn->info;
3826 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3827 bgp_static_free (bgp_static);
3828 rn->info = NULL;
3829 bgp_unlock_node (rn);
3830 }
3831 }
3832}
3833
3834int
paulfd79ac92004-10-13 05:06:08 +00003835bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3836 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003837{
3838 int ret;
3839 struct prefix p;
3840 struct prefix_rd prd;
3841 struct bgp *bgp;
3842 struct bgp_node *prn;
3843 struct bgp_node *rn;
3844 struct bgp_table *table;
3845 struct bgp_static *bgp_static;
3846 u_char tag[3];
3847
3848 bgp = vty->index;
3849
3850 ret = str2prefix (ip_str, &p);
3851 if (! ret)
3852 {
3853 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3854 return CMD_WARNING;
3855 }
3856 apply_mask (&p);
3857
3858 ret = str2prefix_rd (rd_str, &prd);
3859 if (! ret)
3860 {
3861 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3862 return CMD_WARNING;
3863 }
3864
3865 ret = str2tag (tag_str, tag);
3866 if (! ret)
3867 {
3868 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3869 return CMD_WARNING;
3870 }
3871
3872 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3873 (struct prefix *)&prd);
3874 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003875 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003876 else
3877 bgp_unlock_node (prn);
3878 table = prn->info;
3879
3880 rn = bgp_node_get (table, &p);
3881
3882 if (rn->info)
3883 {
3884 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3885 bgp_unlock_node (rn);
3886 }
3887 else
3888 {
3889 /* New configuration. */
3890 bgp_static = bgp_static_new ();
3891 bgp_static->valid = 1;
3892 memcpy (bgp_static->tag, tag, 3);
3893 rn->info = bgp_static;
3894
3895 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3896 }
3897
3898 return CMD_SUCCESS;
3899}
3900
3901/* Configure static BGP network. */
3902int
paulfd79ac92004-10-13 05:06:08 +00003903bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3904 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003905{
3906 int ret;
3907 struct bgp *bgp;
3908 struct prefix p;
3909 struct prefix_rd prd;
3910 struct bgp_node *prn;
3911 struct bgp_node *rn;
3912 struct bgp_table *table;
3913 struct bgp_static *bgp_static;
3914 u_char tag[3];
3915
3916 bgp = vty->index;
3917
3918 /* Convert IP prefix string to struct prefix. */
3919 ret = str2prefix (ip_str, &p);
3920 if (! ret)
3921 {
3922 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3923 return CMD_WARNING;
3924 }
3925 apply_mask (&p);
3926
3927 ret = str2prefix_rd (rd_str, &prd);
3928 if (! ret)
3929 {
3930 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3931 return CMD_WARNING;
3932 }
3933
3934 ret = str2tag (tag_str, tag);
3935 if (! ret)
3936 {
3937 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3938 return CMD_WARNING;
3939 }
3940
3941 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3942 (struct prefix *)&prd);
3943 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003944 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003945 else
3946 bgp_unlock_node (prn);
3947 table = prn->info;
3948
3949 rn = bgp_node_lookup (table, &p);
3950
3951 if (rn)
3952 {
3953 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3954
3955 bgp_static = rn->info;
3956 bgp_static_free (bgp_static);
3957 rn->info = NULL;
3958 bgp_unlock_node (rn);
3959 bgp_unlock_node (rn);
3960 }
3961 else
3962 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3963
3964 return CMD_SUCCESS;
3965}
3966
3967DEFUN (bgp_network,
3968 bgp_network_cmd,
3969 "network A.B.C.D/M",
3970 "Specify a network to announce via BGP\n"
3971 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3972{
3973 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003974 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003975}
3976
3977DEFUN (bgp_network_route_map,
3978 bgp_network_route_map_cmd,
3979 "network A.B.C.D/M route-map WORD",
3980 "Specify a network to announce via BGP\n"
3981 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3982 "Route-map to modify the attributes\n"
3983 "Name of the route map\n")
3984{
3985 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003986 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003987}
3988
3989DEFUN (bgp_network_backdoor,
3990 bgp_network_backdoor_cmd,
3991 "network A.B.C.D/M backdoor",
3992 "Specify a network to announce via BGP\n"
3993 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3994 "Specify a BGP backdoor route\n")
3995{
Paul Jakma41367172007-08-06 15:24:51 +00003996 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003997 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003998}
3999
4000DEFUN (bgp_network_mask,
4001 bgp_network_mask_cmd,
4002 "network A.B.C.D mask A.B.C.D",
4003 "Specify a network to announce via BGP\n"
4004 "Network number\n"
4005 "Network mask\n"
4006 "Network mask\n")
4007{
4008 int ret;
4009 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004010
paul718e3742002-12-13 20:15:29 +00004011 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4012 if (! ret)
4013 {
4014 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4015 return CMD_WARNING;
4016 }
4017
4018 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004019 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004020}
4021
4022DEFUN (bgp_network_mask_route_map,
4023 bgp_network_mask_route_map_cmd,
4024 "network A.B.C.D mask A.B.C.D route-map WORD",
4025 "Specify a network to announce via BGP\n"
4026 "Network number\n"
4027 "Network mask\n"
4028 "Network mask\n"
4029 "Route-map to modify the attributes\n"
4030 "Name of the route map\n")
4031{
4032 int ret;
4033 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004034
paul718e3742002-12-13 20:15:29 +00004035 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4036 if (! ret)
4037 {
4038 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4039 return CMD_WARNING;
4040 }
4041
4042 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004043 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004044}
4045
4046DEFUN (bgp_network_mask_backdoor,
4047 bgp_network_mask_backdoor_cmd,
4048 "network A.B.C.D mask A.B.C.D backdoor",
4049 "Specify a network to announce via BGP\n"
4050 "Network number\n"
4051 "Network mask\n"
4052 "Network mask\n"
4053 "Specify a BGP backdoor route\n")
4054{
4055 int ret;
4056 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004057
paul718e3742002-12-13 20:15:29 +00004058 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4059 if (! ret)
4060 {
4061 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4062 return CMD_WARNING;
4063 }
4064
Paul Jakma41367172007-08-06 15:24:51 +00004065 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004066 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004067}
4068
4069DEFUN (bgp_network_mask_natural,
4070 bgp_network_mask_natural_cmd,
4071 "network A.B.C.D",
4072 "Specify a network to announce via BGP\n"
4073 "Network number\n")
4074{
4075 int ret;
4076 char prefix_str[BUFSIZ];
4077
4078 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4079 if (! ret)
4080 {
4081 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4082 return CMD_WARNING;
4083 }
4084
4085 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004086 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004087}
4088
4089DEFUN (bgp_network_mask_natural_route_map,
4090 bgp_network_mask_natural_route_map_cmd,
4091 "network A.B.C.D route-map WORD",
4092 "Specify a network to announce via BGP\n"
4093 "Network number\n"
4094 "Route-map to modify the attributes\n"
4095 "Name of the route map\n")
4096{
4097 int ret;
4098 char prefix_str[BUFSIZ];
4099
4100 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4101 if (! ret)
4102 {
4103 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4104 return CMD_WARNING;
4105 }
4106
4107 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004108 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004109}
4110
4111DEFUN (bgp_network_mask_natural_backdoor,
4112 bgp_network_mask_natural_backdoor_cmd,
4113 "network A.B.C.D backdoor",
4114 "Specify a network to announce via BGP\n"
4115 "Network number\n"
4116 "Specify a BGP backdoor route\n")
4117{
4118 int ret;
4119 char prefix_str[BUFSIZ];
4120
4121 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4122 if (! ret)
4123 {
4124 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4125 return CMD_WARNING;
4126 }
4127
Paul Jakma41367172007-08-06 15:24:51 +00004128 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004129 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004130}
4131
4132DEFUN (no_bgp_network,
4133 no_bgp_network_cmd,
4134 "no network A.B.C.D/M",
4135 NO_STR
4136 "Specify a network to announce via BGP\n"
4137 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4138{
4139 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4140 bgp_node_safi (vty));
4141}
4142
4143ALIAS (no_bgp_network,
4144 no_bgp_network_route_map_cmd,
4145 "no network A.B.C.D/M route-map WORD",
4146 NO_STR
4147 "Specify a network to announce via BGP\n"
4148 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4149 "Route-map to modify the attributes\n"
4150 "Name of the route map\n")
4151
4152ALIAS (no_bgp_network,
4153 no_bgp_network_backdoor_cmd,
4154 "no network A.B.C.D/M backdoor",
4155 NO_STR
4156 "Specify a network to announce via BGP\n"
4157 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4158 "Specify a BGP backdoor route\n")
4159
4160DEFUN (no_bgp_network_mask,
4161 no_bgp_network_mask_cmd,
4162 "no network A.B.C.D mask A.B.C.D",
4163 NO_STR
4164 "Specify a network to announce via BGP\n"
4165 "Network number\n"
4166 "Network mask\n"
4167 "Network mask\n")
4168{
4169 int ret;
4170 char prefix_str[BUFSIZ];
4171
4172 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4173 if (! ret)
4174 {
4175 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4176 return CMD_WARNING;
4177 }
4178
4179 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4180 bgp_node_safi (vty));
4181}
4182
4183ALIAS (no_bgp_network_mask,
4184 no_bgp_network_mask_route_map_cmd,
4185 "no network A.B.C.D mask A.B.C.D route-map WORD",
4186 NO_STR
4187 "Specify a network to announce via BGP\n"
4188 "Network number\n"
4189 "Network mask\n"
4190 "Network mask\n"
4191 "Route-map to modify the attributes\n"
4192 "Name of the route map\n")
4193
4194ALIAS (no_bgp_network_mask,
4195 no_bgp_network_mask_backdoor_cmd,
4196 "no network A.B.C.D mask A.B.C.D backdoor",
4197 NO_STR
4198 "Specify a network to announce via BGP\n"
4199 "Network number\n"
4200 "Network mask\n"
4201 "Network mask\n"
4202 "Specify a BGP backdoor route\n")
4203
4204DEFUN (no_bgp_network_mask_natural,
4205 no_bgp_network_mask_natural_cmd,
4206 "no network A.B.C.D",
4207 NO_STR
4208 "Specify a network to announce via BGP\n"
4209 "Network number\n")
4210{
4211 int ret;
4212 char prefix_str[BUFSIZ];
4213
4214 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4215 if (! ret)
4216 {
4217 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4218 return CMD_WARNING;
4219 }
4220
4221 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4222 bgp_node_safi (vty));
4223}
4224
4225ALIAS (no_bgp_network_mask_natural,
4226 no_bgp_network_mask_natural_route_map_cmd,
4227 "no network A.B.C.D route-map WORD",
4228 NO_STR
4229 "Specify a network to announce via BGP\n"
4230 "Network number\n"
4231 "Route-map to modify the attributes\n"
4232 "Name of the route map\n")
4233
4234ALIAS (no_bgp_network_mask_natural,
4235 no_bgp_network_mask_natural_backdoor_cmd,
4236 "no network A.B.C.D backdoor",
4237 NO_STR
4238 "Specify a network to announce via BGP\n"
4239 "Network number\n"
4240 "Specify a BGP backdoor route\n")
4241
4242#ifdef HAVE_IPV6
4243DEFUN (ipv6_bgp_network,
4244 ipv6_bgp_network_cmd,
4245 "network X:X::X:X/M",
4246 "Specify a network to announce via BGP\n"
4247 "IPv6 prefix <network>/<length>\n")
4248{
Paul Jakma41367172007-08-06 15:24:51 +00004249 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004250 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004251}
4252
4253DEFUN (ipv6_bgp_network_route_map,
4254 ipv6_bgp_network_route_map_cmd,
4255 "network X:X::X:X/M route-map WORD",
4256 "Specify a network to announce via BGP\n"
4257 "IPv6 prefix <network>/<length>\n"
4258 "Route-map to modify the attributes\n"
4259 "Name of the route map\n")
4260{
4261 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004262 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004263}
4264
4265DEFUN (no_ipv6_bgp_network,
4266 no_ipv6_bgp_network_cmd,
4267 "no network X:X::X:X/M",
4268 NO_STR
4269 "Specify a network to announce via BGP\n"
4270 "IPv6 prefix <network>/<length>\n")
4271{
4272 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4273}
4274
4275ALIAS (no_ipv6_bgp_network,
4276 no_ipv6_bgp_network_route_map_cmd,
4277 "no network X:X::X:X/M route-map WORD",
4278 NO_STR
4279 "Specify a network to announce via BGP\n"
4280 "IPv6 prefix <network>/<length>\n"
4281 "Route-map to modify the attributes\n"
4282 "Name of the route map\n")
4283
4284ALIAS (ipv6_bgp_network,
4285 old_ipv6_bgp_network_cmd,
4286 "ipv6 bgp network X:X::X:X/M",
4287 IPV6_STR
4288 BGP_STR
4289 "Specify a network to announce via BGP\n"
4290 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4291
4292ALIAS (no_ipv6_bgp_network,
4293 old_no_ipv6_bgp_network_cmd,
4294 "no ipv6 bgp network X:X::X:X/M",
4295 NO_STR
4296 IPV6_STR
4297 BGP_STR
4298 "Specify a network to announce via BGP\n"
4299 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4300#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004301
4302/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4303ALIAS_DEPRECATED (bgp_network,
4304 bgp_network_ttl_cmd,
4305 "network A.B.C.D/M pathlimit <0-255>",
4306 "Specify a network to announce via BGP\n"
4307 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4308 "AS-Path hopcount limit attribute\n"
4309 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4310ALIAS_DEPRECATED (bgp_network_backdoor,
4311 bgp_network_backdoor_ttl_cmd,
4312 "network A.B.C.D/M backdoor pathlimit <0-255>",
4313 "Specify a network to announce via BGP\n"
4314 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4315 "Specify a BGP backdoor route\n"
4316 "AS-Path hopcount limit attribute\n"
4317 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4318ALIAS_DEPRECATED (bgp_network_mask,
4319 bgp_network_mask_ttl_cmd,
4320 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4321 "Specify a network to announce via BGP\n"
4322 "Network number\n"
4323 "Network mask\n"
4324 "Network mask\n"
4325 "AS-Path hopcount limit attribute\n"
4326 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4327ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4328 bgp_network_mask_backdoor_ttl_cmd,
4329 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4330 "Specify a network to announce via BGP\n"
4331 "Network number\n"
4332 "Network mask\n"
4333 "Network mask\n"
4334 "Specify a BGP backdoor route\n"
4335 "AS-Path hopcount limit attribute\n"
4336 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4337ALIAS_DEPRECATED (bgp_network_mask_natural,
4338 bgp_network_mask_natural_ttl_cmd,
4339 "network A.B.C.D pathlimit <0-255>",
4340 "Specify a network to announce via BGP\n"
4341 "Network number\n"
4342 "AS-Path hopcount limit attribute\n"
4343 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4344ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4345 bgp_network_mask_natural_backdoor_ttl_cmd,
4346 "network A.B.C.D backdoor pathlimit (1-255>",
4347 "Specify a network to announce via BGP\n"
4348 "Network number\n"
4349 "Specify a BGP backdoor route\n"
4350 "AS-Path hopcount limit attribute\n"
4351 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4352ALIAS_DEPRECATED (no_bgp_network,
4353 no_bgp_network_ttl_cmd,
4354 "no network A.B.C.D/M pathlimit <0-255>",
4355 NO_STR
4356 "Specify a network to announce via BGP\n"
4357 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4358 "AS-Path hopcount limit attribute\n"
4359 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4360ALIAS_DEPRECATED (no_bgp_network,
4361 no_bgp_network_backdoor_ttl_cmd,
4362 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4363 NO_STR
4364 "Specify a network to announce via BGP\n"
4365 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4366 "Specify a BGP backdoor route\n"
4367 "AS-Path hopcount limit attribute\n"
4368 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4369ALIAS_DEPRECATED (no_bgp_network,
4370 no_bgp_network_mask_ttl_cmd,
4371 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4372 NO_STR
4373 "Specify a network to announce via BGP\n"
4374 "Network number\n"
4375 "Network mask\n"
4376 "Network mask\n"
4377 "AS-Path hopcount limit attribute\n"
4378 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4379ALIAS_DEPRECATED (no_bgp_network_mask,
4380 no_bgp_network_mask_backdoor_ttl_cmd,
4381 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4382 NO_STR
4383 "Specify a network to announce via BGP\n"
4384 "Network number\n"
4385 "Network mask\n"
4386 "Network mask\n"
4387 "Specify a BGP backdoor route\n"
4388 "AS-Path hopcount limit attribute\n"
4389 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4390ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4391 no_bgp_network_mask_natural_ttl_cmd,
4392 "no network A.B.C.D pathlimit <0-255>",
4393 NO_STR
4394 "Specify a network to announce via BGP\n"
4395 "Network number\n"
4396 "AS-Path hopcount limit attribute\n"
4397 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4398ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4399 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4400 "no network A.B.C.D backdoor pathlimit <0-255>",
4401 NO_STR
4402 "Specify a network to announce via BGP\n"
4403 "Network number\n"
4404 "Specify a BGP backdoor route\n"
4405 "AS-Path hopcount limit attribute\n"
4406 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004407#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004408ALIAS_DEPRECATED (ipv6_bgp_network,
4409 ipv6_bgp_network_ttl_cmd,
4410 "network X:X::X:X/M pathlimit <0-255>",
4411 "Specify a network to announce via BGP\n"
4412 "IPv6 prefix <network>/<length>\n"
4413 "AS-Path hopcount limit attribute\n"
4414 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4415ALIAS_DEPRECATED (no_ipv6_bgp_network,
4416 no_ipv6_bgp_network_ttl_cmd,
4417 "no network X:X::X:X/M pathlimit <0-255>",
4418 NO_STR
4419 "Specify a network to announce via BGP\n"
4420 "IPv6 prefix <network>/<length>\n"
4421 "AS-Path hopcount limit attribute\n"
4422 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004423#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004424
4425/* Aggreagete address:
4426
4427 advertise-map Set condition to advertise attribute
4428 as-set Generate AS set path information
4429 attribute-map Set attributes of aggregate
4430 route-map Set parameters of aggregate
4431 summary-only Filter more specific routes from updates
4432 suppress-map Conditionally filter more specific routes from updates
4433 <cr>
4434 */
4435struct bgp_aggregate
4436{
4437 /* Summary-only flag. */
4438 u_char summary_only;
4439
4440 /* AS set generation. */
4441 u_char as_set;
4442
4443 /* Route-map for aggregated route. */
4444 struct route_map *map;
4445
4446 /* Suppress-count. */
4447 unsigned long count;
4448
4449 /* SAFI configuration. */
4450 safi_t safi;
4451};
4452
paul94f2b392005-06-28 12:44:16 +00004453static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004454bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004455{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004456 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004457}
4458
paul94f2b392005-06-28 12:44:16 +00004459static void
paul718e3742002-12-13 20:15:29 +00004460bgp_aggregate_free (struct bgp_aggregate *aggregate)
4461{
4462 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4463}
4464
paul94f2b392005-06-28 12:44:16 +00004465static void
paul718e3742002-12-13 20:15:29 +00004466bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4467 afi_t afi, safi_t safi, struct bgp_info *del,
4468 struct bgp_aggregate *aggregate)
4469{
4470 struct bgp_table *table;
4471 struct bgp_node *top;
4472 struct bgp_node *rn;
4473 u_char origin;
4474 struct aspath *aspath = NULL;
4475 struct aspath *asmerge = NULL;
4476 struct community *community = NULL;
4477 struct community *commerge = NULL;
4478 struct in_addr nexthop;
4479 u_int32_t med = 0;
4480 struct bgp_info *ri;
4481 struct bgp_info *new;
4482 int first = 1;
4483 unsigned long match = 0;
4484
4485 /* Record adding route's nexthop and med. */
4486 if (rinew)
4487 {
4488 nexthop = rinew->attr->nexthop;
4489 med = rinew->attr->med;
4490 }
4491
4492 /* ORIGIN attribute: If at least one route among routes that are
4493 aggregated has ORIGIN with the value INCOMPLETE, then the
4494 aggregated route must have the ORIGIN attribute with the value
4495 INCOMPLETE. Otherwise, if at least one route among routes that
4496 are aggregated has ORIGIN with the value EGP, then the aggregated
4497 route must have the origin attribute with the value EGP. In all
4498 other case the value of the ORIGIN attribute of the aggregated
4499 route is INTERNAL. */
4500 origin = BGP_ORIGIN_IGP;
4501
4502 table = bgp->rib[afi][safi];
4503
4504 top = bgp_node_get (table, p);
4505 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4506 if (rn->p.prefixlen > p->prefixlen)
4507 {
4508 match = 0;
4509
4510 for (ri = rn->info; ri; ri = ri->next)
4511 {
4512 if (BGP_INFO_HOLDDOWN (ri))
4513 continue;
4514
4515 if (del && ri == del)
4516 continue;
4517
4518 if (! rinew && first)
4519 {
4520 nexthop = ri->attr->nexthop;
4521 med = ri->attr->med;
4522 first = 0;
4523 }
4524
4525#ifdef AGGREGATE_NEXTHOP_CHECK
4526 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4527 || ri->attr->med != med)
4528 {
4529 if (aspath)
4530 aspath_free (aspath);
4531 if (community)
4532 community_free (community);
4533 bgp_unlock_node (rn);
4534 bgp_unlock_node (top);
4535 return;
4536 }
4537#endif /* AGGREGATE_NEXTHOP_CHECK */
4538
4539 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4540 {
4541 if (aggregate->summary_only)
4542 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004543 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004544 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004545 match++;
4546 }
4547
4548 aggregate->count++;
4549
4550 if (aggregate->as_set)
4551 {
4552 if (origin < ri->attr->origin)
4553 origin = ri->attr->origin;
4554
4555 if (aspath)
4556 {
4557 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4558 aspath_free (aspath);
4559 aspath = asmerge;
4560 }
4561 else
4562 aspath = aspath_dup (ri->attr->aspath);
4563
4564 if (ri->attr->community)
4565 {
4566 if (community)
4567 {
4568 commerge = community_merge (community,
4569 ri->attr->community);
4570 community = community_uniq_sort (commerge);
4571 community_free (commerge);
4572 }
4573 else
4574 community = community_dup (ri->attr->community);
4575 }
4576 }
4577 }
4578 }
4579 if (match)
4580 bgp_process (bgp, rn, afi, safi);
4581 }
4582 bgp_unlock_node (top);
4583
4584 if (rinew)
4585 {
4586 aggregate->count++;
4587
4588 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004589 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004590
4591 if (aggregate->as_set)
4592 {
4593 if (origin < rinew->attr->origin)
4594 origin = rinew->attr->origin;
4595
4596 if (aspath)
4597 {
4598 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4599 aspath_free (aspath);
4600 aspath = asmerge;
4601 }
4602 else
4603 aspath = aspath_dup (rinew->attr->aspath);
4604
4605 if (rinew->attr->community)
4606 {
4607 if (community)
4608 {
4609 commerge = community_merge (community,
4610 rinew->attr->community);
4611 community = community_uniq_sort (commerge);
4612 community_free (commerge);
4613 }
4614 else
4615 community = community_dup (rinew->attr->community);
4616 }
4617 }
4618 }
4619
4620 if (aggregate->count > 0)
4621 {
4622 rn = bgp_node_get (table, p);
4623 new = bgp_info_new ();
4624 new->type = ZEBRA_ROUTE_BGP;
4625 new->sub_type = BGP_ROUTE_AGGREGATE;
4626 new->peer = bgp->peer_self;
4627 SET_FLAG (new->flags, BGP_INFO_VALID);
4628 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004629 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004630
4631 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004632 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004633 bgp_process (bgp, rn, afi, safi);
4634 }
4635 else
4636 {
4637 if (aspath)
4638 aspath_free (aspath);
4639 if (community)
4640 community_free (community);
4641 }
4642}
4643
4644void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4645 struct bgp_aggregate *);
4646
4647void
4648bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4649 struct bgp_info *ri, afi_t afi, safi_t safi)
4650{
4651 struct bgp_node *child;
4652 struct bgp_node *rn;
4653 struct bgp_aggregate *aggregate;
4654
4655 /* MPLS-VPN aggregation is not yet supported. */
4656 if (safi == SAFI_MPLS_VPN)
4657 return;
4658
4659 if (p->prefixlen == 0)
4660 return;
4661
4662 if (BGP_INFO_HOLDDOWN (ri))
4663 return;
4664
4665 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4666
4667 /* Aggregate address configuration check. */
4668 for (rn = child; rn; rn = rn->parent)
4669 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4670 {
4671 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004672 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004673 }
4674 bgp_unlock_node (child);
4675}
4676
4677void
4678bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4679 struct bgp_info *del, afi_t afi, safi_t safi)
4680{
4681 struct bgp_node *child;
4682 struct bgp_node *rn;
4683 struct bgp_aggregate *aggregate;
4684
4685 /* MPLS-VPN aggregation is not yet supported. */
4686 if (safi == SAFI_MPLS_VPN)
4687 return;
4688
4689 if (p->prefixlen == 0)
4690 return;
4691
4692 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4693
4694 /* Aggregate address configuration check. */
4695 for (rn = child; rn; rn = rn->parent)
4696 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4697 {
4698 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004699 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004700 }
4701 bgp_unlock_node (child);
4702}
4703
paul94f2b392005-06-28 12:44:16 +00004704static void
paul718e3742002-12-13 20:15:29 +00004705bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4706 struct bgp_aggregate *aggregate)
4707{
4708 struct bgp_table *table;
4709 struct bgp_node *top;
4710 struct bgp_node *rn;
4711 struct bgp_info *new;
4712 struct bgp_info *ri;
4713 unsigned long match;
4714 u_char origin = BGP_ORIGIN_IGP;
4715 struct aspath *aspath = NULL;
4716 struct aspath *asmerge = NULL;
4717 struct community *community = NULL;
4718 struct community *commerge = NULL;
4719
4720 table = bgp->rib[afi][safi];
4721
4722 /* Sanity check. */
4723 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4724 return;
4725 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4726 return;
4727
4728 /* If routes exists below this node, generate aggregate routes. */
4729 top = bgp_node_get (table, p);
4730 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4731 if (rn->p.prefixlen > p->prefixlen)
4732 {
4733 match = 0;
4734
4735 for (ri = rn->info; ri; ri = ri->next)
4736 {
4737 if (BGP_INFO_HOLDDOWN (ri))
4738 continue;
4739
4740 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4741 {
4742 /* summary-only aggregate route suppress aggregated
4743 route announcement. */
4744 if (aggregate->summary_only)
4745 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004746 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004747 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004748 match++;
4749 }
4750 /* as-set aggregate route generate origin, as path,
4751 community aggregation. */
4752 if (aggregate->as_set)
4753 {
4754 if (origin < ri->attr->origin)
4755 origin = ri->attr->origin;
4756
4757 if (aspath)
4758 {
4759 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4760 aspath_free (aspath);
4761 aspath = asmerge;
4762 }
4763 else
4764 aspath = aspath_dup (ri->attr->aspath);
4765
4766 if (ri->attr->community)
4767 {
4768 if (community)
4769 {
4770 commerge = community_merge (community,
4771 ri->attr->community);
4772 community = community_uniq_sort (commerge);
4773 community_free (commerge);
4774 }
4775 else
4776 community = community_dup (ri->attr->community);
4777 }
4778 }
4779 aggregate->count++;
4780 }
4781 }
4782
4783 /* If this node is suppressed, process the change. */
4784 if (match)
4785 bgp_process (bgp, rn, afi, safi);
4786 }
4787 bgp_unlock_node (top);
4788
4789 /* Add aggregate route to BGP table. */
4790 if (aggregate->count)
4791 {
4792 rn = bgp_node_get (table, p);
4793
4794 new = bgp_info_new ();
4795 new->type = ZEBRA_ROUTE_BGP;
4796 new->sub_type = BGP_ROUTE_AGGREGATE;
4797 new->peer = bgp->peer_self;
4798 SET_FLAG (new->flags, BGP_INFO_VALID);
4799 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004800 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004801
4802 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004803 bgp_unlock_node (rn);
4804
paul718e3742002-12-13 20:15:29 +00004805 /* Process change. */
4806 bgp_process (bgp, rn, afi, safi);
4807 }
4808}
4809
4810void
4811bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4812 safi_t safi, struct bgp_aggregate *aggregate)
4813{
4814 struct bgp_table *table;
4815 struct bgp_node *top;
4816 struct bgp_node *rn;
4817 struct bgp_info *ri;
4818 unsigned long match;
4819
4820 table = bgp->rib[afi][safi];
4821
4822 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4823 return;
4824 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4825 return;
4826
4827 /* If routes exists below this node, generate aggregate routes. */
4828 top = bgp_node_get (table, p);
4829 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4830 if (rn->p.prefixlen > p->prefixlen)
4831 {
4832 match = 0;
4833
4834 for (ri = rn->info; ri; ri = ri->next)
4835 {
4836 if (BGP_INFO_HOLDDOWN (ri))
4837 continue;
4838
4839 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4840 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004841 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004842 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004843 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004844
Paul Jakmafb982c22007-05-04 20:15:47 +00004845 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004846 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004847 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004848 match++;
4849 }
4850 }
4851 aggregate->count--;
4852 }
4853 }
4854
Paul Jakmafb982c22007-05-04 20:15:47 +00004855 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004856 if (match)
4857 bgp_process (bgp, rn, afi, safi);
4858 }
4859 bgp_unlock_node (top);
4860
4861 /* Delete aggregate route from BGP table. */
4862 rn = bgp_node_get (table, p);
4863
4864 for (ri = rn->info; ri; ri = ri->next)
4865 if (ri->peer == bgp->peer_self
4866 && ri->type == ZEBRA_ROUTE_BGP
4867 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4868 break;
4869
4870 /* Withdraw static BGP route from routing table. */
4871 if (ri)
4872 {
paul718e3742002-12-13 20:15:29 +00004873 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004874 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004875 }
4876
4877 /* Unlock bgp_node_lookup. */
4878 bgp_unlock_node (rn);
4879}
4880
4881/* Aggregate route attribute. */
4882#define AGGREGATE_SUMMARY_ONLY 1
4883#define AGGREGATE_AS_SET 1
4884
paul94f2b392005-06-28 12:44:16 +00004885static int
Robert Baysf6269b42010-08-05 10:26:28 -07004886bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4887 afi_t afi, safi_t safi)
4888{
4889 int ret;
4890 struct prefix p;
4891 struct bgp_node *rn;
4892 struct bgp *bgp;
4893 struct bgp_aggregate *aggregate;
4894
4895 /* Convert string to prefix structure. */
4896 ret = str2prefix (prefix_str, &p);
4897 if (!ret)
4898 {
4899 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4900 return CMD_WARNING;
4901 }
4902 apply_mask (&p);
4903
4904 /* Get BGP structure. */
4905 bgp = vty->index;
4906
4907 /* Old configuration check. */
4908 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4909 if (! rn)
4910 {
4911 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4912 VTY_NEWLINE);
4913 return CMD_WARNING;
4914 }
4915
4916 aggregate = rn->info;
4917 if (aggregate->safi & SAFI_UNICAST)
4918 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4919 if (aggregate->safi & SAFI_MULTICAST)
4920 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4921
4922 /* Unlock aggregate address configuration. */
4923 rn->info = NULL;
4924 bgp_aggregate_free (aggregate);
4925 bgp_unlock_node (rn);
4926 bgp_unlock_node (rn);
4927
4928 return CMD_SUCCESS;
4929}
4930
4931static int
4932bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004933 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004934 u_char summary_only, u_char as_set)
4935{
4936 int ret;
4937 struct prefix p;
4938 struct bgp_node *rn;
4939 struct bgp *bgp;
4940 struct bgp_aggregate *aggregate;
4941
4942 /* Convert string to prefix structure. */
4943 ret = str2prefix (prefix_str, &p);
4944 if (!ret)
4945 {
4946 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4947 return CMD_WARNING;
4948 }
4949 apply_mask (&p);
4950
4951 /* Get BGP structure. */
4952 bgp = vty->index;
4953
4954 /* Old configuration check. */
4955 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4956
4957 if (rn->info)
4958 {
4959 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004960 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004961 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4962 if (ret)
4963 {
Robert Bays368473f2010-08-05 10:26:29 -07004964 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4965 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004966 return CMD_WARNING;
4967 }
paul718e3742002-12-13 20:15:29 +00004968 }
4969
4970 /* Make aggregate address structure. */
4971 aggregate = bgp_aggregate_new ();
4972 aggregate->summary_only = summary_only;
4973 aggregate->as_set = as_set;
4974 aggregate->safi = safi;
4975 rn->info = aggregate;
4976
4977 /* Aggregate address insert into BGP routing table. */
4978 if (safi & SAFI_UNICAST)
4979 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4980 if (safi & SAFI_MULTICAST)
4981 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4982
4983 return CMD_SUCCESS;
4984}
4985
paul718e3742002-12-13 20:15:29 +00004986DEFUN (aggregate_address,
4987 aggregate_address_cmd,
4988 "aggregate-address A.B.C.D/M",
4989 "Configure BGP aggregate entries\n"
4990 "Aggregate prefix\n")
4991{
4992 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4993}
4994
4995DEFUN (aggregate_address_mask,
4996 aggregate_address_mask_cmd,
4997 "aggregate-address A.B.C.D A.B.C.D",
4998 "Configure BGP aggregate entries\n"
4999 "Aggregate address\n"
5000 "Aggregate mask\n")
5001{
5002 int ret;
5003 char prefix_str[BUFSIZ];
5004
5005 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5006
5007 if (! ret)
5008 {
5009 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5010 return CMD_WARNING;
5011 }
5012
5013 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5014 0, 0);
5015}
5016
5017DEFUN (aggregate_address_summary_only,
5018 aggregate_address_summary_only_cmd,
5019 "aggregate-address A.B.C.D/M summary-only",
5020 "Configure BGP aggregate entries\n"
5021 "Aggregate prefix\n"
5022 "Filter more specific routes from updates\n")
5023{
5024 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5025 AGGREGATE_SUMMARY_ONLY, 0);
5026}
5027
5028DEFUN (aggregate_address_mask_summary_only,
5029 aggregate_address_mask_summary_only_cmd,
5030 "aggregate-address A.B.C.D A.B.C.D summary-only",
5031 "Configure BGP aggregate entries\n"
5032 "Aggregate address\n"
5033 "Aggregate mask\n"
5034 "Filter more specific routes from updates\n")
5035{
5036 int ret;
5037 char prefix_str[BUFSIZ];
5038
5039 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5040
5041 if (! ret)
5042 {
5043 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5044 return CMD_WARNING;
5045 }
5046
5047 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5048 AGGREGATE_SUMMARY_ONLY, 0);
5049}
5050
5051DEFUN (aggregate_address_as_set,
5052 aggregate_address_as_set_cmd,
5053 "aggregate-address A.B.C.D/M as-set",
5054 "Configure BGP aggregate entries\n"
5055 "Aggregate prefix\n"
5056 "Generate AS set path information\n")
5057{
5058 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5059 0, AGGREGATE_AS_SET);
5060}
5061
5062DEFUN (aggregate_address_mask_as_set,
5063 aggregate_address_mask_as_set_cmd,
5064 "aggregate-address A.B.C.D A.B.C.D as-set",
5065 "Configure BGP aggregate entries\n"
5066 "Aggregate address\n"
5067 "Aggregate mask\n"
5068 "Generate AS set path information\n")
5069{
5070 int ret;
5071 char prefix_str[BUFSIZ];
5072
5073 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5074
5075 if (! ret)
5076 {
5077 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5078 return CMD_WARNING;
5079 }
5080
5081 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5082 0, AGGREGATE_AS_SET);
5083}
5084
5085
5086DEFUN (aggregate_address_as_set_summary,
5087 aggregate_address_as_set_summary_cmd,
5088 "aggregate-address A.B.C.D/M as-set summary-only",
5089 "Configure BGP aggregate entries\n"
5090 "Aggregate prefix\n"
5091 "Generate AS set path information\n"
5092 "Filter more specific routes from updates\n")
5093{
5094 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5095 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5096}
5097
5098ALIAS (aggregate_address_as_set_summary,
5099 aggregate_address_summary_as_set_cmd,
5100 "aggregate-address A.B.C.D/M summary-only as-set",
5101 "Configure BGP aggregate entries\n"
5102 "Aggregate prefix\n"
5103 "Filter more specific routes from updates\n"
5104 "Generate AS set path information\n")
5105
5106DEFUN (aggregate_address_mask_as_set_summary,
5107 aggregate_address_mask_as_set_summary_cmd,
5108 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5109 "Configure BGP aggregate entries\n"
5110 "Aggregate address\n"
5111 "Aggregate mask\n"
5112 "Generate AS set path information\n"
5113 "Filter more specific routes from updates\n")
5114{
5115 int ret;
5116 char prefix_str[BUFSIZ];
5117
5118 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5119
5120 if (! ret)
5121 {
5122 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5123 return CMD_WARNING;
5124 }
5125
5126 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5127 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5128}
5129
5130ALIAS (aggregate_address_mask_as_set_summary,
5131 aggregate_address_mask_summary_as_set_cmd,
5132 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5133 "Configure BGP aggregate entries\n"
5134 "Aggregate address\n"
5135 "Aggregate mask\n"
5136 "Filter more specific routes from updates\n"
5137 "Generate AS set path information\n")
5138
5139DEFUN (no_aggregate_address,
5140 no_aggregate_address_cmd,
5141 "no aggregate-address A.B.C.D/M",
5142 NO_STR
5143 "Configure BGP aggregate entries\n"
5144 "Aggregate prefix\n")
5145{
5146 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5147}
5148
5149ALIAS (no_aggregate_address,
5150 no_aggregate_address_summary_only_cmd,
5151 "no aggregate-address A.B.C.D/M summary-only",
5152 NO_STR
5153 "Configure BGP aggregate entries\n"
5154 "Aggregate prefix\n"
5155 "Filter more specific routes from updates\n")
5156
5157ALIAS (no_aggregate_address,
5158 no_aggregate_address_as_set_cmd,
5159 "no aggregate-address A.B.C.D/M as-set",
5160 NO_STR
5161 "Configure BGP aggregate entries\n"
5162 "Aggregate prefix\n"
5163 "Generate AS set path information\n")
5164
5165ALIAS (no_aggregate_address,
5166 no_aggregate_address_as_set_summary_cmd,
5167 "no aggregate-address A.B.C.D/M as-set summary-only",
5168 NO_STR
5169 "Configure BGP aggregate entries\n"
5170 "Aggregate prefix\n"
5171 "Generate AS set path information\n"
5172 "Filter more specific routes from updates\n")
5173
5174ALIAS (no_aggregate_address,
5175 no_aggregate_address_summary_as_set_cmd,
5176 "no aggregate-address A.B.C.D/M summary-only as-set",
5177 NO_STR
5178 "Configure BGP aggregate entries\n"
5179 "Aggregate prefix\n"
5180 "Filter more specific routes from updates\n"
5181 "Generate AS set path information\n")
5182
5183DEFUN (no_aggregate_address_mask,
5184 no_aggregate_address_mask_cmd,
5185 "no aggregate-address A.B.C.D A.B.C.D",
5186 NO_STR
5187 "Configure BGP aggregate entries\n"
5188 "Aggregate address\n"
5189 "Aggregate mask\n")
5190{
5191 int ret;
5192 char prefix_str[BUFSIZ];
5193
5194 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5195
5196 if (! ret)
5197 {
5198 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5199 return CMD_WARNING;
5200 }
5201
5202 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5203}
5204
5205ALIAS (no_aggregate_address_mask,
5206 no_aggregate_address_mask_summary_only_cmd,
5207 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5208 NO_STR
5209 "Configure BGP aggregate entries\n"
5210 "Aggregate address\n"
5211 "Aggregate mask\n"
5212 "Filter more specific routes from updates\n")
5213
5214ALIAS (no_aggregate_address_mask,
5215 no_aggregate_address_mask_as_set_cmd,
5216 "no aggregate-address A.B.C.D A.B.C.D as-set",
5217 NO_STR
5218 "Configure BGP aggregate entries\n"
5219 "Aggregate address\n"
5220 "Aggregate mask\n"
5221 "Generate AS set path information\n")
5222
5223ALIAS (no_aggregate_address_mask,
5224 no_aggregate_address_mask_as_set_summary_cmd,
5225 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5226 NO_STR
5227 "Configure BGP aggregate entries\n"
5228 "Aggregate address\n"
5229 "Aggregate mask\n"
5230 "Generate AS set path information\n"
5231 "Filter more specific routes from updates\n")
5232
5233ALIAS (no_aggregate_address_mask,
5234 no_aggregate_address_mask_summary_as_set_cmd,
5235 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5236 NO_STR
5237 "Configure BGP aggregate entries\n"
5238 "Aggregate address\n"
5239 "Aggregate mask\n"
5240 "Filter more specific routes from updates\n"
5241 "Generate AS set path information\n")
5242
5243#ifdef HAVE_IPV6
5244DEFUN (ipv6_aggregate_address,
5245 ipv6_aggregate_address_cmd,
5246 "aggregate-address X:X::X:X/M",
5247 "Configure BGP aggregate entries\n"
5248 "Aggregate prefix\n")
5249{
5250 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5251}
5252
5253DEFUN (ipv6_aggregate_address_summary_only,
5254 ipv6_aggregate_address_summary_only_cmd,
5255 "aggregate-address X:X::X:X/M summary-only",
5256 "Configure BGP aggregate entries\n"
5257 "Aggregate prefix\n"
5258 "Filter more specific routes from updates\n")
5259{
5260 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5261 AGGREGATE_SUMMARY_ONLY, 0);
5262}
5263
5264DEFUN (no_ipv6_aggregate_address,
5265 no_ipv6_aggregate_address_cmd,
5266 "no aggregate-address X:X::X:X/M",
5267 NO_STR
5268 "Configure BGP aggregate entries\n"
5269 "Aggregate prefix\n")
5270{
5271 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5272}
5273
5274DEFUN (no_ipv6_aggregate_address_summary_only,
5275 no_ipv6_aggregate_address_summary_only_cmd,
5276 "no aggregate-address X:X::X:X/M summary-only",
5277 NO_STR
5278 "Configure BGP aggregate entries\n"
5279 "Aggregate prefix\n"
5280 "Filter more specific routes from updates\n")
5281{
5282 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5283}
5284
5285ALIAS (ipv6_aggregate_address,
5286 old_ipv6_aggregate_address_cmd,
5287 "ipv6 bgp aggregate-address X:X::X:X/M",
5288 IPV6_STR
5289 BGP_STR
5290 "Configure BGP aggregate entries\n"
5291 "Aggregate prefix\n")
5292
5293ALIAS (ipv6_aggregate_address_summary_only,
5294 old_ipv6_aggregate_address_summary_only_cmd,
5295 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5296 IPV6_STR
5297 BGP_STR
5298 "Configure BGP aggregate entries\n"
5299 "Aggregate prefix\n"
5300 "Filter more specific routes from updates\n")
5301
5302ALIAS (no_ipv6_aggregate_address,
5303 old_no_ipv6_aggregate_address_cmd,
5304 "no ipv6 bgp aggregate-address X:X::X:X/M",
5305 NO_STR
5306 IPV6_STR
5307 BGP_STR
5308 "Configure BGP aggregate entries\n"
5309 "Aggregate prefix\n")
5310
5311ALIAS (no_ipv6_aggregate_address_summary_only,
5312 old_no_ipv6_aggregate_address_summary_only_cmd,
5313 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5314 NO_STR
5315 IPV6_STR
5316 BGP_STR
5317 "Configure BGP aggregate entries\n"
5318 "Aggregate prefix\n"
5319 "Filter more specific routes from updates\n")
5320#endif /* HAVE_IPV6 */
5321
5322/* Redistribute route treatment. */
5323void
5324bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5325 u_int32_t metric, u_char type)
5326{
5327 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005328 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005329 struct bgp_info *new;
5330 struct bgp_info *bi;
5331 struct bgp_info info;
5332 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005333 struct attr attr = { 0 };
5334 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005335 struct attr *new_attr;
5336 afi_t afi;
5337 int ret;
5338
5339 /* Make default attribute. */
5340 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5341 if (nexthop)
5342 attr.nexthop = *nexthop;
5343
5344 attr.med = metric;
5345 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5346
paul1eb8ef22005-04-07 07:30:20 +00005347 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005348 {
5349 afi = family2afi (p->family);
5350
5351 if (bgp->redist[afi][type])
5352 {
5353 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005354 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005355
5356 if (bgp->redist_metric_flag[afi][type])
5357 attr_new.med = bgp->redist_metric[afi][type];
5358
5359 /* Apply route-map. */
5360 if (bgp->rmap[afi][type].map)
5361 {
5362 info.peer = bgp->peer_self;
5363 info.attr = &attr_new;
5364
paulfee0f4c2004-09-13 05:12:46 +00005365 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5366
paul718e3742002-12-13 20:15:29 +00005367 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5368 &info);
paulfee0f4c2004-09-13 05:12:46 +00005369
5370 bgp->peer_self->rmap_type = 0;
5371
paul718e3742002-12-13 20:15:29 +00005372 if (ret == RMAP_DENYMATCH)
5373 {
5374 /* Free uninterned attribute. */
5375 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005376 bgp_attr_extra_free (&attr_new);
5377
paul718e3742002-12-13 20:15:29 +00005378 /* Unintern original. */
5379 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005380 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005381 bgp_redistribute_delete (p, type);
5382 return;
5383 }
5384 }
5385
Paul Jakmafb982c22007-05-04 20:15:47 +00005386 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5387 afi, SAFI_UNICAST, p, NULL);
5388
paul718e3742002-12-13 20:15:29 +00005389 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005390 bgp_attr_extra_free (&attr_new);
5391
paul718e3742002-12-13 20:15:29 +00005392 for (bi = bn->info; bi; bi = bi->next)
5393 if (bi->peer == bgp->peer_self
5394 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5395 break;
5396
5397 if (bi)
5398 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005399 if (attrhash_cmp (bi->attr, new_attr) &&
5400 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005401 {
5402 bgp_attr_unintern (new_attr);
5403 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005404 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005405 bgp_unlock_node (bn);
5406 return;
5407 }
5408 else
5409 {
5410 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005411 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005412
5413 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005414 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5415 bgp_info_restore(bn, bi);
5416 else
5417 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005418 bgp_attr_unintern (bi->attr);
5419 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005420 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005421
5422 /* Process change. */
5423 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5424 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5425 bgp_unlock_node (bn);
5426 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005427 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005428 return;
5429 }
5430 }
5431
5432 new = bgp_info_new ();
5433 new->type = type;
5434 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5435 new->peer = bgp->peer_self;
5436 SET_FLAG (new->flags, BGP_INFO_VALID);
5437 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005438 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005439
5440 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5441 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005442 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005443 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5444 }
5445 }
5446
5447 /* Unintern original. */
5448 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005449 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005450}
5451
5452void
5453bgp_redistribute_delete (struct prefix *p, u_char type)
5454{
5455 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005456 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005457 afi_t afi;
5458 struct bgp_node *rn;
5459 struct bgp_info *ri;
5460
paul1eb8ef22005-04-07 07:30:20 +00005461 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005462 {
5463 afi = family2afi (p->family);
5464
5465 if (bgp->redist[afi][type])
5466 {
paulfee0f4c2004-09-13 05:12:46 +00005467 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005468
5469 for (ri = rn->info; ri; ri = ri->next)
5470 if (ri->peer == bgp->peer_self
5471 && ri->type == type)
5472 break;
5473
5474 if (ri)
5475 {
5476 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005477 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005478 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005479 }
5480 bgp_unlock_node (rn);
5481 }
5482 }
5483}
5484
5485/* Withdraw specified route type's route. */
5486void
5487bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5488{
5489 struct bgp_node *rn;
5490 struct bgp_info *ri;
5491 struct bgp_table *table;
5492
5493 table = bgp->rib[afi][SAFI_UNICAST];
5494
5495 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5496 {
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, &rn->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 }
5509}
5510
5511/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005512static void
paul718e3742002-12-13 20:15:29 +00005513route_vty_out_route (struct prefix *p, struct vty *vty)
5514{
5515 int len;
5516 u_int32_t destination;
5517 char buf[BUFSIZ];
5518
5519 if (p->family == AF_INET)
5520 {
5521 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5522 destination = ntohl (p->u.prefix4.s_addr);
5523
5524 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5525 || (IN_CLASSB (destination) && p->prefixlen == 16)
5526 || (IN_CLASSA (destination) && p->prefixlen == 8)
5527 || p->u.prefix4.s_addr == 0)
5528 {
5529 /* When mask is natural, mask is not displayed. */
5530 }
5531 else
5532 len += vty_out (vty, "/%d", p->prefixlen);
5533 }
5534 else
5535 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5536 p->prefixlen);
5537
5538 len = 17 - len;
5539 if (len < 1)
5540 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5541 else
5542 vty_out (vty, "%*s", len, " ");
5543}
5544
paul718e3742002-12-13 20:15:29 +00005545enum bgp_display_type
5546{
5547 normal_list,
5548};
5549
paulb40d9392005-08-22 22:34:41 +00005550/* Print the short form route status for a bgp_info */
5551static void
5552route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005553{
paulb40d9392005-08-22 22:34:41 +00005554 /* Route status display. */
5555 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5556 vty_out (vty, "R");
5557 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005558 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005559 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005560 vty_out (vty, "s");
5561 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5562 vty_out (vty, "*");
5563 else
5564 vty_out (vty, " ");
5565
5566 /* Selected */
5567 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5568 vty_out (vty, "h");
5569 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5570 vty_out (vty, "d");
5571 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5572 vty_out (vty, ">");
5573 else
5574 vty_out (vty, " ");
5575
5576 /* Internal route. */
5577 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5578 vty_out (vty, "i");
5579 else
paulb40d9392005-08-22 22:34:41 +00005580 vty_out (vty, " ");
5581}
5582
5583/* called from terminal list command */
5584void
5585route_vty_out (struct vty *vty, struct prefix *p,
5586 struct bgp_info *binfo, int display, safi_t safi)
5587{
5588 struct attr *attr;
5589
5590 /* short status lead text */
5591 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005592
5593 /* print prefix and mask */
5594 if (! display)
5595 route_vty_out_route (p, vty);
5596 else
5597 vty_out (vty, "%*s", 17, " ");
5598
5599 /* Print attribute */
5600 attr = binfo->attr;
5601 if (attr)
5602 {
5603 if (p->family == AF_INET)
5604 {
5605 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005606 vty_out (vty, "%-16s",
5607 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005608 else
5609 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5610 }
5611#ifdef HAVE_IPV6
5612 else if (p->family == AF_INET6)
5613 {
5614 int len;
5615 char buf[BUFSIZ];
5616
5617 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005618 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5619 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005620 len = 16 - len;
5621 if (len < 1)
5622 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5623 else
5624 vty_out (vty, "%*s", len, " ");
5625 }
5626#endif /* HAVE_IPV6 */
5627
5628 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005629 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005630 else
5631 vty_out (vty, " ");
5632
5633 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005634 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005635 else
5636 vty_out (vty, " ");
5637
Paul Jakmafb982c22007-05-04 20:15:47 +00005638 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005639
Paul Jakmab2518c12006-05-12 23:48:40 +00005640 /* Print aspath */
5641 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005642 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005643
Paul Jakmab2518c12006-05-12 23:48:40 +00005644 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005645 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005646 }
paul718e3742002-12-13 20:15:29 +00005647 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005648}
5649
5650/* called from terminal list command */
5651void
5652route_vty_out_tmp (struct vty *vty, struct prefix *p,
5653 struct attr *attr, safi_t safi)
5654{
5655 /* Route status display. */
5656 vty_out (vty, "*");
5657 vty_out (vty, ">");
5658 vty_out (vty, " ");
5659
5660 /* print prefix and mask */
5661 route_vty_out_route (p, vty);
5662
5663 /* Print attribute */
5664 if (attr)
5665 {
5666 if (p->family == AF_INET)
5667 {
5668 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005669 vty_out (vty, "%-16s",
5670 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005671 else
5672 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5673 }
5674#ifdef HAVE_IPV6
5675 else if (p->family == AF_INET6)
5676 {
5677 int len;
5678 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005679
5680 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005681
5682 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005683 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5684 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005685 len = 16 - len;
5686 if (len < 1)
5687 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5688 else
5689 vty_out (vty, "%*s", len, " ");
5690 }
5691#endif /* HAVE_IPV6 */
5692
5693 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005694 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005695 else
5696 vty_out (vty, " ");
5697
5698 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005699 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005700 else
5701 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005702
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005703 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005704
Paul Jakmab2518c12006-05-12 23:48:40 +00005705 /* Print aspath */
5706 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005707 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005708
Paul Jakmab2518c12006-05-12 23:48:40 +00005709 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005710 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005711 }
paul718e3742002-12-13 20:15:29 +00005712
5713 vty_out (vty, "%s", VTY_NEWLINE);
5714}
5715
ajs5a646652004-11-05 01:25:55 +00005716void
paul718e3742002-12-13 20:15:29 +00005717route_vty_out_tag (struct vty *vty, struct prefix *p,
5718 struct bgp_info *binfo, int display, safi_t safi)
5719{
5720 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005721 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005722
5723 if (!binfo->extra)
5724 return;
5725
paulb40d9392005-08-22 22:34:41 +00005726 /* short status lead text */
5727 route_vty_short_status_out (vty, binfo);
5728
paul718e3742002-12-13 20:15:29 +00005729 /* print prefix and mask */
5730 if (! display)
5731 route_vty_out_route (p, vty);
5732 else
5733 vty_out (vty, "%*s", 17, " ");
5734
5735 /* Print attribute */
5736 attr = binfo->attr;
5737 if (attr)
5738 {
5739 if (p->family == AF_INET)
5740 {
5741 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005742 vty_out (vty, "%-16s",
5743 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005744 else
5745 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5746 }
5747#ifdef HAVE_IPV6
5748 else if (p->family == AF_INET6)
5749 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005750 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005751 char buf[BUFSIZ];
5752 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005753 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005754 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005755 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5756 buf, BUFSIZ));
5757 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005758 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005759 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5760 buf, BUFSIZ),
5761 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5762 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005763
5764 }
5765#endif /* HAVE_IPV6 */
5766 }
5767
Paul Jakmafb982c22007-05-04 20:15:47 +00005768 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005769
5770 vty_out (vty, "notag/%d", label);
5771
5772 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005773}
5774
5775/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005776static void
paul718e3742002-12-13 20:15:29 +00005777damp_route_vty_out (struct vty *vty, struct prefix *p,
5778 struct bgp_info *binfo, int display, safi_t safi)
5779{
5780 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005781 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005782 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005783
paulb40d9392005-08-22 22:34:41 +00005784 /* short status lead text */
5785 route_vty_short_status_out (vty, binfo);
5786
paul718e3742002-12-13 20:15:29 +00005787 /* print prefix and mask */
5788 if (! display)
5789 route_vty_out_route (p, vty);
5790 else
5791 vty_out (vty, "%*s", 17, " ");
5792
5793 len = vty_out (vty, "%s", binfo->peer->host);
5794 len = 17 - len;
5795 if (len < 1)
5796 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5797 else
5798 vty_out (vty, "%*s", len, " ");
5799
Chris Caputo50aef6f2009-06-23 06:06:49 +00005800 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005801
5802 /* Print attribute */
5803 attr = binfo->attr;
5804 if (attr)
5805 {
5806 /* Print aspath */
5807 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005808 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005809
5810 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005811 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005812 }
5813 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005814}
5815
paul718e3742002-12-13 20:15:29 +00005816/* flap route */
ajs5a646652004-11-05 01:25:55 +00005817static void
paul718e3742002-12-13 20:15:29 +00005818flap_route_vty_out (struct vty *vty, struct prefix *p,
5819 struct bgp_info *binfo, int display, safi_t safi)
5820{
5821 struct attr *attr;
5822 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005823 char timebuf[BGP_UPTIME_LEN];
5824 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005825
5826 if (!binfo->extra)
5827 return;
5828
5829 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005830
paulb40d9392005-08-22 22:34:41 +00005831 /* short status lead text */
5832 route_vty_short_status_out (vty, binfo);
5833
paul718e3742002-12-13 20:15:29 +00005834 /* print prefix and mask */
5835 if (! display)
5836 route_vty_out_route (p, vty);
5837 else
5838 vty_out (vty, "%*s", 17, " ");
5839
5840 len = vty_out (vty, "%s", binfo->peer->host);
5841 len = 16 - len;
5842 if (len < 1)
5843 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5844 else
5845 vty_out (vty, "%*s", len, " ");
5846
5847 len = vty_out (vty, "%d", bdi->flap);
5848 len = 5 - len;
5849 if (len < 1)
5850 vty_out (vty, " ");
5851 else
5852 vty_out (vty, "%*s ", len, " ");
5853
5854 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5855 timebuf, BGP_UPTIME_LEN));
5856
5857 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5858 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005859 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005860 else
5861 vty_out (vty, "%*s ", 8, " ");
5862
5863 /* Print attribute */
5864 attr = binfo->attr;
5865 if (attr)
5866 {
5867 /* Print aspath */
5868 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005869 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005870
5871 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005872 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005873 }
5874 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005875}
5876
paul94f2b392005-06-28 12:44:16 +00005877static void
paul718e3742002-12-13 20:15:29 +00005878route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5879 struct bgp_info *binfo, afi_t afi, safi_t safi)
5880{
5881 char buf[INET6_ADDRSTRLEN];
5882 char buf1[BUFSIZ];
5883 struct attr *attr;
5884 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005885#ifdef HAVE_CLOCK_MONOTONIC
5886 time_t tbuf;
5887#endif
paul718e3742002-12-13 20:15:29 +00005888
5889 attr = binfo->attr;
5890
5891 if (attr)
5892 {
5893 /* Line1 display AS-path, Aggregator */
5894 if (attr->aspath)
5895 {
5896 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005897 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005898 vty_out (vty, "Local");
5899 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005900 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005901 }
5902
paulb40d9392005-08-22 22:34:41 +00005903 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5904 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005905 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5906 vty_out (vty, ", (stale)");
5907 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005908 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005909 attr->extra->aggregator_as,
5910 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005911 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5912 vty_out (vty, ", (Received from a RR-client)");
5913 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5914 vty_out (vty, ", (Received from a RS-client)");
5915 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5916 vty_out (vty, ", (history entry)");
5917 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5918 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005919 vty_out (vty, "%s", VTY_NEWLINE);
5920
5921 /* Line2 display Next-hop, Neighbor, Router-id */
5922 if (p->family == AF_INET)
5923 {
5924 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005925 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005926 inet_ntoa (attr->nexthop));
5927 }
5928#ifdef HAVE_IPV6
5929 else
5930 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005931 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005932 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005933 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005934 buf, INET6_ADDRSTRLEN));
5935 }
5936#endif /* HAVE_IPV6 */
5937
5938 if (binfo->peer == bgp->peer_self)
5939 {
5940 vty_out (vty, " from %s ",
5941 p->family == AF_INET ? "0.0.0.0" : "::");
5942 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5943 }
5944 else
5945 {
5946 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5947 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005948 else if (binfo->extra && binfo->extra->igpmetric)
5949 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005950 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005951 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005952 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005953 else
5954 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5955 }
5956 vty_out (vty, "%s", VTY_NEWLINE);
5957
5958#ifdef HAVE_IPV6
5959 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005960 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005961 {
5962 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005963 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005964 buf, INET6_ADDRSTRLEN),
5965 VTY_NEWLINE);
5966 }
5967#endif /* HAVE_IPV6 */
5968
5969 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5970 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5971
5972 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005973 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005974
5975 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005976 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005977 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005978 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005979
Paul Jakmafb982c22007-05-04 20:15:47 +00005980 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005981 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005982
5983 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5984 vty_out (vty, ", valid");
5985
5986 if (binfo->peer != bgp->peer_self)
5987 {
5988 if (binfo->peer->as == binfo->peer->local_as)
5989 vty_out (vty, ", internal");
5990 else
5991 vty_out (vty, ", %s",
5992 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5993 }
5994 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5995 vty_out (vty, ", aggregated, local");
5996 else if (binfo->type != ZEBRA_ROUTE_BGP)
5997 vty_out (vty, ", sourced");
5998 else
5999 vty_out (vty, ", sourced, local");
6000
6001 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6002 vty_out (vty, ", atomic-aggregate");
6003
Josh Baileyde8d5df2011-07-20 20:46:01 -07006004 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6005 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6006 bgp_info_mpath_count (binfo)))
6007 vty_out (vty, ", multipath");
6008
paul718e3742002-12-13 20:15:29 +00006009 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6010 vty_out (vty, ", best");
6011
6012 vty_out (vty, "%s", VTY_NEWLINE);
6013
6014 /* Line 4 display Community */
6015 if (attr->community)
6016 vty_out (vty, " Community: %s%s", attr->community->str,
6017 VTY_NEWLINE);
6018
6019 /* Line 5 display Extended-community */
6020 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006021 vty_out (vty, " Extended Community: %s%s",
6022 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006023
6024 /* Line 6 display Originator, Cluster-id */
6025 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6026 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6027 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006028 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006029 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006030 vty_out (vty, " Originator: %s",
6031 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006032
6033 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6034 {
6035 int i;
6036 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006037 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6038 vty_out (vty, "%s ",
6039 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006040 }
6041 vty_out (vty, "%s", VTY_NEWLINE);
6042 }
Paul Jakma41367172007-08-06 15:24:51 +00006043
Paul Jakmafb982c22007-05-04 20:15:47 +00006044 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006045 bgp_damp_info_vty (vty, binfo);
6046
6047 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006048#ifdef HAVE_CLOCK_MONOTONIC
6049 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006050 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006051#else
6052 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6053#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006054 }
6055 vty_out (vty, "%s", VTY_NEWLINE);
6056}
6057
paulb40d9392005-08-22 22:34:41 +00006058#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 +00006059#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006060#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6061#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6062#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6063
6064enum bgp_show_type
6065{
6066 bgp_show_type_normal,
6067 bgp_show_type_regexp,
6068 bgp_show_type_prefix_list,
6069 bgp_show_type_filter_list,
6070 bgp_show_type_route_map,
6071 bgp_show_type_neighbor,
6072 bgp_show_type_cidr_only,
6073 bgp_show_type_prefix_longer,
6074 bgp_show_type_community_all,
6075 bgp_show_type_community,
6076 bgp_show_type_community_exact,
6077 bgp_show_type_community_list,
6078 bgp_show_type_community_list_exact,
6079 bgp_show_type_flap_statistics,
6080 bgp_show_type_flap_address,
6081 bgp_show_type_flap_prefix,
6082 bgp_show_type_flap_cidr_only,
6083 bgp_show_type_flap_regexp,
6084 bgp_show_type_flap_filter_list,
6085 bgp_show_type_flap_prefix_list,
6086 bgp_show_type_flap_prefix_longer,
6087 bgp_show_type_flap_route_map,
6088 bgp_show_type_flap_neighbor,
6089 bgp_show_type_dampend_paths,
6090 bgp_show_type_damp_neighbor
6091};
6092
ajs5a646652004-11-05 01:25:55 +00006093static int
paulfee0f4c2004-09-13 05:12:46 +00006094bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006095 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006096{
paul718e3742002-12-13 20:15:29 +00006097 struct bgp_info *ri;
6098 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006099 int header = 1;
paul718e3742002-12-13 20:15:29 +00006100 int display;
ajs5a646652004-11-05 01:25:55 +00006101 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006102
6103 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006104 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006105
paul718e3742002-12-13 20:15:29 +00006106 /* Start processing of routes. */
6107 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6108 if (rn->info != NULL)
6109 {
6110 display = 0;
6111
6112 for (ri = rn->info; ri; ri = ri->next)
6113 {
ajs5a646652004-11-05 01:25:55 +00006114 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006115 || type == bgp_show_type_flap_address
6116 || type == bgp_show_type_flap_prefix
6117 || type == bgp_show_type_flap_cidr_only
6118 || type == bgp_show_type_flap_regexp
6119 || type == bgp_show_type_flap_filter_list
6120 || type == bgp_show_type_flap_prefix_list
6121 || type == bgp_show_type_flap_prefix_longer
6122 || type == bgp_show_type_flap_route_map
6123 || type == bgp_show_type_flap_neighbor
6124 || type == bgp_show_type_dampend_paths
6125 || type == bgp_show_type_damp_neighbor)
6126 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006127 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006128 continue;
6129 }
6130 if (type == bgp_show_type_regexp
6131 || type == bgp_show_type_flap_regexp)
6132 {
ajs5a646652004-11-05 01:25:55 +00006133 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006134
6135 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6136 continue;
6137 }
6138 if (type == bgp_show_type_prefix_list
6139 || type == bgp_show_type_flap_prefix_list)
6140 {
ajs5a646652004-11-05 01:25:55 +00006141 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006142
6143 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6144 continue;
6145 }
6146 if (type == bgp_show_type_filter_list
6147 || type == bgp_show_type_flap_filter_list)
6148 {
ajs5a646652004-11-05 01:25:55 +00006149 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006150
6151 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6152 continue;
6153 }
6154 if (type == bgp_show_type_route_map
6155 || type == bgp_show_type_flap_route_map)
6156 {
ajs5a646652004-11-05 01:25:55 +00006157 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006158 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006159 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006160 int ret;
6161
Paul Jakmafb982c22007-05-04 20:15:47 +00006162 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006163 binfo.peer = ri->peer;
6164 binfo.attr = &dummy_attr;
6165
6166 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006167
6168 bgp_attr_extra_free (&dummy_attr);
6169
paul718e3742002-12-13 20:15:29 +00006170 if (ret == RMAP_DENYMATCH)
6171 continue;
6172 }
6173 if (type == bgp_show_type_neighbor
6174 || type == bgp_show_type_flap_neighbor
6175 || type == bgp_show_type_damp_neighbor)
6176 {
ajs5a646652004-11-05 01:25:55 +00006177 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006178
6179 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6180 continue;
6181 }
6182 if (type == bgp_show_type_cidr_only
6183 || type == bgp_show_type_flap_cidr_only)
6184 {
6185 u_int32_t destination;
6186
6187 destination = ntohl (rn->p.u.prefix4.s_addr);
6188 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6189 continue;
6190 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6191 continue;
6192 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6193 continue;
6194 }
6195 if (type == bgp_show_type_prefix_longer
6196 || type == bgp_show_type_flap_prefix_longer)
6197 {
ajs5a646652004-11-05 01:25:55 +00006198 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006199
6200 if (! prefix_match (p, &rn->p))
6201 continue;
6202 }
6203 if (type == bgp_show_type_community_all)
6204 {
6205 if (! ri->attr->community)
6206 continue;
6207 }
6208 if (type == bgp_show_type_community)
6209 {
ajs5a646652004-11-05 01:25:55 +00006210 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006211
6212 if (! ri->attr->community ||
6213 ! community_match (ri->attr->community, com))
6214 continue;
6215 }
6216 if (type == bgp_show_type_community_exact)
6217 {
ajs5a646652004-11-05 01:25:55 +00006218 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006219
6220 if (! ri->attr->community ||
6221 ! community_cmp (ri->attr->community, com))
6222 continue;
6223 }
6224 if (type == bgp_show_type_community_list)
6225 {
ajs5a646652004-11-05 01:25:55 +00006226 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006227
6228 if (! community_list_match (ri->attr->community, list))
6229 continue;
6230 }
6231 if (type == bgp_show_type_community_list_exact)
6232 {
ajs5a646652004-11-05 01:25:55 +00006233 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006234
6235 if (! community_list_exact_match (ri->attr->community, list))
6236 continue;
6237 }
6238 if (type == bgp_show_type_flap_address
6239 || type == bgp_show_type_flap_prefix)
6240 {
ajs5a646652004-11-05 01:25:55 +00006241 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006242
6243 if (! prefix_match (&rn->p, p))
6244 continue;
6245
6246 if (type == bgp_show_type_flap_prefix)
6247 if (p->prefixlen != rn->p.prefixlen)
6248 continue;
6249 }
6250 if (type == bgp_show_type_dampend_paths
6251 || type == bgp_show_type_damp_neighbor)
6252 {
6253 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6254 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6255 continue;
6256 }
6257
6258 if (header)
6259 {
hasso93406d82005-02-02 14:40:33 +00006260 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6261 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6262 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006263 if (type == bgp_show_type_dampend_paths
6264 || type == bgp_show_type_damp_neighbor)
6265 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6266 else if (type == bgp_show_type_flap_statistics
6267 || type == bgp_show_type_flap_address
6268 || type == bgp_show_type_flap_prefix
6269 || type == bgp_show_type_flap_cidr_only
6270 || type == bgp_show_type_flap_regexp
6271 || type == bgp_show_type_flap_filter_list
6272 || type == bgp_show_type_flap_prefix_list
6273 || type == bgp_show_type_flap_prefix_longer
6274 || type == bgp_show_type_flap_route_map
6275 || type == bgp_show_type_flap_neighbor)
6276 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6277 else
6278 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006279 header = 0;
6280 }
6281
6282 if (type == bgp_show_type_dampend_paths
6283 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006284 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006285 else if (type == bgp_show_type_flap_statistics
6286 || type == bgp_show_type_flap_address
6287 || type == bgp_show_type_flap_prefix
6288 || type == bgp_show_type_flap_cidr_only
6289 || type == bgp_show_type_flap_regexp
6290 || type == bgp_show_type_flap_filter_list
6291 || type == bgp_show_type_flap_prefix_list
6292 || type == bgp_show_type_flap_prefix_longer
6293 || type == bgp_show_type_flap_route_map
6294 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006295 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006296 else
ajs5a646652004-11-05 01:25:55 +00006297 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006298 display++;
6299 }
6300 if (display)
ajs5a646652004-11-05 01:25:55 +00006301 output_count++;
paul718e3742002-12-13 20:15:29 +00006302 }
6303
6304 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006305 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006306 {
6307 if (type == bgp_show_type_normal)
6308 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6309 }
6310 else
6311 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006312 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006313
6314 return CMD_SUCCESS;
6315}
6316
ajs5a646652004-11-05 01:25:55 +00006317static int
paulfee0f4c2004-09-13 05:12:46 +00006318bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006319 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006320{
6321 struct bgp_table *table;
6322
6323 if (bgp == NULL) {
6324 bgp = bgp_get_default ();
6325 }
6326
6327 if (bgp == NULL)
6328 {
6329 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6330 return CMD_WARNING;
6331 }
6332
6333
6334 table = bgp->rib[afi][safi];
6335
ajs5a646652004-11-05 01:25:55 +00006336 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006337}
6338
paul718e3742002-12-13 20:15:29 +00006339/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006340static void
paul718e3742002-12-13 20:15:29 +00006341route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6342 struct bgp_node *rn,
6343 struct prefix_rd *prd, afi_t afi, safi_t safi)
6344{
6345 struct bgp_info *ri;
6346 struct prefix *p;
6347 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006348 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006349 char buf1[INET6_ADDRSTRLEN];
6350 char buf2[INET6_ADDRSTRLEN];
6351 int count = 0;
6352 int best = 0;
6353 int suppress = 0;
6354 int no_export = 0;
6355 int no_advertise = 0;
6356 int local_as = 0;
6357 int first = 0;
6358
6359 p = &rn->p;
6360 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6361 (safi == SAFI_MPLS_VPN ?
6362 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6363 safi == SAFI_MPLS_VPN ? ":" : "",
6364 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6365 p->prefixlen, VTY_NEWLINE);
6366
6367 for (ri = rn->info; ri; ri = ri->next)
6368 {
6369 count++;
6370 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6371 {
6372 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006373 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006374 suppress = 1;
6375 if (ri->attr->community != NULL)
6376 {
6377 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6378 no_advertise = 1;
6379 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6380 no_export = 1;
6381 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6382 local_as = 1;
6383 }
6384 }
6385 }
6386
6387 vty_out (vty, "Paths: (%d available", count);
6388 if (best)
6389 {
6390 vty_out (vty, ", best #%d", best);
6391 if (safi == SAFI_UNICAST)
6392 vty_out (vty, ", table Default-IP-Routing-Table");
6393 }
6394 else
6395 vty_out (vty, ", no best path");
6396 if (no_advertise)
6397 vty_out (vty, ", not advertised to any peer");
6398 else if (no_export)
6399 vty_out (vty, ", not advertised to EBGP peer");
6400 else if (local_as)
6401 vty_out (vty, ", not advertised outside local AS");
6402 if (suppress)
6403 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6404 vty_out (vty, ")%s", VTY_NEWLINE);
6405
6406 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006407 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006408 {
6409 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6410 {
6411 if (! first)
6412 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6413 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6414 first = 1;
6415 }
6416 }
6417 if (! first)
6418 vty_out (vty, " Not advertised to any peer");
6419 vty_out (vty, "%s", VTY_NEWLINE);
6420}
6421
6422/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006423static int
paulfee0f4c2004-09-13 05:12:46 +00006424bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006425 struct bgp_table *rib, const char *ip_str,
6426 afi_t afi, safi_t safi, struct prefix_rd *prd,
6427 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006428{
6429 int ret;
6430 int header;
6431 int display = 0;
6432 struct prefix match;
6433 struct bgp_node *rn;
6434 struct bgp_node *rm;
6435 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006436 struct bgp_table *table;
6437
paul718e3742002-12-13 20:15:29 +00006438 /* Check IP address argument. */
6439 ret = str2prefix (ip_str, &match);
6440 if (! ret)
6441 {
6442 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6443 return CMD_WARNING;
6444 }
6445
6446 match.family = afi2family (afi);
6447
6448 if (safi == SAFI_MPLS_VPN)
6449 {
paulfee0f4c2004-09-13 05:12:46 +00006450 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006451 {
6452 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6453 continue;
6454
6455 if ((table = rn->info) != NULL)
6456 {
6457 header = 1;
6458
6459 if ((rm = bgp_node_match (table, &match)) != NULL)
6460 {
6461 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006462 {
6463 bgp_unlock_node (rm);
6464 continue;
6465 }
paul718e3742002-12-13 20:15:29 +00006466
6467 for (ri = rm->info; ri; ri = ri->next)
6468 {
6469 if (header)
6470 {
6471 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6472 AFI_IP, SAFI_MPLS_VPN);
6473
6474 header = 0;
6475 }
6476 display++;
6477 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6478 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006479
6480 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006481 }
6482 }
6483 }
6484 }
6485 else
6486 {
6487 header = 1;
6488
paulfee0f4c2004-09-13 05:12:46 +00006489 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006490 {
6491 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6492 {
6493 for (ri = rn->info; ri; ri = ri->next)
6494 {
6495 if (header)
6496 {
6497 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6498 header = 0;
6499 }
6500 display++;
6501 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6502 }
6503 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006504
6505 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006506 }
6507 }
6508
6509 if (! display)
6510 {
6511 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6512 return CMD_WARNING;
6513 }
6514
6515 return CMD_SUCCESS;
6516}
6517
paulfee0f4c2004-09-13 05:12:46 +00006518/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006519static int
paulfd79ac92004-10-13 05:06:08 +00006520bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006521 afi_t afi, safi_t safi, struct prefix_rd *prd,
6522 int prefix_check)
6523{
6524 struct bgp *bgp;
6525
6526 /* BGP structure lookup. */
6527 if (view_name)
6528 {
6529 bgp = bgp_lookup_by_name (view_name);
6530 if (bgp == NULL)
6531 {
6532 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6533 return CMD_WARNING;
6534 }
6535 }
6536 else
6537 {
6538 bgp = bgp_get_default ();
6539 if (bgp == NULL)
6540 {
6541 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6542 return CMD_WARNING;
6543 }
6544 }
6545
6546 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6547 afi, safi, prd, prefix_check);
6548}
6549
paul718e3742002-12-13 20:15:29 +00006550/* BGP route print out function. */
6551DEFUN (show_ip_bgp,
6552 show_ip_bgp_cmd,
6553 "show ip bgp",
6554 SHOW_STR
6555 IP_STR
6556 BGP_STR)
6557{
ajs5a646652004-11-05 01:25:55 +00006558 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006559}
6560
6561DEFUN (show_ip_bgp_ipv4,
6562 show_ip_bgp_ipv4_cmd,
6563 "show ip bgp ipv4 (unicast|multicast)",
6564 SHOW_STR
6565 IP_STR
6566 BGP_STR
6567 "Address family\n"
6568 "Address Family modifier\n"
6569 "Address Family modifier\n")
6570{
6571 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006572 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6573 NULL);
paul718e3742002-12-13 20:15:29 +00006574
ajs5a646652004-11-05 01:25:55 +00006575 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006576}
6577
Michael Lambert95cbbd22010-07-23 14:43:04 -04006578ALIAS (show_ip_bgp_ipv4,
6579 show_bgp_ipv4_safi_cmd,
6580 "show bgp ipv4 (unicast|multicast)",
6581 SHOW_STR
6582 BGP_STR
6583 "Address family\n"
6584 "Address Family modifier\n"
6585 "Address Family modifier\n")
6586
paul718e3742002-12-13 20:15:29 +00006587DEFUN (show_ip_bgp_route,
6588 show_ip_bgp_route_cmd,
6589 "show ip bgp A.B.C.D",
6590 SHOW_STR
6591 IP_STR
6592 BGP_STR
6593 "Network in the BGP routing table to display\n")
6594{
6595 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6596}
6597
6598DEFUN (show_ip_bgp_ipv4_route,
6599 show_ip_bgp_ipv4_route_cmd,
6600 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6601 SHOW_STR
6602 IP_STR
6603 BGP_STR
6604 "Address family\n"
6605 "Address Family modifier\n"
6606 "Address Family modifier\n"
6607 "Network in the BGP routing table to display\n")
6608{
6609 if (strncmp (argv[0], "m", 1) == 0)
6610 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6611
6612 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6613}
6614
Michael Lambert95cbbd22010-07-23 14:43:04 -04006615ALIAS (show_ip_bgp_ipv4_route,
6616 show_bgp_ipv4_safi_route_cmd,
6617 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6618 SHOW_STR
6619 BGP_STR
6620 "Address family\n"
6621 "Address Family modifier\n"
6622 "Address Family modifier\n"
6623 "Network in the BGP routing table to display\n")
6624
paul718e3742002-12-13 20:15:29 +00006625DEFUN (show_ip_bgp_vpnv4_all_route,
6626 show_ip_bgp_vpnv4_all_route_cmd,
6627 "show ip bgp vpnv4 all A.B.C.D",
6628 SHOW_STR
6629 IP_STR
6630 BGP_STR
6631 "Display VPNv4 NLRI specific information\n"
6632 "Display information about all VPNv4 NLRIs\n"
6633 "Network in the BGP routing table to display\n")
6634{
6635 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6636}
6637
6638DEFUN (show_ip_bgp_vpnv4_rd_route,
6639 show_ip_bgp_vpnv4_rd_route_cmd,
6640 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6641 SHOW_STR
6642 IP_STR
6643 BGP_STR
6644 "Display VPNv4 NLRI specific information\n"
6645 "Display information for a route distinguisher\n"
6646 "VPN Route Distinguisher\n"
6647 "Network in the BGP routing table to display\n")
6648{
6649 int ret;
6650 struct prefix_rd prd;
6651
6652 ret = str2prefix_rd (argv[0], &prd);
6653 if (! ret)
6654 {
6655 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6656 return CMD_WARNING;
6657 }
6658 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6659}
6660
6661DEFUN (show_ip_bgp_prefix,
6662 show_ip_bgp_prefix_cmd,
6663 "show ip bgp A.B.C.D/M",
6664 SHOW_STR
6665 IP_STR
6666 BGP_STR
6667 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6668{
6669 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6670}
6671
6672DEFUN (show_ip_bgp_ipv4_prefix,
6673 show_ip_bgp_ipv4_prefix_cmd,
6674 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6675 SHOW_STR
6676 IP_STR
6677 BGP_STR
6678 "Address family\n"
6679 "Address Family modifier\n"
6680 "Address Family modifier\n"
6681 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6682{
6683 if (strncmp (argv[0], "m", 1) == 0)
6684 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6685
6686 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6687}
6688
Michael Lambert95cbbd22010-07-23 14:43:04 -04006689ALIAS (show_ip_bgp_ipv4_prefix,
6690 show_bgp_ipv4_safi_prefix_cmd,
6691 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6692 SHOW_STR
6693 BGP_STR
6694 "Address family\n"
6695 "Address Family modifier\n"
6696 "Address Family modifier\n"
6697 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6698
paul718e3742002-12-13 20:15:29 +00006699DEFUN (show_ip_bgp_vpnv4_all_prefix,
6700 show_ip_bgp_vpnv4_all_prefix_cmd,
6701 "show ip bgp vpnv4 all A.B.C.D/M",
6702 SHOW_STR
6703 IP_STR
6704 BGP_STR
6705 "Display VPNv4 NLRI specific information\n"
6706 "Display information about all VPNv4 NLRIs\n"
6707 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6708{
6709 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6710}
6711
6712DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6713 show_ip_bgp_vpnv4_rd_prefix_cmd,
6714 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6715 SHOW_STR
6716 IP_STR
6717 BGP_STR
6718 "Display VPNv4 NLRI specific information\n"
6719 "Display information for a route distinguisher\n"
6720 "VPN Route Distinguisher\n"
6721 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6722{
6723 int ret;
6724 struct prefix_rd prd;
6725
6726 ret = str2prefix_rd (argv[0], &prd);
6727 if (! ret)
6728 {
6729 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6730 return CMD_WARNING;
6731 }
6732 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6733}
6734
6735DEFUN (show_ip_bgp_view,
6736 show_ip_bgp_view_cmd,
6737 "show ip bgp view WORD",
6738 SHOW_STR
6739 IP_STR
6740 BGP_STR
6741 "BGP view\n"
6742 "BGP view name\n")
6743{
paulbb46e942003-10-24 19:02:03 +00006744 struct bgp *bgp;
6745
6746 /* BGP structure lookup. */
6747 bgp = bgp_lookup_by_name (argv[0]);
6748 if (bgp == NULL)
6749 {
6750 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6751 return CMD_WARNING;
6752 }
6753
ajs5a646652004-11-05 01:25:55 +00006754 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006755}
6756
6757DEFUN (show_ip_bgp_view_route,
6758 show_ip_bgp_view_route_cmd,
6759 "show ip bgp view WORD A.B.C.D",
6760 SHOW_STR
6761 IP_STR
6762 BGP_STR
6763 "BGP view\n"
6764 "BGP view name\n"
6765 "Network in the BGP routing table to display\n")
6766{
6767 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6768}
6769
6770DEFUN (show_ip_bgp_view_prefix,
6771 show_ip_bgp_view_prefix_cmd,
6772 "show ip bgp view WORD A.B.C.D/M",
6773 SHOW_STR
6774 IP_STR
6775 BGP_STR
6776 "BGP view\n"
6777 "BGP view name\n"
6778 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6779{
6780 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6781}
6782
6783#ifdef HAVE_IPV6
6784DEFUN (show_bgp,
6785 show_bgp_cmd,
6786 "show bgp",
6787 SHOW_STR
6788 BGP_STR)
6789{
ajs5a646652004-11-05 01:25:55 +00006790 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6791 NULL);
paul718e3742002-12-13 20:15:29 +00006792}
6793
6794ALIAS (show_bgp,
6795 show_bgp_ipv6_cmd,
6796 "show bgp ipv6",
6797 SHOW_STR
6798 BGP_STR
6799 "Address family\n")
6800
Michael Lambert95cbbd22010-07-23 14:43:04 -04006801DEFUN (show_bgp_ipv6_safi,
6802 show_bgp_ipv6_safi_cmd,
6803 "show bgp ipv6 (unicast|multicast)",
6804 SHOW_STR
6805 BGP_STR
6806 "Address family\n"
6807 "Address Family modifier\n"
6808 "Address Family modifier\n")
6809{
6810 if (strncmp (argv[0], "m", 1) == 0)
6811 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6812 NULL);
6813
6814 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6815}
6816
paul718e3742002-12-13 20:15:29 +00006817/* old command */
6818DEFUN (show_ipv6_bgp,
6819 show_ipv6_bgp_cmd,
6820 "show ipv6 bgp",
6821 SHOW_STR
6822 IP_STR
6823 BGP_STR)
6824{
ajs5a646652004-11-05 01:25:55 +00006825 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6826 NULL);
paul718e3742002-12-13 20:15:29 +00006827}
6828
6829DEFUN (show_bgp_route,
6830 show_bgp_route_cmd,
6831 "show bgp X:X::X:X",
6832 SHOW_STR
6833 BGP_STR
6834 "Network in the BGP routing table to display\n")
6835{
6836 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6837}
6838
6839ALIAS (show_bgp_route,
6840 show_bgp_ipv6_route_cmd,
6841 "show bgp ipv6 X:X::X:X",
6842 SHOW_STR
6843 BGP_STR
6844 "Address family\n"
6845 "Network in the BGP routing table to display\n")
6846
Michael Lambert95cbbd22010-07-23 14:43:04 -04006847DEFUN (show_bgp_ipv6_safi_route,
6848 show_bgp_ipv6_safi_route_cmd,
6849 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6850 SHOW_STR
6851 BGP_STR
6852 "Address family\n"
6853 "Address Family modifier\n"
6854 "Address Family modifier\n"
6855 "Network in the BGP routing table to display\n")
6856{
6857 if (strncmp (argv[0], "m", 1) == 0)
6858 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6859
6860 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6861}
6862
paul718e3742002-12-13 20:15:29 +00006863/* old command */
6864DEFUN (show_ipv6_bgp_route,
6865 show_ipv6_bgp_route_cmd,
6866 "show ipv6 bgp X:X::X:X",
6867 SHOW_STR
6868 IP_STR
6869 BGP_STR
6870 "Network in the BGP routing table to display\n")
6871{
6872 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6873}
6874
6875DEFUN (show_bgp_prefix,
6876 show_bgp_prefix_cmd,
6877 "show bgp X:X::X:X/M",
6878 SHOW_STR
6879 BGP_STR
6880 "IPv6 prefix <network>/<length>\n")
6881{
6882 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6883}
6884
6885ALIAS (show_bgp_prefix,
6886 show_bgp_ipv6_prefix_cmd,
6887 "show bgp ipv6 X:X::X:X/M",
6888 SHOW_STR
6889 BGP_STR
6890 "Address family\n"
6891 "IPv6 prefix <network>/<length>\n")
6892
Michael Lambert95cbbd22010-07-23 14:43:04 -04006893DEFUN (show_bgp_ipv6_safi_prefix,
6894 show_bgp_ipv6_safi_prefix_cmd,
6895 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6896 SHOW_STR
6897 BGP_STR
6898 "Address family\n"
6899 "Address Family modifier\n"
6900 "Address Family modifier\n"
6901 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6902{
6903 if (strncmp (argv[0], "m", 1) == 0)
6904 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6905
6906 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6907}
6908
paul718e3742002-12-13 20:15:29 +00006909/* old command */
6910DEFUN (show_ipv6_bgp_prefix,
6911 show_ipv6_bgp_prefix_cmd,
6912 "show ipv6 bgp X:X::X:X/M",
6913 SHOW_STR
6914 IP_STR
6915 BGP_STR
6916 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6917{
6918 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6919}
6920
paulbb46e942003-10-24 19:02:03 +00006921DEFUN (show_bgp_view,
6922 show_bgp_view_cmd,
6923 "show bgp view WORD",
6924 SHOW_STR
6925 BGP_STR
6926 "BGP view\n"
6927 "View name\n")
6928{
6929 struct bgp *bgp;
6930
6931 /* BGP structure lookup. */
6932 bgp = bgp_lookup_by_name (argv[0]);
6933 if (bgp == NULL)
6934 {
6935 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6936 return CMD_WARNING;
6937 }
6938
ajs5a646652004-11-05 01:25:55 +00006939 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006940}
6941
6942ALIAS (show_bgp_view,
6943 show_bgp_view_ipv6_cmd,
6944 "show bgp view WORD ipv6",
6945 SHOW_STR
6946 BGP_STR
6947 "BGP view\n"
6948 "View name\n"
6949 "Address family\n")
6950
6951DEFUN (show_bgp_view_route,
6952 show_bgp_view_route_cmd,
6953 "show bgp view WORD X:X::X:X",
6954 SHOW_STR
6955 BGP_STR
6956 "BGP view\n"
6957 "View name\n"
6958 "Network in the BGP routing table to display\n")
6959{
6960 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6961}
6962
6963ALIAS (show_bgp_view_route,
6964 show_bgp_view_ipv6_route_cmd,
6965 "show bgp view WORD ipv6 X:X::X:X",
6966 SHOW_STR
6967 BGP_STR
6968 "BGP view\n"
6969 "View name\n"
6970 "Address family\n"
6971 "Network in the BGP routing table to display\n")
6972
6973DEFUN (show_bgp_view_prefix,
6974 show_bgp_view_prefix_cmd,
6975 "show bgp view WORD X:X::X:X/M",
6976 SHOW_STR
6977 BGP_STR
6978 "BGP view\n"
6979 "View name\n"
6980 "IPv6 prefix <network>/<length>\n")
6981{
6982 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6983}
6984
6985ALIAS (show_bgp_view_prefix,
6986 show_bgp_view_ipv6_prefix_cmd,
6987 "show bgp view WORD ipv6 X:X::X:X/M",
6988 SHOW_STR
6989 BGP_STR
6990 "BGP view\n"
6991 "View name\n"
6992 "Address family\n"
6993 "IPv6 prefix <network>/<length>\n")
6994
paul718e3742002-12-13 20:15:29 +00006995/* old command */
6996DEFUN (show_ipv6_mbgp,
6997 show_ipv6_mbgp_cmd,
6998 "show ipv6 mbgp",
6999 SHOW_STR
7000 IP_STR
7001 MBGP_STR)
7002{
ajs5a646652004-11-05 01:25:55 +00007003 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
7004 NULL);
paul718e3742002-12-13 20:15:29 +00007005}
7006
7007/* old command */
7008DEFUN (show_ipv6_mbgp_route,
7009 show_ipv6_mbgp_route_cmd,
7010 "show ipv6 mbgp X:X::X:X",
7011 SHOW_STR
7012 IP_STR
7013 MBGP_STR
7014 "Network in the MBGP routing table to display\n")
7015{
7016 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7017}
7018
7019/* old command */
7020DEFUN (show_ipv6_mbgp_prefix,
7021 show_ipv6_mbgp_prefix_cmd,
7022 "show ipv6 mbgp X:X::X:X/M",
7023 SHOW_STR
7024 IP_STR
7025 MBGP_STR
7026 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7027{
7028 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7029}
7030#endif
7031
paul718e3742002-12-13 20:15:29 +00007032
paul94f2b392005-06-28 12:44:16 +00007033static int
paulfd79ac92004-10-13 05:06:08 +00007034bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007035 safi_t safi, enum bgp_show_type type)
7036{
7037 int i;
7038 struct buffer *b;
7039 char *regstr;
7040 int first;
7041 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007042 int rc;
paul718e3742002-12-13 20:15:29 +00007043
7044 first = 0;
7045 b = buffer_new (1024);
7046 for (i = 0; i < argc; i++)
7047 {
7048 if (first)
7049 buffer_putc (b, ' ');
7050 else
7051 {
7052 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7053 continue;
7054 first = 1;
7055 }
7056
7057 buffer_putstr (b, argv[i]);
7058 }
7059 buffer_putc (b, '\0');
7060
7061 regstr = buffer_getstr (b);
7062 buffer_free (b);
7063
7064 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007065 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007066 if (! regex)
7067 {
7068 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7069 VTY_NEWLINE);
7070 return CMD_WARNING;
7071 }
7072
ajs5a646652004-11-05 01:25:55 +00007073 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7074 bgp_regex_free (regex);
7075 return rc;
paul718e3742002-12-13 20:15:29 +00007076}
7077
7078DEFUN (show_ip_bgp_regexp,
7079 show_ip_bgp_regexp_cmd,
7080 "show ip bgp regexp .LINE",
7081 SHOW_STR
7082 IP_STR
7083 BGP_STR
7084 "Display routes matching the AS path regular expression\n"
7085 "A regular-expression to match the BGP AS paths\n")
7086{
7087 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7088 bgp_show_type_regexp);
7089}
7090
7091DEFUN (show_ip_bgp_flap_regexp,
7092 show_ip_bgp_flap_regexp_cmd,
7093 "show ip bgp flap-statistics regexp .LINE",
7094 SHOW_STR
7095 IP_STR
7096 BGP_STR
7097 "Display flap statistics of routes\n"
7098 "Display routes matching the AS path regular expression\n"
7099 "A regular-expression to match the BGP AS paths\n")
7100{
7101 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7102 bgp_show_type_flap_regexp);
7103}
7104
7105DEFUN (show_ip_bgp_ipv4_regexp,
7106 show_ip_bgp_ipv4_regexp_cmd,
7107 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7108 SHOW_STR
7109 IP_STR
7110 BGP_STR
7111 "Address family\n"
7112 "Address Family modifier\n"
7113 "Address Family modifier\n"
7114 "Display routes matching the AS path regular expression\n"
7115 "A regular-expression to match the BGP AS paths\n")
7116{
7117 if (strncmp (argv[0], "m", 1) == 0)
7118 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7119 bgp_show_type_regexp);
7120
7121 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7122 bgp_show_type_regexp);
7123}
7124
7125#ifdef HAVE_IPV6
7126DEFUN (show_bgp_regexp,
7127 show_bgp_regexp_cmd,
7128 "show bgp regexp .LINE",
7129 SHOW_STR
7130 BGP_STR
7131 "Display routes matching the AS path regular expression\n"
7132 "A regular-expression to match the BGP AS paths\n")
7133{
7134 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7135 bgp_show_type_regexp);
7136}
7137
7138ALIAS (show_bgp_regexp,
7139 show_bgp_ipv6_regexp_cmd,
7140 "show bgp ipv6 regexp .LINE",
7141 SHOW_STR
7142 BGP_STR
7143 "Address family\n"
7144 "Display routes matching the AS path regular expression\n"
7145 "A regular-expression to match the BGP AS paths\n")
7146
7147/* old command */
7148DEFUN (show_ipv6_bgp_regexp,
7149 show_ipv6_bgp_regexp_cmd,
7150 "show ipv6 bgp regexp .LINE",
7151 SHOW_STR
7152 IP_STR
7153 BGP_STR
7154 "Display routes matching the AS path regular expression\n"
7155 "A regular-expression to match the BGP AS paths\n")
7156{
7157 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7158 bgp_show_type_regexp);
7159}
7160
7161/* old command */
7162DEFUN (show_ipv6_mbgp_regexp,
7163 show_ipv6_mbgp_regexp_cmd,
7164 "show ipv6 mbgp regexp .LINE",
7165 SHOW_STR
7166 IP_STR
7167 BGP_STR
7168 "Display routes matching the AS path regular expression\n"
7169 "A regular-expression to match the MBGP AS paths\n")
7170{
7171 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7172 bgp_show_type_regexp);
7173}
7174#endif /* HAVE_IPV6 */
7175
paul94f2b392005-06-28 12:44:16 +00007176static int
paulfd79ac92004-10-13 05:06:08 +00007177bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007178 safi_t safi, enum bgp_show_type type)
7179{
7180 struct prefix_list *plist;
7181
7182 plist = prefix_list_lookup (afi, prefix_list_str);
7183 if (plist == NULL)
7184 {
7185 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7186 prefix_list_str, VTY_NEWLINE);
7187 return CMD_WARNING;
7188 }
7189
ajs5a646652004-11-05 01:25:55 +00007190 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007191}
7192
7193DEFUN (show_ip_bgp_prefix_list,
7194 show_ip_bgp_prefix_list_cmd,
7195 "show ip bgp prefix-list WORD",
7196 SHOW_STR
7197 IP_STR
7198 BGP_STR
7199 "Display routes conforming to the prefix-list\n"
7200 "IP prefix-list name\n")
7201{
7202 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7203 bgp_show_type_prefix_list);
7204}
7205
7206DEFUN (show_ip_bgp_flap_prefix_list,
7207 show_ip_bgp_flap_prefix_list_cmd,
7208 "show ip bgp flap-statistics prefix-list WORD",
7209 SHOW_STR
7210 IP_STR
7211 BGP_STR
7212 "Display flap statistics of routes\n"
7213 "Display routes conforming to the prefix-list\n"
7214 "IP prefix-list name\n")
7215{
7216 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7217 bgp_show_type_flap_prefix_list);
7218}
7219
7220DEFUN (show_ip_bgp_ipv4_prefix_list,
7221 show_ip_bgp_ipv4_prefix_list_cmd,
7222 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7223 SHOW_STR
7224 IP_STR
7225 BGP_STR
7226 "Address family\n"
7227 "Address Family modifier\n"
7228 "Address Family modifier\n"
7229 "Display routes conforming to the prefix-list\n"
7230 "IP prefix-list name\n")
7231{
7232 if (strncmp (argv[0], "m", 1) == 0)
7233 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7234 bgp_show_type_prefix_list);
7235
7236 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7237 bgp_show_type_prefix_list);
7238}
7239
7240#ifdef HAVE_IPV6
7241DEFUN (show_bgp_prefix_list,
7242 show_bgp_prefix_list_cmd,
7243 "show bgp prefix-list WORD",
7244 SHOW_STR
7245 BGP_STR
7246 "Display routes conforming to the prefix-list\n"
7247 "IPv6 prefix-list name\n")
7248{
7249 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7250 bgp_show_type_prefix_list);
7251}
7252
7253ALIAS (show_bgp_prefix_list,
7254 show_bgp_ipv6_prefix_list_cmd,
7255 "show bgp ipv6 prefix-list WORD",
7256 SHOW_STR
7257 BGP_STR
7258 "Address family\n"
7259 "Display routes conforming to the prefix-list\n"
7260 "IPv6 prefix-list name\n")
7261
7262/* old command */
7263DEFUN (show_ipv6_bgp_prefix_list,
7264 show_ipv6_bgp_prefix_list_cmd,
7265 "show ipv6 bgp prefix-list WORD",
7266 SHOW_STR
7267 IPV6_STR
7268 BGP_STR
7269 "Display routes matching the prefix-list\n"
7270 "IPv6 prefix-list name\n")
7271{
7272 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7273 bgp_show_type_prefix_list);
7274}
7275
7276/* old command */
7277DEFUN (show_ipv6_mbgp_prefix_list,
7278 show_ipv6_mbgp_prefix_list_cmd,
7279 "show ipv6 mbgp prefix-list WORD",
7280 SHOW_STR
7281 IPV6_STR
7282 MBGP_STR
7283 "Display routes matching the prefix-list\n"
7284 "IPv6 prefix-list name\n")
7285{
7286 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7287 bgp_show_type_prefix_list);
7288}
7289#endif /* HAVE_IPV6 */
7290
paul94f2b392005-06-28 12:44:16 +00007291static int
paulfd79ac92004-10-13 05:06:08 +00007292bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007293 safi_t safi, enum bgp_show_type type)
7294{
7295 struct as_list *as_list;
7296
7297 as_list = as_list_lookup (filter);
7298 if (as_list == NULL)
7299 {
7300 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7301 return CMD_WARNING;
7302 }
7303
ajs5a646652004-11-05 01:25:55 +00007304 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007305}
7306
7307DEFUN (show_ip_bgp_filter_list,
7308 show_ip_bgp_filter_list_cmd,
7309 "show ip bgp filter-list WORD",
7310 SHOW_STR
7311 IP_STR
7312 BGP_STR
7313 "Display routes conforming to the filter-list\n"
7314 "Regular expression access list name\n")
7315{
7316 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7317 bgp_show_type_filter_list);
7318}
7319
7320DEFUN (show_ip_bgp_flap_filter_list,
7321 show_ip_bgp_flap_filter_list_cmd,
7322 "show ip bgp flap-statistics filter-list WORD",
7323 SHOW_STR
7324 IP_STR
7325 BGP_STR
7326 "Display flap statistics of routes\n"
7327 "Display routes conforming to the filter-list\n"
7328 "Regular expression access list name\n")
7329{
7330 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7331 bgp_show_type_flap_filter_list);
7332}
7333
7334DEFUN (show_ip_bgp_ipv4_filter_list,
7335 show_ip_bgp_ipv4_filter_list_cmd,
7336 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7337 SHOW_STR
7338 IP_STR
7339 BGP_STR
7340 "Address family\n"
7341 "Address Family modifier\n"
7342 "Address Family modifier\n"
7343 "Display routes conforming to the filter-list\n"
7344 "Regular expression access list name\n")
7345{
7346 if (strncmp (argv[0], "m", 1) == 0)
7347 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7348 bgp_show_type_filter_list);
7349
7350 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7351 bgp_show_type_filter_list);
7352}
7353
7354#ifdef HAVE_IPV6
7355DEFUN (show_bgp_filter_list,
7356 show_bgp_filter_list_cmd,
7357 "show bgp filter-list WORD",
7358 SHOW_STR
7359 BGP_STR
7360 "Display routes conforming to the filter-list\n"
7361 "Regular expression access list name\n")
7362{
7363 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7364 bgp_show_type_filter_list);
7365}
7366
7367ALIAS (show_bgp_filter_list,
7368 show_bgp_ipv6_filter_list_cmd,
7369 "show bgp ipv6 filter-list WORD",
7370 SHOW_STR
7371 BGP_STR
7372 "Address family\n"
7373 "Display routes conforming to the filter-list\n"
7374 "Regular expression access list name\n")
7375
7376/* old command */
7377DEFUN (show_ipv6_bgp_filter_list,
7378 show_ipv6_bgp_filter_list_cmd,
7379 "show ipv6 bgp filter-list WORD",
7380 SHOW_STR
7381 IPV6_STR
7382 BGP_STR
7383 "Display routes conforming to the filter-list\n"
7384 "Regular expression access list name\n")
7385{
7386 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7387 bgp_show_type_filter_list);
7388}
7389
7390/* old command */
7391DEFUN (show_ipv6_mbgp_filter_list,
7392 show_ipv6_mbgp_filter_list_cmd,
7393 "show ipv6 mbgp filter-list WORD",
7394 SHOW_STR
7395 IPV6_STR
7396 MBGP_STR
7397 "Display routes conforming to the filter-list\n"
7398 "Regular expression access list name\n")
7399{
7400 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7401 bgp_show_type_filter_list);
7402}
7403#endif /* HAVE_IPV6 */
7404
paul94f2b392005-06-28 12:44:16 +00007405static int
paulfd79ac92004-10-13 05:06:08 +00007406bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007407 safi_t safi, enum bgp_show_type type)
7408{
7409 struct route_map *rmap;
7410
7411 rmap = route_map_lookup_by_name (rmap_str);
7412 if (! rmap)
7413 {
7414 vty_out (vty, "%% %s is not a valid route-map name%s",
7415 rmap_str, VTY_NEWLINE);
7416 return CMD_WARNING;
7417 }
7418
ajs5a646652004-11-05 01:25:55 +00007419 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007420}
7421
7422DEFUN (show_ip_bgp_route_map,
7423 show_ip_bgp_route_map_cmd,
7424 "show ip bgp route-map WORD",
7425 SHOW_STR
7426 IP_STR
7427 BGP_STR
7428 "Display routes matching the route-map\n"
7429 "A route-map to match on\n")
7430{
7431 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7432 bgp_show_type_route_map);
7433}
7434
7435DEFUN (show_ip_bgp_flap_route_map,
7436 show_ip_bgp_flap_route_map_cmd,
7437 "show ip bgp flap-statistics route-map WORD",
7438 SHOW_STR
7439 IP_STR
7440 BGP_STR
7441 "Display flap statistics of routes\n"
7442 "Display routes matching the route-map\n"
7443 "A route-map to match on\n")
7444{
7445 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7446 bgp_show_type_flap_route_map);
7447}
7448
7449DEFUN (show_ip_bgp_ipv4_route_map,
7450 show_ip_bgp_ipv4_route_map_cmd,
7451 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7452 SHOW_STR
7453 IP_STR
7454 BGP_STR
7455 "Address family\n"
7456 "Address Family modifier\n"
7457 "Address Family modifier\n"
7458 "Display routes matching the route-map\n"
7459 "A route-map to match on\n")
7460{
7461 if (strncmp (argv[0], "m", 1) == 0)
7462 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7463 bgp_show_type_route_map);
7464
7465 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7466 bgp_show_type_route_map);
7467}
7468
7469DEFUN (show_bgp_route_map,
7470 show_bgp_route_map_cmd,
7471 "show bgp route-map WORD",
7472 SHOW_STR
7473 BGP_STR
7474 "Display routes matching the route-map\n"
7475 "A route-map to match on\n")
7476{
7477 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7478 bgp_show_type_route_map);
7479}
7480
7481ALIAS (show_bgp_route_map,
7482 show_bgp_ipv6_route_map_cmd,
7483 "show bgp ipv6 route-map WORD",
7484 SHOW_STR
7485 BGP_STR
7486 "Address family\n"
7487 "Display routes matching the route-map\n"
7488 "A route-map to match on\n")
7489
7490DEFUN (show_ip_bgp_cidr_only,
7491 show_ip_bgp_cidr_only_cmd,
7492 "show ip bgp cidr-only",
7493 SHOW_STR
7494 IP_STR
7495 BGP_STR
7496 "Display only routes with non-natural netmasks\n")
7497{
7498 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007499 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007500}
7501
7502DEFUN (show_ip_bgp_flap_cidr_only,
7503 show_ip_bgp_flap_cidr_only_cmd,
7504 "show ip bgp flap-statistics cidr-only",
7505 SHOW_STR
7506 IP_STR
7507 BGP_STR
7508 "Display flap statistics of routes\n"
7509 "Display only routes with non-natural netmasks\n")
7510{
7511 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007512 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007513}
7514
7515DEFUN (show_ip_bgp_ipv4_cidr_only,
7516 show_ip_bgp_ipv4_cidr_only_cmd,
7517 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7518 SHOW_STR
7519 IP_STR
7520 BGP_STR
7521 "Address family\n"
7522 "Address Family modifier\n"
7523 "Address Family modifier\n"
7524 "Display only routes with non-natural netmasks\n")
7525{
7526 if (strncmp (argv[0], "m", 1) == 0)
7527 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007528 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007529
7530 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007531 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007532}
7533
7534DEFUN (show_ip_bgp_community_all,
7535 show_ip_bgp_community_all_cmd,
7536 "show ip bgp community",
7537 SHOW_STR
7538 IP_STR
7539 BGP_STR
7540 "Display routes matching the communities\n")
7541{
7542 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007543 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007544}
7545
7546DEFUN (show_ip_bgp_ipv4_community_all,
7547 show_ip_bgp_ipv4_community_all_cmd,
7548 "show ip bgp ipv4 (unicast|multicast) community",
7549 SHOW_STR
7550 IP_STR
7551 BGP_STR
7552 "Address family\n"
7553 "Address Family modifier\n"
7554 "Address Family modifier\n"
7555 "Display routes matching the communities\n")
7556{
7557 if (strncmp (argv[0], "m", 1) == 0)
7558 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007559 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007560
7561 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007562 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007563}
7564
7565#ifdef HAVE_IPV6
7566DEFUN (show_bgp_community_all,
7567 show_bgp_community_all_cmd,
7568 "show bgp community",
7569 SHOW_STR
7570 BGP_STR
7571 "Display routes matching the communities\n")
7572{
7573 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007574 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007575}
7576
7577ALIAS (show_bgp_community_all,
7578 show_bgp_ipv6_community_all_cmd,
7579 "show bgp ipv6 community",
7580 SHOW_STR
7581 BGP_STR
7582 "Address family\n"
7583 "Display routes matching the communities\n")
7584
7585/* old command */
7586DEFUN (show_ipv6_bgp_community_all,
7587 show_ipv6_bgp_community_all_cmd,
7588 "show ipv6 bgp community",
7589 SHOW_STR
7590 IPV6_STR
7591 BGP_STR
7592 "Display routes matching the communities\n")
7593{
7594 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007595 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007596}
7597
7598/* old command */
7599DEFUN (show_ipv6_mbgp_community_all,
7600 show_ipv6_mbgp_community_all_cmd,
7601 "show ipv6 mbgp community",
7602 SHOW_STR
7603 IPV6_STR
7604 MBGP_STR
7605 "Display routes matching the communities\n")
7606{
7607 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007608 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007609}
7610#endif /* HAVE_IPV6 */
7611
paul94f2b392005-06-28 12:44:16 +00007612static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007613bgp_show_community (struct vty *vty, const char *view_name, int argc,
7614 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007615{
7616 struct community *com;
7617 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007618 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007619 int i;
7620 char *str;
7621 int first = 0;
7622
Michael Lambert95cbbd22010-07-23 14:43:04 -04007623 /* BGP structure lookup */
7624 if (view_name)
7625 {
7626 bgp = bgp_lookup_by_name (view_name);
7627 if (bgp == NULL)
7628 {
7629 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7630 return CMD_WARNING;
7631 }
7632 }
7633 else
7634 {
7635 bgp = bgp_get_default ();
7636 if (bgp == NULL)
7637 {
7638 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7639 return CMD_WARNING;
7640 }
7641 }
7642
paul718e3742002-12-13 20:15:29 +00007643 b = buffer_new (1024);
7644 for (i = 0; i < argc; i++)
7645 {
7646 if (first)
7647 buffer_putc (b, ' ');
7648 else
7649 {
7650 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7651 continue;
7652 first = 1;
7653 }
7654
7655 buffer_putstr (b, argv[i]);
7656 }
7657 buffer_putc (b, '\0');
7658
7659 str = buffer_getstr (b);
7660 buffer_free (b);
7661
7662 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007663 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007664 if (! com)
7665 {
7666 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7667 return CMD_WARNING;
7668 }
7669
Michael Lambert95cbbd22010-07-23 14:43:04 -04007670 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007671 (exact ? bgp_show_type_community_exact :
7672 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007673}
7674
7675DEFUN (show_ip_bgp_community,
7676 show_ip_bgp_community_cmd,
7677 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7678 SHOW_STR
7679 IP_STR
7680 BGP_STR
7681 "Display routes matching the communities\n"
7682 "community number\n"
7683 "Do not send outside local AS (well-known community)\n"
7684 "Do not advertise to any peer (well-known community)\n"
7685 "Do not export to next AS (well-known community)\n")
7686{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007687 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007688}
7689
7690ALIAS (show_ip_bgp_community,
7691 show_ip_bgp_community2_cmd,
7692 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7693 SHOW_STR
7694 IP_STR
7695 BGP_STR
7696 "Display routes matching the communities\n"
7697 "community number\n"
7698 "Do not send outside local AS (well-known community)\n"
7699 "Do not advertise to any peer (well-known community)\n"
7700 "Do not export to next AS (well-known community)\n"
7701 "community number\n"
7702 "Do not send outside local AS (well-known community)\n"
7703 "Do not advertise to any peer (well-known community)\n"
7704 "Do not export to next AS (well-known community)\n")
7705
7706ALIAS (show_ip_bgp_community,
7707 show_ip_bgp_community3_cmd,
7708 "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)",
7709 SHOW_STR
7710 IP_STR
7711 BGP_STR
7712 "Display routes matching the communities\n"
7713 "community number\n"
7714 "Do not send outside local AS (well-known community)\n"
7715 "Do not advertise to any peer (well-known community)\n"
7716 "Do not export to next AS (well-known community)\n"
7717 "community number\n"
7718 "Do not send outside local AS (well-known community)\n"
7719 "Do not advertise to any peer (well-known community)\n"
7720 "Do not export to next AS (well-known community)\n"
7721 "community number\n"
7722 "Do not send outside local AS (well-known community)\n"
7723 "Do not advertise to any peer (well-known community)\n"
7724 "Do not export to next AS (well-known community)\n")
7725
7726ALIAS (show_ip_bgp_community,
7727 show_ip_bgp_community4_cmd,
7728 "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)",
7729 SHOW_STR
7730 IP_STR
7731 BGP_STR
7732 "Display routes matching the communities\n"
7733 "community number\n"
7734 "Do not send outside local AS (well-known community)\n"
7735 "Do not advertise to any peer (well-known community)\n"
7736 "Do not export to next AS (well-known community)\n"
7737 "community number\n"
7738 "Do not send outside local AS (well-known community)\n"
7739 "Do not advertise to any peer (well-known community)\n"
7740 "Do not export to next AS (well-known community)\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
7750DEFUN (show_ip_bgp_ipv4_community,
7751 show_ip_bgp_ipv4_community_cmd,
7752 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7753 SHOW_STR
7754 IP_STR
7755 BGP_STR
7756 "Address family\n"
7757 "Address Family modifier\n"
7758 "Address Family modifier\n"
7759 "Display routes matching the communities\n"
7760 "community number\n"
7761 "Do not send outside local AS (well-known community)\n"
7762 "Do not advertise to any peer (well-known community)\n"
7763 "Do not export to next AS (well-known community)\n")
7764{
7765 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007766 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007767
Michael Lambert95cbbd22010-07-23 14:43:04 -04007768 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007769}
7770
7771ALIAS (show_ip_bgp_ipv4_community,
7772 show_ip_bgp_ipv4_community2_cmd,
7773 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7774 SHOW_STR
7775 IP_STR
7776 BGP_STR
7777 "Address family\n"
7778 "Address Family modifier\n"
7779 "Address Family modifier\n"
7780 "Display routes matching the communities\n"
7781 "community number\n"
7782 "Do not send outside local AS (well-known community)\n"
7783 "Do not advertise to any peer (well-known community)\n"
7784 "Do not export to next AS (well-known community)\n"
7785 "community number\n"
7786 "Do not send outside local AS (well-known community)\n"
7787 "Do not advertise to any peer (well-known community)\n"
7788 "Do not export to next AS (well-known community)\n")
7789
7790ALIAS (show_ip_bgp_ipv4_community,
7791 show_ip_bgp_ipv4_community3_cmd,
7792 "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)",
7793 SHOW_STR
7794 IP_STR
7795 BGP_STR
7796 "Address family\n"
7797 "Address Family modifier\n"
7798 "Address Family modifier\n"
7799 "Display routes matching the communities\n"
7800 "community number\n"
7801 "Do not send outside local AS (well-known community)\n"
7802 "Do not advertise to any peer (well-known community)\n"
7803 "Do not export to next AS (well-known community)\n"
7804 "community number\n"
7805 "Do not send outside local AS (well-known community)\n"
7806 "Do not advertise to any peer (well-known community)\n"
7807 "Do not export to next AS (well-known community)\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n")
7812
7813ALIAS (show_ip_bgp_ipv4_community,
7814 show_ip_bgp_ipv4_community4_cmd,
7815 "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)",
7816 SHOW_STR
7817 IP_STR
7818 BGP_STR
7819 "Address family\n"
7820 "Address Family modifier\n"
7821 "Address Family modifier\n"
7822 "Display routes matching the communities\n"
7823 "community number\n"
7824 "Do not send outside local AS (well-known community)\n"
7825 "Do not advertise to any peer (well-known community)\n"
7826 "Do not export to next AS (well-known community)\n"
7827 "community number\n"
7828 "Do not send outside local AS (well-known community)\n"
7829 "Do not advertise to any peer (well-known community)\n"
7830 "Do not export to next AS (well-known community)\n"
7831 "community number\n"
7832 "Do not send outside local AS (well-known community)\n"
7833 "Do not advertise to any peer (well-known community)\n"
7834 "Do not export to next AS (well-known community)\n"
7835 "community number\n"
7836 "Do not send outside local AS (well-known community)\n"
7837 "Do not advertise to any peer (well-known community)\n"
7838 "Do not export to next AS (well-known community)\n")
7839
Michael Lambert95cbbd22010-07-23 14:43:04 -04007840DEFUN (show_bgp_view_afi_safi_community_all,
7841 show_bgp_view_afi_safi_community_all_cmd,
7842#ifdef HAVE_IPV6
7843 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7844#else
7845 "show bgp view WORD ipv4 (unicast|multicast) community",
7846#endif
7847 SHOW_STR
7848 BGP_STR
7849 "BGP view\n"
7850 "BGP view name\n"
7851 "Address family\n"
7852#ifdef HAVE_IPV6
7853 "Address family\n"
7854#endif
7855 "Address Family modifier\n"
7856 "Address Family modifier\n"
7857 "Display routes containing communities\n")
7858{
7859 int afi;
7860 int safi;
7861 struct bgp *bgp;
7862
7863 /* BGP structure lookup. */
7864 bgp = bgp_lookup_by_name (argv[0]);
7865 if (bgp == NULL)
7866 {
7867 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7868 return CMD_WARNING;
7869 }
7870
7871#ifdef HAVE_IPV6
7872 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7873 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7874#else
7875 afi = AFI_IP;
7876 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7877#endif
7878 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7879}
7880
7881DEFUN (show_bgp_view_afi_safi_community,
7882 show_bgp_view_afi_safi_community_cmd,
7883#ifdef HAVE_IPV6
7884 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7885#else
7886 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7887#endif
7888 SHOW_STR
7889 BGP_STR
7890 "BGP view\n"
7891 "BGP view name\n"
7892 "Address family\n"
7893#ifdef HAVE_IPV6
7894 "Address family\n"
7895#endif
7896 "Address family modifier\n"
7897 "Address family modifier\n"
7898 "Display routes matching the communities\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n")
7903{
7904 int afi;
7905 int safi;
7906
7907#ifdef HAVE_IPV6
7908 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7909 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7910 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7911#else
7912 afi = AFI_IP;
7913 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7914 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7915#endif
7916}
7917
7918ALIAS (show_bgp_view_afi_safi_community,
7919 show_bgp_view_afi_safi_community2_cmd,
7920#ifdef HAVE_IPV6
7921 "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)",
7922#else
7923 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7924#endif
7925 SHOW_STR
7926 BGP_STR
7927 "BGP view\n"
7928 "BGP view name\n"
7929 "Address family\n"
7930#ifdef HAVE_IPV6
7931 "Address family\n"
7932#endif
7933 "Address family modifier\n"
7934 "Address family modifier\n"
7935 "Display routes matching the communities\n"
7936 "community number\n"
7937 "Do not send outside local AS (well-known community)\n"
7938 "Do not advertise to any peer (well-known community)\n"
7939 "Do not export to next AS (well-known community)\n"
7940 "community number\n"
7941 "Do not send outside local AS (well-known community)\n"
7942 "Do not advertise to any peer (well-known community)\n"
7943 "Do not export to next AS (well-known community)\n")
7944
7945ALIAS (show_bgp_view_afi_safi_community,
7946 show_bgp_view_afi_safi_community3_cmd,
7947#ifdef HAVE_IPV6
7948 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7949#else
7950 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7951#endif
7952 SHOW_STR
7953 BGP_STR
7954 "BGP view\n"
7955 "BGP view name\n"
7956 "Address family\n"
7957#ifdef HAVE_IPV6
7958 "Address family\n"
7959#endif
7960 "Address family modifier\n"
7961 "Address family modifier\n"
7962 "Display routes matching the communities\n"
7963 "community number\n"
7964 "Do not send outside local AS (well-known community)\n"
7965 "Do not advertise to any peer (well-known community)\n"
7966 "Do not export to next AS (well-known community)\n"
7967 "community number\n"
7968 "Do not send outside local AS (well-known community)\n"
7969 "Do not advertise to any peer (well-known community)\n"
7970 "Do not export to next AS (well-known community)\n"
7971 "community number\n"
7972 "Do not send outside local AS (well-known community)\n"
7973 "Do not advertise to any peer (well-known community)\n"
7974 "Do not export to next AS (well-known community)\n")
7975
7976ALIAS (show_bgp_view_afi_safi_community,
7977 show_bgp_view_afi_safi_community4_cmd,
7978#ifdef HAVE_IPV6
7979 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7980#else
7981 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7982#endif
7983 SHOW_STR
7984 BGP_STR
7985 "BGP view\n"
7986 "BGP view name\n"
7987 "Address family\n"
7988#ifdef HAVE_IPV6
7989 "Address family\n"
7990#endif
7991 "Address family modifier\n"
7992 "Address family modifier\n"
7993 "Display routes matching the communities\n"
7994 "community number\n"
7995 "Do not send outside local AS (well-known community)\n"
7996 "Do not advertise to any peer (well-known community)\n"
7997 "Do not export to next AS (well-known community)\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n")
8010
paul718e3742002-12-13 20:15:29 +00008011DEFUN (show_ip_bgp_community_exact,
8012 show_ip_bgp_community_exact_cmd,
8013 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8014 SHOW_STR
8015 IP_STR
8016 BGP_STR
8017 "Display routes matching the communities\n"
8018 "community number\n"
8019 "Do not send outside local AS (well-known community)\n"
8020 "Do not advertise to any peer (well-known community)\n"
8021 "Do not export to next AS (well-known community)\n"
8022 "Exact match of the communities")
8023{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008024 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008025}
8026
8027ALIAS (show_ip_bgp_community_exact,
8028 show_ip_bgp_community2_exact_cmd,
8029 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8030 SHOW_STR
8031 IP_STR
8032 BGP_STR
8033 "Display routes matching the communities\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 "community number\n"
8039 "Do not send outside local AS (well-known community)\n"
8040 "Do not advertise to any peer (well-known community)\n"
8041 "Do not export to next AS (well-known community)\n"
8042 "Exact match of the communities")
8043
8044ALIAS (show_ip_bgp_community_exact,
8045 show_ip_bgp_community3_exact_cmd,
8046 "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",
8047 SHOW_STR
8048 IP_STR
8049 BGP_STR
8050 "Display routes matching the communities\n"
8051 "community number\n"
8052 "Do not send outside local AS (well-known community)\n"
8053 "Do not advertise to any peer (well-known community)\n"
8054 "Do not export to next AS (well-known community)\n"
8055 "community number\n"
8056 "Do not send outside local AS (well-known community)\n"
8057 "Do not advertise to any peer (well-known community)\n"
8058 "Do not export to next AS (well-known community)\n"
8059 "community number\n"
8060 "Do not send outside local AS (well-known community)\n"
8061 "Do not advertise to any peer (well-known community)\n"
8062 "Do not export to next AS (well-known community)\n"
8063 "Exact match of the communities")
8064
8065ALIAS (show_ip_bgp_community_exact,
8066 show_ip_bgp_community4_exact_cmd,
8067 "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",
8068 SHOW_STR
8069 IP_STR
8070 BGP_STR
8071 "Display routes matching the communities\n"
8072 "community number\n"
8073 "Do not send outside local AS (well-known community)\n"
8074 "Do not advertise to any peer (well-known community)\n"
8075 "Do not export to next AS (well-known community)\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n"
8080 "community number\n"
8081 "Do not send outside local AS (well-known community)\n"
8082 "Do not advertise to any peer (well-known community)\n"
8083 "Do not export to next AS (well-known community)\n"
8084 "community number\n"
8085 "Do not send outside local AS (well-known community)\n"
8086 "Do not advertise to any peer (well-known community)\n"
8087 "Do not export to next AS (well-known community)\n"
8088 "Exact match of the communities")
8089
8090DEFUN (show_ip_bgp_ipv4_community_exact,
8091 show_ip_bgp_ipv4_community_exact_cmd,
8092 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8093 SHOW_STR
8094 IP_STR
8095 BGP_STR
8096 "Address family\n"
8097 "Address Family modifier\n"
8098 "Address Family modifier\n"
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 "Exact match of the communities")
8105{
8106 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008107 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008108
Michael Lambert95cbbd22010-07-23 14:43:04 -04008109 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008110}
8111
8112ALIAS (show_ip_bgp_ipv4_community_exact,
8113 show_ip_bgp_ipv4_community2_exact_cmd,
8114 "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",
8115 SHOW_STR
8116 IP_STR
8117 BGP_STR
8118 "Address family\n"
8119 "Address Family modifier\n"
8120 "Address Family modifier\n"
8121 "Display routes matching the communities\n"
8122 "community number\n"
8123 "Do not send outside local AS (well-known community)\n"
8124 "Do not advertise to any peer (well-known community)\n"
8125 "Do not export to next AS (well-known community)\n"
8126 "community number\n"
8127 "Do not send outside local AS (well-known community)\n"
8128 "Do not advertise to any peer (well-known community)\n"
8129 "Do not export to next AS (well-known community)\n"
8130 "Exact match of the communities")
8131
8132ALIAS (show_ip_bgp_ipv4_community_exact,
8133 show_ip_bgp_ipv4_community3_exact_cmd,
8134 "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",
8135 SHOW_STR
8136 IP_STR
8137 BGP_STR
8138 "Address family\n"
8139 "Address Family modifier\n"
8140 "Address Family modifier\n"
8141 "Display routes matching the communities\n"
8142 "community number\n"
8143 "Do not send outside local AS (well-known community)\n"
8144 "Do not advertise to any peer (well-known community)\n"
8145 "Do not export to next AS (well-known community)\n"
8146 "community number\n"
8147 "Do not send outside local AS (well-known community)\n"
8148 "Do not advertise to any peer (well-known community)\n"
8149 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8155
8156ALIAS (show_ip_bgp_ipv4_community_exact,
8157 show_ip_bgp_ipv4_community4_exact_cmd,
8158 "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",
8159 SHOW_STR
8160 IP_STR
8161 BGP_STR
8162 "Address family\n"
8163 "Address Family modifier\n"
8164 "Address Family modifier\n"
8165 "Display routes matching the communities\n"
8166 "community number\n"
8167 "Do not send outside local AS (well-known community)\n"
8168 "Do not advertise to any peer (well-known community)\n"
8169 "Do not export to next AS (well-known community)\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
8184#ifdef HAVE_IPV6
8185DEFUN (show_bgp_community,
8186 show_bgp_community_cmd,
8187 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8188 SHOW_STR
8189 BGP_STR
8190 "Display routes matching the communities\n"
8191 "community number\n"
8192 "Do not send outside local AS (well-known community)\n"
8193 "Do not advertise to any peer (well-known community)\n"
8194 "Do not export to next AS (well-known community)\n")
8195{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008196 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008197}
8198
8199ALIAS (show_bgp_community,
8200 show_bgp_ipv6_community_cmd,
8201 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8202 SHOW_STR
8203 BGP_STR
8204 "Address family\n"
8205 "Display routes matching the communities\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
8211ALIAS (show_bgp_community,
8212 show_bgp_community2_cmd,
8213 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8214 SHOW_STR
8215 BGP_STR
8216 "Display routes matching the communities\n"
8217 "community number\n"
8218 "Do not send outside local AS (well-known community)\n"
8219 "Do not advertise to any peer (well-known community)\n"
8220 "Do not export to next AS (well-known community)\n"
8221 "community number\n"
8222 "Do not send outside local AS (well-known community)\n"
8223 "Do not advertise to any peer (well-known community)\n"
8224 "Do not export to next AS (well-known community)\n")
8225
8226ALIAS (show_bgp_community,
8227 show_bgp_ipv6_community2_cmd,
8228 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8229 SHOW_STR
8230 BGP_STR
8231 "Address family\n"
8232 "Display routes matching the communities\n"
8233 "community number\n"
8234 "Do not send outside local AS (well-known community)\n"
8235 "Do not advertise to any peer (well-known community)\n"
8236 "Do not export to next AS (well-known community)\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n")
8241
8242ALIAS (show_bgp_community,
8243 show_bgp_community3_cmd,
8244 "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)",
8245 SHOW_STR
8246 BGP_STR
8247 "Display routes matching the communities\n"
8248 "community number\n"
8249 "Do not send outside local AS (well-known community)\n"
8250 "Do not advertise to any peer (well-known community)\n"
8251 "Do not export to next AS (well-known community)\n"
8252 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n"
8256 "community number\n"
8257 "Do not send outside local AS (well-known community)\n"
8258 "Do not advertise to any peer (well-known community)\n"
8259 "Do not export to next AS (well-known community)\n")
8260
8261ALIAS (show_bgp_community,
8262 show_bgp_ipv6_community3_cmd,
8263 "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)",
8264 SHOW_STR
8265 BGP_STR
8266 "Address family\n"
8267 "Display routes matching the communities\n"
8268 "community number\n"
8269 "Do not send outside local AS (well-known community)\n"
8270 "Do not advertise to any peer (well-known community)\n"
8271 "Do not export to next AS (well-known community)\n"
8272 "community number\n"
8273 "Do not send outside local AS (well-known community)\n"
8274 "Do not advertise to any peer (well-known community)\n"
8275 "Do not export to next AS (well-known community)\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
8281ALIAS (show_bgp_community,
8282 show_bgp_community4_cmd,
8283 "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)",
8284 SHOW_STR
8285 BGP_STR
8286 "Display routes matching the communities\n"
8287 "community number\n"
8288 "Do not send outside local AS (well-known community)\n"
8289 "Do not advertise to any peer (well-known community)\n"
8290 "Do not export to next AS (well-known community)\n"
8291 "community number\n"
8292 "Do not send outside local AS (well-known community)\n"
8293 "Do not advertise to any peer (well-known community)\n"
8294 "Do not export to next AS (well-known community)\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n"
8299 "community number\n"
8300 "Do not send outside local AS (well-known community)\n"
8301 "Do not advertise to any peer (well-known community)\n"
8302 "Do not export to next AS (well-known community)\n")
8303
8304ALIAS (show_bgp_community,
8305 show_bgp_ipv6_community4_cmd,
8306 "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)",
8307 SHOW_STR
8308 BGP_STR
8309 "Address family\n"
8310 "Display routes matching the communities\n"
8311 "community number\n"
8312 "Do not send outside local AS (well-known community)\n"
8313 "Do not advertise to any peer (well-known community)\n"
8314 "Do not export to next AS (well-known community)\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
8328/* old command */
8329DEFUN (show_ipv6_bgp_community,
8330 show_ipv6_bgp_community_cmd,
8331 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8332 SHOW_STR
8333 IPV6_STR
8334 BGP_STR
8335 "Display routes matching the communities\n"
8336 "community number\n"
8337 "Do not send outside local AS (well-known community)\n"
8338 "Do not advertise to any peer (well-known community)\n"
8339 "Do not export to next AS (well-known community)\n")
8340{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008341 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008342}
8343
8344/* old command */
8345ALIAS (show_ipv6_bgp_community,
8346 show_ipv6_bgp_community2_cmd,
8347 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8348 SHOW_STR
8349 IPV6_STR
8350 BGP_STR
8351 "Display routes matching the communities\n"
8352 "community number\n"
8353 "Do not send outside local AS (well-known community)\n"
8354 "Do not advertise to any peer (well-known community)\n"
8355 "Do not export to next AS (well-known community)\n"
8356 "community number\n"
8357 "Do not send outside local AS (well-known community)\n"
8358 "Do not advertise to any peer (well-known community)\n"
8359 "Do not export to next AS (well-known community)\n")
8360
8361/* old command */
8362ALIAS (show_ipv6_bgp_community,
8363 show_ipv6_bgp_community3_cmd,
8364 "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)",
8365 SHOW_STR
8366 IPV6_STR
8367 BGP_STR
8368 "Display routes matching the communities\n"
8369 "community number\n"
8370 "Do not send outside local AS (well-known community)\n"
8371 "Do not advertise to any peer (well-known community)\n"
8372 "Do not export to next AS (well-known community)\n"
8373 "community number\n"
8374 "Do not send outside local AS (well-known community)\n"
8375 "Do not advertise to any peer (well-known community)\n"
8376 "Do not export to next AS (well-known community)\n"
8377 "community number\n"
8378 "Do not send outside local AS (well-known community)\n"
8379 "Do not advertise to any peer (well-known community)\n"
8380 "Do not export to next AS (well-known community)\n")
8381
8382/* old command */
8383ALIAS (show_ipv6_bgp_community,
8384 show_ipv6_bgp_community4_cmd,
8385 "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)",
8386 SHOW_STR
8387 IPV6_STR
8388 BGP_STR
8389 "Display routes matching the communities\n"
8390 "community number\n"
8391 "Do not send outside local AS (well-known community)\n"
8392 "Do not advertise to any peer (well-known community)\n"
8393 "Do not export to next AS (well-known community)\n"
8394 "community number\n"
8395 "Do not send outside local AS (well-known community)\n"
8396 "Do not advertise to any peer (well-known community)\n"
8397 "Do not export to next AS (well-known community)\n"
8398 "community number\n"
8399 "Do not send outside local AS (well-known community)\n"
8400 "Do not advertise to any peer (well-known community)\n"
8401 "Do not export to next AS (well-known community)\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n")
8406
8407DEFUN (show_bgp_community_exact,
8408 show_bgp_community_exact_cmd,
8409 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8410 SHOW_STR
8411 BGP_STR
8412 "Display routes matching the communities\n"
8413 "community number\n"
8414 "Do not send outside local AS (well-known community)\n"
8415 "Do not advertise to any peer (well-known community)\n"
8416 "Do not export to next AS (well-known community)\n"
8417 "Exact match of the communities")
8418{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008419 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008420}
8421
8422ALIAS (show_bgp_community_exact,
8423 show_bgp_ipv6_community_exact_cmd,
8424 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8425 SHOW_STR
8426 BGP_STR
8427 "Address family\n"
8428 "Display routes matching the communities\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "Exact match of the communities")
8434
8435ALIAS (show_bgp_community_exact,
8436 show_bgp_community2_exact_cmd,
8437 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (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 "community number\n"
8446 "Do not send outside local AS (well-known community)\n"
8447 "Do not advertise to any peer (well-known community)\n"
8448 "Do not export to next AS (well-known community)\n"
8449 "Exact match of the communities")
8450
8451ALIAS (show_bgp_community_exact,
8452 show_bgp_ipv6_community2_exact_cmd,
8453 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8454 SHOW_STR
8455 BGP_STR
8456 "Address family\n"
8457 "Display routes matching the communities\n"
8458 "community number\n"
8459 "Do not send outside local AS (well-known community)\n"
8460 "Do not advertise to any peer (well-known community)\n"
8461 "Do not export to next AS (well-known community)\n"
8462 "community number\n"
8463 "Do not send outside local AS (well-known community)\n"
8464 "Do not advertise to any peer (well-known community)\n"
8465 "Do not export to next AS (well-known community)\n"
8466 "Exact match of the communities")
8467
8468ALIAS (show_bgp_community_exact,
8469 show_bgp_community3_exact_cmd,
8470 "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",
8471 SHOW_STR
8472 BGP_STR
8473 "Display routes matching the communities\n"
8474 "community number\n"
8475 "Do not send outside local AS (well-known community)\n"
8476 "Do not advertise to any peer (well-known community)\n"
8477 "Do not export to next AS (well-known community)\n"
8478 "community number\n"
8479 "Do not send outside local AS (well-known community)\n"
8480 "Do not advertise to any peer (well-known community)\n"
8481 "Do not export to next AS (well-known community)\n"
8482 "community number\n"
8483 "Do not send outside local AS (well-known community)\n"
8484 "Do not advertise to any peer (well-known community)\n"
8485 "Do not export to next AS (well-known community)\n"
8486 "Exact match of the communities")
8487
8488ALIAS (show_bgp_community_exact,
8489 show_bgp_ipv6_community3_exact_cmd,
8490 "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",
8491 SHOW_STR
8492 BGP_STR
8493 "Address family\n"
8494 "Display routes matching the communities\n"
8495 "community number\n"
8496 "Do not send outside local AS (well-known community)\n"
8497 "Do not advertise to any peer (well-known community)\n"
8498 "Do not export to next AS (well-known community)\n"
8499 "community number\n"
8500 "Do not send outside local AS (well-known community)\n"
8501 "Do not advertise to any peer (well-known community)\n"
8502 "Do not export to next AS (well-known community)\n"
8503 "community number\n"
8504 "Do not send outside local AS (well-known community)\n"
8505 "Do not advertise to any peer (well-known community)\n"
8506 "Do not export to next AS (well-known community)\n"
8507 "Exact match of the communities")
8508
8509ALIAS (show_bgp_community_exact,
8510 show_bgp_community4_exact_cmd,
8511 "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",
8512 SHOW_STR
8513 BGP_STR
8514 "Display routes matching the communities\n"
8515 "community number\n"
8516 "Do not send outside local AS (well-known community)\n"
8517 "Do not advertise to any peer (well-known community)\n"
8518 "Do not export to next AS (well-known community)\n"
8519 "community number\n"
8520 "Do not send outside local AS (well-known community)\n"
8521 "Do not advertise to any peer (well-known community)\n"
8522 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8532
8533ALIAS (show_bgp_community_exact,
8534 show_bgp_ipv6_community4_exact_cmd,
8535 "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",
8536 SHOW_STR
8537 BGP_STR
8538 "Address family\n"
8539 "Display routes matching the communities\n"
8540 "community number\n"
8541 "Do not send outside local AS (well-known community)\n"
8542 "Do not advertise to any peer (well-known community)\n"
8543 "Do not export to next AS (well-known community)\n"
8544 "community number\n"
8545 "Do not send outside local AS (well-known community)\n"
8546 "Do not advertise to any peer (well-known community)\n"
8547 "Do not export to next AS (well-known community)\n"
8548 "community number\n"
8549 "Do not send outside local AS (well-known community)\n"
8550 "Do not advertise to any peer (well-known community)\n"
8551 "Do not export to next AS (well-known community)\n"
8552 "community number\n"
8553 "Do not send outside local AS (well-known community)\n"
8554 "Do not advertise to any peer (well-known community)\n"
8555 "Do not export to next AS (well-known community)\n"
8556 "Exact match of the communities")
8557
8558/* old command */
8559DEFUN (show_ipv6_bgp_community_exact,
8560 show_ipv6_bgp_community_exact_cmd,
8561 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8562 SHOW_STR
8563 IPV6_STR
8564 BGP_STR
8565 "Display routes matching the communities\n"
8566 "community number\n"
8567 "Do not send outside local AS (well-known community)\n"
8568 "Do not advertise to any peer (well-known community)\n"
8569 "Do not export to next AS (well-known community)\n"
8570 "Exact match of the communities")
8571{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008572 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008573}
8574
8575/* old command */
8576ALIAS (show_ipv6_bgp_community_exact,
8577 show_ipv6_bgp_community2_exact_cmd,
8578 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8579 SHOW_STR
8580 IPV6_STR
8581 BGP_STR
8582 "Display routes matching the communities\n"
8583 "community number\n"
8584 "Do not send outside local AS (well-known community)\n"
8585 "Do not advertise to any peer (well-known community)\n"
8586 "Do not export to next AS (well-known community)\n"
8587 "community number\n"
8588 "Do not send outside local AS (well-known community)\n"
8589 "Do not advertise to any peer (well-known community)\n"
8590 "Do not export to next AS (well-known community)\n"
8591 "Exact match of the communities")
8592
8593/* old command */
8594ALIAS (show_ipv6_bgp_community_exact,
8595 show_ipv6_bgp_community3_exact_cmd,
8596 "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",
8597 SHOW_STR
8598 IPV6_STR
8599 BGP_STR
8600 "Display routes matching the communities\n"
8601 "community number\n"
8602 "Do not send outside local AS (well-known community)\n"
8603 "Do not advertise to any peer (well-known community)\n"
8604 "Do not export to next AS (well-known community)\n"
8605 "community number\n"
8606 "Do not send outside local AS (well-known community)\n"
8607 "Do not advertise to any peer (well-known community)\n"
8608 "Do not export to next AS (well-known community)\n"
8609 "community number\n"
8610 "Do not send outside local AS (well-known community)\n"
8611 "Do not advertise to any peer (well-known community)\n"
8612 "Do not export to next AS (well-known community)\n"
8613 "Exact match of the communities")
8614
8615/* old command */
8616ALIAS (show_ipv6_bgp_community_exact,
8617 show_ipv6_bgp_community4_exact_cmd,
8618 "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",
8619 SHOW_STR
8620 IPV6_STR
8621 BGP_STR
8622 "Display routes matching the communities\n"
8623 "community number\n"
8624 "Do not send outside local AS (well-known community)\n"
8625 "Do not advertise to any peer (well-known community)\n"
8626 "Do not export to next AS (well-known community)\n"
8627 "community number\n"
8628 "Do not send outside local AS (well-known community)\n"
8629 "Do not advertise to any peer (well-known community)\n"
8630 "Do not export to next AS (well-known community)\n"
8631 "community number\n"
8632 "Do not send outside local AS (well-known community)\n"
8633 "Do not advertise to any peer (well-known community)\n"
8634 "Do not export to next AS (well-known community)\n"
8635 "community number\n"
8636 "Do not send outside local AS (well-known community)\n"
8637 "Do not advertise to any peer (well-known community)\n"
8638 "Do not export to next AS (well-known community)\n"
8639 "Exact match of the communities")
8640
8641/* old command */
8642DEFUN (show_ipv6_mbgp_community,
8643 show_ipv6_mbgp_community_cmd,
8644 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8645 SHOW_STR
8646 IPV6_STR
8647 MBGP_STR
8648 "Display routes matching the communities\n"
8649 "community number\n"
8650 "Do not send outside local AS (well-known community)\n"
8651 "Do not advertise to any peer (well-known community)\n"
8652 "Do not export to next AS (well-known community)\n")
8653{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008654 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008655}
8656
8657/* old command */
8658ALIAS (show_ipv6_mbgp_community,
8659 show_ipv6_mbgp_community2_cmd,
8660 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8661 SHOW_STR
8662 IPV6_STR
8663 MBGP_STR
8664 "Display routes matching the communities\n"
8665 "community number\n"
8666 "Do not send outside local AS (well-known community)\n"
8667 "Do not advertise to any peer (well-known community)\n"
8668 "Do not export to next AS (well-known community)\n"
8669 "community number\n"
8670 "Do not send outside local AS (well-known community)\n"
8671 "Do not advertise to any peer (well-known community)\n"
8672 "Do not export to next AS (well-known community)\n")
8673
8674/* old command */
8675ALIAS (show_ipv6_mbgp_community,
8676 show_ipv6_mbgp_community3_cmd,
8677 "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)",
8678 SHOW_STR
8679 IPV6_STR
8680 MBGP_STR
8681 "Display routes matching the communities\n"
8682 "community number\n"
8683 "Do not send outside local AS (well-known community)\n"
8684 "Do not advertise to any peer (well-known community)\n"
8685 "Do not export to next AS (well-known community)\n"
8686 "community number\n"
8687 "Do not send outside local AS (well-known community)\n"
8688 "Do not advertise to any peer (well-known community)\n"
8689 "Do not export to next AS (well-known community)\n"
8690 "community number\n"
8691 "Do not send outside local AS (well-known community)\n"
8692 "Do not advertise to any peer (well-known community)\n"
8693 "Do not export to next AS (well-known community)\n")
8694
8695/* old command */
8696ALIAS (show_ipv6_mbgp_community,
8697 show_ipv6_mbgp_community4_cmd,
8698 "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)",
8699 SHOW_STR
8700 IPV6_STR
8701 MBGP_STR
8702 "Display routes matching the communities\n"
8703 "community number\n"
8704 "Do not send outside local AS (well-known community)\n"
8705 "Do not advertise to any peer (well-known community)\n"
8706 "Do not export to next AS (well-known community)\n"
8707 "community number\n"
8708 "Do not send outside local AS (well-known community)\n"
8709 "Do not advertise to any peer (well-known community)\n"
8710 "Do not export to next AS (well-known community)\n"
8711 "community number\n"
8712 "Do not send outside local AS (well-known community)\n"
8713 "Do not advertise to any peer (well-known community)\n"
8714 "Do not export to next AS (well-known community)\n"
8715 "community number\n"
8716 "Do not send outside local AS (well-known community)\n"
8717 "Do not advertise to any peer (well-known community)\n"
8718 "Do not export to next AS (well-known community)\n")
8719
8720/* old command */
8721DEFUN (show_ipv6_mbgp_community_exact,
8722 show_ipv6_mbgp_community_exact_cmd,
8723 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8724 SHOW_STR
8725 IPV6_STR
8726 MBGP_STR
8727 "Display routes matching the communities\n"
8728 "community number\n"
8729 "Do not send outside local AS (well-known community)\n"
8730 "Do not advertise to any peer (well-known community)\n"
8731 "Do not export to next AS (well-known community)\n"
8732 "Exact match of the communities")
8733{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008734 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008735}
8736
8737/* old command */
8738ALIAS (show_ipv6_mbgp_community_exact,
8739 show_ipv6_mbgp_community2_exact_cmd,
8740 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8741 SHOW_STR
8742 IPV6_STR
8743 MBGP_STR
8744 "Display routes matching the communities\n"
8745 "community number\n"
8746 "Do not send outside local AS (well-known community)\n"
8747 "Do not advertise to any peer (well-known community)\n"
8748 "Do not export to next AS (well-known community)\n"
8749 "community number\n"
8750 "Do not send outside local AS (well-known community)\n"
8751 "Do not advertise to any peer (well-known community)\n"
8752 "Do not export to next AS (well-known community)\n"
8753 "Exact match of the communities")
8754
8755/* old command */
8756ALIAS (show_ipv6_mbgp_community_exact,
8757 show_ipv6_mbgp_community3_exact_cmd,
8758 "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",
8759 SHOW_STR
8760 IPV6_STR
8761 MBGP_STR
8762 "Display routes matching the communities\n"
8763 "community number\n"
8764 "Do not send outside local AS (well-known community)\n"
8765 "Do not advertise to any peer (well-known community)\n"
8766 "Do not export to next AS (well-known community)\n"
8767 "community number\n"
8768 "Do not send outside local AS (well-known community)\n"
8769 "Do not advertise to any peer (well-known community)\n"
8770 "Do not export to next AS (well-known community)\n"
8771 "community number\n"
8772 "Do not send outside local AS (well-known community)\n"
8773 "Do not advertise to any peer (well-known community)\n"
8774 "Do not export to next AS (well-known community)\n"
8775 "Exact match of the communities")
8776
8777/* old command */
8778ALIAS (show_ipv6_mbgp_community_exact,
8779 show_ipv6_mbgp_community4_exact_cmd,
8780 "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",
8781 SHOW_STR
8782 IPV6_STR
8783 MBGP_STR
8784 "Display routes matching the communities\n"
8785 "community number\n"
8786 "Do not send outside local AS (well-known community)\n"
8787 "Do not advertise to any peer (well-known community)\n"
8788 "Do not export to next AS (well-known community)\n"
8789 "community number\n"
8790 "Do not send outside local AS (well-known community)\n"
8791 "Do not advertise to any peer (well-known community)\n"
8792 "Do not export to next AS (well-known community)\n"
8793 "community number\n"
8794 "Do not send outside local AS (well-known community)\n"
8795 "Do not advertise to any peer (well-known community)\n"
8796 "Do not export to next AS (well-known community)\n"
8797 "community number\n"
8798 "Do not send outside local AS (well-known community)\n"
8799 "Do not advertise to any peer (well-known community)\n"
8800 "Do not export to next AS (well-known community)\n"
8801 "Exact match of the communities")
8802#endif /* HAVE_IPV6 */
8803
paul94f2b392005-06-28 12:44:16 +00008804static int
paulfd79ac92004-10-13 05:06:08 +00008805bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008806 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008807{
8808 struct community_list *list;
8809
hassofee6e4e2005-02-02 16:29:31 +00008810 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008811 if (list == NULL)
8812 {
8813 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8814 VTY_NEWLINE);
8815 return CMD_WARNING;
8816 }
8817
ajs5a646652004-11-05 01:25:55 +00008818 return bgp_show (vty, NULL, afi, safi,
8819 (exact ? bgp_show_type_community_list_exact :
8820 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008821}
8822
8823DEFUN (show_ip_bgp_community_list,
8824 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008825 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008826 SHOW_STR
8827 IP_STR
8828 BGP_STR
8829 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008830 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008831 "community-list name\n")
8832{
8833 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8834}
8835
8836DEFUN (show_ip_bgp_ipv4_community_list,
8837 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008838 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008839 SHOW_STR
8840 IP_STR
8841 BGP_STR
8842 "Address family\n"
8843 "Address Family modifier\n"
8844 "Address Family modifier\n"
8845 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008846 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008847 "community-list name\n")
8848{
8849 if (strncmp (argv[0], "m", 1) == 0)
8850 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8851
8852 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8853}
8854
8855DEFUN (show_ip_bgp_community_list_exact,
8856 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008857 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008858 SHOW_STR
8859 IP_STR
8860 BGP_STR
8861 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008862 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008863 "community-list name\n"
8864 "Exact match of the communities\n")
8865{
8866 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8867}
8868
8869DEFUN (show_ip_bgp_ipv4_community_list_exact,
8870 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008871 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008872 SHOW_STR
8873 IP_STR
8874 BGP_STR
8875 "Address family\n"
8876 "Address Family modifier\n"
8877 "Address Family modifier\n"
8878 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008879 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008880 "community-list name\n"
8881 "Exact match of the communities\n")
8882{
8883 if (strncmp (argv[0], "m", 1) == 0)
8884 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8885
8886 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8887}
8888
8889#ifdef HAVE_IPV6
8890DEFUN (show_bgp_community_list,
8891 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008892 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008893 SHOW_STR
8894 BGP_STR
8895 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008896 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008897 "community-list name\n")
8898{
8899 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8900}
8901
8902ALIAS (show_bgp_community_list,
8903 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008904 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008905 SHOW_STR
8906 BGP_STR
8907 "Address family\n"
8908 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008909 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008910 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008911
8912/* old command */
8913DEFUN (show_ipv6_bgp_community_list,
8914 show_ipv6_bgp_community_list_cmd,
8915 "show ipv6 bgp community-list WORD",
8916 SHOW_STR
8917 IPV6_STR
8918 BGP_STR
8919 "Display routes matching the community-list\n"
8920 "community-list name\n")
8921{
8922 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8923}
8924
8925/* old command */
8926DEFUN (show_ipv6_mbgp_community_list,
8927 show_ipv6_mbgp_community_list_cmd,
8928 "show ipv6 mbgp community-list WORD",
8929 SHOW_STR
8930 IPV6_STR
8931 MBGP_STR
8932 "Display routes matching the community-list\n"
8933 "community-list name\n")
8934{
8935 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8936}
8937
8938DEFUN (show_bgp_community_list_exact,
8939 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008940 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008941 SHOW_STR
8942 BGP_STR
8943 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008944 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008945 "community-list name\n"
8946 "Exact match of the communities\n")
8947{
8948 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8949}
8950
8951ALIAS (show_bgp_community_list_exact,
8952 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008953 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008954 SHOW_STR
8955 BGP_STR
8956 "Address family\n"
8957 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008958 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008959 "community-list name\n"
8960 "Exact match of the communities\n")
8961
8962/* old command */
8963DEFUN (show_ipv6_bgp_community_list_exact,
8964 show_ipv6_bgp_community_list_exact_cmd,
8965 "show ipv6 bgp community-list WORD exact-match",
8966 SHOW_STR
8967 IPV6_STR
8968 BGP_STR
8969 "Display routes matching the community-list\n"
8970 "community-list name\n"
8971 "Exact match of the communities\n")
8972{
8973 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8974}
8975
8976/* old command */
8977DEFUN (show_ipv6_mbgp_community_list_exact,
8978 show_ipv6_mbgp_community_list_exact_cmd,
8979 "show ipv6 mbgp community-list WORD exact-match",
8980 SHOW_STR
8981 IPV6_STR
8982 MBGP_STR
8983 "Display routes matching the community-list\n"
8984 "community-list name\n"
8985 "Exact match of the communities\n")
8986{
8987 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8988}
8989#endif /* HAVE_IPV6 */
8990
paul94f2b392005-06-28 12:44:16 +00008991static int
paulfd79ac92004-10-13 05:06:08 +00008992bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008993 safi_t safi, enum bgp_show_type type)
8994{
8995 int ret;
8996 struct prefix *p;
8997
8998 p = prefix_new();
8999
9000 ret = str2prefix (prefix, p);
9001 if (! ret)
9002 {
9003 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
9004 return CMD_WARNING;
9005 }
9006
ajs5a646652004-11-05 01:25:55 +00009007 ret = bgp_show (vty, NULL, afi, safi, type, p);
9008 prefix_free(p);
9009 return ret;
paul718e3742002-12-13 20:15:29 +00009010}
9011
9012DEFUN (show_ip_bgp_prefix_longer,
9013 show_ip_bgp_prefix_longer_cmd,
9014 "show ip bgp A.B.C.D/M longer-prefixes",
9015 SHOW_STR
9016 IP_STR
9017 BGP_STR
9018 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9019 "Display route and more specific routes\n")
9020{
9021 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9022 bgp_show_type_prefix_longer);
9023}
9024
9025DEFUN (show_ip_bgp_flap_prefix_longer,
9026 show_ip_bgp_flap_prefix_longer_cmd,
9027 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9028 SHOW_STR
9029 IP_STR
9030 BGP_STR
9031 "Display flap statistics of routes\n"
9032 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9033 "Display route and more specific routes\n")
9034{
9035 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9036 bgp_show_type_flap_prefix_longer);
9037}
9038
9039DEFUN (show_ip_bgp_ipv4_prefix_longer,
9040 show_ip_bgp_ipv4_prefix_longer_cmd,
9041 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9042 SHOW_STR
9043 IP_STR
9044 BGP_STR
9045 "Address family\n"
9046 "Address Family modifier\n"
9047 "Address Family modifier\n"
9048 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9049 "Display route and more specific routes\n")
9050{
9051 if (strncmp (argv[0], "m", 1) == 0)
9052 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9053 bgp_show_type_prefix_longer);
9054
9055 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9056 bgp_show_type_prefix_longer);
9057}
9058
9059DEFUN (show_ip_bgp_flap_address,
9060 show_ip_bgp_flap_address_cmd,
9061 "show ip bgp flap-statistics A.B.C.D",
9062 SHOW_STR
9063 IP_STR
9064 BGP_STR
9065 "Display flap statistics of routes\n"
9066 "Network in the BGP routing table to display\n")
9067{
9068 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9069 bgp_show_type_flap_address);
9070}
9071
9072DEFUN (show_ip_bgp_flap_prefix,
9073 show_ip_bgp_flap_prefix_cmd,
9074 "show ip bgp flap-statistics A.B.C.D/M",
9075 SHOW_STR
9076 IP_STR
9077 BGP_STR
9078 "Display flap statistics of routes\n"
9079 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9080{
9081 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9082 bgp_show_type_flap_prefix);
9083}
9084#ifdef HAVE_IPV6
9085DEFUN (show_bgp_prefix_longer,
9086 show_bgp_prefix_longer_cmd,
9087 "show bgp X:X::X:X/M longer-prefixes",
9088 SHOW_STR
9089 BGP_STR
9090 "IPv6 prefix <network>/<length>\n"
9091 "Display route and more specific routes\n")
9092{
9093 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9094 bgp_show_type_prefix_longer);
9095}
9096
9097ALIAS (show_bgp_prefix_longer,
9098 show_bgp_ipv6_prefix_longer_cmd,
9099 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9100 SHOW_STR
9101 BGP_STR
9102 "Address family\n"
9103 "IPv6 prefix <network>/<length>\n"
9104 "Display route and more specific routes\n")
9105
9106/* old command */
9107DEFUN (show_ipv6_bgp_prefix_longer,
9108 show_ipv6_bgp_prefix_longer_cmd,
9109 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9110 SHOW_STR
9111 IPV6_STR
9112 BGP_STR
9113 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9114 "Display route and more specific routes\n")
9115{
9116 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9117 bgp_show_type_prefix_longer);
9118}
9119
9120/* old command */
9121DEFUN (show_ipv6_mbgp_prefix_longer,
9122 show_ipv6_mbgp_prefix_longer_cmd,
9123 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9124 SHOW_STR
9125 IPV6_STR
9126 MBGP_STR
9127 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9128 "Display route and more specific routes\n")
9129{
9130 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9131 bgp_show_type_prefix_longer);
9132}
9133#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009134
paul94f2b392005-06-28 12:44:16 +00009135static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009136peer_lookup_in_view (struct vty *vty, const char *view_name,
9137 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009138{
9139 int ret;
9140 struct bgp *bgp;
9141 struct peer *peer;
9142 union sockunion su;
9143
9144 /* BGP structure lookup. */
9145 if (view_name)
9146 {
9147 bgp = bgp_lookup_by_name (view_name);
9148 if (! bgp)
9149 {
9150 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9151 return NULL;
9152 }
9153 }
paul5228ad22004-06-04 17:58:18 +00009154 else
paulbb46e942003-10-24 19:02:03 +00009155 {
9156 bgp = bgp_get_default ();
9157 if (! bgp)
9158 {
9159 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9160 return NULL;
9161 }
9162 }
9163
9164 /* Get peer sockunion. */
9165 ret = str2sockunion (ip_str, &su);
9166 if (ret < 0)
9167 {
9168 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9169 return NULL;
9170 }
9171
9172 /* Peer structure lookup. */
9173 peer = peer_lookup (bgp, &su);
9174 if (! peer)
9175 {
9176 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9177 return NULL;
9178 }
9179
9180 return peer;
9181}
Paul Jakma2815e612006-09-14 02:56:07 +00009182
9183enum bgp_stats
9184{
9185 BGP_STATS_MAXBITLEN = 0,
9186 BGP_STATS_RIB,
9187 BGP_STATS_PREFIXES,
9188 BGP_STATS_TOTPLEN,
9189 BGP_STATS_UNAGGREGATEABLE,
9190 BGP_STATS_MAX_AGGREGATEABLE,
9191 BGP_STATS_AGGREGATES,
9192 BGP_STATS_SPACE,
9193 BGP_STATS_ASPATH_COUNT,
9194 BGP_STATS_ASPATH_MAXHOPS,
9195 BGP_STATS_ASPATH_TOTHOPS,
9196 BGP_STATS_ASPATH_MAXSIZE,
9197 BGP_STATS_ASPATH_TOTSIZE,
9198 BGP_STATS_ASN_HIGHEST,
9199 BGP_STATS_MAX,
9200};
paulbb46e942003-10-24 19:02:03 +00009201
Paul Jakma2815e612006-09-14 02:56:07 +00009202static const char *table_stats_strs[] =
9203{
9204 [BGP_STATS_PREFIXES] = "Total Prefixes",
9205 [BGP_STATS_TOTPLEN] = "Average prefix length",
9206 [BGP_STATS_RIB] = "Total Advertisements",
9207 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9208 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9209 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9210 [BGP_STATS_SPACE] = "Address space advertised",
9211 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9212 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9213 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9214 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9215 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9216 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9217 [BGP_STATS_MAX] = NULL,
9218};
9219
9220struct bgp_table_stats
9221{
9222 struct bgp_table *table;
9223 unsigned long long counts[BGP_STATS_MAX];
9224};
9225
9226#if 0
9227#define TALLY_SIGFIG 100000
9228static unsigned long
9229ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9230{
9231 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9232 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9233 unsigned long ret = newtot / count;
9234
9235 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9236 return ret + 1;
9237 else
9238 return ret;
9239}
9240#endif
9241
9242static int
9243bgp_table_stats_walker (struct thread *t)
9244{
9245 struct bgp_node *rn;
9246 struct bgp_node *top;
9247 struct bgp_table_stats *ts = THREAD_ARG (t);
9248 unsigned int space = 0;
9249
Paul Jakma53d9f672006-10-15 23:41:16 +00009250 if (!(top = bgp_table_top (ts->table)))
9251 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009252
9253 switch (top->p.family)
9254 {
9255 case AF_INET:
9256 space = IPV4_MAX_BITLEN;
9257 break;
9258 case AF_INET6:
9259 space = IPV6_MAX_BITLEN;
9260 break;
9261 }
9262
9263 ts->counts[BGP_STATS_MAXBITLEN] = space;
9264
9265 for (rn = top; rn; rn = bgp_route_next (rn))
9266 {
9267 struct bgp_info *ri;
9268 struct bgp_node *prn = rn->parent;
9269 unsigned int rinum = 0;
9270
9271 if (rn == top)
9272 continue;
9273
9274 if (!rn->info)
9275 continue;
9276
9277 ts->counts[BGP_STATS_PREFIXES]++;
9278 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9279
9280#if 0
9281 ts->counts[BGP_STATS_AVGPLEN]
9282 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9283 ts->counts[BGP_STATS_AVGPLEN],
9284 rn->p.prefixlen);
9285#endif
9286
9287 /* check if the prefix is included by any other announcements */
9288 while (prn && !prn->info)
9289 prn = prn->parent;
9290
9291 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009292 {
9293 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9294 /* announced address space */
9295 if (space)
9296 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9297 }
Paul Jakma2815e612006-09-14 02:56:07 +00009298 else if (prn->info)
9299 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9300
Paul Jakma2815e612006-09-14 02:56:07 +00009301 for (ri = rn->info; ri; ri = ri->next)
9302 {
9303 rinum++;
9304 ts->counts[BGP_STATS_RIB]++;
9305
9306 if (ri->attr &&
9307 (CHECK_FLAG (ri->attr->flag,
9308 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9309 ts->counts[BGP_STATS_AGGREGATES]++;
9310
9311 /* as-path stats */
9312 if (ri->attr && ri->attr->aspath)
9313 {
9314 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9315 unsigned int size = aspath_size (ri->attr->aspath);
9316 as_t highest = aspath_highest (ri->attr->aspath);
9317
9318 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9319
9320 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9321 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9322
9323 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9324 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9325
9326 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9327 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9328#if 0
9329 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9330 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9331 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9332 hops);
9333 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9334 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9335 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9336 size);
9337#endif
9338 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9339 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9340 }
9341 }
9342 }
9343 return 0;
9344}
9345
9346static int
9347bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9348{
9349 struct bgp_table_stats ts;
9350 unsigned int i;
9351
9352 if (!bgp->rib[afi][safi])
9353 {
9354 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9355 return CMD_WARNING;
9356 }
9357
9358 memset (&ts, 0, sizeof (ts));
9359 ts.table = bgp->rib[afi][safi];
9360 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9361
9362 vty_out (vty, "BGP %s RIB statistics%s%s",
9363 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9364
9365 for (i = 0; i < BGP_STATS_MAX; i++)
9366 {
9367 if (!table_stats_strs[i])
9368 continue;
9369
9370 switch (i)
9371 {
9372#if 0
9373 case BGP_STATS_ASPATH_AVGHOPS:
9374 case BGP_STATS_ASPATH_AVGSIZE:
9375 case BGP_STATS_AVGPLEN:
9376 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9377 vty_out (vty, "%12.2f",
9378 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9379 break;
9380#endif
9381 case BGP_STATS_ASPATH_TOTHOPS:
9382 case BGP_STATS_ASPATH_TOTSIZE:
9383 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9384 vty_out (vty, "%12.2f",
9385 ts.counts[i] ?
9386 (float)ts.counts[i] /
9387 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9388 : 0);
9389 break;
9390 case BGP_STATS_TOTPLEN:
9391 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9392 vty_out (vty, "%12.2f",
9393 ts.counts[i] ?
9394 (float)ts.counts[i] /
9395 (float)ts.counts[BGP_STATS_PREFIXES]
9396 : 0);
9397 break;
9398 case BGP_STATS_SPACE:
9399 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9400 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9401 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9402 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009403 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009404 vty_out (vty, "%12.2f%s",
9405 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009406 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009407 VTY_NEWLINE);
9408 vty_out (vty, "%30s: ", "/8 equivalent ");
9409 vty_out (vty, "%12.2f%s",
9410 (float)ts.counts[BGP_STATS_SPACE] /
9411 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9412 VTY_NEWLINE);
9413 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9414 break;
9415 vty_out (vty, "%30s: ", "/24 equivalent ");
9416 vty_out (vty, "%12.2f",
9417 (float)ts.counts[BGP_STATS_SPACE] /
9418 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9419 break;
9420 default:
9421 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9422 vty_out (vty, "%12llu", ts.counts[i]);
9423 }
9424
9425 vty_out (vty, "%s", VTY_NEWLINE);
9426 }
9427 return CMD_SUCCESS;
9428}
9429
9430static int
9431bgp_table_stats_vty (struct vty *vty, const char *name,
9432 const char *afi_str, const char *safi_str)
9433{
9434 struct bgp *bgp;
9435 afi_t afi;
9436 safi_t safi;
9437
9438 if (name)
9439 bgp = bgp_lookup_by_name (name);
9440 else
9441 bgp = bgp_get_default ();
9442
9443 if (!bgp)
9444 {
9445 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9446 return CMD_WARNING;
9447 }
9448 if (strncmp (afi_str, "ipv", 3) == 0)
9449 {
9450 if (strncmp (afi_str, "ipv4", 4) == 0)
9451 afi = AFI_IP;
9452 else if (strncmp (afi_str, "ipv6", 4) == 0)
9453 afi = AFI_IP6;
9454 else
9455 {
9456 vty_out (vty, "%% Invalid address family %s%s",
9457 afi_str, VTY_NEWLINE);
9458 return CMD_WARNING;
9459 }
9460 if (strncmp (safi_str, "m", 1) == 0)
9461 safi = SAFI_MULTICAST;
9462 else if (strncmp (safi_str, "u", 1) == 0)
9463 safi = SAFI_UNICAST;
9464 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9465 safi = BGP_SAFI_VPNV4;
9466 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9467 safi = BGP_SAFI_VPNV6;
9468 else
9469 {
9470 vty_out (vty, "%% Invalid subsequent address family %s%s",
9471 safi_str, VTY_NEWLINE);
9472 return CMD_WARNING;
9473 }
9474 }
9475 else
9476 {
9477 vty_out (vty, "%% Invalid address family %s%s",
9478 afi_str, VTY_NEWLINE);
9479 return CMD_WARNING;
9480 }
9481
9482 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9483 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9484 {
9485 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9486 afi_str, safi_str, VTY_NEWLINE);
9487 return CMD_WARNING;
9488 }
9489 return bgp_table_stats (vty, bgp, afi, safi);
9490}
9491
9492DEFUN (show_bgp_statistics,
9493 show_bgp_statistics_cmd,
9494 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9495 SHOW_STR
9496 BGP_STR
9497 "Address family\n"
9498 "Address family\n"
9499 "Address Family modifier\n"
9500 "Address Family modifier\n"
9501 "BGP RIB advertisement statistics\n")
9502{
9503 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9504}
9505
9506ALIAS (show_bgp_statistics,
9507 show_bgp_statistics_vpnv4_cmd,
9508 "show bgp (ipv4) (vpnv4) statistics",
9509 SHOW_STR
9510 BGP_STR
9511 "Address family\n"
9512 "Address Family modifier\n"
9513 "BGP RIB advertisement statistics\n")
9514
9515DEFUN (show_bgp_statistics_view,
9516 show_bgp_statistics_view_cmd,
9517 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9518 SHOW_STR
9519 BGP_STR
9520 "BGP view\n"
9521 "Address family\n"
9522 "Address family\n"
9523 "Address Family modifier\n"
9524 "Address Family modifier\n"
9525 "BGP RIB advertisement statistics\n")
9526{
9527 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9528}
9529
9530ALIAS (show_bgp_statistics_view,
9531 show_bgp_statistics_view_vpnv4_cmd,
9532 "show bgp view WORD (ipv4) (vpnv4) statistics",
9533 SHOW_STR
9534 BGP_STR
9535 "BGP view\n"
9536 "Address family\n"
9537 "Address Family modifier\n"
9538 "BGP RIB advertisement statistics\n")
9539
Paul Jakmaff7924f2006-09-04 01:10:36 +00009540enum bgp_pcounts
9541{
9542 PCOUNT_ADJ_IN = 0,
9543 PCOUNT_DAMPED,
9544 PCOUNT_REMOVED,
9545 PCOUNT_HISTORY,
9546 PCOUNT_STALE,
9547 PCOUNT_VALID,
9548 PCOUNT_ALL,
9549 PCOUNT_COUNTED,
9550 PCOUNT_PFCNT, /* the figure we display to users */
9551 PCOUNT_MAX,
9552};
9553
9554static const char *pcount_strs[] =
9555{
9556 [PCOUNT_ADJ_IN] = "Adj-in",
9557 [PCOUNT_DAMPED] = "Damped",
9558 [PCOUNT_REMOVED] = "Removed",
9559 [PCOUNT_HISTORY] = "History",
9560 [PCOUNT_STALE] = "Stale",
9561 [PCOUNT_VALID] = "Valid",
9562 [PCOUNT_ALL] = "All RIB",
9563 [PCOUNT_COUNTED] = "PfxCt counted",
9564 [PCOUNT_PFCNT] = "Useable",
9565 [PCOUNT_MAX] = NULL,
9566};
9567
Paul Jakma2815e612006-09-14 02:56:07 +00009568struct peer_pcounts
9569{
9570 unsigned int count[PCOUNT_MAX];
9571 const struct peer *peer;
9572 const struct bgp_table *table;
9573};
9574
Paul Jakmaff7924f2006-09-04 01:10:36 +00009575static int
Paul Jakma2815e612006-09-14 02:56:07 +00009576bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009577{
9578 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009579 struct peer_pcounts *pc = THREAD_ARG (t);
9580 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009581
Paul Jakma2815e612006-09-14 02:56:07 +00009582 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009583 {
9584 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009585 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009586
9587 for (ain = rn->adj_in; ain; ain = ain->next)
9588 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009589 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009590
Paul Jakmaff7924f2006-09-04 01:10:36 +00009591 for (ri = rn->info; ri; ri = ri->next)
9592 {
9593 char buf[SU_ADDRSTRLEN];
9594
9595 if (ri->peer != peer)
9596 continue;
9597
Paul Jakma2815e612006-09-14 02:56:07 +00009598 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009599
9600 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009601 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009602 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009603 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009604 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009605 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009606 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009607 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009608 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009609 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009610 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009611 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009612
9613 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9614 {
Paul Jakma2815e612006-09-14 02:56:07 +00009615 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009616 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009617 plog_warn (peer->log,
9618 "%s [pcount] %s/%d is counted but flags 0x%x",
9619 peer->host,
9620 inet_ntop(rn->p.family, &rn->p.u.prefix,
9621 buf, SU_ADDRSTRLEN),
9622 rn->p.prefixlen,
9623 ri->flags);
9624 }
9625 else
9626 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009627 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009628 plog_warn (peer->log,
9629 "%s [pcount] %s/%d not counted but flags 0x%x",
9630 peer->host,
9631 inet_ntop(rn->p.family, &rn->p.u.prefix,
9632 buf, SU_ADDRSTRLEN),
9633 rn->p.prefixlen,
9634 ri->flags);
9635 }
9636 }
9637 }
Paul Jakma2815e612006-09-14 02:56:07 +00009638 return 0;
9639}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009640
Paul Jakma2815e612006-09-14 02:56:07 +00009641static int
9642bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9643{
9644 struct peer_pcounts pcounts = { .peer = peer };
9645 unsigned int i;
9646
9647 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9648 || !peer->bgp->rib[afi][safi])
9649 {
9650 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9651 return CMD_WARNING;
9652 }
9653
9654 memset (&pcounts, 0, sizeof(pcounts));
9655 pcounts.peer = peer;
9656 pcounts.table = peer->bgp->rib[afi][safi];
9657
9658 /* in-place call via thread subsystem so as to record execution time
9659 * stats for the thread-walk (i.e. ensure this can't be blamed on
9660 * on just vty_read()).
9661 */
9662 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9663
Paul Jakmaff7924f2006-09-04 01:10:36 +00009664 vty_out (vty, "Prefix counts for %s, %s%s",
9665 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9666 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9667 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9668 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9669
9670 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009671 vty_out (vty, "%20s: %-10d%s",
9672 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009673
Paul Jakma2815e612006-09-14 02:56:07 +00009674 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009675 {
9676 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9677 peer->host, VTY_NEWLINE);
9678 vty_out (vty, "Please report this bug, with the above command output%s",
9679 VTY_NEWLINE);
9680 }
9681
9682 return CMD_SUCCESS;
9683}
9684
9685DEFUN (show_ip_bgp_neighbor_prefix_counts,
9686 show_ip_bgp_neighbor_prefix_counts_cmd,
9687 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9688 SHOW_STR
9689 IP_STR
9690 BGP_STR
9691 "Detailed information on TCP and BGP neighbor connections\n"
9692 "Neighbor to display information about\n"
9693 "Neighbor to display information about\n"
9694 "Display detailed prefix count information\n")
9695{
9696 struct peer *peer;
9697
9698 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9699 if (! peer)
9700 return CMD_WARNING;
9701
9702 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9703}
9704
9705DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9706 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9707 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9708 SHOW_STR
9709 BGP_STR
9710 "Address family\n"
9711 "Detailed information on TCP and BGP neighbor connections\n"
9712 "Neighbor to display information about\n"
9713 "Neighbor to display information about\n"
9714 "Display detailed prefix count information\n")
9715{
9716 struct peer *peer;
9717
9718 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9719 if (! peer)
9720 return CMD_WARNING;
9721
9722 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9723}
9724
9725DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9726 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9727 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9728 SHOW_STR
9729 IP_STR
9730 BGP_STR
9731 "Address family\n"
9732 "Address Family modifier\n"
9733 "Address Family modifier\n"
9734 "Detailed information on TCP and BGP neighbor connections\n"
9735 "Neighbor to display information about\n"
9736 "Neighbor to display information about\n"
9737 "Display detailed prefix count information\n")
9738{
9739 struct peer *peer;
9740
9741 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9742 if (! peer)
9743 return CMD_WARNING;
9744
9745 if (strncmp (argv[0], "m", 1) == 0)
9746 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9747
9748 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9749}
9750
9751DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9752 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9753 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9754 SHOW_STR
9755 IP_STR
9756 BGP_STR
9757 "Address family\n"
9758 "Address Family modifier\n"
9759 "Address Family modifier\n"
9760 "Detailed information on TCP and BGP neighbor connections\n"
9761 "Neighbor to display information about\n"
9762 "Neighbor to display information about\n"
9763 "Display detailed prefix count information\n")
9764{
9765 struct peer *peer;
9766
9767 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9768 if (! peer)
9769 return CMD_WARNING;
9770
9771 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9772}
9773
9774
paul94f2b392005-06-28 12:44:16 +00009775static void
paul718e3742002-12-13 20:15:29 +00009776show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9777 int in)
9778{
9779 struct bgp_table *table;
9780 struct bgp_adj_in *ain;
9781 struct bgp_adj_out *adj;
9782 unsigned long output_count;
9783 struct bgp_node *rn;
9784 int header1 = 1;
9785 struct bgp *bgp;
9786 int header2 = 1;
9787
paulbb46e942003-10-24 19:02:03 +00009788 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009789
9790 if (! bgp)
9791 return;
9792
9793 table = bgp->rib[afi][safi];
9794
9795 output_count = 0;
9796
9797 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9798 PEER_STATUS_DEFAULT_ORIGINATE))
9799 {
9800 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 +00009801 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9802 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009803
9804 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9805 VTY_NEWLINE, VTY_NEWLINE);
9806 header1 = 0;
9807 }
9808
9809 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9810 if (in)
9811 {
9812 for (ain = rn->adj_in; ain; ain = ain->next)
9813 if (ain->peer == peer)
9814 {
9815 if (header1)
9816 {
9817 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 +00009818 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9819 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009820 header1 = 0;
9821 }
9822 if (header2)
9823 {
9824 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9825 header2 = 0;
9826 }
9827 if (ain->attr)
9828 {
9829 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9830 output_count++;
9831 }
9832 }
9833 }
9834 else
9835 {
9836 for (adj = rn->adj_out; adj; adj = adj->next)
9837 if (adj->peer == peer)
9838 {
9839 if (header1)
9840 {
9841 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 +00009842 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9843 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009844 header1 = 0;
9845 }
9846 if (header2)
9847 {
9848 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9849 header2 = 0;
9850 }
9851 if (adj->attr)
9852 {
9853 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9854 output_count++;
9855 }
9856 }
9857 }
9858
9859 if (output_count != 0)
9860 vty_out (vty, "%sTotal number of prefixes %ld%s",
9861 VTY_NEWLINE, output_count, VTY_NEWLINE);
9862}
9863
paul94f2b392005-06-28 12:44:16 +00009864static int
paulbb46e942003-10-24 19:02:03 +00009865peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9866{
paul718e3742002-12-13 20:15:29 +00009867 if (! peer || ! peer->afc[afi][safi])
9868 {
9869 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9870 return CMD_WARNING;
9871 }
9872
9873 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9874 {
9875 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9876 VTY_NEWLINE);
9877 return CMD_WARNING;
9878 }
9879
9880 show_adj_route (vty, peer, afi, safi, in);
9881
9882 return CMD_SUCCESS;
9883}
9884
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009885DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9886 show_ip_bgp_view_neighbor_advertised_route_cmd,
9887 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9888 SHOW_STR
9889 IP_STR
9890 BGP_STR
9891 "BGP view\n"
9892 "View name\n"
9893 "Detailed information on TCP and BGP neighbor connections\n"
9894 "Neighbor to display information about\n"
9895 "Neighbor to display information about\n"
9896 "Display the routes advertised to a BGP neighbor\n")
9897{
9898 struct peer *peer;
9899
9900 if (argc == 2)
9901 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9902 else
9903 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9904
9905 if (! peer)
9906 return CMD_WARNING;
9907
9908 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9909}
9910
9911ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009912 show_ip_bgp_neighbor_advertised_route_cmd,
9913 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9914 SHOW_STR
9915 IP_STR
9916 BGP_STR
9917 "Detailed information on TCP and BGP neighbor connections\n"
9918 "Neighbor to display information about\n"
9919 "Neighbor to display information about\n"
9920 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009921
9922DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9923 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9924 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9925 SHOW_STR
9926 IP_STR
9927 BGP_STR
9928 "Address family\n"
9929 "Address Family modifier\n"
9930 "Address Family modifier\n"
9931 "Detailed information on TCP and BGP neighbor connections\n"
9932 "Neighbor to display information about\n"
9933 "Neighbor to display information about\n"
9934 "Display the routes advertised to a BGP neighbor\n")
9935{
paulbb46e942003-10-24 19:02:03 +00009936 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009937
paulbb46e942003-10-24 19:02:03 +00009938 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9939 if (! peer)
9940 return CMD_WARNING;
9941
9942 if (strncmp (argv[0], "m", 1) == 0)
9943 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9944
9945 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009946}
9947
9948#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009949DEFUN (show_bgp_view_neighbor_advertised_route,
9950 show_bgp_view_neighbor_advertised_route_cmd,
9951 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9952 SHOW_STR
9953 BGP_STR
9954 "BGP view\n"
9955 "View name\n"
9956 "Detailed information on TCP and BGP neighbor connections\n"
9957 "Neighbor to display information about\n"
9958 "Neighbor to display information about\n"
9959 "Display the routes advertised to a BGP neighbor\n")
9960{
9961 struct peer *peer;
9962
9963 if (argc == 2)
9964 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9965 else
9966 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9967
9968 if (! peer)
9969 return CMD_WARNING;
9970
9971 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9972}
9973
9974ALIAS (show_bgp_view_neighbor_advertised_route,
9975 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9976 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9977 SHOW_STR
9978 BGP_STR
9979 "BGP view\n"
9980 "View name\n"
9981 "Address family\n"
9982 "Detailed information on TCP and BGP neighbor connections\n"
9983 "Neighbor to display information about\n"
9984 "Neighbor to display information about\n"
9985 "Display the routes advertised to a BGP neighbor\n")
9986
9987DEFUN (show_bgp_view_neighbor_received_routes,
9988 show_bgp_view_neighbor_received_routes_cmd,
9989 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9990 SHOW_STR
9991 BGP_STR
9992 "BGP view\n"
9993 "View name\n"
9994 "Detailed information on TCP and BGP neighbor connections\n"
9995 "Neighbor to display information about\n"
9996 "Neighbor to display information about\n"
9997 "Display the received routes from neighbor\n")
9998{
9999 struct peer *peer;
10000
10001 if (argc == 2)
10002 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10003 else
10004 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10005
10006 if (! peer)
10007 return CMD_WARNING;
10008
10009 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10010}
10011
10012ALIAS (show_bgp_view_neighbor_received_routes,
10013 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10014 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10015 SHOW_STR
10016 BGP_STR
10017 "BGP view\n"
10018 "View name\n"
10019 "Address family\n"
10020 "Detailed information on TCP and BGP neighbor connections\n"
10021 "Neighbor to display information about\n"
10022 "Neighbor to display information about\n"
10023 "Display the received routes from neighbor\n")
10024
10025ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010026 show_bgp_neighbor_advertised_route_cmd,
10027 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10028 SHOW_STR
10029 BGP_STR
10030 "Detailed information on TCP and BGP neighbor connections\n"
10031 "Neighbor to display information about\n"
10032 "Neighbor to display information about\n"
10033 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010034
10035ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010036 show_bgp_ipv6_neighbor_advertised_route_cmd,
10037 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10038 SHOW_STR
10039 BGP_STR
10040 "Address family\n"
10041 "Detailed information on TCP and BGP neighbor connections\n"
10042 "Neighbor to display information about\n"
10043 "Neighbor to display information about\n"
10044 "Display the routes advertised to a BGP neighbor\n")
10045
10046/* old command */
paulbb46e942003-10-24 19:02:03 +000010047ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010048 ipv6_bgp_neighbor_advertised_route_cmd,
10049 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10050 SHOW_STR
10051 IPV6_STR
10052 BGP_STR
10053 "Detailed information on TCP and BGP neighbor connections\n"
10054 "Neighbor to display information about\n"
10055 "Neighbor to display information about\n"
10056 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010057
paul718e3742002-12-13 20:15:29 +000010058/* old command */
10059DEFUN (ipv6_mbgp_neighbor_advertised_route,
10060 ipv6_mbgp_neighbor_advertised_route_cmd,
10061 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10062 SHOW_STR
10063 IPV6_STR
10064 MBGP_STR
10065 "Detailed information on TCP and BGP neighbor connections\n"
10066 "Neighbor to display information about\n"
10067 "Neighbor to display information about\n"
10068 "Display the routes advertised to a BGP neighbor\n")
10069{
paulbb46e942003-10-24 19:02:03 +000010070 struct peer *peer;
10071
10072 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10073 if (! peer)
10074 return CMD_WARNING;
10075
10076 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010077}
10078#endif /* HAVE_IPV6 */
10079
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010080DEFUN (show_ip_bgp_view_neighbor_received_routes,
10081 show_ip_bgp_view_neighbor_received_routes_cmd,
10082 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10083 SHOW_STR
10084 IP_STR
10085 BGP_STR
10086 "BGP view\n"
10087 "View name\n"
10088 "Detailed information on TCP and BGP neighbor connections\n"
10089 "Neighbor to display information about\n"
10090 "Neighbor to display information about\n"
10091 "Display the received routes from neighbor\n")
10092{
10093 struct peer *peer;
10094
10095 if (argc == 2)
10096 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10097 else
10098 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10099
10100 if (! peer)
10101 return CMD_WARNING;
10102
10103 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10104}
10105
10106ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010107 show_ip_bgp_neighbor_received_routes_cmd,
10108 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10109 SHOW_STR
10110 IP_STR
10111 BGP_STR
10112 "Detailed information on TCP and BGP neighbor connections\n"
10113 "Neighbor to display information about\n"
10114 "Neighbor to display information about\n"
10115 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010116
10117DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10118 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10119 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10120 SHOW_STR
10121 IP_STR
10122 BGP_STR
10123 "Address family\n"
10124 "Address Family modifier\n"
10125 "Address Family modifier\n"
10126 "Detailed information on TCP and BGP neighbor connections\n"
10127 "Neighbor to display information about\n"
10128 "Neighbor to display information about\n"
10129 "Display the received routes from neighbor\n")
10130{
paulbb46e942003-10-24 19:02:03 +000010131 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010132
paulbb46e942003-10-24 19:02:03 +000010133 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10134 if (! peer)
10135 return CMD_WARNING;
10136
10137 if (strncmp (argv[0], "m", 1) == 0)
10138 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10139
10140 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010141}
10142
Michael Lambert95cbbd22010-07-23 14:43:04 -040010143DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10144 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10145#ifdef HAVE_IPV6
10146 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10147#else
10148 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10149#endif
10150 SHOW_STR
10151 BGP_STR
10152 "BGP view\n"
10153 "BGP view name\n"
10154 "Address family\n"
10155#ifdef HAVE_IPV6
10156 "Address family\n"
10157#endif
10158 "Address family modifier\n"
10159 "Address family modifier\n"
10160 "Detailed information on TCP and BGP neighbor connections\n"
10161 "Neighbor to display information about\n"
10162 "Neighbor to display information about\n"
10163 "Display the advertised routes to neighbor\n"
10164 "Display the received routes from neighbor\n")
10165{
10166 int afi;
10167 int safi;
10168 int in;
10169 struct peer *peer;
10170
10171#ifdef HAVE_IPV6
10172 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10173#else
10174 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10175#endif
10176
10177 if (! peer)
10178 return CMD_WARNING;
10179
10180#ifdef HAVE_IPV6
10181 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10182 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10183 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10184#else
10185 afi = AFI_IP;
10186 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10187 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10188#endif
10189
10190 return peer_adj_routes (vty, peer, afi, safi, in);
10191}
10192
paul718e3742002-12-13 20:15:29 +000010193DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10194 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10195 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10196 SHOW_STR
10197 IP_STR
10198 BGP_STR
10199 "Detailed information on TCP and BGP neighbor connections\n"
10200 "Neighbor to display information about\n"
10201 "Neighbor to display information about\n"
10202 "Display information received from a BGP neighbor\n"
10203 "Display the prefixlist filter\n")
10204{
10205 char name[BUFSIZ];
10206 union sockunion *su;
10207 struct peer *peer;
10208 int count;
10209
10210 su = sockunion_str2su (argv[0]);
10211 if (su == NULL)
10212 return CMD_WARNING;
10213
10214 peer = peer_lookup (NULL, su);
10215 if (! peer)
10216 return CMD_WARNING;
10217
10218 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10219 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10220 if (count)
10221 {
10222 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10223 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10224 }
10225
10226 return CMD_SUCCESS;
10227}
10228
10229DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10230 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10231 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10232 SHOW_STR
10233 IP_STR
10234 BGP_STR
10235 "Address family\n"
10236 "Address Family modifier\n"
10237 "Address Family modifier\n"
10238 "Detailed information on TCP and BGP neighbor connections\n"
10239 "Neighbor to display information about\n"
10240 "Neighbor to display information about\n"
10241 "Display information received from a BGP neighbor\n"
10242 "Display the prefixlist filter\n")
10243{
10244 char name[BUFSIZ];
10245 union sockunion *su;
10246 struct peer *peer;
10247 int count;
10248
10249 su = sockunion_str2su (argv[1]);
10250 if (su == NULL)
10251 return CMD_WARNING;
10252
10253 peer = peer_lookup (NULL, su);
10254 if (! peer)
10255 return CMD_WARNING;
10256
10257 if (strncmp (argv[0], "m", 1) == 0)
10258 {
10259 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10260 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10261 if (count)
10262 {
10263 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10264 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10265 }
10266 }
10267 else
10268 {
10269 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10270 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10271 if (count)
10272 {
10273 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10274 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10275 }
10276 }
10277
10278 return CMD_SUCCESS;
10279}
10280
10281
10282#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010283ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010284 show_bgp_neighbor_received_routes_cmd,
10285 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10286 SHOW_STR
10287 BGP_STR
10288 "Detailed information on TCP and BGP neighbor connections\n"
10289 "Neighbor to display information about\n"
10290 "Neighbor to display information about\n"
10291 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010292
paulbb46e942003-10-24 19:02:03 +000010293ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010294 show_bgp_ipv6_neighbor_received_routes_cmd,
10295 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10296 SHOW_STR
10297 BGP_STR
10298 "Address family\n"
10299 "Detailed information on TCP and BGP neighbor connections\n"
10300 "Neighbor to display information about\n"
10301 "Neighbor to display information about\n"
10302 "Display the received routes from neighbor\n")
10303
10304DEFUN (show_bgp_neighbor_received_prefix_filter,
10305 show_bgp_neighbor_received_prefix_filter_cmd,
10306 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10307 SHOW_STR
10308 BGP_STR
10309 "Detailed information on TCP and BGP neighbor connections\n"
10310 "Neighbor to display information about\n"
10311 "Neighbor to display information about\n"
10312 "Display information received from a BGP neighbor\n"
10313 "Display the prefixlist filter\n")
10314{
10315 char name[BUFSIZ];
10316 union sockunion *su;
10317 struct peer *peer;
10318 int count;
10319
10320 su = sockunion_str2su (argv[0]);
10321 if (su == NULL)
10322 return CMD_WARNING;
10323
10324 peer = peer_lookup (NULL, su);
10325 if (! peer)
10326 return CMD_WARNING;
10327
10328 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10329 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10330 if (count)
10331 {
10332 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10333 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10334 }
10335
10336 return CMD_SUCCESS;
10337}
10338
10339ALIAS (show_bgp_neighbor_received_prefix_filter,
10340 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10341 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10342 SHOW_STR
10343 BGP_STR
10344 "Address family\n"
10345 "Detailed information on TCP and BGP neighbor connections\n"
10346 "Neighbor to display information about\n"
10347 "Neighbor to display information about\n"
10348 "Display information received from a BGP neighbor\n"
10349 "Display the prefixlist filter\n")
10350
10351/* old command */
paulbb46e942003-10-24 19:02:03 +000010352ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010353 ipv6_bgp_neighbor_received_routes_cmd,
10354 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10355 SHOW_STR
10356 IPV6_STR
10357 BGP_STR
10358 "Detailed information on TCP and BGP neighbor connections\n"
10359 "Neighbor to display information about\n"
10360 "Neighbor to display information about\n"
10361 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010362
10363/* old command */
10364DEFUN (ipv6_mbgp_neighbor_received_routes,
10365 ipv6_mbgp_neighbor_received_routes_cmd,
10366 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10367 SHOW_STR
10368 IPV6_STR
10369 MBGP_STR
10370 "Detailed information on TCP and BGP neighbor connections\n"
10371 "Neighbor to display information about\n"
10372 "Neighbor to display information about\n"
10373 "Display the received routes from neighbor\n")
10374{
paulbb46e942003-10-24 19:02:03 +000010375 struct peer *peer;
10376
10377 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10378 if (! peer)
10379 return CMD_WARNING;
10380
10381 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010382}
paulbb46e942003-10-24 19:02:03 +000010383
10384DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10385 show_bgp_view_neighbor_received_prefix_filter_cmd,
10386 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10387 SHOW_STR
10388 BGP_STR
10389 "BGP view\n"
10390 "View name\n"
10391 "Detailed information on TCP and BGP neighbor connections\n"
10392 "Neighbor to display information about\n"
10393 "Neighbor to display information about\n"
10394 "Display information received from a BGP neighbor\n"
10395 "Display the prefixlist filter\n")
10396{
10397 char name[BUFSIZ];
10398 union sockunion *su;
10399 struct peer *peer;
10400 struct bgp *bgp;
10401 int count;
10402
10403 /* BGP structure lookup. */
10404 bgp = bgp_lookup_by_name (argv[0]);
10405 if (bgp == NULL)
10406 {
10407 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10408 return CMD_WARNING;
10409 }
10410
10411 su = sockunion_str2su (argv[1]);
10412 if (su == NULL)
10413 return CMD_WARNING;
10414
10415 peer = peer_lookup (bgp, su);
10416 if (! peer)
10417 return CMD_WARNING;
10418
10419 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10420 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10421 if (count)
10422 {
10423 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10424 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10425 }
10426
10427 return CMD_SUCCESS;
10428}
10429
10430ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10431 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10432 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10433 SHOW_STR
10434 BGP_STR
10435 "BGP view\n"
10436 "View name\n"
10437 "Address family\n"
10438 "Detailed information on TCP and BGP neighbor connections\n"
10439 "Neighbor to display information about\n"
10440 "Neighbor to display information about\n"
10441 "Display information received from a BGP neighbor\n"
10442 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010443#endif /* HAVE_IPV6 */
10444
paul94f2b392005-06-28 12:44:16 +000010445static int
paulbb46e942003-10-24 19:02:03 +000010446bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010447 safi_t safi, enum bgp_show_type type)
10448{
paul718e3742002-12-13 20:15:29 +000010449 if (! peer || ! peer->afc[afi][safi])
10450 {
10451 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010452 return CMD_WARNING;
10453 }
10454
ajs5a646652004-11-05 01:25:55 +000010455 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010456}
10457
10458DEFUN (show_ip_bgp_neighbor_routes,
10459 show_ip_bgp_neighbor_routes_cmd,
10460 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10461 SHOW_STR
10462 IP_STR
10463 BGP_STR
10464 "Detailed information on TCP and BGP neighbor connections\n"
10465 "Neighbor to display information about\n"
10466 "Neighbor to display information about\n"
10467 "Display routes learned from neighbor\n")
10468{
paulbb46e942003-10-24 19:02:03 +000010469 struct peer *peer;
10470
10471 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10472 if (! peer)
10473 return CMD_WARNING;
10474
10475 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010476 bgp_show_type_neighbor);
10477}
10478
10479DEFUN (show_ip_bgp_neighbor_flap,
10480 show_ip_bgp_neighbor_flap_cmd,
10481 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10482 SHOW_STR
10483 IP_STR
10484 BGP_STR
10485 "Detailed information on TCP and BGP neighbor connections\n"
10486 "Neighbor to display information about\n"
10487 "Neighbor to display information about\n"
10488 "Display flap statistics of the routes learned from neighbor\n")
10489{
paulbb46e942003-10-24 19:02:03 +000010490 struct peer *peer;
10491
10492 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10493 if (! peer)
10494 return CMD_WARNING;
10495
10496 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010497 bgp_show_type_flap_neighbor);
10498}
10499
10500DEFUN (show_ip_bgp_neighbor_damp,
10501 show_ip_bgp_neighbor_damp_cmd,
10502 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10503 SHOW_STR
10504 IP_STR
10505 BGP_STR
10506 "Detailed information on TCP and BGP neighbor connections\n"
10507 "Neighbor to display information about\n"
10508 "Neighbor to display information about\n"
10509 "Display the dampened routes received from neighbor\n")
10510{
paulbb46e942003-10-24 19:02:03 +000010511 struct peer *peer;
10512
10513 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10514 if (! peer)
10515 return CMD_WARNING;
10516
10517 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010518 bgp_show_type_damp_neighbor);
10519}
10520
10521DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10522 show_ip_bgp_ipv4_neighbor_routes_cmd,
10523 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10524 SHOW_STR
10525 IP_STR
10526 BGP_STR
10527 "Address family\n"
10528 "Address Family modifier\n"
10529 "Address Family modifier\n"
10530 "Detailed information on TCP and BGP neighbor connections\n"
10531 "Neighbor to display information about\n"
10532 "Neighbor to display information about\n"
10533 "Display routes learned from neighbor\n")
10534{
paulbb46e942003-10-24 19:02:03 +000010535 struct peer *peer;
10536
10537 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10538 if (! peer)
10539 return CMD_WARNING;
10540
paul718e3742002-12-13 20:15:29 +000010541 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010542 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010543 bgp_show_type_neighbor);
10544
paulbb46e942003-10-24 19:02:03 +000010545 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010546 bgp_show_type_neighbor);
10547}
paulbb46e942003-10-24 19:02:03 +000010548
paulfee0f4c2004-09-13 05:12:46 +000010549DEFUN (show_ip_bgp_view_rsclient,
10550 show_ip_bgp_view_rsclient_cmd,
10551 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10552 SHOW_STR
10553 IP_STR
10554 BGP_STR
10555 "BGP view\n"
10556 "BGP view name\n"
10557 "Information about Route Server Client\n"
10558 NEIGHBOR_ADDR_STR)
10559{
10560 struct bgp_table *table;
10561 struct peer *peer;
10562
10563 if (argc == 2)
10564 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10565 else
10566 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10567
10568 if (! peer)
10569 return CMD_WARNING;
10570
10571 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10572 {
10573 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10574 VTY_NEWLINE);
10575 return CMD_WARNING;
10576 }
10577
10578 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10579 PEER_FLAG_RSERVER_CLIENT))
10580 {
10581 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10582 VTY_NEWLINE);
10583 return CMD_WARNING;
10584 }
10585
10586 table = peer->rib[AFI_IP][SAFI_UNICAST];
10587
ajs5a646652004-11-05 01:25:55 +000010588 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010589}
10590
10591ALIAS (show_ip_bgp_view_rsclient,
10592 show_ip_bgp_rsclient_cmd,
10593 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10594 SHOW_STR
10595 IP_STR
10596 BGP_STR
10597 "Information about Route Server Client\n"
10598 NEIGHBOR_ADDR_STR)
10599
Michael Lambert95cbbd22010-07-23 14:43:04 -040010600DEFUN (show_bgp_view_ipv4_safi_rsclient,
10601 show_bgp_view_ipv4_safi_rsclient_cmd,
10602 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10603 SHOW_STR
10604 BGP_STR
10605 "BGP view\n"
10606 "BGP view name\n"
10607 "Address family\n"
10608 "Address Family modifier\n"
10609 "Address Family modifier\n"
10610 "Information about Route Server Client\n"
10611 NEIGHBOR_ADDR_STR)
10612{
10613 struct bgp_table *table;
10614 struct peer *peer;
10615 safi_t safi;
10616
10617 if (argc == 3) {
10618 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10619 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10620 } else {
10621 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10622 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10623 }
10624
10625 if (! peer)
10626 return CMD_WARNING;
10627
10628 if (! peer->afc[AFI_IP][safi])
10629 {
10630 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10631 VTY_NEWLINE);
10632 return CMD_WARNING;
10633 }
10634
10635 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10636 PEER_FLAG_RSERVER_CLIENT))
10637 {
10638 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10639 VTY_NEWLINE);
10640 return CMD_WARNING;
10641 }
10642
10643 table = peer->rib[AFI_IP][safi];
10644
10645 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10646}
10647
10648ALIAS (show_bgp_view_ipv4_safi_rsclient,
10649 show_bgp_ipv4_safi_rsclient_cmd,
10650 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10651 SHOW_STR
10652 BGP_STR
10653 "Address family\n"
10654 "Address Family modifier\n"
10655 "Address Family modifier\n"
10656 "Information about Route Server Client\n"
10657 NEIGHBOR_ADDR_STR)
10658
paulfee0f4c2004-09-13 05:12:46 +000010659DEFUN (show_ip_bgp_view_rsclient_route,
10660 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010661 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010662 SHOW_STR
10663 IP_STR
10664 BGP_STR
10665 "BGP view\n"
10666 "BGP view name\n"
10667 "Information about Route Server Client\n"
10668 NEIGHBOR_ADDR_STR
10669 "Network in the BGP routing table to display\n")
10670{
10671 struct bgp *bgp;
10672 struct peer *peer;
10673
10674 /* BGP structure lookup. */
10675 if (argc == 3)
10676 {
10677 bgp = bgp_lookup_by_name (argv[0]);
10678 if (bgp == NULL)
10679 {
10680 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10681 return CMD_WARNING;
10682 }
10683 }
10684 else
10685 {
10686 bgp = bgp_get_default ();
10687 if (bgp == NULL)
10688 {
10689 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10690 return CMD_WARNING;
10691 }
10692 }
10693
10694 if (argc == 3)
10695 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10696 else
10697 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10698
10699 if (! peer)
10700 return CMD_WARNING;
10701
10702 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10703 {
10704 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10705 VTY_NEWLINE);
10706 return CMD_WARNING;
10707}
10708
10709 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10710 PEER_FLAG_RSERVER_CLIENT))
10711 {
10712 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10713 VTY_NEWLINE);
10714 return CMD_WARNING;
10715 }
10716
10717 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10718 (argc == 3) ? argv[2] : argv[1],
10719 AFI_IP, SAFI_UNICAST, NULL, 0);
10720}
10721
10722ALIAS (show_ip_bgp_view_rsclient_route,
10723 show_ip_bgp_rsclient_route_cmd,
10724 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10725 SHOW_STR
10726 IP_STR
10727 BGP_STR
10728 "Information about Route Server Client\n"
10729 NEIGHBOR_ADDR_STR
10730 "Network in the BGP routing table to display\n")
10731
Michael Lambert95cbbd22010-07-23 14:43:04 -040010732DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10733 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10734 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10735 SHOW_STR
10736 BGP_STR
10737 "BGP view\n"
10738 "BGP view name\n"
10739 "Address family\n"
10740 "Address Family modifier\n"
10741 "Address Family modifier\n"
10742 "Information about Route Server Client\n"
10743 NEIGHBOR_ADDR_STR
10744 "Network in the BGP routing table to display\n")
10745{
10746 struct bgp *bgp;
10747 struct peer *peer;
10748 safi_t safi;
10749
10750 /* BGP structure lookup. */
10751 if (argc == 4)
10752 {
10753 bgp = bgp_lookup_by_name (argv[0]);
10754 if (bgp == NULL)
10755 {
10756 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10757 return CMD_WARNING;
10758 }
10759 }
10760 else
10761 {
10762 bgp = bgp_get_default ();
10763 if (bgp == NULL)
10764 {
10765 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10766 return CMD_WARNING;
10767 }
10768 }
10769
10770 if (argc == 4) {
10771 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10772 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10773 } else {
10774 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10775 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10776 }
10777
10778 if (! peer)
10779 return CMD_WARNING;
10780
10781 if (! peer->afc[AFI_IP][safi])
10782 {
10783 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10784 VTY_NEWLINE);
10785 return CMD_WARNING;
10786}
10787
10788 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10789 PEER_FLAG_RSERVER_CLIENT))
10790 {
10791 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10792 VTY_NEWLINE);
10793 return CMD_WARNING;
10794 }
10795
10796 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10797 (argc == 4) ? argv[3] : argv[2],
10798 AFI_IP, safi, NULL, 0);
10799}
10800
10801ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10802 show_bgp_ipv4_safi_rsclient_route_cmd,
10803 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10804 SHOW_STR
10805 BGP_STR
10806 "Address family\n"
10807 "Address Family modifier\n"
10808 "Address Family modifier\n"
10809 "Information about Route Server Client\n"
10810 NEIGHBOR_ADDR_STR
10811 "Network in the BGP routing table to display\n")
10812
paulfee0f4c2004-09-13 05:12:46 +000010813DEFUN (show_ip_bgp_view_rsclient_prefix,
10814 show_ip_bgp_view_rsclient_prefix_cmd,
10815 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10816 SHOW_STR
10817 IP_STR
10818 BGP_STR
10819 "BGP view\n"
10820 "BGP view name\n"
10821 "Information about Route Server Client\n"
10822 NEIGHBOR_ADDR_STR
10823 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10824{
10825 struct bgp *bgp;
10826 struct peer *peer;
10827
10828 /* BGP structure lookup. */
10829 if (argc == 3)
10830 {
10831 bgp = bgp_lookup_by_name (argv[0]);
10832 if (bgp == NULL)
10833 {
10834 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10835 return CMD_WARNING;
10836 }
10837 }
10838 else
10839 {
10840 bgp = bgp_get_default ();
10841 if (bgp == NULL)
10842 {
10843 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10844 return CMD_WARNING;
10845 }
10846 }
10847
10848 if (argc == 3)
10849 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10850 else
10851 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10852
10853 if (! peer)
10854 return CMD_WARNING;
10855
10856 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10857 {
10858 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10859 VTY_NEWLINE);
10860 return CMD_WARNING;
10861}
10862
10863 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10864 PEER_FLAG_RSERVER_CLIENT))
10865{
10866 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10867 VTY_NEWLINE);
10868 return CMD_WARNING;
10869 }
10870
10871 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10872 (argc == 3) ? argv[2] : argv[1],
10873 AFI_IP, SAFI_UNICAST, NULL, 1);
10874}
10875
10876ALIAS (show_ip_bgp_view_rsclient_prefix,
10877 show_ip_bgp_rsclient_prefix_cmd,
10878 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10879 SHOW_STR
10880 IP_STR
10881 BGP_STR
10882 "Information about Route Server Client\n"
10883 NEIGHBOR_ADDR_STR
10884 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10885
Michael Lambert95cbbd22010-07-23 14:43:04 -040010886DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10887 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10888 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10889 SHOW_STR
10890 BGP_STR
10891 "BGP view\n"
10892 "BGP view name\n"
10893 "Address family\n"
10894 "Address Family modifier\n"
10895 "Address Family modifier\n"
10896 "Information about Route Server Client\n"
10897 NEIGHBOR_ADDR_STR
10898 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10899{
10900 struct bgp *bgp;
10901 struct peer *peer;
10902 safi_t safi;
10903
10904 /* BGP structure lookup. */
10905 if (argc == 4)
10906 {
10907 bgp = bgp_lookup_by_name (argv[0]);
10908 if (bgp == NULL)
10909 {
10910 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10911 return CMD_WARNING;
10912 }
10913 }
10914 else
10915 {
10916 bgp = bgp_get_default ();
10917 if (bgp == NULL)
10918 {
10919 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10920 return CMD_WARNING;
10921 }
10922 }
10923
10924 if (argc == 4) {
10925 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10926 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10927 } else {
10928 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10929 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10930 }
10931
10932 if (! peer)
10933 return CMD_WARNING;
10934
10935 if (! peer->afc[AFI_IP][safi])
10936 {
10937 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10938 VTY_NEWLINE);
10939 return CMD_WARNING;
10940}
10941
10942 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10943 PEER_FLAG_RSERVER_CLIENT))
10944{
10945 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10946 VTY_NEWLINE);
10947 return CMD_WARNING;
10948 }
10949
10950 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10951 (argc == 4) ? argv[3] : argv[2],
10952 AFI_IP, safi, NULL, 1);
10953}
10954
10955ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10956 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10957 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10958 SHOW_STR
10959 BGP_STR
10960 "Address family\n"
10961 "Address Family modifier\n"
10962 "Address Family modifier\n"
10963 "Information about Route Server Client\n"
10964 NEIGHBOR_ADDR_STR
10965 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010966
paul718e3742002-12-13 20:15:29 +000010967#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010968DEFUN (show_bgp_view_neighbor_routes,
10969 show_bgp_view_neighbor_routes_cmd,
10970 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10971 SHOW_STR
10972 BGP_STR
10973 "BGP view\n"
10974 "BGP view name\n"
10975 "Detailed information on TCP and BGP neighbor connections\n"
10976 "Neighbor to display information about\n"
10977 "Neighbor to display information about\n"
10978 "Display routes learned from neighbor\n")
10979{
10980 struct peer *peer;
10981
10982 if (argc == 2)
10983 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10984 else
10985 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10986
10987 if (! peer)
10988 return CMD_WARNING;
10989
10990 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10991 bgp_show_type_neighbor);
10992}
10993
10994ALIAS (show_bgp_view_neighbor_routes,
10995 show_bgp_view_ipv6_neighbor_routes_cmd,
10996 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10997 SHOW_STR
10998 BGP_STR
10999 "BGP view\n"
11000 "BGP view name\n"
11001 "Address family\n"
11002 "Detailed information on TCP and BGP neighbor connections\n"
11003 "Neighbor to display information about\n"
11004 "Neighbor to display information about\n"
11005 "Display routes learned from neighbor\n")
11006
11007DEFUN (show_bgp_view_neighbor_damp,
11008 show_bgp_view_neighbor_damp_cmd,
11009 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11010 SHOW_STR
11011 BGP_STR
11012 "BGP view\n"
11013 "BGP view name\n"
11014 "Detailed information on TCP and BGP neighbor connections\n"
11015 "Neighbor to display information about\n"
11016 "Neighbor to display information about\n"
11017 "Display the dampened routes received from neighbor\n")
11018{
11019 struct peer *peer;
11020
11021 if (argc == 2)
11022 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11023 else
11024 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11025
11026 if (! peer)
11027 return CMD_WARNING;
11028
11029 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11030 bgp_show_type_damp_neighbor);
11031}
11032
11033ALIAS (show_bgp_view_neighbor_damp,
11034 show_bgp_view_ipv6_neighbor_damp_cmd,
11035 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11036 SHOW_STR
11037 BGP_STR
11038 "BGP view\n"
11039 "BGP view name\n"
11040 "Address family\n"
11041 "Detailed information on TCP and BGP neighbor connections\n"
11042 "Neighbor to display information about\n"
11043 "Neighbor to display information about\n"
11044 "Display the dampened routes received from neighbor\n")
11045
11046DEFUN (show_bgp_view_neighbor_flap,
11047 show_bgp_view_neighbor_flap_cmd,
11048 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11049 SHOW_STR
11050 BGP_STR
11051 "BGP view\n"
11052 "BGP view name\n"
11053 "Detailed information on TCP and BGP neighbor connections\n"
11054 "Neighbor to display information about\n"
11055 "Neighbor to display information about\n"
11056 "Display flap statistics of the routes learned from neighbor\n")
11057{
11058 struct peer *peer;
11059
11060 if (argc == 2)
11061 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11062 else
11063 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11064
11065 if (! peer)
11066 return CMD_WARNING;
11067
11068 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11069 bgp_show_type_flap_neighbor);
11070}
11071
11072ALIAS (show_bgp_view_neighbor_flap,
11073 show_bgp_view_ipv6_neighbor_flap_cmd,
11074 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11075 SHOW_STR
11076 BGP_STR
11077 "BGP view\n"
11078 "BGP view name\n"
11079 "Address family\n"
11080 "Detailed information on TCP and BGP neighbor connections\n"
11081 "Neighbor to display information about\n"
11082 "Neighbor to display information about\n"
11083 "Display flap statistics of the routes learned from neighbor\n")
11084
11085ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011086 show_bgp_neighbor_routes_cmd,
11087 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11088 SHOW_STR
11089 BGP_STR
11090 "Detailed information on TCP and BGP neighbor connections\n"
11091 "Neighbor to display information about\n"
11092 "Neighbor to display information about\n"
11093 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011094
paulbb46e942003-10-24 19:02:03 +000011095
11096ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011097 show_bgp_ipv6_neighbor_routes_cmd,
11098 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11099 SHOW_STR
11100 BGP_STR
11101 "Address family\n"
11102 "Detailed information on TCP and BGP neighbor connections\n"
11103 "Neighbor to display information about\n"
11104 "Neighbor to display information about\n"
11105 "Display routes learned from neighbor\n")
11106
11107/* old command */
paulbb46e942003-10-24 19:02:03 +000011108ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011109 ipv6_bgp_neighbor_routes_cmd,
11110 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11111 SHOW_STR
11112 IPV6_STR
11113 BGP_STR
11114 "Detailed information on TCP and BGP neighbor connections\n"
11115 "Neighbor to display information about\n"
11116 "Neighbor to display information about\n"
11117 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011118
11119/* old command */
11120DEFUN (ipv6_mbgp_neighbor_routes,
11121 ipv6_mbgp_neighbor_routes_cmd,
11122 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11123 SHOW_STR
11124 IPV6_STR
11125 MBGP_STR
11126 "Detailed information on TCP and BGP neighbor connections\n"
11127 "Neighbor to display information about\n"
11128 "Neighbor to display information about\n"
11129 "Display routes learned from neighbor\n")
11130{
paulbb46e942003-10-24 19:02:03 +000011131 struct peer *peer;
11132
11133 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11134 if (! peer)
11135 return CMD_WARNING;
11136
11137 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011138 bgp_show_type_neighbor);
11139}
paulbb46e942003-10-24 19:02:03 +000011140
11141ALIAS (show_bgp_view_neighbor_flap,
11142 show_bgp_neighbor_flap_cmd,
11143 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11144 SHOW_STR
11145 BGP_STR
11146 "Detailed information on TCP and BGP neighbor connections\n"
11147 "Neighbor to display information about\n"
11148 "Neighbor to display information about\n"
11149 "Display flap statistics of the routes learned from neighbor\n")
11150
11151ALIAS (show_bgp_view_neighbor_flap,
11152 show_bgp_ipv6_neighbor_flap_cmd,
11153 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11154 SHOW_STR
11155 BGP_STR
11156 "Address family\n"
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 flap statistics of the routes learned from neighbor\n")
11161
11162ALIAS (show_bgp_view_neighbor_damp,
11163 show_bgp_neighbor_damp_cmd,
11164 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11165 SHOW_STR
11166 BGP_STR
11167 "Detailed information on TCP and BGP neighbor connections\n"
11168 "Neighbor to display information about\n"
11169 "Neighbor to display information about\n"
11170 "Display the dampened routes received from neighbor\n")
11171
11172ALIAS (show_bgp_view_neighbor_damp,
11173 show_bgp_ipv6_neighbor_damp_cmd,
11174 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11175 SHOW_STR
11176 BGP_STR
11177 "Address family\n"
11178 "Detailed information on TCP and BGP neighbor connections\n"
11179 "Neighbor to display information about\n"
11180 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011181 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011182
11183DEFUN (show_bgp_view_rsclient,
11184 show_bgp_view_rsclient_cmd,
11185 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11186 SHOW_STR
11187 BGP_STR
11188 "BGP view\n"
11189 "BGP view name\n"
11190 "Information about Route Server Client\n"
11191 NEIGHBOR_ADDR_STR)
11192{
11193 struct bgp_table *table;
11194 struct peer *peer;
11195
11196 if (argc == 2)
11197 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11198 else
11199 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11200
11201 if (! peer)
11202 return CMD_WARNING;
11203
11204 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11205 {
11206 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11207 VTY_NEWLINE);
11208 return CMD_WARNING;
11209 }
11210
11211 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11212 PEER_FLAG_RSERVER_CLIENT))
11213 {
11214 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11215 VTY_NEWLINE);
11216 return CMD_WARNING;
11217 }
11218
11219 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11220
ajs5a646652004-11-05 01:25:55 +000011221 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011222}
11223
11224ALIAS (show_bgp_view_rsclient,
11225 show_bgp_rsclient_cmd,
11226 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11227 SHOW_STR
11228 BGP_STR
11229 "Information about Route Server Client\n"
11230 NEIGHBOR_ADDR_STR)
11231
Michael Lambert95cbbd22010-07-23 14:43:04 -040011232DEFUN (show_bgp_view_ipv6_safi_rsclient,
11233 show_bgp_view_ipv6_safi_rsclient_cmd,
11234 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11235 SHOW_STR
11236 BGP_STR
11237 "BGP view\n"
11238 "BGP view name\n"
11239 "Address family\n"
11240 "Address Family modifier\n"
11241 "Address Family modifier\n"
11242 "Information about Route Server Client\n"
11243 NEIGHBOR_ADDR_STR)
11244{
11245 struct bgp_table *table;
11246 struct peer *peer;
11247 safi_t safi;
11248
11249 if (argc == 3) {
11250 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11251 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11252 } else {
11253 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11254 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11255 }
11256
11257 if (! peer)
11258 return CMD_WARNING;
11259
11260 if (! peer->afc[AFI_IP6][safi])
11261 {
11262 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11263 VTY_NEWLINE);
11264 return CMD_WARNING;
11265 }
11266
11267 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11268 PEER_FLAG_RSERVER_CLIENT))
11269 {
11270 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11271 VTY_NEWLINE);
11272 return CMD_WARNING;
11273 }
11274
11275 table = peer->rib[AFI_IP6][safi];
11276
11277 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11278}
11279
11280ALIAS (show_bgp_view_ipv6_safi_rsclient,
11281 show_bgp_ipv6_safi_rsclient_cmd,
11282 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11283 SHOW_STR
11284 BGP_STR
11285 "Address family\n"
11286 "Address Family modifier\n"
11287 "Address Family modifier\n"
11288 "Information about Route Server Client\n"
11289 NEIGHBOR_ADDR_STR)
11290
paulfee0f4c2004-09-13 05:12:46 +000011291DEFUN (show_bgp_view_rsclient_route,
11292 show_bgp_view_rsclient_route_cmd,
11293 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11294 SHOW_STR
11295 BGP_STR
11296 "BGP view\n"
11297 "BGP view name\n"
11298 "Information about Route Server Client\n"
11299 NEIGHBOR_ADDR_STR
11300 "Network in the BGP routing table to display\n")
11301{
11302 struct bgp *bgp;
11303 struct peer *peer;
11304
11305 /* BGP structure lookup. */
11306 if (argc == 3)
11307 {
11308 bgp = bgp_lookup_by_name (argv[0]);
11309 if (bgp == NULL)
11310 {
11311 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11312 return CMD_WARNING;
11313 }
11314 }
11315 else
11316 {
11317 bgp = bgp_get_default ();
11318 if (bgp == NULL)
11319 {
11320 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11321 return CMD_WARNING;
11322 }
11323 }
11324
11325 if (argc == 3)
11326 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11327 else
11328 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11329
11330 if (! peer)
11331 return CMD_WARNING;
11332
11333 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11334 {
11335 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11336 VTY_NEWLINE);
11337 return CMD_WARNING;
11338 }
11339
11340 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11341 PEER_FLAG_RSERVER_CLIENT))
11342 {
11343 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11344 VTY_NEWLINE);
11345 return CMD_WARNING;
11346 }
11347
11348 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11349 (argc == 3) ? argv[2] : argv[1],
11350 AFI_IP6, SAFI_UNICAST, NULL, 0);
11351}
11352
11353ALIAS (show_bgp_view_rsclient_route,
11354 show_bgp_rsclient_route_cmd,
11355 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11356 SHOW_STR
11357 BGP_STR
11358 "Information about Route Server Client\n"
11359 NEIGHBOR_ADDR_STR
11360 "Network in the BGP routing table to display\n")
11361
Michael Lambert95cbbd22010-07-23 14:43:04 -040011362DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11363 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11364 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11365 SHOW_STR
11366 BGP_STR
11367 "BGP view\n"
11368 "BGP view name\n"
11369 "Address family\n"
11370 "Address Family modifier\n"
11371 "Address Family modifier\n"
11372 "Information about Route Server Client\n"
11373 NEIGHBOR_ADDR_STR
11374 "Network in the BGP routing table to display\n")
11375{
11376 struct bgp *bgp;
11377 struct peer *peer;
11378 safi_t safi;
11379
11380 /* BGP structure lookup. */
11381 if (argc == 4)
11382 {
11383 bgp = bgp_lookup_by_name (argv[0]);
11384 if (bgp == NULL)
11385 {
11386 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11387 return CMD_WARNING;
11388 }
11389 }
11390 else
11391 {
11392 bgp = bgp_get_default ();
11393 if (bgp == NULL)
11394 {
11395 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11396 return CMD_WARNING;
11397 }
11398 }
11399
11400 if (argc == 4) {
11401 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11402 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11403 } else {
11404 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11405 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11406 }
11407
11408 if (! peer)
11409 return CMD_WARNING;
11410
11411 if (! peer->afc[AFI_IP6][safi])
11412 {
11413 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11414 VTY_NEWLINE);
11415 return CMD_WARNING;
11416}
11417
11418 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11419 PEER_FLAG_RSERVER_CLIENT))
11420 {
11421 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11422 VTY_NEWLINE);
11423 return CMD_WARNING;
11424 }
11425
11426 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11427 (argc == 4) ? argv[3] : argv[2],
11428 AFI_IP6, safi, NULL, 0);
11429}
11430
11431ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11432 show_bgp_ipv6_safi_rsclient_route_cmd,
11433 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11434 SHOW_STR
11435 BGP_STR
11436 "Address family\n"
11437 "Address Family modifier\n"
11438 "Address Family modifier\n"
11439 "Information about Route Server Client\n"
11440 NEIGHBOR_ADDR_STR
11441 "Network in the BGP routing table to display\n")
11442
paulfee0f4c2004-09-13 05:12:46 +000011443DEFUN (show_bgp_view_rsclient_prefix,
11444 show_bgp_view_rsclient_prefix_cmd,
11445 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11446 SHOW_STR
11447 BGP_STR
11448 "BGP view\n"
11449 "BGP view name\n"
11450 "Information about Route Server Client\n"
11451 NEIGHBOR_ADDR_STR
11452 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11453{
11454 struct bgp *bgp;
11455 struct peer *peer;
11456
11457 /* BGP structure lookup. */
11458 if (argc == 3)
11459 {
11460 bgp = bgp_lookup_by_name (argv[0]);
11461 if (bgp == NULL)
11462 {
11463 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11464 return CMD_WARNING;
11465 }
11466 }
11467 else
11468 {
11469 bgp = bgp_get_default ();
11470 if (bgp == NULL)
11471 {
11472 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11473 return CMD_WARNING;
11474 }
11475 }
11476
11477 if (argc == 3)
11478 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11479 else
11480 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11481
11482 if (! peer)
11483 return CMD_WARNING;
11484
11485 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11486 {
11487 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11488 VTY_NEWLINE);
11489 return CMD_WARNING;
11490 }
11491
11492 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11493 PEER_FLAG_RSERVER_CLIENT))
11494 {
11495 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11496 VTY_NEWLINE);
11497 return CMD_WARNING;
11498 }
11499
11500 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11501 (argc == 3) ? argv[2] : argv[1],
11502 AFI_IP6, SAFI_UNICAST, NULL, 1);
11503}
11504
11505ALIAS (show_bgp_view_rsclient_prefix,
11506 show_bgp_rsclient_prefix_cmd,
11507 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11508 SHOW_STR
11509 BGP_STR
11510 "Information about Route Server Client\n"
11511 NEIGHBOR_ADDR_STR
11512 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11513
Michael Lambert95cbbd22010-07-23 14:43:04 -040011514DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11515 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11516 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11517 SHOW_STR
11518 BGP_STR
11519 "BGP view\n"
11520 "BGP view name\n"
11521 "Address family\n"
11522 "Address Family modifier\n"
11523 "Address Family modifier\n"
11524 "Information about Route Server Client\n"
11525 NEIGHBOR_ADDR_STR
11526 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11527{
11528 struct bgp *bgp;
11529 struct peer *peer;
11530 safi_t safi;
11531
11532 /* BGP structure lookup. */
11533 if (argc == 4)
11534 {
11535 bgp = bgp_lookup_by_name (argv[0]);
11536 if (bgp == NULL)
11537 {
11538 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11539 return CMD_WARNING;
11540 }
11541 }
11542 else
11543 {
11544 bgp = bgp_get_default ();
11545 if (bgp == NULL)
11546 {
11547 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11548 return CMD_WARNING;
11549 }
11550 }
11551
11552 if (argc == 4) {
11553 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11554 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11555 } else {
11556 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11557 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11558 }
11559
11560 if (! peer)
11561 return CMD_WARNING;
11562
11563 if (! peer->afc[AFI_IP6][safi])
11564 {
11565 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11566 VTY_NEWLINE);
11567 return CMD_WARNING;
11568}
11569
11570 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11571 PEER_FLAG_RSERVER_CLIENT))
11572{
11573 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11574 VTY_NEWLINE);
11575 return CMD_WARNING;
11576 }
11577
11578 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11579 (argc == 4) ? argv[3] : argv[2],
11580 AFI_IP6, safi, NULL, 1);
11581}
11582
11583ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11584 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11585 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11586 SHOW_STR
11587 BGP_STR
11588 "Address family\n"
11589 "Address Family modifier\n"
11590 "Address Family modifier\n"
11591 "Information about Route Server Client\n"
11592 NEIGHBOR_ADDR_STR
11593 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11594
paul718e3742002-12-13 20:15:29 +000011595#endif /* HAVE_IPV6 */
11596
11597struct bgp_table *bgp_distance_table;
11598
11599struct bgp_distance
11600{
11601 /* Distance value for the IP source prefix. */
11602 u_char distance;
11603
11604 /* Name of the access-list to be matched. */
11605 char *access_list;
11606};
11607
paul94f2b392005-06-28 12:44:16 +000011608static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011609bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011610{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011611 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011612}
11613
paul94f2b392005-06-28 12:44:16 +000011614static void
paul718e3742002-12-13 20:15:29 +000011615bgp_distance_free (struct bgp_distance *bdistance)
11616{
11617 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11618}
11619
paul94f2b392005-06-28 12:44:16 +000011620static int
paulfd79ac92004-10-13 05:06:08 +000011621bgp_distance_set (struct vty *vty, const char *distance_str,
11622 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011623{
11624 int ret;
11625 struct prefix_ipv4 p;
11626 u_char distance;
11627 struct bgp_node *rn;
11628 struct bgp_distance *bdistance;
11629
11630 ret = str2prefix_ipv4 (ip_str, &p);
11631 if (ret == 0)
11632 {
11633 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11634 return CMD_WARNING;
11635 }
11636
11637 distance = atoi (distance_str);
11638
11639 /* Get BGP distance node. */
11640 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11641 if (rn->info)
11642 {
11643 bdistance = rn->info;
11644 bgp_unlock_node (rn);
11645 }
11646 else
11647 {
11648 bdistance = bgp_distance_new ();
11649 rn->info = bdistance;
11650 }
11651
11652 /* Set distance value. */
11653 bdistance->distance = distance;
11654
11655 /* Reset access-list configuration. */
11656 if (bdistance->access_list)
11657 {
11658 free (bdistance->access_list);
11659 bdistance->access_list = NULL;
11660 }
11661 if (access_list_str)
11662 bdistance->access_list = strdup (access_list_str);
11663
11664 return CMD_SUCCESS;
11665}
11666
paul94f2b392005-06-28 12:44:16 +000011667static int
paulfd79ac92004-10-13 05:06:08 +000011668bgp_distance_unset (struct vty *vty, const char *distance_str,
11669 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011670{
11671 int ret;
11672 struct prefix_ipv4 p;
11673 u_char distance;
11674 struct bgp_node *rn;
11675 struct bgp_distance *bdistance;
11676
11677 ret = str2prefix_ipv4 (ip_str, &p);
11678 if (ret == 0)
11679 {
11680 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11681 return CMD_WARNING;
11682 }
11683
11684 distance = atoi (distance_str);
11685
11686 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11687 if (! rn)
11688 {
11689 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11690 return CMD_WARNING;
11691 }
11692
11693 bdistance = rn->info;
11694
11695 if (bdistance->access_list)
11696 free (bdistance->access_list);
11697 bgp_distance_free (bdistance);
11698
11699 rn->info = NULL;
11700 bgp_unlock_node (rn);
11701 bgp_unlock_node (rn);
11702
11703 return CMD_SUCCESS;
11704}
11705
paul718e3742002-12-13 20:15:29 +000011706/* Apply BGP information to distance method. */
11707u_char
11708bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11709{
11710 struct bgp_node *rn;
11711 struct prefix_ipv4 q;
11712 struct peer *peer;
11713 struct bgp_distance *bdistance;
11714 struct access_list *alist;
11715 struct bgp_static *bgp_static;
11716
11717 if (! bgp)
11718 return 0;
11719
11720 if (p->family != AF_INET)
11721 return 0;
11722
11723 peer = rinfo->peer;
11724
11725 if (peer->su.sa.sa_family != AF_INET)
11726 return 0;
11727
11728 memset (&q, 0, sizeof (struct prefix_ipv4));
11729 q.family = AF_INET;
11730 q.prefix = peer->su.sin.sin_addr;
11731 q.prefixlen = IPV4_MAX_BITLEN;
11732
11733 /* Check source address. */
11734 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11735 if (rn)
11736 {
11737 bdistance = rn->info;
11738 bgp_unlock_node (rn);
11739
11740 if (bdistance->access_list)
11741 {
11742 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11743 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11744 return bdistance->distance;
11745 }
11746 else
11747 return bdistance->distance;
11748 }
11749
11750 /* Backdoor check. */
11751 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11752 if (rn)
11753 {
11754 bgp_static = rn->info;
11755 bgp_unlock_node (rn);
11756
11757 if (bgp_static->backdoor)
11758 {
11759 if (bgp->distance_local)
11760 return bgp->distance_local;
11761 else
11762 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11763 }
11764 }
11765
11766 if (peer_sort (peer) == BGP_PEER_EBGP)
11767 {
11768 if (bgp->distance_ebgp)
11769 return bgp->distance_ebgp;
11770 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11771 }
11772 else
11773 {
11774 if (bgp->distance_ibgp)
11775 return bgp->distance_ibgp;
11776 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11777 }
11778}
11779
11780DEFUN (bgp_distance,
11781 bgp_distance_cmd,
11782 "distance bgp <1-255> <1-255> <1-255>",
11783 "Define an administrative distance\n"
11784 "BGP distance\n"
11785 "Distance for routes external to the AS\n"
11786 "Distance for routes internal to the AS\n"
11787 "Distance for local routes\n")
11788{
11789 struct bgp *bgp;
11790
11791 bgp = vty->index;
11792
11793 bgp->distance_ebgp = atoi (argv[0]);
11794 bgp->distance_ibgp = atoi (argv[1]);
11795 bgp->distance_local = atoi (argv[2]);
11796 return CMD_SUCCESS;
11797}
11798
11799DEFUN (no_bgp_distance,
11800 no_bgp_distance_cmd,
11801 "no distance bgp <1-255> <1-255> <1-255>",
11802 NO_STR
11803 "Define an administrative distance\n"
11804 "BGP distance\n"
11805 "Distance for routes external to the AS\n"
11806 "Distance for routes internal to the AS\n"
11807 "Distance for local routes\n")
11808{
11809 struct bgp *bgp;
11810
11811 bgp = vty->index;
11812
11813 bgp->distance_ebgp= 0;
11814 bgp->distance_ibgp = 0;
11815 bgp->distance_local = 0;
11816 return CMD_SUCCESS;
11817}
11818
11819ALIAS (no_bgp_distance,
11820 no_bgp_distance2_cmd,
11821 "no distance bgp",
11822 NO_STR
11823 "Define an administrative distance\n"
11824 "BGP distance\n")
11825
11826DEFUN (bgp_distance_source,
11827 bgp_distance_source_cmd,
11828 "distance <1-255> A.B.C.D/M",
11829 "Define an administrative distance\n"
11830 "Administrative distance\n"
11831 "IP source prefix\n")
11832{
11833 bgp_distance_set (vty, argv[0], argv[1], NULL);
11834 return CMD_SUCCESS;
11835}
11836
11837DEFUN (no_bgp_distance_source,
11838 no_bgp_distance_source_cmd,
11839 "no distance <1-255> A.B.C.D/M",
11840 NO_STR
11841 "Define an administrative distance\n"
11842 "Administrative distance\n"
11843 "IP source prefix\n")
11844{
11845 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11846 return CMD_SUCCESS;
11847}
11848
11849DEFUN (bgp_distance_source_access_list,
11850 bgp_distance_source_access_list_cmd,
11851 "distance <1-255> A.B.C.D/M WORD",
11852 "Define an administrative distance\n"
11853 "Administrative distance\n"
11854 "IP source prefix\n"
11855 "Access list name\n")
11856{
11857 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11858 return CMD_SUCCESS;
11859}
11860
11861DEFUN (no_bgp_distance_source_access_list,
11862 no_bgp_distance_source_access_list_cmd,
11863 "no distance <1-255> A.B.C.D/M WORD",
11864 NO_STR
11865 "Define an administrative distance\n"
11866 "Administrative distance\n"
11867 "IP source prefix\n"
11868 "Access list name\n")
11869{
11870 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11871 return CMD_SUCCESS;
11872}
11873
11874DEFUN (bgp_damp_set,
11875 bgp_damp_set_cmd,
11876 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11877 "BGP Specific commands\n"
11878 "Enable route-flap dampening\n"
11879 "Half-life time for the penalty\n"
11880 "Value to start reusing a route\n"
11881 "Value to start suppressing a route\n"
11882 "Maximum duration to suppress a stable route\n")
11883{
11884 struct bgp *bgp;
11885 int half = DEFAULT_HALF_LIFE * 60;
11886 int reuse = DEFAULT_REUSE;
11887 int suppress = DEFAULT_SUPPRESS;
11888 int max = 4 * half;
11889
11890 if (argc == 4)
11891 {
11892 half = atoi (argv[0]) * 60;
11893 reuse = atoi (argv[1]);
11894 suppress = atoi (argv[2]);
11895 max = atoi (argv[3]) * 60;
11896 }
11897 else if (argc == 1)
11898 {
11899 half = atoi (argv[0]) * 60;
11900 max = 4 * half;
11901 }
11902
11903 bgp = vty->index;
11904 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11905 half, reuse, suppress, max);
11906}
11907
11908ALIAS (bgp_damp_set,
11909 bgp_damp_set2_cmd,
11910 "bgp dampening <1-45>",
11911 "BGP Specific commands\n"
11912 "Enable route-flap dampening\n"
11913 "Half-life time for the penalty\n")
11914
11915ALIAS (bgp_damp_set,
11916 bgp_damp_set3_cmd,
11917 "bgp dampening",
11918 "BGP Specific commands\n"
11919 "Enable route-flap dampening\n")
11920
11921DEFUN (bgp_damp_unset,
11922 bgp_damp_unset_cmd,
11923 "no bgp dampening",
11924 NO_STR
11925 "BGP Specific commands\n"
11926 "Enable route-flap dampening\n")
11927{
11928 struct bgp *bgp;
11929
11930 bgp = vty->index;
11931 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11932}
11933
11934ALIAS (bgp_damp_unset,
11935 bgp_damp_unset2_cmd,
11936 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11937 NO_STR
11938 "BGP Specific commands\n"
11939 "Enable route-flap dampening\n"
11940 "Half-life time for the penalty\n"
11941 "Value to start reusing a route\n"
11942 "Value to start suppressing a route\n"
11943 "Maximum duration to suppress a stable route\n")
11944
11945DEFUN (show_ip_bgp_dampened_paths,
11946 show_ip_bgp_dampened_paths_cmd,
11947 "show ip bgp dampened-paths",
11948 SHOW_STR
11949 IP_STR
11950 BGP_STR
11951 "Display paths suppressed due to dampening\n")
11952{
ajs5a646652004-11-05 01:25:55 +000011953 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11954 NULL);
paul718e3742002-12-13 20:15:29 +000011955}
11956
11957DEFUN (show_ip_bgp_flap_statistics,
11958 show_ip_bgp_flap_statistics_cmd,
11959 "show ip bgp flap-statistics",
11960 SHOW_STR
11961 IP_STR
11962 BGP_STR
11963 "Display flap statistics of routes\n")
11964{
ajs5a646652004-11-05 01:25:55 +000011965 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11966 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011967}
11968
11969/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011970static int
paulfd79ac92004-10-13 05:06:08 +000011971bgp_clear_damp_route (struct vty *vty, const char *view_name,
11972 const char *ip_str, afi_t afi, safi_t safi,
11973 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011974{
11975 int ret;
11976 struct prefix match;
11977 struct bgp_node *rn;
11978 struct bgp_node *rm;
11979 struct bgp_info *ri;
11980 struct bgp_info *ri_temp;
11981 struct bgp *bgp;
11982 struct bgp_table *table;
11983
11984 /* BGP structure lookup. */
11985 if (view_name)
11986 {
11987 bgp = bgp_lookup_by_name (view_name);
11988 if (bgp == NULL)
11989 {
11990 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11991 return CMD_WARNING;
11992 }
11993 }
11994 else
11995 {
11996 bgp = bgp_get_default ();
11997 if (bgp == NULL)
11998 {
11999 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
12000 return CMD_WARNING;
12001 }
12002 }
12003
12004 /* Check IP address argument. */
12005 ret = str2prefix (ip_str, &match);
12006 if (! ret)
12007 {
12008 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12009 return CMD_WARNING;
12010 }
12011
12012 match.family = afi2family (afi);
12013
12014 if (safi == SAFI_MPLS_VPN)
12015 {
12016 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12017 {
12018 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12019 continue;
12020
12021 if ((table = rn->info) != NULL)
12022 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012023 {
12024 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12025 {
12026 ri = rm->info;
12027 while (ri)
12028 {
12029 if (ri->extra && ri->extra->damp_info)
12030 {
12031 ri_temp = ri->next;
12032 bgp_damp_info_free (ri->extra->damp_info, 1);
12033 ri = ri_temp;
12034 }
12035 else
12036 ri = ri->next;
12037 }
12038 }
12039
12040 bgp_unlock_node (rm);
12041 }
paul718e3742002-12-13 20:15:29 +000012042 }
12043 }
12044 else
12045 {
12046 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012047 {
12048 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12049 {
12050 ri = rn->info;
12051 while (ri)
12052 {
12053 if (ri->extra && ri->extra->damp_info)
12054 {
12055 ri_temp = ri->next;
12056 bgp_damp_info_free (ri->extra->damp_info, 1);
12057 ri = ri_temp;
12058 }
12059 else
12060 ri = ri->next;
12061 }
12062 }
12063
12064 bgp_unlock_node (rn);
12065 }
paul718e3742002-12-13 20:15:29 +000012066 }
12067
12068 return CMD_SUCCESS;
12069}
12070
12071DEFUN (clear_ip_bgp_dampening,
12072 clear_ip_bgp_dampening_cmd,
12073 "clear ip bgp dampening",
12074 CLEAR_STR
12075 IP_STR
12076 BGP_STR
12077 "Clear route flap dampening information\n")
12078{
12079 bgp_damp_info_clean ();
12080 return CMD_SUCCESS;
12081}
12082
12083DEFUN (clear_ip_bgp_dampening_prefix,
12084 clear_ip_bgp_dampening_prefix_cmd,
12085 "clear ip bgp dampening A.B.C.D/M",
12086 CLEAR_STR
12087 IP_STR
12088 BGP_STR
12089 "Clear route flap dampening information\n"
12090 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12091{
12092 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12093 SAFI_UNICAST, NULL, 1);
12094}
12095
12096DEFUN (clear_ip_bgp_dampening_address,
12097 clear_ip_bgp_dampening_address_cmd,
12098 "clear ip bgp dampening A.B.C.D",
12099 CLEAR_STR
12100 IP_STR
12101 BGP_STR
12102 "Clear route flap dampening information\n"
12103 "Network to clear damping information\n")
12104{
12105 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12106 SAFI_UNICAST, NULL, 0);
12107}
12108
12109DEFUN (clear_ip_bgp_dampening_address_mask,
12110 clear_ip_bgp_dampening_address_mask_cmd,
12111 "clear ip bgp dampening A.B.C.D A.B.C.D",
12112 CLEAR_STR
12113 IP_STR
12114 BGP_STR
12115 "Clear route flap dampening information\n"
12116 "Network to clear damping information\n"
12117 "Network mask\n")
12118{
12119 int ret;
12120 char prefix_str[BUFSIZ];
12121
12122 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12123 if (! ret)
12124 {
12125 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12126 return CMD_WARNING;
12127 }
12128
12129 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12130 SAFI_UNICAST, NULL, 0);
12131}
12132
paul94f2b392005-06-28 12:44:16 +000012133static int
paul718e3742002-12-13 20:15:29 +000012134bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12135 afi_t afi, safi_t safi, int *write)
12136{
12137 struct bgp_node *prn;
12138 struct bgp_node *rn;
12139 struct bgp_table *table;
12140 struct prefix *p;
12141 struct prefix_rd *prd;
12142 struct bgp_static *bgp_static;
12143 u_int32_t label;
12144 char buf[SU_ADDRSTRLEN];
12145 char rdbuf[RD_ADDRSTRLEN];
12146
12147 /* Network configuration. */
12148 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12149 if ((table = prn->info) != NULL)
12150 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12151 if ((bgp_static = rn->info) != NULL)
12152 {
12153 p = &rn->p;
12154 prd = (struct prefix_rd *) &prn->p;
12155
12156 /* "address-family" display. */
12157 bgp_config_write_family_header (vty, afi, safi, write);
12158
12159 /* "network" configuration display. */
12160 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12161 label = decode_label (bgp_static->tag);
12162
12163 vty_out (vty, " network %s/%d rd %s tag %d",
12164 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12165 p->prefixlen,
12166 rdbuf, label);
12167 vty_out (vty, "%s", VTY_NEWLINE);
12168 }
12169 return 0;
12170}
12171
12172/* Configuration of static route announcement and aggregate
12173 information. */
12174int
12175bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12176 afi_t afi, safi_t safi, int *write)
12177{
12178 struct bgp_node *rn;
12179 struct prefix *p;
12180 struct bgp_static *bgp_static;
12181 struct bgp_aggregate *bgp_aggregate;
12182 char buf[SU_ADDRSTRLEN];
12183
12184 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12185 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12186
12187 /* Network configuration. */
12188 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12189 if ((bgp_static = rn->info) != NULL)
12190 {
12191 p = &rn->p;
12192
12193 /* "address-family" display. */
12194 bgp_config_write_family_header (vty, afi, safi, write);
12195
12196 /* "network" configuration display. */
12197 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12198 {
12199 u_int32_t destination;
12200 struct in_addr netmask;
12201
12202 destination = ntohl (p->u.prefix4.s_addr);
12203 masklen2ip (p->prefixlen, &netmask);
12204 vty_out (vty, " network %s",
12205 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12206
12207 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12208 || (IN_CLASSB (destination) && p->prefixlen == 16)
12209 || (IN_CLASSA (destination) && p->prefixlen == 8)
12210 || p->u.prefix4.s_addr == 0)
12211 {
12212 /* Natural mask is not display. */
12213 }
12214 else
12215 vty_out (vty, " mask %s", inet_ntoa (netmask));
12216 }
12217 else
12218 {
12219 vty_out (vty, " network %s/%d",
12220 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12221 p->prefixlen);
12222 }
12223
12224 if (bgp_static->rmap.name)
12225 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012226 else
12227 {
12228 if (bgp_static->backdoor)
12229 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012230 }
paul718e3742002-12-13 20:15:29 +000012231
12232 vty_out (vty, "%s", VTY_NEWLINE);
12233 }
12234
12235 /* Aggregate-address configuration. */
12236 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12237 if ((bgp_aggregate = rn->info) != NULL)
12238 {
12239 p = &rn->p;
12240
12241 /* "address-family" display. */
12242 bgp_config_write_family_header (vty, afi, safi, write);
12243
12244 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12245 {
12246 struct in_addr netmask;
12247
12248 masklen2ip (p->prefixlen, &netmask);
12249 vty_out (vty, " aggregate-address %s %s",
12250 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12251 inet_ntoa (netmask));
12252 }
12253 else
12254 {
12255 vty_out (vty, " aggregate-address %s/%d",
12256 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12257 p->prefixlen);
12258 }
12259
12260 if (bgp_aggregate->as_set)
12261 vty_out (vty, " as-set");
12262
12263 if (bgp_aggregate->summary_only)
12264 vty_out (vty, " summary-only");
12265
12266 vty_out (vty, "%s", VTY_NEWLINE);
12267 }
12268
12269 return 0;
12270}
12271
12272int
12273bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12274{
12275 struct bgp_node *rn;
12276 struct bgp_distance *bdistance;
12277
12278 /* Distance configuration. */
12279 if (bgp->distance_ebgp
12280 && bgp->distance_ibgp
12281 && bgp->distance_local
12282 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12283 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12284 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12285 vty_out (vty, " distance bgp %d %d %d%s",
12286 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12287 VTY_NEWLINE);
12288
12289 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12290 if ((bdistance = rn->info) != NULL)
12291 {
12292 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12293 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12294 bdistance->access_list ? bdistance->access_list : "",
12295 VTY_NEWLINE);
12296 }
12297
12298 return 0;
12299}
12300
12301/* Allocate routing table structure and install commands. */
12302void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012303bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012304{
12305 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012306 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012307
12308 /* IPv4 BGP commands. */
12309 install_element (BGP_NODE, &bgp_network_cmd);
12310 install_element (BGP_NODE, &bgp_network_mask_cmd);
12311 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12312 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12313 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12314 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12315 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12316 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12317 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12318 install_element (BGP_NODE, &no_bgp_network_cmd);
12319 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12320 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12321 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12322 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12323 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12324 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12325 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12326 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12327
12328 install_element (BGP_NODE, &aggregate_address_cmd);
12329 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12330 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12331 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12332 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12333 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12334 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12335 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12336 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12337 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12338 install_element (BGP_NODE, &no_aggregate_address_cmd);
12339 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12340 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12341 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12342 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12343 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12344 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12345 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12346 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12347 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12348
12349 /* IPv4 unicast configuration. */
12350 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12351 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12352 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12353 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12354 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12355 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012356 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012357 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12358 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12359 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12360 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12361 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012362
paul718e3742002-12-13 20:15:29 +000012363 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12364 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12365 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12366 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12367 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12368 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12369 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12370 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12371 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12372 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12373 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12374 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12375 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12376 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12377 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12378 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12379 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12380 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12381 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12382 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12383
12384 /* IPv4 multicast configuration. */
12385 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12386 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12387 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12388 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12389 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12390 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12391 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12392 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12393 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12394 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12395 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12396 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12397 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12398 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12399 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12400 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12401 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12402 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12403 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12404 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12405 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12406 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12407 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12408 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12409 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12410 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12411 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12412 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12413 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12414 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12415 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12416 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12417
12418 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12419 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012420 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012421 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12422 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012423 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012424 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12425 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12426 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12427 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012428 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012429 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12430 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12431 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12432 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12433 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12434 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12435 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12436 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12437 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12438 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12439 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12440 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12441 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12442 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12443 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12444 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12445 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12446 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12447 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12448 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12449 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12450 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12451 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12452 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12453 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012454 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12455 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12456 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12457 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12458 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012459 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12460 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12462 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12463 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12466 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12467 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12468 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012477 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012478 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12489 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12491 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12492 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12493 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012494 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012495 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012496 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012497 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012498 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012499 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012500 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12501 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012502 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012503 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012504 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012505 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012506 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012507 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012508
12509 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12510 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12511 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012512 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012513 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12514 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12515 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012516 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012517 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12518 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12519 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12520 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12521 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12522 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12523 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12524 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12525 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12526 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12527 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12528 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012529 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12530 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12531 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12532 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12533 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012534 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12535 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12536 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12537 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12538 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12539 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12540 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12541 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12542 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012543 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012544 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012545 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012546 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012547 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012548 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012549 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012550
12551 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12552 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012553 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012554 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12555 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012556 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012557 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12558 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12559 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12560 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012561 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012562 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12563 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12564 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12565 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12566 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12567 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12568 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12569 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12570 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12571 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12572 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12573 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12574 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12575 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12576 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12577 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12578 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12579 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12580 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12581 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12582 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12583 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12584 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12585 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12586 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012587 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12588 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12589 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12590 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12591 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012592 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12593 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12595 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12596 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12599 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12600 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12601 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012610 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012611 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12622 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12625 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12626 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012627 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012628 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012629 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012630 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012631 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012632 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012633 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12634 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012635 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012636 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012637 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012638 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012639 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012640 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012641
12642 /* BGP dampening clear commands */
12643 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12644 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12645 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12646 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12647
Paul Jakmaff7924f2006-09-04 01:10:36 +000012648 /* prefix count */
12649 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12650 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12651 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012652#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012653 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12654
paul718e3742002-12-13 20:15:29 +000012655 /* New config IPv6 BGP commands. */
12656 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12657 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12658 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12659 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12660
12661 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12662 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12663 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12664 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12665
12666 /* Old config IPv6 BGP commands. */
12667 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12668 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12669
12670 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12671 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12672 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12673 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12674
12675 install_element (VIEW_NODE, &show_bgp_cmd);
12676 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012677 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012678 install_element (VIEW_NODE, &show_bgp_route_cmd);
12679 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012680 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012681 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12682 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012683 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012684 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12685 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12686 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12687 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12688 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12689 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12690 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12691 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12692 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12693 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12694 install_element (VIEW_NODE, &show_bgp_community_cmd);
12695 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12696 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12697 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12698 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12699 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12700 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12701 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12702 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12703 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12704 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12705 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12706 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12707 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12708 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12709 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12710 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12711 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12712 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12713 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12714 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12715 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12716 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12717 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12718 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12719 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12720 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12721 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12722 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12723 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012724 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12725 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12726 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12727 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012728 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012729 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012730 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012731 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012732 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012733 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012734 install_element (VIEW_NODE, &show_bgp_view_cmd);
12735 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12736 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12737 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12738 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12739 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12740 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12741 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12742 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12743 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12744 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12745 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12746 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12747 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12748 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12749 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12750 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12751 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012752 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012753 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012754 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012755 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012756 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012757 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012758
12759 /* Restricted:
12760 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12761 */
12762 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12763 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012764 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012765 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12766 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012767 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012768 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12769 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12770 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12771 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12772 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12773 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12774 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12775 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12776 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12777 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12778 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12779 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12780 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12781 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12782 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12783 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12784 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012785 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012786 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012787 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012788 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12789 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12790 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12791 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12792 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12793 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12794 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012795 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012796 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012797 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012798
12799 install_element (ENABLE_NODE, &show_bgp_cmd);
12800 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012801 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012802 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12803 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012804 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012805 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12806 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012807 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012808 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12809 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12810 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12811 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12812 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12813 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12814 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12815 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12816 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12817 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12818 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12819 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12820 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12821 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12822 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12823 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12824 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12825 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12826 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12827 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12828 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12829 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12830 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12831 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12832 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12833 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12834 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12835 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12836 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12837 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12838 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12839 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12840 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12841 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12842 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12843 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12844 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12845 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12846 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12847 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012848 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12849 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12850 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012852 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012853 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012854 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012855 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012856 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012857 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012858 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12871 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12872 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12873 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012876 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012877 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012878 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012879 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012880 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012881 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012882
12883 /* Statistics */
12884 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12885 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12886 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12887 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12888
paul718e3742002-12-13 20:15:29 +000012889 /* old command */
12890 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12891 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12892 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12893 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12894 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12895 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12896 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12897 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12898 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12899 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12900 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12901 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12902 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12903 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12904 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12905 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12906 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12907 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12908 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12909 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12910 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12911 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12912 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12913 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12914 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12915 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12916 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12917 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12918 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12919 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12920 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12921 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12922 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12923 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12924 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12925 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012926
paul718e3742002-12-13 20:15:29 +000012927 /* old command */
12928 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12929 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12930 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12931 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12932 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12933 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12934 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12935 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12936 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12937 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12938 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12939 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12940 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12941 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12942 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12943 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12944 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12945 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12946 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12947 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12948 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12949 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12950 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12951 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12952 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12953 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12954 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12955 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12956 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12957 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12958 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12959 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12960 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12961 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12962 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12963 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12964
12965 /* old command */
12966 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12967 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12968 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12969 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12970
12971 /* old command */
12972 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12973 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12974 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12975 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12976
12977 /* old command */
12978 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12979 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12980 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12981 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12982#endif /* HAVE_IPV6 */
12983
12984 install_element (BGP_NODE, &bgp_distance_cmd);
12985 install_element (BGP_NODE, &no_bgp_distance_cmd);
12986 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12987 install_element (BGP_NODE, &bgp_distance_source_cmd);
12988 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12989 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12990 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12991
12992 install_element (BGP_NODE, &bgp_damp_set_cmd);
12993 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12994 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12995 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12996 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12997 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12998 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12999 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
13000 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
13001 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013002
13003 /* Deprecated AS-Pathlimit commands */
13004 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13005 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13006 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13007 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13008 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13009 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13010
13011 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13012 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13013 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13014 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13015 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13016 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13017
13018 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13019 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13020 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13021 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13022 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13023 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13024
13025 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13026 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13027 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13028 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13029 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13030 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13031
13032 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13033 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13034 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13035 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13036 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13037 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13038
13039 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13040 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13041 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13042 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13043 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13044 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013045
13046#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013047 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13048 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013049#endif
paul718e3742002-12-13 20:15:29 +000013050}
Chris Caputo228da422009-07-18 05:44:03 +000013051
13052void
13053bgp_route_finish (void)
13054{
13055 bgp_table_unlock (bgp_distance_table);
13056 bgp_distance_table = NULL;
13057}