blob: 718e25fff6d99357bb13479eb459229e241e056b [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
paul718e3742002-12-13 20:15:29 +000062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
92
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
141 bgp_attr_unintern (binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
paul718e3742002-12-13 20:15:29 +0000144
paul200df112005-06-01 11:17:05 +0000145 peer_unlock (binfo->peer); /* bgp_info peer reference */
146
paul718e3742002-12-13 20:15:29 +0000147 XFREE (MTYPE_BGP_ROUTE, binfo);
148}
149
paul200df112005-06-01 11:17:05 +0000150struct bgp_info *
151bgp_info_lock (struct bgp_info *binfo)
152{
153 binfo->lock++;
154 return binfo;
155}
156
157struct bgp_info *
158bgp_info_unlock (struct bgp_info *binfo)
159{
160 assert (binfo && binfo->lock > 0);
161 binfo->lock--;
162
163 if (binfo->lock == 0)
164 {
165#if 0
166 zlog_debug ("%s: unlocked and freeing", __func__);
167 zlog_backtrace (LOG_DEBUG);
168#endif
169 bgp_info_free (binfo);
170 return NULL;
171 }
172
173#if 0
174 if (binfo->lock == 1)
175 {
176 zlog_debug ("%s: unlocked to 1", __func__);
177 zlog_backtrace (LOG_DEBUG);
178 }
179#endif
180
181 return binfo;
182}
183
paul718e3742002-12-13 20:15:29 +0000184void
185bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
186{
187 struct bgp_info *top;
188
189 top = rn->info;
paul200df112005-06-01 11:17:05 +0000190
paul718e3742002-12-13 20:15:29 +0000191 ri->next = rn->info;
192 ri->prev = NULL;
193 if (top)
194 top->prev = ri;
195 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000196
197 bgp_info_lock (ri);
198 bgp_lock_node (rn);
199 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000200}
201
paulb40d9392005-08-22 22:34:41 +0000202/* Do the actual removal of info from RIB, for use by bgp_process
203 completion callback *only* */
204static void
205bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000206{
207 if (ri->next)
208 ri->next->prev = ri->prev;
209 if (ri->prev)
210 ri->prev->next = ri->next;
211 else
212 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000213
214 bgp_info_unlock (ri);
215 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000216}
217
paulb40d9392005-08-22 22:34:41 +0000218void
219bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
220{
Paul Jakma1a392d42006-09-07 00:24:49 +0000221 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
222 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000223 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
224}
225
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000226/* undo the effects of a previous call to bgp_info_delete; typically
227 called when a route is deleted and then quickly re-added before the
228 deletion has been processed */
229static void
230bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
231{
232 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
233 /* unset of previous already took care of pcount */
234 SET_FLAG (ri->flags, BGP_INFO_VALID);
235}
236
Paul Jakma1a392d42006-09-07 00:24:49 +0000237/* Adjust pcount as required */
238static void
239bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
240{
Paul Jakma6f585442006-10-22 19:13:07 +0000241 assert (rn && rn->table);
242 assert (ri && ri->peer && ri->peer->bgp);
243
Paul Jakma1a392d42006-09-07 00:24:49 +0000244 /* Ignore 'pcount' for RS-client tables */
245 if (rn->table->type != BGP_TABLE_MAIN
246 || ri->peer == ri->peer->bgp->peer_self)
247 return;
248
249 if (BGP_INFO_HOLDDOWN (ri)
250 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
251 {
252
253 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
254
255 /* slight hack, but more robust against errors. */
256 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
257 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
258 else
259 {
260 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
261 __func__, ri->peer->host);
262 zlog_backtrace (LOG_WARNING);
263 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
264 }
265 }
266 else if (!BGP_INFO_HOLDDOWN (ri)
267 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
268 {
269 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
270 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
271 }
272}
273
274
275/* Set/unset bgp_info flags, adjusting any other state as needed.
276 * This is here primarily to keep prefix-count in check.
277 */
278void
279bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
280{
281 SET_FLAG (ri->flags, flag);
282
283 /* early bath if we know it's not a flag that changes useability state */
284 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
285 return;
286
287 bgp_pcount_adjust (rn, ri);
288}
289
290void
291bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
292{
293 UNSET_FLAG (ri->flags, flag);
294
295 /* early bath if we know it's not a flag that changes useability state */
296 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
297 return;
298
299 bgp_pcount_adjust (rn, ri);
300}
301
paul718e3742002-12-13 20:15:29 +0000302/* Get MED value. If MED value is missing and "bgp bestpath
303 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000304static u_int32_t
paul718e3742002-12-13 20:15:29 +0000305bgp_med_value (struct attr *attr, struct bgp *bgp)
306{
307 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
308 return attr->med;
309 else
310 {
311 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000312 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000313 else
314 return 0;
315 }
316}
317
318/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000319static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700320bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
321 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000322{
323 u_int32_t new_pref;
324 u_int32_t exist_pref;
325 u_int32_t new_med;
326 u_int32_t exist_med;
Paul Jakmafb982c22007-05-04 20:15:47 +0000327 u_int32_t new_weight = 0;
328 u_int32_t exist_weight = 0;
paul718e3742002-12-13 20:15:29 +0000329 struct in_addr new_id;
330 struct in_addr exist_id;
331 int new_cluster;
332 int exist_cluster;
333 int internal_as_route = 0;
334 int confed_as_route = 0;
335 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700336 uint32_t newm, existm;
337
338 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000339
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. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700462 newm = (new->extra ? new->extra->igpmetric : 0);
463 existm = (exist->extra ? exist->extra->igpmetric : 0);
464 if (newm < existm)
465 ret = 1;
466 if (newm > existm)
467 ret = 0;
paul718e3742002-12-13 20:15:29 +0000468
469 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700470 if (newm == existm)
471 {
472 if ((peer_sort (new->peer) == BGP_PEER_IBGP))
473 {
474 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
475 *paths_eq = 1;
476 }
477 else if (new->peer->as == exist->peer->as)
478 *paths_eq = 1;
479 }
480 else
481 {
482 /*
483 * TODO: If unequal cost ibgp multipath is enabled we can
484 * mark the paths as equal here instead of returning
485 */
486 return ret;
487 }
paul718e3742002-12-13 20:15:29 +0000488
489 /* 10. If both paths are external, prefer the path that was received
490 first (the oldest one). This step minimizes route-flap, since a
491 newer path won't displace an older one, even if it was the
492 preferred route based on the additional decision criteria below. */
493 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
494 && peer_sort (new->peer) == BGP_PEER_EBGP
495 && peer_sort (exist->peer) == BGP_PEER_EBGP)
496 {
497 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
498 return 1;
499 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
500 return 0;
501 }
502
503 /* 11. Rourter-ID comparision. */
504 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000505 new_id.s_addr = new->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000506 else
507 new_id.s_addr = new->peer->remote_id.s_addr;
508 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000509 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000510 else
511 exist_id.s_addr = exist->peer->remote_id.s_addr;
512
513 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
514 return 1;
515 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
516 return 0;
517
518 /* 12. Cluster length comparision. */
519 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000520 new_cluster = new->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000521 else
522 new_cluster = 0;
523 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000524 exist_cluster = exist->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000525 else
526 exist_cluster = 0;
527
528 if (new_cluster < exist_cluster)
529 return 1;
530 if (new_cluster > exist_cluster)
531 return 0;
532
533 /* 13. Neighbor address comparision. */
534 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
535
536 if (ret == 1)
537 return 0;
538 if (ret == -1)
539 return 1;
540
541 return 1;
542}
543
paul94f2b392005-06-28 12:44:16 +0000544static enum filter_type
paul718e3742002-12-13 20:15:29 +0000545bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
546 afi_t afi, safi_t safi)
547{
548 struct bgp_filter *filter;
549
550 filter = &peer->filter[afi][safi];
551
Paul Jakma650f76c2009-06-25 18:06:31 +0100552#define FILTER_EXIST_WARN(F,f,filter) \
553 if (BGP_DEBUG (update, UPDATE_IN) \
554 && !(F ## _IN (filter))) \
555 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
556 peer->host, #f, F ## _IN_NAME(filter));
557
558 if (DISTRIBUTE_IN_NAME (filter)) {
559 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
560
paul718e3742002-12-13 20:15:29 +0000561 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
562 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100563 }
paul718e3742002-12-13 20:15:29 +0000564
Paul Jakma650f76c2009-06-25 18:06:31 +0100565 if (PREFIX_LIST_IN_NAME (filter)) {
566 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
567
paul718e3742002-12-13 20:15:29 +0000568 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
569 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100570 }
paul718e3742002-12-13 20:15:29 +0000571
Paul Jakma650f76c2009-06-25 18:06:31 +0100572 if (FILTER_LIST_IN_NAME (filter)) {
573 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
574
paul718e3742002-12-13 20:15:29 +0000575 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
576 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100577 }
578
paul718e3742002-12-13 20:15:29 +0000579 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100580#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000581}
582
paul94f2b392005-06-28 12:44:16 +0000583static enum filter_type
paul718e3742002-12-13 20:15:29 +0000584bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
585 afi_t afi, safi_t safi)
586{
587 struct bgp_filter *filter;
588
589 filter = &peer->filter[afi][safi];
590
Paul Jakma650f76c2009-06-25 18:06:31 +0100591#define FILTER_EXIST_WARN(F,f,filter) \
592 if (BGP_DEBUG (update, UPDATE_OUT) \
593 && !(F ## _OUT (filter))) \
594 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
595 peer->host, #f, F ## _OUT_NAME(filter));
596
597 if (DISTRIBUTE_OUT_NAME (filter)) {
598 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
599
paul718e3742002-12-13 20:15:29 +0000600 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
601 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100602 }
paul718e3742002-12-13 20:15:29 +0000603
Paul Jakma650f76c2009-06-25 18:06:31 +0100604 if (PREFIX_LIST_OUT_NAME (filter)) {
605 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
606
paul718e3742002-12-13 20:15:29 +0000607 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
608 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100609 }
paul718e3742002-12-13 20:15:29 +0000610
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 if (FILTER_LIST_OUT_NAME (filter)) {
612 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
613
paul718e3742002-12-13 20:15:29 +0000614 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
615 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100616 }
paul718e3742002-12-13 20:15:29 +0000617
618 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100619#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000620}
621
622/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000623static int
paul718e3742002-12-13 20:15:29 +0000624bgp_community_filter (struct peer *peer, struct attr *attr)
625{
626 if (attr->community)
627 {
628 /* NO_ADVERTISE check. */
629 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
630 return 1;
631
632 /* NO_EXPORT check. */
633 if (peer_sort (peer) == BGP_PEER_EBGP &&
634 community_include (attr->community, COMMUNITY_NO_EXPORT))
635 return 1;
636
637 /* NO_EXPORT_SUBCONFED check. */
638 if (peer_sort (peer) == BGP_PEER_EBGP
639 || peer_sort (peer) == BGP_PEER_CONFED)
640 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
641 return 1;
642 }
643 return 0;
644}
645
646/* Route reflection loop check. */
647static int
648bgp_cluster_filter (struct peer *peer, struct attr *attr)
649{
650 struct in_addr cluster_id;
651
Paul Jakmafb982c22007-05-04 20:15:47 +0000652 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000653 {
654 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
655 cluster_id = peer->bgp->cluster_id;
656 else
657 cluster_id = peer->bgp->router_id;
658
Paul Jakmafb982c22007-05-04 20:15:47 +0000659 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000660 return 1;
661 }
662 return 0;
663}
664
paul94f2b392005-06-28 12:44:16 +0000665static int
paul718e3742002-12-13 20:15:29 +0000666bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
667 afi_t afi, safi_t safi)
668{
669 struct bgp_filter *filter;
670 struct bgp_info info;
671 route_map_result_t ret;
672
673 filter = &peer->filter[afi][safi];
674
675 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000676 if (peer->weight)
677 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000678
679 /* Route map apply. */
680 if (ROUTE_MAP_IN_NAME (filter))
681 {
682 /* Duplicate current value to new strucutre for modification. */
683 info.peer = peer;
684 info.attr = attr;
685
paulac41b2a2003-08-12 05:32:27 +0000686 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
687
paul718e3742002-12-13 20:15:29 +0000688 /* Apply BGP route map to the attribute. */
689 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000690
691 peer->rmap_type = 0;
692
paul718e3742002-12-13 20:15:29 +0000693 if (ret == RMAP_DENYMATCH)
694 {
695 /* Free newly generated AS path and community by route-map. */
696 bgp_attr_flush (attr);
697 return RMAP_DENY;
698 }
699 }
700 return RMAP_PERMIT;
701}
702
paul94f2b392005-06-28 12:44:16 +0000703static int
paulfee0f4c2004-09-13 05:12:46 +0000704bgp_export_modifier (struct peer *rsclient, struct peer *peer,
705 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
706{
707 struct bgp_filter *filter;
708 struct bgp_info info;
709 route_map_result_t ret;
710
711 filter = &peer->filter[afi][safi];
712
713 /* Route map apply. */
714 if (ROUTE_MAP_EXPORT_NAME (filter))
715 {
716 /* Duplicate current value to new strucutre for modification. */
717 info.peer = rsclient;
718 info.attr = attr;
719
720 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
721
722 /* Apply BGP route map to the attribute. */
723 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
724
725 rsclient->rmap_type = 0;
726
727 if (ret == RMAP_DENYMATCH)
728 {
729 /* Free newly generated AS path and community by route-map. */
730 bgp_attr_flush (attr);
731 return RMAP_DENY;
732 }
733 }
734 return RMAP_PERMIT;
735}
736
paul94f2b392005-06-28 12:44:16 +0000737static int
paulfee0f4c2004-09-13 05:12:46 +0000738bgp_import_modifier (struct peer *rsclient, struct peer *peer,
739 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
740{
741 struct bgp_filter *filter;
742 struct bgp_info info;
743 route_map_result_t ret;
744
745 filter = &rsclient->filter[afi][safi];
746
747 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000748 if (peer->weight)
749 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000750
751 /* Route map apply. */
752 if (ROUTE_MAP_IMPORT_NAME (filter))
753 {
754 /* Duplicate current value to new strucutre for modification. */
755 info.peer = peer;
756 info.attr = attr;
757
758 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
759
760 /* Apply BGP route map to the attribute. */
761 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
762
763 peer->rmap_type = 0;
764
765 if (ret == RMAP_DENYMATCH)
766 {
767 /* Free newly generated AS path and community by route-map. */
768 bgp_attr_flush (attr);
769 return RMAP_DENY;
770 }
771 }
772 return RMAP_PERMIT;
773}
774
paul94f2b392005-06-28 12:44:16 +0000775static int
paul718e3742002-12-13 20:15:29 +0000776bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
777 struct attr *attr, afi_t afi, safi_t safi)
778{
779 int ret;
780 char buf[SU_ADDRSTRLEN];
781 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000782 struct peer *from;
783 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000784 int transparent;
785 int reflect;
786
787 from = ri->peer;
788 filter = &peer->filter[afi][safi];
789 bgp = peer->bgp;
790
Paul Jakma750e8142008-07-22 21:11:48 +0000791 if (DISABLE_BGP_ANNOUNCE)
792 return 0;
paul718e3742002-12-13 20:15:29 +0000793
paulfee0f4c2004-09-13 05:12:46 +0000794 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
795 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
796 return 0;
797
paul718e3742002-12-13 20:15:29 +0000798 /* Do not send back route to sender. */
799 if (from == peer)
800 return 0;
801
paul35be31b2004-05-01 18:17:04 +0000802 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
803 if (p->family == AF_INET
804 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
805 return 0;
806#ifdef HAVE_IPV6
807 if (p->family == AF_INET6
808 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
809 return 0;
810#endif
811
paul718e3742002-12-13 20:15:29 +0000812 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000813 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000814 if (! UNSUPPRESS_MAP_NAME (filter))
815 return 0;
816
817 /* Default route check. */
818 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
819 {
820 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
821 return 0;
822#ifdef HAVE_IPV6
823 else if (p->family == AF_INET6 && p->prefixlen == 0)
824 return 0;
825#endif /* HAVE_IPV6 */
826 }
827
paul286e1e72003-08-08 00:24:31 +0000828 /* Transparency check. */
829 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
830 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
831 transparent = 1;
832 else
833 transparent = 0;
834
paul718e3742002-12-13 20:15:29 +0000835 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000836 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000837 return 0;
838
839 /* If the attribute has originator-id and it is same as remote
840 peer's id. */
841 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
842 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000843 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000844 {
845 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000846 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000847 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
848 peer->host,
849 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
850 p->prefixlen);
851 return 0;
852 }
853 }
854
855 /* ORF prefix-list filter check */
856 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
857 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
858 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
859 if (peer->orf_plist[afi][safi])
860 {
861 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
862 return 0;
863 }
864
865 /* Output filter check. */
866 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
867 {
868 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000869 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000870 "%s [Update:SEND] %s/%d is filtered",
871 peer->host,
872 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
873 p->prefixlen);
874 return 0;
875 }
876
877#ifdef BGP_SEND_ASPATH_CHECK
878 /* AS path loop check. */
879 if (aspath_loop_check (ri->attr->aspath, peer->as))
880 {
881 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000882 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400883 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000884 peer->host, peer->as);
885 return 0;
886 }
887#endif /* BGP_SEND_ASPATH_CHECK */
888
889 /* If we're a CONFED we need to loop check the CONFED ID too */
890 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
891 {
892 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
893 {
894 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000895 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400896 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000897 peer->host,
898 bgp->confed_id);
899 return 0;
900 }
901 }
902
903 /* Route-Reflect check. */
904 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
905 reflect = 1;
906 else
907 reflect = 0;
908
909 /* IBGP reflection check. */
910 if (reflect)
911 {
912 /* A route from a Client peer. */
913 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
914 {
915 /* Reflect to all the Non-Client peers and also to the
916 Client peers other than the originator. Originator check
917 is already done. So there is noting to do. */
918 /* no bgp client-to-client reflection check. */
919 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
920 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
921 return 0;
922 }
923 else
924 {
925 /* A route from a Non-client peer. Reflect to all other
926 clients. */
927 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
928 return 0;
929 }
930 }
Paul Jakma41367172007-08-06 15:24:51 +0000931
paul718e3742002-12-13 20:15:29 +0000932 /* For modify attribute, copy it to temporary structure. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000933 bgp_attr_dup (attr, ri->attr);
934
paul718e3742002-12-13 20:15:29 +0000935 /* If local-preference is not set. */
936 if ((peer_sort (peer) == BGP_PEER_IBGP
937 || peer_sort (peer) == BGP_PEER_CONFED)
938 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
939 {
940 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
941 attr->local_pref = bgp->default_local_pref;
942 }
943
paul718e3742002-12-13 20:15:29 +0000944 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
945 if (peer_sort (peer) == BGP_PEER_EBGP
946 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
947 {
948 if (ri->peer != bgp->peer_self && ! transparent
949 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
950 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
951 }
952
953 /* next-hop-set */
954 if (transparent || reflect
955 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
956 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000957#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000958 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000959 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000960#endif /* HAVE_IPV6 */
961 )))
paul718e3742002-12-13 20:15:29 +0000962 {
963 /* NEXT-HOP Unchanged. */
964 }
965 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
966 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
967#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000968 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000969 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000970#endif /* HAVE_IPV6 */
971 || (peer_sort (peer) == BGP_PEER_EBGP
972 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
973 {
974 /* Set IPv4 nexthop. */
975 if (p->family == AF_INET)
976 {
977 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000978 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
979 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000980 else
981 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
982 }
983#ifdef HAVE_IPV6
984 /* Set IPv6 nexthop. */
985 if (p->family == AF_INET6)
986 {
987 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000988 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000989 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000990 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000991 }
992#endif /* HAVE_IPV6 */
993 }
994
995#ifdef HAVE_IPV6
996 if (p->family == AF_INET6)
997 {
paulfee0f4c2004-09-13 05:12:46 +0000998 /* Left nexthop_local unchanged if so configured. */
999 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1000 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1001 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001002 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1003 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001004 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001005 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001006 }
1007
1008 /* Default nexthop_local treatment for non-RS-Clients */
1009 else
1010 {
paul718e3742002-12-13 20:15:29 +00001011 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001012 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001013
1014 /* Set link-local address for shared network peer. */
1015 if (peer->shared_network
1016 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1017 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001018 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001019 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001020 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001021 }
1022
1023 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1024 address.*/
1025 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001026 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001027
1028 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1029 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001030 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001031 }
paulfee0f4c2004-09-13 05:12:46 +00001032
1033 }
paul718e3742002-12-13 20:15:29 +00001034#endif /* HAVE_IPV6 */
1035
1036 /* If this is EBGP peer and remove-private-AS is set. */
1037 if (peer_sort (peer) == BGP_PEER_EBGP
1038 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1039 && aspath_private_as_check (attr->aspath))
1040 attr->aspath = aspath_empty_get ();
1041
1042 /* Route map & unsuppress-map apply. */
1043 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001045 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001046 struct bgp_info info;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001047 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001048
paul718e3742002-12-13 20:15:29 +00001049 info.peer = peer;
1050 info.attr = attr;
1051
1052 /* The route reflector is not allowed to modify the attributes
1053 of the reflected IBGP routes. */
1054 if (peer_sort (from) == BGP_PEER_IBGP
1055 && peer_sort (peer) == BGP_PEER_IBGP)
1056 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001057 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001058 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001059 }
paulac41b2a2003-08-12 05:32:27 +00001060
1061 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1062
Paul Jakmafb982c22007-05-04 20:15:47 +00001063 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001064 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1065 else
1066 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1067
paulac41b2a2003-08-12 05:32:27 +00001068 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001069
Paul Jakma9eda90c2007-08-30 13:36:17 +00001070 if (dummy_attr.extra)
1071 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001072
paul718e3742002-12-13 20:15:29 +00001073 if (ret == RMAP_DENYMATCH)
1074 {
1075 bgp_attr_flush (attr);
1076 return 0;
1077 }
1078 }
1079 return 1;
1080}
1081
paul94f2b392005-06-28 12:44:16 +00001082static int
paulfee0f4c2004-09-13 05:12:46 +00001083bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1084 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001085{
paulfee0f4c2004-09-13 05:12:46 +00001086 int ret;
1087 char buf[SU_ADDRSTRLEN];
1088 struct bgp_filter *filter;
1089 struct bgp_info info;
1090 struct peer *from;
1091 struct bgp *bgp;
1092
1093 from = ri->peer;
1094 filter = &rsclient->filter[afi][safi];
1095 bgp = rsclient->bgp;
1096
Paul Jakma750e8142008-07-22 21:11:48 +00001097 if (DISABLE_BGP_ANNOUNCE)
1098 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001099
1100 /* Do not send back route to sender. */
1101 if (from == rsclient)
1102 return 0;
1103
1104 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001105 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001106 if (! UNSUPPRESS_MAP_NAME (filter))
1107 return 0;
1108
1109 /* Default route check. */
1110 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1111 PEER_STATUS_DEFAULT_ORIGINATE))
1112 {
1113 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1114 return 0;
1115#ifdef HAVE_IPV6
1116 else if (p->family == AF_INET6 && p->prefixlen == 0)
1117 return 0;
1118#endif /* HAVE_IPV6 */
1119 }
1120
1121 /* If the attribute has originator-id and it is same as remote
1122 peer's id. */
1123 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1124 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001125 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1126 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001127 {
1128 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001129 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001130 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1131 rsclient->host,
1132 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1133 p->prefixlen);
1134 return 0;
1135 }
1136 }
1137
1138 /* ORF prefix-list filter check */
1139 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1140 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1141 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1142 if (rsclient->orf_plist[afi][safi])
1143 {
1144 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1145 return 0;
1146 }
1147
1148 /* Output filter check. */
1149 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1150 {
1151 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001152 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001153 "%s [Update:SEND] %s/%d is filtered",
1154 rsclient->host,
1155 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1156 p->prefixlen);
1157 return 0;
1158 }
1159
1160#ifdef BGP_SEND_ASPATH_CHECK
1161 /* AS path loop check. */
1162 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1163 {
1164 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001165 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001166 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001167 rsclient->host, rsclient->as);
1168 return 0;
1169 }
1170#endif /* BGP_SEND_ASPATH_CHECK */
1171
1172 /* For modify attribute, copy it to temporary structure. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001173 bgp_attr_dup (attr, ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001174
1175 /* next-hop-set */
1176 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1177#ifdef HAVE_IPV6
1178 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001179 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001180#endif /* HAVE_IPV6 */
1181 )
1182 {
1183 /* Set IPv4 nexthop. */
1184 if (p->family == AF_INET)
1185 {
1186 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001187 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001188 IPV4_MAX_BYTELEN);
1189 else
1190 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1191 }
1192#ifdef HAVE_IPV6
1193 /* Set IPv6 nexthop. */
1194 if (p->family == AF_INET6)
1195 {
1196 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001197 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001198 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001199 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001200 }
1201#endif /* HAVE_IPV6 */
1202 }
1203
1204#ifdef HAVE_IPV6
1205 if (p->family == AF_INET6)
1206 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001207 struct attr_extra *attre = attr->extra;
1208
1209 assert (attr->extra);
1210
paulfee0f4c2004-09-13 05:12:46 +00001211 /* Left nexthop_local unchanged if so configured. */
1212 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1213 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1214 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001215 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1216 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001217 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001218 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001219 }
1220
1221 /* Default nexthop_local treatment for RS-Clients */
1222 else
1223 {
1224 /* Announcer and RS-Client are both in the same network */
1225 if (rsclient->shared_network && from->shared_network &&
1226 (rsclient->ifindex == from->ifindex))
1227 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001228 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1229 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001230 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001231 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001232 }
1233
1234 /* Set link-local address for shared network peer. */
1235 else if (rsclient->shared_network
1236 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1237 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001238 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001239 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001240 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001241 }
1242
1243 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001244 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001245 }
1246
1247 }
1248#endif /* HAVE_IPV6 */
1249
1250
1251 /* If this is EBGP peer and remove-private-AS is set. */
1252 if (peer_sort (rsclient) == BGP_PEER_EBGP
1253 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1254 && aspath_private_as_check (attr->aspath))
1255 attr->aspath = aspath_empty_get ();
1256
1257 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001258 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001259 {
1260 info.peer = rsclient;
1261 info.attr = attr;
1262
1263 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1264
Paul Jakmafb982c22007-05-04 20:15:47 +00001265 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001266 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1267 else
1268 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1269
1270 rsclient->rmap_type = 0;
1271
1272 if (ret == RMAP_DENYMATCH)
1273 {
1274 bgp_attr_flush (attr);
1275 return 0;
1276 }
1277 }
1278
1279 return 1;
1280}
1281
1282struct bgp_info_pair
1283{
1284 struct bgp_info *old;
1285 struct bgp_info *new;
1286};
1287
paul94f2b392005-06-28 12:44:16 +00001288static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001289bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1290 struct bgp_maxpaths_cfg *mpath_cfg,
1291 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001292{
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;
Josh Bailey96450fa2011-07-20 20:45:12 -07001299 int paths_eq, do_mpath;
1300 struct list mp_list;
1301
1302 bgp_mp_list_init (&mp_list);
1303 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1304 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1305
paul718e3742002-12-13 20:15:29 +00001306 /* bgp deterministic-med */
1307 new_select = NULL;
1308 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1309 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1310 {
1311 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1312 continue;
1313 if (BGP_INFO_HOLDDOWN (ri1))
1314 continue;
1315
1316 new_select = ri1;
1317 if (ri1->next)
1318 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1319 {
1320 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1321 continue;
1322 if (BGP_INFO_HOLDDOWN (ri2))
1323 continue;
1324
1325 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1326 || aspath_cmp_left_confed (ri1->attr->aspath,
1327 ri2->attr->aspath))
1328 {
Josh Bailey96450fa2011-07-20 20:45:12 -07001329 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001330 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001331 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001332 new_select = ri2;
1333 }
1334
Paul Jakma1a392d42006-09-07 00:24:49 +00001335 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001336 }
1337 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001338 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1339 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001340 }
1341
1342 /* Check old selected route and new selected route. */
1343 old_select = NULL;
1344 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001345 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001346 {
1347 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1348 old_select = ri;
1349
1350 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001351 {
1352 /* reap REMOVED routes, if needs be
1353 * selected route must stay for a while longer though
1354 */
1355 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1356 && (ri != old_select))
1357 bgp_info_reap (rn, ri);
1358
1359 continue;
1360 }
paul718e3742002-12-13 20:15:29 +00001361
1362 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1363 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1364 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001365 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001366 continue;
1367 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001368 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1369 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001370
Josh Bailey96450fa2011-07-20 20:45:12 -07001371 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1372 {
1373 new_select = ri;
1374
1375 if (do_mpath && !paths_eq)
1376 {
1377 bgp_mp_list_clear (&mp_list);
1378 bgp_mp_list_add (&mp_list, ri);
1379 }
1380 }
1381
1382 if (do_mpath && paths_eq)
1383 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001384 }
paulb40d9392005-08-22 22:34:41 +00001385
paulfee0f4c2004-09-13 05:12:46 +00001386
Josh Bailey96450fa2011-07-20 20:45:12 -07001387 /*
1388 * TODO: Will add some additional filtering later to only
1389 * output debugs when multipath state for the route changes
1390 */
1391 if (BGP_DEBUG (events, EVENTS) && do_mpath)
1392 {
1393 struct listnode *mp_node;
1394 struct bgp_info *mp_info;
1395 char buf[2][INET_ADDRSTRLEN];
1396
1397 prefix2str (&rn->p, buf[0], sizeof (buf[0]));
1398 zlog_debug ("%s bestpath nexthop %s, %d mpath candidates",
1399 buf[0],
1400 (new_select ?
1401 inet_ntop(AF_INET, &new_select->attr->nexthop,
1402 buf[1], sizeof (buf[1])) :
1403 "None"),
1404 listcount (&mp_list));
1405 for (mp_node = listhead (&mp_list); mp_node;
1406 mp_node = listnextnode (mp_node))
1407 {
1408 mp_info = listgetdata (mp_node);
1409 if (mp_info == new_select)
1410 continue;
1411 zlog_debug (" candidate mpath nexthop %s",
1412 inet_ntop(AF_INET, &mp_info->attr->nexthop, buf[0],
1413 sizeof (buf[0])));
1414 }
1415 }
1416
1417 bgp_mp_list_clear (&mp_list);
1418
1419 result->old = old_select;
1420 result->new = new_select;
1421
1422 return;
paulfee0f4c2004-09-13 05:12:46 +00001423}
1424
paul94f2b392005-06-28 12:44:16 +00001425static int
paulfee0f4c2004-09-13 05:12:46 +00001426bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001427 struct bgp_node *rn, afi_t afi, safi_t safi)
1428{
paulfee0f4c2004-09-13 05:12:46 +00001429 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001430 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001431
1432 p = &rn->p;
1433
Paul Jakma9eda90c2007-08-30 13:36:17 +00001434 /* Announce route to Established peer. */
1435 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001436 return 0;
1437
Paul Jakma9eda90c2007-08-30 13:36:17 +00001438 /* Address family configuration check. */
1439 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001440 return 0;
1441
Paul Jakma9eda90c2007-08-30 13:36:17 +00001442 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001443 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1444 PEER_STATUS_ORF_WAIT_REFRESH))
1445 return 0;
1446
1447 switch (rn->table->type)
1448 {
1449 case BGP_TABLE_MAIN:
1450 /* Announcement to peer->conf. If the route is filtered,
1451 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001452 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1453 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001454 else
1455 bgp_adj_out_unset (rn, peer, p, afi, safi);
1456 break;
1457 case BGP_TABLE_RSCLIENT:
1458 /* Announcement to peer->conf. If the route is filtered,
1459 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001460 if (selected &&
1461 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1462 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1463 else
1464 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001465 break;
1466 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001467
1468 bgp_attr_extra_free (&attr);
1469
paulfee0f4c2004-09-13 05:12:46 +00001470 return 0;
paul200df112005-06-01 11:17:05 +00001471}
paulfee0f4c2004-09-13 05:12:46 +00001472
paul200df112005-06-01 11:17:05 +00001473struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001474{
paul200df112005-06-01 11:17:05 +00001475 struct bgp *bgp;
1476 struct bgp_node *rn;
1477 afi_t afi;
1478 safi_t safi;
1479};
1480
1481static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001482bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001483{
paul0fb58d52005-11-14 14:31:49 +00001484 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001485 struct bgp *bgp = pq->bgp;
1486 struct bgp_node *rn = pq->rn;
1487 afi_t afi = pq->afi;
1488 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001489 struct bgp_info *new_select;
1490 struct bgp_info *old_select;
1491 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001492 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001493 struct peer *rsclient = rn->table->owner;
1494
paulfee0f4c2004-09-13 05:12:46 +00001495 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001496 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001497 new_select = old_and_new.new;
1498 old_select = old_and_new.old;
1499
paul200df112005-06-01 11:17:05 +00001500 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1501 {
Chris Caputo228da422009-07-18 05:44:03 +00001502 if (rsclient->group)
1503 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1504 {
1505 /* Nothing to do. */
1506 if (old_select && old_select == new_select)
1507 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1508 continue;
paulfee0f4c2004-09-13 05:12:46 +00001509
Chris Caputo228da422009-07-18 05:44:03 +00001510 if (old_select)
1511 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1512 if (new_select)
1513 {
1514 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1515 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1516 }
paulfee0f4c2004-09-13 05:12:46 +00001517
Chris Caputo228da422009-07-18 05:44:03 +00001518 bgp_process_announce_selected (rsclient, new_select, rn,
1519 afi, safi);
1520 }
paul200df112005-06-01 11:17:05 +00001521 }
1522 else
1523 {
hassob7395792005-08-26 12:58:38 +00001524 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001525 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001526 if (new_select)
1527 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001528 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1529 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001530 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001531 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001532 }
paulfee0f4c2004-09-13 05:12:46 +00001533
paulb40d9392005-08-22 22:34:41 +00001534 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1535 bgp_info_reap (rn, old_select);
1536
paul200df112005-06-01 11:17:05 +00001537 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1538 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001539}
1540
paul200df112005-06-01 11:17:05 +00001541static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001542bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001543{
paul0fb58d52005-11-14 14:31:49 +00001544 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001545 struct bgp *bgp = pq->bgp;
1546 struct bgp_node *rn = pq->rn;
1547 afi_t afi = pq->afi;
1548 safi_t safi = pq->safi;
1549 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001550 struct bgp_info *new_select;
1551 struct bgp_info *old_select;
1552 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001553 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001554 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001555
paulfee0f4c2004-09-13 05:12:46 +00001556 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001557 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001558 old_select = old_and_new.old;
1559 new_select = old_and_new.new;
1560
1561 /* Nothing to do. */
1562 if (old_select && old_select == new_select)
1563 {
1564 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001565 {
1566 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1567 bgp_zebra_announce (p, old_select, bgp);
1568
1569 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1570 return WQ_SUCCESS;
1571 }
paulfee0f4c2004-09-13 05:12:46 +00001572 }
paul718e3742002-12-13 20:15:29 +00001573
hasso338b3422005-02-23 14:27:24 +00001574 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001575 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001576 if (new_select)
1577 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001578 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1579 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001580 }
1581
1582
paul718e3742002-12-13 20:15:29 +00001583 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001584 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001585 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001586 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001587 }
1588
1589 /* FIB update. */
1590 if (safi == SAFI_UNICAST && ! bgp->name &&
1591 ! bgp_option_check (BGP_OPT_NO_FIB))
1592 {
1593 if (new_select
1594 && new_select->type == ZEBRA_ROUTE_BGP
1595 && new_select->sub_type == BGP_ROUTE_NORMAL)
1596 bgp_zebra_announce (p, new_select, bgp);
1597 else
1598 {
1599 /* Withdraw the route from the kernel. */
1600 if (old_select
1601 && old_select->type == ZEBRA_ROUTE_BGP
1602 && old_select->sub_type == BGP_ROUTE_NORMAL)
1603 bgp_zebra_withdraw (p, old_select);
1604 }
1605 }
paulb40d9392005-08-22 22:34:41 +00001606
1607 /* Reap old select bgp_info, it it has been removed */
1608 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1609 bgp_info_reap (rn, old_select);
1610
paul200df112005-06-01 11:17:05 +00001611 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1612 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001613}
1614
paul200df112005-06-01 11:17:05 +00001615static void
paul0fb58d52005-11-14 14:31:49 +00001616bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001617{
paul0fb58d52005-11-14 14:31:49 +00001618 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001619 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001620
Chris Caputo228da422009-07-18 05:44:03 +00001621 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001622 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001623 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001624 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1625}
1626
1627static void
1628bgp_process_queue_init (void)
1629{
1630 bm->process_main_queue
1631 = work_queue_new (bm->master, "process_main_queue");
1632 bm->process_rsclient_queue
1633 = work_queue_new (bm->master, "process_rsclient_queue");
1634
1635 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1636 {
1637 zlog_err ("%s: Failed to allocate work queue", __func__);
1638 exit (1);
1639 }
1640
1641 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001642 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001643 bm->process_main_queue->spec.max_retries = 0;
1644 bm->process_main_queue->spec.hold = 50;
1645
1646 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1647 sizeof (struct work_queue *));
1648 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001649}
1650
1651void
paulfee0f4c2004-09-13 05:12:46 +00001652bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1653{
paul200df112005-06-01 11:17:05 +00001654 struct bgp_process_queue *pqnode;
1655
1656 /* already scheduled for processing? */
1657 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1658 return;
1659
1660 if ( (bm->process_main_queue == NULL) ||
1661 (bm->process_rsclient_queue == NULL) )
1662 bgp_process_queue_init ();
1663
1664 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1665 sizeof (struct bgp_process_queue));
1666 if (!pqnode)
1667 return;
Chris Caputo228da422009-07-18 05:44:03 +00001668
1669 /* all unlocked in bgp_processq_del */
1670 bgp_table_lock (rn->table);
1671 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001672 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001673 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001674 pqnode->afi = afi;
1675 pqnode->safi = safi;
1676
paulfee0f4c2004-09-13 05:12:46 +00001677 switch (rn->table->type)
1678 {
paul200df112005-06-01 11:17:05 +00001679 case BGP_TABLE_MAIN:
1680 work_queue_add (bm->process_main_queue, pqnode);
1681 break;
1682 case BGP_TABLE_RSCLIENT:
1683 work_queue_add (bm->process_rsclient_queue, pqnode);
1684 break;
paulfee0f4c2004-09-13 05:12:46 +00001685 }
paul200df112005-06-01 11:17:05 +00001686
1687 return;
paulfee0f4c2004-09-13 05:12:46 +00001688}
hasso0a486e52005-02-01 20:57:17 +00001689
paul94f2b392005-06-28 12:44:16 +00001690static int
hasso0a486e52005-02-01 20:57:17 +00001691bgp_maximum_prefix_restart_timer (struct thread *thread)
1692{
1693 struct peer *peer;
1694
1695 peer = THREAD_ARG (thread);
1696 peer->t_pmax_restart = NULL;
1697
1698 if (BGP_DEBUG (events, EVENTS))
1699 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1700 peer->host);
1701
1702 peer_clear (peer);
1703
1704 return 0;
1705}
1706
paulfee0f4c2004-09-13 05:12:46 +00001707int
paul5228ad22004-06-04 17:58:18 +00001708bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1709 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001710{
hassoe0701b72004-05-20 09:19:34 +00001711 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1712 return 0;
1713
1714 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001715 {
hassoe0701b72004-05-20 09:19:34 +00001716 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1717 && ! always)
1718 return 0;
paul718e3742002-12-13 20:15:29 +00001719
hassoe0701b72004-05-20 09:19:34 +00001720 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001721 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1722 "limit %ld", afi_safi_print (afi, safi), peer->host,
1723 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001724 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001725
hassoe0701b72004-05-20 09:19:34 +00001726 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1727 return 0;
paul718e3742002-12-13 20:15:29 +00001728
hassoe0701b72004-05-20 09:19:34 +00001729 {
paul5228ad22004-06-04 17:58:18 +00001730 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001731
1732 if (safi == SAFI_MPLS_VPN)
1733 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001734
1735 ndata[0] = (afi >> 8);
1736 ndata[1] = afi;
1737 ndata[2] = safi;
1738 ndata[3] = (peer->pmax[afi][safi] >> 24);
1739 ndata[4] = (peer->pmax[afi][safi] >> 16);
1740 ndata[5] = (peer->pmax[afi][safi] >> 8);
1741 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001742
1743 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1744 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1745 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1746 }
hasso0a486e52005-02-01 20:57:17 +00001747
1748 /* restart timer start */
1749 if (peer->pmax_restart[afi][safi])
1750 {
1751 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1752
1753 if (BGP_DEBUG (events, EVENTS))
1754 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1755 peer->host, peer->v_pmax_restart);
1756
1757 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1758 peer->v_pmax_restart);
1759 }
1760
hassoe0701b72004-05-20 09:19:34 +00001761 return 1;
paul718e3742002-12-13 20:15:29 +00001762 }
hassoe0701b72004-05-20 09:19:34 +00001763 else
1764 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1765
1766 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1767 {
1768 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1769 && ! always)
1770 return 0;
1771
1772 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001773 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1774 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1775 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001776 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1777 }
1778 else
1779 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001780 return 0;
1781}
1782
paulb40d9392005-08-22 22:34:41 +00001783/* Unconditionally remove the route from the RIB, without taking
1784 * damping into consideration (eg, because the session went down)
1785 */
paul94f2b392005-06-28 12:44:16 +00001786static void
paul718e3742002-12-13 20:15:29 +00001787bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1788 afi_t afi, safi_t safi)
1789{
paul902212c2006-02-05 17:51:19 +00001790 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1791
1792 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1793 bgp_info_delete (rn, ri); /* keep historical info */
1794
paulb40d9392005-08-22 22:34:41 +00001795 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001796}
1797
paul94f2b392005-06-28 12:44:16 +00001798static void
paul718e3742002-12-13 20:15:29 +00001799bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001800 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001801{
paul718e3742002-12-13 20:15:29 +00001802 int status = BGP_DAMP_NONE;
1803
paulb40d9392005-08-22 22:34:41 +00001804 /* apply dampening, if result is suppressed, we'll be retaining
1805 * the bgp_info in the RIB for historical reference.
1806 */
1807 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1808 && peer_sort (peer) == BGP_PEER_EBGP)
1809 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1810 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001811 {
paul902212c2006-02-05 17:51:19 +00001812 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1813 return;
1814 }
1815
1816 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001817}
1818
paul94f2b392005-06-28 12:44:16 +00001819static void
paulfee0f4c2004-09-13 05:12:46 +00001820bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1821 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1822 int sub_type, struct prefix_rd *prd, u_char *tag)
1823{
1824 struct bgp_node *rn;
1825 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001826 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001827 struct attr *attr_new;
1828 struct attr *attr_new2;
1829 struct bgp_info *ri;
1830 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001831 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001832 char buf[SU_ADDRSTRLEN];
1833
1834 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1835 if (peer == rsclient)
1836 return;
1837
1838 bgp = peer->bgp;
1839 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1840
1841 /* Check previously received route. */
1842 for (ri = rn->info; ri; ri = ri->next)
1843 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1844 break;
1845
1846 /* AS path loop check. */
1847 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1848 {
1849 reason = "as-path contains our own AS;";
1850 goto filtered;
1851 }
1852
1853 /* Route reflector originator ID check. */
1854 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001855 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001856 {
1857 reason = "originator is us;";
1858 goto filtered;
1859 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001860
1861 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001862
1863 /* Apply export policy. */
1864 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1865 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1866 {
1867 reason = "export-policy;";
1868 goto filtered;
1869 }
1870
1871 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001872
paulfee0f4c2004-09-13 05:12:46 +00001873 /* Apply import policy. */
1874 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1875 {
1876 bgp_attr_unintern (attr_new2);
1877
1878 reason = "import-policy;";
1879 goto filtered;
1880 }
1881
1882 attr_new = bgp_attr_intern (&new_attr);
1883 bgp_attr_unintern (attr_new2);
1884
1885 /* IPv4 unicast next hop check. */
1886 if (afi == AFI_IP && safi == SAFI_UNICAST)
1887 {
1888 /* Next hop must not be 0.0.0.0 nor Class E address. */
1889 if (new_attr.nexthop.s_addr == 0
1890 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1891 {
1892 bgp_attr_unintern (attr_new);
1893
1894 reason = "martian next-hop;";
1895 goto filtered;
1896 }
1897 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001898
1899 /* new_attr isn't passed to any functions after here */
1900 bgp_attr_extra_free (&new_attr);
1901
paulfee0f4c2004-09-13 05:12:46 +00001902 /* If the update is implicit withdraw. */
1903 if (ri)
1904 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001905 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001906
1907 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001908 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1909 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001910 {
1911
Paul Jakma1a392d42006-09-07 00:24:49 +00001912 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001913
1914 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001915 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001916 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1917 peer->host,
1918 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1919 p->prefixlen, rsclient->host);
1920
Chris Caputo228da422009-07-18 05:44:03 +00001921 bgp_unlock_node (rn);
1922 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001923
Chris Caputo228da422009-07-18 05:44:03 +00001924 return;
paulfee0f4c2004-09-13 05:12:46 +00001925 }
1926
Paul Jakma16d2e242007-04-10 19:32:10 +00001927 /* Withdraw/Announce before we fully processed the withdraw */
1928 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1929 bgp_info_restore (rn, ri);
1930
paulfee0f4c2004-09-13 05:12:46 +00001931 /* Received Logging. */
1932 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001933 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001934 peer->host,
1935 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1936 p->prefixlen, rsclient->host);
1937
1938 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001939 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001940
1941 /* Update to new attribute. */
1942 bgp_attr_unintern (ri->attr);
1943 ri->attr = attr_new;
1944
1945 /* Update MPLS tag. */
1946 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001947 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001948
Paul Jakma1a392d42006-09-07 00:24:49 +00001949 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001950
1951 /* Process change. */
1952 bgp_process (bgp, rn, afi, safi);
1953 bgp_unlock_node (rn);
1954
1955 return;
1956 }
1957
1958 /* Received Logging. */
1959 if (BGP_DEBUG (update, UPDATE_IN))
1960 {
ajsd2c1f162004-12-08 21:10:20 +00001961 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001962 peer->host,
1963 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1964 p->prefixlen, rsclient->host);
1965 }
1966
1967 /* Make new BGP info. */
1968 new = bgp_info_new ();
1969 new->type = type;
1970 new->sub_type = sub_type;
1971 new->peer = peer;
1972 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001973 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001974
1975 /* Update MPLS tag. */
1976 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001977 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001978
Paul Jakma1a392d42006-09-07 00:24:49 +00001979 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001980
1981 /* Register new BGP information. */
1982 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001983
1984 /* route_node_get lock */
1985 bgp_unlock_node (rn);
1986
paulfee0f4c2004-09-13 05:12:46 +00001987 /* Process change. */
1988 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001989
1990 bgp_attr_extra_free (&new_attr);
1991
paulfee0f4c2004-09-13 05:12:46 +00001992 return;
1993
1994 filtered:
1995
1996 /* This BGP update is filtered. Log the reason then update BGP entry. */
1997 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001998 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001999 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2000 peer->host,
2001 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2002 p->prefixlen, rsclient->host, reason);
2003
2004 if (ri)
paulb40d9392005-08-22 22:34:41 +00002005 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002006
2007 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002008
2009 if (new_attr.extra)
2010 bgp_attr_extra_free (&new_attr);
2011
paulfee0f4c2004-09-13 05:12:46 +00002012 return;
2013}
2014
paul94f2b392005-06-28 12:44:16 +00002015static void
paulfee0f4c2004-09-13 05:12:46 +00002016bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2017 struct peer *peer, struct prefix *p, int type, int sub_type,
2018 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002019{
paulfee0f4c2004-09-13 05:12:46 +00002020 struct bgp_node *rn;
2021 struct bgp_info *ri;
2022 char buf[SU_ADDRSTRLEN];
2023
2024 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002025 return;
paulfee0f4c2004-09-13 05:12:46 +00002026
2027 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2028
2029 /* Lookup withdrawn route. */
2030 for (ri = rn->info; ri; ri = ri->next)
2031 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2032 break;
2033
2034 /* Withdraw specified route from routing table. */
2035 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002036 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002037 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002038 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002039 "%s Can't find the route %s/%d", peer->host,
2040 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2041 p->prefixlen);
2042
2043 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002044 bgp_unlock_node (rn);
2045}
paulfee0f4c2004-09-13 05:12:46 +00002046
paul94f2b392005-06-28 12:44:16 +00002047static int
paulfee0f4c2004-09-13 05:12:46 +00002048bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002049 afi_t afi, safi_t safi, int type, int sub_type,
2050 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2051{
2052 int ret;
2053 int aspath_loop_count = 0;
2054 struct bgp_node *rn;
2055 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002056 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002057 struct attr *attr_new;
2058 struct bgp_info *ri;
2059 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002060 const char *reason;
paul718e3742002-12-13 20:15:29 +00002061 char buf[SU_ADDRSTRLEN];
2062
2063 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002064 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002065
paul718e3742002-12-13 20:15:29 +00002066 /* When peer's soft reconfiguration enabled. Record input packet in
2067 Adj-RIBs-In. */
2068 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2069 && peer != bgp->peer_self && ! soft_reconfig)
2070 bgp_adj_in_set (rn, peer, attr);
2071
2072 /* Check previously received route. */
2073 for (ri = rn->info; ri; ri = ri->next)
2074 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2075 break;
2076
2077 /* AS path local-as loop check. */
2078 if (peer->change_local_as)
2079 {
2080 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2081 aspath_loop_count = 1;
2082
2083 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2084 {
2085 reason = "as-path contains our own AS;";
2086 goto filtered;
2087 }
2088 }
2089
2090 /* AS path loop check. */
2091 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2092 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2093 && aspath_loop_check(attr->aspath, bgp->confed_id)
2094 > peer->allowas_in[afi][safi]))
2095 {
2096 reason = "as-path contains our own AS;";
2097 goto filtered;
2098 }
2099
2100 /* Route reflector originator ID check. */
2101 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002102 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002103 {
2104 reason = "originator is us;";
2105 goto filtered;
2106 }
2107
2108 /* Route reflector cluster ID check. */
2109 if (bgp_cluster_filter (peer, attr))
2110 {
2111 reason = "reflected from the same cluster;";
2112 goto filtered;
2113 }
2114
2115 /* Apply incoming filter. */
2116 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2117 {
2118 reason = "filter;";
2119 goto filtered;
2120 }
2121
2122 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002123 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002124
2125 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2126 {
2127 reason = "route-map;";
2128 goto filtered;
2129 }
2130
2131 /* IPv4 unicast next hop check. */
2132 if (afi == AFI_IP && safi == SAFI_UNICAST)
2133 {
2134 /* If the peer is EBGP and nexthop is not on connected route,
2135 discard it. */
2136 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2137 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002138 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002139 {
2140 reason = "non-connected next-hop;";
2141 goto filtered;
2142 }
2143
2144 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2145 must not be my own address. */
2146 if (bgp_nexthop_self (afi, &new_attr)
2147 || new_attr.nexthop.s_addr == 0
2148 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2149 {
2150 reason = "martian next-hop;";
2151 goto filtered;
2152 }
2153 }
2154
2155 attr_new = bgp_attr_intern (&new_attr);
2156
2157 /* If the update is implicit withdraw. */
2158 if (ri)
2159 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002160 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002161
2162 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002163 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2164 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002165 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002166 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002167
2168 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2169 && peer_sort (peer) == BGP_PEER_EBGP
2170 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2171 {
2172 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002173 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002174 peer->host,
2175 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2176 p->prefixlen);
2177
paul902212c2006-02-05 17:51:19 +00002178 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2179 {
2180 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2181 bgp_process (bgp, rn, afi, safi);
2182 }
paul718e3742002-12-13 20:15:29 +00002183 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002184 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002185 {
2186 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002187 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002188 "%s rcvd %s/%d...duplicate ignored",
2189 peer->host,
2190 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2191 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002192
2193 /* graceful restart STALE flag unset. */
2194 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2195 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002196 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002197 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002198 }
paul718e3742002-12-13 20:15:29 +00002199 }
2200
2201 bgp_unlock_node (rn);
2202 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002203 bgp_attr_extra_free (&new_attr);
2204
paul718e3742002-12-13 20:15:29 +00002205 return 0;
2206 }
2207
Paul Jakma16d2e242007-04-10 19:32:10 +00002208 /* Withdraw/Announce before we fully processed the withdraw */
2209 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2210 {
2211 if (BGP_DEBUG (update, UPDATE_IN))
2212 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2213 peer->host,
2214 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2215 p->prefixlen);
2216 bgp_info_restore (rn, ri);
2217 }
2218
paul718e3742002-12-13 20:15:29 +00002219 /* Received Logging. */
2220 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002221 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002222 peer->host,
2223 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2224 p->prefixlen);
2225
hasso93406d82005-02-02 14:40:33 +00002226 /* graceful restart STALE flag unset. */
2227 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002228 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002229
paul718e3742002-12-13 20:15:29 +00002230 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002231 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002232
2233 /* implicit withdraw, decrement aggregate and pcount here.
2234 * only if update is accepted, they'll increment below.
2235 */
paul902212c2006-02-05 17:51:19 +00002236 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2237
paul718e3742002-12-13 20:15:29 +00002238 /* Update bgp route dampening information. */
2239 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2240 && peer_sort (peer) == BGP_PEER_EBGP)
2241 {
2242 /* This is implicit withdraw so we should update dampening
2243 information. */
2244 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2245 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002246 }
2247
paul718e3742002-12-13 20:15:29 +00002248 /* Update to new attribute. */
2249 bgp_attr_unintern (ri->attr);
2250 ri->attr = attr_new;
2251
2252 /* Update MPLS tag. */
2253 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002254 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002255
2256 /* Update bgp route dampening information. */
2257 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2258 && peer_sort (peer) == BGP_PEER_EBGP)
2259 {
2260 /* Now we do normal update dampening. */
2261 ret = bgp_damp_update (ri, rn, afi, safi);
2262 if (ret == BGP_DAMP_SUPPRESSED)
2263 {
2264 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002265 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002266 return 0;
2267 }
2268 }
2269
2270 /* Nexthop reachability check. */
2271 if ((afi == AFI_IP || afi == AFI_IP6)
2272 && safi == SAFI_UNICAST
2273 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002274 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002275 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002276 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002277 {
2278 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002279 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002280 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002281 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002282 }
2283 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002284 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002285
2286 /* Process change. */
2287 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2288
2289 bgp_process (bgp, rn, afi, safi);
2290 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002291 bgp_attr_extra_free (&new_attr);
2292
paul718e3742002-12-13 20:15:29 +00002293 return 0;
2294 }
2295
2296 /* Received Logging. */
2297 if (BGP_DEBUG (update, UPDATE_IN))
2298 {
ajsd2c1f162004-12-08 21:10:20 +00002299 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002300 peer->host,
2301 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2302 p->prefixlen);
2303 }
2304
paul718e3742002-12-13 20:15:29 +00002305 /* Make new BGP info. */
2306 new = bgp_info_new ();
2307 new->type = type;
2308 new->sub_type = sub_type;
2309 new->peer = peer;
2310 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002311 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002312
2313 /* Update MPLS tag. */
2314 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002315 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002316
2317 /* Nexthop reachability check. */
2318 if ((afi == AFI_IP || afi == AFI_IP6)
2319 && safi == SAFI_UNICAST
2320 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002321 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002322 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002323 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002324 {
2325 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002326 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002327 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002328 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002329 }
2330 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002331 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002332
paul902212c2006-02-05 17:51:19 +00002333 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002334 bgp_aggregate_increment (bgp, p, new, afi, safi);
2335
2336 /* Register new BGP information. */
2337 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002338
2339 /* route_node_get lock */
2340 bgp_unlock_node (rn);
2341
Paul Jakmafb982c22007-05-04 20:15:47 +00002342 bgp_attr_extra_free (&new_attr);
2343
paul718e3742002-12-13 20:15:29 +00002344 /* If maximum prefix count is configured and current prefix
2345 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002346 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2347 return -1;
paul718e3742002-12-13 20:15:29 +00002348
2349 /* Process change. */
2350 bgp_process (bgp, rn, afi, safi);
2351
2352 return 0;
2353
2354 /* This BGP update is filtered. Log the reason then update BGP
2355 entry. */
2356 filtered:
2357 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002358 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002359 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2360 peer->host,
2361 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2362 p->prefixlen, reason);
2363
2364 if (ri)
paulb40d9392005-08-22 22:34:41 +00002365 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002366
2367 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002368
2369 bgp_attr_extra_free (&new_attr);
2370
paul718e3742002-12-13 20:15:29 +00002371 return 0;
2372}
2373
2374int
paulfee0f4c2004-09-13 05:12:46 +00002375bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2376 afi_t afi, safi_t safi, int type, int sub_type,
2377 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2378{
2379 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002380 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002381 struct bgp *bgp;
2382 int ret;
2383
2384 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2385 soft_reconfig);
2386
2387 bgp = peer->bgp;
2388
2389 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002390 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002391 {
2392 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2393 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2394 sub_type, prd, tag);
2395 }
2396
2397 return ret;
2398}
2399
2400int
paul718e3742002-12-13 20:15:29 +00002401bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002402 afi_t afi, safi_t safi, int type, int sub_type,
2403 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002404{
2405 struct bgp *bgp;
2406 char buf[SU_ADDRSTRLEN];
2407 struct bgp_node *rn;
2408 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002409 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002410 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002411
2412 bgp = peer->bgp;
2413
paulfee0f4c2004-09-13 05:12:46 +00002414 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002415 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002416 {
2417 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2418 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2419 }
2420
paul718e3742002-12-13 20:15:29 +00002421 /* Logging. */
2422 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002423 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002424 peer->host,
2425 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2426 p->prefixlen);
2427
2428 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002429 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002430
2431 /* If peer is soft reconfiguration enabled. Record input packet for
2432 further calculation. */
2433 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2434 && peer != bgp->peer_self)
2435 bgp_adj_in_unset (rn, peer);
2436
2437 /* Lookup withdrawn route. */
2438 for (ri = rn->info; ri; ri = ri->next)
2439 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2440 break;
2441
2442 /* Withdraw specified route from routing table. */
2443 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002444 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002445 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002446 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002447 "%s Can't find the route %s/%d", peer->host,
2448 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2449 p->prefixlen);
2450
2451 /* Unlock bgp_node_get() lock. */
2452 bgp_unlock_node (rn);
2453
2454 return 0;
2455}
2456
2457void
2458bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2459{
2460 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002461 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002462 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002463 struct prefix p;
2464 struct bgp_info binfo;
2465 struct peer *from;
2466 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002467
Paul Jakmab2497022007-06-14 11:17:58 +00002468 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002469 return;
2470
paul718e3742002-12-13 20:15:29 +00002471 bgp = peer->bgp;
2472 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002473
paul718e3742002-12-13 20:15:29 +00002474 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2475 aspath = attr.aspath;
2476 attr.local_pref = bgp->default_local_pref;
2477 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2478
2479 if (afi == AFI_IP)
2480 str2prefix ("0.0.0.0/0", &p);
2481#ifdef HAVE_IPV6
2482 else if (afi == AFI_IP6)
2483 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002484 struct attr_extra *ae;
2485 attr.extra = NULL;
2486
2487 ae = bgp_attr_extra_get (&attr);
2488 attr.extra = ae;
2489
paul718e3742002-12-13 20:15:29 +00002490 str2prefix ("::/0", &p);
2491
2492 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002493 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002494 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002495 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002496
2497 /* If the peer is on shared nextwork and we have link-local
2498 nexthop set it. */
2499 if (peer->shared_network
2500 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2501 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002502 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002503 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002504 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002505 }
2506 }
2507#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002508
2509 if (peer->default_rmap[afi][safi].name)
2510 {
2511 binfo.peer = bgp->peer_self;
2512 binfo.attr = &attr;
2513
paulfee0f4c2004-09-13 05:12:46 +00002514 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2515
paul718e3742002-12-13 20:15:29 +00002516 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2517 RMAP_BGP, &binfo);
2518
paulfee0f4c2004-09-13 05:12:46 +00002519 bgp->peer_self->rmap_type = 0;
2520
paul718e3742002-12-13 20:15:29 +00002521 if (ret == RMAP_DENYMATCH)
2522 {
2523 bgp_attr_flush (&attr);
2524 withdraw = 1;
2525 }
2526 }
2527
2528 if (withdraw)
2529 {
2530 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2531 bgp_default_withdraw_send (peer, afi, safi);
2532 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2533 }
2534 else
2535 {
2536 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2537 bgp_default_update_send (peer, &attr, afi, safi, from);
2538 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002539
2540 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002541 aspath_unintern (aspath);
2542}
2543
2544static void
2545bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002546 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002547{
2548 struct bgp_node *rn;
2549 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002550 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002551
paul718e3742002-12-13 20:15:29 +00002552 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002553 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002554
2555 if (safi != SAFI_MPLS_VPN
2556 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2557 bgp_default_originate (peer, afi, safi, 0);
2558
2559 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2560 for (ri = rn->info; ri; ri = ri->next)
2561 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2562 {
paulfee0f4c2004-09-13 05:12:46 +00002563 if ( (rsclient) ?
2564 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2565 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002566 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2567 else
2568 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002569
2570 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002571 }
2572}
2573
2574void
2575bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2576{
2577 struct bgp_node *rn;
2578 struct bgp_table *table;
2579
2580 if (peer->status != Established)
2581 return;
2582
2583 if (! peer->afc_nego[afi][safi])
2584 return;
2585
2586 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2587 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2588 return;
2589
2590 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002591 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002592 else
2593 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2594 rn = bgp_route_next(rn))
2595 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002596 bgp_announce_table (peer, afi, safi, table, 0);
2597
2598 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2599 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002600}
2601
2602void
2603bgp_announce_route_all (struct peer *peer)
2604{
2605 afi_t afi;
2606 safi_t safi;
2607
2608 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2609 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2610 bgp_announce_route (peer, afi, safi);
2611}
2612
2613static void
paulfee0f4c2004-09-13 05:12:46 +00002614bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2615 safi_t safi, struct bgp_table *table)
2616{
2617 struct bgp_node *rn;
2618 struct bgp_adj_in *ain;
2619
2620 if (! table)
2621 table = rsclient->bgp->rib[afi][safi];
2622
2623 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2624 for (ain = rn->adj_in; ain; ain = ain->next)
2625 {
2626 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2627 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2628 }
2629}
2630
2631void
2632bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2633{
2634 struct bgp_table *table;
2635 struct bgp_node *rn;
2636
2637 if (safi != SAFI_MPLS_VPN)
2638 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2639
2640 else
2641 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2642 rn = bgp_route_next (rn))
2643 if ((table = rn->info) != NULL)
2644 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2645}
2646
2647static void
paul718e3742002-12-13 20:15:29 +00002648bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2649 struct bgp_table *table)
2650{
2651 int ret;
2652 struct bgp_node *rn;
2653 struct bgp_adj_in *ain;
2654
2655 if (! table)
2656 table = peer->bgp->rib[afi][safi];
2657
2658 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2659 for (ain = rn->adj_in; ain; ain = ain->next)
2660 {
2661 if (ain->peer == peer)
2662 {
2663 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2664 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2665 NULL, NULL, 1);
2666 if (ret < 0)
2667 {
2668 bgp_unlock_node (rn);
2669 return;
2670 }
2671 continue;
2672 }
2673 }
2674}
2675
2676void
2677bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2678{
2679 struct bgp_node *rn;
2680 struct bgp_table *table;
2681
2682 if (peer->status != Established)
2683 return;
2684
2685 if (safi != SAFI_MPLS_VPN)
2686 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2687 else
2688 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2689 rn = bgp_route_next (rn))
2690 if ((table = rn->info) != NULL)
2691 bgp_soft_reconfig_table (peer, afi, safi, table);
2692}
2693
Chris Caputo228da422009-07-18 05:44:03 +00002694
2695struct bgp_clear_node_queue
2696{
2697 struct bgp_node *rn;
2698 enum bgp_clear_route_type purpose;
2699};
2700
paul200df112005-06-01 11:17:05 +00002701static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002702bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002703{
Chris Caputo228da422009-07-18 05:44:03 +00002704 struct bgp_clear_node_queue *cnq = data;
2705 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002706 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002707 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002708 afi_t afi = rn->table->afi;
2709 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002710
Paul Jakma64e580a2006-02-21 01:09:01 +00002711 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002712
Paul Jakma64e580a2006-02-21 01:09:01 +00002713 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002714 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002715 {
2716 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002717 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2718 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002719 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002720 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2721 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002722 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002723 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002724 break;
2725 }
paul200df112005-06-01 11:17:05 +00002726 return WQ_SUCCESS;
2727}
2728
2729static void
paul0fb58d52005-11-14 14:31:49 +00002730bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002731{
Chris Caputo228da422009-07-18 05:44:03 +00002732 struct bgp_clear_node_queue *cnq = data;
2733 struct bgp_node *rn = cnq->rn;
2734 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002735
2736 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002737 bgp_table_unlock (table);
2738 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002739}
2740
2741static void
paul94f2b392005-06-28 12:44:16 +00002742bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002743{
Paul Jakma64e580a2006-02-21 01:09:01 +00002744 struct peer *peer = wq->spec.data;
2745
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002746 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002747 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002748
2749 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002750}
2751
2752static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002753bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002754{
Paul Jakmaa2943652009-07-21 14:02:04 +01002755 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002756
Paul Jakmaa2943652009-07-21 14:02:04 +01002757 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002758#undef CLEAR_QUEUE_NAME_LEN
2759
2760 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002761 {
2762 zlog_err ("%s: Failed to allocate work queue", __func__);
2763 exit (1);
2764 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002765 peer->clear_node_queue->spec.hold = 10;
2766 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2767 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2768 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2769 peer->clear_node_queue->spec.max_retries = 0;
2770
2771 /* we only 'lock' this peer reference when the queue is actually active */
2772 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002773}
2774
paul718e3742002-12-13 20:15:29 +00002775static void
2776bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002777 struct bgp_table *table, struct peer *rsclient,
2778 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002779{
2780 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002781
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002782
paul718e3742002-12-13 20:15:29 +00002783 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002784 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002785
hasso6cf159b2005-03-21 10:28:14 +00002786 /* If still no table => afi/safi isn't configured at all or smth. */
2787 if (! table)
2788 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002789
2790 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2791 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002792 struct bgp_info *ri;
2793 struct bgp_adj_in *ain;
2794 struct bgp_adj_out *aout;
2795
Paul Jakma65ca75e2006-05-04 08:08:15 +00002796 if (rn->info == NULL)
2797 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002798
2799 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2800 * queued for every clearing peer, regardless of whether it is
2801 * relevant to the peer at hand.
2802 *
2803 * Overview: There are 3 different indices which need to be
2804 * scrubbed, potentially, when a peer is removed:
2805 *
2806 * 1 peer's routes visible via the RIB (ie accepted routes)
2807 * 2 peer's routes visible by the (optional) peer's adj-in index
2808 * 3 other routes visible by the peer's adj-out index
2809 *
2810 * 3 there is no hurry in scrubbing, once the struct peer is
2811 * removed from bgp->peer, we could just GC such deleted peer's
2812 * adj-outs at our leisure.
2813 *
2814 * 1 and 2 must be 'scrubbed' in some way, at least made
2815 * invisible via RIB index before peer session is allowed to be
2816 * brought back up. So one needs to know when such a 'search' is
2817 * complete.
2818 *
2819 * Ideally:
2820 *
2821 * - there'd be a single global queue or a single RIB walker
2822 * - rather than tracking which route_nodes still need to be
2823 * examined on a peer basis, we'd track which peers still
2824 * aren't cleared
2825 *
2826 * Given that our per-peer prefix-counts now should be reliable,
2827 * this may actually be achievable. It doesn't seem to be a huge
2828 * problem at this time,
2829 */
2830 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002831 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002832 {
Chris Caputo228da422009-07-18 05:44:03 +00002833 struct bgp_clear_node_queue *cnq;
2834
2835 /* both unlocked in bgp_clear_node_queue_del */
2836 bgp_table_lock (rn->table);
2837 bgp_lock_node (rn);
2838 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2839 sizeof (struct bgp_clear_node_queue));
2840 cnq->rn = rn;
2841 cnq->purpose = purpose;
2842 work_queue_add (peer->clear_node_queue, cnq);
2843 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002844 }
2845
2846 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002847 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002848 {
2849 bgp_adj_in_remove (rn, ain);
2850 bgp_unlock_node (rn);
2851 break;
2852 }
2853 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002854 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002855 {
2856 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2857 bgp_unlock_node (rn);
2858 break;
2859 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002860 }
2861 return;
2862}
2863
2864void
Chris Caputo228da422009-07-18 05:44:03 +00002865bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2866 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002867{
2868 struct bgp_node *rn;
2869 struct bgp_table *table;
2870 struct peer *rsclient;
2871 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002872
Paul Jakma64e580a2006-02-21 01:09:01 +00002873 if (peer->clear_node_queue == NULL)
2874 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002875
Paul Jakmaca058a32006-09-14 02:58:49 +00002876 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2877 * Idle until it receives a Clearing_Completed event. This protects
2878 * against peers which flap faster than we can we clear, which could
2879 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002880 *
2881 * a) race with routes from the new session being installed before
2882 * clear_route_node visits the node (to delete the route of that
2883 * peer)
2884 * b) resource exhaustion, clear_route_node likely leads to an entry
2885 * on the process_main queue. Fast-flapping could cause that queue
2886 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002887 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002888 if (!peer->clear_node_queue->thread)
2889 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002890
Chris Caputo228da422009-07-18 05:44:03 +00002891 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002892 {
Chris Caputo228da422009-07-18 05:44:03 +00002893 case BGP_CLEAR_ROUTE_NORMAL:
2894 if (safi != SAFI_MPLS_VPN)
2895 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2896 else
2897 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2898 rn = bgp_route_next (rn))
2899 if ((table = rn->info) != NULL)
2900 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2901
2902 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2903 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2904 PEER_FLAG_RSERVER_CLIENT))
2905 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2906 break;
2907
2908 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2909 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2910 break;
2911
2912 default:
2913 assert (0);
2914 break;
paulfee0f4c2004-09-13 05:12:46 +00002915 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002916
Paul Jakmaca058a32006-09-14 02:58:49 +00002917 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002918 * completion function won't be run by workqueue code - call it here.
2919 * XXX: Actually, this assumption doesn't hold, see
2920 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002921 *
2922 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002923 * really needed if peer state is Established - peers in
2924 * pre-Established states shouldn't have any route-update state
2925 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002926 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002927 * We still can get here in pre-Established though, through
2928 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2929 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002930 *
2931 * At some future point, this check could be move to the top of the
2932 * function, and do a quick early-return when state is
2933 * pre-Established, avoiding above list and table scans. Once we're
2934 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002935 */
2936 if (!peer->clear_node_queue->thread)
2937 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002938}
2939
2940void
2941bgp_clear_route_all (struct peer *peer)
2942{
2943 afi_t afi;
2944 safi_t safi;
2945
2946 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2947 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002948 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002949}
2950
2951void
2952bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2953{
2954 struct bgp_table *table;
2955 struct bgp_node *rn;
2956 struct bgp_adj_in *ain;
2957
2958 table = peer->bgp->rib[afi][safi];
2959
2960 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2961 for (ain = rn->adj_in; ain ; ain = ain->next)
2962 if (ain->peer == peer)
2963 {
2964 bgp_adj_in_remove (rn, ain);
2965 bgp_unlock_node (rn);
2966 break;
2967 }
2968}
hasso93406d82005-02-02 14:40:33 +00002969
2970void
2971bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2972{
2973 struct bgp_node *rn;
2974 struct bgp_info *ri;
2975 struct bgp_table *table;
2976
2977 table = peer->bgp->rib[afi][safi];
2978
2979 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2980 {
2981 for (ri = rn->info; ri; ri = ri->next)
2982 if (ri->peer == peer)
2983 {
2984 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2985 bgp_rib_remove (rn, ri, peer, afi, safi);
2986 break;
2987 }
2988 }
2989}
paul718e3742002-12-13 20:15:29 +00002990
2991/* Delete all kernel routes. */
2992void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002993bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002994{
2995 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002996 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002997 struct bgp_node *rn;
2998 struct bgp_table *table;
2999 struct bgp_info *ri;
3000
paul1eb8ef22005-04-07 07:30:20 +00003001 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003002 {
3003 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3004
3005 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3006 for (ri = rn->info; ri; ri = ri->next)
3007 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3008 && ri->type == ZEBRA_ROUTE_BGP
3009 && ri->sub_type == BGP_ROUTE_NORMAL)
3010 bgp_zebra_withdraw (&rn->p, ri);
3011
3012 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3013
3014 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3015 for (ri = rn->info; ri; ri = ri->next)
3016 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3017 && ri->type == ZEBRA_ROUTE_BGP
3018 && ri->sub_type == BGP_ROUTE_NORMAL)
3019 bgp_zebra_withdraw (&rn->p, ri);
3020 }
3021}
3022
3023void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003024bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003025{
3026 vty_reset ();
3027 bgp_zclient_reset ();
3028 access_list_reset ();
3029 prefix_list_reset ();
3030}
3031
3032/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3033 value. */
3034int
3035bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3036{
3037 u_char *pnt;
3038 u_char *lim;
3039 struct prefix p;
3040 int psize;
3041 int ret;
3042
3043 /* Check peer status. */
3044 if (peer->status != Established)
3045 return 0;
3046
3047 pnt = packet->nlri;
3048 lim = pnt + packet->length;
3049
3050 for (; pnt < lim; pnt += psize)
3051 {
3052 /* Clear prefix structure. */
3053 memset (&p, 0, sizeof (struct prefix));
3054
3055 /* Fetch prefix length. */
3056 p.prefixlen = *pnt++;
3057 p.family = afi2family (packet->afi);
3058
3059 /* Already checked in nlri_sanity_check(). We do double check
3060 here. */
3061 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3062 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3063 return -1;
3064
3065 /* Packet size overflow check. */
3066 psize = PSIZE (p.prefixlen);
3067
3068 /* When packet overflow occur return immediately. */
3069 if (pnt + psize > lim)
3070 return -1;
3071
3072 /* Fetch prefix from NLRI packet. */
3073 memcpy (&p.u.prefix, pnt, psize);
3074
3075 /* Check address. */
3076 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3077 {
3078 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3079 {
paulf5ba3872004-07-09 12:11:31 +00003080 /*
3081 * From draft-ietf-idr-bgp4-22, Section 6.3:
3082 * If a BGP router receives an UPDATE message with a
3083 * semantically incorrect NLRI field, in which a prefix is
3084 * semantically incorrect (eg. an unexpected multicast IP
3085 * address), it should ignore the prefix.
3086 */
paul718e3742002-12-13 20:15:29 +00003087 zlog (peer->log, LOG_ERR,
3088 "IPv4 unicast NLRI is multicast address %s",
3089 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003090
paul718e3742002-12-13 20:15:29 +00003091 return -1;
3092 }
3093 }
3094
3095#ifdef HAVE_IPV6
3096 /* Check address. */
3097 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3098 {
3099 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3100 {
3101 char buf[BUFSIZ];
3102
3103 zlog (peer->log, LOG_WARNING,
3104 "IPv6 link-local NLRI received %s ignore this NLRI",
3105 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3106
3107 continue;
3108 }
3109 }
3110#endif /* HAVE_IPV6 */
3111
3112 /* Normal process. */
3113 if (attr)
3114 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3115 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3116 else
3117 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3118 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3119
3120 /* Address family configuration mismatch or maximum-prefix count
3121 overflow. */
3122 if (ret < 0)
3123 return -1;
3124 }
3125
3126 /* Packet length consistency check. */
3127 if (pnt != lim)
3128 return -1;
3129
3130 return 0;
3131}
3132
3133/* NLRI encode syntax check routine. */
3134int
3135bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3136 bgp_size_t length)
3137{
3138 u_char *end;
3139 u_char prefixlen;
3140 int psize;
3141
3142 end = pnt + length;
3143
3144 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3145 syntactic validity. If the field is syntactically incorrect,
3146 then the Error Subcode is set to Invalid Network Field. */
3147
3148 while (pnt < end)
3149 {
3150 prefixlen = *pnt++;
3151
3152 /* Prefix length check. */
3153 if ((afi == AFI_IP && prefixlen > 32)
3154 || (afi == AFI_IP6 && prefixlen > 128))
3155 {
3156 plog_err (peer->log,
3157 "%s [Error] Update packet error (wrong prefix length %d)",
3158 peer->host, prefixlen);
3159 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3160 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3161 return -1;
3162 }
3163
3164 /* Packet size overflow check. */
3165 psize = PSIZE (prefixlen);
3166
3167 if (pnt + psize > end)
3168 {
3169 plog_err (peer->log,
3170 "%s [Error] Update packet error"
3171 " (prefix data overflow prefix size is %d)",
3172 peer->host, psize);
3173 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3174 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3175 return -1;
3176 }
3177
3178 pnt += psize;
3179 }
3180
3181 /* Packet length consistency check. */
3182 if (pnt != end)
3183 {
3184 plog_err (peer->log,
3185 "%s [Error] Update packet error"
3186 " (prefix length mismatch with total length)",
3187 peer->host);
3188 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3189 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3190 return -1;
3191 }
3192 return 0;
3193}
3194
paul94f2b392005-06-28 12:44:16 +00003195static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003196bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003197{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003198 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003199}
3200
paul94f2b392005-06-28 12:44:16 +00003201static void
paul718e3742002-12-13 20:15:29 +00003202bgp_static_free (struct bgp_static *bgp_static)
3203{
3204 if (bgp_static->rmap.name)
3205 free (bgp_static->rmap.name);
3206 XFREE (MTYPE_BGP_STATIC, bgp_static);
3207}
3208
paul94f2b392005-06-28 12:44:16 +00003209static void
paulfee0f4c2004-09-13 05:12:46 +00003210bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3211 struct prefix *p, afi_t afi, safi_t safi)
3212{
3213 struct bgp_node *rn;
3214 struct bgp_info *ri;
3215
3216 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3217
3218 /* Check selected route and self inserted route. */
3219 for (ri = rn->info; ri; ri = ri->next)
3220 if (ri->peer == bgp->peer_self
3221 && ri->type == ZEBRA_ROUTE_BGP
3222 && ri->sub_type == BGP_ROUTE_STATIC)
3223 break;
3224
3225 /* Withdraw static BGP route from routing table. */
3226 if (ri)
3227 {
paulfee0f4c2004-09-13 05:12:46 +00003228 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003229 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003230 }
3231
3232 /* Unlock bgp_node_lookup. */
3233 bgp_unlock_node (rn);
3234}
3235
paul94f2b392005-06-28 12:44:16 +00003236static void
paulfee0f4c2004-09-13 05:12:46 +00003237bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003238 struct bgp_static *bgp_static,
3239 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003240{
3241 struct bgp_node *rn;
3242 struct bgp_info *ri;
3243 struct bgp_info *new;
3244 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003245 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003246 struct attr attr = {0 };
3247 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003248 struct bgp *bgp;
3249 int ret;
3250 char buf[SU_ADDRSTRLEN];
3251
3252 bgp = rsclient->bgp;
3253
Paul Jakma06e110f2006-05-12 23:29:22 +00003254 assert (bgp_static);
3255 if (!bgp_static)
3256 return;
3257
paulfee0f4c2004-09-13 05:12:46 +00003258 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3259
3260 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003261
3262 attr.nexthop = bgp_static->igpnexthop;
3263 attr.med = bgp_static->igpmetric;
3264 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003265
Paul Jakma41367172007-08-06 15:24:51 +00003266 if (bgp_static->atomic)
3267 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3268
paulfee0f4c2004-09-13 05:12:46 +00003269 /* Apply network route-map for export to this rsclient. */
3270 if (bgp_static->rmap.name)
3271 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003272 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003273 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003274 info.attr = &attr_tmp;
3275
paulfee0f4c2004-09-13 05:12:46 +00003276 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3277 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3278
3279 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3280
3281 rsclient->rmap_type = 0;
3282
3283 if (ret == RMAP_DENYMATCH)
3284 {
3285 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003286 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003287
3288 /* Unintern original. */
3289 aspath_unintern (attr.aspath);
3290 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003291 bgp_attr_extra_free (&attr);
3292
paulfee0f4c2004-09-13 05:12:46 +00003293 return;
3294 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003295 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003296 }
3297 else
3298 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003299
Stephen Hemminger7badc262010-08-05 10:26:31 -07003300 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003301
paulfee0f4c2004-09-13 05:12:46 +00003302 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3303
Paul Jakmafb982c22007-05-04 20:15:47 +00003304 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3305 == RMAP_DENY)
3306 {
paulfee0f4c2004-09-13 05:12:46 +00003307 /* This BGP update is filtered. Log the reason then update BGP entry. */
3308 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003309 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003310 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3311 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3312 p->prefixlen, rsclient->host);
3313
3314 bgp->peer_self->rmap_type = 0;
3315
3316 bgp_attr_unintern (attr_new);
3317 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003318 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003319
3320 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3321
3322 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003323 }
paulfee0f4c2004-09-13 05:12:46 +00003324
3325 bgp->peer_self->rmap_type = 0;
3326
3327 bgp_attr_unintern (attr_new);
3328 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003329 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003330
3331 for (ri = rn->info; ri; ri = ri->next)
3332 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3333 && ri->sub_type == BGP_ROUTE_STATIC)
3334 break;
3335
3336 if (ri)
3337 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003338 if (attrhash_cmp (ri->attr, attr_new) &&
3339 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003340 {
3341 bgp_unlock_node (rn);
3342 bgp_attr_unintern (attr_new);
3343 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003344 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003345 return;
3346 }
3347 else
3348 {
3349 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003350 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003351
3352 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003353 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3354 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003355 bgp_attr_unintern (ri->attr);
3356 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003357 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003358
3359 /* Process change. */
3360 bgp_process (bgp, rn, afi, safi);
3361 bgp_unlock_node (rn);
3362 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003363 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003364 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003365 }
paulfee0f4c2004-09-13 05:12:46 +00003366 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003367
paulfee0f4c2004-09-13 05:12:46 +00003368 /* Make new BGP info. */
3369 new = bgp_info_new ();
3370 new->type = ZEBRA_ROUTE_BGP;
3371 new->sub_type = BGP_ROUTE_STATIC;
3372 new->peer = bgp->peer_self;
3373 SET_FLAG (new->flags, BGP_INFO_VALID);
3374 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003375 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003376
3377 /* Register new BGP information. */
3378 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003379
3380 /* route_node_get lock */
3381 bgp_unlock_node (rn);
3382
paulfee0f4c2004-09-13 05:12:46 +00003383 /* Process change. */
3384 bgp_process (bgp, rn, afi, safi);
3385
3386 /* Unintern original. */
3387 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003388 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003389}
3390
paul94f2b392005-06-28 12:44:16 +00003391static void
paulfee0f4c2004-09-13 05:12:46 +00003392bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003393 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3394{
3395 struct bgp_node *rn;
3396 struct bgp_info *ri;
3397 struct bgp_info *new;
3398 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003399 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003400 struct attr *attr_new;
3401 int ret;
3402
Paul Jakmadd8103a2006-05-12 23:27:30 +00003403 assert (bgp_static);
3404 if (!bgp_static)
3405 return;
3406
paulfee0f4c2004-09-13 05:12:46 +00003407 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003408
3409 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003410
3411 attr.nexthop = bgp_static->igpnexthop;
3412 attr.med = bgp_static->igpmetric;
3413 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003414
Paul Jakma41367172007-08-06 15:24:51 +00003415 if (bgp_static->atomic)
3416 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3417
paul718e3742002-12-13 20:15:29 +00003418 /* Apply route-map. */
3419 if (bgp_static->rmap.name)
3420 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003421 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003422 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003423 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003424
paulfee0f4c2004-09-13 05:12:46 +00003425 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3426
paul718e3742002-12-13 20:15:29 +00003427 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003428
paulfee0f4c2004-09-13 05:12:46 +00003429 bgp->peer_self->rmap_type = 0;
3430
paul718e3742002-12-13 20:15:29 +00003431 if (ret == RMAP_DENYMATCH)
3432 {
3433 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003434 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003435
3436 /* Unintern original. */
3437 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003438 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003439 bgp_static_withdraw (bgp, p, afi, safi);
3440 return;
3441 }
paul286e1e72003-08-08 00:24:31 +00003442 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003443 }
paul286e1e72003-08-08 00:24:31 +00003444 else
3445 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003446
3447 for (ri = rn->info; ri; ri = ri->next)
3448 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3449 && ri->sub_type == BGP_ROUTE_STATIC)
3450 break;
3451
3452 if (ri)
3453 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003454 if (attrhash_cmp (ri->attr, attr_new) &&
3455 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003456 {
3457 bgp_unlock_node (rn);
3458 bgp_attr_unintern (attr_new);
3459 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003460 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003461 return;
3462 }
3463 else
3464 {
3465 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003466 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003467
3468 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003469 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3470 bgp_info_restore(rn, ri);
3471 else
3472 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003473 bgp_attr_unintern (ri->attr);
3474 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003475 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003476
3477 /* Process change. */
3478 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3479 bgp_process (bgp, rn, afi, safi);
3480 bgp_unlock_node (rn);
3481 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003482 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003483 return;
3484 }
3485 }
3486
3487 /* Make new BGP info. */
3488 new = bgp_info_new ();
3489 new->type = ZEBRA_ROUTE_BGP;
3490 new->sub_type = BGP_ROUTE_STATIC;
3491 new->peer = bgp->peer_self;
3492 SET_FLAG (new->flags, BGP_INFO_VALID);
3493 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003494 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003495
3496 /* Aggregate address increment. */
3497 bgp_aggregate_increment (bgp, p, new, afi, safi);
3498
3499 /* Register new BGP information. */
3500 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003501
3502 /* route_node_get lock */
3503 bgp_unlock_node (rn);
3504
paul718e3742002-12-13 20:15:29 +00003505 /* Process change. */
3506 bgp_process (bgp, rn, afi, safi);
3507
3508 /* Unintern original. */
3509 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003510 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003511}
3512
3513void
paulfee0f4c2004-09-13 05:12:46 +00003514bgp_static_update (struct bgp *bgp, struct prefix *p,
3515 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3516{
3517 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003518 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003519
3520 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3521
paul1eb8ef22005-04-07 07:30:20 +00003522 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003523 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003524 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3525 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003526 }
3527}
3528
paul94f2b392005-06-28 12:44:16 +00003529static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003530bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3531 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003532{
3533 struct bgp_node *rn;
3534 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003535
paulfee0f4c2004-09-13 05:12:46 +00003536 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003537
3538 /* Make new BGP info. */
3539 new = bgp_info_new ();
3540 new->type = ZEBRA_ROUTE_BGP;
3541 new->sub_type = BGP_ROUTE_STATIC;
3542 new->peer = bgp->peer_self;
3543 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3544 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003545 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003546 new->extra = bgp_info_extra_new();
3547 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003548
3549 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003550 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003551
3552 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003553 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003554
paul200df112005-06-01 11:17:05 +00003555 /* route_node_get lock */
3556 bgp_unlock_node (rn);
3557
paul718e3742002-12-13 20:15:29 +00003558 /* Process change. */
3559 bgp_process (bgp, rn, afi, safi);
3560}
3561
3562void
3563bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3564 safi_t safi)
3565{
3566 struct bgp_node *rn;
3567 struct bgp_info *ri;
3568
paulfee0f4c2004-09-13 05:12:46 +00003569 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003570
3571 /* Check selected route and self inserted route. */
3572 for (ri = rn->info; ri; ri = ri->next)
3573 if (ri->peer == bgp->peer_self
3574 && ri->type == ZEBRA_ROUTE_BGP
3575 && ri->sub_type == BGP_ROUTE_STATIC)
3576 break;
3577
3578 /* Withdraw static BGP route from routing table. */
3579 if (ri)
3580 {
3581 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003582 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003583 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003584 }
3585
3586 /* Unlock bgp_node_lookup. */
3587 bgp_unlock_node (rn);
3588}
3589
3590void
paulfee0f4c2004-09-13 05:12:46 +00003591bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3592{
3593 struct bgp_static *bgp_static;
3594 struct bgp *bgp;
3595 struct bgp_node *rn;
3596 struct prefix *p;
3597
3598 bgp = rsclient->bgp;
3599
3600 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3601 if ((bgp_static = rn->info) != NULL)
3602 {
3603 p = &rn->p;
3604
3605 bgp_static_update_rsclient (rsclient, p, bgp_static,
3606 afi, safi);
3607 }
3608}
3609
paul94f2b392005-06-28 12:44:16 +00003610static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003611bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3612 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003613{
3614 struct bgp_node *rn;
3615 struct bgp_info *ri;
3616
paulfee0f4c2004-09-13 05:12:46 +00003617 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003618
3619 /* Check selected route and self inserted route. */
3620 for (ri = rn->info; ri; ri = ri->next)
3621 if (ri->peer == bgp->peer_self
3622 && ri->type == ZEBRA_ROUTE_BGP
3623 && ri->sub_type == BGP_ROUTE_STATIC)
3624 break;
3625
3626 /* Withdraw static BGP route from routing table. */
3627 if (ri)
3628 {
3629 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003630 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003631 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003632 }
3633
3634 /* Unlock bgp_node_lookup. */
3635 bgp_unlock_node (rn);
3636}
3637
3638/* Configure static BGP network. When user don't run zebra, static
3639 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003640static int
paulfd79ac92004-10-13 05:06:08 +00003641bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003642 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003643{
3644 int ret;
3645 struct prefix p;
3646 struct bgp_static *bgp_static;
3647 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003648 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003649
3650 /* Convert IP prefix string to struct prefix. */
3651 ret = str2prefix (ip_str, &p);
3652 if (! ret)
3653 {
3654 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3655 return CMD_WARNING;
3656 }
3657#ifdef HAVE_IPV6
3658 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3659 {
3660 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3661 VTY_NEWLINE);
3662 return CMD_WARNING;
3663 }
3664#endif /* HAVE_IPV6 */
3665
3666 apply_mask (&p);
3667
3668 /* Set BGP static route configuration. */
3669 rn = bgp_node_get (bgp->route[afi][safi], &p);
3670
3671 if (rn->info)
3672 {
3673 /* Configuration change. */
3674 bgp_static = rn->info;
3675
3676 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003677 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3678 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003679
paul718e3742002-12-13 20:15:29 +00003680 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003681
paul718e3742002-12-13 20:15:29 +00003682 if (rmap)
3683 {
3684 if (bgp_static->rmap.name)
3685 free (bgp_static->rmap.name);
3686 bgp_static->rmap.name = strdup (rmap);
3687 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3688 }
3689 else
3690 {
3691 if (bgp_static->rmap.name)
3692 free (bgp_static->rmap.name);
3693 bgp_static->rmap.name = NULL;
3694 bgp_static->rmap.map = NULL;
3695 bgp_static->valid = 0;
3696 }
3697 bgp_unlock_node (rn);
3698 }
3699 else
3700 {
3701 /* New configuration. */
3702 bgp_static = bgp_static_new ();
3703 bgp_static->backdoor = backdoor;
3704 bgp_static->valid = 0;
3705 bgp_static->igpmetric = 0;
3706 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003707
paul718e3742002-12-13 20:15:29 +00003708 if (rmap)
3709 {
3710 if (bgp_static->rmap.name)
3711 free (bgp_static->rmap.name);
3712 bgp_static->rmap.name = strdup (rmap);
3713 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3714 }
3715 rn->info = bgp_static;
3716 }
3717
3718 /* If BGP scan is not enabled, we should install this route here. */
3719 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3720 {
3721 bgp_static->valid = 1;
3722
3723 if (need_update)
3724 bgp_static_withdraw (bgp, &p, afi, safi);
3725
3726 if (! bgp_static->backdoor)
3727 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3728 }
3729
3730 return CMD_SUCCESS;
3731}
3732
3733/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003734static int
paulfd79ac92004-10-13 05:06:08 +00003735bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003736 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003737{
3738 int ret;
3739 struct prefix p;
3740 struct bgp_static *bgp_static;
3741 struct bgp_node *rn;
3742
3743 /* Convert IP prefix string to struct prefix. */
3744 ret = str2prefix (ip_str, &p);
3745 if (! ret)
3746 {
3747 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3748 return CMD_WARNING;
3749 }
3750#ifdef HAVE_IPV6
3751 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3752 {
3753 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3754 VTY_NEWLINE);
3755 return CMD_WARNING;
3756 }
3757#endif /* HAVE_IPV6 */
3758
3759 apply_mask (&p);
3760
3761 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3762 if (! rn)
3763 {
3764 vty_out (vty, "%% Can't find specified static route configuration.%s",
3765 VTY_NEWLINE);
3766 return CMD_WARNING;
3767 }
3768
3769 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003770
paul718e3742002-12-13 20:15:29 +00003771 /* Update BGP RIB. */
3772 if (! bgp_static->backdoor)
3773 bgp_static_withdraw (bgp, &p, afi, safi);
3774
3775 /* Clear configuration. */
3776 bgp_static_free (bgp_static);
3777 rn->info = NULL;
3778 bgp_unlock_node (rn);
3779 bgp_unlock_node (rn);
3780
3781 return CMD_SUCCESS;
3782}
3783
3784/* Called from bgp_delete(). Delete all static routes from the BGP
3785 instance. */
3786void
3787bgp_static_delete (struct bgp *bgp)
3788{
3789 afi_t afi;
3790 safi_t safi;
3791 struct bgp_node *rn;
3792 struct bgp_node *rm;
3793 struct bgp_table *table;
3794 struct bgp_static *bgp_static;
3795
3796 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3797 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3798 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3799 if (rn->info != NULL)
3800 {
3801 if (safi == SAFI_MPLS_VPN)
3802 {
3803 table = rn->info;
3804
3805 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3806 {
3807 bgp_static = rn->info;
3808 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3809 AFI_IP, SAFI_MPLS_VPN,
3810 (struct prefix_rd *)&rn->p,
3811 bgp_static->tag);
3812 bgp_static_free (bgp_static);
3813 rn->info = NULL;
3814 bgp_unlock_node (rn);
3815 }
3816 }
3817 else
3818 {
3819 bgp_static = rn->info;
3820 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3821 bgp_static_free (bgp_static);
3822 rn->info = NULL;
3823 bgp_unlock_node (rn);
3824 }
3825 }
3826}
3827
3828int
paulfd79ac92004-10-13 05:06:08 +00003829bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3830 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003831{
3832 int ret;
3833 struct prefix p;
3834 struct prefix_rd prd;
3835 struct bgp *bgp;
3836 struct bgp_node *prn;
3837 struct bgp_node *rn;
3838 struct bgp_table *table;
3839 struct bgp_static *bgp_static;
3840 u_char tag[3];
3841
3842 bgp = vty->index;
3843
3844 ret = str2prefix (ip_str, &p);
3845 if (! ret)
3846 {
3847 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3848 return CMD_WARNING;
3849 }
3850 apply_mask (&p);
3851
3852 ret = str2prefix_rd (rd_str, &prd);
3853 if (! ret)
3854 {
3855 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3856 return CMD_WARNING;
3857 }
3858
3859 ret = str2tag (tag_str, tag);
3860 if (! ret)
3861 {
3862 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3863 return CMD_WARNING;
3864 }
3865
3866 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3867 (struct prefix *)&prd);
3868 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003869 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003870 else
3871 bgp_unlock_node (prn);
3872 table = prn->info;
3873
3874 rn = bgp_node_get (table, &p);
3875
3876 if (rn->info)
3877 {
3878 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3879 bgp_unlock_node (rn);
3880 }
3881 else
3882 {
3883 /* New configuration. */
3884 bgp_static = bgp_static_new ();
3885 bgp_static->valid = 1;
3886 memcpy (bgp_static->tag, tag, 3);
3887 rn->info = bgp_static;
3888
3889 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3890 }
3891
3892 return CMD_SUCCESS;
3893}
3894
3895/* Configure static BGP network. */
3896int
paulfd79ac92004-10-13 05:06:08 +00003897bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3898 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003899{
3900 int ret;
3901 struct bgp *bgp;
3902 struct prefix p;
3903 struct prefix_rd prd;
3904 struct bgp_node *prn;
3905 struct bgp_node *rn;
3906 struct bgp_table *table;
3907 struct bgp_static *bgp_static;
3908 u_char tag[3];
3909
3910 bgp = vty->index;
3911
3912 /* Convert IP prefix string to struct prefix. */
3913 ret = str2prefix (ip_str, &p);
3914 if (! ret)
3915 {
3916 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3917 return CMD_WARNING;
3918 }
3919 apply_mask (&p);
3920
3921 ret = str2prefix_rd (rd_str, &prd);
3922 if (! ret)
3923 {
3924 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3925 return CMD_WARNING;
3926 }
3927
3928 ret = str2tag (tag_str, tag);
3929 if (! ret)
3930 {
3931 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3932 return CMD_WARNING;
3933 }
3934
3935 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3936 (struct prefix *)&prd);
3937 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003938 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003939 else
3940 bgp_unlock_node (prn);
3941 table = prn->info;
3942
3943 rn = bgp_node_lookup (table, &p);
3944
3945 if (rn)
3946 {
3947 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3948
3949 bgp_static = rn->info;
3950 bgp_static_free (bgp_static);
3951 rn->info = NULL;
3952 bgp_unlock_node (rn);
3953 bgp_unlock_node (rn);
3954 }
3955 else
3956 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3957
3958 return CMD_SUCCESS;
3959}
3960
3961DEFUN (bgp_network,
3962 bgp_network_cmd,
3963 "network A.B.C.D/M",
3964 "Specify a network to announce via BGP\n"
3965 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3966{
3967 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003968 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003969}
3970
3971DEFUN (bgp_network_route_map,
3972 bgp_network_route_map_cmd,
3973 "network A.B.C.D/M route-map WORD",
3974 "Specify a network to announce via BGP\n"
3975 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3976 "Route-map to modify the attributes\n"
3977 "Name of the route map\n")
3978{
3979 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003980 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003981}
3982
3983DEFUN (bgp_network_backdoor,
3984 bgp_network_backdoor_cmd,
3985 "network A.B.C.D/M backdoor",
3986 "Specify a network to announce via BGP\n"
3987 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3988 "Specify a BGP backdoor route\n")
3989{
Paul Jakma41367172007-08-06 15:24:51 +00003990 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003991 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003992}
3993
3994DEFUN (bgp_network_mask,
3995 bgp_network_mask_cmd,
3996 "network A.B.C.D mask A.B.C.D",
3997 "Specify a network to announce via BGP\n"
3998 "Network number\n"
3999 "Network mask\n"
4000 "Network mask\n")
4001{
4002 int ret;
4003 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004004
paul718e3742002-12-13 20:15:29 +00004005 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4006 if (! ret)
4007 {
4008 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4009 return CMD_WARNING;
4010 }
4011
4012 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004013 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004014}
4015
4016DEFUN (bgp_network_mask_route_map,
4017 bgp_network_mask_route_map_cmd,
4018 "network A.B.C.D mask A.B.C.D route-map WORD",
4019 "Specify a network to announce via BGP\n"
4020 "Network number\n"
4021 "Network mask\n"
4022 "Network mask\n"
4023 "Route-map to modify the attributes\n"
4024 "Name of the route map\n")
4025{
4026 int ret;
4027 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004028
paul718e3742002-12-13 20:15:29 +00004029 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4030 if (! ret)
4031 {
4032 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4033 return CMD_WARNING;
4034 }
4035
4036 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004037 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004038}
4039
4040DEFUN (bgp_network_mask_backdoor,
4041 bgp_network_mask_backdoor_cmd,
4042 "network A.B.C.D mask A.B.C.D backdoor",
4043 "Specify a network to announce via BGP\n"
4044 "Network number\n"
4045 "Network mask\n"
4046 "Network mask\n"
4047 "Specify a BGP backdoor route\n")
4048{
4049 int ret;
4050 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004051
paul718e3742002-12-13 20:15:29 +00004052 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4053 if (! ret)
4054 {
4055 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4056 return CMD_WARNING;
4057 }
4058
Paul Jakma41367172007-08-06 15:24:51 +00004059 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004060 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004061}
4062
4063DEFUN (bgp_network_mask_natural,
4064 bgp_network_mask_natural_cmd,
4065 "network A.B.C.D",
4066 "Specify a network to announce via BGP\n"
4067 "Network number\n")
4068{
4069 int ret;
4070 char prefix_str[BUFSIZ];
4071
4072 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4073 if (! ret)
4074 {
4075 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4076 return CMD_WARNING;
4077 }
4078
4079 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004080 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004081}
4082
4083DEFUN (bgp_network_mask_natural_route_map,
4084 bgp_network_mask_natural_route_map_cmd,
4085 "network A.B.C.D route-map WORD",
4086 "Specify a network to announce via BGP\n"
4087 "Network number\n"
4088 "Route-map to modify the attributes\n"
4089 "Name of the route map\n")
4090{
4091 int ret;
4092 char prefix_str[BUFSIZ];
4093
4094 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4095 if (! ret)
4096 {
4097 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4098 return CMD_WARNING;
4099 }
4100
4101 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004102 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004103}
4104
4105DEFUN (bgp_network_mask_natural_backdoor,
4106 bgp_network_mask_natural_backdoor_cmd,
4107 "network A.B.C.D backdoor",
4108 "Specify a network to announce via BGP\n"
4109 "Network number\n"
4110 "Specify a BGP backdoor route\n")
4111{
4112 int ret;
4113 char prefix_str[BUFSIZ];
4114
4115 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4116 if (! ret)
4117 {
4118 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4119 return CMD_WARNING;
4120 }
4121
Paul Jakma41367172007-08-06 15:24:51 +00004122 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004123 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004124}
4125
4126DEFUN (no_bgp_network,
4127 no_bgp_network_cmd,
4128 "no network A.B.C.D/M",
4129 NO_STR
4130 "Specify a network to announce via BGP\n"
4131 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4132{
4133 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4134 bgp_node_safi (vty));
4135}
4136
4137ALIAS (no_bgp_network,
4138 no_bgp_network_route_map_cmd,
4139 "no network A.B.C.D/M route-map WORD",
4140 NO_STR
4141 "Specify a network to announce via BGP\n"
4142 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4143 "Route-map to modify the attributes\n"
4144 "Name of the route map\n")
4145
4146ALIAS (no_bgp_network,
4147 no_bgp_network_backdoor_cmd,
4148 "no network A.B.C.D/M backdoor",
4149 NO_STR
4150 "Specify a network to announce via BGP\n"
4151 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4152 "Specify a BGP backdoor route\n")
4153
4154DEFUN (no_bgp_network_mask,
4155 no_bgp_network_mask_cmd,
4156 "no network A.B.C.D mask A.B.C.D",
4157 NO_STR
4158 "Specify a network to announce via BGP\n"
4159 "Network number\n"
4160 "Network mask\n"
4161 "Network mask\n")
4162{
4163 int ret;
4164 char prefix_str[BUFSIZ];
4165
4166 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4167 if (! ret)
4168 {
4169 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4170 return CMD_WARNING;
4171 }
4172
4173 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4174 bgp_node_safi (vty));
4175}
4176
4177ALIAS (no_bgp_network_mask,
4178 no_bgp_network_mask_route_map_cmd,
4179 "no network A.B.C.D mask A.B.C.D route-map WORD",
4180 NO_STR
4181 "Specify a network to announce via BGP\n"
4182 "Network number\n"
4183 "Network mask\n"
4184 "Network mask\n"
4185 "Route-map to modify the attributes\n"
4186 "Name of the route map\n")
4187
4188ALIAS (no_bgp_network_mask,
4189 no_bgp_network_mask_backdoor_cmd,
4190 "no network A.B.C.D mask A.B.C.D backdoor",
4191 NO_STR
4192 "Specify a network to announce via BGP\n"
4193 "Network number\n"
4194 "Network mask\n"
4195 "Network mask\n"
4196 "Specify a BGP backdoor route\n")
4197
4198DEFUN (no_bgp_network_mask_natural,
4199 no_bgp_network_mask_natural_cmd,
4200 "no network A.B.C.D",
4201 NO_STR
4202 "Specify a network to announce via BGP\n"
4203 "Network number\n")
4204{
4205 int ret;
4206 char prefix_str[BUFSIZ];
4207
4208 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4209 if (! ret)
4210 {
4211 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4212 return CMD_WARNING;
4213 }
4214
4215 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4216 bgp_node_safi (vty));
4217}
4218
4219ALIAS (no_bgp_network_mask_natural,
4220 no_bgp_network_mask_natural_route_map_cmd,
4221 "no network A.B.C.D route-map WORD",
4222 NO_STR
4223 "Specify a network to announce via BGP\n"
4224 "Network number\n"
4225 "Route-map to modify the attributes\n"
4226 "Name of the route map\n")
4227
4228ALIAS (no_bgp_network_mask_natural,
4229 no_bgp_network_mask_natural_backdoor_cmd,
4230 "no network A.B.C.D backdoor",
4231 NO_STR
4232 "Specify a network to announce via BGP\n"
4233 "Network number\n"
4234 "Specify a BGP backdoor route\n")
4235
4236#ifdef HAVE_IPV6
4237DEFUN (ipv6_bgp_network,
4238 ipv6_bgp_network_cmd,
4239 "network X:X::X:X/M",
4240 "Specify a network to announce via BGP\n"
4241 "IPv6 prefix <network>/<length>\n")
4242{
Paul Jakma41367172007-08-06 15:24:51 +00004243 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004244 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004245}
4246
4247DEFUN (ipv6_bgp_network_route_map,
4248 ipv6_bgp_network_route_map_cmd,
4249 "network X:X::X:X/M route-map WORD",
4250 "Specify a network to announce via BGP\n"
4251 "IPv6 prefix <network>/<length>\n"
4252 "Route-map to modify the attributes\n"
4253 "Name of the route map\n")
4254{
4255 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004256 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004257}
4258
4259DEFUN (no_ipv6_bgp_network,
4260 no_ipv6_bgp_network_cmd,
4261 "no network X:X::X:X/M",
4262 NO_STR
4263 "Specify a network to announce via BGP\n"
4264 "IPv6 prefix <network>/<length>\n")
4265{
4266 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4267}
4268
4269ALIAS (no_ipv6_bgp_network,
4270 no_ipv6_bgp_network_route_map_cmd,
4271 "no network X:X::X:X/M route-map WORD",
4272 NO_STR
4273 "Specify a network to announce via BGP\n"
4274 "IPv6 prefix <network>/<length>\n"
4275 "Route-map to modify the attributes\n"
4276 "Name of the route map\n")
4277
4278ALIAS (ipv6_bgp_network,
4279 old_ipv6_bgp_network_cmd,
4280 "ipv6 bgp network X:X::X:X/M",
4281 IPV6_STR
4282 BGP_STR
4283 "Specify a network to announce via BGP\n"
4284 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4285
4286ALIAS (no_ipv6_bgp_network,
4287 old_no_ipv6_bgp_network_cmd,
4288 "no ipv6 bgp network X:X::X:X/M",
4289 NO_STR
4290 IPV6_STR
4291 BGP_STR
4292 "Specify a network to announce via BGP\n"
4293 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4294#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004295
4296/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4297ALIAS_DEPRECATED (bgp_network,
4298 bgp_network_ttl_cmd,
4299 "network A.B.C.D/M pathlimit <0-255>",
4300 "Specify a network to announce via BGP\n"
4301 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4302 "AS-Path hopcount limit attribute\n"
4303 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4304ALIAS_DEPRECATED (bgp_network_backdoor,
4305 bgp_network_backdoor_ttl_cmd,
4306 "network A.B.C.D/M backdoor pathlimit <0-255>",
4307 "Specify a network to announce via BGP\n"
4308 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4309 "Specify a BGP backdoor route\n"
4310 "AS-Path hopcount limit attribute\n"
4311 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4312ALIAS_DEPRECATED (bgp_network_mask,
4313 bgp_network_mask_ttl_cmd,
4314 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4315 "Specify a network to announce via BGP\n"
4316 "Network number\n"
4317 "Network mask\n"
4318 "Network mask\n"
4319 "AS-Path hopcount limit attribute\n"
4320 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4321ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4322 bgp_network_mask_backdoor_ttl_cmd,
4323 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4324 "Specify a network to announce via BGP\n"
4325 "Network number\n"
4326 "Network mask\n"
4327 "Network mask\n"
4328 "Specify a BGP backdoor route\n"
4329 "AS-Path hopcount limit attribute\n"
4330 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4331ALIAS_DEPRECATED (bgp_network_mask_natural,
4332 bgp_network_mask_natural_ttl_cmd,
4333 "network A.B.C.D pathlimit <0-255>",
4334 "Specify a network to announce via BGP\n"
4335 "Network number\n"
4336 "AS-Path hopcount limit attribute\n"
4337 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4338ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4339 bgp_network_mask_natural_backdoor_ttl_cmd,
4340 "network A.B.C.D backdoor pathlimit (1-255>",
4341 "Specify a network to announce via BGP\n"
4342 "Network number\n"
4343 "Specify a BGP backdoor route\n"
4344 "AS-Path hopcount limit attribute\n"
4345 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4346ALIAS_DEPRECATED (no_bgp_network,
4347 no_bgp_network_ttl_cmd,
4348 "no network A.B.C.D/M pathlimit <0-255>",
4349 NO_STR
4350 "Specify a network to announce via BGP\n"
4351 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4352 "AS-Path hopcount limit attribute\n"
4353 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4354ALIAS_DEPRECATED (no_bgp_network,
4355 no_bgp_network_backdoor_ttl_cmd,
4356 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4357 NO_STR
4358 "Specify a network to announce via BGP\n"
4359 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4360 "Specify a BGP backdoor route\n"
4361 "AS-Path hopcount limit attribute\n"
4362 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4363ALIAS_DEPRECATED (no_bgp_network,
4364 no_bgp_network_mask_ttl_cmd,
4365 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4366 NO_STR
4367 "Specify a network to announce via BGP\n"
4368 "Network number\n"
4369 "Network mask\n"
4370 "Network mask\n"
4371 "AS-Path hopcount limit attribute\n"
4372 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4373ALIAS_DEPRECATED (no_bgp_network_mask,
4374 no_bgp_network_mask_backdoor_ttl_cmd,
4375 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4376 NO_STR
4377 "Specify a network to announce via BGP\n"
4378 "Network number\n"
4379 "Network mask\n"
4380 "Network mask\n"
4381 "Specify a BGP backdoor route\n"
4382 "AS-Path hopcount limit attribute\n"
4383 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4384ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4385 no_bgp_network_mask_natural_ttl_cmd,
4386 "no network A.B.C.D pathlimit <0-255>",
4387 NO_STR
4388 "Specify a network to announce via BGP\n"
4389 "Network number\n"
4390 "AS-Path hopcount limit attribute\n"
4391 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4392ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4393 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4394 "no network A.B.C.D backdoor pathlimit <0-255>",
4395 NO_STR
4396 "Specify a network to announce via BGP\n"
4397 "Network number\n"
4398 "Specify a BGP backdoor route\n"
4399 "AS-Path hopcount limit attribute\n"
4400 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004401#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004402ALIAS_DEPRECATED (ipv6_bgp_network,
4403 ipv6_bgp_network_ttl_cmd,
4404 "network X:X::X:X/M pathlimit <0-255>",
4405 "Specify a network to announce via BGP\n"
4406 "IPv6 prefix <network>/<length>\n"
4407 "AS-Path hopcount limit attribute\n"
4408 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4409ALIAS_DEPRECATED (no_ipv6_bgp_network,
4410 no_ipv6_bgp_network_ttl_cmd,
4411 "no network X:X::X:X/M pathlimit <0-255>",
4412 NO_STR
4413 "Specify a network to announce via BGP\n"
4414 "IPv6 prefix <network>/<length>\n"
4415 "AS-Path hopcount limit attribute\n"
4416 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004417#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004418
4419/* Aggreagete address:
4420
4421 advertise-map Set condition to advertise attribute
4422 as-set Generate AS set path information
4423 attribute-map Set attributes of aggregate
4424 route-map Set parameters of aggregate
4425 summary-only Filter more specific routes from updates
4426 suppress-map Conditionally filter more specific routes from updates
4427 <cr>
4428 */
4429struct bgp_aggregate
4430{
4431 /* Summary-only flag. */
4432 u_char summary_only;
4433
4434 /* AS set generation. */
4435 u_char as_set;
4436
4437 /* Route-map for aggregated route. */
4438 struct route_map *map;
4439
4440 /* Suppress-count. */
4441 unsigned long count;
4442
4443 /* SAFI configuration. */
4444 safi_t safi;
4445};
4446
paul94f2b392005-06-28 12:44:16 +00004447static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004448bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004449{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004450 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004451}
4452
paul94f2b392005-06-28 12:44:16 +00004453static void
paul718e3742002-12-13 20:15:29 +00004454bgp_aggregate_free (struct bgp_aggregate *aggregate)
4455{
4456 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4457}
4458
paul94f2b392005-06-28 12:44:16 +00004459static void
paul718e3742002-12-13 20:15:29 +00004460bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4461 afi_t afi, safi_t safi, struct bgp_info *del,
4462 struct bgp_aggregate *aggregate)
4463{
4464 struct bgp_table *table;
4465 struct bgp_node *top;
4466 struct bgp_node *rn;
4467 u_char origin;
4468 struct aspath *aspath = NULL;
4469 struct aspath *asmerge = NULL;
4470 struct community *community = NULL;
4471 struct community *commerge = NULL;
4472 struct in_addr nexthop;
4473 u_int32_t med = 0;
4474 struct bgp_info *ri;
4475 struct bgp_info *new;
4476 int first = 1;
4477 unsigned long match = 0;
4478
4479 /* Record adding route's nexthop and med. */
4480 if (rinew)
4481 {
4482 nexthop = rinew->attr->nexthop;
4483 med = rinew->attr->med;
4484 }
4485
4486 /* ORIGIN attribute: If at least one route among routes that are
4487 aggregated has ORIGIN with the value INCOMPLETE, then the
4488 aggregated route must have the ORIGIN attribute with the value
4489 INCOMPLETE. Otherwise, if at least one route among routes that
4490 are aggregated has ORIGIN with the value EGP, then the aggregated
4491 route must have the origin attribute with the value EGP. In all
4492 other case the value of the ORIGIN attribute of the aggregated
4493 route is INTERNAL. */
4494 origin = BGP_ORIGIN_IGP;
4495
4496 table = bgp->rib[afi][safi];
4497
4498 top = bgp_node_get (table, p);
4499 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4500 if (rn->p.prefixlen > p->prefixlen)
4501 {
4502 match = 0;
4503
4504 for (ri = rn->info; ri; ri = ri->next)
4505 {
4506 if (BGP_INFO_HOLDDOWN (ri))
4507 continue;
4508
4509 if (del && ri == del)
4510 continue;
4511
4512 if (! rinew && first)
4513 {
4514 nexthop = ri->attr->nexthop;
4515 med = ri->attr->med;
4516 first = 0;
4517 }
4518
4519#ifdef AGGREGATE_NEXTHOP_CHECK
4520 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4521 || ri->attr->med != med)
4522 {
4523 if (aspath)
4524 aspath_free (aspath);
4525 if (community)
4526 community_free (community);
4527 bgp_unlock_node (rn);
4528 bgp_unlock_node (top);
4529 return;
4530 }
4531#endif /* AGGREGATE_NEXTHOP_CHECK */
4532
4533 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4534 {
4535 if (aggregate->summary_only)
4536 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004537 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004538 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004539 match++;
4540 }
4541
4542 aggregate->count++;
4543
4544 if (aggregate->as_set)
4545 {
4546 if (origin < ri->attr->origin)
4547 origin = ri->attr->origin;
4548
4549 if (aspath)
4550 {
4551 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4552 aspath_free (aspath);
4553 aspath = asmerge;
4554 }
4555 else
4556 aspath = aspath_dup (ri->attr->aspath);
4557
4558 if (ri->attr->community)
4559 {
4560 if (community)
4561 {
4562 commerge = community_merge (community,
4563 ri->attr->community);
4564 community = community_uniq_sort (commerge);
4565 community_free (commerge);
4566 }
4567 else
4568 community = community_dup (ri->attr->community);
4569 }
4570 }
4571 }
4572 }
4573 if (match)
4574 bgp_process (bgp, rn, afi, safi);
4575 }
4576 bgp_unlock_node (top);
4577
4578 if (rinew)
4579 {
4580 aggregate->count++;
4581
4582 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004583 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004584
4585 if (aggregate->as_set)
4586 {
4587 if (origin < rinew->attr->origin)
4588 origin = rinew->attr->origin;
4589
4590 if (aspath)
4591 {
4592 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4593 aspath_free (aspath);
4594 aspath = asmerge;
4595 }
4596 else
4597 aspath = aspath_dup (rinew->attr->aspath);
4598
4599 if (rinew->attr->community)
4600 {
4601 if (community)
4602 {
4603 commerge = community_merge (community,
4604 rinew->attr->community);
4605 community = community_uniq_sort (commerge);
4606 community_free (commerge);
4607 }
4608 else
4609 community = community_dup (rinew->attr->community);
4610 }
4611 }
4612 }
4613
4614 if (aggregate->count > 0)
4615 {
4616 rn = bgp_node_get (table, p);
4617 new = bgp_info_new ();
4618 new->type = ZEBRA_ROUTE_BGP;
4619 new->sub_type = BGP_ROUTE_AGGREGATE;
4620 new->peer = bgp->peer_self;
4621 SET_FLAG (new->flags, BGP_INFO_VALID);
4622 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004623 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004624
4625 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004626 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004627 bgp_process (bgp, rn, afi, safi);
4628 }
4629 else
4630 {
4631 if (aspath)
4632 aspath_free (aspath);
4633 if (community)
4634 community_free (community);
4635 }
4636}
4637
4638void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4639 struct bgp_aggregate *);
4640
4641void
4642bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4643 struct bgp_info *ri, afi_t afi, safi_t safi)
4644{
4645 struct bgp_node *child;
4646 struct bgp_node *rn;
4647 struct bgp_aggregate *aggregate;
4648
4649 /* MPLS-VPN aggregation is not yet supported. */
4650 if (safi == SAFI_MPLS_VPN)
4651 return;
4652
4653 if (p->prefixlen == 0)
4654 return;
4655
4656 if (BGP_INFO_HOLDDOWN (ri))
4657 return;
4658
4659 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4660
4661 /* Aggregate address configuration check. */
4662 for (rn = child; rn; rn = rn->parent)
4663 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4664 {
4665 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004666 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004667 }
4668 bgp_unlock_node (child);
4669}
4670
4671void
4672bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4673 struct bgp_info *del, afi_t afi, safi_t safi)
4674{
4675 struct bgp_node *child;
4676 struct bgp_node *rn;
4677 struct bgp_aggregate *aggregate;
4678
4679 /* MPLS-VPN aggregation is not yet supported. */
4680 if (safi == SAFI_MPLS_VPN)
4681 return;
4682
4683 if (p->prefixlen == 0)
4684 return;
4685
4686 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4687
4688 /* Aggregate address configuration check. */
4689 for (rn = child; rn; rn = rn->parent)
4690 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4691 {
4692 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004693 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004694 }
4695 bgp_unlock_node (child);
4696}
4697
paul94f2b392005-06-28 12:44:16 +00004698static void
paul718e3742002-12-13 20:15:29 +00004699bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4700 struct bgp_aggregate *aggregate)
4701{
4702 struct bgp_table *table;
4703 struct bgp_node *top;
4704 struct bgp_node *rn;
4705 struct bgp_info *new;
4706 struct bgp_info *ri;
4707 unsigned long match;
4708 u_char origin = BGP_ORIGIN_IGP;
4709 struct aspath *aspath = NULL;
4710 struct aspath *asmerge = NULL;
4711 struct community *community = NULL;
4712 struct community *commerge = NULL;
4713
4714 table = bgp->rib[afi][safi];
4715
4716 /* Sanity check. */
4717 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4718 return;
4719 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4720 return;
4721
4722 /* If routes exists below this node, generate aggregate routes. */
4723 top = bgp_node_get (table, p);
4724 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4725 if (rn->p.prefixlen > p->prefixlen)
4726 {
4727 match = 0;
4728
4729 for (ri = rn->info; ri; ri = ri->next)
4730 {
4731 if (BGP_INFO_HOLDDOWN (ri))
4732 continue;
4733
4734 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4735 {
4736 /* summary-only aggregate route suppress aggregated
4737 route announcement. */
4738 if (aggregate->summary_only)
4739 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004740 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004741 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004742 match++;
4743 }
4744 /* as-set aggregate route generate origin, as path,
4745 community aggregation. */
4746 if (aggregate->as_set)
4747 {
4748 if (origin < ri->attr->origin)
4749 origin = ri->attr->origin;
4750
4751 if (aspath)
4752 {
4753 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4754 aspath_free (aspath);
4755 aspath = asmerge;
4756 }
4757 else
4758 aspath = aspath_dup (ri->attr->aspath);
4759
4760 if (ri->attr->community)
4761 {
4762 if (community)
4763 {
4764 commerge = community_merge (community,
4765 ri->attr->community);
4766 community = community_uniq_sort (commerge);
4767 community_free (commerge);
4768 }
4769 else
4770 community = community_dup (ri->attr->community);
4771 }
4772 }
4773 aggregate->count++;
4774 }
4775 }
4776
4777 /* If this node is suppressed, process the change. */
4778 if (match)
4779 bgp_process (bgp, rn, afi, safi);
4780 }
4781 bgp_unlock_node (top);
4782
4783 /* Add aggregate route to BGP table. */
4784 if (aggregate->count)
4785 {
4786 rn = bgp_node_get (table, p);
4787
4788 new = bgp_info_new ();
4789 new->type = ZEBRA_ROUTE_BGP;
4790 new->sub_type = BGP_ROUTE_AGGREGATE;
4791 new->peer = bgp->peer_self;
4792 SET_FLAG (new->flags, BGP_INFO_VALID);
4793 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004794 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004795
4796 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004797 bgp_unlock_node (rn);
4798
paul718e3742002-12-13 20:15:29 +00004799 /* Process change. */
4800 bgp_process (bgp, rn, afi, safi);
4801 }
4802}
4803
4804void
4805bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4806 safi_t safi, struct bgp_aggregate *aggregate)
4807{
4808 struct bgp_table *table;
4809 struct bgp_node *top;
4810 struct bgp_node *rn;
4811 struct bgp_info *ri;
4812 unsigned long match;
4813
4814 table = bgp->rib[afi][safi];
4815
4816 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4817 return;
4818 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4819 return;
4820
4821 /* If routes exists below this node, generate aggregate routes. */
4822 top = bgp_node_get (table, p);
4823 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4824 if (rn->p.prefixlen > p->prefixlen)
4825 {
4826 match = 0;
4827
4828 for (ri = rn->info; ri; ri = ri->next)
4829 {
4830 if (BGP_INFO_HOLDDOWN (ri))
4831 continue;
4832
4833 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4834 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004835 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004836 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004837 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004838
Paul Jakmafb982c22007-05-04 20:15:47 +00004839 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004840 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004841 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004842 match++;
4843 }
4844 }
4845 aggregate->count--;
4846 }
4847 }
4848
Paul Jakmafb982c22007-05-04 20:15:47 +00004849 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004850 if (match)
4851 bgp_process (bgp, rn, afi, safi);
4852 }
4853 bgp_unlock_node (top);
4854
4855 /* Delete aggregate route from BGP table. */
4856 rn = bgp_node_get (table, p);
4857
4858 for (ri = rn->info; ri; ri = ri->next)
4859 if (ri->peer == bgp->peer_self
4860 && ri->type == ZEBRA_ROUTE_BGP
4861 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4862 break;
4863
4864 /* Withdraw static BGP route from routing table. */
4865 if (ri)
4866 {
paul718e3742002-12-13 20:15:29 +00004867 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004868 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004869 }
4870
4871 /* Unlock bgp_node_lookup. */
4872 bgp_unlock_node (rn);
4873}
4874
4875/* Aggregate route attribute. */
4876#define AGGREGATE_SUMMARY_ONLY 1
4877#define AGGREGATE_AS_SET 1
4878
paul94f2b392005-06-28 12:44:16 +00004879static int
Robert Baysf6269b42010-08-05 10:26:28 -07004880bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4881 afi_t afi, safi_t safi)
4882{
4883 int ret;
4884 struct prefix p;
4885 struct bgp_node *rn;
4886 struct bgp *bgp;
4887 struct bgp_aggregate *aggregate;
4888
4889 /* Convert string to prefix structure. */
4890 ret = str2prefix (prefix_str, &p);
4891 if (!ret)
4892 {
4893 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4894 return CMD_WARNING;
4895 }
4896 apply_mask (&p);
4897
4898 /* Get BGP structure. */
4899 bgp = vty->index;
4900
4901 /* Old configuration check. */
4902 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4903 if (! rn)
4904 {
4905 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4906 VTY_NEWLINE);
4907 return CMD_WARNING;
4908 }
4909
4910 aggregate = rn->info;
4911 if (aggregate->safi & SAFI_UNICAST)
4912 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4913 if (aggregate->safi & SAFI_MULTICAST)
4914 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4915
4916 /* Unlock aggregate address configuration. */
4917 rn->info = NULL;
4918 bgp_aggregate_free (aggregate);
4919 bgp_unlock_node (rn);
4920 bgp_unlock_node (rn);
4921
4922 return CMD_SUCCESS;
4923}
4924
4925static int
4926bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004927 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004928 u_char summary_only, u_char as_set)
4929{
4930 int ret;
4931 struct prefix p;
4932 struct bgp_node *rn;
4933 struct bgp *bgp;
4934 struct bgp_aggregate *aggregate;
4935
4936 /* Convert string to prefix structure. */
4937 ret = str2prefix (prefix_str, &p);
4938 if (!ret)
4939 {
4940 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4941 return CMD_WARNING;
4942 }
4943 apply_mask (&p);
4944
4945 /* Get BGP structure. */
4946 bgp = vty->index;
4947
4948 /* Old configuration check. */
4949 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4950
4951 if (rn->info)
4952 {
4953 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004954 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004955 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4956 if (ret)
4957 {
Robert Bays368473f2010-08-05 10:26:29 -07004958 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4959 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004960 return CMD_WARNING;
4961 }
paul718e3742002-12-13 20:15:29 +00004962 }
4963
4964 /* Make aggregate address structure. */
4965 aggregate = bgp_aggregate_new ();
4966 aggregate->summary_only = summary_only;
4967 aggregate->as_set = as_set;
4968 aggregate->safi = safi;
4969 rn->info = aggregate;
4970
4971 /* Aggregate address insert into BGP routing table. */
4972 if (safi & SAFI_UNICAST)
4973 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4974 if (safi & SAFI_MULTICAST)
4975 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4976
4977 return CMD_SUCCESS;
4978}
4979
paul718e3742002-12-13 20:15:29 +00004980DEFUN (aggregate_address,
4981 aggregate_address_cmd,
4982 "aggregate-address A.B.C.D/M",
4983 "Configure BGP aggregate entries\n"
4984 "Aggregate prefix\n")
4985{
4986 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4987}
4988
4989DEFUN (aggregate_address_mask,
4990 aggregate_address_mask_cmd,
4991 "aggregate-address A.B.C.D A.B.C.D",
4992 "Configure BGP aggregate entries\n"
4993 "Aggregate address\n"
4994 "Aggregate mask\n")
4995{
4996 int ret;
4997 char prefix_str[BUFSIZ];
4998
4999 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5000
5001 if (! ret)
5002 {
5003 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5004 return CMD_WARNING;
5005 }
5006
5007 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5008 0, 0);
5009}
5010
5011DEFUN (aggregate_address_summary_only,
5012 aggregate_address_summary_only_cmd,
5013 "aggregate-address A.B.C.D/M summary-only",
5014 "Configure BGP aggregate entries\n"
5015 "Aggregate prefix\n"
5016 "Filter more specific routes from updates\n")
5017{
5018 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5019 AGGREGATE_SUMMARY_ONLY, 0);
5020}
5021
5022DEFUN (aggregate_address_mask_summary_only,
5023 aggregate_address_mask_summary_only_cmd,
5024 "aggregate-address A.B.C.D A.B.C.D summary-only",
5025 "Configure BGP aggregate entries\n"
5026 "Aggregate address\n"
5027 "Aggregate mask\n"
5028 "Filter more specific routes from updates\n")
5029{
5030 int ret;
5031 char prefix_str[BUFSIZ];
5032
5033 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5034
5035 if (! ret)
5036 {
5037 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5038 return CMD_WARNING;
5039 }
5040
5041 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5042 AGGREGATE_SUMMARY_ONLY, 0);
5043}
5044
5045DEFUN (aggregate_address_as_set,
5046 aggregate_address_as_set_cmd,
5047 "aggregate-address A.B.C.D/M as-set",
5048 "Configure BGP aggregate entries\n"
5049 "Aggregate prefix\n"
5050 "Generate AS set path information\n")
5051{
5052 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5053 0, AGGREGATE_AS_SET);
5054}
5055
5056DEFUN (aggregate_address_mask_as_set,
5057 aggregate_address_mask_as_set_cmd,
5058 "aggregate-address A.B.C.D A.B.C.D as-set",
5059 "Configure BGP aggregate entries\n"
5060 "Aggregate address\n"
5061 "Aggregate mask\n"
5062 "Generate AS set path information\n")
5063{
5064 int ret;
5065 char prefix_str[BUFSIZ];
5066
5067 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5068
5069 if (! ret)
5070 {
5071 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5072 return CMD_WARNING;
5073 }
5074
5075 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5076 0, AGGREGATE_AS_SET);
5077}
5078
5079
5080DEFUN (aggregate_address_as_set_summary,
5081 aggregate_address_as_set_summary_cmd,
5082 "aggregate-address A.B.C.D/M as-set summary-only",
5083 "Configure BGP aggregate entries\n"
5084 "Aggregate prefix\n"
5085 "Generate AS set path information\n"
5086 "Filter more specific routes from updates\n")
5087{
5088 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5089 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5090}
5091
5092ALIAS (aggregate_address_as_set_summary,
5093 aggregate_address_summary_as_set_cmd,
5094 "aggregate-address A.B.C.D/M summary-only as-set",
5095 "Configure BGP aggregate entries\n"
5096 "Aggregate prefix\n"
5097 "Filter more specific routes from updates\n"
5098 "Generate AS set path information\n")
5099
5100DEFUN (aggregate_address_mask_as_set_summary,
5101 aggregate_address_mask_as_set_summary_cmd,
5102 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5103 "Configure BGP aggregate entries\n"
5104 "Aggregate address\n"
5105 "Aggregate mask\n"
5106 "Generate AS set path information\n"
5107 "Filter more specific routes from updates\n")
5108{
5109 int ret;
5110 char prefix_str[BUFSIZ];
5111
5112 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5113
5114 if (! ret)
5115 {
5116 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5117 return CMD_WARNING;
5118 }
5119
5120 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5121 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5122}
5123
5124ALIAS (aggregate_address_mask_as_set_summary,
5125 aggregate_address_mask_summary_as_set_cmd,
5126 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5127 "Configure BGP aggregate entries\n"
5128 "Aggregate address\n"
5129 "Aggregate mask\n"
5130 "Filter more specific routes from updates\n"
5131 "Generate AS set path information\n")
5132
5133DEFUN (no_aggregate_address,
5134 no_aggregate_address_cmd,
5135 "no aggregate-address A.B.C.D/M",
5136 NO_STR
5137 "Configure BGP aggregate entries\n"
5138 "Aggregate prefix\n")
5139{
5140 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5141}
5142
5143ALIAS (no_aggregate_address,
5144 no_aggregate_address_summary_only_cmd,
5145 "no aggregate-address A.B.C.D/M summary-only",
5146 NO_STR
5147 "Configure BGP aggregate entries\n"
5148 "Aggregate prefix\n"
5149 "Filter more specific routes from updates\n")
5150
5151ALIAS (no_aggregate_address,
5152 no_aggregate_address_as_set_cmd,
5153 "no aggregate-address A.B.C.D/M as-set",
5154 NO_STR
5155 "Configure BGP aggregate entries\n"
5156 "Aggregate prefix\n"
5157 "Generate AS set path information\n")
5158
5159ALIAS (no_aggregate_address,
5160 no_aggregate_address_as_set_summary_cmd,
5161 "no aggregate-address A.B.C.D/M as-set summary-only",
5162 NO_STR
5163 "Configure BGP aggregate entries\n"
5164 "Aggregate prefix\n"
5165 "Generate AS set path information\n"
5166 "Filter more specific routes from updates\n")
5167
5168ALIAS (no_aggregate_address,
5169 no_aggregate_address_summary_as_set_cmd,
5170 "no aggregate-address A.B.C.D/M summary-only as-set",
5171 NO_STR
5172 "Configure BGP aggregate entries\n"
5173 "Aggregate prefix\n"
5174 "Filter more specific routes from updates\n"
5175 "Generate AS set path information\n")
5176
5177DEFUN (no_aggregate_address_mask,
5178 no_aggregate_address_mask_cmd,
5179 "no aggregate-address A.B.C.D A.B.C.D",
5180 NO_STR
5181 "Configure BGP aggregate entries\n"
5182 "Aggregate address\n"
5183 "Aggregate mask\n")
5184{
5185 int ret;
5186 char prefix_str[BUFSIZ];
5187
5188 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5189
5190 if (! ret)
5191 {
5192 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5193 return CMD_WARNING;
5194 }
5195
5196 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5197}
5198
5199ALIAS (no_aggregate_address_mask,
5200 no_aggregate_address_mask_summary_only_cmd,
5201 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5202 NO_STR
5203 "Configure BGP aggregate entries\n"
5204 "Aggregate address\n"
5205 "Aggregate mask\n"
5206 "Filter more specific routes from updates\n")
5207
5208ALIAS (no_aggregate_address_mask,
5209 no_aggregate_address_mask_as_set_cmd,
5210 "no aggregate-address A.B.C.D A.B.C.D as-set",
5211 NO_STR
5212 "Configure BGP aggregate entries\n"
5213 "Aggregate address\n"
5214 "Aggregate mask\n"
5215 "Generate AS set path information\n")
5216
5217ALIAS (no_aggregate_address_mask,
5218 no_aggregate_address_mask_as_set_summary_cmd,
5219 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5220 NO_STR
5221 "Configure BGP aggregate entries\n"
5222 "Aggregate address\n"
5223 "Aggregate mask\n"
5224 "Generate AS set path information\n"
5225 "Filter more specific routes from updates\n")
5226
5227ALIAS (no_aggregate_address_mask,
5228 no_aggregate_address_mask_summary_as_set_cmd,
5229 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5230 NO_STR
5231 "Configure BGP aggregate entries\n"
5232 "Aggregate address\n"
5233 "Aggregate mask\n"
5234 "Filter more specific routes from updates\n"
5235 "Generate AS set path information\n")
5236
5237#ifdef HAVE_IPV6
5238DEFUN (ipv6_aggregate_address,
5239 ipv6_aggregate_address_cmd,
5240 "aggregate-address X:X::X:X/M",
5241 "Configure BGP aggregate entries\n"
5242 "Aggregate prefix\n")
5243{
5244 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5245}
5246
5247DEFUN (ipv6_aggregate_address_summary_only,
5248 ipv6_aggregate_address_summary_only_cmd,
5249 "aggregate-address X:X::X:X/M summary-only",
5250 "Configure BGP aggregate entries\n"
5251 "Aggregate prefix\n"
5252 "Filter more specific routes from updates\n")
5253{
5254 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5255 AGGREGATE_SUMMARY_ONLY, 0);
5256}
5257
5258DEFUN (no_ipv6_aggregate_address,
5259 no_ipv6_aggregate_address_cmd,
5260 "no aggregate-address X:X::X:X/M",
5261 NO_STR
5262 "Configure BGP aggregate entries\n"
5263 "Aggregate prefix\n")
5264{
5265 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5266}
5267
5268DEFUN (no_ipv6_aggregate_address_summary_only,
5269 no_ipv6_aggregate_address_summary_only_cmd,
5270 "no aggregate-address X:X::X:X/M summary-only",
5271 NO_STR
5272 "Configure BGP aggregate entries\n"
5273 "Aggregate prefix\n"
5274 "Filter more specific routes from updates\n")
5275{
5276 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5277}
5278
5279ALIAS (ipv6_aggregate_address,
5280 old_ipv6_aggregate_address_cmd,
5281 "ipv6 bgp aggregate-address X:X::X:X/M",
5282 IPV6_STR
5283 BGP_STR
5284 "Configure BGP aggregate entries\n"
5285 "Aggregate prefix\n")
5286
5287ALIAS (ipv6_aggregate_address_summary_only,
5288 old_ipv6_aggregate_address_summary_only_cmd,
5289 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5290 IPV6_STR
5291 BGP_STR
5292 "Configure BGP aggregate entries\n"
5293 "Aggregate prefix\n"
5294 "Filter more specific routes from updates\n")
5295
5296ALIAS (no_ipv6_aggregate_address,
5297 old_no_ipv6_aggregate_address_cmd,
5298 "no ipv6 bgp aggregate-address X:X::X:X/M",
5299 NO_STR
5300 IPV6_STR
5301 BGP_STR
5302 "Configure BGP aggregate entries\n"
5303 "Aggregate prefix\n")
5304
5305ALIAS (no_ipv6_aggregate_address_summary_only,
5306 old_no_ipv6_aggregate_address_summary_only_cmd,
5307 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5308 NO_STR
5309 IPV6_STR
5310 BGP_STR
5311 "Configure BGP aggregate entries\n"
5312 "Aggregate prefix\n"
5313 "Filter more specific routes from updates\n")
5314#endif /* HAVE_IPV6 */
5315
5316/* Redistribute route treatment. */
5317void
5318bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5319 u_int32_t metric, u_char type)
5320{
5321 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005322 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005323 struct bgp_info *new;
5324 struct bgp_info *bi;
5325 struct bgp_info info;
5326 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005327 struct attr attr = { 0 };
5328 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005329 struct attr *new_attr;
5330 afi_t afi;
5331 int ret;
5332
5333 /* Make default attribute. */
5334 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5335 if (nexthop)
5336 attr.nexthop = *nexthop;
5337
5338 attr.med = metric;
5339 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5340
paul1eb8ef22005-04-07 07:30:20 +00005341 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005342 {
5343 afi = family2afi (p->family);
5344
5345 if (bgp->redist[afi][type])
5346 {
5347 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005348 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005349
5350 if (bgp->redist_metric_flag[afi][type])
5351 attr_new.med = bgp->redist_metric[afi][type];
5352
5353 /* Apply route-map. */
5354 if (bgp->rmap[afi][type].map)
5355 {
5356 info.peer = bgp->peer_self;
5357 info.attr = &attr_new;
5358
paulfee0f4c2004-09-13 05:12:46 +00005359 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5360
paul718e3742002-12-13 20:15:29 +00005361 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5362 &info);
paulfee0f4c2004-09-13 05:12:46 +00005363
5364 bgp->peer_self->rmap_type = 0;
5365
paul718e3742002-12-13 20:15:29 +00005366 if (ret == RMAP_DENYMATCH)
5367 {
5368 /* Free uninterned attribute. */
5369 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005370 bgp_attr_extra_free (&attr_new);
5371
paul718e3742002-12-13 20:15:29 +00005372 /* Unintern original. */
5373 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005374 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005375 bgp_redistribute_delete (p, type);
5376 return;
5377 }
5378 }
5379
Paul Jakmafb982c22007-05-04 20:15:47 +00005380 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5381 afi, SAFI_UNICAST, p, NULL);
5382
paul718e3742002-12-13 20:15:29 +00005383 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005384 bgp_attr_extra_free (&attr_new);
5385
paul718e3742002-12-13 20:15:29 +00005386 for (bi = bn->info; bi; bi = bi->next)
5387 if (bi->peer == bgp->peer_self
5388 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5389 break;
5390
5391 if (bi)
5392 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005393 if (attrhash_cmp (bi->attr, new_attr) &&
5394 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005395 {
5396 bgp_attr_unintern (new_attr);
5397 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005398 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005399 bgp_unlock_node (bn);
5400 return;
5401 }
5402 else
5403 {
5404 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005405 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005406
5407 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005408 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5409 bgp_info_restore(bn, bi);
5410 else
5411 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005412 bgp_attr_unintern (bi->attr);
5413 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005414 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005415
5416 /* Process change. */
5417 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5418 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5419 bgp_unlock_node (bn);
5420 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005421 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005422 return;
5423 }
5424 }
5425
5426 new = bgp_info_new ();
5427 new->type = type;
5428 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5429 new->peer = bgp->peer_self;
5430 SET_FLAG (new->flags, BGP_INFO_VALID);
5431 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005432 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005433
5434 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5435 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005436 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005437 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5438 }
5439 }
5440
5441 /* Unintern original. */
5442 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005443 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005444}
5445
5446void
5447bgp_redistribute_delete (struct prefix *p, u_char type)
5448{
5449 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005450 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005451 afi_t afi;
5452 struct bgp_node *rn;
5453 struct bgp_info *ri;
5454
paul1eb8ef22005-04-07 07:30:20 +00005455 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005456 {
5457 afi = family2afi (p->family);
5458
5459 if (bgp->redist[afi][type])
5460 {
paulfee0f4c2004-09-13 05:12:46 +00005461 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005462
5463 for (ri = rn->info; ri; ri = ri->next)
5464 if (ri->peer == bgp->peer_self
5465 && ri->type == type)
5466 break;
5467
5468 if (ri)
5469 {
5470 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005471 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005472 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005473 }
5474 bgp_unlock_node (rn);
5475 }
5476 }
5477}
5478
5479/* Withdraw specified route type's route. */
5480void
5481bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5482{
5483 struct bgp_node *rn;
5484 struct bgp_info *ri;
5485 struct bgp_table *table;
5486
5487 table = bgp->rib[afi][SAFI_UNICAST];
5488
5489 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5490 {
5491 for (ri = rn->info; ri; ri = ri->next)
5492 if (ri->peer == bgp->peer_self
5493 && ri->type == type)
5494 break;
5495
5496 if (ri)
5497 {
5498 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005499 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005500 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005501 }
5502 }
5503}
5504
5505/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005506static void
paul718e3742002-12-13 20:15:29 +00005507route_vty_out_route (struct prefix *p, struct vty *vty)
5508{
5509 int len;
5510 u_int32_t destination;
5511 char buf[BUFSIZ];
5512
5513 if (p->family == AF_INET)
5514 {
5515 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5516 destination = ntohl (p->u.prefix4.s_addr);
5517
5518 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5519 || (IN_CLASSB (destination) && p->prefixlen == 16)
5520 || (IN_CLASSA (destination) && p->prefixlen == 8)
5521 || p->u.prefix4.s_addr == 0)
5522 {
5523 /* When mask is natural, mask is not displayed. */
5524 }
5525 else
5526 len += vty_out (vty, "/%d", p->prefixlen);
5527 }
5528 else
5529 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5530 p->prefixlen);
5531
5532 len = 17 - len;
5533 if (len < 1)
5534 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5535 else
5536 vty_out (vty, "%*s", len, " ");
5537}
5538
paul718e3742002-12-13 20:15:29 +00005539enum bgp_display_type
5540{
5541 normal_list,
5542};
5543
paulb40d9392005-08-22 22:34:41 +00005544/* Print the short form route status for a bgp_info */
5545static void
5546route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005547{
paulb40d9392005-08-22 22:34:41 +00005548 /* Route status display. */
5549 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5550 vty_out (vty, "R");
5551 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005552 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005553 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005554 vty_out (vty, "s");
5555 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5556 vty_out (vty, "*");
5557 else
5558 vty_out (vty, " ");
5559
5560 /* Selected */
5561 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5562 vty_out (vty, "h");
5563 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5564 vty_out (vty, "d");
5565 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5566 vty_out (vty, ">");
5567 else
5568 vty_out (vty, " ");
5569
5570 /* Internal route. */
5571 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5572 vty_out (vty, "i");
5573 else
paulb40d9392005-08-22 22:34:41 +00005574 vty_out (vty, " ");
5575}
5576
5577/* called from terminal list command */
5578void
5579route_vty_out (struct vty *vty, struct prefix *p,
5580 struct bgp_info *binfo, int display, safi_t safi)
5581{
5582 struct attr *attr;
5583
5584 /* short status lead text */
5585 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005586
5587 /* print prefix and mask */
5588 if (! display)
5589 route_vty_out_route (p, vty);
5590 else
5591 vty_out (vty, "%*s", 17, " ");
5592
5593 /* Print attribute */
5594 attr = binfo->attr;
5595 if (attr)
5596 {
5597 if (p->family == AF_INET)
5598 {
5599 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005600 vty_out (vty, "%-16s",
5601 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005602 else
5603 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5604 }
5605#ifdef HAVE_IPV6
5606 else if (p->family == AF_INET6)
5607 {
5608 int len;
5609 char buf[BUFSIZ];
5610
5611 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005612 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5613 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005614 len = 16 - len;
5615 if (len < 1)
5616 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5617 else
5618 vty_out (vty, "%*s", len, " ");
5619 }
5620#endif /* HAVE_IPV6 */
5621
5622 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005623 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005624 else
5625 vty_out (vty, " ");
5626
5627 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005628 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005629 else
5630 vty_out (vty, " ");
5631
Paul Jakmafb982c22007-05-04 20:15:47 +00005632 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005633
Paul Jakmab2518c12006-05-12 23:48:40 +00005634 /* Print aspath */
5635 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005636 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005637
Paul Jakmab2518c12006-05-12 23:48:40 +00005638 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005639 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005640 }
paul718e3742002-12-13 20:15:29 +00005641 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005642}
5643
5644/* called from terminal list command */
5645void
5646route_vty_out_tmp (struct vty *vty, struct prefix *p,
5647 struct attr *attr, safi_t safi)
5648{
5649 /* Route status display. */
5650 vty_out (vty, "*");
5651 vty_out (vty, ">");
5652 vty_out (vty, " ");
5653
5654 /* print prefix and mask */
5655 route_vty_out_route (p, vty);
5656
5657 /* Print attribute */
5658 if (attr)
5659 {
5660 if (p->family == AF_INET)
5661 {
5662 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005663 vty_out (vty, "%-16s",
5664 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005665 else
5666 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5667 }
5668#ifdef HAVE_IPV6
5669 else if (p->family == AF_INET6)
5670 {
5671 int len;
5672 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005673
5674 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005675
5676 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005677 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5678 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005679 len = 16 - len;
5680 if (len < 1)
5681 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5682 else
5683 vty_out (vty, "%*s", len, " ");
5684 }
5685#endif /* HAVE_IPV6 */
5686
5687 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005688 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005689 else
5690 vty_out (vty, " ");
5691
5692 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005693 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005694 else
5695 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005696
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005697 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005698
Paul Jakmab2518c12006-05-12 23:48:40 +00005699 /* Print aspath */
5700 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005701 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005702
Paul Jakmab2518c12006-05-12 23:48:40 +00005703 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005704 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005705 }
paul718e3742002-12-13 20:15:29 +00005706
5707 vty_out (vty, "%s", VTY_NEWLINE);
5708}
5709
ajs5a646652004-11-05 01:25:55 +00005710void
paul718e3742002-12-13 20:15:29 +00005711route_vty_out_tag (struct vty *vty, struct prefix *p,
5712 struct bgp_info *binfo, int display, safi_t safi)
5713{
5714 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005715 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005716
5717 if (!binfo->extra)
5718 return;
5719
paulb40d9392005-08-22 22:34:41 +00005720 /* short status lead text */
5721 route_vty_short_status_out (vty, binfo);
5722
paul718e3742002-12-13 20:15:29 +00005723 /* print prefix and mask */
5724 if (! display)
5725 route_vty_out_route (p, vty);
5726 else
5727 vty_out (vty, "%*s", 17, " ");
5728
5729 /* Print attribute */
5730 attr = binfo->attr;
5731 if (attr)
5732 {
5733 if (p->family == AF_INET)
5734 {
5735 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005736 vty_out (vty, "%-16s",
5737 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005738 else
5739 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5740 }
5741#ifdef HAVE_IPV6
5742 else if (p->family == AF_INET6)
5743 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005744 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005745 char buf[BUFSIZ];
5746 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005747 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005748 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005749 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5750 buf, BUFSIZ));
5751 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005752 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005753 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5754 buf, BUFSIZ),
5755 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5756 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005757
5758 }
5759#endif /* HAVE_IPV6 */
5760 }
5761
Paul Jakmafb982c22007-05-04 20:15:47 +00005762 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005763
5764 vty_out (vty, "notag/%d", label);
5765
5766 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005767}
5768
5769/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005770static void
paul718e3742002-12-13 20:15:29 +00005771damp_route_vty_out (struct vty *vty, struct prefix *p,
5772 struct bgp_info *binfo, int display, safi_t safi)
5773{
5774 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005775 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005776 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005777
paulb40d9392005-08-22 22:34:41 +00005778 /* short status lead text */
5779 route_vty_short_status_out (vty, binfo);
5780
paul718e3742002-12-13 20:15:29 +00005781 /* print prefix and mask */
5782 if (! display)
5783 route_vty_out_route (p, vty);
5784 else
5785 vty_out (vty, "%*s", 17, " ");
5786
5787 len = vty_out (vty, "%s", binfo->peer->host);
5788 len = 17 - len;
5789 if (len < 1)
5790 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5791 else
5792 vty_out (vty, "%*s", len, " ");
5793
Chris Caputo50aef6f2009-06-23 06:06:49 +00005794 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005795
5796 /* Print attribute */
5797 attr = binfo->attr;
5798 if (attr)
5799 {
5800 /* Print aspath */
5801 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005802 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005803
5804 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005805 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005806 }
5807 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005808}
5809
paul718e3742002-12-13 20:15:29 +00005810/* flap route */
ajs5a646652004-11-05 01:25:55 +00005811static void
paul718e3742002-12-13 20:15:29 +00005812flap_route_vty_out (struct vty *vty, struct prefix *p,
5813 struct bgp_info *binfo, int display, safi_t safi)
5814{
5815 struct attr *attr;
5816 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005817 char timebuf[BGP_UPTIME_LEN];
5818 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005819
5820 if (!binfo->extra)
5821 return;
5822
5823 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005824
paulb40d9392005-08-22 22:34:41 +00005825 /* short status lead text */
5826 route_vty_short_status_out (vty, binfo);
5827
paul718e3742002-12-13 20:15:29 +00005828 /* print prefix and mask */
5829 if (! display)
5830 route_vty_out_route (p, vty);
5831 else
5832 vty_out (vty, "%*s", 17, " ");
5833
5834 len = vty_out (vty, "%s", binfo->peer->host);
5835 len = 16 - len;
5836 if (len < 1)
5837 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5838 else
5839 vty_out (vty, "%*s", len, " ");
5840
5841 len = vty_out (vty, "%d", bdi->flap);
5842 len = 5 - len;
5843 if (len < 1)
5844 vty_out (vty, " ");
5845 else
5846 vty_out (vty, "%*s ", len, " ");
5847
5848 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5849 timebuf, BGP_UPTIME_LEN));
5850
5851 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5852 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005853 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005854 else
5855 vty_out (vty, "%*s ", 8, " ");
5856
5857 /* Print attribute */
5858 attr = binfo->attr;
5859 if (attr)
5860 {
5861 /* Print aspath */
5862 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005863 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005864
5865 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005866 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005867 }
5868 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005869}
5870
paul94f2b392005-06-28 12:44:16 +00005871static void
paul718e3742002-12-13 20:15:29 +00005872route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5873 struct bgp_info *binfo, afi_t afi, safi_t safi)
5874{
5875 char buf[INET6_ADDRSTRLEN];
5876 char buf1[BUFSIZ];
5877 struct attr *attr;
5878 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005879#ifdef HAVE_CLOCK_MONOTONIC
5880 time_t tbuf;
5881#endif
paul718e3742002-12-13 20:15:29 +00005882
5883 attr = binfo->attr;
5884
5885 if (attr)
5886 {
5887 /* Line1 display AS-path, Aggregator */
5888 if (attr->aspath)
5889 {
5890 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005891 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005892 vty_out (vty, "Local");
5893 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005894 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005895 }
5896
paulb40d9392005-08-22 22:34:41 +00005897 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5898 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005899 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5900 vty_out (vty, ", (stale)");
5901 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005902 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005903 attr->extra->aggregator_as,
5904 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005905 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5906 vty_out (vty, ", (Received from a RR-client)");
5907 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5908 vty_out (vty, ", (Received from a RS-client)");
5909 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5910 vty_out (vty, ", (history entry)");
5911 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5912 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005913 vty_out (vty, "%s", VTY_NEWLINE);
5914
5915 /* Line2 display Next-hop, Neighbor, Router-id */
5916 if (p->family == AF_INET)
5917 {
5918 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005919 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005920 inet_ntoa (attr->nexthop));
5921 }
5922#ifdef HAVE_IPV6
5923 else
5924 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005925 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005926 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005927 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005928 buf, INET6_ADDRSTRLEN));
5929 }
5930#endif /* HAVE_IPV6 */
5931
5932 if (binfo->peer == bgp->peer_self)
5933 {
5934 vty_out (vty, " from %s ",
5935 p->family == AF_INET ? "0.0.0.0" : "::");
5936 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5937 }
5938 else
5939 {
5940 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5941 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005942 else if (binfo->extra && binfo->extra->igpmetric)
5943 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005944 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005945 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005946 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005947 else
5948 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5949 }
5950 vty_out (vty, "%s", VTY_NEWLINE);
5951
5952#ifdef HAVE_IPV6
5953 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005954 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005955 {
5956 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005957 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005958 buf, INET6_ADDRSTRLEN),
5959 VTY_NEWLINE);
5960 }
5961#endif /* HAVE_IPV6 */
5962
5963 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5964 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5965
5966 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005967 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005968
5969 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005970 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005971 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005972 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005973
Paul Jakmafb982c22007-05-04 20:15:47 +00005974 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005975 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005976
5977 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5978 vty_out (vty, ", valid");
5979
5980 if (binfo->peer != bgp->peer_self)
5981 {
5982 if (binfo->peer->as == binfo->peer->local_as)
5983 vty_out (vty, ", internal");
5984 else
5985 vty_out (vty, ", %s",
5986 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5987 }
5988 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5989 vty_out (vty, ", aggregated, local");
5990 else if (binfo->type != ZEBRA_ROUTE_BGP)
5991 vty_out (vty, ", sourced");
5992 else
5993 vty_out (vty, ", sourced, local");
5994
5995 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5996 vty_out (vty, ", atomic-aggregate");
5997
5998 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5999 vty_out (vty, ", best");
6000
6001 vty_out (vty, "%s", VTY_NEWLINE);
6002
6003 /* Line 4 display Community */
6004 if (attr->community)
6005 vty_out (vty, " Community: %s%s", attr->community->str,
6006 VTY_NEWLINE);
6007
6008 /* Line 5 display Extended-community */
6009 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006010 vty_out (vty, " Extended Community: %s%s",
6011 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006012
6013 /* Line 6 display Originator, Cluster-id */
6014 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6015 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6016 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006017 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006018 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006019 vty_out (vty, " Originator: %s",
6020 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006021
6022 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6023 {
6024 int i;
6025 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006026 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6027 vty_out (vty, "%s ",
6028 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006029 }
6030 vty_out (vty, "%s", VTY_NEWLINE);
6031 }
Paul Jakma41367172007-08-06 15:24:51 +00006032
Paul Jakmafb982c22007-05-04 20:15:47 +00006033 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006034 bgp_damp_info_vty (vty, binfo);
6035
6036 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006037#ifdef HAVE_CLOCK_MONOTONIC
6038 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006039 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006040#else
6041 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6042#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006043 }
6044 vty_out (vty, "%s", VTY_NEWLINE);
6045}
6046
paulb40d9392005-08-22 22:34:41 +00006047#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 +00006048#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006049#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6050#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6051#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6052
6053enum bgp_show_type
6054{
6055 bgp_show_type_normal,
6056 bgp_show_type_regexp,
6057 bgp_show_type_prefix_list,
6058 bgp_show_type_filter_list,
6059 bgp_show_type_route_map,
6060 bgp_show_type_neighbor,
6061 bgp_show_type_cidr_only,
6062 bgp_show_type_prefix_longer,
6063 bgp_show_type_community_all,
6064 bgp_show_type_community,
6065 bgp_show_type_community_exact,
6066 bgp_show_type_community_list,
6067 bgp_show_type_community_list_exact,
6068 bgp_show_type_flap_statistics,
6069 bgp_show_type_flap_address,
6070 bgp_show_type_flap_prefix,
6071 bgp_show_type_flap_cidr_only,
6072 bgp_show_type_flap_regexp,
6073 bgp_show_type_flap_filter_list,
6074 bgp_show_type_flap_prefix_list,
6075 bgp_show_type_flap_prefix_longer,
6076 bgp_show_type_flap_route_map,
6077 bgp_show_type_flap_neighbor,
6078 bgp_show_type_dampend_paths,
6079 bgp_show_type_damp_neighbor
6080};
6081
ajs5a646652004-11-05 01:25:55 +00006082static int
paulfee0f4c2004-09-13 05:12:46 +00006083bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006084 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006085{
paul718e3742002-12-13 20:15:29 +00006086 struct bgp_info *ri;
6087 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006088 int header = 1;
paul718e3742002-12-13 20:15:29 +00006089 int display;
ajs5a646652004-11-05 01:25:55 +00006090 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006091
6092 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006093 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006094
paul718e3742002-12-13 20:15:29 +00006095 /* Start processing of routes. */
6096 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6097 if (rn->info != NULL)
6098 {
6099 display = 0;
6100
6101 for (ri = rn->info; ri; ri = ri->next)
6102 {
ajs5a646652004-11-05 01:25:55 +00006103 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006104 || type == bgp_show_type_flap_address
6105 || type == bgp_show_type_flap_prefix
6106 || type == bgp_show_type_flap_cidr_only
6107 || type == bgp_show_type_flap_regexp
6108 || type == bgp_show_type_flap_filter_list
6109 || type == bgp_show_type_flap_prefix_list
6110 || type == bgp_show_type_flap_prefix_longer
6111 || type == bgp_show_type_flap_route_map
6112 || type == bgp_show_type_flap_neighbor
6113 || type == bgp_show_type_dampend_paths
6114 || type == bgp_show_type_damp_neighbor)
6115 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006116 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006117 continue;
6118 }
6119 if (type == bgp_show_type_regexp
6120 || type == bgp_show_type_flap_regexp)
6121 {
ajs5a646652004-11-05 01:25:55 +00006122 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006123
6124 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6125 continue;
6126 }
6127 if (type == bgp_show_type_prefix_list
6128 || type == bgp_show_type_flap_prefix_list)
6129 {
ajs5a646652004-11-05 01:25:55 +00006130 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006131
6132 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6133 continue;
6134 }
6135 if (type == bgp_show_type_filter_list
6136 || type == bgp_show_type_flap_filter_list)
6137 {
ajs5a646652004-11-05 01:25:55 +00006138 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006139
6140 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6141 continue;
6142 }
6143 if (type == bgp_show_type_route_map
6144 || type == bgp_show_type_flap_route_map)
6145 {
ajs5a646652004-11-05 01:25:55 +00006146 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006147 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006148 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006149 int ret;
6150
Paul Jakmafb982c22007-05-04 20:15:47 +00006151 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006152 binfo.peer = ri->peer;
6153 binfo.attr = &dummy_attr;
6154
6155 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006156
6157 bgp_attr_extra_free (&dummy_attr);
6158
paul718e3742002-12-13 20:15:29 +00006159 if (ret == RMAP_DENYMATCH)
6160 continue;
6161 }
6162 if (type == bgp_show_type_neighbor
6163 || type == bgp_show_type_flap_neighbor
6164 || type == bgp_show_type_damp_neighbor)
6165 {
ajs5a646652004-11-05 01:25:55 +00006166 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006167
6168 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6169 continue;
6170 }
6171 if (type == bgp_show_type_cidr_only
6172 || type == bgp_show_type_flap_cidr_only)
6173 {
6174 u_int32_t destination;
6175
6176 destination = ntohl (rn->p.u.prefix4.s_addr);
6177 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6178 continue;
6179 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6180 continue;
6181 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6182 continue;
6183 }
6184 if (type == bgp_show_type_prefix_longer
6185 || type == bgp_show_type_flap_prefix_longer)
6186 {
ajs5a646652004-11-05 01:25:55 +00006187 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006188
6189 if (! prefix_match (p, &rn->p))
6190 continue;
6191 }
6192 if (type == bgp_show_type_community_all)
6193 {
6194 if (! ri->attr->community)
6195 continue;
6196 }
6197 if (type == bgp_show_type_community)
6198 {
ajs5a646652004-11-05 01:25:55 +00006199 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006200
6201 if (! ri->attr->community ||
6202 ! community_match (ri->attr->community, com))
6203 continue;
6204 }
6205 if (type == bgp_show_type_community_exact)
6206 {
ajs5a646652004-11-05 01:25:55 +00006207 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006208
6209 if (! ri->attr->community ||
6210 ! community_cmp (ri->attr->community, com))
6211 continue;
6212 }
6213 if (type == bgp_show_type_community_list)
6214 {
ajs5a646652004-11-05 01:25:55 +00006215 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006216
6217 if (! community_list_match (ri->attr->community, list))
6218 continue;
6219 }
6220 if (type == bgp_show_type_community_list_exact)
6221 {
ajs5a646652004-11-05 01:25:55 +00006222 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006223
6224 if (! community_list_exact_match (ri->attr->community, list))
6225 continue;
6226 }
6227 if (type == bgp_show_type_flap_address
6228 || type == bgp_show_type_flap_prefix)
6229 {
ajs5a646652004-11-05 01:25:55 +00006230 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006231
6232 if (! prefix_match (&rn->p, p))
6233 continue;
6234
6235 if (type == bgp_show_type_flap_prefix)
6236 if (p->prefixlen != rn->p.prefixlen)
6237 continue;
6238 }
6239 if (type == bgp_show_type_dampend_paths
6240 || type == bgp_show_type_damp_neighbor)
6241 {
6242 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6243 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6244 continue;
6245 }
6246
6247 if (header)
6248 {
hasso93406d82005-02-02 14:40:33 +00006249 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6250 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6251 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006252 if (type == bgp_show_type_dampend_paths
6253 || type == bgp_show_type_damp_neighbor)
6254 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6255 else if (type == bgp_show_type_flap_statistics
6256 || type == bgp_show_type_flap_address
6257 || type == bgp_show_type_flap_prefix
6258 || type == bgp_show_type_flap_cidr_only
6259 || type == bgp_show_type_flap_regexp
6260 || type == bgp_show_type_flap_filter_list
6261 || type == bgp_show_type_flap_prefix_list
6262 || type == bgp_show_type_flap_prefix_longer
6263 || type == bgp_show_type_flap_route_map
6264 || type == bgp_show_type_flap_neighbor)
6265 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6266 else
6267 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006268 header = 0;
6269 }
6270
6271 if (type == bgp_show_type_dampend_paths
6272 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006273 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006274 else if (type == bgp_show_type_flap_statistics
6275 || type == bgp_show_type_flap_address
6276 || type == bgp_show_type_flap_prefix
6277 || type == bgp_show_type_flap_cidr_only
6278 || type == bgp_show_type_flap_regexp
6279 || type == bgp_show_type_flap_filter_list
6280 || type == bgp_show_type_flap_prefix_list
6281 || type == bgp_show_type_flap_prefix_longer
6282 || type == bgp_show_type_flap_route_map
6283 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006284 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006285 else
ajs5a646652004-11-05 01:25:55 +00006286 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006287 display++;
6288 }
6289 if (display)
ajs5a646652004-11-05 01:25:55 +00006290 output_count++;
paul718e3742002-12-13 20:15:29 +00006291 }
6292
6293 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006294 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006295 {
6296 if (type == bgp_show_type_normal)
6297 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6298 }
6299 else
6300 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006301 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006302
6303 return CMD_SUCCESS;
6304}
6305
ajs5a646652004-11-05 01:25:55 +00006306static int
paulfee0f4c2004-09-13 05:12:46 +00006307bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006308 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006309{
6310 struct bgp_table *table;
6311
6312 if (bgp == NULL) {
6313 bgp = bgp_get_default ();
6314 }
6315
6316 if (bgp == NULL)
6317 {
6318 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6319 return CMD_WARNING;
6320 }
6321
6322
6323 table = bgp->rib[afi][safi];
6324
ajs5a646652004-11-05 01:25:55 +00006325 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006326}
6327
paul718e3742002-12-13 20:15:29 +00006328/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006329static void
paul718e3742002-12-13 20:15:29 +00006330route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6331 struct bgp_node *rn,
6332 struct prefix_rd *prd, afi_t afi, safi_t safi)
6333{
6334 struct bgp_info *ri;
6335 struct prefix *p;
6336 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006337 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006338 char buf1[INET6_ADDRSTRLEN];
6339 char buf2[INET6_ADDRSTRLEN];
6340 int count = 0;
6341 int best = 0;
6342 int suppress = 0;
6343 int no_export = 0;
6344 int no_advertise = 0;
6345 int local_as = 0;
6346 int first = 0;
6347
6348 p = &rn->p;
6349 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6350 (safi == SAFI_MPLS_VPN ?
6351 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6352 safi == SAFI_MPLS_VPN ? ":" : "",
6353 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6354 p->prefixlen, VTY_NEWLINE);
6355
6356 for (ri = rn->info; ri; ri = ri->next)
6357 {
6358 count++;
6359 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6360 {
6361 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006362 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006363 suppress = 1;
6364 if (ri->attr->community != NULL)
6365 {
6366 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6367 no_advertise = 1;
6368 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6369 no_export = 1;
6370 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6371 local_as = 1;
6372 }
6373 }
6374 }
6375
6376 vty_out (vty, "Paths: (%d available", count);
6377 if (best)
6378 {
6379 vty_out (vty, ", best #%d", best);
6380 if (safi == SAFI_UNICAST)
6381 vty_out (vty, ", table Default-IP-Routing-Table");
6382 }
6383 else
6384 vty_out (vty, ", no best path");
6385 if (no_advertise)
6386 vty_out (vty, ", not advertised to any peer");
6387 else if (no_export)
6388 vty_out (vty, ", not advertised to EBGP peer");
6389 else if (local_as)
6390 vty_out (vty, ", not advertised outside local AS");
6391 if (suppress)
6392 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6393 vty_out (vty, ")%s", VTY_NEWLINE);
6394
6395 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006396 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006397 {
6398 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6399 {
6400 if (! first)
6401 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6402 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6403 first = 1;
6404 }
6405 }
6406 if (! first)
6407 vty_out (vty, " Not advertised to any peer");
6408 vty_out (vty, "%s", VTY_NEWLINE);
6409}
6410
6411/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006412static int
paulfee0f4c2004-09-13 05:12:46 +00006413bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006414 struct bgp_table *rib, const char *ip_str,
6415 afi_t afi, safi_t safi, struct prefix_rd *prd,
6416 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006417{
6418 int ret;
6419 int header;
6420 int display = 0;
6421 struct prefix match;
6422 struct bgp_node *rn;
6423 struct bgp_node *rm;
6424 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006425 struct bgp_table *table;
6426
paul718e3742002-12-13 20:15:29 +00006427 /* Check IP address argument. */
6428 ret = str2prefix (ip_str, &match);
6429 if (! ret)
6430 {
6431 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6432 return CMD_WARNING;
6433 }
6434
6435 match.family = afi2family (afi);
6436
6437 if (safi == SAFI_MPLS_VPN)
6438 {
paulfee0f4c2004-09-13 05:12:46 +00006439 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006440 {
6441 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6442 continue;
6443
6444 if ((table = rn->info) != NULL)
6445 {
6446 header = 1;
6447
6448 if ((rm = bgp_node_match (table, &match)) != NULL)
6449 {
6450 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006451 {
6452 bgp_unlock_node (rm);
6453 continue;
6454 }
paul718e3742002-12-13 20:15:29 +00006455
6456 for (ri = rm->info; ri; ri = ri->next)
6457 {
6458 if (header)
6459 {
6460 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6461 AFI_IP, SAFI_MPLS_VPN);
6462
6463 header = 0;
6464 }
6465 display++;
6466 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6467 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006468
6469 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006470 }
6471 }
6472 }
6473 }
6474 else
6475 {
6476 header = 1;
6477
paulfee0f4c2004-09-13 05:12:46 +00006478 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006479 {
6480 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6481 {
6482 for (ri = rn->info; ri; ri = ri->next)
6483 {
6484 if (header)
6485 {
6486 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6487 header = 0;
6488 }
6489 display++;
6490 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6491 }
6492 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006493
6494 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006495 }
6496 }
6497
6498 if (! display)
6499 {
6500 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6501 return CMD_WARNING;
6502 }
6503
6504 return CMD_SUCCESS;
6505}
6506
paulfee0f4c2004-09-13 05:12:46 +00006507/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006508static int
paulfd79ac92004-10-13 05:06:08 +00006509bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006510 afi_t afi, safi_t safi, struct prefix_rd *prd,
6511 int prefix_check)
6512{
6513 struct bgp *bgp;
6514
6515 /* BGP structure lookup. */
6516 if (view_name)
6517 {
6518 bgp = bgp_lookup_by_name (view_name);
6519 if (bgp == NULL)
6520 {
6521 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6522 return CMD_WARNING;
6523 }
6524 }
6525 else
6526 {
6527 bgp = bgp_get_default ();
6528 if (bgp == NULL)
6529 {
6530 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6531 return CMD_WARNING;
6532 }
6533 }
6534
6535 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6536 afi, safi, prd, prefix_check);
6537}
6538
paul718e3742002-12-13 20:15:29 +00006539/* BGP route print out function. */
6540DEFUN (show_ip_bgp,
6541 show_ip_bgp_cmd,
6542 "show ip bgp",
6543 SHOW_STR
6544 IP_STR
6545 BGP_STR)
6546{
ajs5a646652004-11-05 01:25:55 +00006547 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006548}
6549
6550DEFUN (show_ip_bgp_ipv4,
6551 show_ip_bgp_ipv4_cmd,
6552 "show ip bgp ipv4 (unicast|multicast)",
6553 SHOW_STR
6554 IP_STR
6555 BGP_STR
6556 "Address family\n"
6557 "Address Family modifier\n"
6558 "Address Family modifier\n")
6559{
6560 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006561 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6562 NULL);
paul718e3742002-12-13 20:15:29 +00006563
ajs5a646652004-11-05 01:25:55 +00006564 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006565}
6566
Michael Lambert95cbbd22010-07-23 14:43:04 -04006567ALIAS (show_ip_bgp_ipv4,
6568 show_bgp_ipv4_safi_cmd,
6569 "show bgp ipv4 (unicast|multicast)",
6570 SHOW_STR
6571 BGP_STR
6572 "Address family\n"
6573 "Address Family modifier\n"
6574 "Address Family modifier\n")
6575
paul718e3742002-12-13 20:15:29 +00006576DEFUN (show_ip_bgp_route,
6577 show_ip_bgp_route_cmd,
6578 "show ip bgp A.B.C.D",
6579 SHOW_STR
6580 IP_STR
6581 BGP_STR
6582 "Network in the BGP routing table to display\n")
6583{
6584 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6585}
6586
6587DEFUN (show_ip_bgp_ipv4_route,
6588 show_ip_bgp_ipv4_route_cmd,
6589 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6590 SHOW_STR
6591 IP_STR
6592 BGP_STR
6593 "Address family\n"
6594 "Address Family modifier\n"
6595 "Address Family modifier\n"
6596 "Network in the BGP routing table to display\n")
6597{
6598 if (strncmp (argv[0], "m", 1) == 0)
6599 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6600
6601 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6602}
6603
Michael Lambert95cbbd22010-07-23 14:43:04 -04006604ALIAS (show_ip_bgp_ipv4_route,
6605 show_bgp_ipv4_safi_route_cmd,
6606 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6607 SHOW_STR
6608 BGP_STR
6609 "Address family\n"
6610 "Address Family modifier\n"
6611 "Address Family modifier\n"
6612 "Network in the BGP routing table to display\n")
6613
paul718e3742002-12-13 20:15:29 +00006614DEFUN (show_ip_bgp_vpnv4_all_route,
6615 show_ip_bgp_vpnv4_all_route_cmd,
6616 "show ip bgp vpnv4 all A.B.C.D",
6617 SHOW_STR
6618 IP_STR
6619 BGP_STR
6620 "Display VPNv4 NLRI specific information\n"
6621 "Display information about all VPNv4 NLRIs\n"
6622 "Network in the BGP routing table to display\n")
6623{
6624 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6625}
6626
6627DEFUN (show_ip_bgp_vpnv4_rd_route,
6628 show_ip_bgp_vpnv4_rd_route_cmd,
6629 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6630 SHOW_STR
6631 IP_STR
6632 BGP_STR
6633 "Display VPNv4 NLRI specific information\n"
6634 "Display information for a route distinguisher\n"
6635 "VPN Route Distinguisher\n"
6636 "Network in the BGP routing table to display\n")
6637{
6638 int ret;
6639 struct prefix_rd prd;
6640
6641 ret = str2prefix_rd (argv[0], &prd);
6642 if (! ret)
6643 {
6644 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6645 return CMD_WARNING;
6646 }
6647 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6648}
6649
6650DEFUN (show_ip_bgp_prefix,
6651 show_ip_bgp_prefix_cmd,
6652 "show ip bgp A.B.C.D/M",
6653 SHOW_STR
6654 IP_STR
6655 BGP_STR
6656 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6657{
6658 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6659}
6660
6661DEFUN (show_ip_bgp_ipv4_prefix,
6662 show_ip_bgp_ipv4_prefix_cmd,
6663 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6664 SHOW_STR
6665 IP_STR
6666 BGP_STR
6667 "Address family\n"
6668 "Address Family modifier\n"
6669 "Address Family modifier\n"
6670 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6671{
6672 if (strncmp (argv[0], "m", 1) == 0)
6673 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6674
6675 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6676}
6677
Michael Lambert95cbbd22010-07-23 14:43:04 -04006678ALIAS (show_ip_bgp_ipv4_prefix,
6679 show_bgp_ipv4_safi_prefix_cmd,
6680 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6681 SHOW_STR
6682 BGP_STR
6683 "Address family\n"
6684 "Address Family modifier\n"
6685 "Address Family modifier\n"
6686 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6687
paul718e3742002-12-13 20:15:29 +00006688DEFUN (show_ip_bgp_vpnv4_all_prefix,
6689 show_ip_bgp_vpnv4_all_prefix_cmd,
6690 "show ip bgp vpnv4 all A.B.C.D/M",
6691 SHOW_STR
6692 IP_STR
6693 BGP_STR
6694 "Display VPNv4 NLRI specific information\n"
6695 "Display information about all VPNv4 NLRIs\n"
6696 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6697{
6698 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6699}
6700
6701DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6702 show_ip_bgp_vpnv4_rd_prefix_cmd,
6703 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6704 SHOW_STR
6705 IP_STR
6706 BGP_STR
6707 "Display VPNv4 NLRI specific information\n"
6708 "Display information for a route distinguisher\n"
6709 "VPN Route Distinguisher\n"
6710 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6711{
6712 int ret;
6713 struct prefix_rd prd;
6714
6715 ret = str2prefix_rd (argv[0], &prd);
6716 if (! ret)
6717 {
6718 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6719 return CMD_WARNING;
6720 }
6721 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6722}
6723
6724DEFUN (show_ip_bgp_view,
6725 show_ip_bgp_view_cmd,
6726 "show ip bgp view WORD",
6727 SHOW_STR
6728 IP_STR
6729 BGP_STR
6730 "BGP view\n"
6731 "BGP view name\n")
6732{
paulbb46e942003-10-24 19:02:03 +00006733 struct bgp *bgp;
6734
6735 /* BGP structure lookup. */
6736 bgp = bgp_lookup_by_name (argv[0]);
6737 if (bgp == NULL)
6738 {
6739 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6740 return CMD_WARNING;
6741 }
6742
ajs5a646652004-11-05 01:25:55 +00006743 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006744}
6745
6746DEFUN (show_ip_bgp_view_route,
6747 show_ip_bgp_view_route_cmd,
6748 "show ip bgp view WORD A.B.C.D",
6749 SHOW_STR
6750 IP_STR
6751 BGP_STR
6752 "BGP view\n"
6753 "BGP view name\n"
6754 "Network in the BGP routing table to display\n")
6755{
6756 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6757}
6758
6759DEFUN (show_ip_bgp_view_prefix,
6760 show_ip_bgp_view_prefix_cmd,
6761 "show ip bgp view WORD A.B.C.D/M",
6762 SHOW_STR
6763 IP_STR
6764 BGP_STR
6765 "BGP view\n"
6766 "BGP view name\n"
6767 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6768{
6769 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6770}
6771
6772#ifdef HAVE_IPV6
6773DEFUN (show_bgp,
6774 show_bgp_cmd,
6775 "show bgp",
6776 SHOW_STR
6777 BGP_STR)
6778{
ajs5a646652004-11-05 01:25:55 +00006779 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6780 NULL);
paul718e3742002-12-13 20:15:29 +00006781}
6782
6783ALIAS (show_bgp,
6784 show_bgp_ipv6_cmd,
6785 "show bgp ipv6",
6786 SHOW_STR
6787 BGP_STR
6788 "Address family\n")
6789
Michael Lambert95cbbd22010-07-23 14:43:04 -04006790DEFUN (show_bgp_ipv6_safi,
6791 show_bgp_ipv6_safi_cmd,
6792 "show bgp ipv6 (unicast|multicast)",
6793 SHOW_STR
6794 BGP_STR
6795 "Address family\n"
6796 "Address Family modifier\n"
6797 "Address Family modifier\n")
6798{
6799 if (strncmp (argv[0], "m", 1) == 0)
6800 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6801 NULL);
6802
6803 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6804}
6805
paul718e3742002-12-13 20:15:29 +00006806/* old command */
6807DEFUN (show_ipv6_bgp,
6808 show_ipv6_bgp_cmd,
6809 "show ipv6 bgp",
6810 SHOW_STR
6811 IP_STR
6812 BGP_STR)
6813{
ajs5a646652004-11-05 01:25:55 +00006814 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6815 NULL);
paul718e3742002-12-13 20:15:29 +00006816}
6817
6818DEFUN (show_bgp_route,
6819 show_bgp_route_cmd,
6820 "show bgp X:X::X:X",
6821 SHOW_STR
6822 BGP_STR
6823 "Network in the BGP routing table to display\n")
6824{
6825 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6826}
6827
6828ALIAS (show_bgp_route,
6829 show_bgp_ipv6_route_cmd,
6830 "show bgp ipv6 X:X::X:X",
6831 SHOW_STR
6832 BGP_STR
6833 "Address family\n"
6834 "Network in the BGP routing table to display\n")
6835
Michael Lambert95cbbd22010-07-23 14:43:04 -04006836DEFUN (show_bgp_ipv6_safi_route,
6837 show_bgp_ipv6_safi_route_cmd,
6838 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6839 SHOW_STR
6840 BGP_STR
6841 "Address family\n"
6842 "Address Family modifier\n"
6843 "Address Family modifier\n"
6844 "Network in the BGP routing table to display\n")
6845{
6846 if (strncmp (argv[0], "m", 1) == 0)
6847 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6848
6849 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6850}
6851
paul718e3742002-12-13 20:15:29 +00006852/* old command */
6853DEFUN (show_ipv6_bgp_route,
6854 show_ipv6_bgp_route_cmd,
6855 "show ipv6 bgp X:X::X:X",
6856 SHOW_STR
6857 IP_STR
6858 BGP_STR
6859 "Network in the BGP routing table to display\n")
6860{
6861 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6862}
6863
6864DEFUN (show_bgp_prefix,
6865 show_bgp_prefix_cmd,
6866 "show bgp X:X::X:X/M",
6867 SHOW_STR
6868 BGP_STR
6869 "IPv6 prefix <network>/<length>\n")
6870{
6871 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6872}
6873
6874ALIAS (show_bgp_prefix,
6875 show_bgp_ipv6_prefix_cmd,
6876 "show bgp ipv6 X:X::X:X/M",
6877 SHOW_STR
6878 BGP_STR
6879 "Address family\n"
6880 "IPv6 prefix <network>/<length>\n")
6881
Michael Lambert95cbbd22010-07-23 14:43:04 -04006882DEFUN (show_bgp_ipv6_safi_prefix,
6883 show_bgp_ipv6_safi_prefix_cmd,
6884 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6885 SHOW_STR
6886 BGP_STR
6887 "Address family\n"
6888 "Address Family modifier\n"
6889 "Address Family modifier\n"
6890 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6891{
6892 if (strncmp (argv[0], "m", 1) == 0)
6893 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6894
6895 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6896}
6897
paul718e3742002-12-13 20:15:29 +00006898/* old command */
6899DEFUN (show_ipv6_bgp_prefix,
6900 show_ipv6_bgp_prefix_cmd,
6901 "show ipv6 bgp X:X::X:X/M",
6902 SHOW_STR
6903 IP_STR
6904 BGP_STR
6905 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6906{
6907 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6908}
6909
paulbb46e942003-10-24 19:02:03 +00006910DEFUN (show_bgp_view,
6911 show_bgp_view_cmd,
6912 "show bgp view WORD",
6913 SHOW_STR
6914 BGP_STR
6915 "BGP view\n"
6916 "View name\n")
6917{
6918 struct bgp *bgp;
6919
6920 /* BGP structure lookup. */
6921 bgp = bgp_lookup_by_name (argv[0]);
6922 if (bgp == NULL)
6923 {
6924 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6925 return CMD_WARNING;
6926 }
6927
ajs5a646652004-11-05 01:25:55 +00006928 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006929}
6930
6931ALIAS (show_bgp_view,
6932 show_bgp_view_ipv6_cmd,
6933 "show bgp view WORD ipv6",
6934 SHOW_STR
6935 BGP_STR
6936 "BGP view\n"
6937 "View name\n"
6938 "Address family\n")
6939
6940DEFUN (show_bgp_view_route,
6941 show_bgp_view_route_cmd,
6942 "show bgp view WORD X:X::X:X",
6943 SHOW_STR
6944 BGP_STR
6945 "BGP view\n"
6946 "View name\n"
6947 "Network in the BGP routing table to display\n")
6948{
6949 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6950}
6951
6952ALIAS (show_bgp_view_route,
6953 show_bgp_view_ipv6_route_cmd,
6954 "show bgp view WORD ipv6 X:X::X:X",
6955 SHOW_STR
6956 BGP_STR
6957 "BGP view\n"
6958 "View name\n"
6959 "Address family\n"
6960 "Network in the BGP routing table to display\n")
6961
6962DEFUN (show_bgp_view_prefix,
6963 show_bgp_view_prefix_cmd,
6964 "show bgp view WORD X:X::X:X/M",
6965 SHOW_STR
6966 BGP_STR
6967 "BGP view\n"
6968 "View name\n"
6969 "IPv6 prefix <network>/<length>\n")
6970{
6971 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6972}
6973
6974ALIAS (show_bgp_view_prefix,
6975 show_bgp_view_ipv6_prefix_cmd,
6976 "show bgp view WORD ipv6 X:X::X:X/M",
6977 SHOW_STR
6978 BGP_STR
6979 "BGP view\n"
6980 "View name\n"
6981 "Address family\n"
6982 "IPv6 prefix <network>/<length>\n")
6983
paul718e3742002-12-13 20:15:29 +00006984/* old command */
6985DEFUN (show_ipv6_mbgp,
6986 show_ipv6_mbgp_cmd,
6987 "show ipv6 mbgp",
6988 SHOW_STR
6989 IP_STR
6990 MBGP_STR)
6991{
ajs5a646652004-11-05 01:25:55 +00006992 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6993 NULL);
paul718e3742002-12-13 20:15:29 +00006994}
6995
6996/* old command */
6997DEFUN (show_ipv6_mbgp_route,
6998 show_ipv6_mbgp_route_cmd,
6999 "show ipv6 mbgp X:X::X:X",
7000 SHOW_STR
7001 IP_STR
7002 MBGP_STR
7003 "Network in the MBGP routing table to display\n")
7004{
7005 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7006}
7007
7008/* old command */
7009DEFUN (show_ipv6_mbgp_prefix,
7010 show_ipv6_mbgp_prefix_cmd,
7011 "show ipv6 mbgp X:X::X:X/M",
7012 SHOW_STR
7013 IP_STR
7014 MBGP_STR
7015 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7016{
7017 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7018}
7019#endif
7020
paul718e3742002-12-13 20:15:29 +00007021
paul94f2b392005-06-28 12:44:16 +00007022static int
paulfd79ac92004-10-13 05:06:08 +00007023bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007024 safi_t safi, enum bgp_show_type type)
7025{
7026 int i;
7027 struct buffer *b;
7028 char *regstr;
7029 int first;
7030 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007031 int rc;
paul718e3742002-12-13 20:15:29 +00007032
7033 first = 0;
7034 b = buffer_new (1024);
7035 for (i = 0; i < argc; i++)
7036 {
7037 if (first)
7038 buffer_putc (b, ' ');
7039 else
7040 {
7041 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7042 continue;
7043 first = 1;
7044 }
7045
7046 buffer_putstr (b, argv[i]);
7047 }
7048 buffer_putc (b, '\0');
7049
7050 regstr = buffer_getstr (b);
7051 buffer_free (b);
7052
7053 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007054 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007055 if (! regex)
7056 {
7057 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7058 VTY_NEWLINE);
7059 return CMD_WARNING;
7060 }
7061
ajs5a646652004-11-05 01:25:55 +00007062 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7063 bgp_regex_free (regex);
7064 return rc;
paul718e3742002-12-13 20:15:29 +00007065}
7066
7067DEFUN (show_ip_bgp_regexp,
7068 show_ip_bgp_regexp_cmd,
7069 "show ip bgp regexp .LINE",
7070 SHOW_STR
7071 IP_STR
7072 BGP_STR
7073 "Display routes matching the AS path regular expression\n"
7074 "A regular-expression to match the BGP AS paths\n")
7075{
7076 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7077 bgp_show_type_regexp);
7078}
7079
7080DEFUN (show_ip_bgp_flap_regexp,
7081 show_ip_bgp_flap_regexp_cmd,
7082 "show ip bgp flap-statistics regexp .LINE",
7083 SHOW_STR
7084 IP_STR
7085 BGP_STR
7086 "Display flap statistics of routes\n"
7087 "Display routes matching the AS path regular expression\n"
7088 "A regular-expression to match the BGP AS paths\n")
7089{
7090 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7091 bgp_show_type_flap_regexp);
7092}
7093
7094DEFUN (show_ip_bgp_ipv4_regexp,
7095 show_ip_bgp_ipv4_regexp_cmd,
7096 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7097 SHOW_STR
7098 IP_STR
7099 BGP_STR
7100 "Address family\n"
7101 "Address Family modifier\n"
7102 "Address Family modifier\n"
7103 "Display routes matching the AS path regular expression\n"
7104 "A regular-expression to match the BGP AS paths\n")
7105{
7106 if (strncmp (argv[0], "m", 1) == 0)
7107 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7108 bgp_show_type_regexp);
7109
7110 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7111 bgp_show_type_regexp);
7112}
7113
7114#ifdef HAVE_IPV6
7115DEFUN (show_bgp_regexp,
7116 show_bgp_regexp_cmd,
7117 "show bgp regexp .LINE",
7118 SHOW_STR
7119 BGP_STR
7120 "Display routes matching the AS path regular expression\n"
7121 "A regular-expression to match the BGP AS paths\n")
7122{
7123 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7124 bgp_show_type_regexp);
7125}
7126
7127ALIAS (show_bgp_regexp,
7128 show_bgp_ipv6_regexp_cmd,
7129 "show bgp ipv6 regexp .LINE",
7130 SHOW_STR
7131 BGP_STR
7132 "Address family\n"
7133 "Display routes matching the AS path regular expression\n"
7134 "A regular-expression to match the BGP AS paths\n")
7135
7136/* old command */
7137DEFUN (show_ipv6_bgp_regexp,
7138 show_ipv6_bgp_regexp_cmd,
7139 "show ipv6 bgp regexp .LINE",
7140 SHOW_STR
7141 IP_STR
7142 BGP_STR
7143 "Display routes matching the AS path regular expression\n"
7144 "A regular-expression to match the BGP AS paths\n")
7145{
7146 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7147 bgp_show_type_regexp);
7148}
7149
7150/* old command */
7151DEFUN (show_ipv6_mbgp_regexp,
7152 show_ipv6_mbgp_regexp_cmd,
7153 "show ipv6 mbgp regexp .LINE",
7154 SHOW_STR
7155 IP_STR
7156 BGP_STR
7157 "Display routes matching the AS path regular expression\n"
7158 "A regular-expression to match the MBGP AS paths\n")
7159{
7160 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7161 bgp_show_type_regexp);
7162}
7163#endif /* HAVE_IPV6 */
7164
paul94f2b392005-06-28 12:44:16 +00007165static int
paulfd79ac92004-10-13 05:06:08 +00007166bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007167 safi_t safi, enum bgp_show_type type)
7168{
7169 struct prefix_list *plist;
7170
7171 plist = prefix_list_lookup (afi, prefix_list_str);
7172 if (plist == NULL)
7173 {
7174 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7175 prefix_list_str, VTY_NEWLINE);
7176 return CMD_WARNING;
7177 }
7178
ajs5a646652004-11-05 01:25:55 +00007179 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007180}
7181
7182DEFUN (show_ip_bgp_prefix_list,
7183 show_ip_bgp_prefix_list_cmd,
7184 "show ip bgp prefix-list WORD",
7185 SHOW_STR
7186 IP_STR
7187 BGP_STR
7188 "Display routes conforming to the prefix-list\n"
7189 "IP prefix-list name\n")
7190{
7191 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7192 bgp_show_type_prefix_list);
7193}
7194
7195DEFUN (show_ip_bgp_flap_prefix_list,
7196 show_ip_bgp_flap_prefix_list_cmd,
7197 "show ip bgp flap-statistics prefix-list WORD",
7198 SHOW_STR
7199 IP_STR
7200 BGP_STR
7201 "Display flap statistics of routes\n"
7202 "Display routes conforming to the prefix-list\n"
7203 "IP prefix-list name\n")
7204{
7205 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7206 bgp_show_type_flap_prefix_list);
7207}
7208
7209DEFUN (show_ip_bgp_ipv4_prefix_list,
7210 show_ip_bgp_ipv4_prefix_list_cmd,
7211 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7212 SHOW_STR
7213 IP_STR
7214 BGP_STR
7215 "Address family\n"
7216 "Address Family modifier\n"
7217 "Address Family modifier\n"
7218 "Display routes conforming to the prefix-list\n"
7219 "IP prefix-list name\n")
7220{
7221 if (strncmp (argv[0], "m", 1) == 0)
7222 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7223 bgp_show_type_prefix_list);
7224
7225 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7226 bgp_show_type_prefix_list);
7227}
7228
7229#ifdef HAVE_IPV6
7230DEFUN (show_bgp_prefix_list,
7231 show_bgp_prefix_list_cmd,
7232 "show bgp prefix-list WORD",
7233 SHOW_STR
7234 BGP_STR
7235 "Display routes conforming to the prefix-list\n"
7236 "IPv6 prefix-list name\n")
7237{
7238 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7239 bgp_show_type_prefix_list);
7240}
7241
7242ALIAS (show_bgp_prefix_list,
7243 show_bgp_ipv6_prefix_list_cmd,
7244 "show bgp ipv6 prefix-list WORD",
7245 SHOW_STR
7246 BGP_STR
7247 "Address family\n"
7248 "Display routes conforming to the prefix-list\n"
7249 "IPv6 prefix-list name\n")
7250
7251/* old command */
7252DEFUN (show_ipv6_bgp_prefix_list,
7253 show_ipv6_bgp_prefix_list_cmd,
7254 "show ipv6 bgp prefix-list WORD",
7255 SHOW_STR
7256 IPV6_STR
7257 BGP_STR
7258 "Display routes matching the prefix-list\n"
7259 "IPv6 prefix-list name\n")
7260{
7261 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7262 bgp_show_type_prefix_list);
7263}
7264
7265/* old command */
7266DEFUN (show_ipv6_mbgp_prefix_list,
7267 show_ipv6_mbgp_prefix_list_cmd,
7268 "show ipv6 mbgp prefix-list WORD",
7269 SHOW_STR
7270 IPV6_STR
7271 MBGP_STR
7272 "Display routes matching the prefix-list\n"
7273 "IPv6 prefix-list name\n")
7274{
7275 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7276 bgp_show_type_prefix_list);
7277}
7278#endif /* HAVE_IPV6 */
7279
paul94f2b392005-06-28 12:44:16 +00007280static int
paulfd79ac92004-10-13 05:06:08 +00007281bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007282 safi_t safi, enum bgp_show_type type)
7283{
7284 struct as_list *as_list;
7285
7286 as_list = as_list_lookup (filter);
7287 if (as_list == NULL)
7288 {
7289 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7290 return CMD_WARNING;
7291 }
7292
ajs5a646652004-11-05 01:25:55 +00007293 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007294}
7295
7296DEFUN (show_ip_bgp_filter_list,
7297 show_ip_bgp_filter_list_cmd,
7298 "show ip bgp filter-list WORD",
7299 SHOW_STR
7300 IP_STR
7301 BGP_STR
7302 "Display routes conforming to the filter-list\n"
7303 "Regular expression access list name\n")
7304{
7305 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7306 bgp_show_type_filter_list);
7307}
7308
7309DEFUN (show_ip_bgp_flap_filter_list,
7310 show_ip_bgp_flap_filter_list_cmd,
7311 "show ip bgp flap-statistics filter-list WORD",
7312 SHOW_STR
7313 IP_STR
7314 BGP_STR
7315 "Display flap statistics of routes\n"
7316 "Display routes conforming to the filter-list\n"
7317 "Regular expression access list name\n")
7318{
7319 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7320 bgp_show_type_flap_filter_list);
7321}
7322
7323DEFUN (show_ip_bgp_ipv4_filter_list,
7324 show_ip_bgp_ipv4_filter_list_cmd,
7325 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7326 SHOW_STR
7327 IP_STR
7328 BGP_STR
7329 "Address family\n"
7330 "Address Family modifier\n"
7331 "Address Family modifier\n"
7332 "Display routes conforming to the filter-list\n"
7333 "Regular expression access list name\n")
7334{
7335 if (strncmp (argv[0], "m", 1) == 0)
7336 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7337 bgp_show_type_filter_list);
7338
7339 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7340 bgp_show_type_filter_list);
7341}
7342
7343#ifdef HAVE_IPV6
7344DEFUN (show_bgp_filter_list,
7345 show_bgp_filter_list_cmd,
7346 "show bgp filter-list WORD",
7347 SHOW_STR
7348 BGP_STR
7349 "Display routes conforming to the filter-list\n"
7350 "Regular expression access list name\n")
7351{
7352 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7353 bgp_show_type_filter_list);
7354}
7355
7356ALIAS (show_bgp_filter_list,
7357 show_bgp_ipv6_filter_list_cmd,
7358 "show bgp ipv6 filter-list WORD",
7359 SHOW_STR
7360 BGP_STR
7361 "Address family\n"
7362 "Display routes conforming to the filter-list\n"
7363 "Regular expression access list name\n")
7364
7365/* old command */
7366DEFUN (show_ipv6_bgp_filter_list,
7367 show_ipv6_bgp_filter_list_cmd,
7368 "show ipv6 bgp filter-list WORD",
7369 SHOW_STR
7370 IPV6_STR
7371 BGP_STR
7372 "Display routes conforming to the filter-list\n"
7373 "Regular expression access list name\n")
7374{
7375 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7376 bgp_show_type_filter_list);
7377}
7378
7379/* old command */
7380DEFUN (show_ipv6_mbgp_filter_list,
7381 show_ipv6_mbgp_filter_list_cmd,
7382 "show ipv6 mbgp filter-list WORD",
7383 SHOW_STR
7384 IPV6_STR
7385 MBGP_STR
7386 "Display routes conforming to the filter-list\n"
7387 "Regular expression access list name\n")
7388{
7389 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7390 bgp_show_type_filter_list);
7391}
7392#endif /* HAVE_IPV6 */
7393
paul94f2b392005-06-28 12:44:16 +00007394static int
paulfd79ac92004-10-13 05:06:08 +00007395bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007396 safi_t safi, enum bgp_show_type type)
7397{
7398 struct route_map *rmap;
7399
7400 rmap = route_map_lookup_by_name (rmap_str);
7401 if (! rmap)
7402 {
7403 vty_out (vty, "%% %s is not a valid route-map name%s",
7404 rmap_str, VTY_NEWLINE);
7405 return CMD_WARNING;
7406 }
7407
ajs5a646652004-11-05 01:25:55 +00007408 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007409}
7410
7411DEFUN (show_ip_bgp_route_map,
7412 show_ip_bgp_route_map_cmd,
7413 "show ip bgp route-map WORD",
7414 SHOW_STR
7415 IP_STR
7416 BGP_STR
7417 "Display routes matching the route-map\n"
7418 "A route-map to match on\n")
7419{
7420 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7421 bgp_show_type_route_map);
7422}
7423
7424DEFUN (show_ip_bgp_flap_route_map,
7425 show_ip_bgp_flap_route_map_cmd,
7426 "show ip bgp flap-statistics route-map WORD",
7427 SHOW_STR
7428 IP_STR
7429 BGP_STR
7430 "Display flap statistics of routes\n"
7431 "Display routes matching the route-map\n"
7432 "A route-map to match on\n")
7433{
7434 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7435 bgp_show_type_flap_route_map);
7436}
7437
7438DEFUN (show_ip_bgp_ipv4_route_map,
7439 show_ip_bgp_ipv4_route_map_cmd,
7440 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7441 SHOW_STR
7442 IP_STR
7443 BGP_STR
7444 "Address family\n"
7445 "Address Family modifier\n"
7446 "Address Family modifier\n"
7447 "Display routes matching the route-map\n"
7448 "A route-map to match on\n")
7449{
7450 if (strncmp (argv[0], "m", 1) == 0)
7451 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7452 bgp_show_type_route_map);
7453
7454 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7455 bgp_show_type_route_map);
7456}
7457
7458DEFUN (show_bgp_route_map,
7459 show_bgp_route_map_cmd,
7460 "show bgp route-map WORD",
7461 SHOW_STR
7462 BGP_STR
7463 "Display routes matching the route-map\n"
7464 "A route-map to match on\n")
7465{
7466 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7467 bgp_show_type_route_map);
7468}
7469
7470ALIAS (show_bgp_route_map,
7471 show_bgp_ipv6_route_map_cmd,
7472 "show bgp ipv6 route-map WORD",
7473 SHOW_STR
7474 BGP_STR
7475 "Address family\n"
7476 "Display routes matching the route-map\n"
7477 "A route-map to match on\n")
7478
7479DEFUN (show_ip_bgp_cidr_only,
7480 show_ip_bgp_cidr_only_cmd,
7481 "show ip bgp cidr-only",
7482 SHOW_STR
7483 IP_STR
7484 BGP_STR
7485 "Display only routes with non-natural netmasks\n")
7486{
7487 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007488 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007489}
7490
7491DEFUN (show_ip_bgp_flap_cidr_only,
7492 show_ip_bgp_flap_cidr_only_cmd,
7493 "show ip bgp flap-statistics cidr-only",
7494 SHOW_STR
7495 IP_STR
7496 BGP_STR
7497 "Display flap statistics of routes\n"
7498 "Display only routes with non-natural netmasks\n")
7499{
7500 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007501 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007502}
7503
7504DEFUN (show_ip_bgp_ipv4_cidr_only,
7505 show_ip_bgp_ipv4_cidr_only_cmd,
7506 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7507 SHOW_STR
7508 IP_STR
7509 BGP_STR
7510 "Address family\n"
7511 "Address Family modifier\n"
7512 "Address Family modifier\n"
7513 "Display only routes with non-natural netmasks\n")
7514{
7515 if (strncmp (argv[0], "m", 1) == 0)
7516 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007517 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007518
7519 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007520 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007521}
7522
7523DEFUN (show_ip_bgp_community_all,
7524 show_ip_bgp_community_all_cmd,
7525 "show ip bgp community",
7526 SHOW_STR
7527 IP_STR
7528 BGP_STR
7529 "Display routes matching the communities\n")
7530{
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
7535DEFUN (show_ip_bgp_ipv4_community_all,
7536 show_ip_bgp_ipv4_community_all_cmd,
7537 "show ip bgp ipv4 (unicast|multicast) community",
7538 SHOW_STR
7539 IP_STR
7540 BGP_STR
7541 "Address family\n"
7542 "Address Family modifier\n"
7543 "Address Family modifier\n"
7544 "Display routes matching the communities\n")
7545{
7546 if (strncmp (argv[0], "m", 1) == 0)
7547 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007548 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007549
7550 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007551 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007552}
7553
7554#ifdef HAVE_IPV6
7555DEFUN (show_bgp_community_all,
7556 show_bgp_community_all_cmd,
7557 "show bgp community",
7558 SHOW_STR
7559 BGP_STR
7560 "Display routes matching the communities\n")
7561{
7562 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007563 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007564}
7565
7566ALIAS (show_bgp_community_all,
7567 show_bgp_ipv6_community_all_cmd,
7568 "show bgp ipv6 community",
7569 SHOW_STR
7570 BGP_STR
7571 "Address family\n"
7572 "Display routes matching the communities\n")
7573
7574/* old command */
7575DEFUN (show_ipv6_bgp_community_all,
7576 show_ipv6_bgp_community_all_cmd,
7577 "show ipv6 bgp community",
7578 SHOW_STR
7579 IPV6_STR
7580 BGP_STR
7581 "Display routes matching the communities\n")
7582{
7583 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007584 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007585}
7586
7587/* old command */
7588DEFUN (show_ipv6_mbgp_community_all,
7589 show_ipv6_mbgp_community_all_cmd,
7590 "show ipv6 mbgp community",
7591 SHOW_STR
7592 IPV6_STR
7593 MBGP_STR
7594 "Display routes matching the communities\n")
7595{
7596 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007597 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007598}
7599#endif /* HAVE_IPV6 */
7600
paul94f2b392005-06-28 12:44:16 +00007601static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007602bgp_show_community (struct vty *vty, const char *view_name, int argc,
7603 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007604{
7605 struct community *com;
7606 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007607 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007608 int i;
7609 char *str;
7610 int first = 0;
7611
Michael Lambert95cbbd22010-07-23 14:43:04 -04007612 /* BGP structure lookup */
7613 if (view_name)
7614 {
7615 bgp = bgp_lookup_by_name (view_name);
7616 if (bgp == NULL)
7617 {
7618 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7619 return CMD_WARNING;
7620 }
7621 }
7622 else
7623 {
7624 bgp = bgp_get_default ();
7625 if (bgp == NULL)
7626 {
7627 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7628 return CMD_WARNING;
7629 }
7630 }
7631
paul718e3742002-12-13 20:15:29 +00007632 b = buffer_new (1024);
7633 for (i = 0; i < argc; i++)
7634 {
7635 if (first)
7636 buffer_putc (b, ' ');
7637 else
7638 {
7639 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7640 continue;
7641 first = 1;
7642 }
7643
7644 buffer_putstr (b, argv[i]);
7645 }
7646 buffer_putc (b, '\0');
7647
7648 str = buffer_getstr (b);
7649 buffer_free (b);
7650
7651 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007652 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007653 if (! com)
7654 {
7655 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7656 return CMD_WARNING;
7657 }
7658
Michael Lambert95cbbd22010-07-23 14:43:04 -04007659 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007660 (exact ? bgp_show_type_community_exact :
7661 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007662}
7663
7664DEFUN (show_ip_bgp_community,
7665 show_ip_bgp_community_cmd,
7666 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7667 SHOW_STR
7668 IP_STR
7669 BGP_STR
7670 "Display routes matching the communities\n"
7671 "community number\n"
7672 "Do not send outside local AS (well-known community)\n"
7673 "Do not advertise to any peer (well-known community)\n"
7674 "Do not export to next AS (well-known community)\n")
7675{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007676 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007677}
7678
7679ALIAS (show_ip_bgp_community,
7680 show_ip_bgp_community2_cmd,
7681 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7682 SHOW_STR
7683 IP_STR
7684 BGP_STR
7685 "Display routes matching the communities\n"
7686 "community number\n"
7687 "Do not send outside local AS (well-known community)\n"
7688 "Do not advertise to any peer (well-known community)\n"
7689 "Do not export to next AS (well-known community)\n"
7690 "community number\n"
7691 "Do not send outside local AS (well-known community)\n"
7692 "Do not advertise to any peer (well-known community)\n"
7693 "Do not export to next AS (well-known community)\n")
7694
7695ALIAS (show_ip_bgp_community,
7696 show_ip_bgp_community3_cmd,
7697 "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)",
7698 SHOW_STR
7699 IP_STR
7700 BGP_STR
7701 "Display routes matching the communities\n"
7702 "community number\n"
7703 "Do not send outside local AS (well-known community)\n"
7704 "Do not advertise to any peer (well-known community)\n"
7705 "Do not export to next AS (well-known community)\n"
7706 "community number\n"
7707 "Do not send outside local AS (well-known community)\n"
7708 "Do not advertise to any peer (well-known community)\n"
7709 "Do not export to next AS (well-known community)\n"
7710 "community number\n"
7711 "Do not send outside local AS (well-known community)\n"
7712 "Do not advertise to any peer (well-known community)\n"
7713 "Do not export to next AS (well-known community)\n")
7714
7715ALIAS (show_ip_bgp_community,
7716 show_ip_bgp_community4_cmd,
7717 "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)",
7718 SHOW_STR
7719 IP_STR
7720 BGP_STR
7721 "Display routes matching the communities\n"
7722 "community number\n"
7723 "Do not send outside local AS (well-known community)\n"
7724 "Do not advertise to any peer (well-known community)\n"
7725 "Do not export to next AS (well-known community)\n"
7726 "community number\n"
7727 "Do not send outside local AS (well-known community)\n"
7728 "Do not advertise to any peer (well-known community)\n"
7729 "Do not export to next AS (well-known community)\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
7739DEFUN (show_ip_bgp_ipv4_community,
7740 show_ip_bgp_ipv4_community_cmd,
7741 "show ip bgp ipv4 (unicast|multicast) community (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{
7754 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007755 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007756
Michael Lambert95cbbd22010-07-23 14:43:04 -04007757 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007758}
7759
7760ALIAS (show_ip_bgp_ipv4_community,
7761 show_ip_bgp_ipv4_community2_cmd,
7762 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7763 SHOW_STR
7764 IP_STR
7765 BGP_STR
7766 "Address family\n"
7767 "Address Family modifier\n"
7768 "Address Family modifier\n"
7769 "Display routes matching the communities\n"
7770 "community number\n"
7771 "Do not send outside local AS (well-known community)\n"
7772 "Do not advertise to any peer (well-known community)\n"
7773 "Do not export to next AS (well-known community)\n"
7774 "community number\n"
7775 "Do not send outside local AS (well-known community)\n"
7776 "Do not advertise to any peer (well-known community)\n"
7777 "Do not export to next AS (well-known community)\n")
7778
7779ALIAS (show_ip_bgp_ipv4_community,
7780 show_ip_bgp_ipv4_community3_cmd,
7781 "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)",
7782 SHOW_STR
7783 IP_STR
7784 BGP_STR
7785 "Address family\n"
7786 "Address Family modifier\n"
7787 "Address Family modifier\n"
7788 "Display routes matching the communities\n"
7789 "community number\n"
7790 "Do not send outside local AS (well-known community)\n"
7791 "Do not advertise to any peer (well-known community)\n"
7792 "Do not export to next AS (well-known community)\n"
7793 "community number\n"
7794 "Do not send outside local AS (well-known community)\n"
7795 "Do not advertise to any peer (well-known community)\n"
7796 "Do not export to next AS (well-known community)\n"
7797 "community number\n"
7798 "Do not send outside local AS (well-known community)\n"
7799 "Do not advertise to any peer (well-known community)\n"
7800 "Do not export to next AS (well-known community)\n")
7801
7802ALIAS (show_ip_bgp_ipv4_community,
7803 show_ip_bgp_ipv4_community4_cmd,
7804 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7805 SHOW_STR
7806 IP_STR
7807 BGP_STR
7808 "Address family\n"
7809 "Address Family modifier\n"
7810 "Address Family modifier\n"
7811 "Display routes matching the communities\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n"
7824 "community number\n"
7825 "Do not send outside local AS (well-known community)\n"
7826 "Do not advertise to any peer (well-known community)\n"
7827 "Do not export to next AS (well-known community)\n")
7828
Michael Lambert95cbbd22010-07-23 14:43:04 -04007829DEFUN (show_bgp_view_afi_safi_community_all,
7830 show_bgp_view_afi_safi_community_all_cmd,
7831#ifdef HAVE_IPV6
7832 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7833#else
7834 "show bgp view WORD ipv4 (unicast|multicast) community",
7835#endif
7836 SHOW_STR
7837 BGP_STR
7838 "BGP view\n"
7839 "BGP view name\n"
7840 "Address family\n"
7841#ifdef HAVE_IPV6
7842 "Address family\n"
7843#endif
7844 "Address Family modifier\n"
7845 "Address Family modifier\n"
7846 "Display routes containing communities\n")
7847{
7848 int afi;
7849 int safi;
7850 struct bgp *bgp;
7851
7852 /* BGP structure lookup. */
7853 bgp = bgp_lookup_by_name (argv[0]);
7854 if (bgp == NULL)
7855 {
7856 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7857 return CMD_WARNING;
7858 }
7859
7860#ifdef HAVE_IPV6
7861 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7862 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7863#else
7864 afi = AFI_IP;
7865 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7866#endif
7867 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7868}
7869
7870DEFUN (show_bgp_view_afi_safi_community,
7871 show_bgp_view_afi_safi_community_cmd,
7872#ifdef HAVE_IPV6
7873 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7874#else
7875 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7876#endif
7877 SHOW_STR
7878 BGP_STR
7879 "BGP view\n"
7880 "BGP view name\n"
7881 "Address family\n"
7882#ifdef HAVE_IPV6
7883 "Address family\n"
7884#endif
7885 "Address family modifier\n"
7886 "Address family modifier\n"
7887 "Display routes matching the communities\n"
7888 "community number\n"
7889 "Do not send outside local AS (well-known community)\n"
7890 "Do not advertise to any peer (well-known community)\n"
7891 "Do not export to next AS (well-known community)\n")
7892{
7893 int afi;
7894 int safi;
7895
7896#ifdef HAVE_IPV6
7897 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7898 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7899 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7900#else
7901 afi = AFI_IP;
7902 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7903 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7904#endif
7905}
7906
7907ALIAS (show_bgp_view_afi_safi_community,
7908 show_bgp_view_afi_safi_community2_cmd,
7909#ifdef HAVE_IPV6
7910 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7911#else
7912 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7913#endif
7914 SHOW_STR
7915 BGP_STR
7916 "BGP view\n"
7917 "BGP view name\n"
7918 "Address family\n"
7919#ifdef HAVE_IPV6
7920 "Address family\n"
7921#endif
7922 "Address family modifier\n"
7923 "Address family modifier\n"
7924 "Display routes matching the communities\n"
7925 "community number\n"
7926 "Do not send outside local AS (well-known community)\n"
7927 "Do not advertise to any peer (well-known community)\n"
7928 "Do not export to next AS (well-known community)\n"
7929 "community number\n"
7930 "Do not send outside local AS (well-known community)\n"
7931 "Do not advertise to any peer (well-known community)\n"
7932 "Do not export to next AS (well-known community)\n")
7933
7934ALIAS (show_bgp_view_afi_safi_community,
7935 show_bgp_view_afi_safi_community3_cmd,
7936#ifdef HAVE_IPV6
7937 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7938#else
7939 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7940#endif
7941 SHOW_STR
7942 BGP_STR
7943 "BGP view\n"
7944 "BGP view name\n"
7945 "Address family\n"
7946#ifdef HAVE_IPV6
7947 "Address family\n"
7948#endif
7949 "Address family modifier\n"
7950 "Address family modifier\n"
7951 "Display routes matching the communities\n"
7952 "community number\n"
7953 "Do not send outside local AS (well-known community)\n"
7954 "Do not advertise to any peer (well-known community)\n"
7955 "Do not export to next AS (well-known community)\n"
7956 "community number\n"
7957 "Do not send outside local AS (well-known community)\n"
7958 "Do not advertise to any peer (well-known community)\n"
7959 "Do not export to next AS (well-known community)\n"
7960 "community number\n"
7961 "Do not send outside local AS (well-known community)\n"
7962 "Do not advertise to any peer (well-known community)\n"
7963 "Do not export to next AS (well-known community)\n")
7964
7965ALIAS (show_bgp_view_afi_safi_community,
7966 show_bgp_view_afi_safi_community4_cmd,
7967#ifdef HAVE_IPV6
7968 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7969#else
7970 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7971#endif
7972 SHOW_STR
7973 BGP_STR
7974 "BGP view\n"
7975 "BGP view name\n"
7976 "Address family\n"
7977#ifdef HAVE_IPV6
7978 "Address family\n"
7979#endif
7980 "Address family modifier\n"
7981 "Address family modifier\n"
7982 "Display routes matching the communities\n"
7983 "community number\n"
7984 "Do not send outside local AS (well-known community)\n"
7985 "Do not advertise to any peer (well-known community)\n"
7986 "Do not export to next AS (well-known community)\n"
7987 "community number\n"
7988 "Do not send outside local AS (well-known community)\n"
7989 "Do not advertise to any peer (well-known community)\n"
7990 "Do not export to next AS (well-known community)\n"
7991 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n"
7995 "community number\n"
7996 "Do not send outside local AS (well-known community)\n"
7997 "Do not advertise to any peer (well-known community)\n"
7998 "Do not export to next AS (well-known community)\n")
7999
paul718e3742002-12-13 20:15:29 +00008000DEFUN (show_ip_bgp_community_exact,
8001 show_ip_bgp_community_exact_cmd,
8002 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8003 SHOW_STR
8004 IP_STR
8005 BGP_STR
8006 "Display routes matching the communities\n"
8007 "community number\n"
8008 "Do not send outside local AS (well-known community)\n"
8009 "Do not advertise to any peer (well-known community)\n"
8010 "Do not export to next AS (well-known community)\n"
8011 "Exact match of the communities")
8012{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008013 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008014}
8015
8016ALIAS (show_ip_bgp_community_exact,
8017 show_ip_bgp_community2_exact_cmd,
8018 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8019 SHOW_STR
8020 IP_STR
8021 BGP_STR
8022 "Display routes matching the communities\n"
8023 "community number\n"
8024 "Do not send outside local AS (well-known community)\n"
8025 "Do not advertise to any peer (well-known community)\n"
8026 "Do not export to next AS (well-known community)\n"
8027 "community number\n"
8028 "Do not send outside local AS (well-known community)\n"
8029 "Do not advertise to any peer (well-known community)\n"
8030 "Do not export to next AS (well-known community)\n"
8031 "Exact match of the communities")
8032
8033ALIAS (show_ip_bgp_community_exact,
8034 show_ip_bgp_community3_exact_cmd,
8035 "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",
8036 SHOW_STR
8037 IP_STR
8038 BGP_STR
8039 "Display routes matching the communities\n"
8040 "community number\n"
8041 "Do not send outside local AS (well-known community)\n"
8042 "Do not advertise to any peer (well-known community)\n"
8043 "Do not export to next AS (well-known community)\n"
8044 "community number\n"
8045 "Do not send outside local AS (well-known community)\n"
8046 "Do not advertise to any peer (well-known community)\n"
8047 "Do not export to next AS (well-known community)\n"
8048 "community number\n"
8049 "Do not send outside local AS (well-known community)\n"
8050 "Do not advertise to any peer (well-known community)\n"
8051 "Do not export to next AS (well-known community)\n"
8052 "Exact match of the communities")
8053
8054ALIAS (show_ip_bgp_community_exact,
8055 show_ip_bgp_community4_exact_cmd,
8056 "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",
8057 SHOW_STR
8058 IP_STR
8059 BGP_STR
8060 "Display routes matching the communities\n"
8061 "community number\n"
8062 "Do not send outside local AS (well-known community)\n"
8063 "Do not advertise to any peer (well-known community)\n"
8064 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8078
8079DEFUN (show_ip_bgp_ipv4_community_exact,
8080 show_ip_bgp_ipv4_community_exact_cmd,
8081 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8082 SHOW_STR
8083 IP_STR
8084 BGP_STR
8085 "Address family\n"
8086 "Address Family modifier\n"
8087 "Address Family modifier\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 "Exact match of the communities")
8094{
8095 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008096 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008097
Michael Lambert95cbbd22010-07-23 14:43:04 -04008098 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008099}
8100
8101ALIAS (show_ip_bgp_ipv4_community_exact,
8102 show_ip_bgp_ipv4_community2_exact_cmd,
8103 "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",
8104 SHOW_STR
8105 IP_STR
8106 BGP_STR
8107 "Address family\n"
8108 "Address Family modifier\n"
8109 "Address Family modifier\n"
8110 "Display routes matching the communities\n"
8111 "community number\n"
8112 "Do not send outside local AS (well-known community)\n"
8113 "Do not advertise to any peer (well-known community)\n"
8114 "Do not export to next AS (well-known community)\n"
8115 "community number\n"
8116 "Do not send outside local AS (well-known community)\n"
8117 "Do not advertise to any peer (well-known community)\n"
8118 "Do not export to next AS (well-known community)\n"
8119 "Exact match of the communities")
8120
8121ALIAS (show_ip_bgp_ipv4_community_exact,
8122 show_ip_bgp_ipv4_community3_exact_cmd,
8123 "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",
8124 SHOW_STR
8125 IP_STR
8126 BGP_STR
8127 "Address family\n"
8128 "Address Family modifier\n"
8129 "Address Family modifier\n"
8130 "Display routes matching the communities\n"
8131 "community number\n"
8132 "Do not send outside local AS (well-known community)\n"
8133 "Do not advertise to any peer (well-known community)\n"
8134 "Do not export to next AS (well-known community)\n"
8135 "community number\n"
8136 "Do not send outside local AS (well-known community)\n"
8137 "Do not advertise to any peer (well-known community)\n"
8138 "Do not export to next AS (well-known community)\n"
8139 "community number\n"
8140 "Do not send outside local AS (well-known community)\n"
8141 "Do not advertise to any peer (well-known community)\n"
8142 "Do not export to next AS (well-known community)\n"
8143 "Exact match of the communities")
8144
8145ALIAS (show_ip_bgp_ipv4_community_exact,
8146 show_ip_bgp_ipv4_community4_exact_cmd,
8147 "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",
8148 SHOW_STR
8149 IP_STR
8150 BGP_STR
8151 "Address family\n"
8152 "Address Family modifier\n"
8153 "Address Family modifier\n"
8154 "Display routes matching the communities\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n"
8163 "community number\n"
8164 "Do not send outside local AS (well-known community)\n"
8165 "Do not advertise to any peer (well-known community)\n"
8166 "Do not export to next AS (well-known community)\n"
8167 "community number\n"
8168 "Do not send outside local AS (well-known community)\n"
8169 "Do not advertise to any peer (well-known community)\n"
8170 "Do not export to next AS (well-known community)\n"
8171 "Exact match of the communities")
8172
8173#ifdef HAVE_IPV6
8174DEFUN (show_bgp_community,
8175 show_bgp_community_cmd,
8176 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8177 SHOW_STR
8178 BGP_STR
8179 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008185 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008186}
8187
8188ALIAS (show_bgp_community,
8189 show_bgp_ipv6_community_cmd,
8190 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8191 SHOW_STR
8192 BGP_STR
8193 "Address family\n"
8194 "Display routes matching the communities\n"
8195 "community number\n"
8196 "Do not send outside local AS (well-known community)\n"
8197 "Do not advertise to any peer (well-known community)\n"
8198 "Do not export to next AS (well-known community)\n")
8199
8200ALIAS (show_bgp_community,
8201 show_bgp_community2_cmd,
8202 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8203 SHOW_STR
8204 BGP_STR
8205 "Display routes matching the communities\n"
8206 "community number\n"
8207 "Do not send outside local AS (well-known community)\n"
8208 "Do not advertise to any peer (well-known community)\n"
8209 "Do not export to next AS (well-known community)\n"
8210 "community number\n"
8211 "Do not send outside local AS (well-known community)\n"
8212 "Do not advertise to any peer (well-known community)\n"
8213 "Do not export to next AS (well-known community)\n")
8214
8215ALIAS (show_bgp_community,
8216 show_bgp_ipv6_community2_cmd,
8217 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8218 SHOW_STR
8219 BGP_STR
8220 "Address family\n"
8221 "Display routes matching the communities\n"
8222 "community number\n"
8223 "Do not send outside local AS (well-known community)\n"
8224 "Do not advertise to any peer (well-known community)\n"
8225 "Do not export to next AS (well-known community)\n"
8226 "community number\n"
8227 "Do not send outside local AS (well-known community)\n"
8228 "Do not advertise to any peer (well-known community)\n"
8229 "Do not export to next AS (well-known community)\n")
8230
8231ALIAS (show_bgp_community,
8232 show_bgp_community3_cmd,
8233 "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)",
8234 SHOW_STR
8235 BGP_STR
8236 "Display routes matching the communities\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n"
8245 "community number\n"
8246 "Do not send outside local AS (well-known community)\n"
8247 "Do not advertise to any peer (well-known community)\n"
8248 "Do not export to next AS (well-known community)\n")
8249
8250ALIAS (show_bgp_community,
8251 show_bgp_ipv6_community3_cmd,
8252 "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)",
8253 SHOW_STR
8254 BGP_STR
8255 "Address family\n"
8256 "Display routes matching the communities\n"
8257 "community number\n"
8258 "Do not send outside local AS (well-known community)\n"
8259 "Do not advertise to any peer (well-known community)\n"
8260 "Do not export to next AS (well-known community)\n"
8261 "community number\n"
8262 "Do not send outside local AS (well-known community)\n"
8263 "Do not advertise to any peer (well-known community)\n"
8264 "Do not export to next AS (well-known community)\n"
8265 "community number\n"
8266 "Do not send outside local AS (well-known community)\n"
8267 "Do not advertise to any peer (well-known community)\n"
8268 "Do not export to next AS (well-known community)\n")
8269
8270ALIAS (show_bgp_community,
8271 show_bgp_community4_cmd,
8272 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8273 SHOW_STR
8274 BGP_STR
8275 "Display routes matching the communities\n"
8276 "community number\n"
8277 "Do not send outside local AS (well-known community)\n"
8278 "Do not advertise to any peer (well-known community)\n"
8279 "Do not export to next AS (well-known community)\n"
8280 "community number\n"
8281 "Do not send outside local AS (well-known community)\n"
8282 "Do not advertise to any peer (well-known community)\n"
8283 "Do not export to next AS (well-known community)\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n"
8288 "community number\n"
8289 "Do not send outside local AS (well-known community)\n"
8290 "Do not advertise to any peer (well-known community)\n"
8291 "Do not export to next AS (well-known community)\n")
8292
8293ALIAS (show_bgp_community,
8294 show_bgp_ipv6_community4_cmd,
8295 "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)",
8296 SHOW_STR
8297 BGP_STR
8298 "Address family\n"
8299 "Display routes matching the communities\n"
8300 "community number\n"
8301 "Do not send outside local AS (well-known community)\n"
8302 "Do not advertise to any peer (well-known community)\n"
8303 "Do not export to next AS (well-known community)\n"
8304 "community number\n"
8305 "Do not send outside local AS (well-known community)\n"
8306 "Do not advertise to any peer (well-known community)\n"
8307 "Do not export to next AS (well-known community)\n"
8308 "community number\n"
8309 "Do not send outside local AS (well-known community)\n"
8310 "Do not advertise to any peer (well-known community)\n"
8311 "Do not export to next AS (well-known community)\n"
8312 "community number\n"
8313 "Do not send outside local AS (well-known community)\n"
8314 "Do not advertise to any peer (well-known community)\n"
8315 "Do not export to next AS (well-known community)\n")
8316
8317/* old command */
8318DEFUN (show_ipv6_bgp_community,
8319 show_ipv6_bgp_community_cmd,
8320 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8321 SHOW_STR
8322 IPV6_STR
8323 BGP_STR
8324 "Display routes matching the communities\n"
8325 "community number\n"
8326 "Do not send outside local AS (well-known community)\n"
8327 "Do not advertise to any peer (well-known community)\n"
8328 "Do not export to next AS (well-known community)\n")
8329{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008330 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008331}
8332
8333/* old command */
8334ALIAS (show_ipv6_bgp_community,
8335 show_ipv6_bgp_community2_cmd,
8336 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8337 SHOW_STR
8338 IPV6_STR
8339 BGP_STR
8340 "Display routes matching the communities\n"
8341 "community number\n"
8342 "Do not send outside local AS (well-known community)\n"
8343 "Do not advertise to any peer (well-known community)\n"
8344 "Do not export to next AS (well-known community)\n"
8345 "community number\n"
8346 "Do not send outside local AS (well-known community)\n"
8347 "Do not advertise to any peer (well-known community)\n"
8348 "Do not export to next AS (well-known community)\n")
8349
8350/* old command */
8351ALIAS (show_ipv6_bgp_community,
8352 show_ipv6_bgp_community3_cmd,
8353 "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)",
8354 SHOW_STR
8355 IPV6_STR
8356 BGP_STR
8357 "Display routes matching the communities\n"
8358 "community number\n"
8359 "Do not send outside local AS (well-known community)\n"
8360 "Do not advertise to any peer (well-known community)\n"
8361 "Do not export to next AS (well-known community)\n"
8362 "community number\n"
8363 "Do not send outside local AS (well-known community)\n"
8364 "Do not advertise to any peer (well-known community)\n"
8365 "Do not export to next AS (well-known community)\n"
8366 "community number\n"
8367 "Do not send outside local AS (well-known community)\n"
8368 "Do not advertise to any peer (well-known community)\n"
8369 "Do not export to next AS (well-known community)\n")
8370
8371/* old command */
8372ALIAS (show_ipv6_bgp_community,
8373 show_ipv6_bgp_community4_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) (AA:NN|local-AS|no-advertise|no-export)",
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 "community number\n"
8392 "Do not send outside local AS (well-known community)\n"
8393 "Do not advertise to any peer (well-known community)\n"
8394 "Do not export to next AS (well-known community)\n")
8395
8396DEFUN (show_bgp_community_exact,
8397 show_bgp_community_exact_cmd,
8398 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8399 SHOW_STR
8400 BGP_STR
8401 "Display routes matching the communities\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n"
8406 "Exact match of the communities")
8407{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008408 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008409}
8410
8411ALIAS (show_bgp_community_exact,
8412 show_bgp_ipv6_community_exact_cmd,
8413 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8414 SHOW_STR
8415 BGP_STR
8416 "Address family\n"
8417 "Display routes matching the communities\n"
8418 "community number\n"
8419 "Do not send outside local AS (well-known community)\n"
8420 "Do not advertise to any peer (well-known community)\n"
8421 "Do not export to next AS (well-known community)\n"
8422 "Exact match of the communities")
8423
8424ALIAS (show_bgp_community_exact,
8425 show_bgp_community2_exact_cmd,
8426 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8427 SHOW_STR
8428 BGP_STR
8429 "Display routes matching the communities\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "community number\n"
8435 "Do not send outside local AS (well-known community)\n"
8436 "Do not advertise to any peer (well-known community)\n"
8437 "Do not export to next AS (well-known community)\n"
8438 "Exact match of the communities")
8439
8440ALIAS (show_bgp_community_exact,
8441 show_bgp_ipv6_community2_exact_cmd,
8442 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8443 SHOW_STR
8444 BGP_STR
8445 "Address family\n"
8446 "Display routes matching the communities\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "Exact match of the communities")
8456
8457ALIAS (show_bgp_community_exact,
8458 show_bgp_community3_exact_cmd,
8459 "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",
8460 SHOW_STR
8461 BGP_STR
8462 "Display routes matching the communities\n"
8463 "community number\n"
8464 "Do not send outside local AS (well-known community)\n"
8465 "Do not advertise to any peer (well-known community)\n"
8466 "Do not export to next AS (well-known community)\n"
8467 "community number\n"
8468 "Do not send outside local AS (well-known community)\n"
8469 "Do not advertise to any peer (well-known community)\n"
8470 "Do not export to next AS (well-known community)\n"
8471 "community number\n"
8472 "Do not send outside local AS (well-known community)\n"
8473 "Do not advertise to any peer (well-known community)\n"
8474 "Do not export to next AS (well-known community)\n"
8475 "Exact match of the communities")
8476
8477ALIAS (show_bgp_community_exact,
8478 show_bgp_ipv6_community3_exact_cmd,
8479 "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",
8480 SHOW_STR
8481 BGP_STR
8482 "Address family\n"
8483 "Display routes matching the communities\n"
8484 "community number\n"
8485 "Do not send outside local AS (well-known community)\n"
8486 "Do not advertise to any peer (well-known community)\n"
8487 "Do not export to next AS (well-known community)\n"
8488 "community number\n"
8489 "Do not send outside local AS (well-known community)\n"
8490 "Do not advertise to any peer (well-known community)\n"
8491 "Do not export to next AS (well-known community)\n"
8492 "community number\n"
8493 "Do not send outside local AS (well-known community)\n"
8494 "Do not advertise to any peer (well-known community)\n"
8495 "Do not export to next AS (well-known community)\n"
8496 "Exact match of the communities")
8497
8498ALIAS (show_bgp_community_exact,
8499 show_bgp_community4_exact_cmd,
8500 "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",
8501 SHOW_STR
8502 BGP_STR
8503 "Display routes matching the communities\n"
8504 "community number\n"
8505 "Do not send outside local AS (well-known community)\n"
8506 "Do not advertise to any peer (well-known community)\n"
8507 "Do not export to next AS (well-known community)\n"
8508 "community number\n"
8509 "Do not send outside local AS (well-known community)\n"
8510 "Do not advertise to any peer (well-known community)\n"
8511 "Do not export to next AS (well-known community)\n"
8512 "community number\n"
8513 "Do not send outside local AS (well-known community)\n"
8514 "Do not advertise to any peer (well-known community)\n"
8515 "Do not export to next AS (well-known community)\n"
8516 "community number\n"
8517 "Do not send outside local AS (well-known community)\n"
8518 "Do not advertise to any peer (well-known community)\n"
8519 "Do not export to next AS (well-known community)\n"
8520 "Exact match of the communities")
8521
8522ALIAS (show_bgp_community_exact,
8523 show_bgp_ipv6_community4_exact_cmd,
8524 "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",
8525 SHOW_STR
8526 BGP_STR
8527 "Address family\n"
8528 "Display routes matching the communities\n"
8529 "community number\n"
8530 "Do not send outside local AS (well-known community)\n"
8531 "Do not advertise to any peer (well-known community)\n"
8532 "Do not export to next AS (well-known community)\n"
8533 "community number\n"
8534 "Do not send outside local AS (well-known community)\n"
8535 "Do not advertise to any peer (well-known community)\n"
8536 "Do not export to next AS (well-known community)\n"
8537 "community number\n"
8538 "Do not send outside local AS (well-known community)\n"
8539 "Do not advertise to any peer (well-known community)\n"
8540 "Do not export to next AS (well-known community)\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 "Exact match of the communities")
8546
8547/* old command */
8548DEFUN (show_ipv6_bgp_community_exact,
8549 show_ipv6_bgp_community_exact_cmd,
8550 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8551 SHOW_STR
8552 IPV6_STR
8553 BGP_STR
8554 "Display routes matching the communities\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "Exact match of the communities")
8560{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008561 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008562}
8563
8564/* old command */
8565ALIAS (show_ipv6_bgp_community_exact,
8566 show_ipv6_bgp_community2_exact_cmd,
8567 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8568 SHOW_STR
8569 IPV6_STR
8570 BGP_STR
8571 "Display routes matching the communities\n"
8572 "community number\n"
8573 "Do not send outside local AS (well-known community)\n"
8574 "Do not advertise to any peer (well-known community)\n"
8575 "Do not export to next AS (well-known community)\n"
8576 "community number\n"
8577 "Do not send outside local AS (well-known community)\n"
8578 "Do not advertise to any peer (well-known community)\n"
8579 "Do not export to next AS (well-known community)\n"
8580 "Exact match of the communities")
8581
8582/* old command */
8583ALIAS (show_ipv6_bgp_community_exact,
8584 show_ipv6_bgp_community3_exact_cmd,
8585 "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",
8586 SHOW_STR
8587 IPV6_STR
8588 BGP_STR
8589 "Display routes matching the communities\n"
8590 "community number\n"
8591 "Do not send outside local AS (well-known community)\n"
8592 "Do not advertise to any peer (well-known community)\n"
8593 "Do not export to next AS (well-known community)\n"
8594 "community number\n"
8595 "Do not send outside local AS (well-known community)\n"
8596 "Do not advertise to any peer (well-known community)\n"
8597 "Do not export to next AS (well-known community)\n"
8598 "community number\n"
8599 "Do not send outside local AS (well-known community)\n"
8600 "Do not advertise to any peer (well-known community)\n"
8601 "Do not export to next AS (well-known community)\n"
8602 "Exact match of the communities")
8603
8604/* old command */
8605ALIAS (show_ipv6_bgp_community_exact,
8606 show_ipv6_bgp_community4_exact_cmd,
8607 "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",
8608 SHOW_STR
8609 IPV6_STR
8610 BGP_STR
8611 "Display routes matching the communities\n"
8612 "community number\n"
8613 "Do not send outside local AS (well-known community)\n"
8614 "Do not advertise to any peer (well-known community)\n"
8615 "Do not export to next AS (well-known community)\n"
8616 "community number\n"
8617 "Do not send outside local AS (well-known community)\n"
8618 "Do not advertise to any peer (well-known community)\n"
8619 "Do not export to next AS (well-known community)\n"
8620 "community number\n"
8621 "Do not send outside local AS (well-known community)\n"
8622 "Do not advertise to any peer (well-known community)\n"
8623 "Do not export to next AS (well-known community)\n"
8624 "community number\n"
8625 "Do not send outside local AS (well-known community)\n"
8626 "Do not advertise to any peer (well-known community)\n"
8627 "Do not export to next AS (well-known community)\n"
8628 "Exact match of the communities")
8629
8630/* old command */
8631DEFUN (show_ipv6_mbgp_community,
8632 show_ipv6_mbgp_community_cmd,
8633 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8634 SHOW_STR
8635 IPV6_STR
8636 MBGP_STR
8637 "Display routes matching the communities\n"
8638 "community number\n"
8639 "Do not send outside local AS (well-known community)\n"
8640 "Do not advertise to any peer (well-known community)\n"
8641 "Do not export to next AS (well-known community)\n")
8642{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008643 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008644}
8645
8646/* old command */
8647ALIAS (show_ipv6_mbgp_community,
8648 show_ipv6_mbgp_community2_cmd,
8649 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8650 SHOW_STR
8651 IPV6_STR
8652 MBGP_STR
8653 "Display routes matching the communities\n"
8654 "community number\n"
8655 "Do not send outside local AS (well-known community)\n"
8656 "Do not advertise to any peer (well-known community)\n"
8657 "Do not export to next AS (well-known community)\n"
8658 "community number\n"
8659 "Do not send outside local AS (well-known community)\n"
8660 "Do not advertise to any peer (well-known community)\n"
8661 "Do not export to next AS (well-known community)\n")
8662
8663/* old command */
8664ALIAS (show_ipv6_mbgp_community,
8665 show_ipv6_mbgp_community3_cmd,
8666 "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)",
8667 SHOW_STR
8668 IPV6_STR
8669 MBGP_STR
8670 "Display routes matching the communities\n"
8671 "community number\n"
8672 "Do not send outside local AS (well-known community)\n"
8673 "Do not advertise to any peer (well-known community)\n"
8674 "Do not export to next AS (well-known community)\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n"
8679 "community number\n"
8680 "Do not send outside local AS (well-known community)\n"
8681 "Do not advertise to any peer (well-known community)\n"
8682 "Do not export to next AS (well-known community)\n")
8683
8684/* old command */
8685ALIAS (show_ipv6_mbgp_community,
8686 show_ipv6_mbgp_community4_cmd,
8687 "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)",
8688 SHOW_STR
8689 IPV6_STR
8690 MBGP_STR
8691 "Display routes matching the communities\n"
8692 "community number\n"
8693 "Do not send outside local AS (well-known community)\n"
8694 "Do not advertise to any peer (well-known community)\n"
8695 "Do not export to next AS (well-known community)\n"
8696 "community number\n"
8697 "Do not send outside local AS (well-known community)\n"
8698 "Do not advertise to any peer (well-known community)\n"
8699 "Do not export to next AS (well-known community)\n"
8700 "community number\n"
8701 "Do not send outside local AS (well-known community)\n"
8702 "Do not advertise to any peer (well-known community)\n"
8703 "Do not export to next AS (well-known community)\n"
8704 "community number\n"
8705 "Do not send outside local AS (well-known community)\n"
8706 "Do not advertise to any peer (well-known community)\n"
8707 "Do not export to next AS (well-known community)\n")
8708
8709/* old command */
8710DEFUN (show_ipv6_mbgp_community_exact,
8711 show_ipv6_mbgp_community_exact_cmd,
8712 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8713 SHOW_STR
8714 IPV6_STR
8715 MBGP_STR
8716 "Display routes matching the communities\n"
8717 "community number\n"
8718 "Do not send outside local AS (well-known community)\n"
8719 "Do not advertise to any peer (well-known community)\n"
8720 "Do not export to next AS (well-known community)\n"
8721 "Exact match of the communities")
8722{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008723 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008724}
8725
8726/* old command */
8727ALIAS (show_ipv6_mbgp_community_exact,
8728 show_ipv6_mbgp_community2_exact_cmd,
8729 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8730 SHOW_STR
8731 IPV6_STR
8732 MBGP_STR
8733 "Display routes matching the communities\n"
8734 "community number\n"
8735 "Do not send outside local AS (well-known community)\n"
8736 "Do not advertise to any peer (well-known community)\n"
8737 "Do not export to next AS (well-known community)\n"
8738 "community number\n"
8739 "Do not send outside local AS (well-known community)\n"
8740 "Do not advertise to any peer (well-known community)\n"
8741 "Do not export to next AS (well-known community)\n"
8742 "Exact match of the communities")
8743
8744/* old command */
8745ALIAS (show_ipv6_mbgp_community_exact,
8746 show_ipv6_mbgp_community3_exact_cmd,
8747 "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",
8748 SHOW_STR
8749 IPV6_STR
8750 MBGP_STR
8751 "Display routes matching the communities\n"
8752 "community number\n"
8753 "Do not send outside local AS (well-known community)\n"
8754 "Do not advertise to any peer (well-known community)\n"
8755 "Do not export to next AS (well-known community)\n"
8756 "community number\n"
8757 "Do not send outside local AS (well-known community)\n"
8758 "Do not advertise to any peer (well-known community)\n"
8759 "Do not export to next AS (well-known community)\n"
8760 "community number\n"
8761 "Do not send outside local AS (well-known community)\n"
8762 "Do not advertise to any peer (well-known community)\n"
8763 "Do not export to next AS (well-known community)\n"
8764 "Exact match of the communities")
8765
8766/* old command */
8767ALIAS (show_ipv6_mbgp_community_exact,
8768 show_ipv6_mbgp_community4_exact_cmd,
8769 "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",
8770 SHOW_STR
8771 IPV6_STR
8772 MBGP_STR
8773 "Display routes matching the communities\n"
8774 "community number\n"
8775 "Do not send outside local AS (well-known community)\n"
8776 "Do not advertise to any peer (well-known community)\n"
8777 "Do not export to next AS (well-known community)\n"
8778 "community number\n"
8779 "Do not send outside local AS (well-known community)\n"
8780 "Do not advertise to any peer (well-known community)\n"
8781 "Do not export to next AS (well-known community)\n"
8782 "community number\n"
8783 "Do not send outside local AS (well-known community)\n"
8784 "Do not advertise to any peer (well-known community)\n"
8785 "Do not export to next AS (well-known community)\n"
8786 "community number\n"
8787 "Do not send outside local AS (well-known community)\n"
8788 "Do not advertise to any peer (well-known community)\n"
8789 "Do not export to next AS (well-known community)\n"
8790 "Exact match of the communities")
8791#endif /* HAVE_IPV6 */
8792
paul94f2b392005-06-28 12:44:16 +00008793static int
paulfd79ac92004-10-13 05:06:08 +00008794bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008795 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008796{
8797 struct community_list *list;
8798
hassofee6e4e2005-02-02 16:29:31 +00008799 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008800 if (list == NULL)
8801 {
8802 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8803 VTY_NEWLINE);
8804 return CMD_WARNING;
8805 }
8806
ajs5a646652004-11-05 01:25:55 +00008807 return bgp_show (vty, NULL, afi, safi,
8808 (exact ? bgp_show_type_community_list_exact :
8809 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008810}
8811
8812DEFUN (show_ip_bgp_community_list,
8813 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008814 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008815 SHOW_STR
8816 IP_STR
8817 BGP_STR
8818 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008819 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008820 "community-list name\n")
8821{
8822 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8823}
8824
8825DEFUN (show_ip_bgp_ipv4_community_list,
8826 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008827 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008828 SHOW_STR
8829 IP_STR
8830 BGP_STR
8831 "Address family\n"
8832 "Address Family modifier\n"
8833 "Address Family modifier\n"
8834 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008835 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008836 "community-list name\n")
8837{
8838 if (strncmp (argv[0], "m", 1) == 0)
8839 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8840
8841 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8842}
8843
8844DEFUN (show_ip_bgp_community_list_exact,
8845 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008846 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008847 SHOW_STR
8848 IP_STR
8849 BGP_STR
8850 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008851 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008852 "community-list name\n"
8853 "Exact match of the communities\n")
8854{
8855 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8856}
8857
8858DEFUN (show_ip_bgp_ipv4_community_list_exact,
8859 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008860 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008861 SHOW_STR
8862 IP_STR
8863 BGP_STR
8864 "Address family\n"
8865 "Address Family modifier\n"
8866 "Address Family modifier\n"
8867 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008868 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008869 "community-list name\n"
8870 "Exact match of the communities\n")
8871{
8872 if (strncmp (argv[0], "m", 1) == 0)
8873 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8874
8875 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8876}
8877
8878#ifdef HAVE_IPV6
8879DEFUN (show_bgp_community_list,
8880 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008881 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008882 SHOW_STR
8883 BGP_STR
8884 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008885 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008886 "community-list name\n")
8887{
8888 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8889}
8890
8891ALIAS (show_bgp_community_list,
8892 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008893 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008894 SHOW_STR
8895 BGP_STR
8896 "Address family\n"
8897 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008898 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008899 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008900
8901/* old command */
8902DEFUN (show_ipv6_bgp_community_list,
8903 show_ipv6_bgp_community_list_cmd,
8904 "show ipv6 bgp community-list WORD",
8905 SHOW_STR
8906 IPV6_STR
8907 BGP_STR
8908 "Display routes matching the community-list\n"
8909 "community-list name\n")
8910{
8911 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8912}
8913
8914/* old command */
8915DEFUN (show_ipv6_mbgp_community_list,
8916 show_ipv6_mbgp_community_list_cmd,
8917 "show ipv6 mbgp community-list WORD",
8918 SHOW_STR
8919 IPV6_STR
8920 MBGP_STR
8921 "Display routes matching the community-list\n"
8922 "community-list name\n")
8923{
8924 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8925}
8926
8927DEFUN (show_bgp_community_list_exact,
8928 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008929 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008930 SHOW_STR
8931 BGP_STR
8932 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008933 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008934 "community-list name\n"
8935 "Exact match of the communities\n")
8936{
8937 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8938}
8939
8940ALIAS (show_bgp_community_list_exact,
8941 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008942 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008943 SHOW_STR
8944 BGP_STR
8945 "Address family\n"
8946 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008947 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008948 "community-list name\n"
8949 "Exact match of the communities\n")
8950
8951/* old command */
8952DEFUN (show_ipv6_bgp_community_list_exact,
8953 show_ipv6_bgp_community_list_exact_cmd,
8954 "show ipv6 bgp community-list WORD exact-match",
8955 SHOW_STR
8956 IPV6_STR
8957 BGP_STR
8958 "Display routes matching the community-list\n"
8959 "community-list name\n"
8960 "Exact match of the communities\n")
8961{
8962 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8963}
8964
8965/* old command */
8966DEFUN (show_ipv6_mbgp_community_list_exact,
8967 show_ipv6_mbgp_community_list_exact_cmd,
8968 "show ipv6 mbgp community-list WORD exact-match",
8969 SHOW_STR
8970 IPV6_STR
8971 MBGP_STR
8972 "Display routes matching the community-list\n"
8973 "community-list name\n"
8974 "Exact match of the communities\n")
8975{
8976 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8977}
8978#endif /* HAVE_IPV6 */
8979
paul94f2b392005-06-28 12:44:16 +00008980static int
paulfd79ac92004-10-13 05:06:08 +00008981bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008982 safi_t safi, enum bgp_show_type type)
8983{
8984 int ret;
8985 struct prefix *p;
8986
8987 p = prefix_new();
8988
8989 ret = str2prefix (prefix, p);
8990 if (! ret)
8991 {
8992 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8993 return CMD_WARNING;
8994 }
8995
ajs5a646652004-11-05 01:25:55 +00008996 ret = bgp_show (vty, NULL, afi, safi, type, p);
8997 prefix_free(p);
8998 return ret;
paul718e3742002-12-13 20:15:29 +00008999}
9000
9001DEFUN (show_ip_bgp_prefix_longer,
9002 show_ip_bgp_prefix_longer_cmd,
9003 "show ip bgp A.B.C.D/M longer-prefixes",
9004 SHOW_STR
9005 IP_STR
9006 BGP_STR
9007 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9008 "Display route and more specific routes\n")
9009{
9010 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9011 bgp_show_type_prefix_longer);
9012}
9013
9014DEFUN (show_ip_bgp_flap_prefix_longer,
9015 show_ip_bgp_flap_prefix_longer_cmd,
9016 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9017 SHOW_STR
9018 IP_STR
9019 BGP_STR
9020 "Display flap statistics of routes\n"
9021 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9022 "Display route and more specific routes\n")
9023{
9024 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9025 bgp_show_type_flap_prefix_longer);
9026}
9027
9028DEFUN (show_ip_bgp_ipv4_prefix_longer,
9029 show_ip_bgp_ipv4_prefix_longer_cmd,
9030 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9031 SHOW_STR
9032 IP_STR
9033 BGP_STR
9034 "Address family\n"
9035 "Address Family modifier\n"
9036 "Address Family modifier\n"
9037 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9038 "Display route and more specific routes\n")
9039{
9040 if (strncmp (argv[0], "m", 1) == 0)
9041 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9042 bgp_show_type_prefix_longer);
9043
9044 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9045 bgp_show_type_prefix_longer);
9046}
9047
9048DEFUN (show_ip_bgp_flap_address,
9049 show_ip_bgp_flap_address_cmd,
9050 "show ip bgp flap-statistics A.B.C.D",
9051 SHOW_STR
9052 IP_STR
9053 BGP_STR
9054 "Display flap statistics of routes\n"
9055 "Network in the BGP routing table to display\n")
9056{
9057 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9058 bgp_show_type_flap_address);
9059}
9060
9061DEFUN (show_ip_bgp_flap_prefix,
9062 show_ip_bgp_flap_prefix_cmd,
9063 "show ip bgp flap-statistics A.B.C.D/M",
9064 SHOW_STR
9065 IP_STR
9066 BGP_STR
9067 "Display flap statistics of routes\n"
9068 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9069{
9070 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9071 bgp_show_type_flap_prefix);
9072}
9073#ifdef HAVE_IPV6
9074DEFUN (show_bgp_prefix_longer,
9075 show_bgp_prefix_longer_cmd,
9076 "show bgp X:X::X:X/M longer-prefixes",
9077 SHOW_STR
9078 BGP_STR
9079 "IPv6 prefix <network>/<length>\n"
9080 "Display route and more specific routes\n")
9081{
9082 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9083 bgp_show_type_prefix_longer);
9084}
9085
9086ALIAS (show_bgp_prefix_longer,
9087 show_bgp_ipv6_prefix_longer_cmd,
9088 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9089 SHOW_STR
9090 BGP_STR
9091 "Address family\n"
9092 "IPv6 prefix <network>/<length>\n"
9093 "Display route and more specific routes\n")
9094
9095/* old command */
9096DEFUN (show_ipv6_bgp_prefix_longer,
9097 show_ipv6_bgp_prefix_longer_cmd,
9098 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9099 SHOW_STR
9100 IPV6_STR
9101 BGP_STR
9102 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9103 "Display route and more specific routes\n")
9104{
9105 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9106 bgp_show_type_prefix_longer);
9107}
9108
9109/* old command */
9110DEFUN (show_ipv6_mbgp_prefix_longer,
9111 show_ipv6_mbgp_prefix_longer_cmd,
9112 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9113 SHOW_STR
9114 IPV6_STR
9115 MBGP_STR
9116 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9117 "Display route and more specific routes\n")
9118{
9119 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9120 bgp_show_type_prefix_longer);
9121}
9122#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009123
paul94f2b392005-06-28 12:44:16 +00009124static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009125peer_lookup_in_view (struct vty *vty, const char *view_name,
9126 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009127{
9128 int ret;
9129 struct bgp *bgp;
9130 struct peer *peer;
9131 union sockunion su;
9132
9133 /* BGP structure lookup. */
9134 if (view_name)
9135 {
9136 bgp = bgp_lookup_by_name (view_name);
9137 if (! bgp)
9138 {
9139 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9140 return NULL;
9141 }
9142 }
paul5228ad22004-06-04 17:58:18 +00009143 else
paulbb46e942003-10-24 19:02:03 +00009144 {
9145 bgp = bgp_get_default ();
9146 if (! bgp)
9147 {
9148 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9149 return NULL;
9150 }
9151 }
9152
9153 /* Get peer sockunion. */
9154 ret = str2sockunion (ip_str, &su);
9155 if (ret < 0)
9156 {
9157 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9158 return NULL;
9159 }
9160
9161 /* Peer structure lookup. */
9162 peer = peer_lookup (bgp, &su);
9163 if (! peer)
9164 {
9165 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9166 return NULL;
9167 }
9168
9169 return peer;
9170}
Paul Jakma2815e612006-09-14 02:56:07 +00009171
9172enum bgp_stats
9173{
9174 BGP_STATS_MAXBITLEN = 0,
9175 BGP_STATS_RIB,
9176 BGP_STATS_PREFIXES,
9177 BGP_STATS_TOTPLEN,
9178 BGP_STATS_UNAGGREGATEABLE,
9179 BGP_STATS_MAX_AGGREGATEABLE,
9180 BGP_STATS_AGGREGATES,
9181 BGP_STATS_SPACE,
9182 BGP_STATS_ASPATH_COUNT,
9183 BGP_STATS_ASPATH_MAXHOPS,
9184 BGP_STATS_ASPATH_TOTHOPS,
9185 BGP_STATS_ASPATH_MAXSIZE,
9186 BGP_STATS_ASPATH_TOTSIZE,
9187 BGP_STATS_ASN_HIGHEST,
9188 BGP_STATS_MAX,
9189};
paulbb46e942003-10-24 19:02:03 +00009190
Paul Jakma2815e612006-09-14 02:56:07 +00009191static const char *table_stats_strs[] =
9192{
9193 [BGP_STATS_PREFIXES] = "Total Prefixes",
9194 [BGP_STATS_TOTPLEN] = "Average prefix length",
9195 [BGP_STATS_RIB] = "Total Advertisements",
9196 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9197 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9198 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9199 [BGP_STATS_SPACE] = "Address space advertised",
9200 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9201 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9202 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9203 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9204 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9205 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9206 [BGP_STATS_MAX] = NULL,
9207};
9208
9209struct bgp_table_stats
9210{
9211 struct bgp_table *table;
9212 unsigned long long counts[BGP_STATS_MAX];
9213};
9214
9215#if 0
9216#define TALLY_SIGFIG 100000
9217static unsigned long
9218ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9219{
9220 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9221 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9222 unsigned long ret = newtot / count;
9223
9224 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9225 return ret + 1;
9226 else
9227 return ret;
9228}
9229#endif
9230
9231static int
9232bgp_table_stats_walker (struct thread *t)
9233{
9234 struct bgp_node *rn;
9235 struct bgp_node *top;
9236 struct bgp_table_stats *ts = THREAD_ARG (t);
9237 unsigned int space = 0;
9238
Paul Jakma53d9f672006-10-15 23:41:16 +00009239 if (!(top = bgp_table_top (ts->table)))
9240 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009241
9242 switch (top->p.family)
9243 {
9244 case AF_INET:
9245 space = IPV4_MAX_BITLEN;
9246 break;
9247 case AF_INET6:
9248 space = IPV6_MAX_BITLEN;
9249 break;
9250 }
9251
9252 ts->counts[BGP_STATS_MAXBITLEN] = space;
9253
9254 for (rn = top; rn; rn = bgp_route_next (rn))
9255 {
9256 struct bgp_info *ri;
9257 struct bgp_node *prn = rn->parent;
9258 unsigned int rinum = 0;
9259
9260 if (rn == top)
9261 continue;
9262
9263 if (!rn->info)
9264 continue;
9265
9266 ts->counts[BGP_STATS_PREFIXES]++;
9267 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9268
9269#if 0
9270 ts->counts[BGP_STATS_AVGPLEN]
9271 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9272 ts->counts[BGP_STATS_AVGPLEN],
9273 rn->p.prefixlen);
9274#endif
9275
9276 /* check if the prefix is included by any other announcements */
9277 while (prn && !prn->info)
9278 prn = prn->parent;
9279
9280 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009281 {
9282 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9283 /* announced address space */
9284 if (space)
9285 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9286 }
Paul Jakma2815e612006-09-14 02:56:07 +00009287 else if (prn->info)
9288 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9289
Paul Jakma2815e612006-09-14 02:56:07 +00009290 for (ri = rn->info; ri; ri = ri->next)
9291 {
9292 rinum++;
9293 ts->counts[BGP_STATS_RIB]++;
9294
9295 if (ri->attr &&
9296 (CHECK_FLAG (ri->attr->flag,
9297 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9298 ts->counts[BGP_STATS_AGGREGATES]++;
9299
9300 /* as-path stats */
9301 if (ri->attr && ri->attr->aspath)
9302 {
9303 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9304 unsigned int size = aspath_size (ri->attr->aspath);
9305 as_t highest = aspath_highest (ri->attr->aspath);
9306
9307 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9308
9309 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9310 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9311
9312 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9313 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9314
9315 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9316 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9317#if 0
9318 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9319 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9320 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9321 hops);
9322 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9323 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9324 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9325 size);
9326#endif
9327 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9328 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9329 }
9330 }
9331 }
9332 return 0;
9333}
9334
9335static int
9336bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9337{
9338 struct bgp_table_stats ts;
9339 unsigned int i;
9340
9341 if (!bgp->rib[afi][safi])
9342 {
9343 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9344 return CMD_WARNING;
9345 }
9346
9347 memset (&ts, 0, sizeof (ts));
9348 ts.table = bgp->rib[afi][safi];
9349 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9350
9351 vty_out (vty, "BGP %s RIB statistics%s%s",
9352 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9353
9354 for (i = 0; i < BGP_STATS_MAX; i++)
9355 {
9356 if (!table_stats_strs[i])
9357 continue;
9358
9359 switch (i)
9360 {
9361#if 0
9362 case BGP_STATS_ASPATH_AVGHOPS:
9363 case BGP_STATS_ASPATH_AVGSIZE:
9364 case BGP_STATS_AVGPLEN:
9365 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9366 vty_out (vty, "%12.2f",
9367 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9368 break;
9369#endif
9370 case BGP_STATS_ASPATH_TOTHOPS:
9371 case BGP_STATS_ASPATH_TOTSIZE:
9372 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9373 vty_out (vty, "%12.2f",
9374 ts.counts[i] ?
9375 (float)ts.counts[i] /
9376 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9377 : 0);
9378 break;
9379 case BGP_STATS_TOTPLEN:
9380 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9381 vty_out (vty, "%12.2f",
9382 ts.counts[i] ?
9383 (float)ts.counts[i] /
9384 (float)ts.counts[BGP_STATS_PREFIXES]
9385 : 0);
9386 break;
9387 case BGP_STATS_SPACE:
9388 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9389 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9390 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9391 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009392 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009393 vty_out (vty, "%12.2f%s",
9394 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009395 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009396 VTY_NEWLINE);
9397 vty_out (vty, "%30s: ", "/8 equivalent ");
9398 vty_out (vty, "%12.2f%s",
9399 (float)ts.counts[BGP_STATS_SPACE] /
9400 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9401 VTY_NEWLINE);
9402 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9403 break;
9404 vty_out (vty, "%30s: ", "/24 equivalent ");
9405 vty_out (vty, "%12.2f",
9406 (float)ts.counts[BGP_STATS_SPACE] /
9407 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9408 break;
9409 default:
9410 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9411 vty_out (vty, "%12llu", ts.counts[i]);
9412 }
9413
9414 vty_out (vty, "%s", VTY_NEWLINE);
9415 }
9416 return CMD_SUCCESS;
9417}
9418
9419static int
9420bgp_table_stats_vty (struct vty *vty, const char *name,
9421 const char *afi_str, const char *safi_str)
9422{
9423 struct bgp *bgp;
9424 afi_t afi;
9425 safi_t safi;
9426
9427 if (name)
9428 bgp = bgp_lookup_by_name (name);
9429 else
9430 bgp = bgp_get_default ();
9431
9432 if (!bgp)
9433 {
9434 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9435 return CMD_WARNING;
9436 }
9437 if (strncmp (afi_str, "ipv", 3) == 0)
9438 {
9439 if (strncmp (afi_str, "ipv4", 4) == 0)
9440 afi = AFI_IP;
9441 else if (strncmp (afi_str, "ipv6", 4) == 0)
9442 afi = AFI_IP6;
9443 else
9444 {
9445 vty_out (vty, "%% Invalid address family %s%s",
9446 afi_str, VTY_NEWLINE);
9447 return CMD_WARNING;
9448 }
9449 if (strncmp (safi_str, "m", 1) == 0)
9450 safi = SAFI_MULTICAST;
9451 else if (strncmp (safi_str, "u", 1) == 0)
9452 safi = SAFI_UNICAST;
9453 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9454 safi = BGP_SAFI_VPNV4;
9455 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9456 safi = BGP_SAFI_VPNV6;
9457 else
9458 {
9459 vty_out (vty, "%% Invalid subsequent address family %s%s",
9460 safi_str, VTY_NEWLINE);
9461 return CMD_WARNING;
9462 }
9463 }
9464 else
9465 {
9466 vty_out (vty, "%% Invalid address family %s%s",
9467 afi_str, VTY_NEWLINE);
9468 return CMD_WARNING;
9469 }
9470
9471 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9472 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9473 {
9474 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9475 afi_str, safi_str, VTY_NEWLINE);
9476 return CMD_WARNING;
9477 }
9478 return bgp_table_stats (vty, bgp, afi, safi);
9479}
9480
9481DEFUN (show_bgp_statistics,
9482 show_bgp_statistics_cmd,
9483 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9484 SHOW_STR
9485 BGP_STR
9486 "Address family\n"
9487 "Address family\n"
9488 "Address Family modifier\n"
9489 "Address Family modifier\n"
9490 "BGP RIB advertisement statistics\n")
9491{
9492 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9493}
9494
9495ALIAS (show_bgp_statistics,
9496 show_bgp_statistics_vpnv4_cmd,
9497 "show bgp (ipv4) (vpnv4) statistics",
9498 SHOW_STR
9499 BGP_STR
9500 "Address family\n"
9501 "Address Family modifier\n"
9502 "BGP RIB advertisement statistics\n")
9503
9504DEFUN (show_bgp_statistics_view,
9505 show_bgp_statistics_view_cmd,
9506 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9507 SHOW_STR
9508 BGP_STR
9509 "BGP view\n"
9510 "Address family\n"
9511 "Address family\n"
9512 "Address Family modifier\n"
9513 "Address Family modifier\n"
9514 "BGP RIB advertisement statistics\n")
9515{
9516 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9517}
9518
9519ALIAS (show_bgp_statistics_view,
9520 show_bgp_statistics_view_vpnv4_cmd,
9521 "show bgp view WORD (ipv4) (vpnv4) statistics",
9522 SHOW_STR
9523 BGP_STR
9524 "BGP view\n"
9525 "Address family\n"
9526 "Address Family modifier\n"
9527 "BGP RIB advertisement statistics\n")
9528
Paul Jakmaff7924f2006-09-04 01:10:36 +00009529enum bgp_pcounts
9530{
9531 PCOUNT_ADJ_IN = 0,
9532 PCOUNT_DAMPED,
9533 PCOUNT_REMOVED,
9534 PCOUNT_HISTORY,
9535 PCOUNT_STALE,
9536 PCOUNT_VALID,
9537 PCOUNT_ALL,
9538 PCOUNT_COUNTED,
9539 PCOUNT_PFCNT, /* the figure we display to users */
9540 PCOUNT_MAX,
9541};
9542
9543static const char *pcount_strs[] =
9544{
9545 [PCOUNT_ADJ_IN] = "Adj-in",
9546 [PCOUNT_DAMPED] = "Damped",
9547 [PCOUNT_REMOVED] = "Removed",
9548 [PCOUNT_HISTORY] = "History",
9549 [PCOUNT_STALE] = "Stale",
9550 [PCOUNT_VALID] = "Valid",
9551 [PCOUNT_ALL] = "All RIB",
9552 [PCOUNT_COUNTED] = "PfxCt counted",
9553 [PCOUNT_PFCNT] = "Useable",
9554 [PCOUNT_MAX] = NULL,
9555};
9556
Paul Jakma2815e612006-09-14 02:56:07 +00009557struct peer_pcounts
9558{
9559 unsigned int count[PCOUNT_MAX];
9560 const struct peer *peer;
9561 const struct bgp_table *table;
9562};
9563
Paul Jakmaff7924f2006-09-04 01:10:36 +00009564static int
Paul Jakma2815e612006-09-14 02:56:07 +00009565bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009566{
9567 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009568 struct peer_pcounts *pc = THREAD_ARG (t);
9569 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009570
Paul Jakma2815e612006-09-14 02:56:07 +00009571 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009572 {
9573 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009574 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009575
9576 for (ain = rn->adj_in; ain; ain = ain->next)
9577 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009578 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009579
Paul Jakmaff7924f2006-09-04 01:10:36 +00009580 for (ri = rn->info; ri; ri = ri->next)
9581 {
9582 char buf[SU_ADDRSTRLEN];
9583
9584 if (ri->peer != peer)
9585 continue;
9586
Paul Jakma2815e612006-09-14 02:56:07 +00009587 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009588
9589 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009590 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009591 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009592 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009593 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009594 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009595 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009596 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009597 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009598 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009599 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009600 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009601
9602 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9603 {
Paul Jakma2815e612006-09-14 02:56:07 +00009604 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009605 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009606 plog_warn (peer->log,
9607 "%s [pcount] %s/%d is counted but flags 0x%x",
9608 peer->host,
9609 inet_ntop(rn->p.family, &rn->p.u.prefix,
9610 buf, SU_ADDRSTRLEN),
9611 rn->p.prefixlen,
9612 ri->flags);
9613 }
9614 else
9615 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009616 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009617 plog_warn (peer->log,
9618 "%s [pcount] %s/%d not counted but flags 0x%x",
9619 peer->host,
9620 inet_ntop(rn->p.family, &rn->p.u.prefix,
9621 buf, SU_ADDRSTRLEN),
9622 rn->p.prefixlen,
9623 ri->flags);
9624 }
9625 }
9626 }
Paul Jakma2815e612006-09-14 02:56:07 +00009627 return 0;
9628}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009629
Paul Jakma2815e612006-09-14 02:56:07 +00009630static int
9631bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9632{
9633 struct peer_pcounts pcounts = { .peer = peer };
9634 unsigned int i;
9635
9636 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9637 || !peer->bgp->rib[afi][safi])
9638 {
9639 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9640 return CMD_WARNING;
9641 }
9642
9643 memset (&pcounts, 0, sizeof(pcounts));
9644 pcounts.peer = peer;
9645 pcounts.table = peer->bgp->rib[afi][safi];
9646
9647 /* in-place call via thread subsystem so as to record execution time
9648 * stats for the thread-walk (i.e. ensure this can't be blamed on
9649 * on just vty_read()).
9650 */
9651 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9652
Paul Jakmaff7924f2006-09-04 01:10:36 +00009653 vty_out (vty, "Prefix counts for %s, %s%s",
9654 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9655 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9656 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9657 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9658
9659 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009660 vty_out (vty, "%20s: %-10d%s",
9661 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009662
Paul Jakma2815e612006-09-14 02:56:07 +00009663 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009664 {
9665 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9666 peer->host, VTY_NEWLINE);
9667 vty_out (vty, "Please report this bug, with the above command output%s",
9668 VTY_NEWLINE);
9669 }
9670
9671 return CMD_SUCCESS;
9672}
9673
9674DEFUN (show_ip_bgp_neighbor_prefix_counts,
9675 show_ip_bgp_neighbor_prefix_counts_cmd,
9676 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9677 SHOW_STR
9678 IP_STR
9679 BGP_STR
9680 "Detailed information on TCP and BGP neighbor connections\n"
9681 "Neighbor to display information about\n"
9682 "Neighbor to display information about\n"
9683 "Display detailed prefix count information\n")
9684{
9685 struct peer *peer;
9686
9687 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9688 if (! peer)
9689 return CMD_WARNING;
9690
9691 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9692}
9693
9694DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9695 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9696 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9697 SHOW_STR
9698 BGP_STR
9699 "Address family\n"
9700 "Detailed information on TCP and BGP neighbor connections\n"
9701 "Neighbor to display information about\n"
9702 "Neighbor to display information about\n"
9703 "Display detailed prefix count information\n")
9704{
9705 struct peer *peer;
9706
9707 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9708 if (! peer)
9709 return CMD_WARNING;
9710
9711 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9712}
9713
9714DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9715 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9716 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9717 SHOW_STR
9718 IP_STR
9719 BGP_STR
9720 "Address family\n"
9721 "Address Family modifier\n"
9722 "Address Family modifier\n"
9723 "Detailed information on TCP and BGP neighbor connections\n"
9724 "Neighbor to display information about\n"
9725 "Neighbor to display information about\n"
9726 "Display detailed prefix count information\n")
9727{
9728 struct peer *peer;
9729
9730 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9731 if (! peer)
9732 return CMD_WARNING;
9733
9734 if (strncmp (argv[0], "m", 1) == 0)
9735 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9736
9737 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9738}
9739
9740DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9741 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9742 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9743 SHOW_STR
9744 IP_STR
9745 BGP_STR
9746 "Address family\n"
9747 "Address Family modifier\n"
9748 "Address Family modifier\n"
9749 "Detailed information on TCP and BGP neighbor connections\n"
9750 "Neighbor to display information about\n"
9751 "Neighbor to display information about\n"
9752 "Display detailed prefix count information\n")
9753{
9754 struct peer *peer;
9755
9756 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9757 if (! peer)
9758 return CMD_WARNING;
9759
9760 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9761}
9762
9763
paul94f2b392005-06-28 12:44:16 +00009764static void
paul718e3742002-12-13 20:15:29 +00009765show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9766 int in)
9767{
9768 struct bgp_table *table;
9769 struct bgp_adj_in *ain;
9770 struct bgp_adj_out *adj;
9771 unsigned long output_count;
9772 struct bgp_node *rn;
9773 int header1 = 1;
9774 struct bgp *bgp;
9775 int header2 = 1;
9776
paulbb46e942003-10-24 19:02:03 +00009777 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009778
9779 if (! bgp)
9780 return;
9781
9782 table = bgp->rib[afi][safi];
9783
9784 output_count = 0;
9785
9786 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9787 PEER_STATUS_DEFAULT_ORIGINATE))
9788 {
9789 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 +00009790 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9791 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009792
9793 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9794 VTY_NEWLINE, VTY_NEWLINE);
9795 header1 = 0;
9796 }
9797
9798 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9799 if (in)
9800 {
9801 for (ain = rn->adj_in; ain; ain = ain->next)
9802 if (ain->peer == peer)
9803 {
9804 if (header1)
9805 {
9806 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 +00009807 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9808 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009809 header1 = 0;
9810 }
9811 if (header2)
9812 {
9813 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9814 header2 = 0;
9815 }
9816 if (ain->attr)
9817 {
9818 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9819 output_count++;
9820 }
9821 }
9822 }
9823 else
9824 {
9825 for (adj = rn->adj_out; adj; adj = adj->next)
9826 if (adj->peer == peer)
9827 {
9828 if (header1)
9829 {
9830 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 +00009831 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9832 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009833 header1 = 0;
9834 }
9835 if (header2)
9836 {
9837 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9838 header2 = 0;
9839 }
9840 if (adj->attr)
9841 {
9842 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9843 output_count++;
9844 }
9845 }
9846 }
9847
9848 if (output_count != 0)
9849 vty_out (vty, "%sTotal number of prefixes %ld%s",
9850 VTY_NEWLINE, output_count, VTY_NEWLINE);
9851}
9852
paul94f2b392005-06-28 12:44:16 +00009853static int
paulbb46e942003-10-24 19:02:03 +00009854peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9855{
paul718e3742002-12-13 20:15:29 +00009856 if (! peer || ! peer->afc[afi][safi])
9857 {
9858 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9859 return CMD_WARNING;
9860 }
9861
9862 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9863 {
9864 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9865 VTY_NEWLINE);
9866 return CMD_WARNING;
9867 }
9868
9869 show_adj_route (vty, peer, afi, safi, in);
9870
9871 return CMD_SUCCESS;
9872}
9873
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009874DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9875 show_ip_bgp_view_neighbor_advertised_route_cmd,
9876 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9877 SHOW_STR
9878 IP_STR
9879 BGP_STR
9880 "BGP view\n"
9881 "View name\n"
9882 "Detailed information on TCP and BGP neighbor connections\n"
9883 "Neighbor to display information about\n"
9884 "Neighbor to display information about\n"
9885 "Display the routes advertised to a BGP neighbor\n")
9886{
9887 struct peer *peer;
9888
9889 if (argc == 2)
9890 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9891 else
9892 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9893
9894 if (! peer)
9895 return CMD_WARNING;
9896
9897 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9898}
9899
9900ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009901 show_ip_bgp_neighbor_advertised_route_cmd,
9902 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9903 SHOW_STR
9904 IP_STR
9905 BGP_STR
9906 "Detailed information on TCP and BGP neighbor connections\n"
9907 "Neighbor to display information about\n"
9908 "Neighbor to display information about\n"
9909 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009910
9911DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9912 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9913 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9914 SHOW_STR
9915 IP_STR
9916 BGP_STR
9917 "Address family\n"
9918 "Address Family modifier\n"
9919 "Address Family modifier\n"
9920 "Detailed information on TCP and BGP neighbor connections\n"
9921 "Neighbor to display information about\n"
9922 "Neighbor to display information about\n"
9923 "Display the routes advertised to a BGP neighbor\n")
9924{
paulbb46e942003-10-24 19:02:03 +00009925 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009926
paulbb46e942003-10-24 19:02:03 +00009927 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9928 if (! peer)
9929 return CMD_WARNING;
9930
9931 if (strncmp (argv[0], "m", 1) == 0)
9932 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9933
9934 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009935}
9936
9937#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009938DEFUN (show_bgp_view_neighbor_advertised_route,
9939 show_bgp_view_neighbor_advertised_route_cmd,
9940 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9941 SHOW_STR
9942 BGP_STR
9943 "BGP view\n"
9944 "View name\n"
9945 "Detailed information on TCP and BGP neighbor connections\n"
9946 "Neighbor to display information about\n"
9947 "Neighbor to display information about\n"
9948 "Display the routes advertised to a BGP neighbor\n")
9949{
9950 struct peer *peer;
9951
9952 if (argc == 2)
9953 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9954 else
9955 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9956
9957 if (! peer)
9958 return CMD_WARNING;
9959
9960 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9961}
9962
9963ALIAS (show_bgp_view_neighbor_advertised_route,
9964 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9965 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9966 SHOW_STR
9967 BGP_STR
9968 "BGP view\n"
9969 "View name\n"
9970 "Address family\n"
9971 "Detailed information on TCP and BGP neighbor connections\n"
9972 "Neighbor to display information about\n"
9973 "Neighbor to display information about\n"
9974 "Display the routes advertised to a BGP neighbor\n")
9975
9976DEFUN (show_bgp_view_neighbor_received_routes,
9977 show_bgp_view_neighbor_received_routes_cmd,
9978 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9979 SHOW_STR
9980 BGP_STR
9981 "BGP view\n"
9982 "View name\n"
9983 "Detailed information on TCP and BGP neighbor connections\n"
9984 "Neighbor to display information about\n"
9985 "Neighbor to display information about\n"
9986 "Display the received routes from neighbor\n")
9987{
9988 struct peer *peer;
9989
9990 if (argc == 2)
9991 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9992 else
9993 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9994
9995 if (! peer)
9996 return CMD_WARNING;
9997
9998 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9999}
10000
10001ALIAS (show_bgp_view_neighbor_received_routes,
10002 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10003 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10004 SHOW_STR
10005 BGP_STR
10006 "BGP view\n"
10007 "View name\n"
10008 "Address family\n"
10009 "Detailed information on TCP and BGP neighbor connections\n"
10010 "Neighbor to display information about\n"
10011 "Neighbor to display information about\n"
10012 "Display the received routes from neighbor\n")
10013
10014ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010015 show_bgp_neighbor_advertised_route_cmd,
10016 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10017 SHOW_STR
10018 BGP_STR
10019 "Detailed information on TCP and BGP neighbor connections\n"
10020 "Neighbor to display information about\n"
10021 "Neighbor to display information about\n"
10022 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010023
10024ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010025 show_bgp_ipv6_neighbor_advertised_route_cmd,
10026 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10027 SHOW_STR
10028 BGP_STR
10029 "Address family\n"
10030 "Detailed information on TCP and BGP neighbor connections\n"
10031 "Neighbor to display information about\n"
10032 "Neighbor to display information about\n"
10033 "Display the routes advertised to a BGP neighbor\n")
10034
10035/* old command */
paulbb46e942003-10-24 19:02:03 +000010036ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010037 ipv6_bgp_neighbor_advertised_route_cmd,
10038 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10039 SHOW_STR
10040 IPV6_STR
10041 BGP_STR
10042 "Detailed information on TCP and BGP neighbor connections\n"
10043 "Neighbor to display information about\n"
10044 "Neighbor to display information about\n"
10045 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010046
paul718e3742002-12-13 20:15:29 +000010047/* old command */
10048DEFUN (ipv6_mbgp_neighbor_advertised_route,
10049 ipv6_mbgp_neighbor_advertised_route_cmd,
10050 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10051 SHOW_STR
10052 IPV6_STR
10053 MBGP_STR
10054 "Detailed information on TCP and BGP neighbor connections\n"
10055 "Neighbor to display information about\n"
10056 "Neighbor to display information about\n"
10057 "Display the routes advertised to a BGP neighbor\n")
10058{
paulbb46e942003-10-24 19:02:03 +000010059 struct peer *peer;
10060
10061 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10062 if (! peer)
10063 return CMD_WARNING;
10064
10065 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010066}
10067#endif /* HAVE_IPV6 */
10068
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010069DEFUN (show_ip_bgp_view_neighbor_received_routes,
10070 show_ip_bgp_view_neighbor_received_routes_cmd,
10071 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10072 SHOW_STR
10073 IP_STR
10074 BGP_STR
10075 "BGP view\n"
10076 "View name\n"
10077 "Detailed information on TCP and BGP neighbor connections\n"
10078 "Neighbor to display information about\n"
10079 "Neighbor to display information about\n"
10080 "Display the received routes from neighbor\n")
10081{
10082 struct peer *peer;
10083
10084 if (argc == 2)
10085 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10086 else
10087 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10088
10089 if (! peer)
10090 return CMD_WARNING;
10091
10092 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10093}
10094
10095ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010096 show_ip_bgp_neighbor_received_routes_cmd,
10097 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10098 SHOW_STR
10099 IP_STR
10100 BGP_STR
10101 "Detailed information on TCP and BGP neighbor connections\n"
10102 "Neighbor to display information about\n"
10103 "Neighbor to display information about\n"
10104 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010105
10106DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10107 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10108 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10109 SHOW_STR
10110 IP_STR
10111 BGP_STR
10112 "Address family\n"
10113 "Address Family modifier\n"
10114 "Address Family modifier\n"
10115 "Detailed information on TCP and BGP neighbor connections\n"
10116 "Neighbor to display information about\n"
10117 "Neighbor to display information about\n"
10118 "Display the received routes from neighbor\n")
10119{
paulbb46e942003-10-24 19:02:03 +000010120 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010121
paulbb46e942003-10-24 19:02:03 +000010122 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10123 if (! peer)
10124 return CMD_WARNING;
10125
10126 if (strncmp (argv[0], "m", 1) == 0)
10127 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10128
10129 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010130}
10131
Michael Lambert95cbbd22010-07-23 14:43:04 -040010132DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10133 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10134#ifdef HAVE_IPV6
10135 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10136#else
10137 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10138#endif
10139 SHOW_STR
10140 BGP_STR
10141 "BGP view\n"
10142 "BGP view name\n"
10143 "Address family\n"
10144#ifdef HAVE_IPV6
10145 "Address family\n"
10146#endif
10147 "Address family modifier\n"
10148 "Address family modifier\n"
10149 "Detailed information on TCP and BGP neighbor connections\n"
10150 "Neighbor to display information about\n"
10151 "Neighbor to display information about\n"
10152 "Display the advertised routes to neighbor\n"
10153 "Display the received routes from neighbor\n")
10154{
10155 int afi;
10156 int safi;
10157 int in;
10158 struct peer *peer;
10159
10160#ifdef HAVE_IPV6
10161 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10162#else
10163 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10164#endif
10165
10166 if (! peer)
10167 return CMD_WARNING;
10168
10169#ifdef HAVE_IPV6
10170 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10171 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10172 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10173#else
10174 afi = AFI_IP;
10175 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10176 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10177#endif
10178
10179 return peer_adj_routes (vty, peer, afi, safi, in);
10180}
10181
paul718e3742002-12-13 20:15:29 +000010182DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10183 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10184 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10185 SHOW_STR
10186 IP_STR
10187 BGP_STR
10188 "Detailed information on TCP and BGP neighbor connections\n"
10189 "Neighbor to display information about\n"
10190 "Neighbor to display information about\n"
10191 "Display information received from a BGP neighbor\n"
10192 "Display the prefixlist filter\n")
10193{
10194 char name[BUFSIZ];
10195 union sockunion *su;
10196 struct peer *peer;
10197 int count;
10198
10199 su = sockunion_str2su (argv[0]);
10200 if (su == NULL)
10201 return CMD_WARNING;
10202
10203 peer = peer_lookup (NULL, su);
10204 if (! peer)
10205 return CMD_WARNING;
10206
10207 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10208 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10209 if (count)
10210 {
10211 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10212 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10213 }
10214
10215 return CMD_SUCCESS;
10216}
10217
10218DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10219 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10220 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10221 SHOW_STR
10222 IP_STR
10223 BGP_STR
10224 "Address family\n"
10225 "Address Family modifier\n"
10226 "Address Family modifier\n"
10227 "Detailed information on TCP and BGP neighbor connections\n"
10228 "Neighbor to display information about\n"
10229 "Neighbor to display information about\n"
10230 "Display information received from a BGP neighbor\n"
10231 "Display the prefixlist filter\n")
10232{
10233 char name[BUFSIZ];
10234 union sockunion *su;
10235 struct peer *peer;
10236 int count;
10237
10238 su = sockunion_str2su (argv[1]);
10239 if (su == NULL)
10240 return CMD_WARNING;
10241
10242 peer = peer_lookup (NULL, su);
10243 if (! peer)
10244 return CMD_WARNING;
10245
10246 if (strncmp (argv[0], "m", 1) == 0)
10247 {
10248 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10249 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10250 if (count)
10251 {
10252 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10253 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10254 }
10255 }
10256 else
10257 {
10258 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10259 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10260 if (count)
10261 {
10262 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10263 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10264 }
10265 }
10266
10267 return CMD_SUCCESS;
10268}
10269
10270
10271#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010272ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010273 show_bgp_neighbor_received_routes_cmd,
10274 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10275 SHOW_STR
10276 BGP_STR
10277 "Detailed information on TCP and BGP neighbor connections\n"
10278 "Neighbor to display information about\n"
10279 "Neighbor to display information about\n"
10280 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010281
paulbb46e942003-10-24 19:02:03 +000010282ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010283 show_bgp_ipv6_neighbor_received_routes_cmd,
10284 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10285 SHOW_STR
10286 BGP_STR
10287 "Address family\n"
10288 "Detailed information on TCP and BGP neighbor connections\n"
10289 "Neighbor to display information about\n"
10290 "Neighbor to display information about\n"
10291 "Display the received routes from neighbor\n")
10292
10293DEFUN (show_bgp_neighbor_received_prefix_filter,
10294 show_bgp_neighbor_received_prefix_filter_cmd,
10295 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10296 SHOW_STR
10297 BGP_STR
10298 "Detailed information on TCP and BGP neighbor connections\n"
10299 "Neighbor to display information about\n"
10300 "Neighbor to display information about\n"
10301 "Display information received from a BGP neighbor\n"
10302 "Display the prefixlist filter\n")
10303{
10304 char name[BUFSIZ];
10305 union sockunion *su;
10306 struct peer *peer;
10307 int count;
10308
10309 su = sockunion_str2su (argv[0]);
10310 if (su == NULL)
10311 return CMD_WARNING;
10312
10313 peer = peer_lookup (NULL, su);
10314 if (! peer)
10315 return CMD_WARNING;
10316
10317 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10318 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10319 if (count)
10320 {
10321 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10322 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10323 }
10324
10325 return CMD_SUCCESS;
10326}
10327
10328ALIAS (show_bgp_neighbor_received_prefix_filter,
10329 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10330 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10331 SHOW_STR
10332 BGP_STR
10333 "Address family\n"
10334 "Detailed information on TCP and BGP neighbor connections\n"
10335 "Neighbor to display information about\n"
10336 "Neighbor to display information about\n"
10337 "Display information received from a BGP neighbor\n"
10338 "Display the prefixlist filter\n")
10339
10340/* old command */
paulbb46e942003-10-24 19:02:03 +000010341ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010342 ipv6_bgp_neighbor_received_routes_cmd,
10343 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10344 SHOW_STR
10345 IPV6_STR
10346 BGP_STR
10347 "Detailed information on TCP and BGP neighbor connections\n"
10348 "Neighbor to display information about\n"
10349 "Neighbor to display information about\n"
10350 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010351
10352/* old command */
10353DEFUN (ipv6_mbgp_neighbor_received_routes,
10354 ipv6_mbgp_neighbor_received_routes_cmd,
10355 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10356 SHOW_STR
10357 IPV6_STR
10358 MBGP_STR
10359 "Detailed information on TCP and BGP neighbor connections\n"
10360 "Neighbor to display information about\n"
10361 "Neighbor to display information about\n"
10362 "Display the received routes from neighbor\n")
10363{
paulbb46e942003-10-24 19:02:03 +000010364 struct peer *peer;
10365
10366 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10367 if (! peer)
10368 return CMD_WARNING;
10369
10370 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010371}
paulbb46e942003-10-24 19:02:03 +000010372
10373DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10374 show_bgp_view_neighbor_received_prefix_filter_cmd,
10375 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10376 SHOW_STR
10377 BGP_STR
10378 "BGP view\n"
10379 "View name\n"
10380 "Detailed information on TCP and BGP neighbor connections\n"
10381 "Neighbor to display information about\n"
10382 "Neighbor to display information about\n"
10383 "Display information received from a BGP neighbor\n"
10384 "Display the prefixlist filter\n")
10385{
10386 char name[BUFSIZ];
10387 union sockunion *su;
10388 struct peer *peer;
10389 struct bgp *bgp;
10390 int count;
10391
10392 /* BGP structure lookup. */
10393 bgp = bgp_lookup_by_name (argv[0]);
10394 if (bgp == NULL)
10395 {
10396 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10397 return CMD_WARNING;
10398 }
10399
10400 su = sockunion_str2su (argv[1]);
10401 if (su == NULL)
10402 return CMD_WARNING;
10403
10404 peer = peer_lookup (bgp, su);
10405 if (! peer)
10406 return CMD_WARNING;
10407
10408 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10409 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10410 if (count)
10411 {
10412 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10413 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10414 }
10415
10416 return CMD_SUCCESS;
10417}
10418
10419ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10420 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10421 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10422 SHOW_STR
10423 BGP_STR
10424 "BGP view\n"
10425 "View name\n"
10426 "Address family\n"
10427 "Detailed information on TCP and BGP neighbor connections\n"
10428 "Neighbor to display information about\n"
10429 "Neighbor to display information about\n"
10430 "Display information received from a BGP neighbor\n"
10431 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010432#endif /* HAVE_IPV6 */
10433
paul94f2b392005-06-28 12:44:16 +000010434static int
paulbb46e942003-10-24 19:02:03 +000010435bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010436 safi_t safi, enum bgp_show_type type)
10437{
paul718e3742002-12-13 20:15:29 +000010438 if (! peer || ! peer->afc[afi][safi])
10439 {
10440 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010441 return CMD_WARNING;
10442 }
10443
ajs5a646652004-11-05 01:25:55 +000010444 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010445}
10446
10447DEFUN (show_ip_bgp_neighbor_routes,
10448 show_ip_bgp_neighbor_routes_cmd,
10449 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10450 SHOW_STR
10451 IP_STR
10452 BGP_STR
10453 "Detailed information on TCP and BGP neighbor connections\n"
10454 "Neighbor to display information about\n"
10455 "Neighbor to display information about\n"
10456 "Display routes learned from neighbor\n")
10457{
paulbb46e942003-10-24 19:02:03 +000010458 struct peer *peer;
10459
10460 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10461 if (! peer)
10462 return CMD_WARNING;
10463
10464 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010465 bgp_show_type_neighbor);
10466}
10467
10468DEFUN (show_ip_bgp_neighbor_flap,
10469 show_ip_bgp_neighbor_flap_cmd,
10470 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10471 SHOW_STR
10472 IP_STR
10473 BGP_STR
10474 "Detailed information on TCP and BGP neighbor connections\n"
10475 "Neighbor to display information about\n"
10476 "Neighbor to display information about\n"
10477 "Display flap statistics of the routes learned from neighbor\n")
10478{
paulbb46e942003-10-24 19:02:03 +000010479 struct peer *peer;
10480
10481 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10482 if (! peer)
10483 return CMD_WARNING;
10484
10485 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010486 bgp_show_type_flap_neighbor);
10487}
10488
10489DEFUN (show_ip_bgp_neighbor_damp,
10490 show_ip_bgp_neighbor_damp_cmd,
10491 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10492 SHOW_STR
10493 IP_STR
10494 BGP_STR
10495 "Detailed information on TCP and BGP neighbor connections\n"
10496 "Neighbor to display information about\n"
10497 "Neighbor to display information about\n"
10498 "Display the dampened routes received from neighbor\n")
10499{
paulbb46e942003-10-24 19:02:03 +000010500 struct peer *peer;
10501
10502 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10503 if (! peer)
10504 return CMD_WARNING;
10505
10506 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010507 bgp_show_type_damp_neighbor);
10508}
10509
10510DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10511 show_ip_bgp_ipv4_neighbor_routes_cmd,
10512 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10513 SHOW_STR
10514 IP_STR
10515 BGP_STR
10516 "Address family\n"
10517 "Address Family modifier\n"
10518 "Address Family modifier\n"
10519 "Detailed information on TCP and BGP neighbor connections\n"
10520 "Neighbor to display information about\n"
10521 "Neighbor to display information about\n"
10522 "Display routes learned from neighbor\n")
10523{
paulbb46e942003-10-24 19:02:03 +000010524 struct peer *peer;
10525
10526 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10527 if (! peer)
10528 return CMD_WARNING;
10529
paul718e3742002-12-13 20:15:29 +000010530 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010531 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010532 bgp_show_type_neighbor);
10533
paulbb46e942003-10-24 19:02:03 +000010534 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010535 bgp_show_type_neighbor);
10536}
paulbb46e942003-10-24 19:02:03 +000010537
paulfee0f4c2004-09-13 05:12:46 +000010538DEFUN (show_ip_bgp_view_rsclient,
10539 show_ip_bgp_view_rsclient_cmd,
10540 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10541 SHOW_STR
10542 IP_STR
10543 BGP_STR
10544 "BGP view\n"
10545 "BGP view name\n"
10546 "Information about Route Server Client\n"
10547 NEIGHBOR_ADDR_STR)
10548{
10549 struct bgp_table *table;
10550 struct peer *peer;
10551
10552 if (argc == 2)
10553 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10554 else
10555 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10556
10557 if (! peer)
10558 return CMD_WARNING;
10559
10560 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10561 {
10562 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10563 VTY_NEWLINE);
10564 return CMD_WARNING;
10565 }
10566
10567 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10568 PEER_FLAG_RSERVER_CLIENT))
10569 {
10570 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10571 VTY_NEWLINE);
10572 return CMD_WARNING;
10573 }
10574
10575 table = peer->rib[AFI_IP][SAFI_UNICAST];
10576
ajs5a646652004-11-05 01:25:55 +000010577 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010578}
10579
10580ALIAS (show_ip_bgp_view_rsclient,
10581 show_ip_bgp_rsclient_cmd,
10582 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10583 SHOW_STR
10584 IP_STR
10585 BGP_STR
10586 "Information about Route Server Client\n"
10587 NEIGHBOR_ADDR_STR)
10588
Michael Lambert95cbbd22010-07-23 14:43:04 -040010589DEFUN (show_bgp_view_ipv4_safi_rsclient,
10590 show_bgp_view_ipv4_safi_rsclient_cmd,
10591 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10592 SHOW_STR
10593 BGP_STR
10594 "BGP view\n"
10595 "BGP view name\n"
10596 "Address family\n"
10597 "Address Family modifier\n"
10598 "Address Family modifier\n"
10599 "Information about Route Server Client\n"
10600 NEIGHBOR_ADDR_STR)
10601{
10602 struct bgp_table *table;
10603 struct peer *peer;
10604 safi_t safi;
10605
10606 if (argc == 3) {
10607 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10608 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10609 } else {
10610 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10611 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10612 }
10613
10614 if (! peer)
10615 return CMD_WARNING;
10616
10617 if (! peer->afc[AFI_IP][safi])
10618 {
10619 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10620 VTY_NEWLINE);
10621 return CMD_WARNING;
10622 }
10623
10624 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10625 PEER_FLAG_RSERVER_CLIENT))
10626 {
10627 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10628 VTY_NEWLINE);
10629 return CMD_WARNING;
10630 }
10631
10632 table = peer->rib[AFI_IP][safi];
10633
10634 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10635}
10636
10637ALIAS (show_bgp_view_ipv4_safi_rsclient,
10638 show_bgp_ipv4_safi_rsclient_cmd,
10639 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10640 SHOW_STR
10641 BGP_STR
10642 "Address family\n"
10643 "Address Family modifier\n"
10644 "Address Family modifier\n"
10645 "Information about Route Server Client\n"
10646 NEIGHBOR_ADDR_STR)
10647
paulfee0f4c2004-09-13 05:12:46 +000010648DEFUN (show_ip_bgp_view_rsclient_route,
10649 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010650 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010651 SHOW_STR
10652 IP_STR
10653 BGP_STR
10654 "BGP view\n"
10655 "BGP view name\n"
10656 "Information about Route Server Client\n"
10657 NEIGHBOR_ADDR_STR
10658 "Network in the BGP routing table to display\n")
10659{
10660 struct bgp *bgp;
10661 struct peer *peer;
10662
10663 /* BGP structure lookup. */
10664 if (argc == 3)
10665 {
10666 bgp = bgp_lookup_by_name (argv[0]);
10667 if (bgp == NULL)
10668 {
10669 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10670 return CMD_WARNING;
10671 }
10672 }
10673 else
10674 {
10675 bgp = bgp_get_default ();
10676 if (bgp == NULL)
10677 {
10678 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10679 return CMD_WARNING;
10680 }
10681 }
10682
10683 if (argc == 3)
10684 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10685 else
10686 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10687
10688 if (! peer)
10689 return CMD_WARNING;
10690
10691 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10692 {
10693 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10694 VTY_NEWLINE);
10695 return CMD_WARNING;
10696}
10697
10698 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10699 PEER_FLAG_RSERVER_CLIENT))
10700 {
10701 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10702 VTY_NEWLINE);
10703 return CMD_WARNING;
10704 }
10705
10706 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10707 (argc == 3) ? argv[2] : argv[1],
10708 AFI_IP, SAFI_UNICAST, NULL, 0);
10709}
10710
10711ALIAS (show_ip_bgp_view_rsclient_route,
10712 show_ip_bgp_rsclient_route_cmd,
10713 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10714 SHOW_STR
10715 IP_STR
10716 BGP_STR
10717 "Information about Route Server Client\n"
10718 NEIGHBOR_ADDR_STR
10719 "Network in the BGP routing table to display\n")
10720
Michael Lambert95cbbd22010-07-23 14:43:04 -040010721DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10722 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10723 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10724 SHOW_STR
10725 BGP_STR
10726 "BGP view\n"
10727 "BGP view name\n"
10728 "Address family\n"
10729 "Address Family modifier\n"
10730 "Address Family modifier\n"
10731 "Information about Route Server Client\n"
10732 NEIGHBOR_ADDR_STR
10733 "Network in the BGP routing table to display\n")
10734{
10735 struct bgp *bgp;
10736 struct peer *peer;
10737 safi_t safi;
10738
10739 /* BGP structure lookup. */
10740 if (argc == 4)
10741 {
10742 bgp = bgp_lookup_by_name (argv[0]);
10743 if (bgp == NULL)
10744 {
10745 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10746 return CMD_WARNING;
10747 }
10748 }
10749 else
10750 {
10751 bgp = bgp_get_default ();
10752 if (bgp == NULL)
10753 {
10754 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10755 return CMD_WARNING;
10756 }
10757 }
10758
10759 if (argc == 4) {
10760 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10761 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10762 } else {
10763 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10764 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10765 }
10766
10767 if (! peer)
10768 return CMD_WARNING;
10769
10770 if (! peer->afc[AFI_IP][safi])
10771 {
10772 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10773 VTY_NEWLINE);
10774 return CMD_WARNING;
10775}
10776
10777 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10778 PEER_FLAG_RSERVER_CLIENT))
10779 {
10780 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10781 VTY_NEWLINE);
10782 return CMD_WARNING;
10783 }
10784
10785 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10786 (argc == 4) ? argv[3] : argv[2],
10787 AFI_IP, safi, NULL, 0);
10788}
10789
10790ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10791 show_bgp_ipv4_safi_rsclient_route_cmd,
10792 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10793 SHOW_STR
10794 BGP_STR
10795 "Address family\n"
10796 "Address Family modifier\n"
10797 "Address Family modifier\n"
10798 "Information about Route Server Client\n"
10799 NEIGHBOR_ADDR_STR
10800 "Network in the BGP routing table to display\n")
10801
paulfee0f4c2004-09-13 05:12:46 +000010802DEFUN (show_ip_bgp_view_rsclient_prefix,
10803 show_ip_bgp_view_rsclient_prefix_cmd,
10804 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10805 SHOW_STR
10806 IP_STR
10807 BGP_STR
10808 "BGP view\n"
10809 "BGP view name\n"
10810 "Information about Route Server Client\n"
10811 NEIGHBOR_ADDR_STR
10812 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10813{
10814 struct bgp *bgp;
10815 struct peer *peer;
10816
10817 /* BGP structure lookup. */
10818 if (argc == 3)
10819 {
10820 bgp = bgp_lookup_by_name (argv[0]);
10821 if (bgp == NULL)
10822 {
10823 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10824 return CMD_WARNING;
10825 }
10826 }
10827 else
10828 {
10829 bgp = bgp_get_default ();
10830 if (bgp == NULL)
10831 {
10832 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10833 return CMD_WARNING;
10834 }
10835 }
10836
10837 if (argc == 3)
10838 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10839 else
10840 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10841
10842 if (! peer)
10843 return CMD_WARNING;
10844
10845 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10846 {
10847 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10848 VTY_NEWLINE);
10849 return CMD_WARNING;
10850}
10851
10852 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10853 PEER_FLAG_RSERVER_CLIENT))
10854{
10855 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10856 VTY_NEWLINE);
10857 return CMD_WARNING;
10858 }
10859
10860 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10861 (argc == 3) ? argv[2] : argv[1],
10862 AFI_IP, SAFI_UNICAST, NULL, 1);
10863}
10864
10865ALIAS (show_ip_bgp_view_rsclient_prefix,
10866 show_ip_bgp_rsclient_prefix_cmd,
10867 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10868 SHOW_STR
10869 IP_STR
10870 BGP_STR
10871 "Information about Route Server Client\n"
10872 NEIGHBOR_ADDR_STR
10873 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10874
Michael Lambert95cbbd22010-07-23 14:43:04 -040010875DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10876 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10877 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10878 SHOW_STR
10879 BGP_STR
10880 "BGP view\n"
10881 "BGP view name\n"
10882 "Address family\n"
10883 "Address Family modifier\n"
10884 "Address Family modifier\n"
10885 "Information about Route Server Client\n"
10886 NEIGHBOR_ADDR_STR
10887 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10888{
10889 struct bgp *bgp;
10890 struct peer *peer;
10891 safi_t safi;
10892
10893 /* BGP structure lookup. */
10894 if (argc == 4)
10895 {
10896 bgp = bgp_lookup_by_name (argv[0]);
10897 if (bgp == NULL)
10898 {
10899 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10900 return CMD_WARNING;
10901 }
10902 }
10903 else
10904 {
10905 bgp = bgp_get_default ();
10906 if (bgp == NULL)
10907 {
10908 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10909 return CMD_WARNING;
10910 }
10911 }
10912
10913 if (argc == 4) {
10914 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10915 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10916 } else {
10917 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10918 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10919 }
10920
10921 if (! peer)
10922 return CMD_WARNING;
10923
10924 if (! peer->afc[AFI_IP][safi])
10925 {
10926 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10927 VTY_NEWLINE);
10928 return CMD_WARNING;
10929}
10930
10931 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10932 PEER_FLAG_RSERVER_CLIENT))
10933{
10934 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10935 VTY_NEWLINE);
10936 return CMD_WARNING;
10937 }
10938
10939 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10940 (argc == 4) ? argv[3] : argv[2],
10941 AFI_IP, safi, NULL, 1);
10942}
10943
10944ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10945 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10946 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10947 SHOW_STR
10948 BGP_STR
10949 "Address family\n"
10950 "Address Family modifier\n"
10951 "Address Family modifier\n"
10952 "Information about Route Server Client\n"
10953 NEIGHBOR_ADDR_STR
10954 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010955
paul718e3742002-12-13 20:15:29 +000010956#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010957DEFUN (show_bgp_view_neighbor_routes,
10958 show_bgp_view_neighbor_routes_cmd,
10959 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10960 SHOW_STR
10961 BGP_STR
10962 "BGP view\n"
10963 "BGP view name\n"
10964 "Detailed information on TCP and BGP neighbor connections\n"
10965 "Neighbor to display information about\n"
10966 "Neighbor to display information about\n"
10967 "Display routes learned from neighbor\n")
10968{
10969 struct peer *peer;
10970
10971 if (argc == 2)
10972 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10973 else
10974 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10975
10976 if (! peer)
10977 return CMD_WARNING;
10978
10979 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10980 bgp_show_type_neighbor);
10981}
10982
10983ALIAS (show_bgp_view_neighbor_routes,
10984 show_bgp_view_ipv6_neighbor_routes_cmd,
10985 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10986 SHOW_STR
10987 BGP_STR
10988 "BGP view\n"
10989 "BGP view name\n"
10990 "Address family\n"
10991 "Detailed information on TCP and BGP neighbor connections\n"
10992 "Neighbor to display information about\n"
10993 "Neighbor to display information about\n"
10994 "Display routes learned from neighbor\n")
10995
10996DEFUN (show_bgp_view_neighbor_damp,
10997 show_bgp_view_neighbor_damp_cmd,
10998 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10999 SHOW_STR
11000 BGP_STR
11001 "BGP view\n"
11002 "BGP view name\n"
11003 "Detailed information on TCP and BGP neighbor connections\n"
11004 "Neighbor to display information about\n"
11005 "Neighbor to display information about\n"
11006 "Display the dampened routes received from neighbor\n")
11007{
11008 struct peer *peer;
11009
11010 if (argc == 2)
11011 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11012 else
11013 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11014
11015 if (! peer)
11016 return CMD_WARNING;
11017
11018 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11019 bgp_show_type_damp_neighbor);
11020}
11021
11022ALIAS (show_bgp_view_neighbor_damp,
11023 show_bgp_view_ipv6_neighbor_damp_cmd,
11024 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11025 SHOW_STR
11026 BGP_STR
11027 "BGP view\n"
11028 "BGP view name\n"
11029 "Address family\n"
11030 "Detailed information on TCP and BGP neighbor connections\n"
11031 "Neighbor to display information about\n"
11032 "Neighbor to display information about\n"
11033 "Display the dampened routes received from neighbor\n")
11034
11035DEFUN (show_bgp_view_neighbor_flap,
11036 show_bgp_view_neighbor_flap_cmd,
11037 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11038 SHOW_STR
11039 BGP_STR
11040 "BGP view\n"
11041 "BGP view name\n"
11042 "Detailed information on TCP and BGP neighbor connections\n"
11043 "Neighbor to display information about\n"
11044 "Neighbor to display information about\n"
11045 "Display flap statistics of the routes learned from neighbor\n")
11046{
11047 struct peer *peer;
11048
11049 if (argc == 2)
11050 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11051 else
11052 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11053
11054 if (! peer)
11055 return CMD_WARNING;
11056
11057 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11058 bgp_show_type_flap_neighbor);
11059}
11060
11061ALIAS (show_bgp_view_neighbor_flap,
11062 show_bgp_view_ipv6_neighbor_flap_cmd,
11063 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11064 SHOW_STR
11065 BGP_STR
11066 "BGP view\n"
11067 "BGP view name\n"
11068 "Address family\n"
11069 "Detailed information on TCP and BGP neighbor connections\n"
11070 "Neighbor to display information about\n"
11071 "Neighbor to display information about\n"
11072 "Display flap statistics of the routes learned from neighbor\n")
11073
11074ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011075 show_bgp_neighbor_routes_cmd,
11076 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11077 SHOW_STR
11078 BGP_STR
11079 "Detailed information on TCP and BGP neighbor connections\n"
11080 "Neighbor to display information about\n"
11081 "Neighbor to display information about\n"
11082 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011083
paulbb46e942003-10-24 19:02:03 +000011084
11085ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011086 show_bgp_ipv6_neighbor_routes_cmd,
11087 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11088 SHOW_STR
11089 BGP_STR
11090 "Address family\n"
11091 "Detailed information on TCP and BGP neighbor connections\n"
11092 "Neighbor to display information about\n"
11093 "Neighbor to display information about\n"
11094 "Display routes learned from neighbor\n")
11095
11096/* old command */
paulbb46e942003-10-24 19:02:03 +000011097ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011098 ipv6_bgp_neighbor_routes_cmd,
11099 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11100 SHOW_STR
11101 IPV6_STR
11102 BGP_STR
11103 "Detailed information on TCP and BGP neighbor connections\n"
11104 "Neighbor to display information about\n"
11105 "Neighbor to display information about\n"
11106 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011107
11108/* old command */
11109DEFUN (ipv6_mbgp_neighbor_routes,
11110 ipv6_mbgp_neighbor_routes_cmd,
11111 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11112 SHOW_STR
11113 IPV6_STR
11114 MBGP_STR
11115 "Detailed information on TCP and BGP neighbor connections\n"
11116 "Neighbor to display information about\n"
11117 "Neighbor to display information about\n"
11118 "Display routes learned from neighbor\n")
11119{
paulbb46e942003-10-24 19:02:03 +000011120 struct peer *peer;
11121
11122 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11123 if (! peer)
11124 return CMD_WARNING;
11125
11126 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011127 bgp_show_type_neighbor);
11128}
paulbb46e942003-10-24 19:02:03 +000011129
11130ALIAS (show_bgp_view_neighbor_flap,
11131 show_bgp_neighbor_flap_cmd,
11132 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11133 SHOW_STR
11134 BGP_STR
11135 "Detailed information on TCP and BGP neighbor connections\n"
11136 "Neighbor to display information about\n"
11137 "Neighbor to display information about\n"
11138 "Display flap statistics of the routes learned from neighbor\n")
11139
11140ALIAS (show_bgp_view_neighbor_flap,
11141 show_bgp_ipv6_neighbor_flap_cmd,
11142 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11143 SHOW_STR
11144 BGP_STR
11145 "Address family\n"
11146 "Detailed information on TCP and BGP neighbor connections\n"
11147 "Neighbor to display information about\n"
11148 "Neighbor to display information about\n"
11149 "Display flap statistics of the routes learned from neighbor\n")
11150
11151ALIAS (show_bgp_view_neighbor_damp,
11152 show_bgp_neighbor_damp_cmd,
11153 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11154 SHOW_STR
11155 BGP_STR
11156 "Detailed information on TCP and BGP neighbor connections\n"
11157 "Neighbor to display information about\n"
11158 "Neighbor to display information about\n"
11159 "Display the dampened routes received from neighbor\n")
11160
11161ALIAS (show_bgp_view_neighbor_damp,
11162 show_bgp_ipv6_neighbor_damp_cmd,
11163 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11164 SHOW_STR
11165 BGP_STR
11166 "Address family\n"
11167 "Detailed information on TCP and BGP neighbor connections\n"
11168 "Neighbor to display information about\n"
11169 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011170 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011171
11172DEFUN (show_bgp_view_rsclient,
11173 show_bgp_view_rsclient_cmd,
11174 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11175 SHOW_STR
11176 BGP_STR
11177 "BGP view\n"
11178 "BGP view name\n"
11179 "Information about Route Server Client\n"
11180 NEIGHBOR_ADDR_STR)
11181{
11182 struct bgp_table *table;
11183 struct peer *peer;
11184
11185 if (argc == 2)
11186 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11187 else
11188 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11189
11190 if (! peer)
11191 return CMD_WARNING;
11192
11193 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11194 {
11195 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11196 VTY_NEWLINE);
11197 return CMD_WARNING;
11198 }
11199
11200 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11201 PEER_FLAG_RSERVER_CLIENT))
11202 {
11203 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11204 VTY_NEWLINE);
11205 return CMD_WARNING;
11206 }
11207
11208 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11209
ajs5a646652004-11-05 01:25:55 +000011210 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011211}
11212
11213ALIAS (show_bgp_view_rsclient,
11214 show_bgp_rsclient_cmd,
11215 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11216 SHOW_STR
11217 BGP_STR
11218 "Information about Route Server Client\n"
11219 NEIGHBOR_ADDR_STR)
11220
Michael Lambert95cbbd22010-07-23 14:43:04 -040011221DEFUN (show_bgp_view_ipv6_safi_rsclient,
11222 show_bgp_view_ipv6_safi_rsclient_cmd,
11223 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11224 SHOW_STR
11225 BGP_STR
11226 "BGP view\n"
11227 "BGP view name\n"
11228 "Address family\n"
11229 "Address Family modifier\n"
11230 "Address Family modifier\n"
11231 "Information about Route Server Client\n"
11232 NEIGHBOR_ADDR_STR)
11233{
11234 struct bgp_table *table;
11235 struct peer *peer;
11236 safi_t safi;
11237
11238 if (argc == 3) {
11239 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11240 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11241 } else {
11242 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11243 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11244 }
11245
11246 if (! peer)
11247 return CMD_WARNING;
11248
11249 if (! peer->afc[AFI_IP6][safi])
11250 {
11251 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11252 VTY_NEWLINE);
11253 return CMD_WARNING;
11254 }
11255
11256 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11257 PEER_FLAG_RSERVER_CLIENT))
11258 {
11259 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11260 VTY_NEWLINE);
11261 return CMD_WARNING;
11262 }
11263
11264 table = peer->rib[AFI_IP6][safi];
11265
11266 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11267}
11268
11269ALIAS (show_bgp_view_ipv6_safi_rsclient,
11270 show_bgp_ipv6_safi_rsclient_cmd,
11271 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11272 SHOW_STR
11273 BGP_STR
11274 "Address family\n"
11275 "Address Family modifier\n"
11276 "Address Family modifier\n"
11277 "Information about Route Server Client\n"
11278 NEIGHBOR_ADDR_STR)
11279
paulfee0f4c2004-09-13 05:12:46 +000011280DEFUN (show_bgp_view_rsclient_route,
11281 show_bgp_view_rsclient_route_cmd,
11282 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11283 SHOW_STR
11284 BGP_STR
11285 "BGP view\n"
11286 "BGP view name\n"
11287 "Information about Route Server Client\n"
11288 NEIGHBOR_ADDR_STR
11289 "Network in the BGP routing table to display\n")
11290{
11291 struct bgp *bgp;
11292 struct peer *peer;
11293
11294 /* BGP structure lookup. */
11295 if (argc == 3)
11296 {
11297 bgp = bgp_lookup_by_name (argv[0]);
11298 if (bgp == NULL)
11299 {
11300 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11301 return CMD_WARNING;
11302 }
11303 }
11304 else
11305 {
11306 bgp = bgp_get_default ();
11307 if (bgp == NULL)
11308 {
11309 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11310 return CMD_WARNING;
11311 }
11312 }
11313
11314 if (argc == 3)
11315 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11316 else
11317 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11318
11319 if (! peer)
11320 return CMD_WARNING;
11321
11322 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11323 {
11324 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11325 VTY_NEWLINE);
11326 return CMD_WARNING;
11327 }
11328
11329 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11330 PEER_FLAG_RSERVER_CLIENT))
11331 {
11332 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11333 VTY_NEWLINE);
11334 return CMD_WARNING;
11335 }
11336
11337 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11338 (argc == 3) ? argv[2] : argv[1],
11339 AFI_IP6, SAFI_UNICAST, NULL, 0);
11340}
11341
11342ALIAS (show_bgp_view_rsclient_route,
11343 show_bgp_rsclient_route_cmd,
11344 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11345 SHOW_STR
11346 BGP_STR
11347 "Information about Route Server Client\n"
11348 NEIGHBOR_ADDR_STR
11349 "Network in the BGP routing table to display\n")
11350
Michael Lambert95cbbd22010-07-23 14:43:04 -040011351DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11352 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11353 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11354 SHOW_STR
11355 BGP_STR
11356 "BGP view\n"
11357 "BGP view name\n"
11358 "Address family\n"
11359 "Address Family modifier\n"
11360 "Address Family modifier\n"
11361 "Information about Route Server Client\n"
11362 NEIGHBOR_ADDR_STR
11363 "Network in the BGP routing table to display\n")
11364{
11365 struct bgp *bgp;
11366 struct peer *peer;
11367 safi_t safi;
11368
11369 /* BGP structure lookup. */
11370 if (argc == 4)
11371 {
11372 bgp = bgp_lookup_by_name (argv[0]);
11373 if (bgp == NULL)
11374 {
11375 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11376 return CMD_WARNING;
11377 }
11378 }
11379 else
11380 {
11381 bgp = bgp_get_default ();
11382 if (bgp == NULL)
11383 {
11384 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11385 return CMD_WARNING;
11386 }
11387 }
11388
11389 if (argc == 4) {
11390 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11391 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11392 } else {
11393 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11394 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11395 }
11396
11397 if (! peer)
11398 return CMD_WARNING;
11399
11400 if (! peer->afc[AFI_IP6][safi])
11401 {
11402 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11403 VTY_NEWLINE);
11404 return CMD_WARNING;
11405}
11406
11407 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11408 PEER_FLAG_RSERVER_CLIENT))
11409 {
11410 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11411 VTY_NEWLINE);
11412 return CMD_WARNING;
11413 }
11414
11415 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11416 (argc == 4) ? argv[3] : argv[2],
11417 AFI_IP6, safi, NULL, 0);
11418}
11419
11420ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11421 show_bgp_ipv6_safi_rsclient_route_cmd,
11422 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11423 SHOW_STR
11424 BGP_STR
11425 "Address family\n"
11426 "Address Family modifier\n"
11427 "Address Family modifier\n"
11428 "Information about Route Server Client\n"
11429 NEIGHBOR_ADDR_STR
11430 "Network in the BGP routing table to display\n")
11431
paulfee0f4c2004-09-13 05:12:46 +000011432DEFUN (show_bgp_view_rsclient_prefix,
11433 show_bgp_view_rsclient_prefix_cmd,
11434 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11435 SHOW_STR
11436 BGP_STR
11437 "BGP view\n"
11438 "BGP view name\n"
11439 "Information about Route Server Client\n"
11440 NEIGHBOR_ADDR_STR
11441 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11442{
11443 struct bgp *bgp;
11444 struct peer *peer;
11445
11446 /* BGP structure lookup. */
11447 if (argc == 3)
11448 {
11449 bgp = bgp_lookup_by_name (argv[0]);
11450 if (bgp == NULL)
11451 {
11452 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11453 return CMD_WARNING;
11454 }
11455 }
11456 else
11457 {
11458 bgp = bgp_get_default ();
11459 if (bgp == NULL)
11460 {
11461 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11462 return CMD_WARNING;
11463 }
11464 }
11465
11466 if (argc == 3)
11467 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11468 else
11469 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11470
11471 if (! peer)
11472 return CMD_WARNING;
11473
11474 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11475 {
11476 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11477 VTY_NEWLINE);
11478 return CMD_WARNING;
11479 }
11480
11481 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11482 PEER_FLAG_RSERVER_CLIENT))
11483 {
11484 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11485 VTY_NEWLINE);
11486 return CMD_WARNING;
11487 }
11488
11489 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11490 (argc == 3) ? argv[2] : argv[1],
11491 AFI_IP6, SAFI_UNICAST, NULL, 1);
11492}
11493
11494ALIAS (show_bgp_view_rsclient_prefix,
11495 show_bgp_rsclient_prefix_cmd,
11496 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11497 SHOW_STR
11498 BGP_STR
11499 "Information about Route Server Client\n"
11500 NEIGHBOR_ADDR_STR
11501 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11502
Michael Lambert95cbbd22010-07-23 14:43:04 -040011503DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11504 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11505 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11506 SHOW_STR
11507 BGP_STR
11508 "BGP view\n"
11509 "BGP view name\n"
11510 "Address family\n"
11511 "Address Family modifier\n"
11512 "Address Family modifier\n"
11513 "Information about Route Server Client\n"
11514 NEIGHBOR_ADDR_STR
11515 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11516{
11517 struct bgp *bgp;
11518 struct peer *peer;
11519 safi_t safi;
11520
11521 /* BGP structure lookup. */
11522 if (argc == 4)
11523 {
11524 bgp = bgp_lookup_by_name (argv[0]);
11525 if (bgp == NULL)
11526 {
11527 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11528 return CMD_WARNING;
11529 }
11530 }
11531 else
11532 {
11533 bgp = bgp_get_default ();
11534 if (bgp == NULL)
11535 {
11536 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11537 return CMD_WARNING;
11538 }
11539 }
11540
11541 if (argc == 4) {
11542 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11543 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11544 } else {
11545 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11546 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11547 }
11548
11549 if (! peer)
11550 return CMD_WARNING;
11551
11552 if (! peer->afc[AFI_IP6][safi])
11553 {
11554 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11555 VTY_NEWLINE);
11556 return CMD_WARNING;
11557}
11558
11559 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11560 PEER_FLAG_RSERVER_CLIENT))
11561{
11562 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11563 VTY_NEWLINE);
11564 return CMD_WARNING;
11565 }
11566
11567 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11568 (argc == 4) ? argv[3] : argv[2],
11569 AFI_IP6, safi, NULL, 1);
11570}
11571
11572ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11573 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11574 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11575 SHOW_STR
11576 BGP_STR
11577 "Address family\n"
11578 "Address Family modifier\n"
11579 "Address Family modifier\n"
11580 "Information about Route Server Client\n"
11581 NEIGHBOR_ADDR_STR
11582 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11583
paul718e3742002-12-13 20:15:29 +000011584#endif /* HAVE_IPV6 */
11585
11586struct bgp_table *bgp_distance_table;
11587
11588struct bgp_distance
11589{
11590 /* Distance value for the IP source prefix. */
11591 u_char distance;
11592
11593 /* Name of the access-list to be matched. */
11594 char *access_list;
11595};
11596
paul94f2b392005-06-28 12:44:16 +000011597static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011598bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011599{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011600 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011601}
11602
paul94f2b392005-06-28 12:44:16 +000011603static void
paul718e3742002-12-13 20:15:29 +000011604bgp_distance_free (struct bgp_distance *bdistance)
11605{
11606 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11607}
11608
paul94f2b392005-06-28 12:44:16 +000011609static int
paulfd79ac92004-10-13 05:06:08 +000011610bgp_distance_set (struct vty *vty, const char *distance_str,
11611 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011612{
11613 int ret;
11614 struct prefix_ipv4 p;
11615 u_char distance;
11616 struct bgp_node *rn;
11617 struct bgp_distance *bdistance;
11618
11619 ret = str2prefix_ipv4 (ip_str, &p);
11620 if (ret == 0)
11621 {
11622 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11623 return CMD_WARNING;
11624 }
11625
11626 distance = atoi (distance_str);
11627
11628 /* Get BGP distance node. */
11629 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11630 if (rn->info)
11631 {
11632 bdistance = rn->info;
11633 bgp_unlock_node (rn);
11634 }
11635 else
11636 {
11637 bdistance = bgp_distance_new ();
11638 rn->info = bdistance;
11639 }
11640
11641 /* Set distance value. */
11642 bdistance->distance = distance;
11643
11644 /* Reset access-list configuration. */
11645 if (bdistance->access_list)
11646 {
11647 free (bdistance->access_list);
11648 bdistance->access_list = NULL;
11649 }
11650 if (access_list_str)
11651 bdistance->access_list = strdup (access_list_str);
11652
11653 return CMD_SUCCESS;
11654}
11655
paul94f2b392005-06-28 12:44:16 +000011656static int
paulfd79ac92004-10-13 05:06:08 +000011657bgp_distance_unset (struct vty *vty, const char *distance_str,
11658 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011659{
11660 int ret;
11661 struct prefix_ipv4 p;
11662 u_char distance;
11663 struct bgp_node *rn;
11664 struct bgp_distance *bdistance;
11665
11666 ret = str2prefix_ipv4 (ip_str, &p);
11667 if (ret == 0)
11668 {
11669 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11670 return CMD_WARNING;
11671 }
11672
11673 distance = atoi (distance_str);
11674
11675 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11676 if (! rn)
11677 {
11678 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11679 return CMD_WARNING;
11680 }
11681
11682 bdistance = rn->info;
11683
11684 if (bdistance->access_list)
11685 free (bdistance->access_list);
11686 bgp_distance_free (bdistance);
11687
11688 rn->info = NULL;
11689 bgp_unlock_node (rn);
11690 bgp_unlock_node (rn);
11691
11692 return CMD_SUCCESS;
11693}
11694
paul718e3742002-12-13 20:15:29 +000011695/* Apply BGP information to distance method. */
11696u_char
11697bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11698{
11699 struct bgp_node *rn;
11700 struct prefix_ipv4 q;
11701 struct peer *peer;
11702 struct bgp_distance *bdistance;
11703 struct access_list *alist;
11704 struct bgp_static *bgp_static;
11705
11706 if (! bgp)
11707 return 0;
11708
11709 if (p->family != AF_INET)
11710 return 0;
11711
11712 peer = rinfo->peer;
11713
11714 if (peer->su.sa.sa_family != AF_INET)
11715 return 0;
11716
11717 memset (&q, 0, sizeof (struct prefix_ipv4));
11718 q.family = AF_INET;
11719 q.prefix = peer->su.sin.sin_addr;
11720 q.prefixlen = IPV4_MAX_BITLEN;
11721
11722 /* Check source address. */
11723 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11724 if (rn)
11725 {
11726 bdistance = rn->info;
11727 bgp_unlock_node (rn);
11728
11729 if (bdistance->access_list)
11730 {
11731 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11732 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11733 return bdistance->distance;
11734 }
11735 else
11736 return bdistance->distance;
11737 }
11738
11739 /* Backdoor check. */
11740 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11741 if (rn)
11742 {
11743 bgp_static = rn->info;
11744 bgp_unlock_node (rn);
11745
11746 if (bgp_static->backdoor)
11747 {
11748 if (bgp->distance_local)
11749 return bgp->distance_local;
11750 else
11751 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11752 }
11753 }
11754
11755 if (peer_sort (peer) == BGP_PEER_EBGP)
11756 {
11757 if (bgp->distance_ebgp)
11758 return bgp->distance_ebgp;
11759 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11760 }
11761 else
11762 {
11763 if (bgp->distance_ibgp)
11764 return bgp->distance_ibgp;
11765 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11766 }
11767}
11768
11769DEFUN (bgp_distance,
11770 bgp_distance_cmd,
11771 "distance bgp <1-255> <1-255> <1-255>",
11772 "Define an administrative distance\n"
11773 "BGP distance\n"
11774 "Distance for routes external to the AS\n"
11775 "Distance for routes internal to the AS\n"
11776 "Distance for local routes\n")
11777{
11778 struct bgp *bgp;
11779
11780 bgp = vty->index;
11781
11782 bgp->distance_ebgp = atoi (argv[0]);
11783 bgp->distance_ibgp = atoi (argv[1]);
11784 bgp->distance_local = atoi (argv[2]);
11785 return CMD_SUCCESS;
11786}
11787
11788DEFUN (no_bgp_distance,
11789 no_bgp_distance_cmd,
11790 "no distance bgp <1-255> <1-255> <1-255>",
11791 NO_STR
11792 "Define an administrative distance\n"
11793 "BGP distance\n"
11794 "Distance for routes external to the AS\n"
11795 "Distance for routes internal to the AS\n"
11796 "Distance for local routes\n")
11797{
11798 struct bgp *bgp;
11799
11800 bgp = vty->index;
11801
11802 bgp->distance_ebgp= 0;
11803 bgp->distance_ibgp = 0;
11804 bgp->distance_local = 0;
11805 return CMD_SUCCESS;
11806}
11807
11808ALIAS (no_bgp_distance,
11809 no_bgp_distance2_cmd,
11810 "no distance bgp",
11811 NO_STR
11812 "Define an administrative distance\n"
11813 "BGP distance\n")
11814
11815DEFUN (bgp_distance_source,
11816 bgp_distance_source_cmd,
11817 "distance <1-255> A.B.C.D/M",
11818 "Define an administrative distance\n"
11819 "Administrative distance\n"
11820 "IP source prefix\n")
11821{
11822 bgp_distance_set (vty, argv[0], argv[1], NULL);
11823 return CMD_SUCCESS;
11824}
11825
11826DEFUN (no_bgp_distance_source,
11827 no_bgp_distance_source_cmd,
11828 "no distance <1-255> A.B.C.D/M",
11829 NO_STR
11830 "Define an administrative distance\n"
11831 "Administrative distance\n"
11832 "IP source prefix\n")
11833{
11834 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11835 return CMD_SUCCESS;
11836}
11837
11838DEFUN (bgp_distance_source_access_list,
11839 bgp_distance_source_access_list_cmd,
11840 "distance <1-255> A.B.C.D/M WORD",
11841 "Define an administrative distance\n"
11842 "Administrative distance\n"
11843 "IP source prefix\n"
11844 "Access list name\n")
11845{
11846 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11847 return CMD_SUCCESS;
11848}
11849
11850DEFUN (no_bgp_distance_source_access_list,
11851 no_bgp_distance_source_access_list_cmd,
11852 "no distance <1-255> A.B.C.D/M WORD",
11853 NO_STR
11854 "Define an administrative distance\n"
11855 "Administrative distance\n"
11856 "IP source prefix\n"
11857 "Access list name\n")
11858{
11859 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11860 return CMD_SUCCESS;
11861}
11862
11863DEFUN (bgp_damp_set,
11864 bgp_damp_set_cmd,
11865 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11866 "BGP Specific commands\n"
11867 "Enable route-flap dampening\n"
11868 "Half-life time for the penalty\n"
11869 "Value to start reusing a route\n"
11870 "Value to start suppressing a route\n"
11871 "Maximum duration to suppress a stable route\n")
11872{
11873 struct bgp *bgp;
11874 int half = DEFAULT_HALF_LIFE * 60;
11875 int reuse = DEFAULT_REUSE;
11876 int suppress = DEFAULT_SUPPRESS;
11877 int max = 4 * half;
11878
11879 if (argc == 4)
11880 {
11881 half = atoi (argv[0]) * 60;
11882 reuse = atoi (argv[1]);
11883 suppress = atoi (argv[2]);
11884 max = atoi (argv[3]) * 60;
11885 }
11886 else if (argc == 1)
11887 {
11888 half = atoi (argv[0]) * 60;
11889 max = 4 * half;
11890 }
11891
11892 bgp = vty->index;
11893 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11894 half, reuse, suppress, max);
11895}
11896
11897ALIAS (bgp_damp_set,
11898 bgp_damp_set2_cmd,
11899 "bgp dampening <1-45>",
11900 "BGP Specific commands\n"
11901 "Enable route-flap dampening\n"
11902 "Half-life time for the penalty\n")
11903
11904ALIAS (bgp_damp_set,
11905 bgp_damp_set3_cmd,
11906 "bgp dampening",
11907 "BGP Specific commands\n"
11908 "Enable route-flap dampening\n")
11909
11910DEFUN (bgp_damp_unset,
11911 bgp_damp_unset_cmd,
11912 "no bgp dampening",
11913 NO_STR
11914 "BGP Specific commands\n"
11915 "Enable route-flap dampening\n")
11916{
11917 struct bgp *bgp;
11918
11919 bgp = vty->index;
11920 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11921}
11922
11923ALIAS (bgp_damp_unset,
11924 bgp_damp_unset2_cmd,
11925 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11926 NO_STR
11927 "BGP Specific commands\n"
11928 "Enable route-flap dampening\n"
11929 "Half-life time for the penalty\n"
11930 "Value to start reusing a route\n"
11931 "Value to start suppressing a route\n"
11932 "Maximum duration to suppress a stable route\n")
11933
11934DEFUN (show_ip_bgp_dampened_paths,
11935 show_ip_bgp_dampened_paths_cmd,
11936 "show ip bgp dampened-paths",
11937 SHOW_STR
11938 IP_STR
11939 BGP_STR
11940 "Display paths suppressed due to dampening\n")
11941{
ajs5a646652004-11-05 01:25:55 +000011942 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11943 NULL);
paul718e3742002-12-13 20:15:29 +000011944}
11945
11946DEFUN (show_ip_bgp_flap_statistics,
11947 show_ip_bgp_flap_statistics_cmd,
11948 "show ip bgp flap-statistics",
11949 SHOW_STR
11950 IP_STR
11951 BGP_STR
11952 "Display flap statistics of routes\n")
11953{
ajs5a646652004-11-05 01:25:55 +000011954 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11955 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011956}
11957
11958/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011959static int
paulfd79ac92004-10-13 05:06:08 +000011960bgp_clear_damp_route (struct vty *vty, const char *view_name,
11961 const char *ip_str, afi_t afi, safi_t safi,
11962 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011963{
11964 int ret;
11965 struct prefix match;
11966 struct bgp_node *rn;
11967 struct bgp_node *rm;
11968 struct bgp_info *ri;
11969 struct bgp_info *ri_temp;
11970 struct bgp *bgp;
11971 struct bgp_table *table;
11972
11973 /* BGP structure lookup. */
11974 if (view_name)
11975 {
11976 bgp = bgp_lookup_by_name (view_name);
11977 if (bgp == NULL)
11978 {
11979 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11980 return CMD_WARNING;
11981 }
11982 }
11983 else
11984 {
11985 bgp = bgp_get_default ();
11986 if (bgp == NULL)
11987 {
11988 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11989 return CMD_WARNING;
11990 }
11991 }
11992
11993 /* Check IP address argument. */
11994 ret = str2prefix (ip_str, &match);
11995 if (! ret)
11996 {
11997 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11998 return CMD_WARNING;
11999 }
12000
12001 match.family = afi2family (afi);
12002
12003 if (safi == SAFI_MPLS_VPN)
12004 {
12005 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12006 {
12007 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12008 continue;
12009
12010 if ((table = rn->info) != NULL)
12011 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012012 {
12013 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12014 {
12015 ri = rm->info;
12016 while (ri)
12017 {
12018 if (ri->extra && ri->extra->damp_info)
12019 {
12020 ri_temp = ri->next;
12021 bgp_damp_info_free (ri->extra->damp_info, 1);
12022 ri = ri_temp;
12023 }
12024 else
12025 ri = ri->next;
12026 }
12027 }
12028
12029 bgp_unlock_node (rm);
12030 }
paul718e3742002-12-13 20:15:29 +000012031 }
12032 }
12033 else
12034 {
12035 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012036 {
12037 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12038 {
12039 ri = rn->info;
12040 while (ri)
12041 {
12042 if (ri->extra && ri->extra->damp_info)
12043 {
12044 ri_temp = ri->next;
12045 bgp_damp_info_free (ri->extra->damp_info, 1);
12046 ri = ri_temp;
12047 }
12048 else
12049 ri = ri->next;
12050 }
12051 }
12052
12053 bgp_unlock_node (rn);
12054 }
paul718e3742002-12-13 20:15:29 +000012055 }
12056
12057 return CMD_SUCCESS;
12058}
12059
12060DEFUN (clear_ip_bgp_dampening,
12061 clear_ip_bgp_dampening_cmd,
12062 "clear ip bgp dampening",
12063 CLEAR_STR
12064 IP_STR
12065 BGP_STR
12066 "Clear route flap dampening information\n")
12067{
12068 bgp_damp_info_clean ();
12069 return CMD_SUCCESS;
12070}
12071
12072DEFUN (clear_ip_bgp_dampening_prefix,
12073 clear_ip_bgp_dampening_prefix_cmd,
12074 "clear ip bgp dampening A.B.C.D/M",
12075 CLEAR_STR
12076 IP_STR
12077 BGP_STR
12078 "Clear route flap dampening information\n"
12079 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12080{
12081 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12082 SAFI_UNICAST, NULL, 1);
12083}
12084
12085DEFUN (clear_ip_bgp_dampening_address,
12086 clear_ip_bgp_dampening_address_cmd,
12087 "clear ip bgp dampening A.B.C.D",
12088 CLEAR_STR
12089 IP_STR
12090 BGP_STR
12091 "Clear route flap dampening information\n"
12092 "Network to clear damping information\n")
12093{
12094 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12095 SAFI_UNICAST, NULL, 0);
12096}
12097
12098DEFUN (clear_ip_bgp_dampening_address_mask,
12099 clear_ip_bgp_dampening_address_mask_cmd,
12100 "clear ip bgp dampening A.B.C.D A.B.C.D",
12101 CLEAR_STR
12102 IP_STR
12103 BGP_STR
12104 "Clear route flap dampening information\n"
12105 "Network to clear damping information\n"
12106 "Network mask\n")
12107{
12108 int ret;
12109 char prefix_str[BUFSIZ];
12110
12111 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12112 if (! ret)
12113 {
12114 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12115 return CMD_WARNING;
12116 }
12117
12118 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12119 SAFI_UNICAST, NULL, 0);
12120}
12121
paul94f2b392005-06-28 12:44:16 +000012122static int
paul718e3742002-12-13 20:15:29 +000012123bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12124 afi_t afi, safi_t safi, int *write)
12125{
12126 struct bgp_node *prn;
12127 struct bgp_node *rn;
12128 struct bgp_table *table;
12129 struct prefix *p;
12130 struct prefix_rd *prd;
12131 struct bgp_static *bgp_static;
12132 u_int32_t label;
12133 char buf[SU_ADDRSTRLEN];
12134 char rdbuf[RD_ADDRSTRLEN];
12135
12136 /* Network configuration. */
12137 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12138 if ((table = prn->info) != NULL)
12139 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12140 if ((bgp_static = rn->info) != NULL)
12141 {
12142 p = &rn->p;
12143 prd = (struct prefix_rd *) &prn->p;
12144
12145 /* "address-family" display. */
12146 bgp_config_write_family_header (vty, afi, safi, write);
12147
12148 /* "network" configuration display. */
12149 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12150 label = decode_label (bgp_static->tag);
12151
12152 vty_out (vty, " network %s/%d rd %s tag %d",
12153 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12154 p->prefixlen,
12155 rdbuf, label);
12156 vty_out (vty, "%s", VTY_NEWLINE);
12157 }
12158 return 0;
12159}
12160
12161/* Configuration of static route announcement and aggregate
12162 information. */
12163int
12164bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12165 afi_t afi, safi_t safi, int *write)
12166{
12167 struct bgp_node *rn;
12168 struct prefix *p;
12169 struct bgp_static *bgp_static;
12170 struct bgp_aggregate *bgp_aggregate;
12171 char buf[SU_ADDRSTRLEN];
12172
12173 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12174 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12175
12176 /* Network configuration. */
12177 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12178 if ((bgp_static = rn->info) != NULL)
12179 {
12180 p = &rn->p;
12181
12182 /* "address-family" display. */
12183 bgp_config_write_family_header (vty, afi, safi, write);
12184
12185 /* "network" configuration display. */
12186 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12187 {
12188 u_int32_t destination;
12189 struct in_addr netmask;
12190
12191 destination = ntohl (p->u.prefix4.s_addr);
12192 masklen2ip (p->prefixlen, &netmask);
12193 vty_out (vty, " network %s",
12194 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12195
12196 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12197 || (IN_CLASSB (destination) && p->prefixlen == 16)
12198 || (IN_CLASSA (destination) && p->prefixlen == 8)
12199 || p->u.prefix4.s_addr == 0)
12200 {
12201 /* Natural mask is not display. */
12202 }
12203 else
12204 vty_out (vty, " mask %s", inet_ntoa (netmask));
12205 }
12206 else
12207 {
12208 vty_out (vty, " network %s/%d",
12209 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12210 p->prefixlen);
12211 }
12212
12213 if (bgp_static->rmap.name)
12214 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012215 else
12216 {
12217 if (bgp_static->backdoor)
12218 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012219 }
paul718e3742002-12-13 20:15:29 +000012220
12221 vty_out (vty, "%s", VTY_NEWLINE);
12222 }
12223
12224 /* Aggregate-address configuration. */
12225 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12226 if ((bgp_aggregate = rn->info) != NULL)
12227 {
12228 p = &rn->p;
12229
12230 /* "address-family" display. */
12231 bgp_config_write_family_header (vty, afi, safi, write);
12232
12233 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12234 {
12235 struct in_addr netmask;
12236
12237 masklen2ip (p->prefixlen, &netmask);
12238 vty_out (vty, " aggregate-address %s %s",
12239 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12240 inet_ntoa (netmask));
12241 }
12242 else
12243 {
12244 vty_out (vty, " aggregate-address %s/%d",
12245 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12246 p->prefixlen);
12247 }
12248
12249 if (bgp_aggregate->as_set)
12250 vty_out (vty, " as-set");
12251
12252 if (bgp_aggregate->summary_only)
12253 vty_out (vty, " summary-only");
12254
12255 vty_out (vty, "%s", VTY_NEWLINE);
12256 }
12257
12258 return 0;
12259}
12260
12261int
12262bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12263{
12264 struct bgp_node *rn;
12265 struct bgp_distance *bdistance;
12266
12267 /* Distance configuration. */
12268 if (bgp->distance_ebgp
12269 && bgp->distance_ibgp
12270 && bgp->distance_local
12271 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12272 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12273 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12274 vty_out (vty, " distance bgp %d %d %d%s",
12275 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12276 VTY_NEWLINE);
12277
12278 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12279 if ((bdistance = rn->info) != NULL)
12280 {
12281 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12282 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12283 bdistance->access_list ? bdistance->access_list : "",
12284 VTY_NEWLINE);
12285 }
12286
12287 return 0;
12288}
12289
12290/* Allocate routing table structure and install commands. */
12291void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012292bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012293{
12294 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012295 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012296
12297 /* IPv4 BGP commands. */
12298 install_element (BGP_NODE, &bgp_network_cmd);
12299 install_element (BGP_NODE, &bgp_network_mask_cmd);
12300 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12301 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12302 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12303 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12304 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12305 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12306 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12307 install_element (BGP_NODE, &no_bgp_network_cmd);
12308 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12309 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12310 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12311 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12312 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12313 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12314 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12315 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12316
12317 install_element (BGP_NODE, &aggregate_address_cmd);
12318 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12319 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12320 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12321 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12322 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12323 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12324 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12325 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12326 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12327 install_element (BGP_NODE, &no_aggregate_address_cmd);
12328 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12329 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12330 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12331 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12332 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12333 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12334 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12335 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12336 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12337
12338 /* IPv4 unicast configuration. */
12339 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12340 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12341 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12342 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12343 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12344 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012345 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012346 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12347 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12348 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12349 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12350 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012351
paul718e3742002-12-13 20:15:29 +000012352 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12353 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12354 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12355 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12356 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12357 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12358 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12359 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12360 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12361 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12362 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12363 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12364 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12365 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12366 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12367 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12368 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12369 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12370 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12371 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12372
12373 /* IPv4 multicast configuration. */
12374 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12375 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12376 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12377 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12378 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12379 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12380 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12381 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12382 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12383 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12384 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12385 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12386 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12387 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12388 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12389 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12390 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12391 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12392 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12393 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12394 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12395 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12396 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12397 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12398 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12399 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12400 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12401 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12402 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12403 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12404 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12405 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12406
12407 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12408 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012409 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012410 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12411 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012412 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012413 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12414 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12415 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12416 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012417 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012418 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12419 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12420 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12421 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12422 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12423 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12424 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12425 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12426 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12427 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12428 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12429 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12430 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12431 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12432 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12433 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12434 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12435 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12436 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12437 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12438 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12439 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12440 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12441 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12442 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012443 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12444 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12445 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12446 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12447 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012448 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12449 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12450 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12451 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12452 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12453 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12454 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12455 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12456 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12457 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12458 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12459 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12460 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12462 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12463 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012466 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012467 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12468 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12472 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12473 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012483 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012484 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012485 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012486 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012487 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012488 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012489 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12490 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012491 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012492 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012493 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012494 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012495 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012496 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012497
12498 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12499 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12500 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012501 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012502 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12503 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12504 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012505 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012506 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12507 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12508 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12509 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12510 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12511 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12512 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12513 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12514 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12515 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12516 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12517 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012518 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12519 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12520 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12521 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12522 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012523 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12524 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12525 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12526 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12527 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12528 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12529 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12530 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12531 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012532 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012533 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012534 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012535 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012536 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012537 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012538 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012539
12540 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12541 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012542 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012543 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12544 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012545 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012546 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12547 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12548 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12549 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012550 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012551 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12552 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12553 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12554 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12555 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12556 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12557 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12558 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12559 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12560 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12561 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12562 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12563 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12564 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12565 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12566 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12567 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12568 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12569 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12570 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12571 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12572 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12573 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12574 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12575 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012576 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12577 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12578 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12579 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12580 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012581 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12582 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12583 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12584 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12585 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12586 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12587 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12588 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12589 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12590 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12591 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12592 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12593 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12595 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12596 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012599 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012600 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12601 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12605 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12606 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012616 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012617 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012618 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012619 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012620 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012621 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012622 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012624 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012625 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012626 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012627 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012628 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012629 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012630
12631 /* BGP dampening clear commands */
12632 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12633 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12634 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12635 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12636
Paul Jakmaff7924f2006-09-04 01:10:36 +000012637 /* prefix count */
12638 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12639 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12640 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012641#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012642 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12643
paul718e3742002-12-13 20:15:29 +000012644 /* New config IPv6 BGP commands. */
12645 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12646 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12647 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12648 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12649
12650 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12651 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12652 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12653 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12654
12655 /* Old config IPv6 BGP commands. */
12656 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12657 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12658
12659 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12660 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12661 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12662 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12663
12664 install_element (VIEW_NODE, &show_bgp_cmd);
12665 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012666 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012667 install_element (VIEW_NODE, &show_bgp_route_cmd);
12668 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012669 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012670 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12671 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012672 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012673 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12674 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12675 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12676 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12677 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12678 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12679 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12680 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12681 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12682 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12683 install_element (VIEW_NODE, &show_bgp_community_cmd);
12684 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12685 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12686 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12687 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12688 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12689 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12690 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12691 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12692 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12693 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12694 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12695 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12696 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12697 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12698 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12699 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12700 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12701 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12702 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12703 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12704 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12705 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12706 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12707 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12708 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12709 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12710 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12711 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12712 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012713 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12714 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12715 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12716 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012717 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012718 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012719 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012720 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012721 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012722 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012723 install_element (VIEW_NODE, &show_bgp_view_cmd);
12724 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12725 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12726 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12727 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12728 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12729 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12730 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12731 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12732 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12733 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12734 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12735 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12736 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12737 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12738 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12739 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12740 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012741 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012742 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012743 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012744 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012745 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012746 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012747
12748 /* Restricted:
12749 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12750 */
12751 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12752 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012753 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012754 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12755 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012756 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012757 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12758 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12759 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12760 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12761 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12762 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12763 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12764 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12765 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12766 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12767 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12768 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12769 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12770 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12771 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12772 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12773 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012774 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012775 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012776 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012777 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12778 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12779 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12780 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12781 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12782 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12783 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012784 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012785 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012786 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012787
12788 install_element (ENABLE_NODE, &show_bgp_cmd);
12789 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012790 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012791 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12792 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012793 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012794 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12795 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012796 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012797 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12798 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12799 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12800 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12801 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12802 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12803 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12804 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12805 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12806 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12807 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12808 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12809 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12810 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12811 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12812 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12813 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12814 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12815 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12816 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12817 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12818 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12819 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12820 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12821 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12822 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12823 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12824 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12825 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12826 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12827 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12828 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12829 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12830 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12831 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12832 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12833 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12834 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12835 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12836 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012837 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12838 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12839 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12840 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012841 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012842 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012843 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012844 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012845 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012846 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012847 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12848 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12849 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12850 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12851 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12852 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012865 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012866 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012867 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012868 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012869 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012870 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012871
12872 /* Statistics */
12873 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12874 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12875 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12876 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12877
paul718e3742002-12-13 20:15:29 +000012878 /* old command */
12879 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12880 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12881 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12882 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12883 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12884 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12885 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12886 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12887 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12888 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12889 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12890 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12891 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12892 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12893 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12894 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12895 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12896 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12897 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12898 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12899 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12900 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12901 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12902 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12903 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12904 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12905 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12906 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12907 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12908 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12909 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12910 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12911 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12912 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12913 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12914 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012915
paul718e3742002-12-13 20:15:29 +000012916 /* old command */
12917 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12918 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12919 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12920 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12921 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12922 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12923 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12924 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12925 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12926 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12927 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12928 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12929 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12930 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12931 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12932 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12933 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12934 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12935 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12936 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12937 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12938 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12939 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12940 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12941 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12942 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12943 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12944 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12945 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12946 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12947 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12948 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12949 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12950 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12951 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12952 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12953
12954 /* old command */
12955 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12956 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12957 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12958 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12959
12960 /* old command */
12961 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12962 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12963 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12964 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12965
12966 /* old command */
12967 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12968 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12969 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12970 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12971#endif /* HAVE_IPV6 */
12972
12973 install_element (BGP_NODE, &bgp_distance_cmd);
12974 install_element (BGP_NODE, &no_bgp_distance_cmd);
12975 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12976 install_element (BGP_NODE, &bgp_distance_source_cmd);
12977 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12978 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12979 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12980
12981 install_element (BGP_NODE, &bgp_damp_set_cmd);
12982 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12983 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12984 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12985 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12986 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12987 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12988 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12989 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12990 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012991
12992 /* Deprecated AS-Pathlimit commands */
12993 install_element (BGP_NODE, &bgp_network_ttl_cmd);
12994 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
12995 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
12996 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
12997 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12998 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12999
13000 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13001 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13002 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13003 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13004 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13005 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13006
13007 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13008 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13009 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13010 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13011 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13012 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13013
13014 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13015 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13016 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13017 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13018 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13019 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13020
13021 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13022 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13023 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13024 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13025 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13026 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13027
13028 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13029 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13030 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13031 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13032 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13033 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013034
13035#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013036 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13037 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013038#endif
paul718e3742002-12-13 20:15:29 +000013039}
Chris Caputo228da422009-07-18 05:44:03 +000013040
13041void
13042bgp_route_finish (void)
13043{
13044 bgp_table_unlock (bgp_distance_table);
13045 bgp_distance_table = NULL;
13046}