blob: 4fbc4babde9b8f4c41301ecc6607c72ca2d865b8 [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;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001048 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001049
paul718e3742002-12-13 20:15:29 +00001050 info.peer = peer;
1051 info.attr = attr;
1052
1053 /* The route reflector is not allowed to modify the attributes
1054 of the reflected IBGP routes. */
1055 if (peer_sort (from) == BGP_PEER_IBGP
1056 && peer_sort (peer) == BGP_PEER_IBGP)
1057 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001058 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001059 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001060 }
paulac41b2a2003-08-12 05:32:27 +00001061
1062 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1063
Paul Jakmafb982c22007-05-04 20:15:47 +00001064 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001065 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1066 else
1067 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1068
paulac41b2a2003-08-12 05:32:27 +00001069 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001070
Paul Jakma9eda90c2007-08-30 13:36:17 +00001071 if (dummy_attr.extra)
1072 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001073
paul718e3742002-12-13 20:15:29 +00001074 if (ret == RMAP_DENYMATCH)
1075 {
1076 bgp_attr_flush (attr);
1077 return 0;
1078 }
1079 }
1080 return 1;
1081}
1082
paul94f2b392005-06-28 12:44:16 +00001083static int
paulfee0f4c2004-09-13 05:12:46 +00001084bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1085 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001086{
paulfee0f4c2004-09-13 05:12:46 +00001087 int ret;
1088 char buf[SU_ADDRSTRLEN];
1089 struct bgp_filter *filter;
1090 struct bgp_info info;
1091 struct peer *from;
1092 struct bgp *bgp;
1093
1094 from = ri->peer;
1095 filter = &rsclient->filter[afi][safi];
1096 bgp = rsclient->bgp;
1097
1098#ifdef DISABLE_BGP_ANNOUNCE
1099 return 0;
1100#endif
1101
1102 /* Do not send back route to sender. */
1103 if (from == rsclient)
1104 return 0;
1105
1106 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001107 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001108 if (! UNSUPPRESS_MAP_NAME (filter))
1109 return 0;
1110
1111 /* Default route check. */
1112 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1113 PEER_STATUS_DEFAULT_ORIGINATE))
1114 {
1115 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1116 return 0;
1117#ifdef HAVE_IPV6
1118 else if (p->family == AF_INET6 && p->prefixlen == 0)
1119 return 0;
1120#endif /* HAVE_IPV6 */
1121 }
1122
1123 /* If the attribute has originator-id and it is same as remote
1124 peer's id. */
1125 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1126 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001127 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1128 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001129 {
1130 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001131 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001132 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1133 rsclient->host,
1134 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1135 p->prefixlen);
1136 return 0;
1137 }
1138 }
1139
1140 /* ORF prefix-list filter check */
1141 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1142 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1143 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1144 if (rsclient->orf_plist[afi][safi])
1145 {
1146 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1147 return 0;
1148 }
1149
1150 /* Output filter check. */
1151 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1152 {
1153 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001154 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001155 "%s [Update:SEND] %s/%d is filtered",
1156 rsclient->host,
1157 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1158 p->prefixlen);
1159 return 0;
1160 }
1161
1162#ifdef BGP_SEND_ASPATH_CHECK
1163 /* AS path loop check. */
1164 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1165 {
1166 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001167 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001168 "%s [Update:SEND] suppress announcement to peer AS %d is AS path.",
1169 rsclient->host, rsclient->as);
1170 return 0;
1171 }
1172#endif /* BGP_SEND_ASPATH_CHECK */
1173
1174 /* For modify attribute, copy it to temporary structure. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001175 bgp_attr_dup (attr, ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001176
1177 /* next-hop-set */
1178 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1179#ifdef HAVE_IPV6
1180 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001181 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001182#endif /* HAVE_IPV6 */
1183 )
1184 {
1185 /* Set IPv4 nexthop. */
1186 if (p->family == AF_INET)
1187 {
1188 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001189 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001190 IPV4_MAX_BYTELEN);
1191 else
1192 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1193 }
1194#ifdef HAVE_IPV6
1195 /* Set IPv6 nexthop. */
1196 if (p->family == AF_INET6)
1197 {
1198 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001199 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001200 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001201 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001202 }
1203#endif /* HAVE_IPV6 */
1204 }
1205
1206#ifdef HAVE_IPV6
1207 if (p->family == AF_INET6)
1208 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001209 struct attr_extra *attre = attr->extra;
1210
1211 assert (attr->extra);
1212
paulfee0f4c2004-09-13 05:12:46 +00001213 /* Left nexthop_local unchanged if so configured. */
1214 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1215 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1216 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001217 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1218 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001219 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001220 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001221 }
1222
1223 /* Default nexthop_local treatment for RS-Clients */
1224 else
1225 {
1226 /* Announcer and RS-Client are both in the same network */
1227 if (rsclient->shared_network && from->shared_network &&
1228 (rsclient->ifindex == from->ifindex))
1229 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001230 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1231 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001232 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001233 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001234 }
1235
1236 /* Set link-local address for shared network peer. */
1237 else if (rsclient->shared_network
1238 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1239 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001240 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001241 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001242 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001243 }
1244
1245 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001246 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001247 }
1248
1249 }
1250#endif /* HAVE_IPV6 */
1251
1252
1253 /* If this is EBGP peer and remove-private-AS is set. */
1254 if (peer_sort (rsclient) == BGP_PEER_EBGP
1255 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1256 && aspath_private_as_check (attr->aspath))
1257 attr->aspath = aspath_empty_get ();
1258
1259 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001261 {
1262 info.peer = rsclient;
1263 info.attr = attr;
1264
1265 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1266
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001268 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1269 else
1270 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1271
1272 rsclient->rmap_type = 0;
1273
1274 if (ret == RMAP_DENYMATCH)
1275 {
1276 bgp_attr_flush (attr);
1277 return 0;
1278 }
1279 }
1280
1281 return 1;
1282}
1283
1284struct bgp_info_pair
1285{
1286 struct bgp_info *old;
1287 struct bgp_info *new;
1288};
1289
paul94f2b392005-06-28 12:44:16 +00001290static void
paulfee0f4c2004-09-13 05:12:46 +00001291bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1292{
paul718e3742002-12-13 20:15:29 +00001293 struct bgp_info *new_select;
1294 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001295 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001296 struct bgp_info *ri1;
1297 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001298 struct bgp_info *nextri = NULL;
1299
paul718e3742002-12-13 20:15:29 +00001300 /* bgp deterministic-med */
1301 new_select = NULL;
1302 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1303 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1304 {
1305 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1306 continue;
1307 if (BGP_INFO_HOLDDOWN (ri1))
1308 continue;
1309
1310 new_select = ri1;
1311 if (ri1->next)
1312 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1313 {
1314 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1315 continue;
1316 if (BGP_INFO_HOLDDOWN (ri2))
1317 continue;
1318
1319 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1320 || aspath_cmp_left_confed (ri1->attr->aspath,
1321 ri2->attr->aspath))
1322 {
1323 if (bgp_info_cmp (bgp, ri2, new_select))
1324 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001325 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001326 new_select = ri2;
1327 }
1328
Paul Jakma1a392d42006-09-07 00:24:49 +00001329 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001330 }
1331 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001332 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1333 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001334 }
1335
1336 /* Check old selected route and new selected route. */
1337 old_select = NULL;
1338 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001339 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001340 {
1341 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1342 old_select = ri;
1343
1344 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001345 {
1346 /* reap REMOVED routes, if needs be
1347 * selected route must stay for a while longer though
1348 */
1349 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1350 && (ri != old_select))
1351 bgp_info_reap (rn, ri);
1352
1353 continue;
1354 }
paul718e3742002-12-13 20:15:29 +00001355
1356 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1357 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1358 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001359 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001360 continue;
1361 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001362 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1363 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001364
1365 if (bgp_info_cmp (bgp, ri, new_select))
1366 new_select = ri;
1367 }
paulb40d9392005-08-22 22:34:41 +00001368
paulfee0f4c2004-09-13 05:12:46 +00001369 result->old = old_select;
1370 result->new = new_select;
1371
1372 return;
1373}
1374
paul94f2b392005-06-28 12:44:16 +00001375static int
paulfee0f4c2004-09-13 05:12:46 +00001376bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001377 struct bgp_node *rn, afi_t afi, safi_t safi)
1378{
paulfee0f4c2004-09-13 05:12:46 +00001379 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001380 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001381
1382 p = &rn->p;
1383
Paul Jakma9eda90c2007-08-30 13:36:17 +00001384 /* Announce route to Established peer. */
1385 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001386 return 0;
1387
Paul Jakma9eda90c2007-08-30 13:36:17 +00001388 /* Address family configuration check. */
1389 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001390 return 0;
1391
Paul Jakma9eda90c2007-08-30 13:36:17 +00001392 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001393 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. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001402 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1403 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001404 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. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001410 if (selected &&
1411 bgp_announce_check_rsclient (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);
paulfee0f4c2004-09-13 05:12:46 +00001415 break;
1416 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001417
1418 bgp_attr_extra_free (&attr);
1419
paulfee0f4c2004-09-13 05:12:46 +00001420 return 0;
paul200df112005-06-01 11:17:05 +00001421}
paulfee0f4c2004-09-13 05:12:46 +00001422
paul200df112005-06-01 11:17:05 +00001423struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001424{
paul200df112005-06-01 11:17:05 +00001425 struct bgp *bgp;
1426 struct bgp_node *rn;
1427 afi_t afi;
1428 safi_t safi;
1429};
1430
1431static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001432bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001433{
paul0fb58d52005-11-14 14:31:49 +00001434 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001435 struct bgp *bgp = pq->bgp;
1436 struct bgp_node *rn = pq->rn;
1437 afi_t afi = pq->afi;
1438 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001439 struct bgp_info *new_select;
1440 struct bgp_info *old_select;
1441 struct bgp_info_pair old_and_new;
1442 struct attr attr;
paul1eb8ef22005-04-07 07:30:20 +00001443 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001444 struct peer *rsclient = rn->table->owner;
1445
Paul Jakmafb982c22007-05-04 20:15:47 +00001446 memset (&attr, 0, sizeof (struct attr));
paulfee0f4c2004-09-13 05:12:46 +00001447 /* Best path selection. */
1448 bgp_best_selection (bgp, rn, &old_and_new);
1449 new_select = old_and_new.new;
1450 old_select = old_and_new.old;
1451
paul200df112005-06-01 11:17:05 +00001452 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1453 {
1454 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1455 {
1456 /* Nothing to do. */
1457 if (old_select && old_select == new_select)
1458 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1459 continue;
paulfee0f4c2004-09-13 05:12:46 +00001460
paul200df112005-06-01 11:17:05 +00001461 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001462 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
paul200df112005-06-01 11:17:05 +00001463 if (new_select)
1464 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001465 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1466 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
paul200df112005-06-01 11:17:05 +00001467 }
paulfee0f4c2004-09-13 05:12:46 +00001468
Paul Jakma9eda90c2007-08-30 13:36:17 +00001469 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001470 }
1471 }
1472 else
1473 {
hassob7395792005-08-26 12:58:38 +00001474 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001475 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001476 if (new_select)
1477 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001478 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1479 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001480 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001481 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001482 }
paulfee0f4c2004-09-13 05:12:46 +00001483
paulb40d9392005-08-22 22:34:41 +00001484 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1485 bgp_info_reap (rn, old_select);
1486
Paul Jakmafb982c22007-05-04 20:15:47 +00001487 bgp_attr_extra_free (&attr);
1488
paul200df112005-06-01 11:17:05 +00001489 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1490 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001491}
1492
paul200df112005-06-01 11:17:05 +00001493static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001494bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001495{
paul0fb58d52005-11-14 14:31:49 +00001496 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001497 struct bgp *bgp = pq->bgp;
1498 struct bgp_node *rn = pq->rn;
1499 afi_t afi = pq->afi;
1500 safi_t safi = pq->safi;
1501 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001502 struct bgp_info *new_select;
1503 struct bgp_info *old_select;
1504 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001505 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001506 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001507
paulfee0f4c2004-09-13 05:12:46 +00001508 /* Best path selection. */
1509 bgp_best_selection (bgp, rn, &old_and_new);
1510 old_select = old_and_new.old;
1511 new_select = old_and_new.new;
1512
1513 /* Nothing to do. */
1514 if (old_select && old_select == new_select)
1515 {
1516 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001517 {
1518 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1519 bgp_zebra_announce (p, old_select, bgp);
1520
1521 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1522 return WQ_SUCCESS;
1523 }
paulfee0f4c2004-09-13 05:12:46 +00001524 }
paul718e3742002-12-13 20:15:29 +00001525
hasso338b3422005-02-23 14:27:24 +00001526 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001527 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001528 if (new_select)
1529 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001530 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1531 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001532 }
1533
1534
paul718e3742002-12-13 20:15:29 +00001535 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001536 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001537 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001538 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001539 }
1540
1541 /* FIB update. */
1542 if (safi == SAFI_UNICAST && ! bgp->name &&
1543 ! bgp_option_check (BGP_OPT_NO_FIB))
1544 {
1545 if (new_select
1546 && new_select->type == ZEBRA_ROUTE_BGP
1547 && new_select->sub_type == BGP_ROUTE_NORMAL)
1548 bgp_zebra_announce (p, new_select, bgp);
1549 else
1550 {
1551 /* Withdraw the route from the kernel. */
1552 if (old_select
1553 && old_select->type == ZEBRA_ROUTE_BGP
1554 && old_select->sub_type == BGP_ROUTE_NORMAL)
1555 bgp_zebra_withdraw (p, old_select);
1556 }
1557 }
paulb40d9392005-08-22 22:34:41 +00001558
1559 /* Reap old select bgp_info, it it has been removed */
1560 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1561 bgp_info_reap (rn, old_select);
1562
paul200df112005-06-01 11:17:05 +00001563 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1564 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001565}
1566
paul200df112005-06-01 11:17:05 +00001567static void
paul0fb58d52005-11-14 14:31:49 +00001568bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001569{
paul0fb58d52005-11-14 14:31:49 +00001570 struct bgp_process_queue *pq = data;
1571
paul200df112005-06-01 11:17:05 +00001572 bgp_unlock_node (pq->rn);
1573 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1574}
1575
1576static void
1577bgp_process_queue_init (void)
1578{
1579 bm->process_main_queue
1580 = work_queue_new (bm->master, "process_main_queue");
1581 bm->process_rsclient_queue
1582 = work_queue_new (bm->master, "process_rsclient_queue");
1583
1584 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1585 {
1586 zlog_err ("%s: Failed to allocate work queue", __func__);
1587 exit (1);
1588 }
1589
1590 bm->process_main_queue->spec.workfunc = &bgp_process_main;
1591 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1592 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1593 bm->process_rsclient_queue->spec.del_item_data
1594 = bm->process_main_queue->spec.del_item_data;
1595 bm->process_main_queue->spec.max_retries
1596 = bm->process_main_queue->spec.max_retries = 0;
1597 bm->process_rsclient_queue->spec.hold
Paul Jakma09dd5612006-09-14 03:38:16 +00001598 = bm->process_main_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001599}
1600
1601void
paulfee0f4c2004-09-13 05:12:46 +00001602bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1603{
paul200df112005-06-01 11:17:05 +00001604 struct bgp_process_queue *pqnode;
1605
1606 /* already scheduled for processing? */
1607 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1608 return;
1609
1610 if ( (bm->process_main_queue == NULL) ||
1611 (bm->process_rsclient_queue == NULL) )
1612 bgp_process_queue_init ();
1613
1614 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1615 sizeof (struct bgp_process_queue));
1616 if (!pqnode)
1617 return;
1618
1619 pqnode->rn = bgp_lock_node (rn); /* unlocked by bgp_processq_del */
1620 pqnode->bgp = bgp;
1621 pqnode->afi = afi;
1622 pqnode->safi = safi;
1623
paulfee0f4c2004-09-13 05:12:46 +00001624 switch (rn->table->type)
1625 {
paul200df112005-06-01 11:17:05 +00001626 case BGP_TABLE_MAIN:
1627 work_queue_add (bm->process_main_queue, pqnode);
1628 break;
1629 case BGP_TABLE_RSCLIENT:
1630 work_queue_add (bm->process_rsclient_queue, pqnode);
1631 break;
paulfee0f4c2004-09-13 05:12:46 +00001632 }
paul200df112005-06-01 11:17:05 +00001633
1634 return;
paulfee0f4c2004-09-13 05:12:46 +00001635}
hasso0a486e52005-02-01 20:57:17 +00001636
paul94f2b392005-06-28 12:44:16 +00001637static int
hasso0a486e52005-02-01 20:57:17 +00001638bgp_maximum_prefix_restart_timer (struct thread *thread)
1639{
1640 struct peer *peer;
1641
1642 peer = THREAD_ARG (thread);
1643 peer->t_pmax_restart = NULL;
1644
1645 if (BGP_DEBUG (events, EVENTS))
1646 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1647 peer->host);
1648
1649 peer_clear (peer);
1650
1651 return 0;
1652}
1653
paulfee0f4c2004-09-13 05:12:46 +00001654int
paul5228ad22004-06-04 17:58:18 +00001655bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1656 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001657{
hassoe0701b72004-05-20 09:19:34 +00001658 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1659 return 0;
1660
1661 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001662 {
hassoe0701b72004-05-20 09:19:34 +00001663 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1664 && ! always)
1665 return 0;
paul718e3742002-12-13 20:15:29 +00001666
hassoe0701b72004-05-20 09:19:34 +00001667 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001668 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1669 "limit %ld", afi_safi_print (afi, safi), peer->host,
1670 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001671 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001672
hassoe0701b72004-05-20 09:19:34 +00001673 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1674 return 0;
paul718e3742002-12-13 20:15:29 +00001675
hassoe0701b72004-05-20 09:19:34 +00001676 {
paul5228ad22004-06-04 17:58:18 +00001677 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001678
1679 if (safi == SAFI_MPLS_VPN)
1680 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001681
1682 ndata[0] = (afi >> 8);
1683 ndata[1] = afi;
1684 ndata[2] = safi;
1685 ndata[3] = (peer->pmax[afi][safi] >> 24);
1686 ndata[4] = (peer->pmax[afi][safi] >> 16);
1687 ndata[5] = (peer->pmax[afi][safi] >> 8);
1688 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001689
1690 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1691 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1692 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1693 }
hasso0a486e52005-02-01 20:57:17 +00001694
1695 /* restart timer start */
1696 if (peer->pmax_restart[afi][safi])
1697 {
1698 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1699
1700 if (BGP_DEBUG (events, EVENTS))
1701 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1702 peer->host, peer->v_pmax_restart);
1703
1704 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1705 peer->v_pmax_restart);
1706 }
1707
hassoe0701b72004-05-20 09:19:34 +00001708 return 1;
paul718e3742002-12-13 20:15:29 +00001709 }
hassoe0701b72004-05-20 09:19:34 +00001710 else
1711 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1712
1713 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1714 {
1715 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1716 && ! always)
1717 return 0;
1718
1719 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001720 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1721 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1722 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001723 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1724 }
1725 else
1726 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001727 return 0;
1728}
1729
paulb40d9392005-08-22 22:34:41 +00001730/* Unconditionally remove the route from the RIB, without taking
1731 * damping into consideration (eg, because the session went down)
1732 */
paul94f2b392005-06-28 12:44:16 +00001733static void
paul718e3742002-12-13 20:15:29 +00001734bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1735 afi_t afi, safi_t safi)
1736{
paul902212c2006-02-05 17:51:19 +00001737 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1738
1739 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1740 bgp_info_delete (rn, ri); /* keep historical info */
1741
paulb40d9392005-08-22 22:34:41 +00001742 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001743}
1744
paul94f2b392005-06-28 12:44:16 +00001745static void
paul718e3742002-12-13 20:15:29 +00001746bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001747 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001748{
paul718e3742002-12-13 20:15:29 +00001749 int status = BGP_DAMP_NONE;
1750
paulb40d9392005-08-22 22:34:41 +00001751 /* apply dampening, if result is suppressed, we'll be retaining
1752 * the bgp_info in the RIB for historical reference.
1753 */
1754 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1755 && peer_sort (peer) == BGP_PEER_EBGP)
1756 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1757 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001758 {
paul902212c2006-02-05 17:51:19 +00001759 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1760 return;
1761 }
1762
1763 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001764}
1765
paul94f2b392005-06-28 12:44:16 +00001766static void
paulfee0f4c2004-09-13 05:12:46 +00001767bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1768 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1769 int sub_type, struct prefix_rd *prd, u_char *tag)
1770{
1771 struct bgp_node *rn;
1772 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001773 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001774 struct attr *attr_new;
1775 struct attr *attr_new2;
1776 struct bgp_info *ri;
1777 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001778 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001779 char buf[SU_ADDRSTRLEN];
1780
Paul Jakmafb982c22007-05-04 20:15:47 +00001781 //memset (new_attr, 0, sizeof (struct attr));
1782
paulfee0f4c2004-09-13 05:12:46 +00001783 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1784 if (peer == rsclient)
1785 return;
1786
1787 bgp = peer->bgp;
1788 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1789
1790 /* Check previously received route. */
1791 for (ri = rn->info; ri; ri = ri->next)
1792 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1793 break;
1794
1795 /* AS path loop check. */
1796 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1797 {
1798 reason = "as-path contains our own AS;";
1799 goto filtered;
1800 }
1801
1802 /* Route reflector originator ID check. */
1803 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001804 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001805 {
1806 reason = "originator is us;";
1807 goto filtered;
1808 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001809
1810 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001811
1812 /* Apply export policy. */
1813 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1814 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1815 {
1816 reason = "export-policy;";
1817 goto filtered;
1818 }
1819
1820 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001821
paulfee0f4c2004-09-13 05:12:46 +00001822 /* Apply import policy. */
1823 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1824 {
1825 bgp_attr_unintern (attr_new2);
1826
1827 reason = "import-policy;";
1828 goto filtered;
1829 }
1830
1831 attr_new = bgp_attr_intern (&new_attr);
1832 bgp_attr_unintern (attr_new2);
1833
1834 /* IPv4 unicast next hop check. */
1835 if (afi == AFI_IP && safi == SAFI_UNICAST)
1836 {
1837 /* Next hop must not be 0.0.0.0 nor Class E address. */
1838 if (new_attr.nexthop.s_addr == 0
1839 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1840 {
1841 bgp_attr_unintern (attr_new);
1842
1843 reason = "martian next-hop;";
1844 goto filtered;
1845 }
1846 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001847
1848 /* new_attr isn't passed to any functions after here */
1849 bgp_attr_extra_free (&new_attr);
1850
paulfee0f4c2004-09-13 05:12:46 +00001851 /* If the update is implicit withdraw. */
1852 if (ri)
1853 {
1854 ri->uptime = time (NULL);
1855
1856 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001857 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1858 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001859 {
1860
Paul Jakma1a392d42006-09-07 00:24:49 +00001861 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001862
1863 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001864 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001865 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1866 peer->host,
1867 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1868 p->prefixlen, rsclient->host);
1869
1870 bgp_unlock_node (rn);
1871 bgp_attr_unintern (attr_new);
1872
1873 return;
1874 }
1875
Paul Jakma16d2e242007-04-10 19:32:10 +00001876 /* Withdraw/Announce before we fully processed the withdraw */
1877 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1878 bgp_info_restore (rn, ri);
1879
paulfee0f4c2004-09-13 05:12:46 +00001880 /* Received Logging. */
1881 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001882 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001883 peer->host,
1884 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1885 p->prefixlen, rsclient->host);
1886
1887 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001888 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001889
1890 /* Update to new attribute. */
1891 bgp_attr_unintern (ri->attr);
1892 ri->attr = attr_new;
1893
1894 /* Update MPLS tag. */
1895 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001896 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001897
Paul Jakma1a392d42006-09-07 00:24:49 +00001898 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001899
1900 /* Process change. */
1901 bgp_process (bgp, rn, afi, safi);
1902 bgp_unlock_node (rn);
1903
1904 return;
1905 }
1906
1907 /* Received Logging. */
1908 if (BGP_DEBUG (update, UPDATE_IN))
1909 {
ajsd2c1f162004-12-08 21:10:20 +00001910 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001911 peer->host,
1912 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1913 p->prefixlen, rsclient->host);
1914 }
1915
1916 /* Make new BGP info. */
1917 new = bgp_info_new ();
1918 new->type = type;
1919 new->sub_type = sub_type;
1920 new->peer = peer;
1921 new->attr = attr_new;
1922 new->uptime = time (NULL);
1923
1924 /* Update MPLS tag. */
1925 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001926 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001927
Paul Jakma1a392d42006-09-07 00:24:49 +00001928 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001929
1930 /* Register new BGP information. */
1931 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001932
1933 /* route_node_get lock */
1934 bgp_unlock_node (rn);
1935
paulfee0f4c2004-09-13 05:12:46 +00001936 /* Process change. */
1937 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001938
1939 bgp_attr_extra_free (&new_attr);
1940
paulfee0f4c2004-09-13 05:12:46 +00001941 return;
1942
1943 filtered:
1944
1945 /* This BGP update is filtered. Log the reason then update BGP entry. */
1946 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001947 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001948 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1949 peer->host,
1950 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1951 p->prefixlen, rsclient->host, reason);
1952
1953 if (ri)
paulb40d9392005-08-22 22:34:41 +00001954 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001955
1956 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001957
1958 if (new_attr.extra)
1959 bgp_attr_extra_free (&new_attr);
1960
paulfee0f4c2004-09-13 05:12:46 +00001961 return;
1962}
1963
paul94f2b392005-06-28 12:44:16 +00001964static void
paulfee0f4c2004-09-13 05:12:46 +00001965bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1966 struct peer *peer, struct prefix *p, int type, int sub_type,
1967 struct prefix_rd *prd, u_char *tag)
1968 {
1969 struct bgp_node *rn;
1970 struct bgp_info *ri;
1971 char buf[SU_ADDRSTRLEN];
1972
1973 if (rsclient == peer)
1974 return;
1975
1976 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1977
1978 /* Lookup withdrawn route. */
1979 for (ri = rn->info; ri; ri = ri->next)
1980 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1981 break;
1982
1983 /* Withdraw specified route from routing table. */
1984 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001985 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001986 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001987 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001988 "%s Can't find the route %s/%d", peer->host,
1989 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1990 p->prefixlen);
1991
1992 /* Unlock bgp_node_get() lock. */
1993 bgp_unlock_node (rn);
1994 }
1995
paul94f2b392005-06-28 12:44:16 +00001996static int
paulfee0f4c2004-09-13 05:12:46 +00001997bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001998 afi_t afi, safi_t safi, int type, int sub_type,
1999 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2000{
2001 int ret;
2002 int aspath_loop_count = 0;
2003 struct bgp_node *rn;
2004 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002005 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002006 struct attr *attr_new;
2007 struct bgp_info *ri;
2008 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002009 const char *reason;
paul718e3742002-12-13 20:15:29 +00002010 char buf[SU_ADDRSTRLEN];
2011
2012 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002013 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002014
paul718e3742002-12-13 20:15:29 +00002015 /* When peer's soft reconfiguration enabled. Record input packet in
2016 Adj-RIBs-In. */
2017 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2018 && peer != bgp->peer_self && ! soft_reconfig)
2019 bgp_adj_in_set (rn, peer, attr);
2020
2021 /* Check previously received route. */
2022 for (ri = rn->info; ri; ri = ri->next)
2023 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2024 break;
2025
2026 /* AS path local-as loop check. */
2027 if (peer->change_local_as)
2028 {
2029 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2030 aspath_loop_count = 1;
2031
2032 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2033 {
2034 reason = "as-path contains our own AS;";
2035 goto filtered;
2036 }
2037 }
2038
2039 /* AS path loop check. */
2040 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2041 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2042 && aspath_loop_check(attr->aspath, bgp->confed_id)
2043 > peer->allowas_in[afi][safi]))
2044 {
2045 reason = "as-path contains our own AS;";
2046 goto filtered;
2047 }
2048
2049 /* Route reflector originator ID check. */
2050 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002051 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002052 {
2053 reason = "originator is us;";
2054 goto filtered;
2055 }
2056
2057 /* Route reflector cluster ID check. */
2058 if (bgp_cluster_filter (peer, attr))
2059 {
2060 reason = "reflected from the same cluster;";
2061 goto filtered;
2062 }
2063
2064 /* Apply incoming filter. */
2065 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2066 {
2067 reason = "filter;";
2068 goto filtered;
2069 }
2070
2071 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002072 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002073
2074 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2075 {
2076 reason = "route-map;";
2077 goto filtered;
2078 }
2079
2080 /* IPv4 unicast next hop check. */
2081 if (afi == AFI_IP && safi == SAFI_UNICAST)
2082 {
2083 /* If the peer is EBGP and nexthop is not on connected route,
2084 discard it. */
2085 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2086 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002087 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002088 {
2089 reason = "non-connected next-hop;";
2090 goto filtered;
2091 }
2092
2093 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2094 must not be my own address. */
2095 if (bgp_nexthop_self (afi, &new_attr)
2096 || new_attr.nexthop.s_addr == 0
2097 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2098 {
2099 reason = "martian next-hop;";
2100 goto filtered;
2101 }
2102 }
2103
2104 attr_new = bgp_attr_intern (&new_attr);
2105
2106 /* If the update is implicit withdraw. */
2107 if (ri)
2108 {
2109 ri->uptime = time (NULL);
2110
2111 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002112 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2113 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002114 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002115 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002116
2117 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2118 && peer_sort (peer) == BGP_PEER_EBGP
2119 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2120 {
2121 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002122 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002123 peer->host,
2124 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2125 p->prefixlen);
2126
paul902212c2006-02-05 17:51:19 +00002127 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2128 {
2129 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2130 bgp_process (bgp, rn, afi, safi);
2131 }
paul718e3742002-12-13 20:15:29 +00002132 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002133 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002134 {
2135 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002136 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002137 "%s rcvd %s/%d...duplicate ignored",
2138 peer->host,
2139 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2140 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002141
2142 /* graceful restart STALE flag unset. */
2143 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2144 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002145 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002146 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002147 }
paul718e3742002-12-13 20:15:29 +00002148 }
2149
2150 bgp_unlock_node (rn);
2151 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002152 bgp_attr_extra_free (&new_attr);
2153
paul718e3742002-12-13 20:15:29 +00002154 return 0;
2155 }
2156
Paul Jakma16d2e242007-04-10 19:32:10 +00002157 /* Withdraw/Announce before we fully processed the withdraw */
2158 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2159 {
2160 if (BGP_DEBUG (update, UPDATE_IN))
2161 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2162 peer->host,
2163 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2164 p->prefixlen);
2165 bgp_info_restore (rn, ri);
2166 }
2167
paul718e3742002-12-13 20:15:29 +00002168 /* Received Logging. */
2169 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002170 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002171 peer->host,
2172 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2173 p->prefixlen);
2174
hasso93406d82005-02-02 14:40:33 +00002175 /* graceful restart STALE flag unset. */
2176 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002177 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002178
paul718e3742002-12-13 20:15:29 +00002179 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002180 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002181
2182 /* implicit withdraw, decrement aggregate and pcount here.
2183 * only if update is accepted, they'll increment below.
2184 */
paul902212c2006-02-05 17:51:19 +00002185 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2186
paul718e3742002-12-13 20:15:29 +00002187 /* Update bgp route dampening information. */
2188 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2189 && peer_sort (peer) == BGP_PEER_EBGP)
2190 {
2191 /* This is implicit withdraw so we should update dampening
2192 information. */
2193 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2194 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002195 }
2196
paul718e3742002-12-13 20:15:29 +00002197 /* Update to new attribute. */
2198 bgp_attr_unintern (ri->attr);
2199 ri->attr = attr_new;
2200
2201 /* Update MPLS tag. */
2202 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002203 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002204
2205 /* Update bgp route dampening information. */
2206 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2207 && peer_sort (peer) == BGP_PEER_EBGP)
2208 {
2209 /* Now we do normal update dampening. */
2210 ret = bgp_damp_update (ri, rn, afi, safi);
2211 if (ret == BGP_DAMP_SUPPRESSED)
2212 {
2213 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002214 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002215 return 0;
2216 }
2217 }
2218
2219 /* Nexthop reachability check. */
2220 if ((afi == AFI_IP || afi == AFI_IP6)
2221 && safi == SAFI_UNICAST
2222 && (peer_sort (peer) == BGP_PEER_IBGP
2223 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002224 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002225 {
2226 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002227 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002228 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002229 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002230 }
2231 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002232 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002233
2234 /* Process change. */
2235 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2236
2237 bgp_process (bgp, rn, afi, safi);
2238 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002239 bgp_attr_extra_free (&new_attr);
2240
paul718e3742002-12-13 20:15:29 +00002241 return 0;
2242 }
2243
2244 /* Received Logging. */
2245 if (BGP_DEBUG (update, UPDATE_IN))
2246 {
ajsd2c1f162004-12-08 21:10:20 +00002247 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002248 peer->host,
2249 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2250 p->prefixlen);
2251 }
2252
paul718e3742002-12-13 20:15:29 +00002253 /* Make new BGP info. */
2254 new = bgp_info_new ();
2255 new->type = type;
2256 new->sub_type = sub_type;
2257 new->peer = peer;
2258 new->attr = attr_new;
2259 new->uptime = time (NULL);
2260
2261 /* Update MPLS tag. */
2262 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002263 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002264
2265 /* Nexthop reachability check. */
2266 if ((afi == AFI_IP || afi == AFI_IP6)
2267 && safi == SAFI_UNICAST
2268 && (peer_sort (peer) == BGP_PEER_IBGP
2269 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002270 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002271 {
2272 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002273 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002274 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002275 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002276 }
2277 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002278 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002279
paul902212c2006-02-05 17:51:19 +00002280 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002281 bgp_aggregate_increment (bgp, p, new, afi, safi);
2282
2283 /* Register new BGP information. */
2284 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002285
2286 /* route_node_get lock */
2287 bgp_unlock_node (rn);
2288
Paul Jakmafb982c22007-05-04 20:15:47 +00002289 bgp_attr_extra_free (&new_attr);
2290
paul718e3742002-12-13 20:15:29 +00002291 /* If maximum prefix count is configured and current prefix
2292 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002293 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2294 return -1;
paul718e3742002-12-13 20:15:29 +00002295
2296 /* Process change. */
2297 bgp_process (bgp, rn, afi, safi);
2298
2299 return 0;
2300
2301 /* This BGP update is filtered. Log the reason then update BGP
2302 entry. */
2303 filtered:
2304 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002305 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002306 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2307 peer->host,
2308 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2309 p->prefixlen, reason);
2310
2311 if (ri)
paulb40d9392005-08-22 22:34:41 +00002312 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002313
2314 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002315
2316 bgp_attr_extra_free (&new_attr);
2317
paul718e3742002-12-13 20:15:29 +00002318 return 0;
2319}
2320
2321int
paulfee0f4c2004-09-13 05:12:46 +00002322bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2323 afi_t afi, safi_t safi, int type, int sub_type,
2324 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2325{
2326 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002327 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002328 struct bgp *bgp;
2329 int ret;
2330
2331 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2332 soft_reconfig);
2333
2334 bgp = peer->bgp;
2335
2336 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002337 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002338 {
2339 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2340 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2341 sub_type, prd, tag);
2342 }
2343
2344 return ret;
2345}
2346
2347int
paul718e3742002-12-13 20:15:29 +00002348bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002349 afi_t afi, safi_t safi, int type, int sub_type,
2350 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002351{
2352 struct bgp *bgp;
2353 char buf[SU_ADDRSTRLEN];
2354 struct bgp_node *rn;
2355 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002356 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002357 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002358
2359 bgp = peer->bgp;
2360
paulfee0f4c2004-09-13 05:12:46 +00002361 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002362 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002363 {
2364 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2365 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2366 }
2367
paul718e3742002-12-13 20:15:29 +00002368 /* Logging. */
2369 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002370 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002371 peer->host,
2372 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2373 p->prefixlen);
2374
2375 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002376 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002377
2378 /* If peer is soft reconfiguration enabled. Record input packet for
2379 further calculation. */
2380 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2381 && peer != bgp->peer_self)
2382 bgp_adj_in_unset (rn, peer);
2383
2384 /* Lookup withdrawn route. */
2385 for (ri = rn->info; ri; ri = ri->next)
2386 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2387 break;
2388
2389 /* Withdraw specified route from routing table. */
2390 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002391 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002392 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002393 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002394 "%s Can't find the route %s/%d", peer->host,
2395 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2396 p->prefixlen);
2397
2398 /* Unlock bgp_node_get() lock. */
2399 bgp_unlock_node (rn);
2400
2401 return 0;
2402}
2403
2404void
2405bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2406{
2407 struct bgp *bgp;
2408 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002409 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002410 struct prefix p;
2411 struct bgp_info binfo;
2412 struct peer *from;
2413 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002414
Paul Jakmab2497022007-06-14 11:17:58 +00002415 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002416 return;
2417
paul718e3742002-12-13 20:15:29 +00002418 bgp = peer->bgp;
2419 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002420
paul718e3742002-12-13 20:15:29 +00002421 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2422 aspath = attr.aspath;
2423 attr.local_pref = bgp->default_local_pref;
2424 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2425
2426 if (afi == AFI_IP)
2427 str2prefix ("0.0.0.0/0", &p);
2428#ifdef HAVE_IPV6
2429 else if (afi == AFI_IP6)
2430 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002431 struct attr_extra *ae;
2432 attr.extra = NULL;
2433
2434 ae = bgp_attr_extra_get (&attr);
2435 attr.extra = ae;
2436
paul718e3742002-12-13 20:15:29 +00002437 str2prefix ("::/0", &p);
2438
2439 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002440 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002441 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002442 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002443
2444 /* If the peer is on shared nextwork and we have link-local
2445 nexthop set it. */
2446 if (peer->shared_network
2447 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2448 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002449 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002450 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002451 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002452 }
2453 }
2454#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002455
2456 if (peer->default_rmap[afi][safi].name)
2457 {
2458 binfo.peer = bgp->peer_self;
2459 binfo.attr = &attr;
2460
paulfee0f4c2004-09-13 05:12:46 +00002461 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2462
paul718e3742002-12-13 20:15:29 +00002463 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2464 RMAP_BGP, &binfo);
2465
paulfee0f4c2004-09-13 05:12:46 +00002466 bgp->peer_self->rmap_type = 0;
2467
paul718e3742002-12-13 20:15:29 +00002468 if (ret == RMAP_DENYMATCH)
2469 {
2470 bgp_attr_flush (&attr);
2471 withdraw = 1;
2472 }
2473 }
2474
2475 if (withdraw)
2476 {
2477 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2478 bgp_default_withdraw_send (peer, afi, safi);
2479 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2480 }
2481 else
2482 {
2483 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2484 bgp_default_update_send (peer, &attr, afi, safi, from);
2485 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002486
2487 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002488 aspath_unintern (aspath);
2489}
2490
2491static void
2492bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002493 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002494{
2495 struct bgp_node *rn;
2496 struct bgp_info *ri;
2497 struct attr attr;
Paul Jakmafb982c22007-05-04 20:15:47 +00002498
2499 memset (&attr, 0, sizeof (struct attr));
2500
paul718e3742002-12-13 20:15:29 +00002501 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002502 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002503
2504 if (safi != SAFI_MPLS_VPN
2505 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2506 bgp_default_originate (peer, afi, safi, 0);
2507
2508 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2509 for (ri = rn->info; ri; ri = ri->next)
2510 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2511 {
paulfee0f4c2004-09-13 05:12:46 +00002512 if ( (rsclient) ?
2513 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2514 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002515 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2516 else
2517 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002518
2519 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002520 }
2521}
2522
2523void
2524bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2525{
2526 struct bgp_node *rn;
2527 struct bgp_table *table;
2528
2529 if (peer->status != Established)
2530 return;
2531
2532 if (! peer->afc_nego[afi][safi])
2533 return;
2534
2535 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2536 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2537 return;
2538
2539 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002540 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002541 else
2542 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2543 rn = bgp_route_next(rn))
2544 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002545 bgp_announce_table (peer, afi, safi, table, 0);
2546
2547 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2548 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002549}
2550
2551void
2552bgp_announce_route_all (struct peer *peer)
2553{
2554 afi_t afi;
2555 safi_t safi;
2556
2557 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2558 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2559 bgp_announce_route (peer, afi, safi);
2560}
2561
2562static void
paulfee0f4c2004-09-13 05:12:46 +00002563bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2564 safi_t safi, struct bgp_table *table)
2565{
2566 struct bgp_node *rn;
2567 struct bgp_adj_in *ain;
2568
2569 if (! table)
2570 table = rsclient->bgp->rib[afi][safi];
2571
2572 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2573 for (ain = rn->adj_in; ain; ain = ain->next)
2574 {
2575 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2576 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2577 }
2578}
2579
2580void
2581bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2582{
2583 struct bgp_table *table;
2584 struct bgp_node *rn;
2585
2586 if (safi != SAFI_MPLS_VPN)
2587 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2588
2589 else
2590 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2591 rn = bgp_route_next (rn))
2592 if ((table = rn->info) != NULL)
2593 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2594}
2595
2596static void
paul718e3742002-12-13 20:15:29 +00002597bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2598 struct bgp_table *table)
2599{
2600 int ret;
2601 struct bgp_node *rn;
2602 struct bgp_adj_in *ain;
2603
2604 if (! table)
2605 table = peer->bgp->rib[afi][safi];
2606
2607 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2608 for (ain = rn->adj_in; ain; ain = ain->next)
2609 {
2610 if (ain->peer == peer)
2611 {
2612 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2613 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2614 NULL, NULL, 1);
2615 if (ret < 0)
2616 {
2617 bgp_unlock_node (rn);
2618 return;
2619 }
2620 continue;
2621 }
2622 }
2623}
2624
2625void
2626bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2627{
2628 struct bgp_node *rn;
2629 struct bgp_table *table;
2630
2631 if (peer->status != Established)
2632 return;
2633
2634 if (safi != SAFI_MPLS_VPN)
2635 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2636 else
2637 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2638 rn = bgp_route_next (rn))
2639 if ((table = rn->info) != NULL)
2640 bgp_soft_reconfig_table (peer, afi, safi, table);
2641}
2642
paul200df112005-06-01 11:17:05 +00002643static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002644bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002645{
Paul Jakma64e580a2006-02-21 01:09:01 +00002646 struct bgp_node *rn = data;
2647 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002648 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002649 afi_t afi = rn->table->afi;
2650 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002651
Paul Jakma64e580a2006-02-21 01:09:01 +00002652 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002653
Paul Jakma64e580a2006-02-21 01:09:01 +00002654 for (ri = rn->info; ri; ri = ri->next)
2655 if (ri->peer == peer)
paul200df112005-06-01 11:17:05 +00002656 {
2657 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002658 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2659 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002660 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002661 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2662 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002663 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002664 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002665 break;
2666 }
paul200df112005-06-01 11:17:05 +00002667 return WQ_SUCCESS;
2668}
2669
2670static void
paul0fb58d52005-11-14 14:31:49 +00002671bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002672{
Paul Jakma64e580a2006-02-21 01:09:01 +00002673 struct bgp_node *rn = data;
2674
2675 bgp_unlock_node (rn);
paul200df112005-06-01 11:17:05 +00002676}
2677
2678static void
paul94f2b392005-06-28 12:44:16 +00002679bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002680{
Paul Jakma64e580a2006-02-21 01:09:01 +00002681 struct peer *peer = wq->spec.data;
2682
Paul Jakma64e580a2006-02-21 01:09:01 +00002683 peer_unlock (peer); /* bgp_clear_node_complete */
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002684
2685 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002686 BGP_EVENT_ADD (peer, Clearing_Completed);
paul200df112005-06-01 11:17:05 +00002687}
2688
2689static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002690bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002691{
Paul Jakma64e580a2006-02-21 01:09:01 +00002692#define CLEAR_QUEUE_NAME_LEN 26 /* "clear 2001:123:123:123::1" */
2693 char wname[CLEAR_QUEUE_NAME_LEN];
2694
2695 snprintf (wname, CLEAR_QUEUE_NAME_LEN, "clear %s", peer->host);
2696#undef CLEAR_QUEUE_NAME_LEN
2697
2698 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002699 {
2700 zlog_err ("%s: Failed to allocate work queue", __func__);
2701 exit (1);
2702 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002703 peer->clear_node_queue->spec.hold = 10;
2704 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2705 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2706 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2707 peer->clear_node_queue->spec.max_retries = 0;
2708
2709 /* we only 'lock' this peer reference when the queue is actually active */
2710 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002711}
2712
paul718e3742002-12-13 20:15:29 +00002713static void
2714bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002715 struct bgp_table *table, struct peer *rsclient)
paul718e3742002-12-13 20:15:29 +00002716{
2717 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002718
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002719
paul718e3742002-12-13 20:15:29 +00002720 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002721 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002722
hasso6cf159b2005-03-21 10:28:14 +00002723 /* If still no table => afi/safi isn't configured at all or smth. */
2724 if (! table)
2725 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002726
2727 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2728 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002729 struct bgp_info *ri;
2730 struct bgp_adj_in *ain;
2731 struct bgp_adj_out *aout;
2732
Paul Jakma65ca75e2006-05-04 08:08:15 +00002733 if (rn->info == NULL)
2734 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002735
2736 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2737 * queued for every clearing peer, regardless of whether it is
2738 * relevant to the peer at hand.
2739 *
2740 * Overview: There are 3 different indices which need to be
2741 * scrubbed, potentially, when a peer is removed:
2742 *
2743 * 1 peer's routes visible via the RIB (ie accepted routes)
2744 * 2 peer's routes visible by the (optional) peer's adj-in index
2745 * 3 other routes visible by the peer's adj-out index
2746 *
2747 * 3 there is no hurry in scrubbing, once the struct peer is
2748 * removed from bgp->peer, we could just GC such deleted peer's
2749 * adj-outs at our leisure.
2750 *
2751 * 1 and 2 must be 'scrubbed' in some way, at least made
2752 * invisible via RIB index before peer session is allowed to be
2753 * brought back up. So one needs to know when such a 'search' is
2754 * complete.
2755 *
2756 * Ideally:
2757 *
2758 * - there'd be a single global queue or a single RIB walker
2759 * - rather than tracking which route_nodes still need to be
2760 * examined on a peer basis, we'd track which peers still
2761 * aren't cleared
2762 *
2763 * Given that our per-peer prefix-counts now should be reliable,
2764 * this may actually be achievable. It doesn't seem to be a huge
2765 * problem at this time,
2766 */
2767 for (ri = rn->info; ri; ri = ri->next)
2768 if (ri->peer == peer)
2769 {
2770 bgp_lock_node (rn); /* unlocked: bgp_clear_node_queue_del */
2771 work_queue_add (peer->clear_node_queue, rn);
2772 }
2773
2774 for (ain = rn->adj_in; ain; ain = ain->next)
2775 if (ain->peer == peer)
2776 {
2777 bgp_adj_in_remove (rn, ain);
2778 bgp_unlock_node (rn);
2779 break;
2780 }
2781 for (aout = rn->adj_out; aout; aout = aout->next)
2782 if (aout->peer == peer)
2783 {
2784 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2785 bgp_unlock_node (rn);
2786 break;
2787 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002788 }
2789 return;
2790}
2791
2792void
2793bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi)
2794{
2795 struct bgp_node *rn;
2796 struct bgp_table *table;
2797 struct peer *rsclient;
2798 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002799
Paul Jakma64e580a2006-02-21 01:09:01 +00002800 if (peer->clear_node_queue == NULL)
2801 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002802
Paul Jakmaca058a32006-09-14 02:58:49 +00002803 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2804 * Idle until it receives a Clearing_Completed event. This protects
2805 * against peers which flap faster than we can we clear, which could
2806 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002807 *
2808 * a) race with routes from the new session being installed before
2809 * clear_route_node visits the node (to delete the route of that
2810 * peer)
2811 * b) resource exhaustion, clear_route_node likely leads to an entry
2812 * on the process_main queue. Fast-flapping could cause that queue
2813 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002814 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002815 if (!peer->clear_node_queue->thread)
2816 peer_lock (peer); /* bgp_clear_node_complete */
paul200df112005-06-01 11:17:05 +00002817
paul718e3742002-12-13 20:15:29 +00002818 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002819 bgp_clear_route_table (peer, afi, safi, NULL, NULL);
paul718e3742002-12-13 20:15:29 +00002820 else
2821 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2822 rn = bgp_route_next (rn))
2823 if ((table = rn->info) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002824 bgp_clear_route_table (peer, afi, safi, table, NULL);
2825
paul1eb8ef22005-04-07 07:30:20 +00002826 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002827 {
2828 if (CHECK_FLAG(rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2829 bgp_clear_route_table (peer, afi, safi, NULL, rsclient);
2830 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002831
Paul Jakmaca058a32006-09-14 02:58:49 +00002832 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002833 * completion function won't be run by workqueue code - call it here.
2834 * XXX: Actually, this assumption doesn't hold, see
2835 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002836 *
2837 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002838 * really needed if peer state is Established - peers in
2839 * pre-Established states shouldn't have any route-update state
2840 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002841 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002842 * We still can get here in pre-Established though, through
2843 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2844 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002845 *
2846 * At some future point, this check could be move to the top of the
2847 * function, and do a quick early-return when state is
2848 * pre-Established, avoiding above list and table scans. Once we're
2849 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002850 */
2851 if (!peer->clear_node_queue->thread)
2852 bgp_clear_node_complete (peer->clear_node_queue);
Paul Jakmaca058a32006-09-14 02:58:49 +00002853 else
2854 {
2855 /* clearing queue scheduled. Normal if in Established state
2856 * (and about to transition out of it), but otherwise...
2857 */
2858 if (peer->status != Established)
2859 {
2860 plog_err (peer->log, "%s [Error] State %s is not Established,"
2861 " but routes were cleared - bug!",
2862 peer->host, LOOKUP (bgp_status_msg, peer->status));
2863 assert (peer->status == Established);
2864 }
2865 }
paul718e3742002-12-13 20:15:29 +00002866}
2867
2868void
2869bgp_clear_route_all (struct peer *peer)
2870{
2871 afi_t afi;
2872 safi_t safi;
2873
2874 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2875 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2876 bgp_clear_route (peer, afi, safi);
2877}
2878
2879void
2880bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2881{
2882 struct bgp_table *table;
2883 struct bgp_node *rn;
2884 struct bgp_adj_in *ain;
2885
2886 table = peer->bgp->rib[afi][safi];
2887
2888 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2889 for (ain = rn->adj_in; ain ; ain = ain->next)
2890 if (ain->peer == peer)
2891 {
2892 bgp_adj_in_remove (rn, ain);
2893 bgp_unlock_node (rn);
2894 break;
2895 }
2896}
hasso93406d82005-02-02 14:40:33 +00002897
2898void
2899bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2900{
2901 struct bgp_node *rn;
2902 struct bgp_info *ri;
2903 struct bgp_table *table;
2904
2905 table = peer->bgp->rib[afi][safi];
2906
2907 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2908 {
2909 for (ri = rn->info; ri; ri = ri->next)
2910 if (ri->peer == peer)
2911 {
2912 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2913 bgp_rib_remove (rn, ri, peer, afi, safi);
2914 break;
2915 }
2916 }
2917}
paul718e3742002-12-13 20:15:29 +00002918
2919/* Delete all kernel routes. */
2920void
paul545acaf2004-04-20 15:13:15 +00002921bgp_cleanup_routes ()
paul718e3742002-12-13 20:15:29 +00002922{
2923 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002924 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002925 struct bgp_node *rn;
2926 struct bgp_table *table;
2927 struct bgp_info *ri;
2928
paul1eb8ef22005-04-07 07:30:20 +00002929 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002930 {
2931 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2932
2933 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2934 for (ri = rn->info; ri; ri = ri->next)
2935 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2936 && ri->type == ZEBRA_ROUTE_BGP
2937 && ri->sub_type == BGP_ROUTE_NORMAL)
2938 bgp_zebra_withdraw (&rn->p, ri);
2939
2940 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2941
2942 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2943 for (ri = rn->info; ri; ri = ri->next)
2944 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2945 && ri->type == ZEBRA_ROUTE_BGP
2946 && ri->sub_type == BGP_ROUTE_NORMAL)
2947 bgp_zebra_withdraw (&rn->p, ri);
2948 }
2949}
2950
2951void
2952bgp_reset ()
2953{
2954 vty_reset ();
2955 bgp_zclient_reset ();
2956 access_list_reset ();
2957 prefix_list_reset ();
2958}
2959
2960/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2961 value. */
2962int
2963bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2964{
2965 u_char *pnt;
2966 u_char *lim;
2967 struct prefix p;
2968 int psize;
2969 int ret;
2970
2971 /* Check peer status. */
2972 if (peer->status != Established)
2973 return 0;
2974
2975 pnt = packet->nlri;
2976 lim = pnt + packet->length;
2977
2978 for (; pnt < lim; pnt += psize)
2979 {
2980 /* Clear prefix structure. */
2981 memset (&p, 0, sizeof (struct prefix));
2982
2983 /* Fetch prefix length. */
2984 p.prefixlen = *pnt++;
2985 p.family = afi2family (packet->afi);
2986
2987 /* Already checked in nlri_sanity_check(). We do double check
2988 here. */
2989 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2990 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2991 return -1;
2992
2993 /* Packet size overflow check. */
2994 psize = PSIZE (p.prefixlen);
2995
2996 /* When packet overflow occur return immediately. */
2997 if (pnt + psize > lim)
2998 return -1;
2999
3000 /* Fetch prefix from NLRI packet. */
3001 memcpy (&p.u.prefix, pnt, psize);
3002
3003 /* Check address. */
3004 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3005 {
3006 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3007 {
paulf5ba3872004-07-09 12:11:31 +00003008 /*
3009 * From draft-ietf-idr-bgp4-22, Section 6.3:
3010 * If a BGP router receives an UPDATE message with a
3011 * semantically incorrect NLRI field, in which a prefix is
3012 * semantically incorrect (eg. an unexpected multicast IP
3013 * address), it should ignore the prefix.
3014 */
paul718e3742002-12-13 20:15:29 +00003015 zlog (peer->log, LOG_ERR,
3016 "IPv4 unicast NLRI is multicast address %s",
3017 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003018
paul718e3742002-12-13 20:15:29 +00003019 return -1;
3020 }
3021 }
3022
3023#ifdef HAVE_IPV6
3024 /* Check address. */
3025 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3026 {
3027 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3028 {
3029 char buf[BUFSIZ];
3030
3031 zlog (peer->log, LOG_WARNING,
3032 "IPv6 link-local NLRI received %s ignore this NLRI",
3033 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3034
3035 continue;
3036 }
3037 }
3038#endif /* HAVE_IPV6 */
3039
3040 /* Normal process. */
3041 if (attr)
3042 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3043 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3044 else
3045 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3046 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3047
3048 /* Address family configuration mismatch or maximum-prefix count
3049 overflow. */
3050 if (ret < 0)
3051 return -1;
3052 }
3053
3054 /* Packet length consistency check. */
3055 if (pnt != lim)
3056 return -1;
3057
3058 return 0;
3059}
3060
3061/* NLRI encode syntax check routine. */
3062int
3063bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3064 bgp_size_t length)
3065{
3066 u_char *end;
3067 u_char prefixlen;
3068 int psize;
3069
3070 end = pnt + length;
3071
3072 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3073 syntactic validity. If the field is syntactically incorrect,
3074 then the Error Subcode is set to Invalid Network Field. */
3075
3076 while (pnt < end)
3077 {
3078 prefixlen = *pnt++;
3079
3080 /* Prefix length check. */
3081 if ((afi == AFI_IP && prefixlen > 32)
3082 || (afi == AFI_IP6 && prefixlen > 128))
3083 {
3084 plog_err (peer->log,
3085 "%s [Error] Update packet error (wrong prefix length %d)",
3086 peer->host, prefixlen);
3087 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3088 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3089 return -1;
3090 }
3091
3092 /* Packet size overflow check. */
3093 psize = PSIZE (prefixlen);
3094
3095 if (pnt + psize > end)
3096 {
3097 plog_err (peer->log,
3098 "%s [Error] Update packet error"
3099 " (prefix data overflow prefix size is %d)",
3100 peer->host, psize);
3101 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3102 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3103 return -1;
3104 }
3105
3106 pnt += psize;
3107 }
3108
3109 /* Packet length consistency check. */
3110 if (pnt != end)
3111 {
3112 plog_err (peer->log,
3113 "%s [Error] Update packet error"
3114 " (prefix length mismatch with total length)",
3115 peer->host);
3116 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3117 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3118 return -1;
3119 }
3120 return 0;
3121}
3122
paul94f2b392005-06-28 12:44:16 +00003123static struct bgp_static *
paul718e3742002-12-13 20:15:29 +00003124bgp_static_new ()
3125{
3126 struct bgp_static *new;
3127 new = XMALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
3128 memset (new, 0, sizeof (struct bgp_static));
3129 return new;
3130}
3131
paul94f2b392005-06-28 12:44:16 +00003132static void
paul718e3742002-12-13 20:15:29 +00003133bgp_static_free (struct bgp_static *bgp_static)
3134{
3135 if (bgp_static->rmap.name)
3136 free (bgp_static->rmap.name);
3137 XFREE (MTYPE_BGP_STATIC, bgp_static);
3138}
3139
paul94f2b392005-06-28 12:44:16 +00003140static void
paulfee0f4c2004-09-13 05:12:46 +00003141bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3142 struct prefix *p, afi_t afi, safi_t safi)
3143{
3144 struct bgp_node *rn;
3145 struct bgp_info *ri;
3146
3147 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3148
3149 /* Check selected route and self inserted route. */
3150 for (ri = rn->info; ri; ri = ri->next)
3151 if (ri->peer == bgp->peer_self
3152 && ri->type == ZEBRA_ROUTE_BGP
3153 && ri->sub_type == BGP_ROUTE_STATIC)
3154 break;
3155
3156 /* Withdraw static BGP route from routing table. */
3157 if (ri)
3158 {
paulfee0f4c2004-09-13 05:12:46 +00003159 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003160 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003161 }
3162
3163 /* Unlock bgp_node_lookup. */
3164 bgp_unlock_node (rn);
3165}
3166
paul94f2b392005-06-28 12:44:16 +00003167static void
paulfee0f4c2004-09-13 05:12:46 +00003168bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003169 struct bgp_static *bgp_static,
3170 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003171{
3172 struct bgp_node *rn;
3173 struct bgp_info *ri;
3174 struct bgp_info *new;
3175 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003176 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003177 struct attr attr = {0 };
3178 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003179 struct bgp *bgp;
3180 int ret;
3181 char buf[SU_ADDRSTRLEN];
3182
3183 bgp = rsclient->bgp;
3184
Paul Jakma06e110f2006-05-12 23:29:22 +00003185 assert (bgp_static);
3186 if (!bgp_static)
3187 return;
3188
paulfee0f4c2004-09-13 05:12:46 +00003189 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3190
3191 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003192
3193 attr.nexthop = bgp_static->igpnexthop;
3194 attr.med = bgp_static->igpmetric;
3195 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003196
3197 if (bgp_static->ttl)
3198 {
3199 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3200 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3201 attr.pathlimit.as = 0;
3202 attr.pathlimit.ttl = bgp_static->ttl;
3203 }
3204
3205 if (bgp_static->atomic)
3206 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3207
paulfee0f4c2004-09-13 05:12:46 +00003208 /* Apply network route-map for export to this rsclient. */
3209 if (bgp_static->rmap.name)
3210 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003211 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003212 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003213 info.attr = &attr_tmp;
3214
paulfee0f4c2004-09-13 05:12:46 +00003215 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3216 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3217
3218 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3219
3220 rsclient->rmap_type = 0;
3221
3222 if (ret == RMAP_DENYMATCH)
3223 {
3224 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003225 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003226
3227 /* Unintern original. */
3228 aspath_unintern (attr.aspath);
3229 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003230 bgp_attr_extra_free (&attr);
3231
paulfee0f4c2004-09-13 05:12:46 +00003232 return;
3233 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003234 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003235 }
3236 else
3237 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003238
paulfee0f4c2004-09-13 05:12:46 +00003239 new_attr = *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003240
paulfee0f4c2004-09-13 05:12:46 +00003241 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3242
Paul Jakmafb982c22007-05-04 20:15:47 +00003243 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3244 == RMAP_DENY)
3245 {
paulfee0f4c2004-09-13 05:12:46 +00003246 /* This BGP update is filtered. Log the reason then update BGP entry. */
3247 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003248 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003249 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3250 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3251 p->prefixlen, rsclient->host);
3252
3253 bgp->peer_self->rmap_type = 0;
3254
3255 bgp_attr_unintern (attr_new);
3256 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003257 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003258
3259 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3260
3261 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003262 }
paulfee0f4c2004-09-13 05:12:46 +00003263
3264 bgp->peer_self->rmap_type = 0;
3265
3266 bgp_attr_unintern (attr_new);
3267 attr_new = bgp_attr_intern (&new_attr);
3268
3269 for (ri = rn->info; ri; ri = ri->next)
3270 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3271 && ri->sub_type == BGP_ROUTE_STATIC)
3272 break;
3273
3274 if (ri)
3275 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003276 if (attrhash_cmp (ri->attr, attr_new) &&
3277 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003278 {
3279 bgp_unlock_node (rn);
3280 bgp_attr_unintern (attr_new);
3281 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003282 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003283 return;
3284 }
3285 else
3286 {
3287 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003288 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003289
3290 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003291 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3292 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003293 bgp_attr_unintern (ri->attr);
3294 ri->attr = attr_new;
3295 ri->uptime = time (NULL);
3296
3297 /* Process change. */
3298 bgp_process (bgp, rn, afi, safi);
3299 bgp_unlock_node (rn);
3300 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003301 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003302 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003303 }
paulfee0f4c2004-09-13 05:12:46 +00003304 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003305
paulfee0f4c2004-09-13 05:12:46 +00003306 /* Make new BGP info. */
3307 new = bgp_info_new ();
3308 new->type = ZEBRA_ROUTE_BGP;
3309 new->sub_type = BGP_ROUTE_STATIC;
3310 new->peer = bgp->peer_self;
3311 SET_FLAG (new->flags, BGP_INFO_VALID);
3312 new->attr = attr_new;
3313 new->uptime = time (NULL);
3314
3315 /* Register new BGP information. */
3316 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003317
3318 /* route_node_get lock */
3319 bgp_unlock_node (rn);
3320
paulfee0f4c2004-09-13 05:12:46 +00003321 /* Process change. */
3322 bgp_process (bgp, rn, afi, safi);
3323
3324 /* Unintern original. */
3325 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003326 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003327}
3328
paul94f2b392005-06-28 12:44:16 +00003329static void
paulfee0f4c2004-09-13 05:12:46 +00003330bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003331 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3332{
3333 struct bgp_node *rn;
3334 struct bgp_info *ri;
3335 struct bgp_info *new;
3336 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003337 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003338 struct attr *attr_new;
3339 int ret;
3340
Paul Jakmadd8103a2006-05-12 23:27:30 +00003341 assert (bgp_static);
3342 if (!bgp_static)
3343 return;
3344
paulfee0f4c2004-09-13 05:12:46 +00003345 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003346
3347 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003348
3349 attr.nexthop = bgp_static->igpnexthop;
3350 attr.med = bgp_static->igpmetric;
3351 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003352
Paul Jakma41367172007-08-06 15:24:51 +00003353 if (bgp_static->ttl)
3354 {
3355 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_AS_PATHLIMIT);
3356 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3357 attr.pathlimit.as = 0;
3358 attr.pathlimit.ttl = bgp_static->ttl;
3359 }
3360
3361 if (bgp_static->atomic)
3362 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3363
paul718e3742002-12-13 20:15:29 +00003364 /* Apply route-map. */
3365 if (bgp_static->rmap.name)
3366 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003367 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003368 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003369 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003370
paulfee0f4c2004-09-13 05:12:46 +00003371 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3372
paul718e3742002-12-13 20:15:29 +00003373 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003374
paulfee0f4c2004-09-13 05:12:46 +00003375 bgp->peer_self->rmap_type = 0;
3376
paul718e3742002-12-13 20:15:29 +00003377 if (ret == RMAP_DENYMATCH)
3378 {
3379 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003380 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003381
3382 /* Unintern original. */
3383 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003384 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003385 bgp_static_withdraw (bgp, p, afi, safi);
3386 return;
3387 }
paul286e1e72003-08-08 00:24:31 +00003388 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003389 }
paul286e1e72003-08-08 00:24:31 +00003390 else
3391 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003392
3393 for (ri = rn->info; ri; ri = ri->next)
3394 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3395 && ri->sub_type == BGP_ROUTE_STATIC)
3396 break;
3397
3398 if (ri)
3399 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003400 if (attrhash_cmp (ri->attr, attr_new) &&
3401 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003402 {
3403 bgp_unlock_node (rn);
3404 bgp_attr_unintern (attr_new);
3405 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003406 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003407 return;
3408 }
3409 else
3410 {
3411 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003412 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003413
3414 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003415 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3416 bgp_info_restore(rn, ri);
3417 else
3418 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003419 bgp_attr_unintern (ri->attr);
3420 ri->attr = attr_new;
3421 ri->uptime = time (NULL);
3422
3423 /* Process change. */
3424 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3425 bgp_process (bgp, rn, afi, safi);
3426 bgp_unlock_node (rn);
3427 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003428 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003429 return;
3430 }
3431 }
3432
3433 /* Make new BGP info. */
3434 new = bgp_info_new ();
3435 new->type = ZEBRA_ROUTE_BGP;
3436 new->sub_type = BGP_ROUTE_STATIC;
3437 new->peer = bgp->peer_self;
3438 SET_FLAG (new->flags, BGP_INFO_VALID);
3439 new->attr = attr_new;
3440 new->uptime = time (NULL);
3441
3442 /* Aggregate address increment. */
3443 bgp_aggregate_increment (bgp, p, new, afi, safi);
3444
3445 /* Register new BGP information. */
3446 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003447
3448 /* route_node_get lock */
3449 bgp_unlock_node (rn);
3450
paul718e3742002-12-13 20:15:29 +00003451 /* Process change. */
3452 bgp_process (bgp, rn, afi, safi);
3453
3454 /* Unintern original. */
3455 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003456 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003457}
3458
3459void
paulfee0f4c2004-09-13 05:12:46 +00003460bgp_static_update (struct bgp *bgp, struct prefix *p,
3461 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3462{
3463 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003464 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003465
3466 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3467
paul1eb8ef22005-04-07 07:30:20 +00003468 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003469 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003470 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3471 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003472 }
3473}
3474
paul94f2b392005-06-28 12:44:16 +00003475static void
paul718e3742002-12-13 20:15:29 +00003476bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3477 u_char safi, struct prefix_rd *prd, u_char *tag)
3478{
3479 struct bgp_node *rn;
3480 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003481
paulfee0f4c2004-09-13 05:12:46 +00003482 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003483
3484 /* Make new BGP info. */
3485 new = bgp_info_new ();
3486 new->type = ZEBRA_ROUTE_BGP;
3487 new->sub_type = BGP_ROUTE_STATIC;
3488 new->peer = bgp->peer_self;
3489 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3490 SET_FLAG (new->flags, BGP_INFO_VALID);
3491 new->uptime = time (NULL);
Paul Jakmafb982c22007-05-04 20:15:47 +00003492 new->extra = bgp_info_extra_new();
3493 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003494
3495 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003496 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003497
3498 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003499 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003500
paul200df112005-06-01 11:17:05 +00003501 /* route_node_get lock */
3502 bgp_unlock_node (rn);
3503
paul718e3742002-12-13 20:15:29 +00003504 /* Process change. */
3505 bgp_process (bgp, rn, afi, safi);
3506}
3507
3508void
3509bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3510 safi_t safi)
3511{
3512 struct bgp_node *rn;
3513 struct bgp_info *ri;
3514
paulfee0f4c2004-09-13 05:12:46 +00003515 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003516
3517 /* Check selected route and self inserted route. */
3518 for (ri = rn->info; ri; ri = ri->next)
3519 if (ri->peer == bgp->peer_self
3520 && ri->type == ZEBRA_ROUTE_BGP
3521 && ri->sub_type == BGP_ROUTE_STATIC)
3522 break;
3523
3524 /* Withdraw static BGP route from routing table. */
3525 if (ri)
3526 {
3527 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003528 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003529 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003530 }
3531
3532 /* Unlock bgp_node_lookup. */
3533 bgp_unlock_node (rn);
3534}
3535
3536void
paulfee0f4c2004-09-13 05:12:46 +00003537bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3538{
3539 struct bgp_static *bgp_static;
3540 struct bgp *bgp;
3541 struct bgp_node *rn;
3542 struct prefix *p;
3543
3544 bgp = rsclient->bgp;
3545
3546 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3547 if ((bgp_static = rn->info) != NULL)
3548 {
3549 p = &rn->p;
3550
3551 bgp_static_update_rsclient (rsclient, p, bgp_static,
3552 afi, safi);
3553 }
3554}
3555
paul94f2b392005-06-28 12:44:16 +00003556static void
paul718e3742002-12-13 20:15:29 +00003557bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, u_int16_t afi,
3558 u_char safi, struct prefix_rd *prd, u_char *tag)
3559{
3560 struct bgp_node *rn;
3561 struct bgp_info *ri;
3562
paulfee0f4c2004-09-13 05:12:46 +00003563 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003564
3565 /* Check selected route and self inserted route. */
3566 for (ri = rn->info; ri; ri = ri->next)
3567 if (ri->peer == bgp->peer_self
3568 && ri->type == ZEBRA_ROUTE_BGP
3569 && ri->sub_type == BGP_ROUTE_STATIC)
3570 break;
3571
3572 /* Withdraw static BGP route from routing table. */
3573 if (ri)
3574 {
3575 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003576 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003577 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003578 }
3579
3580 /* Unlock bgp_node_lookup. */
3581 bgp_unlock_node (rn);
3582}
3583
Paul Jakma41367172007-08-06 15:24:51 +00003584static void
3585bgp_pathlimit_update_parents (struct bgp *bgp, struct bgp_node *rn,
3586 int ttl_edge)
3587{
3588 struct bgp_node *parent = rn;
3589 struct bgp_static *sp;
3590
3591 /* Existing static changed TTL, search parents and adjust their atomic */
3592 while ((parent = parent->parent))
3593 if ((sp = parent->info))
3594 {
3595 int sp_level = (sp->atomic ? 1 : 0);
3596 ttl_edge ? sp->atomic++ : sp->atomic--;
3597
3598 /* did we change state of parent whether atomic is set or not? */
3599 if (sp_level != (sp->atomic ? 1 : 0))
3600 {
3601 bgp_static_update (bgp, &parent->p, sp,
3602 rn->table->afi, rn->table->safi);
3603 }
3604 }
3605}
3606
paul718e3742002-12-13 20:15:29 +00003607/* Configure static BGP network. When user don't run zebra, static
3608 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003609static int
paulfd79ac92004-10-13 05:06:08 +00003610bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakma41367172007-08-06 15:24:51 +00003611 u_int16_t afi, u_char safi, const char *rmap, int backdoor,
3612 u_char ttl)
paul718e3742002-12-13 20:15:29 +00003613{
3614 int ret;
3615 struct prefix p;
3616 struct bgp_static *bgp_static;
3617 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003618 u_char need_update = 0;
3619 u_char ttl_change = 0;
3620 u_char ttl_edge = (ttl ? 1 : 0);
3621 u_char new = 0;
paul718e3742002-12-13 20:15:29 +00003622
3623 /* Convert IP prefix string to struct prefix. */
3624 ret = str2prefix (ip_str, &p);
3625 if (! ret)
3626 {
3627 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3628 return CMD_WARNING;
3629 }
3630#ifdef HAVE_IPV6
3631 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3632 {
3633 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3634 VTY_NEWLINE);
3635 return CMD_WARNING;
3636 }
3637#endif /* HAVE_IPV6 */
3638
3639 apply_mask (&p);
3640
3641 /* Set BGP static route configuration. */
3642 rn = bgp_node_get (bgp->route[afi][safi], &p);
3643
3644 if (rn->info)
3645 {
3646 /* Configuration change. */
3647 bgp_static = rn->info;
3648
3649 /* Check previous routes are installed into BGP. */
Paul Jakma41367172007-08-06 15:24:51 +00003650 if (bgp_static->valid)
3651 {
3652 if (bgp_static->backdoor != backdoor
3653 || bgp_static->ttl != ttl)
3654 need_update = 1;
3655 }
3656
3657 /* need to catch TTL set/unset transitions for handling of
3658 * ATOMIC_AGGREGATE
3659 */
3660 if ((bgp_static->ttl ? 1 : 0) != ttl_edge)
3661 ttl_change = 1;
3662
paul718e3742002-12-13 20:15:29 +00003663 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003664 bgp_static->ttl = ttl;
3665
paul718e3742002-12-13 20:15:29 +00003666 if (rmap)
3667 {
3668 if (bgp_static->rmap.name)
3669 free (bgp_static->rmap.name);
3670 bgp_static->rmap.name = strdup (rmap);
3671 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3672 }
3673 else
3674 {
3675 if (bgp_static->rmap.name)
3676 free (bgp_static->rmap.name);
3677 bgp_static->rmap.name = NULL;
3678 bgp_static->rmap.map = NULL;
3679 bgp_static->valid = 0;
3680 }
3681 bgp_unlock_node (rn);
3682 }
3683 else
3684 {
3685 /* New configuration. */
3686 bgp_static = bgp_static_new ();
3687 bgp_static->backdoor = backdoor;
3688 bgp_static->valid = 0;
3689 bgp_static->igpmetric = 0;
3690 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003691 bgp_static->ttl = ttl;
3692 ttl_change = ttl_edge;
3693 new = 1;
3694
paul718e3742002-12-13 20:15:29 +00003695 if (rmap)
3696 {
3697 if (bgp_static->rmap.name)
3698 free (bgp_static->rmap.name);
3699 bgp_static->rmap.name = strdup (rmap);
3700 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3701 }
3702 rn->info = bgp_static;
3703 }
3704
Paul Jakma41367172007-08-06 15:24:51 +00003705 /* ".. sites that choose to advertise the
3706 * AS_PATHLIMIT path attribute SHOULD advertise the ATOMIC_AGGREGATE on
3707 * all less specific covering prefixes as well as the more specific
3708 * prefixes."
3709 *
3710 * So:
3711 * Prefix that has just had pathlimit set/unset:
3712 * - Must bump ATOMIC refcount on all parents.
3713 *
3714 * To catch less specific prefixes:
3715 * - Must search children for ones with TTL, bump atomic refcount
3716 * (we dont care if we're deleting a less specific prefix..)
3717 */
3718 if (ttl_change)
3719 {
3720 /* Existing static changed TTL, search parents and adjust their atomic */
3721 bgp_pathlimit_update_parents (bgp, rn, ttl_edge);
3722 }
3723
3724 if (new)
3725 {
3726 struct bgp_node *child;
3727 struct bgp_static *sc;
3728
3729 /* New static, search children and bump this statics atomic.. */
3730 child = bgp_lock_node (rn); /* route_next_until unlocks it.. */
3731 while ((child = bgp_route_next_until (child, rn)))
3732 {
3733 if ((sc = child->info) && sc->ttl)
3734 bgp_static->atomic++;
3735 }
3736 }
3737
paul718e3742002-12-13 20:15:29 +00003738 /* If BGP scan is not enabled, we should install this route here. */
3739 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3740 {
3741 bgp_static->valid = 1;
3742
3743 if (need_update)
3744 bgp_static_withdraw (bgp, &p, afi, safi);
3745
3746 if (! bgp_static->backdoor)
3747 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3748 }
3749
3750 return CMD_SUCCESS;
3751}
3752
3753/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003754static int
paulfd79ac92004-10-13 05:06:08 +00003755bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
paul718e3742002-12-13 20:15:29 +00003756 u_int16_t afi, u_char safi)
3757{
3758 int ret;
3759 struct prefix p;
3760 struct bgp_static *bgp_static;
3761 struct bgp_node *rn;
3762
3763 /* Convert IP prefix string to struct prefix. */
3764 ret = str2prefix (ip_str, &p);
3765 if (! ret)
3766 {
3767 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3768 return CMD_WARNING;
3769 }
3770#ifdef HAVE_IPV6
3771 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3772 {
3773 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3774 VTY_NEWLINE);
3775 return CMD_WARNING;
3776 }
3777#endif /* HAVE_IPV6 */
3778
3779 apply_mask (&p);
3780
3781 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3782 if (! rn)
3783 {
3784 vty_out (vty, "%% Can't find specified static route configuration.%s",
3785 VTY_NEWLINE);
3786 return CMD_WARNING;
3787 }
3788
3789 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003790
3791 /* decrement atomic in parents, see bgp_static_set */
3792 bgp_pathlimit_update_parents (bgp, rn, 0);
3793
paul718e3742002-12-13 20:15:29 +00003794 /* Update BGP RIB. */
3795 if (! bgp_static->backdoor)
3796 bgp_static_withdraw (bgp, &p, afi, safi);
3797
3798 /* Clear configuration. */
3799 bgp_static_free (bgp_static);
3800 rn->info = NULL;
3801 bgp_unlock_node (rn);
3802 bgp_unlock_node (rn);
3803
3804 return CMD_SUCCESS;
3805}
3806
3807/* Called from bgp_delete(). Delete all static routes from the BGP
3808 instance. */
3809void
3810bgp_static_delete (struct bgp *bgp)
3811{
3812 afi_t afi;
3813 safi_t safi;
3814 struct bgp_node *rn;
3815 struct bgp_node *rm;
3816 struct bgp_table *table;
3817 struct bgp_static *bgp_static;
3818
3819 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3820 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3821 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3822 if (rn->info != NULL)
3823 {
3824 if (safi == SAFI_MPLS_VPN)
3825 {
3826 table = rn->info;
3827
3828 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3829 {
3830 bgp_static = rn->info;
3831 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3832 AFI_IP, SAFI_MPLS_VPN,
3833 (struct prefix_rd *)&rn->p,
3834 bgp_static->tag);
3835 bgp_static_free (bgp_static);
3836 rn->info = NULL;
3837 bgp_unlock_node (rn);
3838 }
3839 }
3840 else
3841 {
3842 bgp_static = rn->info;
3843 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3844 bgp_static_free (bgp_static);
3845 rn->info = NULL;
3846 bgp_unlock_node (rn);
3847 }
3848 }
3849}
3850
3851int
paulfd79ac92004-10-13 05:06:08 +00003852bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3853 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003854{
3855 int ret;
3856 struct prefix p;
3857 struct prefix_rd prd;
3858 struct bgp *bgp;
3859 struct bgp_node *prn;
3860 struct bgp_node *rn;
3861 struct bgp_table *table;
3862 struct bgp_static *bgp_static;
3863 u_char tag[3];
3864
3865 bgp = vty->index;
3866
3867 ret = str2prefix (ip_str, &p);
3868 if (! ret)
3869 {
3870 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3871 return CMD_WARNING;
3872 }
3873 apply_mask (&p);
3874
3875 ret = str2prefix_rd (rd_str, &prd);
3876 if (! ret)
3877 {
3878 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3879 return CMD_WARNING;
3880 }
3881
3882 ret = str2tag (tag_str, tag);
3883 if (! ret)
3884 {
3885 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3886 return CMD_WARNING;
3887 }
3888
3889 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3890 (struct prefix *)&prd);
3891 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003892 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003893 else
3894 bgp_unlock_node (prn);
3895 table = prn->info;
3896
3897 rn = bgp_node_get (table, &p);
3898
3899 if (rn->info)
3900 {
3901 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3902 bgp_unlock_node (rn);
3903 }
3904 else
3905 {
3906 /* New configuration. */
3907 bgp_static = bgp_static_new ();
3908 bgp_static->valid = 1;
3909 memcpy (bgp_static->tag, tag, 3);
3910 rn->info = bgp_static;
3911
3912 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3913 }
3914
3915 return CMD_SUCCESS;
3916}
3917
3918/* Configure static BGP network. */
3919int
paulfd79ac92004-10-13 05:06:08 +00003920bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3921 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003922{
3923 int ret;
3924 struct bgp *bgp;
3925 struct prefix p;
3926 struct prefix_rd prd;
3927 struct bgp_node *prn;
3928 struct bgp_node *rn;
3929 struct bgp_table *table;
3930 struct bgp_static *bgp_static;
3931 u_char tag[3];
3932
3933 bgp = vty->index;
3934
3935 /* Convert IP prefix string to struct prefix. */
3936 ret = str2prefix (ip_str, &p);
3937 if (! ret)
3938 {
3939 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3940 return CMD_WARNING;
3941 }
3942 apply_mask (&p);
3943
3944 ret = str2prefix_rd (rd_str, &prd);
3945 if (! ret)
3946 {
3947 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3948 return CMD_WARNING;
3949 }
3950
3951 ret = str2tag (tag_str, tag);
3952 if (! ret)
3953 {
3954 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3955 return CMD_WARNING;
3956 }
3957
3958 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3959 (struct prefix *)&prd);
3960 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003961 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003962 else
3963 bgp_unlock_node (prn);
3964 table = prn->info;
3965
3966 rn = bgp_node_lookup (table, &p);
3967
3968 if (rn)
3969 {
3970 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3971
3972 bgp_static = rn->info;
3973 bgp_static_free (bgp_static);
3974 rn->info = NULL;
3975 bgp_unlock_node (rn);
3976 bgp_unlock_node (rn);
3977 }
3978 else
3979 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3980
3981 return CMD_SUCCESS;
3982}
3983
3984DEFUN (bgp_network,
3985 bgp_network_cmd,
3986 "network A.B.C.D/M",
3987 "Specify a network to announce via BGP\n"
3988 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3989{
Paul Jakma41367172007-08-06 15:24:51 +00003990 u_char ttl = 0;
3991
3992 if (argc == 2)
3993 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
3994
paul718e3742002-12-13 20:15:29 +00003995 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00003996 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00003997}
3998
Paul Jakma41367172007-08-06 15:24:51 +00003999ALIAS (bgp_network,
4000 bgp_network_ttl_cmd,
4001 "network A.B.C.D/M pathlimit <0-255>",
4002 "Specify a network to announce via BGP\n"
4003 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4004 "AS-Path hopcount limit attribute\n"
4005 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4006
paul718e3742002-12-13 20:15:29 +00004007DEFUN (bgp_network_route_map,
4008 bgp_network_route_map_cmd,
4009 "network A.B.C.D/M route-map WORD",
4010 "Specify a network to announce via BGP\n"
4011 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4012 "Route-map to modify the attributes\n"
4013 "Name of the route map\n")
4014{
4015 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakma41367172007-08-06 15:24:51 +00004016 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004017}
4018
4019DEFUN (bgp_network_backdoor,
4020 bgp_network_backdoor_cmd,
4021 "network A.B.C.D/M backdoor",
4022 "Specify a network to announce via BGP\n"
4023 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4024 "Specify a BGP backdoor route\n")
4025{
Paul Jakma41367172007-08-06 15:24:51 +00004026 u_char ttl = 0;
4027
4028 if (argc == 2)
4029 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4030
4031 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
4032 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004033}
4034
Paul Jakma41367172007-08-06 15:24:51 +00004035ALIAS (bgp_network_backdoor,
4036 bgp_network_backdoor_ttl_cmd,
4037 "network A.B.C.D/M backdoor pathlimit <0-255>",
4038 "Specify a network to announce via BGP\n"
4039 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4040 "Specify a BGP backdoor route\n"
4041 "AS-Path hopcount limit attribute\n"
4042 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4043
paul718e3742002-12-13 20:15:29 +00004044DEFUN (bgp_network_mask,
4045 bgp_network_mask_cmd,
4046 "network A.B.C.D mask A.B.C.D",
4047 "Specify a network to announce via BGP\n"
4048 "Network number\n"
4049 "Network mask\n"
4050 "Network mask\n")
4051{
4052 int ret;
4053 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004054 u_char ttl = 0;
4055
4056 if (argc == 3)
4057 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
4058
paul718e3742002-12-13 20:15:29 +00004059 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4060 if (! ret)
4061 {
4062 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4063 return CMD_WARNING;
4064 }
4065
4066 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004067 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004068}
4069
Paul Jakma41367172007-08-06 15:24:51 +00004070ALIAS (bgp_network_mask,
4071 bgp_network_mask_ttl_cmd,
4072 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4073 "Specify a network to announce via BGP\n"
4074 "Network number\n"
4075 "Network mask\n"
4076 "Network mask\n"
4077 "AS-Path hopcount limit attribute\n"
4078 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4079
paul718e3742002-12-13 20:15:29 +00004080DEFUN (bgp_network_mask_route_map,
4081 bgp_network_mask_route_map_cmd,
4082 "network A.B.C.D mask A.B.C.D route-map WORD",
4083 "Specify a network to announce via BGP\n"
4084 "Network number\n"
4085 "Network mask\n"
4086 "Network mask\n"
4087 "Route-map to modify the attributes\n"
4088 "Name of the route map\n")
4089{
4090 int ret;
4091 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004092
paul718e3742002-12-13 20:15:29 +00004093 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4094 if (! ret)
4095 {
4096 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4097 return CMD_WARNING;
4098 }
4099
4100 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004101 AFI_IP, bgp_node_safi (vty), argv[2], 0, 0);
paul718e3742002-12-13 20:15:29 +00004102}
4103
4104DEFUN (bgp_network_mask_backdoor,
4105 bgp_network_mask_backdoor_cmd,
4106 "network A.B.C.D mask A.B.C.D backdoor",
4107 "Specify a network to announce via BGP\n"
4108 "Network number\n"
4109 "Network mask\n"
4110 "Network mask\n"
4111 "Specify a BGP backdoor route\n")
4112{
4113 int ret;
4114 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004115 u_char ttl = 0;
4116
4117 if (argc == 3)
4118 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[2], 1, 255);
paul718e3742002-12-13 20:15:29 +00004119
4120 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4121 if (! ret)
4122 {
4123 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4124 return CMD_WARNING;
4125 }
4126
Paul Jakma41367172007-08-06 15:24:51 +00004127 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4128 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004129}
4130
Paul Jakma41367172007-08-06 15:24:51 +00004131ALIAS (bgp_network_mask_backdoor,
4132 bgp_network_mask_backdoor_ttl_cmd,
4133 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4134 "Specify a network to announce via BGP\n"
4135 "Network number\n"
4136 "Network mask\n"
4137 "Network mask\n"
4138 "Specify a BGP backdoor route\n"
4139 "AS-Path hopcount limit attribute\n"
4140 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4141
paul718e3742002-12-13 20:15:29 +00004142DEFUN (bgp_network_mask_natural,
4143 bgp_network_mask_natural_cmd,
4144 "network A.B.C.D",
4145 "Specify a network to announce via BGP\n"
4146 "Network number\n")
4147{
4148 int ret;
4149 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004150 u_char ttl = 0;
4151
4152 if (argc == 2)
4153 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004154
4155 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4156 if (! ret)
4157 {
4158 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4159 return CMD_WARNING;
4160 }
4161
4162 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004163 AFI_IP, bgp_node_safi (vty), NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004164}
4165
Paul Jakma41367172007-08-06 15:24:51 +00004166ALIAS (bgp_network_mask_natural,
4167 bgp_network_mask_natural_ttl_cmd,
4168 "network A.B.C.D pathlimit <0-255>",
4169 "Specify a network to announce via BGP\n"
4170 "Network number\n"
4171 "AS-Path hopcount limit attribute\n"
4172 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4173
paul718e3742002-12-13 20:15:29 +00004174DEFUN (bgp_network_mask_natural_route_map,
4175 bgp_network_mask_natural_route_map_cmd,
4176 "network A.B.C.D route-map WORD",
4177 "Specify a network to announce via BGP\n"
4178 "Network number\n"
4179 "Route-map to modify the attributes\n"
4180 "Name of the route map\n")
4181{
4182 int ret;
4183 char prefix_str[BUFSIZ];
4184
4185 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4186 if (! ret)
4187 {
4188 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4189 return CMD_WARNING;
4190 }
4191
4192 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakma41367172007-08-06 15:24:51 +00004193 AFI_IP, bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004194}
4195
4196DEFUN (bgp_network_mask_natural_backdoor,
4197 bgp_network_mask_natural_backdoor_cmd,
4198 "network A.B.C.D backdoor",
4199 "Specify a network to announce via BGP\n"
4200 "Network number\n"
4201 "Specify a BGP backdoor route\n")
4202{
4203 int ret;
4204 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004205 u_char ttl = 0;
4206
4207 if (argc == 2)
4208 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
paul718e3742002-12-13 20:15:29 +00004209
4210 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4211 if (! ret)
4212 {
4213 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4214 return CMD_WARNING;
4215 }
4216
Paul Jakma41367172007-08-06 15:24:51 +00004217 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
4218 NULL, 1, ttl);
paul718e3742002-12-13 20:15:29 +00004219}
4220
Paul Jakma41367172007-08-06 15:24:51 +00004221ALIAS (bgp_network_mask_natural_backdoor,
4222 bgp_network_mask_natural_backdoor_ttl_cmd,
4223 "network A.B.C.D backdoor pathlimit (1-255>",
4224 "Specify a network to announce via BGP\n"
4225 "Network number\n"
4226 "Specify a BGP backdoor route\n"
4227 "AS-Path hopcount limit attribute\n"
4228 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4229
paul718e3742002-12-13 20:15:29 +00004230DEFUN (no_bgp_network,
4231 no_bgp_network_cmd,
4232 "no network A.B.C.D/M",
4233 NO_STR
4234 "Specify a network to announce via BGP\n"
4235 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4236{
4237 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4238 bgp_node_safi (vty));
4239}
4240
4241ALIAS (no_bgp_network,
Paul Jakma41367172007-08-06 15:24:51 +00004242 no_bgp_network_ttl_cmd,
4243 "no network A.B.C.D/M pathlimit <0-255>",
4244 NO_STR
4245 "Specify a network to announce via BGP\n"
4246 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4247 "AS-Path hopcount limit attribute\n"
4248 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4249
4250ALIAS (no_bgp_network,
paul718e3742002-12-13 20:15:29 +00004251 no_bgp_network_route_map_cmd,
4252 "no network A.B.C.D/M route-map WORD",
4253 NO_STR
4254 "Specify a network to announce via BGP\n"
4255 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4256 "Route-map to modify the attributes\n"
4257 "Name of the route map\n")
4258
4259ALIAS (no_bgp_network,
4260 no_bgp_network_backdoor_cmd,
4261 "no network A.B.C.D/M backdoor",
4262 NO_STR
4263 "Specify a network to announce via BGP\n"
4264 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4265 "Specify a BGP backdoor route\n")
4266
Paul Jakma41367172007-08-06 15:24:51 +00004267ALIAS (no_bgp_network,
4268 no_bgp_network_backdoor_ttl_cmd,
4269 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4270 NO_STR
4271 "Specify a network to announce via BGP\n"
4272 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4273 "Specify a BGP backdoor route\n"
4274 "AS-Path hopcount limit attribute\n"
4275 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4276
paul718e3742002-12-13 20:15:29 +00004277DEFUN (no_bgp_network_mask,
4278 no_bgp_network_mask_cmd,
4279 "no network A.B.C.D mask A.B.C.D",
4280 NO_STR
4281 "Specify a network to announce via BGP\n"
4282 "Network number\n"
4283 "Network mask\n"
4284 "Network mask\n")
4285{
4286 int ret;
4287 char prefix_str[BUFSIZ];
4288
4289 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4290 if (! ret)
4291 {
4292 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4293 return CMD_WARNING;
4294 }
4295
4296 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4297 bgp_node_safi (vty));
4298}
4299
Paul Jakma41367172007-08-06 15:24:51 +00004300ALIAS (no_bgp_network,
4301 no_bgp_network_mask_ttl_cmd,
4302 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4303 NO_STR
4304 "Specify a network to announce via BGP\n"
4305 "Network number\n"
4306 "Network mask\n"
4307 "Network mask\n"
4308 "AS-Path hopcount limit attribute\n"
4309 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4310
paul718e3742002-12-13 20:15:29 +00004311ALIAS (no_bgp_network_mask,
4312 no_bgp_network_mask_route_map_cmd,
4313 "no network A.B.C.D mask A.B.C.D route-map WORD",
4314 NO_STR
4315 "Specify a network to announce via BGP\n"
4316 "Network number\n"
4317 "Network mask\n"
4318 "Network mask\n"
4319 "Route-map to modify the attributes\n"
4320 "Name of the route map\n")
4321
4322ALIAS (no_bgp_network_mask,
4323 no_bgp_network_mask_backdoor_cmd,
4324 "no network A.B.C.D mask A.B.C.D backdoor",
4325 NO_STR
4326 "Specify a network to announce via BGP\n"
4327 "Network number\n"
4328 "Network mask\n"
4329 "Network mask\n"
4330 "Specify a BGP backdoor route\n")
4331
Paul Jakma41367172007-08-06 15:24:51 +00004332ALIAS (no_bgp_network_mask,
4333 no_bgp_network_mask_backdoor_ttl_cmd,
4334 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4335 NO_STR
4336 "Specify a network to announce via BGP\n"
4337 "Network number\n"
4338 "Network mask\n"
4339 "Network mask\n"
4340 "Specify a BGP backdoor route\n"
4341 "AS-Path hopcount limit attribute\n"
4342 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4343
paul718e3742002-12-13 20:15:29 +00004344DEFUN (no_bgp_network_mask_natural,
4345 no_bgp_network_mask_natural_cmd,
4346 "no network A.B.C.D",
4347 NO_STR
4348 "Specify a network to announce via BGP\n"
4349 "Network number\n")
4350{
4351 int ret;
4352 char prefix_str[BUFSIZ];
4353
4354 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4355 if (! ret)
4356 {
4357 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4358 return CMD_WARNING;
4359 }
4360
4361 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4362 bgp_node_safi (vty));
4363}
4364
4365ALIAS (no_bgp_network_mask_natural,
4366 no_bgp_network_mask_natural_route_map_cmd,
4367 "no network A.B.C.D route-map WORD",
4368 NO_STR
4369 "Specify a network to announce via BGP\n"
4370 "Network number\n"
4371 "Route-map to modify the attributes\n"
4372 "Name of the route map\n")
4373
4374ALIAS (no_bgp_network_mask_natural,
4375 no_bgp_network_mask_natural_backdoor_cmd,
4376 "no network A.B.C.D backdoor",
4377 NO_STR
4378 "Specify a network to announce via BGP\n"
4379 "Network number\n"
4380 "Specify a BGP backdoor route\n")
4381
Paul Jakma41367172007-08-06 15:24:51 +00004382ALIAS (no_bgp_network_mask_natural,
4383 no_bgp_network_mask_natural_ttl_cmd,
4384 "no network A.B.C.D pathlimit <0-255>",
4385 NO_STR
4386 "Specify a network to announce via BGP\n"
4387 "Network number\n"
4388 "AS-Path hopcount limit attribute\n"
4389 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4390
4391ALIAS (no_bgp_network_mask_natural,
4392 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4393 "no network A.B.C.D backdoor pathlimit <0-255>",
4394 NO_STR
4395 "Specify a network to announce via BGP\n"
4396 "Network number\n"
4397 "Specify a BGP backdoor route\n"
4398 "AS-Path hopcount limit attribute\n"
4399 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4400
paul718e3742002-12-13 20:15:29 +00004401#ifdef HAVE_IPV6
4402DEFUN (ipv6_bgp_network,
4403 ipv6_bgp_network_cmd,
4404 "network X:X::X:X/M",
4405 "Specify a network to announce via BGP\n"
4406 "IPv6 prefix <network>/<length>\n")
4407{
Paul Jakma41367172007-08-06 15:24:51 +00004408 u_char ttl = 0;
4409
4410 if (argc == 2)
4411 VTY_GET_INTEGER_RANGE ("Pathlimit TTL", ttl, argv[1], 1, 255);
4412
4413 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
4414 NULL, 0, ttl);
paul718e3742002-12-13 20:15:29 +00004415}
4416
Paul Jakma41367172007-08-06 15:24:51 +00004417ALIAS (ipv6_bgp_network,
4418 ipv6_bgp_network_ttl_cmd,
4419 "network X:X::X:X/M pathlimit <0-255>",
4420 "Specify a network to announce via BGP\n"
4421 "IPv6 prefix <network>/<length>\n"
4422 "AS-Path hopcount limit attribute\n"
4423 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4424
paul718e3742002-12-13 20:15:29 +00004425DEFUN (ipv6_bgp_network_route_map,
4426 ipv6_bgp_network_route_map_cmd,
4427 "network X:X::X:X/M route-map WORD",
4428 "Specify a network to announce via BGP\n"
4429 "IPv6 prefix <network>/<length>\n"
4430 "Route-map to modify the attributes\n"
4431 "Name of the route map\n")
4432{
4433 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakma41367172007-08-06 15:24:51 +00004434 bgp_node_safi (vty), argv[1], 0, 0);
paul718e3742002-12-13 20:15:29 +00004435}
4436
4437DEFUN (no_ipv6_bgp_network,
4438 no_ipv6_bgp_network_cmd,
4439 "no network X:X::X:X/M",
4440 NO_STR
4441 "Specify a network to announce via BGP\n"
4442 "IPv6 prefix <network>/<length>\n")
4443{
4444 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4445}
4446
4447ALIAS (no_ipv6_bgp_network,
4448 no_ipv6_bgp_network_route_map_cmd,
4449 "no network X:X::X:X/M route-map WORD",
4450 NO_STR
4451 "Specify a network to announce via BGP\n"
4452 "IPv6 prefix <network>/<length>\n"
4453 "Route-map to modify the attributes\n"
4454 "Name of the route map\n")
4455
Paul Jakma41367172007-08-06 15:24:51 +00004456ALIAS (no_ipv6_bgp_network,
4457 no_ipv6_bgp_network_ttl_cmd,
4458 "no network X:X::X:X/M pathlimit <0-255>",
4459 NO_STR
4460 "Specify a network to announce via BGP\n"
4461 "IPv6 prefix <network>/<length>\n"
4462 "AS-Path hopcount limit attribute\n"
4463 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4464
paul718e3742002-12-13 20:15:29 +00004465ALIAS (ipv6_bgp_network,
4466 old_ipv6_bgp_network_cmd,
4467 "ipv6 bgp network X:X::X:X/M",
4468 IPV6_STR
4469 BGP_STR
4470 "Specify a network to announce via BGP\n"
4471 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4472
4473ALIAS (no_ipv6_bgp_network,
4474 old_no_ipv6_bgp_network_cmd,
4475 "no ipv6 bgp network X:X::X:X/M",
4476 NO_STR
4477 IPV6_STR
4478 BGP_STR
4479 "Specify a network to announce via BGP\n"
4480 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4481#endif /* HAVE_IPV6 */
4482
4483/* Aggreagete address:
4484
4485 advertise-map Set condition to advertise attribute
4486 as-set Generate AS set path information
4487 attribute-map Set attributes of aggregate
4488 route-map Set parameters of aggregate
4489 summary-only Filter more specific routes from updates
4490 suppress-map Conditionally filter more specific routes from updates
4491 <cr>
4492 */
4493struct bgp_aggregate
4494{
4495 /* Summary-only flag. */
4496 u_char summary_only;
4497
4498 /* AS set generation. */
4499 u_char as_set;
4500
4501 /* Route-map for aggregated route. */
4502 struct route_map *map;
4503
4504 /* Suppress-count. */
4505 unsigned long count;
4506
4507 /* SAFI configuration. */
4508 safi_t safi;
4509};
4510
paul94f2b392005-06-28 12:44:16 +00004511static struct bgp_aggregate *
paul718e3742002-12-13 20:15:29 +00004512bgp_aggregate_new ()
4513{
4514 struct bgp_aggregate *new;
4515 new = XMALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
4516 memset (new, 0, sizeof (struct bgp_aggregate));
4517 return new;
4518}
4519
paul94f2b392005-06-28 12:44:16 +00004520static void
paul718e3742002-12-13 20:15:29 +00004521bgp_aggregate_free (struct bgp_aggregate *aggregate)
4522{
4523 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4524}
4525
paul94f2b392005-06-28 12:44:16 +00004526static void
paul718e3742002-12-13 20:15:29 +00004527bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4528 afi_t afi, safi_t safi, struct bgp_info *del,
4529 struct bgp_aggregate *aggregate)
4530{
4531 struct bgp_table *table;
4532 struct bgp_node *top;
4533 struct bgp_node *rn;
4534 u_char origin;
4535 struct aspath *aspath = NULL;
4536 struct aspath *asmerge = NULL;
4537 struct community *community = NULL;
4538 struct community *commerge = NULL;
4539 struct in_addr nexthop;
4540 u_int32_t med = 0;
4541 struct bgp_info *ri;
4542 struct bgp_info *new;
4543 int first = 1;
4544 unsigned long match = 0;
4545
4546 /* Record adding route's nexthop and med. */
4547 if (rinew)
4548 {
4549 nexthop = rinew->attr->nexthop;
4550 med = rinew->attr->med;
4551 }
4552
4553 /* ORIGIN attribute: If at least one route among routes that are
4554 aggregated has ORIGIN with the value INCOMPLETE, then the
4555 aggregated route must have the ORIGIN attribute with the value
4556 INCOMPLETE. Otherwise, if at least one route among routes that
4557 are aggregated has ORIGIN with the value EGP, then the aggregated
4558 route must have the origin attribute with the value EGP. In all
4559 other case the value of the ORIGIN attribute of the aggregated
4560 route is INTERNAL. */
4561 origin = BGP_ORIGIN_IGP;
4562
4563 table = bgp->rib[afi][safi];
4564
4565 top = bgp_node_get (table, p);
4566 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4567 if (rn->p.prefixlen > p->prefixlen)
4568 {
4569 match = 0;
4570
4571 for (ri = rn->info; ri; ri = ri->next)
4572 {
4573 if (BGP_INFO_HOLDDOWN (ri))
4574 continue;
4575
4576 if (del && ri == del)
4577 continue;
4578
4579 if (! rinew && first)
4580 {
4581 nexthop = ri->attr->nexthop;
4582 med = ri->attr->med;
4583 first = 0;
4584 }
4585
4586#ifdef AGGREGATE_NEXTHOP_CHECK
4587 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4588 || ri->attr->med != med)
4589 {
4590 if (aspath)
4591 aspath_free (aspath);
4592 if (community)
4593 community_free (community);
4594 bgp_unlock_node (rn);
4595 bgp_unlock_node (top);
4596 return;
4597 }
4598#endif /* AGGREGATE_NEXTHOP_CHECK */
4599
4600 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4601 {
4602 if (aggregate->summary_only)
4603 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004604 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004605 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004606 match++;
4607 }
4608
4609 aggregate->count++;
4610
4611 if (aggregate->as_set)
4612 {
4613 if (origin < ri->attr->origin)
4614 origin = ri->attr->origin;
4615
4616 if (aspath)
4617 {
4618 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4619 aspath_free (aspath);
4620 aspath = asmerge;
4621 }
4622 else
4623 aspath = aspath_dup (ri->attr->aspath);
4624
4625 if (ri->attr->community)
4626 {
4627 if (community)
4628 {
4629 commerge = community_merge (community,
4630 ri->attr->community);
4631 community = community_uniq_sort (commerge);
4632 community_free (commerge);
4633 }
4634 else
4635 community = community_dup (ri->attr->community);
4636 }
4637 }
4638 }
4639 }
4640 if (match)
4641 bgp_process (bgp, rn, afi, safi);
4642 }
4643 bgp_unlock_node (top);
4644
4645 if (rinew)
4646 {
4647 aggregate->count++;
4648
4649 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004650 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004651
4652 if (aggregate->as_set)
4653 {
4654 if (origin < rinew->attr->origin)
4655 origin = rinew->attr->origin;
4656
4657 if (aspath)
4658 {
4659 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4660 aspath_free (aspath);
4661 aspath = asmerge;
4662 }
4663 else
4664 aspath = aspath_dup (rinew->attr->aspath);
4665
4666 if (rinew->attr->community)
4667 {
4668 if (community)
4669 {
4670 commerge = community_merge (community,
4671 rinew->attr->community);
4672 community = community_uniq_sort (commerge);
4673 community_free (commerge);
4674 }
4675 else
4676 community = community_dup (rinew->attr->community);
4677 }
4678 }
4679 }
4680
4681 if (aggregate->count > 0)
4682 {
4683 rn = bgp_node_get (table, p);
4684 new = bgp_info_new ();
4685 new->type = ZEBRA_ROUTE_BGP;
4686 new->sub_type = BGP_ROUTE_AGGREGATE;
4687 new->peer = bgp->peer_self;
4688 SET_FLAG (new->flags, BGP_INFO_VALID);
4689 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4690 new->uptime = time (NULL);
4691
4692 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004693 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004694 bgp_process (bgp, rn, afi, safi);
4695 }
4696 else
4697 {
4698 if (aspath)
4699 aspath_free (aspath);
4700 if (community)
4701 community_free (community);
4702 }
4703}
4704
4705void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4706 struct bgp_aggregate *);
4707
4708void
4709bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4710 struct bgp_info *ri, afi_t afi, safi_t safi)
4711{
4712 struct bgp_node *child;
4713 struct bgp_node *rn;
4714 struct bgp_aggregate *aggregate;
4715
4716 /* MPLS-VPN aggregation is not yet supported. */
4717 if (safi == SAFI_MPLS_VPN)
4718 return;
4719
4720 if (p->prefixlen == 0)
4721 return;
4722
4723 if (BGP_INFO_HOLDDOWN (ri))
4724 return;
4725
4726 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4727
4728 /* Aggregate address configuration check. */
4729 for (rn = child; rn; rn = rn->parent)
4730 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4731 {
4732 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004733 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004734 }
4735 bgp_unlock_node (child);
4736}
4737
4738void
4739bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4740 struct bgp_info *del, afi_t afi, safi_t safi)
4741{
4742 struct bgp_node *child;
4743 struct bgp_node *rn;
4744 struct bgp_aggregate *aggregate;
4745
4746 /* MPLS-VPN aggregation is not yet supported. */
4747 if (safi == SAFI_MPLS_VPN)
4748 return;
4749
4750 if (p->prefixlen == 0)
4751 return;
4752
4753 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4754
4755 /* Aggregate address configuration check. */
4756 for (rn = child; rn; rn = rn->parent)
4757 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4758 {
4759 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004760 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004761 }
4762 bgp_unlock_node (child);
4763}
4764
paul94f2b392005-06-28 12:44:16 +00004765static void
paul718e3742002-12-13 20:15:29 +00004766bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4767 struct bgp_aggregate *aggregate)
4768{
4769 struct bgp_table *table;
4770 struct bgp_node *top;
4771 struct bgp_node *rn;
4772 struct bgp_info *new;
4773 struct bgp_info *ri;
4774 unsigned long match;
4775 u_char origin = BGP_ORIGIN_IGP;
4776 struct aspath *aspath = NULL;
4777 struct aspath *asmerge = NULL;
4778 struct community *community = NULL;
4779 struct community *commerge = NULL;
4780
4781 table = bgp->rib[afi][safi];
4782
4783 /* Sanity check. */
4784 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4785 return;
4786 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4787 return;
4788
4789 /* If routes exists below this node, generate aggregate routes. */
4790 top = bgp_node_get (table, p);
4791 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4792 if (rn->p.prefixlen > p->prefixlen)
4793 {
4794 match = 0;
4795
4796 for (ri = rn->info; ri; ri = ri->next)
4797 {
4798 if (BGP_INFO_HOLDDOWN (ri))
4799 continue;
4800
4801 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4802 {
4803 /* summary-only aggregate route suppress aggregated
4804 route announcement. */
4805 if (aggregate->summary_only)
4806 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004807 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004808 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004809 match++;
4810 }
4811 /* as-set aggregate route generate origin, as path,
4812 community aggregation. */
4813 if (aggregate->as_set)
4814 {
4815 if (origin < ri->attr->origin)
4816 origin = ri->attr->origin;
4817
4818 if (aspath)
4819 {
4820 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4821 aspath_free (aspath);
4822 aspath = asmerge;
4823 }
4824 else
4825 aspath = aspath_dup (ri->attr->aspath);
4826
4827 if (ri->attr->community)
4828 {
4829 if (community)
4830 {
4831 commerge = community_merge (community,
4832 ri->attr->community);
4833 community = community_uniq_sort (commerge);
4834 community_free (commerge);
4835 }
4836 else
4837 community = community_dup (ri->attr->community);
4838 }
4839 }
4840 aggregate->count++;
4841 }
4842 }
4843
4844 /* If this node is suppressed, process the change. */
4845 if (match)
4846 bgp_process (bgp, rn, afi, safi);
4847 }
4848 bgp_unlock_node (top);
4849
4850 /* Add aggregate route to BGP table. */
4851 if (aggregate->count)
4852 {
4853 rn = bgp_node_get (table, p);
4854
4855 new = bgp_info_new ();
4856 new->type = ZEBRA_ROUTE_BGP;
4857 new->sub_type = BGP_ROUTE_AGGREGATE;
4858 new->peer = bgp->peer_self;
4859 SET_FLAG (new->flags, BGP_INFO_VALID);
4860 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
4861 new->uptime = time (NULL);
4862
4863 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004864 bgp_unlock_node (rn);
4865
paul718e3742002-12-13 20:15:29 +00004866 /* Process change. */
4867 bgp_process (bgp, rn, afi, safi);
4868 }
4869}
4870
4871void
4872bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4873 safi_t safi, struct bgp_aggregate *aggregate)
4874{
4875 struct bgp_table *table;
4876 struct bgp_node *top;
4877 struct bgp_node *rn;
4878 struct bgp_info *ri;
4879 unsigned long match;
4880
4881 table = bgp->rib[afi][safi];
4882
4883 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4884 return;
4885 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4886 return;
4887
4888 /* If routes exists below this node, generate aggregate routes. */
4889 top = bgp_node_get (table, p);
4890 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4891 if (rn->p.prefixlen > p->prefixlen)
4892 {
4893 match = 0;
4894
4895 for (ri = rn->info; ri; ri = ri->next)
4896 {
4897 if (BGP_INFO_HOLDDOWN (ri))
4898 continue;
4899
4900 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4901 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004902 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004903 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004904 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004905
Paul Jakmafb982c22007-05-04 20:15:47 +00004906 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004907 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004908 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004909 match++;
4910 }
4911 }
4912 aggregate->count--;
4913 }
4914 }
4915
Paul Jakmafb982c22007-05-04 20:15:47 +00004916 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004917 if (match)
4918 bgp_process (bgp, rn, afi, safi);
4919 }
4920 bgp_unlock_node (top);
4921
4922 /* Delete aggregate route from BGP table. */
4923 rn = bgp_node_get (table, p);
4924
4925 for (ri = rn->info; ri; ri = ri->next)
4926 if (ri->peer == bgp->peer_self
4927 && ri->type == ZEBRA_ROUTE_BGP
4928 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4929 break;
4930
4931 /* Withdraw static BGP route from routing table. */
4932 if (ri)
4933 {
paul718e3742002-12-13 20:15:29 +00004934 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004935 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004936 }
4937
4938 /* Unlock bgp_node_lookup. */
4939 bgp_unlock_node (rn);
4940}
4941
4942/* Aggregate route attribute. */
4943#define AGGREGATE_SUMMARY_ONLY 1
4944#define AGGREGATE_AS_SET 1
4945
paul94f2b392005-06-28 12:44:16 +00004946static int
paulfd79ac92004-10-13 05:06:08 +00004947bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4948 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004949 u_char summary_only, u_char as_set)
4950{
4951 int ret;
4952 struct prefix p;
4953 struct bgp_node *rn;
4954 struct bgp *bgp;
4955 struct bgp_aggregate *aggregate;
4956
4957 /* Convert string to prefix structure. */
4958 ret = str2prefix (prefix_str, &p);
4959 if (!ret)
4960 {
4961 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4962 return CMD_WARNING;
4963 }
4964 apply_mask (&p);
4965
4966 /* Get BGP structure. */
4967 bgp = vty->index;
4968
4969 /* Old configuration check. */
4970 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4971
4972 if (rn->info)
4973 {
4974 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4975 bgp_unlock_node (rn);
4976 return CMD_WARNING;
4977 }
4978
4979 /* Make aggregate address structure. */
4980 aggregate = bgp_aggregate_new ();
4981 aggregate->summary_only = summary_only;
4982 aggregate->as_set = as_set;
4983 aggregate->safi = safi;
4984 rn->info = aggregate;
4985
4986 /* Aggregate address insert into BGP routing table. */
4987 if (safi & SAFI_UNICAST)
4988 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4989 if (safi & SAFI_MULTICAST)
4990 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4991
4992 return CMD_SUCCESS;
4993}
4994
paul94f2b392005-06-28 12:44:16 +00004995static int
paulfd79ac92004-10-13 05:06:08 +00004996bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4997 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004998{
4999 int ret;
5000 struct prefix p;
5001 struct bgp_node *rn;
5002 struct bgp *bgp;
5003 struct bgp_aggregate *aggregate;
5004
5005 /* Convert string to prefix structure. */
5006 ret = str2prefix (prefix_str, &p);
5007 if (!ret)
5008 {
5009 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
5010 return CMD_WARNING;
5011 }
5012 apply_mask (&p);
5013
5014 /* Get BGP structure. */
5015 bgp = vty->index;
5016
5017 /* Old configuration check. */
5018 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
5019 if (! rn)
5020 {
5021 vty_out (vty, "%% There is no aggregate-address configuration.%s",
5022 VTY_NEWLINE);
5023 return CMD_WARNING;
5024 }
5025
5026 aggregate = rn->info;
5027 if (aggregate->safi & SAFI_UNICAST)
5028 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
5029 if (aggregate->safi & SAFI_MULTICAST)
5030 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
5031
5032 /* Unlock aggregate address configuration. */
5033 rn->info = NULL;
5034 bgp_aggregate_free (aggregate);
5035 bgp_unlock_node (rn);
5036 bgp_unlock_node (rn);
5037
5038 return CMD_SUCCESS;
5039}
5040
5041DEFUN (aggregate_address,
5042 aggregate_address_cmd,
5043 "aggregate-address A.B.C.D/M",
5044 "Configure BGP aggregate entries\n"
5045 "Aggregate prefix\n")
5046{
5047 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
5048}
5049
5050DEFUN (aggregate_address_mask,
5051 aggregate_address_mask_cmd,
5052 "aggregate-address A.B.C.D A.B.C.D",
5053 "Configure BGP aggregate entries\n"
5054 "Aggregate address\n"
5055 "Aggregate mask\n")
5056{
5057 int ret;
5058 char prefix_str[BUFSIZ];
5059
5060 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5061
5062 if (! ret)
5063 {
5064 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5065 return CMD_WARNING;
5066 }
5067
5068 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5069 0, 0);
5070}
5071
5072DEFUN (aggregate_address_summary_only,
5073 aggregate_address_summary_only_cmd,
5074 "aggregate-address A.B.C.D/M summary-only",
5075 "Configure BGP aggregate entries\n"
5076 "Aggregate prefix\n"
5077 "Filter more specific routes from updates\n")
5078{
5079 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5080 AGGREGATE_SUMMARY_ONLY, 0);
5081}
5082
5083DEFUN (aggregate_address_mask_summary_only,
5084 aggregate_address_mask_summary_only_cmd,
5085 "aggregate-address A.B.C.D A.B.C.D summary-only",
5086 "Configure BGP aggregate entries\n"
5087 "Aggregate address\n"
5088 "Aggregate mask\n"
5089 "Filter more specific routes from updates\n")
5090{
5091 int ret;
5092 char prefix_str[BUFSIZ];
5093
5094 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5095
5096 if (! ret)
5097 {
5098 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5099 return CMD_WARNING;
5100 }
5101
5102 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5103 AGGREGATE_SUMMARY_ONLY, 0);
5104}
5105
5106DEFUN (aggregate_address_as_set,
5107 aggregate_address_as_set_cmd,
5108 "aggregate-address A.B.C.D/M as-set",
5109 "Configure BGP aggregate entries\n"
5110 "Aggregate prefix\n"
5111 "Generate AS set path information\n")
5112{
5113 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5114 0, AGGREGATE_AS_SET);
5115}
5116
5117DEFUN (aggregate_address_mask_as_set,
5118 aggregate_address_mask_as_set_cmd,
5119 "aggregate-address A.B.C.D A.B.C.D as-set",
5120 "Configure BGP aggregate entries\n"
5121 "Aggregate address\n"
5122 "Aggregate mask\n"
5123 "Generate AS set path information\n")
5124{
5125 int ret;
5126 char prefix_str[BUFSIZ];
5127
5128 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5129
5130 if (! ret)
5131 {
5132 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5133 return CMD_WARNING;
5134 }
5135
5136 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5137 0, AGGREGATE_AS_SET);
5138}
5139
5140
5141DEFUN (aggregate_address_as_set_summary,
5142 aggregate_address_as_set_summary_cmd,
5143 "aggregate-address A.B.C.D/M as-set summary-only",
5144 "Configure BGP aggregate entries\n"
5145 "Aggregate prefix\n"
5146 "Generate AS set path information\n"
5147 "Filter more specific routes from updates\n")
5148{
5149 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5150 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5151}
5152
5153ALIAS (aggregate_address_as_set_summary,
5154 aggregate_address_summary_as_set_cmd,
5155 "aggregate-address A.B.C.D/M summary-only as-set",
5156 "Configure BGP aggregate entries\n"
5157 "Aggregate prefix\n"
5158 "Filter more specific routes from updates\n"
5159 "Generate AS set path information\n")
5160
5161DEFUN (aggregate_address_mask_as_set_summary,
5162 aggregate_address_mask_as_set_summary_cmd,
5163 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5164 "Configure BGP aggregate entries\n"
5165 "Aggregate address\n"
5166 "Aggregate mask\n"
5167 "Generate AS set path information\n"
5168 "Filter more specific routes from updates\n")
5169{
5170 int ret;
5171 char prefix_str[BUFSIZ];
5172
5173 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5174
5175 if (! ret)
5176 {
5177 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5178 return CMD_WARNING;
5179 }
5180
5181 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5182 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5183}
5184
5185ALIAS (aggregate_address_mask_as_set_summary,
5186 aggregate_address_mask_summary_as_set_cmd,
5187 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5188 "Configure BGP aggregate entries\n"
5189 "Aggregate address\n"
5190 "Aggregate mask\n"
5191 "Filter more specific routes from updates\n"
5192 "Generate AS set path information\n")
5193
5194DEFUN (no_aggregate_address,
5195 no_aggregate_address_cmd,
5196 "no aggregate-address A.B.C.D/M",
5197 NO_STR
5198 "Configure BGP aggregate entries\n"
5199 "Aggregate prefix\n")
5200{
5201 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5202}
5203
5204ALIAS (no_aggregate_address,
5205 no_aggregate_address_summary_only_cmd,
5206 "no aggregate-address A.B.C.D/M summary-only",
5207 NO_STR
5208 "Configure BGP aggregate entries\n"
5209 "Aggregate prefix\n"
5210 "Filter more specific routes from updates\n")
5211
5212ALIAS (no_aggregate_address,
5213 no_aggregate_address_as_set_cmd,
5214 "no aggregate-address A.B.C.D/M as-set",
5215 NO_STR
5216 "Configure BGP aggregate entries\n"
5217 "Aggregate prefix\n"
5218 "Generate AS set path information\n")
5219
5220ALIAS (no_aggregate_address,
5221 no_aggregate_address_as_set_summary_cmd,
5222 "no aggregate-address A.B.C.D/M as-set summary-only",
5223 NO_STR
5224 "Configure BGP aggregate entries\n"
5225 "Aggregate prefix\n"
5226 "Generate AS set path information\n"
5227 "Filter more specific routes from updates\n")
5228
5229ALIAS (no_aggregate_address,
5230 no_aggregate_address_summary_as_set_cmd,
5231 "no aggregate-address A.B.C.D/M summary-only as-set",
5232 NO_STR
5233 "Configure BGP aggregate entries\n"
5234 "Aggregate prefix\n"
5235 "Filter more specific routes from updates\n"
5236 "Generate AS set path information\n")
5237
5238DEFUN (no_aggregate_address_mask,
5239 no_aggregate_address_mask_cmd,
5240 "no aggregate-address A.B.C.D A.B.C.D",
5241 NO_STR
5242 "Configure BGP aggregate entries\n"
5243 "Aggregate address\n"
5244 "Aggregate mask\n")
5245{
5246 int ret;
5247 char prefix_str[BUFSIZ];
5248
5249 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5250
5251 if (! ret)
5252 {
5253 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5254 return CMD_WARNING;
5255 }
5256
5257 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5258}
5259
5260ALIAS (no_aggregate_address_mask,
5261 no_aggregate_address_mask_summary_only_cmd,
5262 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5263 NO_STR
5264 "Configure BGP aggregate entries\n"
5265 "Aggregate address\n"
5266 "Aggregate mask\n"
5267 "Filter more specific routes from updates\n")
5268
5269ALIAS (no_aggregate_address_mask,
5270 no_aggregate_address_mask_as_set_cmd,
5271 "no aggregate-address A.B.C.D A.B.C.D as-set",
5272 NO_STR
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate address\n"
5275 "Aggregate mask\n"
5276 "Generate AS set path information\n")
5277
5278ALIAS (no_aggregate_address_mask,
5279 no_aggregate_address_mask_as_set_summary_cmd,
5280 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5281 NO_STR
5282 "Configure BGP aggregate entries\n"
5283 "Aggregate address\n"
5284 "Aggregate mask\n"
5285 "Generate AS set path information\n"
5286 "Filter more specific routes from updates\n")
5287
5288ALIAS (no_aggregate_address_mask,
5289 no_aggregate_address_mask_summary_as_set_cmd,
5290 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5291 NO_STR
5292 "Configure BGP aggregate entries\n"
5293 "Aggregate address\n"
5294 "Aggregate mask\n"
5295 "Filter more specific routes from updates\n"
5296 "Generate AS set path information\n")
5297
5298#ifdef HAVE_IPV6
5299DEFUN (ipv6_aggregate_address,
5300 ipv6_aggregate_address_cmd,
5301 "aggregate-address X:X::X:X/M",
5302 "Configure BGP aggregate entries\n"
5303 "Aggregate prefix\n")
5304{
5305 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5306}
5307
5308DEFUN (ipv6_aggregate_address_summary_only,
5309 ipv6_aggregate_address_summary_only_cmd,
5310 "aggregate-address X:X::X:X/M summary-only",
5311 "Configure BGP aggregate entries\n"
5312 "Aggregate prefix\n"
5313 "Filter more specific routes from updates\n")
5314{
5315 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5316 AGGREGATE_SUMMARY_ONLY, 0);
5317}
5318
5319DEFUN (no_ipv6_aggregate_address,
5320 no_ipv6_aggregate_address_cmd,
5321 "no aggregate-address X:X::X:X/M",
5322 NO_STR
5323 "Configure BGP aggregate entries\n"
5324 "Aggregate prefix\n")
5325{
5326 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5327}
5328
5329DEFUN (no_ipv6_aggregate_address_summary_only,
5330 no_ipv6_aggregate_address_summary_only_cmd,
5331 "no aggregate-address X:X::X:X/M summary-only",
5332 NO_STR
5333 "Configure BGP aggregate entries\n"
5334 "Aggregate prefix\n"
5335 "Filter more specific routes from updates\n")
5336{
5337 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5338}
5339
5340ALIAS (ipv6_aggregate_address,
5341 old_ipv6_aggregate_address_cmd,
5342 "ipv6 bgp aggregate-address X:X::X:X/M",
5343 IPV6_STR
5344 BGP_STR
5345 "Configure BGP aggregate entries\n"
5346 "Aggregate prefix\n")
5347
5348ALIAS (ipv6_aggregate_address_summary_only,
5349 old_ipv6_aggregate_address_summary_only_cmd,
5350 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5351 IPV6_STR
5352 BGP_STR
5353 "Configure BGP aggregate entries\n"
5354 "Aggregate prefix\n"
5355 "Filter more specific routes from updates\n")
5356
5357ALIAS (no_ipv6_aggregate_address,
5358 old_no_ipv6_aggregate_address_cmd,
5359 "no ipv6 bgp aggregate-address X:X::X:X/M",
5360 NO_STR
5361 IPV6_STR
5362 BGP_STR
5363 "Configure BGP aggregate entries\n"
5364 "Aggregate prefix\n")
5365
5366ALIAS (no_ipv6_aggregate_address_summary_only,
5367 old_no_ipv6_aggregate_address_summary_only_cmd,
5368 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5369 NO_STR
5370 IPV6_STR
5371 BGP_STR
5372 "Configure BGP aggregate entries\n"
5373 "Aggregate prefix\n"
5374 "Filter more specific routes from updates\n")
5375#endif /* HAVE_IPV6 */
5376
5377/* Redistribute route treatment. */
5378void
5379bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5380 u_int32_t metric, u_char type)
5381{
5382 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005383 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005384 struct bgp_info *new;
5385 struct bgp_info *bi;
5386 struct bgp_info info;
5387 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005388 struct attr attr = { 0 };
5389 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005390 struct attr *new_attr;
5391 afi_t afi;
5392 int ret;
5393
5394 /* Make default attribute. */
5395 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5396 if (nexthop)
5397 attr.nexthop = *nexthop;
5398
5399 attr.med = metric;
5400 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5401
paul1eb8ef22005-04-07 07:30:20 +00005402 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005403 {
5404 afi = family2afi (p->family);
5405
5406 if (bgp->redist[afi][type])
5407 {
5408 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005409 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005410
5411 if (bgp->redist_metric_flag[afi][type])
5412 attr_new.med = bgp->redist_metric[afi][type];
5413
5414 /* Apply route-map. */
5415 if (bgp->rmap[afi][type].map)
5416 {
5417 info.peer = bgp->peer_self;
5418 info.attr = &attr_new;
5419
paulfee0f4c2004-09-13 05:12:46 +00005420 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5421
paul718e3742002-12-13 20:15:29 +00005422 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5423 &info);
paulfee0f4c2004-09-13 05:12:46 +00005424
5425 bgp->peer_self->rmap_type = 0;
5426
paul718e3742002-12-13 20:15:29 +00005427 if (ret == RMAP_DENYMATCH)
5428 {
5429 /* Free uninterned attribute. */
5430 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005431 bgp_attr_extra_free (&attr_new);
5432
paul718e3742002-12-13 20:15:29 +00005433 /* Unintern original. */
5434 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005435 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005436 bgp_redistribute_delete (p, type);
5437 return;
5438 }
5439 }
5440
Paul Jakmafb982c22007-05-04 20:15:47 +00005441 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5442 afi, SAFI_UNICAST, p, NULL);
5443
paul718e3742002-12-13 20:15:29 +00005444 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005445 bgp_attr_extra_free (&attr_new);
5446
paul718e3742002-12-13 20:15:29 +00005447 for (bi = bn->info; bi; bi = bi->next)
5448 if (bi->peer == bgp->peer_self
5449 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5450 break;
5451
5452 if (bi)
5453 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005454 if (attrhash_cmp (bi->attr, new_attr) &&
5455 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005456 {
5457 bgp_attr_unintern (new_attr);
5458 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005459 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005460 bgp_unlock_node (bn);
5461 return;
5462 }
5463 else
5464 {
5465 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005466 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005467
5468 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005469 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5470 bgp_info_restore(bn, bi);
5471 else
5472 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005473 bgp_attr_unintern (bi->attr);
5474 bi->attr = new_attr;
5475 bi->uptime = time (NULL);
5476
5477 /* Process change. */
5478 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5479 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5480 bgp_unlock_node (bn);
5481 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005482 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005483 return;
5484 }
5485 }
5486
5487 new = bgp_info_new ();
5488 new->type = type;
5489 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5490 new->peer = bgp->peer_self;
5491 SET_FLAG (new->flags, BGP_INFO_VALID);
5492 new->attr = new_attr;
5493 new->uptime = time (NULL);
5494
5495 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5496 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005497 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005498 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5499 }
5500 }
5501
5502 /* Unintern original. */
5503 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005504 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005505}
5506
5507void
5508bgp_redistribute_delete (struct prefix *p, u_char type)
5509{
5510 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005511 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005512 afi_t afi;
5513 struct bgp_node *rn;
5514 struct bgp_info *ri;
5515
paul1eb8ef22005-04-07 07:30:20 +00005516 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005517 {
5518 afi = family2afi (p->family);
5519
5520 if (bgp->redist[afi][type])
5521 {
paulfee0f4c2004-09-13 05:12:46 +00005522 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005523
5524 for (ri = rn->info; ri; ri = ri->next)
5525 if (ri->peer == bgp->peer_self
5526 && ri->type == type)
5527 break;
5528
5529 if (ri)
5530 {
5531 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005532 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005533 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005534 }
5535 bgp_unlock_node (rn);
5536 }
5537 }
5538}
5539
5540/* Withdraw specified route type's route. */
5541void
5542bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5543{
5544 struct bgp_node *rn;
5545 struct bgp_info *ri;
5546 struct bgp_table *table;
5547
5548 table = bgp->rib[afi][SAFI_UNICAST];
5549
5550 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5551 {
5552 for (ri = rn->info; ri; ri = ri->next)
5553 if (ri->peer == bgp->peer_self
5554 && ri->type == type)
5555 break;
5556
5557 if (ri)
5558 {
5559 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005560 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005561 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005562 }
5563 }
5564}
5565
5566/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005567static void
paul718e3742002-12-13 20:15:29 +00005568route_vty_out_route (struct prefix *p, struct vty *vty)
5569{
5570 int len;
5571 u_int32_t destination;
5572 char buf[BUFSIZ];
5573
5574 if (p->family == AF_INET)
5575 {
5576 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5577 destination = ntohl (p->u.prefix4.s_addr);
5578
5579 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5580 || (IN_CLASSB (destination) && p->prefixlen == 16)
5581 || (IN_CLASSA (destination) && p->prefixlen == 8)
5582 || p->u.prefix4.s_addr == 0)
5583 {
5584 /* When mask is natural, mask is not displayed. */
5585 }
5586 else
5587 len += vty_out (vty, "/%d", p->prefixlen);
5588 }
5589 else
5590 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5591 p->prefixlen);
5592
5593 len = 17 - len;
5594 if (len < 1)
5595 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5596 else
5597 vty_out (vty, "%*s", len, " ");
5598}
5599
paul718e3742002-12-13 20:15:29 +00005600enum bgp_display_type
5601{
5602 normal_list,
5603};
5604
paulb40d9392005-08-22 22:34:41 +00005605/* Print the short form route status for a bgp_info */
5606static void
5607route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005608{
paulb40d9392005-08-22 22:34:41 +00005609 /* Route status display. */
5610 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5611 vty_out (vty, "R");
5612 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005613 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005614 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005615 vty_out (vty, "s");
5616 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5617 vty_out (vty, "*");
5618 else
5619 vty_out (vty, " ");
5620
5621 /* Selected */
5622 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5623 vty_out (vty, "h");
5624 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5625 vty_out (vty, "d");
5626 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5627 vty_out (vty, ">");
5628 else
5629 vty_out (vty, " ");
5630
5631 /* Internal route. */
5632 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5633 vty_out (vty, "i");
5634 else
paulb40d9392005-08-22 22:34:41 +00005635 vty_out (vty, " ");
5636}
5637
5638/* called from terminal list command */
5639void
5640route_vty_out (struct vty *vty, struct prefix *p,
5641 struct bgp_info *binfo, int display, safi_t safi)
5642{
5643 struct attr *attr;
5644
5645 /* short status lead text */
5646 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005647
5648 /* print prefix and mask */
5649 if (! display)
5650 route_vty_out_route (p, vty);
5651 else
5652 vty_out (vty, "%*s", 17, " ");
5653
5654 /* Print attribute */
5655 attr = binfo->attr;
5656 if (attr)
5657 {
5658 if (p->family == AF_INET)
5659 {
5660 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005661 vty_out (vty, "%-16s",
5662 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005663 else
5664 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5665 }
5666#ifdef HAVE_IPV6
5667 else if (p->family == AF_INET6)
5668 {
5669 int len;
5670 char buf[BUFSIZ];
5671
5672 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005673 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5674 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005675 len = 16 - len;
5676 if (len < 1)
5677 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5678 else
5679 vty_out (vty, "%*s", len, " ");
5680 }
5681#endif /* HAVE_IPV6 */
5682
5683 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5684 vty_out (vty, "%10d", attr->med);
5685 else
5686 vty_out (vty, " ");
5687
5688 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5689 vty_out (vty, "%7d", attr->local_pref);
5690 else
5691 vty_out (vty, " ");
5692
Paul Jakmafb982c22007-05-04 20:15:47 +00005693 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005694
Paul Jakmab2518c12006-05-12 23:48:40 +00005695 /* Print aspath */
5696 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005697 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005698
Paul Jakmab2518c12006-05-12 23:48:40 +00005699 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005700 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005701 }
paul718e3742002-12-13 20:15:29 +00005702 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005703}
5704
5705/* called from terminal list command */
5706void
5707route_vty_out_tmp (struct vty *vty, struct prefix *p,
5708 struct attr *attr, safi_t safi)
5709{
5710 /* Route status display. */
5711 vty_out (vty, "*");
5712 vty_out (vty, ">");
5713 vty_out (vty, " ");
5714
5715 /* print prefix and mask */
5716 route_vty_out_route (p, vty);
5717
5718 /* Print attribute */
5719 if (attr)
5720 {
5721 if (p->family == AF_INET)
5722 {
5723 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005724 vty_out (vty, "%-16s",
5725 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005726 else
5727 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5728 }
5729#ifdef HAVE_IPV6
5730 else if (p->family == AF_INET6)
5731 {
5732 int len;
5733 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005734
5735 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005736
5737 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005738 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5739 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005740 len = 16 - len;
5741 if (len < 1)
5742 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5743 else
5744 vty_out (vty, "%*s", len, " ");
5745 }
5746#endif /* HAVE_IPV6 */
5747
5748 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
5749 vty_out (vty, "%10d", attr->med);
5750 else
5751 vty_out (vty, " ");
5752
5753 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
5754 vty_out (vty, "%7d", attr->local_pref);
5755 else
5756 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005757
5758 vty_out (vty, "%7d ", (attr->extra ? attr->extra->weight : 0));
5759
Paul Jakmab2518c12006-05-12 23:48:40 +00005760 /* Print aspath */
5761 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005762 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005763
Paul Jakmab2518c12006-05-12 23:48:40 +00005764 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005765 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005766 }
paul718e3742002-12-13 20:15:29 +00005767
5768 vty_out (vty, "%s", VTY_NEWLINE);
5769}
5770
ajs5a646652004-11-05 01:25:55 +00005771void
paul718e3742002-12-13 20:15:29 +00005772route_vty_out_tag (struct vty *vty, struct prefix *p,
5773 struct bgp_info *binfo, int display, safi_t safi)
5774{
5775 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005776 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005777
5778 if (!binfo->extra)
5779 return;
5780
paulb40d9392005-08-22 22:34:41 +00005781 /* short status lead text */
5782 route_vty_short_status_out (vty, binfo);
5783
paul718e3742002-12-13 20:15:29 +00005784 /* print prefix and mask */
5785 if (! display)
5786 route_vty_out_route (p, vty);
5787 else
5788 vty_out (vty, "%*s", 17, " ");
5789
5790 /* Print attribute */
5791 attr = binfo->attr;
5792 if (attr)
5793 {
5794 if (p->family == AF_INET)
5795 {
5796 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005797 vty_out (vty, "%-16s",
5798 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005799 else
5800 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5801 }
5802#ifdef HAVE_IPV6
5803 else if (p->family == AF_INET6)
5804 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005805 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005806 char buf[BUFSIZ];
5807 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005808 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005809 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005810 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5811 buf, BUFSIZ));
5812 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005813 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005814 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5815 buf, BUFSIZ),
5816 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5817 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005818
5819 }
5820#endif /* HAVE_IPV6 */
5821 }
5822
Paul Jakmafb982c22007-05-04 20:15:47 +00005823 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005824
5825 vty_out (vty, "notag/%d", label);
5826
5827 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005828}
5829
5830/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005831static void
paul718e3742002-12-13 20:15:29 +00005832damp_route_vty_out (struct vty *vty, struct prefix *p,
5833 struct bgp_info *binfo, int display, safi_t safi)
5834{
5835 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005836 int len;
5837
paulb40d9392005-08-22 22:34:41 +00005838 /* short status lead text */
5839 route_vty_short_status_out (vty, binfo);
5840
paul718e3742002-12-13 20:15:29 +00005841 /* print prefix and mask */
5842 if (! display)
5843 route_vty_out_route (p, vty);
5844 else
5845 vty_out (vty, "%*s", 17, " ");
5846
5847 len = vty_out (vty, "%s", binfo->peer->host);
5848 len = 17 - len;
5849 if (len < 1)
5850 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5851 else
5852 vty_out (vty, "%*s", len, " ");
5853
5854 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5855
5856 /* Print attribute */
5857 attr = binfo->attr;
5858 if (attr)
5859 {
5860 /* Print aspath */
5861 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005862 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005863
5864 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005865 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005866 }
5867 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005868}
5869
5870#define BGP_UPTIME_LEN 25
5871
5872/* flap route */
ajs5a646652004-11-05 01:25:55 +00005873static void
paul718e3742002-12-13 20:15:29 +00005874flap_route_vty_out (struct vty *vty, struct prefix *p,
5875 struct bgp_info *binfo, int display, safi_t safi)
5876{
5877 struct attr *attr;
5878 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005879 char timebuf[BGP_UPTIME_LEN];
5880 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005881
5882 if (!binfo->extra)
5883 return;
5884
5885 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005886
paulb40d9392005-08-22 22:34:41 +00005887 /* short status lead text */
5888 route_vty_short_status_out (vty, binfo);
5889
paul718e3742002-12-13 20:15:29 +00005890 /* print prefix and mask */
5891 if (! display)
5892 route_vty_out_route (p, vty);
5893 else
5894 vty_out (vty, "%*s", 17, " ");
5895
5896 len = vty_out (vty, "%s", binfo->peer->host);
5897 len = 16 - len;
5898 if (len < 1)
5899 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5900 else
5901 vty_out (vty, "%*s", len, " ");
5902
5903 len = vty_out (vty, "%d", bdi->flap);
5904 len = 5 - len;
5905 if (len < 1)
5906 vty_out (vty, " ");
5907 else
5908 vty_out (vty, "%*s ", len, " ");
5909
5910 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5911 timebuf, BGP_UPTIME_LEN));
5912
5913 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5914 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5915 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo));
5916 else
5917 vty_out (vty, "%*s ", 8, " ");
5918
5919 /* Print attribute */
5920 attr = binfo->attr;
5921 if (attr)
5922 {
5923 /* Print aspath */
5924 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005925 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005926
5927 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005928 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005929 }
5930 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005931}
5932
paul94f2b392005-06-28 12:44:16 +00005933static void
paul718e3742002-12-13 20:15:29 +00005934route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5935 struct bgp_info *binfo, afi_t afi, safi_t safi)
5936{
5937 char buf[INET6_ADDRSTRLEN];
5938 char buf1[BUFSIZ];
5939 struct attr *attr;
5940 int sockunion_vty_out (struct vty *, union sockunion *);
5941
5942 attr = binfo->attr;
5943
5944 if (attr)
5945 {
5946 /* Line1 display AS-path, Aggregator */
5947 if (attr->aspath)
5948 {
5949 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005950 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005951 vty_out (vty, "Local");
5952 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005953 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005954 }
5955
paulb40d9392005-08-22 22:34:41 +00005956 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5957 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005958 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5959 vty_out (vty, ", (stale)");
5960 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Paul Jakmafb982c22007-05-04 20:15:47 +00005961 vty_out (vty, ", (aggregated by %d %s)",
5962 attr->extra->aggregator_as,
5963 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005964 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5965 vty_out (vty, ", (Received from a RR-client)");
5966 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5967 vty_out (vty, ", (Received from a RS-client)");
5968 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5969 vty_out (vty, ", (history entry)");
5970 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5971 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005972 vty_out (vty, "%s", VTY_NEWLINE);
5973
5974 /* Line2 display Next-hop, Neighbor, Router-id */
5975 if (p->family == AF_INET)
5976 {
5977 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005978 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005979 inet_ntoa (attr->nexthop));
5980 }
5981#ifdef HAVE_IPV6
5982 else
5983 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005984 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005985 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005986 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005987 buf, INET6_ADDRSTRLEN));
5988 }
5989#endif /* HAVE_IPV6 */
5990
5991 if (binfo->peer == bgp->peer_self)
5992 {
5993 vty_out (vty, " from %s ",
5994 p->family == AF_INET ? "0.0.0.0" : "::");
5995 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5996 }
5997 else
5998 {
5999 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
6000 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00006001 else if (binfo->extra && binfo->extra->igpmetric)
6002 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00006003 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00006004 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006005 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006006 else
6007 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
6008 }
6009 vty_out (vty, "%s", VTY_NEWLINE);
6010
6011#ifdef HAVE_IPV6
6012 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00006013 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00006014 {
6015 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00006016 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00006017 buf, INET6_ADDRSTRLEN),
6018 VTY_NEWLINE);
6019 }
6020#endif /* HAVE_IPV6 */
6021
6022 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
6023 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
6024
6025 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
6026 vty_out (vty, ", metric %d", attr->med);
6027
6028 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
6029 vty_out (vty, ", localpref %d", attr->local_pref);
6030 else
6031 vty_out (vty, ", localpref %d", bgp->default_local_pref);
6032
Paul Jakmafb982c22007-05-04 20:15:47 +00006033 if (attr->extra && attr->extra->weight != 0)
6034 vty_out (vty, ", weight %d", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00006035
6036 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
6037 vty_out (vty, ", valid");
6038
6039 if (binfo->peer != bgp->peer_self)
6040 {
6041 if (binfo->peer->as == binfo->peer->local_as)
6042 vty_out (vty, ", internal");
6043 else
6044 vty_out (vty, ", %s",
6045 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
6046 }
6047 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
6048 vty_out (vty, ", aggregated, local");
6049 else if (binfo->type != ZEBRA_ROUTE_BGP)
6050 vty_out (vty, ", sourced");
6051 else
6052 vty_out (vty, ", sourced, local");
6053
6054 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
6055 vty_out (vty, ", atomic-aggregate");
6056
6057 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6058 vty_out (vty, ", best");
6059
6060 vty_out (vty, "%s", VTY_NEWLINE);
6061
6062 /* Line 4 display Community */
6063 if (attr->community)
6064 vty_out (vty, " Community: %s%s", attr->community->str,
6065 VTY_NEWLINE);
6066
6067 /* Line 5 display Extended-community */
6068 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006069 vty_out (vty, " Extended Community: %s%s",
6070 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006071
6072 /* Line 6 display Originator, Cluster-id */
6073 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6074 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6075 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006076 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006077 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006078 vty_out (vty, " Originator: %s",
6079 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006080
6081 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6082 {
6083 int i;
6084 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006085 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6086 vty_out (vty, "%s ",
6087 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006088 }
6089 vty_out (vty, "%s", VTY_NEWLINE);
6090 }
Paul Jakma41367172007-08-06 15:24:51 +00006091
6092 /* 7: AS Pathlimit */
6093 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_AS_PATHLIMIT))
6094 {
6095
6096 vty_out (vty, " AS-Pathlimit: %u",
6097 attr->pathlimit.ttl);
6098 if (attr->pathlimit.as)
6099 vty_out (vty, " (%u)", attr->pathlimit.as);
6100 vty_out (vty, "%s", VTY_NEWLINE);
6101 }
6102
Paul Jakmafb982c22007-05-04 20:15:47 +00006103 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006104 bgp_damp_info_vty (vty, binfo);
6105
6106 /* Line 7 display Uptime */
6107 vty_out (vty, " Last update: %s", ctime (&binfo->uptime));
6108 }
6109 vty_out (vty, "%s", VTY_NEWLINE);
6110}
6111
paulb40d9392005-08-22 22:34:41 +00006112#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 +00006113#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006114#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6115#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6116#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6117
6118enum bgp_show_type
6119{
6120 bgp_show_type_normal,
6121 bgp_show_type_regexp,
6122 bgp_show_type_prefix_list,
6123 bgp_show_type_filter_list,
6124 bgp_show_type_route_map,
6125 bgp_show_type_neighbor,
6126 bgp_show_type_cidr_only,
6127 bgp_show_type_prefix_longer,
6128 bgp_show_type_community_all,
6129 bgp_show_type_community,
6130 bgp_show_type_community_exact,
6131 bgp_show_type_community_list,
6132 bgp_show_type_community_list_exact,
6133 bgp_show_type_flap_statistics,
6134 bgp_show_type_flap_address,
6135 bgp_show_type_flap_prefix,
6136 bgp_show_type_flap_cidr_only,
6137 bgp_show_type_flap_regexp,
6138 bgp_show_type_flap_filter_list,
6139 bgp_show_type_flap_prefix_list,
6140 bgp_show_type_flap_prefix_longer,
6141 bgp_show_type_flap_route_map,
6142 bgp_show_type_flap_neighbor,
6143 bgp_show_type_dampend_paths,
6144 bgp_show_type_damp_neighbor
6145};
6146
ajs5a646652004-11-05 01:25:55 +00006147static int
paulfee0f4c2004-09-13 05:12:46 +00006148bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006149 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006150{
paul718e3742002-12-13 20:15:29 +00006151 struct bgp_info *ri;
6152 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006153 int header = 1;
paul718e3742002-12-13 20:15:29 +00006154 int display;
ajs5a646652004-11-05 01:25:55 +00006155 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006156
6157 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006158 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006159
paul718e3742002-12-13 20:15:29 +00006160 /* Start processing of routes. */
6161 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6162 if (rn->info != NULL)
6163 {
6164 display = 0;
6165
6166 for (ri = rn->info; ri; ri = ri->next)
6167 {
ajs5a646652004-11-05 01:25:55 +00006168 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006169 || type == bgp_show_type_flap_address
6170 || type == bgp_show_type_flap_prefix
6171 || type == bgp_show_type_flap_cidr_only
6172 || type == bgp_show_type_flap_regexp
6173 || type == bgp_show_type_flap_filter_list
6174 || type == bgp_show_type_flap_prefix_list
6175 || type == bgp_show_type_flap_prefix_longer
6176 || type == bgp_show_type_flap_route_map
6177 || type == bgp_show_type_flap_neighbor
6178 || type == bgp_show_type_dampend_paths
6179 || type == bgp_show_type_damp_neighbor)
6180 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006181 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006182 continue;
6183 }
6184 if (type == bgp_show_type_regexp
6185 || type == bgp_show_type_flap_regexp)
6186 {
ajs5a646652004-11-05 01:25:55 +00006187 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006188
6189 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6190 continue;
6191 }
6192 if (type == bgp_show_type_prefix_list
6193 || type == bgp_show_type_flap_prefix_list)
6194 {
ajs5a646652004-11-05 01:25:55 +00006195 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006196
6197 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6198 continue;
6199 }
6200 if (type == bgp_show_type_filter_list
6201 || type == bgp_show_type_flap_filter_list)
6202 {
ajs5a646652004-11-05 01:25:55 +00006203 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006204
6205 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6206 continue;
6207 }
6208 if (type == bgp_show_type_route_map
6209 || type == bgp_show_type_flap_route_map)
6210 {
ajs5a646652004-11-05 01:25:55 +00006211 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006212 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006213 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006214 int ret;
6215
Paul Jakmafb982c22007-05-04 20:15:47 +00006216 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006217 binfo.peer = ri->peer;
6218 binfo.attr = &dummy_attr;
6219
6220 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006221
6222 bgp_attr_extra_free (&dummy_attr);
6223
paul718e3742002-12-13 20:15:29 +00006224 if (ret == RMAP_DENYMATCH)
6225 continue;
6226 }
6227 if (type == bgp_show_type_neighbor
6228 || type == bgp_show_type_flap_neighbor
6229 || type == bgp_show_type_damp_neighbor)
6230 {
ajs5a646652004-11-05 01:25:55 +00006231 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006232
6233 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6234 continue;
6235 }
6236 if (type == bgp_show_type_cidr_only
6237 || type == bgp_show_type_flap_cidr_only)
6238 {
6239 u_int32_t destination;
6240
6241 destination = ntohl (rn->p.u.prefix4.s_addr);
6242 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6243 continue;
6244 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6245 continue;
6246 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6247 continue;
6248 }
6249 if (type == bgp_show_type_prefix_longer
6250 || type == bgp_show_type_flap_prefix_longer)
6251 {
ajs5a646652004-11-05 01:25:55 +00006252 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006253
6254 if (! prefix_match (p, &rn->p))
6255 continue;
6256 }
6257 if (type == bgp_show_type_community_all)
6258 {
6259 if (! ri->attr->community)
6260 continue;
6261 }
6262 if (type == bgp_show_type_community)
6263 {
ajs5a646652004-11-05 01:25:55 +00006264 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006265
6266 if (! ri->attr->community ||
6267 ! community_match (ri->attr->community, com))
6268 continue;
6269 }
6270 if (type == bgp_show_type_community_exact)
6271 {
ajs5a646652004-11-05 01:25:55 +00006272 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006273
6274 if (! ri->attr->community ||
6275 ! community_cmp (ri->attr->community, com))
6276 continue;
6277 }
6278 if (type == bgp_show_type_community_list)
6279 {
ajs5a646652004-11-05 01:25:55 +00006280 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006281
6282 if (! community_list_match (ri->attr->community, list))
6283 continue;
6284 }
6285 if (type == bgp_show_type_community_list_exact)
6286 {
ajs5a646652004-11-05 01:25:55 +00006287 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006288
6289 if (! community_list_exact_match (ri->attr->community, list))
6290 continue;
6291 }
6292 if (type == bgp_show_type_flap_address
6293 || type == bgp_show_type_flap_prefix)
6294 {
ajs5a646652004-11-05 01:25:55 +00006295 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006296
6297 if (! prefix_match (&rn->p, p))
6298 continue;
6299
6300 if (type == bgp_show_type_flap_prefix)
6301 if (p->prefixlen != rn->p.prefixlen)
6302 continue;
6303 }
6304 if (type == bgp_show_type_dampend_paths
6305 || type == bgp_show_type_damp_neighbor)
6306 {
6307 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6308 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6309 continue;
6310 }
6311
6312 if (header)
6313 {
hasso93406d82005-02-02 14:40:33 +00006314 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6315 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6316 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006317 if (type == bgp_show_type_dampend_paths
6318 || type == bgp_show_type_damp_neighbor)
6319 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6320 else if (type == bgp_show_type_flap_statistics
6321 || type == bgp_show_type_flap_address
6322 || type == bgp_show_type_flap_prefix
6323 || type == bgp_show_type_flap_cidr_only
6324 || type == bgp_show_type_flap_regexp
6325 || type == bgp_show_type_flap_filter_list
6326 || type == bgp_show_type_flap_prefix_list
6327 || type == bgp_show_type_flap_prefix_longer
6328 || type == bgp_show_type_flap_route_map
6329 || type == bgp_show_type_flap_neighbor)
6330 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6331 else
6332 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006333 header = 0;
6334 }
6335
6336 if (type == bgp_show_type_dampend_paths
6337 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006338 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006339 else if (type == bgp_show_type_flap_statistics
6340 || type == bgp_show_type_flap_address
6341 || type == bgp_show_type_flap_prefix
6342 || type == bgp_show_type_flap_cidr_only
6343 || type == bgp_show_type_flap_regexp
6344 || type == bgp_show_type_flap_filter_list
6345 || type == bgp_show_type_flap_prefix_list
6346 || type == bgp_show_type_flap_prefix_longer
6347 || type == bgp_show_type_flap_route_map
6348 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006349 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006350 else
ajs5a646652004-11-05 01:25:55 +00006351 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006352 display++;
6353 }
6354 if (display)
ajs5a646652004-11-05 01:25:55 +00006355 output_count++;
paul718e3742002-12-13 20:15:29 +00006356 }
6357
6358 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006359 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006360 {
6361 if (type == bgp_show_type_normal)
6362 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6363 }
6364 else
6365 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006366 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006367
6368 return CMD_SUCCESS;
6369}
6370
ajs5a646652004-11-05 01:25:55 +00006371static int
paulfee0f4c2004-09-13 05:12:46 +00006372bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006373 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006374{
6375 struct bgp_table *table;
6376
6377 if (bgp == NULL) {
6378 bgp = bgp_get_default ();
6379 }
6380
6381 if (bgp == NULL)
6382 {
6383 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6384 return CMD_WARNING;
6385 }
6386
6387
6388 table = bgp->rib[afi][safi];
6389
ajs5a646652004-11-05 01:25:55 +00006390 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006391}
6392
paul718e3742002-12-13 20:15:29 +00006393/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006394static void
paul718e3742002-12-13 20:15:29 +00006395route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6396 struct bgp_node *rn,
6397 struct prefix_rd *prd, afi_t afi, safi_t safi)
6398{
6399 struct bgp_info *ri;
6400 struct prefix *p;
6401 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006402 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006403 char buf1[INET6_ADDRSTRLEN];
6404 char buf2[INET6_ADDRSTRLEN];
6405 int count = 0;
6406 int best = 0;
6407 int suppress = 0;
6408 int no_export = 0;
6409 int no_advertise = 0;
6410 int local_as = 0;
6411 int first = 0;
6412
6413 p = &rn->p;
6414 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6415 (safi == SAFI_MPLS_VPN ?
6416 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6417 safi == SAFI_MPLS_VPN ? ":" : "",
6418 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6419 p->prefixlen, VTY_NEWLINE);
6420
6421 for (ri = rn->info; ri; ri = ri->next)
6422 {
6423 count++;
6424 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6425 {
6426 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006427 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006428 suppress = 1;
6429 if (ri->attr->community != NULL)
6430 {
6431 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6432 no_advertise = 1;
6433 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6434 no_export = 1;
6435 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6436 local_as = 1;
6437 }
6438 }
6439 }
6440
6441 vty_out (vty, "Paths: (%d available", count);
6442 if (best)
6443 {
6444 vty_out (vty, ", best #%d", best);
6445 if (safi == SAFI_UNICAST)
6446 vty_out (vty, ", table Default-IP-Routing-Table");
6447 }
6448 else
6449 vty_out (vty, ", no best path");
6450 if (no_advertise)
6451 vty_out (vty, ", not advertised to any peer");
6452 else if (no_export)
6453 vty_out (vty, ", not advertised to EBGP peer");
6454 else if (local_as)
6455 vty_out (vty, ", not advertised outside local AS");
6456 if (suppress)
6457 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6458 vty_out (vty, ")%s", VTY_NEWLINE);
6459
6460 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006461 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006462 {
6463 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6464 {
6465 if (! first)
6466 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6467 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6468 first = 1;
6469 }
6470 }
6471 if (! first)
6472 vty_out (vty, " Not advertised to any peer");
6473 vty_out (vty, "%s", VTY_NEWLINE);
6474}
6475
6476/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006477static int
paulfee0f4c2004-09-13 05:12:46 +00006478bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006479 struct bgp_table *rib, const char *ip_str,
6480 afi_t afi, safi_t safi, struct prefix_rd *prd,
6481 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006482{
6483 int ret;
6484 int header;
6485 int display = 0;
6486 struct prefix match;
6487 struct bgp_node *rn;
6488 struct bgp_node *rm;
6489 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006490 struct bgp_table *table;
6491
paul718e3742002-12-13 20:15:29 +00006492 /* Check IP address argument. */
6493 ret = str2prefix (ip_str, &match);
6494 if (! ret)
6495 {
6496 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6497 return CMD_WARNING;
6498 }
6499
6500 match.family = afi2family (afi);
6501
6502 if (safi == SAFI_MPLS_VPN)
6503 {
paulfee0f4c2004-09-13 05:12:46 +00006504 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006505 {
6506 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6507 continue;
6508
6509 if ((table = rn->info) != NULL)
6510 {
6511 header = 1;
6512
6513 if ((rm = bgp_node_match (table, &match)) != NULL)
6514 {
6515 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6516 continue;
6517
6518 for (ri = rm->info; ri; ri = ri->next)
6519 {
6520 if (header)
6521 {
6522 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6523 AFI_IP, SAFI_MPLS_VPN);
6524
6525 header = 0;
6526 }
6527 display++;
6528 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6529 }
6530 }
6531 }
6532 }
6533 }
6534 else
6535 {
6536 header = 1;
6537
paulfee0f4c2004-09-13 05:12:46 +00006538 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006539 {
6540 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6541 {
6542 for (ri = rn->info; ri; ri = ri->next)
6543 {
6544 if (header)
6545 {
6546 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6547 header = 0;
6548 }
6549 display++;
6550 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6551 }
6552 }
6553 }
6554 }
6555
6556 if (! display)
6557 {
6558 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6559 return CMD_WARNING;
6560 }
6561
6562 return CMD_SUCCESS;
6563}
6564
paulfee0f4c2004-09-13 05:12:46 +00006565/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006566static int
paulfd79ac92004-10-13 05:06:08 +00006567bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006568 afi_t afi, safi_t safi, struct prefix_rd *prd,
6569 int prefix_check)
6570{
6571 struct bgp *bgp;
6572
6573 /* BGP structure lookup. */
6574 if (view_name)
6575 {
6576 bgp = bgp_lookup_by_name (view_name);
6577 if (bgp == NULL)
6578 {
6579 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6580 return CMD_WARNING;
6581 }
6582 }
6583 else
6584 {
6585 bgp = bgp_get_default ();
6586 if (bgp == NULL)
6587 {
6588 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6589 return CMD_WARNING;
6590 }
6591 }
6592
6593 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6594 afi, safi, prd, prefix_check);
6595}
6596
paul718e3742002-12-13 20:15:29 +00006597/* BGP route print out function. */
6598DEFUN (show_ip_bgp,
6599 show_ip_bgp_cmd,
6600 "show ip bgp",
6601 SHOW_STR
6602 IP_STR
6603 BGP_STR)
6604{
ajs5a646652004-11-05 01:25:55 +00006605 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006606}
6607
6608DEFUN (show_ip_bgp_ipv4,
6609 show_ip_bgp_ipv4_cmd,
6610 "show ip bgp ipv4 (unicast|multicast)",
6611 SHOW_STR
6612 IP_STR
6613 BGP_STR
6614 "Address family\n"
6615 "Address Family modifier\n"
6616 "Address Family modifier\n")
6617{
6618 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006619 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6620 NULL);
paul718e3742002-12-13 20:15:29 +00006621
ajs5a646652004-11-05 01:25:55 +00006622 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006623}
6624
6625DEFUN (show_ip_bgp_route,
6626 show_ip_bgp_route_cmd,
6627 "show ip bgp A.B.C.D",
6628 SHOW_STR
6629 IP_STR
6630 BGP_STR
6631 "Network in the BGP routing table to display\n")
6632{
6633 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6634}
6635
6636DEFUN (show_ip_bgp_ipv4_route,
6637 show_ip_bgp_ipv4_route_cmd,
6638 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6639 SHOW_STR
6640 IP_STR
6641 BGP_STR
6642 "Address family\n"
6643 "Address Family modifier\n"
6644 "Address Family modifier\n"
6645 "Network in the BGP routing table to display\n")
6646{
6647 if (strncmp (argv[0], "m", 1) == 0)
6648 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6649
6650 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6651}
6652
6653DEFUN (show_ip_bgp_vpnv4_all_route,
6654 show_ip_bgp_vpnv4_all_route_cmd,
6655 "show ip bgp vpnv4 all A.B.C.D",
6656 SHOW_STR
6657 IP_STR
6658 BGP_STR
6659 "Display VPNv4 NLRI specific information\n"
6660 "Display information about all VPNv4 NLRIs\n"
6661 "Network in the BGP routing table to display\n")
6662{
6663 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6664}
6665
6666DEFUN (show_ip_bgp_vpnv4_rd_route,
6667 show_ip_bgp_vpnv4_rd_route_cmd,
6668 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6669 SHOW_STR
6670 IP_STR
6671 BGP_STR
6672 "Display VPNv4 NLRI specific information\n"
6673 "Display information for a route distinguisher\n"
6674 "VPN Route Distinguisher\n"
6675 "Network in the BGP routing table to display\n")
6676{
6677 int ret;
6678 struct prefix_rd prd;
6679
6680 ret = str2prefix_rd (argv[0], &prd);
6681 if (! ret)
6682 {
6683 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6684 return CMD_WARNING;
6685 }
6686 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6687}
6688
6689DEFUN (show_ip_bgp_prefix,
6690 show_ip_bgp_prefix_cmd,
6691 "show ip bgp A.B.C.D/M",
6692 SHOW_STR
6693 IP_STR
6694 BGP_STR
6695 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6696{
6697 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6698}
6699
6700DEFUN (show_ip_bgp_ipv4_prefix,
6701 show_ip_bgp_ipv4_prefix_cmd,
6702 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6703 SHOW_STR
6704 IP_STR
6705 BGP_STR
6706 "Address family\n"
6707 "Address Family modifier\n"
6708 "Address Family modifier\n"
6709 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6710{
6711 if (strncmp (argv[0], "m", 1) == 0)
6712 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6713
6714 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6715}
6716
6717DEFUN (show_ip_bgp_vpnv4_all_prefix,
6718 show_ip_bgp_vpnv4_all_prefix_cmd,
6719 "show ip bgp vpnv4 all A.B.C.D/M",
6720 SHOW_STR
6721 IP_STR
6722 BGP_STR
6723 "Display VPNv4 NLRI specific information\n"
6724 "Display information about all VPNv4 NLRIs\n"
6725 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6726{
6727 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6728}
6729
6730DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6731 show_ip_bgp_vpnv4_rd_prefix_cmd,
6732 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6733 SHOW_STR
6734 IP_STR
6735 BGP_STR
6736 "Display VPNv4 NLRI specific information\n"
6737 "Display information for a route distinguisher\n"
6738 "VPN Route Distinguisher\n"
6739 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6740{
6741 int ret;
6742 struct prefix_rd prd;
6743
6744 ret = str2prefix_rd (argv[0], &prd);
6745 if (! ret)
6746 {
6747 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6748 return CMD_WARNING;
6749 }
6750 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6751}
6752
6753DEFUN (show_ip_bgp_view,
6754 show_ip_bgp_view_cmd,
6755 "show ip bgp view WORD",
6756 SHOW_STR
6757 IP_STR
6758 BGP_STR
6759 "BGP view\n"
6760 "BGP view name\n")
6761{
paulbb46e942003-10-24 19:02:03 +00006762 struct bgp *bgp;
6763
6764 /* BGP structure lookup. */
6765 bgp = bgp_lookup_by_name (argv[0]);
6766 if (bgp == NULL)
6767 {
6768 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6769 return CMD_WARNING;
6770 }
6771
ajs5a646652004-11-05 01:25:55 +00006772 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006773}
6774
6775DEFUN (show_ip_bgp_view_route,
6776 show_ip_bgp_view_route_cmd,
6777 "show ip bgp view WORD A.B.C.D",
6778 SHOW_STR
6779 IP_STR
6780 BGP_STR
6781 "BGP view\n"
6782 "BGP view name\n"
6783 "Network in the BGP routing table to display\n")
6784{
6785 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6786}
6787
6788DEFUN (show_ip_bgp_view_prefix,
6789 show_ip_bgp_view_prefix_cmd,
6790 "show ip bgp view WORD A.B.C.D/M",
6791 SHOW_STR
6792 IP_STR
6793 BGP_STR
6794 "BGP view\n"
6795 "BGP view name\n"
6796 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6797{
6798 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6799}
6800
6801#ifdef HAVE_IPV6
6802DEFUN (show_bgp,
6803 show_bgp_cmd,
6804 "show bgp",
6805 SHOW_STR
6806 BGP_STR)
6807{
ajs5a646652004-11-05 01:25:55 +00006808 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6809 NULL);
paul718e3742002-12-13 20:15:29 +00006810}
6811
6812ALIAS (show_bgp,
6813 show_bgp_ipv6_cmd,
6814 "show bgp ipv6",
6815 SHOW_STR
6816 BGP_STR
6817 "Address family\n")
6818
6819/* old command */
6820DEFUN (show_ipv6_bgp,
6821 show_ipv6_bgp_cmd,
6822 "show ipv6 bgp",
6823 SHOW_STR
6824 IP_STR
6825 BGP_STR)
6826{
ajs5a646652004-11-05 01:25:55 +00006827 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6828 NULL);
paul718e3742002-12-13 20:15:29 +00006829}
6830
6831DEFUN (show_bgp_route,
6832 show_bgp_route_cmd,
6833 "show bgp X:X::X:X",
6834 SHOW_STR
6835 BGP_STR
6836 "Network in the BGP routing table to display\n")
6837{
6838 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6839}
6840
6841ALIAS (show_bgp_route,
6842 show_bgp_ipv6_route_cmd,
6843 "show bgp ipv6 X:X::X:X",
6844 SHOW_STR
6845 BGP_STR
6846 "Address family\n"
6847 "Network in the BGP routing table to display\n")
6848
6849/* old command */
6850DEFUN (show_ipv6_bgp_route,
6851 show_ipv6_bgp_route_cmd,
6852 "show ipv6 bgp X:X::X:X",
6853 SHOW_STR
6854 IP_STR
6855 BGP_STR
6856 "Network in the BGP routing table to display\n")
6857{
6858 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6859}
6860
6861DEFUN (show_bgp_prefix,
6862 show_bgp_prefix_cmd,
6863 "show bgp X:X::X:X/M",
6864 SHOW_STR
6865 BGP_STR
6866 "IPv6 prefix <network>/<length>\n")
6867{
6868 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6869}
6870
6871ALIAS (show_bgp_prefix,
6872 show_bgp_ipv6_prefix_cmd,
6873 "show bgp ipv6 X:X::X:X/M",
6874 SHOW_STR
6875 BGP_STR
6876 "Address family\n"
6877 "IPv6 prefix <network>/<length>\n")
6878
6879/* old command */
6880DEFUN (show_ipv6_bgp_prefix,
6881 show_ipv6_bgp_prefix_cmd,
6882 "show ipv6 bgp X:X::X:X/M",
6883 SHOW_STR
6884 IP_STR
6885 BGP_STR
6886 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6887{
6888 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6889}
6890
paulbb46e942003-10-24 19:02:03 +00006891DEFUN (show_bgp_view,
6892 show_bgp_view_cmd,
6893 "show bgp view WORD",
6894 SHOW_STR
6895 BGP_STR
6896 "BGP view\n"
6897 "View name\n")
6898{
6899 struct bgp *bgp;
6900
6901 /* BGP structure lookup. */
6902 bgp = bgp_lookup_by_name (argv[0]);
6903 if (bgp == NULL)
6904 {
6905 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6906 return CMD_WARNING;
6907 }
6908
ajs5a646652004-11-05 01:25:55 +00006909 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006910}
6911
6912ALIAS (show_bgp_view,
6913 show_bgp_view_ipv6_cmd,
6914 "show bgp view WORD ipv6",
6915 SHOW_STR
6916 BGP_STR
6917 "BGP view\n"
6918 "View name\n"
6919 "Address family\n")
6920
6921DEFUN (show_bgp_view_route,
6922 show_bgp_view_route_cmd,
6923 "show bgp view WORD X:X::X:X",
6924 SHOW_STR
6925 BGP_STR
6926 "BGP view\n"
6927 "View name\n"
6928 "Network in the BGP routing table to display\n")
6929{
6930 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6931}
6932
6933ALIAS (show_bgp_view_route,
6934 show_bgp_view_ipv6_route_cmd,
6935 "show bgp view WORD ipv6 X:X::X:X",
6936 SHOW_STR
6937 BGP_STR
6938 "BGP view\n"
6939 "View name\n"
6940 "Address family\n"
6941 "Network in the BGP routing table to display\n")
6942
6943DEFUN (show_bgp_view_prefix,
6944 show_bgp_view_prefix_cmd,
6945 "show bgp view WORD X:X::X:X/M",
6946 SHOW_STR
6947 BGP_STR
6948 "BGP view\n"
6949 "View name\n"
6950 "IPv6 prefix <network>/<length>\n")
6951{
6952 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6953}
6954
6955ALIAS (show_bgp_view_prefix,
6956 show_bgp_view_ipv6_prefix_cmd,
6957 "show bgp view WORD ipv6 X:X::X:X/M",
6958 SHOW_STR
6959 BGP_STR
6960 "BGP view\n"
6961 "View name\n"
6962 "Address family\n"
6963 "IPv6 prefix <network>/<length>\n")
6964
paul718e3742002-12-13 20:15:29 +00006965/* old command */
6966DEFUN (show_ipv6_mbgp,
6967 show_ipv6_mbgp_cmd,
6968 "show ipv6 mbgp",
6969 SHOW_STR
6970 IP_STR
6971 MBGP_STR)
6972{
ajs5a646652004-11-05 01:25:55 +00006973 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6974 NULL);
paul718e3742002-12-13 20:15:29 +00006975}
6976
6977/* old command */
6978DEFUN (show_ipv6_mbgp_route,
6979 show_ipv6_mbgp_route_cmd,
6980 "show ipv6 mbgp X:X::X:X",
6981 SHOW_STR
6982 IP_STR
6983 MBGP_STR
6984 "Network in the MBGP routing table to display\n")
6985{
6986 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6987}
6988
6989/* old command */
6990DEFUN (show_ipv6_mbgp_prefix,
6991 show_ipv6_mbgp_prefix_cmd,
6992 "show ipv6 mbgp X:X::X:X/M",
6993 SHOW_STR
6994 IP_STR
6995 MBGP_STR
6996 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6997{
6998 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6999}
7000#endif
7001
paul718e3742002-12-13 20:15:29 +00007002
paul94f2b392005-06-28 12:44:16 +00007003static int
paulfd79ac92004-10-13 05:06:08 +00007004bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007005 safi_t safi, enum bgp_show_type type)
7006{
7007 int i;
7008 struct buffer *b;
7009 char *regstr;
7010 int first;
7011 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007012 int rc;
paul718e3742002-12-13 20:15:29 +00007013
7014 first = 0;
7015 b = buffer_new (1024);
7016 for (i = 0; i < argc; i++)
7017 {
7018 if (first)
7019 buffer_putc (b, ' ');
7020 else
7021 {
7022 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7023 continue;
7024 first = 1;
7025 }
7026
7027 buffer_putstr (b, argv[i]);
7028 }
7029 buffer_putc (b, '\0');
7030
7031 regstr = buffer_getstr (b);
7032 buffer_free (b);
7033
7034 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007035 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007036 if (! regex)
7037 {
7038 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7039 VTY_NEWLINE);
7040 return CMD_WARNING;
7041 }
7042
ajs5a646652004-11-05 01:25:55 +00007043 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7044 bgp_regex_free (regex);
7045 return rc;
paul718e3742002-12-13 20:15:29 +00007046}
7047
7048DEFUN (show_ip_bgp_regexp,
7049 show_ip_bgp_regexp_cmd,
7050 "show ip bgp regexp .LINE",
7051 SHOW_STR
7052 IP_STR
7053 BGP_STR
7054 "Display routes matching the AS path regular expression\n"
7055 "A regular-expression to match the BGP AS paths\n")
7056{
7057 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7058 bgp_show_type_regexp);
7059}
7060
7061DEFUN (show_ip_bgp_flap_regexp,
7062 show_ip_bgp_flap_regexp_cmd,
7063 "show ip bgp flap-statistics regexp .LINE",
7064 SHOW_STR
7065 IP_STR
7066 BGP_STR
7067 "Display flap statistics of routes\n"
7068 "Display routes matching the AS path regular expression\n"
7069 "A regular-expression to match the BGP AS paths\n")
7070{
7071 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7072 bgp_show_type_flap_regexp);
7073}
7074
7075DEFUN (show_ip_bgp_ipv4_regexp,
7076 show_ip_bgp_ipv4_regexp_cmd,
7077 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7078 SHOW_STR
7079 IP_STR
7080 BGP_STR
7081 "Address family\n"
7082 "Address Family modifier\n"
7083 "Address Family modifier\n"
7084 "Display routes matching the AS path regular expression\n"
7085 "A regular-expression to match the BGP AS paths\n")
7086{
7087 if (strncmp (argv[0], "m", 1) == 0)
7088 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7089 bgp_show_type_regexp);
7090
7091 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7092 bgp_show_type_regexp);
7093}
7094
7095#ifdef HAVE_IPV6
7096DEFUN (show_bgp_regexp,
7097 show_bgp_regexp_cmd,
7098 "show bgp regexp .LINE",
7099 SHOW_STR
7100 BGP_STR
7101 "Display routes matching the AS path regular expression\n"
7102 "A regular-expression to match the BGP AS paths\n")
7103{
7104 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7105 bgp_show_type_regexp);
7106}
7107
7108ALIAS (show_bgp_regexp,
7109 show_bgp_ipv6_regexp_cmd,
7110 "show bgp ipv6 regexp .LINE",
7111 SHOW_STR
7112 BGP_STR
7113 "Address family\n"
7114 "Display routes matching the AS path regular expression\n"
7115 "A regular-expression to match the BGP AS paths\n")
7116
7117/* old command */
7118DEFUN (show_ipv6_bgp_regexp,
7119 show_ipv6_bgp_regexp_cmd,
7120 "show ipv6 bgp regexp .LINE",
7121 SHOW_STR
7122 IP_STR
7123 BGP_STR
7124 "Display routes matching the AS path regular expression\n"
7125 "A regular-expression to match the BGP AS paths\n")
7126{
7127 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7128 bgp_show_type_regexp);
7129}
7130
7131/* old command */
7132DEFUN (show_ipv6_mbgp_regexp,
7133 show_ipv6_mbgp_regexp_cmd,
7134 "show ipv6 mbgp regexp .LINE",
7135 SHOW_STR
7136 IP_STR
7137 BGP_STR
7138 "Display routes matching the AS path regular expression\n"
7139 "A regular-expression to match the MBGP AS paths\n")
7140{
7141 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7142 bgp_show_type_regexp);
7143}
7144#endif /* HAVE_IPV6 */
7145
paul94f2b392005-06-28 12:44:16 +00007146static int
paulfd79ac92004-10-13 05:06:08 +00007147bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007148 safi_t safi, enum bgp_show_type type)
7149{
7150 struct prefix_list *plist;
7151
7152 plist = prefix_list_lookup (afi, prefix_list_str);
7153 if (plist == NULL)
7154 {
7155 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7156 prefix_list_str, VTY_NEWLINE);
7157 return CMD_WARNING;
7158 }
7159
ajs5a646652004-11-05 01:25:55 +00007160 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007161}
7162
7163DEFUN (show_ip_bgp_prefix_list,
7164 show_ip_bgp_prefix_list_cmd,
7165 "show ip bgp prefix-list WORD",
7166 SHOW_STR
7167 IP_STR
7168 BGP_STR
7169 "Display routes conforming to the prefix-list\n"
7170 "IP prefix-list name\n")
7171{
7172 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7173 bgp_show_type_prefix_list);
7174}
7175
7176DEFUN (show_ip_bgp_flap_prefix_list,
7177 show_ip_bgp_flap_prefix_list_cmd,
7178 "show ip bgp flap-statistics prefix-list WORD",
7179 SHOW_STR
7180 IP_STR
7181 BGP_STR
7182 "Display flap statistics of routes\n"
7183 "Display routes conforming to the prefix-list\n"
7184 "IP prefix-list name\n")
7185{
7186 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7187 bgp_show_type_flap_prefix_list);
7188}
7189
7190DEFUN (show_ip_bgp_ipv4_prefix_list,
7191 show_ip_bgp_ipv4_prefix_list_cmd,
7192 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7193 SHOW_STR
7194 IP_STR
7195 BGP_STR
7196 "Address family\n"
7197 "Address Family modifier\n"
7198 "Address Family modifier\n"
7199 "Display routes conforming to the prefix-list\n"
7200 "IP prefix-list name\n")
7201{
7202 if (strncmp (argv[0], "m", 1) == 0)
7203 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7204 bgp_show_type_prefix_list);
7205
7206 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7207 bgp_show_type_prefix_list);
7208}
7209
7210#ifdef HAVE_IPV6
7211DEFUN (show_bgp_prefix_list,
7212 show_bgp_prefix_list_cmd,
7213 "show bgp prefix-list WORD",
7214 SHOW_STR
7215 BGP_STR
7216 "Display routes conforming to the prefix-list\n"
7217 "IPv6 prefix-list name\n")
7218{
7219 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7220 bgp_show_type_prefix_list);
7221}
7222
7223ALIAS (show_bgp_prefix_list,
7224 show_bgp_ipv6_prefix_list_cmd,
7225 "show bgp ipv6 prefix-list WORD",
7226 SHOW_STR
7227 BGP_STR
7228 "Address family\n"
7229 "Display routes conforming to the prefix-list\n"
7230 "IPv6 prefix-list name\n")
7231
7232/* old command */
7233DEFUN (show_ipv6_bgp_prefix_list,
7234 show_ipv6_bgp_prefix_list_cmd,
7235 "show ipv6 bgp prefix-list WORD",
7236 SHOW_STR
7237 IPV6_STR
7238 BGP_STR
7239 "Display routes matching the prefix-list\n"
7240 "IPv6 prefix-list name\n")
7241{
7242 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7243 bgp_show_type_prefix_list);
7244}
7245
7246/* old command */
7247DEFUN (show_ipv6_mbgp_prefix_list,
7248 show_ipv6_mbgp_prefix_list_cmd,
7249 "show ipv6 mbgp prefix-list WORD",
7250 SHOW_STR
7251 IPV6_STR
7252 MBGP_STR
7253 "Display routes matching the prefix-list\n"
7254 "IPv6 prefix-list name\n")
7255{
7256 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7257 bgp_show_type_prefix_list);
7258}
7259#endif /* HAVE_IPV6 */
7260
paul94f2b392005-06-28 12:44:16 +00007261static int
paulfd79ac92004-10-13 05:06:08 +00007262bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007263 safi_t safi, enum bgp_show_type type)
7264{
7265 struct as_list *as_list;
7266
7267 as_list = as_list_lookup (filter);
7268 if (as_list == NULL)
7269 {
7270 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7271 return CMD_WARNING;
7272 }
7273
ajs5a646652004-11-05 01:25:55 +00007274 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007275}
7276
7277DEFUN (show_ip_bgp_filter_list,
7278 show_ip_bgp_filter_list_cmd,
7279 "show ip bgp filter-list WORD",
7280 SHOW_STR
7281 IP_STR
7282 BGP_STR
7283 "Display routes conforming to the filter-list\n"
7284 "Regular expression access list name\n")
7285{
7286 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7287 bgp_show_type_filter_list);
7288}
7289
7290DEFUN (show_ip_bgp_flap_filter_list,
7291 show_ip_bgp_flap_filter_list_cmd,
7292 "show ip bgp flap-statistics filter-list WORD",
7293 SHOW_STR
7294 IP_STR
7295 BGP_STR
7296 "Display flap statistics of routes\n"
7297 "Display routes conforming to the filter-list\n"
7298 "Regular expression access list name\n")
7299{
7300 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7301 bgp_show_type_flap_filter_list);
7302}
7303
7304DEFUN (show_ip_bgp_ipv4_filter_list,
7305 show_ip_bgp_ipv4_filter_list_cmd,
7306 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7307 SHOW_STR
7308 IP_STR
7309 BGP_STR
7310 "Address family\n"
7311 "Address Family modifier\n"
7312 "Address Family modifier\n"
7313 "Display routes conforming to the filter-list\n"
7314 "Regular expression access list name\n")
7315{
7316 if (strncmp (argv[0], "m", 1) == 0)
7317 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7318 bgp_show_type_filter_list);
7319
7320 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7321 bgp_show_type_filter_list);
7322}
7323
7324#ifdef HAVE_IPV6
7325DEFUN (show_bgp_filter_list,
7326 show_bgp_filter_list_cmd,
7327 "show bgp filter-list WORD",
7328 SHOW_STR
7329 BGP_STR
7330 "Display routes conforming to the filter-list\n"
7331 "Regular expression access list name\n")
7332{
7333 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7334 bgp_show_type_filter_list);
7335}
7336
7337ALIAS (show_bgp_filter_list,
7338 show_bgp_ipv6_filter_list_cmd,
7339 "show bgp ipv6 filter-list WORD",
7340 SHOW_STR
7341 BGP_STR
7342 "Address family\n"
7343 "Display routes conforming to the filter-list\n"
7344 "Regular expression access list name\n")
7345
7346/* old command */
7347DEFUN (show_ipv6_bgp_filter_list,
7348 show_ipv6_bgp_filter_list_cmd,
7349 "show ipv6 bgp filter-list WORD",
7350 SHOW_STR
7351 IPV6_STR
7352 BGP_STR
7353 "Display routes conforming to the filter-list\n"
7354 "Regular expression access list name\n")
7355{
7356 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7357 bgp_show_type_filter_list);
7358}
7359
7360/* old command */
7361DEFUN (show_ipv6_mbgp_filter_list,
7362 show_ipv6_mbgp_filter_list_cmd,
7363 "show ipv6 mbgp filter-list WORD",
7364 SHOW_STR
7365 IPV6_STR
7366 MBGP_STR
7367 "Display routes conforming to the filter-list\n"
7368 "Regular expression access list name\n")
7369{
7370 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7371 bgp_show_type_filter_list);
7372}
7373#endif /* HAVE_IPV6 */
7374
paul94f2b392005-06-28 12:44:16 +00007375static int
paulfd79ac92004-10-13 05:06:08 +00007376bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007377 safi_t safi, enum bgp_show_type type)
7378{
7379 struct route_map *rmap;
7380
7381 rmap = route_map_lookup_by_name (rmap_str);
7382 if (! rmap)
7383 {
7384 vty_out (vty, "%% %s is not a valid route-map name%s",
7385 rmap_str, VTY_NEWLINE);
7386 return CMD_WARNING;
7387 }
7388
ajs5a646652004-11-05 01:25:55 +00007389 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007390}
7391
7392DEFUN (show_ip_bgp_route_map,
7393 show_ip_bgp_route_map_cmd,
7394 "show ip bgp route-map WORD",
7395 SHOW_STR
7396 IP_STR
7397 BGP_STR
7398 "Display routes matching the route-map\n"
7399 "A route-map to match on\n")
7400{
7401 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7402 bgp_show_type_route_map);
7403}
7404
7405DEFUN (show_ip_bgp_flap_route_map,
7406 show_ip_bgp_flap_route_map_cmd,
7407 "show ip bgp flap-statistics route-map WORD",
7408 SHOW_STR
7409 IP_STR
7410 BGP_STR
7411 "Display flap statistics of routes\n"
7412 "Display routes matching the route-map\n"
7413 "A route-map to match on\n")
7414{
7415 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7416 bgp_show_type_flap_route_map);
7417}
7418
7419DEFUN (show_ip_bgp_ipv4_route_map,
7420 show_ip_bgp_ipv4_route_map_cmd,
7421 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7422 SHOW_STR
7423 IP_STR
7424 BGP_STR
7425 "Address family\n"
7426 "Address Family modifier\n"
7427 "Address Family modifier\n"
7428 "Display routes matching the route-map\n"
7429 "A route-map to match on\n")
7430{
7431 if (strncmp (argv[0], "m", 1) == 0)
7432 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7433 bgp_show_type_route_map);
7434
7435 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7436 bgp_show_type_route_map);
7437}
7438
7439DEFUN (show_bgp_route_map,
7440 show_bgp_route_map_cmd,
7441 "show bgp route-map WORD",
7442 SHOW_STR
7443 BGP_STR
7444 "Display routes matching the route-map\n"
7445 "A route-map to match on\n")
7446{
7447 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7448 bgp_show_type_route_map);
7449}
7450
7451ALIAS (show_bgp_route_map,
7452 show_bgp_ipv6_route_map_cmd,
7453 "show bgp ipv6 route-map WORD",
7454 SHOW_STR
7455 BGP_STR
7456 "Address family\n"
7457 "Display routes matching the route-map\n"
7458 "A route-map to match on\n")
7459
7460DEFUN (show_ip_bgp_cidr_only,
7461 show_ip_bgp_cidr_only_cmd,
7462 "show ip bgp cidr-only",
7463 SHOW_STR
7464 IP_STR
7465 BGP_STR
7466 "Display only routes with non-natural netmasks\n")
7467{
7468 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007469 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007470}
7471
7472DEFUN (show_ip_bgp_flap_cidr_only,
7473 show_ip_bgp_flap_cidr_only_cmd,
7474 "show ip bgp flap-statistics cidr-only",
7475 SHOW_STR
7476 IP_STR
7477 BGP_STR
7478 "Display flap statistics of routes\n"
7479 "Display only routes with non-natural netmasks\n")
7480{
7481 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007482 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007483}
7484
7485DEFUN (show_ip_bgp_ipv4_cidr_only,
7486 show_ip_bgp_ipv4_cidr_only_cmd,
7487 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7488 SHOW_STR
7489 IP_STR
7490 BGP_STR
7491 "Address family\n"
7492 "Address Family modifier\n"
7493 "Address Family modifier\n"
7494 "Display only routes with non-natural netmasks\n")
7495{
7496 if (strncmp (argv[0], "m", 1) == 0)
7497 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007498 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007499
7500 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007501 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007502}
7503
7504DEFUN (show_ip_bgp_community_all,
7505 show_ip_bgp_community_all_cmd,
7506 "show ip bgp community",
7507 SHOW_STR
7508 IP_STR
7509 BGP_STR
7510 "Display routes matching the communities\n")
7511{
7512 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007513 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007514}
7515
7516DEFUN (show_ip_bgp_ipv4_community_all,
7517 show_ip_bgp_ipv4_community_all_cmd,
7518 "show ip bgp ipv4 (unicast|multicast) community",
7519 SHOW_STR
7520 IP_STR
7521 BGP_STR
7522 "Address family\n"
7523 "Address Family modifier\n"
7524 "Address Family modifier\n"
7525 "Display routes matching the communities\n")
7526{
7527 if (strncmp (argv[0], "m", 1) == 0)
7528 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007529 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007530
7531 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007532 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007533}
7534
7535#ifdef HAVE_IPV6
7536DEFUN (show_bgp_community_all,
7537 show_bgp_community_all_cmd,
7538 "show bgp community",
7539 SHOW_STR
7540 BGP_STR
7541 "Display routes matching the communities\n")
7542{
7543 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007544 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007545}
7546
7547ALIAS (show_bgp_community_all,
7548 show_bgp_ipv6_community_all_cmd,
7549 "show bgp ipv6 community",
7550 SHOW_STR
7551 BGP_STR
7552 "Address family\n"
7553 "Display routes matching the communities\n")
7554
7555/* old command */
7556DEFUN (show_ipv6_bgp_community_all,
7557 show_ipv6_bgp_community_all_cmd,
7558 "show ipv6 bgp community",
7559 SHOW_STR
7560 IPV6_STR
7561 BGP_STR
7562 "Display routes matching the communities\n")
7563{
7564 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007565 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007566}
7567
7568/* old command */
7569DEFUN (show_ipv6_mbgp_community_all,
7570 show_ipv6_mbgp_community_all_cmd,
7571 "show ipv6 mbgp community",
7572 SHOW_STR
7573 IPV6_STR
7574 MBGP_STR
7575 "Display routes matching the communities\n")
7576{
7577 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007578 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007579}
7580#endif /* HAVE_IPV6 */
7581
paul94f2b392005-06-28 12:44:16 +00007582static int
paulfd79ac92004-10-13 05:06:08 +00007583bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
7584 u_int16_t afi, u_char safi)
paul718e3742002-12-13 20:15:29 +00007585{
7586 struct community *com;
7587 struct buffer *b;
7588 int i;
7589 char *str;
7590 int first = 0;
7591
7592 b = buffer_new (1024);
7593 for (i = 0; i < argc; i++)
7594 {
7595 if (first)
7596 buffer_putc (b, ' ');
7597 else
7598 {
7599 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7600 continue;
7601 first = 1;
7602 }
7603
7604 buffer_putstr (b, argv[i]);
7605 }
7606 buffer_putc (b, '\0');
7607
7608 str = buffer_getstr (b);
7609 buffer_free (b);
7610
7611 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007612 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007613 if (! com)
7614 {
7615 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7616 return CMD_WARNING;
7617 }
7618
ajs5a646652004-11-05 01:25:55 +00007619 return bgp_show (vty, NULL, afi, safi,
7620 (exact ? bgp_show_type_community_exact :
7621 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007622}
7623
7624DEFUN (show_ip_bgp_community,
7625 show_ip_bgp_community_cmd,
7626 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7627 SHOW_STR
7628 IP_STR
7629 BGP_STR
7630 "Display routes matching the communities\n"
7631 "community number\n"
7632 "Do not send outside local AS (well-known community)\n"
7633 "Do not advertise to any peer (well-known community)\n"
7634 "Do not export to next AS (well-known community)\n")
7635{
7636 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7637}
7638
7639ALIAS (show_ip_bgp_community,
7640 show_ip_bgp_community2_cmd,
7641 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7642 SHOW_STR
7643 IP_STR
7644 BGP_STR
7645 "Display routes matching the communities\n"
7646 "community number\n"
7647 "Do not send outside local AS (well-known community)\n"
7648 "Do not advertise to any peer (well-known community)\n"
7649 "Do not export to next AS (well-known community)\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
7655ALIAS (show_ip_bgp_community,
7656 show_ip_bgp_community3_cmd,
7657 "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)",
7658 SHOW_STR
7659 IP_STR
7660 BGP_STR
7661 "Display routes matching the communities\n"
7662 "community number\n"
7663 "Do not send outside local AS (well-known community)\n"
7664 "Do not advertise to any peer (well-known community)\n"
7665 "Do not export to next AS (well-known community)\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
7675ALIAS (show_ip_bgp_community,
7676 show_ip_bgp_community4_cmd,
7677 "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)",
7678 SHOW_STR
7679 IP_STR
7680 BGP_STR
7681 "Display routes matching the communities\n"
7682 "community number\n"
7683 "Do not send outside local AS (well-known community)\n"
7684 "Do not advertise to any peer (well-known community)\n"
7685 "Do not export to next AS (well-known community)\n"
7686 "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
7699DEFUN (show_ip_bgp_ipv4_community,
7700 show_ip_bgp_ipv4_community_cmd,
7701 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7702 SHOW_STR
7703 IP_STR
7704 BGP_STR
7705 "Address family\n"
7706 "Address Family modifier\n"
7707 "Address Family modifier\n"
7708 "Display routes matching the communities\n"
7709 "community number\n"
7710 "Do not send outside local AS (well-known community)\n"
7711 "Do not advertise to any peer (well-known community)\n"
7712 "Do not export to next AS (well-known community)\n")
7713{
7714 if (strncmp (argv[0], "m", 1) == 0)
7715 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7716
7717 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7718}
7719
7720ALIAS (show_ip_bgp_ipv4_community,
7721 show_ip_bgp_ipv4_community2_cmd,
7722 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7723 SHOW_STR
7724 IP_STR
7725 BGP_STR
7726 "Address family\n"
7727 "Address Family modifier\n"
7728 "Address Family modifier\n"
7729 "Display routes matching the communities\n"
7730 "community number\n"
7731 "Do not send outside local AS (well-known community)\n"
7732 "Do not advertise to any peer (well-known community)\n"
7733 "Do not export to next AS (well-known community)\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
7739ALIAS (show_ip_bgp_ipv4_community,
7740 show_ip_bgp_ipv4_community3_cmd,
7741 "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)",
7742 SHOW_STR
7743 IP_STR
7744 BGP_STR
7745 "Address family\n"
7746 "Address Family modifier\n"
7747 "Address Family modifier\n"
7748 "Display routes matching the communities\n"
7749 "community number\n"
7750 "Do not send outside local AS (well-known community)\n"
7751 "Do not advertise to any peer (well-known community)\n"
7752 "Do not export to next AS (well-known community)\n"
7753 "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
7762ALIAS (show_ip_bgp_ipv4_community,
7763 show_ip_bgp_ipv4_community4_cmd,
7764 "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)",
7765 SHOW_STR
7766 IP_STR
7767 BGP_STR
7768 "Address family\n"
7769 "Address Family modifier\n"
7770 "Address Family modifier\n"
7771 "Display routes matching the communities\n"
7772 "community number\n"
7773 "Do not send outside local AS (well-known community)\n"
7774 "Do not advertise to any peer (well-known community)\n"
7775 "Do not export to next AS (well-known community)\n"
7776 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n"
7780 "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
7789DEFUN (show_ip_bgp_community_exact,
7790 show_ip_bgp_community_exact_cmd,
7791 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7792 SHOW_STR
7793 IP_STR
7794 BGP_STR
7795 "Display routes matching the communities\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n"
7800 "Exact match of the communities")
7801{
7802 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7803}
7804
7805ALIAS (show_ip_bgp_community_exact,
7806 show_ip_bgp_community2_exact_cmd,
7807 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7808 SHOW_STR
7809 IP_STR
7810 BGP_STR
7811 "Display routes matching the communities\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "Exact match of the communities")
7821
7822ALIAS (show_ip_bgp_community_exact,
7823 show_ip_bgp_community3_exact_cmd,
7824 "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",
7825 SHOW_STR
7826 IP_STR
7827 BGP_STR
7828 "Display routes matching the communities\n"
7829 "community number\n"
7830 "Do not send outside local AS (well-known community)\n"
7831 "Do not advertise to any peer (well-known community)\n"
7832 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7842
7843ALIAS (show_ip_bgp_community_exact,
7844 show_ip_bgp_community4_exact_cmd,
7845 "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",
7846 SHOW_STR
7847 IP_STR
7848 BGP_STR
7849 "Display routes matching the communities\n"
7850 "community number\n"
7851 "Do not send outside local AS (well-known community)\n"
7852 "Do not advertise to any peer (well-known community)\n"
7853 "Do not export to next AS (well-known community)\n"
7854 "community number\n"
7855 "Do not send outside local AS (well-known community)\n"
7856 "Do not advertise to any peer (well-known community)\n"
7857 "Do not export to next AS (well-known community)\n"
7858 "community number\n"
7859 "Do not send outside local AS (well-known community)\n"
7860 "Do not advertise to any peer (well-known community)\n"
7861 "Do not export to next AS (well-known community)\n"
7862 "community number\n"
7863 "Do not send outside local AS (well-known community)\n"
7864 "Do not advertise to any peer (well-known community)\n"
7865 "Do not export to next AS (well-known community)\n"
7866 "Exact match of the communities")
7867
7868DEFUN (show_ip_bgp_ipv4_community_exact,
7869 show_ip_bgp_ipv4_community_exact_cmd,
7870 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7871 SHOW_STR
7872 IP_STR
7873 BGP_STR
7874 "Address family\n"
7875 "Address Family modifier\n"
7876 "Address Family modifier\n"
7877 "Display routes matching the communities\n"
7878 "community number\n"
7879 "Do not send outside local AS (well-known community)\n"
7880 "Do not advertise to any peer (well-known community)\n"
7881 "Do not export to next AS (well-known community)\n"
7882 "Exact match of the communities")
7883{
7884 if (strncmp (argv[0], "m", 1) == 0)
7885 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7886
7887 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7888}
7889
7890ALIAS (show_ip_bgp_ipv4_community_exact,
7891 show_ip_bgp_ipv4_community2_exact_cmd,
7892 "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",
7893 SHOW_STR
7894 IP_STR
7895 BGP_STR
7896 "Address family\n"
7897 "Address Family modifier\n"
7898 "Address Family modifier\n"
7899 "Display routes matching the communities\n"
7900 "community number\n"
7901 "Do not send outside local AS (well-known community)\n"
7902 "Do not advertise to any peer (well-known community)\n"
7903 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7909
7910ALIAS (show_ip_bgp_ipv4_community_exact,
7911 show_ip_bgp_ipv4_community3_exact_cmd,
7912 "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",
7913 SHOW_STR
7914 IP_STR
7915 BGP_STR
7916 "Address family\n"
7917 "Address Family modifier\n"
7918 "Address Family modifier\n"
7919 "Display routes matching the communities\n"
7920 "community number\n"
7921 "Do not send outside local AS (well-known community)\n"
7922 "Do not advertise to any peer (well-known community)\n"
7923 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7933
7934ALIAS (show_ip_bgp_ipv4_community_exact,
7935 show_ip_bgp_ipv4_community4_exact_cmd,
7936 "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",
7937 SHOW_STR
7938 IP_STR
7939 BGP_STR
7940 "Address family\n"
7941 "Address Family modifier\n"
7942 "Address Family modifier\n"
7943 "Display routes matching the communities\n"
7944 "community number\n"
7945 "Do not send outside local AS (well-known community)\n"
7946 "Do not advertise to any peer (well-known community)\n"
7947 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
7961
7962#ifdef HAVE_IPV6
7963DEFUN (show_bgp_community,
7964 show_bgp_community_cmd,
7965 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7966 SHOW_STR
7967 BGP_STR
7968 "Display routes matching the communities\n"
7969 "community number\n"
7970 "Do not send outside local AS (well-known community)\n"
7971 "Do not advertise to any peer (well-known community)\n"
7972 "Do not export to next AS (well-known community)\n")
7973{
7974 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7975}
7976
7977ALIAS (show_bgp_community,
7978 show_bgp_ipv6_community_cmd,
7979 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7980 SHOW_STR
7981 BGP_STR
7982 "Address family\n"
7983 "Display routes matching the communities\n"
7984 "community number\n"
7985 "Do not send outside local AS (well-known community)\n"
7986 "Do not advertise to any peer (well-known community)\n"
7987 "Do not export to next AS (well-known community)\n")
7988
7989ALIAS (show_bgp_community,
7990 show_bgp_community2_cmd,
7991 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7992 SHOW_STR
7993 BGP_STR
7994 "Display routes matching the communities\n"
7995 "community number\n"
7996 "Do not send outside local AS (well-known community)\n"
7997 "Do not advertise to any peer (well-known community)\n"
7998 "Do not export to next AS (well-known community)\n"
7999 "community number\n"
8000 "Do not send outside local AS (well-known community)\n"
8001 "Do not advertise to any peer (well-known community)\n"
8002 "Do not export to next AS (well-known community)\n")
8003
8004ALIAS (show_bgp_community,
8005 show_bgp_ipv6_community2_cmd,
8006 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8007 SHOW_STR
8008 BGP_STR
8009 "Address family\n"
8010 "Display routes matching the communities\n"
8011 "community number\n"
8012 "Do not send outside local AS (well-known community)\n"
8013 "Do not advertise to any peer (well-known community)\n"
8014 "Do not export to next AS (well-known community)\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
8020ALIAS (show_bgp_community,
8021 show_bgp_community3_cmd,
8022 "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)",
8023 SHOW_STR
8024 BGP_STR
8025 "Display routes matching the communities\n"
8026 "community number\n"
8027 "Do not send outside local AS (well-known community)\n"
8028 "Do not advertise to any peer (well-known community)\n"
8029 "Do not export to next AS (well-known community)\n"
8030 "community number\n"
8031 "Do not send outside local AS (well-known community)\n"
8032 "Do not advertise to any peer (well-known community)\n"
8033 "Do not export to next AS (well-known community)\n"
8034 "community number\n"
8035 "Do not send outside local AS (well-known community)\n"
8036 "Do not advertise to any peer (well-known community)\n"
8037 "Do not export to next AS (well-known community)\n")
8038
8039ALIAS (show_bgp_community,
8040 show_bgp_ipv6_community3_cmd,
8041 "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)",
8042 SHOW_STR
8043 BGP_STR
8044 "Address family\n"
8045 "Display routes matching the communities\n"
8046 "community number\n"
8047 "Do not send outside local AS (well-known community)\n"
8048 "Do not advertise to any peer (well-known community)\n"
8049 "Do not export to next AS (well-known community)\n"
8050 "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
8059ALIAS (show_bgp_community,
8060 show_bgp_community4_cmd,
8061 "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)",
8062 SHOW_STR
8063 BGP_STR
8064 "Display routes matching the communities\n"
8065 "community number\n"
8066 "Do not send outside local AS (well-known community)\n"
8067 "Do not advertise to any peer (well-known community)\n"
8068 "Do not export to next AS (well-known community)\n"
8069 "community number\n"
8070 "Do not send outside local AS (well-known community)\n"
8071 "Do not advertise to any peer (well-known community)\n"
8072 "Do not export to next AS (well-known community)\n"
8073 "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
8082ALIAS (show_bgp_community,
8083 show_bgp_ipv6_community4_cmd,
8084 "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)",
8085 SHOW_STR
8086 BGP_STR
8087 "Address family\n"
8088 "Display routes matching the communities\n"
8089 "community number\n"
8090 "Do not send outside local AS (well-known community)\n"
8091 "Do not advertise to any peer (well-known community)\n"
8092 "Do not export to next AS (well-known community)\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
8106/* old command */
8107DEFUN (show_ipv6_bgp_community,
8108 show_ipv6_bgp_community_cmd,
8109 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8110 SHOW_STR
8111 IPV6_STR
8112 BGP_STR
8113 "Display routes matching the communities\n"
8114 "community number\n"
8115 "Do not send outside local AS (well-known community)\n"
8116 "Do not advertise to any peer (well-known community)\n"
8117 "Do not export to next AS (well-known community)\n")
8118{
8119 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
8120}
8121
8122/* old command */
8123ALIAS (show_ipv6_bgp_community,
8124 show_ipv6_bgp_community2_cmd,
8125 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8126 SHOW_STR
8127 IPV6_STR
8128 BGP_STR
8129 "Display routes matching the communities\n"
8130 "community number\n"
8131 "Do not send outside local AS (well-known community)\n"
8132 "Do not advertise to any peer (well-known community)\n"
8133 "Do not export to next AS (well-known community)\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
8139/* old command */
8140ALIAS (show_ipv6_bgp_community,
8141 show_ipv6_bgp_community3_cmd,
8142 "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)",
8143 SHOW_STR
8144 IPV6_STR
8145 BGP_STR
8146 "Display routes matching the communities\n"
8147 "community number\n"
8148 "Do not send outside local AS (well-known community)\n"
8149 "Do not advertise to any peer (well-known community)\n"
8150 "Do not export to next AS (well-known community)\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
8160/* old command */
8161ALIAS (show_ipv6_bgp_community,
8162 show_ipv6_bgp_community4_cmd,
8163 "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)",
8164 SHOW_STR
8165 IPV6_STR
8166 BGP_STR
8167 "Display routes matching the communities\n"
8168 "community number\n"
8169 "Do not send outside local AS (well-known community)\n"
8170 "Do not advertise to any peer (well-known community)\n"
8171 "Do not export to next AS (well-known community)\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
8185DEFUN (show_bgp_community_exact,
8186 show_bgp_community_exact_cmd,
8187 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8188 SHOW_STR
8189 BGP_STR
8190 "Display routes matching the communities\n"
8191 "community number\n"
8192 "Do not send outside local AS (well-known community)\n"
8193 "Do not advertise to any peer (well-known community)\n"
8194 "Do not export to next AS (well-known community)\n"
8195 "Exact match of the communities")
8196{
8197 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8198}
8199
8200ALIAS (show_bgp_community_exact,
8201 show_bgp_ipv6_community_exact_cmd,
8202 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8203 SHOW_STR
8204 BGP_STR
8205 "Address family\n"
8206 "Display routes matching the communities\n"
8207 "community number\n"
8208 "Do not send outside local AS (well-known community)\n"
8209 "Do not advertise to any peer (well-known community)\n"
8210 "Do not export to next AS (well-known community)\n"
8211 "Exact match of the communities")
8212
8213ALIAS (show_bgp_community_exact,
8214 show_bgp_community2_exact_cmd,
8215 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8216 SHOW_STR
8217 BGP_STR
8218 "Display routes matching the communities\n"
8219 "community number\n"
8220 "Do not send outside local AS (well-known community)\n"
8221 "Do not advertise to any peer (well-known community)\n"
8222 "Do not export to next AS (well-known community)\n"
8223 "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 "Exact match of the communities")
8228
8229ALIAS (show_bgp_community_exact,
8230 show_bgp_ipv6_community2_exact_cmd,
8231 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8232 SHOW_STR
8233 BGP_STR
8234 "Address family\n"
8235 "Display routes matching the communities\n"
8236 "community number\n"
8237 "Do not send outside local AS (well-known community)\n"
8238 "Do not advertise to any peer (well-known community)\n"
8239 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8245
8246ALIAS (show_bgp_community_exact,
8247 show_bgp_community3_exact_cmd,
8248 "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",
8249 SHOW_STR
8250 BGP_STR
8251 "Display routes matching the communities\n"
8252 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n"
8256 "community number\n"
8257 "Do not send outside local AS (well-known community)\n"
8258 "Do not advertise to any peer (well-known community)\n"
8259 "Do not export to next AS (well-known community)\n"
8260 "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 "Exact match of the communities")
8265
8266ALIAS (show_bgp_community_exact,
8267 show_bgp_ipv6_community3_exact_cmd,
8268 "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",
8269 SHOW_STR
8270 BGP_STR
8271 "Address family\n"
8272 "Display routes matching the communities\n"
8273 "community number\n"
8274 "Do not send outside local AS (well-known community)\n"
8275 "Do not advertise to any peer (well-known community)\n"
8276 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8286
8287ALIAS (show_bgp_community_exact,
8288 show_bgp_community4_exact_cmd,
8289 "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",
8290 SHOW_STR
8291 BGP_STR
8292 "Display routes matching the communities\n"
8293 "community number\n"
8294 "Do not send outside local AS (well-known community)\n"
8295 "Do not advertise to any peer (well-known community)\n"
8296 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8310
8311ALIAS (show_bgp_community_exact,
8312 show_bgp_ipv6_community4_exact_cmd,
8313 "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",
8314 SHOW_STR
8315 BGP_STR
8316 "Address family\n"
8317 "Display routes matching the communities\n"
8318 "community number\n"
8319 "Do not send outside local AS (well-known community)\n"
8320 "Do not advertise to any peer (well-known community)\n"
8321 "Do not export to next AS (well-known community)\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n"
8326 "community number\n"
8327 "Do not send outside local AS (well-known community)\n"
8328 "Do not advertise to any peer (well-known community)\n"
8329 "Do not export to next AS (well-known community)\n"
8330 "community number\n"
8331 "Do not send outside local AS (well-known community)\n"
8332 "Do not advertise to any peer (well-known community)\n"
8333 "Do not export to next AS (well-known community)\n"
8334 "Exact match of the communities")
8335
8336/* old command */
8337DEFUN (show_ipv6_bgp_community_exact,
8338 show_ipv6_bgp_community_exact_cmd,
8339 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8340 SHOW_STR
8341 IPV6_STR
8342 BGP_STR
8343 "Display routes matching the communities\n"
8344 "community number\n"
8345 "Do not send outside local AS (well-known community)\n"
8346 "Do not advertise to any peer (well-known community)\n"
8347 "Do not export to next AS (well-known community)\n"
8348 "Exact match of the communities")
8349{
8350 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8351}
8352
8353/* old command */
8354ALIAS (show_ipv6_bgp_community_exact,
8355 show_ipv6_bgp_community2_exact_cmd,
8356 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8357 SHOW_STR
8358 IPV6_STR
8359 BGP_STR
8360 "Display routes matching the communities\n"
8361 "community number\n"
8362 "Do not send outside local AS (well-known community)\n"
8363 "Do not advertise to any peer (well-known community)\n"
8364 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8370
8371/* old command */
8372ALIAS (show_ipv6_bgp_community_exact,
8373 show_ipv6_bgp_community3_exact_cmd,
8374 "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",
8375 SHOW_STR
8376 IPV6_STR
8377 BGP_STR
8378 "Display routes matching the communities\n"
8379 "community number\n"
8380 "Do not send outside local AS (well-known community)\n"
8381 "Do not advertise to any peer (well-known community)\n"
8382 "Do not export to next AS (well-known community)\n"
8383 "community number\n"
8384 "Do not send outside local AS (well-known community)\n"
8385 "Do not advertise to any peer (well-known community)\n"
8386 "Do not export to next AS (well-known community)\n"
8387 "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 "Exact match of the communities")
8392
8393/* old command */
8394ALIAS (show_ipv6_bgp_community_exact,
8395 show_ipv6_bgp_community4_exact_cmd,
8396 "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",
8397 SHOW_STR
8398 IPV6_STR
8399 BGP_STR
8400 "Display routes matching the communities\n"
8401 "community number\n"
8402 "Do not send outside local AS (well-known community)\n"
8403 "Do not advertise to any peer (well-known community)\n"
8404 "Do not export to next AS (well-known community)\n"
8405 "community number\n"
8406 "Do not send outside local AS (well-known community)\n"
8407 "Do not advertise to any peer (well-known community)\n"
8408 "Do not export to next AS (well-known community)\n"
8409 "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 "Exact match of the communities")
8418
8419/* old command */
8420DEFUN (show_ipv6_mbgp_community,
8421 show_ipv6_mbgp_community_cmd,
8422 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8423 SHOW_STR
8424 IPV6_STR
8425 MBGP_STR
8426 "Display routes matching the communities\n"
8427 "community number\n"
8428 "Do not send outside local AS (well-known community)\n"
8429 "Do not advertise to any peer (well-known community)\n"
8430 "Do not export to next AS (well-known community)\n")
8431{
8432 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8433}
8434
8435/* old command */
8436ALIAS (show_ipv6_mbgp_community,
8437 show_ipv6_mbgp_community2_cmd,
8438 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8439 SHOW_STR
8440 IPV6_STR
8441 MBGP_STR
8442 "Display routes matching the communities\n"
8443 "community number\n"
8444 "Do not send outside local AS (well-known community)\n"
8445 "Do not advertise to any peer (well-known community)\n"
8446 "Do not export to next AS (well-known community)\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
8452/* old command */
8453ALIAS (show_ipv6_mbgp_community,
8454 show_ipv6_mbgp_community3_cmd,
8455 "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)",
8456 SHOW_STR
8457 IPV6_STR
8458 MBGP_STR
8459 "Display routes matching the communities\n"
8460 "community number\n"
8461 "Do not send outside local AS (well-known community)\n"
8462 "Do not advertise to any peer (well-known community)\n"
8463 "Do not export to next AS (well-known community)\n"
8464 "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
8473/* old command */
8474ALIAS (show_ipv6_mbgp_community,
8475 show_ipv6_mbgp_community4_cmd,
8476 "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)",
8477 SHOW_STR
8478 IPV6_STR
8479 MBGP_STR
8480 "Display routes matching the communities\n"
8481 "community number\n"
8482 "Do not send outside local AS (well-known community)\n"
8483 "Do not advertise to any peer (well-known community)\n"
8484 "Do not export to next AS (well-known community)\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
8498/* old command */
8499DEFUN (show_ipv6_mbgp_community_exact,
8500 show_ipv6_mbgp_community_exact_cmd,
8501 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8502 SHOW_STR
8503 IPV6_STR
8504 MBGP_STR
8505 "Display routes matching the communities\n"
8506 "community number\n"
8507 "Do not send outside local AS (well-known community)\n"
8508 "Do not advertise to any peer (well-known community)\n"
8509 "Do not export to next AS (well-known community)\n"
8510 "Exact match of the communities")
8511{
8512 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8513}
8514
8515/* old command */
8516ALIAS (show_ipv6_mbgp_community_exact,
8517 show_ipv6_mbgp_community2_exact_cmd,
8518 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8519 SHOW_STR
8520 IPV6_STR
8521 MBGP_STR
8522 "Display routes matching the communities\n"
8523 "community number\n"
8524 "Do not send outside local AS (well-known community)\n"
8525 "Do not advertise to any peer (well-known community)\n"
8526 "Do not export to next AS (well-known community)\n"
8527 "community number\n"
8528 "Do not send outside local AS (well-known community)\n"
8529 "Do not advertise to any peer (well-known community)\n"
8530 "Do not export to next AS (well-known community)\n"
8531 "Exact match of the communities")
8532
8533/* old command */
8534ALIAS (show_ipv6_mbgp_community_exact,
8535 show_ipv6_mbgp_community3_exact_cmd,
8536 "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",
8537 SHOW_STR
8538 IPV6_STR
8539 MBGP_STR
8540 "Display routes matching the communities\n"
8541 "community number\n"
8542 "Do not send outside local AS (well-known community)\n"
8543 "Do not advertise to any peer (well-known community)\n"
8544 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8554
8555/* old command */
8556ALIAS (show_ipv6_mbgp_community_exact,
8557 show_ipv6_mbgp_community4_exact_cmd,
8558 "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",
8559 SHOW_STR
8560 IPV6_STR
8561 MBGP_STR
8562 "Display routes matching the communities\n"
8563 "community number\n"
8564 "Do not send outside local AS (well-known community)\n"
8565 "Do not advertise to any peer (well-known community)\n"
8566 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8580#endif /* HAVE_IPV6 */
8581
paul94f2b392005-06-28 12:44:16 +00008582static int
paulfd79ac92004-10-13 05:06:08 +00008583bgp_show_community_list (struct vty *vty, const char *com, int exact,
paul718e3742002-12-13 20:15:29 +00008584 u_int16_t afi, u_char safi)
8585{
8586 struct community_list *list;
8587
hassofee6e4e2005-02-02 16:29:31 +00008588 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008589 if (list == NULL)
8590 {
8591 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8592 VTY_NEWLINE);
8593 return CMD_WARNING;
8594 }
8595
ajs5a646652004-11-05 01:25:55 +00008596 return bgp_show (vty, NULL, afi, safi,
8597 (exact ? bgp_show_type_community_list_exact :
8598 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008599}
8600
8601DEFUN (show_ip_bgp_community_list,
8602 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008603 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008604 SHOW_STR
8605 IP_STR
8606 BGP_STR
8607 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008608 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008609 "community-list name\n")
8610{
8611 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8612}
8613
8614DEFUN (show_ip_bgp_ipv4_community_list,
8615 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008616 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008617 SHOW_STR
8618 IP_STR
8619 BGP_STR
8620 "Address family\n"
8621 "Address Family modifier\n"
8622 "Address Family modifier\n"
8623 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008624 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008625 "community-list name\n")
8626{
8627 if (strncmp (argv[0], "m", 1) == 0)
8628 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8629
8630 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8631}
8632
8633DEFUN (show_ip_bgp_community_list_exact,
8634 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008635 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008636 SHOW_STR
8637 IP_STR
8638 BGP_STR
8639 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008640 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008641 "community-list name\n"
8642 "Exact match of the communities\n")
8643{
8644 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8645}
8646
8647DEFUN (show_ip_bgp_ipv4_community_list_exact,
8648 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008649 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008650 SHOW_STR
8651 IP_STR
8652 BGP_STR
8653 "Address family\n"
8654 "Address Family modifier\n"
8655 "Address Family modifier\n"
8656 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008657 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008658 "community-list name\n"
8659 "Exact match of the communities\n")
8660{
8661 if (strncmp (argv[0], "m", 1) == 0)
8662 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8663
8664 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8665}
8666
8667#ifdef HAVE_IPV6
8668DEFUN (show_bgp_community_list,
8669 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008670 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008671 SHOW_STR
8672 BGP_STR
8673 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008674 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008675 "community-list name\n")
8676{
8677 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8678}
8679
8680ALIAS (show_bgp_community_list,
8681 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008682 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008683 SHOW_STR
8684 BGP_STR
8685 "Address family\n"
8686 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008687 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008688 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008689
8690/* old command */
8691DEFUN (show_ipv6_bgp_community_list,
8692 show_ipv6_bgp_community_list_cmd,
8693 "show ipv6 bgp community-list WORD",
8694 SHOW_STR
8695 IPV6_STR
8696 BGP_STR
8697 "Display routes matching the community-list\n"
8698 "community-list name\n")
8699{
8700 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8701}
8702
8703/* old command */
8704DEFUN (show_ipv6_mbgp_community_list,
8705 show_ipv6_mbgp_community_list_cmd,
8706 "show ipv6 mbgp community-list WORD",
8707 SHOW_STR
8708 IPV6_STR
8709 MBGP_STR
8710 "Display routes matching the community-list\n"
8711 "community-list name\n")
8712{
8713 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8714}
8715
8716DEFUN (show_bgp_community_list_exact,
8717 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008718 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008719 SHOW_STR
8720 BGP_STR
8721 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008722 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008723 "community-list name\n"
8724 "Exact match of the communities\n")
8725{
8726 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8727}
8728
8729ALIAS (show_bgp_community_list_exact,
8730 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008731 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008732 SHOW_STR
8733 BGP_STR
8734 "Address family\n"
8735 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008736 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008737 "community-list name\n"
8738 "Exact match of the communities\n")
8739
8740/* old command */
8741DEFUN (show_ipv6_bgp_community_list_exact,
8742 show_ipv6_bgp_community_list_exact_cmd,
8743 "show ipv6 bgp community-list WORD exact-match",
8744 SHOW_STR
8745 IPV6_STR
8746 BGP_STR
8747 "Display routes matching the community-list\n"
8748 "community-list name\n"
8749 "Exact match of the communities\n")
8750{
8751 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8752}
8753
8754/* old command */
8755DEFUN (show_ipv6_mbgp_community_list_exact,
8756 show_ipv6_mbgp_community_list_exact_cmd,
8757 "show ipv6 mbgp community-list WORD exact-match",
8758 SHOW_STR
8759 IPV6_STR
8760 MBGP_STR
8761 "Display routes matching the community-list\n"
8762 "community-list name\n"
8763 "Exact match of the communities\n")
8764{
8765 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8766}
8767#endif /* HAVE_IPV6 */
8768
paul94f2b392005-06-28 12:44:16 +00008769static int
paulfd79ac92004-10-13 05:06:08 +00008770bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008771 safi_t safi, enum bgp_show_type type)
8772{
8773 int ret;
8774 struct prefix *p;
8775
8776 p = prefix_new();
8777
8778 ret = str2prefix (prefix, p);
8779 if (! ret)
8780 {
8781 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8782 return CMD_WARNING;
8783 }
8784
ajs5a646652004-11-05 01:25:55 +00008785 ret = bgp_show (vty, NULL, afi, safi, type, p);
8786 prefix_free(p);
8787 return ret;
paul718e3742002-12-13 20:15:29 +00008788}
8789
8790DEFUN (show_ip_bgp_prefix_longer,
8791 show_ip_bgp_prefix_longer_cmd,
8792 "show ip bgp A.B.C.D/M longer-prefixes",
8793 SHOW_STR
8794 IP_STR
8795 BGP_STR
8796 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8797 "Display route and more specific routes\n")
8798{
8799 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8800 bgp_show_type_prefix_longer);
8801}
8802
8803DEFUN (show_ip_bgp_flap_prefix_longer,
8804 show_ip_bgp_flap_prefix_longer_cmd,
8805 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8806 SHOW_STR
8807 IP_STR
8808 BGP_STR
8809 "Display flap statistics of routes\n"
8810 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8811 "Display route and more specific routes\n")
8812{
8813 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8814 bgp_show_type_flap_prefix_longer);
8815}
8816
8817DEFUN (show_ip_bgp_ipv4_prefix_longer,
8818 show_ip_bgp_ipv4_prefix_longer_cmd,
8819 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8820 SHOW_STR
8821 IP_STR
8822 BGP_STR
8823 "Address family\n"
8824 "Address Family modifier\n"
8825 "Address Family modifier\n"
8826 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8827 "Display route and more specific routes\n")
8828{
8829 if (strncmp (argv[0], "m", 1) == 0)
8830 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8831 bgp_show_type_prefix_longer);
8832
8833 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8834 bgp_show_type_prefix_longer);
8835}
8836
8837DEFUN (show_ip_bgp_flap_address,
8838 show_ip_bgp_flap_address_cmd,
8839 "show ip bgp flap-statistics A.B.C.D",
8840 SHOW_STR
8841 IP_STR
8842 BGP_STR
8843 "Display flap statistics of routes\n"
8844 "Network in the BGP routing table to display\n")
8845{
8846 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8847 bgp_show_type_flap_address);
8848}
8849
8850DEFUN (show_ip_bgp_flap_prefix,
8851 show_ip_bgp_flap_prefix_cmd,
8852 "show ip bgp flap-statistics A.B.C.D/M",
8853 SHOW_STR
8854 IP_STR
8855 BGP_STR
8856 "Display flap statistics of routes\n"
8857 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8858{
8859 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8860 bgp_show_type_flap_prefix);
8861}
8862#ifdef HAVE_IPV6
8863DEFUN (show_bgp_prefix_longer,
8864 show_bgp_prefix_longer_cmd,
8865 "show bgp X:X::X:X/M longer-prefixes",
8866 SHOW_STR
8867 BGP_STR
8868 "IPv6 prefix <network>/<length>\n"
8869 "Display route and more specific routes\n")
8870{
8871 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8872 bgp_show_type_prefix_longer);
8873}
8874
8875ALIAS (show_bgp_prefix_longer,
8876 show_bgp_ipv6_prefix_longer_cmd,
8877 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8878 SHOW_STR
8879 BGP_STR
8880 "Address family\n"
8881 "IPv6 prefix <network>/<length>\n"
8882 "Display route and more specific routes\n")
8883
8884/* old command */
8885DEFUN (show_ipv6_bgp_prefix_longer,
8886 show_ipv6_bgp_prefix_longer_cmd,
8887 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8888 SHOW_STR
8889 IPV6_STR
8890 BGP_STR
8891 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8892 "Display route and more specific routes\n")
8893{
8894 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8895 bgp_show_type_prefix_longer);
8896}
8897
8898/* old command */
8899DEFUN (show_ipv6_mbgp_prefix_longer,
8900 show_ipv6_mbgp_prefix_longer_cmd,
8901 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8902 SHOW_STR
8903 IPV6_STR
8904 MBGP_STR
8905 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8906 "Display route and more specific routes\n")
8907{
8908 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8909 bgp_show_type_prefix_longer);
8910}
8911#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008912
paul94f2b392005-06-28 12:44:16 +00008913static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008914peer_lookup_in_view (struct vty *vty, const char *view_name,
8915 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008916{
8917 int ret;
8918 struct bgp *bgp;
8919 struct peer *peer;
8920 union sockunion su;
8921
8922 /* BGP structure lookup. */
8923 if (view_name)
8924 {
8925 bgp = bgp_lookup_by_name (view_name);
8926 if (! bgp)
8927 {
8928 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8929 return NULL;
8930 }
8931 }
paul5228ad22004-06-04 17:58:18 +00008932 else
paulbb46e942003-10-24 19:02:03 +00008933 {
8934 bgp = bgp_get_default ();
8935 if (! bgp)
8936 {
8937 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8938 return NULL;
8939 }
8940 }
8941
8942 /* Get peer sockunion. */
8943 ret = str2sockunion (ip_str, &su);
8944 if (ret < 0)
8945 {
8946 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8947 return NULL;
8948 }
8949
8950 /* Peer structure lookup. */
8951 peer = peer_lookup (bgp, &su);
8952 if (! peer)
8953 {
8954 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8955 return NULL;
8956 }
8957
8958 return peer;
8959}
Paul Jakma2815e612006-09-14 02:56:07 +00008960
8961enum bgp_stats
8962{
8963 BGP_STATS_MAXBITLEN = 0,
8964 BGP_STATS_RIB,
8965 BGP_STATS_PREFIXES,
8966 BGP_STATS_TOTPLEN,
8967 BGP_STATS_UNAGGREGATEABLE,
8968 BGP_STATS_MAX_AGGREGATEABLE,
8969 BGP_STATS_AGGREGATES,
8970 BGP_STATS_SPACE,
8971 BGP_STATS_ASPATH_COUNT,
8972 BGP_STATS_ASPATH_MAXHOPS,
8973 BGP_STATS_ASPATH_TOTHOPS,
8974 BGP_STATS_ASPATH_MAXSIZE,
8975 BGP_STATS_ASPATH_TOTSIZE,
8976 BGP_STATS_ASN_HIGHEST,
8977 BGP_STATS_MAX,
8978};
paulbb46e942003-10-24 19:02:03 +00008979
Paul Jakma2815e612006-09-14 02:56:07 +00008980static const char *table_stats_strs[] =
8981{
8982 [BGP_STATS_PREFIXES] = "Total Prefixes",
8983 [BGP_STATS_TOTPLEN] = "Average prefix length",
8984 [BGP_STATS_RIB] = "Total Advertisements",
8985 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8986 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8987 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8988 [BGP_STATS_SPACE] = "Address space advertised",
8989 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8990 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8991 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8992 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8993 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8994 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8995 [BGP_STATS_MAX] = NULL,
8996};
8997
8998struct bgp_table_stats
8999{
9000 struct bgp_table *table;
9001 unsigned long long counts[BGP_STATS_MAX];
9002};
9003
9004#if 0
9005#define TALLY_SIGFIG 100000
9006static unsigned long
9007ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9008{
9009 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9010 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9011 unsigned long ret = newtot / count;
9012
9013 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9014 return ret + 1;
9015 else
9016 return ret;
9017}
9018#endif
9019
9020static int
9021bgp_table_stats_walker (struct thread *t)
9022{
9023 struct bgp_node *rn;
9024 struct bgp_node *top;
9025 struct bgp_table_stats *ts = THREAD_ARG (t);
9026 unsigned int space = 0;
9027
Paul Jakma53d9f672006-10-15 23:41:16 +00009028 if (!(top = bgp_table_top (ts->table)))
9029 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009030
9031 switch (top->p.family)
9032 {
9033 case AF_INET:
9034 space = IPV4_MAX_BITLEN;
9035 break;
9036 case AF_INET6:
9037 space = IPV6_MAX_BITLEN;
9038 break;
9039 }
9040
9041 ts->counts[BGP_STATS_MAXBITLEN] = space;
9042
9043 for (rn = top; rn; rn = bgp_route_next (rn))
9044 {
9045 struct bgp_info *ri;
9046 struct bgp_node *prn = rn->parent;
9047 unsigned int rinum = 0;
9048
9049 if (rn == top)
9050 continue;
9051
9052 if (!rn->info)
9053 continue;
9054
9055 ts->counts[BGP_STATS_PREFIXES]++;
9056 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9057
9058#if 0
9059 ts->counts[BGP_STATS_AVGPLEN]
9060 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9061 ts->counts[BGP_STATS_AVGPLEN],
9062 rn->p.prefixlen);
9063#endif
9064
9065 /* check if the prefix is included by any other announcements */
9066 while (prn && !prn->info)
9067 prn = prn->parent;
9068
9069 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009070 {
9071 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9072 /* announced address space */
9073 if (space)
9074 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9075 }
Paul Jakma2815e612006-09-14 02:56:07 +00009076 else if (prn->info)
9077 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9078
Paul Jakma2815e612006-09-14 02:56:07 +00009079 for (ri = rn->info; ri; ri = ri->next)
9080 {
9081 rinum++;
9082 ts->counts[BGP_STATS_RIB]++;
9083
9084 if (ri->attr &&
9085 (CHECK_FLAG (ri->attr->flag,
9086 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9087 ts->counts[BGP_STATS_AGGREGATES]++;
9088
9089 /* as-path stats */
9090 if (ri->attr && ri->attr->aspath)
9091 {
9092 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9093 unsigned int size = aspath_size (ri->attr->aspath);
9094 as_t highest = aspath_highest (ri->attr->aspath);
9095
9096 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9097
9098 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9099 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9100
9101 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9102 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9103
9104 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9105 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9106#if 0
9107 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9108 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9109 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9110 hops);
9111 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9112 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9113 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9114 size);
9115#endif
9116 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9117 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9118 }
9119 }
9120 }
9121 return 0;
9122}
9123
9124static int
9125bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9126{
9127 struct bgp_table_stats ts;
9128 unsigned int i;
9129
9130 if (!bgp->rib[afi][safi])
9131 {
9132 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9133 return CMD_WARNING;
9134 }
9135
9136 memset (&ts, 0, sizeof (ts));
9137 ts.table = bgp->rib[afi][safi];
9138 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9139
9140 vty_out (vty, "BGP %s RIB statistics%s%s",
9141 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9142
9143 for (i = 0; i < BGP_STATS_MAX; i++)
9144 {
9145 if (!table_stats_strs[i])
9146 continue;
9147
9148 switch (i)
9149 {
9150#if 0
9151 case BGP_STATS_ASPATH_AVGHOPS:
9152 case BGP_STATS_ASPATH_AVGSIZE:
9153 case BGP_STATS_AVGPLEN:
9154 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9155 vty_out (vty, "%12.2f",
9156 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9157 break;
9158#endif
9159 case BGP_STATS_ASPATH_TOTHOPS:
9160 case BGP_STATS_ASPATH_TOTSIZE:
9161 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9162 vty_out (vty, "%12.2f",
9163 ts.counts[i] ?
9164 (float)ts.counts[i] /
9165 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9166 : 0);
9167 break;
9168 case BGP_STATS_TOTPLEN:
9169 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9170 vty_out (vty, "%12.2f",
9171 ts.counts[i] ?
9172 (float)ts.counts[i] /
9173 (float)ts.counts[BGP_STATS_PREFIXES]
9174 : 0);
9175 break;
9176 case BGP_STATS_SPACE:
9177 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9178 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9179 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9180 break;
9181 vty_out (vty, "%30s: ", "\% announced ");
9182 vty_out (vty, "%12.2f%s",
9183 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009184 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009185 VTY_NEWLINE);
9186 vty_out (vty, "%30s: ", "/8 equivalent ");
9187 vty_out (vty, "%12.2f%s",
9188 (float)ts.counts[BGP_STATS_SPACE] /
9189 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9190 VTY_NEWLINE);
9191 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9192 break;
9193 vty_out (vty, "%30s: ", "/24 equivalent ");
9194 vty_out (vty, "%12.2f",
9195 (float)ts.counts[BGP_STATS_SPACE] /
9196 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9197 break;
9198 default:
9199 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9200 vty_out (vty, "%12llu", ts.counts[i]);
9201 }
9202
9203 vty_out (vty, "%s", VTY_NEWLINE);
9204 }
9205 return CMD_SUCCESS;
9206}
9207
9208static int
9209bgp_table_stats_vty (struct vty *vty, const char *name,
9210 const char *afi_str, const char *safi_str)
9211{
9212 struct bgp *bgp;
9213 afi_t afi;
9214 safi_t safi;
9215
9216 if (name)
9217 bgp = bgp_lookup_by_name (name);
9218 else
9219 bgp = bgp_get_default ();
9220
9221 if (!bgp)
9222 {
9223 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9224 return CMD_WARNING;
9225 }
9226 if (strncmp (afi_str, "ipv", 3) == 0)
9227 {
9228 if (strncmp (afi_str, "ipv4", 4) == 0)
9229 afi = AFI_IP;
9230 else if (strncmp (afi_str, "ipv6", 4) == 0)
9231 afi = AFI_IP6;
9232 else
9233 {
9234 vty_out (vty, "%% Invalid address family %s%s",
9235 afi_str, VTY_NEWLINE);
9236 return CMD_WARNING;
9237 }
9238 if (strncmp (safi_str, "m", 1) == 0)
9239 safi = SAFI_MULTICAST;
9240 else if (strncmp (safi_str, "u", 1) == 0)
9241 safi = SAFI_UNICAST;
9242 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9243 safi = BGP_SAFI_VPNV4;
9244 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9245 safi = BGP_SAFI_VPNV6;
9246 else
9247 {
9248 vty_out (vty, "%% Invalid subsequent address family %s%s",
9249 safi_str, VTY_NEWLINE);
9250 return CMD_WARNING;
9251 }
9252 }
9253 else
9254 {
9255 vty_out (vty, "%% Invalid address family %s%s",
9256 afi_str, VTY_NEWLINE);
9257 return CMD_WARNING;
9258 }
9259
9260 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9261 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9262 {
9263 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9264 afi_str, safi_str, VTY_NEWLINE);
9265 return CMD_WARNING;
9266 }
9267 return bgp_table_stats (vty, bgp, afi, safi);
9268}
9269
9270DEFUN (show_bgp_statistics,
9271 show_bgp_statistics_cmd,
9272 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9273 SHOW_STR
9274 BGP_STR
9275 "Address family\n"
9276 "Address family\n"
9277 "Address Family modifier\n"
9278 "Address Family modifier\n"
9279 "BGP RIB advertisement statistics\n")
9280{
9281 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9282}
9283
9284ALIAS (show_bgp_statistics,
9285 show_bgp_statistics_vpnv4_cmd,
9286 "show bgp (ipv4) (vpnv4) statistics",
9287 SHOW_STR
9288 BGP_STR
9289 "Address family\n"
9290 "Address Family modifier\n"
9291 "BGP RIB advertisement statistics\n")
9292
9293DEFUN (show_bgp_statistics_view,
9294 show_bgp_statistics_view_cmd,
9295 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9296 SHOW_STR
9297 BGP_STR
9298 "BGP view\n"
9299 "Address family\n"
9300 "Address family\n"
9301 "Address Family modifier\n"
9302 "Address Family modifier\n"
9303 "BGP RIB advertisement statistics\n")
9304{
9305 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9306}
9307
9308ALIAS (show_bgp_statistics_view,
9309 show_bgp_statistics_view_vpnv4_cmd,
9310 "show bgp view WORD (ipv4) (vpnv4) statistics",
9311 SHOW_STR
9312 BGP_STR
9313 "BGP view\n"
9314 "Address family\n"
9315 "Address Family modifier\n"
9316 "BGP RIB advertisement statistics\n")
9317
Paul Jakmaff7924f2006-09-04 01:10:36 +00009318enum bgp_pcounts
9319{
9320 PCOUNT_ADJ_IN = 0,
9321 PCOUNT_DAMPED,
9322 PCOUNT_REMOVED,
9323 PCOUNT_HISTORY,
9324 PCOUNT_STALE,
9325 PCOUNT_VALID,
9326 PCOUNT_ALL,
9327 PCOUNT_COUNTED,
9328 PCOUNT_PFCNT, /* the figure we display to users */
9329 PCOUNT_MAX,
9330};
9331
9332static const char *pcount_strs[] =
9333{
9334 [PCOUNT_ADJ_IN] = "Adj-in",
9335 [PCOUNT_DAMPED] = "Damped",
9336 [PCOUNT_REMOVED] = "Removed",
9337 [PCOUNT_HISTORY] = "History",
9338 [PCOUNT_STALE] = "Stale",
9339 [PCOUNT_VALID] = "Valid",
9340 [PCOUNT_ALL] = "All RIB",
9341 [PCOUNT_COUNTED] = "PfxCt counted",
9342 [PCOUNT_PFCNT] = "Useable",
9343 [PCOUNT_MAX] = NULL,
9344};
9345
Paul Jakma2815e612006-09-14 02:56:07 +00009346struct peer_pcounts
9347{
9348 unsigned int count[PCOUNT_MAX];
9349 const struct peer *peer;
9350 const struct bgp_table *table;
9351};
9352
Paul Jakmaff7924f2006-09-04 01:10:36 +00009353static int
Paul Jakma2815e612006-09-14 02:56:07 +00009354bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009355{
9356 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009357 struct peer_pcounts *pc = THREAD_ARG (t);
9358 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009359
Paul Jakma2815e612006-09-14 02:56:07 +00009360 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009361 {
9362 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009363 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009364
9365 for (ain = rn->adj_in; ain; ain = ain->next)
9366 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009367 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009368
Paul Jakmaff7924f2006-09-04 01:10:36 +00009369 for (ri = rn->info; ri; ri = ri->next)
9370 {
9371 char buf[SU_ADDRSTRLEN];
9372
9373 if (ri->peer != peer)
9374 continue;
9375
Paul Jakma2815e612006-09-14 02:56:07 +00009376 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009377
9378 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009379 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009380 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009381 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009382 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009383 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009384 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009385 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009386 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009387 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009388 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009389 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009390
9391 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9392 {
Paul Jakma2815e612006-09-14 02:56:07 +00009393 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009394 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009395 plog_warn (peer->log,
9396 "%s [pcount] %s/%d is counted but flags 0x%x",
9397 peer->host,
9398 inet_ntop(rn->p.family, &rn->p.u.prefix,
9399 buf, SU_ADDRSTRLEN),
9400 rn->p.prefixlen,
9401 ri->flags);
9402 }
9403 else
9404 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009405 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009406 plog_warn (peer->log,
9407 "%s [pcount] %s/%d not counted but flags 0x%x",
9408 peer->host,
9409 inet_ntop(rn->p.family, &rn->p.u.prefix,
9410 buf, SU_ADDRSTRLEN),
9411 rn->p.prefixlen,
9412 ri->flags);
9413 }
9414 }
9415 }
Paul Jakma2815e612006-09-14 02:56:07 +00009416 return 0;
9417}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009418
Paul Jakma2815e612006-09-14 02:56:07 +00009419static int
9420bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9421{
9422 struct peer_pcounts pcounts = { .peer = peer };
9423 unsigned int i;
9424
9425 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9426 || !peer->bgp->rib[afi][safi])
9427 {
9428 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9429 return CMD_WARNING;
9430 }
9431
9432 memset (&pcounts, 0, sizeof(pcounts));
9433 pcounts.peer = peer;
9434 pcounts.table = peer->bgp->rib[afi][safi];
9435
9436 /* in-place call via thread subsystem so as to record execution time
9437 * stats for the thread-walk (i.e. ensure this can't be blamed on
9438 * on just vty_read()).
9439 */
9440 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9441
Paul Jakmaff7924f2006-09-04 01:10:36 +00009442 vty_out (vty, "Prefix counts for %s, %s%s",
9443 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9444 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9445 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9446 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9447
9448 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009449 vty_out (vty, "%20s: %-10d%s",
9450 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009451
Paul Jakma2815e612006-09-14 02:56:07 +00009452 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009453 {
9454 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9455 peer->host, VTY_NEWLINE);
9456 vty_out (vty, "Please report this bug, with the above command output%s",
9457 VTY_NEWLINE);
9458 }
9459
9460 return CMD_SUCCESS;
9461}
9462
9463DEFUN (show_ip_bgp_neighbor_prefix_counts,
9464 show_ip_bgp_neighbor_prefix_counts_cmd,
9465 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9466 SHOW_STR
9467 IP_STR
9468 BGP_STR
9469 "Detailed information on TCP and BGP neighbor connections\n"
9470 "Neighbor to display information about\n"
9471 "Neighbor to display information about\n"
9472 "Display detailed prefix count information\n")
9473{
9474 struct peer *peer;
9475
9476 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9477 if (! peer)
9478 return CMD_WARNING;
9479
9480 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9481}
9482
9483DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9484 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9485 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9486 SHOW_STR
9487 BGP_STR
9488 "Address family\n"
9489 "Detailed information on TCP and BGP neighbor connections\n"
9490 "Neighbor to display information about\n"
9491 "Neighbor to display information about\n"
9492 "Display detailed prefix count information\n")
9493{
9494 struct peer *peer;
9495
9496 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9497 if (! peer)
9498 return CMD_WARNING;
9499
9500 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9501}
9502
9503DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9504 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9505 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9506 SHOW_STR
9507 IP_STR
9508 BGP_STR
9509 "Address family\n"
9510 "Address Family modifier\n"
9511 "Address Family modifier\n"
9512 "Detailed information on TCP and BGP neighbor connections\n"
9513 "Neighbor to display information about\n"
9514 "Neighbor to display information about\n"
9515 "Display detailed prefix count information\n")
9516{
9517 struct peer *peer;
9518
9519 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9520 if (! peer)
9521 return CMD_WARNING;
9522
9523 if (strncmp (argv[0], "m", 1) == 0)
9524 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9525
9526 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9527}
9528
9529DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9530 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9531 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9532 SHOW_STR
9533 IP_STR
9534 BGP_STR
9535 "Address family\n"
9536 "Address Family modifier\n"
9537 "Address Family modifier\n"
9538 "Detailed information on TCP and BGP neighbor connections\n"
9539 "Neighbor to display information about\n"
9540 "Neighbor to display information about\n"
9541 "Display detailed prefix count information\n")
9542{
9543 struct peer *peer;
9544
9545 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9546 if (! peer)
9547 return CMD_WARNING;
9548
9549 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9550}
9551
9552
paul94f2b392005-06-28 12:44:16 +00009553static void
paul718e3742002-12-13 20:15:29 +00009554show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9555 int in)
9556{
9557 struct bgp_table *table;
9558 struct bgp_adj_in *ain;
9559 struct bgp_adj_out *adj;
9560 unsigned long output_count;
9561 struct bgp_node *rn;
9562 int header1 = 1;
9563 struct bgp *bgp;
9564 int header2 = 1;
9565
paulbb46e942003-10-24 19:02:03 +00009566 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009567
9568 if (! bgp)
9569 return;
9570
9571 table = bgp->rib[afi][safi];
9572
9573 output_count = 0;
9574
9575 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9576 PEER_STATUS_DEFAULT_ORIGINATE))
9577 {
9578 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 +00009579 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9580 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009581
9582 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9583 VTY_NEWLINE, VTY_NEWLINE);
9584 header1 = 0;
9585 }
9586
9587 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9588 if (in)
9589 {
9590 for (ain = rn->adj_in; ain; ain = ain->next)
9591 if (ain->peer == peer)
9592 {
9593 if (header1)
9594 {
9595 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 +00009596 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9597 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009598 header1 = 0;
9599 }
9600 if (header2)
9601 {
9602 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9603 header2 = 0;
9604 }
9605 if (ain->attr)
9606 {
9607 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9608 output_count++;
9609 }
9610 }
9611 }
9612 else
9613 {
9614 for (adj = rn->adj_out; adj; adj = adj->next)
9615 if (adj->peer == peer)
9616 {
9617 if (header1)
9618 {
9619 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 +00009620 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9621 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009622 header1 = 0;
9623 }
9624 if (header2)
9625 {
9626 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9627 header2 = 0;
9628 }
9629 if (adj->attr)
9630 {
9631 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9632 output_count++;
9633 }
9634 }
9635 }
9636
9637 if (output_count != 0)
9638 vty_out (vty, "%sTotal number of prefixes %ld%s",
9639 VTY_NEWLINE, output_count, VTY_NEWLINE);
9640}
9641
paul94f2b392005-06-28 12:44:16 +00009642static int
paulbb46e942003-10-24 19:02:03 +00009643peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9644{
paul718e3742002-12-13 20:15:29 +00009645 if (! peer || ! peer->afc[afi][safi])
9646 {
9647 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9648 return CMD_WARNING;
9649 }
9650
9651 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9652 {
9653 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9654 VTY_NEWLINE);
9655 return CMD_WARNING;
9656 }
9657
9658 show_adj_route (vty, peer, afi, safi, in);
9659
9660 return CMD_SUCCESS;
9661}
9662
9663DEFUN (show_ip_bgp_neighbor_advertised_route,
9664 show_ip_bgp_neighbor_advertised_route_cmd,
9665 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9666 SHOW_STR
9667 IP_STR
9668 BGP_STR
9669 "Detailed information on TCP and BGP neighbor connections\n"
9670 "Neighbor to display information about\n"
9671 "Neighbor to display information about\n"
9672 "Display the routes advertised to a BGP neighbor\n")
9673{
paulbb46e942003-10-24 19:02:03 +00009674 struct peer *peer;
9675
9676 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9677 if (! peer)
9678 return CMD_WARNING;
9679
9680 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009681}
9682
9683DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9684 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9685 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9686 SHOW_STR
9687 IP_STR
9688 BGP_STR
9689 "Address family\n"
9690 "Address Family modifier\n"
9691 "Address Family modifier\n"
9692 "Detailed information on TCP and BGP neighbor connections\n"
9693 "Neighbor to display information about\n"
9694 "Neighbor to display information about\n"
9695 "Display the routes advertised to a BGP neighbor\n")
9696{
paulbb46e942003-10-24 19:02:03 +00009697 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009698
paulbb46e942003-10-24 19:02:03 +00009699 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9700 if (! peer)
9701 return CMD_WARNING;
9702
9703 if (strncmp (argv[0], "m", 1) == 0)
9704 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9705
9706 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009707}
9708
9709#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009710DEFUN (show_bgp_view_neighbor_advertised_route,
9711 show_bgp_view_neighbor_advertised_route_cmd,
9712 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9713 SHOW_STR
9714 BGP_STR
9715 "BGP view\n"
9716 "View name\n"
9717 "Detailed information on TCP and BGP neighbor connections\n"
9718 "Neighbor to display information about\n"
9719 "Neighbor to display information about\n"
9720 "Display the routes advertised to a BGP neighbor\n")
9721{
9722 struct peer *peer;
9723
9724 if (argc == 2)
9725 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9726 else
9727 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9728
9729 if (! peer)
9730 return CMD_WARNING;
9731
9732 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9733}
9734
9735ALIAS (show_bgp_view_neighbor_advertised_route,
9736 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9737 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9738 SHOW_STR
9739 BGP_STR
9740 "BGP view\n"
9741 "View name\n"
9742 "Address family\n"
9743 "Detailed information on TCP and BGP neighbor connections\n"
9744 "Neighbor to display information about\n"
9745 "Neighbor to display information about\n"
9746 "Display the routes advertised to a BGP neighbor\n")
9747
9748DEFUN (show_bgp_view_neighbor_received_routes,
9749 show_bgp_view_neighbor_received_routes_cmd,
9750 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9751 SHOW_STR
9752 BGP_STR
9753 "BGP view\n"
9754 "View name\n"
9755 "Detailed information on TCP and BGP neighbor connections\n"
9756 "Neighbor to display information about\n"
9757 "Neighbor to display information about\n"
9758 "Display the received routes from neighbor\n")
9759{
9760 struct peer *peer;
9761
9762 if (argc == 2)
9763 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9764 else
9765 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9766
9767 if (! peer)
9768 return CMD_WARNING;
9769
9770 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9771}
9772
9773ALIAS (show_bgp_view_neighbor_received_routes,
9774 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9775 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9776 SHOW_STR
9777 BGP_STR
9778 "BGP view\n"
9779 "View name\n"
9780 "Address family\n"
9781 "Detailed information on TCP and BGP neighbor connections\n"
9782 "Neighbor to display information about\n"
9783 "Neighbor to display information about\n"
9784 "Display the received routes from neighbor\n")
9785
9786ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009787 show_bgp_neighbor_advertised_route_cmd,
9788 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9789 SHOW_STR
9790 BGP_STR
9791 "Detailed information on TCP and BGP neighbor connections\n"
9792 "Neighbor to display information about\n"
9793 "Neighbor to display information about\n"
9794 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009795
9796ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009797 show_bgp_ipv6_neighbor_advertised_route_cmd,
9798 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9799 SHOW_STR
9800 BGP_STR
9801 "Address family\n"
9802 "Detailed information on TCP and BGP neighbor connections\n"
9803 "Neighbor to display information about\n"
9804 "Neighbor to display information about\n"
9805 "Display the routes advertised to a BGP neighbor\n")
9806
9807/* old command */
paulbb46e942003-10-24 19:02:03 +00009808ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009809 ipv6_bgp_neighbor_advertised_route_cmd,
9810 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9811 SHOW_STR
9812 IPV6_STR
9813 BGP_STR
9814 "Detailed information on TCP and BGP neighbor connections\n"
9815 "Neighbor to display information about\n"
9816 "Neighbor to display information about\n"
9817 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009818
paul718e3742002-12-13 20:15:29 +00009819/* old command */
9820DEFUN (ipv6_mbgp_neighbor_advertised_route,
9821 ipv6_mbgp_neighbor_advertised_route_cmd,
9822 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9823 SHOW_STR
9824 IPV6_STR
9825 MBGP_STR
9826 "Detailed information on TCP and BGP neighbor connections\n"
9827 "Neighbor to display information about\n"
9828 "Neighbor to display information about\n"
9829 "Display the routes advertised to a BGP neighbor\n")
9830{
paulbb46e942003-10-24 19:02:03 +00009831 struct peer *peer;
9832
9833 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9834 if (! peer)
9835 return CMD_WARNING;
9836
9837 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009838}
9839#endif /* HAVE_IPV6 */
9840
9841DEFUN (show_ip_bgp_neighbor_received_routes,
9842 show_ip_bgp_neighbor_received_routes_cmd,
9843 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9844 SHOW_STR
9845 IP_STR
9846 BGP_STR
9847 "Detailed information on TCP and BGP neighbor connections\n"
9848 "Neighbor to display information about\n"
9849 "Neighbor to display information about\n"
9850 "Display the received routes from neighbor\n")
9851{
paulbb46e942003-10-24 19:02:03 +00009852 struct peer *peer;
9853
9854 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9855 if (! peer)
9856 return CMD_WARNING;
9857
9858 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009859}
9860
9861DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9862 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9863 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9864 SHOW_STR
9865 IP_STR
9866 BGP_STR
9867 "Address family\n"
9868 "Address Family modifier\n"
9869 "Address Family modifier\n"
9870 "Detailed information on TCP and BGP neighbor connections\n"
9871 "Neighbor to display information about\n"
9872 "Neighbor to display information about\n"
9873 "Display the received routes from neighbor\n")
9874{
paulbb46e942003-10-24 19:02:03 +00009875 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009876
paulbb46e942003-10-24 19:02:03 +00009877 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9878 if (! peer)
9879 return CMD_WARNING;
9880
9881 if (strncmp (argv[0], "m", 1) == 0)
9882 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9883
9884 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009885}
9886
9887DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9888 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9889 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9890 SHOW_STR
9891 IP_STR
9892 BGP_STR
9893 "Detailed information on TCP and BGP neighbor connections\n"
9894 "Neighbor to display information about\n"
9895 "Neighbor to display information about\n"
9896 "Display information received from a BGP neighbor\n"
9897 "Display the prefixlist filter\n")
9898{
9899 char name[BUFSIZ];
9900 union sockunion *su;
9901 struct peer *peer;
9902 int count;
9903
9904 su = sockunion_str2su (argv[0]);
9905 if (su == NULL)
9906 return CMD_WARNING;
9907
9908 peer = peer_lookup (NULL, su);
9909 if (! peer)
9910 return CMD_WARNING;
9911
9912 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9913 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9914 if (count)
9915 {
9916 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9917 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9918 }
9919
9920 return CMD_SUCCESS;
9921}
9922
9923DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9924 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9925 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9926 SHOW_STR
9927 IP_STR
9928 BGP_STR
9929 "Address family\n"
9930 "Address Family modifier\n"
9931 "Address Family modifier\n"
9932 "Detailed information on TCP and BGP neighbor connections\n"
9933 "Neighbor to display information about\n"
9934 "Neighbor to display information about\n"
9935 "Display information received from a BGP neighbor\n"
9936 "Display the prefixlist filter\n")
9937{
9938 char name[BUFSIZ];
9939 union sockunion *su;
9940 struct peer *peer;
9941 int count;
9942
9943 su = sockunion_str2su (argv[1]);
9944 if (su == NULL)
9945 return CMD_WARNING;
9946
9947 peer = peer_lookup (NULL, su);
9948 if (! peer)
9949 return CMD_WARNING;
9950
9951 if (strncmp (argv[0], "m", 1) == 0)
9952 {
9953 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9954 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9955 if (count)
9956 {
9957 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9958 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9959 }
9960 }
9961 else
9962 {
9963 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9964 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9965 if (count)
9966 {
9967 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9968 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9969 }
9970 }
9971
9972 return CMD_SUCCESS;
9973}
9974
9975
9976#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009977ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009978 show_bgp_neighbor_received_routes_cmd,
9979 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9980 SHOW_STR
9981 BGP_STR
9982 "Detailed information on TCP and BGP neighbor connections\n"
9983 "Neighbor to display information about\n"
9984 "Neighbor to display information about\n"
9985 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009986
paulbb46e942003-10-24 19:02:03 +00009987ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009988 show_bgp_ipv6_neighbor_received_routes_cmd,
9989 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9990 SHOW_STR
9991 BGP_STR
9992 "Address family\n"
9993 "Detailed information on TCP and BGP neighbor connections\n"
9994 "Neighbor to display information about\n"
9995 "Neighbor to display information about\n"
9996 "Display the received routes from neighbor\n")
9997
9998DEFUN (show_bgp_neighbor_received_prefix_filter,
9999 show_bgp_neighbor_received_prefix_filter_cmd,
10000 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10001 SHOW_STR
10002 BGP_STR
10003 "Detailed information on TCP and BGP neighbor connections\n"
10004 "Neighbor to display information about\n"
10005 "Neighbor to display information about\n"
10006 "Display information received from a BGP neighbor\n"
10007 "Display the prefixlist filter\n")
10008{
10009 char name[BUFSIZ];
10010 union sockunion *su;
10011 struct peer *peer;
10012 int count;
10013
10014 su = sockunion_str2su (argv[0]);
10015 if (su == NULL)
10016 return CMD_WARNING;
10017
10018 peer = peer_lookup (NULL, su);
10019 if (! peer)
10020 return CMD_WARNING;
10021
10022 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10023 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10024 if (count)
10025 {
10026 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10027 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10028 }
10029
10030 return CMD_SUCCESS;
10031}
10032
10033ALIAS (show_bgp_neighbor_received_prefix_filter,
10034 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10035 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10036 SHOW_STR
10037 BGP_STR
10038 "Address family\n"
10039 "Detailed information on TCP and BGP neighbor connections\n"
10040 "Neighbor to display information about\n"
10041 "Neighbor to display information about\n"
10042 "Display information received from a BGP neighbor\n"
10043 "Display the prefixlist filter\n")
10044
10045/* old command */
paulbb46e942003-10-24 19:02:03 +000010046ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010047 ipv6_bgp_neighbor_received_routes_cmd,
10048 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10049 SHOW_STR
10050 IPV6_STR
10051 BGP_STR
10052 "Detailed information on TCP and BGP neighbor connections\n"
10053 "Neighbor to display information about\n"
10054 "Neighbor to display information about\n"
10055 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010056
10057/* old command */
10058DEFUN (ipv6_mbgp_neighbor_received_routes,
10059 ipv6_mbgp_neighbor_received_routes_cmd,
10060 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10061 SHOW_STR
10062 IPV6_STR
10063 MBGP_STR
10064 "Detailed information on TCP and BGP neighbor connections\n"
10065 "Neighbor to display information about\n"
10066 "Neighbor to display information about\n"
10067 "Display the received routes from neighbor\n")
10068{
paulbb46e942003-10-24 19:02:03 +000010069 struct peer *peer;
10070
10071 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10072 if (! peer)
10073 return CMD_WARNING;
10074
10075 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010076}
paulbb46e942003-10-24 19:02:03 +000010077
10078DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10079 show_bgp_view_neighbor_received_prefix_filter_cmd,
10080 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10081 SHOW_STR
10082 BGP_STR
10083 "BGP view\n"
10084 "View name\n"
10085 "Detailed information on TCP and BGP neighbor connections\n"
10086 "Neighbor to display information about\n"
10087 "Neighbor to display information about\n"
10088 "Display information received from a BGP neighbor\n"
10089 "Display the prefixlist filter\n")
10090{
10091 char name[BUFSIZ];
10092 union sockunion *su;
10093 struct peer *peer;
10094 struct bgp *bgp;
10095 int count;
10096
10097 /* BGP structure lookup. */
10098 bgp = bgp_lookup_by_name (argv[0]);
10099 if (bgp == NULL)
10100 {
10101 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10102 return CMD_WARNING;
10103 }
10104
10105 su = sockunion_str2su (argv[1]);
10106 if (su == NULL)
10107 return CMD_WARNING;
10108
10109 peer = peer_lookup (bgp, su);
10110 if (! peer)
10111 return CMD_WARNING;
10112
10113 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10114 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10115 if (count)
10116 {
10117 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10118 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10119 }
10120
10121 return CMD_SUCCESS;
10122}
10123
10124ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10125 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10126 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10127 SHOW_STR
10128 BGP_STR
10129 "BGP view\n"
10130 "View name\n"
10131 "Address family\n"
10132 "Detailed information on TCP and BGP neighbor connections\n"
10133 "Neighbor to display information about\n"
10134 "Neighbor to display information about\n"
10135 "Display information received from a BGP neighbor\n"
10136 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010137#endif /* HAVE_IPV6 */
10138
paul94f2b392005-06-28 12:44:16 +000010139static int
paulbb46e942003-10-24 19:02:03 +000010140bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010141 safi_t safi, enum bgp_show_type type)
10142{
paul718e3742002-12-13 20:15:29 +000010143 if (! peer || ! peer->afc[afi][safi])
10144 {
10145 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010146 return CMD_WARNING;
10147 }
10148
ajs5a646652004-11-05 01:25:55 +000010149 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010150}
10151
10152DEFUN (show_ip_bgp_neighbor_routes,
10153 show_ip_bgp_neighbor_routes_cmd,
10154 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10155 SHOW_STR
10156 IP_STR
10157 BGP_STR
10158 "Detailed information on TCP and BGP neighbor connections\n"
10159 "Neighbor to display information about\n"
10160 "Neighbor to display information about\n"
10161 "Display routes learned from neighbor\n")
10162{
paulbb46e942003-10-24 19:02:03 +000010163 struct peer *peer;
10164
10165 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10166 if (! peer)
10167 return CMD_WARNING;
10168
10169 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010170 bgp_show_type_neighbor);
10171}
10172
10173DEFUN (show_ip_bgp_neighbor_flap,
10174 show_ip_bgp_neighbor_flap_cmd,
10175 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10176 SHOW_STR
10177 IP_STR
10178 BGP_STR
10179 "Detailed information on TCP and BGP neighbor connections\n"
10180 "Neighbor to display information about\n"
10181 "Neighbor to display information about\n"
10182 "Display flap statistics of the routes learned from neighbor\n")
10183{
paulbb46e942003-10-24 19:02:03 +000010184 struct peer *peer;
10185
10186 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10187 if (! peer)
10188 return CMD_WARNING;
10189
10190 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010191 bgp_show_type_flap_neighbor);
10192}
10193
10194DEFUN (show_ip_bgp_neighbor_damp,
10195 show_ip_bgp_neighbor_damp_cmd,
10196 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10197 SHOW_STR
10198 IP_STR
10199 BGP_STR
10200 "Detailed information on TCP and BGP neighbor connections\n"
10201 "Neighbor to display information about\n"
10202 "Neighbor to display information about\n"
10203 "Display the dampened routes received from neighbor\n")
10204{
paulbb46e942003-10-24 19:02:03 +000010205 struct peer *peer;
10206
10207 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10208 if (! peer)
10209 return CMD_WARNING;
10210
10211 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010212 bgp_show_type_damp_neighbor);
10213}
10214
10215DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10216 show_ip_bgp_ipv4_neighbor_routes_cmd,
10217 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10218 SHOW_STR
10219 IP_STR
10220 BGP_STR
10221 "Address family\n"
10222 "Address Family modifier\n"
10223 "Address Family modifier\n"
10224 "Detailed information on TCP and BGP neighbor connections\n"
10225 "Neighbor to display information about\n"
10226 "Neighbor to display information about\n"
10227 "Display routes learned from neighbor\n")
10228{
paulbb46e942003-10-24 19:02:03 +000010229 struct peer *peer;
10230
10231 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10232 if (! peer)
10233 return CMD_WARNING;
10234
paul718e3742002-12-13 20:15:29 +000010235 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010236 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010237 bgp_show_type_neighbor);
10238
paulbb46e942003-10-24 19:02:03 +000010239 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010240 bgp_show_type_neighbor);
10241}
paulbb46e942003-10-24 19:02:03 +000010242
paulfee0f4c2004-09-13 05:12:46 +000010243DEFUN (show_ip_bgp_view_rsclient,
10244 show_ip_bgp_view_rsclient_cmd,
10245 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10246 SHOW_STR
10247 IP_STR
10248 BGP_STR
10249 "BGP view\n"
10250 "BGP view name\n"
10251 "Information about Route Server Client\n"
10252 NEIGHBOR_ADDR_STR)
10253{
10254 struct bgp_table *table;
10255 struct peer *peer;
10256
10257 if (argc == 2)
10258 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10259 else
10260 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10261
10262 if (! peer)
10263 return CMD_WARNING;
10264
10265 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10266 {
10267 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10268 VTY_NEWLINE);
10269 return CMD_WARNING;
10270 }
10271
10272 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10273 PEER_FLAG_RSERVER_CLIENT))
10274 {
10275 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10276 VTY_NEWLINE);
10277 return CMD_WARNING;
10278 }
10279
10280 table = peer->rib[AFI_IP][SAFI_UNICAST];
10281
ajs5a646652004-11-05 01:25:55 +000010282 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010283}
10284
10285ALIAS (show_ip_bgp_view_rsclient,
10286 show_ip_bgp_rsclient_cmd,
10287 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10288 SHOW_STR
10289 IP_STR
10290 BGP_STR
10291 "Information about Route Server Client\n"
10292 NEIGHBOR_ADDR_STR)
10293
10294DEFUN (show_ip_bgp_view_rsclient_route,
10295 show_ip_bgp_view_rsclient_route_cmd,
10296 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10297 SHOW_STR
10298 IP_STR
10299 BGP_STR
10300 "BGP view\n"
10301 "BGP view name\n"
10302 "Information about Route Server Client\n"
10303 NEIGHBOR_ADDR_STR
10304 "Network in the BGP routing table to display\n")
10305{
10306 struct bgp *bgp;
10307 struct peer *peer;
10308
10309 /* BGP structure lookup. */
10310 if (argc == 3)
10311 {
10312 bgp = bgp_lookup_by_name (argv[0]);
10313 if (bgp == NULL)
10314 {
10315 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10316 return CMD_WARNING;
10317 }
10318 }
10319 else
10320 {
10321 bgp = bgp_get_default ();
10322 if (bgp == NULL)
10323 {
10324 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10325 return CMD_WARNING;
10326 }
10327 }
10328
10329 if (argc == 3)
10330 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10331 else
10332 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10333
10334 if (! peer)
10335 return CMD_WARNING;
10336
10337 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10338 {
10339 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10340 VTY_NEWLINE);
10341 return CMD_WARNING;
10342}
10343
10344 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10345 PEER_FLAG_RSERVER_CLIENT))
10346 {
10347 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10348 VTY_NEWLINE);
10349 return CMD_WARNING;
10350 }
10351
10352 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10353 (argc == 3) ? argv[2] : argv[1],
10354 AFI_IP, SAFI_UNICAST, NULL, 0);
10355}
10356
10357ALIAS (show_ip_bgp_view_rsclient_route,
10358 show_ip_bgp_rsclient_route_cmd,
10359 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10360 SHOW_STR
10361 IP_STR
10362 BGP_STR
10363 "Information about Route Server Client\n"
10364 NEIGHBOR_ADDR_STR
10365 "Network in the BGP routing table to display\n")
10366
10367DEFUN (show_ip_bgp_view_rsclient_prefix,
10368 show_ip_bgp_view_rsclient_prefix_cmd,
10369 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10370 SHOW_STR
10371 IP_STR
10372 BGP_STR
10373 "BGP view\n"
10374 "BGP view name\n"
10375 "Information about Route Server Client\n"
10376 NEIGHBOR_ADDR_STR
10377 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10378{
10379 struct bgp *bgp;
10380 struct peer *peer;
10381
10382 /* BGP structure lookup. */
10383 if (argc == 3)
10384 {
10385 bgp = bgp_lookup_by_name (argv[0]);
10386 if (bgp == NULL)
10387 {
10388 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10389 return CMD_WARNING;
10390 }
10391 }
10392 else
10393 {
10394 bgp = bgp_get_default ();
10395 if (bgp == NULL)
10396 {
10397 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10398 return CMD_WARNING;
10399 }
10400 }
10401
10402 if (argc == 3)
10403 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10404 else
10405 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10406
10407 if (! peer)
10408 return CMD_WARNING;
10409
10410 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10411 {
10412 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10413 VTY_NEWLINE);
10414 return CMD_WARNING;
10415}
10416
10417 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10418 PEER_FLAG_RSERVER_CLIENT))
10419{
10420 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10421 VTY_NEWLINE);
10422 return CMD_WARNING;
10423 }
10424
10425 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10426 (argc == 3) ? argv[2] : argv[1],
10427 AFI_IP, SAFI_UNICAST, NULL, 1);
10428}
10429
10430ALIAS (show_ip_bgp_view_rsclient_prefix,
10431 show_ip_bgp_rsclient_prefix_cmd,
10432 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10433 SHOW_STR
10434 IP_STR
10435 BGP_STR
10436 "Information about Route Server Client\n"
10437 NEIGHBOR_ADDR_STR
10438 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10439
10440
paul718e3742002-12-13 20:15:29 +000010441#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010442DEFUN (show_bgp_view_neighbor_routes,
10443 show_bgp_view_neighbor_routes_cmd,
10444 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10445 SHOW_STR
10446 BGP_STR
10447 "BGP view\n"
10448 "BGP view name\n"
10449 "Detailed information on TCP and BGP neighbor connections\n"
10450 "Neighbor to display information about\n"
10451 "Neighbor to display information about\n"
10452 "Display routes learned from neighbor\n")
10453{
10454 struct peer *peer;
10455
10456 if (argc == 2)
10457 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10458 else
10459 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10460
10461 if (! peer)
10462 return CMD_WARNING;
10463
10464 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10465 bgp_show_type_neighbor);
10466}
10467
10468ALIAS (show_bgp_view_neighbor_routes,
10469 show_bgp_view_ipv6_neighbor_routes_cmd,
10470 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10471 SHOW_STR
10472 BGP_STR
10473 "BGP view\n"
10474 "BGP view name\n"
10475 "Address family\n"
10476 "Detailed information on TCP and BGP neighbor connections\n"
10477 "Neighbor to display information about\n"
10478 "Neighbor to display information about\n"
10479 "Display routes learned from neighbor\n")
10480
10481DEFUN (show_bgp_view_neighbor_damp,
10482 show_bgp_view_neighbor_damp_cmd,
10483 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10484 SHOW_STR
10485 BGP_STR
10486 "BGP view\n"
10487 "BGP view name\n"
10488 "Detailed information on TCP and BGP neighbor connections\n"
10489 "Neighbor to display information about\n"
10490 "Neighbor to display information about\n"
10491 "Display the dampened routes received from neighbor\n")
10492{
10493 struct peer *peer;
10494
10495 if (argc == 2)
10496 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10497 else
10498 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10499
10500 if (! peer)
10501 return CMD_WARNING;
10502
10503 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10504 bgp_show_type_damp_neighbor);
10505}
10506
10507ALIAS (show_bgp_view_neighbor_damp,
10508 show_bgp_view_ipv6_neighbor_damp_cmd,
10509 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10510 SHOW_STR
10511 BGP_STR
10512 "BGP view\n"
10513 "BGP view name\n"
10514 "Address family\n"
10515 "Detailed information on TCP and BGP neighbor connections\n"
10516 "Neighbor to display information about\n"
10517 "Neighbor to display information about\n"
10518 "Display the dampened routes received from neighbor\n")
10519
10520DEFUN (show_bgp_view_neighbor_flap,
10521 show_bgp_view_neighbor_flap_cmd,
10522 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10523 SHOW_STR
10524 BGP_STR
10525 "BGP view\n"
10526 "BGP view name\n"
10527 "Detailed information on TCP and BGP neighbor connections\n"
10528 "Neighbor to display information about\n"
10529 "Neighbor to display information about\n"
10530 "Display flap statistics of the routes learned from neighbor\n")
10531{
10532 struct peer *peer;
10533
10534 if (argc == 2)
10535 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10536 else
10537 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10538
10539 if (! peer)
10540 return CMD_WARNING;
10541
10542 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10543 bgp_show_type_flap_neighbor);
10544}
10545
10546ALIAS (show_bgp_view_neighbor_flap,
10547 show_bgp_view_ipv6_neighbor_flap_cmd,
10548 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10549 SHOW_STR
10550 BGP_STR
10551 "BGP view\n"
10552 "BGP view name\n"
10553 "Address family\n"
10554 "Detailed information on TCP and BGP neighbor connections\n"
10555 "Neighbor to display information about\n"
10556 "Neighbor to display information about\n"
10557 "Display flap statistics of the routes learned from neighbor\n")
10558
10559ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010560 show_bgp_neighbor_routes_cmd,
10561 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10562 SHOW_STR
10563 BGP_STR
10564 "Detailed information on TCP and BGP neighbor connections\n"
10565 "Neighbor to display information about\n"
10566 "Neighbor to display information about\n"
10567 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010568
paulbb46e942003-10-24 19:02:03 +000010569
10570ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010571 show_bgp_ipv6_neighbor_routes_cmd,
10572 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10573 SHOW_STR
10574 BGP_STR
10575 "Address family\n"
10576 "Detailed information on TCP and BGP neighbor connections\n"
10577 "Neighbor to display information about\n"
10578 "Neighbor to display information about\n"
10579 "Display routes learned from neighbor\n")
10580
10581/* old command */
paulbb46e942003-10-24 19:02:03 +000010582ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010583 ipv6_bgp_neighbor_routes_cmd,
10584 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10585 SHOW_STR
10586 IPV6_STR
10587 BGP_STR
10588 "Detailed information on TCP and BGP neighbor connections\n"
10589 "Neighbor to display information about\n"
10590 "Neighbor to display information about\n"
10591 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010592
10593/* old command */
10594DEFUN (ipv6_mbgp_neighbor_routes,
10595 ipv6_mbgp_neighbor_routes_cmd,
10596 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10597 SHOW_STR
10598 IPV6_STR
10599 MBGP_STR
10600 "Detailed information on TCP and BGP neighbor connections\n"
10601 "Neighbor to display information about\n"
10602 "Neighbor to display information about\n"
10603 "Display routes learned from neighbor\n")
10604{
paulbb46e942003-10-24 19:02:03 +000010605 struct peer *peer;
10606
10607 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10608 if (! peer)
10609 return CMD_WARNING;
10610
10611 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010612 bgp_show_type_neighbor);
10613}
paulbb46e942003-10-24 19:02:03 +000010614
10615ALIAS (show_bgp_view_neighbor_flap,
10616 show_bgp_neighbor_flap_cmd,
10617 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10618 SHOW_STR
10619 BGP_STR
10620 "Detailed information on TCP and BGP neighbor connections\n"
10621 "Neighbor to display information about\n"
10622 "Neighbor to display information about\n"
10623 "Display flap statistics of the routes learned from neighbor\n")
10624
10625ALIAS (show_bgp_view_neighbor_flap,
10626 show_bgp_ipv6_neighbor_flap_cmd,
10627 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10628 SHOW_STR
10629 BGP_STR
10630 "Address family\n"
10631 "Detailed information on TCP and BGP neighbor connections\n"
10632 "Neighbor to display information about\n"
10633 "Neighbor to display information about\n"
10634 "Display flap statistics of the routes learned from neighbor\n")
10635
10636ALIAS (show_bgp_view_neighbor_damp,
10637 show_bgp_neighbor_damp_cmd,
10638 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10639 SHOW_STR
10640 BGP_STR
10641 "Detailed information on TCP and BGP neighbor connections\n"
10642 "Neighbor to display information about\n"
10643 "Neighbor to display information about\n"
10644 "Display the dampened routes received from neighbor\n")
10645
10646ALIAS (show_bgp_view_neighbor_damp,
10647 show_bgp_ipv6_neighbor_damp_cmd,
10648 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10649 SHOW_STR
10650 BGP_STR
10651 "Address family\n"
10652 "Detailed information on TCP and BGP neighbor connections\n"
10653 "Neighbor to display information about\n"
10654 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010655 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010656
10657DEFUN (show_bgp_view_rsclient,
10658 show_bgp_view_rsclient_cmd,
10659 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10660 SHOW_STR
10661 BGP_STR
10662 "BGP view\n"
10663 "BGP view name\n"
10664 "Information about Route Server Client\n"
10665 NEIGHBOR_ADDR_STR)
10666{
10667 struct bgp_table *table;
10668 struct peer *peer;
10669
10670 if (argc == 2)
10671 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10672 else
10673 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10674
10675 if (! peer)
10676 return CMD_WARNING;
10677
10678 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10679 {
10680 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10681 VTY_NEWLINE);
10682 return CMD_WARNING;
10683 }
10684
10685 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10686 PEER_FLAG_RSERVER_CLIENT))
10687 {
10688 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10689 VTY_NEWLINE);
10690 return CMD_WARNING;
10691 }
10692
10693 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10694
ajs5a646652004-11-05 01:25:55 +000010695 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010696}
10697
10698ALIAS (show_bgp_view_rsclient,
10699 show_bgp_rsclient_cmd,
10700 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10701 SHOW_STR
10702 BGP_STR
10703 "Information about Route Server Client\n"
10704 NEIGHBOR_ADDR_STR)
10705
10706DEFUN (show_bgp_view_rsclient_route,
10707 show_bgp_view_rsclient_route_cmd,
10708 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10709 SHOW_STR
10710 BGP_STR
10711 "BGP view\n"
10712 "BGP view name\n"
10713 "Information about Route Server Client\n"
10714 NEIGHBOR_ADDR_STR
10715 "Network in the BGP routing table to display\n")
10716{
10717 struct bgp *bgp;
10718 struct peer *peer;
10719
10720 /* BGP structure lookup. */
10721 if (argc == 3)
10722 {
10723 bgp = bgp_lookup_by_name (argv[0]);
10724 if (bgp == NULL)
10725 {
10726 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10727 return CMD_WARNING;
10728 }
10729 }
10730 else
10731 {
10732 bgp = bgp_get_default ();
10733 if (bgp == NULL)
10734 {
10735 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10736 return CMD_WARNING;
10737 }
10738 }
10739
10740 if (argc == 3)
10741 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10742 else
10743 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10744
10745 if (! peer)
10746 return CMD_WARNING;
10747
10748 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10749 {
10750 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10751 VTY_NEWLINE);
10752 return CMD_WARNING;
10753 }
10754
10755 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10756 PEER_FLAG_RSERVER_CLIENT))
10757 {
10758 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10759 VTY_NEWLINE);
10760 return CMD_WARNING;
10761 }
10762
10763 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10764 (argc == 3) ? argv[2] : argv[1],
10765 AFI_IP6, SAFI_UNICAST, NULL, 0);
10766}
10767
10768ALIAS (show_bgp_view_rsclient_route,
10769 show_bgp_rsclient_route_cmd,
10770 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10771 SHOW_STR
10772 BGP_STR
10773 "Information about Route Server Client\n"
10774 NEIGHBOR_ADDR_STR
10775 "Network in the BGP routing table to display\n")
10776
10777DEFUN (show_bgp_view_rsclient_prefix,
10778 show_bgp_view_rsclient_prefix_cmd,
10779 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10780 SHOW_STR
10781 BGP_STR
10782 "BGP view\n"
10783 "BGP view name\n"
10784 "Information about Route Server Client\n"
10785 NEIGHBOR_ADDR_STR
10786 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10787{
10788 struct bgp *bgp;
10789 struct peer *peer;
10790
10791 /* BGP structure lookup. */
10792 if (argc == 3)
10793 {
10794 bgp = bgp_lookup_by_name (argv[0]);
10795 if (bgp == NULL)
10796 {
10797 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10798 return CMD_WARNING;
10799 }
10800 }
10801 else
10802 {
10803 bgp = bgp_get_default ();
10804 if (bgp == NULL)
10805 {
10806 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10807 return CMD_WARNING;
10808 }
10809 }
10810
10811 if (argc == 3)
10812 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10813 else
10814 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10815
10816 if (! peer)
10817 return CMD_WARNING;
10818
10819 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10820 {
10821 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10822 VTY_NEWLINE);
10823 return CMD_WARNING;
10824 }
10825
10826 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10827 PEER_FLAG_RSERVER_CLIENT))
10828 {
10829 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10830 VTY_NEWLINE);
10831 return CMD_WARNING;
10832 }
10833
10834 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10835 (argc == 3) ? argv[2] : argv[1],
10836 AFI_IP6, SAFI_UNICAST, NULL, 1);
10837}
10838
10839ALIAS (show_bgp_view_rsclient_prefix,
10840 show_bgp_rsclient_prefix_cmd,
10841 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10842 SHOW_STR
10843 BGP_STR
10844 "Information about Route Server Client\n"
10845 NEIGHBOR_ADDR_STR
10846 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10847
paul718e3742002-12-13 20:15:29 +000010848#endif /* HAVE_IPV6 */
10849
10850struct bgp_table *bgp_distance_table;
10851
10852struct bgp_distance
10853{
10854 /* Distance value for the IP source prefix. */
10855 u_char distance;
10856
10857 /* Name of the access-list to be matched. */
10858 char *access_list;
10859};
10860
paul94f2b392005-06-28 12:44:16 +000010861static struct bgp_distance *
paul718e3742002-12-13 20:15:29 +000010862bgp_distance_new ()
10863{
10864 struct bgp_distance *new;
10865 new = XMALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
10866 memset (new, 0, sizeof (struct bgp_distance));
10867 return new;
10868}
10869
paul94f2b392005-06-28 12:44:16 +000010870static void
paul718e3742002-12-13 20:15:29 +000010871bgp_distance_free (struct bgp_distance *bdistance)
10872{
10873 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10874}
10875
paul94f2b392005-06-28 12:44:16 +000010876static int
paulfd79ac92004-10-13 05:06:08 +000010877bgp_distance_set (struct vty *vty, const char *distance_str,
10878 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010879{
10880 int ret;
10881 struct prefix_ipv4 p;
10882 u_char distance;
10883 struct bgp_node *rn;
10884 struct bgp_distance *bdistance;
10885
10886 ret = str2prefix_ipv4 (ip_str, &p);
10887 if (ret == 0)
10888 {
10889 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10890 return CMD_WARNING;
10891 }
10892
10893 distance = atoi (distance_str);
10894
10895 /* Get BGP distance node. */
10896 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10897 if (rn->info)
10898 {
10899 bdistance = rn->info;
10900 bgp_unlock_node (rn);
10901 }
10902 else
10903 {
10904 bdistance = bgp_distance_new ();
10905 rn->info = bdistance;
10906 }
10907
10908 /* Set distance value. */
10909 bdistance->distance = distance;
10910
10911 /* Reset access-list configuration. */
10912 if (bdistance->access_list)
10913 {
10914 free (bdistance->access_list);
10915 bdistance->access_list = NULL;
10916 }
10917 if (access_list_str)
10918 bdistance->access_list = strdup (access_list_str);
10919
10920 return CMD_SUCCESS;
10921}
10922
paul94f2b392005-06-28 12:44:16 +000010923static int
paulfd79ac92004-10-13 05:06:08 +000010924bgp_distance_unset (struct vty *vty, const char *distance_str,
10925 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010926{
10927 int ret;
10928 struct prefix_ipv4 p;
10929 u_char distance;
10930 struct bgp_node *rn;
10931 struct bgp_distance *bdistance;
10932
10933 ret = str2prefix_ipv4 (ip_str, &p);
10934 if (ret == 0)
10935 {
10936 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10937 return CMD_WARNING;
10938 }
10939
10940 distance = atoi (distance_str);
10941
10942 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10943 if (! rn)
10944 {
10945 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10946 return CMD_WARNING;
10947 }
10948
10949 bdistance = rn->info;
10950
10951 if (bdistance->access_list)
10952 free (bdistance->access_list);
10953 bgp_distance_free (bdistance);
10954
10955 rn->info = NULL;
10956 bgp_unlock_node (rn);
10957 bgp_unlock_node (rn);
10958
10959 return CMD_SUCCESS;
10960}
10961
paul94f2b392005-06-28 12:44:16 +000010962static void
paul718e3742002-12-13 20:15:29 +000010963bgp_distance_reset ()
10964{
10965 struct bgp_node *rn;
10966 struct bgp_distance *bdistance;
10967
10968 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
10969 if ((bdistance = rn->info) != NULL)
10970 {
10971 if (bdistance->access_list)
10972 free (bdistance->access_list);
10973 bgp_distance_free (bdistance);
10974 rn->info = NULL;
10975 bgp_unlock_node (rn);
10976 }
10977}
10978
10979/* Apply BGP information to distance method. */
10980u_char
10981bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10982{
10983 struct bgp_node *rn;
10984 struct prefix_ipv4 q;
10985 struct peer *peer;
10986 struct bgp_distance *bdistance;
10987 struct access_list *alist;
10988 struct bgp_static *bgp_static;
10989
10990 if (! bgp)
10991 return 0;
10992
10993 if (p->family != AF_INET)
10994 return 0;
10995
10996 peer = rinfo->peer;
10997
10998 if (peer->su.sa.sa_family != AF_INET)
10999 return 0;
11000
11001 memset (&q, 0, sizeof (struct prefix_ipv4));
11002 q.family = AF_INET;
11003 q.prefix = peer->su.sin.sin_addr;
11004 q.prefixlen = IPV4_MAX_BITLEN;
11005
11006 /* Check source address. */
11007 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11008 if (rn)
11009 {
11010 bdistance = rn->info;
11011 bgp_unlock_node (rn);
11012
11013 if (bdistance->access_list)
11014 {
11015 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11016 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11017 return bdistance->distance;
11018 }
11019 else
11020 return bdistance->distance;
11021 }
11022
11023 /* Backdoor check. */
11024 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11025 if (rn)
11026 {
11027 bgp_static = rn->info;
11028 bgp_unlock_node (rn);
11029
11030 if (bgp_static->backdoor)
11031 {
11032 if (bgp->distance_local)
11033 return bgp->distance_local;
11034 else
11035 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11036 }
11037 }
11038
11039 if (peer_sort (peer) == BGP_PEER_EBGP)
11040 {
11041 if (bgp->distance_ebgp)
11042 return bgp->distance_ebgp;
11043 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11044 }
11045 else
11046 {
11047 if (bgp->distance_ibgp)
11048 return bgp->distance_ibgp;
11049 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11050 }
11051}
11052
11053DEFUN (bgp_distance,
11054 bgp_distance_cmd,
11055 "distance bgp <1-255> <1-255> <1-255>",
11056 "Define an administrative distance\n"
11057 "BGP distance\n"
11058 "Distance for routes external to the AS\n"
11059 "Distance for routes internal to the AS\n"
11060 "Distance for local routes\n")
11061{
11062 struct bgp *bgp;
11063
11064 bgp = vty->index;
11065
11066 bgp->distance_ebgp = atoi (argv[0]);
11067 bgp->distance_ibgp = atoi (argv[1]);
11068 bgp->distance_local = atoi (argv[2]);
11069 return CMD_SUCCESS;
11070}
11071
11072DEFUN (no_bgp_distance,
11073 no_bgp_distance_cmd,
11074 "no distance bgp <1-255> <1-255> <1-255>",
11075 NO_STR
11076 "Define an administrative distance\n"
11077 "BGP distance\n"
11078 "Distance for routes external to the AS\n"
11079 "Distance for routes internal to the AS\n"
11080 "Distance for local routes\n")
11081{
11082 struct bgp *bgp;
11083
11084 bgp = vty->index;
11085
11086 bgp->distance_ebgp= 0;
11087 bgp->distance_ibgp = 0;
11088 bgp->distance_local = 0;
11089 return CMD_SUCCESS;
11090}
11091
11092ALIAS (no_bgp_distance,
11093 no_bgp_distance2_cmd,
11094 "no distance bgp",
11095 NO_STR
11096 "Define an administrative distance\n"
11097 "BGP distance\n")
11098
11099DEFUN (bgp_distance_source,
11100 bgp_distance_source_cmd,
11101 "distance <1-255> A.B.C.D/M",
11102 "Define an administrative distance\n"
11103 "Administrative distance\n"
11104 "IP source prefix\n")
11105{
11106 bgp_distance_set (vty, argv[0], argv[1], NULL);
11107 return CMD_SUCCESS;
11108}
11109
11110DEFUN (no_bgp_distance_source,
11111 no_bgp_distance_source_cmd,
11112 "no distance <1-255> A.B.C.D/M",
11113 NO_STR
11114 "Define an administrative distance\n"
11115 "Administrative distance\n"
11116 "IP source prefix\n")
11117{
11118 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11119 return CMD_SUCCESS;
11120}
11121
11122DEFUN (bgp_distance_source_access_list,
11123 bgp_distance_source_access_list_cmd,
11124 "distance <1-255> A.B.C.D/M WORD",
11125 "Define an administrative distance\n"
11126 "Administrative distance\n"
11127 "IP source prefix\n"
11128 "Access list name\n")
11129{
11130 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11131 return CMD_SUCCESS;
11132}
11133
11134DEFUN (no_bgp_distance_source_access_list,
11135 no_bgp_distance_source_access_list_cmd,
11136 "no distance <1-255> A.B.C.D/M WORD",
11137 NO_STR
11138 "Define an administrative distance\n"
11139 "Administrative distance\n"
11140 "IP source prefix\n"
11141 "Access list name\n")
11142{
11143 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11144 return CMD_SUCCESS;
11145}
11146
11147DEFUN (bgp_damp_set,
11148 bgp_damp_set_cmd,
11149 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11150 "BGP Specific commands\n"
11151 "Enable route-flap dampening\n"
11152 "Half-life time for the penalty\n"
11153 "Value to start reusing a route\n"
11154 "Value to start suppressing a route\n"
11155 "Maximum duration to suppress a stable route\n")
11156{
11157 struct bgp *bgp;
11158 int half = DEFAULT_HALF_LIFE * 60;
11159 int reuse = DEFAULT_REUSE;
11160 int suppress = DEFAULT_SUPPRESS;
11161 int max = 4 * half;
11162
11163 if (argc == 4)
11164 {
11165 half = atoi (argv[0]) * 60;
11166 reuse = atoi (argv[1]);
11167 suppress = atoi (argv[2]);
11168 max = atoi (argv[3]) * 60;
11169 }
11170 else if (argc == 1)
11171 {
11172 half = atoi (argv[0]) * 60;
11173 max = 4 * half;
11174 }
11175
11176 bgp = vty->index;
11177 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11178 half, reuse, suppress, max);
11179}
11180
11181ALIAS (bgp_damp_set,
11182 bgp_damp_set2_cmd,
11183 "bgp dampening <1-45>",
11184 "BGP Specific commands\n"
11185 "Enable route-flap dampening\n"
11186 "Half-life time for the penalty\n")
11187
11188ALIAS (bgp_damp_set,
11189 bgp_damp_set3_cmd,
11190 "bgp dampening",
11191 "BGP Specific commands\n"
11192 "Enable route-flap dampening\n")
11193
11194DEFUN (bgp_damp_unset,
11195 bgp_damp_unset_cmd,
11196 "no bgp dampening",
11197 NO_STR
11198 "BGP Specific commands\n"
11199 "Enable route-flap dampening\n")
11200{
11201 struct bgp *bgp;
11202
11203 bgp = vty->index;
11204 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11205}
11206
11207ALIAS (bgp_damp_unset,
11208 bgp_damp_unset2_cmd,
11209 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11210 NO_STR
11211 "BGP Specific commands\n"
11212 "Enable route-flap dampening\n"
11213 "Half-life time for the penalty\n"
11214 "Value to start reusing a route\n"
11215 "Value to start suppressing a route\n"
11216 "Maximum duration to suppress a stable route\n")
11217
11218DEFUN (show_ip_bgp_dampened_paths,
11219 show_ip_bgp_dampened_paths_cmd,
11220 "show ip bgp dampened-paths",
11221 SHOW_STR
11222 IP_STR
11223 BGP_STR
11224 "Display paths suppressed due to dampening\n")
11225{
ajs5a646652004-11-05 01:25:55 +000011226 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11227 NULL);
paul718e3742002-12-13 20:15:29 +000011228}
11229
11230DEFUN (show_ip_bgp_flap_statistics,
11231 show_ip_bgp_flap_statistics_cmd,
11232 "show ip bgp flap-statistics",
11233 SHOW_STR
11234 IP_STR
11235 BGP_STR
11236 "Display flap statistics of routes\n")
11237{
ajs5a646652004-11-05 01:25:55 +000011238 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11239 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011240}
11241
11242/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011243static int
paulfd79ac92004-10-13 05:06:08 +000011244bgp_clear_damp_route (struct vty *vty, const char *view_name,
11245 const char *ip_str, afi_t afi, safi_t safi,
11246 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011247{
11248 int ret;
11249 struct prefix match;
11250 struct bgp_node *rn;
11251 struct bgp_node *rm;
11252 struct bgp_info *ri;
11253 struct bgp_info *ri_temp;
11254 struct bgp *bgp;
11255 struct bgp_table *table;
11256
11257 /* BGP structure lookup. */
11258 if (view_name)
11259 {
11260 bgp = bgp_lookup_by_name (view_name);
11261 if (bgp == NULL)
11262 {
11263 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11264 return CMD_WARNING;
11265 }
11266 }
11267 else
11268 {
11269 bgp = bgp_get_default ();
11270 if (bgp == NULL)
11271 {
11272 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11273 return CMD_WARNING;
11274 }
11275 }
11276
11277 /* Check IP address argument. */
11278 ret = str2prefix (ip_str, &match);
11279 if (! ret)
11280 {
11281 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11282 return CMD_WARNING;
11283 }
11284
11285 match.family = afi2family (afi);
11286
11287 if (safi == SAFI_MPLS_VPN)
11288 {
11289 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11290 {
11291 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11292 continue;
11293
11294 if ((table = rn->info) != NULL)
11295 if ((rm = bgp_node_match (table, &match)) != NULL)
11296 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11297 {
11298 ri = rm->info;
11299 while (ri)
11300 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011301 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011302 {
11303 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011304 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011305 ri = ri_temp;
11306 }
11307 else
11308 ri = ri->next;
11309 }
11310 }
11311 }
11312 }
11313 else
11314 {
11315 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11316 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11317 {
11318 ri = rn->info;
11319 while (ri)
11320 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011321 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011322 {
11323 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011324 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011325 ri = ri_temp;
11326 }
11327 else
11328 ri = ri->next;
11329 }
11330 }
11331 }
11332
11333 return CMD_SUCCESS;
11334}
11335
11336DEFUN (clear_ip_bgp_dampening,
11337 clear_ip_bgp_dampening_cmd,
11338 "clear ip bgp dampening",
11339 CLEAR_STR
11340 IP_STR
11341 BGP_STR
11342 "Clear route flap dampening information\n")
11343{
11344 bgp_damp_info_clean ();
11345 return CMD_SUCCESS;
11346}
11347
11348DEFUN (clear_ip_bgp_dampening_prefix,
11349 clear_ip_bgp_dampening_prefix_cmd,
11350 "clear ip bgp dampening A.B.C.D/M",
11351 CLEAR_STR
11352 IP_STR
11353 BGP_STR
11354 "Clear route flap dampening information\n"
11355 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11356{
11357 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11358 SAFI_UNICAST, NULL, 1);
11359}
11360
11361DEFUN (clear_ip_bgp_dampening_address,
11362 clear_ip_bgp_dampening_address_cmd,
11363 "clear ip bgp dampening A.B.C.D",
11364 CLEAR_STR
11365 IP_STR
11366 BGP_STR
11367 "Clear route flap dampening information\n"
11368 "Network to clear damping information\n")
11369{
11370 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11371 SAFI_UNICAST, NULL, 0);
11372}
11373
11374DEFUN (clear_ip_bgp_dampening_address_mask,
11375 clear_ip_bgp_dampening_address_mask_cmd,
11376 "clear ip bgp dampening A.B.C.D A.B.C.D",
11377 CLEAR_STR
11378 IP_STR
11379 BGP_STR
11380 "Clear route flap dampening information\n"
11381 "Network to clear damping information\n"
11382 "Network mask\n")
11383{
11384 int ret;
11385 char prefix_str[BUFSIZ];
11386
11387 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11388 if (! ret)
11389 {
11390 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11391 return CMD_WARNING;
11392 }
11393
11394 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11395 SAFI_UNICAST, NULL, 0);
11396}
11397
paul94f2b392005-06-28 12:44:16 +000011398static int
paul718e3742002-12-13 20:15:29 +000011399bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11400 afi_t afi, safi_t safi, int *write)
11401{
11402 struct bgp_node *prn;
11403 struct bgp_node *rn;
11404 struct bgp_table *table;
11405 struct prefix *p;
11406 struct prefix_rd *prd;
11407 struct bgp_static *bgp_static;
11408 u_int32_t label;
11409 char buf[SU_ADDRSTRLEN];
11410 char rdbuf[RD_ADDRSTRLEN];
11411
11412 /* Network configuration. */
11413 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11414 if ((table = prn->info) != NULL)
11415 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11416 if ((bgp_static = rn->info) != NULL)
11417 {
11418 p = &rn->p;
11419 prd = (struct prefix_rd *) &prn->p;
11420
11421 /* "address-family" display. */
11422 bgp_config_write_family_header (vty, afi, safi, write);
11423
11424 /* "network" configuration display. */
11425 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11426 label = decode_label (bgp_static->tag);
11427
11428 vty_out (vty, " network %s/%d rd %s tag %d",
11429 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11430 p->prefixlen,
11431 rdbuf, label);
11432 vty_out (vty, "%s", VTY_NEWLINE);
11433 }
11434 return 0;
11435}
11436
11437/* Configuration of static route announcement and aggregate
11438 information. */
11439int
11440bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11441 afi_t afi, safi_t safi, int *write)
11442{
11443 struct bgp_node *rn;
11444 struct prefix *p;
11445 struct bgp_static *bgp_static;
11446 struct bgp_aggregate *bgp_aggregate;
11447 char buf[SU_ADDRSTRLEN];
11448
11449 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11450 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11451
11452 /* Network configuration. */
11453 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11454 if ((bgp_static = rn->info) != NULL)
11455 {
11456 p = &rn->p;
11457
11458 /* "address-family" display. */
11459 bgp_config_write_family_header (vty, afi, safi, write);
11460
11461 /* "network" configuration display. */
11462 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11463 {
11464 u_int32_t destination;
11465 struct in_addr netmask;
11466
11467 destination = ntohl (p->u.prefix4.s_addr);
11468 masklen2ip (p->prefixlen, &netmask);
11469 vty_out (vty, " network %s",
11470 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11471
11472 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11473 || (IN_CLASSB (destination) && p->prefixlen == 16)
11474 || (IN_CLASSA (destination) && p->prefixlen == 8)
11475 || p->u.prefix4.s_addr == 0)
11476 {
11477 /* Natural mask is not display. */
11478 }
11479 else
11480 vty_out (vty, " mask %s", inet_ntoa (netmask));
11481 }
11482 else
11483 {
11484 vty_out (vty, " network %s/%d",
11485 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11486 p->prefixlen);
11487 }
11488
11489 if (bgp_static->rmap.name)
11490 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011491 else
11492 {
11493 if (bgp_static->backdoor)
11494 vty_out (vty, " backdoor");
11495 if (bgp_static->ttl)
11496 vty_out (vty, " pathlimit %u", bgp_static->ttl);
11497 }
paul718e3742002-12-13 20:15:29 +000011498
11499 vty_out (vty, "%s", VTY_NEWLINE);
11500 }
11501
11502 /* Aggregate-address configuration. */
11503 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11504 if ((bgp_aggregate = rn->info) != NULL)
11505 {
11506 p = &rn->p;
11507
11508 /* "address-family" display. */
11509 bgp_config_write_family_header (vty, afi, safi, write);
11510
11511 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11512 {
11513 struct in_addr netmask;
11514
11515 masklen2ip (p->prefixlen, &netmask);
11516 vty_out (vty, " aggregate-address %s %s",
11517 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11518 inet_ntoa (netmask));
11519 }
11520 else
11521 {
11522 vty_out (vty, " aggregate-address %s/%d",
11523 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11524 p->prefixlen);
11525 }
11526
11527 if (bgp_aggregate->as_set)
11528 vty_out (vty, " as-set");
11529
11530 if (bgp_aggregate->summary_only)
11531 vty_out (vty, " summary-only");
11532
11533 vty_out (vty, "%s", VTY_NEWLINE);
11534 }
11535
11536 return 0;
11537}
11538
11539int
11540bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11541{
11542 struct bgp_node *rn;
11543 struct bgp_distance *bdistance;
11544
11545 /* Distance configuration. */
11546 if (bgp->distance_ebgp
11547 && bgp->distance_ibgp
11548 && bgp->distance_local
11549 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11550 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11551 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11552 vty_out (vty, " distance bgp %d %d %d%s",
11553 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11554 VTY_NEWLINE);
11555
11556 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11557 if ((bdistance = rn->info) != NULL)
11558 {
11559 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11560 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11561 bdistance->access_list ? bdistance->access_list : "",
11562 VTY_NEWLINE);
11563 }
11564
11565 return 0;
11566}
11567
11568/* Allocate routing table structure and install commands. */
11569void
11570bgp_route_init ()
11571{
11572 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011573 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011574
11575 /* IPv4 BGP commands. */
11576 install_element (BGP_NODE, &bgp_network_cmd);
11577 install_element (BGP_NODE, &bgp_network_mask_cmd);
11578 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11579 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11580 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11581 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11582 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11583 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11584 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011585 install_element (BGP_NODE, &bgp_network_ttl_cmd);
11586 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
11587 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
11588 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
11589 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11590 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011591 install_element (BGP_NODE, &no_bgp_network_cmd);
11592 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11593 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11594 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11595 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11596 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11597 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11598 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11599 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011600 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
11601 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
11602 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11603 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
11604 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11605 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011606
11607 install_element (BGP_NODE, &aggregate_address_cmd);
11608 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11609 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11610 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11611 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11612 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11613 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11614 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11615 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11616 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11617 install_element (BGP_NODE, &no_aggregate_address_cmd);
11618 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11619 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11620 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11621 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11622 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11623 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11624 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11625 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11626 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11627
11628 /* IPv4 unicast configuration. */
11629 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11630 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11631 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11632 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11633 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11634 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011635 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
11636 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
11637 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
11638 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
11639 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11640 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 +000011641 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11642 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11643 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11644 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11645 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011646 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
11647 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
11648 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11649 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
11650 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11651 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 +000011652 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11653 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11654 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11655 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11656 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11657 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11658 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11659 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11660 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11661 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11662 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11663 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11664 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11665 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11666 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11667 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11668 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11669 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11670 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11671 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11672
11673 /* IPv4 multicast configuration. */
11674 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11675 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11676 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11677 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11678 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11679 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011680 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
11681 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
11682 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
11683 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
11684 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
11685 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 +000011686 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11687 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11688 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11689 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11690 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11691 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011692 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
11693 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
11694 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
11695 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
11696 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
11697 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 +000011698 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11699 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11700 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11701 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11702 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11703 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11704 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11705 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11706 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11707 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11708 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11709 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11710 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11711 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11712 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11713 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11714 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11715 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11716 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11717 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11718
11719 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11720 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11721 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11722 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11723 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11724 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11725 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11726 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11727 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11728 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11729 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11730 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11731 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11732 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11733 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11734 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11735 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11736 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11737 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11738 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11739 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11740 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11741 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11742 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11743 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11744 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11745 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11746 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11747 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11748 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11749 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11750 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11751 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11752 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11753 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11754 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11755 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11756 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11757 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11758 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11759 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11760 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11761 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11762 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11763 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11764 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11765 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11766 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11767 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11768 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11769 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11770 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11771 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11772 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11773 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11774 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11775 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11776 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11777 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11778 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11779 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11780 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11781 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11782 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11783 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11784 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11785 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011786 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11787 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11788 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11789 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11790 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11791 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011792
11793 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11794 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11795 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11796 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11797 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11798 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11799 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11800 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11801 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11802 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11803 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11804 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11805 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11806 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11807 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11808 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11809 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11810 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11811 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11812 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11813 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11814 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11815 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11816 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11817 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11818 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11819 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11820 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11821 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11822 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11823 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11824 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11825 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11826 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11827 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11828 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11829 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11830 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11831 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11832 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11833 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11834 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11835 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11836 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11837 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11838 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11839 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11840 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11841 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11842 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11843 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11844 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11845 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11846 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11847 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11848 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11849 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11850 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11851 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11852 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11853 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11854 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11855 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11856 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11857 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11858 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11859 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011860 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11861 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11862 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11863 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11864 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11865 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011866
11867 /* BGP dampening clear commands */
11868 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11869 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11870 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11871 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11872
Paul Jakmaff7924f2006-09-04 01:10:36 +000011873 /* prefix count */
11874 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11875 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11876 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011877#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011878 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11879
paul718e3742002-12-13 20:15:29 +000011880 /* New config IPv6 BGP commands. */
11881 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11882 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011883 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011884 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11885 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
Paul Jakma41367172007-08-06 15:24:51 +000011886 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000011887
11888 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11889 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11890 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11891 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11892
11893 /* Old config IPv6 BGP commands. */
11894 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11895 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11896
11897 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11898 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11899 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11900 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11901
11902 install_element (VIEW_NODE, &show_bgp_cmd);
11903 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11904 install_element (VIEW_NODE, &show_bgp_route_cmd);
11905 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11906 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11907 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11908 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11909 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11910 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11911 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11912 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11913 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11914 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11915 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11916 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11917 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11918 install_element (VIEW_NODE, &show_bgp_community_cmd);
11919 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11920 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11921 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11922 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11923 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11924 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11925 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11926 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11927 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11928 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11929 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11930 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11931 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11932 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11933 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11934 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11935 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11936 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11937 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11938 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11939 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11940 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11941 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11942 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11943 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11944 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11945 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11946 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11947 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011948 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11949 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11950 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11951 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011952 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11953 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11954 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011955 install_element (VIEW_NODE, &show_bgp_view_cmd);
11956 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11957 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11958 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11959 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11960 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11961 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11962 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11963 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11964 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11965 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11966 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11967 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11968 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11969 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11970 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11971 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11972 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011973 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11974 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11975 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011976
11977 install_element (ENABLE_NODE, &show_bgp_cmd);
11978 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11979 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11980 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11981 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11982 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11983 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11984 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11985 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11986 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11987 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11988 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11989 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11990 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11991 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11992 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11993 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11994 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11995 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11996 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11997 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11998 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11999 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12000 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12001 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12002 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12003 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12004 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12005 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12006 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12007 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12008 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12009 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12010 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12011 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12012 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12013 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12014 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12015 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12016 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12017 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12018 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12019 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12020 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12021 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12022 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012023 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12024 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12025 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12026 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012027 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
12028 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
12029 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012030 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12031 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12032 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12033 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12034 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12035 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12036 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12037 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12038 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12039 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12040 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12041 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12042 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12043 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12044 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12045 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12046 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12047 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012048 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
12049 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
12050 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012051
12052 /* Statistics */
12053 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12054 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12055 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12056 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12057
paul718e3742002-12-13 20:15:29 +000012058 /* old command */
12059 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12060 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12061 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12062 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12063 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12064 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12065 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12066 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12067 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12068 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12069 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12070 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12071 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12072 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12073 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12074 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12075 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12076 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12077 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12078 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12079 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12080 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12081 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12082 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12083 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12084 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12085 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12086 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12087 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12088 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12089 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12090 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12091 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12092 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12093 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12094 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012095
paul718e3742002-12-13 20:15:29 +000012096 /* old command */
12097 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12098 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12099 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12100 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12101 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12102 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12103 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12104 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12105 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12106 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12107 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12108 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12109 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12110 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12111 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12112 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12113 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12114 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12115 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12116 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12117 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12118 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12119 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12120 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12121 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12122 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12123 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12124 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12125 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12126 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12127 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12128 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12129 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12130 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12131 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12132 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12133
12134 /* old command */
12135 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12136 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12137 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12138 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12139
12140 /* old command */
12141 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12142 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12143 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12144 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12145
12146 /* old command */
12147 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12148 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12149 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12150 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12151#endif /* HAVE_IPV6 */
12152
12153 install_element (BGP_NODE, &bgp_distance_cmd);
12154 install_element (BGP_NODE, &no_bgp_distance_cmd);
12155 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12156 install_element (BGP_NODE, &bgp_distance_source_cmd);
12157 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12158 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12159 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12160
12161 install_element (BGP_NODE, &bgp_damp_set_cmd);
12162 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12163 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12164 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12165 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12166 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12167 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12168 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12169 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12170 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
12171}