blob: 0f4da980f0c6543c42e8a2c7864e0e047f3ec3a2 [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"
paul718e3742002-12-13 20:15:29 +000057
58/* Extern from bgp_dump.c */
59extern char *bgp_origin_str[];
60extern char *bgp_origin_long_str[];
61
paul94f2b392005-06-28 12:44:16 +000062static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000063bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000064 struct prefix_rd *prd)
65{
66 struct bgp_node *rn;
67 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000068
69 assert (table);
70 if (!table)
71 return NULL;
72
paul718e3742002-12-13 20:15:29 +000073 if (safi == SAFI_MPLS_VPN)
74 {
paulfee0f4c2004-09-13 05:12:46 +000075 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000076
77 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000078 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000079 else
80 bgp_unlock_node (prn);
81 table = prn->info;
82 }
paul718e3742002-12-13 20:15:29 +000083
84 rn = bgp_node_get (table, p);
85
86 if (safi == SAFI_MPLS_VPN)
87 rn->prn = prn;
88
89 return rn;
90}
91
Paul Jakmafb982c22007-05-04 20:15:47 +000092/* Allocate bgp_info_extra */
93static struct bgp_info_extra *
94bgp_info_extra_new (void)
95{
96 struct bgp_info_extra *new;
97 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
98 return new;
99}
100
101static void
102bgp_info_extra_free (struct bgp_info_extra **extra)
103{
104 if (extra && *extra)
105 {
106 if ((*extra)->damp_info)
107 bgp_damp_info_free ((*extra)->damp_info, 0);
108
109 (*extra)->damp_info = NULL;
110
111 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
112
113 *extra = NULL;
114 }
115}
116
117/* Get bgp_info extra information for the given bgp_info, lazy allocated
118 * if required.
119 */
120struct bgp_info_extra *
121bgp_info_extra_get (struct bgp_info *ri)
122{
123 if (!ri->extra)
124 ri->extra = bgp_info_extra_new();
125 return ri->extra;
126}
127
paul718e3742002-12-13 20:15:29 +0000128/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000129static struct bgp_info *
paul718e3742002-12-13 20:15:29 +0000130bgp_info_new ()
131{
132 struct bgp_info *new;
133
134 new = XMALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
135 memset (new, 0, sizeof (struct bgp_info));
136
137 return new;
138}
139
140/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000141static void
paul718e3742002-12-13 20:15:29 +0000142bgp_info_free (struct bgp_info *binfo)
143{
144 if (binfo->attr)
145 bgp_attr_unintern (binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000146
147 bgp_info_extra_free (&binfo->extra);
paul718e3742002-12-13 20:15:29 +0000148
paul200df112005-06-01 11:17:05 +0000149 peer_unlock (binfo->peer); /* bgp_info peer reference */
150
paul718e3742002-12-13 20:15:29 +0000151 XFREE (MTYPE_BGP_ROUTE, binfo);
152}
153
paul200df112005-06-01 11:17:05 +0000154struct bgp_info *
155bgp_info_lock (struct bgp_info *binfo)
156{
157 binfo->lock++;
158 return binfo;
159}
160
161struct bgp_info *
162bgp_info_unlock (struct bgp_info *binfo)
163{
164 assert (binfo && binfo->lock > 0);
165 binfo->lock--;
166
167 if (binfo->lock == 0)
168 {
169#if 0
170 zlog_debug ("%s: unlocked and freeing", __func__);
171 zlog_backtrace (LOG_DEBUG);
172#endif
173 bgp_info_free (binfo);
174 return NULL;
175 }
176
177#if 0
178 if (binfo->lock == 1)
179 {
180 zlog_debug ("%s: unlocked to 1", __func__);
181 zlog_backtrace (LOG_DEBUG);
182 }
183#endif
184
185 return binfo;
186}
187
paul718e3742002-12-13 20:15:29 +0000188void
189bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
190{
191 struct bgp_info *top;
192
193 top = rn->info;
paul200df112005-06-01 11:17:05 +0000194
paul718e3742002-12-13 20:15:29 +0000195 ri->next = rn->info;
196 ri->prev = NULL;
197 if (top)
198 top->prev = ri;
199 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000200
201 bgp_info_lock (ri);
202 bgp_lock_node (rn);
203 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000204}
205
paulb40d9392005-08-22 22:34:41 +0000206/* Do the actual removal of info from RIB, for use by bgp_process
207 completion callback *only* */
208static void
209bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000210{
211 if (ri->next)
212 ri->next->prev = ri->prev;
213 if (ri->prev)
214 ri->prev->next = ri->next;
215 else
216 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000217
218 bgp_info_unlock (ri);
219 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000220}
221
paulb40d9392005-08-22 22:34:41 +0000222void
223bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
224{
Paul Jakma1a392d42006-09-07 00:24:49 +0000225 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
226 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000227 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
228}
229
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000230/* undo the effects of a previous call to bgp_info_delete; typically
231 called when a route is deleted and then quickly re-added before the
232 deletion has been processed */
233static void
234bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
235{
236 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
237 /* unset of previous already took care of pcount */
238 SET_FLAG (ri->flags, BGP_INFO_VALID);
239}
240
Paul Jakma1a392d42006-09-07 00:24:49 +0000241/* Adjust pcount as required */
242static void
243bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
244{
Paul Jakma6f585442006-10-22 19:13:07 +0000245 assert (rn && rn->table);
246 assert (ri && ri->peer && ri->peer->bgp);
247
Paul Jakma1a392d42006-09-07 00:24:49 +0000248 /* Ignore 'pcount' for RS-client tables */
249 if (rn->table->type != BGP_TABLE_MAIN
250 || ri->peer == ri->peer->bgp->peer_self)
251 return;
252
253 if (BGP_INFO_HOLDDOWN (ri)
254 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
255 {
256
257 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
258
259 /* slight hack, but more robust against errors. */
260 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
261 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
262 else
263 {
264 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
265 __func__, ri->peer->host);
266 zlog_backtrace (LOG_WARNING);
267 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
268 }
269 }
270 else if (!BGP_INFO_HOLDDOWN (ri)
271 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
272 {
273 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
274 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
275 }
276}
277
278
279/* Set/unset bgp_info flags, adjusting any other state as needed.
280 * This is here primarily to keep prefix-count in check.
281 */
282void
283bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
284{
285 SET_FLAG (ri->flags, flag);
286
287 /* early bath if we know it's not a flag that changes useability state */
288 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
289 return;
290
291 bgp_pcount_adjust (rn, ri);
292}
293
294void
295bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
296{
297 UNSET_FLAG (ri->flags, flag);
298
299 /* early bath if we know it's not a flag that changes useability state */
300 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
301 return;
302
303 bgp_pcount_adjust (rn, ri);
304}
305
paul718e3742002-12-13 20:15:29 +0000306/* Get MED value. If MED value is missing and "bgp bestpath
307 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000308static u_int32_t
paul718e3742002-12-13 20:15:29 +0000309bgp_med_value (struct attr *attr, struct bgp *bgp)
310{
311 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
312 return attr->med;
313 else
314 {
315 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000316 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000317 else
318 return 0;
319 }
320}
321
322/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000323static int
paul718e3742002-12-13 20:15:29 +0000324bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
325{
326 u_int32_t new_pref;
327 u_int32_t exist_pref;
328 u_int32_t new_med;
329 u_int32_t exist_med;
Paul Jakmafb982c22007-05-04 20:15:47 +0000330 u_int32_t new_weight = 0;
331 u_int32_t exist_weight = 0;
paul718e3742002-12-13 20:15:29 +0000332 struct in_addr new_id;
333 struct in_addr exist_id;
334 int new_cluster;
335 int exist_cluster;
336 int internal_as_route = 0;
337 int confed_as_route = 0;
338 int ret;
339
340 /* 0. Null check. */
341 if (new == NULL)
342 return 0;
343 if (exist == NULL)
344 return 1;
345
346 /* 1. Weight check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000347 if (new->attr->extra)
348 new_weight = new->attr->extra->weight;
349 if (exist->attr->extra)
350 exist_weight = exist->attr->extra->weight;
351 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000352 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000353 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000354 return 0;
355
356 /* 2. Local preference check. */
357 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
358 new_pref = new->attr->local_pref;
359 else
360 new_pref = bgp->default_local_pref;
361
362 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
363 exist_pref = exist->attr->local_pref;
364 else
365 exist_pref = bgp->default_local_pref;
366
367 if (new_pref > exist_pref)
368 return 1;
369 if (new_pref < exist_pref)
370 return 0;
371
372 /* 3. Local route check. */
373 if (new->sub_type == BGP_ROUTE_STATIC)
374 return 1;
375 if (exist->sub_type == BGP_ROUTE_STATIC)
376 return 0;
377
378 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
379 return 1;
380 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
381 return 0;
382
383 if (new->sub_type == BGP_ROUTE_AGGREGATE)
384 return 1;
385 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
386 return 0;
387
388 /* 4. AS path length check. */
389 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
390 {
paulfe69a502005-09-10 16:55:02 +0000391 int exist_hops = aspath_count_hops (exist->attr->aspath);
392 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
393
hasso68118452005-04-08 15:40:36 +0000394 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
395 {
paulfe69a502005-09-10 16:55:02 +0000396 int aspath_hops;
397
398 aspath_hops = aspath_count_hops (new->attr->aspath);
399 aspath_hops += aspath_count_confeds (new->attr->aspath);
400
401 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000402 return 1;
paulfe69a502005-09-10 16:55:02 +0000403 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000404 return 0;
405 }
406 else
407 {
paulfe69a502005-09-10 16:55:02 +0000408 int newhops = aspath_count_hops (new->attr->aspath);
409
410 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000411 return 1;
paulfe69a502005-09-10 16:55:02 +0000412 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000413 return 0;
414 }
paul718e3742002-12-13 20:15:29 +0000415 }
416
417 /* 5. Origin check. */
418 if (new->attr->origin < exist->attr->origin)
419 return 1;
420 if (new->attr->origin > exist->attr->origin)
421 return 0;
422
423 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000424 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
425 && aspath_count_hops (exist->attr->aspath) == 0);
426 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
427 && aspath_count_confeds (exist->attr->aspath) > 0
428 && aspath_count_hops (new->attr->aspath) == 0
429 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000430
431 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
432 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
433 && confed_as_route)
434 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
435 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
436 || internal_as_route)
437 {
438 new_med = bgp_med_value (new->attr, bgp);
439 exist_med = bgp_med_value (exist->attr, bgp);
440
441 if (new_med < exist_med)
442 return 1;
443 if (new_med > exist_med)
444 return 0;
445 }
446
447 /* 7. Peer type check. */
448 if (peer_sort (new->peer) == BGP_PEER_EBGP
449 && peer_sort (exist->peer) == BGP_PEER_IBGP)
450 return 1;
451 if (peer_sort (new->peer) == BGP_PEER_EBGP
452 && peer_sort (exist->peer) == BGP_PEER_CONFED)
453 return 1;
454 if (peer_sort (new->peer) == BGP_PEER_IBGP
455 && peer_sort (exist->peer) == BGP_PEER_EBGP)
456 return 0;
457 if (peer_sort (new->peer) == BGP_PEER_CONFED
458 && peer_sort (exist->peer) == BGP_PEER_EBGP)
459 return 0;
460
461 /* 8. IGP metric check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000462 if (new->extra || exist->extra)
463 {
464 uint32_t newm = (new->extra ? new->extra->igpmetric : 0);
465 uint32_t existm = (exist->extra ? exist->extra->igpmetric : 0);
466
467 if (newm < existm)
468 return 1;
469 if (newm > existm)
470 return 0;
471 }
paul718e3742002-12-13 20:15:29 +0000472
473 /* 9. Maximum path check. */
474
475 /* 10. If both paths are external, prefer the path that was received
476 first (the oldest one). This step minimizes route-flap, since a
477 newer path won't displace an older one, even if it was the
478 preferred route based on the additional decision criteria below. */
479 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
480 && peer_sort (new->peer) == BGP_PEER_EBGP
481 && peer_sort (exist->peer) == BGP_PEER_EBGP)
482 {
483 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
484 return 1;
485 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
486 return 0;
487 }
488
489 /* 11. Rourter-ID comparision. */
490 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000491 new_id.s_addr = new->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000492 else
493 new_id.s_addr = new->peer->remote_id.s_addr;
494 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000495 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000496 else
497 exist_id.s_addr = exist->peer->remote_id.s_addr;
498
499 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
500 return 1;
501 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
502 return 0;
503
504 /* 12. Cluster length comparision. */
505 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000506 new_cluster = new->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000507 else
508 new_cluster = 0;
509 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000510 exist_cluster = exist->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000511 else
512 exist_cluster = 0;
513
514 if (new_cluster < exist_cluster)
515 return 1;
516 if (new_cluster > exist_cluster)
517 return 0;
518
519 /* 13. Neighbor address comparision. */
520 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
521
522 if (ret == 1)
523 return 0;
524 if (ret == -1)
525 return 1;
526
527 return 1;
528}
529
paul94f2b392005-06-28 12:44:16 +0000530static enum filter_type
paul718e3742002-12-13 20:15:29 +0000531bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
532 afi_t afi, safi_t safi)
533{
534 struct bgp_filter *filter;
535
536 filter = &peer->filter[afi][safi];
537
538 if (DISTRIBUTE_IN_NAME (filter))
539 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
540 return FILTER_DENY;
541
542 if (PREFIX_LIST_IN_NAME (filter))
543 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
544 return FILTER_DENY;
545
546 if (FILTER_LIST_IN_NAME (filter))
547 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
548 return FILTER_DENY;
549
550 return FILTER_PERMIT;
551}
552
paul94f2b392005-06-28 12:44:16 +0000553static enum filter_type
paul718e3742002-12-13 20:15:29 +0000554bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
555 afi_t afi, safi_t safi)
556{
557 struct bgp_filter *filter;
558
559 filter = &peer->filter[afi][safi];
560
561 if (DISTRIBUTE_OUT_NAME (filter))
562 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
563 return FILTER_DENY;
564
565 if (PREFIX_LIST_OUT_NAME (filter))
566 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
567 return FILTER_DENY;
568
569 if (FILTER_LIST_OUT_NAME (filter))
570 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
571 return FILTER_DENY;
572
573 return FILTER_PERMIT;
574}
575
576/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000577static int
paul718e3742002-12-13 20:15:29 +0000578bgp_community_filter (struct peer *peer, struct attr *attr)
579{
580 if (attr->community)
581 {
582 /* NO_ADVERTISE check. */
583 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
584 return 1;
585
586 /* NO_EXPORT check. */
587 if (peer_sort (peer) == BGP_PEER_EBGP &&
588 community_include (attr->community, COMMUNITY_NO_EXPORT))
589 return 1;
590
591 /* NO_EXPORT_SUBCONFED check. */
592 if (peer_sort (peer) == BGP_PEER_EBGP
593 || peer_sort (peer) == BGP_PEER_CONFED)
594 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
595 return 1;
596 }
597 return 0;
598}
599
600/* Route reflection loop check. */
601static int
602bgp_cluster_filter (struct peer *peer, struct attr *attr)
603{
604 struct in_addr cluster_id;
605
Paul Jakmafb982c22007-05-04 20:15:47 +0000606 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000607 {
608 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
609 cluster_id = peer->bgp->cluster_id;
610 else
611 cluster_id = peer->bgp->router_id;
612
Paul Jakmafb982c22007-05-04 20:15:47 +0000613 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000614 return 1;
615 }
616 return 0;
617}
618
paul94f2b392005-06-28 12:44:16 +0000619static int
paul718e3742002-12-13 20:15:29 +0000620bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
621 afi_t afi, safi_t safi)
622{
623 struct bgp_filter *filter;
624 struct bgp_info info;
625 route_map_result_t ret;
626
627 filter = &peer->filter[afi][safi];
628
629 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000630 if (peer->weight)
631 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000632
633 /* Route map apply. */
634 if (ROUTE_MAP_IN_NAME (filter))
635 {
636 /* Duplicate current value to new strucutre for modification. */
637 info.peer = peer;
638 info.attr = attr;
639
paulac41b2a2003-08-12 05:32:27 +0000640 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
641
paul718e3742002-12-13 20:15:29 +0000642 /* Apply BGP route map to the attribute. */
643 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000644
645 peer->rmap_type = 0;
646
paul718e3742002-12-13 20:15:29 +0000647 if (ret == RMAP_DENYMATCH)
648 {
649 /* Free newly generated AS path and community by route-map. */
650 bgp_attr_flush (attr);
651 return RMAP_DENY;
652 }
653 }
654 return RMAP_PERMIT;
655}
656
paul94f2b392005-06-28 12:44:16 +0000657static int
paulfee0f4c2004-09-13 05:12:46 +0000658bgp_export_modifier (struct peer *rsclient, struct peer *peer,
659 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
660{
661 struct bgp_filter *filter;
662 struct bgp_info info;
663 route_map_result_t ret;
664
665 filter = &peer->filter[afi][safi];
666
667 /* Route map apply. */
668 if (ROUTE_MAP_EXPORT_NAME (filter))
669 {
670 /* Duplicate current value to new strucutre for modification. */
671 info.peer = rsclient;
672 info.attr = attr;
673
674 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
675
676 /* Apply BGP route map to the attribute. */
677 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
678
679 rsclient->rmap_type = 0;
680
681 if (ret == RMAP_DENYMATCH)
682 {
683 /* Free newly generated AS path and community by route-map. */
684 bgp_attr_flush (attr);
685 return RMAP_DENY;
686 }
687 }
688 return RMAP_PERMIT;
689}
690
paul94f2b392005-06-28 12:44:16 +0000691static int
paulfee0f4c2004-09-13 05:12:46 +0000692bgp_import_modifier (struct peer *rsclient, struct peer *peer,
693 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
694{
695 struct bgp_filter *filter;
696 struct bgp_info info;
697 route_map_result_t ret;
698
699 filter = &rsclient->filter[afi][safi];
700
701 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000702 if (peer->weight)
703 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000704
705 /* Route map apply. */
706 if (ROUTE_MAP_IMPORT_NAME (filter))
707 {
708 /* Duplicate current value to new strucutre for modification. */
709 info.peer = peer;
710 info.attr = attr;
711
712 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
713
714 /* Apply BGP route map to the attribute. */
715 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
716
717 peer->rmap_type = 0;
718
719 if (ret == RMAP_DENYMATCH)
720 {
721 /* Free newly generated AS path and community by route-map. */
722 bgp_attr_flush (attr);
723 return RMAP_DENY;
724 }
725 }
726 return RMAP_PERMIT;
727}
728
paul94f2b392005-06-28 12:44:16 +0000729static int
paul718e3742002-12-13 20:15:29 +0000730bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
731 struct attr *attr, afi_t afi, safi_t safi)
732{
733 int ret;
734 char buf[SU_ADDRSTRLEN];
735 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000736 struct peer *from;
737 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000738 int transparent;
739 int reflect;
740
741 from = ri->peer;
742 filter = &peer->filter[afi][safi];
743 bgp = peer->bgp;
744
745#ifdef DISABLE_BGP_ANNOUNCE
746 return 0;
747#endif
748
paulfee0f4c2004-09-13 05:12:46 +0000749 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
750 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
751 return 0;
752
paul718e3742002-12-13 20:15:29 +0000753 /* Do not send back route to sender. */
754 if (from == peer)
755 return 0;
756
paul35be31b2004-05-01 18:17:04 +0000757 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
758 if (p->family == AF_INET
759 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
760 return 0;
761#ifdef HAVE_IPV6
762 if (p->family == AF_INET6
763 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
764 return 0;
765#endif
766
paul718e3742002-12-13 20:15:29 +0000767 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000768 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000769 if (! UNSUPPRESS_MAP_NAME (filter))
770 return 0;
771
772 /* Default route check. */
773 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
774 {
775 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
776 return 0;
777#ifdef HAVE_IPV6
778 else if (p->family == AF_INET6 && p->prefixlen == 0)
779 return 0;
780#endif /* HAVE_IPV6 */
781 }
782
paul286e1e72003-08-08 00:24:31 +0000783 /* Transparency check. */
784 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
785 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
786 transparent = 1;
787 else
788 transparent = 0;
789
paul718e3742002-12-13 20:15:29 +0000790 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000791 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000792 return 0;
793
794 /* If the attribute has originator-id and it is same as remote
795 peer's id. */
796 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
797 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000798 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000799 {
800 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000801 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000802 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
803 peer->host,
804 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
805 p->prefixlen);
806 return 0;
807 }
808 }
809
810 /* ORF prefix-list filter check */
811 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
812 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
813 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
814 if (peer->orf_plist[afi][safi])
815 {
816 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
817 return 0;
818 }
819
820 /* Output filter check. */
821 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
822 {
823 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000824 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000825 "%s [Update:SEND] %s/%d is filtered",
826 peer->host,
827 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
828 p->prefixlen);
829 return 0;
830 }
831
832#ifdef BGP_SEND_ASPATH_CHECK
833 /* AS path loop check. */
834 if (aspath_loop_check (ri->attr->aspath, peer->as))
835 {
836 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000837 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000838 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
839 peer->host, peer->as);
840 return 0;
841 }
842#endif /* BGP_SEND_ASPATH_CHECK */
843
844 /* If we're a CONFED we need to loop check the CONFED ID too */
845 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
846 {
847 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
848 {
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] suppress announcement to peer AS %d is AS path.",
852 peer->host,
853 bgp->confed_id);
854 return 0;
855 }
856 }
857
858 /* Route-Reflect check. */
859 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
860 reflect = 1;
861 else
862 reflect = 0;
863
864 /* IBGP reflection check. */
865 if (reflect)
866 {
867 /* A route from a Client peer. */
868 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
869 {
870 /* Reflect to all the Non-Client peers and also to the
871 Client peers other than the originator. Originator check
872 is already done. So there is noting to do. */
873 /* no bgp client-to-client reflection check. */
874 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
875 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
876 return 0;
877 }
878 else
879 {
880 /* A route from a Non-client peer. Reflect to all other
881 clients. */
882 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
883 return 0;
884 }
885 }
Paul Jakma41367172007-08-06 15:24:51 +0000886
887 /* AS-Pathlimit check */
888 if (ri->attr->pathlimit.ttl && peer_sort (peer) == BGP_PEER_EBGP)
889 /* Our ASN has not yet been pre-pended, that's done in packet_attribute
890 * on output. Hence the test here is for >=.
891 */
892 if (aspath_count_hops (ri->attr->aspath) >= ri->attr->pathlimit.ttl)
893 {
894 if (BGP_DEBUG (filter, FILTER))
895 zlog_info ("%s [Update:SEND] suppressed, AS-Pathlimit TTL %u exceeded",
896 peer->host, ri->attr->pathlimit.ttl);
897 return 0;
898 }
899
paul718e3742002-12-13 20:15:29 +0000900 /* For modify attribute, copy it to temporary structure. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000901 bgp_attr_dup (attr, ri->attr);
902
paul718e3742002-12-13 20:15:29 +0000903 /* If local-preference is not set. */
904 if ((peer_sort (peer) == BGP_PEER_IBGP
905 || peer_sort (peer) == BGP_PEER_CONFED)
906 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
907 {
908 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
909 attr->local_pref = bgp->default_local_pref;
910 }
911
paul718e3742002-12-13 20:15:29 +0000912 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
913 if (peer_sort (peer) == BGP_PEER_EBGP
914 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
915 {
916 if (ri->peer != bgp->peer_self && ! transparent
917 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
918 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
919 }
920
921 /* next-hop-set */
922 if (transparent || reflect
923 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
924 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000925#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000926 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000927 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000928#endif /* HAVE_IPV6 */
929 )))
paul718e3742002-12-13 20:15:29 +0000930 {
931 /* NEXT-HOP Unchanged. */
932 }
933 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
934 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
935#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000936 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000937 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000938#endif /* HAVE_IPV6 */
939 || (peer_sort (peer) == BGP_PEER_EBGP
940 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
941 {
942 /* Set IPv4 nexthop. */
943 if (p->family == AF_INET)
944 {
945 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000946 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
947 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000948 else
949 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
950 }
951#ifdef HAVE_IPV6
952 /* Set IPv6 nexthop. */
953 if (p->family == AF_INET6)
954 {
955 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000956 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000957 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000958 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000959 }
960#endif /* HAVE_IPV6 */
961 }
962
963#ifdef HAVE_IPV6
964 if (p->family == AF_INET6)
965 {
paulfee0f4c2004-09-13 05:12:46 +0000966 /* Left nexthop_local unchanged if so configured. */
967 if ( CHECK_FLAG (peer->af_flags[afi][safi],
968 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
969 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000970 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
971 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +0000972 else
Paul Jakmafb982c22007-05-04 20:15:47 +0000973 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +0000974 }
975
976 /* Default nexthop_local treatment for non-RS-Clients */
977 else
978 {
paul718e3742002-12-13 20:15:29 +0000979 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000980 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000981
982 /* Set link-local address for shared network peer. */
983 if (peer->shared_network
984 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
985 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000986 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +0000987 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000988 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +0000989 }
990
991 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
992 address.*/
993 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +0000994 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000995
996 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
997 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +0000998 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000999 }
paulfee0f4c2004-09-13 05:12:46 +00001000
1001 }
paul718e3742002-12-13 20:15:29 +00001002#endif /* HAVE_IPV6 */
1003
Paul Jakma41367172007-08-06 15:24:51 +00001004 /* AS-Pathlimit: Check ASN for private/confed */
1005 if (attr->pathlimit.ttl)
1006 {
1007 /* locally originated update */
1008 if (!attr->pathlimit.as)
1009 attr->pathlimit.as = peer->local_as;
1010
1011 /* if the AS_PATHLIMIT attribute is attached to a prefix by a
1012 member of a confederation, then when the prefix is advertised outside
1013 of the confederation boundary, then the AS number of the
1014 confederation member inside of the AS_PATHLIMIT attribute should be
1015 replaced by the confederation's AS number. */
1016 if (peer_sort (from) == BGP_PEER_CONFED
1017 && peer_sort (peer) != BGP_PEER_CONFED)
1018 attr->pathlimit.as = peer->local_as;
1019
1020 /* Private ASN should be updated whenever announcement leaves
1021 * private space. This is deliberately done after simple confed
1022 * based update..
1023 */
1024 if (attr->pathlimit.as >= BGP_PRIVATE_AS_MIN
1025 && attr->pathlimit.as <= BGP_PRIVATE_AS_MAX)
1026 {
1027 if (peer->local_as < BGP_PRIVATE_AS_MIN
1028 || peer->local_as > BGP_PRIVATE_AS_MAX)
1029 attr->pathlimit.as = peer->local_as;
1030 /* Ours is private, try using theirs.. */
1031 else if (peer->as < BGP_PRIVATE_AS_MIN
1032 || peer->local_as > BGP_PRIVATE_AS_MAX)
1033 attr->pathlimit.as = peer->as;
1034 }
1035 }
1036
paul718e3742002-12-13 20:15:29 +00001037 /* If this is EBGP peer and remove-private-AS is set. */
1038 if (peer_sort (peer) == BGP_PEER_EBGP
1039 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1040 && aspath_private_as_check (attr->aspath))
1041 attr->aspath = aspath_empty_get ();
1042
1043 /* Route map & unsuppress-map apply. */
1044 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001045 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001046 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001047 struct bgp_info info;
1048 struct attr dummy_attr;
1049
paul718e3742002-12-13 20:15:29 +00001050 info.peer = peer;
1051 info.attr = attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00001052
paul718e3742002-12-13 20:15:29 +00001053
1054 /* The route reflector is not allowed to modify the attributes
1055 of the reflected IBGP routes. */
1056 if (peer_sort (from) == BGP_PEER_IBGP
1057 && peer_sort (peer) == BGP_PEER_IBGP)
1058 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001059 dummy_attr.extra = NULL;
1060 bgp_attr_dup (&dummy_attr, attr);
1061 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001062 }
paulac41b2a2003-08-12 05:32:27 +00001063
1064 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1065
Paul Jakmafb982c22007-05-04 20:15:47 +00001066 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001067 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1068 else
1069 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1070
paulac41b2a2003-08-12 05:32:27 +00001071 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001072
1073 bgp_attr_extra_free (&dummy_attr);
1074
paul718e3742002-12-13 20:15:29 +00001075 if (ret == RMAP_DENYMATCH)
1076 {
1077 bgp_attr_flush (attr);
1078 return 0;
1079 }
1080 }
1081 return 1;
1082}
1083
paul94f2b392005-06-28 12:44:16 +00001084static int
paulfee0f4c2004-09-13 05:12:46 +00001085bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1086 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001087{
paulfee0f4c2004-09-13 05:12:46 +00001088 int ret;
1089 char buf[SU_ADDRSTRLEN];
1090 struct bgp_filter *filter;
1091 struct bgp_info info;
1092 struct peer *from;
1093 struct bgp *bgp;
1094
1095 from = ri->peer;
1096 filter = &rsclient->filter[afi][safi];
1097 bgp = rsclient->bgp;
1098
1099#ifdef DISABLE_BGP_ANNOUNCE
1100 return 0;
1101#endif
1102
1103 /* Do not send back route to sender. */
1104 if (from == rsclient)
1105 return 0;
1106
1107 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001108 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001109 if (! UNSUPPRESS_MAP_NAME (filter))
1110 return 0;
1111
1112 /* Default route check. */
1113 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1114 PEER_STATUS_DEFAULT_ORIGINATE))
1115 {
1116 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1117 return 0;
1118#ifdef HAVE_IPV6
1119 else if (p->family == AF_INET6 && p->prefixlen == 0)
1120 return 0;
1121#endif /* HAVE_IPV6 */
1122 }
1123
1124 /* If the attribute has originator-id and it is same as remote
1125 peer's id. */
1126 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1127 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001128 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1129 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001130 {
1131 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001132 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001133 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1134 rsclient->host,
1135 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1136 p->prefixlen);
1137 return 0;
1138 }
1139 }
1140
1141 /* ORF prefix-list filter check */
1142 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1143 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1144 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1145 if (rsclient->orf_plist[afi][safi])
1146 {
1147 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1148 return 0;
1149 }
1150
1151 /* Output filter check. */
1152 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1153 {
1154 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001155 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001156 "%s [Update:SEND] %s/%d is filtered",
1157 rsclient->host,
1158 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1159 p->prefixlen);
1160 return 0;
1161 }
1162
1163#ifdef BGP_SEND_ASPATH_CHECK
1164 /* AS path loop check. */
1165 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1166 {
1167 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001168 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001169 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
1170 rsclient->host, rsclient->as);
1171 return 0;
1172 }
1173#endif /* BGP_SEND_ASPATH_CHECK */
1174
1175 /* For modify attribute, copy it to temporary structure. */
1176 *attr = *ri->attr;
1177
1178 /* next-hop-set */
1179 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1180#ifdef HAVE_IPV6
1181 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001182 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001183#endif /* HAVE_IPV6 */
1184 )
1185 {
1186 /* Set IPv4 nexthop. */
1187 if (p->family == AF_INET)
1188 {
1189 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001190 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001191 IPV4_MAX_BYTELEN);
1192 else
1193 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1194 }
1195#ifdef HAVE_IPV6
1196 /* Set IPv6 nexthop. */
1197 if (p->family == AF_INET6)
1198 {
1199 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001200 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001201 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001202 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001203 }
1204#endif /* HAVE_IPV6 */
1205 }
1206
1207#ifdef HAVE_IPV6
1208 if (p->family == AF_INET6)
1209 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001210 struct attr_extra *attre = attr->extra;
1211
1212 assert (attr->extra);
1213
paulfee0f4c2004-09-13 05:12:46 +00001214 /* Left nexthop_local unchanged if so configured. */
1215 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1216 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1217 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001218 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1219 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001220 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001221 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001222 }
1223
1224 /* Default nexthop_local treatment for RS-Clients */
1225 else
1226 {
1227 /* Announcer and RS-Client are both in the same network */
1228 if (rsclient->shared_network && from->shared_network &&
1229 (rsclient->ifindex == from->ifindex))
1230 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001231 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1232 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001233 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001234 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001235 }
1236
1237 /* Set link-local address for shared network peer. */
1238 else if (rsclient->shared_network
1239 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1240 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001241 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001242 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001243 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001244 }
1245
1246 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001247 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001248 }
1249
1250 }
1251#endif /* HAVE_IPV6 */
1252
1253
1254 /* If this is EBGP peer and remove-private-AS is set. */
1255 if (peer_sort (rsclient) == BGP_PEER_EBGP
1256 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1257 && aspath_private_as_check (attr->aspath))
1258 attr->aspath = aspath_empty_get ();
1259
1260 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001261 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001262 {
1263 info.peer = rsclient;
1264 info.attr = attr;
1265
1266 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1267
Paul Jakmafb982c22007-05-04 20:15:47 +00001268 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001269 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1270 else
1271 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1272
1273 rsclient->rmap_type = 0;
1274
1275 if (ret == RMAP_DENYMATCH)
1276 {
1277 bgp_attr_flush (attr);
1278 return 0;
1279 }
1280 }
1281
1282 return 1;
1283}
1284
1285struct bgp_info_pair
1286{
1287 struct bgp_info *old;
1288 struct bgp_info *new;
1289};
1290
paul94f2b392005-06-28 12:44:16 +00001291static void
paulfee0f4c2004-09-13 05:12:46 +00001292bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1293{
paul718e3742002-12-13 20:15:29 +00001294 struct bgp_info *new_select;
1295 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001296 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001297 struct bgp_info *ri1;
1298 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001299 struct bgp_info *nextri = NULL;
1300
paul718e3742002-12-13 20:15:29 +00001301 /* bgp deterministic-med */
1302 new_select = NULL;
1303 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1304 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1305 {
1306 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1307 continue;
1308 if (BGP_INFO_HOLDDOWN (ri1))
1309 continue;
1310
1311 new_select = ri1;
1312 if (ri1->next)
1313 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1314 {
1315 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1316 continue;
1317 if (BGP_INFO_HOLDDOWN (ri2))
1318 continue;
1319
1320 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1321 || aspath_cmp_left_confed (ri1->attr->aspath,
1322 ri2->attr->aspath))
1323 {
1324 if (bgp_info_cmp (bgp, ri2, new_select))
1325 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001326 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001327 new_select = ri2;
1328 }
1329
Paul Jakma1a392d42006-09-07 00:24:49 +00001330 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001331 }
1332 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001333 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1334 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001335 }
1336
1337 /* Check old selected route and new selected route. */
1338 old_select = NULL;
1339 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001340 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001341 {
1342 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1343 old_select = ri;
1344
1345 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001346 {
1347 /* reap REMOVED routes, if needs be
1348 * selected route must stay for a while longer though
1349 */
1350 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1351 && (ri != old_select))
1352 bgp_info_reap (rn, ri);
1353
1354 continue;
1355 }
paul718e3742002-12-13 20:15:29 +00001356
1357 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1358 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1359 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001360 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001361 continue;
1362 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001363 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1364 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001365
1366 if (bgp_info_cmp (bgp, ri, new_select))
1367 new_select = ri;
1368 }
paulb40d9392005-08-22 22:34:41 +00001369
paulfee0f4c2004-09-13 05:12:46 +00001370 result->old = old_select;
1371 result->new = new_select;
1372
1373 return;
1374}
1375
paul94f2b392005-06-28 12:44:16 +00001376static int
paulfee0f4c2004-09-13 05:12:46 +00001377bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
1378 struct bgp_node *rn, struct attr *attr, afi_t afi, safi_t safi)
1379 {
1380 struct prefix *p;
1381
1382 p = &rn->p;
1383
1384 /* Announce route to Established peer. */
1385 if (peer->status != Established)
1386 return 0;
1387
1388 /* Address family configuration check. */
1389 if (! peer->afc_nego[afi][safi])
1390 return 0;
1391
1392 /* First update is deferred until ORF or ROUTE-REFRESH is received */
1393 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1394 PEER_STATUS_ORF_WAIT_REFRESH))
1395 return 0;
1396
1397 switch (rn->table->type)
1398 {
1399 case BGP_TABLE_MAIN:
1400 /* Announcement to peer->conf. If the route is filtered,
1401 withdraw it. */
1402 if (selected && bgp_announce_check (selected, peer, p, attr, afi, safi))
1403 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1404 else
1405 bgp_adj_out_unset (rn, peer, p, afi, safi);
1406 break;
1407 case BGP_TABLE_RSCLIENT:
1408 /* Announcement to peer->conf. If the route is filtered,
1409 withdraw it. */
1410 if (selected && bgp_announce_check_rsclient
1411 (selected, peer, p, attr, afi, safi))
1412 bgp_adj_out_set (rn, peer, p, attr, afi, safi, selected);
1413 else
1414 bgp_adj_out_unset (rn, peer, p, afi, safi);
1415 break;
1416 }
1417 return 0;
paul200df112005-06-01 11:17:05 +00001418}
paulfee0f4c2004-09-13 05:12:46 +00001419
paul200df112005-06-01 11:17:05 +00001420struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001421{
paul200df112005-06-01 11:17:05 +00001422 struct bgp *bgp;
1423 struct bgp_node *rn;
1424 afi_t afi;
1425 safi_t safi;
1426};
1427
1428static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001429bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001430{
paul0fb58d52005-11-14 14:31:49 +00001431 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001432 struct bgp *bgp = pq->bgp;
1433 struct bgp_node *rn = pq->rn;
1434 afi_t afi = pq->afi;
1435 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001436 struct bgp_info *new_select;
1437 struct bgp_info *old_select;
1438 struct bgp_info_pair old_and_new;
1439 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001440 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001441 struct peer *rsclient = rn->table->owner;
1442
Paul Jakmafb982c22007-05-04 20:15:47 +00001443 memset (&attr, 0, sizeof (struct attr));
paulfee0f4c2004-09-13 05:12:46 +00001444 /* Best path selection. */
1445 bgp_best_selection (bgp, rn, &old_and_new);
1446 new_select = old_and_new.new;
1447 old_select = old_and_new.old;
1448
paul200df112005-06-01 11:17:05 +00001449 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1450 {
1451 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1452 {
1453 /* Nothing to do. */
1454 if (old_select && old_select == new_select)
1455 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1456 continue;
paulfee0f4c2004-09-13 05:12:46 +00001457
paul200df112005-06-01 11:17:05 +00001458 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001459 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
paul200df112005-06-01 11:17:05 +00001460 if (new_select)
1461 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001462 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1463 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
paul200df112005-06-01 11:17:05 +00001464 }
paulfee0f4c2004-09-13 05:12:46 +00001465
paul200df112005-06-01 11:17:05 +00001466 bgp_process_announce_selected (rsclient, new_select, rn, &attr,
1467 afi, safi);
1468 }
1469 }
1470 else
1471 {
hassob7395792005-08-26 12:58:38 +00001472 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001473 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001474 if (new_select)
1475 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001476 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1477 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001478 }
paul200df112005-06-01 11:17:05 +00001479 bgp_process_announce_selected (rsclient, new_select, rn,
1480 &attr, afi, safi);
1481 }
paulfee0f4c2004-09-13 05:12:46 +00001482
paulb40d9392005-08-22 22:34:41 +00001483 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1484 bgp_info_reap (rn, old_select);
1485
Paul Jakmafb982c22007-05-04 20:15:47 +00001486 bgp_attr_extra_free (&attr);
1487
paul200df112005-06-01 11:17:05 +00001488 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1489 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001490}
1491
paul200df112005-06-01 11:17:05 +00001492static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001493bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001494{
paul0fb58d52005-11-14 14:31:49 +00001495 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001496 struct bgp *bgp = pq->bgp;
1497 struct bgp_node *rn = pq->rn;
1498 afi_t afi = pq->afi;
1499 safi_t safi = pq->safi;
1500 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001501 struct bgp_info *new_select;
1502 struct bgp_info *old_select;
1503 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001504 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001505 struct peer *peer;
1506 struct attr attr;
paul200df112005-06-01 11:17:05 +00001507
Paul Jakmafb982c22007-05-04 20:15:47 +00001508 memset (&attr, 0, sizeof (struct attr));
1509
paulfee0f4c2004-09-13 05:12:46 +00001510 /* Best path selection. */
1511 bgp_best_selection (bgp, rn, &old_and_new);
1512 old_select = old_and_new.old;
1513 new_select = old_and_new.new;
1514
1515 /* Nothing to do. */
1516 if (old_select && old_select == new_select)
1517 {
1518 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001519 {
1520 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1521 bgp_zebra_announce (p, old_select, bgp);
1522
1523 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1524 return WQ_SUCCESS;
1525 }
paulfee0f4c2004-09-13 05:12:46 +00001526 }
paul718e3742002-12-13 20:15:29 +00001527
hasso338b3422005-02-23 14:27:24 +00001528 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001529 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001530 if (new_select)
1531 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001532 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1533 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001534 }
1535
1536
paul718e3742002-12-13 20:15:29 +00001537 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001538 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001539 {
paulfee0f4c2004-09-13 05:12:46 +00001540 bgp_process_announce_selected (peer, new_select, rn, &attr, afi, safi);
paul718e3742002-12-13 20:15:29 +00001541 }
1542
1543 /* FIB update. */
1544 if (safi == SAFI_UNICAST && ! bgp->name &&
1545 ! bgp_option_check (BGP_OPT_NO_FIB))
1546 {
1547 if (new_select
1548 && new_select->type == ZEBRA_ROUTE_BGP
1549 && new_select->sub_type == BGP_ROUTE_NORMAL)
1550 bgp_zebra_announce (p, new_select, bgp);
1551 else
1552 {
1553 /* Withdraw the route from the kernel. */
1554 if (old_select
1555 && old_select->type == ZEBRA_ROUTE_BGP
1556 && old_select->sub_type == BGP_ROUTE_NORMAL)
1557 bgp_zebra_withdraw (p, old_select);
1558 }
1559 }
paulb40d9392005-08-22 22:34:41 +00001560
1561 /* Reap old select bgp_info, it it has been removed */
1562 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1563 bgp_info_reap (rn, old_select);
1564
Paul Jakmafb982c22007-05-04 20:15:47 +00001565 bgp_attr_extra_free (&attr);
1566
paul200df112005-06-01 11:17:05 +00001567 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1568 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001569}
1570
paul200df112005-06-01 11:17:05 +00001571static void
paul0fb58d52005-11-14 14:31:49 +00001572bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001573{
paul0fb58d52005-11-14 14:31:49 +00001574 struct bgp_process_queue *pq = data;
1575
paul200df112005-06-01 11:17:05 +00001576 bgp_unlock_node (pq->rn);
1577 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1578}
1579
1580static void
1581bgp_process_queue_init (void)
1582{
1583 bm->process_main_queue
1584 = work_queue_new (bm->master, "process_main_queue");
1585 bm->process_rsclient_queue
1586 = work_queue_new (bm->master, "process_rsclient_queue");
1587
1588 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1589 {
1590 zlog_err ("%s: Failed to allocate work queue", __func__);
1591 exit (1);
1592 }
1593
1594 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1595 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1596 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1597 bm->process_rsclient_queue->spec.del_item_data
1598 = bm->process_main_queue->spec.del_item_data;
1599 bm->process_main_queue->spec.max_retries
1600 = bm->process_main_queue->spec.max_retries = 0;
1601 bm->process_rsclient_queue->spec.hold
Paul Jakma09dd5612006-09-14 03:38:16 +00001602 = bm->process_main_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001603}
1604
1605void
paulfee0f4c2004-09-13 05:12:46 +00001606bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1607{
paul200df112005-06-01 11:17:05 +00001608 struct bgp_process_queue *pqnode;
1609
1610 /* already scheduled for processing? */
1611 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1612 return;
1613
1614 if ( (bm->process_main_queue == NULL) ||
1615 (bm->process_rsclient_queue == NULL) )
1616 bgp_process_queue_init ();
1617
1618 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1619 sizeof (struct bgp_process_queue));
1620 if (!pqnode)
1621 return;
1622
1623 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1624 pqnode->bgp = bgp;
1625 pqnode->afi = afi;
1626 pqnode->safi = safi;
1627
paulfee0f4c2004-09-13 05:12:46 +00001628 switch (rn->table->type)
1629 {
paul200df112005-06-01 11:17:05 +00001630 case BGP_TABLE_MAIN:
1631 work_queue_add (bm->process_main_queue, pqnode);
1632 break;
1633 case BGP_TABLE_RSCLIENT:
1634 work_queue_add (bm->process_rsclient_queue, pqnode);
1635 break;
paulfee0f4c2004-09-13 05:12:46 +00001636 }
paul200df112005-06-01 11:17:05 +00001637
1638 return;
paulfee0f4c2004-09-13 05:12:46 +00001639}
hasso0a486e52005-02-01 20:57:17 +00001640
paul94f2b392005-06-28 12:44:16 +00001641static int
hasso0a486e52005-02-01 20:57:17 +00001642bgp_maximum_prefix_restart_timer (struct thread *thread)
1643{
1644 struct peer *peer;
1645
1646 peer = THREAD_ARG (thread);
1647 peer->t_pmax_restart = NULL;
1648
1649 if (BGP_DEBUG (events, EVENTS))
1650 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1651 peer->host);
1652
1653 peer_clear (peer);
1654
1655 return 0;
1656}
1657
paulfee0f4c2004-09-13 05:12:46 +00001658int
paul5228ad22004-06-04 17:58:18 +00001659bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1660 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001661{
hassoe0701b72004-05-20 09:19:34 +00001662 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1663 return 0;
1664
1665 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001666 {
hassoe0701b72004-05-20 09:19:34 +00001667 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1668 && ! always)
1669 return 0;
paul718e3742002-12-13 20:15:29 +00001670
hassoe0701b72004-05-20 09:19:34 +00001671 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001672 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1673 "limit %ld", afi_safi_print (afi, safi), peer->host,
1674 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001675 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001676
hassoe0701b72004-05-20 09:19:34 +00001677 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1678 return 0;
paul718e3742002-12-13 20:15:29 +00001679
hassoe0701b72004-05-20 09:19:34 +00001680 {
paul5228ad22004-06-04 17:58:18 +00001681 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001682
1683 if (safi == SAFI_MPLS_VPN)
1684 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001685
1686 ndata[0] = (afi >> 8);
1687 ndata[1] = afi;
1688 ndata[2] = safi;
1689 ndata[3] = (peer->pmax[afi][safi] >> 24);
1690 ndata[4] = (peer->pmax[afi][safi] >> 16);
1691 ndata[5] = (peer->pmax[afi][safi] >> 8);
1692 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001693
1694 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1695 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1696 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1697 }
hasso0a486e52005-02-01 20:57:17 +00001698
1699 /* restart timer start */
1700 if (peer->pmax_restart[afi][safi])
1701 {
1702 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1703
1704 if (BGP_DEBUG (events, EVENTS))
1705 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1706 peer->host, peer->v_pmax_restart);
1707
1708 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1709 peer->v_pmax_restart);
1710 }
1711
hassoe0701b72004-05-20 09:19:34 +00001712 return 1;
paul718e3742002-12-13 20:15:29 +00001713 }
hassoe0701b72004-05-20 09:19:34 +00001714 else
1715 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1716
1717 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1718 {
1719 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1720 && ! always)
1721 return 0;
1722
1723 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001724 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1725 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1726 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001727 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1728 }
1729 else
1730 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001731 return 0;
1732}
1733
paulb40d9392005-08-22 22:34:41 +00001734/* Unconditionally remove the route from the RIB, without taking
1735 * damping into consideration (eg, because the session went down)
1736 */
paul94f2b392005-06-28 12:44:16 +00001737static void
paul718e3742002-12-13 20:15:29 +00001738bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1739 afi_t afi, safi_t safi)
1740{
paul902212c2006-02-05 17:51:19 +00001741 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1742
1743 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1744 bgp_info_delete (rn, ri); /* keep historical info */
1745
paulb40d9392005-08-22 22:34:41 +00001746 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001747}
1748
paul94f2b392005-06-28 12:44:16 +00001749static void
paul718e3742002-12-13 20:15:29 +00001750bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001751 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001752{
paul718e3742002-12-13 20:15:29 +00001753 int status = BGP_DAMP_NONE;
1754
paulb40d9392005-08-22 22:34:41 +00001755 /* apply dampening, if result is suppressed, we'll be retaining
1756 * the bgp_info in the RIB for historical reference.
1757 */
1758 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1759 && peer_sort (peer) == BGP_PEER_EBGP)
1760 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1761 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001762 {
paul902212c2006-02-05 17:51:19 +00001763 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1764 return;
1765 }
1766
1767 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001768}
1769
paul94f2b392005-06-28 12:44:16 +00001770static void
paulfee0f4c2004-09-13 05:12:46 +00001771bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1772 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1773 int sub_type, struct prefix_rd *prd, u_char *tag)
1774{
1775 struct bgp_node *rn;
1776 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001777 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001778 struct attr *attr_new;
1779 struct attr *attr_new2;
1780 struct bgp_info *ri;
1781 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001782 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001783 char buf[SU_ADDRSTRLEN];
1784
Paul Jakmafb982c22007-05-04 20:15:47 +00001785 //memset (new_attr, 0, sizeof (struct attr));
1786
paulfee0f4c2004-09-13 05:12:46 +00001787 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1788 if (peer == rsclient)
1789 return;
1790
1791 bgp = peer->bgp;
1792 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1793
1794 /* Check previously received route. */
1795 for (ri = rn->info; ri; ri = ri->next)
1796 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1797 break;
1798
1799 /* AS path loop check. */
1800 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1801 {
1802 reason = "as-path contains our own AS;";
1803 goto filtered;
1804 }
1805
1806 /* Route reflector originator ID check. */
1807 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001808 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001809 {
1810 reason = "originator is us;";
1811 goto filtered;
1812 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001813
1814 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001815
1816 /* Apply export policy. */
1817 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1818 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1819 {
1820 reason = "export-policy;";
1821 goto filtered;
1822 }
1823
1824 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001825
paulfee0f4c2004-09-13 05:12:46 +00001826 /* Apply import policy. */
1827 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1828 {
1829 bgp_attr_unintern (attr_new2);
1830
1831 reason = "import-policy;";
1832 goto filtered;
1833 }
1834
1835 attr_new = bgp_attr_intern (&new_attr);
1836 bgp_attr_unintern (attr_new2);
1837
1838 /* IPv4 unicast next hop check. */
1839 if (afi == AFI_IP && safi == SAFI_UNICAST)
1840 {
1841 /* Next hop must not be 0.0.0.0 nor Class E address. */
1842 if (new_attr.nexthop.s_addr == 0
1843 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1844 {
1845 bgp_attr_unintern (attr_new);
1846
1847 reason = "martian next-hop;";
1848 goto filtered;
1849 }
1850 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001851
1852 /* new_attr isn't passed to any functions after here */
1853 bgp_attr_extra_free (&new_attr);
1854
paulfee0f4c2004-09-13 05:12:46 +00001855 /* If the update is implicit withdraw. */
1856 if (ri)
1857 {
1858 ri->uptime = time (NULL);
1859
1860 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001861 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1862 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001863 {
1864
Paul Jakma1a392d42006-09-07 00:24:49 +00001865 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001866
1867 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001868 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001869 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1870 peer->host,
1871 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1872 p->prefixlen, rsclient->host);
1873
1874 bgp_unlock_node (rn);
1875 bgp_attr_unintern (attr_new);
1876
1877 return;
1878 }
1879
Paul Jakma16d2e242007-04-10 19:32:10 +00001880 /* Withdraw/Announce before we fully processed the withdraw */
1881 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1882 bgp_info_restore (rn, ri);
1883
paulfee0f4c2004-09-13 05:12:46 +00001884 /* Received Logging. */
1885 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001886 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001887 peer->host,
1888 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1889 p->prefixlen, rsclient->host);
1890
1891 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001892 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001893
1894 /* Update to new attribute. */
1895 bgp_attr_unintern (ri->attr);
1896 ri->attr = attr_new;
1897
1898 /* Update MPLS tag. */
1899 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001900 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001901
Paul Jakma1a392d42006-09-07 00:24:49 +00001902 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001903
1904 /* Process change. */
1905 bgp_process (bgp, rn, afi, safi);
1906 bgp_unlock_node (rn);
1907
1908 return;
1909 }
1910
1911 /* Received Logging. */
1912 if (BGP_DEBUG (update, UPDATE_IN))
1913 {
ajsd2c1f162004-12-08 21:10:20 +00001914 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001915 peer->host,
1916 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1917 p->prefixlen, rsclient->host);
1918 }
1919
1920 /* Make new BGP info. */
1921 new = bgp_info_new ();
1922 new->type = type;
1923 new->sub_type = sub_type;
1924 new->peer = peer;
1925 new->attr = attr_new;
1926 new->uptime = time (NULL);
1927
1928 /* Update MPLS tag. */
1929 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001930 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001931
Paul Jakma1a392d42006-09-07 00:24:49 +00001932 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001933
1934 /* Register new BGP information. */
1935 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001936
1937 /* route_node_get lock */
1938 bgp_unlock_node (rn);
1939
paulfee0f4c2004-09-13 05:12:46 +00001940 /* Process change. */
1941 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001942
1943 bgp_attr_extra_free (&new_attr);
1944
paulfee0f4c2004-09-13 05:12:46 +00001945 return;
1946
1947 filtered:
1948
1949 /* This BGP update is filtered. Log the reason then update BGP entry. */
1950 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001951 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001952 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1953 peer->host,
1954 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1955 p->prefixlen, rsclient->host, reason);
1956
1957 if (ri)
paulb40d9392005-08-22 22:34:41 +00001958 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001959
1960 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001961
1962 if (new_attr.extra)
1963 bgp_attr_extra_free (&new_attr);
1964
paulfee0f4c2004-09-13 05:12:46 +00001965 return;
1966}
1967
paul94f2b392005-06-28 12:44:16 +00001968static void
paulfee0f4c2004-09-13 05:12:46 +00001969bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1970 struct peer *peer, struct prefix *p, int type, int sub_type,
1971 struct prefix_rd *prd, u_char *tag)
1972 {
1973 struct bgp_node *rn;
1974 struct bgp_info *ri;
1975 char buf[SU_ADDRSTRLEN];
1976
1977 if (rsclient == peer)
1978 return;
1979
1980 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1981
1982 /* Lookup withdrawn route. */
1983 for (ri = rn->info; ri; ri = ri->next)
1984 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1985 break;
1986
1987 /* Withdraw specified route from routing table. */
1988 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001989 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001990 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001991 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001992 "%s Can't find the route %s/%d", peer->host,
1993 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1994 p->prefixlen);
1995
1996 /* Unlock bgp_node_get() lock. */
1997 bgp_unlock_node (rn);
1998 }
1999
paul94f2b392005-06-28 12:44:16 +00002000static int
paulfee0f4c2004-09-13 05:12:46 +00002001bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002002 afi_t afi, safi_t safi, int type, int sub_type,
2003 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2004{
2005 int ret;
2006 int aspath_loop_count = 0;
2007 struct bgp_node *rn;
2008 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002009 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002010 struct attr *attr_new;
2011 struct bgp_info *ri;
2012 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002013 const char *reason;
paul718e3742002-12-13 20:15:29 +00002014 char buf[SU_ADDRSTRLEN];
2015
2016 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002017 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002018
paul718e3742002-12-13 20:15:29 +00002019 /* When peer's soft reconfiguration enabled. Record input packet in
2020 Adj-RIBs-In. */
2021 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2022 && peer != bgp->peer_self && ! soft_reconfig)
2023 bgp_adj_in_set (rn, peer, attr);
2024
2025 /* Check previously received route. */
2026 for (ri = rn->info; ri; ri = ri->next)
2027 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2028 break;
2029
2030 /* AS path local-as loop check. */
2031 if (peer->change_local_as)
2032 {
2033 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2034 aspath_loop_count = 1;
2035
2036 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2037 {
2038 reason = "as-path contains our own AS;";
2039 goto filtered;
2040 }
2041 }
2042
2043 /* AS path loop check. */
2044 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2045 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2046 && aspath_loop_check(attr->aspath, bgp->confed_id)
2047 > peer->allowas_in[afi][safi]))
2048 {
2049 reason = "as-path contains our own AS;";
2050 goto filtered;
2051 }
2052
2053 /* Route reflector originator ID check. */
2054 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002055 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002056 {
2057 reason = "originator is us;";
2058 goto filtered;
2059 }
2060
2061 /* Route reflector cluster ID check. */
2062 if (bgp_cluster_filter (peer, attr))
2063 {
2064 reason = "reflected from the same cluster;";
2065 goto filtered;
2066 }
2067
2068 /* Apply incoming filter. */
2069 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2070 {
2071 reason = "filter;";
2072 goto filtered;
2073 }
2074
2075 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002076 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002077
2078 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2079 {
2080 reason = "route-map;";
2081 goto filtered;
2082 }
2083
2084 /* IPv4 unicast next hop check. */
2085 if (afi == AFI_IP && safi == SAFI_UNICAST)
2086 {
2087 /* If the peer is EBGP and nexthop is not on connected route,
2088 discard it. */
2089 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2090 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002091 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002092 {
2093 reason = "non-connected next-hop;";
2094 goto filtered;
2095 }
2096
2097 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2098 must not be my own address. */
2099 if (bgp_nexthop_self (afi, &new_attr)
2100 || new_attr.nexthop.s_addr == 0
2101 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2102 {
2103 reason = "martian next-hop;";
2104 goto filtered;
2105 }
2106 }
2107
2108 attr_new = bgp_attr_intern (&new_attr);
2109
2110 /* If the update is implicit withdraw. */
2111 if (ri)
2112 {
2113 ri->uptime = time (NULL);
2114
2115 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002116 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2117 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002118 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002119 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002120
2121 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2122 && peer_sort (peer) == BGP_PEER_EBGP
2123 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2124 {
2125 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002126 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002127 peer->host,
2128 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2129 p->prefixlen);
2130
paul902212c2006-02-05 17:51:19 +00002131 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2132 {
2133 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2134 bgp_process (bgp, rn, afi, safi);
2135 }
paul718e3742002-12-13 20:15:29 +00002136 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002137 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002138 {
2139 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002140 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002141 "%s rcvd %s/%d...duplicate ignored",
2142 peer->host,
2143 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2144 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002145
2146 /* graceful restart STALE flag unset. */
2147 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2148 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002149 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002150 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002151 }
paul718e3742002-12-13 20:15:29 +00002152 }
2153
2154 bgp_unlock_node (rn);
2155 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002156 bgp_attr_extra_free (&new_attr);
2157
paul718e3742002-12-13 20:15:29 +00002158 return 0;
2159 }
2160
Paul Jakma16d2e242007-04-10 19:32:10 +00002161 /* Withdraw/Announce before we fully processed the withdraw */
2162 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2163 {
2164 if (BGP_DEBUG (update, UPDATE_IN))
2165 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2166 peer->host,
2167 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2168 p->prefixlen);
2169 bgp_info_restore (rn, ri);
2170 }
2171
paul718e3742002-12-13 20:15:29 +00002172 /* Received Logging. */
2173 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002174 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002175 peer->host,
2176 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2177 p->prefixlen);
2178
hasso93406d82005-02-02 14:40:33 +00002179 /* graceful restart STALE flag unset. */
2180 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002181 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002182
paul718e3742002-12-13 20:15:29 +00002183 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002184 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002185
2186 /* implicit withdraw, decrement aggregate and pcount here.
2187 * only if update is accepted, they'll increment below.
2188 */
paul902212c2006-02-05 17:51:19 +00002189 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2190
paul718e3742002-12-13 20:15:29 +00002191 /* Update bgp route dampening information. */
2192 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2193 && peer_sort (peer) == BGP_PEER_EBGP)
2194 {
2195 /* This is implicit withdraw so we should update dampening
2196 information. */
2197 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2198 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002199 }
2200
paul718e3742002-12-13 20:15:29 +00002201 /* Update to new attribute. */
2202 bgp_attr_unintern (ri->attr);
2203 ri->attr = attr_new;
2204
2205 /* Update MPLS tag. */
2206 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002207 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002208
2209 /* Update bgp route dampening information. */
2210 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2211 && peer_sort (peer) == BGP_PEER_EBGP)
2212 {
2213 /* Now we do normal update dampening. */
2214 ret = bgp_damp_update (ri, rn, afi, safi);
2215 if (ret == BGP_DAMP_SUPPRESSED)
2216 {
2217 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002218 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002219 return 0;
2220 }
2221 }
2222
2223 /* Nexthop reachability check. */
2224 if ((afi == AFI_IP || afi == AFI_IP6)
2225 && safi == SAFI_UNICAST
2226 && (peer_sort (peer) == BGP_PEER_IBGP
2227 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002228 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002229 {
2230 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002231 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002232 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002233 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002234 }
2235 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002236 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002237
2238 /* Process change. */
2239 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2240
2241 bgp_process (bgp, rn, afi, safi);
2242 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002243 bgp_attr_extra_free (&new_attr);
2244
paul718e3742002-12-13 20:15:29 +00002245 return 0;
2246 }
2247
2248 /* Received Logging. */
2249 if (BGP_DEBUG (update, UPDATE_IN))
2250 {
ajsd2c1f162004-12-08 21:10:20 +00002251 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002252 peer->host,
2253 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2254 p->prefixlen);
2255 }
2256
paul718e3742002-12-13 20:15:29 +00002257 /* Make new BGP info. */
2258 new = bgp_info_new ();
2259 new->type = type;
2260 new->sub_type = sub_type;
2261 new->peer = peer;
2262 new->attr = attr_new;
2263 new->uptime = time (NULL);
2264
2265 /* Update MPLS tag. */
2266 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002267 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002268
2269 /* Nexthop reachability check. */
2270 if ((afi == AFI_IP || afi == AFI_IP6)
2271 && safi == SAFI_UNICAST
2272 && (peer_sort (peer) == BGP_PEER_IBGP
2273 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002274 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002275 {
2276 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002277 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002278 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002279 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002280 }
2281 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002282 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002283
paul902212c2006-02-05 17:51:19 +00002284 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002285 bgp_aggregate_increment (bgp, p, new, afi, safi);
2286
2287 /* Register new BGP information. */
2288 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002289
2290 /* route_node_get lock */
2291 bgp_unlock_node (rn);
2292
Paul Jakmafb982c22007-05-04 20:15:47 +00002293 bgp_attr_extra_free (&new_attr);
2294
paul718e3742002-12-13 20:15:29 +00002295 /* If maximum prefix count is configured and current prefix
2296 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002297 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2298 return -1;
paul718e3742002-12-13 20:15:29 +00002299
2300 /* Process change. */
2301 bgp_process (bgp, rn, afi, safi);
2302
2303 return 0;
2304
2305 /* This BGP update is filtered. Log the reason then update BGP
2306 entry. */
2307 filtered:
2308 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002309 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002310 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2311 peer->host,
2312 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2313 p->prefixlen, reason);
2314
2315 if (ri)
paulb40d9392005-08-22 22:34:41 +00002316 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002317
2318 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002319
2320 bgp_attr_extra_free (&new_attr);
2321
paul718e3742002-12-13 20:15:29 +00002322 return 0;
2323}
2324
2325int
paulfee0f4c2004-09-13 05:12:46 +00002326bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2327 afi_t afi, safi_t safi, int type, int sub_type,
2328 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2329{
2330 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002331 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002332 struct bgp *bgp;
2333 int ret;
2334
2335 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2336 soft_reconfig);
2337
2338 bgp = peer->bgp;
2339
2340 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002341 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002342 {
2343 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2344 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2345 sub_type, prd, tag);
2346 }
2347
2348 return ret;
2349}
2350
2351int
paul718e3742002-12-13 20:15:29 +00002352bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002353 afi_t afi, safi_t safi, int type, int sub_type,
2354 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002355{
2356 struct bgp *bgp;
2357 char buf[SU_ADDRSTRLEN];
2358 struct bgp_node *rn;
2359 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002360 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002361 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002362
2363 bgp = peer->bgp;
2364
paulfee0f4c2004-09-13 05:12:46 +00002365 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002366 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002367 {
2368 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2369 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2370 }
2371
paul718e3742002-12-13 20:15:29 +00002372 /* Logging. */
2373 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002374 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002375 peer->host,
2376 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2377 p->prefixlen);
2378
2379 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002380 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002381
2382 /* If peer is soft reconfiguration enabled. Record input packet for
2383 further calculation. */
2384 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2385 && peer != bgp->peer_self)
2386 bgp_adj_in_unset (rn, peer);
2387
2388 /* Lookup withdrawn route. */
2389 for (ri = rn->info; ri; ri = ri->next)
2390 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2391 break;
2392
2393 /* Withdraw specified route from routing table. */
2394 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002395 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002396 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002397 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002398 "%s Can't find the route %s/%d", peer->host,
2399 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2400 p->prefixlen);
2401
2402 /* Unlock bgp_node_get() lock. */
2403 bgp_unlock_node (rn);
2404
2405 return 0;
2406}
2407
2408void
2409bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2410{
2411 struct bgp *bgp;
2412 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002413 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002414 struct prefix p;
2415 struct bgp_info binfo;
2416 struct peer *from;
2417 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002418
Paul Jakmab2497022007-06-14 11:17:58 +00002419 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002420 return;
2421
paul718e3742002-12-13 20:15:29 +00002422 bgp = peer->bgp;
2423 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002424
paul718e3742002-12-13 20:15:29 +00002425 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2426 aspath = attr.aspath;
2427 attr.local_pref = bgp->default_local_pref;
2428 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2429
2430 if (afi == AFI_IP)
2431 str2prefix ("0.0.0.0/0", &p);
2432#ifdef HAVE_IPV6
2433 else if (afi == AFI_IP6)
2434 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002435 struct attr_extra *ae;
2436 attr.extra = NULL;
2437
2438 ae = bgp_attr_extra_get (&attr);
2439 attr.extra = ae;
2440
paul718e3742002-12-13 20:15:29 +00002441 str2prefix ("::/0", &p);
2442
2443 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002444 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002445 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002446 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002447
2448 /* If the peer is on shared nextwork and we have link-local
2449 nexthop set it. */
2450 if (peer->shared_network
2451 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2452 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002453 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002454 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002455 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002456 }
2457 }
2458#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002459
2460 if (peer->default_rmap[afi][safi].name)
2461 {
2462 binfo.peer = bgp->peer_self;
2463 binfo.attr = &attr;
2464
paulfee0f4c2004-09-13 05:12:46 +00002465 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2466
paul718e3742002-12-13 20:15:29 +00002467 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2468 RMAP_BGP, &binfo);
2469
paulfee0f4c2004-09-13 05:12:46 +00002470 bgp->peer_self->rmap_type = 0;
2471
paul718e3742002-12-13 20:15:29 +00002472 if (ret == RMAP_DENYMATCH)
2473 {
2474 bgp_attr_flush (&attr);
2475 withdraw = 1;
2476 }
2477 }
2478
2479 if (withdraw)
2480 {
2481 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2482 bgp_default_withdraw_send (peer, afi, safi);
2483 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2484 }
2485 else
2486 {
2487 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2488 bgp_default_update_send (peer, &attr, afi, safi, from);
2489 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002490
2491 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002492 aspath_unintern (aspath);
2493}
2494
2495static void
2496bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002497 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002498{
2499 struct bgp_node *rn;
2500 struct bgp_info *ri;
2501 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002502
2503 memset (&attr, 0, sizeof (struct attr));
2504
paul718e3742002-12-13 20:15:29 +00002505 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002506 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002507
2508 if (safi != SAFI_MPLS_VPN
2509 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2510 bgp_default_originate (peer, afi, safi, 0);
2511
2512 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2513 for (ri = rn->info; ri; ri = ri->next)
2514 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2515 {
paulfee0f4c2004-09-13 05:12:46 +00002516 if ( (rsclient) ?
2517 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2518 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002519 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2520 else
2521 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002522
2523 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002524 }
2525}
2526
2527void
2528bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2529{
2530 struct bgp_node *rn;
2531 struct bgp_table *table;
2532
2533 if (peer->status != Established)
2534 return;
2535
2536 if (! peer->afc_nego[afi][safi])
2537 return;
2538
2539 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2540 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2541 return;
2542
2543 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002544 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002545 else
2546 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2547 rn = bgp_route_next(rn))
2548 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002549 bgp_announce_table (peer, afi, safi, table, 0);
2550
2551 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2552 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002553}
2554
2555void
2556bgp_announce_route_all (struct peer *peer)
2557{
2558 afi_t afi;
2559 safi_t safi;
2560
2561 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2562 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2563 bgp_announce_route (peer, afi, safi);
2564}
2565
2566static void
paulfee0f4c2004-09-13 05:12:46 +00002567bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2568 safi_t safi, struct bgp_table *table)
2569{
2570 struct bgp_node *rn;
2571 struct bgp_adj_in *ain;
2572
2573 if (! table)
2574 table = rsclient->bgp->rib[afi][safi];
2575
2576 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2577 for (ain = rn->adj_in; ain; ain = ain->next)
2578 {
2579 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2580 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2581 }
2582}
2583
2584void
2585bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2586{
2587 struct bgp_table *table;
2588 struct bgp_node *rn;
2589
2590 if (safi != SAFI_MPLS_VPN)
2591 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2592
2593 else
2594 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2595 rn = bgp_route_next (rn))
2596 if ((table = rn->info) != NULL)
2597 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2598}
2599
2600static void
paul718e3742002-12-13 20:15:29 +00002601bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2602 struct bgp_table *table)
2603{
2604 int ret;
2605 struct bgp_node *rn;
2606 struct bgp_adj_in *ain;
2607
2608 if (! table)
2609 table = peer->bgp->rib[afi][safi];
2610
2611 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2612 for (ain = rn->adj_in; ain; ain = ain->next)
2613 {
2614 if (ain->peer == peer)
2615 {
2616 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2617 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2618 NULL, NULL, 1);
2619 if (ret < 0)
2620 {
2621 bgp_unlock_node (rn);
2622 return;
2623 }
2624 continue;
2625 }
2626 }
2627}
2628
2629void
2630bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2631{
2632 struct bgp_node *rn;
2633 struct bgp_table *table;
2634
2635 if (peer->status != Established)
2636 return;
2637
2638 if (safi != SAFI_MPLS_VPN)
2639 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2640 else
2641 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2642 rn = bgp_route_next (rn))
2643 if ((table = rn->info) != NULL)
2644 bgp_soft_reconfig_table (peer, afi, safi, table);
2645}
2646
paul200df112005-06-01 11:17:05 +00002647static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002648bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002649{
Paul Jakma64e580a2006-02-21 01:09:01 +00002650 struct bgp_node *rn = data;
2651 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002652 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002653 afi_t afi = rn->table->afi;
2654 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002655
Paul Jakma64e580a2006-02-21 01:09:01 +00002656 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002657
Paul Jakma64e580a2006-02-21 01:09:01 +00002658 for (ri = rn->info; ri; ri = ri->next)
2659 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002660 {
2661 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002662 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2663 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002664 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002665 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2666 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002667 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002668 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002669 break;
2670 }
paul200df112005-06-01 11:17:05 +00002671 return WQ_SUCCESS;
2672}
2673
2674static void
paul0fb58d52005-11-14 14:31:49 +00002675bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002676{
Paul Jakma64e580a2006-02-21 01:09:01 +00002677 struct bgp_node *rn = data;
2678
2679 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002680}
2681
2682static void
paul94f2b392005-06-28 12:44:16 +00002683bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002684{
Paul Jakma64e580a2006-02-21 01:09:01 +00002685 struct peer *peer = wq->spec.data;
2686
Paul Jakma64e580a2006-02-21 01:09:01 +00002687 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002688
2689 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002690 BGP_EVENT_ADD (peer, Clearing_Completed);
paul200df112005-06-01 11:17:05 +00002691}
2692
2693static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002694bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002695{
Paul Jakma64e580a2006-02-21 01:09:01 +00002696#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2697 char wname[CLEAR_QUEUE_NAME_LEN];
2698
2699 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2700#undef CLEAR_QUEUE_NAME_LEN
2701
2702 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002703 {
2704 zlog_err ("%s: Failed to allocate work queue", __func__);
2705 exit (1);
2706 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002707 peer->clear_node_queue->spec.hold = 10;
2708 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2709 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2710 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2711 peer->clear_node_queue->spec.max_retries = 0;
2712
2713 /* we only 'lock' this peer reference when the queue is actually active */
2714 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002715}
2716
paul718e3742002-12-13 20:15:29 +00002717static void
2718bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002719 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002720{
2721 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002722
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002723
paul718e3742002-12-13 20:15:29 +00002724 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002725 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002726
hasso6cf159b2005-03-21 10:28:14 +00002727 /* If still no table => afi/safi isn't configured at all or smth. */
2728 if (! table)
2729 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002730
2731 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2732 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002733 struct bgp_info *ri;
2734 struct bgp_adj_in *ain;
2735 struct bgp_adj_out *aout;
2736
Paul Jakma65ca75e2006-05-04 08:08:15 +00002737 if (rn->info == NULL)
2738 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002739
2740 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2741 * queued for every clearing peer, regardless of whether it is
2742 * relevant to the peer at hand.
2743 *
2744 * Overview: There are 3 different indices which need to be
2745 * scrubbed, potentially, when a peer is removed:
2746 *
2747 * 1 peer's routes visible via the RIB (ie accepted routes)
2748 * 2 peer's routes visible by the (optional) peer's adj-in index
2749 * 3 other routes visible by the peer's adj-out index
2750 *
2751 * 3 there is no hurry in scrubbing, once the struct peer is
2752 * removed from bgp->peer, we could just GC such deleted peer's
2753 * adj-outs at our leisure.
2754 *
2755 * 1 and 2 must be 'scrubbed' in some way, at least made
2756 * invisible via RIB index before peer session is allowed to be
2757 * brought back up. So one needs to know when such a 'search' is
2758 * complete.
2759 *
2760 * Ideally:
2761 *
2762 * - there'd be a single global queue or a single RIB walker
2763 * - rather than tracking which route_nodes still need to be
2764 * examined on a peer basis, we'd track which peers still
2765 * aren't cleared
2766 *
2767 * Given that our per-peer prefix-counts now should be reliable,
2768 * this may actually be achievable. It doesn't seem to be a huge
2769 * problem at this time,
2770 */
2771 for (ri = rn->info; ri; ri = ri->next)
2772 if (ri->peer == peer)
2773 {
2774 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2775 work_queue_add (peer->clear_node_queue, rn);
2776 }
2777
2778 for (ain = rn->adj_in; ain; ain = ain->next)
2779 if (ain->peer == peer)
2780 {
2781 bgp_adj_in_remove (rn, ain);
2782 bgp_unlock_node (rn);
2783 break;
2784 }
2785 for (aout = rn->adj_out; aout; aout = aout->next)
2786 if (aout->peer == peer)
2787 {
2788 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2789 bgp_unlock_node (rn);
2790 break;
2791 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002792 }
2793 return;
2794}
2795
2796void
2797bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2798{
2799 struct bgp_node *rn;
2800 struct bgp_table *table;
2801 struct peer *rsclient;
2802 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002803
Paul Jakma64e580a2006-02-21 01:09:01 +00002804 if (peer->clear_node_queue == NULL)
2805 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002806
Paul Jakmaca058a32006-09-14 02:58:49 +00002807 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2808 * Idle until it receives a Clearing_Completed event. This protects
2809 * against peers which flap faster than we can we clear, which could
2810 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002811 *
2812 * a) race with routes from the new session being installed before
2813 * clear_route_node visits the node (to delete the route of that
2814 * peer)
2815 * b) resource exhaustion, clear_route_node likely leads to an entry
2816 * on the process_main queue. Fast-flapping could cause that queue
2817 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002818 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002819 if (!peer->clear_node_queue->thread)
2820 peer_lock (peer); /* bgp_clear_node_complete */
paul200df112005-06-01 11:17:05 +00002821
paul718e3742002-12-13 20:15:29 +00002822 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002823 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002824 else
2825 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2826 rn = bgp_route_next (rn))
2827 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002828 bgp_clear_route_table (peer, afi, safi, table, NULL);
2829
paul1eb8ef22005-04-07 07:30:20 +00002830 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002831 {
2832 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2833 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2834 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002835
Paul Jakmaca058a32006-09-14 02:58:49 +00002836 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002837 * completion function won't be run by workqueue code - call it here.
2838 * XXX: Actually, this assumption doesn't hold, see
2839 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002840 *
2841 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002842 * really needed if peer state is Established - peers in
2843 * pre-Established states shouldn't have any route-update state
2844 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002845 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002846 * We still can get here in pre-Established though, through
2847 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2848 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002849 *
2850 * At some future point, this check could be move to the top of the
2851 * function, and do a quick early-return when state is
2852 * pre-Established, avoiding above list and table scans. Once we're
2853 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002854 */
2855 if (!peer->clear_node_queue->thread)
2856 bgp_clear_node_complete (peer->clear_node_queue);
Paul Jakmaca058a32006-09-14 02:58:49 +00002857 else
2858 {
2859 /* clearing queue scheduled. Normal if in Established state
2860 * (and about to transition out of it), but otherwise...
2861 */
2862 if (peer->status != Established)
2863 {
2864 plog_err (peer->log, "%s [Error] State %s is not Established,"
2865 " but routes were cleared - bug!",
2866 peer->host, LOOKUP (bgp_status_msg, peer->status));
2867 assert (peer->status == Established);
2868 }
2869 }
paul718e3742002-12-13 20:15:29 +00002870}
2871
2872void
2873bgp_clear_route_all (struct peer *peer)
2874{
2875 afi_t afi;
2876 safi_t safi;
2877
2878 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2879 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2880 bgp_clear_route (peer, afi, safi);
2881}
2882
2883void
2884bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2885{
2886 struct bgp_table *table;
2887 struct bgp_node *rn;
2888 struct bgp_adj_in *ain;
2889
2890 table = peer->bgp->rib[afi][safi];
2891
2892 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2893 for (ain = rn->adj_in; ain ; ain = ain->next)
2894 if (ain->peer == peer)
2895 {
2896 bgp_adj_in_remove (rn, ain);
2897 bgp_unlock_node (rn);
2898 break;
2899 }
2900}
hasso93406d82005-02-02 14:40:33 +00002901
2902void
2903bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2904{
2905 struct bgp_node *rn;
2906 struct bgp_info *ri;
2907 struct bgp_table *table;
2908
2909 table = peer->bgp->rib[afi][safi];
2910
2911 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2912 {
2913 for (ri = rn->info; ri; ri = ri->next)
2914 if (ri->peer == peer)
2915 {
2916 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2917 bgp_rib_remove (rn, ri, peer, afi, safi);
2918 break;
2919 }
2920 }
2921}
paul718e3742002-12-13 20:15:29 +00002922
2923/* Delete all kernel routes. */
2924void
paul545acaf2004-04-20 15:13:15 +00002925bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002926{
2927 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002928 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002929 struct bgp_node *rn;
2930 struct bgp_table *table;
2931 struct bgp_info *ri;
2932
paul1eb8ef22005-04-07 07:30:20 +00002933 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002934 {
2935 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2936
2937 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2938 for (ri = rn->info; ri; ri = ri->next)
2939 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2940 && ri->type == ZEBRA_ROUTE_BGP
2941 && ri->sub_type == BGP_ROUTE_NORMAL)
2942 bgp_zebra_withdraw (&rn->p, ri);
2943
2944 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2945
2946 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2947 for (ri = rn->info; ri; ri = ri->next)
2948 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2949 && ri->type == ZEBRA_ROUTE_BGP
2950 && ri->sub_type == BGP_ROUTE_NORMAL)
2951 bgp_zebra_withdraw (&rn->p, ri);
2952 }
2953}
2954
2955void
2956bgp_reset ()
2957{
2958 vty_reset ();
2959 bgp_zclient_reset ();
2960 access_list_reset ();
2961 prefix_list_reset ();
2962}
2963
2964/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2965 value. */
2966int
2967bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2968{
2969 u_char *pnt;
2970 u_char *lim;
2971 struct prefix p;
2972 int psize;
2973 int ret;
2974
2975 /* Check peer status. */
2976 if (peer->status != Established)
2977 return 0;
2978
2979 pnt = packet->nlri;
2980 lim = pnt + packet->length;
2981
2982 for (; pnt < lim; pnt += psize)
2983 {
2984 /* Clear prefix structure. */
2985 memset (&p, 0, sizeof (struct prefix));
2986
2987 /* Fetch prefix length. */
2988 p.prefixlen = *pnt++;
2989 p.family = afi2family (packet->afi);
2990
2991 /* Already checked in nlri_sanity_check(). We do double check
2992 here. */
2993 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2994 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2995 return -1;
2996
2997 /* Packet size overflow check. */
2998 psize = PSIZE (p.prefixlen);
2999
3000 /* When packet overflow occur return immediately. */
3001 if (pnt + psize > lim)
3002 return -1;
3003
3004 /* Fetch prefix from NLRI packet. */
3005 memcpy (&p.u.prefix, pnt, psize);
3006
3007 /* Check address. */
3008 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3009 {
3010 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3011 {
paulf5ba3872004-07-09 12:11:31 +00003012 /*
3013 * From draft-ietf-idr-bgp4-22, Section 6.3:
3014 * If a BGP router receives an UPDATE message with a
3015 * semantically incorrect NLRI field, in which a prefix is
3016 * semantically incorrect (eg. an unexpected multicast IP
3017 * address), it should ignore the prefix.
3018 */
paul718e3742002-12-13 20:15:29 +00003019 zlog (peer->log, LOG_ERR,
3020 "IPv4 unicast NLRI is multicast address %s",
3021 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003022
paul718e3742002-12-13 20:15:29 +00003023 return -1;
3024 }
3025 }
3026
3027#ifdef HAVE_IPV6
3028 /* Check address. */
3029 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3030 {
3031 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3032 {
3033 char buf[BUFSIZ];
3034
3035 zlog (peer->log, LOG_WARNING,
3036 "IPv6 link-local NLRI received %s ignore this NLRI",
3037 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3038
3039 continue;
3040 }
3041 }
3042#endif /* HAVE_IPV6 */
3043
3044 /* Normal process. */
3045 if (attr)
3046 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3047 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3048 else
3049 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3050 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3051
3052 /* Address family configuration mismatch or maximum-prefix count
3053 overflow. */
3054 if (ret < 0)
3055 return -1;
3056 }
3057
3058 /* Packet length consistency check. */
3059 if (pnt != lim)
3060 return -1;
3061
3062 return 0;
3063}
3064
3065/* NLRI encode syntax check routine. */
3066int
3067bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3068 bgp_size_t length)
3069{
3070 u_char *end;
3071 u_char prefixlen;
3072 int psize;
3073
3074 end = pnt + length;
3075
3076 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3077 syntactic validity. If the field is syntactically incorrect,
3078 then the Error Subcode is set to Invalid Network Field. */
3079
3080 while (pnt < end)
3081 {
3082 prefixlen = *pnt++;
3083
3084 /* Prefix length check. */
3085 if ((afi == AFI_IP && prefixlen > 32)
3086 || (afi == AFI_IP6 && prefixlen > 128))
3087 {
3088 plog_err (peer->log,
3089 "%s [Error] Update packet error (wrong prefix length %d)",
3090 peer->host, prefixlen);
3091 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3092 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3093 return -1;
3094 }
3095
3096 /* Packet size overflow check. */
3097 psize = PSIZE (prefixlen);
3098
3099 if (pnt + psize > end)
3100 {
3101 plog_err (peer->log,
3102 "%s [Error] Update packet error"
3103 " (prefix data overflow prefix size is %d)",
3104 peer->host, psize);
3105 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3106 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3107 return -1;
3108 }
3109
3110 pnt += psize;
3111 }
3112
3113 /* Packet length consistency check. */
3114 if (pnt != end)
3115 {
3116 plog_err (peer->log,
3117 "%s [Error] Update packet error"
3118 " (prefix length mismatch with total length)",
3119 peer->host);
3120 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3121 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3122 return -1;
3123 }
3124 return 0;
3125}
3126
paul94f2b392005-06-28 12:44:16 +00003127static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00003128bgp_static_new ()
3129{
3130 struct bgp_static *new;
3131 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3132 memset (new, 0, sizeof (struct bgp_static));
3133 return new;
3134}
3135
paul94f2b392005-06-28 12:44:16 +00003136static void
paul718e3742002-12-13 20:15:29 +00003137bgp_static_free (struct bgp_static *bgp_static)
3138{
3139 if (bgp_static->rmap.name)
3140 free (bgp_static->rmap.name);
3141 XFREE (MTYPE_BGP_STATIC, bgp_static);
3142}
3143
paul94f2b392005-06-28 12:44:16 +00003144static void
paulfee0f4c2004-09-13 05:12:46 +00003145bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3146 struct prefix *p, afi_t afi, safi_t safi)
3147{
3148 struct bgp_node *rn;
3149 struct bgp_info *ri;
3150
3151 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3152
3153 /* Check selected route and self inserted route. */
3154 for (ri = rn->info; ri; ri = ri->next)
3155 if (ri->peer == bgp->peer_self
3156 && ri->type == ZEBRA_ROUTE_BGP
3157 && ri->sub_type == BGP_ROUTE_STATIC)
3158 break;
3159
3160 /* Withdraw static BGP route from routing table. */
3161 if (ri)
3162 {
paulfee0f4c2004-09-13 05:12:46 +00003163 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003164 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003165 }
3166
3167 /* Unlock bgp_node_lookup. */
3168 bgp_unlock_node (rn);
3169}
3170
paul94f2b392005-06-28 12:44:16 +00003171static void
paulfee0f4c2004-09-13 05:12:46 +00003172bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003173 struct bgp_static *bgp_static,
3174 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003175{
3176 struct bgp_node *rn;
3177 struct bgp_info *ri;
3178 struct bgp_info *new;
3179 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003180 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003181 struct attr attr = {0 };
3182 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003183 struct bgp *bgp;
3184 int ret;
3185 char buf[SU_ADDRSTRLEN];
3186
3187 bgp = rsclient->bgp;
3188
Paul Jakma06e110f2006-05-12 23:29:22 +00003189 assert (bgp_static);
3190 if (!bgp_static)
3191 return;
3192
paulfee0f4c2004-09-13 05:12:46 +00003193 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3194
3195 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003196
3197 attr.nexthop = bgp_static->igpnexthop;
3198 attr.med = bgp_static->igpmetric;
3199 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003200
3201 if (bgp_static->ttl)
3202 {
3203 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3204 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3205 attr.pathlimit.as = 0;
3206 attr.pathlimit.ttl = bgp_static->ttl;
3207 }
3208
3209 if (bgp_static->atomic)
3210 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3211
paulfee0f4c2004-09-13 05:12:46 +00003212 /* Apply network route-map for export to this rsclient. */
3213 if (bgp_static->rmap.name)
3214 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003215 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003216 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003217 info.attr = &attr_tmp;
3218
paulfee0f4c2004-09-13 05:12:46 +00003219 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3220 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3221
3222 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3223
3224 rsclient->rmap_type = 0;
3225
3226 if (ret == RMAP_DENYMATCH)
3227 {
3228 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003229 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003230
3231 /* Unintern original. */
3232 aspath_unintern (attr.aspath);
3233 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003234 bgp_attr_extra_free (&attr);
3235
paulfee0f4c2004-09-13 05:12:46 +00003236 return;
3237 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003238 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003239 }
3240 else
3241 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003242
paulfee0f4c2004-09-13 05:12:46 +00003243 new_attr = *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003244
paulfee0f4c2004-09-13 05:12:46 +00003245 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3246
Paul Jakmafb982c22007-05-04 20:15:47 +00003247 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3248 == RMAP_DENY)
3249 {
paulfee0f4c2004-09-13 05:12:46 +00003250 /* This BGP update is filtered. Log the reason then update BGP entry. */
3251 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003252 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003253 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3254 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3255 p->prefixlen, rsclient->host);
3256
3257 bgp->peer_self->rmap_type = 0;
3258
3259 bgp_attr_unintern (attr_new);
3260 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003261 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003262
3263 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3264
3265 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003266 }
paulfee0f4c2004-09-13 05:12:46 +00003267
3268 bgp->peer_self->rmap_type = 0;
3269
3270 bgp_attr_unintern (attr_new);
3271 attr_new = bgp_attr_intern (&new_attr);
3272
3273 for (ri = rn->info; ri; ri = ri->next)
3274 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3275 && ri->sub_type == BGP_ROUTE_STATIC)
3276 break;
3277
3278 if (ri)
3279 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003280 if (attrhash_cmp (ri->attr, attr_new) &&
3281 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003282 {
3283 bgp_unlock_node (rn);
3284 bgp_attr_unintern (attr_new);
3285 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003286 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003287 return;
3288 }
3289 else
3290 {
3291 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003292 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003293
3294 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003295 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3296 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003297 bgp_attr_unintern (ri->attr);
3298 ri->attr = attr_new;
3299 ri->uptime = time (NULL);
3300
3301 /* Process change. */
3302 bgp_process (bgp, rn, afi, safi);
3303 bgp_unlock_node (rn);
3304 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003305 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003306 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003307 }
paulfee0f4c2004-09-13 05:12:46 +00003308 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003309
paulfee0f4c2004-09-13 05:12:46 +00003310 /* Make new BGP info. */
3311 new = bgp_info_new ();
3312 new->type = ZEBRA_ROUTE_BGP;
3313 new->sub_type = BGP_ROUTE_STATIC;
3314 new->peer = bgp->peer_self;
3315 SET_FLAG (new->flags, BGP_INFO_VALID);
3316 new->attr = attr_new;
3317 new->uptime = time (NULL);
3318
3319 /* Register new BGP information. */
3320 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003321
3322 /* route_node_get lock */
3323 bgp_unlock_node (rn);
3324
paulfee0f4c2004-09-13 05:12:46 +00003325 /* Process change. */
3326 bgp_process (bgp, rn, afi, safi);
3327
3328 /* Unintern original. */
3329 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003330 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003331}
3332
paul94f2b392005-06-28 12:44:16 +00003333static void
paulfee0f4c2004-09-13 05:12:46 +00003334bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003335 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3336{
3337 struct bgp_node *rn;
3338 struct bgp_info *ri;
3339 struct bgp_info *new;
3340 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003341 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003342 struct attr *attr_new;
3343 int ret;
3344
Paul Jakmadd8103a2006-05-12 23:27:30 +00003345 assert (bgp_static);
3346 if (!bgp_static)
3347 return;
3348
paulfee0f4c2004-09-13 05:12:46 +00003349 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003350
3351 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003352
3353 attr.nexthop = bgp_static->igpnexthop;
3354 attr.med = bgp_static->igpmetric;
3355 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003356
Paul Jakma41367172007-08-06 15:24:51 +00003357 if (bgp_static->ttl)
3358 {
3359 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3360 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3361 attr.pathlimit.as = 0;
3362 attr.pathlimit.ttl = bgp_static->ttl;
3363 }
3364
3365 if (bgp_static->atomic)
3366 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3367
paul718e3742002-12-13 20:15:29 +00003368 /* Apply route-map. */
3369 if (bgp_static->rmap.name)
3370 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003371 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003372 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003373 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003374
paulfee0f4c2004-09-13 05:12:46 +00003375 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3376
paul718e3742002-12-13 20:15:29 +00003377 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003378
paulfee0f4c2004-09-13 05:12:46 +00003379 bgp->peer_self->rmap_type = 0;
3380
paul718e3742002-12-13 20:15:29 +00003381 if (ret == RMAP_DENYMATCH)
3382 {
3383 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003384 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003385
3386 /* Unintern original. */
3387 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003388 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003389 bgp_static_withdraw (bgp, p, afi, safi);
3390 return;
3391 }
paul286e1e72003-08-08 00:24:31 +00003392 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003393 }
paul286e1e72003-08-08 00:24:31 +00003394 else
3395 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003396
3397 for (ri = rn->info; ri; ri = ri->next)
3398 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3399 && ri->sub_type == BGP_ROUTE_STATIC)
3400 break;
3401
3402 if (ri)
3403 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003404 if (attrhash_cmp (ri->attr, attr_new) &&
3405 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003406 {
3407 bgp_unlock_node (rn);
3408 bgp_attr_unintern (attr_new);
3409 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003410 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003411 return;
3412 }
3413 else
3414 {
3415 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003416 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003417
3418 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003419 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3420 bgp_info_restore(rn, ri);
3421 else
3422 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003423 bgp_attr_unintern (ri->attr);
3424 ri->attr = attr_new;
3425 ri->uptime = time (NULL);
3426
3427 /* Process change. */
3428 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3429 bgp_process (bgp, rn, afi, safi);
3430 bgp_unlock_node (rn);
3431 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003432 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003433 return;
3434 }
3435 }
3436
3437 /* Make new BGP info. */
3438 new = bgp_info_new ();
3439 new->type = ZEBRA_ROUTE_BGP;
3440 new->sub_type = BGP_ROUTE_STATIC;
3441 new->peer = bgp->peer_self;
3442 SET_FLAG (new->flags, BGP_INFO_VALID);
3443 new->attr = attr_new;
3444 new->uptime = time (NULL);
3445
3446 /* Aggregate address increment. */
3447 bgp_aggregate_increment (bgp, p, new, afi, safi);
3448
3449 /* Register new BGP information. */
3450 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003451
3452 /* route_node_get lock */
3453 bgp_unlock_node (rn);
3454
paul718e3742002-12-13 20:15:29 +00003455 /* Process change. */
3456 bgp_process (bgp, rn, afi, safi);
3457
3458 /* Unintern original. */
3459 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003460 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003461}
3462
3463void
paulfee0f4c2004-09-13 05:12:46 +00003464bgp_static_update (struct bgp *bgp, struct prefix *p,
3465 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3466{
3467 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003468 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003469
3470 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3471
paul1eb8ef22005-04-07 07:30:20 +00003472 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003473 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003474 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3475 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003476 }
3477}
3478
paul94f2b392005-06-28 12:44:16 +00003479static void
paul718e3742002-12-13 20:15:29 +00003480bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3481 u_char safi, struct prefix_rd *prd, u_char *tag)
3482{
3483 struct bgp_node *rn;
3484 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003485
paulfee0f4c2004-09-13 05:12:46 +00003486 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003487
3488 /* Make new BGP info. */
3489 new = bgp_info_new ();
3490 new->type = ZEBRA_ROUTE_BGP;
3491 new->sub_type = BGP_ROUTE_STATIC;
3492 new->peer = bgp->peer_self;
3493 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3494 SET_FLAG (new->flags, BGP_INFO_VALID);
3495 new->uptime = time (NULL);
Paul Jakmafb982c22007-05-04 20:15:47 +00003496 new->extra = bgp_info_extra_new();
3497 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003498
3499 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003500 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003501
3502 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003503 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003504
paul200df112005-06-01 11:17:05 +00003505 /* route_node_get lock */
3506 bgp_unlock_node (rn);
3507
paul718e3742002-12-13 20:15:29 +00003508 /* Process change. */
3509 bgp_process (bgp, rn, afi, safi);
3510}
3511
3512void
3513bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3514 safi_t safi)
3515{
3516 struct bgp_node *rn;
3517 struct bgp_info *ri;
3518
paulfee0f4c2004-09-13 05:12:46 +00003519 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003520
3521 /* Check selected route and self inserted route. */
3522 for (ri = rn->info; ri; ri = ri->next)
3523 if (ri->peer == bgp->peer_self
3524 && ri->type == ZEBRA_ROUTE_BGP
3525 && ri->sub_type == BGP_ROUTE_STATIC)
3526 break;
3527
3528 /* Withdraw static BGP route from routing table. */
3529 if (ri)
3530 {
3531 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003532 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003533 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003534 }
3535
3536 /* Unlock bgp_node_lookup. */
3537 bgp_unlock_node (rn);
3538}
3539
3540void
paulfee0f4c2004-09-13 05:12:46 +00003541bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3542{
3543 struct bgp_static *bgp_static;
3544 struct bgp *bgp;
3545 struct bgp_node *rn;
3546 struct prefix *p;
3547
3548 bgp = rsclient->bgp;
3549
3550 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3551 if ((bgp_static = rn->info) != NULL)
3552 {
3553 p = &rn->p;
3554
3555 bgp_static_update_rsclient (rsclient, p, bgp_static,
3556 afi, safi);
3557 }
3558}
3559
paul94f2b392005-06-28 12:44:16 +00003560static void
paul718e3742002-12-13 20:15:29 +00003561bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3562 u_char safi, struct prefix_rd *prd, u_char *tag)
3563{
3564 struct bgp_node *rn;
3565 struct bgp_info *ri;
3566
paulfee0f4c2004-09-13 05:12:46 +00003567 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003568
3569 /* Check selected route and self inserted route. */
3570 for (ri = rn->info; ri; ri = ri->next)
3571 if (ri->peer == bgp->peer_self
3572 && ri->type == ZEBRA_ROUTE_BGP
3573 && ri->sub_type == BGP_ROUTE_STATIC)
3574 break;
3575
3576 /* Withdraw static BGP route from routing table. */
3577 if (ri)
3578 {
3579 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003580 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003581 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003582 }
3583
3584 /* Unlock bgp_node_lookup. */
3585 bgp_unlock_node (rn);
3586}
3587
Paul Jakma41367172007-08-06 15:24:51 +00003588static void
3589bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3590 int ttl_edge)
3591{
3592 struct bgp_node *parent = rn;
3593 struct bgp_static *sp;
3594
3595 /* Existing static changed TTL, search parents and adjust their atomic */
3596 while ((parent = parent->parent))
3597 if ((sp = parent->info))
3598 {
3599 int sp_level = (sp->atomic ? 1 : 0);
3600 ttl_edge ? sp->atomic++ : sp->atomic--;
3601
3602 /* did we change state of parent whether atomic is set or not? */
3603 if (sp_level != (sp->atomic ? 1 : 0))
3604 {
3605 bgp_static_update (bgp, &parent->p, sp,
3606 rn->table->afi, rn->table->safi);
3607 }
3608 }
3609}
3610
paul718e3742002-12-13 20:15:29 +00003611/* Configure static BGP network. When user don't run zebra, static
3612 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003613static int
paulfd79ac92004-10-13 05:06:08 +00003614bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakma41367172007-08-06 15:24:51 +00003615 u_int16_t afi, u_char safi, const char *rmap, int backdoor,
3616 u_char ttl)
paul718e3742002-12-13 20:15:29 +00003617{
3618 int ret;
3619 struct prefix p;
3620 struct bgp_static *bgp_static;
3621 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003622 u_char need_update = 0;
3623 u_char ttl_change = 0;
3624 u_char ttl_edge = (ttl ? 1 : 0);
3625 u_char new = 0;
paul718e3742002-12-13 20:15:29 +00003626
3627 /* Convert IP prefix string to struct prefix. */
3628 ret = str2prefix (ip_str, &p);
3629 if (! ret)
3630 {
3631 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3632 return CMD_WARNING;
3633 }
3634#ifdef HAVE_IPV6
3635 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3636 {
3637 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3638 VTY_NEWLINE);
3639 return CMD_WARNING;
3640 }
3641#endif /* HAVE_IPV6 */
3642
3643 apply_mask (&p);
3644
3645 /* Set BGP static route configuration. */
3646 rn = bgp_node_get (bgp->route[afi][safi], &p);
3647
3648 if (rn->info)
3649 {
3650 /* Configuration change. */
3651 bgp_static = rn->info;
3652
3653 /* Check previous routes are installed into BGP. */
Paul Jakma41367172007-08-06 15:24:51 +00003654 if (bgp_static->valid)
3655 {
3656 if (bgp_static->backdoor != backdoor
3657 || bgp_static->ttl != ttl)
3658 need_update = 1;
3659 }
3660
3661 /* need to catch TTL set/unset transitions for handling of
3662 * ATOMIC_AGGREGATE
3663 */
3664 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3665 ttl_change = 1;
3666
paul718e3742002-12-13 20:15:29 +00003667 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003668 bgp_static->ttl = ttl;
3669
paul718e3742002-12-13 20:15:29 +00003670 if (rmap)
3671 {
3672 if (bgp_static->rmap.name)
3673 free (bgp_static->rmap.name);
3674 bgp_static->rmap.name = strdup (rmap);
3675 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3676 }
3677 else
3678 {
3679 if (bgp_static->rmap.name)
3680 free (bgp_static->rmap.name);
3681 bgp_static->rmap.name = NULL;
3682 bgp_static->rmap.map = NULL;
3683 bgp_static->valid = 0;
3684 }
3685 bgp_unlock_node (rn);
3686 }
3687 else
3688 {
3689 /* New configuration. */
3690 bgp_static = bgp_static_new ();
3691 bgp_static->backdoor = backdoor;
3692 bgp_static->valid = 0;
3693 bgp_static->igpmetric = 0;
3694 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003695 bgp_static->ttl = ttl;
3696 ttl_change = ttl_edge;
3697 new = 1;
3698
paul718e3742002-12-13 20:15:29 +00003699 if (rmap)
3700 {
3701 if (bgp_static->rmap.name)
3702 free (bgp_static->rmap.name);
3703 bgp_static->rmap.name = strdup (rmap);
3704 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3705 }
3706 rn->info = bgp_static;
3707 }
3708
Paul Jakma41367172007-08-06 15:24:51 +00003709 /* ".. sites that choose to advertise the
3710 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3711 * all less specific covering prefixes as well as the more specific
3712 * prefixes."
3713 *
3714 * So:
3715 * Prefix that has just had pathlimit set/unset:
3716 * - Must bump ATOMIC refcount on all parents.
3717 *
3718 * To catch less specific prefixes:
3719 * - Must search children for ones with TTL, bump atomic refcount
3720 * (we dont care if we're deleting a less specific prefix..)
3721 */
3722 if (ttl_change)
3723 {
3724 /* Existing static changed TTL, search parents and adjust their atomic */
3725 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3726 }
3727
3728 if (new)
3729 {
3730 struct bgp_node *child;
3731 struct bgp_static *sc;
3732
3733 /* New static, search children and bump this statics atomic.. */
3734 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3735 while ((child = bgp_route_next_until (child, rn)))
3736 {
3737 if ((sc = child->info) && sc->ttl)
3738 bgp_static->atomic++;
3739 }
3740 }
3741
paul718e3742002-12-13 20:15:29 +00003742 /* If BGP scan is not enabled, we should install this route here. */
3743 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3744 {
3745 bgp_static->valid = 1;
3746
3747 if (need_update)
3748 bgp_static_withdraw (bgp, &p, afi, safi);
3749
3750 if (! bgp_static->backdoor)
3751 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3752 }
3753
3754 return CMD_SUCCESS;
3755}
3756
3757/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003758static int
paulfd79ac92004-10-13 05:06:08 +00003759bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003760 u_int16_t afi, u_char safi)
3761{
3762 int ret;
3763 struct prefix p;
3764 struct bgp_static *bgp_static;
3765 struct bgp_node *rn;
3766
3767 /* Convert IP prefix string to struct prefix. */
3768 ret = str2prefix (ip_str, &p);
3769 if (! ret)
3770 {
3771 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3772 return CMD_WARNING;
3773 }
3774#ifdef HAVE_IPV6
3775 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3776 {
3777 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3778 VTY_NEWLINE);
3779 return CMD_WARNING;
3780 }
3781#endif /* HAVE_IPV6 */
3782
3783 apply_mask (&p);
3784
3785 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3786 if (! rn)
3787 {
3788 vty_out (vty, "%% Can't find specified static route configuration.%s",
3789 VTY_NEWLINE);
3790 return CMD_WARNING;
3791 }
3792
3793 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003794
3795 /* decrement atomic in parents, see bgp_static_set */
3796 bgp_pathlimit_update_parents (bgp, rn, 0);
3797
paul718e3742002-12-13 20:15:29 +00003798 /* Update BGP RIB. */
3799 if (! bgp_static->backdoor)
3800 bgp_static_withdraw (bgp, &p, afi, safi);
3801
3802 /* Clear configuration. */
3803 bgp_static_free (bgp_static);
3804 rn->info = NULL;
3805 bgp_unlock_node (rn);
3806 bgp_unlock_node (rn);
3807
3808 return CMD_SUCCESS;
3809}
3810
3811/* Called from bgp_delete(). Delete all static routes from the BGP
3812 instance. */
3813void
3814bgp_static_delete (struct bgp *bgp)
3815{
3816 afi_t afi;
3817 safi_t safi;
3818 struct bgp_node *rn;
3819 struct bgp_node *rm;
3820 struct bgp_table *table;
3821 struct bgp_static *bgp_static;
3822
3823 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3824 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3825 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3826 if (rn->info != NULL)
3827 {
3828 if (safi == SAFI_MPLS_VPN)
3829 {
3830 table = rn->info;
3831
3832 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3833 {
3834 bgp_static = rn->info;
3835 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3836 AFI_IP, SAFI_MPLS_VPN,
3837 (struct prefix_rd *)&rn->p,
3838 bgp_static->tag);
3839 bgp_static_free (bgp_static);
3840 rn->info = NULL;
3841 bgp_unlock_node (rn);
3842 }
3843 }
3844 else
3845 {
3846 bgp_static = rn->info;
3847 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3848 bgp_static_free (bgp_static);
3849 rn->info = NULL;
3850 bgp_unlock_node (rn);
3851 }
3852 }
3853}
3854
3855int
paulfd79ac92004-10-13 05:06:08 +00003856bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3857 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003858{
3859 int ret;
3860 struct prefix p;
3861 struct prefix_rd prd;
3862 struct bgp *bgp;
3863 struct bgp_node *prn;
3864 struct bgp_node *rn;
3865 struct bgp_table *table;
3866 struct bgp_static *bgp_static;
3867 u_char tag[3];
3868
3869 bgp = vty->index;
3870
3871 ret = str2prefix (ip_str, &p);
3872 if (! ret)
3873 {
3874 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3875 return CMD_WARNING;
3876 }
3877 apply_mask (&p);
3878
3879 ret = str2prefix_rd (rd_str, &prd);
3880 if (! ret)
3881 {
3882 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3883 return CMD_WARNING;
3884 }
3885
3886 ret = str2tag (tag_str, tag);
3887 if (! ret)
3888 {
3889 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3890 return CMD_WARNING;
3891 }
3892
3893 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3894 (struct prefix *)&prd);
3895 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003896 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003897 else
3898 bgp_unlock_node (prn);
3899 table = prn->info;
3900
3901 rn = bgp_node_get (table, &p);
3902
3903 if (rn->info)
3904 {
3905 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3906 bgp_unlock_node (rn);
3907 }
3908 else
3909 {
3910 /* New configuration. */
3911 bgp_static = bgp_static_new ();
3912 bgp_static->valid = 1;
3913 memcpy (bgp_static->tag, tag, 3);
3914 rn->info = bgp_static;
3915
3916 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3917 }
3918
3919 return CMD_SUCCESS;
3920}
3921
3922/* Configure static BGP network. */
3923int
paulfd79ac92004-10-13 05:06:08 +00003924bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3925 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003926{
3927 int ret;
3928 struct bgp *bgp;
3929 struct prefix p;
3930 struct prefix_rd prd;
3931 struct bgp_node *prn;
3932 struct bgp_node *rn;
3933 struct bgp_table *table;
3934 struct bgp_static *bgp_static;
3935 u_char tag[3];
3936
3937 bgp = vty->index;
3938
3939 /* Convert IP prefix string to struct prefix. */
3940 ret = str2prefix (ip_str, &p);
3941 if (! ret)
3942 {
3943 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3944 return CMD_WARNING;
3945 }
3946 apply_mask (&p);
3947
3948 ret = str2prefix_rd (rd_str, &prd);
3949 if (! ret)
3950 {
3951 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3952 return CMD_WARNING;
3953 }
3954
3955 ret = str2tag (tag_str, tag);
3956 if (! ret)
3957 {
3958 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3959 return CMD_WARNING;
3960 }
3961
3962 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3963 (struct prefix *)&prd);
3964 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003965 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003966 else
3967 bgp_unlock_node (prn);
3968 table = prn->info;
3969
3970 rn = bgp_node_lookup (table, &p);
3971
3972 if (rn)
3973 {
3974 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3975
3976 bgp_static = rn->info;
3977 bgp_static_free (bgp_static);
3978 rn->info = NULL;
3979 bgp_unlock_node (rn);
3980 bgp_unlock_node (rn);
3981 }
3982 else
3983 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3984
3985 return CMD_SUCCESS;
3986}
3987
3988DEFUN (bgp_network,
3989 bgp_network_cmd,
3990 "network A.B.C.D/M",
3991 "Specify a network to announce via BGP\n"
3992 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3993{
Paul Jakma41367172007-08-06 15:24:51 +00003994 u_char ttl = 0;
3995
3996 if (argc == 2)
3997 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
3998
paul718e3742002-12-13 20:15:29 +00003999 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004000 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004001}
4002
Paul Jakma41367172007-08-06 15:24:51 +00004003ALIAS (bgp_network,
4004 bgp_network_ttl_cmd,
4005 "network A.B.C.D/M pathlimit <0-255>",
4006 "Specify a network to announce via BGP\n"
4007 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4008 "AS-Path hopcount limit attribute\n"
4009 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4010
paul718e3742002-12-13 20:15:29 +00004011DEFUN (bgp_network_route_map,
4012 bgp_network_route_map_cmd,
4013 "network A.B.C.D/M route-map WORD",
4014 "Specify a network to announce via BGP\n"
4015 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4016 "Route-map to modify the attributes\n"
4017 "Name of the route map\n")
4018{
4019 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004020 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004021}
4022
4023DEFUN (bgp_network_backdoor,
4024 bgp_network_backdoor_cmd,
4025 "network A.B.C.D/M backdoor",
4026 "Specify a network to announce via BGP\n"
4027 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4028 "Specify a BGP backdoor route\n")
4029{
Paul Jakma41367172007-08-06 15:24:51 +00004030 u_char ttl = 0;
4031
4032 if (argc == 2)
4033 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4034
4035 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4036 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004037}
4038
Paul Jakma41367172007-08-06 15:24:51 +00004039ALIAS (bgp_network_backdoor,
4040 bgp_network_backdoor_ttl_cmd,
4041 "network A.B.C.D/M backdoor pathlimit <0-255>",
4042 "Specify a network to announce via BGP\n"
4043 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4044 "Specify a BGP backdoor route\n"
4045 "AS-Path hopcount limit attribute\n"
4046 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4047
paul718e3742002-12-13 20:15:29 +00004048DEFUN (bgp_network_mask,
4049 bgp_network_mask_cmd,
4050 "network A.B.C.D mask A.B.C.D",
4051 "Specify a network to announce via BGP\n"
4052 "Network number\n"
4053 "Network mask\n"
4054 "Network mask\n")
4055{
4056 int ret;
4057 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004058 u_char ttl = 0;
4059
4060 if (argc == 3)
4061 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4062
paul718e3742002-12-13 20:15:29 +00004063 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4064 if (! ret)
4065 {
4066 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4067 return CMD_WARNING;
4068 }
4069
4070 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004071 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004072}
4073
Paul Jakma41367172007-08-06 15:24:51 +00004074ALIAS (bgp_network_mask,
4075 bgp_network_mask_ttl_cmd,
4076 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4077 "Specify a network to announce via BGP\n"
4078 "Network number\n"
4079 "Network mask\n"
4080 "Network mask\n"
4081 "AS-Path hopcount limit attribute\n"
4082 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4083
paul718e3742002-12-13 20:15:29 +00004084DEFUN (bgp_network_mask_route_map,
4085 bgp_network_mask_route_map_cmd,
4086 "network A.B.C.D mask A.B.C.D route-map WORD",
4087 "Specify a network to announce via BGP\n"
4088 "Network number\n"
4089 "Network mask\n"
4090 "Network mask\n"
4091 "Route-map to modify the attributes\n"
4092 "Name of the route map\n")
4093{
4094 int ret;
4095 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004096
paul718e3742002-12-13 20:15:29 +00004097 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4098 if (! ret)
4099 {
4100 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4101 return CMD_WARNING;
4102 }
4103
4104 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004105 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
paul718e3742002-12-13 20:15:29 +00004106}
4107
4108DEFUN (bgp_network_mask_backdoor,
4109 bgp_network_mask_backdoor_cmd,
4110 "network A.B.C.D mask A.B.C.D backdoor",
4111 "Specify a network to announce via BGP\n"
4112 "Network number\n"
4113 "Network mask\n"
4114 "Network mask\n"
4115 "Specify a BGP backdoor route\n")
4116{
4117 int ret;
4118 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004119 u_char ttl = 0;
4120
4121 if (argc == 3)
4122 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
paul718e3742002-12-13 20:15:29 +00004123
4124 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4125 if (! ret)
4126 {
4127 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4128 return CMD_WARNING;
4129 }
4130
Paul Jakma41367172007-08-06 15:24:51 +00004131 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4132 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004133}
4134
Paul Jakma41367172007-08-06 15:24:51 +00004135ALIAS (bgp_network_mask_backdoor,
4136 bgp_network_mask_backdoor_ttl_cmd,
4137 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4138 "Specify a network to announce via BGP\n"
4139 "Network number\n"
4140 "Network mask\n"
4141 "Network mask\n"
4142 "Specify a BGP backdoor route\n"
4143 "AS-Path hopcount limit attribute\n"
4144 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4145
paul718e3742002-12-13 20:15:29 +00004146DEFUN (bgp_network_mask_natural,
4147 bgp_network_mask_natural_cmd,
4148 "network A.B.C.D",
4149 "Specify a network to announce via BGP\n"
4150 "Network number\n")
4151{
4152 int ret;
4153 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004154 u_char ttl = 0;
4155
4156 if (argc == 2)
4157 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004158
4159 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4160 if (! ret)
4161 {
4162 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4163 return CMD_WARNING;
4164 }
4165
4166 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004167 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004168}
4169
Paul Jakma41367172007-08-06 15:24:51 +00004170ALIAS (bgp_network_mask_natural,
4171 bgp_network_mask_natural_ttl_cmd,
4172 "network A.B.C.D pathlimit <0-255>",
4173 "Specify a network to announce via BGP\n"
4174 "Network number\n"
4175 "AS-Path hopcount limit attribute\n"
4176 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4177
paul718e3742002-12-13 20:15:29 +00004178DEFUN (bgp_network_mask_natural_route_map,
4179 bgp_network_mask_natural_route_map_cmd,
4180 "network A.B.C.D route-map WORD",
4181 "Specify a network to announce via BGP\n"
4182 "Network number\n"
4183 "Route-map to modify the attributes\n"
4184 "Name of the route map\n")
4185{
4186 int ret;
4187 char prefix_str[BUFSIZ];
4188
4189 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4190 if (! ret)
4191 {
4192 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4193 return CMD_WARNING;
4194 }
4195
4196 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004197 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004198}
4199
4200DEFUN (bgp_network_mask_natural_backdoor,
4201 bgp_network_mask_natural_backdoor_cmd,
4202 "network A.B.C.D backdoor",
4203 "Specify a network to announce via BGP\n"
4204 "Network number\n"
4205 "Specify a BGP backdoor route\n")
4206{
4207 int ret;
4208 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004209 u_char ttl = 0;
4210
4211 if (argc == 2)
4212 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004213
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
Paul Jakma41367172007-08-06 15:24:51 +00004221 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4222 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004223}
4224
Paul Jakma41367172007-08-06 15:24:51 +00004225ALIAS (bgp_network_mask_natural_backdoor,
4226 bgp_network_mask_natural_backdoor_ttl_cmd,
4227 "network A.B.C.D backdoor pathlimit (1-255>",
4228 "Specify a network to announce via BGP\n"
4229 "Network number\n"
4230 "Specify a BGP backdoor route\n"
4231 "AS-Path hopcount limit attribute\n"
4232 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4233
paul718e3742002-12-13 20:15:29 +00004234DEFUN (no_bgp_network,
4235 no_bgp_network_cmd,
4236 "no network A.B.C.D/M",
4237 NO_STR
4238 "Specify a network to announce via BGP\n"
4239 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4240{
4241 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4242 bgp_node_safi (vty));
4243}
4244
4245ALIAS (no_bgp_network,
Paul Jakma41367172007-08-06 15:24:51 +00004246 no_bgp_network_ttl_cmd,
4247 "no network A.B.C.D/M pathlimit <0-255>",
4248 NO_STR
4249 "Specify a network to announce via BGP\n"
4250 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4251 "AS-Path hopcount limit attribute\n"
4252 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4253
4254ALIAS (no_bgp_network,
paul718e3742002-12-13 20:15:29 +00004255 no_bgp_network_route_map_cmd,
4256 "no network A.B.C.D/M route-map WORD",
4257 NO_STR
4258 "Specify a network to announce via BGP\n"
4259 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4260 "Route-map to modify the attributes\n"
4261 "Name of the route map\n")
4262
4263ALIAS (no_bgp_network,
4264 no_bgp_network_backdoor_cmd,
4265 "no network A.B.C.D/M backdoor",
4266 NO_STR
4267 "Specify a network to announce via BGP\n"
4268 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4269 "Specify a BGP backdoor route\n")
4270
Paul Jakma41367172007-08-06 15:24:51 +00004271ALIAS (no_bgp_network,
4272 no_bgp_network_backdoor_ttl_cmd,
4273 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4274 NO_STR
4275 "Specify a network to announce via BGP\n"
4276 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4277 "Specify a BGP backdoor route\n"
4278 "AS-Path hopcount limit attribute\n"
4279 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4280
paul718e3742002-12-13 20:15:29 +00004281DEFUN (no_bgp_network_mask,
4282 no_bgp_network_mask_cmd,
4283 "no network A.B.C.D mask A.B.C.D",
4284 NO_STR
4285 "Specify a network to announce via BGP\n"
4286 "Network number\n"
4287 "Network mask\n"
4288 "Network mask\n")
4289{
4290 int ret;
4291 char prefix_str[BUFSIZ];
4292
4293 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4294 if (! ret)
4295 {
4296 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4297 return CMD_WARNING;
4298 }
4299
4300 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4301 bgp_node_safi (vty));
4302}
4303
Paul Jakma41367172007-08-06 15:24:51 +00004304ALIAS (no_bgp_network,
4305 no_bgp_network_mask_ttl_cmd,
4306 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4307 NO_STR
4308 "Specify a network to announce via BGP\n"
4309 "Network number\n"
4310 "Network mask\n"
4311 "Network mask\n"
4312 "AS-Path hopcount limit attribute\n"
4313 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4314
paul718e3742002-12-13 20:15:29 +00004315ALIAS (no_bgp_network_mask,
4316 no_bgp_network_mask_route_map_cmd,
4317 "no network A.B.C.D mask A.B.C.D route-map WORD",
4318 NO_STR
4319 "Specify a network to announce via BGP\n"
4320 "Network number\n"
4321 "Network mask\n"
4322 "Network mask\n"
4323 "Route-map to modify the attributes\n"
4324 "Name of the route map\n")
4325
4326ALIAS (no_bgp_network_mask,
4327 no_bgp_network_mask_backdoor_cmd,
4328 "no network A.B.C.D mask A.B.C.D backdoor",
4329 NO_STR
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
Paul Jakma41367172007-08-06 15:24:51 +00004336ALIAS (no_bgp_network_mask,
4337 no_bgp_network_mask_backdoor_ttl_cmd,
4338 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4339 NO_STR
4340 "Specify a network to announce via BGP\n"
4341 "Network number\n"
4342 "Network mask\n"
4343 "Network mask\n"
4344 "Specify a BGP backdoor route\n"
4345 "AS-Path hopcount limit attribute\n"
4346 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4347
paul718e3742002-12-13 20:15:29 +00004348DEFUN (no_bgp_network_mask_natural,
4349 no_bgp_network_mask_natural_cmd,
4350 "no network A.B.C.D",
4351 NO_STR
4352 "Specify a network to announce via BGP\n"
4353 "Network number\n")
4354{
4355 int ret;
4356 char prefix_str[BUFSIZ];
4357
4358 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4359 if (! ret)
4360 {
4361 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4362 return CMD_WARNING;
4363 }
4364
4365 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4366 bgp_node_safi (vty));
4367}
4368
4369ALIAS (no_bgp_network_mask_natural,
4370 no_bgp_network_mask_natural_route_map_cmd,
4371 "no network A.B.C.D route-map WORD",
4372 NO_STR
4373 "Specify a network to announce via BGP\n"
4374 "Network number\n"
4375 "Route-map to modify the attributes\n"
4376 "Name of the route map\n")
4377
4378ALIAS (no_bgp_network_mask_natural,
4379 no_bgp_network_mask_natural_backdoor_cmd,
4380 "no network A.B.C.D backdoor",
4381 NO_STR
4382 "Specify a network to announce via BGP\n"
4383 "Network number\n"
4384 "Specify a BGP backdoor route\n")
4385
Paul Jakma41367172007-08-06 15:24:51 +00004386ALIAS (no_bgp_network_mask_natural,
4387 no_bgp_network_mask_natural_ttl_cmd,
4388 "no network A.B.C.D pathlimit <0-255>",
4389 NO_STR
4390 "Specify a network to announce via BGP\n"
4391 "Network number\n"
4392 "AS-Path hopcount limit attribute\n"
4393 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4394
4395ALIAS (no_bgp_network_mask_natural,
4396 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4397 "no network A.B.C.D backdoor pathlimit <0-255>",
4398 NO_STR
4399 "Specify a network to announce via BGP\n"
4400 "Network number\n"
4401 "Specify a BGP backdoor route\n"
4402 "AS-Path hopcount limit attribute\n"
4403 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4404
paul718e3742002-12-13 20:15:29 +00004405#ifdef HAVE_IPV6
4406DEFUN (ipv6_bgp_network,
4407 ipv6_bgp_network_cmd,
4408 "network X:X::X:X/M",
4409 "Specify a network to announce via BGP\n"
4410 "IPv6 prefix <network>/<length>\n")
4411{
Paul Jakma41367172007-08-06 15:24:51 +00004412 u_char ttl = 0;
4413
4414 if (argc == 2)
4415 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4416
4417 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4418 NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004419}
4420
Paul Jakma41367172007-08-06 15:24:51 +00004421ALIAS (ipv6_bgp_network,
4422 ipv6_bgp_network_ttl_cmd,
4423 "network X:X::X:X/M pathlimit <0-255>",
4424 "Specify a network to announce via BGP\n"
4425 "IPv6 prefix <network>/<length>\n"
4426 "AS-Path hopcount limit attribute\n"
4427 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4428
paul718e3742002-12-13 20:15:29 +00004429DEFUN (ipv6_bgp_network_route_map,
4430 ipv6_bgp_network_route_map_cmd,
4431 "network X:X::X:X/M route-map WORD",
4432 "Specify a network to announce via BGP\n"
4433 "IPv6 prefix <network>/<length>\n"
4434 "Route-map to modify the attributes\n"
4435 "Name of the route map\n")
4436{
4437 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakma41367172007-08-06 15:24:51 +00004438 bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004439}
4440
4441DEFUN (no_ipv6_bgp_network,
4442 no_ipv6_bgp_network_cmd,
4443 "no network X:X::X:X/M",
4444 NO_STR
4445 "Specify a network to announce via BGP\n"
4446 "IPv6 prefix <network>/<length>\n")
4447{
4448 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4449}
4450
4451ALIAS (no_ipv6_bgp_network,
4452 no_ipv6_bgp_network_route_map_cmd,
4453 "no network X:X::X:X/M route-map WORD",
4454 NO_STR
4455 "Specify a network to announce via BGP\n"
4456 "IPv6 prefix <network>/<length>\n"
4457 "Route-map to modify the attributes\n"
4458 "Name of the route map\n")
4459
Paul Jakma41367172007-08-06 15:24:51 +00004460ALIAS (no_ipv6_bgp_network,
4461 no_ipv6_bgp_network_ttl_cmd,
4462 "no network X:X::X:X/M pathlimit <0-255>",
4463 NO_STR
4464 "Specify a network to announce via BGP\n"
4465 "IPv6 prefix <network>/<length>\n"
4466 "AS-Path hopcount limit attribute\n"
4467 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4468
paul718e3742002-12-13 20:15:29 +00004469ALIAS (ipv6_bgp_network,
4470 old_ipv6_bgp_network_cmd,
4471 "ipv6 bgp network X:X::X:X/M",
4472 IPV6_STR
4473 BGP_STR
4474 "Specify a network to announce via BGP\n"
4475 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4476
4477ALIAS (no_ipv6_bgp_network,
4478 old_no_ipv6_bgp_network_cmd,
4479 "no ipv6 bgp network X:X::X:X/M",
4480 NO_STR
4481 IPV6_STR
4482 BGP_STR
4483 "Specify a network to announce via BGP\n"
4484 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4485#endif /* HAVE_IPV6 */
4486
4487/* Aggreagete address:
4488
4489 advertise-map Set condition to advertise attribute
4490 as-set Generate AS set path information
4491 attribute-map Set attributes of aggregate
4492 route-map Set parameters of aggregate
4493 summary-only Filter more specific routes from updates
4494 suppress-map Conditionally filter more specific routes from updates
4495 <cr>
4496 */
4497struct bgp_aggregate
4498{
4499 /* Summary-only flag. */
4500 u_char summary_only;
4501
4502 /* AS set generation. */
4503 u_char as_set;
4504
4505 /* Route-map for aggregated route. */
4506 struct route_map *map;
4507
4508 /* Suppress-count. */
4509 unsigned long count;
4510
4511 /* SAFI configuration. */
4512 safi_t safi;
4513};
4514
paul94f2b392005-06-28 12:44:16 +00004515static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00004516bgp_aggregate_new ()
4517{
4518 struct bgp_aggregate *new;
4519 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4520 memset (new, 0, sizeof (struct bgp_aggregate));
4521 return new;
4522}
4523
paul94f2b392005-06-28 12:44:16 +00004524static void
paul718e3742002-12-13 20:15:29 +00004525bgp_aggregate_free (struct bgp_aggregate *aggregate)
4526{
4527 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4528}
4529
paul94f2b392005-06-28 12:44:16 +00004530static void
paul718e3742002-12-13 20:15:29 +00004531bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4532 afi_t afi, safi_t safi, struct bgp_info *del,
4533 struct bgp_aggregate *aggregate)
4534{
4535 struct bgp_table *table;
4536 struct bgp_node *top;
4537 struct bgp_node *rn;
4538 u_char origin;
4539 struct aspath *aspath = NULL;
4540 struct aspath *asmerge = NULL;
4541 struct community *community = NULL;
4542 struct community *commerge = NULL;
4543 struct in_addr nexthop;
4544 u_int32_t med = 0;
4545 struct bgp_info *ri;
4546 struct bgp_info *new;
4547 int first = 1;
4548 unsigned long match = 0;
4549
4550 /* Record adding route's nexthop and med. */
4551 if (rinew)
4552 {
4553 nexthop = rinew->attr->nexthop;
4554 med = rinew->attr->med;
4555 }
4556
4557 /* ORIGIN attribute: If at least one route among routes that are
4558 aggregated has ORIGIN with the value INCOMPLETE, then the
4559 aggregated route must have the ORIGIN attribute with the value
4560 INCOMPLETE. Otherwise, if at least one route among routes that
4561 are aggregated has ORIGIN with the value EGP, then the aggregated
4562 route must have the origin attribute with the value EGP. In all
4563 other case the value of the ORIGIN attribute of the aggregated
4564 route is INTERNAL. */
4565 origin = BGP_ORIGIN_IGP;
4566
4567 table = bgp->rib[afi][safi];
4568
4569 top = bgp_node_get (table, p);
4570 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4571 if (rn->p.prefixlen > p->prefixlen)
4572 {
4573 match = 0;
4574
4575 for (ri = rn->info; ri; ri = ri->next)
4576 {
4577 if (BGP_INFO_HOLDDOWN (ri))
4578 continue;
4579
4580 if (del && ri == del)
4581 continue;
4582
4583 if (! rinew && first)
4584 {
4585 nexthop = ri->attr->nexthop;
4586 med = ri->attr->med;
4587 first = 0;
4588 }
4589
4590#ifdef AGGREGATE_NEXTHOP_CHECK
4591 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4592 || ri->attr->med != med)
4593 {
4594 if (aspath)
4595 aspath_free (aspath);
4596 if (community)
4597 community_free (community);
4598 bgp_unlock_node (rn);
4599 bgp_unlock_node (top);
4600 return;
4601 }
4602#endif /* AGGREGATE_NEXTHOP_CHECK */
4603
4604 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4605 {
4606 if (aggregate->summary_only)
4607 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004608 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004609 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004610 match++;
4611 }
4612
4613 aggregate->count++;
4614
4615 if (aggregate->as_set)
4616 {
4617 if (origin < ri->attr->origin)
4618 origin = ri->attr->origin;
4619
4620 if (aspath)
4621 {
4622 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4623 aspath_free (aspath);
4624 aspath = asmerge;
4625 }
4626 else
4627 aspath = aspath_dup (ri->attr->aspath);
4628
4629 if (ri->attr->community)
4630 {
4631 if (community)
4632 {
4633 commerge = community_merge (community,
4634 ri->attr->community);
4635 community = community_uniq_sort (commerge);
4636 community_free (commerge);
4637 }
4638 else
4639 community = community_dup (ri->attr->community);
4640 }
4641 }
4642 }
4643 }
4644 if (match)
4645 bgp_process (bgp, rn, afi, safi);
4646 }
4647 bgp_unlock_node (top);
4648
4649 if (rinew)
4650 {
4651 aggregate->count++;
4652
4653 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004654 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004655
4656 if (aggregate->as_set)
4657 {
4658 if (origin < rinew->attr->origin)
4659 origin = rinew->attr->origin;
4660
4661 if (aspath)
4662 {
4663 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4664 aspath_free (aspath);
4665 aspath = asmerge;
4666 }
4667 else
4668 aspath = aspath_dup (rinew->attr->aspath);
4669
4670 if (rinew->attr->community)
4671 {
4672 if (community)
4673 {
4674 commerge = community_merge (community,
4675 rinew->attr->community);
4676 community = community_uniq_sort (commerge);
4677 community_free (commerge);
4678 }
4679 else
4680 community = community_dup (rinew->attr->community);
4681 }
4682 }
4683 }
4684
4685 if (aggregate->count > 0)
4686 {
4687 rn = bgp_node_get (table, p);
4688 new = bgp_info_new ();
4689 new->type = ZEBRA_ROUTE_BGP;
4690 new->sub_type = BGP_ROUTE_AGGREGATE;
4691 new->peer = bgp->peer_self;
4692 SET_FLAG (new->flags, BGP_INFO_VALID);
4693 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4694 new->uptime = time (NULL);
4695
4696 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004697 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004698 bgp_process (bgp, rn, afi, safi);
4699 }
4700 else
4701 {
4702 if (aspath)
4703 aspath_free (aspath);
4704 if (community)
4705 community_free (community);
4706 }
4707}
4708
4709void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4710 struct bgp_aggregate *);
4711
4712void
4713bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4714 struct bgp_info *ri, afi_t afi, safi_t safi)
4715{
4716 struct bgp_node *child;
4717 struct bgp_node *rn;
4718 struct bgp_aggregate *aggregate;
4719
4720 /* MPLS-VPN aggregation is not yet supported. */
4721 if (safi == SAFI_MPLS_VPN)
4722 return;
4723
4724 if (p->prefixlen == 0)
4725 return;
4726
4727 if (BGP_INFO_HOLDDOWN (ri))
4728 return;
4729
4730 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4731
4732 /* Aggregate address configuration check. */
4733 for (rn = child; rn; rn = rn->parent)
4734 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4735 {
4736 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004737 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004738 }
4739 bgp_unlock_node (child);
4740}
4741
4742void
4743bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4744 struct bgp_info *del, afi_t afi, safi_t safi)
4745{
4746 struct bgp_node *child;
4747 struct bgp_node *rn;
4748 struct bgp_aggregate *aggregate;
4749
4750 /* MPLS-VPN aggregation is not yet supported. */
4751 if (safi == SAFI_MPLS_VPN)
4752 return;
4753
4754 if (p->prefixlen == 0)
4755 return;
4756
4757 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4758
4759 /* Aggregate address configuration check. */
4760 for (rn = child; rn; rn = rn->parent)
4761 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4762 {
4763 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004764 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004765 }
4766 bgp_unlock_node (child);
4767}
4768
paul94f2b392005-06-28 12:44:16 +00004769static void
paul718e3742002-12-13 20:15:29 +00004770bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4771 struct bgp_aggregate *aggregate)
4772{
4773 struct bgp_table *table;
4774 struct bgp_node *top;
4775 struct bgp_node *rn;
4776 struct bgp_info *new;
4777 struct bgp_info *ri;
4778 unsigned long match;
4779 u_char origin = BGP_ORIGIN_IGP;
4780 struct aspath *aspath = NULL;
4781 struct aspath *asmerge = NULL;
4782 struct community *community = NULL;
4783 struct community *commerge = NULL;
4784
4785 table = bgp->rib[afi][safi];
4786
4787 /* Sanity check. */
4788 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4789 return;
4790 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4791 return;
4792
4793 /* If routes exists below this node, generate aggregate routes. */
4794 top = bgp_node_get (table, p);
4795 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4796 if (rn->p.prefixlen > p->prefixlen)
4797 {
4798 match = 0;
4799
4800 for (ri = rn->info; ri; ri = ri->next)
4801 {
4802 if (BGP_INFO_HOLDDOWN (ri))
4803 continue;
4804
4805 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4806 {
4807 /* summary-only aggregate route suppress aggregated
4808 route announcement. */
4809 if (aggregate->summary_only)
4810 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004811 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004812 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004813 match++;
4814 }
4815 /* as-set aggregate route generate origin, as path,
4816 community aggregation. */
4817 if (aggregate->as_set)
4818 {
4819 if (origin < ri->attr->origin)
4820 origin = ri->attr->origin;
4821
4822 if (aspath)
4823 {
4824 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4825 aspath_free (aspath);
4826 aspath = asmerge;
4827 }
4828 else
4829 aspath = aspath_dup (ri->attr->aspath);
4830
4831 if (ri->attr->community)
4832 {
4833 if (community)
4834 {
4835 commerge = community_merge (community,
4836 ri->attr->community);
4837 community = community_uniq_sort (commerge);
4838 community_free (commerge);
4839 }
4840 else
4841 community = community_dup (ri->attr->community);
4842 }
4843 }
4844 aggregate->count++;
4845 }
4846 }
4847
4848 /* If this node is suppressed, process the change. */
4849 if (match)
4850 bgp_process (bgp, rn, afi, safi);
4851 }
4852 bgp_unlock_node (top);
4853
4854 /* Add aggregate route to BGP table. */
4855 if (aggregate->count)
4856 {
4857 rn = bgp_node_get (table, p);
4858
4859 new = bgp_info_new ();
4860 new->type = ZEBRA_ROUTE_BGP;
4861 new->sub_type = BGP_ROUTE_AGGREGATE;
4862 new->peer = bgp->peer_self;
4863 SET_FLAG (new->flags, BGP_INFO_VALID);
4864 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4865 new->uptime = time (NULL);
4866
4867 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004868 bgp_unlock_node (rn);
4869
paul718e3742002-12-13 20:15:29 +00004870 /* Process change. */
4871 bgp_process (bgp, rn, afi, safi);
4872 }
4873}
4874
4875void
4876bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4877 safi_t safi, struct bgp_aggregate *aggregate)
4878{
4879 struct bgp_table *table;
4880 struct bgp_node *top;
4881 struct bgp_node *rn;
4882 struct bgp_info *ri;
4883 unsigned long match;
4884
4885 table = bgp->rib[afi][safi];
4886
4887 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4888 return;
4889 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4890 return;
4891
4892 /* If routes exists below this node, generate aggregate routes. */
4893 top = bgp_node_get (table, p);
4894 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4895 if (rn->p.prefixlen > p->prefixlen)
4896 {
4897 match = 0;
4898
4899 for (ri = rn->info; ri; ri = ri->next)
4900 {
4901 if (BGP_INFO_HOLDDOWN (ri))
4902 continue;
4903
4904 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4905 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004906 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004907 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004908 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004909
Paul Jakmafb982c22007-05-04 20:15:47 +00004910 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004911 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004912 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004913 match++;
4914 }
4915 }
4916 aggregate->count--;
4917 }
4918 }
4919
Paul Jakmafb982c22007-05-04 20:15:47 +00004920 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004921 if (match)
4922 bgp_process (bgp, rn, afi, safi);
4923 }
4924 bgp_unlock_node (top);
4925
4926 /* Delete aggregate route from BGP table. */
4927 rn = bgp_node_get (table, p);
4928
4929 for (ri = rn->info; ri; ri = ri->next)
4930 if (ri->peer == bgp->peer_self
4931 && ri->type == ZEBRA_ROUTE_BGP
4932 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4933 break;
4934
4935 /* Withdraw static BGP route from routing table. */
4936 if (ri)
4937 {
paul718e3742002-12-13 20:15:29 +00004938 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004939 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004940 }
4941
4942 /* Unlock bgp_node_lookup. */
4943 bgp_unlock_node (rn);
4944}
4945
4946/* Aggregate route attribute. */
4947#define AGGREGATE_SUMMARY_ONLY 1
4948#define AGGREGATE_AS_SET 1
4949
paul94f2b392005-06-28 12:44:16 +00004950static int
paulfd79ac92004-10-13 05:06:08 +00004951bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4952 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004953 u_char summary_only, u_char as_set)
4954{
4955 int ret;
4956 struct prefix p;
4957 struct bgp_node *rn;
4958 struct bgp *bgp;
4959 struct bgp_aggregate *aggregate;
4960
4961 /* Convert string to prefix structure. */
4962 ret = str2prefix (prefix_str, &p);
4963 if (!ret)
4964 {
4965 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4966 return CMD_WARNING;
4967 }
4968 apply_mask (&p);
4969
4970 /* Get BGP structure. */
4971 bgp = vty->index;
4972
4973 /* Old configuration check. */
4974 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4975
4976 if (rn->info)
4977 {
4978 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4979 bgp_unlock_node (rn);
4980 return CMD_WARNING;
4981 }
4982
4983 /* Make aggregate address structure. */
4984 aggregate = bgp_aggregate_new ();
4985 aggregate->summary_only = summary_only;
4986 aggregate->as_set = as_set;
4987 aggregate->safi = safi;
4988 rn->info = aggregate;
4989
4990 /* Aggregate address insert into BGP routing table. */
4991 if (safi & SAFI_UNICAST)
4992 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4993 if (safi & SAFI_MULTICAST)
4994 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4995
4996 return CMD_SUCCESS;
4997}
4998
paul94f2b392005-06-28 12:44:16 +00004999static int
paulfd79ac92004-10-13 05:06:08 +00005000bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
5001 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00005002{
5003 int ret;
5004 struct prefix p;
5005 struct bgp_node *rn;
5006 struct bgp *bgp;
5007 struct bgp_aggregate *aggregate;
5008
5009 /* Convert string to prefix structure. */
5010 ret = str2prefix (prefix_str, &p);
5011 if (!ret)
5012 {
5013 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5014 return CMD_WARNING;
5015 }
5016 apply_mask (&p);
5017
5018 /* Get BGP structure. */
5019 bgp = vty->index;
5020
5021 /* Old configuration check. */
5022 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5023 if (! rn)
5024 {
5025 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5026 VTY_NEWLINE);
5027 return CMD_WARNING;
5028 }
5029
5030 aggregate = rn->info;
5031 if (aggregate->safi & SAFI_UNICAST)
5032 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5033 if (aggregate->safi & SAFI_MULTICAST)
5034 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5035
5036 /* Unlock aggregate address configuration. */
5037 rn->info = NULL;
5038 bgp_aggregate_free (aggregate);
5039 bgp_unlock_node (rn);
5040 bgp_unlock_node (rn);
5041
5042 return CMD_SUCCESS;
5043}
5044
5045DEFUN (aggregate_address,
5046 aggregate_address_cmd,
5047 "aggregate-address A.B.C.D/M",
5048 "Configure BGP aggregate entries\n"
5049 "Aggregate prefix\n")
5050{
5051 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5052}
5053
5054DEFUN (aggregate_address_mask,
5055 aggregate_address_mask_cmd,
5056 "aggregate-address A.B.C.D A.B.C.D",
5057 "Configure BGP aggregate entries\n"
5058 "Aggregate address\n"
5059 "Aggregate mask\n")
5060{
5061 int ret;
5062 char prefix_str[BUFSIZ];
5063
5064 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5065
5066 if (! ret)
5067 {
5068 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5069 return CMD_WARNING;
5070 }
5071
5072 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5073 0, 0);
5074}
5075
5076DEFUN (aggregate_address_summary_only,
5077 aggregate_address_summary_only_cmd,
5078 "aggregate-address A.B.C.D/M summary-only",
5079 "Configure BGP aggregate entries\n"
5080 "Aggregate prefix\n"
5081 "Filter more specific routes from updates\n")
5082{
5083 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5084 AGGREGATE_SUMMARY_ONLY, 0);
5085}
5086
5087DEFUN (aggregate_address_mask_summary_only,
5088 aggregate_address_mask_summary_only_cmd,
5089 "aggregate-address A.B.C.D A.B.C.D summary-only",
5090 "Configure BGP aggregate entries\n"
5091 "Aggregate address\n"
5092 "Aggregate mask\n"
5093 "Filter more specific routes from updates\n")
5094{
5095 int ret;
5096 char prefix_str[BUFSIZ];
5097
5098 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5099
5100 if (! ret)
5101 {
5102 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5103 return CMD_WARNING;
5104 }
5105
5106 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5107 AGGREGATE_SUMMARY_ONLY, 0);
5108}
5109
5110DEFUN (aggregate_address_as_set,
5111 aggregate_address_as_set_cmd,
5112 "aggregate-address A.B.C.D/M as-set",
5113 "Configure BGP aggregate entries\n"
5114 "Aggregate prefix\n"
5115 "Generate AS set path information\n")
5116{
5117 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5118 0, AGGREGATE_AS_SET);
5119}
5120
5121DEFUN (aggregate_address_mask_as_set,
5122 aggregate_address_mask_as_set_cmd,
5123 "aggregate-address A.B.C.D A.B.C.D as-set",
5124 "Configure BGP aggregate entries\n"
5125 "Aggregate address\n"
5126 "Aggregate mask\n"
5127 "Generate AS set path information\n")
5128{
5129 int ret;
5130 char prefix_str[BUFSIZ];
5131
5132 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5133
5134 if (! ret)
5135 {
5136 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5137 return CMD_WARNING;
5138 }
5139
5140 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5141 0, AGGREGATE_AS_SET);
5142}
5143
5144
5145DEFUN (aggregate_address_as_set_summary,
5146 aggregate_address_as_set_summary_cmd,
5147 "aggregate-address A.B.C.D/M as-set summary-only",
5148 "Configure BGP aggregate entries\n"
5149 "Aggregate prefix\n"
5150 "Generate AS set path information\n"
5151 "Filter more specific routes from updates\n")
5152{
5153 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5154 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5155}
5156
5157ALIAS (aggregate_address_as_set_summary,
5158 aggregate_address_summary_as_set_cmd,
5159 "aggregate-address A.B.C.D/M summary-only as-set",
5160 "Configure BGP aggregate entries\n"
5161 "Aggregate prefix\n"
5162 "Filter more specific routes from updates\n"
5163 "Generate AS set path information\n")
5164
5165DEFUN (aggregate_address_mask_as_set_summary,
5166 aggregate_address_mask_as_set_summary_cmd,
5167 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5168 "Configure BGP aggregate entries\n"
5169 "Aggregate address\n"
5170 "Aggregate mask\n"
5171 "Generate AS set path information\n"
5172 "Filter more specific routes from updates\n")
5173{
5174 int ret;
5175 char prefix_str[BUFSIZ];
5176
5177 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5178
5179 if (! ret)
5180 {
5181 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5182 return CMD_WARNING;
5183 }
5184
5185 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5186 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5187}
5188
5189ALIAS (aggregate_address_mask_as_set_summary,
5190 aggregate_address_mask_summary_as_set_cmd,
5191 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5192 "Configure BGP aggregate entries\n"
5193 "Aggregate address\n"
5194 "Aggregate mask\n"
5195 "Filter more specific routes from updates\n"
5196 "Generate AS set path information\n")
5197
5198DEFUN (no_aggregate_address,
5199 no_aggregate_address_cmd,
5200 "no aggregate-address A.B.C.D/M",
5201 NO_STR
5202 "Configure BGP aggregate entries\n"
5203 "Aggregate prefix\n")
5204{
5205 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5206}
5207
5208ALIAS (no_aggregate_address,
5209 no_aggregate_address_summary_only_cmd,
5210 "no aggregate-address A.B.C.D/M summary-only",
5211 NO_STR
5212 "Configure BGP aggregate entries\n"
5213 "Aggregate prefix\n"
5214 "Filter more specific routes from updates\n")
5215
5216ALIAS (no_aggregate_address,
5217 no_aggregate_address_as_set_cmd,
5218 "no aggregate-address A.B.C.D/M as-set",
5219 NO_STR
5220 "Configure BGP aggregate entries\n"
5221 "Aggregate prefix\n"
5222 "Generate AS set path information\n")
5223
5224ALIAS (no_aggregate_address,
5225 no_aggregate_address_as_set_summary_cmd,
5226 "no aggregate-address A.B.C.D/M as-set summary-only",
5227 NO_STR
5228 "Configure BGP aggregate entries\n"
5229 "Aggregate prefix\n"
5230 "Generate AS set path information\n"
5231 "Filter more specific routes from updates\n")
5232
5233ALIAS (no_aggregate_address,
5234 no_aggregate_address_summary_as_set_cmd,
5235 "no aggregate-address A.B.C.D/M summary-only as-set",
5236 NO_STR
5237 "Configure BGP aggregate entries\n"
5238 "Aggregate prefix\n"
5239 "Filter more specific routes from updates\n"
5240 "Generate AS set path information\n")
5241
5242DEFUN (no_aggregate_address_mask,
5243 no_aggregate_address_mask_cmd,
5244 "no aggregate-address A.B.C.D A.B.C.D",
5245 NO_STR
5246 "Configure BGP aggregate entries\n"
5247 "Aggregate address\n"
5248 "Aggregate mask\n")
5249{
5250 int ret;
5251 char prefix_str[BUFSIZ];
5252
5253 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5254
5255 if (! ret)
5256 {
5257 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5258 return CMD_WARNING;
5259 }
5260
5261 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5262}
5263
5264ALIAS (no_aggregate_address_mask,
5265 no_aggregate_address_mask_summary_only_cmd,
5266 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5267 NO_STR
5268 "Configure BGP aggregate entries\n"
5269 "Aggregate address\n"
5270 "Aggregate mask\n"
5271 "Filter more specific routes from updates\n")
5272
5273ALIAS (no_aggregate_address_mask,
5274 no_aggregate_address_mask_as_set_cmd,
5275 "no aggregate-address A.B.C.D A.B.C.D as-set",
5276 NO_STR
5277 "Configure BGP aggregate entries\n"
5278 "Aggregate address\n"
5279 "Aggregate mask\n"
5280 "Generate AS set path information\n")
5281
5282ALIAS (no_aggregate_address_mask,
5283 no_aggregate_address_mask_as_set_summary_cmd,
5284 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5285 NO_STR
5286 "Configure BGP aggregate entries\n"
5287 "Aggregate address\n"
5288 "Aggregate mask\n"
5289 "Generate AS set path information\n"
5290 "Filter more specific routes from updates\n")
5291
5292ALIAS (no_aggregate_address_mask,
5293 no_aggregate_address_mask_summary_as_set_cmd,
5294 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5295 NO_STR
5296 "Configure BGP aggregate entries\n"
5297 "Aggregate address\n"
5298 "Aggregate mask\n"
5299 "Filter more specific routes from updates\n"
5300 "Generate AS set path information\n")
5301
5302#ifdef HAVE_IPV6
5303DEFUN (ipv6_aggregate_address,
5304 ipv6_aggregate_address_cmd,
5305 "aggregate-address X:X::X:X/M",
5306 "Configure BGP aggregate entries\n"
5307 "Aggregate prefix\n")
5308{
5309 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5310}
5311
5312DEFUN (ipv6_aggregate_address_summary_only,
5313 ipv6_aggregate_address_summary_only_cmd,
5314 "aggregate-address X:X::X:X/M summary-only",
5315 "Configure BGP aggregate entries\n"
5316 "Aggregate prefix\n"
5317 "Filter more specific routes from updates\n")
5318{
5319 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5320 AGGREGATE_SUMMARY_ONLY, 0);
5321}
5322
5323DEFUN (no_ipv6_aggregate_address,
5324 no_ipv6_aggregate_address_cmd,
5325 "no aggregate-address X:X::X:X/M",
5326 NO_STR
5327 "Configure BGP aggregate entries\n"
5328 "Aggregate prefix\n")
5329{
5330 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5331}
5332
5333DEFUN (no_ipv6_aggregate_address_summary_only,
5334 no_ipv6_aggregate_address_summary_only_cmd,
5335 "no aggregate-address X:X::X:X/M summary-only",
5336 NO_STR
5337 "Configure BGP aggregate entries\n"
5338 "Aggregate prefix\n"
5339 "Filter more specific routes from updates\n")
5340{
5341 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5342}
5343
5344ALIAS (ipv6_aggregate_address,
5345 old_ipv6_aggregate_address_cmd,
5346 "ipv6 bgp aggregate-address X:X::X:X/M",
5347 IPV6_STR
5348 BGP_STR
5349 "Configure BGP aggregate entries\n"
5350 "Aggregate prefix\n")
5351
5352ALIAS (ipv6_aggregate_address_summary_only,
5353 old_ipv6_aggregate_address_summary_only_cmd,
5354 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5355 IPV6_STR
5356 BGP_STR
5357 "Configure BGP aggregate entries\n"
5358 "Aggregate prefix\n"
5359 "Filter more specific routes from updates\n")
5360
5361ALIAS (no_ipv6_aggregate_address,
5362 old_no_ipv6_aggregate_address_cmd,
5363 "no ipv6 bgp aggregate-address X:X::X:X/M",
5364 NO_STR
5365 IPV6_STR
5366 BGP_STR
5367 "Configure BGP aggregate entries\n"
5368 "Aggregate prefix\n")
5369
5370ALIAS (no_ipv6_aggregate_address_summary_only,
5371 old_no_ipv6_aggregate_address_summary_only_cmd,
5372 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5373 NO_STR
5374 IPV6_STR
5375 BGP_STR
5376 "Configure BGP aggregate entries\n"
5377 "Aggregate prefix\n"
5378 "Filter more specific routes from updates\n")
5379#endif /* HAVE_IPV6 */
5380
5381/* Redistribute route treatment. */
5382void
5383bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5384 u_int32_t metric, u_char type)
5385{
5386 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005387 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005388 struct bgp_info *new;
5389 struct bgp_info *bi;
5390 struct bgp_info info;
5391 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005392 struct attr attr = { 0 };
5393 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005394 struct attr *new_attr;
5395 afi_t afi;
5396 int ret;
5397
5398 /* Make default attribute. */
5399 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5400 if (nexthop)
5401 attr.nexthop = *nexthop;
5402
5403 attr.med = metric;
5404 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5405
paul1eb8ef22005-04-07 07:30:20 +00005406 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005407 {
5408 afi = family2afi (p->family);
5409
5410 if (bgp->redist[afi][type])
5411 {
5412 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005413 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005414
5415 if (bgp->redist_metric_flag[afi][type])
5416 attr_new.med = bgp->redist_metric[afi][type];
5417
5418 /* Apply route-map. */
5419 if (bgp->rmap[afi][type].map)
5420 {
5421 info.peer = bgp->peer_self;
5422 info.attr = &attr_new;
5423
paulfee0f4c2004-09-13 05:12:46 +00005424 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5425
paul718e3742002-12-13 20:15:29 +00005426 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5427 &info);
paulfee0f4c2004-09-13 05:12:46 +00005428
5429 bgp->peer_self->rmap_type = 0;
5430
paul718e3742002-12-13 20:15:29 +00005431 if (ret == RMAP_DENYMATCH)
5432 {
5433 /* Free uninterned attribute. */
5434 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005435 bgp_attr_extra_free (&attr_new);
5436
paul718e3742002-12-13 20:15:29 +00005437 /* Unintern original. */
5438 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005439 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005440 bgp_redistribute_delete (p, type);
5441 return;
5442 }
5443 }
5444
Paul Jakmafb982c22007-05-04 20:15:47 +00005445 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5446 afi, SAFI_UNICAST, p, NULL);
5447
paul718e3742002-12-13 20:15:29 +00005448 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005449 bgp_attr_extra_free (&attr_new);
5450
paul718e3742002-12-13 20:15:29 +00005451 for (bi = bn->info; bi; bi = bi->next)
5452 if (bi->peer == bgp->peer_self
5453 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5454 break;
5455
5456 if (bi)
5457 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005458 if (attrhash_cmp (bi->attr, new_attr) &&
5459 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005460 {
5461 bgp_attr_unintern (new_attr);
5462 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005463 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005464 bgp_unlock_node (bn);
5465 return;
5466 }
5467 else
5468 {
5469 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005470 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005471
5472 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005473 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5474 bgp_info_restore(bn, bi);
5475 else
5476 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005477 bgp_attr_unintern (bi->attr);
5478 bi->attr = new_attr;
5479 bi->uptime = time (NULL);
5480
5481 /* Process change. */
5482 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5483 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5484 bgp_unlock_node (bn);
5485 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005486 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005487 return;
5488 }
5489 }
5490
5491 new = bgp_info_new ();
5492 new->type = type;
5493 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5494 new->peer = bgp->peer_self;
5495 SET_FLAG (new->flags, BGP_INFO_VALID);
5496 new->attr = new_attr;
5497 new->uptime = time (NULL);
5498
5499 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5500 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005501 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005502 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5503 }
5504 }
5505
5506 /* Unintern original. */
5507 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005508 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005509}
5510
5511void
5512bgp_redistribute_delete (struct prefix *p, u_char type)
5513{
5514 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005515 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005516 afi_t afi;
5517 struct bgp_node *rn;
5518 struct bgp_info *ri;
5519
paul1eb8ef22005-04-07 07:30:20 +00005520 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005521 {
5522 afi = family2afi (p->family);
5523
5524 if (bgp->redist[afi][type])
5525 {
paulfee0f4c2004-09-13 05:12:46 +00005526 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005527
5528 for (ri = rn->info; ri; ri = ri->next)
5529 if (ri->peer == bgp->peer_self
5530 && ri->type == type)
5531 break;
5532
5533 if (ri)
5534 {
5535 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005536 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005537 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005538 }
5539 bgp_unlock_node (rn);
5540 }
5541 }
5542}
5543
5544/* Withdraw specified route type's route. */
5545void
5546bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5547{
5548 struct bgp_node *rn;
5549 struct bgp_info *ri;
5550 struct bgp_table *table;
5551
5552 table = bgp->rib[afi][SAFI_UNICAST];
5553
5554 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5555 {
5556 for (ri = rn->info; ri; ri = ri->next)
5557 if (ri->peer == bgp->peer_self
5558 && ri->type == type)
5559 break;
5560
5561 if (ri)
5562 {
5563 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005564 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005565 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005566 }
5567 }
5568}
5569
5570/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005571static void
paul718e3742002-12-13 20:15:29 +00005572route_vty_out_route (struct prefix *p, struct vty *vty)
5573{
5574 int len;
5575 u_int32_t destination;
5576 char buf[BUFSIZ];
5577
5578 if (p->family == AF_INET)
5579 {
5580 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5581 destination = ntohl (p->u.prefix4.s_addr);
5582
5583 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5584 || (IN_CLASSB (destination) && p->prefixlen == 16)
5585 || (IN_CLASSA (destination) && p->prefixlen == 8)
5586 || p->u.prefix4.s_addr == 0)
5587 {
5588 /* When mask is natural, mask is not displayed. */
5589 }
5590 else
5591 len += vty_out (vty, "/%d", p->prefixlen);
5592 }
5593 else
5594 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5595 p->prefixlen);
5596
5597 len = 17 - len;
5598 if (len < 1)
5599 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5600 else
5601 vty_out (vty, "%*s", len, " ");
5602}
5603
paul718e3742002-12-13 20:15:29 +00005604enum bgp_display_type
5605{
5606 normal_list,
5607};
5608
paulb40d9392005-08-22 22:34:41 +00005609/* Print the short form route status for a bgp_info */
5610static void
5611route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005612{
paulb40d9392005-08-22 22:34:41 +00005613 /* Route status display. */
5614 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5615 vty_out (vty, "R");
5616 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005617 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005618 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005619 vty_out (vty, "s");
5620 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5621 vty_out (vty, "*");
5622 else
5623 vty_out (vty, " ");
5624
5625 /* Selected */
5626 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5627 vty_out (vty, "h");
5628 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5629 vty_out (vty, "d");
5630 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5631 vty_out (vty, ">");
5632 else
5633 vty_out (vty, " ");
5634
5635 /* Internal route. */
5636 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5637 vty_out (vty, "i");
5638 else
paulb40d9392005-08-22 22:34:41 +00005639 vty_out (vty, " ");
5640}
5641
5642/* called from terminal list command */
5643void
5644route_vty_out (struct vty *vty, struct prefix *p,
5645 struct bgp_info *binfo, int display, safi_t safi)
5646{
5647 struct attr *attr;
5648
5649 /* short status lead text */
5650 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005651
5652 /* print prefix and mask */
5653 if (! display)
5654 route_vty_out_route (p, vty);
5655 else
5656 vty_out (vty, "%*s", 17, " ");
5657
5658 /* Print attribute */
5659 attr = binfo->attr;
5660 if (attr)
5661 {
5662 if (p->family == AF_INET)
5663 {
5664 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005665 vty_out (vty, "%-16s",
5666 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005667 else
5668 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5669 }
5670#ifdef HAVE_IPV6
5671 else if (p->family == AF_INET6)
5672 {
5673 int len;
5674 char buf[BUFSIZ];
5675
5676 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005677 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5678 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005679 len = 16 - len;
5680 if (len < 1)
5681 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5682 else
5683 vty_out (vty, "%*s", len, " ");
5684 }
5685#endif /* HAVE_IPV6 */
5686
5687 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5688 vty_out (vty, "%10d", attr->med);
5689 else
5690 vty_out (vty, " ");
5691
5692 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5693 vty_out (vty, "%7d", attr->local_pref);
5694 else
5695 vty_out (vty, " ");
5696
Paul Jakmafb982c22007-05-04 20:15:47 +00005697 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005698
Paul Jakmab2518c12006-05-12 23:48:40 +00005699 /* Print aspath */
5700 if (attr->aspath)
5701 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005702
Paul Jakmab2518c12006-05-12 23:48:40 +00005703 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005704 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005705 }
paul718e3742002-12-13 20:15:29 +00005706 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005707}
5708
5709/* called from terminal list command */
5710void
5711route_vty_out_tmp (struct vty *vty, struct prefix *p,
5712 struct attr *attr, safi_t safi)
5713{
5714 /* Route status display. */
5715 vty_out (vty, "*");
5716 vty_out (vty, ">");
5717 vty_out (vty, " ");
5718
5719 /* print prefix and mask */
5720 route_vty_out_route (p, vty);
5721
5722 /* Print attribute */
5723 if (attr)
5724 {
5725 if (p->family == AF_INET)
5726 {
5727 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005728 vty_out (vty, "%-16s",
5729 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005730 else
5731 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5732 }
5733#ifdef HAVE_IPV6
5734 else if (p->family == AF_INET6)
5735 {
5736 int len;
5737 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005738
5739 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005740
5741 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005742 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5743 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005744 len = 16 - len;
5745 if (len < 1)
5746 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5747 else
5748 vty_out (vty, "%*s", len, " ");
5749 }
5750#endif /* HAVE_IPV6 */
5751
5752 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5753 vty_out (vty, "%10d", attr->med);
5754 else
5755 vty_out (vty, " ");
5756
5757 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5758 vty_out (vty, "%7d", attr->local_pref);
5759 else
5760 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005761
5762 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5763
Paul Jakmab2518c12006-05-12 23:48:40 +00005764 /* Print aspath */
5765 if (attr->aspath)
5766 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005767
Paul Jakmab2518c12006-05-12 23:48:40 +00005768 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005769 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005770 }
paul718e3742002-12-13 20:15:29 +00005771
5772 vty_out (vty, "%s", VTY_NEWLINE);
5773}
5774
ajs5a646652004-11-05 01:25:55 +00005775void
paul718e3742002-12-13 20:15:29 +00005776route_vty_out_tag (struct vty *vty, struct prefix *p,
5777 struct bgp_info *binfo, int display, safi_t safi)
5778{
5779 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005780 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005781
5782 if (!binfo->extra)
5783 return;
5784
paulb40d9392005-08-22 22:34:41 +00005785 /* short status lead text */
5786 route_vty_short_status_out (vty, binfo);
5787
paul718e3742002-12-13 20:15:29 +00005788 /* print prefix and mask */
5789 if (! display)
5790 route_vty_out_route (p, vty);
5791 else
5792 vty_out (vty, "%*s", 17, " ");
5793
5794 /* Print attribute */
5795 attr = binfo->attr;
5796 if (attr)
5797 {
5798 if (p->family == AF_INET)
5799 {
5800 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005801 vty_out (vty, "%-16s",
5802 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005803 else
5804 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5805 }
5806#ifdef HAVE_IPV6
5807 else if (p->family == AF_INET6)
5808 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005809 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005810 char buf[BUFSIZ];
5811 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005812 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005813 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005814 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5815 buf, BUFSIZ));
5816 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005817 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005818 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5819 buf, BUFSIZ),
5820 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5821 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005822
5823 }
5824#endif /* HAVE_IPV6 */
5825 }
5826
Paul Jakmafb982c22007-05-04 20:15:47 +00005827 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005828
5829 vty_out (vty, "notag/%d", label);
5830
5831 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005832}
5833
5834/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005835static void
paul718e3742002-12-13 20:15:29 +00005836damp_route_vty_out (struct vty *vty, struct prefix *p,
5837 struct bgp_info *binfo, int display, safi_t safi)
5838{
5839 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005840 int len;
5841
paulb40d9392005-08-22 22:34:41 +00005842 /* short status lead text */
5843 route_vty_short_status_out (vty, binfo);
5844
paul718e3742002-12-13 20:15:29 +00005845 /* print prefix and mask */
5846 if (! display)
5847 route_vty_out_route (p, vty);
5848 else
5849 vty_out (vty, "%*s", 17, " ");
5850
5851 len = vty_out (vty, "%s", binfo->peer->host);
5852 len = 17 - len;
5853 if (len < 1)
5854 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5855 else
5856 vty_out (vty, "%*s", len, " ");
5857
5858 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5859
5860 /* Print attribute */
5861 attr = binfo->attr;
5862 if (attr)
5863 {
5864 /* Print aspath */
5865 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005866 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005867
5868 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005869 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005870 }
5871 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005872}
5873
5874#define BGP_UPTIME_LEN 25
5875
5876/* flap route */
ajs5a646652004-11-05 01:25:55 +00005877static void
paul718e3742002-12-13 20:15:29 +00005878flap_route_vty_out (struct vty *vty, struct prefix *p,
5879 struct bgp_info *binfo, int display, safi_t safi)
5880{
5881 struct attr *attr;
5882 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005883 char timebuf[BGP_UPTIME_LEN];
5884 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005885
5886 if (!binfo->extra)
5887 return;
5888
5889 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005890
paulb40d9392005-08-22 22:34:41 +00005891 /* short status lead text */
5892 route_vty_short_status_out (vty, binfo);
5893
paul718e3742002-12-13 20:15:29 +00005894 /* print prefix and mask */
5895 if (! display)
5896 route_vty_out_route (p, vty);
5897 else
5898 vty_out (vty, "%*s", 17, " ");
5899
5900 len = vty_out (vty, "%s", binfo->peer->host);
5901 len = 16 - len;
5902 if (len < 1)
5903 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5904 else
5905 vty_out (vty, "%*s", len, " ");
5906
5907 len = vty_out (vty, "%d", bdi->flap);
5908 len = 5 - len;
5909 if (len < 1)
5910 vty_out (vty, " ");
5911 else
5912 vty_out (vty, "%*s ", len, " ");
5913
5914 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5915 timebuf, BGP_UPTIME_LEN));
5916
5917 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5918 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5919 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5920 else
5921 vty_out (vty, "%*s ", 8, " ");
5922
5923 /* Print attribute */
5924 attr = binfo->attr;
5925 if (attr)
5926 {
5927 /* Print aspath */
5928 if (attr->aspath)
Paul Jakmab2518c12006-05-12 23:48:40 +00005929 aspath_print_vty (vty, "%s ", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005930
5931 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005932 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005933 }
5934 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005935}
5936
paul94f2b392005-06-28 12:44:16 +00005937static void
paul718e3742002-12-13 20:15:29 +00005938route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5939 struct bgp_info *binfo, afi_t afi, safi_t safi)
5940{
5941 char buf[INET6_ADDRSTRLEN];
5942 char buf1[BUFSIZ];
5943 struct attr *attr;
5944 int sockunion_vty_out (struct vty *, union sockunion *);
5945
5946 attr = binfo->attr;
5947
5948 if (attr)
5949 {
5950 /* Line1 display AS-path, Aggregator */
5951 if (attr->aspath)
5952 {
5953 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005954 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005955 vty_out (vty, "Local");
5956 else
Paul Jakmab2518c12006-05-12 23:48:40 +00005957 aspath_print_vty (vty, "%s", attr->aspath);
paul718e3742002-12-13 20:15:29 +00005958 }
5959
paulb40d9392005-08-22 22:34:41 +00005960 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5961 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005962 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5963 vty_out (vty, ", (stale)");
5964 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Paul Jakmafb982c22007-05-04 20:15:47 +00005965 vty_out (vty, ", (aggregated by %d %s)",
5966 attr->extra->aggregator_as,
5967 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005968 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5969 vty_out (vty, ", (Received from a RR-client)");
5970 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5971 vty_out (vty, ", (Received from a RS-client)");
5972 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5973 vty_out (vty, ", (history entry)");
5974 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5975 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005976 vty_out (vty, "%s", VTY_NEWLINE);
5977
5978 /* Line2 display Next-hop, Neighbor, Router-id */
5979 if (p->family == AF_INET)
5980 {
5981 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005982 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005983 inet_ntoa (attr->nexthop));
5984 }
5985#ifdef HAVE_IPV6
5986 else
5987 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005988 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005989 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005990 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005991 buf, INET6_ADDRSTRLEN));
5992 }
5993#endif /* HAVE_IPV6 */
5994
5995 if (binfo->peer == bgp->peer_self)
5996 {
5997 vty_out (vty, " from %s ",
5998 p->family == AF_INET ? "0.0.0.0" : "::");
5999 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
6000 }
6001 else
6002 {
6003 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6004 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006005 else if (binfo->extra && binfo->extra->igpmetric)
6006 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006007 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006008 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006009 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006010 else
6011 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6012 }
6013 vty_out (vty, "%s", VTY_NEWLINE);
6014
6015#ifdef HAVE_IPV6
6016 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006017 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006018 {
6019 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006020 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006021 buf, INET6_ADDRSTRLEN),
6022 VTY_NEWLINE);
6023 }
6024#endif /* HAVE_IPV6 */
6025
6026 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6027 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6028
6029 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6030 vty_out (vty, ", metric %d", attr->med);
6031
6032 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6033 vty_out (vty, ", localpref %d", attr->local_pref);
6034 else
6035 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6036
Paul Jakmafb982c22007-05-04 20:15:47 +00006037 if (attr->extra && attr->extra->weight != 0)
6038 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006039
6040 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6041 vty_out (vty, ", valid");
6042
6043 if (binfo->peer != bgp->peer_self)
6044 {
6045 if (binfo->peer->as == binfo->peer->local_as)
6046 vty_out (vty, ", internal");
6047 else
6048 vty_out (vty, ", %s",
6049 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6050 }
6051 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6052 vty_out (vty, ", aggregated, local");
6053 else if (binfo->type != ZEBRA_ROUTE_BGP)
6054 vty_out (vty, ", sourced");
6055 else
6056 vty_out (vty, ", sourced, local");
6057
6058 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6059 vty_out (vty, ", atomic-aggregate");
6060
6061 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6062 vty_out (vty, ", best");
6063
6064 vty_out (vty, "%s", VTY_NEWLINE);
6065
6066 /* Line 4 display Community */
6067 if (attr->community)
6068 vty_out (vty, " Community: %s%s", attr->community->str,
6069 VTY_NEWLINE);
6070
6071 /* Line 5 display Extended-community */
6072 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006073 vty_out (vty, " Extended Community: %s%s",
6074 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006075
6076 /* Line 6 display Originator, Cluster-id */
6077 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6078 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6079 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006080 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006081 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006082 vty_out (vty, " Originator: %s",
6083 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006084
6085 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6086 {
6087 int i;
6088 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006089 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6090 vty_out (vty, "%s ",
6091 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006092 }
6093 vty_out (vty, "%s", VTY_NEWLINE);
6094 }
Paul Jakma41367172007-08-06 15:24:51 +00006095
6096 /* 7: AS Pathlimit */
6097 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6098 {
6099
6100 vty_out (vty, " AS-Pathlimit: %u",
6101 attr->pathlimit.ttl);
6102 if (attr->pathlimit.as)
6103 vty_out (vty, " (%u)", attr->pathlimit.as);
6104 vty_out (vty, "%s", VTY_NEWLINE);
6105 }
6106
Paul Jakmafb982c22007-05-04 20:15:47 +00006107 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006108 bgp_damp_info_vty (vty, binfo);
6109
6110 /* Line 7 display Uptime */
6111 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
6112 }
6113 vty_out (vty, "%s", VTY_NEWLINE);
6114}
6115
paulb40d9392005-08-22 22:34:41 +00006116#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 +00006117#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006118#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6119#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6120#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6121
6122enum bgp_show_type
6123{
6124 bgp_show_type_normal,
6125 bgp_show_type_regexp,
6126 bgp_show_type_prefix_list,
6127 bgp_show_type_filter_list,
6128 bgp_show_type_route_map,
6129 bgp_show_type_neighbor,
6130 bgp_show_type_cidr_only,
6131 bgp_show_type_prefix_longer,
6132 bgp_show_type_community_all,
6133 bgp_show_type_community,
6134 bgp_show_type_community_exact,
6135 bgp_show_type_community_list,
6136 bgp_show_type_community_list_exact,
6137 bgp_show_type_flap_statistics,
6138 bgp_show_type_flap_address,
6139 bgp_show_type_flap_prefix,
6140 bgp_show_type_flap_cidr_only,
6141 bgp_show_type_flap_regexp,
6142 bgp_show_type_flap_filter_list,
6143 bgp_show_type_flap_prefix_list,
6144 bgp_show_type_flap_prefix_longer,
6145 bgp_show_type_flap_route_map,
6146 bgp_show_type_flap_neighbor,
6147 bgp_show_type_dampend_paths,
6148 bgp_show_type_damp_neighbor
6149};
6150
ajs5a646652004-11-05 01:25:55 +00006151static int
paulfee0f4c2004-09-13 05:12:46 +00006152bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006153 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006154{
paul718e3742002-12-13 20:15:29 +00006155 struct bgp_info *ri;
6156 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006157 int header = 1;
paul718e3742002-12-13 20:15:29 +00006158 int display;
ajs5a646652004-11-05 01:25:55 +00006159 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006160
6161 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006162 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006163
paul718e3742002-12-13 20:15:29 +00006164 /* Start processing of routes. */
6165 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6166 if (rn->info != NULL)
6167 {
6168 display = 0;
6169
6170 for (ri = rn->info; ri; ri = ri->next)
6171 {
ajs5a646652004-11-05 01:25:55 +00006172 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006173 || type == bgp_show_type_flap_address
6174 || type == bgp_show_type_flap_prefix
6175 || type == bgp_show_type_flap_cidr_only
6176 || type == bgp_show_type_flap_regexp
6177 || type == bgp_show_type_flap_filter_list
6178 || type == bgp_show_type_flap_prefix_list
6179 || type == bgp_show_type_flap_prefix_longer
6180 || type == bgp_show_type_flap_route_map
6181 || type == bgp_show_type_flap_neighbor
6182 || type == bgp_show_type_dampend_paths
6183 || type == bgp_show_type_damp_neighbor)
6184 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006185 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006186 continue;
6187 }
6188 if (type == bgp_show_type_regexp
6189 || type == bgp_show_type_flap_regexp)
6190 {
ajs5a646652004-11-05 01:25:55 +00006191 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006192
6193 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6194 continue;
6195 }
6196 if (type == bgp_show_type_prefix_list
6197 || type == bgp_show_type_flap_prefix_list)
6198 {
ajs5a646652004-11-05 01:25:55 +00006199 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006200
6201 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6202 continue;
6203 }
6204 if (type == bgp_show_type_filter_list
6205 || type == bgp_show_type_flap_filter_list)
6206 {
ajs5a646652004-11-05 01:25:55 +00006207 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006208
6209 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6210 continue;
6211 }
6212 if (type == bgp_show_type_route_map
6213 || type == bgp_show_type_flap_route_map)
6214 {
ajs5a646652004-11-05 01:25:55 +00006215 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006216 struct bgp_info binfo;
6217 struct attr dummy_attr;
6218 int ret;
6219
Paul Jakmafb982c22007-05-04 20:15:47 +00006220 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006221 binfo.peer = ri->peer;
6222 binfo.attr = &dummy_attr;
6223
6224 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006225
6226 bgp_attr_extra_free (&dummy_attr);
6227
paul718e3742002-12-13 20:15:29 +00006228 if (ret == RMAP_DENYMATCH)
6229 continue;
6230 }
6231 if (type == bgp_show_type_neighbor
6232 || type == bgp_show_type_flap_neighbor
6233 || type == bgp_show_type_damp_neighbor)
6234 {
ajs5a646652004-11-05 01:25:55 +00006235 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006236
6237 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6238 continue;
6239 }
6240 if (type == bgp_show_type_cidr_only
6241 || type == bgp_show_type_flap_cidr_only)
6242 {
6243 u_int32_t destination;
6244
6245 destination = ntohl (rn->p.u.prefix4.s_addr);
6246 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6247 continue;
6248 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6249 continue;
6250 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6251 continue;
6252 }
6253 if (type == bgp_show_type_prefix_longer
6254 || type == bgp_show_type_flap_prefix_longer)
6255 {
ajs5a646652004-11-05 01:25:55 +00006256 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006257
6258 if (! prefix_match (p, &rn->p))
6259 continue;
6260 }
6261 if (type == bgp_show_type_community_all)
6262 {
6263 if (! ri->attr->community)
6264 continue;
6265 }
6266 if (type == bgp_show_type_community)
6267 {
ajs5a646652004-11-05 01:25:55 +00006268 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006269
6270 if (! ri->attr->community ||
6271 ! community_match (ri->attr->community, com))
6272 continue;
6273 }
6274 if (type == bgp_show_type_community_exact)
6275 {
ajs5a646652004-11-05 01:25:55 +00006276 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006277
6278 if (! ri->attr->community ||
6279 ! community_cmp (ri->attr->community, com))
6280 continue;
6281 }
6282 if (type == bgp_show_type_community_list)
6283 {
ajs5a646652004-11-05 01:25:55 +00006284 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006285
6286 if (! community_list_match (ri->attr->community, list))
6287 continue;
6288 }
6289 if (type == bgp_show_type_community_list_exact)
6290 {
ajs5a646652004-11-05 01:25:55 +00006291 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006292
6293 if (! community_list_exact_match (ri->attr->community, list))
6294 continue;
6295 }
6296 if (type == bgp_show_type_flap_address
6297 || type == bgp_show_type_flap_prefix)
6298 {
ajs5a646652004-11-05 01:25:55 +00006299 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006300
6301 if (! prefix_match (&rn->p, p))
6302 continue;
6303
6304 if (type == bgp_show_type_flap_prefix)
6305 if (p->prefixlen != rn->p.prefixlen)
6306 continue;
6307 }
6308 if (type == bgp_show_type_dampend_paths
6309 || type == bgp_show_type_damp_neighbor)
6310 {
6311 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6312 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6313 continue;
6314 }
6315
6316 if (header)
6317 {
hasso93406d82005-02-02 14:40:33 +00006318 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6319 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6320 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006321 if (type == bgp_show_type_dampend_paths
6322 || type == bgp_show_type_damp_neighbor)
6323 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6324 else if (type == bgp_show_type_flap_statistics
6325 || type == bgp_show_type_flap_address
6326 || type == bgp_show_type_flap_prefix
6327 || type == bgp_show_type_flap_cidr_only
6328 || type == bgp_show_type_flap_regexp
6329 || type == bgp_show_type_flap_filter_list
6330 || type == bgp_show_type_flap_prefix_list
6331 || type == bgp_show_type_flap_prefix_longer
6332 || type == bgp_show_type_flap_route_map
6333 || type == bgp_show_type_flap_neighbor)
6334 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6335 else
6336 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006337 header = 0;
6338 }
6339
6340 if (type == bgp_show_type_dampend_paths
6341 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006342 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006343 else if (type == bgp_show_type_flap_statistics
6344 || type == bgp_show_type_flap_address
6345 || type == bgp_show_type_flap_prefix
6346 || type == bgp_show_type_flap_cidr_only
6347 || type == bgp_show_type_flap_regexp
6348 || type == bgp_show_type_flap_filter_list
6349 || type == bgp_show_type_flap_prefix_list
6350 || type == bgp_show_type_flap_prefix_longer
6351 || type == bgp_show_type_flap_route_map
6352 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006353 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006354 else
ajs5a646652004-11-05 01:25:55 +00006355 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006356 display++;
6357 }
6358 if (display)
ajs5a646652004-11-05 01:25:55 +00006359 output_count++;
paul718e3742002-12-13 20:15:29 +00006360 }
6361
6362 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006363 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006364 {
6365 if (type == bgp_show_type_normal)
6366 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6367 }
6368 else
6369 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006370 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006371
6372 return CMD_SUCCESS;
6373}
6374
ajs5a646652004-11-05 01:25:55 +00006375static int
paulfee0f4c2004-09-13 05:12:46 +00006376bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006377 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006378{
6379 struct bgp_table *table;
6380
6381 if (bgp == NULL) {
6382 bgp = bgp_get_default ();
6383 }
6384
6385 if (bgp == NULL)
6386 {
6387 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6388 return CMD_WARNING;
6389 }
6390
6391
6392 table = bgp->rib[afi][safi];
6393
ajs5a646652004-11-05 01:25:55 +00006394 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006395}
6396
paul718e3742002-12-13 20:15:29 +00006397/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006398static void
paul718e3742002-12-13 20:15:29 +00006399route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6400 struct bgp_node *rn,
6401 struct prefix_rd *prd, afi_t afi, safi_t safi)
6402{
6403 struct bgp_info *ri;
6404 struct prefix *p;
6405 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006406 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006407 char buf1[INET6_ADDRSTRLEN];
6408 char buf2[INET6_ADDRSTRLEN];
6409 int count = 0;
6410 int best = 0;
6411 int suppress = 0;
6412 int no_export = 0;
6413 int no_advertise = 0;
6414 int local_as = 0;
6415 int first = 0;
6416
6417 p = &rn->p;
6418 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6419 (safi == SAFI_MPLS_VPN ?
6420 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6421 safi == SAFI_MPLS_VPN ? ":" : "",
6422 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6423 p->prefixlen, VTY_NEWLINE);
6424
6425 for (ri = rn->info; ri; ri = ri->next)
6426 {
6427 count++;
6428 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6429 {
6430 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006431 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006432 suppress = 1;
6433 if (ri->attr->community != NULL)
6434 {
6435 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6436 no_advertise = 1;
6437 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6438 no_export = 1;
6439 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6440 local_as = 1;
6441 }
6442 }
6443 }
6444
6445 vty_out (vty, "Paths: (%d available", count);
6446 if (best)
6447 {
6448 vty_out (vty, ", best #%d", best);
6449 if (safi == SAFI_UNICAST)
6450 vty_out (vty, ", table Default-IP-Routing-Table");
6451 }
6452 else
6453 vty_out (vty, ", no best path");
6454 if (no_advertise)
6455 vty_out (vty, ", not advertised to any peer");
6456 else if (no_export)
6457 vty_out (vty, ", not advertised to EBGP peer");
6458 else if (local_as)
6459 vty_out (vty, ", not advertised outside local AS");
6460 if (suppress)
6461 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6462 vty_out (vty, ")%s", VTY_NEWLINE);
6463
6464 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006465 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006466 {
6467 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6468 {
6469 if (! first)
6470 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6471 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6472 first = 1;
6473 }
6474 }
6475 if (! first)
6476 vty_out (vty, " Not advertised to any peer");
6477 vty_out (vty, "%s", VTY_NEWLINE);
6478}
6479
6480/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006481static int
paulfee0f4c2004-09-13 05:12:46 +00006482bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006483 struct bgp_table *rib, const char *ip_str,
6484 afi_t afi, safi_t safi, struct prefix_rd *prd,
6485 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006486{
6487 int ret;
6488 int header;
6489 int display = 0;
6490 struct prefix match;
6491 struct bgp_node *rn;
6492 struct bgp_node *rm;
6493 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006494 struct bgp_table *table;
6495
paul718e3742002-12-13 20:15:29 +00006496 /* Check IP address argument. */
6497 ret = str2prefix (ip_str, &match);
6498 if (! ret)
6499 {
6500 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6501 return CMD_WARNING;
6502 }
6503
6504 match.family = afi2family (afi);
6505
6506 if (safi == SAFI_MPLS_VPN)
6507 {
paulfee0f4c2004-09-13 05:12:46 +00006508 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006509 {
6510 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6511 continue;
6512
6513 if ((table = rn->info) != NULL)
6514 {
6515 header = 1;
6516
6517 if ((rm = bgp_node_match (table, &match)) != NULL)
6518 {
6519 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6520 continue;
6521
6522 for (ri = rm->info; ri; ri = ri->next)
6523 {
6524 if (header)
6525 {
6526 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6527 AFI_IP, SAFI_MPLS_VPN);
6528
6529 header = 0;
6530 }
6531 display++;
6532 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6533 }
6534 }
6535 }
6536 }
6537 }
6538 else
6539 {
6540 header = 1;
6541
paulfee0f4c2004-09-13 05:12:46 +00006542 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006543 {
6544 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6545 {
6546 for (ri = rn->info; ri; ri = ri->next)
6547 {
6548 if (header)
6549 {
6550 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6551 header = 0;
6552 }
6553 display++;
6554 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6555 }
6556 }
6557 }
6558 }
6559
6560 if (! display)
6561 {
6562 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6563 return CMD_WARNING;
6564 }
6565
6566 return CMD_SUCCESS;
6567}
6568
paulfee0f4c2004-09-13 05:12:46 +00006569/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006570static int
paulfd79ac92004-10-13 05:06:08 +00006571bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006572 afi_t afi, safi_t safi, struct prefix_rd *prd,
6573 int prefix_check)
6574{
6575 struct bgp *bgp;
6576
6577 /* BGP structure lookup. */
6578 if (view_name)
6579 {
6580 bgp = bgp_lookup_by_name (view_name);
6581 if (bgp == NULL)
6582 {
6583 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6584 return CMD_WARNING;
6585 }
6586 }
6587 else
6588 {
6589 bgp = bgp_get_default ();
6590 if (bgp == NULL)
6591 {
6592 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6593 return CMD_WARNING;
6594 }
6595 }
6596
6597 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6598 afi, safi, prd, prefix_check);
6599}
6600
paul718e3742002-12-13 20:15:29 +00006601/* BGP route print out function. */
6602DEFUN (show_ip_bgp,
6603 show_ip_bgp_cmd,
6604 "show ip bgp",
6605 SHOW_STR
6606 IP_STR
6607 BGP_STR)
6608{
ajs5a646652004-11-05 01:25:55 +00006609 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006610}
6611
6612DEFUN (show_ip_bgp_ipv4,
6613 show_ip_bgp_ipv4_cmd,
6614 "show ip bgp ipv4 (unicast|multicast)",
6615 SHOW_STR
6616 IP_STR
6617 BGP_STR
6618 "Address family\n"
6619 "Address Family modifier\n"
6620 "Address Family modifier\n")
6621{
6622 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006623 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6624 NULL);
paul718e3742002-12-13 20:15:29 +00006625
ajs5a646652004-11-05 01:25:55 +00006626 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006627}
6628
6629DEFUN (show_ip_bgp_route,
6630 show_ip_bgp_route_cmd,
6631 "show ip bgp A.B.C.D",
6632 SHOW_STR
6633 IP_STR
6634 BGP_STR
6635 "Network in the BGP routing table to display\n")
6636{
6637 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6638}
6639
6640DEFUN (show_ip_bgp_ipv4_route,
6641 show_ip_bgp_ipv4_route_cmd,
6642 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6643 SHOW_STR
6644 IP_STR
6645 BGP_STR
6646 "Address family\n"
6647 "Address Family modifier\n"
6648 "Address Family modifier\n"
6649 "Network in the BGP routing table to display\n")
6650{
6651 if (strncmp (argv[0], "m", 1) == 0)
6652 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6653
6654 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6655}
6656
6657DEFUN (show_ip_bgp_vpnv4_all_route,
6658 show_ip_bgp_vpnv4_all_route_cmd,
6659 "show ip bgp vpnv4 all A.B.C.D",
6660 SHOW_STR
6661 IP_STR
6662 BGP_STR
6663 "Display VPNv4 NLRI specific information\n"
6664 "Display information about all VPNv4 NLRIs\n"
6665 "Network in the BGP routing table to display\n")
6666{
6667 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6668}
6669
6670DEFUN (show_ip_bgp_vpnv4_rd_route,
6671 show_ip_bgp_vpnv4_rd_route_cmd,
6672 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6673 SHOW_STR
6674 IP_STR
6675 BGP_STR
6676 "Display VPNv4 NLRI specific information\n"
6677 "Display information for a route distinguisher\n"
6678 "VPN Route Distinguisher\n"
6679 "Network in the BGP routing table to display\n")
6680{
6681 int ret;
6682 struct prefix_rd prd;
6683
6684 ret = str2prefix_rd (argv[0], &prd);
6685 if (! ret)
6686 {
6687 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6688 return CMD_WARNING;
6689 }
6690 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6691}
6692
6693DEFUN (show_ip_bgp_prefix,
6694 show_ip_bgp_prefix_cmd,
6695 "show ip bgp A.B.C.D/M",
6696 SHOW_STR
6697 IP_STR
6698 BGP_STR
6699 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6700{
6701 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6702}
6703
6704DEFUN (show_ip_bgp_ipv4_prefix,
6705 show_ip_bgp_ipv4_prefix_cmd,
6706 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6707 SHOW_STR
6708 IP_STR
6709 BGP_STR
6710 "Address family\n"
6711 "Address Family modifier\n"
6712 "Address Family modifier\n"
6713 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6714{
6715 if (strncmp (argv[0], "m", 1) == 0)
6716 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6717
6718 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6719}
6720
6721DEFUN (show_ip_bgp_vpnv4_all_prefix,
6722 show_ip_bgp_vpnv4_all_prefix_cmd,
6723 "show ip bgp vpnv4 all A.B.C.D/M",
6724 SHOW_STR
6725 IP_STR
6726 BGP_STR
6727 "Display VPNv4 NLRI specific information\n"
6728 "Display information about all VPNv4 NLRIs\n"
6729 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6730{
6731 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6732}
6733
6734DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6735 show_ip_bgp_vpnv4_rd_prefix_cmd,
6736 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6737 SHOW_STR
6738 IP_STR
6739 BGP_STR
6740 "Display VPNv4 NLRI specific information\n"
6741 "Display information for a route distinguisher\n"
6742 "VPN Route Distinguisher\n"
6743 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6744{
6745 int ret;
6746 struct prefix_rd prd;
6747
6748 ret = str2prefix_rd (argv[0], &prd);
6749 if (! ret)
6750 {
6751 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6752 return CMD_WARNING;
6753 }
6754 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6755}
6756
6757DEFUN (show_ip_bgp_view,
6758 show_ip_bgp_view_cmd,
6759 "show ip bgp view WORD",
6760 SHOW_STR
6761 IP_STR
6762 BGP_STR
6763 "BGP view\n"
6764 "BGP view name\n")
6765{
paulbb46e942003-10-24 19:02:03 +00006766 struct bgp *bgp;
6767
6768 /* BGP structure lookup. */
6769 bgp = bgp_lookup_by_name (argv[0]);
6770 if (bgp == NULL)
6771 {
6772 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6773 return CMD_WARNING;
6774 }
6775
ajs5a646652004-11-05 01:25:55 +00006776 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006777}
6778
6779DEFUN (show_ip_bgp_view_route,
6780 show_ip_bgp_view_route_cmd,
6781 "show ip bgp view WORD A.B.C.D",
6782 SHOW_STR
6783 IP_STR
6784 BGP_STR
6785 "BGP view\n"
6786 "BGP view name\n"
6787 "Network in the BGP routing table to display\n")
6788{
6789 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6790}
6791
6792DEFUN (show_ip_bgp_view_prefix,
6793 show_ip_bgp_view_prefix_cmd,
6794 "show ip bgp view WORD A.B.C.D/M",
6795 SHOW_STR
6796 IP_STR
6797 BGP_STR
6798 "BGP view\n"
6799 "BGP view name\n"
6800 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6801{
6802 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6803}
6804
6805#ifdef HAVE_IPV6
6806DEFUN (show_bgp,
6807 show_bgp_cmd,
6808 "show bgp",
6809 SHOW_STR
6810 BGP_STR)
6811{
ajs5a646652004-11-05 01:25:55 +00006812 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6813 NULL);
paul718e3742002-12-13 20:15:29 +00006814}
6815
6816ALIAS (show_bgp,
6817 show_bgp_ipv6_cmd,
6818 "show bgp ipv6",
6819 SHOW_STR
6820 BGP_STR
6821 "Address family\n")
6822
6823/* old command */
6824DEFUN (show_ipv6_bgp,
6825 show_ipv6_bgp_cmd,
6826 "show ipv6 bgp",
6827 SHOW_STR
6828 IP_STR
6829 BGP_STR)
6830{
ajs5a646652004-11-05 01:25:55 +00006831 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6832 NULL);
paul718e3742002-12-13 20:15:29 +00006833}
6834
6835DEFUN (show_bgp_route,
6836 show_bgp_route_cmd,
6837 "show bgp X:X::X:X",
6838 SHOW_STR
6839 BGP_STR
6840 "Network in the BGP routing table to display\n")
6841{
6842 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6843}
6844
6845ALIAS (show_bgp_route,
6846 show_bgp_ipv6_route_cmd,
6847 "show bgp ipv6 X:X::X:X",
6848 SHOW_STR
6849 BGP_STR
6850 "Address family\n"
6851 "Network in the BGP routing table to display\n")
6852
6853/* old command */
6854DEFUN (show_ipv6_bgp_route,
6855 show_ipv6_bgp_route_cmd,
6856 "show ipv6 bgp X:X::X:X",
6857 SHOW_STR
6858 IP_STR
6859 BGP_STR
6860 "Network in the BGP routing table to display\n")
6861{
6862 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6863}
6864
6865DEFUN (show_bgp_prefix,
6866 show_bgp_prefix_cmd,
6867 "show bgp X:X::X:X/M",
6868 SHOW_STR
6869 BGP_STR
6870 "IPv6 prefix <network>/<length>\n")
6871{
6872 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6873}
6874
6875ALIAS (show_bgp_prefix,
6876 show_bgp_ipv6_prefix_cmd,
6877 "show bgp ipv6 X:X::X:X/M",
6878 SHOW_STR
6879 BGP_STR
6880 "Address family\n"
6881 "IPv6 prefix <network>/<length>\n")
6882
6883/* old command */
6884DEFUN (show_ipv6_bgp_prefix,
6885 show_ipv6_bgp_prefix_cmd,
6886 "show ipv6 bgp X:X::X:X/M",
6887 SHOW_STR
6888 IP_STR
6889 BGP_STR
6890 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6891{
6892 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6893}
6894
paulbb46e942003-10-24 19:02:03 +00006895DEFUN (show_bgp_view,
6896 show_bgp_view_cmd,
6897 "show bgp view WORD",
6898 SHOW_STR
6899 BGP_STR
6900 "BGP view\n"
6901 "View name\n")
6902{
6903 struct bgp *bgp;
6904
6905 /* BGP structure lookup. */
6906 bgp = bgp_lookup_by_name (argv[0]);
6907 if (bgp == NULL)
6908 {
6909 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6910 return CMD_WARNING;
6911 }
6912
ajs5a646652004-11-05 01:25:55 +00006913 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006914}
6915
6916ALIAS (show_bgp_view,
6917 show_bgp_view_ipv6_cmd,
6918 "show bgp view WORD ipv6",
6919 SHOW_STR
6920 BGP_STR
6921 "BGP view\n"
6922 "View name\n"
6923 "Address family\n")
6924
6925DEFUN (show_bgp_view_route,
6926 show_bgp_view_route_cmd,
6927 "show bgp view WORD X:X::X:X",
6928 SHOW_STR
6929 BGP_STR
6930 "BGP view\n"
6931 "View name\n"
6932 "Network in the BGP routing table to display\n")
6933{
6934 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6935}
6936
6937ALIAS (show_bgp_view_route,
6938 show_bgp_view_ipv6_route_cmd,
6939 "show bgp view WORD ipv6 X:X::X:X",
6940 SHOW_STR
6941 BGP_STR
6942 "BGP view\n"
6943 "View name\n"
6944 "Address family\n"
6945 "Network in the BGP routing table to display\n")
6946
6947DEFUN (show_bgp_view_prefix,
6948 show_bgp_view_prefix_cmd,
6949 "show bgp view WORD X:X::X:X/M",
6950 SHOW_STR
6951 BGP_STR
6952 "BGP view\n"
6953 "View name\n"
6954 "IPv6 prefix <network>/<length>\n")
6955{
6956 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6957}
6958
6959ALIAS (show_bgp_view_prefix,
6960 show_bgp_view_ipv6_prefix_cmd,
6961 "show bgp view WORD ipv6 X:X::X:X/M",
6962 SHOW_STR
6963 BGP_STR
6964 "BGP view\n"
6965 "View name\n"
6966 "Address family\n"
6967 "IPv6 prefix <network>/<length>\n")
6968
paul718e3742002-12-13 20:15:29 +00006969/* old command */
6970DEFUN (show_ipv6_mbgp,
6971 show_ipv6_mbgp_cmd,
6972 "show ipv6 mbgp",
6973 SHOW_STR
6974 IP_STR
6975 MBGP_STR)
6976{
ajs5a646652004-11-05 01:25:55 +00006977 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6978 NULL);
paul718e3742002-12-13 20:15:29 +00006979}
6980
6981/* old command */
6982DEFUN (show_ipv6_mbgp_route,
6983 show_ipv6_mbgp_route_cmd,
6984 "show ipv6 mbgp X:X::X:X",
6985 SHOW_STR
6986 IP_STR
6987 MBGP_STR
6988 "Network in the MBGP routing table to display\n")
6989{
6990 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6991}
6992
6993/* old command */
6994DEFUN (show_ipv6_mbgp_prefix,
6995 show_ipv6_mbgp_prefix_cmd,
6996 "show ipv6 mbgp X:X::X:X/M",
6997 SHOW_STR
6998 IP_STR
6999 MBGP_STR
7000 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7001{
7002 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7003}
7004#endif
7005
paul718e3742002-12-13 20:15:29 +00007006
paul94f2b392005-06-28 12:44:16 +00007007static int
paulfd79ac92004-10-13 05:06:08 +00007008bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007009 safi_t safi, enum bgp_show_type type)
7010{
7011 int i;
7012 struct buffer *b;
7013 char *regstr;
7014 int first;
7015 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007016 int rc;
paul718e3742002-12-13 20:15:29 +00007017
7018 first = 0;
7019 b = buffer_new (1024);
7020 for (i = 0; i < argc; i++)
7021 {
7022 if (first)
7023 buffer_putc (b, ' ');
7024 else
7025 {
7026 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7027 continue;
7028 first = 1;
7029 }
7030
7031 buffer_putstr (b, argv[i]);
7032 }
7033 buffer_putc (b, '\0');
7034
7035 regstr = buffer_getstr (b);
7036 buffer_free (b);
7037
7038 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007039 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007040 if (! regex)
7041 {
7042 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7043 VTY_NEWLINE);
7044 return CMD_WARNING;
7045 }
7046
ajs5a646652004-11-05 01:25:55 +00007047 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7048 bgp_regex_free (regex);
7049 return rc;
paul718e3742002-12-13 20:15:29 +00007050}
7051
7052DEFUN (show_ip_bgp_regexp,
7053 show_ip_bgp_regexp_cmd,
7054 "show ip bgp regexp .LINE",
7055 SHOW_STR
7056 IP_STR
7057 BGP_STR
7058 "Display routes matching the AS path regular expression\n"
7059 "A regular-expression to match the BGP AS paths\n")
7060{
7061 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7062 bgp_show_type_regexp);
7063}
7064
7065DEFUN (show_ip_bgp_flap_regexp,
7066 show_ip_bgp_flap_regexp_cmd,
7067 "show ip bgp flap-statistics regexp .LINE",
7068 SHOW_STR
7069 IP_STR
7070 BGP_STR
7071 "Display flap statistics of routes\n"
7072 "Display routes matching the AS path regular expression\n"
7073 "A regular-expression to match the BGP AS paths\n")
7074{
7075 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7076 bgp_show_type_flap_regexp);
7077}
7078
7079DEFUN (show_ip_bgp_ipv4_regexp,
7080 show_ip_bgp_ipv4_regexp_cmd,
7081 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7082 SHOW_STR
7083 IP_STR
7084 BGP_STR
7085 "Address family\n"
7086 "Address Family modifier\n"
7087 "Address Family modifier\n"
7088 "Display routes matching the AS path regular expression\n"
7089 "A regular-expression to match the BGP AS paths\n")
7090{
7091 if (strncmp (argv[0], "m", 1) == 0)
7092 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7093 bgp_show_type_regexp);
7094
7095 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7096 bgp_show_type_regexp);
7097}
7098
7099#ifdef HAVE_IPV6
7100DEFUN (show_bgp_regexp,
7101 show_bgp_regexp_cmd,
7102 "show bgp regexp .LINE",
7103 SHOW_STR
7104 BGP_STR
7105 "Display routes matching the AS path regular expression\n"
7106 "A regular-expression to match the BGP AS paths\n")
7107{
7108 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7109 bgp_show_type_regexp);
7110}
7111
7112ALIAS (show_bgp_regexp,
7113 show_bgp_ipv6_regexp_cmd,
7114 "show bgp ipv6 regexp .LINE",
7115 SHOW_STR
7116 BGP_STR
7117 "Address family\n"
7118 "Display routes matching the AS path regular expression\n"
7119 "A regular-expression to match the BGP AS paths\n")
7120
7121/* old command */
7122DEFUN (show_ipv6_bgp_regexp,
7123 show_ipv6_bgp_regexp_cmd,
7124 "show ipv6 bgp regexp .LINE",
7125 SHOW_STR
7126 IP_STR
7127 BGP_STR
7128 "Display routes matching the AS path regular expression\n"
7129 "A regular-expression to match the BGP AS paths\n")
7130{
7131 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7132 bgp_show_type_regexp);
7133}
7134
7135/* old command */
7136DEFUN (show_ipv6_mbgp_regexp,
7137 show_ipv6_mbgp_regexp_cmd,
7138 "show ipv6 mbgp regexp .LINE",
7139 SHOW_STR
7140 IP_STR
7141 BGP_STR
7142 "Display routes matching the AS path regular expression\n"
7143 "A regular-expression to match the MBGP AS paths\n")
7144{
7145 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7146 bgp_show_type_regexp);
7147}
7148#endif /* HAVE_IPV6 */
7149
paul94f2b392005-06-28 12:44:16 +00007150static int
paulfd79ac92004-10-13 05:06:08 +00007151bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007152 safi_t safi, enum bgp_show_type type)
7153{
7154 struct prefix_list *plist;
7155
7156 plist = prefix_list_lookup (afi, prefix_list_str);
7157 if (plist == NULL)
7158 {
7159 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7160 prefix_list_str, VTY_NEWLINE);
7161 return CMD_WARNING;
7162 }
7163
ajs5a646652004-11-05 01:25:55 +00007164 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007165}
7166
7167DEFUN (show_ip_bgp_prefix_list,
7168 show_ip_bgp_prefix_list_cmd,
7169 "show ip bgp prefix-list WORD",
7170 SHOW_STR
7171 IP_STR
7172 BGP_STR
7173 "Display routes conforming to the prefix-list\n"
7174 "IP prefix-list name\n")
7175{
7176 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7177 bgp_show_type_prefix_list);
7178}
7179
7180DEFUN (show_ip_bgp_flap_prefix_list,
7181 show_ip_bgp_flap_prefix_list_cmd,
7182 "show ip bgp flap-statistics prefix-list WORD",
7183 SHOW_STR
7184 IP_STR
7185 BGP_STR
7186 "Display flap statistics of routes\n"
7187 "Display routes conforming to the prefix-list\n"
7188 "IP prefix-list name\n")
7189{
7190 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7191 bgp_show_type_flap_prefix_list);
7192}
7193
7194DEFUN (show_ip_bgp_ipv4_prefix_list,
7195 show_ip_bgp_ipv4_prefix_list_cmd,
7196 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7197 SHOW_STR
7198 IP_STR
7199 BGP_STR
7200 "Address family\n"
7201 "Address Family modifier\n"
7202 "Address Family modifier\n"
7203 "Display routes conforming to the prefix-list\n"
7204 "IP prefix-list name\n")
7205{
7206 if (strncmp (argv[0], "m", 1) == 0)
7207 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7208 bgp_show_type_prefix_list);
7209
7210 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7211 bgp_show_type_prefix_list);
7212}
7213
7214#ifdef HAVE_IPV6
7215DEFUN (show_bgp_prefix_list,
7216 show_bgp_prefix_list_cmd,
7217 "show bgp prefix-list WORD",
7218 SHOW_STR
7219 BGP_STR
7220 "Display routes conforming to the prefix-list\n"
7221 "IPv6 prefix-list name\n")
7222{
7223 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7224 bgp_show_type_prefix_list);
7225}
7226
7227ALIAS (show_bgp_prefix_list,
7228 show_bgp_ipv6_prefix_list_cmd,
7229 "show bgp ipv6 prefix-list WORD",
7230 SHOW_STR
7231 BGP_STR
7232 "Address family\n"
7233 "Display routes conforming to the prefix-list\n"
7234 "IPv6 prefix-list name\n")
7235
7236/* old command */
7237DEFUN (show_ipv6_bgp_prefix_list,
7238 show_ipv6_bgp_prefix_list_cmd,
7239 "show ipv6 bgp prefix-list WORD",
7240 SHOW_STR
7241 IPV6_STR
7242 BGP_STR
7243 "Display routes matching the prefix-list\n"
7244 "IPv6 prefix-list name\n")
7245{
7246 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7247 bgp_show_type_prefix_list);
7248}
7249
7250/* old command */
7251DEFUN (show_ipv6_mbgp_prefix_list,
7252 show_ipv6_mbgp_prefix_list_cmd,
7253 "show ipv6 mbgp prefix-list WORD",
7254 SHOW_STR
7255 IPV6_STR
7256 MBGP_STR
7257 "Display routes matching the prefix-list\n"
7258 "IPv6 prefix-list name\n")
7259{
7260 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7261 bgp_show_type_prefix_list);
7262}
7263#endif /* HAVE_IPV6 */
7264
paul94f2b392005-06-28 12:44:16 +00007265static int
paulfd79ac92004-10-13 05:06:08 +00007266bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007267 safi_t safi, enum bgp_show_type type)
7268{
7269 struct as_list *as_list;
7270
7271 as_list = as_list_lookup (filter);
7272 if (as_list == NULL)
7273 {
7274 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7275 return CMD_WARNING;
7276 }
7277
ajs5a646652004-11-05 01:25:55 +00007278 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007279}
7280
7281DEFUN (show_ip_bgp_filter_list,
7282 show_ip_bgp_filter_list_cmd,
7283 "show ip bgp filter-list WORD",
7284 SHOW_STR
7285 IP_STR
7286 BGP_STR
7287 "Display routes conforming to the filter-list\n"
7288 "Regular expression access list name\n")
7289{
7290 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7291 bgp_show_type_filter_list);
7292}
7293
7294DEFUN (show_ip_bgp_flap_filter_list,
7295 show_ip_bgp_flap_filter_list_cmd,
7296 "show ip bgp flap-statistics filter-list WORD",
7297 SHOW_STR
7298 IP_STR
7299 BGP_STR
7300 "Display flap statistics of routes\n"
7301 "Display routes conforming to the filter-list\n"
7302 "Regular expression access list name\n")
7303{
7304 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7305 bgp_show_type_flap_filter_list);
7306}
7307
7308DEFUN (show_ip_bgp_ipv4_filter_list,
7309 show_ip_bgp_ipv4_filter_list_cmd,
7310 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7311 SHOW_STR
7312 IP_STR
7313 BGP_STR
7314 "Address family\n"
7315 "Address Family modifier\n"
7316 "Address Family modifier\n"
7317 "Display routes conforming to the filter-list\n"
7318 "Regular expression access list name\n")
7319{
7320 if (strncmp (argv[0], "m", 1) == 0)
7321 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7322 bgp_show_type_filter_list);
7323
7324 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7325 bgp_show_type_filter_list);
7326}
7327
7328#ifdef HAVE_IPV6
7329DEFUN (show_bgp_filter_list,
7330 show_bgp_filter_list_cmd,
7331 "show bgp filter-list WORD",
7332 SHOW_STR
7333 BGP_STR
7334 "Display routes conforming to the filter-list\n"
7335 "Regular expression access list name\n")
7336{
7337 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7338 bgp_show_type_filter_list);
7339}
7340
7341ALIAS (show_bgp_filter_list,
7342 show_bgp_ipv6_filter_list_cmd,
7343 "show bgp ipv6 filter-list WORD",
7344 SHOW_STR
7345 BGP_STR
7346 "Address family\n"
7347 "Display routes conforming to the filter-list\n"
7348 "Regular expression access list name\n")
7349
7350/* old command */
7351DEFUN (show_ipv6_bgp_filter_list,
7352 show_ipv6_bgp_filter_list_cmd,
7353 "show ipv6 bgp filter-list WORD",
7354 SHOW_STR
7355 IPV6_STR
7356 BGP_STR
7357 "Display routes conforming to the filter-list\n"
7358 "Regular expression access list name\n")
7359{
7360 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7361 bgp_show_type_filter_list);
7362}
7363
7364/* old command */
7365DEFUN (show_ipv6_mbgp_filter_list,
7366 show_ipv6_mbgp_filter_list_cmd,
7367 "show ipv6 mbgp filter-list WORD",
7368 SHOW_STR
7369 IPV6_STR
7370 MBGP_STR
7371 "Display routes conforming to the filter-list\n"
7372 "Regular expression access list name\n")
7373{
7374 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7375 bgp_show_type_filter_list);
7376}
7377#endif /* HAVE_IPV6 */
7378
paul94f2b392005-06-28 12:44:16 +00007379static int
paulfd79ac92004-10-13 05:06:08 +00007380bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007381 safi_t safi, enum bgp_show_type type)
7382{
7383 struct route_map *rmap;
7384
7385 rmap = route_map_lookup_by_name (rmap_str);
7386 if (! rmap)
7387 {
7388 vty_out (vty, "%% %s is not a valid route-map name%s",
7389 rmap_str, VTY_NEWLINE);
7390 return CMD_WARNING;
7391 }
7392
ajs5a646652004-11-05 01:25:55 +00007393 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007394}
7395
7396DEFUN (show_ip_bgp_route_map,
7397 show_ip_bgp_route_map_cmd,
7398 "show ip bgp route-map WORD",
7399 SHOW_STR
7400 IP_STR
7401 BGP_STR
7402 "Display routes matching the route-map\n"
7403 "A route-map to match on\n")
7404{
7405 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7406 bgp_show_type_route_map);
7407}
7408
7409DEFUN (show_ip_bgp_flap_route_map,
7410 show_ip_bgp_flap_route_map_cmd,
7411 "show ip bgp flap-statistics route-map WORD",
7412 SHOW_STR
7413 IP_STR
7414 BGP_STR
7415 "Display flap statistics of routes\n"
7416 "Display routes matching the route-map\n"
7417 "A route-map to match on\n")
7418{
7419 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7420 bgp_show_type_flap_route_map);
7421}
7422
7423DEFUN (show_ip_bgp_ipv4_route_map,
7424 show_ip_bgp_ipv4_route_map_cmd,
7425 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7426 SHOW_STR
7427 IP_STR
7428 BGP_STR
7429 "Address family\n"
7430 "Address Family modifier\n"
7431 "Address Family modifier\n"
7432 "Display routes matching the route-map\n"
7433 "A route-map to match on\n")
7434{
7435 if (strncmp (argv[0], "m", 1) == 0)
7436 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7437 bgp_show_type_route_map);
7438
7439 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7440 bgp_show_type_route_map);
7441}
7442
7443DEFUN (show_bgp_route_map,
7444 show_bgp_route_map_cmd,
7445 "show bgp route-map WORD",
7446 SHOW_STR
7447 BGP_STR
7448 "Display routes matching the route-map\n"
7449 "A route-map to match on\n")
7450{
7451 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7452 bgp_show_type_route_map);
7453}
7454
7455ALIAS (show_bgp_route_map,
7456 show_bgp_ipv6_route_map_cmd,
7457 "show bgp ipv6 route-map WORD",
7458 SHOW_STR
7459 BGP_STR
7460 "Address family\n"
7461 "Display routes matching the route-map\n"
7462 "A route-map to match on\n")
7463
7464DEFUN (show_ip_bgp_cidr_only,
7465 show_ip_bgp_cidr_only_cmd,
7466 "show ip bgp cidr-only",
7467 SHOW_STR
7468 IP_STR
7469 BGP_STR
7470 "Display only routes with non-natural netmasks\n")
7471{
7472 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007473 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007474}
7475
7476DEFUN (show_ip_bgp_flap_cidr_only,
7477 show_ip_bgp_flap_cidr_only_cmd,
7478 "show ip bgp flap-statistics cidr-only",
7479 SHOW_STR
7480 IP_STR
7481 BGP_STR
7482 "Display flap statistics of routes\n"
7483 "Display only routes with non-natural netmasks\n")
7484{
7485 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007486 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007487}
7488
7489DEFUN (show_ip_bgp_ipv4_cidr_only,
7490 show_ip_bgp_ipv4_cidr_only_cmd,
7491 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7492 SHOW_STR
7493 IP_STR
7494 BGP_STR
7495 "Address family\n"
7496 "Address Family modifier\n"
7497 "Address Family modifier\n"
7498 "Display only routes with non-natural netmasks\n")
7499{
7500 if (strncmp (argv[0], "m", 1) == 0)
7501 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007502 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007503
7504 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007505 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007506}
7507
7508DEFUN (show_ip_bgp_community_all,
7509 show_ip_bgp_community_all_cmd,
7510 "show ip bgp community",
7511 SHOW_STR
7512 IP_STR
7513 BGP_STR
7514 "Display routes matching the communities\n")
7515{
7516 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007517 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007518}
7519
7520DEFUN (show_ip_bgp_ipv4_community_all,
7521 show_ip_bgp_ipv4_community_all_cmd,
7522 "show ip bgp ipv4 (unicast|multicast) community",
7523 SHOW_STR
7524 IP_STR
7525 BGP_STR
7526 "Address family\n"
7527 "Address Family modifier\n"
7528 "Address Family modifier\n"
7529 "Display routes matching the communities\n")
7530{
7531 if (strncmp (argv[0], "m", 1) == 0)
7532 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007533 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007534
7535 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007536 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007537}
7538
7539#ifdef HAVE_IPV6
7540DEFUN (show_bgp_community_all,
7541 show_bgp_community_all_cmd,
7542 "show bgp community",
7543 SHOW_STR
7544 BGP_STR
7545 "Display routes matching the communities\n")
7546{
7547 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007548 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007549}
7550
7551ALIAS (show_bgp_community_all,
7552 show_bgp_ipv6_community_all_cmd,
7553 "show bgp ipv6 community",
7554 SHOW_STR
7555 BGP_STR
7556 "Address family\n"
7557 "Display routes matching the communities\n")
7558
7559/* old command */
7560DEFUN (show_ipv6_bgp_community_all,
7561 show_ipv6_bgp_community_all_cmd,
7562 "show ipv6 bgp community",
7563 SHOW_STR
7564 IPV6_STR
7565 BGP_STR
7566 "Display routes matching the communities\n")
7567{
7568 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007569 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007570}
7571
7572/* old command */
7573DEFUN (show_ipv6_mbgp_community_all,
7574 show_ipv6_mbgp_community_all_cmd,
7575 "show ipv6 mbgp community",
7576 SHOW_STR
7577 IPV6_STR
7578 MBGP_STR
7579 "Display routes matching the communities\n")
7580{
7581 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007582 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007583}
7584#endif /* HAVE_IPV6 */
7585
paul94f2b392005-06-28 12:44:16 +00007586static int
paulfd79ac92004-10-13 05:06:08 +00007587bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7588 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007589{
7590 struct community *com;
7591 struct buffer *b;
7592 int i;
7593 char *str;
7594 int first = 0;
7595
7596 b = buffer_new (1024);
7597 for (i = 0; i < argc; i++)
7598 {
7599 if (first)
7600 buffer_putc (b, ' ');
7601 else
7602 {
7603 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7604 continue;
7605 first = 1;
7606 }
7607
7608 buffer_putstr (b, argv[i]);
7609 }
7610 buffer_putc (b, '\0');
7611
7612 str = buffer_getstr (b);
7613 buffer_free (b);
7614
7615 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007616 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007617 if (! com)
7618 {
7619 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7620 return CMD_WARNING;
7621 }
7622
ajs5a646652004-11-05 01:25:55 +00007623 return bgp_show (vty, NULL, afi, safi,
7624 (exact ? bgp_show_type_community_exact :
7625 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007626}
7627
7628DEFUN (show_ip_bgp_community,
7629 show_ip_bgp_community_cmd,
7630 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7631 SHOW_STR
7632 IP_STR
7633 BGP_STR
7634 "Display routes matching the communities\n"
7635 "community number\n"
7636 "Do not send outside local AS (well-known community)\n"
7637 "Do not advertise to any peer (well-known community)\n"
7638 "Do not export to next AS (well-known community)\n")
7639{
7640 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7641}
7642
7643ALIAS (show_ip_bgp_community,
7644 show_ip_bgp_community2_cmd,
7645 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7646 SHOW_STR
7647 IP_STR
7648 BGP_STR
7649 "Display routes matching the communities\n"
7650 "community number\n"
7651 "Do not send outside local AS (well-known community)\n"
7652 "Do not advertise to any peer (well-known community)\n"
7653 "Do not export to next AS (well-known community)\n"
7654 "community number\n"
7655 "Do not send outside local AS (well-known community)\n"
7656 "Do not advertise to any peer (well-known community)\n"
7657 "Do not export to next AS (well-known community)\n")
7658
7659ALIAS (show_ip_bgp_community,
7660 show_ip_bgp_community3_cmd,
7661 "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)",
7662 SHOW_STR
7663 IP_STR
7664 BGP_STR
7665 "Display routes matching the communities\n"
7666 "community number\n"
7667 "Do not send outside local AS (well-known community)\n"
7668 "Do not advertise to any peer (well-known community)\n"
7669 "Do not export to next AS (well-known community)\n"
7670 "community number\n"
7671 "Do not send outside local AS (well-known community)\n"
7672 "Do not advertise to any peer (well-known community)\n"
7673 "Do not export to next AS (well-known community)\n"
7674 "community number\n"
7675 "Do not send outside local AS (well-known community)\n"
7676 "Do not advertise to any peer (well-known community)\n"
7677 "Do not export to next AS (well-known community)\n")
7678
7679ALIAS (show_ip_bgp_community,
7680 show_ip_bgp_community4_cmd,
7681 "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)",
7682 SHOW_STR
7683 IP_STR
7684 BGP_STR
7685 "Display routes matching the communities\n"
7686 "community number\n"
7687 "Do not send outside local AS (well-known community)\n"
7688 "Do not advertise to any peer (well-known community)\n"
7689 "Do not export to next AS (well-known community)\n"
7690 "community number\n"
7691 "Do not send outside local AS (well-known community)\n"
7692 "Do not advertise to any peer (well-known community)\n"
7693 "Do not export to next AS (well-known community)\n"
7694 "community number\n"
7695 "Do not send outside local AS (well-known community)\n"
7696 "Do not advertise to any peer (well-known community)\n"
7697 "Do not export to next AS (well-known community)\n"
7698 "community number\n"
7699 "Do not send outside local AS (well-known community)\n"
7700 "Do not advertise to any peer (well-known community)\n"
7701 "Do not export to next AS (well-known community)\n")
7702
7703DEFUN (show_ip_bgp_ipv4_community,
7704 show_ip_bgp_ipv4_community_cmd,
7705 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7706 SHOW_STR
7707 IP_STR
7708 BGP_STR
7709 "Address family\n"
7710 "Address Family modifier\n"
7711 "Address Family modifier\n"
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{
7718 if (strncmp (argv[0], "m", 1) == 0)
7719 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7720
7721 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7722}
7723
7724ALIAS (show_ip_bgp_ipv4_community,
7725 show_ip_bgp_ipv4_community2_cmd,
7726 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7727 SHOW_STR
7728 IP_STR
7729 BGP_STR
7730 "Address family\n"
7731 "Address Family modifier\n"
7732 "Address Family modifier\n"
7733 "Display routes matching the communities\n"
7734 "community number\n"
7735 "Do not send outside local AS (well-known community)\n"
7736 "Do not advertise to any peer (well-known community)\n"
7737 "Do not export to next AS (well-known community)\n"
7738 "community number\n"
7739 "Do not send outside local AS (well-known community)\n"
7740 "Do not advertise to any peer (well-known community)\n"
7741 "Do not export to next AS (well-known community)\n")
7742
7743ALIAS (show_ip_bgp_ipv4_community,
7744 show_ip_bgp_ipv4_community3_cmd,
7745 "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)",
7746 SHOW_STR
7747 IP_STR
7748 BGP_STR
7749 "Address family\n"
7750 "Address Family modifier\n"
7751 "Address Family modifier\n"
7752 "Display routes matching the communities\n"
7753 "community number\n"
7754 "Do not send outside local AS (well-known community)\n"
7755 "Do not advertise to any peer (well-known community)\n"
7756 "Do not export to next AS (well-known community)\n"
7757 "community number\n"
7758 "Do not send outside local AS (well-known community)\n"
7759 "Do not advertise to any peer (well-known community)\n"
7760 "Do not export to next AS (well-known community)\n"
7761 "community number\n"
7762 "Do not send outside local AS (well-known community)\n"
7763 "Do not advertise to any peer (well-known community)\n"
7764 "Do not export to next AS (well-known community)\n")
7765
7766ALIAS (show_ip_bgp_ipv4_community,
7767 show_ip_bgp_ipv4_community4_cmd,
7768 "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)",
7769 SHOW_STR
7770 IP_STR
7771 BGP_STR
7772 "Address family\n"
7773 "Address Family modifier\n"
7774 "Address Family modifier\n"
7775 "Display routes matching the communities\n"
7776 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n"
7780 "community number\n"
7781 "Do not send outside local AS (well-known community)\n"
7782 "Do not advertise to any peer (well-known community)\n"
7783 "Do not export to next AS (well-known community)\n"
7784 "community number\n"
7785 "Do not send outside local AS (well-known community)\n"
7786 "Do not advertise to any peer (well-known community)\n"
7787 "Do not export to next AS (well-known community)\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n")
7792
7793DEFUN (show_ip_bgp_community_exact,
7794 show_ip_bgp_community_exact_cmd,
7795 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7796 SHOW_STR
7797 IP_STR
7798 BGP_STR
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 "Exact match of the communities")
7805{
7806 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7807}
7808
7809ALIAS (show_ip_bgp_community_exact,
7810 show_ip_bgp_community2_exact_cmd,
7811 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7812 SHOW_STR
7813 IP_STR
7814 BGP_STR
7815 "Display routes matching the communities\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n"
7824 "Exact match of the communities")
7825
7826ALIAS (show_ip_bgp_community_exact,
7827 show_ip_bgp_community3_exact_cmd,
7828 "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",
7829 SHOW_STR
7830 IP_STR
7831 BGP_STR
7832 "Display routes matching the communities\n"
7833 "community number\n"
7834 "Do not send outside local AS (well-known community)\n"
7835 "Do not advertise to any peer (well-known community)\n"
7836 "Do not export to next AS (well-known community)\n"
7837 "community number\n"
7838 "Do not send outside local AS (well-known community)\n"
7839 "Do not advertise to any peer (well-known community)\n"
7840 "Do not export to next AS (well-known community)\n"
7841 "community number\n"
7842 "Do not send outside local AS (well-known community)\n"
7843 "Do not advertise to any peer (well-known community)\n"
7844 "Do not export to next AS (well-known community)\n"
7845 "Exact match of the communities")
7846
7847ALIAS (show_ip_bgp_community_exact,
7848 show_ip_bgp_community4_exact_cmd,
7849 "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",
7850 SHOW_STR
7851 IP_STR
7852 BGP_STR
7853 "Display routes matching the communities\n"
7854 "community number\n"
7855 "Do not send outside local AS (well-known community)\n"
7856 "Do not advertise to any peer (well-known community)\n"
7857 "Do not export to next AS (well-known community)\n"
7858 "community number\n"
7859 "Do not send outside local AS (well-known community)\n"
7860 "Do not advertise to any peer (well-known community)\n"
7861 "Do not export to next AS (well-known community)\n"
7862 "community number\n"
7863 "Do not send outside local AS (well-known community)\n"
7864 "Do not advertise to any peer (well-known community)\n"
7865 "Do not export to next AS (well-known community)\n"
7866 "community number\n"
7867 "Do not send outside local AS (well-known community)\n"
7868 "Do not advertise to any peer (well-known community)\n"
7869 "Do not export to next AS (well-known community)\n"
7870 "Exact match of the communities")
7871
7872DEFUN (show_ip_bgp_ipv4_community_exact,
7873 show_ip_bgp_ipv4_community_exact_cmd,
7874 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7875 SHOW_STR
7876 IP_STR
7877 BGP_STR
7878 "Address family\n"
7879 "Address Family modifier\n"
7880 "Address Family modifier\n"
7881 "Display routes matching the communities\n"
7882 "community number\n"
7883 "Do not send outside local AS (well-known community)\n"
7884 "Do not advertise to any peer (well-known community)\n"
7885 "Do not export to next AS (well-known community)\n"
7886 "Exact match of the communities")
7887{
7888 if (strncmp (argv[0], "m", 1) == 0)
7889 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7890
7891 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7892}
7893
7894ALIAS (show_ip_bgp_ipv4_community_exact,
7895 show_ip_bgp_ipv4_community2_exact_cmd,
7896 "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",
7897 SHOW_STR
7898 IP_STR
7899 BGP_STR
7900 "Address family\n"
7901 "Address Family modifier\n"
7902 "Address Family modifier\n"
7903 "Display routes matching the communities\n"
7904 "community number\n"
7905 "Do not send outside local AS (well-known community)\n"
7906 "Do not advertise to any peer (well-known community)\n"
7907 "Do not export to next AS (well-known community)\n"
7908 "community number\n"
7909 "Do not send outside local AS (well-known community)\n"
7910 "Do not advertise to any peer (well-known community)\n"
7911 "Do not export to next AS (well-known community)\n"
7912 "Exact match of the communities")
7913
7914ALIAS (show_ip_bgp_ipv4_community_exact,
7915 show_ip_bgp_ipv4_community3_exact_cmd,
7916 "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",
7917 SHOW_STR
7918 IP_STR
7919 BGP_STR
7920 "Address family\n"
7921 "Address Family modifier\n"
7922 "Address Family modifier\n"
7923 "Display routes matching the communities\n"
7924 "community number\n"
7925 "Do not send outside local AS (well-known community)\n"
7926 "Do not advertise to any peer (well-known community)\n"
7927 "Do not export to next AS (well-known community)\n"
7928 "community number\n"
7929 "Do not send outside local AS (well-known community)\n"
7930 "Do not advertise to any peer (well-known community)\n"
7931 "Do not export to next AS (well-known community)\n"
7932 "community number\n"
7933 "Do not send outside local AS (well-known community)\n"
7934 "Do not advertise to any peer (well-known community)\n"
7935 "Do not export to next AS (well-known community)\n"
7936 "Exact match of the communities")
7937
7938ALIAS (show_ip_bgp_ipv4_community_exact,
7939 show_ip_bgp_ipv4_community4_exact_cmd,
7940 "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",
7941 SHOW_STR
7942 IP_STR
7943 BGP_STR
7944 "Address family\n"
7945 "Address Family modifier\n"
7946 "Address Family modifier\n"
7947 "Display routes matching the communities\n"
7948 "community number\n"
7949 "Do not send outside local AS (well-known community)\n"
7950 "Do not advertise to any peer (well-known community)\n"
7951 "Do not export to next AS (well-known community)\n"
7952 "community number\n"
7953 "Do not send outside local AS (well-known community)\n"
7954 "Do not advertise to any peer (well-known community)\n"
7955 "Do not export to next AS (well-known community)\n"
7956 "community number\n"
7957 "Do not send outside local AS (well-known community)\n"
7958 "Do not advertise to any peer (well-known community)\n"
7959 "Do not export to next AS (well-known community)\n"
7960 "community number\n"
7961 "Do not send outside local AS (well-known community)\n"
7962 "Do not advertise to any peer (well-known community)\n"
7963 "Do not export to next AS (well-known community)\n"
7964 "Exact match of the communities")
7965
7966#ifdef HAVE_IPV6
7967DEFUN (show_bgp_community,
7968 show_bgp_community_cmd,
7969 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7970 SHOW_STR
7971 BGP_STR
7972 "Display routes matching the communities\n"
7973 "community number\n"
7974 "Do not send outside local AS (well-known community)\n"
7975 "Do not advertise to any peer (well-known community)\n"
7976 "Do not export to next AS (well-known community)\n")
7977{
7978 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7979}
7980
7981ALIAS (show_bgp_community,
7982 show_bgp_ipv6_community_cmd,
7983 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7984 SHOW_STR
7985 BGP_STR
7986 "Address family\n"
7987 "Display routes matching the communities\n"
7988 "community number\n"
7989 "Do not send outside local AS (well-known community)\n"
7990 "Do not advertise to any peer (well-known community)\n"
7991 "Do not export to next AS (well-known community)\n")
7992
7993ALIAS (show_bgp_community,
7994 show_bgp_community2_cmd,
7995 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7996 SHOW_STR
7997 BGP_STR
7998 "Display routes matching the communities\n"
7999 "community number\n"
8000 "Do not send outside local AS (well-known community)\n"
8001 "Do not advertise to any peer (well-known community)\n"
8002 "Do not export to next AS (well-known community)\n"
8003 "community number\n"
8004 "Do not send outside local AS (well-known community)\n"
8005 "Do not advertise to any peer (well-known community)\n"
8006 "Do not export to next AS (well-known community)\n")
8007
8008ALIAS (show_bgp_community,
8009 show_bgp_ipv6_community2_cmd,
8010 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8011 SHOW_STR
8012 BGP_STR
8013 "Address family\n"
8014 "Display routes matching the communities\n"
8015 "community number\n"
8016 "Do not send outside local AS (well-known community)\n"
8017 "Do not advertise to any peer (well-known community)\n"
8018 "Do not export to next AS (well-known community)\n"
8019 "community number\n"
8020 "Do not send outside local AS (well-known community)\n"
8021 "Do not advertise to any peer (well-known community)\n"
8022 "Do not export to next AS (well-known community)\n")
8023
8024ALIAS (show_bgp_community,
8025 show_bgp_community3_cmd,
8026 "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)",
8027 SHOW_STR
8028 BGP_STR
8029 "Display routes matching the communities\n"
8030 "community number\n"
8031 "Do not send outside local AS (well-known community)\n"
8032 "Do not advertise to any peer (well-known community)\n"
8033 "Do not export to next AS (well-known community)\n"
8034 "community number\n"
8035 "Do not send outside local AS (well-known community)\n"
8036 "Do not advertise to any peer (well-known community)\n"
8037 "Do not export to next AS (well-known community)\n"
8038 "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
8043ALIAS (show_bgp_community,
8044 show_bgp_ipv6_community3_cmd,
8045 "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)",
8046 SHOW_STR
8047 BGP_STR
8048 "Address family\n"
8049 "Display routes matching the communities\n"
8050 "community number\n"
8051 "Do not send outside local AS (well-known community)\n"
8052 "Do not advertise to any peer (well-known community)\n"
8053 "Do not export to next AS (well-known community)\n"
8054 "community number\n"
8055 "Do not send outside local AS (well-known community)\n"
8056 "Do not advertise to any peer (well-known community)\n"
8057 "Do not export to next AS (well-known community)\n"
8058 "community number\n"
8059 "Do not send outside local AS (well-known community)\n"
8060 "Do not advertise to any peer (well-known community)\n"
8061 "Do not export to next AS (well-known community)\n")
8062
8063ALIAS (show_bgp_community,
8064 show_bgp_community4_cmd,
8065 "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)",
8066 SHOW_STR
8067 BGP_STR
8068 "Display routes matching the communities\n"
8069 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n"
8077 "community number\n"
8078 "Do not send outside local AS (well-known community)\n"
8079 "Do not advertise to any peer (well-known community)\n"
8080 "Do not export to next AS (well-known community)\n"
8081 "community number\n"
8082 "Do not send outside local AS (well-known community)\n"
8083 "Do not advertise to any peer (well-known community)\n"
8084 "Do not export to next AS (well-known community)\n")
8085
8086ALIAS (show_bgp_community,
8087 show_bgp_ipv6_community4_cmd,
8088 "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)",
8089 SHOW_STR
8090 BGP_STR
8091 "Address family\n"
8092 "Display routes matching the communities\n"
8093 "community number\n"
8094 "Do not send outside local AS (well-known community)\n"
8095 "Do not advertise to any peer (well-known community)\n"
8096 "Do not export to next AS (well-known community)\n"
8097 "community number\n"
8098 "Do not send outside local AS (well-known community)\n"
8099 "Do not advertise to any peer (well-known community)\n"
8100 "Do not export to next AS (well-known community)\n"
8101 "community number\n"
8102 "Do not send outside local AS (well-known community)\n"
8103 "Do not advertise to any peer (well-known community)\n"
8104 "Do not export to next AS (well-known community)\n"
8105 "community number\n"
8106 "Do not send outside local AS (well-known community)\n"
8107 "Do not advertise to any peer (well-known community)\n"
8108 "Do not export to next AS (well-known community)\n")
8109
8110/* old command */
8111DEFUN (show_ipv6_bgp_community,
8112 show_ipv6_bgp_community_cmd,
8113 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8114 SHOW_STR
8115 IPV6_STR
8116 BGP_STR
8117 "Display routes matching the communities\n"
8118 "community number\n"
8119 "Do not send outside local AS (well-known community)\n"
8120 "Do not advertise to any peer (well-known community)\n"
8121 "Do not export to next AS (well-known community)\n")
8122{
8123 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8124}
8125
8126/* old command */
8127ALIAS (show_ipv6_bgp_community,
8128 show_ipv6_bgp_community2_cmd,
8129 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8130 SHOW_STR
8131 IPV6_STR
8132 BGP_STR
8133 "Display routes matching the communities\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n"
8138 "community number\n"
8139 "Do not send outside local AS (well-known community)\n"
8140 "Do not advertise to any peer (well-known community)\n"
8141 "Do not export to next AS (well-known community)\n")
8142
8143/* old command */
8144ALIAS (show_ipv6_bgp_community,
8145 show_ipv6_bgp_community3_cmd,
8146 "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)",
8147 SHOW_STR
8148 IPV6_STR
8149 BGP_STR
8150 "Display routes matching the communities\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n")
8163
8164/* old command */
8165ALIAS (show_ipv6_bgp_community,
8166 show_ipv6_bgp_community4_cmd,
8167 "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)",
8168 SHOW_STR
8169 IPV6_STR
8170 BGP_STR
8171 "Display routes matching the communities\n"
8172 "community number\n"
8173 "Do not send outside local AS (well-known community)\n"
8174 "Do not advertise to any peer (well-known community)\n"
8175 "Do not export to next AS (well-known community)\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n"
8180 "community number\n"
8181 "Do not send outside local AS (well-known community)\n"
8182 "Do not advertise to any peer (well-known community)\n"
8183 "Do not export to next AS (well-known community)\n"
8184 "community number\n"
8185 "Do not send outside local AS (well-known community)\n"
8186 "Do not advertise to any peer (well-known community)\n"
8187 "Do not export to next AS (well-known community)\n")
8188
8189DEFUN (show_bgp_community_exact,
8190 show_bgp_community_exact_cmd,
8191 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8192 SHOW_STR
8193 BGP_STR
8194 "Display routes matching the communities\n"
8195 "community number\n"
8196 "Do not send outside local AS (well-known community)\n"
8197 "Do not advertise to any peer (well-known community)\n"
8198 "Do not export to next AS (well-known community)\n"
8199 "Exact match of the communities")
8200{
8201 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8202}
8203
8204ALIAS (show_bgp_community_exact,
8205 show_bgp_ipv6_community_exact_cmd,
8206 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8207 SHOW_STR
8208 BGP_STR
8209 "Address family\n"
8210 "Display routes matching the communities\n"
8211 "community number\n"
8212 "Do not send outside local AS (well-known community)\n"
8213 "Do not advertise to any peer (well-known community)\n"
8214 "Do not export to next AS (well-known community)\n"
8215 "Exact match of the communities")
8216
8217ALIAS (show_bgp_community_exact,
8218 show_bgp_community2_exact_cmd,
8219 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8220 SHOW_STR
8221 BGP_STR
8222 "Display routes matching the communities\n"
8223 "community number\n"
8224 "Do not send outside local AS (well-known community)\n"
8225 "Do not advertise to any peer (well-known community)\n"
8226 "Do not export to next AS (well-known community)\n"
8227 "community number\n"
8228 "Do not send outside local AS (well-known community)\n"
8229 "Do not advertise to any peer (well-known community)\n"
8230 "Do not export to next AS (well-known community)\n"
8231 "Exact match of the communities")
8232
8233ALIAS (show_bgp_community_exact,
8234 show_bgp_ipv6_community2_exact_cmd,
8235 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8236 SHOW_STR
8237 BGP_STR
8238 "Address family\n"
8239 "Display routes matching the communities\n"
8240 "community number\n"
8241 "Do not send outside local AS (well-known community)\n"
8242 "Do not advertise to any peer (well-known community)\n"
8243 "Do not export to next AS (well-known community)\n"
8244 "community number\n"
8245 "Do not send outside local AS (well-known community)\n"
8246 "Do not advertise to any peer (well-known community)\n"
8247 "Do not export to next AS (well-known community)\n"
8248 "Exact match of the communities")
8249
8250ALIAS (show_bgp_community_exact,
8251 show_bgp_community3_exact_cmd,
8252 "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",
8253 SHOW_STR
8254 BGP_STR
8255 "Display routes matching the communities\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 "community number\n"
8261 "Do not send outside local AS (well-known community)\n"
8262 "Do not advertise to any peer (well-known community)\n"
8263 "Do not export to next AS (well-known community)\n"
8264 "community number\n"
8265 "Do not send outside local AS (well-known community)\n"
8266 "Do not advertise to any peer (well-known community)\n"
8267 "Do not export to next AS (well-known community)\n"
8268 "Exact match of the communities")
8269
8270ALIAS (show_bgp_community_exact,
8271 show_bgp_ipv6_community3_exact_cmd,
8272 "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",
8273 SHOW_STR
8274 BGP_STR
8275 "Address family\n"
8276 "Display routes matching the communities\n"
8277 "community number\n"
8278 "Do not send outside local AS (well-known community)\n"
8279 "Do not advertise to any peer (well-known community)\n"
8280 "Do not export to next AS (well-known community)\n"
8281 "community number\n"
8282 "Do not send outside local AS (well-known community)\n"
8283 "Do not advertise to any peer (well-known community)\n"
8284 "Do not export to next AS (well-known community)\n"
8285 "community number\n"
8286 "Do not send outside local AS (well-known community)\n"
8287 "Do not advertise to any peer (well-known community)\n"
8288 "Do not export to next AS (well-known community)\n"
8289 "Exact match of the communities")
8290
8291ALIAS (show_bgp_community_exact,
8292 show_bgp_community4_exact_cmd,
8293 "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",
8294 SHOW_STR
8295 BGP_STR
8296 "Display routes matching the communities\n"
8297 "community number\n"
8298 "Do not send outside local AS (well-known community)\n"
8299 "Do not advertise to any peer (well-known community)\n"
8300 "Do not export to next AS (well-known community)\n"
8301 "community number\n"
8302 "Do not send outside local AS (well-known community)\n"
8303 "Do not advertise to any peer (well-known community)\n"
8304 "Do not export to next AS (well-known community)\n"
8305 "community number\n"
8306 "Do not send outside local AS (well-known community)\n"
8307 "Do not advertise to any peer (well-known community)\n"
8308 "Do not export to next AS (well-known community)\n"
8309 "community number\n"
8310 "Do not send outside local AS (well-known community)\n"
8311 "Do not advertise to any peer (well-known community)\n"
8312 "Do not export to next AS (well-known community)\n"
8313 "Exact match of the communities")
8314
8315ALIAS (show_bgp_community_exact,
8316 show_bgp_ipv6_community4_exact_cmd,
8317 "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",
8318 SHOW_STR
8319 BGP_STR
8320 "Address family\n"
8321 "Display routes matching the communities\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n"
8326 "community number\n"
8327 "Do not send outside local AS (well-known community)\n"
8328 "Do not advertise to any peer (well-known community)\n"
8329 "Do not export to next AS (well-known community)\n"
8330 "community number\n"
8331 "Do not send outside local AS (well-known community)\n"
8332 "Do not advertise to any peer (well-known community)\n"
8333 "Do not export to next AS (well-known community)\n"
8334 "community number\n"
8335 "Do not send outside local AS (well-known community)\n"
8336 "Do not advertise to any peer (well-known community)\n"
8337 "Do not export to next AS (well-known community)\n"
8338 "Exact match of the communities")
8339
8340/* old command */
8341DEFUN (show_ipv6_bgp_community_exact,
8342 show_ipv6_bgp_community_exact_cmd,
8343 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8344 SHOW_STR
8345 IPV6_STR
8346 BGP_STR
8347 "Display routes matching the communities\n"
8348 "community number\n"
8349 "Do not send outside local AS (well-known community)\n"
8350 "Do not advertise to any peer (well-known community)\n"
8351 "Do not export to next AS (well-known community)\n"
8352 "Exact match of the communities")
8353{
8354 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8355}
8356
8357/* old command */
8358ALIAS (show_ipv6_bgp_community_exact,
8359 show_ipv6_bgp_community2_exact_cmd,
8360 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8361 SHOW_STR
8362 IPV6_STR
8363 BGP_STR
8364 "Display routes matching the communities\n"
8365 "community number\n"
8366 "Do not send outside local AS (well-known community)\n"
8367 "Do not advertise to any peer (well-known community)\n"
8368 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8374
8375/* old command */
8376ALIAS (show_ipv6_bgp_community_exact,
8377 show_ipv6_bgp_community3_exact_cmd,
8378 "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",
8379 SHOW_STR
8380 IPV6_STR
8381 BGP_STR
8382 "Display routes matching the communities\n"
8383 "community number\n"
8384 "Do not send outside local AS (well-known community)\n"
8385 "Do not advertise to any peer (well-known community)\n"
8386 "Do not export to next AS (well-known community)\n"
8387 "community number\n"
8388 "Do not send outside local AS (well-known community)\n"
8389 "Do not advertise to any peer (well-known community)\n"
8390 "Do not export to next AS (well-known community)\n"
8391 "community number\n"
8392 "Do not send outside local AS (well-known community)\n"
8393 "Do not advertise to any peer (well-known community)\n"
8394 "Do not export to next AS (well-known community)\n"
8395 "Exact match of the communities")
8396
8397/* old command */
8398ALIAS (show_ipv6_bgp_community_exact,
8399 show_ipv6_bgp_community4_exact_cmd,
8400 "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",
8401 SHOW_STR
8402 IPV6_STR
8403 BGP_STR
8404 "Display routes matching the communities\n"
8405 "community number\n"
8406 "Do not send outside local AS (well-known community)\n"
8407 "Do not advertise to any peer (well-known community)\n"
8408 "Do not export to next AS (well-known community)\n"
8409 "community number\n"
8410 "Do not send outside local AS (well-known community)\n"
8411 "Do not advertise to any peer (well-known community)\n"
8412 "Do not export to next AS (well-known community)\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 "community number\n"
8418 "Do not send outside local AS (well-known community)\n"
8419 "Do not advertise to any peer (well-known community)\n"
8420 "Do not export to next AS (well-known community)\n"
8421 "Exact match of the communities")
8422
8423/* old command */
8424DEFUN (show_ipv6_mbgp_community,
8425 show_ipv6_mbgp_community_cmd,
8426 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8427 SHOW_STR
8428 IPV6_STR
8429 MBGP_STR
8430 "Display routes matching the communities\n"
8431 "community number\n"
8432 "Do not send outside local AS (well-known community)\n"
8433 "Do not advertise to any peer (well-known community)\n"
8434 "Do not export to next AS (well-known community)\n")
8435{
8436 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8437}
8438
8439/* old command */
8440ALIAS (show_ipv6_mbgp_community,
8441 show_ipv6_mbgp_community2_cmd,
8442 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8443 SHOW_STR
8444 IPV6_STR
8445 MBGP_STR
8446 "Display routes matching the communities\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n")
8455
8456/* old command */
8457ALIAS (show_ipv6_mbgp_community,
8458 show_ipv6_mbgp_community3_cmd,
8459 "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)",
8460 SHOW_STR
8461 IPV6_STR
8462 MBGP_STR
8463 "Display routes matching the communities\n"
8464 "community number\n"
8465 "Do not send outside local AS (well-known community)\n"
8466 "Do not advertise to any peer (well-known community)\n"
8467 "Do not export to next AS (well-known community)\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n")
8476
8477/* old command */
8478ALIAS (show_ipv6_mbgp_community,
8479 show_ipv6_mbgp_community4_cmd,
8480 "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)",
8481 SHOW_STR
8482 IPV6_STR
8483 MBGP_STR
8484 "Display routes matching the communities\n"
8485 "community number\n"
8486 "Do not send outside local AS (well-known community)\n"
8487 "Do not advertise to any peer (well-known community)\n"
8488 "Do not export to next AS (well-known community)\n"
8489 "community number\n"
8490 "Do not send outside local AS (well-known community)\n"
8491 "Do not advertise to any peer (well-known community)\n"
8492 "Do not export to next AS (well-known community)\n"
8493 "community number\n"
8494 "Do not send outside local AS (well-known community)\n"
8495 "Do not advertise to any peer (well-known community)\n"
8496 "Do not export to next AS (well-known community)\n"
8497 "community number\n"
8498 "Do not send outside local AS (well-known community)\n"
8499 "Do not advertise to any peer (well-known community)\n"
8500 "Do not export to next AS (well-known community)\n")
8501
8502/* old command */
8503DEFUN (show_ipv6_mbgp_community_exact,
8504 show_ipv6_mbgp_community_exact_cmd,
8505 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8506 SHOW_STR
8507 IPV6_STR
8508 MBGP_STR
8509 "Display routes matching the communities\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n"
8514 "Exact match of the communities")
8515{
8516 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8517}
8518
8519/* old command */
8520ALIAS (show_ipv6_mbgp_community_exact,
8521 show_ipv6_mbgp_community2_exact_cmd,
8522 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8523 SHOW_STR
8524 IPV6_STR
8525 MBGP_STR
8526 "Display routes matching the communities\n"
8527 "community number\n"
8528 "Do not send outside local AS (well-known community)\n"
8529 "Do not advertise to any peer (well-known community)\n"
8530 "Do not export to next AS (well-known community)\n"
8531 "community number\n"
8532 "Do not send outside local AS (well-known community)\n"
8533 "Do not advertise to any peer (well-known community)\n"
8534 "Do not export to next AS (well-known community)\n"
8535 "Exact match of the communities")
8536
8537/* old command */
8538ALIAS (show_ipv6_mbgp_community_exact,
8539 show_ipv6_mbgp_community3_exact_cmd,
8540 "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",
8541 SHOW_STR
8542 IPV6_STR
8543 MBGP_STR
8544 "Display routes matching the communities\n"
8545 "community number\n"
8546 "Do not send outside local AS (well-known community)\n"
8547 "Do not advertise to any peer (well-known community)\n"
8548 "Do not export to next AS (well-known community)\n"
8549 "community number\n"
8550 "Do not send outside local AS (well-known community)\n"
8551 "Do not advertise to any peer (well-known community)\n"
8552 "Do not export to next AS (well-known community)\n"
8553 "community number\n"
8554 "Do not send outside local AS (well-known community)\n"
8555 "Do not advertise to any peer (well-known community)\n"
8556 "Do not export to next AS (well-known community)\n"
8557 "Exact match of the communities")
8558
8559/* old command */
8560ALIAS (show_ipv6_mbgp_community_exact,
8561 show_ipv6_mbgp_community4_exact_cmd,
8562 "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",
8563 SHOW_STR
8564 IPV6_STR
8565 MBGP_STR
8566 "Display routes matching the communities\n"
8567 "community number\n"
8568 "Do not send outside local AS (well-known community)\n"
8569 "Do not advertise to any peer (well-known community)\n"
8570 "Do not export to next AS (well-known community)\n"
8571 "community number\n"
8572 "Do not send outside local AS (well-known community)\n"
8573 "Do not advertise to any peer (well-known community)\n"
8574 "Do not export to next AS (well-known community)\n"
8575 "community number\n"
8576 "Do not send outside local AS (well-known community)\n"
8577 "Do not advertise to any peer (well-known community)\n"
8578 "Do not export to next AS (well-known community)\n"
8579 "community number\n"
8580 "Do not send outside local AS (well-known community)\n"
8581 "Do not advertise to any peer (well-known community)\n"
8582 "Do not export to next AS (well-known community)\n"
8583 "Exact match of the communities")
8584#endif /* HAVE_IPV6 */
8585
paul94f2b392005-06-28 12:44:16 +00008586static int
paulfd79ac92004-10-13 05:06:08 +00008587bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008588 u_int16_t afi, u_char safi)
8589{
8590 struct community_list *list;
8591
hassofee6e4e2005-02-02 16:29:31 +00008592 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008593 if (list == NULL)
8594 {
8595 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8596 VTY_NEWLINE);
8597 return CMD_WARNING;
8598 }
8599
ajs5a646652004-11-05 01:25:55 +00008600 return bgp_show (vty, NULL, afi, safi,
8601 (exact ? bgp_show_type_community_list_exact :
8602 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008603}
8604
8605DEFUN (show_ip_bgp_community_list,
8606 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008607 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008608 SHOW_STR
8609 IP_STR
8610 BGP_STR
8611 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008612 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008613 "community-list name\n")
8614{
8615 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8616}
8617
8618DEFUN (show_ip_bgp_ipv4_community_list,
8619 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008620 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008621 SHOW_STR
8622 IP_STR
8623 BGP_STR
8624 "Address family\n"
8625 "Address Family modifier\n"
8626 "Address Family modifier\n"
8627 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008628 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008629 "community-list name\n")
8630{
8631 if (strncmp (argv[0], "m", 1) == 0)
8632 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8633
8634 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8635}
8636
8637DEFUN (show_ip_bgp_community_list_exact,
8638 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008639 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008640 SHOW_STR
8641 IP_STR
8642 BGP_STR
8643 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008644 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008645 "community-list name\n"
8646 "Exact match of the communities\n")
8647{
8648 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8649}
8650
8651DEFUN (show_ip_bgp_ipv4_community_list_exact,
8652 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008653 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008654 SHOW_STR
8655 IP_STR
8656 BGP_STR
8657 "Address family\n"
8658 "Address Family modifier\n"
8659 "Address Family modifier\n"
8660 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008661 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008662 "community-list name\n"
8663 "Exact match of the communities\n")
8664{
8665 if (strncmp (argv[0], "m", 1) == 0)
8666 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8667
8668 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8669}
8670
8671#ifdef HAVE_IPV6
8672DEFUN (show_bgp_community_list,
8673 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008674 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008675 SHOW_STR
8676 BGP_STR
8677 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008678 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008679 "community-list name\n")
8680{
8681 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8682}
8683
8684ALIAS (show_bgp_community_list,
8685 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008686 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008687 SHOW_STR
8688 BGP_STR
8689 "Address family\n"
8690 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008691 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008692 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008693
8694/* old command */
8695DEFUN (show_ipv6_bgp_community_list,
8696 show_ipv6_bgp_community_list_cmd,
8697 "show ipv6 bgp community-list WORD",
8698 SHOW_STR
8699 IPV6_STR
8700 BGP_STR
8701 "Display routes matching the community-list\n"
8702 "community-list name\n")
8703{
8704 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8705}
8706
8707/* old command */
8708DEFUN (show_ipv6_mbgp_community_list,
8709 show_ipv6_mbgp_community_list_cmd,
8710 "show ipv6 mbgp community-list WORD",
8711 SHOW_STR
8712 IPV6_STR
8713 MBGP_STR
8714 "Display routes matching the community-list\n"
8715 "community-list name\n")
8716{
8717 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8718}
8719
8720DEFUN (show_bgp_community_list_exact,
8721 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008722 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008723 SHOW_STR
8724 BGP_STR
8725 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008726 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008727 "community-list name\n"
8728 "Exact match of the communities\n")
8729{
8730 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8731}
8732
8733ALIAS (show_bgp_community_list_exact,
8734 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008735 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008736 SHOW_STR
8737 BGP_STR
8738 "Address family\n"
8739 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008740 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008741 "community-list name\n"
8742 "Exact match of the communities\n")
8743
8744/* old command */
8745DEFUN (show_ipv6_bgp_community_list_exact,
8746 show_ipv6_bgp_community_list_exact_cmd,
8747 "show ipv6 bgp community-list WORD exact-match",
8748 SHOW_STR
8749 IPV6_STR
8750 BGP_STR
8751 "Display routes matching the community-list\n"
8752 "community-list name\n"
8753 "Exact match of the communities\n")
8754{
8755 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8756}
8757
8758/* old command */
8759DEFUN (show_ipv6_mbgp_community_list_exact,
8760 show_ipv6_mbgp_community_list_exact_cmd,
8761 "show ipv6 mbgp community-list WORD exact-match",
8762 SHOW_STR
8763 IPV6_STR
8764 MBGP_STR
8765 "Display routes matching the community-list\n"
8766 "community-list name\n"
8767 "Exact match of the communities\n")
8768{
8769 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8770}
8771#endif /* HAVE_IPV6 */
8772
paul94f2b392005-06-28 12:44:16 +00008773static int
paulfd79ac92004-10-13 05:06:08 +00008774bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008775 safi_t safi, enum bgp_show_type type)
8776{
8777 int ret;
8778 struct prefix *p;
8779
8780 p = prefix_new();
8781
8782 ret = str2prefix (prefix, p);
8783 if (! ret)
8784 {
8785 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8786 return CMD_WARNING;
8787 }
8788
ajs5a646652004-11-05 01:25:55 +00008789 ret = bgp_show (vty, NULL, afi, safi, type, p);
8790 prefix_free(p);
8791 return ret;
paul718e3742002-12-13 20:15:29 +00008792}
8793
8794DEFUN (show_ip_bgp_prefix_longer,
8795 show_ip_bgp_prefix_longer_cmd,
8796 "show ip bgp A.B.C.D/M longer-prefixes",
8797 SHOW_STR
8798 IP_STR
8799 BGP_STR
8800 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8801 "Display route and more specific routes\n")
8802{
8803 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8804 bgp_show_type_prefix_longer);
8805}
8806
8807DEFUN (show_ip_bgp_flap_prefix_longer,
8808 show_ip_bgp_flap_prefix_longer_cmd,
8809 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8810 SHOW_STR
8811 IP_STR
8812 BGP_STR
8813 "Display flap statistics of routes\n"
8814 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8815 "Display route and more specific routes\n")
8816{
8817 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8818 bgp_show_type_flap_prefix_longer);
8819}
8820
8821DEFUN (show_ip_bgp_ipv4_prefix_longer,
8822 show_ip_bgp_ipv4_prefix_longer_cmd,
8823 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8824 SHOW_STR
8825 IP_STR
8826 BGP_STR
8827 "Address family\n"
8828 "Address Family modifier\n"
8829 "Address Family modifier\n"
8830 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8831 "Display route and more specific routes\n")
8832{
8833 if (strncmp (argv[0], "m", 1) == 0)
8834 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8835 bgp_show_type_prefix_longer);
8836
8837 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8838 bgp_show_type_prefix_longer);
8839}
8840
8841DEFUN (show_ip_bgp_flap_address,
8842 show_ip_bgp_flap_address_cmd,
8843 "show ip bgp flap-statistics A.B.C.D",
8844 SHOW_STR
8845 IP_STR
8846 BGP_STR
8847 "Display flap statistics of routes\n"
8848 "Network in the BGP routing table to display\n")
8849{
8850 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8851 bgp_show_type_flap_address);
8852}
8853
8854DEFUN (show_ip_bgp_flap_prefix,
8855 show_ip_bgp_flap_prefix_cmd,
8856 "show ip bgp flap-statistics A.B.C.D/M",
8857 SHOW_STR
8858 IP_STR
8859 BGP_STR
8860 "Display flap statistics of routes\n"
8861 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8862{
8863 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8864 bgp_show_type_flap_prefix);
8865}
8866#ifdef HAVE_IPV6
8867DEFUN (show_bgp_prefix_longer,
8868 show_bgp_prefix_longer_cmd,
8869 "show bgp X:X::X:X/M longer-prefixes",
8870 SHOW_STR
8871 BGP_STR
8872 "IPv6 prefix <network>/<length>\n"
8873 "Display route and more specific routes\n")
8874{
8875 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8876 bgp_show_type_prefix_longer);
8877}
8878
8879ALIAS (show_bgp_prefix_longer,
8880 show_bgp_ipv6_prefix_longer_cmd,
8881 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8882 SHOW_STR
8883 BGP_STR
8884 "Address family\n"
8885 "IPv6 prefix <network>/<length>\n"
8886 "Display route and more specific routes\n")
8887
8888/* old command */
8889DEFUN (show_ipv6_bgp_prefix_longer,
8890 show_ipv6_bgp_prefix_longer_cmd,
8891 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8892 SHOW_STR
8893 IPV6_STR
8894 BGP_STR
8895 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8896 "Display route and more specific routes\n")
8897{
8898 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8899 bgp_show_type_prefix_longer);
8900}
8901
8902/* old command */
8903DEFUN (show_ipv6_mbgp_prefix_longer,
8904 show_ipv6_mbgp_prefix_longer_cmd,
8905 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8906 SHOW_STR
8907 IPV6_STR
8908 MBGP_STR
8909 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8910 "Display route and more specific routes\n")
8911{
8912 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8913 bgp_show_type_prefix_longer);
8914}
8915#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008916
paul94f2b392005-06-28 12:44:16 +00008917static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008918peer_lookup_in_view (struct vty *vty, const char *view_name,
8919 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008920{
8921 int ret;
8922 struct bgp *bgp;
8923 struct peer *peer;
8924 union sockunion su;
8925
8926 /* BGP structure lookup. */
8927 if (view_name)
8928 {
8929 bgp = bgp_lookup_by_name (view_name);
8930 if (! bgp)
8931 {
8932 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8933 return NULL;
8934 }
8935 }
paul5228ad22004-06-04 17:58:18 +00008936 else
paulbb46e942003-10-24 19:02:03 +00008937 {
8938 bgp = bgp_get_default ();
8939 if (! bgp)
8940 {
8941 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8942 return NULL;
8943 }
8944 }
8945
8946 /* Get peer sockunion. */
8947 ret = str2sockunion (ip_str, &su);
8948 if (ret < 0)
8949 {
8950 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8951 return NULL;
8952 }
8953
8954 /* Peer structure lookup. */
8955 peer = peer_lookup (bgp, &su);
8956 if (! peer)
8957 {
8958 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8959 return NULL;
8960 }
8961
8962 return peer;
8963}
Paul Jakma2815e612006-09-14 02:56:07 +00008964
8965enum bgp_stats
8966{
8967 BGP_STATS_MAXBITLEN = 0,
8968 BGP_STATS_RIB,
8969 BGP_STATS_PREFIXES,
8970 BGP_STATS_TOTPLEN,
8971 BGP_STATS_UNAGGREGATEABLE,
8972 BGP_STATS_MAX_AGGREGATEABLE,
8973 BGP_STATS_AGGREGATES,
8974 BGP_STATS_SPACE,
8975 BGP_STATS_ASPATH_COUNT,
8976 BGP_STATS_ASPATH_MAXHOPS,
8977 BGP_STATS_ASPATH_TOTHOPS,
8978 BGP_STATS_ASPATH_MAXSIZE,
8979 BGP_STATS_ASPATH_TOTSIZE,
8980 BGP_STATS_ASN_HIGHEST,
8981 BGP_STATS_MAX,
8982};
paulbb46e942003-10-24 19:02:03 +00008983
Paul Jakma2815e612006-09-14 02:56:07 +00008984static const char *table_stats_strs[] =
8985{
8986 [BGP_STATS_PREFIXES] = "Total Prefixes",
8987 [BGP_STATS_TOTPLEN] = "Average prefix length",
8988 [BGP_STATS_RIB] = "Total Advertisements",
8989 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8990 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8991 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8992 [BGP_STATS_SPACE] = "Address space advertised",
8993 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8994 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8995 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8996 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8997 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8998 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8999 [BGP_STATS_MAX] = NULL,
9000};
9001
9002struct bgp_table_stats
9003{
9004 struct bgp_table *table;
9005 unsigned long long counts[BGP_STATS_MAX];
9006};
9007
9008#if 0
9009#define TALLY_SIGFIG 100000
9010static unsigned long
9011ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9012{
9013 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9014 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9015 unsigned long ret = newtot / count;
9016
9017 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9018 return ret + 1;
9019 else
9020 return ret;
9021}
9022#endif
9023
9024static int
9025bgp_table_stats_walker (struct thread *t)
9026{
9027 struct bgp_node *rn;
9028 struct bgp_node *top;
9029 struct bgp_table_stats *ts = THREAD_ARG (t);
9030 unsigned int space = 0;
9031
Paul Jakma53d9f672006-10-15 23:41:16 +00009032 if (!(top = bgp_table_top (ts->table)))
9033 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009034
9035 switch (top->p.family)
9036 {
9037 case AF_INET:
9038 space = IPV4_MAX_BITLEN;
9039 break;
9040 case AF_INET6:
9041 space = IPV6_MAX_BITLEN;
9042 break;
9043 }
9044
9045 ts->counts[BGP_STATS_MAXBITLEN] = space;
9046
9047 for (rn = top; rn; rn = bgp_route_next (rn))
9048 {
9049 struct bgp_info *ri;
9050 struct bgp_node *prn = rn->parent;
9051 unsigned int rinum = 0;
9052
9053 if (rn == top)
9054 continue;
9055
9056 if (!rn->info)
9057 continue;
9058
9059 ts->counts[BGP_STATS_PREFIXES]++;
9060 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9061
9062#if 0
9063 ts->counts[BGP_STATS_AVGPLEN]
9064 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9065 ts->counts[BGP_STATS_AVGPLEN],
9066 rn->p.prefixlen);
9067#endif
9068
9069 /* check if the prefix is included by any other announcements */
9070 while (prn && !prn->info)
9071 prn = prn->parent;
9072
9073 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009074 {
9075 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9076 /* announced address space */
9077 if (space)
9078 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9079 }
Paul Jakma2815e612006-09-14 02:56:07 +00009080 else if (prn->info)
9081 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9082
Paul Jakma2815e612006-09-14 02:56:07 +00009083 for (ri = rn->info; ri; ri = ri->next)
9084 {
9085 rinum++;
9086 ts->counts[BGP_STATS_RIB]++;
9087
9088 if (ri->attr &&
9089 (CHECK_FLAG (ri->attr->flag,
9090 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9091 ts->counts[BGP_STATS_AGGREGATES]++;
9092
9093 /* as-path stats */
9094 if (ri->attr && ri->attr->aspath)
9095 {
9096 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9097 unsigned int size = aspath_size (ri->attr->aspath);
9098 as_t highest = aspath_highest (ri->attr->aspath);
9099
9100 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9101
9102 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9103 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9104
9105 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9106 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9107
9108 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9109 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9110#if 0
9111 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9112 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9113 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9114 hops);
9115 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9116 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9117 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9118 size);
9119#endif
9120 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9121 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9122 }
9123 }
9124 }
9125 return 0;
9126}
9127
9128static int
9129bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9130{
9131 struct bgp_table_stats ts;
9132 unsigned int i;
9133
9134 if (!bgp->rib[afi][safi])
9135 {
9136 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9137 return CMD_WARNING;
9138 }
9139
9140 memset (&ts, 0, sizeof (ts));
9141 ts.table = bgp->rib[afi][safi];
9142 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9143
9144 vty_out (vty, "BGP %s RIB statistics%s%s",
9145 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9146
9147 for (i = 0; i < BGP_STATS_MAX; i++)
9148 {
9149 if (!table_stats_strs[i])
9150 continue;
9151
9152 switch (i)
9153 {
9154#if 0
9155 case BGP_STATS_ASPATH_AVGHOPS:
9156 case BGP_STATS_ASPATH_AVGSIZE:
9157 case BGP_STATS_AVGPLEN:
9158 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9159 vty_out (vty, "%12.2f",
9160 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9161 break;
9162#endif
9163 case BGP_STATS_ASPATH_TOTHOPS:
9164 case BGP_STATS_ASPATH_TOTSIZE:
9165 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9166 vty_out (vty, "%12.2f",
9167 ts.counts[i] ?
9168 (float)ts.counts[i] /
9169 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9170 : 0);
9171 break;
9172 case BGP_STATS_TOTPLEN:
9173 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9174 vty_out (vty, "%12.2f",
9175 ts.counts[i] ?
9176 (float)ts.counts[i] /
9177 (float)ts.counts[BGP_STATS_PREFIXES]
9178 : 0);
9179 break;
9180 case BGP_STATS_SPACE:
9181 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9182 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9183 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9184 break;
9185 vty_out (vty, "%30s: ", "\% announced ");
9186 vty_out (vty, "%12.2f%s",
9187 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009188 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009189 VTY_NEWLINE);
9190 vty_out (vty, "%30s: ", "/8 equivalent ");
9191 vty_out (vty, "%12.2f%s",
9192 (float)ts.counts[BGP_STATS_SPACE] /
9193 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9194 VTY_NEWLINE);
9195 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9196 break;
9197 vty_out (vty, "%30s: ", "/24 equivalent ");
9198 vty_out (vty, "%12.2f",
9199 (float)ts.counts[BGP_STATS_SPACE] /
9200 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9201 break;
9202 default:
9203 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9204 vty_out (vty, "%12llu", ts.counts[i]);
9205 }
9206
9207 vty_out (vty, "%s", VTY_NEWLINE);
9208 }
9209 return CMD_SUCCESS;
9210}
9211
9212static int
9213bgp_table_stats_vty (struct vty *vty, const char *name,
9214 const char *afi_str, const char *safi_str)
9215{
9216 struct bgp *bgp;
9217 afi_t afi;
9218 safi_t safi;
9219
9220 if (name)
9221 bgp = bgp_lookup_by_name (name);
9222 else
9223 bgp = bgp_get_default ();
9224
9225 if (!bgp)
9226 {
9227 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9228 return CMD_WARNING;
9229 }
9230 if (strncmp (afi_str, "ipv", 3) == 0)
9231 {
9232 if (strncmp (afi_str, "ipv4", 4) == 0)
9233 afi = AFI_IP;
9234 else if (strncmp (afi_str, "ipv6", 4) == 0)
9235 afi = AFI_IP6;
9236 else
9237 {
9238 vty_out (vty, "%% Invalid address family %s%s",
9239 afi_str, VTY_NEWLINE);
9240 return CMD_WARNING;
9241 }
9242 if (strncmp (safi_str, "m", 1) == 0)
9243 safi = SAFI_MULTICAST;
9244 else if (strncmp (safi_str, "u", 1) == 0)
9245 safi = SAFI_UNICAST;
9246 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9247 safi = BGP_SAFI_VPNV4;
9248 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9249 safi = BGP_SAFI_VPNV6;
9250 else
9251 {
9252 vty_out (vty, "%% Invalid subsequent address family %s%s",
9253 safi_str, VTY_NEWLINE);
9254 return CMD_WARNING;
9255 }
9256 }
9257 else
9258 {
9259 vty_out (vty, "%% Invalid address family %s%s",
9260 afi_str, VTY_NEWLINE);
9261 return CMD_WARNING;
9262 }
9263
9264 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9265 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9266 {
9267 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9268 afi_str, safi_str, VTY_NEWLINE);
9269 return CMD_WARNING;
9270 }
9271 return bgp_table_stats (vty, bgp, afi, safi);
9272}
9273
9274DEFUN (show_bgp_statistics,
9275 show_bgp_statistics_cmd,
9276 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9277 SHOW_STR
9278 BGP_STR
9279 "Address family\n"
9280 "Address family\n"
9281 "Address Family modifier\n"
9282 "Address Family modifier\n"
9283 "BGP RIB advertisement statistics\n")
9284{
9285 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9286}
9287
9288ALIAS (show_bgp_statistics,
9289 show_bgp_statistics_vpnv4_cmd,
9290 "show bgp (ipv4) (vpnv4) statistics",
9291 SHOW_STR
9292 BGP_STR
9293 "Address family\n"
9294 "Address Family modifier\n"
9295 "BGP RIB advertisement statistics\n")
9296
9297DEFUN (show_bgp_statistics_view,
9298 show_bgp_statistics_view_cmd,
9299 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9300 SHOW_STR
9301 BGP_STR
9302 "BGP view\n"
9303 "Address family\n"
9304 "Address family\n"
9305 "Address Family modifier\n"
9306 "Address Family modifier\n"
9307 "BGP RIB advertisement statistics\n")
9308{
9309 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9310}
9311
9312ALIAS (show_bgp_statistics_view,
9313 show_bgp_statistics_view_vpnv4_cmd,
9314 "show bgp view WORD (ipv4) (vpnv4) statistics",
9315 SHOW_STR
9316 BGP_STR
9317 "BGP view\n"
9318 "Address family\n"
9319 "Address Family modifier\n"
9320 "BGP RIB advertisement statistics\n")
9321
Paul Jakmaff7924f2006-09-04 01:10:36 +00009322enum bgp_pcounts
9323{
9324 PCOUNT_ADJ_IN = 0,
9325 PCOUNT_DAMPED,
9326 PCOUNT_REMOVED,
9327 PCOUNT_HISTORY,
9328 PCOUNT_STALE,
9329 PCOUNT_VALID,
9330 PCOUNT_ALL,
9331 PCOUNT_COUNTED,
9332 PCOUNT_PFCNT, /* the figure we display to users */
9333 PCOUNT_MAX,
9334};
9335
9336static const char *pcount_strs[] =
9337{
9338 [PCOUNT_ADJ_IN] = "Adj-in",
9339 [PCOUNT_DAMPED] = "Damped",
9340 [PCOUNT_REMOVED] = "Removed",
9341 [PCOUNT_HISTORY] = "History",
9342 [PCOUNT_STALE] = "Stale",
9343 [PCOUNT_VALID] = "Valid",
9344 [PCOUNT_ALL] = "All RIB",
9345 [PCOUNT_COUNTED] = "PfxCt counted",
9346 [PCOUNT_PFCNT] = "Useable",
9347 [PCOUNT_MAX] = NULL,
9348};
9349
Paul Jakma2815e612006-09-14 02:56:07 +00009350struct peer_pcounts
9351{
9352 unsigned int count[PCOUNT_MAX];
9353 const struct peer *peer;
9354 const struct bgp_table *table;
9355};
9356
Paul Jakmaff7924f2006-09-04 01:10:36 +00009357static int
Paul Jakma2815e612006-09-14 02:56:07 +00009358bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009359{
9360 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009361 struct peer_pcounts *pc = THREAD_ARG (t);
9362 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009363
Paul Jakma2815e612006-09-14 02:56:07 +00009364 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009365 {
9366 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009367 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009368
9369 for (ain = rn->adj_in; ain; ain = ain->next)
9370 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009371 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009372
Paul Jakmaff7924f2006-09-04 01:10:36 +00009373 for (ri = rn->info; ri; ri = ri->next)
9374 {
9375 char buf[SU_ADDRSTRLEN];
9376
9377 if (ri->peer != peer)
9378 continue;
9379
Paul Jakma2815e612006-09-14 02:56:07 +00009380 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009381
9382 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009383 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009384 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009385 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009386 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009387 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009388 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009389 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009390 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009391 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009392 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009393 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009394
9395 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9396 {
Paul Jakma2815e612006-09-14 02:56:07 +00009397 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009398 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009399 plog_warn (peer->log,
9400 "%s [pcount] %s/%d is counted but flags 0x%x",
9401 peer->host,
9402 inet_ntop(rn->p.family, &rn->p.u.prefix,
9403 buf, SU_ADDRSTRLEN),
9404 rn->p.prefixlen,
9405 ri->flags);
9406 }
9407 else
9408 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009409 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009410 plog_warn (peer->log,
9411 "%s [pcount] %s/%d not counted but flags 0x%x",
9412 peer->host,
9413 inet_ntop(rn->p.family, &rn->p.u.prefix,
9414 buf, SU_ADDRSTRLEN),
9415 rn->p.prefixlen,
9416 ri->flags);
9417 }
9418 }
9419 }
Paul Jakma2815e612006-09-14 02:56:07 +00009420 return 0;
9421}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009422
Paul Jakma2815e612006-09-14 02:56:07 +00009423static int
9424bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9425{
9426 struct peer_pcounts pcounts = { .peer = peer };
9427 unsigned int i;
9428
9429 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9430 || !peer->bgp->rib[afi][safi])
9431 {
9432 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9433 return CMD_WARNING;
9434 }
9435
9436 memset (&pcounts, 0, sizeof(pcounts));
9437 pcounts.peer = peer;
9438 pcounts.table = peer->bgp->rib[afi][safi];
9439
9440 /* in-place call via thread subsystem so as to record execution time
9441 * stats for the thread-walk (i.e. ensure this can't be blamed on
9442 * on just vty_read()).
9443 */
9444 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9445
Paul Jakmaff7924f2006-09-04 01:10:36 +00009446 vty_out (vty, "Prefix counts for %s, %s%s",
9447 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9448 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9449 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9450 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9451
9452 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009453 vty_out (vty, "%20s: %-10d%s",
9454 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009455
Paul Jakma2815e612006-09-14 02:56:07 +00009456 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009457 {
9458 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9459 peer->host, VTY_NEWLINE);
9460 vty_out (vty, "Please report this bug, with the above command output%s",
9461 VTY_NEWLINE);
9462 }
9463
9464 return CMD_SUCCESS;
9465}
9466
9467DEFUN (show_ip_bgp_neighbor_prefix_counts,
9468 show_ip_bgp_neighbor_prefix_counts_cmd,
9469 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9470 SHOW_STR
9471 IP_STR
9472 BGP_STR
9473 "Detailed information on TCP and BGP neighbor connections\n"
9474 "Neighbor to display information about\n"
9475 "Neighbor to display information about\n"
9476 "Display detailed prefix count information\n")
9477{
9478 struct peer *peer;
9479
9480 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9481 if (! peer)
9482 return CMD_WARNING;
9483
9484 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9485}
9486
9487DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9488 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9489 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9490 SHOW_STR
9491 BGP_STR
9492 "Address family\n"
9493 "Detailed information on TCP and BGP neighbor connections\n"
9494 "Neighbor to display information about\n"
9495 "Neighbor to display information about\n"
9496 "Display detailed prefix count information\n")
9497{
9498 struct peer *peer;
9499
9500 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9501 if (! peer)
9502 return CMD_WARNING;
9503
9504 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9505}
9506
9507DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9508 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9509 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9510 SHOW_STR
9511 IP_STR
9512 BGP_STR
9513 "Address family\n"
9514 "Address Family modifier\n"
9515 "Address Family modifier\n"
9516 "Detailed information on TCP and BGP neighbor connections\n"
9517 "Neighbor to display information about\n"
9518 "Neighbor to display information about\n"
9519 "Display detailed prefix count information\n")
9520{
9521 struct peer *peer;
9522
9523 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9524 if (! peer)
9525 return CMD_WARNING;
9526
9527 if (strncmp (argv[0], "m", 1) == 0)
9528 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9529
9530 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9531}
9532
9533DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9534 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9535 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9536 SHOW_STR
9537 IP_STR
9538 BGP_STR
9539 "Address family\n"
9540 "Address Family modifier\n"
9541 "Address Family modifier\n"
9542 "Detailed information on TCP and BGP neighbor connections\n"
9543 "Neighbor to display information about\n"
9544 "Neighbor to display information about\n"
9545 "Display detailed prefix count information\n")
9546{
9547 struct peer *peer;
9548
9549 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9550 if (! peer)
9551 return CMD_WARNING;
9552
9553 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9554}
9555
9556
paul94f2b392005-06-28 12:44:16 +00009557static void
paul718e3742002-12-13 20:15:29 +00009558show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9559 int in)
9560{
9561 struct bgp_table *table;
9562 struct bgp_adj_in *ain;
9563 struct bgp_adj_out *adj;
9564 unsigned long output_count;
9565 struct bgp_node *rn;
9566 int header1 = 1;
9567 struct bgp *bgp;
9568 int header2 = 1;
9569
paulbb46e942003-10-24 19:02:03 +00009570 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009571
9572 if (! bgp)
9573 return;
9574
9575 table = bgp->rib[afi][safi];
9576
9577 output_count = 0;
9578
9579 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9580 PEER_STATUS_DEFAULT_ORIGINATE))
9581 {
9582 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 +00009583 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9584 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009585
9586 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9587 VTY_NEWLINE, VTY_NEWLINE);
9588 header1 = 0;
9589 }
9590
9591 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9592 if (in)
9593 {
9594 for (ain = rn->adj_in; ain; ain = ain->next)
9595 if (ain->peer == peer)
9596 {
9597 if (header1)
9598 {
9599 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 +00009600 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9601 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009602 header1 = 0;
9603 }
9604 if (header2)
9605 {
9606 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9607 header2 = 0;
9608 }
9609 if (ain->attr)
9610 {
9611 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9612 output_count++;
9613 }
9614 }
9615 }
9616 else
9617 {
9618 for (adj = rn->adj_out; adj; adj = adj->next)
9619 if (adj->peer == peer)
9620 {
9621 if (header1)
9622 {
9623 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 +00009624 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9625 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009626 header1 = 0;
9627 }
9628 if (header2)
9629 {
9630 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9631 header2 = 0;
9632 }
9633 if (adj->attr)
9634 {
9635 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9636 output_count++;
9637 }
9638 }
9639 }
9640
9641 if (output_count != 0)
9642 vty_out (vty, "%sTotal number of prefixes %ld%s",
9643 VTY_NEWLINE, output_count, VTY_NEWLINE);
9644}
9645
paul94f2b392005-06-28 12:44:16 +00009646static int
paulbb46e942003-10-24 19:02:03 +00009647peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9648{
paul718e3742002-12-13 20:15:29 +00009649 if (! peer || ! peer->afc[afi][safi])
9650 {
9651 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9652 return CMD_WARNING;
9653 }
9654
9655 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9656 {
9657 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9658 VTY_NEWLINE);
9659 return CMD_WARNING;
9660 }
9661
9662 show_adj_route (vty, peer, afi, safi, in);
9663
9664 return CMD_SUCCESS;
9665}
9666
9667DEFUN (show_ip_bgp_neighbor_advertised_route,
9668 show_ip_bgp_neighbor_advertised_route_cmd,
9669 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9670 SHOW_STR
9671 IP_STR
9672 BGP_STR
9673 "Detailed information on TCP and BGP neighbor connections\n"
9674 "Neighbor to display information about\n"
9675 "Neighbor to display information about\n"
9676 "Display the routes advertised to a BGP neighbor\n")
9677{
paulbb46e942003-10-24 19:02:03 +00009678 struct peer *peer;
9679
9680 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9681 if (! peer)
9682 return CMD_WARNING;
9683
9684 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009685}
9686
9687DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9688 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9689 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9690 SHOW_STR
9691 IP_STR
9692 BGP_STR
9693 "Address family\n"
9694 "Address Family modifier\n"
9695 "Address Family modifier\n"
9696 "Detailed information on TCP and BGP neighbor connections\n"
9697 "Neighbor to display information about\n"
9698 "Neighbor to display information about\n"
9699 "Display the routes advertised to a BGP neighbor\n")
9700{
paulbb46e942003-10-24 19:02:03 +00009701 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009702
paulbb46e942003-10-24 19:02:03 +00009703 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9704 if (! peer)
9705 return CMD_WARNING;
9706
9707 if (strncmp (argv[0], "m", 1) == 0)
9708 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9709
9710 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009711}
9712
9713#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009714DEFUN (show_bgp_view_neighbor_advertised_route,
9715 show_bgp_view_neighbor_advertised_route_cmd,
9716 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9717 SHOW_STR
9718 BGP_STR
9719 "BGP view\n"
9720 "View name\n"
9721 "Detailed information on TCP and BGP neighbor connections\n"
9722 "Neighbor to display information about\n"
9723 "Neighbor to display information about\n"
9724 "Display the routes advertised to a BGP neighbor\n")
9725{
9726 struct peer *peer;
9727
9728 if (argc == 2)
9729 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9730 else
9731 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9732
9733 if (! peer)
9734 return CMD_WARNING;
9735
9736 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9737}
9738
9739ALIAS (show_bgp_view_neighbor_advertised_route,
9740 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9741 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9742 SHOW_STR
9743 BGP_STR
9744 "BGP view\n"
9745 "View name\n"
9746 "Address family\n"
9747 "Detailed information on TCP and BGP neighbor connections\n"
9748 "Neighbor to display information about\n"
9749 "Neighbor to display information about\n"
9750 "Display the routes advertised to a BGP neighbor\n")
9751
9752DEFUN (show_bgp_view_neighbor_received_routes,
9753 show_bgp_view_neighbor_received_routes_cmd,
9754 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9755 SHOW_STR
9756 BGP_STR
9757 "BGP view\n"
9758 "View name\n"
9759 "Detailed information on TCP and BGP neighbor connections\n"
9760 "Neighbor to display information about\n"
9761 "Neighbor to display information about\n"
9762 "Display the received routes from neighbor\n")
9763{
9764 struct peer *peer;
9765
9766 if (argc == 2)
9767 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9768 else
9769 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9770
9771 if (! peer)
9772 return CMD_WARNING;
9773
9774 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9775}
9776
9777ALIAS (show_bgp_view_neighbor_received_routes,
9778 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9779 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9780 SHOW_STR
9781 BGP_STR
9782 "BGP view\n"
9783 "View name\n"
9784 "Address family\n"
9785 "Detailed information on TCP and BGP neighbor connections\n"
9786 "Neighbor to display information about\n"
9787 "Neighbor to display information about\n"
9788 "Display the received routes from neighbor\n")
9789
9790ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009791 show_bgp_neighbor_advertised_route_cmd,
9792 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9793 SHOW_STR
9794 BGP_STR
9795 "Detailed information on TCP and BGP neighbor connections\n"
9796 "Neighbor to display information about\n"
9797 "Neighbor to display information about\n"
9798 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009799
9800ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009801 show_bgp_ipv6_neighbor_advertised_route_cmd,
9802 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9803 SHOW_STR
9804 BGP_STR
9805 "Address family\n"
9806 "Detailed information on TCP and BGP neighbor connections\n"
9807 "Neighbor to display information about\n"
9808 "Neighbor to display information about\n"
9809 "Display the routes advertised to a BGP neighbor\n")
9810
9811/* old command */
paulbb46e942003-10-24 19:02:03 +00009812ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009813 ipv6_bgp_neighbor_advertised_route_cmd,
9814 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9815 SHOW_STR
9816 IPV6_STR
9817 BGP_STR
9818 "Detailed information on TCP and BGP neighbor connections\n"
9819 "Neighbor to display information about\n"
9820 "Neighbor to display information about\n"
9821 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009822
paul718e3742002-12-13 20:15:29 +00009823/* old command */
9824DEFUN (ipv6_mbgp_neighbor_advertised_route,
9825 ipv6_mbgp_neighbor_advertised_route_cmd,
9826 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9827 SHOW_STR
9828 IPV6_STR
9829 MBGP_STR
9830 "Detailed information on TCP and BGP neighbor connections\n"
9831 "Neighbor to display information about\n"
9832 "Neighbor to display information about\n"
9833 "Display the routes advertised to a BGP neighbor\n")
9834{
paulbb46e942003-10-24 19:02:03 +00009835 struct peer *peer;
9836
9837 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9838 if (! peer)
9839 return CMD_WARNING;
9840
9841 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009842}
9843#endif /* HAVE_IPV6 */
9844
9845DEFUN (show_ip_bgp_neighbor_received_routes,
9846 show_ip_bgp_neighbor_received_routes_cmd,
9847 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9848 SHOW_STR
9849 IP_STR
9850 BGP_STR
9851 "Detailed information on TCP and BGP neighbor connections\n"
9852 "Neighbor to display information about\n"
9853 "Neighbor to display information about\n"
9854 "Display the received routes from neighbor\n")
9855{
paulbb46e942003-10-24 19:02:03 +00009856 struct peer *peer;
9857
9858 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9859 if (! peer)
9860 return CMD_WARNING;
9861
9862 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009863}
9864
9865DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9866 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9867 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9868 SHOW_STR
9869 IP_STR
9870 BGP_STR
9871 "Address family\n"
9872 "Address Family modifier\n"
9873 "Address Family modifier\n"
9874 "Detailed information on TCP and BGP neighbor connections\n"
9875 "Neighbor to display information about\n"
9876 "Neighbor to display information about\n"
9877 "Display the received routes from neighbor\n")
9878{
paulbb46e942003-10-24 19:02:03 +00009879 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009880
paulbb46e942003-10-24 19:02:03 +00009881 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9882 if (! peer)
9883 return CMD_WARNING;
9884
9885 if (strncmp (argv[0], "m", 1) == 0)
9886 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9887
9888 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009889}
9890
9891DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9892 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9893 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9894 SHOW_STR
9895 IP_STR
9896 BGP_STR
9897 "Detailed information on TCP and BGP neighbor connections\n"
9898 "Neighbor to display information about\n"
9899 "Neighbor to display information about\n"
9900 "Display information received from a BGP neighbor\n"
9901 "Display the prefixlist filter\n")
9902{
9903 char name[BUFSIZ];
9904 union sockunion *su;
9905 struct peer *peer;
9906 int count;
9907
9908 su = sockunion_str2su (argv[0]);
9909 if (su == NULL)
9910 return CMD_WARNING;
9911
9912 peer = peer_lookup (NULL, su);
9913 if (! peer)
9914 return CMD_WARNING;
9915
9916 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9917 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9918 if (count)
9919 {
9920 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9921 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9922 }
9923
9924 return CMD_SUCCESS;
9925}
9926
9927DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9928 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9929 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9930 SHOW_STR
9931 IP_STR
9932 BGP_STR
9933 "Address family\n"
9934 "Address Family modifier\n"
9935 "Address Family modifier\n"
9936 "Detailed information on TCP and BGP neighbor connections\n"
9937 "Neighbor to display information about\n"
9938 "Neighbor to display information about\n"
9939 "Display information received from a BGP neighbor\n"
9940 "Display the prefixlist filter\n")
9941{
9942 char name[BUFSIZ];
9943 union sockunion *su;
9944 struct peer *peer;
9945 int count;
9946
9947 su = sockunion_str2su (argv[1]);
9948 if (su == NULL)
9949 return CMD_WARNING;
9950
9951 peer = peer_lookup (NULL, su);
9952 if (! peer)
9953 return CMD_WARNING;
9954
9955 if (strncmp (argv[0], "m", 1) == 0)
9956 {
9957 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9958 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9959 if (count)
9960 {
9961 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9962 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9963 }
9964 }
9965 else
9966 {
9967 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9968 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9969 if (count)
9970 {
9971 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9972 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9973 }
9974 }
9975
9976 return CMD_SUCCESS;
9977}
9978
9979
9980#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009981ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009982 show_bgp_neighbor_received_routes_cmd,
9983 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9984 SHOW_STR
9985 BGP_STR
9986 "Detailed information on TCP and BGP neighbor connections\n"
9987 "Neighbor to display information about\n"
9988 "Neighbor to display information about\n"
9989 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009990
paulbb46e942003-10-24 19:02:03 +00009991ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009992 show_bgp_ipv6_neighbor_received_routes_cmd,
9993 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9994 SHOW_STR
9995 BGP_STR
9996 "Address family\n"
9997 "Detailed information on TCP and BGP neighbor connections\n"
9998 "Neighbor to display information about\n"
9999 "Neighbor to display information about\n"
10000 "Display the received routes from neighbor\n")
10001
10002DEFUN (show_bgp_neighbor_received_prefix_filter,
10003 show_bgp_neighbor_received_prefix_filter_cmd,
10004 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10005 SHOW_STR
10006 BGP_STR
10007 "Detailed information on TCP and BGP neighbor connections\n"
10008 "Neighbor to display information about\n"
10009 "Neighbor to display information about\n"
10010 "Display information received from a BGP neighbor\n"
10011 "Display the prefixlist filter\n")
10012{
10013 char name[BUFSIZ];
10014 union sockunion *su;
10015 struct peer *peer;
10016 int count;
10017
10018 su = sockunion_str2su (argv[0]);
10019 if (su == NULL)
10020 return CMD_WARNING;
10021
10022 peer = peer_lookup (NULL, su);
10023 if (! peer)
10024 return CMD_WARNING;
10025
10026 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10027 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10028 if (count)
10029 {
10030 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10031 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10032 }
10033
10034 return CMD_SUCCESS;
10035}
10036
10037ALIAS (show_bgp_neighbor_received_prefix_filter,
10038 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10039 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10040 SHOW_STR
10041 BGP_STR
10042 "Address family\n"
10043 "Detailed information on TCP and BGP neighbor connections\n"
10044 "Neighbor to display information about\n"
10045 "Neighbor to display information about\n"
10046 "Display information received from a BGP neighbor\n"
10047 "Display the prefixlist filter\n")
10048
10049/* old command */
paulbb46e942003-10-24 19:02:03 +000010050ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010051 ipv6_bgp_neighbor_received_routes_cmd,
10052 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10053 SHOW_STR
10054 IPV6_STR
10055 BGP_STR
10056 "Detailed information on TCP and BGP neighbor connections\n"
10057 "Neighbor to display information about\n"
10058 "Neighbor to display information about\n"
10059 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010060
10061/* old command */
10062DEFUN (ipv6_mbgp_neighbor_received_routes,
10063 ipv6_mbgp_neighbor_received_routes_cmd,
10064 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10065 SHOW_STR
10066 IPV6_STR
10067 MBGP_STR
10068 "Detailed information on TCP and BGP neighbor connections\n"
10069 "Neighbor to display information about\n"
10070 "Neighbor to display information about\n"
10071 "Display the received routes from neighbor\n")
10072{
paulbb46e942003-10-24 19:02:03 +000010073 struct peer *peer;
10074
10075 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10076 if (! peer)
10077 return CMD_WARNING;
10078
10079 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010080}
paulbb46e942003-10-24 19:02:03 +000010081
10082DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10083 show_bgp_view_neighbor_received_prefix_filter_cmd,
10084 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10085 SHOW_STR
10086 BGP_STR
10087 "BGP view\n"
10088 "View name\n"
10089 "Detailed information on TCP and BGP neighbor connections\n"
10090 "Neighbor to display information about\n"
10091 "Neighbor to display information about\n"
10092 "Display information received from a BGP neighbor\n"
10093 "Display the prefixlist filter\n")
10094{
10095 char name[BUFSIZ];
10096 union sockunion *su;
10097 struct peer *peer;
10098 struct bgp *bgp;
10099 int count;
10100
10101 /* BGP structure lookup. */
10102 bgp = bgp_lookup_by_name (argv[0]);
10103 if (bgp == NULL)
10104 {
10105 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10106 return CMD_WARNING;
10107 }
10108
10109 su = sockunion_str2su (argv[1]);
10110 if (su == NULL)
10111 return CMD_WARNING;
10112
10113 peer = peer_lookup (bgp, su);
10114 if (! peer)
10115 return CMD_WARNING;
10116
10117 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10118 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10119 if (count)
10120 {
10121 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10122 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10123 }
10124
10125 return CMD_SUCCESS;
10126}
10127
10128ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10129 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10130 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10131 SHOW_STR
10132 BGP_STR
10133 "BGP view\n"
10134 "View name\n"
10135 "Address family\n"
10136 "Detailed information on TCP and BGP neighbor connections\n"
10137 "Neighbor to display information about\n"
10138 "Neighbor to display information about\n"
10139 "Display information received from a BGP neighbor\n"
10140 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010141#endif /* HAVE_IPV6 */
10142
paul94f2b392005-06-28 12:44:16 +000010143static int
paulbb46e942003-10-24 19:02:03 +000010144bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010145 safi_t safi, enum bgp_show_type type)
10146{
paul718e3742002-12-13 20:15:29 +000010147 if (! peer || ! peer->afc[afi][safi])
10148 {
10149 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010150 return CMD_WARNING;
10151 }
10152
ajs5a646652004-11-05 01:25:55 +000010153 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010154}
10155
10156DEFUN (show_ip_bgp_neighbor_routes,
10157 show_ip_bgp_neighbor_routes_cmd,
10158 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10159 SHOW_STR
10160 IP_STR
10161 BGP_STR
10162 "Detailed information on TCP and BGP neighbor connections\n"
10163 "Neighbor to display information about\n"
10164 "Neighbor to display information about\n"
10165 "Display routes learned from neighbor\n")
10166{
paulbb46e942003-10-24 19:02:03 +000010167 struct peer *peer;
10168
10169 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10170 if (! peer)
10171 return CMD_WARNING;
10172
10173 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010174 bgp_show_type_neighbor);
10175}
10176
10177DEFUN (show_ip_bgp_neighbor_flap,
10178 show_ip_bgp_neighbor_flap_cmd,
10179 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10180 SHOW_STR
10181 IP_STR
10182 BGP_STR
10183 "Detailed information on TCP and BGP neighbor connections\n"
10184 "Neighbor to display information about\n"
10185 "Neighbor to display information about\n"
10186 "Display flap statistics of the routes learned from neighbor\n")
10187{
paulbb46e942003-10-24 19:02:03 +000010188 struct peer *peer;
10189
10190 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10191 if (! peer)
10192 return CMD_WARNING;
10193
10194 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010195 bgp_show_type_flap_neighbor);
10196}
10197
10198DEFUN (show_ip_bgp_neighbor_damp,
10199 show_ip_bgp_neighbor_damp_cmd,
10200 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10201 SHOW_STR
10202 IP_STR
10203 BGP_STR
10204 "Detailed information on TCP and BGP neighbor connections\n"
10205 "Neighbor to display information about\n"
10206 "Neighbor to display information about\n"
10207 "Display the dampened routes received from neighbor\n")
10208{
paulbb46e942003-10-24 19:02:03 +000010209 struct peer *peer;
10210
10211 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10212 if (! peer)
10213 return CMD_WARNING;
10214
10215 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010216 bgp_show_type_damp_neighbor);
10217}
10218
10219DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10220 show_ip_bgp_ipv4_neighbor_routes_cmd,
10221 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10222 SHOW_STR
10223 IP_STR
10224 BGP_STR
10225 "Address family\n"
10226 "Address Family modifier\n"
10227 "Address Family modifier\n"
10228 "Detailed information on TCP and BGP neighbor connections\n"
10229 "Neighbor to display information about\n"
10230 "Neighbor to display information about\n"
10231 "Display routes learned from neighbor\n")
10232{
paulbb46e942003-10-24 19:02:03 +000010233 struct peer *peer;
10234
10235 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10236 if (! peer)
10237 return CMD_WARNING;
10238
paul718e3742002-12-13 20:15:29 +000010239 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010240 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010241 bgp_show_type_neighbor);
10242
paulbb46e942003-10-24 19:02:03 +000010243 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010244 bgp_show_type_neighbor);
10245}
paulbb46e942003-10-24 19:02:03 +000010246
paulfee0f4c2004-09-13 05:12:46 +000010247DEFUN (show_ip_bgp_view_rsclient,
10248 show_ip_bgp_view_rsclient_cmd,
10249 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10250 SHOW_STR
10251 IP_STR
10252 BGP_STR
10253 "BGP view\n"
10254 "BGP view name\n"
10255 "Information about Route Server Client\n"
10256 NEIGHBOR_ADDR_STR)
10257{
10258 struct bgp_table *table;
10259 struct peer *peer;
10260
10261 if (argc == 2)
10262 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10263 else
10264 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10265
10266 if (! peer)
10267 return CMD_WARNING;
10268
10269 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10270 {
10271 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10272 VTY_NEWLINE);
10273 return CMD_WARNING;
10274 }
10275
10276 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10277 PEER_FLAG_RSERVER_CLIENT))
10278 {
10279 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10280 VTY_NEWLINE);
10281 return CMD_WARNING;
10282 }
10283
10284 table = peer->rib[AFI_IP][SAFI_UNICAST];
10285
ajs5a646652004-11-05 01:25:55 +000010286 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010287}
10288
10289ALIAS (show_ip_bgp_view_rsclient,
10290 show_ip_bgp_rsclient_cmd,
10291 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10292 SHOW_STR
10293 IP_STR
10294 BGP_STR
10295 "Information about Route Server Client\n"
10296 NEIGHBOR_ADDR_STR)
10297
10298DEFUN (show_ip_bgp_view_rsclient_route,
10299 show_ip_bgp_view_rsclient_route_cmd,
10300 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10301 SHOW_STR
10302 IP_STR
10303 BGP_STR
10304 "BGP view\n"
10305 "BGP view name\n"
10306 "Information about Route Server Client\n"
10307 NEIGHBOR_ADDR_STR
10308 "Network in the BGP routing table to display\n")
10309{
10310 struct bgp *bgp;
10311 struct peer *peer;
10312
10313 /* BGP structure lookup. */
10314 if (argc == 3)
10315 {
10316 bgp = bgp_lookup_by_name (argv[0]);
10317 if (bgp == NULL)
10318 {
10319 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10320 return CMD_WARNING;
10321 }
10322 }
10323 else
10324 {
10325 bgp = bgp_get_default ();
10326 if (bgp == NULL)
10327 {
10328 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10329 return CMD_WARNING;
10330 }
10331 }
10332
10333 if (argc == 3)
10334 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10335 else
10336 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10337
10338 if (! peer)
10339 return CMD_WARNING;
10340
10341 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10342 {
10343 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10344 VTY_NEWLINE);
10345 return CMD_WARNING;
10346}
10347
10348 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10349 PEER_FLAG_RSERVER_CLIENT))
10350 {
10351 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10352 VTY_NEWLINE);
10353 return CMD_WARNING;
10354 }
10355
10356 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10357 (argc == 3) ? argv[2] : argv[1],
10358 AFI_IP, SAFI_UNICAST, NULL, 0);
10359}
10360
10361ALIAS (show_ip_bgp_view_rsclient_route,
10362 show_ip_bgp_rsclient_route_cmd,
10363 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10364 SHOW_STR
10365 IP_STR
10366 BGP_STR
10367 "Information about Route Server Client\n"
10368 NEIGHBOR_ADDR_STR
10369 "Network in the BGP routing table to display\n")
10370
10371DEFUN (show_ip_bgp_view_rsclient_prefix,
10372 show_ip_bgp_view_rsclient_prefix_cmd,
10373 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10374 SHOW_STR
10375 IP_STR
10376 BGP_STR
10377 "BGP view\n"
10378 "BGP view name\n"
10379 "Information about Route Server Client\n"
10380 NEIGHBOR_ADDR_STR
10381 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10382{
10383 struct bgp *bgp;
10384 struct peer *peer;
10385
10386 /* BGP structure lookup. */
10387 if (argc == 3)
10388 {
10389 bgp = bgp_lookup_by_name (argv[0]);
10390 if (bgp == NULL)
10391 {
10392 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10393 return CMD_WARNING;
10394 }
10395 }
10396 else
10397 {
10398 bgp = bgp_get_default ();
10399 if (bgp == NULL)
10400 {
10401 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10402 return CMD_WARNING;
10403 }
10404 }
10405
10406 if (argc == 3)
10407 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10408 else
10409 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10410
10411 if (! peer)
10412 return CMD_WARNING;
10413
10414 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10415 {
10416 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10417 VTY_NEWLINE);
10418 return CMD_WARNING;
10419}
10420
10421 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10422 PEER_FLAG_RSERVER_CLIENT))
10423{
10424 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10425 VTY_NEWLINE);
10426 return CMD_WARNING;
10427 }
10428
10429 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10430 (argc == 3) ? argv[2] : argv[1],
10431 AFI_IP, SAFI_UNICAST, NULL, 1);
10432}
10433
10434ALIAS (show_ip_bgp_view_rsclient_prefix,
10435 show_ip_bgp_rsclient_prefix_cmd,
10436 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10437 SHOW_STR
10438 IP_STR
10439 BGP_STR
10440 "Information about Route Server Client\n"
10441 NEIGHBOR_ADDR_STR
10442 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10443
10444
paul718e3742002-12-13 20:15:29 +000010445#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010446DEFUN (show_bgp_view_neighbor_routes,
10447 show_bgp_view_neighbor_routes_cmd,
10448 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10449 SHOW_STR
10450 BGP_STR
10451 "BGP view\n"
10452 "BGP view name\n"
10453 "Detailed information on TCP and BGP neighbor connections\n"
10454 "Neighbor to display information about\n"
10455 "Neighbor to display information about\n"
10456 "Display routes learned from neighbor\n")
10457{
10458 struct peer *peer;
10459
10460 if (argc == 2)
10461 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10462 else
10463 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10464
10465 if (! peer)
10466 return CMD_WARNING;
10467
10468 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10469 bgp_show_type_neighbor);
10470}
10471
10472ALIAS (show_bgp_view_neighbor_routes,
10473 show_bgp_view_ipv6_neighbor_routes_cmd,
10474 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10475 SHOW_STR
10476 BGP_STR
10477 "BGP view\n"
10478 "BGP view name\n"
10479 "Address family\n"
10480 "Detailed information on TCP and BGP neighbor connections\n"
10481 "Neighbor to display information about\n"
10482 "Neighbor to display information about\n"
10483 "Display routes learned from neighbor\n")
10484
10485DEFUN (show_bgp_view_neighbor_damp,
10486 show_bgp_view_neighbor_damp_cmd,
10487 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10488 SHOW_STR
10489 BGP_STR
10490 "BGP view\n"
10491 "BGP view name\n"
10492 "Detailed information on TCP and BGP neighbor connections\n"
10493 "Neighbor to display information about\n"
10494 "Neighbor to display information about\n"
10495 "Display the dampened routes received from neighbor\n")
10496{
10497 struct peer *peer;
10498
10499 if (argc == 2)
10500 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10501 else
10502 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10503
10504 if (! peer)
10505 return CMD_WARNING;
10506
10507 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10508 bgp_show_type_damp_neighbor);
10509}
10510
10511ALIAS (show_bgp_view_neighbor_damp,
10512 show_bgp_view_ipv6_neighbor_damp_cmd,
10513 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10514 SHOW_STR
10515 BGP_STR
10516 "BGP view\n"
10517 "BGP view name\n"
10518 "Address family\n"
10519 "Detailed information on TCP and BGP neighbor connections\n"
10520 "Neighbor to display information about\n"
10521 "Neighbor to display information about\n"
10522 "Display the dampened routes received from neighbor\n")
10523
10524DEFUN (show_bgp_view_neighbor_flap,
10525 show_bgp_view_neighbor_flap_cmd,
10526 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10527 SHOW_STR
10528 BGP_STR
10529 "BGP view\n"
10530 "BGP view name\n"
10531 "Detailed information on TCP and BGP neighbor connections\n"
10532 "Neighbor to display information about\n"
10533 "Neighbor to display information about\n"
10534 "Display flap statistics of the routes learned from neighbor\n")
10535{
10536 struct peer *peer;
10537
10538 if (argc == 2)
10539 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10540 else
10541 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10542
10543 if (! peer)
10544 return CMD_WARNING;
10545
10546 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10547 bgp_show_type_flap_neighbor);
10548}
10549
10550ALIAS (show_bgp_view_neighbor_flap,
10551 show_bgp_view_ipv6_neighbor_flap_cmd,
10552 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10553 SHOW_STR
10554 BGP_STR
10555 "BGP view\n"
10556 "BGP view name\n"
10557 "Address family\n"
10558 "Detailed information on TCP and BGP neighbor connections\n"
10559 "Neighbor to display information about\n"
10560 "Neighbor to display information about\n"
10561 "Display flap statistics of the routes learned from neighbor\n")
10562
10563ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010564 show_bgp_neighbor_routes_cmd,
10565 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10566 SHOW_STR
10567 BGP_STR
10568 "Detailed information on TCP and BGP neighbor connections\n"
10569 "Neighbor to display information about\n"
10570 "Neighbor to display information about\n"
10571 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010572
paulbb46e942003-10-24 19:02:03 +000010573
10574ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010575 show_bgp_ipv6_neighbor_routes_cmd,
10576 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10577 SHOW_STR
10578 BGP_STR
10579 "Address family\n"
10580 "Detailed information on TCP and BGP neighbor connections\n"
10581 "Neighbor to display information about\n"
10582 "Neighbor to display information about\n"
10583 "Display routes learned from neighbor\n")
10584
10585/* old command */
paulbb46e942003-10-24 19:02:03 +000010586ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010587 ipv6_bgp_neighbor_routes_cmd,
10588 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10589 SHOW_STR
10590 IPV6_STR
10591 BGP_STR
10592 "Detailed information on TCP and BGP neighbor connections\n"
10593 "Neighbor to display information about\n"
10594 "Neighbor to display information about\n"
10595 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010596
10597/* old command */
10598DEFUN (ipv6_mbgp_neighbor_routes,
10599 ipv6_mbgp_neighbor_routes_cmd,
10600 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10601 SHOW_STR
10602 IPV6_STR
10603 MBGP_STR
10604 "Detailed information on TCP and BGP neighbor connections\n"
10605 "Neighbor to display information about\n"
10606 "Neighbor to display information about\n"
10607 "Display routes learned from neighbor\n")
10608{
paulbb46e942003-10-24 19:02:03 +000010609 struct peer *peer;
10610
10611 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10612 if (! peer)
10613 return CMD_WARNING;
10614
10615 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010616 bgp_show_type_neighbor);
10617}
paulbb46e942003-10-24 19:02:03 +000010618
10619ALIAS (show_bgp_view_neighbor_flap,
10620 show_bgp_neighbor_flap_cmd,
10621 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10622 SHOW_STR
10623 BGP_STR
10624 "Detailed information on TCP and BGP neighbor connections\n"
10625 "Neighbor to display information about\n"
10626 "Neighbor to display information about\n"
10627 "Display flap statistics of the routes learned from neighbor\n")
10628
10629ALIAS (show_bgp_view_neighbor_flap,
10630 show_bgp_ipv6_neighbor_flap_cmd,
10631 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10632 SHOW_STR
10633 BGP_STR
10634 "Address family\n"
10635 "Detailed information on TCP and BGP neighbor connections\n"
10636 "Neighbor to display information about\n"
10637 "Neighbor to display information about\n"
10638 "Display flap statistics of the routes learned from neighbor\n")
10639
10640ALIAS (show_bgp_view_neighbor_damp,
10641 show_bgp_neighbor_damp_cmd,
10642 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10643 SHOW_STR
10644 BGP_STR
10645 "Detailed information on TCP and BGP neighbor connections\n"
10646 "Neighbor to display information about\n"
10647 "Neighbor to display information about\n"
10648 "Display the dampened routes received from neighbor\n")
10649
10650ALIAS (show_bgp_view_neighbor_damp,
10651 show_bgp_ipv6_neighbor_damp_cmd,
10652 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10653 SHOW_STR
10654 BGP_STR
10655 "Address family\n"
10656 "Detailed information on TCP and BGP neighbor connections\n"
10657 "Neighbor to display information about\n"
10658 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010659 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010660
10661DEFUN (show_bgp_view_rsclient,
10662 show_bgp_view_rsclient_cmd,
10663 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10664 SHOW_STR
10665 BGP_STR
10666 "BGP view\n"
10667 "BGP view name\n"
10668 "Information about Route Server Client\n"
10669 NEIGHBOR_ADDR_STR)
10670{
10671 struct bgp_table *table;
10672 struct peer *peer;
10673
10674 if (argc == 2)
10675 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10676 else
10677 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10678
10679 if (! peer)
10680 return CMD_WARNING;
10681
10682 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10683 {
10684 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10685 VTY_NEWLINE);
10686 return CMD_WARNING;
10687 }
10688
10689 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10690 PEER_FLAG_RSERVER_CLIENT))
10691 {
10692 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10693 VTY_NEWLINE);
10694 return CMD_WARNING;
10695 }
10696
10697 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10698
ajs5a646652004-11-05 01:25:55 +000010699 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010700}
10701
10702ALIAS (show_bgp_view_rsclient,
10703 show_bgp_rsclient_cmd,
10704 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10705 SHOW_STR
10706 BGP_STR
10707 "Information about Route Server Client\n"
10708 NEIGHBOR_ADDR_STR)
10709
10710DEFUN (show_bgp_view_rsclient_route,
10711 show_bgp_view_rsclient_route_cmd,
10712 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10713 SHOW_STR
10714 BGP_STR
10715 "BGP view\n"
10716 "BGP view name\n"
10717 "Information about Route Server Client\n"
10718 NEIGHBOR_ADDR_STR
10719 "Network in the BGP routing table to display\n")
10720{
10721 struct bgp *bgp;
10722 struct peer *peer;
10723
10724 /* BGP structure lookup. */
10725 if (argc == 3)
10726 {
10727 bgp = bgp_lookup_by_name (argv[0]);
10728 if (bgp == NULL)
10729 {
10730 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10731 return CMD_WARNING;
10732 }
10733 }
10734 else
10735 {
10736 bgp = bgp_get_default ();
10737 if (bgp == NULL)
10738 {
10739 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10740 return CMD_WARNING;
10741 }
10742 }
10743
10744 if (argc == 3)
10745 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10746 else
10747 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10748
10749 if (! peer)
10750 return CMD_WARNING;
10751
10752 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10753 {
10754 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10755 VTY_NEWLINE);
10756 return CMD_WARNING;
10757 }
10758
10759 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10760 PEER_FLAG_RSERVER_CLIENT))
10761 {
10762 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10763 VTY_NEWLINE);
10764 return CMD_WARNING;
10765 }
10766
10767 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10768 (argc == 3) ? argv[2] : argv[1],
10769 AFI_IP6, SAFI_UNICAST, NULL, 0);
10770}
10771
10772ALIAS (show_bgp_view_rsclient_route,
10773 show_bgp_rsclient_route_cmd,
10774 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10775 SHOW_STR
10776 BGP_STR
10777 "Information about Route Server Client\n"
10778 NEIGHBOR_ADDR_STR
10779 "Network in the BGP routing table to display\n")
10780
10781DEFUN (show_bgp_view_rsclient_prefix,
10782 show_bgp_view_rsclient_prefix_cmd,
10783 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10784 SHOW_STR
10785 BGP_STR
10786 "BGP view\n"
10787 "BGP view name\n"
10788 "Information about Route Server Client\n"
10789 NEIGHBOR_ADDR_STR
10790 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10791{
10792 struct bgp *bgp;
10793 struct peer *peer;
10794
10795 /* BGP structure lookup. */
10796 if (argc == 3)
10797 {
10798 bgp = bgp_lookup_by_name (argv[0]);
10799 if (bgp == NULL)
10800 {
10801 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10802 return CMD_WARNING;
10803 }
10804 }
10805 else
10806 {
10807 bgp = bgp_get_default ();
10808 if (bgp == NULL)
10809 {
10810 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10811 return CMD_WARNING;
10812 }
10813 }
10814
10815 if (argc == 3)
10816 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10817 else
10818 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10819
10820 if (! peer)
10821 return CMD_WARNING;
10822
10823 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10824 {
10825 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10826 VTY_NEWLINE);
10827 return CMD_WARNING;
10828 }
10829
10830 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10831 PEER_FLAG_RSERVER_CLIENT))
10832 {
10833 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10834 VTY_NEWLINE);
10835 return CMD_WARNING;
10836 }
10837
10838 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10839 (argc == 3) ? argv[2] : argv[1],
10840 AFI_IP6, SAFI_UNICAST, NULL, 1);
10841}
10842
10843ALIAS (show_bgp_view_rsclient_prefix,
10844 show_bgp_rsclient_prefix_cmd,
10845 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10846 SHOW_STR
10847 BGP_STR
10848 "Information about Route Server Client\n"
10849 NEIGHBOR_ADDR_STR
10850 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10851
paul718e3742002-12-13 20:15:29 +000010852#endif /* HAVE_IPV6 */
10853
10854struct bgp_table *bgp_distance_table;
10855
10856struct bgp_distance
10857{
10858 /* Distance value for the IP source prefix. */
10859 u_char distance;
10860
10861 /* Name of the access-list to be matched. */
10862 char *access_list;
10863};
10864
paul94f2b392005-06-28 12:44:16 +000010865static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +000010866bgp_distance_new ()
10867{
10868 struct bgp_distance *new;
10869 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
10870 memset (new, 0, sizeof (struct bgp_distance));
10871 return new;
10872}
10873
paul94f2b392005-06-28 12:44:16 +000010874static void
paul718e3742002-12-13 20:15:29 +000010875bgp_distance_free (struct bgp_distance *bdistance)
10876{
10877 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10878}
10879
paul94f2b392005-06-28 12:44:16 +000010880static int
paulfd79ac92004-10-13 05:06:08 +000010881bgp_distance_set (struct vty *vty, const char *distance_str,
10882 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010883{
10884 int ret;
10885 struct prefix_ipv4 p;
10886 u_char distance;
10887 struct bgp_node *rn;
10888 struct bgp_distance *bdistance;
10889
10890 ret = str2prefix_ipv4 (ip_str, &p);
10891 if (ret == 0)
10892 {
10893 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10894 return CMD_WARNING;
10895 }
10896
10897 distance = atoi (distance_str);
10898
10899 /* Get BGP distance node. */
10900 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10901 if (rn->info)
10902 {
10903 bdistance = rn->info;
10904 bgp_unlock_node (rn);
10905 }
10906 else
10907 {
10908 bdistance = bgp_distance_new ();
10909 rn->info = bdistance;
10910 }
10911
10912 /* Set distance value. */
10913 bdistance->distance = distance;
10914
10915 /* Reset access-list configuration. */
10916 if (bdistance->access_list)
10917 {
10918 free (bdistance->access_list);
10919 bdistance->access_list = NULL;
10920 }
10921 if (access_list_str)
10922 bdistance->access_list = strdup (access_list_str);
10923
10924 return CMD_SUCCESS;
10925}
10926
paul94f2b392005-06-28 12:44:16 +000010927static int
paulfd79ac92004-10-13 05:06:08 +000010928bgp_distance_unset (struct vty *vty, const char *distance_str,
10929 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010930{
10931 int ret;
10932 struct prefix_ipv4 p;
10933 u_char distance;
10934 struct bgp_node *rn;
10935 struct bgp_distance *bdistance;
10936
10937 ret = str2prefix_ipv4 (ip_str, &p);
10938 if (ret == 0)
10939 {
10940 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10941 return CMD_WARNING;
10942 }
10943
10944 distance = atoi (distance_str);
10945
10946 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10947 if (! rn)
10948 {
10949 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10950 return CMD_WARNING;
10951 }
10952
10953 bdistance = rn->info;
10954
10955 if (bdistance->access_list)
10956 free (bdistance->access_list);
10957 bgp_distance_free (bdistance);
10958
10959 rn->info = NULL;
10960 bgp_unlock_node (rn);
10961 bgp_unlock_node (rn);
10962
10963 return CMD_SUCCESS;
10964}
10965
paul94f2b392005-06-28 12:44:16 +000010966static void
paul718e3742002-12-13 20:15:29 +000010967bgp_distance_reset ()
10968{
10969 struct bgp_node *rn;
10970 struct bgp_distance *bdistance;
10971
10972 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10973 if ((bdistance = rn->info) != NULL)
10974 {
10975 if (bdistance->access_list)
10976 free (bdistance->access_list);
10977 bgp_distance_free (bdistance);
10978 rn->info = NULL;
10979 bgp_unlock_node (rn);
10980 }
10981}
10982
10983/* Apply BGP information to distance method. */
10984u_char
10985bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10986{
10987 struct bgp_node *rn;
10988 struct prefix_ipv4 q;
10989 struct peer *peer;
10990 struct bgp_distance *bdistance;
10991 struct access_list *alist;
10992 struct bgp_static *bgp_static;
10993
10994 if (! bgp)
10995 return 0;
10996
10997 if (p->family != AF_INET)
10998 return 0;
10999
11000 peer = rinfo->peer;
11001
11002 if (peer->su.sa.sa_family != AF_INET)
11003 return 0;
11004
11005 memset (&q, 0, sizeof (struct prefix_ipv4));
11006 q.family = AF_INET;
11007 q.prefix = peer->su.sin.sin_addr;
11008 q.prefixlen = IPV4_MAX_BITLEN;
11009
11010 /* Check source address. */
11011 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11012 if (rn)
11013 {
11014 bdistance = rn->info;
11015 bgp_unlock_node (rn);
11016
11017 if (bdistance->access_list)
11018 {
11019 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11020 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11021 return bdistance->distance;
11022 }
11023 else
11024 return bdistance->distance;
11025 }
11026
11027 /* Backdoor check. */
11028 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11029 if (rn)
11030 {
11031 bgp_static = rn->info;
11032 bgp_unlock_node (rn);
11033
11034 if (bgp_static->backdoor)
11035 {
11036 if (bgp->distance_local)
11037 return bgp->distance_local;
11038 else
11039 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11040 }
11041 }
11042
11043 if (peer_sort (peer) == BGP_PEER_EBGP)
11044 {
11045 if (bgp->distance_ebgp)
11046 return bgp->distance_ebgp;
11047 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11048 }
11049 else
11050 {
11051 if (bgp->distance_ibgp)
11052 return bgp->distance_ibgp;
11053 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11054 }
11055}
11056
11057DEFUN (bgp_distance,
11058 bgp_distance_cmd,
11059 "distance bgp <1-255> <1-255> <1-255>",
11060 "Define an administrative distance\n"
11061 "BGP distance\n"
11062 "Distance for routes external to the AS\n"
11063 "Distance for routes internal to the AS\n"
11064 "Distance for local routes\n")
11065{
11066 struct bgp *bgp;
11067
11068 bgp = vty->index;
11069
11070 bgp->distance_ebgp = atoi (argv[0]);
11071 bgp->distance_ibgp = atoi (argv[1]);
11072 bgp->distance_local = atoi (argv[2]);
11073 return CMD_SUCCESS;
11074}
11075
11076DEFUN (no_bgp_distance,
11077 no_bgp_distance_cmd,
11078 "no distance bgp <1-255> <1-255> <1-255>",
11079 NO_STR
11080 "Define an administrative distance\n"
11081 "BGP distance\n"
11082 "Distance for routes external to the AS\n"
11083 "Distance for routes internal to the AS\n"
11084 "Distance for local routes\n")
11085{
11086 struct bgp *bgp;
11087
11088 bgp = vty->index;
11089
11090 bgp->distance_ebgp= 0;
11091 bgp->distance_ibgp = 0;
11092 bgp->distance_local = 0;
11093 return CMD_SUCCESS;
11094}
11095
11096ALIAS (no_bgp_distance,
11097 no_bgp_distance2_cmd,
11098 "no distance bgp",
11099 NO_STR
11100 "Define an administrative distance\n"
11101 "BGP distance\n")
11102
11103DEFUN (bgp_distance_source,
11104 bgp_distance_source_cmd,
11105 "distance <1-255> A.B.C.D/M",
11106 "Define an administrative distance\n"
11107 "Administrative distance\n"
11108 "IP source prefix\n")
11109{
11110 bgp_distance_set (vty, argv[0], argv[1], NULL);
11111 return CMD_SUCCESS;
11112}
11113
11114DEFUN (no_bgp_distance_source,
11115 no_bgp_distance_source_cmd,
11116 "no distance <1-255> A.B.C.D/M",
11117 NO_STR
11118 "Define an administrative distance\n"
11119 "Administrative distance\n"
11120 "IP source prefix\n")
11121{
11122 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11123 return CMD_SUCCESS;
11124}
11125
11126DEFUN (bgp_distance_source_access_list,
11127 bgp_distance_source_access_list_cmd,
11128 "distance <1-255> A.B.C.D/M WORD",
11129 "Define an administrative distance\n"
11130 "Administrative distance\n"
11131 "IP source prefix\n"
11132 "Access list name\n")
11133{
11134 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11135 return CMD_SUCCESS;
11136}
11137
11138DEFUN (no_bgp_distance_source_access_list,
11139 no_bgp_distance_source_access_list_cmd,
11140 "no distance <1-255> A.B.C.D/M WORD",
11141 NO_STR
11142 "Define an administrative distance\n"
11143 "Administrative distance\n"
11144 "IP source prefix\n"
11145 "Access list name\n")
11146{
11147 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11148 return CMD_SUCCESS;
11149}
11150
11151DEFUN (bgp_damp_set,
11152 bgp_damp_set_cmd,
11153 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11154 "BGP Specific commands\n"
11155 "Enable route-flap dampening\n"
11156 "Half-life time for the penalty\n"
11157 "Value to start reusing a route\n"
11158 "Value to start suppressing a route\n"
11159 "Maximum duration to suppress a stable route\n")
11160{
11161 struct bgp *bgp;
11162 int half = DEFAULT_HALF_LIFE * 60;
11163 int reuse = DEFAULT_REUSE;
11164 int suppress = DEFAULT_SUPPRESS;
11165 int max = 4 * half;
11166
11167 if (argc == 4)
11168 {
11169 half = atoi (argv[0]) * 60;
11170 reuse = atoi (argv[1]);
11171 suppress = atoi (argv[2]);
11172 max = atoi (argv[3]) * 60;
11173 }
11174 else if (argc == 1)
11175 {
11176 half = atoi (argv[0]) * 60;
11177 max = 4 * half;
11178 }
11179
11180 bgp = vty->index;
11181 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11182 half, reuse, suppress, max);
11183}
11184
11185ALIAS (bgp_damp_set,
11186 bgp_damp_set2_cmd,
11187 "bgp dampening <1-45>",
11188 "BGP Specific commands\n"
11189 "Enable route-flap dampening\n"
11190 "Half-life time for the penalty\n")
11191
11192ALIAS (bgp_damp_set,
11193 bgp_damp_set3_cmd,
11194 "bgp dampening",
11195 "BGP Specific commands\n"
11196 "Enable route-flap dampening\n")
11197
11198DEFUN (bgp_damp_unset,
11199 bgp_damp_unset_cmd,
11200 "no bgp dampening",
11201 NO_STR
11202 "BGP Specific commands\n"
11203 "Enable route-flap dampening\n")
11204{
11205 struct bgp *bgp;
11206
11207 bgp = vty->index;
11208 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11209}
11210
11211ALIAS (bgp_damp_unset,
11212 bgp_damp_unset2_cmd,
11213 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11214 NO_STR
11215 "BGP Specific commands\n"
11216 "Enable route-flap dampening\n"
11217 "Half-life time for the penalty\n"
11218 "Value to start reusing a route\n"
11219 "Value to start suppressing a route\n"
11220 "Maximum duration to suppress a stable route\n")
11221
11222DEFUN (show_ip_bgp_dampened_paths,
11223 show_ip_bgp_dampened_paths_cmd,
11224 "show ip bgp dampened-paths",
11225 SHOW_STR
11226 IP_STR
11227 BGP_STR
11228 "Display paths suppressed due to dampening\n")
11229{
ajs5a646652004-11-05 01:25:55 +000011230 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11231 NULL);
paul718e3742002-12-13 20:15:29 +000011232}
11233
11234DEFUN (show_ip_bgp_flap_statistics,
11235 show_ip_bgp_flap_statistics_cmd,
11236 "show ip bgp flap-statistics",
11237 SHOW_STR
11238 IP_STR
11239 BGP_STR
11240 "Display flap statistics of routes\n")
11241{
ajs5a646652004-11-05 01:25:55 +000011242 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11243 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011244}
11245
11246/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011247static int
paulfd79ac92004-10-13 05:06:08 +000011248bgp_clear_damp_route (struct vty *vty, const char *view_name,
11249 const char *ip_str, afi_t afi, safi_t safi,
11250 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011251{
11252 int ret;
11253 struct prefix match;
11254 struct bgp_node *rn;
11255 struct bgp_node *rm;
11256 struct bgp_info *ri;
11257 struct bgp_info *ri_temp;
11258 struct bgp *bgp;
11259 struct bgp_table *table;
11260
11261 /* BGP structure lookup. */
11262 if (view_name)
11263 {
11264 bgp = bgp_lookup_by_name (view_name);
11265 if (bgp == NULL)
11266 {
11267 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11268 return CMD_WARNING;
11269 }
11270 }
11271 else
11272 {
11273 bgp = bgp_get_default ();
11274 if (bgp == NULL)
11275 {
11276 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11277 return CMD_WARNING;
11278 }
11279 }
11280
11281 /* Check IP address argument. */
11282 ret = str2prefix (ip_str, &match);
11283 if (! ret)
11284 {
11285 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11286 return CMD_WARNING;
11287 }
11288
11289 match.family = afi2family (afi);
11290
11291 if (safi == SAFI_MPLS_VPN)
11292 {
11293 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11294 {
11295 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11296 continue;
11297
11298 if ((table = rn->info) != NULL)
11299 if ((rm = bgp_node_match (table, &match)) != NULL)
11300 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11301 {
11302 ri = rm->info;
11303 while (ri)
11304 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011305 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011306 {
11307 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011308 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011309 ri = ri_temp;
11310 }
11311 else
11312 ri = ri->next;
11313 }
11314 }
11315 }
11316 }
11317 else
11318 {
11319 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11320 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11321 {
11322 ri = rn->info;
11323 while (ri)
11324 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011325 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011326 {
11327 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011328 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011329 ri = ri_temp;
11330 }
11331 else
11332 ri = ri->next;
11333 }
11334 }
11335 }
11336
11337 return CMD_SUCCESS;
11338}
11339
11340DEFUN (clear_ip_bgp_dampening,
11341 clear_ip_bgp_dampening_cmd,
11342 "clear ip bgp dampening",
11343 CLEAR_STR
11344 IP_STR
11345 BGP_STR
11346 "Clear route flap dampening information\n")
11347{
11348 bgp_damp_info_clean ();
11349 return CMD_SUCCESS;
11350}
11351
11352DEFUN (clear_ip_bgp_dampening_prefix,
11353 clear_ip_bgp_dampening_prefix_cmd,
11354 "clear ip bgp dampening A.B.C.D/M",
11355 CLEAR_STR
11356 IP_STR
11357 BGP_STR
11358 "Clear route flap dampening information\n"
11359 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11360{
11361 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11362 SAFI_UNICAST, NULL, 1);
11363}
11364
11365DEFUN (clear_ip_bgp_dampening_address,
11366 clear_ip_bgp_dampening_address_cmd,
11367 "clear ip bgp dampening A.B.C.D",
11368 CLEAR_STR
11369 IP_STR
11370 BGP_STR
11371 "Clear route flap dampening information\n"
11372 "Network to clear damping information\n")
11373{
11374 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11375 SAFI_UNICAST, NULL, 0);
11376}
11377
11378DEFUN (clear_ip_bgp_dampening_address_mask,
11379 clear_ip_bgp_dampening_address_mask_cmd,
11380 "clear ip bgp dampening A.B.C.D A.B.C.D",
11381 CLEAR_STR
11382 IP_STR
11383 BGP_STR
11384 "Clear route flap dampening information\n"
11385 "Network to clear damping information\n"
11386 "Network mask\n")
11387{
11388 int ret;
11389 char prefix_str[BUFSIZ];
11390
11391 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11392 if (! ret)
11393 {
11394 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11395 return CMD_WARNING;
11396 }
11397
11398 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11399 SAFI_UNICAST, NULL, 0);
11400}
11401
paul94f2b392005-06-28 12:44:16 +000011402static int
paul718e3742002-12-13 20:15:29 +000011403bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11404 afi_t afi, safi_t safi, int *write)
11405{
11406 struct bgp_node *prn;
11407 struct bgp_node *rn;
11408 struct bgp_table *table;
11409 struct prefix *p;
11410 struct prefix_rd *prd;
11411 struct bgp_static *bgp_static;
11412 u_int32_t label;
11413 char buf[SU_ADDRSTRLEN];
11414 char rdbuf[RD_ADDRSTRLEN];
11415
11416 /* Network configuration. */
11417 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11418 if ((table = prn->info) != NULL)
11419 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11420 if ((bgp_static = rn->info) != NULL)
11421 {
11422 p = &rn->p;
11423 prd = (struct prefix_rd *) &prn->p;
11424
11425 /* "address-family" display. */
11426 bgp_config_write_family_header (vty, afi, safi, write);
11427
11428 /* "network" configuration display. */
11429 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11430 label = decode_label (bgp_static->tag);
11431
11432 vty_out (vty, " network %s/%d rd %s tag %d",
11433 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11434 p->prefixlen,
11435 rdbuf, label);
11436 vty_out (vty, "%s", VTY_NEWLINE);
11437 }
11438 return 0;
11439}
11440
11441/* Configuration of static route announcement and aggregate
11442 information. */
11443int
11444bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11445 afi_t afi, safi_t safi, int *write)
11446{
11447 struct bgp_node *rn;
11448 struct prefix *p;
11449 struct bgp_static *bgp_static;
11450 struct bgp_aggregate *bgp_aggregate;
11451 char buf[SU_ADDRSTRLEN];
11452
11453 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11454 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11455
11456 /* Network configuration. */
11457 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11458 if ((bgp_static = rn->info) != NULL)
11459 {
11460 p = &rn->p;
11461
11462 /* "address-family" display. */
11463 bgp_config_write_family_header (vty, afi, safi, write);
11464
11465 /* "network" configuration display. */
11466 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11467 {
11468 u_int32_t destination;
11469 struct in_addr netmask;
11470
11471 destination = ntohl (p->u.prefix4.s_addr);
11472 masklen2ip (p->prefixlen, &netmask);
11473 vty_out (vty, " network %s",
11474 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11475
11476 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11477 || (IN_CLASSB (destination) && p->prefixlen == 16)
11478 || (IN_CLASSA (destination) && p->prefixlen == 8)
11479 || p->u.prefix4.s_addr == 0)
11480 {
11481 /* Natural mask is not display. */
11482 }
11483 else
11484 vty_out (vty, " mask %s", inet_ntoa (netmask));
11485 }
11486 else
11487 {
11488 vty_out (vty, " network %s/%d",
11489 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11490 p->prefixlen);
11491 }
11492
11493 if (bgp_static->rmap.name)
11494 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011495 else
11496 {
11497 if (bgp_static->backdoor)
11498 vty_out (vty, " backdoor");
11499 if (bgp_static->ttl)
11500 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11501 }
paul718e3742002-12-13 20:15:29 +000011502
11503 vty_out (vty, "%s", VTY_NEWLINE);
11504 }
11505
11506 /* Aggregate-address configuration. */
11507 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11508 if ((bgp_aggregate = rn->info) != NULL)
11509 {
11510 p = &rn->p;
11511
11512 /* "address-family" display. */
11513 bgp_config_write_family_header (vty, afi, safi, write);
11514
11515 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11516 {
11517 struct in_addr netmask;
11518
11519 masklen2ip (p->prefixlen, &netmask);
11520 vty_out (vty, " aggregate-address %s %s",
11521 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11522 inet_ntoa (netmask));
11523 }
11524 else
11525 {
11526 vty_out (vty, " aggregate-address %s/%d",
11527 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11528 p->prefixlen);
11529 }
11530
11531 if (bgp_aggregate->as_set)
11532 vty_out (vty, " as-set");
11533
11534 if (bgp_aggregate->summary_only)
11535 vty_out (vty, " summary-only");
11536
11537 vty_out (vty, "%s", VTY_NEWLINE);
11538 }
11539
11540 return 0;
11541}
11542
11543int
11544bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11545{
11546 struct bgp_node *rn;
11547 struct bgp_distance *bdistance;
11548
11549 /* Distance configuration. */
11550 if (bgp->distance_ebgp
11551 && bgp->distance_ibgp
11552 && bgp->distance_local
11553 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11554 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11555 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11556 vty_out (vty, " distance bgp %d %d %d%s",
11557 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11558 VTY_NEWLINE);
11559
11560 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11561 if ((bdistance = rn->info) != NULL)
11562 {
11563 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11564 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11565 bdistance->access_list ? bdistance->access_list : "",
11566 VTY_NEWLINE);
11567 }
11568
11569 return 0;
11570}
11571
11572/* Allocate routing table structure and install commands. */
11573void
11574bgp_route_init ()
11575{
11576 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011577 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011578
11579 /* IPv4 BGP commands. */
11580 install_element (BGP_NODE, &bgp_network_cmd);
11581 install_element (BGP_NODE, &bgp_network_mask_cmd);
11582 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11583 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11584 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11585 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11586 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11587 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11588 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011589 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11590 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11591 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11592 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11593 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11594 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011595 install_element (BGP_NODE, &no_bgp_network_cmd);
11596 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11597 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11598 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11599 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11600 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11601 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11602 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11603 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011604 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11605 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11606 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11607 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11608 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11609 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011610
11611 install_element (BGP_NODE, &aggregate_address_cmd);
11612 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11613 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11614 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11615 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11616 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11617 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11618 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11619 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11620 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11621 install_element (BGP_NODE, &no_aggregate_address_cmd);
11622 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11623 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11624 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11625 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11626 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11627 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11628 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11629 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11630 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11631
11632 /* IPv4 unicast configuration. */
11633 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11634 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11635 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11636 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11637 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11638 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011639 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11640 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11641 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11642 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11643 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11644 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011645 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11646 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11647 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11648 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11649 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011650 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11651 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11652 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11653 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11654 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11655 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011656 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11657 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11658 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11659 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11660 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11661 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11662 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11663 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11664 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11665 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11666 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11667 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11668 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11669 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11670 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11671 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11672 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11673 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11674 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11675 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11676
11677 /* IPv4 multicast configuration. */
11678 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11679 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11680 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11681 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11682 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11683 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011684 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11685 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11686 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11687 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11688 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11689 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011690 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11691 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11692 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11693 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11694 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11695 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011696 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11697 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11698 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11699 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11700 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11701 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd); install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011702 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11703 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11704 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11705 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11706 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11707 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11708 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11709 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11710 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11711 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11712 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11713 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11714 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11715 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11716 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11717 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11718 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11719 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11720 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11721 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11722
11723 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11724 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11725 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11726 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11727 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11728 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11729 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11730 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11731 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11732 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11733 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11734 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11735 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11736 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11737 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11738 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11739 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11740 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11741 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11742 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11743 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11744 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11745 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11746 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11747 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11748 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11749 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11750 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11751 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11752 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11753 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11754 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11755 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11756 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11757 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11758 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11759 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11760 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11761 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11762 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11763 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11764 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11765 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11766 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11767 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11768 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11769 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11770 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11771 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11772 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11773 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11774 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11775 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11776 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11777 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11778 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11779 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11780 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11781 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11782 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11783 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11784 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11785 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11786 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11787 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11788 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11789 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011790 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11791 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11792 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11793 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11794 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11795 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011796
11797 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11798 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11799 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11800 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11801 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11802 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11803 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11804 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11805 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11806 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11807 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11808 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11809 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11810 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11811 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11812 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11813 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11814 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11815 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11816 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11817 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11818 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11819 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11820 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11821 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11822 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11823 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11824 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11825 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11826 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11827 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11828 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11829 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11830 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11831 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11832 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11833 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11834 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11835 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11836 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11837 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11838 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11839 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11840 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11841 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11842 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11843 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11844 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11845 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11846 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11847 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11848 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11849 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11850 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11851 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11852 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11853 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11854 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11855 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11856 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11857 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11858 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11859 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11860 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11861 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11862 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11863 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011864 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11865 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11866 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11867 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11868 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11869 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011870
11871 /* BGP dampening clear commands */
11872 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11873 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11874 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11875 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11876
Paul Jakmaff7924f2006-09-04 01:10:36 +000011877 /* prefix count */
11878 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11879 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11880 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011881#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011882 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11883
paul718e3742002-12-13 20:15:29 +000011884 /* New config IPv6 BGP commands. */
11885 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11886 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011887 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011888 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11889 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011890 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011891
11892 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11893 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11894 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11895 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11896
11897 /* Old config IPv6 BGP commands. */
11898 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11899 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11900
11901 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11902 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11903 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11904 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11905
11906 install_element (VIEW_NODE, &show_bgp_cmd);
11907 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11908 install_element (VIEW_NODE, &show_bgp_route_cmd);
11909 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11910 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11911 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11912 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11913 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11914 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11915 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11916 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11917 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11918 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11919 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11920 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11921 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11922 install_element (VIEW_NODE, &show_bgp_community_cmd);
11923 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11924 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11925 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11926 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11927 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11928 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11929 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11930 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11931 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11932 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11933 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11934 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11935 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11936 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11937 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11938 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11939 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11940 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11941 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11942 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11943 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11944 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11945 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11946 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11947 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11948 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11949 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11950 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11951 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011952 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11953 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11954 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11955 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011956 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11957 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11958 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011959 install_element (VIEW_NODE, &show_bgp_view_cmd);
11960 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11961 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11962 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11963 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11964 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11965 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11966 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11967 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11968 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11969 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11970 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11971 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11972 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11973 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11974 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11975 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11976 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011977 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11978 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11979 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011980
11981 install_element (ENABLE_NODE, &show_bgp_cmd);
11982 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11983 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11984 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11985 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11986 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11987 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11988 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11989 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11990 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11991 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11992 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11993 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11994 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11995 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11996 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11997 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11998 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11999 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12000 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12001 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12002 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12003 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12004 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12005 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12006 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12007 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12008 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12009 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12010 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12011 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12012 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12013 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12014 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12015 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12016 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12017 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12018 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12019 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12020 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12021 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12022 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12023 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12024 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12025 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12026 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012027 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12028 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12029 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12030 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012031 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12032 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12033 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012034 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12035 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12036 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12037 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12038 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12039 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12040 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12041 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12042 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12043 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12044 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12045 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12046 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12047 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12048 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12049 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12050 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12051 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012052 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12053 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12054 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012055
12056 /* Statistics */
12057 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12058 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12059 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12060 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12061
paul718e3742002-12-13 20:15:29 +000012062 /* old command */
12063 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12064 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12065 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12066 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12067 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12068 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12069 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12070 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12071 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12072 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12073 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12074 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12075 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12076 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12077 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12078 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12079 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12080 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12081 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12082 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12083 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12084 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12085 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12086 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12087 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12088 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12089 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12090 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12091 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12092 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12093 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12094 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12095 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12096 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12097 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12098 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012099
paul718e3742002-12-13 20:15:29 +000012100 /* old command */
12101 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12102 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12103 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12104 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12105 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12106 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12107 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12108 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12109 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12110 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12111 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12112 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12113 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12114 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12115 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12116 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12117 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12118 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12119 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12120 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12121 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12122 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12123 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12124 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12125 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12126 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12127 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12128 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12129 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12130 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12131 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12132 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12133 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12134 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12135 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12136 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12137
12138 /* old command */
12139 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12140 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12141 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12142 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12143
12144 /* old command */
12145 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12146 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12147 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12148 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12149
12150 /* old command */
12151 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12152 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12153 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12154 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12155#endif /* HAVE_IPV6 */
12156
12157 install_element (BGP_NODE, &bgp_distance_cmd);
12158 install_element (BGP_NODE, &no_bgp_distance_cmd);
12159 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12160 install_element (BGP_NODE, &bgp_distance_source_cmd);
12161 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12162 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12163 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12164
12165 install_element (BGP_NODE, &bgp_damp_set_cmd);
12166 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12167 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12168 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12169 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12170 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12171 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12172 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12173 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12174 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12175}