blob: 13ff63ca72fa6fda9ca5ca8baea7c57df1fc5d7d [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
paul718e3742002-12-13 20:15:29 +000057
58/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070059extern const char *bgp_origin_str[];
60extern const char *bgp_origin_long_str[];
paul718e3742002-12-13 20:15:29 +000061
paul94f2b392005-06-28 12:44:16 +000062static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000063bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000064 struct prefix_rd *prd)
65{
66 struct bgp_node *rn;
67 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000068
69 assert (table);
70 if (!table)
71 return NULL;
72
paul718e3742002-12-13 20:15:29 +000073 if (safi == SAFI_MPLS_VPN)
74 {
paulfee0f4c2004-09-13 05:12:46 +000075 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000076
77 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000078 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000079 else
80 bgp_unlock_node (prn);
81 table = prn->info;
82 }
paul718e3742002-12-13 20:15:29 +000083
84 rn = bgp_node_get (table, p);
85
86 if (safi == SAFI_MPLS_VPN)
87 rn->prn = prn;
88
89 return rn;
90}
91
Paul Jakmafb982c22007-05-04 20:15:47 +000092/* Allocate bgp_info_extra */
93static struct bgp_info_extra *
94bgp_info_extra_new (void)
95{
96 struct bgp_info_extra *new;
97 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
98 return new;
99}
100
101static void
102bgp_info_extra_free (struct bgp_info_extra **extra)
103{
104 if (extra && *extra)
105 {
106 if ((*extra)->damp_info)
107 bgp_damp_info_free ((*extra)->damp_info, 0);
108
109 (*extra)->damp_info = NULL;
110
111 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
112
113 *extra = NULL;
114 }
115}
116
117/* Get bgp_info extra information for the given bgp_info, lazy allocated
118 * if required.
119 */
120struct bgp_info_extra *
121bgp_info_extra_get (struct bgp_info *ri)
122{
123 if (!ri->extra)
124 ri->extra = bgp_info_extra_new();
125 return ri->extra;
126}
127
paul718e3742002-12-13 20:15:29 +0000128/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000129static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800130bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000131{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700132 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000133}
134
135/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000136static void
paul718e3742002-12-13 20:15:29 +0000137bgp_info_free (struct bgp_info *binfo)
138{
139 if (binfo->attr)
140 bgp_attr_unintern (binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000141
142 bgp_info_extra_free (&binfo->extra);
paul718e3742002-12-13 20:15:29 +0000143
paul200df112005-06-01 11:17:05 +0000144 peer_unlock (binfo->peer); /* bgp_info peer reference */
145
paul718e3742002-12-13 20:15:29 +0000146 XFREE (MTYPE_BGP_ROUTE, binfo);
147}
148
paul200df112005-06-01 11:17:05 +0000149struct bgp_info *
150bgp_info_lock (struct bgp_info *binfo)
151{
152 binfo->lock++;
153 return binfo;
154}
155
156struct bgp_info *
157bgp_info_unlock (struct bgp_info *binfo)
158{
159 assert (binfo && binfo->lock > 0);
160 binfo->lock--;
161
162 if (binfo->lock == 0)
163 {
164#if 0
165 zlog_debug ("%s: unlocked and freeing", __func__);
166 zlog_backtrace (LOG_DEBUG);
167#endif
168 bgp_info_free (binfo);
169 return NULL;
170 }
171
172#if 0
173 if (binfo->lock == 1)
174 {
175 zlog_debug ("%s: unlocked to 1", __func__);
176 zlog_backtrace (LOG_DEBUG);
177 }
178#endif
179
180 return binfo;
181}
182
paul718e3742002-12-13 20:15:29 +0000183void
184bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
185{
186 struct bgp_info *top;
187
188 top = rn->info;
paul200df112005-06-01 11:17:05 +0000189
paul718e3742002-12-13 20:15:29 +0000190 ri->next = rn->info;
191 ri->prev = NULL;
192 if (top)
193 top->prev = ri;
194 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000195
196 bgp_info_lock (ri);
197 bgp_lock_node (rn);
198 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000199}
200
paulb40d9392005-08-22 22:34:41 +0000201/* Do the actual removal of info from RIB, for use by bgp_process
202 completion callback *only* */
203static void
204bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000205{
206 if (ri->next)
207 ri->next->prev = ri->prev;
208 if (ri->prev)
209 ri->prev->next = ri->next;
210 else
211 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000212
213 bgp_info_unlock (ri);
214 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000215}
216
paulb40d9392005-08-22 22:34:41 +0000217void
218bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
219{
Paul Jakma1a392d42006-09-07 00:24:49 +0000220 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
221 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000222 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
223}
224
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000225/* undo the effects of a previous call to bgp_info_delete; typically
226 called when a route is deleted and then quickly re-added before the
227 deletion has been processed */
228static void
229bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
230{
231 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
232 /* unset of previous already took care of pcount */
233 SET_FLAG (ri->flags, BGP_INFO_VALID);
234}
235
Paul Jakma1a392d42006-09-07 00:24:49 +0000236/* Adjust pcount as required */
237static void
238bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
239{
Paul Jakma6f585442006-10-22 19:13:07 +0000240 assert (rn && rn->table);
241 assert (ri && ri->peer && ri->peer->bgp);
242
Paul Jakma1a392d42006-09-07 00:24:49 +0000243 /* Ignore 'pcount' for RS-client tables */
244 if (rn->table->type != BGP_TABLE_MAIN
245 || ri->peer == ri->peer->bgp->peer_self)
246 return;
247
248 if (BGP_INFO_HOLDDOWN (ri)
249 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
250 {
251
252 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
253
254 /* slight hack, but more robust against errors. */
255 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
256 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
257 else
258 {
259 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
260 __func__, ri->peer->host);
261 zlog_backtrace (LOG_WARNING);
262 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
263 }
264 }
265 else if (!BGP_INFO_HOLDDOWN (ri)
266 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
267 {
268 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
269 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
270 }
271}
272
273
274/* Set/unset bgp_info flags, adjusting any other state as needed.
275 * This is here primarily to keep prefix-count in check.
276 */
277void
278bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
279{
280 SET_FLAG (ri->flags, flag);
281
282 /* early bath if we know it's not a flag that changes useability state */
283 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
284 return;
285
286 bgp_pcount_adjust (rn, ri);
287}
288
289void
290bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
291{
292 UNSET_FLAG (ri->flags, flag);
293
294 /* early bath if we know it's not a flag that changes useability state */
295 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
296 return;
297
298 bgp_pcount_adjust (rn, ri);
299}
300
paul718e3742002-12-13 20:15:29 +0000301/* Get MED value. If MED value is missing and "bgp bestpath
302 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000303static u_int32_t
paul718e3742002-12-13 20:15:29 +0000304bgp_med_value (struct attr *attr, struct bgp *bgp)
305{
306 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
307 return attr->med;
308 else
309 {
310 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000311 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000312 else
313 return 0;
314 }
315}
316
317/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000318static int
paul718e3742002-12-13 20:15:29 +0000319bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist)
320{
321 u_int32_t new_pref;
322 u_int32_t exist_pref;
323 u_int32_t new_med;
324 u_int32_t exist_med;
Paul Jakmafb982c22007-05-04 20:15:47 +0000325 u_int32_t new_weight = 0;
326 u_int32_t exist_weight = 0;
paul718e3742002-12-13 20:15:29 +0000327 struct in_addr new_id;
328 struct in_addr exist_id;
329 int new_cluster;
330 int exist_cluster;
331 int internal_as_route = 0;
332 int confed_as_route = 0;
333 int ret;
334
335 /* 0. Null check. */
336 if (new == NULL)
337 return 0;
338 if (exist == NULL)
339 return 1;
340
341 /* 1. Weight check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000342 if (new->attr->extra)
343 new_weight = new->attr->extra->weight;
344 if (exist->attr->extra)
345 exist_weight = exist->attr->extra->weight;
346 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000347 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000348 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000349 return 0;
350
351 /* 2. Local preference check. */
352 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
353 new_pref = new->attr->local_pref;
354 else
355 new_pref = bgp->default_local_pref;
356
357 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
358 exist_pref = exist->attr->local_pref;
359 else
360 exist_pref = bgp->default_local_pref;
361
362 if (new_pref > exist_pref)
363 return 1;
364 if (new_pref < exist_pref)
365 return 0;
366
367 /* 3. Local route check. */
368 if (new->sub_type == BGP_ROUTE_STATIC)
369 return 1;
370 if (exist->sub_type == BGP_ROUTE_STATIC)
371 return 0;
372
373 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
374 return 1;
375 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
376 return 0;
377
378 if (new->sub_type == BGP_ROUTE_AGGREGATE)
379 return 1;
380 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
381 return 0;
382
383 /* 4. AS path length check. */
384 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
385 {
paulfe69a502005-09-10 16:55:02 +0000386 int exist_hops = aspath_count_hops (exist->attr->aspath);
387 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
388
hasso68118452005-04-08 15:40:36 +0000389 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
390 {
paulfe69a502005-09-10 16:55:02 +0000391 int aspath_hops;
392
393 aspath_hops = aspath_count_hops (new->attr->aspath);
394 aspath_hops += aspath_count_confeds (new->attr->aspath);
395
396 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000397 return 1;
paulfe69a502005-09-10 16:55:02 +0000398 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000399 return 0;
400 }
401 else
402 {
paulfe69a502005-09-10 16:55:02 +0000403 int newhops = aspath_count_hops (new->attr->aspath);
404
405 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000406 return 1;
paulfe69a502005-09-10 16:55:02 +0000407 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000408 return 0;
409 }
paul718e3742002-12-13 20:15:29 +0000410 }
411
412 /* 5. Origin check. */
413 if (new->attr->origin < exist->attr->origin)
414 return 1;
415 if (new->attr->origin > exist->attr->origin)
416 return 0;
417
418 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000419 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
420 && aspath_count_hops (exist->attr->aspath) == 0);
421 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
422 && aspath_count_confeds (exist->attr->aspath) > 0
423 && aspath_count_hops (new->attr->aspath) == 0
424 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000425
426 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
427 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
428 && confed_as_route)
429 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
430 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
431 || internal_as_route)
432 {
433 new_med = bgp_med_value (new->attr, bgp);
434 exist_med = bgp_med_value (exist->attr, bgp);
435
436 if (new_med < exist_med)
437 return 1;
438 if (new_med > exist_med)
439 return 0;
440 }
441
442 /* 7. Peer type check. */
443 if (peer_sort (new->peer) == BGP_PEER_EBGP
444 && peer_sort (exist->peer) == BGP_PEER_IBGP)
445 return 1;
446 if (peer_sort (new->peer) == BGP_PEER_EBGP
447 && peer_sort (exist->peer) == BGP_PEER_CONFED)
448 return 1;
449 if (peer_sort (new->peer) == BGP_PEER_IBGP
450 && peer_sort (exist->peer) == BGP_PEER_EBGP)
451 return 0;
452 if (peer_sort (new->peer) == BGP_PEER_CONFED
453 && peer_sort (exist->peer) == BGP_PEER_EBGP)
454 return 0;
455
456 /* 8. IGP metric check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000457 if (new->extra || exist->extra)
458 {
459 uint32_t newm = (new->extra ? new->extra->igpmetric : 0);
460 uint32_t existm = (exist->extra ? exist->extra->igpmetric : 0);
461
462 if (newm < existm)
463 return 1;
464 if (newm > existm)
465 return 0;
466 }
paul718e3742002-12-13 20:15:29 +0000467
468 /* 9. Maximum path check. */
469
470 /* 10. If both paths are external, prefer the path that was received
471 first (the oldest one). This step minimizes route-flap, since a
472 newer path won't displace an older one, even if it was the
473 preferred route based on the additional decision criteria below. */
474 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
475 && peer_sort (new->peer) == BGP_PEER_EBGP
476 && peer_sort (exist->peer) == BGP_PEER_EBGP)
477 {
478 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
479 return 1;
480 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
481 return 0;
482 }
483
484 /* 11. Rourter-ID comparision. */
485 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000486 new_id.s_addr = new->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000487 else
488 new_id.s_addr = new->peer->remote_id.s_addr;
489 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000490 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000491 else
492 exist_id.s_addr = exist->peer->remote_id.s_addr;
493
494 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
495 return 1;
496 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
497 return 0;
498
499 /* 12. Cluster length comparision. */
500 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000501 new_cluster = new->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000502 else
503 new_cluster = 0;
504 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000505 exist_cluster = exist->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000506 else
507 exist_cluster = 0;
508
509 if (new_cluster < exist_cluster)
510 return 1;
511 if (new_cluster > exist_cluster)
512 return 0;
513
514 /* 13. Neighbor address comparision. */
515 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
516
517 if (ret == 1)
518 return 0;
519 if (ret == -1)
520 return 1;
521
522 return 1;
523}
524
paul94f2b392005-06-28 12:44:16 +0000525static enum filter_type
paul718e3742002-12-13 20:15:29 +0000526bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
527 afi_t afi, safi_t safi)
528{
529 struct bgp_filter *filter;
530
531 filter = &peer->filter[afi][safi];
532
Paul Jakma650f76c2009-06-25 18:06:31 +0100533#define FILTER_EXIST_WARN(F,f,filter) \
534 if (BGP_DEBUG (update, UPDATE_IN) \
535 && !(F ## _IN (filter))) \
536 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
537 peer->host, #f, F ## _IN_NAME(filter));
538
539 if (DISTRIBUTE_IN_NAME (filter)) {
540 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
541
paul718e3742002-12-13 20:15:29 +0000542 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
543 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100544 }
paul718e3742002-12-13 20:15:29 +0000545
Paul Jakma650f76c2009-06-25 18:06:31 +0100546 if (PREFIX_LIST_IN_NAME (filter)) {
547 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
548
paul718e3742002-12-13 20:15:29 +0000549 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
550 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100551 }
paul718e3742002-12-13 20:15:29 +0000552
Paul Jakma650f76c2009-06-25 18:06:31 +0100553 if (FILTER_LIST_IN_NAME (filter)) {
554 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
555
paul718e3742002-12-13 20:15:29 +0000556 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
557 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100558 }
559
paul718e3742002-12-13 20:15:29 +0000560 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100561#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000562}
563
paul94f2b392005-06-28 12:44:16 +0000564static enum filter_type
paul718e3742002-12-13 20:15:29 +0000565bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
566 afi_t afi, safi_t safi)
567{
568 struct bgp_filter *filter;
569
570 filter = &peer->filter[afi][safi];
571
Paul Jakma650f76c2009-06-25 18:06:31 +0100572#define FILTER_EXIST_WARN(F,f,filter) \
573 if (BGP_DEBUG (update, UPDATE_OUT) \
574 && !(F ## _OUT (filter))) \
575 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
576 peer->host, #f, F ## _OUT_NAME(filter));
577
578 if (DISTRIBUTE_OUT_NAME (filter)) {
579 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
580
paul718e3742002-12-13 20:15:29 +0000581 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
582 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100583 }
paul718e3742002-12-13 20:15:29 +0000584
Paul Jakma650f76c2009-06-25 18:06:31 +0100585 if (PREFIX_LIST_OUT_NAME (filter)) {
586 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
587
paul718e3742002-12-13 20:15:29 +0000588 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
589 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100590 }
paul718e3742002-12-13 20:15:29 +0000591
Paul Jakma650f76c2009-06-25 18:06:31 +0100592 if (FILTER_LIST_OUT_NAME (filter)) {
593 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
594
paul718e3742002-12-13 20:15:29 +0000595 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
596 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100597 }
paul718e3742002-12-13 20:15:29 +0000598
599 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100600#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000601}
602
603/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000604static int
paul718e3742002-12-13 20:15:29 +0000605bgp_community_filter (struct peer *peer, struct attr *attr)
606{
607 if (attr->community)
608 {
609 /* NO_ADVERTISE check. */
610 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
611 return 1;
612
613 /* NO_EXPORT check. */
614 if (peer_sort (peer) == BGP_PEER_EBGP &&
615 community_include (attr->community, COMMUNITY_NO_EXPORT))
616 return 1;
617
618 /* NO_EXPORT_SUBCONFED check. */
619 if (peer_sort (peer) == BGP_PEER_EBGP
620 || peer_sort (peer) == BGP_PEER_CONFED)
621 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
622 return 1;
623 }
624 return 0;
625}
626
627/* Route reflection loop check. */
628static int
629bgp_cluster_filter (struct peer *peer, struct attr *attr)
630{
631 struct in_addr cluster_id;
632
Paul Jakmafb982c22007-05-04 20:15:47 +0000633 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000634 {
635 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
636 cluster_id = peer->bgp->cluster_id;
637 else
638 cluster_id = peer->bgp->router_id;
639
Paul Jakmafb982c22007-05-04 20:15:47 +0000640 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000641 return 1;
642 }
643 return 0;
644}
645
paul94f2b392005-06-28 12:44:16 +0000646static int
paul718e3742002-12-13 20:15:29 +0000647bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
648 afi_t afi, safi_t safi)
649{
650 struct bgp_filter *filter;
651 struct bgp_info info;
652 route_map_result_t ret;
653
654 filter = &peer->filter[afi][safi];
655
656 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000657 if (peer->weight)
658 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000659
660 /* Route map apply. */
661 if (ROUTE_MAP_IN_NAME (filter))
662 {
663 /* Duplicate current value to new strucutre for modification. */
664 info.peer = peer;
665 info.attr = attr;
666
paulac41b2a2003-08-12 05:32:27 +0000667 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
668
paul718e3742002-12-13 20:15:29 +0000669 /* Apply BGP route map to the attribute. */
670 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000671
672 peer->rmap_type = 0;
673
paul718e3742002-12-13 20:15:29 +0000674 if (ret == RMAP_DENYMATCH)
675 {
676 /* Free newly generated AS path and community by route-map. */
677 bgp_attr_flush (attr);
678 return RMAP_DENY;
679 }
680 }
681 return RMAP_PERMIT;
682}
683
paul94f2b392005-06-28 12:44:16 +0000684static int
paulfee0f4c2004-09-13 05:12:46 +0000685bgp_export_modifier (struct peer *rsclient, struct peer *peer,
686 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
687{
688 struct bgp_filter *filter;
689 struct bgp_info info;
690 route_map_result_t ret;
691
692 filter = &peer->filter[afi][safi];
693
694 /* Route map apply. */
695 if (ROUTE_MAP_EXPORT_NAME (filter))
696 {
697 /* Duplicate current value to new strucutre for modification. */
698 info.peer = rsclient;
699 info.attr = attr;
700
701 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
702
703 /* Apply BGP route map to the attribute. */
704 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
705
706 rsclient->rmap_type = 0;
707
708 if (ret == RMAP_DENYMATCH)
709 {
710 /* Free newly generated AS path and community by route-map. */
711 bgp_attr_flush (attr);
712 return RMAP_DENY;
713 }
714 }
715 return RMAP_PERMIT;
716}
717
paul94f2b392005-06-28 12:44:16 +0000718static int
paulfee0f4c2004-09-13 05:12:46 +0000719bgp_import_modifier (struct peer *rsclient, struct peer *peer,
720 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
721{
722 struct bgp_filter *filter;
723 struct bgp_info info;
724 route_map_result_t ret;
725
726 filter = &rsclient->filter[afi][safi];
727
728 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000729 if (peer->weight)
730 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000731
732 /* Route map apply. */
733 if (ROUTE_MAP_IMPORT_NAME (filter))
734 {
735 /* Duplicate current value to new strucutre for modification. */
736 info.peer = peer;
737 info.attr = attr;
738
739 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
740
741 /* Apply BGP route map to the attribute. */
742 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
743
744 peer->rmap_type = 0;
745
746 if (ret == RMAP_DENYMATCH)
747 {
748 /* Free newly generated AS path and community by route-map. */
749 bgp_attr_flush (attr);
750 return RMAP_DENY;
751 }
752 }
753 return RMAP_PERMIT;
754}
755
paul94f2b392005-06-28 12:44:16 +0000756static int
paul718e3742002-12-13 20:15:29 +0000757bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
758 struct attr *attr, afi_t afi, safi_t safi)
759{
760 int ret;
761 char buf[SU_ADDRSTRLEN];
762 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000763 struct peer *from;
764 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000765 int transparent;
766 int reflect;
767
768 from = ri->peer;
769 filter = &peer->filter[afi][safi];
770 bgp = peer->bgp;
771
Paul Jakma750e8142008-07-22 21:11:48 +0000772 if (DISABLE_BGP_ANNOUNCE)
773 return 0;
paul718e3742002-12-13 20:15:29 +0000774
paulfee0f4c2004-09-13 05:12:46 +0000775 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
776 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
777 return 0;
778
paul718e3742002-12-13 20:15:29 +0000779 /* Do not send back route to sender. */
780 if (from == peer)
781 return 0;
782
paul35be31b2004-05-01 18:17:04 +0000783 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
784 if (p->family == AF_INET
785 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
786 return 0;
787#ifdef HAVE_IPV6
788 if (p->family == AF_INET6
789 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
790 return 0;
791#endif
792
paul718e3742002-12-13 20:15:29 +0000793 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000794 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000795 if (! UNSUPPRESS_MAP_NAME (filter))
796 return 0;
797
798 /* Default route check. */
799 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
800 {
801 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
802 return 0;
803#ifdef HAVE_IPV6
804 else if (p->family == AF_INET6 && p->prefixlen == 0)
805 return 0;
806#endif /* HAVE_IPV6 */
807 }
808
paul286e1e72003-08-08 00:24:31 +0000809 /* Transparency check. */
810 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
811 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
812 transparent = 1;
813 else
814 transparent = 0;
815
paul718e3742002-12-13 20:15:29 +0000816 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000817 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000818 return 0;
819
820 /* If the attribute has originator-id and it is same as remote
821 peer's id. */
822 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
823 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000824 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000825 {
826 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000827 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000828 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
829 peer->host,
830 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
831 p->prefixlen);
832 return 0;
833 }
834 }
835
836 /* ORF prefix-list filter check */
837 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
838 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
839 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
840 if (peer->orf_plist[afi][safi])
841 {
842 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
843 return 0;
844 }
845
846 /* Output filter check. */
847 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
848 {
849 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000850 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000851 "%s [Update:SEND] %s/%d is filtered",
852 peer->host,
853 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
854 p->prefixlen);
855 return 0;
856 }
857
858#ifdef BGP_SEND_ASPATH_CHECK
859 /* AS path loop check. */
860 if (aspath_loop_check (ri->attr->aspath, peer->as))
861 {
862 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000863 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400864 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000865 peer->host, peer->as);
866 return 0;
867 }
868#endif /* BGP_SEND_ASPATH_CHECK */
869
870 /* If we're a CONFED we need to loop check the CONFED ID too */
871 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
872 {
873 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
874 {
875 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000876 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400877 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000878 peer->host,
879 bgp->confed_id);
880 return 0;
881 }
882 }
883
884 /* Route-Reflect check. */
885 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
886 reflect = 1;
887 else
888 reflect = 0;
889
890 /* IBGP reflection check. */
891 if (reflect)
892 {
893 /* A route from a Client peer. */
894 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
895 {
896 /* Reflect to all the Non-Client peers and also to the
897 Client peers other than the originator. Originator check
898 is already done. So there is noting to do. */
899 /* no bgp client-to-client reflection check. */
900 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
901 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
902 return 0;
903 }
904 else
905 {
906 /* A route from a Non-client peer. Reflect to all other
907 clients. */
908 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
909 return 0;
910 }
911 }
Paul Jakma41367172007-08-06 15:24:51 +0000912
paul718e3742002-12-13 20:15:29 +0000913 /* For modify attribute, copy it to temporary structure. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000914 bgp_attr_dup (attr, ri->attr);
915
paul718e3742002-12-13 20:15:29 +0000916 /* If local-preference is not set. */
917 if ((peer_sort (peer) == BGP_PEER_IBGP
918 || peer_sort (peer) == BGP_PEER_CONFED)
919 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
920 {
921 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
922 attr->local_pref = bgp->default_local_pref;
923 }
924
paul718e3742002-12-13 20:15:29 +0000925 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
926 if (peer_sort (peer) == BGP_PEER_EBGP
927 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
928 {
929 if (ri->peer != bgp->peer_self && ! transparent
930 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
931 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
932 }
933
934 /* next-hop-set */
935 if (transparent || reflect
936 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
937 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000938#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000939 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000940 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000941#endif /* HAVE_IPV6 */
942 )))
paul718e3742002-12-13 20:15:29 +0000943 {
944 /* NEXT-HOP Unchanged. */
945 }
946 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
947 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
948#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000949 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000950 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000951#endif /* HAVE_IPV6 */
952 || (peer_sort (peer) == BGP_PEER_EBGP
953 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
954 {
955 /* Set IPv4 nexthop. */
956 if (p->family == AF_INET)
957 {
958 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000959 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
960 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000961 else
962 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
963 }
964#ifdef HAVE_IPV6
965 /* Set IPv6 nexthop. */
966 if (p->family == AF_INET6)
967 {
968 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000969 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000970 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000971 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000972 }
973#endif /* HAVE_IPV6 */
974 }
975
976#ifdef HAVE_IPV6
977 if (p->family == AF_INET6)
978 {
paulfee0f4c2004-09-13 05:12:46 +0000979 /* Left nexthop_local unchanged if so configured. */
980 if ( CHECK_FLAG (peer->af_flags[afi][safi],
981 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
982 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000983 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
984 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +0000985 else
Paul Jakmafb982c22007-05-04 20:15:47 +0000986 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +0000987 }
988
989 /* Default nexthop_local treatment for non-RS-Clients */
990 else
991 {
paul718e3742002-12-13 20:15:29 +0000992 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000993 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000994
995 /* Set link-local address for shared network peer. */
996 if (peer->shared_network
997 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
998 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000999 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001000 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001001 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001002 }
1003
1004 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1005 address.*/
1006 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001007 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001008
1009 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1010 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001011 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001012 }
paulfee0f4c2004-09-13 05:12:46 +00001013
1014 }
paul718e3742002-12-13 20:15:29 +00001015#endif /* HAVE_IPV6 */
1016
1017 /* If this is EBGP peer and remove-private-AS is set. */
1018 if (peer_sort (peer) == BGP_PEER_EBGP
1019 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1020 && aspath_private_as_check (attr->aspath))
1021 attr->aspath = aspath_empty_get ();
1022
1023 /* Route map & unsuppress-map apply. */
1024 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001025 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001026 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001027 struct bgp_info info;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001028 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001029
paul718e3742002-12-13 20:15:29 +00001030 info.peer = peer;
1031 info.attr = attr;
1032
1033 /* The route reflector is not allowed to modify the attributes
1034 of the reflected IBGP routes. */
1035 if (peer_sort (from) == BGP_PEER_IBGP
1036 && peer_sort (peer) == BGP_PEER_IBGP)
1037 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001038 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001039 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001040 }
paulac41b2a2003-08-12 05:32:27 +00001041
1042 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1043
Paul Jakmafb982c22007-05-04 20:15:47 +00001044 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001045 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1046 else
1047 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1048
paulac41b2a2003-08-12 05:32:27 +00001049 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001050
Paul Jakma9eda90c2007-08-30 13:36:17 +00001051 if (dummy_attr.extra)
1052 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001053
paul718e3742002-12-13 20:15:29 +00001054 if (ret == RMAP_DENYMATCH)
1055 {
1056 bgp_attr_flush (attr);
1057 return 0;
1058 }
1059 }
1060 return 1;
1061}
1062
paul94f2b392005-06-28 12:44:16 +00001063static int
paulfee0f4c2004-09-13 05:12:46 +00001064bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1065 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001066{
paulfee0f4c2004-09-13 05:12:46 +00001067 int ret;
1068 char buf[SU_ADDRSTRLEN];
1069 struct bgp_filter *filter;
1070 struct bgp_info info;
1071 struct peer *from;
1072 struct bgp *bgp;
1073
1074 from = ri->peer;
1075 filter = &rsclient->filter[afi][safi];
1076 bgp = rsclient->bgp;
1077
Paul Jakma750e8142008-07-22 21:11:48 +00001078 if (DISABLE_BGP_ANNOUNCE)
1079 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001080
1081 /* Do not send back route to sender. */
1082 if (from == rsclient)
1083 return 0;
1084
1085 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001086 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001087 if (! UNSUPPRESS_MAP_NAME (filter))
1088 return 0;
1089
1090 /* Default route check. */
1091 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1092 PEER_STATUS_DEFAULT_ORIGINATE))
1093 {
1094 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1095 return 0;
1096#ifdef HAVE_IPV6
1097 else if (p->family == AF_INET6 && p->prefixlen == 0)
1098 return 0;
1099#endif /* HAVE_IPV6 */
1100 }
1101
1102 /* If the attribute has originator-id and it is same as remote
1103 peer's id. */
1104 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1105 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001106 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1107 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001108 {
1109 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001110 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001111 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1112 rsclient->host,
1113 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1114 p->prefixlen);
1115 return 0;
1116 }
1117 }
1118
1119 /* ORF prefix-list filter check */
1120 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1121 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1122 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1123 if (rsclient->orf_plist[afi][safi])
1124 {
1125 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1126 return 0;
1127 }
1128
1129 /* Output filter check. */
1130 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1131 {
1132 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001133 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001134 "%s [Update:SEND] %s/%d is filtered",
1135 rsclient->host,
1136 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1137 p->prefixlen);
1138 return 0;
1139 }
1140
1141#ifdef BGP_SEND_ASPATH_CHECK
1142 /* AS path loop check. */
1143 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1144 {
1145 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001146 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001147 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001148 rsclient->host, rsclient->as);
1149 return 0;
1150 }
1151#endif /* BGP_SEND_ASPATH_CHECK */
1152
1153 /* For modify attribute, copy it to temporary structure. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001154 bgp_attr_dup (attr, ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001155
1156 /* next-hop-set */
1157 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1158#ifdef HAVE_IPV6
1159 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001160 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001161#endif /* HAVE_IPV6 */
1162 )
1163 {
1164 /* Set IPv4 nexthop. */
1165 if (p->family == AF_INET)
1166 {
1167 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001168 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001169 IPV4_MAX_BYTELEN);
1170 else
1171 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1172 }
1173#ifdef HAVE_IPV6
1174 /* Set IPv6 nexthop. */
1175 if (p->family == AF_INET6)
1176 {
1177 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001178 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001179 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001180 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001181 }
1182#endif /* HAVE_IPV6 */
1183 }
1184
1185#ifdef HAVE_IPV6
1186 if (p->family == AF_INET6)
1187 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001188 struct attr_extra *attre = attr->extra;
1189
1190 assert (attr->extra);
1191
paulfee0f4c2004-09-13 05:12:46 +00001192 /* Left nexthop_local unchanged if so configured. */
1193 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1194 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1195 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001196 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1197 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001198 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001199 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001200 }
1201
1202 /* Default nexthop_local treatment for RS-Clients */
1203 else
1204 {
1205 /* Announcer and RS-Client are both in the same network */
1206 if (rsclient->shared_network && from->shared_network &&
1207 (rsclient->ifindex == from->ifindex))
1208 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001209 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1210 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001211 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001212 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001213 }
1214
1215 /* Set link-local address for shared network peer. */
1216 else if (rsclient->shared_network
1217 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1218 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001219 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001220 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001221 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001222 }
1223
1224 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001225 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001226 }
1227
1228 }
1229#endif /* HAVE_IPV6 */
1230
1231
1232 /* If this is EBGP peer and remove-private-AS is set. */
1233 if (peer_sort (rsclient) == BGP_PEER_EBGP
1234 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1235 && aspath_private_as_check (attr->aspath))
1236 attr->aspath = aspath_empty_get ();
1237
1238 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001239 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001240 {
1241 info.peer = rsclient;
1242 info.attr = attr;
1243
1244 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1245
Paul Jakmafb982c22007-05-04 20:15:47 +00001246 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001247 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1248 else
1249 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1250
1251 rsclient->rmap_type = 0;
1252
1253 if (ret == RMAP_DENYMATCH)
1254 {
1255 bgp_attr_flush (attr);
1256 return 0;
1257 }
1258 }
1259
1260 return 1;
1261}
1262
1263struct bgp_info_pair
1264{
1265 struct bgp_info *old;
1266 struct bgp_info *new;
1267};
1268
paul94f2b392005-06-28 12:44:16 +00001269static void
paulfee0f4c2004-09-13 05:12:46 +00001270bgp_best_selection (struct bgp *bgp, struct bgp_node *rn, struct bgp_info_pair *result)
1271{
paul718e3742002-12-13 20:15:29 +00001272 struct bgp_info *new_select;
1273 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001274 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001275 struct bgp_info *ri1;
1276 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001277 struct bgp_info *nextri = NULL;
1278
paul718e3742002-12-13 20:15:29 +00001279 /* bgp deterministic-med */
1280 new_select = NULL;
1281 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1282 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1283 {
1284 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1285 continue;
1286 if (BGP_INFO_HOLDDOWN (ri1))
1287 continue;
1288
1289 new_select = ri1;
1290 if (ri1->next)
1291 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1292 {
1293 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1294 continue;
1295 if (BGP_INFO_HOLDDOWN (ri2))
1296 continue;
1297
1298 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1299 || aspath_cmp_left_confed (ri1->attr->aspath,
1300 ri2->attr->aspath))
1301 {
1302 if (bgp_info_cmp (bgp, ri2, new_select))
1303 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001304 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001305 new_select = ri2;
1306 }
1307
Paul Jakma1a392d42006-09-07 00:24:49 +00001308 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001309 }
1310 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001311 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1312 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001313 }
1314
1315 /* Check old selected route and new selected route. */
1316 old_select = NULL;
1317 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001318 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001319 {
1320 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1321 old_select = ri;
1322
1323 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001324 {
1325 /* reap REMOVED routes, if needs be
1326 * selected route must stay for a while longer though
1327 */
1328 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1329 && (ri != old_select))
1330 bgp_info_reap (rn, ri);
1331
1332 continue;
1333 }
paul718e3742002-12-13 20:15:29 +00001334
1335 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1336 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1337 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001338 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001339 continue;
1340 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001341 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1342 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001343
1344 if (bgp_info_cmp (bgp, ri, new_select))
1345 new_select = ri;
1346 }
paulb40d9392005-08-22 22:34:41 +00001347
paulfee0f4c2004-09-13 05:12:46 +00001348 result->old = old_select;
1349 result->new = new_select;
1350
1351 return;
1352}
1353
paul94f2b392005-06-28 12:44:16 +00001354static int
paulfee0f4c2004-09-13 05:12:46 +00001355bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001356 struct bgp_node *rn, afi_t afi, safi_t safi)
1357{
paulfee0f4c2004-09-13 05:12:46 +00001358 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001359 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001360
1361 p = &rn->p;
1362
Paul Jakma9eda90c2007-08-30 13:36:17 +00001363 /* Announce route to Established peer. */
1364 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001365 return 0;
1366
Paul Jakma9eda90c2007-08-30 13:36:17 +00001367 /* Address family configuration check. */
1368 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001369 return 0;
1370
Paul Jakma9eda90c2007-08-30 13:36:17 +00001371 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001372 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1373 PEER_STATUS_ORF_WAIT_REFRESH))
1374 return 0;
1375
1376 switch (rn->table->type)
1377 {
1378 case BGP_TABLE_MAIN:
1379 /* Announcement to peer->conf. If the route is filtered,
1380 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001381 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1382 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001383 else
1384 bgp_adj_out_unset (rn, peer, p, afi, safi);
1385 break;
1386 case BGP_TABLE_RSCLIENT:
1387 /* Announcement to peer->conf. If the route is filtered,
1388 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001389 if (selected &&
1390 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1391 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1392 else
1393 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001394 break;
1395 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001396
1397 bgp_attr_extra_free (&attr);
1398
paulfee0f4c2004-09-13 05:12:46 +00001399 return 0;
paul200df112005-06-01 11:17:05 +00001400}
paulfee0f4c2004-09-13 05:12:46 +00001401
paul200df112005-06-01 11:17:05 +00001402struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001403{
paul200df112005-06-01 11:17:05 +00001404 struct bgp *bgp;
1405 struct bgp_node *rn;
1406 afi_t afi;
1407 safi_t safi;
1408};
1409
1410static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001411bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001412{
paul0fb58d52005-11-14 14:31:49 +00001413 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001414 struct bgp *bgp = pq->bgp;
1415 struct bgp_node *rn = pq->rn;
1416 afi_t afi = pq->afi;
1417 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001418 struct bgp_info *new_select;
1419 struct bgp_info *old_select;
1420 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001421 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001422 struct peer *rsclient = rn->table->owner;
1423
paulfee0f4c2004-09-13 05:12:46 +00001424 /* Best path selection. */
1425 bgp_best_selection (bgp, rn, &old_and_new);
1426 new_select = old_and_new.new;
1427 old_select = old_and_new.old;
1428
paul200df112005-06-01 11:17:05 +00001429 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1430 {
Chris Caputo228da422009-07-18 05:44:03 +00001431 if (rsclient->group)
1432 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1433 {
1434 /* Nothing to do. */
1435 if (old_select && old_select == new_select)
1436 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1437 continue;
paulfee0f4c2004-09-13 05:12:46 +00001438
Chris Caputo228da422009-07-18 05:44:03 +00001439 if (old_select)
1440 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1441 if (new_select)
1442 {
1443 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1444 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
1445 }
paulfee0f4c2004-09-13 05:12:46 +00001446
Chris Caputo228da422009-07-18 05:44:03 +00001447 bgp_process_announce_selected (rsclient, new_select, rn,
1448 afi, safi);
1449 }
paul200df112005-06-01 11:17:05 +00001450 }
1451 else
1452 {
hassob7395792005-08-26 12:58:38 +00001453 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001454 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001455 if (new_select)
1456 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001457 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1458 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001459 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001460 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001461 }
paulfee0f4c2004-09-13 05:12:46 +00001462
paulb40d9392005-08-22 22:34:41 +00001463 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1464 bgp_info_reap (rn, old_select);
1465
paul200df112005-06-01 11:17:05 +00001466 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1467 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001468}
1469
paul200df112005-06-01 11:17:05 +00001470static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001471bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001472{
paul0fb58d52005-11-14 14:31:49 +00001473 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001474 struct bgp *bgp = pq->bgp;
1475 struct bgp_node *rn = pq->rn;
1476 afi_t afi = pq->afi;
1477 safi_t safi = pq->safi;
1478 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001479 struct bgp_info *new_select;
1480 struct bgp_info *old_select;
1481 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001482 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001483 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001484
paulfee0f4c2004-09-13 05:12:46 +00001485 /* Best path selection. */
1486 bgp_best_selection (bgp, rn, &old_and_new);
1487 old_select = old_and_new.old;
1488 new_select = old_and_new.new;
1489
1490 /* Nothing to do. */
1491 if (old_select && old_select == new_select)
1492 {
1493 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001494 {
1495 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1496 bgp_zebra_announce (p, old_select, bgp);
1497
1498 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1499 return WQ_SUCCESS;
1500 }
paulfee0f4c2004-09-13 05:12:46 +00001501 }
paul718e3742002-12-13 20:15:29 +00001502
hasso338b3422005-02-23 14:27:24 +00001503 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001504 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001505 if (new_select)
1506 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001507 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1508 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001509 }
1510
1511
paul718e3742002-12-13 20:15:29 +00001512 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001513 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001514 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001515 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001516 }
1517
1518 /* FIB update. */
1519 if (safi == SAFI_UNICAST && ! bgp->name &&
1520 ! bgp_option_check (BGP_OPT_NO_FIB))
1521 {
1522 if (new_select
1523 && new_select->type == ZEBRA_ROUTE_BGP
1524 && new_select->sub_type == BGP_ROUTE_NORMAL)
1525 bgp_zebra_announce (p, new_select, bgp);
1526 else
1527 {
1528 /* Withdraw the route from the kernel. */
1529 if (old_select
1530 && old_select->type == ZEBRA_ROUTE_BGP
1531 && old_select->sub_type == BGP_ROUTE_NORMAL)
1532 bgp_zebra_withdraw (p, old_select);
1533 }
1534 }
paulb40d9392005-08-22 22:34:41 +00001535
1536 /* Reap old select bgp_info, it it has been removed */
1537 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1538 bgp_info_reap (rn, old_select);
1539
paul200df112005-06-01 11:17:05 +00001540 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1541 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001542}
1543
paul200df112005-06-01 11:17:05 +00001544static void
paul0fb58d52005-11-14 14:31:49 +00001545bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001546{
paul0fb58d52005-11-14 14:31:49 +00001547 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001548 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001549
Chris Caputo228da422009-07-18 05:44:03 +00001550 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001551 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001552 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001553 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1554}
1555
1556static void
1557bgp_process_queue_init (void)
1558{
1559 bm->process_main_queue
1560 = work_queue_new (bm->master, "process_main_queue");
1561 bm->process_rsclient_queue
1562 = work_queue_new (bm->master, "process_rsclient_queue");
1563
1564 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1565 {
1566 zlog_err ("%s: Failed to allocate work queue", __func__);
1567 exit (1);
1568 }
1569
1570 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001571 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001572 bm->process_main_queue->spec.max_retries = 0;
1573 bm->process_main_queue->spec.hold = 50;
1574
1575 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1576 sizeof (struct work_queue *));
1577 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001578}
1579
1580void
paulfee0f4c2004-09-13 05:12:46 +00001581bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1582{
paul200df112005-06-01 11:17:05 +00001583 struct bgp_process_queue *pqnode;
1584
1585 /* already scheduled for processing? */
1586 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1587 return;
1588
1589 if ( (bm->process_main_queue == NULL) ||
1590 (bm->process_rsclient_queue == NULL) )
1591 bgp_process_queue_init ();
1592
1593 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1594 sizeof (struct bgp_process_queue));
1595 if (!pqnode)
1596 return;
Chris Caputo228da422009-07-18 05:44:03 +00001597
1598 /* all unlocked in bgp_processq_del */
1599 bgp_table_lock (rn->table);
1600 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001601 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001602 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001603 pqnode->afi = afi;
1604 pqnode->safi = safi;
1605
paulfee0f4c2004-09-13 05:12:46 +00001606 switch (rn->table->type)
1607 {
paul200df112005-06-01 11:17:05 +00001608 case BGP_TABLE_MAIN:
1609 work_queue_add (bm->process_main_queue, pqnode);
1610 break;
1611 case BGP_TABLE_RSCLIENT:
1612 work_queue_add (bm->process_rsclient_queue, pqnode);
1613 break;
paulfee0f4c2004-09-13 05:12:46 +00001614 }
paul200df112005-06-01 11:17:05 +00001615
1616 return;
paulfee0f4c2004-09-13 05:12:46 +00001617}
hasso0a486e52005-02-01 20:57:17 +00001618
paul94f2b392005-06-28 12:44:16 +00001619static int
hasso0a486e52005-02-01 20:57:17 +00001620bgp_maximum_prefix_restart_timer (struct thread *thread)
1621{
1622 struct peer *peer;
1623
1624 peer = THREAD_ARG (thread);
1625 peer->t_pmax_restart = NULL;
1626
1627 if (BGP_DEBUG (events, EVENTS))
1628 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1629 peer->host);
1630
1631 peer_clear (peer);
1632
1633 return 0;
1634}
1635
paulfee0f4c2004-09-13 05:12:46 +00001636int
paul5228ad22004-06-04 17:58:18 +00001637bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1638 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001639{
hassoe0701b72004-05-20 09:19:34 +00001640 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1641 return 0;
1642
1643 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001644 {
hassoe0701b72004-05-20 09:19:34 +00001645 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1646 && ! always)
1647 return 0;
paul718e3742002-12-13 20:15:29 +00001648
hassoe0701b72004-05-20 09:19:34 +00001649 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001650 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1651 "limit %ld", afi_safi_print (afi, safi), peer->host,
1652 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001653 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001654
hassoe0701b72004-05-20 09:19:34 +00001655 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1656 return 0;
paul718e3742002-12-13 20:15:29 +00001657
hassoe0701b72004-05-20 09:19:34 +00001658 {
paul5228ad22004-06-04 17:58:18 +00001659 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001660
1661 if (safi == SAFI_MPLS_VPN)
1662 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001663
1664 ndata[0] = (afi >> 8);
1665 ndata[1] = afi;
1666 ndata[2] = safi;
1667 ndata[3] = (peer->pmax[afi][safi] >> 24);
1668 ndata[4] = (peer->pmax[afi][safi] >> 16);
1669 ndata[5] = (peer->pmax[afi][safi] >> 8);
1670 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001671
1672 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1673 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1674 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1675 }
hasso0a486e52005-02-01 20:57:17 +00001676
1677 /* restart timer start */
1678 if (peer->pmax_restart[afi][safi])
1679 {
1680 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1681
1682 if (BGP_DEBUG (events, EVENTS))
1683 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1684 peer->host, peer->v_pmax_restart);
1685
1686 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1687 peer->v_pmax_restart);
1688 }
1689
hassoe0701b72004-05-20 09:19:34 +00001690 return 1;
paul718e3742002-12-13 20:15:29 +00001691 }
hassoe0701b72004-05-20 09:19:34 +00001692 else
1693 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1694
1695 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1696 {
1697 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1698 && ! always)
1699 return 0;
1700
1701 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001702 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1703 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1704 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001705 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1706 }
1707 else
1708 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001709 return 0;
1710}
1711
paulb40d9392005-08-22 22:34:41 +00001712/* Unconditionally remove the route from the RIB, without taking
1713 * damping into consideration (eg, because the session went down)
1714 */
paul94f2b392005-06-28 12:44:16 +00001715static void
paul718e3742002-12-13 20:15:29 +00001716bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1717 afi_t afi, safi_t safi)
1718{
paul902212c2006-02-05 17:51:19 +00001719 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1720
1721 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1722 bgp_info_delete (rn, ri); /* keep historical info */
1723
paulb40d9392005-08-22 22:34:41 +00001724 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001725}
1726
paul94f2b392005-06-28 12:44:16 +00001727static void
paul718e3742002-12-13 20:15:29 +00001728bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001729 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001730{
paul718e3742002-12-13 20:15:29 +00001731 int status = BGP_DAMP_NONE;
1732
paulb40d9392005-08-22 22:34:41 +00001733 /* apply dampening, if result is suppressed, we'll be retaining
1734 * the bgp_info in the RIB for historical reference.
1735 */
1736 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1737 && peer_sort (peer) == BGP_PEER_EBGP)
1738 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1739 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001740 {
paul902212c2006-02-05 17:51:19 +00001741 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1742 return;
1743 }
1744
1745 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001746}
1747
paul94f2b392005-06-28 12:44:16 +00001748static void
paulfee0f4c2004-09-13 05:12:46 +00001749bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1750 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1751 int sub_type, struct prefix_rd *prd, u_char *tag)
1752{
1753 struct bgp_node *rn;
1754 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001755 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001756 struct attr *attr_new;
1757 struct attr *attr_new2;
1758 struct bgp_info *ri;
1759 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001760 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001761 char buf[SU_ADDRSTRLEN];
1762
1763 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1764 if (peer == rsclient)
1765 return;
1766
1767 bgp = peer->bgp;
1768 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1769
1770 /* Check previously received route. */
1771 for (ri = rn->info; ri; ri = ri->next)
1772 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1773 break;
1774
1775 /* AS path loop check. */
1776 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1777 {
1778 reason = "as-path contains our own AS;";
1779 goto filtered;
1780 }
1781
1782 /* Route reflector originator ID check. */
1783 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001784 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001785 {
1786 reason = "originator is us;";
1787 goto filtered;
1788 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001789
1790 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001791
1792 /* Apply export policy. */
1793 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1794 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1795 {
1796 reason = "export-policy;";
1797 goto filtered;
1798 }
1799
1800 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001801
paulfee0f4c2004-09-13 05:12:46 +00001802 /* Apply import policy. */
1803 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1804 {
1805 bgp_attr_unintern (attr_new2);
1806
1807 reason = "import-policy;";
1808 goto filtered;
1809 }
1810
1811 attr_new = bgp_attr_intern (&new_attr);
1812 bgp_attr_unintern (attr_new2);
1813
1814 /* IPv4 unicast next hop check. */
1815 if (afi == AFI_IP && safi == SAFI_UNICAST)
1816 {
1817 /* Next hop must not be 0.0.0.0 nor Class E address. */
1818 if (new_attr.nexthop.s_addr == 0
1819 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1820 {
1821 bgp_attr_unintern (attr_new);
1822
1823 reason = "martian next-hop;";
1824 goto filtered;
1825 }
1826 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001827
1828 /* new_attr isn't passed to any functions after here */
1829 bgp_attr_extra_free (&new_attr);
1830
paulfee0f4c2004-09-13 05:12:46 +00001831 /* If the update is implicit withdraw. */
1832 if (ri)
1833 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001834 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001835
1836 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001837 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1838 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001839 {
1840
Paul Jakma1a392d42006-09-07 00:24:49 +00001841 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001842
1843 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001844 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001845 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1846 peer->host,
1847 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1848 p->prefixlen, rsclient->host);
1849
Chris Caputo228da422009-07-18 05:44:03 +00001850 bgp_unlock_node (rn);
1851 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001852
Chris Caputo228da422009-07-18 05:44:03 +00001853 return;
paulfee0f4c2004-09-13 05:12:46 +00001854 }
1855
Paul Jakma16d2e242007-04-10 19:32:10 +00001856 /* Withdraw/Announce before we fully processed the withdraw */
1857 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1858 bgp_info_restore (rn, ri);
1859
paulfee0f4c2004-09-13 05:12:46 +00001860 /* Received Logging. */
1861 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001862 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001863 peer->host,
1864 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1865 p->prefixlen, rsclient->host);
1866
1867 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001868 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001869
1870 /* Update to new attribute. */
1871 bgp_attr_unintern (ri->attr);
1872 ri->attr = attr_new;
1873
1874 /* Update MPLS tag. */
1875 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001876 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001877
Paul Jakma1a392d42006-09-07 00:24:49 +00001878 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001879
1880 /* Process change. */
1881 bgp_process (bgp, rn, afi, safi);
1882 bgp_unlock_node (rn);
1883
1884 return;
1885 }
1886
1887 /* Received Logging. */
1888 if (BGP_DEBUG (update, UPDATE_IN))
1889 {
ajsd2c1f162004-12-08 21:10:20 +00001890 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001891 peer->host,
1892 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1893 p->prefixlen, rsclient->host);
1894 }
1895
1896 /* Make new BGP info. */
1897 new = bgp_info_new ();
1898 new->type = type;
1899 new->sub_type = sub_type;
1900 new->peer = peer;
1901 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001902 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001903
1904 /* Update MPLS tag. */
1905 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001906 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001907
Paul Jakma1a392d42006-09-07 00:24:49 +00001908 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001909
1910 /* Register new BGP information. */
1911 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001912
1913 /* route_node_get lock */
1914 bgp_unlock_node (rn);
1915
paulfee0f4c2004-09-13 05:12:46 +00001916 /* Process change. */
1917 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001918
1919 bgp_attr_extra_free (&new_attr);
1920
paulfee0f4c2004-09-13 05:12:46 +00001921 return;
1922
1923 filtered:
1924
1925 /* This BGP update is filtered. Log the reason then update BGP entry. */
1926 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001927 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001928 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1929 peer->host,
1930 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1931 p->prefixlen, rsclient->host, reason);
1932
1933 if (ri)
paulb40d9392005-08-22 22:34:41 +00001934 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001935
1936 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001937
1938 if (new_attr.extra)
1939 bgp_attr_extra_free (&new_attr);
1940
paulfee0f4c2004-09-13 05:12:46 +00001941 return;
1942}
1943
paul94f2b392005-06-28 12:44:16 +00001944static void
paulfee0f4c2004-09-13 05:12:46 +00001945bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1946 struct peer *peer, struct prefix *p, int type, int sub_type,
1947 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00001948{
paulfee0f4c2004-09-13 05:12:46 +00001949 struct bgp_node *rn;
1950 struct bgp_info *ri;
1951 char buf[SU_ADDRSTRLEN];
1952
1953 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00001954 return;
paulfee0f4c2004-09-13 05:12:46 +00001955
1956 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1957
1958 /* Lookup withdrawn route. */
1959 for (ri = rn->info; ri; ri = ri->next)
1960 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1961 break;
1962
1963 /* Withdraw specified route from routing table. */
1964 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001965 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001966 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001967 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001968 "%s Can't find the route %s/%d", peer->host,
1969 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1970 p->prefixlen);
1971
1972 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00001973 bgp_unlock_node (rn);
1974}
paulfee0f4c2004-09-13 05:12:46 +00001975
paul94f2b392005-06-28 12:44:16 +00001976static int
paulfee0f4c2004-09-13 05:12:46 +00001977bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001978 afi_t afi, safi_t safi, int type, int sub_type,
1979 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1980{
1981 int ret;
1982 int aspath_loop_count = 0;
1983 struct bgp_node *rn;
1984 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001985 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00001986 struct attr *attr_new;
1987 struct bgp_info *ri;
1988 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001989 const char *reason;
paul718e3742002-12-13 20:15:29 +00001990 char buf[SU_ADDRSTRLEN];
1991
1992 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001993 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00001994
paul718e3742002-12-13 20:15:29 +00001995 /* When peer's soft reconfiguration enabled. Record input packet in
1996 Adj-RIBs-In. */
1997 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1998 && peer != bgp->peer_self && ! soft_reconfig)
1999 bgp_adj_in_set (rn, peer, attr);
2000
2001 /* Check previously received route. */
2002 for (ri = rn->info; ri; ri = ri->next)
2003 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2004 break;
2005
2006 /* AS path local-as loop check. */
2007 if (peer->change_local_as)
2008 {
2009 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2010 aspath_loop_count = 1;
2011
2012 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2013 {
2014 reason = "as-path contains our own AS;";
2015 goto filtered;
2016 }
2017 }
2018
2019 /* AS path loop check. */
2020 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2021 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2022 && aspath_loop_check(attr->aspath, bgp->confed_id)
2023 > peer->allowas_in[afi][safi]))
2024 {
2025 reason = "as-path contains our own AS;";
2026 goto filtered;
2027 }
2028
2029 /* Route reflector originator ID check. */
2030 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002031 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002032 {
2033 reason = "originator is us;";
2034 goto filtered;
2035 }
2036
2037 /* Route reflector cluster ID check. */
2038 if (bgp_cluster_filter (peer, attr))
2039 {
2040 reason = "reflected from the same cluster;";
2041 goto filtered;
2042 }
2043
2044 /* Apply incoming filter. */
2045 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2046 {
2047 reason = "filter;";
2048 goto filtered;
2049 }
2050
2051 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002052 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002053
2054 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2055 {
2056 reason = "route-map;";
2057 goto filtered;
2058 }
2059
2060 /* IPv4 unicast next hop check. */
2061 if (afi == AFI_IP && safi == SAFI_UNICAST)
2062 {
2063 /* If the peer is EBGP and nexthop is not on connected route,
2064 discard it. */
2065 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2066 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002067 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002068 {
2069 reason = "non-connected next-hop;";
2070 goto filtered;
2071 }
2072
2073 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2074 must not be my own address. */
2075 if (bgp_nexthop_self (afi, &new_attr)
2076 || new_attr.nexthop.s_addr == 0
2077 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2078 {
2079 reason = "martian next-hop;";
2080 goto filtered;
2081 }
2082 }
2083
2084 attr_new = bgp_attr_intern (&new_attr);
2085
2086 /* If the update is implicit withdraw. */
2087 if (ri)
2088 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002089 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002090
2091 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002092 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2093 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002094 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002095 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002096
2097 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2098 && peer_sort (peer) == BGP_PEER_EBGP
2099 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2100 {
2101 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002102 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002103 peer->host,
2104 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2105 p->prefixlen);
2106
paul902212c2006-02-05 17:51:19 +00002107 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2108 {
2109 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2110 bgp_process (bgp, rn, afi, safi);
2111 }
paul718e3742002-12-13 20:15:29 +00002112 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002113 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002114 {
2115 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002116 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002117 "%s rcvd %s/%d...duplicate ignored",
2118 peer->host,
2119 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2120 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002121
2122 /* graceful restart STALE flag unset. */
2123 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2124 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002125 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002126 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002127 }
paul718e3742002-12-13 20:15:29 +00002128 }
2129
2130 bgp_unlock_node (rn);
2131 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002132 bgp_attr_extra_free (&new_attr);
2133
paul718e3742002-12-13 20:15:29 +00002134 return 0;
2135 }
2136
Paul Jakma16d2e242007-04-10 19:32:10 +00002137 /* Withdraw/Announce before we fully processed the withdraw */
2138 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2139 {
2140 if (BGP_DEBUG (update, UPDATE_IN))
2141 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2142 peer->host,
2143 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2144 p->prefixlen);
2145 bgp_info_restore (rn, ri);
2146 }
2147
paul718e3742002-12-13 20:15:29 +00002148 /* Received Logging. */
2149 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002150 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002151 peer->host,
2152 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2153 p->prefixlen);
2154
hasso93406d82005-02-02 14:40:33 +00002155 /* graceful restart STALE flag unset. */
2156 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002157 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002158
paul718e3742002-12-13 20:15:29 +00002159 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002160 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002161
2162 /* implicit withdraw, decrement aggregate and pcount here.
2163 * only if update is accepted, they'll increment below.
2164 */
paul902212c2006-02-05 17:51:19 +00002165 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2166
paul718e3742002-12-13 20:15:29 +00002167 /* Update bgp route dampening information. */
2168 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2169 && peer_sort (peer) == BGP_PEER_EBGP)
2170 {
2171 /* This is implicit withdraw so we should update dampening
2172 information. */
2173 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2174 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002175 }
2176
paul718e3742002-12-13 20:15:29 +00002177 /* Update to new attribute. */
2178 bgp_attr_unintern (ri->attr);
2179 ri->attr = attr_new;
2180
2181 /* Update MPLS tag. */
2182 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002183 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002184
2185 /* Update bgp route dampening information. */
2186 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2187 && peer_sort (peer) == BGP_PEER_EBGP)
2188 {
2189 /* Now we do normal update dampening. */
2190 ret = bgp_damp_update (ri, rn, afi, safi);
2191 if (ret == BGP_DAMP_SUPPRESSED)
2192 {
2193 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002194 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002195 return 0;
2196 }
2197 }
2198
2199 /* Nexthop reachability check. */
2200 if ((afi == AFI_IP || afi == AFI_IP6)
2201 && safi == SAFI_UNICAST
2202 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002203 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002204 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002205 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002206 {
2207 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002208 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002209 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002210 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002211 }
2212 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002213 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002214
2215 /* Process change. */
2216 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2217
2218 bgp_process (bgp, rn, afi, safi);
2219 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002220 bgp_attr_extra_free (&new_attr);
2221
paul718e3742002-12-13 20:15:29 +00002222 return 0;
2223 }
2224
2225 /* Received Logging. */
2226 if (BGP_DEBUG (update, UPDATE_IN))
2227 {
ajsd2c1f162004-12-08 21:10:20 +00002228 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002229 peer->host,
2230 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2231 p->prefixlen);
2232 }
2233
paul718e3742002-12-13 20:15:29 +00002234 /* Make new BGP info. */
2235 new = bgp_info_new ();
2236 new->type = type;
2237 new->sub_type = sub_type;
2238 new->peer = peer;
2239 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002240 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002241
2242 /* Update MPLS tag. */
2243 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002244 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002245
2246 /* Nexthop reachability check. */
2247 if ((afi == AFI_IP || afi == AFI_IP6)
2248 && safi == SAFI_UNICAST
2249 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002250 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002251 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002252 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002253 {
2254 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002255 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002256 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002257 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002258 }
2259 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002260 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002261
paul902212c2006-02-05 17:51:19 +00002262 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002263 bgp_aggregate_increment (bgp, p, new, afi, safi);
2264
2265 /* Register new BGP information. */
2266 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002267
2268 /* route_node_get lock */
2269 bgp_unlock_node (rn);
2270
Paul Jakmafb982c22007-05-04 20:15:47 +00002271 bgp_attr_extra_free (&new_attr);
2272
paul718e3742002-12-13 20:15:29 +00002273 /* If maximum prefix count is configured and current prefix
2274 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002275 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2276 return -1;
paul718e3742002-12-13 20:15:29 +00002277
2278 /* Process change. */
2279 bgp_process (bgp, rn, afi, safi);
2280
2281 return 0;
2282
2283 /* This BGP update is filtered. Log the reason then update BGP
2284 entry. */
2285 filtered:
2286 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002287 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002288 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2289 peer->host,
2290 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2291 p->prefixlen, reason);
2292
2293 if (ri)
paulb40d9392005-08-22 22:34:41 +00002294 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002295
2296 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002297
2298 bgp_attr_extra_free (&new_attr);
2299
paul718e3742002-12-13 20:15:29 +00002300 return 0;
2301}
2302
2303int
paulfee0f4c2004-09-13 05:12:46 +00002304bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2305 afi_t afi, safi_t safi, int type, int sub_type,
2306 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2307{
2308 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002309 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002310 struct bgp *bgp;
2311 int ret;
2312
2313 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2314 soft_reconfig);
2315
2316 bgp = peer->bgp;
2317
2318 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002319 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002320 {
2321 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2322 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2323 sub_type, prd, tag);
2324 }
2325
2326 return ret;
2327}
2328
2329int
paul718e3742002-12-13 20:15:29 +00002330bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002331 afi_t afi, safi_t safi, int type, int sub_type,
2332 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002333{
2334 struct bgp *bgp;
2335 char buf[SU_ADDRSTRLEN];
2336 struct bgp_node *rn;
2337 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002338 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002339 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002340
2341 bgp = peer->bgp;
2342
paulfee0f4c2004-09-13 05:12:46 +00002343 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002344 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002345 {
2346 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2347 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2348 }
2349
paul718e3742002-12-13 20:15:29 +00002350 /* Logging. */
2351 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002352 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002353 peer->host,
2354 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2355 p->prefixlen);
2356
2357 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002358 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002359
2360 /* If peer is soft reconfiguration enabled. Record input packet for
2361 further calculation. */
2362 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2363 && peer != bgp->peer_self)
2364 bgp_adj_in_unset (rn, peer);
2365
2366 /* Lookup withdrawn route. */
2367 for (ri = rn->info; ri; ri = ri->next)
2368 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2369 break;
2370
2371 /* Withdraw specified route from routing table. */
2372 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002373 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002374 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002375 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002376 "%s Can't find the route %s/%d", peer->host,
2377 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2378 p->prefixlen);
2379
2380 /* Unlock bgp_node_get() lock. */
2381 bgp_unlock_node (rn);
2382
2383 return 0;
2384}
2385
2386void
2387bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2388{
2389 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002390 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002391 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002392 struct prefix p;
2393 struct bgp_info binfo;
2394 struct peer *from;
2395 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002396
Paul Jakmab2497022007-06-14 11:17:58 +00002397 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002398 return;
2399
paul718e3742002-12-13 20:15:29 +00002400 bgp = peer->bgp;
2401 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002402
paul718e3742002-12-13 20:15:29 +00002403 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2404 aspath = attr.aspath;
2405 attr.local_pref = bgp->default_local_pref;
2406 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2407
2408 if (afi == AFI_IP)
2409 str2prefix ("0.0.0.0/0", &p);
2410#ifdef HAVE_IPV6
2411 else if (afi == AFI_IP6)
2412 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002413 struct attr_extra *ae;
2414 attr.extra = NULL;
2415
2416 ae = bgp_attr_extra_get (&attr);
2417 attr.extra = ae;
2418
paul718e3742002-12-13 20:15:29 +00002419 str2prefix ("::/0", &p);
2420
2421 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002422 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002423 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002424 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002425
2426 /* If the peer is on shared nextwork and we have link-local
2427 nexthop set it. */
2428 if (peer->shared_network
2429 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2430 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002431 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002432 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002433 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002434 }
2435 }
2436#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002437
2438 if (peer->default_rmap[afi][safi].name)
2439 {
2440 binfo.peer = bgp->peer_self;
2441 binfo.attr = &attr;
2442
paulfee0f4c2004-09-13 05:12:46 +00002443 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2444
paul718e3742002-12-13 20:15:29 +00002445 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2446 RMAP_BGP, &binfo);
2447
paulfee0f4c2004-09-13 05:12:46 +00002448 bgp->peer_self->rmap_type = 0;
2449
paul718e3742002-12-13 20:15:29 +00002450 if (ret == RMAP_DENYMATCH)
2451 {
2452 bgp_attr_flush (&attr);
2453 withdraw = 1;
2454 }
2455 }
2456
2457 if (withdraw)
2458 {
2459 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2460 bgp_default_withdraw_send (peer, afi, safi);
2461 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2462 }
2463 else
2464 {
2465 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2466 bgp_default_update_send (peer, &attr, afi, safi, from);
2467 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002468
2469 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002470 aspath_unintern (aspath);
2471}
2472
2473static void
2474bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002475 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002476{
2477 struct bgp_node *rn;
2478 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002479 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002480
paul718e3742002-12-13 20:15:29 +00002481 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002482 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002483
2484 if (safi != SAFI_MPLS_VPN
2485 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2486 bgp_default_originate (peer, afi, safi, 0);
2487
2488 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2489 for (ri = rn->info; ri; ri = ri->next)
2490 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2491 {
paulfee0f4c2004-09-13 05:12:46 +00002492 if ( (rsclient) ?
2493 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2494 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002495 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2496 else
2497 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002498
2499 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002500 }
2501}
2502
2503void
2504bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2505{
2506 struct bgp_node *rn;
2507 struct bgp_table *table;
2508
2509 if (peer->status != Established)
2510 return;
2511
2512 if (! peer->afc_nego[afi][safi])
2513 return;
2514
2515 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2516 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2517 return;
2518
2519 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002520 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002521 else
2522 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2523 rn = bgp_route_next(rn))
2524 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002525 bgp_announce_table (peer, afi, safi, table, 0);
2526
2527 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2528 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002529}
2530
2531void
2532bgp_announce_route_all (struct peer *peer)
2533{
2534 afi_t afi;
2535 safi_t safi;
2536
2537 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2538 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2539 bgp_announce_route (peer, afi, safi);
2540}
2541
2542static void
paulfee0f4c2004-09-13 05:12:46 +00002543bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2544 safi_t safi, struct bgp_table *table)
2545{
2546 struct bgp_node *rn;
2547 struct bgp_adj_in *ain;
2548
2549 if (! table)
2550 table = rsclient->bgp->rib[afi][safi];
2551
2552 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2553 for (ain = rn->adj_in; ain; ain = ain->next)
2554 {
2555 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2556 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2557 }
2558}
2559
2560void
2561bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2562{
2563 struct bgp_table *table;
2564 struct bgp_node *rn;
2565
2566 if (safi != SAFI_MPLS_VPN)
2567 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2568
2569 else
2570 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2571 rn = bgp_route_next (rn))
2572 if ((table = rn->info) != NULL)
2573 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2574}
2575
2576static void
paul718e3742002-12-13 20:15:29 +00002577bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2578 struct bgp_table *table)
2579{
2580 int ret;
2581 struct bgp_node *rn;
2582 struct bgp_adj_in *ain;
2583
2584 if (! table)
2585 table = peer->bgp->rib[afi][safi];
2586
2587 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2588 for (ain = rn->adj_in; ain; ain = ain->next)
2589 {
2590 if (ain->peer == peer)
2591 {
2592 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2593 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2594 NULL, NULL, 1);
2595 if (ret < 0)
2596 {
2597 bgp_unlock_node (rn);
2598 return;
2599 }
2600 continue;
2601 }
2602 }
2603}
2604
2605void
2606bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2607{
2608 struct bgp_node *rn;
2609 struct bgp_table *table;
2610
2611 if (peer->status != Established)
2612 return;
2613
2614 if (safi != SAFI_MPLS_VPN)
2615 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2616 else
2617 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2618 rn = bgp_route_next (rn))
2619 if ((table = rn->info) != NULL)
2620 bgp_soft_reconfig_table (peer, afi, safi, table);
2621}
2622
Chris Caputo228da422009-07-18 05:44:03 +00002623
2624struct bgp_clear_node_queue
2625{
2626 struct bgp_node *rn;
2627 enum bgp_clear_route_type purpose;
2628};
2629
paul200df112005-06-01 11:17:05 +00002630static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002631bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002632{
Chris Caputo228da422009-07-18 05:44:03 +00002633 struct bgp_clear_node_queue *cnq = data;
2634 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002635 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002636 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002637 afi_t afi = rn->table->afi;
2638 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002639
Paul Jakma64e580a2006-02-21 01:09:01 +00002640 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002641
Paul Jakma64e580a2006-02-21 01:09:01 +00002642 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002643 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002644 {
2645 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002646 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2647 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002648 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002649 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2650 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002651 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002652 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002653 break;
2654 }
paul200df112005-06-01 11:17:05 +00002655 return WQ_SUCCESS;
2656}
2657
2658static void
paul0fb58d52005-11-14 14:31:49 +00002659bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002660{
Chris Caputo228da422009-07-18 05:44:03 +00002661 struct bgp_clear_node_queue *cnq = data;
2662 struct bgp_node *rn = cnq->rn;
2663 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002664
2665 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002666 bgp_table_unlock (table);
2667 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002668}
2669
2670static void
paul94f2b392005-06-28 12:44:16 +00002671bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002672{
Paul Jakma64e580a2006-02-21 01:09:01 +00002673 struct peer *peer = wq->spec.data;
2674
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002675 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002676 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002677
2678 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002679}
2680
2681static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002682bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002683{
Paul Jakmaa2943652009-07-21 14:02:04 +01002684 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002685
Paul Jakmaa2943652009-07-21 14:02:04 +01002686 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002687#undef CLEAR_QUEUE_NAME_LEN
2688
2689 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002690 {
2691 zlog_err ("%s: Failed to allocate work queue", __func__);
2692 exit (1);
2693 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002694 peer->clear_node_queue->spec.hold = 10;
2695 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2696 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2697 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2698 peer->clear_node_queue->spec.max_retries = 0;
2699
2700 /* we only 'lock' this peer reference when the queue is actually active */
2701 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002702}
2703
paul718e3742002-12-13 20:15:29 +00002704static void
2705bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002706 struct bgp_table *table, struct peer *rsclient,
2707 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002708{
2709 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002710
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002711
paul718e3742002-12-13 20:15:29 +00002712 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002713 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002714
hasso6cf159b2005-03-21 10:28:14 +00002715 /* If still no table => afi/safi isn't configured at all or smth. */
2716 if (! table)
2717 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002718
2719 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2720 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002721 struct bgp_info *ri;
2722 struct bgp_adj_in *ain;
2723 struct bgp_adj_out *aout;
2724
Paul Jakma65ca75e2006-05-04 08:08:15 +00002725 if (rn->info == NULL)
2726 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002727
2728 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2729 * queued for every clearing peer, regardless of whether it is
2730 * relevant to the peer at hand.
2731 *
2732 * Overview: There are 3 different indices which need to be
2733 * scrubbed, potentially, when a peer is removed:
2734 *
2735 * 1 peer's routes visible via the RIB (ie accepted routes)
2736 * 2 peer's routes visible by the (optional) peer's adj-in index
2737 * 3 other routes visible by the peer's adj-out index
2738 *
2739 * 3 there is no hurry in scrubbing, once the struct peer is
2740 * removed from bgp->peer, we could just GC such deleted peer's
2741 * adj-outs at our leisure.
2742 *
2743 * 1 and 2 must be 'scrubbed' in some way, at least made
2744 * invisible via RIB index before peer session is allowed to be
2745 * brought back up. So one needs to know when such a 'search' is
2746 * complete.
2747 *
2748 * Ideally:
2749 *
2750 * - there'd be a single global queue or a single RIB walker
2751 * - rather than tracking which route_nodes still need to be
2752 * examined on a peer basis, we'd track which peers still
2753 * aren't cleared
2754 *
2755 * Given that our per-peer prefix-counts now should be reliable,
2756 * this may actually be achievable. It doesn't seem to be a huge
2757 * problem at this time,
2758 */
2759 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002760 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002761 {
Chris Caputo228da422009-07-18 05:44:03 +00002762 struct bgp_clear_node_queue *cnq;
2763
2764 /* both unlocked in bgp_clear_node_queue_del */
2765 bgp_table_lock (rn->table);
2766 bgp_lock_node (rn);
2767 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2768 sizeof (struct bgp_clear_node_queue));
2769 cnq->rn = rn;
2770 cnq->purpose = purpose;
2771 work_queue_add (peer->clear_node_queue, cnq);
2772 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002773 }
2774
2775 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002776 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002777 {
2778 bgp_adj_in_remove (rn, ain);
2779 bgp_unlock_node (rn);
2780 break;
2781 }
2782 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002783 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002784 {
2785 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2786 bgp_unlock_node (rn);
2787 break;
2788 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002789 }
2790 return;
2791}
2792
2793void
Chris Caputo228da422009-07-18 05:44:03 +00002794bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2795 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002796{
2797 struct bgp_node *rn;
2798 struct bgp_table *table;
2799 struct peer *rsclient;
2800 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002801
Paul Jakma64e580a2006-02-21 01:09:01 +00002802 if (peer->clear_node_queue == NULL)
2803 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002804
Paul Jakmaca058a32006-09-14 02:58:49 +00002805 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2806 * Idle until it receives a Clearing_Completed event. This protects
2807 * against peers which flap faster than we can we clear, which could
2808 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002809 *
2810 * a) race with routes from the new session being installed before
2811 * clear_route_node visits the node (to delete the route of that
2812 * peer)
2813 * b) resource exhaustion, clear_route_node likely leads to an entry
2814 * on the process_main queue. Fast-flapping could cause that queue
2815 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002816 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002817 if (!peer->clear_node_queue->thread)
2818 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002819
Chris Caputo228da422009-07-18 05:44:03 +00002820 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002821 {
Chris Caputo228da422009-07-18 05:44:03 +00002822 case BGP_CLEAR_ROUTE_NORMAL:
2823 if (safi != SAFI_MPLS_VPN)
2824 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2825 else
2826 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2827 rn = bgp_route_next (rn))
2828 if ((table = rn->info) != NULL)
2829 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2830
2831 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2832 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2833 PEER_FLAG_RSERVER_CLIENT))
2834 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2835 break;
2836
2837 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2838 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2839 break;
2840
2841 default:
2842 assert (0);
2843 break;
paulfee0f4c2004-09-13 05:12:46 +00002844 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002845
Paul Jakmaca058a32006-09-14 02:58:49 +00002846 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002847 * completion function won't be run by workqueue code - call it here.
2848 * XXX: Actually, this assumption doesn't hold, see
2849 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002850 *
2851 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002852 * really needed if peer state is Established - peers in
2853 * pre-Established states shouldn't have any route-update state
2854 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002855 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002856 * We still can get here in pre-Established though, through
2857 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2858 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002859 *
2860 * At some future point, this check could be move to the top of the
2861 * function, and do a quick early-return when state is
2862 * pre-Established, avoiding above list and table scans. Once we're
2863 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002864 */
2865 if (!peer->clear_node_queue->thread)
2866 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002867}
2868
2869void
2870bgp_clear_route_all (struct peer *peer)
2871{
2872 afi_t afi;
2873 safi_t safi;
2874
2875 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2876 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002877 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002878}
2879
2880void
2881bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2882{
2883 struct bgp_table *table;
2884 struct bgp_node *rn;
2885 struct bgp_adj_in *ain;
2886
2887 table = peer->bgp->rib[afi][safi];
2888
2889 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2890 for (ain = rn->adj_in; ain ; ain = ain->next)
2891 if (ain->peer == peer)
2892 {
2893 bgp_adj_in_remove (rn, ain);
2894 bgp_unlock_node (rn);
2895 break;
2896 }
2897}
hasso93406d82005-02-02 14:40:33 +00002898
2899void
2900bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2901{
2902 struct bgp_node *rn;
2903 struct bgp_info *ri;
2904 struct bgp_table *table;
2905
2906 table = peer->bgp->rib[afi][safi];
2907
2908 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2909 {
2910 for (ri = rn->info; ri; ri = ri->next)
2911 if (ri->peer == peer)
2912 {
2913 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2914 bgp_rib_remove (rn, ri, peer, afi, safi);
2915 break;
2916 }
2917 }
2918}
paul718e3742002-12-13 20:15:29 +00002919
2920/* Delete all kernel routes. */
2921void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002922bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002923{
2924 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002925 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002926 struct bgp_node *rn;
2927 struct bgp_table *table;
2928 struct bgp_info *ri;
2929
paul1eb8ef22005-04-07 07:30:20 +00002930 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002931 {
2932 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2933
2934 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2935 for (ri = rn->info; ri; ri = ri->next)
2936 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2937 && ri->type == ZEBRA_ROUTE_BGP
2938 && ri->sub_type == BGP_ROUTE_NORMAL)
2939 bgp_zebra_withdraw (&rn->p, ri);
2940
2941 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2942
2943 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2944 for (ri = rn->info; ri; ri = ri->next)
2945 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2946 && ri->type == ZEBRA_ROUTE_BGP
2947 && ri->sub_type == BGP_ROUTE_NORMAL)
2948 bgp_zebra_withdraw (&rn->p, ri);
2949 }
2950}
2951
2952void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002953bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00002954{
2955 vty_reset ();
2956 bgp_zclient_reset ();
2957 access_list_reset ();
2958 prefix_list_reset ();
2959}
2960
2961/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2962 value. */
2963int
2964bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2965{
2966 u_char *pnt;
2967 u_char *lim;
2968 struct prefix p;
2969 int psize;
2970 int ret;
2971
2972 /* Check peer status. */
2973 if (peer->status != Established)
2974 return 0;
2975
2976 pnt = packet->nlri;
2977 lim = pnt + packet->length;
2978
2979 for (; pnt < lim; pnt += psize)
2980 {
2981 /* Clear prefix structure. */
2982 memset (&p, 0, sizeof (struct prefix));
2983
2984 /* Fetch prefix length. */
2985 p.prefixlen = *pnt++;
2986 p.family = afi2family (packet->afi);
2987
2988 /* Already checked in nlri_sanity_check(). We do double check
2989 here. */
2990 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2991 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2992 return -1;
2993
2994 /* Packet size overflow check. */
2995 psize = PSIZE (p.prefixlen);
2996
2997 /* When packet overflow occur return immediately. */
2998 if (pnt + psize > lim)
2999 return -1;
3000
3001 /* Fetch prefix from NLRI packet. */
3002 memcpy (&p.u.prefix, pnt, psize);
3003
3004 /* Check address. */
3005 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3006 {
3007 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3008 {
paulf5ba3872004-07-09 12:11:31 +00003009 /*
3010 * From draft-ietf-idr-bgp4-22, Section 6.3:
3011 * If a BGP router receives an UPDATE message with a
3012 * semantically incorrect NLRI field, in which a prefix is
3013 * semantically incorrect (eg. an unexpected multicast IP
3014 * address), it should ignore the prefix.
3015 */
paul718e3742002-12-13 20:15:29 +00003016 zlog (peer->log, LOG_ERR,
3017 "IPv4 unicast NLRI is multicast address %s",
3018 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003019
paul718e3742002-12-13 20:15:29 +00003020 return -1;
3021 }
3022 }
3023
3024#ifdef HAVE_IPV6
3025 /* Check address. */
3026 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3027 {
3028 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3029 {
3030 char buf[BUFSIZ];
3031
3032 zlog (peer->log, LOG_WARNING,
3033 "IPv6 link-local NLRI received %s ignore this NLRI",
3034 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3035
3036 continue;
3037 }
3038 }
3039#endif /* HAVE_IPV6 */
3040
3041 /* Normal process. */
3042 if (attr)
3043 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3044 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3045 else
3046 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3047 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3048
3049 /* Address family configuration mismatch or maximum-prefix count
3050 overflow. */
3051 if (ret < 0)
3052 return -1;
3053 }
3054
3055 /* Packet length consistency check. */
3056 if (pnt != lim)
3057 return -1;
3058
3059 return 0;
3060}
3061
3062/* NLRI encode syntax check routine. */
3063int
3064bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3065 bgp_size_t length)
3066{
3067 u_char *end;
3068 u_char prefixlen;
3069 int psize;
3070
3071 end = pnt + length;
3072
3073 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3074 syntactic validity. If the field is syntactically incorrect,
3075 then the Error Subcode is set to Invalid Network Field. */
3076
3077 while (pnt < end)
3078 {
3079 prefixlen = *pnt++;
3080
3081 /* Prefix length check. */
3082 if ((afi == AFI_IP && prefixlen > 32)
3083 || (afi == AFI_IP6 && prefixlen > 128))
3084 {
3085 plog_err (peer->log,
3086 "%s [Error] Update packet error (wrong prefix length %d)",
3087 peer->host, prefixlen);
3088 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3089 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3090 return -1;
3091 }
3092
3093 /* Packet size overflow check. */
3094 psize = PSIZE (prefixlen);
3095
3096 if (pnt + psize > end)
3097 {
3098 plog_err (peer->log,
3099 "%s [Error] Update packet error"
3100 " (prefix data overflow prefix size is %d)",
3101 peer->host, psize);
3102 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3103 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3104 return -1;
3105 }
3106
3107 pnt += psize;
3108 }
3109
3110 /* Packet length consistency check. */
3111 if (pnt != end)
3112 {
3113 plog_err (peer->log,
3114 "%s [Error] Update packet error"
3115 " (prefix length mismatch with total length)",
3116 peer->host);
3117 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3118 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3119 return -1;
3120 }
3121 return 0;
3122}
3123
paul94f2b392005-06-28 12:44:16 +00003124static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003125bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003126{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003127 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003128}
3129
paul94f2b392005-06-28 12:44:16 +00003130static void
paul718e3742002-12-13 20:15:29 +00003131bgp_static_free (struct bgp_static *bgp_static)
3132{
3133 if (bgp_static->rmap.name)
3134 free (bgp_static->rmap.name);
3135 XFREE (MTYPE_BGP_STATIC, bgp_static);
3136}
3137
paul94f2b392005-06-28 12:44:16 +00003138static void
paulfee0f4c2004-09-13 05:12:46 +00003139bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3140 struct prefix *p, afi_t afi, safi_t safi)
3141{
3142 struct bgp_node *rn;
3143 struct bgp_info *ri;
3144
3145 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3146
3147 /* Check selected route and self inserted route. */
3148 for (ri = rn->info; ri; ri = ri->next)
3149 if (ri->peer == bgp->peer_self
3150 && ri->type == ZEBRA_ROUTE_BGP
3151 && ri->sub_type == BGP_ROUTE_STATIC)
3152 break;
3153
3154 /* Withdraw static BGP route from routing table. */
3155 if (ri)
3156 {
paulfee0f4c2004-09-13 05:12:46 +00003157 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003158 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003159 }
3160
3161 /* Unlock bgp_node_lookup. */
3162 bgp_unlock_node (rn);
3163}
3164
paul94f2b392005-06-28 12:44:16 +00003165static void
paulfee0f4c2004-09-13 05:12:46 +00003166bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003167 struct bgp_static *bgp_static,
3168 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003169{
3170 struct bgp_node *rn;
3171 struct bgp_info *ri;
3172 struct bgp_info *new;
3173 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003174 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003175 struct attr attr = {0 };
3176 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003177 struct bgp *bgp;
3178 int ret;
3179 char buf[SU_ADDRSTRLEN];
3180
3181 bgp = rsclient->bgp;
3182
Paul Jakma06e110f2006-05-12 23:29:22 +00003183 assert (bgp_static);
3184 if (!bgp_static)
3185 return;
3186
paulfee0f4c2004-09-13 05:12:46 +00003187 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3188
3189 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003190
3191 attr.nexthop = bgp_static->igpnexthop;
3192 attr.med = bgp_static->igpmetric;
3193 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003194
Paul Jakma41367172007-08-06 15:24:51 +00003195 if (bgp_static->atomic)
3196 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3197
paulfee0f4c2004-09-13 05:12:46 +00003198 /* Apply network route-map for export to this rsclient. */
3199 if (bgp_static->rmap.name)
3200 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003201 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003202 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003203 info.attr = &attr_tmp;
3204
paulfee0f4c2004-09-13 05:12:46 +00003205 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3206 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3207
3208 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3209
3210 rsclient->rmap_type = 0;
3211
3212 if (ret == RMAP_DENYMATCH)
3213 {
3214 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003215 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003216
3217 /* Unintern original. */
3218 aspath_unintern (attr.aspath);
3219 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003220 bgp_attr_extra_free (&attr);
3221
paulfee0f4c2004-09-13 05:12:46 +00003222 return;
3223 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003224 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003225 }
3226 else
3227 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003228
Stephen Hemminger7badc262010-08-05 10:26:31 -07003229 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003230
paulfee0f4c2004-09-13 05:12:46 +00003231 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3232
Paul Jakmafb982c22007-05-04 20:15:47 +00003233 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3234 == RMAP_DENY)
3235 {
paulfee0f4c2004-09-13 05:12:46 +00003236 /* This BGP update is filtered. Log the reason then update BGP entry. */
3237 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003238 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003239 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3240 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3241 p->prefixlen, rsclient->host);
3242
3243 bgp->peer_self->rmap_type = 0;
3244
3245 bgp_attr_unintern (attr_new);
3246 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003247 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003248
3249 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3250
3251 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003252 }
paulfee0f4c2004-09-13 05:12:46 +00003253
3254 bgp->peer_self->rmap_type = 0;
3255
3256 bgp_attr_unintern (attr_new);
3257 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003258 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003259
3260 for (ri = rn->info; ri; ri = ri->next)
3261 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3262 && ri->sub_type == BGP_ROUTE_STATIC)
3263 break;
3264
3265 if (ri)
3266 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003267 if (attrhash_cmp (ri->attr, attr_new) &&
3268 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003269 {
3270 bgp_unlock_node (rn);
3271 bgp_attr_unintern (attr_new);
3272 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003273 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003274 return;
3275 }
3276 else
3277 {
3278 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003279 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003280
3281 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003282 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3283 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003284 bgp_attr_unintern (ri->attr);
3285 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003286 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003287
3288 /* Process change. */
3289 bgp_process (bgp, rn, afi, safi);
3290 bgp_unlock_node (rn);
3291 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003292 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003293 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003294 }
paulfee0f4c2004-09-13 05:12:46 +00003295 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003296
paulfee0f4c2004-09-13 05:12:46 +00003297 /* Make new BGP info. */
3298 new = bgp_info_new ();
3299 new->type = ZEBRA_ROUTE_BGP;
3300 new->sub_type = BGP_ROUTE_STATIC;
3301 new->peer = bgp->peer_self;
3302 SET_FLAG (new->flags, BGP_INFO_VALID);
3303 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003304 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003305
3306 /* Register new BGP information. */
3307 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003308
3309 /* route_node_get lock */
3310 bgp_unlock_node (rn);
3311
paulfee0f4c2004-09-13 05:12:46 +00003312 /* Process change. */
3313 bgp_process (bgp, rn, afi, safi);
3314
3315 /* Unintern original. */
3316 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003317 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003318}
3319
paul94f2b392005-06-28 12:44:16 +00003320static void
paulfee0f4c2004-09-13 05:12:46 +00003321bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003322 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3323{
3324 struct bgp_node *rn;
3325 struct bgp_info *ri;
3326 struct bgp_info *new;
3327 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003328 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003329 struct attr *attr_new;
3330 int ret;
3331
Paul Jakmadd8103a2006-05-12 23:27:30 +00003332 assert (bgp_static);
3333 if (!bgp_static)
3334 return;
3335
paulfee0f4c2004-09-13 05:12:46 +00003336 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003337
3338 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003339
3340 attr.nexthop = bgp_static->igpnexthop;
3341 attr.med = bgp_static->igpmetric;
3342 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003343
Paul Jakma41367172007-08-06 15:24:51 +00003344 if (bgp_static->atomic)
3345 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3346
paul718e3742002-12-13 20:15:29 +00003347 /* Apply route-map. */
3348 if (bgp_static->rmap.name)
3349 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003350 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003351 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003352 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003353
paulfee0f4c2004-09-13 05:12:46 +00003354 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3355
paul718e3742002-12-13 20:15:29 +00003356 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003357
paulfee0f4c2004-09-13 05:12:46 +00003358 bgp->peer_self->rmap_type = 0;
3359
paul718e3742002-12-13 20:15:29 +00003360 if (ret == RMAP_DENYMATCH)
3361 {
3362 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003363 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003364
3365 /* Unintern original. */
3366 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003367 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003368 bgp_static_withdraw (bgp, p, afi, safi);
3369 return;
3370 }
paul286e1e72003-08-08 00:24:31 +00003371 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003372 }
paul286e1e72003-08-08 00:24:31 +00003373 else
3374 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003375
3376 for (ri = rn->info; ri; ri = ri->next)
3377 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3378 && ri->sub_type == BGP_ROUTE_STATIC)
3379 break;
3380
3381 if (ri)
3382 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003383 if (attrhash_cmp (ri->attr, attr_new) &&
3384 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003385 {
3386 bgp_unlock_node (rn);
3387 bgp_attr_unintern (attr_new);
3388 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003389 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003390 return;
3391 }
3392 else
3393 {
3394 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003395 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003396
3397 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003398 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3399 bgp_info_restore(rn, ri);
3400 else
3401 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003402 bgp_attr_unintern (ri->attr);
3403 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003404 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003405
3406 /* Process change. */
3407 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3408 bgp_process (bgp, rn, afi, safi);
3409 bgp_unlock_node (rn);
3410 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003411 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003412 return;
3413 }
3414 }
3415
3416 /* Make new BGP info. */
3417 new = bgp_info_new ();
3418 new->type = ZEBRA_ROUTE_BGP;
3419 new->sub_type = BGP_ROUTE_STATIC;
3420 new->peer = bgp->peer_self;
3421 SET_FLAG (new->flags, BGP_INFO_VALID);
3422 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003423 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003424
3425 /* Aggregate address increment. */
3426 bgp_aggregate_increment (bgp, p, new, afi, safi);
3427
3428 /* Register new BGP information. */
3429 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003430
3431 /* route_node_get lock */
3432 bgp_unlock_node (rn);
3433
paul718e3742002-12-13 20:15:29 +00003434 /* Process change. */
3435 bgp_process (bgp, rn, afi, safi);
3436
3437 /* Unintern original. */
3438 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003439 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003440}
3441
3442void
paulfee0f4c2004-09-13 05:12:46 +00003443bgp_static_update (struct bgp *bgp, struct prefix *p,
3444 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3445{
3446 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003447 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003448
3449 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3450
paul1eb8ef22005-04-07 07:30:20 +00003451 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003452 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003453 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3454 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003455 }
3456}
3457
paul94f2b392005-06-28 12:44:16 +00003458static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003459bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3460 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003461{
3462 struct bgp_node *rn;
3463 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003464
paulfee0f4c2004-09-13 05:12:46 +00003465 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003466
3467 /* Make new BGP info. */
3468 new = bgp_info_new ();
3469 new->type = ZEBRA_ROUTE_BGP;
3470 new->sub_type = BGP_ROUTE_STATIC;
3471 new->peer = bgp->peer_self;
3472 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3473 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003474 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003475 new->extra = bgp_info_extra_new();
3476 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003477
3478 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003479 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003480
3481 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003482 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003483
paul200df112005-06-01 11:17:05 +00003484 /* route_node_get lock */
3485 bgp_unlock_node (rn);
3486
paul718e3742002-12-13 20:15:29 +00003487 /* Process change. */
3488 bgp_process (bgp, rn, afi, safi);
3489}
3490
3491void
3492bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3493 safi_t safi)
3494{
3495 struct bgp_node *rn;
3496 struct bgp_info *ri;
3497
paulfee0f4c2004-09-13 05:12:46 +00003498 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003499
3500 /* Check selected route and self inserted route. */
3501 for (ri = rn->info; ri; ri = ri->next)
3502 if (ri->peer == bgp->peer_self
3503 && ri->type == ZEBRA_ROUTE_BGP
3504 && ri->sub_type == BGP_ROUTE_STATIC)
3505 break;
3506
3507 /* Withdraw static BGP route from routing table. */
3508 if (ri)
3509 {
3510 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003511 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003512 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003513 }
3514
3515 /* Unlock bgp_node_lookup. */
3516 bgp_unlock_node (rn);
3517}
3518
3519void
paulfee0f4c2004-09-13 05:12:46 +00003520bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3521{
3522 struct bgp_static *bgp_static;
3523 struct bgp *bgp;
3524 struct bgp_node *rn;
3525 struct prefix *p;
3526
3527 bgp = rsclient->bgp;
3528
3529 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3530 if ((bgp_static = rn->info) != NULL)
3531 {
3532 p = &rn->p;
3533
3534 bgp_static_update_rsclient (rsclient, p, bgp_static,
3535 afi, safi);
3536 }
3537}
3538
paul94f2b392005-06-28 12:44:16 +00003539static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003540bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3541 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003542{
3543 struct bgp_node *rn;
3544 struct bgp_info *ri;
3545
paulfee0f4c2004-09-13 05:12:46 +00003546 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003547
3548 /* Check selected route and self inserted route. */
3549 for (ri = rn->info; ri; ri = ri->next)
3550 if (ri->peer == bgp->peer_self
3551 && ri->type == ZEBRA_ROUTE_BGP
3552 && ri->sub_type == BGP_ROUTE_STATIC)
3553 break;
3554
3555 /* Withdraw static BGP route from routing table. */
3556 if (ri)
3557 {
3558 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003559 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003560 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003561 }
3562
3563 /* Unlock bgp_node_lookup. */
3564 bgp_unlock_node (rn);
3565}
3566
3567/* Configure static BGP network. When user don't run zebra, static
3568 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003569static int
paulfd79ac92004-10-13 05:06:08 +00003570bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003571 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003572{
3573 int ret;
3574 struct prefix p;
3575 struct bgp_static *bgp_static;
3576 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003577 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003578
3579 /* Convert IP prefix string to struct prefix. */
3580 ret = str2prefix (ip_str, &p);
3581 if (! ret)
3582 {
3583 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3584 return CMD_WARNING;
3585 }
3586#ifdef HAVE_IPV6
3587 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3588 {
3589 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3590 VTY_NEWLINE);
3591 return CMD_WARNING;
3592 }
3593#endif /* HAVE_IPV6 */
3594
3595 apply_mask (&p);
3596
3597 /* Set BGP static route configuration. */
3598 rn = bgp_node_get (bgp->route[afi][safi], &p);
3599
3600 if (rn->info)
3601 {
3602 /* Configuration change. */
3603 bgp_static = rn->info;
3604
3605 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003606 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3607 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003608
paul718e3742002-12-13 20:15:29 +00003609 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003610
paul718e3742002-12-13 20:15:29 +00003611 if (rmap)
3612 {
3613 if (bgp_static->rmap.name)
3614 free (bgp_static->rmap.name);
3615 bgp_static->rmap.name = strdup (rmap);
3616 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3617 }
3618 else
3619 {
3620 if (bgp_static->rmap.name)
3621 free (bgp_static->rmap.name);
3622 bgp_static->rmap.name = NULL;
3623 bgp_static->rmap.map = NULL;
3624 bgp_static->valid = 0;
3625 }
3626 bgp_unlock_node (rn);
3627 }
3628 else
3629 {
3630 /* New configuration. */
3631 bgp_static = bgp_static_new ();
3632 bgp_static->backdoor = backdoor;
3633 bgp_static->valid = 0;
3634 bgp_static->igpmetric = 0;
3635 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003636
paul718e3742002-12-13 20:15:29 +00003637 if (rmap)
3638 {
3639 if (bgp_static->rmap.name)
3640 free (bgp_static->rmap.name);
3641 bgp_static->rmap.name = strdup (rmap);
3642 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3643 }
3644 rn->info = bgp_static;
3645 }
3646
3647 /* If BGP scan is not enabled, we should install this route here. */
3648 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3649 {
3650 bgp_static->valid = 1;
3651
3652 if (need_update)
3653 bgp_static_withdraw (bgp, &p, afi, safi);
3654
3655 if (! bgp_static->backdoor)
3656 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3657 }
3658
3659 return CMD_SUCCESS;
3660}
3661
3662/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003663static int
paulfd79ac92004-10-13 05:06:08 +00003664bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003665 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003666{
3667 int ret;
3668 struct prefix p;
3669 struct bgp_static *bgp_static;
3670 struct bgp_node *rn;
3671
3672 /* Convert IP prefix string to struct prefix. */
3673 ret = str2prefix (ip_str, &p);
3674 if (! ret)
3675 {
3676 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3677 return CMD_WARNING;
3678 }
3679#ifdef HAVE_IPV6
3680 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3681 {
3682 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3683 VTY_NEWLINE);
3684 return CMD_WARNING;
3685 }
3686#endif /* HAVE_IPV6 */
3687
3688 apply_mask (&p);
3689
3690 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3691 if (! rn)
3692 {
3693 vty_out (vty, "%% Can't find specified static route configuration.%s",
3694 VTY_NEWLINE);
3695 return CMD_WARNING;
3696 }
3697
3698 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003699
paul718e3742002-12-13 20:15:29 +00003700 /* Update BGP RIB. */
3701 if (! bgp_static->backdoor)
3702 bgp_static_withdraw (bgp, &p, afi, safi);
3703
3704 /* Clear configuration. */
3705 bgp_static_free (bgp_static);
3706 rn->info = NULL;
3707 bgp_unlock_node (rn);
3708 bgp_unlock_node (rn);
3709
3710 return CMD_SUCCESS;
3711}
3712
3713/* Called from bgp_delete(). Delete all static routes from the BGP
3714 instance. */
3715void
3716bgp_static_delete (struct bgp *bgp)
3717{
3718 afi_t afi;
3719 safi_t safi;
3720 struct bgp_node *rn;
3721 struct bgp_node *rm;
3722 struct bgp_table *table;
3723 struct bgp_static *bgp_static;
3724
3725 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3726 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3727 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3728 if (rn->info != NULL)
3729 {
3730 if (safi == SAFI_MPLS_VPN)
3731 {
3732 table = rn->info;
3733
3734 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3735 {
3736 bgp_static = rn->info;
3737 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3738 AFI_IP, SAFI_MPLS_VPN,
3739 (struct prefix_rd *)&rn->p,
3740 bgp_static->tag);
3741 bgp_static_free (bgp_static);
3742 rn->info = NULL;
3743 bgp_unlock_node (rn);
3744 }
3745 }
3746 else
3747 {
3748 bgp_static = rn->info;
3749 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3750 bgp_static_free (bgp_static);
3751 rn->info = NULL;
3752 bgp_unlock_node (rn);
3753 }
3754 }
3755}
3756
3757int
paulfd79ac92004-10-13 05:06:08 +00003758bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3759 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003760{
3761 int ret;
3762 struct prefix p;
3763 struct prefix_rd prd;
3764 struct bgp *bgp;
3765 struct bgp_node *prn;
3766 struct bgp_node *rn;
3767 struct bgp_table *table;
3768 struct bgp_static *bgp_static;
3769 u_char tag[3];
3770
3771 bgp = vty->index;
3772
3773 ret = str2prefix (ip_str, &p);
3774 if (! ret)
3775 {
3776 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3777 return CMD_WARNING;
3778 }
3779 apply_mask (&p);
3780
3781 ret = str2prefix_rd (rd_str, &prd);
3782 if (! ret)
3783 {
3784 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3785 return CMD_WARNING;
3786 }
3787
3788 ret = str2tag (tag_str, tag);
3789 if (! ret)
3790 {
3791 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3792 return CMD_WARNING;
3793 }
3794
3795 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3796 (struct prefix *)&prd);
3797 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003798 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003799 else
3800 bgp_unlock_node (prn);
3801 table = prn->info;
3802
3803 rn = bgp_node_get (table, &p);
3804
3805 if (rn->info)
3806 {
3807 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3808 bgp_unlock_node (rn);
3809 }
3810 else
3811 {
3812 /* New configuration. */
3813 bgp_static = bgp_static_new ();
3814 bgp_static->valid = 1;
3815 memcpy (bgp_static->tag, tag, 3);
3816 rn->info = bgp_static;
3817
3818 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3819 }
3820
3821 return CMD_SUCCESS;
3822}
3823
3824/* Configure static BGP network. */
3825int
paulfd79ac92004-10-13 05:06:08 +00003826bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3827 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003828{
3829 int ret;
3830 struct bgp *bgp;
3831 struct prefix p;
3832 struct prefix_rd prd;
3833 struct bgp_node *prn;
3834 struct bgp_node *rn;
3835 struct bgp_table *table;
3836 struct bgp_static *bgp_static;
3837 u_char tag[3];
3838
3839 bgp = vty->index;
3840
3841 /* Convert IP prefix string to struct prefix. */
3842 ret = str2prefix (ip_str, &p);
3843 if (! ret)
3844 {
3845 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3846 return CMD_WARNING;
3847 }
3848 apply_mask (&p);
3849
3850 ret = str2prefix_rd (rd_str, &prd);
3851 if (! ret)
3852 {
3853 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3854 return CMD_WARNING;
3855 }
3856
3857 ret = str2tag (tag_str, tag);
3858 if (! ret)
3859 {
3860 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3861 return CMD_WARNING;
3862 }
3863
3864 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3865 (struct prefix *)&prd);
3866 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003867 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003868 else
3869 bgp_unlock_node (prn);
3870 table = prn->info;
3871
3872 rn = bgp_node_lookup (table, &p);
3873
3874 if (rn)
3875 {
3876 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3877
3878 bgp_static = rn->info;
3879 bgp_static_free (bgp_static);
3880 rn->info = NULL;
3881 bgp_unlock_node (rn);
3882 bgp_unlock_node (rn);
3883 }
3884 else
3885 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3886
3887 return CMD_SUCCESS;
3888}
3889
3890DEFUN (bgp_network,
3891 bgp_network_cmd,
3892 "network A.B.C.D/M",
3893 "Specify a network to announce via BGP\n"
3894 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3895{
3896 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003897 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003898}
3899
3900DEFUN (bgp_network_route_map,
3901 bgp_network_route_map_cmd,
3902 "network A.B.C.D/M route-map WORD",
3903 "Specify a network to announce via BGP\n"
3904 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3905 "Route-map to modify the attributes\n"
3906 "Name of the route map\n")
3907{
3908 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003909 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003910}
3911
3912DEFUN (bgp_network_backdoor,
3913 bgp_network_backdoor_cmd,
3914 "network A.B.C.D/M backdoor",
3915 "Specify a network to announce via BGP\n"
3916 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3917 "Specify a BGP backdoor route\n")
3918{
Paul Jakma41367172007-08-06 15:24:51 +00003919 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003920 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003921}
3922
3923DEFUN (bgp_network_mask,
3924 bgp_network_mask_cmd,
3925 "network A.B.C.D mask A.B.C.D",
3926 "Specify a network to announce via BGP\n"
3927 "Network number\n"
3928 "Network mask\n"
3929 "Network mask\n")
3930{
3931 int ret;
3932 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003933
paul718e3742002-12-13 20:15:29 +00003934 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3935 if (! ret)
3936 {
3937 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3938 return CMD_WARNING;
3939 }
3940
3941 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003942 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003943}
3944
3945DEFUN (bgp_network_mask_route_map,
3946 bgp_network_mask_route_map_cmd,
3947 "network A.B.C.D mask A.B.C.D route-map WORD",
3948 "Specify a network to announce via BGP\n"
3949 "Network number\n"
3950 "Network mask\n"
3951 "Network mask\n"
3952 "Route-map to modify the attributes\n"
3953 "Name of the route map\n")
3954{
3955 int ret;
3956 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003957
paul718e3742002-12-13 20:15:29 +00003958 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3959 if (! ret)
3960 {
3961 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3962 return CMD_WARNING;
3963 }
3964
3965 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003966 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00003967}
3968
3969DEFUN (bgp_network_mask_backdoor,
3970 bgp_network_mask_backdoor_cmd,
3971 "network A.B.C.D mask A.B.C.D backdoor",
3972 "Specify a network to announce via BGP\n"
3973 "Network number\n"
3974 "Network mask\n"
3975 "Network mask\n"
3976 "Specify a BGP backdoor route\n")
3977{
3978 int ret;
3979 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003980
paul718e3742002-12-13 20:15:29 +00003981 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3982 if (! ret)
3983 {
3984 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3985 return CMD_WARNING;
3986 }
3987
Paul Jakma41367172007-08-06 15:24:51 +00003988 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003989 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003990}
3991
3992DEFUN (bgp_network_mask_natural,
3993 bgp_network_mask_natural_cmd,
3994 "network A.B.C.D",
3995 "Specify a network to announce via BGP\n"
3996 "Network number\n")
3997{
3998 int ret;
3999 char prefix_str[BUFSIZ];
4000
4001 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4002 if (! ret)
4003 {
4004 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4005 return CMD_WARNING;
4006 }
4007
4008 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004009 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004010}
4011
4012DEFUN (bgp_network_mask_natural_route_map,
4013 bgp_network_mask_natural_route_map_cmd,
4014 "network A.B.C.D route-map WORD",
4015 "Specify a network to announce via BGP\n"
4016 "Network number\n"
4017 "Route-map to modify the attributes\n"
4018 "Name of the route map\n")
4019{
4020 int ret;
4021 char prefix_str[BUFSIZ];
4022
4023 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4024 if (! ret)
4025 {
4026 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4027 return CMD_WARNING;
4028 }
4029
4030 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004031 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004032}
4033
4034DEFUN (bgp_network_mask_natural_backdoor,
4035 bgp_network_mask_natural_backdoor_cmd,
4036 "network A.B.C.D backdoor",
4037 "Specify a network to announce via BGP\n"
4038 "Network number\n"
4039 "Specify a BGP backdoor route\n")
4040{
4041 int ret;
4042 char prefix_str[BUFSIZ];
4043
4044 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4045 if (! ret)
4046 {
4047 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4048 return CMD_WARNING;
4049 }
4050
Paul Jakma41367172007-08-06 15:24:51 +00004051 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004052 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004053}
4054
4055DEFUN (no_bgp_network,
4056 no_bgp_network_cmd,
4057 "no network A.B.C.D/M",
4058 NO_STR
4059 "Specify a network to announce via BGP\n"
4060 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4061{
4062 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4063 bgp_node_safi (vty));
4064}
4065
4066ALIAS (no_bgp_network,
4067 no_bgp_network_route_map_cmd,
4068 "no network A.B.C.D/M route-map WORD",
4069 NO_STR
4070 "Specify a network to announce via BGP\n"
4071 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4072 "Route-map to modify the attributes\n"
4073 "Name of the route map\n")
4074
4075ALIAS (no_bgp_network,
4076 no_bgp_network_backdoor_cmd,
4077 "no network A.B.C.D/M backdoor",
4078 NO_STR
4079 "Specify a network to announce via BGP\n"
4080 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4081 "Specify a BGP backdoor route\n")
4082
4083DEFUN (no_bgp_network_mask,
4084 no_bgp_network_mask_cmd,
4085 "no network A.B.C.D mask A.B.C.D",
4086 NO_STR
4087 "Specify a network to announce via BGP\n"
4088 "Network number\n"
4089 "Network mask\n"
4090 "Network mask\n")
4091{
4092 int ret;
4093 char prefix_str[BUFSIZ];
4094
4095 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4096 if (! ret)
4097 {
4098 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4099 return CMD_WARNING;
4100 }
4101
4102 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4103 bgp_node_safi (vty));
4104}
4105
4106ALIAS (no_bgp_network_mask,
4107 no_bgp_network_mask_route_map_cmd,
4108 "no network A.B.C.D mask A.B.C.D route-map WORD",
4109 NO_STR
4110 "Specify a network to announce via BGP\n"
4111 "Network number\n"
4112 "Network mask\n"
4113 "Network mask\n"
4114 "Route-map to modify the attributes\n"
4115 "Name of the route map\n")
4116
4117ALIAS (no_bgp_network_mask,
4118 no_bgp_network_mask_backdoor_cmd,
4119 "no network A.B.C.D mask A.B.C.D backdoor",
4120 NO_STR
4121 "Specify a network to announce via BGP\n"
4122 "Network number\n"
4123 "Network mask\n"
4124 "Network mask\n"
4125 "Specify a BGP backdoor route\n")
4126
4127DEFUN (no_bgp_network_mask_natural,
4128 no_bgp_network_mask_natural_cmd,
4129 "no network A.B.C.D",
4130 NO_STR
4131 "Specify a network to announce via BGP\n"
4132 "Network number\n")
4133{
4134 int ret;
4135 char prefix_str[BUFSIZ];
4136
4137 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4138 if (! ret)
4139 {
4140 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4141 return CMD_WARNING;
4142 }
4143
4144 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4145 bgp_node_safi (vty));
4146}
4147
4148ALIAS (no_bgp_network_mask_natural,
4149 no_bgp_network_mask_natural_route_map_cmd,
4150 "no network A.B.C.D route-map WORD",
4151 NO_STR
4152 "Specify a network to announce via BGP\n"
4153 "Network number\n"
4154 "Route-map to modify the attributes\n"
4155 "Name of the route map\n")
4156
4157ALIAS (no_bgp_network_mask_natural,
4158 no_bgp_network_mask_natural_backdoor_cmd,
4159 "no network A.B.C.D backdoor",
4160 NO_STR
4161 "Specify a network to announce via BGP\n"
4162 "Network number\n"
4163 "Specify a BGP backdoor route\n")
4164
4165#ifdef HAVE_IPV6
4166DEFUN (ipv6_bgp_network,
4167 ipv6_bgp_network_cmd,
4168 "network X:X::X:X/M",
4169 "Specify a network to announce via BGP\n"
4170 "IPv6 prefix <network>/<length>\n")
4171{
Paul Jakma41367172007-08-06 15:24:51 +00004172 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004173 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004174}
4175
4176DEFUN (ipv6_bgp_network_route_map,
4177 ipv6_bgp_network_route_map_cmd,
4178 "network X:X::X:X/M route-map WORD",
4179 "Specify a network to announce via BGP\n"
4180 "IPv6 prefix <network>/<length>\n"
4181 "Route-map to modify the attributes\n"
4182 "Name of the route map\n")
4183{
4184 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004185 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004186}
4187
4188DEFUN (no_ipv6_bgp_network,
4189 no_ipv6_bgp_network_cmd,
4190 "no network X:X::X:X/M",
4191 NO_STR
4192 "Specify a network to announce via BGP\n"
4193 "IPv6 prefix <network>/<length>\n")
4194{
4195 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4196}
4197
4198ALIAS (no_ipv6_bgp_network,
4199 no_ipv6_bgp_network_route_map_cmd,
4200 "no network X:X::X:X/M route-map WORD",
4201 NO_STR
4202 "Specify a network to announce via BGP\n"
4203 "IPv6 prefix <network>/<length>\n"
4204 "Route-map to modify the attributes\n"
4205 "Name of the route map\n")
4206
4207ALIAS (ipv6_bgp_network,
4208 old_ipv6_bgp_network_cmd,
4209 "ipv6 bgp network X:X::X:X/M",
4210 IPV6_STR
4211 BGP_STR
4212 "Specify a network to announce via BGP\n"
4213 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4214
4215ALIAS (no_ipv6_bgp_network,
4216 old_no_ipv6_bgp_network_cmd,
4217 "no ipv6 bgp network X:X::X:X/M",
4218 NO_STR
4219 IPV6_STR
4220 BGP_STR
4221 "Specify a network to announce via BGP\n"
4222 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4223#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004224
4225/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4226ALIAS_DEPRECATED (bgp_network,
4227 bgp_network_ttl_cmd,
4228 "network A.B.C.D/M pathlimit <0-255>",
4229 "Specify a network to announce via BGP\n"
4230 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4231 "AS-Path hopcount limit attribute\n"
4232 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4233ALIAS_DEPRECATED (bgp_network_backdoor,
4234 bgp_network_backdoor_ttl_cmd,
4235 "network A.B.C.D/M backdoor pathlimit <0-255>",
4236 "Specify a network to announce via BGP\n"
4237 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4238 "Specify a BGP backdoor route\n"
4239 "AS-Path hopcount limit attribute\n"
4240 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4241ALIAS_DEPRECATED (bgp_network_mask,
4242 bgp_network_mask_ttl_cmd,
4243 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4244 "Specify a network to announce via BGP\n"
4245 "Network number\n"
4246 "Network mask\n"
4247 "Network mask\n"
4248 "AS-Path hopcount limit attribute\n"
4249 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4250ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4251 bgp_network_mask_backdoor_ttl_cmd,
4252 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4253 "Specify a network to announce via BGP\n"
4254 "Network number\n"
4255 "Network mask\n"
4256 "Network mask\n"
4257 "Specify a BGP backdoor route\n"
4258 "AS-Path hopcount limit attribute\n"
4259 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4260ALIAS_DEPRECATED (bgp_network_mask_natural,
4261 bgp_network_mask_natural_ttl_cmd,
4262 "network A.B.C.D pathlimit <0-255>",
4263 "Specify a network to announce via BGP\n"
4264 "Network number\n"
4265 "AS-Path hopcount limit attribute\n"
4266 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4267ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4268 bgp_network_mask_natural_backdoor_ttl_cmd,
4269 "network A.B.C.D backdoor pathlimit (1-255>",
4270 "Specify a network to announce via BGP\n"
4271 "Network number\n"
4272 "Specify a BGP backdoor route\n"
4273 "AS-Path hopcount limit attribute\n"
4274 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4275ALIAS_DEPRECATED (no_bgp_network,
4276 no_bgp_network_ttl_cmd,
4277 "no network A.B.C.D/M pathlimit <0-255>",
4278 NO_STR
4279 "Specify a network to announce via BGP\n"
4280 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4281 "AS-Path hopcount limit attribute\n"
4282 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4283ALIAS_DEPRECATED (no_bgp_network,
4284 no_bgp_network_backdoor_ttl_cmd,
4285 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4286 NO_STR
4287 "Specify a network to announce via BGP\n"
4288 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4289 "Specify a BGP backdoor route\n"
4290 "AS-Path hopcount limit attribute\n"
4291 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4292ALIAS_DEPRECATED (no_bgp_network,
4293 no_bgp_network_mask_ttl_cmd,
4294 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4295 NO_STR
4296 "Specify a network to announce via BGP\n"
4297 "Network number\n"
4298 "Network mask\n"
4299 "Network mask\n"
4300 "AS-Path hopcount limit attribute\n"
4301 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4302ALIAS_DEPRECATED (no_bgp_network_mask,
4303 no_bgp_network_mask_backdoor_ttl_cmd,
4304 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4305 NO_STR
4306 "Specify a network to announce via BGP\n"
4307 "Network number\n"
4308 "Network mask\n"
4309 "Network mask\n"
4310 "Specify a BGP backdoor route\n"
4311 "AS-Path hopcount limit attribute\n"
4312 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4313ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4314 no_bgp_network_mask_natural_ttl_cmd,
4315 "no network A.B.C.D pathlimit <0-255>",
4316 NO_STR
4317 "Specify a network to announce via BGP\n"
4318 "Network number\n"
4319 "AS-Path hopcount limit attribute\n"
4320 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4321ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4322 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4323 "no network A.B.C.D backdoor pathlimit <0-255>",
4324 NO_STR
4325 "Specify a network to announce via BGP\n"
4326 "Network number\n"
4327 "Specify a BGP backdoor route\n"
4328 "AS-Path hopcount limit attribute\n"
4329 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4330ALIAS_DEPRECATED (ipv6_bgp_network,
4331 ipv6_bgp_network_ttl_cmd,
4332 "network X:X::X:X/M pathlimit <0-255>",
4333 "Specify a network to announce via BGP\n"
4334 "IPv6 prefix <network>/<length>\n"
4335 "AS-Path hopcount limit attribute\n"
4336 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4337ALIAS_DEPRECATED (no_ipv6_bgp_network,
4338 no_ipv6_bgp_network_ttl_cmd,
4339 "no network X:X::X:X/M pathlimit <0-255>",
4340 NO_STR
4341 "Specify a network to announce via BGP\n"
4342 "IPv6 prefix <network>/<length>\n"
4343 "AS-Path hopcount limit attribute\n"
4344 "AS-Pathlimit TTL, in number of AS-Path hops\n")
paul718e3742002-12-13 20:15:29 +00004345
4346/* Aggreagete address:
4347
4348 advertise-map Set condition to advertise attribute
4349 as-set Generate AS set path information
4350 attribute-map Set attributes of aggregate
4351 route-map Set parameters of aggregate
4352 summary-only Filter more specific routes from updates
4353 suppress-map Conditionally filter more specific routes from updates
4354 <cr>
4355 */
4356struct bgp_aggregate
4357{
4358 /* Summary-only flag. */
4359 u_char summary_only;
4360
4361 /* AS set generation. */
4362 u_char as_set;
4363
4364 /* Route-map for aggregated route. */
4365 struct route_map *map;
4366
4367 /* Suppress-count. */
4368 unsigned long count;
4369
4370 /* SAFI configuration. */
4371 safi_t safi;
4372};
4373
paul94f2b392005-06-28 12:44:16 +00004374static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004375bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004376{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004377 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004378}
4379
paul94f2b392005-06-28 12:44:16 +00004380static void
paul718e3742002-12-13 20:15:29 +00004381bgp_aggregate_free (struct bgp_aggregate *aggregate)
4382{
4383 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4384}
4385
paul94f2b392005-06-28 12:44:16 +00004386static void
paul718e3742002-12-13 20:15:29 +00004387bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4388 afi_t afi, safi_t safi, struct bgp_info *del,
4389 struct bgp_aggregate *aggregate)
4390{
4391 struct bgp_table *table;
4392 struct bgp_node *top;
4393 struct bgp_node *rn;
4394 u_char origin;
4395 struct aspath *aspath = NULL;
4396 struct aspath *asmerge = NULL;
4397 struct community *community = NULL;
4398 struct community *commerge = NULL;
4399 struct in_addr nexthop;
4400 u_int32_t med = 0;
4401 struct bgp_info *ri;
4402 struct bgp_info *new;
4403 int first = 1;
4404 unsigned long match = 0;
4405
4406 /* Record adding route's nexthop and med. */
4407 if (rinew)
4408 {
4409 nexthop = rinew->attr->nexthop;
4410 med = rinew->attr->med;
4411 }
4412
4413 /* ORIGIN attribute: If at least one route among routes that are
4414 aggregated has ORIGIN with the value INCOMPLETE, then the
4415 aggregated route must have the ORIGIN attribute with the value
4416 INCOMPLETE. Otherwise, if at least one route among routes that
4417 are aggregated has ORIGIN with the value EGP, then the aggregated
4418 route must have the origin attribute with the value EGP. In all
4419 other case the value of the ORIGIN attribute of the aggregated
4420 route is INTERNAL. */
4421 origin = BGP_ORIGIN_IGP;
4422
4423 table = bgp->rib[afi][safi];
4424
4425 top = bgp_node_get (table, p);
4426 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4427 if (rn->p.prefixlen > p->prefixlen)
4428 {
4429 match = 0;
4430
4431 for (ri = rn->info; ri; ri = ri->next)
4432 {
4433 if (BGP_INFO_HOLDDOWN (ri))
4434 continue;
4435
4436 if (del && ri == del)
4437 continue;
4438
4439 if (! rinew && first)
4440 {
4441 nexthop = ri->attr->nexthop;
4442 med = ri->attr->med;
4443 first = 0;
4444 }
4445
4446#ifdef AGGREGATE_NEXTHOP_CHECK
4447 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4448 || ri->attr->med != med)
4449 {
4450 if (aspath)
4451 aspath_free (aspath);
4452 if (community)
4453 community_free (community);
4454 bgp_unlock_node (rn);
4455 bgp_unlock_node (top);
4456 return;
4457 }
4458#endif /* AGGREGATE_NEXTHOP_CHECK */
4459
4460 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4461 {
4462 if (aggregate->summary_only)
4463 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004464 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004465 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004466 match++;
4467 }
4468
4469 aggregate->count++;
4470
4471 if (aggregate->as_set)
4472 {
4473 if (origin < ri->attr->origin)
4474 origin = ri->attr->origin;
4475
4476 if (aspath)
4477 {
4478 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4479 aspath_free (aspath);
4480 aspath = asmerge;
4481 }
4482 else
4483 aspath = aspath_dup (ri->attr->aspath);
4484
4485 if (ri->attr->community)
4486 {
4487 if (community)
4488 {
4489 commerge = community_merge (community,
4490 ri->attr->community);
4491 community = community_uniq_sort (commerge);
4492 community_free (commerge);
4493 }
4494 else
4495 community = community_dup (ri->attr->community);
4496 }
4497 }
4498 }
4499 }
4500 if (match)
4501 bgp_process (bgp, rn, afi, safi);
4502 }
4503 bgp_unlock_node (top);
4504
4505 if (rinew)
4506 {
4507 aggregate->count++;
4508
4509 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004510 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004511
4512 if (aggregate->as_set)
4513 {
4514 if (origin < rinew->attr->origin)
4515 origin = rinew->attr->origin;
4516
4517 if (aspath)
4518 {
4519 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4520 aspath_free (aspath);
4521 aspath = asmerge;
4522 }
4523 else
4524 aspath = aspath_dup (rinew->attr->aspath);
4525
4526 if (rinew->attr->community)
4527 {
4528 if (community)
4529 {
4530 commerge = community_merge (community,
4531 rinew->attr->community);
4532 community = community_uniq_sort (commerge);
4533 community_free (commerge);
4534 }
4535 else
4536 community = community_dup (rinew->attr->community);
4537 }
4538 }
4539 }
4540
4541 if (aggregate->count > 0)
4542 {
4543 rn = bgp_node_get (table, p);
4544 new = bgp_info_new ();
4545 new->type = ZEBRA_ROUTE_BGP;
4546 new->sub_type = BGP_ROUTE_AGGREGATE;
4547 new->peer = bgp->peer_self;
4548 SET_FLAG (new->flags, BGP_INFO_VALID);
4549 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004550 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004551
4552 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004553 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004554 bgp_process (bgp, rn, afi, safi);
4555 }
4556 else
4557 {
4558 if (aspath)
4559 aspath_free (aspath);
4560 if (community)
4561 community_free (community);
4562 }
4563}
4564
4565void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4566 struct bgp_aggregate *);
4567
4568void
4569bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4570 struct bgp_info *ri, afi_t afi, safi_t safi)
4571{
4572 struct bgp_node *child;
4573 struct bgp_node *rn;
4574 struct bgp_aggregate *aggregate;
4575
4576 /* MPLS-VPN aggregation is not yet supported. */
4577 if (safi == SAFI_MPLS_VPN)
4578 return;
4579
4580 if (p->prefixlen == 0)
4581 return;
4582
4583 if (BGP_INFO_HOLDDOWN (ri))
4584 return;
4585
4586 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4587
4588 /* Aggregate address configuration check. */
4589 for (rn = child; rn; rn = rn->parent)
4590 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4591 {
4592 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004593 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004594 }
4595 bgp_unlock_node (child);
4596}
4597
4598void
4599bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4600 struct bgp_info *del, afi_t afi, safi_t safi)
4601{
4602 struct bgp_node *child;
4603 struct bgp_node *rn;
4604 struct bgp_aggregate *aggregate;
4605
4606 /* MPLS-VPN aggregation is not yet supported. */
4607 if (safi == SAFI_MPLS_VPN)
4608 return;
4609
4610 if (p->prefixlen == 0)
4611 return;
4612
4613 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4614
4615 /* Aggregate address configuration check. */
4616 for (rn = child; rn; rn = rn->parent)
4617 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4618 {
4619 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004620 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004621 }
4622 bgp_unlock_node (child);
4623}
4624
paul94f2b392005-06-28 12:44:16 +00004625static void
paul718e3742002-12-13 20:15:29 +00004626bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4627 struct bgp_aggregate *aggregate)
4628{
4629 struct bgp_table *table;
4630 struct bgp_node *top;
4631 struct bgp_node *rn;
4632 struct bgp_info *new;
4633 struct bgp_info *ri;
4634 unsigned long match;
4635 u_char origin = BGP_ORIGIN_IGP;
4636 struct aspath *aspath = NULL;
4637 struct aspath *asmerge = NULL;
4638 struct community *community = NULL;
4639 struct community *commerge = NULL;
4640
4641 table = bgp->rib[afi][safi];
4642
4643 /* Sanity check. */
4644 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4645 return;
4646 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4647 return;
4648
4649 /* If routes exists below this node, generate aggregate routes. */
4650 top = bgp_node_get (table, p);
4651 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4652 if (rn->p.prefixlen > p->prefixlen)
4653 {
4654 match = 0;
4655
4656 for (ri = rn->info; ri; ri = ri->next)
4657 {
4658 if (BGP_INFO_HOLDDOWN (ri))
4659 continue;
4660
4661 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4662 {
4663 /* summary-only aggregate route suppress aggregated
4664 route announcement. */
4665 if (aggregate->summary_only)
4666 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004667 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004668 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004669 match++;
4670 }
4671 /* as-set aggregate route generate origin, as path,
4672 community aggregation. */
4673 if (aggregate->as_set)
4674 {
4675 if (origin < ri->attr->origin)
4676 origin = ri->attr->origin;
4677
4678 if (aspath)
4679 {
4680 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4681 aspath_free (aspath);
4682 aspath = asmerge;
4683 }
4684 else
4685 aspath = aspath_dup (ri->attr->aspath);
4686
4687 if (ri->attr->community)
4688 {
4689 if (community)
4690 {
4691 commerge = community_merge (community,
4692 ri->attr->community);
4693 community = community_uniq_sort (commerge);
4694 community_free (commerge);
4695 }
4696 else
4697 community = community_dup (ri->attr->community);
4698 }
4699 }
4700 aggregate->count++;
4701 }
4702 }
4703
4704 /* If this node is suppressed, process the change. */
4705 if (match)
4706 bgp_process (bgp, rn, afi, safi);
4707 }
4708 bgp_unlock_node (top);
4709
4710 /* Add aggregate route to BGP table. */
4711 if (aggregate->count)
4712 {
4713 rn = bgp_node_get (table, p);
4714
4715 new = bgp_info_new ();
4716 new->type = ZEBRA_ROUTE_BGP;
4717 new->sub_type = BGP_ROUTE_AGGREGATE;
4718 new->peer = bgp->peer_self;
4719 SET_FLAG (new->flags, BGP_INFO_VALID);
4720 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004721 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004722
4723 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004724 bgp_unlock_node (rn);
4725
paul718e3742002-12-13 20:15:29 +00004726 /* Process change. */
4727 bgp_process (bgp, rn, afi, safi);
4728 }
4729}
4730
4731void
4732bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4733 safi_t safi, struct bgp_aggregate *aggregate)
4734{
4735 struct bgp_table *table;
4736 struct bgp_node *top;
4737 struct bgp_node *rn;
4738 struct bgp_info *ri;
4739 unsigned long match;
4740
4741 table = bgp->rib[afi][safi];
4742
4743 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4744 return;
4745 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4746 return;
4747
4748 /* If routes exists below this node, generate aggregate routes. */
4749 top = bgp_node_get (table, p);
4750 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4751 if (rn->p.prefixlen > p->prefixlen)
4752 {
4753 match = 0;
4754
4755 for (ri = rn->info; ri; ri = ri->next)
4756 {
4757 if (BGP_INFO_HOLDDOWN (ri))
4758 continue;
4759
4760 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4761 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004762 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004763 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004764 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004765
Paul Jakmafb982c22007-05-04 20:15:47 +00004766 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004767 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004768 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004769 match++;
4770 }
4771 }
4772 aggregate->count--;
4773 }
4774 }
4775
Paul Jakmafb982c22007-05-04 20:15:47 +00004776 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004777 if (match)
4778 bgp_process (bgp, rn, afi, safi);
4779 }
4780 bgp_unlock_node (top);
4781
4782 /* Delete aggregate route from BGP table. */
4783 rn = bgp_node_get (table, p);
4784
4785 for (ri = rn->info; ri; ri = ri->next)
4786 if (ri->peer == bgp->peer_self
4787 && ri->type == ZEBRA_ROUTE_BGP
4788 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4789 break;
4790
4791 /* Withdraw static BGP route from routing table. */
4792 if (ri)
4793 {
paul718e3742002-12-13 20:15:29 +00004794 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004795 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004796 }
4797
4798 /* Unlock bgp_node_lookup. */
4799 bgp_unlock_node (rn);
4800}
4801
4802/* Aggregate route attribute. */
4803#define AGGREGATE_SUMMARY_ONLY 1
4804#define AGGREGATE_AS_SET 1
4805
paul94f2b392005-06-28 12:44:16 +00004806static int
Robert Baysf6269b42010-08-05 10:26:28 -07004807bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4808 afi_t afi, safi_t safi)
4809{
4810 int ret;
4811 struct prefix p;
4812 struct bgp_node *rn;
4813 struct bgp *bgp;
4814 struct bgp_aggregate *aggregate;
4815
4816 /* Convert string to prefix structure. */
4817 ret = str2prefix (prefix_str, &p);
4818 if (!ret)
4819 {
4820 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4821 return CMD_WARNING;
4822 }
4823 apply_mask (&p);
4824
4825 /* Get BGP structure. */
4826 bgp = vty->index;
4827
4828 /* Old configuration check. */
4829 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4830 if (! rn)
4831 {
4832 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4833 VTY_NEWLINE);
4834 return CMD_WARNING;
4835 }
4836
4837 aggregate = rn->info;
4838 if (aggregate->safi & SAFI_UNICAST)
4839 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4840 if (aggregate->safi & SAFI_MULTICAST)
4841 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4842
4843 /* Unlock aggregate address configuration. */
4844 rn->info = NULL;
4845 bgp_aggregate_free (aggregate);
4846 bgp_unlock_node (rn);
4847 bgp_unlock_node (rn);
4848
4849 return CMD_SUCCESS;
4850}
4851
4852static int
4853bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004854 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004855 u_char summary_only, u_char as_set)
4856{
4857 int ret;
4858 struct prefix p;
4859 struct bgp_node *rn;
4860 struct bgp *bgp;
4861 struct bgp_aggregate *aggregate;
4862
4863 /* Convert string to prefix structure. */
4864 ret = str2prefix (prefix_str, &p);
4865 if (!ret)
4866 {
4867 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4868 return CMD_WARNING;
4869 }
4870 apply_mask (&p);
4871
4872 /* Get BGP structure. */
4873 bgp = vty->index;
4874
4875 /* Old configuration check. */
4876 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4877
4878 if (rn->info)
4879 {
4880 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004881 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004882 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4883 if (ret)
4884 {
Robert Bays368473f2010-08-05 10:26:29 -07004885 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4886 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004887 return CMD_WARNING;
4888 }
paul718e3742002-12-13 20:15:29 +00004889 }
4890
4891 /* Make aggregate address structure. */
4892 aggregate = bgp_aggregate_new ();
4893 aggregate->summary_only = summary_only;
4894 aggregate->as_set = as_set;
4895 aggregate->safi = safi;
4896 rn->info = aggregate;
4897
4898 /* Aggregate address insert into BGP routing table. */
4899 if (safi & SAFI_UNICAST)
4900 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4901 if (safi & SAFI_MULTICAST)
4902 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4903
4904 return CMD_SUCCESS;
4905}
4906
paul718e3742002-12-13 20:15:29 +00004907DEFUN (aggregate_address,
4908 aggregate_address_cmd,
4909 "aggregate-address A.B.C.D/M",
4910 "Configure BGP aggregate entries\n"
4911 "Aggregate prefix\n")
4912{
4913 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4914}
4915
4916DEFUN (aggregate_address_mask,
4917 aggregate_address_mask_cmd,
4918 "aggregate-address A.B.C.D A.B.C.D",
4919 "Configure BGP aggregate entries\n"
4920 "Aggregate address\n"
4921 "Aggregate mask\n")
4922{
4923 int ret;
4924 char prefix_str[BUFSIZ];
4925
4926 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4927
4928 if (! ret)
4929 {
4930 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4931 return CMD_WARNING;
4932 }
4933
4934 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4935 0, 0);
4936}
4937
4938DEFUN (aggregate_address_summary_only,
4939 aggregate_address_summary_only_cmd,
4940 "aggregate-address A.B.C.D/M summary-only",
4941 "Configure BGP aggregate entries\n"
4942 "Aggregate prefix\n"
4943 "Filter more specific routes from updates\n")
4944{
4945 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4946 AGGREGATE_SUMMARY_ONLY, 0);
4947}
4948
4949DEFUN (aggregate_address_mask_summary_only,
4950 aggregate_address_mask_summary_only_cmd,
4951 "aggregate-address A.B.C.D A.B.C.D summary-only",
4952 "Configure BGP aggregate entries\n"
4953 "Aggregate address\n"
4954 "Aggregate mask\n"
4955 "Filter more specific routes from updates\n")
4956{
4957 int ret;
4958 char prefix_str[BUFSIZ];
4959
4960 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4961
4962 if (! ret)
4963 {
4964 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4965 return CMD_WARNING;
4966 }
4967
4968 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4969 AGGREGATE_SUMMARY_ONLY, 0);
4970}
4971
4972DEFUN (aggregate_address_as_set,
4973 aggregate_address_as_set_cmd,
4974 "aggregate-address A.B.C.D/M as-set",
4975 "Configure BGP aggregate entries\n"
4976 "Aggregate prefix\n"
4977 "Generate AS set path information\n")
4978{
4979 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4980 0, AGGREGATE_AS_SET);
4981}
4982
4983DEFUN (aggregate_address_mask_as_set,
4984 aggregate_address_mask_as_set_cmd,
4985 "aggregate-address A.B.C.D A.B.C.D as-set",
4986 "Configure BGP aggregate entries\n"
4987 "Aggregate address\n"
4988 "Aggregate mask\n"
4989 "Generate AS set path information\n")
4990{
4991 int ret;
4992 char prefix_str[BUFSIZ];
4993
4994 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4995
4996 if (! ret)
4997 {
4998 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4999 return CMD_WARNING;
5000 }
5001
5002 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5003 0, AGGREGATE_AS_SET);
5004}
5005
5006
5007DEFUN (aggregate_address_as_set_summary,
5008 aggregate_address_as_set_summary_cmd,
5009 "aggregate-address A.B.C.D/M as-set summary-only",
5010 "Configure BGP aggregate entries\n"
5011 "Aggregate prefix\n"
5012 "Generate AS set path information\n"
5013 "Filter more specific routes from updates\n")
5014{
5015 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5016 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5017}
5018
5019ALIAS (aggregate_address_as_set_summary,
5020 aggregate_address_summary_as_set_cmd,
5021 "aggregate-address A.B.C.D/M summary-only as-set",
5022 "Configure BGP aggregate entries\n"
5023 "Aggregate prefix\n"
5024 "Filter more specific routes from updates\n"
5025 "Generate AS set path information\n")
5026
5027DEFUN (aggregate_address_mask_as_set_summary,
5028 aggregate_address_mask_as_set_summary_cmd,
5029 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5030 "Configure BGP aggregate entries\n"
5031 "Aggregate address\n"
5032 "Aggregate mask\n"
5033 "Generate AS set path information\n"
5034 "Filter more specific routes from updates\n")
5035{
5036 int ret;
5037 char prefix_str[BUFSIZ];
5038
5039 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5040
5041 if (! ret)
5042 {
5043 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5044 return CMD_WARNING;
5045 }
5046
5047 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5048 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5049}
5050
5051ALIAS (aggregate_address_mask_as_set_summary,
5052 aggregate_address_mask_summary_as_set_cmd,
5053 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5054 "Configure BGP aggregate entries\n"
5055 "Aggregate address\n"
5056 "Aggregate mask\n"
5057 "Filter more specific routes from updates\n"
5058 "Generate AS set path information\n")
5059
5060DEFUN (no_aggregate_address,
5061 no_aggregate_address_cmd,
5062 "no aggregate-address A.B.C.D/M",
5063 NO_STR
5064 "Configure BGP aggregate entries\n"
5065 "Aggregate prefix\n")
5066{
5067 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5068}
5069
5070ALIAS (no_aggregate_address,
5071 no_aggregate_address_summary_only_cmd,
5072 "no aggregate-address A.B.C.D/M summary-only",
5073 NO_STR
5074 "Configure BGP aggregate entries\n"
5075 "Aggregate prefix\n"
5076 "Filter more specific routes from updates\n")
5077
5078ALIAS (no_aggregate_address,
5079 no_aggregate_address_as_set_cmd,
5080 "no aggregate-address A.B.C.D/M as-set",
5081 NO_STR
5082 "Configure BGP aggregate entries\n"
5083 "Aggregate prefix\n"
5084 "Generate AS set path information\n")
5085
5086ALIAS (no_aggregate_address,
5087 no_aggregate_address_as_set_summary_cmd,
5088 "no aggregate-address A.B.C.D/M as-set summary-only",
5089 NO_STR
5090 "Configure BGP aggregate entries\n"
5091 "Aggregate prefix\n"
5092 "Generate AS set path information\n"
5093 "Filter more specific routes from updates\n")
5094
5095ALIAS (no_aggregate_address,
5096 no_aggregate_address_summary_as_set_cmd,
5097 "no aggregate-address A.B.C.D/M summary-only as-set",
5098 NO_STR
5099 "Configure BGP aggregate entries\n"
5100 "Aggregate prefix\n"
5101 "Filter more specific routes from updates\n"
5102 "Generate AS set path information\n")
5103
5104DEFUN (no_aggregate_address_mask,
5105 no_aggregate_address_mask_cmd,
5106 "no aggregate-address A.B.C.D A.B.C.D",
5107 NO_STR
5108 "Configure BGP aggregate entries\n"
5109 "Aggregate address\n"
5110 "Aggregate mask\n")
5111{
5112 int ret;
5113 char prefix_str[BUFSIZ];
5114
5115 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5116
5117 if (! ret)
5118 {
5119 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5120 return CMD_WARNING;
5121 }
5122
5123 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5124}
5125
5126ALIAS (no_aggregate_address_mask,
5127 no_aggregate_address_mask_summary_only_cmd,
5128 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5129 NO_STR
5130 "Configure BGP aggregate entries\n"
5131 "Aggregate address\n"
5132 "Aggregate mask\n"
5133 "Filter more specific routes from updates\n")
5134
5135ALIAS (no_aggregate_address_mask,
5136 no_aggregate_address_mask_as_set_cmd,
5137 "no aggregate-address A.B.C.D A.B.C.D as-set",
5138 NO_STR
5139 "Configure BGP aggregate entries\n"
5140 "Aggregate address\n"
5141 "Aggregate mask\n"
5142 "Generate AS set path information\n")
5143
5144ALIAS (no_aggregate_address_mask,
5145 no_aggregate_address_mask_as_set_summary_cmd,
5146 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5147 NO_STR
5148 "Configure BGP aggregate entries\n"
5149 "Aggregate address\n"
5150 "Aggregate mask\n"
5151 "Generate AS set path information\n"
5152 "Filter more specific routes from updates\n")
5153
5154ALIAS (no_aggregate_address_mask,
5155 no_aggregate_address_mask_summary_as_set_cmd,
5156 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5157 NO_STR
5158 "Configure BGP aggregate entries\n"
5159 "Aggregate address\n"
5160 "Aggregate mask\n"
5161 "Filter more specific routes from updates\n"
5162 "Generate AS set path information\n")
5163
5164#ifdef HAVE_IPV6
5165DEFUN (ipv6_aggregate_address,
5166 ipv6_aggregate_address_cmd,
5167 "aggregate-address X:X::X:X/M",
5168 "Configure BGP aggregate entries\n"
5169 "Aggregate prefix\n")
5170{
5171 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5172}
5173
5174DEFUN (ipv6_aggregate_address_summary_only,
5175 ipv6_aggregate_address_summary_only_cmd,
5176 "aggregate-address X:X::X:X/M summary-only",
5177 "Configure BGP aggregate entries\n"
5178 "Aggregate prefix\n"
5179 "Filter more specific routes from updates\n")
5180{
5181 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5182 AGGREGATE_SUMMARY_ONLY, 0);
5183}
5184
5185DEFUN (no_ipv6_aggregate_address,
5186 no_ipv6_aggregate_address_cmd,
5187 "no aggregate-address X:X::X:X/M",
5188 NO_STR
5189 "Configure BGP aggregate entries\n"
5190 "Aggregate prefix\n")
5191{
5192 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5193}
5194
5195DEFUN (no_ipv6_aggregate_address_summary_only,
5196 no_ipv6_aggregate_address_summary_only_cmd,
5197 "no aggregate-address X:X::X:X/M summary-only",
5198 NO_STR
5199 "Configure BGP aggregate entries\n"
5200 "Aggregate prefix\n"
5201 "Filter more specific routes from updates\n")
5202{
5203 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5204}
5205
5206ALIAS (ipv6_aggregate_address,
5207 old_ipv6_aggregate_address_cmd,
5208 "ipv6 bgp aggregate-address X:X::X:X/M",
5209 IPV6_STR
5210 BGP_STR
5211 "Configure BGP aggregate entries\n"
5212 "Aggregate prefix\n")
5213
5214ALIAS (ipv6_aggregate_address_summary_only,
5215 old_ipv6_aggregate_address_summary_only_cmd,
5216 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5217 IPV6_STR
5218 BGP_STR
5219 "Configure BGP aggregate entries\n"
5220 "Aggregate prefix\n"
5221 "Filter more specific routes from updates\n")
5222
5223ALIAS (no_ipv6_aggregate_address,
5224 old_no_ipv6_aggregate_address_cmd,
5225 "no ipv6 bgp aggregate-address X:X::X:X/M",
5226 NO_STR
5227 IPV6_STR
5228 BGP_STR
5229 "Configure BGP aggregate entries\n"
5230 "Aggregate prefix\n")
5231
5232ALIAS (no_ipv6_aggregate_address_summary_only,
5233 old_no_ipv6_aggregate_address_summary_only_cmd,
5234 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5235 NO_STR
5236 IPV6_STR
5237 BGP_STR
5238 "Configure BGP aggregate entries\n"
5239 "Aggregate prefix\n"
5240 "Filter more specific routes from updates\n")
5241#endif /* HAVE_IPV6 */
5242
5243/* Redistribute route treatment. */
5244void
5245bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5246 u_int32_t metric, u_char type)
5247{
5248 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005249 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005250 struct bgp_info *new;
5251 struct bgp_info *bi;
5252 struct bgp_info info;
5253 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005254 struct attr attr = { 0 };
5255 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005256 struct attr *new_attr;
5257 afi_t afi;
5258 int ret;
5259
5260 /* Make default attribute. */
5261 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5262 if (nexthop)
5263 attr.nexthop = *nexthop;
5264
5265 attr.med = metric;
5266 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5267
paul1eb8ef22005-04-07 07:30:20 +00005268 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005269 {
5270 afi = family2afi (p->family);
5271
5272 if (bgp->redist[afi][type])
5273 {
5274 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005275 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005276
5277 if (bgp->redist_metric_flag[afi][type])
5278 attr_new.med = bgp->redist_metric[afi][type];
5279
5280 /* Apply route-map. */
5281 if (bgp->rmap[afi][type].map)
5282 {
5283 info.peer = bgp->peer_self;
5284 info.attr = &attr_new;
5285
paulfee0f4c2004-09-13 05:12:46 +00005286 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5287
paul718e3742002-12-13 20:15:29 +00005288 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5289 &info);
paulfee0f4c2004-09-13 05:12:46 +00005290
5291 bgp->peer_self->rmap_type = 0;
5292
paul718e3742002-12-13 20:15:29 +00005293 if (ret == RMAP_DENYMATCH)
5294 {
5295 /* Free uninterned attribute. */
5296 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005297 bgp_attr_extra_free (&attr_new);
5298
paul718e3742002-12-13 20:15:29 +00005299 /* Unintern original. */
5300 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005301 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005302 bgp_redistribute_delete (p, type);
5303 return;
5304 }
5305 }
5306
Paul Jakmafb982c22007-05-04 20:15:47 +00005307 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5308 afi, SAFI_UNICAST, p, NULL);
5309
paul718e3742002-12-13 20:15:29 +00005310 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005311 bgp_attr_extra_free (&attr_new);
5312
paul718e3742002-12-13 20:15:29 +00005313 for (bi = bn->info; bi; bi = bi->next)
5314 if (bi->peer == bgp->peer_self
5315 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5316 break;
5317
5318 if (bi)
5319 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005320 if (attrhash_cmp (bi->attr, new_attr) &&
5321 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005322 {
5323 bgp_attr_unintern (new_attr);
5324 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005325 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005326 bgp_unlock_node (bn);
5327 return;
5328 }
5329 else
5330 {
5331 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005332 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005333
5334 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005335 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5336 bgp_info_restore(bn, bi);
5337 else
5338 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005339 bgp_attr_unintern (bi->attr);
5340 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005341 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005342
5343 /* Process change. */
5344 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5345 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5346 bgp_unlock_node (bn);
5347 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005348 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005349 return;
5350 }
5351 }
5352
5353 new = bgp_info_new ();
5354 new->type = type;
5355 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5356 new->peer = bgp->peer_self;
5357 SET_FLAG (new->flags, BGP_INFO_VALID);
5358 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005359 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005360
5361 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5362 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005363 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005364 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5365 }
5366 }
5367
5368 /* Unintern original. */
5369 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005370 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005371}
5372
5373void
5374bgp_redistribute_delete (struct prefix *p, u_char type)
5375{
5376 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005377 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005378 afi_t afi;
5379 struct bgp_node *rn;
5380 struct bgp_info *ri;
5381
paul1eb8ef22005-04-07 07:30:20 +00005382 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005383 {
5384 afi = family2afi (p->family);
5385
5386 if (bgp->redist[afi][type])
5387 {
paulfee0f4c2004-09-13 05:12:46 +00005388 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005389
5390 for (ri = rn->info; ri; ri = ri->next)
5391 if (ri->peer == bgp->peer_self
5392 && ri->type == type)
5393 break;
5394
5395 if (ri)
5396 {
5397 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005398 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005399 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005400 }
5401 bgp_unlock_node (rn);
5402 }
5403 }
5404}
5405
5406/* Withdraw specified route type's route. */
5407void
5408bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5409{
5410 struct bgp_node *rn;
5411 struct bgp_info *ri;
5412 struct bgp_table *table;
5413
5414 table = bgp->rib[afi][SAFI_UNICAST];
5415
5416 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5417 {
5418 for (ri = rn->info; ri; ri = ri->next)
5419 if (ri->peer == bgp->peer_self
5420 && ri->type == type)
5421 break;
5422
5423 if (ri)
5424 {
5425 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005426 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005427 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005428 }
5429 }
5430}
5431
5432/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005433static void
paul718e3742002-12-13 20:15:29 +00005434route_vty_out_route (struct prefix *p, struct vty *vty)
5435{
5436 int len;
5437 u_int32_t destination;
5438 char buf[BUFSIZ];
5439
5440 if (p->family == AF_INET)
5441 {
5442 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5443 destination = ntohl (p->u.prefix4.s_addr);
5444
5445 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5446 || (IN_CLASSB (destination) && p->prefixlen == 16)
5447 || (IN_CLASSA (destination) && p->prefixlen == 8)
5448 || p->u.prefix4.s_addr == 0)
5449 {
5450 /* When mask is natural, mask is not displayed. */
5451 }
5452 else
5453 len += vty_out (vty, "/%d", p->prefixlen);
5454 }
5455 else
5456 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5457 p->prefixlen);
5458
5459 len = 17 - len;
5460 if (len < 1)
5461 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5462 else
5463 vty_out (vty, "%*s", len, " ");
5464}
5465
paul718e3742002-12-13 20:15:29 +00005466enum bgp_display_type
5467{
5468 normal_list,
5469};
5470
paulb40d9392005-08-22 22:34:41 +00005471/* Print the short form route status for a bgp_info */
5472static void
5473route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005474{
paulb40d9392005-08-22 22:34:41 +00005475 /* Route status display. */
5476 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5477 vty_out (vty, "R");
5478 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005479 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005480 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005481 vty_out (vty, "s");
5482 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5483 vty_out (vty, "*");
5484 else
5485 vty_out (vty, " ");
5486
5487 /* Selected */
5488 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5489 vty_out (vty, "h");
5490 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5491 vty_out (vty, "d");
5492 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5493 vty_out (vty, ">");
5494 else
5495 vty_out (vty, " ");
5496
5497 /* Internal route. */
5498 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5499 vty_out (vty, "i");
5500 else
paulb40d9392005-08-22 22:34:41 +00005501 vty_out (vty, " ");
5502}
5503
5504/* called from terminal list command */
5505void
5506route_vty_out (struct vty *vty, struct prefix *p,
5507 struct bgp_info *binfo, int display, safi_t safi)
5508{
5509 struct attr *attr;
5510
5511 /* short status lead text */
5512 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005513
5514 /* print prefix and mask */
5515 if (! display)
5516 route_vty_out_route (p, vty);
5517 else
5518 vty_out (vty, "%*s", 17, " ");
5519
5520 /* Print attribute */
5521 attr = binfo->attr;
5522 if (attr)
5523 {
5524 if (p->family == AF_INET)
5525 {
5526 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005527 vty_out (vty, "%-16s",
5528 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005529 else
5530 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5531 }
5532#ifdef HAVE_IPV6
5533 else if (p->family == AF_INET6)
5534 {
5535 int len;
5536 char buf[BUFSIZ];
5537
5538 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005539 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5540 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005541 len = 16 - len;
5542 if (len < 1)
5543 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5544 else
5545 vty_out (vty, "%*s", len, " ");
5546 }
5547#endif /* HAVE_IPV6 */
5548
5549 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005550 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005551 else
5552 vty_out (vty, " ");
5553
5554 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005555 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005556 else
5557 vty_out (vty, " ");
5558
Paul Jakmafb982c22007-05-04 20:15:47 +00005559 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005560
Paul Jakmab2518c12006-05-12 23:48:40 +00005561 /* Print aspath */
5562 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005563 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005564
Paul Jakmab2518c12006-05-12 23:48:40 +00005565 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005566 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005567 }
paul718e3742002-12-13 20:15:29 +00005568 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005569}
5570
5571/* called from terminal list command */
5572void
5573route_vty_out_tmp (struct vty *vty, struct prefix *p,
5574 struct attr *attr, safi_t safi)
5575{
5576 /* Route status display. */
5577 vty_out (vty, "*");
5578 vty_out (vty, ">");
5579 vty_out (vty, " ");
5580
5581 /* print prefix and mask */
5582 route_vty_out_route (p, vty);
5583
5584 /* Print attribute */
5585 if (attr)
5586 {
5587 if (p->family == AF_INET)
5588 {
5589 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005590 vty_out (vty, "%-16s",
5591 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005592 else
5593 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5594 }
5595#ifdef HAVE_IPV6
5596 else if (p->family == AF_INET6)
5597 {
5598 int len;
5599 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005600
5601 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005602
5603 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005604 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5605 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005606 len = 16 - len;
5607 if (len < 1)
5608 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5609 else
5610 vty_out (vty, "%*s", len, " ");
5611 }
5612#endif /* HAVE_IPV6 */
5613
5614 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005615 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005616 else
5617 vty_out (vty, " ");
5618
5619 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005620 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005621 else
5622 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005623
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005624 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005625
Paul Jakmab2518c12006-05-12 23:48:40 +00005626 /* Print aspath */
5627 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005628 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005629
Paul Jakmab2518c12006-05-12 23:48:40 +00005630 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005631 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005632 }
paul718e3742002-12-13 20:15:29 +00005633
5634 vty_out (vty, "%s", VTY_NEWLINE);
5635}
5636
ajs5a646652004-11-05 01:25:55 +00005637void
paul718e3742002-12-13 20:15:29 +00005638route_vty_out_tag (struct vty *vty, struct prefix *p,
5639 struct bgp_info *binfo, int display, safi_t safi)
5640{
5641 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005642 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005643
5644 if (!binfo->extra)
5645 return;
5646
paulb40d9392005-08-22 22:34:41 +00005647 /* short status lead text */
5648 route_vty_short_status_out (vty, binfo);
5649
paul718e3742002-12-13 20:15:29 +00005650 /* print prefix and mask */
5651 if (! display)
5652 route_vty_out_route (p, vty);
5653 else
5654 vty_out (vty, "%*s", 17, " ");
5655
5656 /* Print attribute */
5657 attr = binfo->attr;
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 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005671 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005672 char buf[BUFSIZ];
5673 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005674 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005675 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005676 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5677 buf, BUFSIZ));
5678 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005679 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005680 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5681 buf, BUFSIZ),
5682 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5683 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005684
5685 }
5686#endif /* HAVE_IPV6 */
5687 }
5688
Paul Jakmafb982c22007-05-04 20:15:47 +00005689 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005690
5691 vty_out (vty, "notag/%d", label);
5692
5693 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005694}
5695
5696/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005697static void
paul718e3742002-12-13 20:15:29 +00005698damp_route_vty_out (struct vty *vty, struct prefix *p,
5699 struct bgp_info *binfo, int display, safi_t safi)
5700{
5701 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005702 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005703 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005704
paulb40d9392005-08-22 22:34:41 +00005705 /* short status lead text */
5706 route_vty_short_status_out (vty, binfo);
5707
paul718e3742002-12-13 20:15:29 +00005708 /* print prefix and mask */
5709 if (! display)
5710 route_vty_out_route (p, vty);
5711 else
5712 vty_out (vty, "%*s", 17, " ");
5713
5714 len = vty_out (vty, "%s", binfo->peer->host);
5715 len = 17 - len;
5716 if (len < 1)
5717 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5718 else
5719 vty_out (vty, "%*s", len, " ");
5720
Chris Caputo50aef6f2009-06-23 06:06:49 +00005721 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005722
5723 /* Print attribute */
5724 attr = binfo->attr;
5725 if (attr)
5726 {
5727 /* Print aspath */
5728 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005729 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005730
5731 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005732 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005733 }
5734 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005735}
5736
paul718e3742002-12-13 20:15:29 +00005737/* flap route */
ajs5a646652004-11-05 01:25:55 +00005738static void
paul718e3742002-12-13 20:15:29 +00005739flap_route_vty_out (struct vty *vty, struct prefix *p,
5740 struct bgp_info *binfo, int display, safi_t safi)
5741{
5742 struct attr *attr;
5743 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005744 char timebuf[BGP_UPTIME_LEN];
5745 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005746
5747 if (!binfo->extra)
5748 return;
5749
5750 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005751
paulb40d9392005-08-22 22:34:41 +00005752 /* short status lead text */
5753 route_vty_short_status_out (vty, binfo);
5754
paul718e3742002-12-13 20:15:29 +00005755 /* print prefix and mask */
5756 if (! display)
5757 route_vty_out_route (p, vty);
5758 else
5759 vty_out (vty, "%*s", 17, " ");
5760
5761 len = vty_out (vty, "%s", binfo->peer->host);
5762 len = 16 - len;
5763 if (len < 1)
5764 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5765 else
5766 vty_out (vty, "%*s", len, " ");
5767
5768 len = vty_out (vty, "%d", bdi->flap);
5769 len = 5 - len;
5770 if (len < 1)
5771 vty_out (vty, " ");
5772 else
5773 vty_out (vty, "%*s ", len, " ");
5774
5775 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5776 timebuf, BGP_UPTIME_LEN));
5777
5778 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5779 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005780 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005781 else
5782 vty_out (vty, "%*s ", 8, " ");
5783
5784 /* Print attribute */
5785 attr = binfo->attr;
5786 if (attr)
5787 {
5788 /* Print aspath */
5789 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005790 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005791
5792 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005793 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005794 }
5795 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005796}
5797
paul94f2b392005-06-28 12:44:16 +00005798static void
paul718e3742002-12-13 20:15:29 +00005799route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5800 struct bgp_info *binfo, afi_t afi, safi_t safi)
5801{
5802 char buf[INET6_ADDRSTRLEN];
5803 char buf1[BUFSIZ];
5804 struct attr *attr;
5805 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005806#ifdef HAVE_CLOCK_MONOTONIC
5807 time_t tbuf;
5808#endif
paul718e3742002-12-13 20:15:29 +00005809
5810 attr = binfo->attr;
5811
5812 if (attr)
5813 {
5814 /* Line1 display AS-path, Aggregator */
5815 if (attr->aspath)
5816 {
5817 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005818 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005819 vty_out (vty, "Local");
5820 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005821 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005822 }
5823
paulb40d9392005-08-22 22:34:41 +00005824 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5825 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005826 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5827 vty_out (vty, ", (stale)");
5828 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005829 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005830 attr->extra->aggregator_as,
5831 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005832 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5833 vty_out (vty, ", (Received from a RR-client)");
5834 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5835 vty_out (vty, ", (Received from a RS-client)");
5836 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5837 vty_out (vty, ", (history entry)");
5838 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5839 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005840 vty_out (vty, "%s", VTY_NEWLINE);
5841
5842 /* Line2 display Next-hop, Neighbor, Router-id */
5843 if (p->family == AF_INET)
5844 {
5845 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005846 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005847 inet_ntoa (attr->nexthop));
5848 }
5849#ifdef HAVE_IPV6
5850 else
5851 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005852 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005853 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005854 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005855 buf, INET6_ADDRSTRLEN));
5856 }
5857#endif /* HAVE_IPV6 */
5858
5859 if (binfo->peer == bgp->peer_self)
5860 {
5861 vty_out (vty, " from %s ",
5862 p->family == AF_INET ? "0.0.0.0" : "::");
5863 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5864 }
5865 else
5866 {
5867 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5868 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005869 else if (binfo->extra && binfo->extra->igpmetric)
5870 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005871 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005872 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005873 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005874 else
5875 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5876 }
5877 vty_out (vty, "%s", VTY_NEWLINE);
5878
5879#ifdef HAVE_IPV6
5880 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005881 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005882 {
5883 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005884 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005885 buf, INET6_ADDRSTRLEN),
5886 VTY_NEWLINE);
5887 }
5888#endif /* HAVE_IPV6 */
5889
5890 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5891 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5892
5893 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005894 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005895
5896 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005897 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005898 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005899 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005900
Paul Jakmafb982c22007-05-04 20:15:47 +00005901 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005902 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005903
5904 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5905 vty_out (vty, ", valid");
5906
5907 if (binfo->peer != bgp->peer_self)
5908 {
5909 if (binfo->peer->as == binfo->peer->local_as)
5910 vty_out (vty, ", internal");
5911 else
5912 vty_out (vty, ", %s",
5913 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5914 }
5915 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5916 vty_out (vty, ", aggregated, local");
5917 else if (binfo->type != ZEBRA_ROUTE_BGP)
5918 vty_out (vty, ", sourced");
5919 else
5920 vty_out (vty, ", sourced, local");
5921
5922 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5923 vty_out (vty, ", atomic-aggregate");
5924
5925 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5926 vty_out (vty, ", best");
5927
5928 vty_out (vty, "%s", VTY_NEWLINE);
5929
5930 /* Line 4 display Community */
5931 if (attr->community)
5932 vty_out (vty, " Community: %s%s", attr->community->str,
5933 VTY_NEWLINE);
5934
5935 /* Line 5 display Extended-community */
5936 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00005937 vty_out (vty, " Extended Community: %s%s",
5938 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005939
5940 /* Line 6 display Originator, Cluster-id */
5941 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5942 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5943 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005944 assert (attr->extra);
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, " Originator: %s",
5947 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005948
5949 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5950 {
5951 int i;
5952 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005953 for (i = 0; i < attr->extra->cluster->length / 4; i++)
5954 vty_out (vty, "%s ",
5955 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00005956 }
5957 vty_out (vty, "%s", VTY_NEWLINE);
5958 }
Paul Jakma41367172007-08-06 15:24:51 +00005959
Paul Jakmafb982c22007-05-04 20:15:47 +00005960 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00005961 bgp_damp_info_vty (vty, binfo);
5962
5963 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03005964#ifdef HAVE_CLOCK_MONOTONIC
5965 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04005966 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03005967#else
5968 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
5969#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00005970 }
5971 vty_out (vty, "%s", VTY_NEWLINE);
5972}
5973
paulb40d9392005-08-22 22:34:41 +00005974#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 +00005975#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005976#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5977#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5978#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5979
5980enum bgp_show_type
5981{
5982 bgp_show_type_normal,
5983 bgp_show_type_regexp,
5984 bgp_show_type_prefix_list,
5985 bgp_show_type_filter_list,
5986 bgp_show_type_route_map,
5987 bgp_show_type_neighbor,
5988 bgp_show_type_cidr_only,
5989 bgp_show_type_prefix_longer,
5990 bgp_show_type_community_all,
5991 bgp_show_type_community,
5992 bgp_show_type_community_exact,
5993 bgp_show_type_community_list,
5994 bgp_show_type_community_list_exact,
5995 bgp_show_type_flap_statistics,
5996 bgp_show_type_flap_address,
5997 bgp_show_type_flap_prefix,
5998 bgp_show_type_flap_cidr_only,
5999 bgp_show_type_flap_regexp,
6000 bgp_show_type_flap_filter_list,
6001 bgp_show_type_flap_prefix_list,
6002 bgp_show_type_flap_prefix_longer,
6003 bgp_show_type_flap_route_map,
6004 bgp_show_type_flap_neighbor,
6005 bgp_show_type_dampend_paths,
6006 bgp_show_type_damp_neighbor
6007};
6008
ajs5a646652004-11-05 01:25:55 +00006009static int
paulfee0f4c2004-09-13 05:12:46 +00006010bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006011 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006012{
paul718e3742002-12-13 20:15:29 +00006013 struct bgp_info *ri;
6014 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006015 int header = 1;
paul718e3742002-12-13 20:15:29 +00006016 int display;
ajs5a646652004-11-05 01:25:55 +00006017 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006018
6019 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006020 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006021
paul718e3742002-12-13 20:15:29 +00006022 /* Start processing of routes. */
6023 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6024 if (rn->info != NULL)
6025 {
6026 display = 0;
6027
6028 for (ri = rn->info; ri; ri = ri->next)
6029 {
ajs5a646652004-11-05 01:25:55 +00006030 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006031 || type == bgp_show_type_flap_address
6032 || type == bgp_show_type_flap_prefix
6033 || type == bgp_show_type_flap_cidr_only
6034 || type == bgp_show_type_flap_regexp
6035 || type == bgp_show_type_flap_filter_list
6036 || type == bgp_show_type_flap_prefix_list
6037 || type == bgp_show_type_flap_prefix_longer
6038 || type == bgp_show_type_flap_route_map
6039 || type == bgp_show_type_flap_neighbor
6040 || type == bgp_show_type_dampend_paths
6041 || type == bgp_show_type_damp_neighbor)
6042 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006043 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006044 continue;
6045 }
6046 if (type == bgp_show_type_regexp
6047 || type == bgp_show_type_flap_regexp)
6048 {
ajs5a646652004-11-05 01:25:55 +00006049 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006050
6051 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6052 continue;
6053 }
6054 if (type == bgp_show_type_prefix_list
6055 || type == bgp_show_type_flap_prefix_list)
6056 {
ajs5a646652004-11-05 01:25:55 +00006057 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006058
6059 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6060 continue;
6061 }
6062 if (type == bgp_show_type_filter_list
6063 || type == bgp_show_type_flap_filter_list)
6064 {
ajs5a646652004-11-05 01:25:55 +00006065 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006066
6067 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6068 continue;
6069 }
6070 if (type == bgp_show_type_route_map
6071 || type == bgp_show_type_flap_route_map)
6072 {
ajs5a646652004-11-05 01:25:55 +00006073 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006074 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006075 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006076 int ret;
6077
Paul Jakmafb982c22007-05-04 20:15:47 +00006078 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006079 binfo.peer = ri->peer;
6080 binfo.attr = &dummy_attr;
6081
6082 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006083
6084 bgp_attr_extra_free (&dummy_attr);
6085
paul718e3742002-12-13 20:15:29 +00006086 if (ret == RMAP_DENYMATCH)
6087 continue;
6088 }
6089 if (type == bgp_show_type_neighbor
6090 || type == bgp_show_type_flap_neighbor
6091 || type == bgp_show_type_damp_neighbor)
6092 {
ajs5a646652004-11-05 01:25:55 +00006093 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006094
6095 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6096 continue;
6097 }
6098 if (type == bgp_show_type_cidr_only
6099 || type == bgp_show_type_flap_cidr_only)
6100 {
6101 u_int32_t destination;
6102
6103 destination = ntohl (rn->p.u.prefix4.s_addr);
6104 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6105 continue;
6106 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6107 continue;
6108 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6109 continue;
6110 }
6111 if (type == bgp_show_type_prefix_longer
6112 || type == bgp_show_type_flap_prefix_longer)
6113 {
ajs5a646652004-11-05 01:25:55 +00006114 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006115
6116 if (! prefix_match (p, &rn->p))
6117 continue;
6118 }
6119 if (type == bgp_show_type_community_all)
6120 {
6121 if (! ri->attr->community)
6122 continue;
6123 }
6124 if (type == bgp_show_type_community)
6125 {
ajs5a646652004-11-05 01:25:55 +00006126 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006127
6128 if (! ri->attr->community ||
6129 ! community_match (ri->attr->community, com))
6130 continue;
6131 }
6132 if (type == bgp_show_type_community_exact)
6133 {
ajs5a646652004-11-05 01:25:55 +00006134 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006135
6136 if (! ri->attr->community ||
6137 ! community_cmp (ri->attr->community, com))
6138 continue;
6139 }
6140 if (type == bgp_show_type_community_list)
6141 {
ajs5a646652004-11-05 01:25:55 +00006142 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006143
6144 if (! community_list_match (ri->attr->community, list))
6145 continue;
6146 }
6147 if (type == bgp_show_type_community_list_exact)
6148 {
ajs5a646652004-11-05 01:25:55 +00006149 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006150
6151 if (! community_list_exact_match (ri->attr->community, list))
6152 continue;
6153 }
6154 if (type == bgp_show_type_flap_address
6155 || type == bgp_show_type_flap_prefix)
6156 {
ajs5a646652004-11-05 01:25:55 +00006157 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006158
6159 if (! prefix_match (&rn->p, p))
6160 continue;
6161
6162 if (type == bgp_show_type_flap_prefix)
6163 if (p->prefixlen != rn->p.prefixlen)
6164 continue;
6165 }
6166 if (type == bgp_show_type_dampend_paths
6167 || type == bgp_show_type_damp_neighbor)
6168 {
6169 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6170 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6171 continue;
6172 }
6173
6174 if (header)
6175 {
hasso93406d82005-02-02 14:40:33 +00006176 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6177 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6178 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006179 if (type == bgp_show_type_dampend_paths
6180 || type == bgp_show_type_damp_neighbor)
6181 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6182 else if (type == bgp_show_type_flap_statistics
6183 || type == bgp_show_type_flap_address
6184 || type == bgp_show_type_flap_prefix
6185 || type == bgp_show_type_flap_cidr_only
6186 || type == bgp_show_type_flap_regexp
6187 || type == bgp_show_type_flap_filter_list
6188 || type == bgp_show_type_flap_prefix_list
6189 || type == bgp_show_type_flap_prefix_longer
6190 || type == bgp_show_type_flap_route_map
6191 || type == bgp_show_type_flap_neighbor)
6192 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6193 else
6194 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006195 header = 0;
6196 }
6197
6198 if (type == bgp_show_type_dampend_paths
6199 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006200 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006201 else if (type == bgp_show_type_flap_statistics
6202 || type == bgp_show_type_flap_address
6203 || type == bgp_show_type_flap_prefix
6204 || type == bgp_show_type_flap_cidr_only
6205 || type == bgp_show_type_flap_regexp
6206 || type == bgp_show_type_flap_filter_list
6207 || type == bgp_show_type_flap_prefix_list
6208 || type == bgp_show_type_flap_prefix_longer
6209 || type == bgp_show_type_flap_route_map
6210 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006211 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006212 else
ajs5a646652004-11-05 01:25:55 +00006213 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006214 display++;
6215 }
6216 if (display)
ajs5a646652004-11-05 01:25:55 +00006217 output_count++;
paul718e3742002-12-13 20:15:29 +00006218 }
6219
6220 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006221 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006222 {
6223 if (type == bgp_show_type_normal)
6224 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6225 }
6226 else
6227 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006228 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006229
6230 return CMD_SUCCESS;
6231}
6232
ajs5a646652004-11-05 01:25:55 +00006233static int
paulfee0f4c2004-09-13 05:12:46 +00006234bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006235 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006236{
6237 struct bgp_table *table;
6238
6239 if (bgp == NULL) {
6240 bgp = bgp_get_default ();
6241 }
6242
6243 if (bgp == NULL)
6244 {
6245 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6246 return CMD_WARNING;
6247 }
6248
6249
6250 table = bgp->rib[afi][safi];
6251
ajs5a646652004-11-05 01:25:55 +00006252 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006253}
6254
paul718e3742002-12-13 20:15:29 +00006255/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006256static void
paul718e3742002-12-13 20:15:29 +00006257route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6258 struct bgp_node *rn,
6259 struct prefix_rd *prd, afi_t afi, safi_t safi)
6260{
6261 struct bgp_info *ri;
6262 struct prefix *p;
6263 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006264 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006265 char buf1[INET6_ADDRSTRLEN];
6266 char buf2[INET6_ADDRSTRLEN];
6267 int count = 0;
6268 int best = 0;
6269 int suppress = 0;
6270 int no_export = 0;
6271 int no_advertise = 0;
6272 int local_as = 0;
6273 int first = 0;
6274
6275 p = &rn->p;
6276 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6277 (safi == SAFI_MPLS_VPN ?
6278 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6279 safi == SAFI_MPLS_VPN ? ":" : "",
6280 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6281 p->prefixlen, VTY_NEWLINE);
6282
6283 for (ri = rn->info; ri; ri = ri->next)
6284 {
6285 count++;
6286 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6287 {
6288 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006289 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006290 suppress = 1;
6291 if (ri->attr->community != NULL)
6292 {
6293 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6294 no_advertise = 1;
6295 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6296 no_export = 1;
6297 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6298 local_as = 1;
6299 }
6300 }
6301 }
6302
6303 vty_out (vty, "Paths: (%d available", count);
6304 if (best)
6305 {
6306 vty_out (vty, ", best #%d", best);
6307 if (safi == SAFI_UNICAST)
6308 vty_out (vty, ", table Default-IP-Routing-Table");
6309 }
6310 else
6311 vty_out (vty, ", no best path");
6312 if (no_advertise)
6313 vty_out (vty, ", not advertised to any peer");
6314 else if (no_export)
6315 vty_out (vty, ", not advertised to EBGP peer");
6316 else if (local_as)
6317 vty_out (vty, ", not advertised outside local AS");
6318 if (suppress)
6319 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6320 vty_out (vty, ")%s", VTY_NEWLINE);
6321
6322 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006323 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006324 {
6325 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6326 {
6327 if (! first)
6328 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6329 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6330 first = 1;
6331 }
6332 }
6333 if (! first)
6334 vty_out (vty, " Not advertised to any peer");
6335 vty_out (vty, "%s", VTY_NEWLINE);
6336}
6337
6338/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006339static int
paulfee0f4c2004-09-13 05:12:46 +00006340bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006341 struct bgp_table *rib, const char *ip_str,
6342 afi_t afi, safi_t safi, struct prefix_rd *prd,
6343 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006344{
6345 int ret;
6346 int header;
6347 int display = 0;
6348 struct prefix match;
6349 struct bgp_node *rn;
6350 struct bgp_node *rm;
6351 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006352 struct bgp_table *table;
6353
paul718e3742002-12-13 20:15:29 +00006354 /* Check IP address argument. */
6355 ret = str2prefix (ip_str, &match);
6356 if (! ret)
6357 {
6358 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6359 return CMD_WARNING;
6360 }
6361
6362 match.family = afi2family (afi);
6363
6364 if (safi == SAFI_MPLS_VPN)
6365 {
paulfee0f4c2004-09-13 05:12:46 +00006366 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006367 {
6368 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6369 continue;
6370
6371 if ((table = rn->info) != NULL)
6372 {
6373 header = 1;
6374
6375 if ((rm = bgp_node_match (table, &match)) != NULL)
6376 {
6377 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006378 {
6379 bgp_unlock_node (rm);
6380 continue;
6381 }
paul718e3742002-12-13 20:15:29 +00006382
6383 for (ri = rm->info; ri; ri = ri->next)
6384 {
6385 if (header)
6386 {
6387 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6388 AFI_IP, SAFI_MPLS_VPN);
6389
6390 header = 0;
6391 }
6392 display++;
6393 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6394 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006395
6396 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006397 }
6398 }
6399 }
6400 }
6401 else
6402 {
6403 header = 1;
6404
paulfee0f4c2004-09-13 05:12:46 +00006405 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006406 {
6407 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6408 {
6409 for (ri = rn->info; ri; ri = ri->next)
6410 {
6411 if (header)
6412 {
6413 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6414 header = 0;
6415 }
6416 display++;
6417 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6418 }
6419 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006420
6421 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006422 }
6423 }
6424
6425 if (! display)
6426 {
6427 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6428 return CMD_WARNING;
6429 }
6430
6431 return CMD_SUCCESS;
6432}
6433
paulfee0f4c2004-09-13 05:12:46 +00006434/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006435static int
paulfd79ac92004-10-13 05:06:08 +00006436bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006437 afi_t afi, safi_t safi, struct prefix_rd *prd,
6438 int prefix_check)
6439{
6440 struct bgp *bgp;
6441
6442 /* BGP structure lookup. */
6443 if (view_name)
6444 {
6445 bgp = bgp_lookup_by_name (view_name);
6446 if (bgp == NULL)
6447 {
6448 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6449 return CMD_WARNING;
6450 }
6451 }
6452 else
6453 {
6454 bgp = bgp_get_default ();
6455 if (bgp == NULL)
6456 {
6457 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6458 return CMD_WARNING;
6459 }
6460 }
6461
6462 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6463 afi, safi, prd, prefix_check);
6464}
6465
paul718e3742002-12-13 20:15:29 +00006466/* BGP route print out function. */
6467DEFUN (show_ip_bgp,
6468 show_ip_bgp_cmd,
6469 "show ip bgp",
6470 SHOW_STR
6471 IP_STR
6472 BGP_STR)
6473{
ajs5a646652004-11-05 01:25:55 +00006474 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006475}
6476
6477DEFUN (show_ip_bgp_ipv4,
6478 show_ip_bgp_ipv4_cmd,
6479 "show ip bgp ipv4 (unicast|multicast)",
6480 SHOW_STR
6481 IP_STR
6482 BGP_STR
6483 "Address family\n"
6484 "Address Family modifier\n"
6485 "Address Family modifier\n")
6486{
6487 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006488 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6489 NULL);
paul718e3742002-12-13 20:15:29 +00006490
ajs5a646652004-11-05 01:25:55 +00006491 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006492}
6493
6494DEFUN (show_ip_bgp_route,
6495 show_ip_bgp_route_cmd,
6496 "show ip bgp A.B.C.D",
6497 SHOW_STR
6498 IP_STR
6499 BGP_STR
6500 "Network in the BGP routing table to display\n")
6501{
6502 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6503}
6504
6505DEFUN (show_ip_bgp_ipv4_route,
6506 show_ip_bgp_ipv4_route_cmd,
6507 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6508 SHOW_STR
6509 IP_STR
6510 BGP_STR
6511 "Address family\n"
6512 "Address Family modifier\n"
6513 "Address Family modifier\n"
6514 "Network in the BGP routing table to display\n")
6515{
6516 if (strncmp (argv[0], "m", 1) == 0)
6517 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6518
6519 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6520}
6521
6522DEFUN (show_ip_bgp_vpnv4_all_route,
6523 show_ip_bgp_vpnv4_all_route_cmd,
6524 "show ip bgp vpnv4 all A.B.C.D",
6525 SHOW_STR
6526 IP_STR
6527 BGP_STR
6528 "Display VPNv4 NLRI specific information\n"
6529 "Display information about all VPNv4 NLRIs\n"
6530 "Network in the BGP routing table to display\n")
6531{
6532 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6533}
6534
6535DEFUN (show_ip_bgp_vpnv4_rd_route,
6536 show_ip_bgp_vpnv4_rd_route_cmd,
6537 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6538 SHOW_STR
6539 IP_STR
6540 BGP_STR
6541 "Display VPNv4 NLRI specific information\n"
6542 "Display information for a route distinguisher\n"
6543 "VPN Route Distinguisher\n"
6544 "Network in the BGP routing table to display\n")
6545{
6546 int ret;
6547 struct prefix_rd prd;
6548
6549 ret = str2prefix_rd (argv[0], &prd);
6550 if (! ret)
6551 {
6552 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6553 return CMD_WARNING;
6554 }
6555 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6556}
6557
6558DEFUN (show_ip_bgp_prefix,
6559 show_ip_bgp_prefix_cmd,
6560 "show ip bgp A.B.C.D/M",
6561 SHOW_STR
6562 IP_STR
6563 BGP_STR
6564 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6565{
6566 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6567}
6568
6569DEFUN (show_ip_bgp_ipv4_prefix,
6570 show_ip_bgp_ipv4_prefix_cmd,
6571 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6572 SHOW_STR
6573 IP_STR
6574 BGP_STR
6575 "Address family\n"
6576 "Address Family modifier\n"
6577 "Address Family modifier\n"
6578 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6579{
6580 if (strncmp (argv[0], "m", 1) == 0)
6581 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6582
6583 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6584}
6585
6586DEFUN (show_ip_bgp_vpnv4_all_prefix,
6587 show_ip_bgp_vpnv4_all_prefix_cmd,
6588 "show ip bgp vpnv4 all A.B.C.D/M",
6589 SHOW_STR
6590 IP_STR
6591 BGP_STR
6592 "Display VPNv4 NLRI specific information\n"
6593 "Display information about all VPNv4 NLRIs\n"
6594 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6595{
6596 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6597}
6598
6599DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6600 show_ip_bgp_vpnv4_rd_prefix_cmd,
6601 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6602 SHOW_STR
6603 IP_STR
6604 BGP_STR
6605 "Display VPNv4 NLRI specific information\n"
6606 "Display information for a route distinguisher\n"
6607 "VPN Route Distinguisher\n"
6608 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6609{
6610 int ret;
6611 struct prefix_rd prd;
6612
6613 ret = str2prefix_rd (argv[0], &prd);
6614 if (! ret)
6615 {
6616 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6617 return CMD_WARNING;
6618 }
6619 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6620}
6621
6622DEFUN (show_ip_bgp_view,
6623 show_ip_bgp_view_cmd,
6624 "show ip bgp view WORD",
6625 SHOW_STR
6626 IP_STR
6627 BGP_STR
6628 "BGP view\n"
6629 "BGP view name\n")
6630{
paulbb46e942003-10-24 19:02:03 +00006631 struct bgp *bgp;
6632
6633 /* BGP structure lookup. */
6634 bgp = bgp_lookup_by_name (argv[0]);
6635 if (bgp == NULL)
6636 {
6637 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6638 return CMD_WARNING;
6639 }
6640
ajs5a646652004-11-05 01:25:55 +00006641 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006642}
6643
6644DEFUN (show_ip_bgp_view_route,
6645 show_ip_bgp_view_route_cmd,
6646 "show ip bgp view WORD A.B.C.D",
6647 SHOW_STR
6648 IP_STR
6649 BGP_STR
6650 "BGP view\n"
6651 "BGP view name\n"
6652 "Network in the BGP routing table to display\n")
6653{
6654 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6655}
6656
6657DEFUN (show_ip_bgp_view_prefix,
6658 show_ip_bgp_view_prefix_cmd,
6659 "show ip bgp view WORD A.B.C.D/M",
6660 SHOW_STR
6661 IP_STR
6662 BGP_STR
6663 "BGP view\n"
6664 "BGP view name\n"
6665 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6666{
6667 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6668}
6669
6670#ifdef HAVE_IPV6
6671DEFUN (show_bgp,
6672 show_bgp_cmd,
6673 "show bgp",
6674 SHOW_STR
6675 BGP_STR)
6676{
ajs5a646652004-11-05 01:25:55 +00006677 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6678 NULL);
paul718e3742002-12-13 20:15:29 +00006679}
6680
6681ALIAS (show_bgp,
6682 show_bgp_ipv6_cmd,
6683 "show bgp ipv6",
6684 SHOW_STR
6685 BGP_STR
6686 "Address family\n")
6687
6688/* old command */
6689DEFUN (show_ipv6_bgp,
6690 show_ipv6_bgp_cmd,
6691 "show ipv6 bgp",
6692 SHOW_STR
6693 IP_STR
6694 BGP_STR)
6695{
ajs5a646652004-11-05 01:25:55 +00006696 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6697 NULL);
paul718e3742002-12-13 20:15:29 +00006698}
6699
6700DEFUN (show_bgp_route,
6701 show_bgp_route_cmd,
6702 "show bgp X:X::X:X",
6703 SHOW_STR
6704 BGP_STR
6705 "Network in the BGP routing table to display\n")
6706{
6707 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6708}
6709
6710ALIAS (show_bgp_route,
6711 show_bgp_ipv6_route_cmd,
6712 "show bgp ipv6 X:X::X:X",
6713 SHOW_STR
6714 BGP_STR
6715 "Address family\n"
6716 "Network in the BGP routing table to display\n")
6717
6718/* old command */
6719DEFUN (show_ipv6_bgp_route,
6720 show_ipv6_bgp_route_cmd,
6721 "show ipv6 bgp X:X::X:X",
6722 SHOW_STR
6723 IP_STR
6724 BGP_STR
6725 "Network in the BGP routing table to display\n")
6726{
6727 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6728}
6729
6730DEFUN (show_bgp_prefix,
6731 show_bgp_prefix_cmd,
6732 "show bgp X:X::X:X/M",
6733 SHOW_STR
6734 BGP_STR
6735 "IPv6 prefix <network>/<length>\n")
6736{
6737 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6738}
6739
6740ALIAS (show_bgp_prefix,
6741 show_bgp_ipv6_prefix_cmd,
6742 "show bgp ipv6 X:X::X:X/M",
6743 SHOW_STR
6744 BGP_STR
6745 "Address family\n"
6746 "IPv6 prefix <network>/<length>\n")
6747
6748/* old command */
6749DEFUN (show_ipv6_bgp_prefix,
6750 show_ipv6_bgp_prefix_cmd,
6751 "show ipv6 bgp X:X::X:X/M",
6752 SHOW_STR
6753 IP_STR
6754 BGP_STR
6755 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6756{
6757 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6758}
6759
paulbb46e942003-10-24 19:02:03 +00006760DEFUN (show_bgp_view,
6761 show_bgp_view_cmd,
6762 "show bgp view WORD",
6763 SHOW_STR
6764 BGP_STR
6765 "BGP view\n"
6766 "View name\n")
6767{
6768 struct bgp *bgp;
6769
6770 /* BGP structure lookup. */
6771 bgp = bgp_lookup_by_name (argv[0]);
6772 if (bgp == NULL)
6773 {
6774 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6775 return CMD_WARNING;
6776 }
6777
ajs5a646652004-11-05 01:25:55 +00006778 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006779}
6780
6781ALIAS (show_bgp_view,
6782 show_bgp_view_ipv6_cmd,
6783 "show bgp view WORD ipv6",
6784 SHOW_STR
6785 BGP_STR
6786 "BGP view\n"
6787 "View name\n"
6788 "Address family\n")
6789
6790DEFUN (show_bgp_view_route,
6791 show_bgp_view_route_cmd,
6792 "show bgp view WORD X:X::X:X",
6793 SHOW_STR
6794 BGP_STR
6795 "BGP view\n"
6796 "View name\n"
6797 "Network in the BGP routing table to display\n")
6798{
6799 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6800}
6801
6802ALIAS (show_bgp_view_route,
6803 show_bgp_view_ipv6_route_cmd,
6804 "show bgp view WORD ipv6 X:X::X:X",
6805 SHOW_STR
6806 BGP_STR
6807 "BGP view\n"
6808 "View name\n"
6809 "Address family\n"
6810 "Network in the BGP routing table to display\n")
6811
6812DEFUN (show_bgp_view_prefix,
6813 show_bgp_view_prefix_cmd,
6814 "show bgp view WORD X:X::X:X/M",
6815 SHOW_STR
6816 BGP_STR
6817 "BGP view\n"
6818 "View name\n"
6819 "IPv6 prefix <network>/<length>\n")
6820{
6821 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6822}
6823
6824ALIAS (show_bgp_view_prefix,
6825 show_bgp_view_ipv6_prefix_cmd,
6826 "show bgp view WORD ipv6 X:X::X:X/M",
6827 SHOW_STR
6828 BGP_STR
6829 "BGP view\n"
6830 "View name\n"
6831 "Address family\n"
6832 "IPv6 prefix <network>/<length>\n")
6833
paul718e3742002-12-13 20:15:29 +00006834/* old command */
6835DEFUN (show_ipv6_mbgp,
6836 show_ipv6_mbgp_cmd,
6837 "show ipv6 mbgp",
6838 SHOW_STR
6839 IP_STR
6840 MBGP_STR)
6841{
ajs5a646652004-11-05 01:25:55 +00006842 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6843 NULL);
paul718e3742002-12-13 20:15:29 +00006844}
6845
6846/* old command */
6847DEFUN (show_ipv6_mbgp_route,
6848 show_ipv6_mbgp_route_cmd,
6849 "show ipv6 mbgp X:X::X:X",
6850 SHOW_STR
6851 IP_STR
6852 MBGP_STR
6853 "Network in the MBGP routing table to display\n")
6854{
6855 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6856}
6857
6858/* old command */
6859DEFUN (show_ipv6_mbgp_prefix,
6860 show_ipv6_mbgp_prefix_cmd,
6861 "show ipv6 mbgp X:X::X:X/M",
6862 SHOW_STR
6863 IP_STR
6864 MBGP_STR
6865 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6866{
6867 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6868}
6869#endif
6870
paul718e3742002-12-13 20:15:29 +00006871
paul94f2b392005-06-28 12:44:16 +00006872static int
paulfd79ac92004-10-13 05:06:08 +00006873bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006874 safi_t safi, enum bgp_show_type type)
6875{
6876 int i;
6877 struct buffer *b;
6878 char *regstr;
6879 int first;
6880 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006881 int rc;
paul718e3742002-12-13 20:15:29 +00006882
6883 first = 0;
6884 b = buffer_new (1024);
6885 for (i = 0; i < argc; i++)
6886 {
6887 if (first)
6888 buffer_putc (b, ' ');
6889 else
6890 {
6891 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6892 continue;
6893 first = 1;
6894 }
6895
6896 buffer_putstr (b, argv[i]);
6897 }
6898 buffer_putc (b, '\0');
6899
6900 regstr = buffer_getstr (b);
6901 buffer_free (b);
6902
6903 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006904 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006905 if (! regex)
6906 {
6907 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6908 VTY_NEWLINE);
6909 return CMD_WARNING;
6910 }
6911
ajs5a646652004-11-05 01:25:55 +00006912 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6913 bgp_regex_free (regex);
6914 return rc;
paul718e3742002-12-13 20:15:29 +00006915}
6916
6917DEFUN (show_ip_bgp_regexp,
6918 show_ip_bgp_regexp_cmd,
6919 "show ip bgp regexp .LINE",
6920 SHOW_STR
6921 IP_STR
6922 BGP_STR
6923 "Display routes matching the AS path regular expression\n"
6924 "A regular-expression to match the BGP AS paths\n")
6925{
6926 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6927 bgp_show_type_regexp);
6928}
6929
6930DEFUN (show_ip_bgp_flap_regexp,
6931 show_ip_bgp_flap_regexp_cmd,
6932 "show ip bgp flap-statistics regexp .LINE",
6933 SHOW_STR
6934 IP_STR
6935 BGP_STR
6936 "Display flap statistics of routes\n"
6937 "Display routes matching the AS path regular expression\n"
6938 "A regular-expression to match the BGP AS paths\n")
6939{
6940 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6941 bgp_show_type_flap_regexp);
6942}
6943
6944DEFUN (show_ip_bgp_ipv4_regexp,
6945 show_ip_bgp_ipv4_regexp_cmd,
6946 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6947 SHOW_STR
6948 IP_STR
6949 BGP_STR
6950 "Address family\n"
6951 "Address Family modifier\n"
6952 "Address Family modifier\n"
6953 "Display routes matching the AS path regular expression\n"
6954 "A regular-expression to match the BGP AS paths\n")
6955{
6956 if (strncmp (argv[0], "m", 1) == 0)
6957 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6958 bgp_show_type_regexp);
6959
6960 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6961 bgp_show_type_regexp);
6962}
6963
6964#ifdef HAVE_IPV6
6965DEFUN (show_bgp_regexp,
6966 show_bgp_regexp_cmd,
6967 "show bgp regexp .LINE",
6968 SHOW_STR
6969 BGP_STR
6970 "Display routes matching the AS path regular expression\n"
6971 "A regular-expression to match the BGP AS paths\n")
6972{
6973 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6974 bgp_show_type_regexp);
6975}
6976
6977ALIAS (show_bgp_regexp,
6978 show_bgp_ipv6_regexp_cmd,
6979 "show bgp ipv6 regexp .LINE",
6980 SHOW_STR
6981 BGP_STR
6982 "Address family\n"
6983 "Display routes matching the AS path regular expression\n"
6984 "A regular-expression to match the BGP AS paths\n")
6985
6986/* old command */
6987DEFUN (show_ipv6_bgp_regexp,
6988 show_ipv6_bgp_regexp_cmd,
6989 "show ipv6 bgp regexp .LINE",
6990 SHOW_STR
6991 IP_STR
6992 BGP_STR
6993 "Display routes matching the AS path regular expression\n"
6994 "A regular-expression to match the BGP AS paths\n")
6995{
6996 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6997 bgp_show_type_regexp);
6998}
6999
7000/* old command */
7001DEFUN (show_ipv6_mbgp_regexp,
7002 show_ipv6_mbgp_regexp_cmd,
7003 "show ipv6 mbgp regexp .LINE",
7004 SHOW_STR
7005 IP_STR
7006 BGP_STR
7007 "Display routes matching the AS path regular expression\n"
7008 "A regular-expression to match the MBGP AS paths\n")
7009{
7010 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7011 bgp_show_type_regexp);
7012}
7013#endif /* HAVE_IPV6 */
7014
paul94f2b392005-06-28 12:44:16 +00007015static int
paulfd79ac92004-10-13 05:06:08 +00007016bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007017 safi_t safi, enum bgp_show_type type)
7018{
7019 struct prefix_list *plist;
7020
7021 plist = prefix_list_lookup (afi, prefix_list_str);
7022 if (plist == NULL)
7023 {
7024 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7025 prefix_list_str, VTY_NEWLINE);
7026 return CMD_WARNING;
7027 }
7028
ajs5a646652004-11-05 01:25:55 +00007029 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007030}
7031
7032DEFUN (show_ip_bgp_prefix_list,
7033 show_ip_bgp_prefix_list_cmd,
7034 "show ip bgp prefix-list WORD",
7035 SHOW_STR
7036 IP_STR
7037 BGP_STR
7038 "Display routes conforming to the prefix-list\n"
7039 "IP prefix-list name\n")
7040{
7041 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7042 bgp_show_type_prefix_list);
7043}
7044
7045DEFUN (show_ip_bgp_flap_prefix_list,
7046 show_ip_bgp_flap_prefix_list_cmd,
7047 "show ip bgp flap-statistics prefix-list WORD",
7048 SHOW_STR
7049 IP_STR
7050 BGP_STR
7051 "Display flap statistics of routes\n"
7052 "Display routes conforming to the prefix-list\n"
7053 "IP prefix-list name\n")
7054{
7055 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7056 bgp_show_type_flap_prefix_list);
7057}
7058
7059DEFUN (show_ip_bgp_ipv4_prefix_list,
7060 show_ip_bgp_ipv4_prefix_list_cmd,
7061 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7062 SHOW_STR
7063 IP_STR
7064 BGP_STR
7065 "Address family\n"
7066 "Address Family modifier\n"
7067 "Address Family modifier\n"
7068 "Display routes conforming to the prefix-list\n"
7069 "IP prefix-list name\n")
7070{
7071 if (strncmp (argv[0], "m", 1) == 0)
7072 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7073 bgp_show_type_prefix_list);
7074
7075 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7076 bgp_show_type_prefix_list);
7077}
7078
7079#ifdef HAVE_IPV6
7080DEFUN (show_bgp_prefix_list,
7081 show_bgp_prefix_list_cmd,
7082 "show bgp prefix-list WORD",
7083 SHOW_STR
7084 BGP_STR
7085 "Display routes conforming to the prefix-list\n"
7086 "IPv6 prefix-list name\n")
7087{
7088 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7089 bgp_show_type_prefix_list);
7090}
7091
7092ALIAS (show_bgp_prefix_list,
7093 show_bgp_ipv6_prefix_list_cmd,
7094 "show bgp ipv6 prefix-list WORD",
7095 SHOW_STR
7096 BGP_STR
7097 "Address family\n"
7098 "Display routes conforming to the prefix-list\n"
7099 "IPv6 prefix-list name\n")
7100
7101/* old command */
7102DEFUN (show_ipv6_bgp_prefix_list,
7103 show_ipv6_bgp_prefix_list_cmd,
7104 "show ipv6 bgp prefix-list WORD",
7105 SHOW_STR
7106 IPV6_STR
7107 BGP_STR
7108 "Display routes matching the prefix-list\n"
7109 "IPv6 prefix-list name\n")
7110{
7111 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7112 bgp_show_type_prefix_list);
7113}
7114
7115/* old command */
7116DEFUN (show_ipv6_mbgp_prefix_list,
7117 show_ipv6_mbgp_prefix_list_cmd,
7118 "show ipv6 mbgp prefix-list WORD",
7119 SHOW_STR
7120 IPV6_STR
7121 MBGP_STR
7122 "Display routes matching the prefix-list\n"
7123 "IPv6 prefix-list name\n")
7124{
7125 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7126 bgp_show_type_prefix_list);
7127}
7128#endif /* HAVE_IPV6 */
7129
paul94f2b392005-06-28 12:44:16 +00007130static int
paulfd79ac92004-10-13 05:06:08 +00007131bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007132 safi_t safi, enum bgp_show_type type)
7133{
7134 struct as_list *as_list;
7135
7136 as_list = as_list_lookup (filter);
7137 if (as_list == NULL)
7138 {
7139 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7140 return CMD_WARNING;
7141 }
7142
ajs5a646652004-11-05 01:25:55 +00007143 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007144}
7145
7146DEFUN (show_ip_bgp_filter_list,
7147 show_ip_bgp_filter_list_cmd,
7148 "show ip bgp filter-list WORD",
7149 SHOW_STR
7150 IP_STR
7151 BGP_STR
7152 "Display routes conforming to the filter-list\n"
7153 "Regular expression access list name\n")
7154{
7155 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7156 bgp_show_type_filter_list);
7157}
7158
7159DEFUN (show_ip_bgp_flap_filter_list,
7160 show_ip_bgp_flap_filter_list_cmd,
7161 "show ip bgp flap-statistics filter-list WORD",
7162 SHOW_STR
7163 IP_STR
7164 BGP_STR
7165 "Display flap statistics of routes\n"
7166 "Display routes conforming to the filter-list\n"
7167 "Regular expression access list name\n")
7168{
7169 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7170 bgp_show_type_flap_filter_list);
7171}
7172
7173DEFUN (show_ip_bgp_ipv4_filter_list,
7174 show_ip_bgp_ipv4_filter_list_cmd,
7175 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7176 SHOW_STR
7177 IP_STR
7178 BGP_STR
7179 "Address family\n"
7180 "Address Family modifier\n"
7181 "Address Family modifier\n"
7182 "Display routes conforming to the filter-list\n"
7183 "Regular expression access list name\n")
7184{
7185 if (strncmp (argv[0], "m", 1) == 0)
7186 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7187 bgp_show_type_filter_list);
7188
7189 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7190 bgp_show_type_filter_list);
7191}
7192
7193#ifdef HAVE_IPV6
7194DEFUN (show_bgp_filter_list,
7195 show_bgp_filter_list_cmd,
7196 "show bgp filter-list WORD",
7197 SHOW_STR
7198 BGP_STR
7199 "Display routes conforming to the filter-list\n"
7200 "Regular expression access list name\n")
7201{
7202 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7203 bgp_show_type_filter_list);
7204}
7205
7206ALIAS (show_bgp_filter_list,
7207 show_bgp_ipv6_filter_list_cmd,
7208 "show bgp ipv6 filter-list WORD",
7209 SHOW_STR
7210 BGP_STR
7211 "Address family\n"
7212 "Display routes conforming to the filter-list\n"
7213 "Regular expression access list name\n")
7214
7215/* old command */
7216DEFUN (show_ipv6_bgp_filter_list,
7217 show_ipv6_bgp_filter_list_cmd,
7218 "show ipv6 bgp filter-list WORD",
7219 SHOW_STR
7220 IPV6_STR
7221 BGP_STR
7222 "Display routes conforming to the filter-list\n"
7223 "Regular expression access list name\n")
7224{
7225 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7226 bgp_show_type_filter_list);
7227}
7228
7229/* old command */
7230DEFUN (show_ipv6_mbgp_filter_list,
7231 show_ipv6_mbgp_filter_list_cmd,
7232 "show ipv6 mbgp filter-list WORD",
7233 SHOW_STR
7234 IPV6_STR
7235 MBGP_STR
7236 "Display routes conforming to the filter-list\n"
7237 "Regular expression access list name\n")
7238{
7239 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7240 bgp_show_type_filter_list);
7241}
7242#endif /* HAVE_IPV6 */
7243
paul94f2b392005-06-28 12:44:16 +00007244static int
paulfd79ac92004-10-13 05:06:08 +00007245bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007246 safi_t safi, enum bgp_show_type type)
7247{
7248 struct route_map *rmap;
7249
7250 rmap = route_map_lookup_by_name (rmap_str);
7251 if (! rmap)
7252 {
7253 vty_out (vty, "%% %s is not a valid route-map name%s",
7254 rmap_str, VTY_NEWLINE);
7255 return CMD_WARNING;
7256 }
7257
ajs5a646652004-11-05 01:25:55 +00007258 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007259}
7260
7261DEFUN (show_ip_bgp_route_map,
7262 show_ip_bgp_route_map_cmd,
7263 "show ip bgp route-map WORD",
7264 SHOW_STR
7265 IP_STR
7266 BGP_STR
7267 "Display routes matching the route-map\n"
7268 "A route-map to match on\n")
7269{
7270 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7271 bgp_show_type_route_map);
7272}
7273
7274DEFUN (show_ip_bgp_flap_route_map,
7275 show_ip_bgp_flap_route_map_cmd,
7276 "show ip bgp flap-statistics route-map WORD",
7277 SHOW_STR
7278 IP_STR
7279 BGP_STR
7280 "Display flap statistics of routes\n"
7281 "Display routes matching the route-map\n"
7282 "A route-map to match on\n")
7283{
7284 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7285 bgp_show_type_flap_route_map);
7286}
7287
7288DEFUN (show_ip_bgp_ipv4_route_map,
7289 show_ip_bgp_ipv4_route_map_cmd,
7290 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7291 SHOW_STR
7292 IP_STR
7293 BGP_STR
7294 "Address family\n"
7295 "Address Family modifier\n"
7296 "Address Family modifier\n"
7297 "Display routes matching the route-map\n"
7298 "A route-map to match on\n")
7299{
7300 if (strncmp (argv[0], "m", 1) == 0)
7301 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7302 bgp_show_type_route_map);
7303
7304 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7305 bgp_show_type_route_map);
7306}
7307
7308DEFUN (show_bgp_route_map,
7309 show_bgp_route_map_cmd,
7310 "show bgp route-map WORD",
7311 SHOW_STR
7312 BGP_STR
7313 "Display routes matching the route-map\n"
7314 "A route-map to match on\n")
7315{
7316 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7317 bgp_show_type_route_map);
7318}
7319
7320ALIAS (show_bgp_route_map,
7321 show_bgp_ipv6_route_map_cmd,
7322 "show bgp ipv6 route-map WORD",
7323 SHOW_STR
7324 BGP_STR
7325 "Address family\n"
7326 "Display routes matching the route-map\n"
7327 "A route-map to match on\n")
7328
7329DEFUN (show_ip_bgp_cidr_only,
7330 show_ip_bgp_cidr_only_cmd,
7331 "show ip bgp cidr-only",
7332 SHOW_STR
7333 IP_STR
7334 BGP_STR
7335 "Display only routes with non-natural netmasks\n")
7336{
7337 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007338 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007339}
7340
7341DEFUN (show_ip_bgp_flap_cidr_only,
7342 show_ip_bgp_flap_cidr_only_cmd,
7343 "show ip bgp flap-statistics cidr-only",
7344 SHOW_STR
7345 IP_STR
7346 BGP_STR
7347 "Display flap statistics of routes\n"
7348 "Display only routes with non-natural netmasks\n")
7349{
7350 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007351 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007352}
7353
7354DEFUN (show_ip_bgp_ipv4_cidr_only,
7355 show_ip_bgp_ipv4_cidr_only_cmd,
7356 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7357 SHOW_STR
7358 IP_STR
7359 BGP_STR
7360 "Address family\n"
7361 "Address Family modifier\n"
7362 "Address Family modifier\n"
7363 "Display only routes with non-natural netmasks\n")
7364{
7365 if (strncmp (argv[0], "m", 1) == 0)
7366 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007367 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007368
7369 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007370 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007371}
7372
7373DEFUN (show_ip_bgp_community_all,
7374 show_ip_bgp_community_all_cmd,
7375 "show ip bgp community",
7376 SHOW_STR
7377 IP_STR
7378 BGP_STR
7379 "Display routes matching the communities\n")
7380{
7381 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007382 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007383}
7384
7385DEFUN (show_ip_bgp_ipv4_community_all,
7386 show_ip_bgp_ipv4_community_all_cmd,
7387 "show ip bgp ipv4 (unicast|multicast) community",
7388 SHOW_STR
7389 IP_STR
7390 BGP_STR
7391 "Address family\n"
7392 "Address Family modifier\n"
7393 "Address Family modifier\n"
7394 "Display routes matching the communities\n")
7395{
7396 if (strncmp (argv[0], "m", 1) == 0)
7397 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007398 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007399
7400 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007401 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007402}
7403
7404#ifdef HAVE_IPV6
7405DEFUN (show_bgp_community_all,
7406 show_bgp_community_all_cmd,
7407 "show bgp community",
7408 SHOW_STR
7409 BGP_STR
7410 "Display routes matching the communities\n")
7411{
7412 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007413 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007414}
7415
7416ALIAS (show_bgp_community_all,
7417 show_bgp_ipv6_community_all_cmd,
7418 "show bgp ipv6 community",
7419 SHOW_STR
7420 BGP_STR
7421 "Address family\n"
7422 "Display routes matching the communities\n")
7423
7424/* old command */
7425DEFUN (show_ipv6_bgp_community_all,
7426 show_ipv6_bgp_community_all_cmd,
7427 "show ipv6 bgp community",
7428 SHOW_STR
7429 IPV6_STR
7430 BGP_STR
7431 "Display routes matching the communities\n")
7432{
7433 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007434 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007435}
7436
7437/* old command */
7438DEFUN (show_ipv6_mbgp_community_all,
7439 show_ipv6_mbgp_community_all_cmd,
7440 "show ipv6 mbgp community",
7441 SHOW_STR
7442 IPV6_STR
7443 MBGP_STR
7444 "Display routes matching the communities\n")
7445{
7446 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007447 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007448}
7449#endif /* HAVE_IPV6 */
7450
paul94f2b392005-06-28 12:44:16 +00007451static int
paulfd79ac92004-10-13 05:06:08 +00007452bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04007453 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007454{
7455 struct community *com;
7456 struct buffer *b;
7457 int i;
7458 char *str;
7459 int first = 0;
7460
7461 b = buffer_new (1024);
7462 for (i = 0; i < argc; i++)
7463 {
7464 if (first)
7465 buffer_putc (b, ' ');
7466 else
7467 {
7468 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7469 continue;
7470 first = 1;
7471 }
7472
7473 buffer_putstr (b, argv[i]);
7474 }
7475 buffer_putc (b, '\0');
7476
7477 str = buffer_getstr (b);
7478 buffer_free (b);
7479
7480 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007481 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007482 if (! com)
7483 {
7484 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7485 return CMD_WARNING;
7486 }
7487
ajs5a646652004-11-05 01:25:55 +00007488 return bgp_show (vty, NULL, afi, safi,
7489 (exact ? bgp_show_type_community_exact :
7490 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007491}
7492
7493DEFUN (show_ip_bgp_community,
7494 show_ip_bgp_community_cmd,
7495 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7496 SHOW_STR
7497 IP_STR
7498 BGP_STR
7499 "Display routes matching the communities\n"
7500 "community number\n"
7501 "Do not send outside local AS (well-known community)\n"
7502 "Do not advertise to any peer (well-known community)\n"
7503 "Do not export to next AS (well-known community)\n")
7504{
7505 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7506}
7507
7508ALIAS (show_ip_bgp_community,
7509 show_ip_bgp_community2_cmd,
7510 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7511 SHOW_STR
7512 IP_STR
7513 BGP_STR
7514 "Display routes matching the communities\n"
7515 "community number\n"
7516 "Do not send outside local AS (well-known community)\n"
7517 "Do not advertise to any peer (well-known community)\n"
7518 "Do not export to next AS (well-known community)\n"
7519 "community number\n"
7520 "Do not send outside local AS (well-known community)\n"
7521 "Do not advertise to any peer (well-known community)\n"
7522 "Do not export to next AS (well-known community)\n")
7523
7524ALIAS (show_ip_bgp_community,
7525 show_ip_bgp_community3_cmd,
7526 "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)",
7527 SHOW_STR
7528 IP_STR
7529 BGP_STR
7530 "Display routes matching the communities\n"
7531 "community number\n"
7532 "Do not send outside local AS (well-known community)\n"
7533 "Do not advertise to any peer (well-known community)\n"
7534 "Do not export to next AS (well-known community)\n"
7535 "community number\n"
7536 "Do not send outside local AS (well-known community)\n"
7537 "Do not advertise to any peer (well-known community)\n"
7538 "Do not export to next AS (well-known community)\n"
7539 "community number\n"
7540 "Do not send outside local AS (well-known community)\n"
7541 "Do not advertise to any peer (well-known community)\n"
7542 "Do not export to next AS (well-known community)\n")
7543
7544ALIAS (show_ip_bgp_community,
7545 show_ip_bgp_community4_cmd,
7546 "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)",
7547 SHOW_STR
7548 IP_STR
7549 BGP_STR
7550 "Display routes matching the communities\n"
7551 "community number\n"
7552 "Do not send outside local AS (well-known community)\n"
7553 "Do not advertise to any peer (well-known community)\n"
7554 "Do not export to next AS (well-known community)\n"
7555 "community number\n"
7556 "Do not send outside local AS (well-known community)\n"
7557 "Do not advertise to any peer (well-known community)\n"
7558 "Do not export to next AS (well-known community)\n"
7559 "community number\n"
7560 "Do not send outside local AS (well-known community)\n"
7561 "Do not advertise to any peer (well-known community)\n"
7562 "Do not export to next AS (well-known community)\n"
7563 "community number\n"
7564 "Do not send outside local AS (well-known community)\n"
7565 "Do not advertise to any peer (well-known community)\n"
7566 "Do not export to next AS (well-known community)\n")
7567
7568DEFUN (show_ip_bgp_ipv4_community,
7569 show_ip_bgp_ipv4_community_cmd,
7570 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7571 SHOW_STR
7572 IP_STR
7573 BGP_STR
7574 "Address family\n"
7575 "Address Family modifier\n"
7576 "Address Family modifier\n"
7577 "Display routes matching the communities\n"
7578 "community number\n"
7579 "Do not send outside local AS (well-known community)\n"
7580 "Do not advertise to any peer (well-known community)\n"
7581 "Do not export to next AS (well-known community)\n")
7582{
7583 if (strncmp (argv[0], "m", 1) == 0)
7584 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7585
7586 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7587}
7588
7589ALIAS (show_ip_bgp_ipv4_community,
7590 show_ip_bgp_ipv4_community2_cmd,
7591 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7592 SHOW_STR
7593 IP_STR
7594 BGP_STR
7595 "Address family\n"
7596 "Address Family modifier\n"
7597 "Address Family modifier\n"
7598 "Display routes matching the communities\n"
7599 "community number\n"
7600 "Do not send outside local AS (well-known community)\n"
7601 "Do not advertise to any peer (well-known community)\n"
7602 "Do not export to next AS (well-known community)\n"
7603 "community number\n"
7604 "Do not send outside local AS (well-known community)\n"
7605 "Do not advertise to any peer (well-known community)\n"
7606 "Do not export to next AS (well-known community)\n")
7607
7608ALIAS (show_ip_bgp_ipv4_community,
7609 show_ip_bgp_ipv4_community3_cmd,
7610 "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)",
7611 SHOW_STR
7612 IP_STR
7613 BGP_STR
7614 "Address family\n"
7615 "Address Family modifier\n"
7616 "Address Family modifier\n"
7617 "Display routes matching the communities\n"
7618 "community number\n"
7619 "Do not send outside local AS (well-known community)\n"
7620 "Do not advertise to any peer (well-known community)\n"
7621 "Do not export to next AS (well-known community)\n"
7622 "community number\n"
7623 "Do not send outside local AS (well-known community)\n"
7624 "Do not advertise to any peer (well-known community)\n"
7625 "Do not export to next AS (well-known community)\n"
7626 "community number\n"
7627 "Do not send outside local AS (well-known community)\n"
7628 "Do not advertise to any peer (well-known community)\n"
7629 "Do not export to next AS (well-known community)\n")
7630
7631ALIAS (show_ip_bgp_ipv4_community,
7632 show_ip_bgp_ipv4_community4_cmd,
7633 "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)",
7634 SHOW_STR
7635 IP_STR
7636 BGP_STR
7637 "Address family\n"
7638 "Address Family modifier\n"
7639 "Address Family modifier\n"
7640 "Display routes matching the communities\n"
7641 "community number\n"
7642 "Do not send outside local AS (well-known community)\n"
7643 "Do not advertise to any peer (well-known community)\n"
7644 "Do not export to next AS (well-known community)\n"
7645 "community number\n"
7646 "Do not send outside local AS (well-known community)\n"
7647 "Do not advertise to any peer (well-known community)\n"
7648 "Do not export to next AS (well-known community)\n"
7649 "community number\n"
7650 "Do not send outside local AS (well-known community)\n"
7651 "Do not advertise to any peer (well-known community)\n"
7652 "Do not export to next AS (well-known community)\n"
7653 "community number\n"
7654 "Do not send outside local AS (well-known community)\n"
7655 "Do not advertise to any peer (well-known community)\n"
7656 "Do not export to next AS (well-known community)\n")
7657
7658DEFUN (show_ip_bgp_community_exact,
7659 show_ip_bgp_community_exact_cmd,
7660 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7661 SHOW_STR
7662 IP_STR
7663 BGP_STR
7664 "Display routes matching the communities\n"
7665 "community number\n"
7666 "Do not send outside local AS (well-known community)\n"
7667 "Do not advertise to any peer (well-known community)\n"
7668 "Do not export to next AS (well-known community)\n"
7669 "Exact match of the communities")
7670{
7671 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7672}
7673
7674ALIAS (show_ip_bgp_community_exact,
7675 show_ip_bgp_community2_exact_cmd,
7676 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7677 SHOW_STR
7678 IP_STR
7679 BGP_STR
7680 "Display routes matching the communities\n"
7681 "community number\n"
7682 "Do not send outside local AS (well-known community)\n"
7683 "Do not advertise to any peer (well-known community)\n"
7684 "Do not export to next AS (well-known community)\n"
7685 "community number\n"
7686 "Do not send outside local AS (well-known community)\n"
7687 "Do not advertise to any peer (well-known community)\n"
7688 "Do not export to next AS (well-known community)\n"
7689 "Exact match of the communities")
7690
7691ALIAS (show_ip_bgp_community_exact,
7692 show_ip_bgp_community3_exact_cmd,
7693 "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",
7694 SHOW_STR
7695 IP_STR
7696 BGP_STR
7697 "Display routes matching the communities\n"
7698 "community number\n"
7699 "Do not send outside local AS (well-known community)\n"
7700 "Do not advertise to any peer (well-known community)\n"
7701 "Do not export to next AS (well-known community)\n"
7702 "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 "Exact match of the communities")
7711
7712ALIAS (show_ip_bgp_community_exact,
7713 show_ip_bgp_community4_exact_cmd,
7714 "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",
7715 SHOW_STR
7716 IP_STR
7717 BGP_STR
7718 "Display routes matching the communities\n"
7719 "community number\n"
7720 "Do not send outside local AS (well-known community)\n"
7721 "Do not advertise to any peer (well-known community)\n"
7722 "Do not export to next AS (well-known community)\n"
7723 "community number\n"
7724 "Do not send outside local AS (well-known community)\n"
7725 "Do not advertise to any peer (well-known community)\n"
7726 "Do not export to next AS (well-known community)\n"
7727 "community number\n"
7728 "Do not send outside local AS (well-known community)\n"
7729 "Do not advertise to any peer (well-known community)\n"
7730 "Do not export to next AS (well-known community)\n"
7731 "community number\n"
7732 "Do not send outside local AS (well-known community)\n"
7733 "Do not advertise to any peer (well-known community)\n"
7734 "Do not export to next AS (well-known community)\n"
7735 "Exact match of the communities")
7736
7737DEFUN (show_ip_bgp_ipv4_community_exact,
7738 show_ip_bgp_ipv4_community_exact_cmd,
7739 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7740 SHOW_STR
7741 IP_STR
7742 BGP_STR
7743 "Address family\n"
7744 "Address Family modifier\n"
7745 "Address Family modifier\n"
7746 "Display routes matching the communities\n"
7747 "community number\n"
7748 "Do not send outside local AS (well-known community)\n"
7749 "Do not advertise to any peer (well-known community)\n"
7750 "Do not export to next AS (well-known community)\n"
7751 "Exact match of the communities")
7752{
7753 if (strncmp (argv[0], "m", 1) == 0)
7754 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7755
7756 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7757}
7758
7759ALIAS (show_ip_bgp_ipv4_community_exact,
7760 show_ip_bgp_ipv4_community2_exact_cmd,
7761 "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",
7762 SHOW_STR
7763 IP_STR
7764 BGP_STR
7765 "Address family\n"
7766 "Address Family modifier\n"
7767 "Address Family modifier\n"
7768 "Display routes matching the communities\n"
7769 "community number\n"
7770 "Do not send outside local AS (well-known community)\n"
7771 "Do not advertise to any peer (well-known community)\n"
7772 "Do not export to next AS (well-known community)\n"
7773 "community number\n"
7774 "Do not send outside local AS (well-known community)\n"
7775 "Do not advertise to any peer (well-known community)\n"
7776 "Do not export to next AS (well-known community)\n"
7777 "Exact match of the communities")
7778
7779ALIAS (show_ip_bgp_ipv4_community_exact,
7780 show_ip_bgp_ipv4_community3_exact_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) exact-match",
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 "Exact match of the communities")
7802
7803ALIAS (show_ip_bgp_ipv4_community_exact,
7804 show_ip_bgp_ipv4_community4_exact_cmd,
7805 "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",
7806 SHOW_STR
7807 IP_STR
7808 BGP_STR
7809 "Address family\n"
7810 "Address Family modifier\n"
7811 "Address Family modifier\n"
7812 "Display routes matching the communities\n"
7813 "community number\n"
7814 "Do not send outside local AS (well-known community)\n"
7815 "Do not advertise to any peer (well-known community)\n"
7816 "Do not export to next AS (well-known community)\n"
7817 "community number\n"
7818 "Do not send outside local AS (well-known community)\n"
7819 "Do not advertise to any peer (well-known community)\n"
7820 "Do not export to next AS (well-known community)\n"
7821 "community number\n"
7822 "Do not send outside local AS (well-known community)\n"
7823 "Do not advertise to any peer (well-known community)\n"
7824 "Do not export to next AS (well-known community)\n"
7825 "community number\n"
7826 "Do not send outside local AS (well-known community)\n"
7827 "Do not advertise to any peer (well-known community)\n"
7828 "Do not export to next AS (well-known community)\n"
7829 "Exact match of the communities")
7830
7831#ifdef HAVE_IPV6
7832DEFUN (show_bgp_community,
7833 show_bgp_community_cmd,
7834 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7835 SHOW_STR
7836 BGP_STR
7837 "Display routes matching the communities\n"
7838 "community number\n"
7839 "Do not send outside local AS (well-known community)\n"
7840 "Do not advertise to any peer (well-known community)\n"
7841 "Do not export to next AS (well-known community)\n")
7842{
7843 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7844}
7845
7846ALIAS (show_bgp_community,
7847 show_bgp_ipv6_community_cmd,
7848 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7849 SHOW_STR
7850 BGP_STR
7851 "Address family\n"
7852 "Display routes matching the communities\n"
7853 "community number\n"
7854 "Do not send outside local AS (well-known community)\n"
7855 "Do not advertise to any peer (well-known community)\n"
7856 "Do not export to next AS (well-known community)\n")
7857
7858ALIAS (show_bgp_community,
7859 show_bgp_community2_cmd,
7860 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7861 SHOW_STR
7862 BGP_STR
7863 "Display routes matching the communities\n"
7864 "community number\n"
7865 "Do not send outside local AS (well-known community)\n"
7866 "Do not advertise to any peer (well-known community)\n"
7867 "Do not export to next AS (well-known community)\n"
7868 "community number\n"
7869 "Do not send outside local AS (well-known community)\n"
7870 "Do not advertise to any peer (well-known community)\n"
7871 "Do not export to next AS (well-known community)\n")
7872
7873ALIAS (show_bgp_community,
7874 show_bgp_ipv6_community2_cmd,
7875 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7876 SHOW_STR
7877 BGP_STR
7878 "Address family\n"
7879 "Display routes matching the communities\n"
7880 "community number\n"
7881 "Do not send outside local AS (well-known community)\n"
7882 "Do not advertise to any peer (well-known community)\n"
7883 "Do not export to next AS (well-known community)\n"
7884 "community number\n"
7885 "Do not send outside local AS (well-known community)\n"
7886 "Do not advertise to any peer (well-known community)\n"
7887 "Do not export to next AS (well-known community)\n")
7888
7889ALIAS (show_bgp_community,
7890 show_bgp_community3_cmd,
7891 "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)",
7892 SHOW_STR
7893 BGP_STR
7894 "Display routes matching the communities\n"
7895 "community number\n"
7896 "Do not send outside local AS (well-known community)\n"
7897 "Do not advertise to any peer (well-known community)\n"
7898 "Do not export to next AS (well-known community)\n"
7899 "community number\n"
7900 "Do not send outside local AS (well-known community)\n"
7901 "Do not advertise to any peer (well-known community)\n"
7902 "Do not export to next AS (well-known community)\n"
7903 "community number\n"
7904 "Do not send outside local AS (well-known community)\n"
7905 "Do not advertise to any peer (well-known community)\n"
7906 "Do not export to next AS (well-known community)\n")
7907
7908ALIAS (show_bgp_community,
7909 show_bgp_ipv6_community3_cmd,
7910 "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)",
7911 SHOW_STR
7912 BGP_STR
7913 "Address family\n"
7914 "Display routes matching the communities\n"
7915 "community number\n"
7916 "Do not send outside local AS (well-known community)\n"
7917 "Do not advertise to any peer (well-known community)\n"
7918 "Do not export to next AS (well-known community)\n"
7919 "community number\n"
7920 "Do not send outside local AS (well-known community)\n"
7921 "Do not advertise to any peer (well-known community)\n"
7922 "Do not export to next AS (well-known community)\n"
7923 "community number\n"
7924 "Do not send outside local AS (well-known community)\n"
7925 "Do not advertise to any peer (well-known community)\n"
7926 "Do not export to next AS (well-known community)\n")
7927
7928ALIAS (show_bgp_community,
7929 show_bgp_community4_cmd,
7930 "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)",
7931 SHOW_STR
7932 BGP_STR
7933 "Display routes matching the communities\n"
7934 "community number\n"
7935 "Do not send outside local AS (well-known community)\n"
7936 "Do not advertise to any peer (well-known community)\n"
7937 "Do not export to next AS (well-known community)\n"
7938 "community number\n"
7939 "Do not send outside local AS (well-known community)\n"
7940 "Do not advertise to any peer (well-known community)\n"
7941 "Do not export to next AS (well-known community)\n"
7942 "community number\n"
7943 "Do not send outside local AS (well-known community)\n"
7944 "Do not advertise to any peer (well-known community)\n"
7945 "Do not export to next AS (well-known community)\n"
7946 "community number\n"
7947 "Do not send outside local AS (well-known community)\n"
7948 "Do not advertise to any peer (well-known community)\n"
7949 "Do not export to next AS (well-known community)\n")
7950
7951ALIAS (show_bgp_community,
7952 show_bgp_ipv6_community4_cmd,
7953 "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)",
7954 SHOW_STR
7955 BGP_STR
7956 "Address family\n"
7957 "Display routes matching the communities\n"
7958 "community number\n"
7959 "Do not send outside local AS (well-known community)\n"
7960 "Do not advertise to any peer (well-known community)\n"
7961 "Do not export to next AS (well-known community)\n"
7962 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n"
7970 "community number\n"
7971 "Do not send outside local AS (well-known community)\n"
7972 "Do not advertise to any peer (well-known community)\n"
7973 "Do not export to next AS (well-known community)\n")
7974
7975/* old command */
7976DEFUN (show_ipv6_bgp_community,
7977 show_ipv6_bgp_community_cmd,
7978 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7979 SHOW_STR
7980 IPV6_STR
7981 BGP_STR
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{
7988 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7989}
7990
7991/* old command */
7992ALIAS (show_ipv6_bgp_community,
7993 show_ipv6_bgp_community2_cmd,
7994 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7995 SHOW_STR
7996 IPV6_STR
7997 BGP_STR
7998 "Display routes matching the communities\n"
7999 "community number\n"
8000 "Do not send outside local AS (well-known community)\n"
8001 "Do not advertise to any peer (well-known community)\n"
8002 "Do not export to next AS (well-known community)\n"
8003 "community number\n"
8004 "Do not send outside local AS (well-known community)\n"
8005 "Do not advertise to any peer (well-known community)\n"
8006 "Do not export to next AS (well-known community)\n")
8007
8008/* old command */
8009ALIAS (show_ipv6_bgp_community,
8010 show_ipv6_bgp_community3_cmd,
8011 "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)",
8012 SHOW_STR
8013 IPV6_STR
8014 BGP_STR
8015 "Display routes matching the communities\n"
8016 "community number\n"
8017 "Do not send outside local AS (well-known community)\n"
8018 "Do not advertise to any peer (well-known community)\n"
8019 "Do not export to next AS (well-known community)\n"
8020 "community number\n"
8021 "Do not send outside local AS (well-known community)\n"
8022 "Do not advertise to any peer (well-known community)\n"
8023 "Do not export to next AS (well-known community)\n"
8024 "community number\n"
8025 "Do not send outside local AS (well-known community)\n"
8026 "Do not advertise to any peer (well-known community)\n"
8027 "Do not export to next AS (well-known community)\n")
8028
8029/* old command */
8030ALIAS (show_ipv6_bgp_community,
8031 show_ipv6_bgp_community4_cmd,
8032 "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)",
8033 SHOW_STR
8034 IPV6_STR
8035 BGP_STR
8036 "Display routes matching the communities\n"
8037 "community number\n"
8038 "Do not send outside local AS (well-known community)\n"
8039 "Do not advertise to any peer (well-known community)\n"
8040 "Do not export to next AS (well-known community)\n"
8041 "community number\n"
8042 "Do not send outside local AS (well-known community)\n"
8043 "Do not advertise to any peer (well-known community)\n"
8044 "Do not export to next AS (well-known community)\n"
8045 "community number\n"
8046 "Do not send outside local AS (well-known community)\n"
8047 "Do not advertise to any peer (well-known community)\n"
8048 "Do not export to next AS (well-known community)\n"
8049 "community number\n"
8050 "Do not send outside local AS (well-known community)\n"
8051 "Do not advertise to any peer (well-known community)\n"
8052 "Do not export to next AS (well-known community)\n")
8053
8054DEFUN (show_bgp_community_exact,
8055 show_bgp_community_exact_cmd,
8056 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8057 SHOW_STR
8058 BGP_STR
8059 "Display routes matching the communities\n"
8060 "community number\n"
8061 "Do not send outside local AS (well-known community)\n"
8062 "Do not advertise to any peer (well-known community)\n"
8063 "Do not export to next AS (well-known community)\n"
8064 "Exact match of the communities")
8065{
8066 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8067}
8068
8069ALIAS (show_bgp_community_exact,
8070 show_bgp_ipv6_community_exact_cmd,
8071 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8072 SHOW_STR
8073 BGP_STR
8074 "Address family\n"
8075 "Display routes matching the communities\n"
8076 "community number\n"
8077 "Do not send outside local AS (well-known community)\n"
8078 "Do not advertise to any peer (well-known community)\n"
8079 "Do not export to next AS (well-known community)\n"
8080 "Exact match of the communities")
8081
8082ALIAS (show_bgp_community_exact,
8083 show_bgp_community2_exact_cmd,
8084 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8085 SHOW_STR
8086 BGP_STR
8087 "Display routes matching the communities\n"
8088 "community number\n"
8089 "Do not send outside local AS (well-known community)\n"
8090 "Do not advertise to any peer (well-known community)\n"
8091 "Do not export to next AS (well-known community)\n"
8092 "community number\n"
8093 "Do not send outside local AS (well-known community)\n"
8094 "Do not advertise to any peer (well-known community)\n"
8095 "Do not export to next AS (well-known community)\n"
8096 "Exact match of the communities")
8097
8098ALIAS (show_bgp_community_exact,
8099 show_bgp_ipv6_community2_exact_cmd,
8100 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8101 SHOW_STR
8102 BGP_STR
8103 "Address family\n"
8104 "Display routes matching the communities\n"
8105 "community number\n"
8106 "Do not send outside local AS (well-known community)\n"
8107 "Do not advertise to any peer (well-known community)\n"
8108 "Do not export to next AS (well-known community)\n"
8109 "community number\n"
8110 "Do not send outside local AS (well-known community)\n"
8111 "Do not advertise to any peer (well-known community)\n"
8112 "Do not export to next AS (well-known community)\n"
8113 "Exact match of the communities")
8114
8115ALIAS (show_bgp_community_exact,
8116 show_bgp_community3_exact_cmd,
8117 "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",
8118 SHOW_STR
8119 BGP_STR
8120 "Display routes matching the communities\n"
8121 "community number\n"
8122 "Do not send outside local AS (well-known community)\n"
8123 "Do not advertise to any peer (well-known community)\n"
8124 "Do not export to next AS (well-known community)\n"
8125 "community number\n"
8126 "Do not send outside local AS (well-known community)\n"
8127 "Do not advertise to any peer (well-known community)\n"
8128 "Do not export to next AS (well-known community)\n"
8129 "community number\n"
8130 "Do not send outside local AS (well-known community)\n"
8131 "Do not advertise to any peer (well-known community)\n"
8132 "Do not export to next AS (well-known community)\n"
8133 "Exact match of the communities")
8134
8135ALIAS (show_bgp_community_exact,
8136 show_bgp_ipv6_community3_exact_cmd,
8137 "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",
8138 SHOW_STR
8139 BGP_STR
8140 "Address family\n"
8141 "Display routes matching the communities\n"
8142 "community number\n"
8143 "Do not send outside local AS (well-known community)\n"
8144 "Do not advertise to any peer (well-known community)\n"
8145 "Do not export to next AS (well-known community)\n"
8146 "community number\n"
8147 "Do not send outside local AS (well-known community)\n"
8148 "Do not advertise to any peer (well-known community)\n"
8149 "Do not export to next AS (well-known community)\n"
8150 "community number\n"
8151 "Do not send outside local AS (well-known community)\n"
8152 "Do not advertise to any peer (well-known community)\n"
8153 "Do not export to next AS (well-known community)\n"
8154 "Exact match of the communities")
8155
8156ALIAS (show_bgp_community_exact,
8157 show_bgp_community4_exact_cmd,
8158 "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",
8159 SHOW_STR
8160 BGP_STR
8161 "Display routes matching the communities\n"
8162 "community number\n"
8163 "Do not send outside local AS (well-known community)\n"
8164 "Do not advertise to any peer (well-known community)\n"
8165 "Do not export to next AS (well-known community)\n"
8166 "community number\n"
8167 "Do not send outside local AS (well-known community)\n"
8168 "Do not advertise to any peer (well-known community)\n"
8169 "Do not export to next AS (well-known community)\n"
8170 "community number\n"
8171 "Do not send outside local AS (well-known community)\n"
8172 "Do not advertise to any peer (well-known community)\n"
8173 "Do not export to next AS (well-known community)\n"
8174 "community number\n"
8175 "Do not send outside local AS (well-known community)\n"
8176 "Do not advertise to any peer (well-known community)\n"
8177 "Do not export to next AS (well-known community)\n"
8178 "Exact match of the communities")
8179
8180ALIAS (show_bgp_community_exact,
8181 show_bgp_ipv6_community4_exact_cmd,
8182 "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",
8183 SHOW_STR
8184 BGP_STR
8185 "Address family\n"
8186 "Display routes matching the communities\n"
8187 "community number\n"
8188 "Do not send outside local AS (well-known community)\n"
8189 "Do not advertise to any peer (well-known community)\n"
8190 "Do not export to next AS (well-known community)\n"
8191 "community number\n"
8192 "Do not send outside local AS (well-known community)\n"
8193 "Do not advertise to any peer (well-known community)\n"
8194 "Do not export to next AS (well-known community)\n"
8195 "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 "community number\n"
8200 "Do not send outside local AS (well-known community)\n"
8201 "Do not advertise to any peer (well-known community)\n"
8202 "Do not export to next AS (well-known community)\n"
8203 "Exact match of the communities")
8204
8205/* old command */
8206DEFUN (show_ipv6_bgp_community_exact,
8207 show_ipv6_bgp_community_exact_cmd,
8208 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8209 SHOW_STR
8210 IPV6_STR
8211 BGP_STR
8212 "Display routes matching the communities\n"
8213 "community number\n"
8214 "Do not send outside local AS (well-known community)\n"
8215 "Do not advertise to any peer (well-known community)\n"
8216 "Do not export to next AS (well-known community)\n"
8217 "Exact match of the communities")
8218{
8219 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8220}
8221
8222/* old command */
8223ALIAS (show_ipv6_bgp_community_exact,
8224 show_ipv6_bgp_community2_exact_cmd,
8225 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8226 SHOW_STR
8227 IPV6_STR
8228 BGP_STR
8229 "Display routes matching the communities\n"
8230 "community number\n"
8231 "Do not send outside local AS (well-known community)\n"
8232 "Do not advertise to any peer (well-known community)\n"
8233 "Do not export to next AS (well-known community)\n"
8234 "community number\n"
8235 "Do not send outside local AS (well-known community)\n"
8236 "Do not advertise to any peer (well-known community)\n"
8237 "Do not export to next AS (well-known community)\n"
8238 "Exact match of the communities")
8239
8240/* old command */
8241ALIAS (show_ipv6_bgp_community_exact,
8242 show_ipv6_bgp_community3_exact_cmd,
8243 "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",
8244 SHOW_STR
8245 IPV6_STR
8246 BGP_STR
8247 "Display routes matching the communities\n"
8248 "community number\n"
8249 "Do not send outside local AS (well-known community)\n"
8250 "Do not advertise to any peer (well-known community)\n"
8251 "Do not export to next AS (well-known community)\n"
8252 "community number\n"
8253 "Do not send outside local AS (well-known community)\n"
8254 "Do not advertise to any peer (well-known community)\n"
8255 "Do not export to next AS (well-known community)\n"
8256 "community number\n"
8257 "Do not send outside local AS (well-known community)\n"
8258 "Do not advertise to any peer (well-known community)\n"
8259 "Do not export to next AS (well-known community)\n"
8260 "Exact match of the communities")
8261
8262/* old command */
8263ALIAS (show_ipv6_bgp_community_exact,
8264 show_ipv6_bgp_community4_exact_cmd,
8265 "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",
8266 SHOW_STR
8267 IPV6_STR
8268 BGP_STR
8269 "Display routes matching the communities\n"
8270 "community number\n"
8271 "Do not send outside local AS (well-known community)\n"
8272 "Do not advertise to any peer (well-known community)\n"
8273 "Do not export to next AS (well-known community)\n"
8274 "community number\n"
8275 "Do not send outside local AS (well-known community)\n"
8276 "Do not advertise to any peer (well-known community)\n"
8277 "Do not export to next AS (well-known community)\n"
8278 "community number\n"
8279 "Do not send outside local AS (well-known community)\n"
8280 "Do not advertise to any peer (well-known community)\n"
8281 "Do not export to next AS (well-known community)\n"
8282 "community number\n"
8283 "Do not send outside local AS (well-known community)\n"
8284 "Do not advertise to any peer (well-known community)\n"
8285 "Do not export to next AS (well-known community)\n"
8286 "Exact match of the communities")
8287
8288/* old command */
8289DEFUN (show_ipv6_mbgp_community,
8290 show_ipv6_mbgp_community_cmd,
8291 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8292 SHOW_STR
8293 IPV6_STR
8294 MBGP_STR
8295 "Display routes matching the communities\n"
8296 "community number\n"
8297 "Do not send outside local AS (well-known community)\n"
8298 "Do not advertise to any peer (well-known community)\n"
8299 "Do not export to next AS (well-known community)\n")
8300{
8301 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8302}
8303
8304/* old command */
8305ALIAS (show_ipv6_mbgp_community,
8306 show_ipv6_mbgp_community2_cmd,
8307 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8308 SHOW_STR
8309 IPV6_STR
8310 MBGP_STR
8311 "Display routes matching the communities\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 "community number\n"
8317 "Do not send outside local AS (well-known community)\n"
8318 "Do not advertise to any peer (well-known community)\n"
8319 "Do not export to next AS (well-known community)\n")
8320
8321/* old command */
8322ALIAS (show_ipv6_mbgp_community,
8323 show_ipv6_mbgp_community3_cmd,
8324 "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)",
8325 SHOW_STR
8326 IPV6_STR
8327 MBGP_STR
8328 "Display routes matching the communities\n"
8329 "community number\n"
8330 "Do not send outside local AS (well-known community)\n"
8331 "Do not advertise to any peer (well-known community)\n"
8332 "Do not export to next AS (well-known community)\n"
8333 "community number\n"
8334 "Do not send outside local AS (well-known community)\n"
8335 "Do not advertise to any peer (well-known community)\n"
8336 "Do not export to next AS (well-known community)\n"
8337 "community number\n"
8338 "Do not send outside local AS (well-known community)\n"
8339 "Do not advertise to any peer (well-known community)\n"
8340 "Do not export to next AS (well-known community)\n")
8341
8342/* old command */
8343ALIAS (show_ipv6_mbgp_community,
8344 show_ipv6_mbgp_community4_cmd,
8345 "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)",
8346 SHOW_STR
8347 IPV6_STR
8348 MBGP_STR
8349 "Display routes matching the communities\n"
8350 "community number\n"
8351 "Do not send outside local AS (well-known community)\n"
8352 "Do not advertise to any peer (well-known community)\n"
8353 "Do not export to next AS (well-known community)\n"
8354 "community number\n"
8355 "Do not send outside local AS (well-known community)\n"
8356 "Do not advertise to any peer (well-known community)\n"
8357 "Do not export to next AS (well-known community)\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
8367/* old command */
8368DEFUN (show_ipv6_mbgp_community_exact,
8369 show_ipv6_mbgp_community_exact_cmd,
8370 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8371 SHOW_STR
8372 IPV6_STR
8373 MBGP_STR
8374 "Display routes matching the communities\n"
8375 "community number\n"
8376 "Do not send outside local AS (well-known community)\n"
8377 "Do not advertise to any peer (well-known community)\n"
8378 "Do not export to next AS (well-known community)\n"
8379 "Exact match of the communities")
8380{
8381 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8382}
8383
8384/* old command */
8385ALIAS (show_ipv6_mbgp_community_exact,
8386 show_ipv6_mbgp_community2_exact_cmd,
8387 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8388 SHOW_STR
8389 IPV6_STR
8390 MBGP_STR
8391 "Display routes matching the communities\n"
8392 "community number\n"
8393 "Do not send outside local AS (well-known community)\n"
8394 "Do not advertise to any peer (well-known community)\n"
8395 "Do not export to next AS (well-known community)\n"
8396 "community number\n"
8397 "Do not send outside local AS (well-known community)\n"
8398 "Do not advertise to any peer (well-known community)\n"
8399 "Do not export to next AS (well-known community)\n"
8400 "Exact match of the communities")
8401
8402/* old command */
8403ALIAS (show_ipv6_mbgp_community_exact,
8404 show_ipv6_mbgp_community3_exact_cmd,
8405 "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",
8406 SHOW_STR
8407 IPV6_STR
8408 MBGP_STR
8409 "Display routes matching the communities\n"
8410 "community number\n"
8411 "Do not send outside local AS (well-known community)\n"
8412 "Do not advertise to any peer (well-known community)\n"
8413 "Do not export to next AS (well-known community)\n"
8414 "community number\n"
8415 "Do not send outside local AS (well-known community)\n"
8416 "Do not advertise to any peer (well-known community)\n"
8417 "Do not export to next AS (well-known community)\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
8424/* old command */
8425ALIAS (show_ipv6_mbgp_community_exact,
8426 show_ipv6_mbgp_community4_exact_cmd,
8427 "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",
8428 SHOW_STR
8429 IPV6_STR
8430 MBGP_STR
8431 "Display routes matching the communities\n"
8432 "community number\n"
8433 "Do not send outside local AS (well-known community)\n"
8434 "Do not advertise to any peer (well-known community)\n"
8435 "Do not export to next AS (well-known community)\n"
8436 "community number\n"
8437 "Do not send outside local AS (well-known community)\n"
8438 "Do not advertise to any peer (well-known community)\n"
8439 "Do not export to next AS (well-known community)\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "community number\n"
8445 "Do not send outside local AS (well-known community)\n"
8446 "Do not advertise to any peer (well-known community)\n"
8447 "Do not export to next AS (well-known community)\n"
8448 "Exact match of the communities")
8449#endif /* HAVE_IPV6 */
8450
paul94f2b392005-06-28 12:44:16 +00008451static int
paulfd79ac92004-10-13 05:06:08 +00008452bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008453 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008454{
8455 struct community_list *list;
8456
hassofee6e4e2005-02-02 16:29:31 +00008457 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008458 if (list == NULL)
8459 {
8460 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8461 VTY_NEWLINE);
8462 return CMD_WARNING;
8463 }
8464
ajs5a646652004-11-05 01:25:55 +00008465 return bgp_show (vty, NULL, afi, safi,
8466 (exact ? bgp_show_type_community_list_exact :
8467 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008468}
8469
8470DEFUN (show_ip_bgp_community_list,
8471 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008472 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008473 SHOW_STR
8474 IP_STR
8475 BGP_STR
8476 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008477 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008478 "community-list name\n")
8479{
8480 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8481}
8482
8483DEFUN (show_ip_bgp_ipv4_community_list,
8484 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008485 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008486 SHOW_STR
8487 IP_STR
8488 BGP_STR
8489 "Address family\n"
8490 "Address Family modifier\n"
8491 "Address Family modifier\n"
8492 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008493 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008494 "community-list name\n")
8495{
8496 if (strncmp (argv[0], "m", 1) == 0)
8497 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8498
8499 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8500}
8501
8502DEFUN (show_ip_bgp_community_list_exact,
8503 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008504 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008505 SHOW_STR
8506 IP_STR
8507 BGP_STR
8508 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008509 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008510 "community-list name\n"
8511 "Exact match of the communities\n")
8512{
8513 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8514}
8515
8516DEFUN (show_ip_bgp_ipv4_community_list_exact,
8517 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008518 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008519 SHOW_STR
8520 IP_STR
8521 BGP_STR
8522 "Address family\n"
8523 "Address Family modifier\n"
8524 "Address Family modifier\n"
8525 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008526 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008527 "community-list name\n"
8528 "Exact match of the communities\n")
8529{
8530 if (strncmp (argv[0], "m", 1) == 0)
8531 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8532
8533 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8534}
8535
8536#ifdef HAVE_IPV6
8537DEFUN (show_bgp_community_list,
8538 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008539 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008540 SHOW_STR
8541 BGP_STR
8542 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008543 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008544 "community-list name\n")
8545{
8546 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8547}
8548
8549ALIAS (show_bgp_community_list,
8550 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008551 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008552 SHOW_STR
8553 BGP_STR
8554 "Address family\n"
8555 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008556 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008557 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008558
8559/* old command */
8560DEFUN (show_ipv6_bgp_community_list,
8561 show_ipv6_bgp_community_list_cmd,
8562 "show ipv6 bgp community-list WORD",
8563 SHOW_STR
8564 IPV6_STR
8565 BGP_STR
8566 "Display routes matching the community-list\n"
8567 "community-list name\n")
8568{
8569 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8570}
8571
8572/* old command */
8573DEFUN (show_ipv6_mbgp_community_list,
8574 show_ipv6_mbgp_community_list_cmd,
8575 "show ipv6 mbgp community-list WORD",
8576 SHOW_STR
8577 IPV6_STR
8578 MBGP_STR
8579 "Display routes matching the community-list\n"
8580 "community-list name\n")
8581{
8582 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8583}
8584
8585DEFUN (show_bgp_community_list_exact,
8586 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008587 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008588 SHOW_STR
8589 BGP_STR
8590 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008591 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008592 "community-list name\n"
8593 "Exact match of the communities\n")
8594{
8595 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8596}
8597
8598ALIAS (show_bgp_community_list_exact,
8599 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008600 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008601 SHOW_STR
8602 BGP_STR
8603 "Address family\n"
8604 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008605 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008606 "community-list name\n"
8607 "Exact match of the communities\n")
8608
8609/* old command */
8610DEFUN (show_ipv6_bgp_community_list_exact,
8611 show_ipv6_bgp_community_list_exact_cmd,
8612 "show ipv6 bgp community-list WORD exact-match",
8613 SHOW_STR
8614 IPV6_STR
8615 BGP_STR
8616 "Display routes matching the community-list\n"
8617 "community-list name\n"
8618 "Exact match of the communities\n")
8619{
8620 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8621}
8622
8623/* old command */
8624DEFUN (show_ipv6_mbgp_community_list_exact,
8625 show_ipv6_mbgp_community_list_exact_cmd,
8626 "show ipv6 mbgp community-list WORD exact-match",
8627 SHOW_STR
8628 IPV6_STR
8629 MBGP_STR
8630 "Display routes matching the community-list\n"
8631 "community-list name\n"
8632 "Exact match of the communities\n")
8633{
8634 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8635}
8636#endif /* HAVE_IPV6 */
8637
paul94f2b392005-06-28 12:44:16 +00008638static int
paulfd79ac92004-10-13 05:06:08 +00008639bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008640 safi_t safi, enum bgp_show_type type)
8641{
8642 int ret;
8643 struct prefix *p;
8644
8645 p = prefix_new();
8646
8647 ret = str2prefix (prefix, p);
8648 if (! ret)
8649 {
8650 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8651 return CMD_WARNING;
8652 }
8653
ajs5a646652004-11-05 01:25:55 +00008654 ret = bgp_show (vty, NULL, afi, safi, type, p);
8655 prefix_free(p);
8656 return ret;
paul718e3742002-12-13 20:15:29 +00008657}
8658
8659DEFUN (show_ip_bgp_prefix_longer,
8660 show_ip_bgp_prefix_longer_cmd,
8661 "show ip bgp A.B.C.D/M longer-prefixes",
8662 SHOW_STR
8663 IP_STR
8664 BGP_STR
8665 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8666 "Display route and more specific routes\n")
8667{
8668 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8669 bgp_show_type_prefix_longer);
8670}
8671
8672DEFUN (show_ip_bgp_flap_prefix_longer,
8673 show_ip_bgp_flap_prefix_longer_cmd,
8674 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8675 SHOW_STR
8676 IP_STR
8677 BGP_STR
8678 "Display flap statistics of routes\n"
8679 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8680 "Display route and more specific routes\n")
8681{
8682 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8683 bgp_show_type_flap_prefix_longer);
8684}
8685
8686DEFUN (show_ip_bgp_ipv4_prefix_longer,
8687 show_ip_bgp_ipv4_prefix_longer_cmd,
8688 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8689 SHOW_STR
8690 IP_STR
8691 BGP_STR
8692 "Address family\n"
8693 "Address Family modifier\n"
8694 "Address Family modifier\n"
8695 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8696 "Display route and more specific routes\n")
8697{
8698 if (strncmp (argv[0], "m", 1) == 0)
8699 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8700 bgp_show_type_prefix_longer);
8701
8702 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8703 bgp_show_type_prefix_longer);
8704}
8705
8706DEFUN (show_ip_bgp_flap_address,
8707 show_ip_bgp_flap_address_cmd,
8708 "show ip bgp flap-statistics A.B.C.D",
8709 SHOW_STR
8710 IP_STR
8711 BGP_STR
8712 "Display flap statistics of routes\n"
8713 "Network in the BGP routing table to display\n")
8714{
8715 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8716 bgp_show_type_flap_address);
8717}
8718
8719DEFUN (show_ip_bgp_flap_prefix,
8720 show_ip_bgp_flap_prefix_cmd,
8721 "show ip bgp flap-statistics A.B.C.D/M",
8722 SHOW_STR
8723 IP_STR
8724 BGP_STR
8725 "Display flap statistics of routes\n"
8726 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8727{
8728 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8729 bgp_show_type_flap_prefix);
8730}
8731#ifdef HAVE_IPV6
8732DEFUN (show_bgp_prefix_longer,
8733 show_bgp_prefix_longer_cmd,
8734 "show bgp X:X::X:X/M longer-prefixes",
8735 SHOW_STR
8736 BGP_STR
8737 "IPv6 prefix <network>/<length>\n"
8738 "Display route and more specific routes\n")
8739{
8740 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8741 bgp_show_type_prefix_longer);
8742}
8743
8744ALIAS (show_bgp_prefix_longer,
8745 show_bgp_ipv6_prefix_longer_cmd,
8746 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8747 SHOW_STR
8748 BGP_STR
8749 "Address family\n"
8750 "IPv6 prefix <network>/<length>\n"
8751 "Display route and more specific routes\n")
8752
8753/* old command */
8754DEFUN (show_ipv6_bgp_prefix_longer,
8755 show_ipv6_bgp_prefix_longer_cmd,
8756 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8757 SHOW_STR
8758 IPV6_STR
8759 BGP_STR
8760 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8761 "Display route and more specific routes\n")
8762{
8763 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8764 bgp_show_type_prefix_longer);
8765}
8766
8767/* old command */
8768DEFUN (show_ipv6_mbgp_prefix_longer,
8769 show_ipv6_mbgp_prefix_longer_cmd,
8770 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8771 SHOW_STR
8772 IPV6_STR
8773 MBGP_STR
8774 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8775 "Display route and more specific routes\n")
8776{
8777 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8778 bgp_show_type_prefix_longer);
8779}
8780#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008781
paul94f2b392005-06-28 12:44:16 +00008782static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008783peer_lookup_in_view (struct vty *vty, const char *view_name,
8784 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008785{
8786 int ret;
8787 struct bgp *bgp;
8788 struct peer *peer;
8789 union sockunion su;
8790
8791 /* BGP structure lookup. */
8792 if (view_name)
8793 {
8794 bgp = bgp_lookup_by_name (view_name);
8795 if (! bgp)
8796 {
8797 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8798 return NULL;
8799 }
8800 }
paul5228ad22004-06-04 17:58:18 +00008801 else
paulbb46e942003-10-24 19:02:03 +00008802 {
8803 bgp = bgp_get_default ();
8804 if (! bgp)
8805 {
8806 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8807 return NULL;
8808 }
8809 }
8810
8811 /* Get peer sockunion. */
8812 ret = str2sockunion (ip_str, &su);
8813 if (ret < 0)
8814 {
8815 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8816 return NULL;
8817 }
8818
8819 /* Peer structure lookup. */
8820 peer = peer_lookup (bgp, &su);
8821 if (! peer)
8822 {
8823 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8824 return NULL;
8825 }
8826
8827 return peer;
8828}
Paul Jakma2815e612006-09-14 02:56:07 +00008829
8830enum bgp_stats
8831{
8832 BGP_STATS_MAXBITLEN = 0,
8833 BGP_STATS_RIB,
8834 BGP_STATS_PREFIXES,
8835 BGP_STATS_TOTPLEN,
8836 BGP_STATS_UNAGGREGATEABLE,
8837 BGP_STATS_MAX_AGGREGATEABLE,
8838 BGP_STATS_AGGREGATES,
8839 BGP_STATS_SPACE,
8840 BGP_STATS_ASPATH_COUNT,
8841 BGP_STATS_ASPATH_MAXHOPS,
8842 BGP_STATS_ASPATH_TOTHOPS,
8843 BGP_STATS_ASPATH_MAXSIZE,
8844 BGP_STATS_ASPATH_TOTSIZE,
8845 BGP_STATS_ASN_HIGHEST,
8846 BGP_STATS_MAX,
8847};
paulbb46e942003-10-24 19:02:03 +00008848
Paul Jakma2815e612006-09-14 02:56:07 +00008849static const char *table_stats_strs[] =
8850{
8851 [BGP_STATS_PREFIXES] = "Total Prefixes",
8852 [BGP_STATS_TOTPLEN] = "Average prefix length",
8853 [BGP_STATS_RIB] = "Total Advertisements",
8854 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8855 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8856 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8857 [BGP_STATS_SPACE] = "Address space advertised",
8858 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8859 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8860 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8861 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8862 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8863 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8864 [BGP_STATS_MAX] = NULL,
8865};
8866
8867struct bgp_table_stats
8868{
8869 struct bgp_table *table;
8870 unsigned long long counts[BGP_STATS_MAX];
8871};
8872
8873#if 0
8874#define TALLY_SIGFIG 100000
8875static unsigned long
8876ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8877{
8878 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8879 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8880 unsigned long ret = newtot / count;
8881
8882 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8883 return ret + 1;
8884 else
8885 return ret;
8886}
8887#endif
8888
8889static int
8890bgp_table_stats_walker (struct thread *t)
8891{
8892 struct bgp_node *rn;
8893 struct bgp_node *top;
8894 struct bgp_table_stats *ts = THREAD_ARG (t);
8895 unsigned int space = 0;
8896
Paul Jakma53d9f672006-10-15 23:41:16 +00008897 if (!(top = bgp_table_top (ts->table)))
8898 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00008899
8900 switch (top->p.family)
8901 {
8902 case AF_INET:
8903 space = IPV4_MAX_BITLEN;
8904 break;
8905 case AF_INET6:
8906 space = IPV6_MAX_BITLEN;
8907 break;
8908 }
8909
8910 ts->counts[BGP_STATS_MAXBITLEN] = space;
8911
8912 for (rn = top; rn; rn = bgp_route_next (rn))
8913 {
8914 struct bgp_info *ri;
8915 struct bgp_node *prn = rn->parent;
8916 unsigned int rinum = 0;
8917
8918 if (rn == top)
8919 continue;
8920
8921 if (!rn->info)
8922 continue;
8923
8924 ts->counts[BGP_STATS_PREFIXES]++;
8925 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
8926
8927#if 0
8928 ts->counts[BGP_STATS_AVGPLEN]
8929 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
8930 ts->counts[BGP_STATS_AVGPLEN],
8931 rn->p.prefixlen);
8932#endif
8933
8934 /* check if the prefix is included by any other announcements */
8935 while (prn && !prn->info)
8936 prn = prn->parent;
8937
8938 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00008939 {
8940 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
8941 /* announced address space */
8942 if (space)
8943 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
8944 }
Paul Jakma2815e612006-09-14 02:56:07 +00008945 else if (prn->info)
8946 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
8947
Paul Jakma2815e612006-09-14 02:56:07 +00008948 for (ri = rn->info; ri; ri = ri->next)
8949 {
8950 rinum++;
8951 ts->counts[BGP_STATS_RIB]++;
8952
8953 if (ri->attr &&
8954 (CHECK_FLAG (ri->attr->flag,
8955 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
8956 ts->counts[BGP_STATS_AGGREGATES]++;
8957
8958 /* as-path stats */
8959 if (ri->attr && ri->attr->aspath)
8960 {
8961 unsigned int hops = aspath_count_hops (ri->attr->aspath);
8962 unsigned int size = aspath_size (ri->attr->aspath);
8963 as_t highest = aspath_highest (ri->attr->aspath);
8964
8965 ts->counts[BGP_STATS_ASPATH_COUNT]++;
8966
8967 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
8968 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
8969
8970 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
8971 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
8972
8973 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
8974 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
8975#if 0
8976 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
8977 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8978 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
8979 hops);
8980 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
8981 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8982 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
8983 size);
8984#endif
8985 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
8986 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
8987 }
8988 }
8989 }
8990 return 0;
8991}
8992
8993static int
8994bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
8995{
8996 struct bgp_table_stats ts;
8997 unsigned int i;
8998
8999 if (!bgp->rib[afi][safi])
9000 {
9001 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9002 return CMD_WARNING;
9003 }
9004
9005 memset (&ts, 0, sizeof (ts));
9006 ts.table = bgp->rib[afi][safi];
9007 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9008
9009 vty_out (vty, "BGP %s RIB statistics%s%s",
9010 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9011
9012 for (i = 0; i < BGP_STATS_MAX; i++)
9013 {
9014 if (!table_stats_strs[i])
9015 continue;
9016
9017 switch (i)
9018 {
9019#if 0
9020 case BGP_STATS_ASPATH_AVGHOPS:
9021 case BGP_STATS_ASPATH_AVGSIZE:
9022 case BGP_STATS_AVGPLEN:
9023 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9024 vty_out (vty, "%12.2f",
9025 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9026 break;
9027#endif
9028 case BGP_STATS_ASPATH_TOTHOPS:
9029 case BGP_STATS_ASPATH_TOTSIZE:
9030 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9031 vty_out (vty, "%12.2f",
9032 ts.counts[i] ?
9033 (float)ts.counts[i] /
9034 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9035 : 0);
9036 break;
9037 case BGP_STATS_TOTPLEN:
9038 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9039 vty_out (vty, "%12.2f",
9040 ts.counts[i] ?
9041 (float)ts.counts[i] /
9042 (float)ts.counts[BGP_STATS_PREFIXES]
9043 : 0);
9044 break;
9045 case BGP_STATS_SPACE:
9046 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9047 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9048 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9049 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009050 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009051 vty_out (vty, "%12.2f%s",
9052 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009053 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009054 VTY_NEWLINE);
9055 vty_out (vty, "%30s: ", "/8 equivalent ");
9056 vty_out (vty, "%12.2f%s",
9057 (float)ts.counts[BGP_STATS_SPACE] /
9058 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9059 VTY_NEWLINE);
9060 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9061 break;
9062 vty_out (vty, "%30s: ", "/24 equivalent ");
9063 vty_out (vty, "%12.2f",
9064 (float)ts.counts[BGP_STATS_SPACE] /
9065 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9066 break;
9067 default:
9068 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9069 vty_out (vty, "%12llu", ts.counts[i]);
9070 }
9071
9072 vty_out (vty, "%s", VTY_NEWLINE);
9073 }
9074 return CMD_SUCCESS;
9075}
9076
9077static int
9078bgp_table_stats_vty (struct vty *vty, const char *name,
9079 const char *afi_str, const char *safi_str)
9080{
9081 struct bgp *bgp;
9082 afi_t afi;
9083 safi_t safi;
9084
9085 if (name)
9086 bgp = bgp_lookup_by_name (name);
9087 else
9088 bgp = bgp_get_default ();
9089
9090 if (!bgp)
9091 {
9092 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9093 return CMD_WARNING;
9094 }
9095 if (strncmp (afi_str, "ipv", 3) == 0)
9096 {
9097 if (strncmp (afi_str, "ipv4", 4) == 0)
9098 afi = AFI_IP;
9099 else if (strncmp (afi_str, "ipv6", 4) == 0)
9100 afi = AFI_IP6;
9101 else
9102 {
9103 vty_out (vty, "%% Invalid address family %s%s",
9104 afi_str, VTY_NEWLINE);
9105 return CMD_WARNING;
9106 }
9107 if (strncmp (safi_str, "m", 1) == 0)
9108 safi = SAFI_MULTICAST;
9109 else if (strncmp (safi_str, "u", 1) == 0)
9110 safi = SAFI_UNICAST;
9111 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9112 safi = BGP_SAFI_VPNV4;
9113 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9114 safi = BGP_SAFI_VPNV6;
9115 else
9116 {
9117 vty_out (vty, "%% Invalid subsequent address family %s%s",
9118 safi_str, VTY_NEWLINE);
9119 return CMD_WARNING;
9120 }
9121 }
9122 else
9123 {
9124 vty_out (vty, "%% Invalid address family %s%s",
9125 afi_str, VTY_NEWLINE);
9126 return CMD_WARNING;
9127 }
9128
9129 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9130 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9131 {
9132 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9133 afi_str, safi_str, VTY_NEWLINE);
9134 return CMD_WARNING;
9135 }
9136 return bgp_table_stats (vty, bgp, afi, safi);
9137}
9138
9139DEFUN (show_bgp_statistics,
9140 show_bgp_statistics_cmd,
9141 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9142 SHOW_STR
9143 BGP_STR
9144 "Address family\n"
9145 "Address family\n"
9146 "Address Family modifier\n"
9147 "Address Family modifier\n"
9148 "BGP RIB advertisement statistics\n")
9149{
9150 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9151}
9152
9153ALIAS (show_bgp_statistics,
9154 show_bgp_statistics_vpnv4_cmd,
9155 "show bgp (ipv4) (vpnv4) statistics",
9156 SHOW_STR
9157 BGP_STR
9158 "Address family\n"
9159 "Address Family modifier\n"
9160 "BGP RIB advertisement statistics\n")
9161
9162DEFUN (show_bgp_statistics_view,
9163 show_bgp_statistics_view_cmd,
9164 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9165 SHOW_STR
9166 BGP_STR
9167 "BGP view\n"
9168 "Address family\n"
9169 "Address family\n"
9170 "Address Family modifier\n"
9171 "Address Family modifier\n"
9172 "BGP RIB advertisement statistics\n")
9173{
9174 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9175}
9176
9177ALIAS (show_bgp_statistics_view,
9178 show_bgp_statistics_view_vpnv4_cmd,
9179 "show bgp view WORD (ipv4) (vpnv4) statistics",
9180 SHOW_STR
9181 BGP_STR
9182 "BGP view\n"
9183 "Address family\n"
9184 "Address Family modifier\n"
9185 "BGP RIB advertisement statistics\n")
9186
Paul Jakmaff7924f2006-09-04 01:10:36 +00009187enum bgp_pcounts
9188{
9189 PCOUNT_ADJ_IN = 0,
9190 PCOUNT_DAMPED,
9191 PCOUNT_REMOVED,
9192 PCOUNT_HISTORY,
9193 PCOUNT_STALE,
9194 PCOUNT_VALID,
9195 PCOUNT_ALL,
9196 PCOUNT_COUNTED,
9197 PCOUNT_PFCNT, /* the figure we display to users */
9198 PCOUNT_MAX,
9199};
9200
9201static const char *pcount_strs[] =
9202{
9203 [PCOUNT_ADJ_IN] = "Adj-in",
9204 [PCOUNT_DAMPED] = "Damped",
9205 [PCOUNT_REMOVED] = "Removed",
9206 [PCOUNT_HISTORY] = "History",
9207 [PCOUNT_STALE] = "Stale",
9208 [PCOUNT_VALID] = "Valid",
9209 [PCOUNT_ALL] = "All RIB",
9210 [PCOUNT_COUNTED] = "PfxCt counted",
9211 [PCOUNT_PFCNT] = "Useable",
9212 [PCOUNT_MAX] = NULL,
9213};
9214
Paul Jakma2815e612006-09-14 02:56:07 +00009215struct peer_pcounts
9216{
9217 unsigned int count[PCOUNT_MAX];
9218 const struct peer *peer;
9219 const struct bgp_table *table;
9220};
9221
Paul Jakmaff7924f2006-09-04 01:10:36 +00009222static int
Paul Jakma2815e612006-09-14 02:56:07 +00009223bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009224{
9225 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009226 struct peer_pcounts *pc = THREAD_ARG (t);
9227 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009228
Paul Jakma2815e612006-09-14 02:56:07 +00009229 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009230 {
9231 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009232 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009233
9234 for (ain = rn->adj_in; ain; ain = ain->next)
9235 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009236 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009237
Paul Jakmaff7924f2006-09-04 01:10:36 +00009238 for (ri = rn->info; ri; ri = ri->next)
9239 {
9240 char buf[SU_ADDRSTRLEN];
9241
9242 if (ri->peer != peer)
9243 continue;
9244
Paul Jakma2815e612006-09-14 02:56:07 +00009245 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009246
9247 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009248 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009249 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009250 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009251 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009252 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009253 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009254 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009255 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009256 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009257 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009258 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009259
9260 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9261 {
Paul Jakma2815e612006-09-14 02:56:07 +00009262 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009263 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009264 plog_warn (peer->log,
9265 "%s [pcount] %s/%d is counted but flags 0x%x",
9266 peer->host,
9267 inet_ntop(rn->p.family, &rn->p.u.prefix,
9268 buf, SU_ADDRSTRLEN),
9269 rn->p.prefixlen,
9270 ri->flags);
9271 }
9272 else
9273 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009274 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009275 plog_warn (peer->log,
9276 "%s [pcount] %s/%d not counted but flags 0x%x",
9277 peer->host,
9278 inet_ntop(rn->p.family, &rn->p.u.prefix,
9279 buf, SU_ADDRSTRLEN),
9280 rn->p.prefixlen,
9281 ri->flags);
9282 }
9283 }
9284 }
Paul Jakma2815e612006-09-14 02:56:07 +00009285 return 0;
9286}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009287
Paul Jakma2815e612006-09-14 02:56:07 +00009288static int
9289bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9290{
9291 struct peer_pcounts pcounts = { .peer = peer };
9292 unsigned int i;
9293
9294 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9295 || !peer->bgp->rib[afi][safi])
9296 {
9297 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9298 return CMD_WARNING;
9299 }
9300
9301 memset (&pcounts, 0, sizeof(pcounts));
9302 pcounts.peer = peer;
9303 pcounts.table = peer->bgp->rib[afi][safi];
9304
9305 /* in-place call via thread subsystem so as to record execution time
9306 * stats for the thread-walk (i.e. ensure this can't be blamed on
9307 * on just vty_read()).
9308 */
9309 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9310
Paul Jakmaff7924f2006-09-04 01:10:36 +00009311 vty_out (vty, "Prefix counts for %s, %s%s",
9312 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9313 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9314 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9315 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9316
9317 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009318 vty_out (vty, "%20s: %-10d%s",
9319 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009320
Paul Jakma2815e612006-09-14 02:56:07 +00009321 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009322 {
9323 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9324 peer->host, VTY_NEWLINE);
9325 vty_out (vty, "Please report this bug, with the above command output%s",
9326 VTY_NEWLINE);
9327 }
9328
9329 return CMD_SUCCESS;
9330}
9331
9332DEFUN (show_ip_bgp_neighbor_prefix_counts,
9333 show_ip_bgp_neighbor_prefix_counts_cmd,
9334 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9335 SHOW_STR
9336 IP_STR
9337 BGP_STR
9338 "Detailed information on TCP and BGP neighbor connections\n"
9339 "Neighbor to display information about\n"
9340 "Neighbor to display information about\n"
9341 "Display detailed prefix count information\n")
9342{
9343 struct peer *peer;
9344
9345 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9346 if (! peer)
9347 return CMD_WARNING;
9348
9349 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9350}
9351
9352DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9353 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9354 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9355 SHOW_STR
9356 BGP_STR
9357 "Address family\n"
9358 "Detailed information on TCP and BGP neighbor connections\n"
9359 "Neighbor to display information about\n"
9360 "Neighbor to display information about\n"
9361 "Display detailed prefix count information\n")
9362{
9363 struct peer *peer;
9364
9365 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9366 if (! peer)
9367 return CMD_WARNING;
9368
9369 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9370}
9371
9372DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9373 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9374 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9375 SHOW_STR
9376 IP_STR
9377 BGP_STR
9378 "Address family\n"
9379 "Address Family modifier\n"
9380 "Address Family modifier\n"
9381 "Detailed information on TCP and BGP neighbor connections\n"
9382 "Neighbor to display information about\n"
9383 "Neighbor to display information about\n"
9384 "Display detailed prefix count information\n")
9385{
9386 struct peer *peer;
9387
9388 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9389 if (! peer)
9390 return CMD_WARNING;
9391
9392 if (strncmp (argv[0], "m", 1) == 0)
9393 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9394
9395 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9396}
9397
9398DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9399 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9400 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9401 SHOW_STR
9402 IP_STR
9403 BGP_STR
9404 "Address family\n"
9405 "Address Family modifier\n"
9406 "Address Family modifier\n"
9407 "Detailed information on TCP and BGP neighbor connections\n"
9408 "Neighbor to display information about\n"
9409 "Neighbor to display information about\n"
9410 "Display detailed prefix count information\n")
9411{
9412 struct peer *peer;
9413
9414 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9415 if (! peer)
9416 return CMD_WARNING;
9417
9418 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9419}
9420
9421
paul94f2b392005-06-28 12:44:16 +00009422static void
paul718e3742002-12-13 20:15:29 +00009423show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9424 int in)
9425{
9426 struct bgp_table *table;
9427 struct bgp_adj_in *ain;
9428 struct bgp_adj_out *adj;
9429 unsigned long output_count;
9430 struct bgp_node *rn;
9431 int header1 = 1;
9432 struct bgp *bgp;
9433 int header2 = 1;
9434
paulbb46e942003-10-24 19:02:03 +00009435 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009436
9437 if (! bgp)
9438 return;
9439
9440 table = bgp->rib[afi][safi];
9441
9442 output_count = 0;
9443
9444 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9445 PEER_STATUS_DEFAULT_ORIGINATE))
9446 {
9447 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 +00009448 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9449 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009450
9451 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9452 VTY_NEWLINE, VTY_NEWLINE);
9453 header1 = 0;
9454 }
9455
9456 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9457 if (in)
9458 {
9459 for (ain = rn->adj_in; ain; ain = ain->next)
9460 if (ain->peer == peer)
9461 {
9462 if (header1)
9463 {
9464 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 +00009465 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9466 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009467 header1 = 0;
9468 }
9469 if (header2)
9470 {
9471 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9472 header2 = 0;
9473 }
9474 if (ain->attr)
9475 {
9476 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9477 output_count++;
9478 }
9479 }
9480 }
9481 else
9482 {
9483 for (adj = rn->adj_out; adj; adj = adj->next)
9484 if (adj->peer == peer)
9485 {
9486 if (header1)
9487 {
9488 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 +00009489 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9490 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009491 header1 = 0;
9492 }
9493 if (header2)
9494 {
9495 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9496 header2 = 0;
9497 }
9498 if (adj->attr)
9499 {
9500 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9501 output_count++;
9502 }
9503 }
9504 }
9505
9506 if (output_count != 0)
9507 vty_out (vty, "%sTotal number of prefixes %ld%s",
9508 VTY_NEWLINE, output_count, VTY_NEWLINE);
9509}
9510
paul94f2b392005-06-28 12:44:16 +00009511static int
paulbb46e942003-10-24 19:02:03 +00009512peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9513{
paul718e3742002-12-13 20:15:29 +00009514 if (! peer || ! peer->afc[afi][safi])
9515 {
9516 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9517 return CMD_WARNING;
9518 }
9519
9520 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9521 {
9522 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9523 VTY_NEWLINE);
9524 return CMD_WARNING;
9525 }
9526
9527 show_adj_route (vty, peer, afi, safi, in);
9528
9529 return CMD_SUCCESS;
9530}
9531
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009532DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9533 show_ip_bgp_view_neighbor_advertised_route_cmd,
9534 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9535 SHOW_STR
9536 IP_STR
9537 BGP_STR
9538 "BGP view\n"
9539 "View name\n"
9540 "Detailed information on TCP and BGP neighbor connections\n"
9541 "Neighbor to display information about\n"
9542 "Neighbor to display information about\n"
9543 "Display the routes advertised to a BGP neighbor\n")
9544{
9545 struct peer *peer;
9546
9547 if (argc == 2)
9548 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9549 else
9550 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9551
9552 if (! peer)
9553 return CMD_WARNING;
9554
9555 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9556}
9557
9558ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009559 show_ip_bgp_neighbor_advertised_route_cmd,
9560 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9561 SHOW_STR
9562 IP_STR
9563 BGP_STR
9564 "Detailed information on TCP and BGP neighbor connections\n"
9565 "Neighbor to display information about\n"
9566 "Neighbor to display information about\n"
9567 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009568
9569DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9570 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9571 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9572 SHOW_STR
9573 IP_STR
9574 BGP_STR
9575 "Address family\n"
9576 "Address Family modifier\n"
9577 "Address Family modifier\n"
9578 "Detailed information on TCP and BGP neighbor connections\n"
9579 "Neighbor to display information about\n"
9580 "Neighbor to display information about\n"
9581 "Display the routes advertised to a BGP neighbor\n")
9582{
paulbb46e942003-10-24 19:02:03 +00009583 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009584
paulbb46e942003-10-24 19:02:03 +00009585 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9586 if (! peer)
9587 return CMD_WARNING;
9588
9589 if (strncmp (argv[0], "m", 1) == 0)
9590 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9591
9592 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009593}
9594
9595#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009596DEFUN (show_bgp_view_neighbor_advertised_route,
9597 show_bgp_view_neighbor_advertised_route_cmd,
9598 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9599 SHOW_STR
9600 BGP_STR
9601 "BGP view\n"
9602 "View name\n"
9603 "Detailed information on TCP and BGP neighbor connections\n"
9604 "Neighbor to display information about\n"
9605 "Neighbor to display information about\n"
9606 "Display the routes advertised to a BGP neighbor\n")
9607{
9608 struct peer *peer;
9609
9610 if (argc == 2)
9611 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9612 else
9613 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9614
9615 if (! peer)
9616 return CMD_WARNING;
9617
9618 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9619}
9620
9621ALIAS (show_bgp_view_neighbor_advertised_route,
9622 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9623 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9624 SHOW_STR
9625 BGP_STR
9626 "BGP view\n"
9627 "View name\n"
9628 "Address family\n"
9629 "Detailed information on TCP and BGP neighbor connections\n"
9630 "Neighbor to display information about\n"
9631 "Neighbor to display information about\n"
9632 "Display the routes advertised to a BGP neighbor\n")
9633
9634DEFUN (show_bgp_view_neighbor_received_routes,
9635 show_bgp_view_neighbor_received_routes_cmd,
9636 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9637 SHOW_STR
9638 BGP_STR
9639 "BGP view\n"
9640 "View name\n"
9641 "Detailed information on TCP and BGP neighbor connections\n"
9642 "Neighbor to display information about\n"
9643 "Neighbor to display information about\n"
9644 "Display the received routes from neighbor\n")
9645{
9646 struct peer *peer;
9647
9648 if (argc == 2)
9649 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9650 else
9651 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9652
9653 if (! peer)
9654 return CMD_WARNING;
9655
9656 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9657}
9658
9659ALIAS (show_bgp_view_neighbor_received_routes,
9660 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9661 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9662 SHOW_STR
9663 BGP_STR
9664 "BGP view\n"
9665 "View name\n"
9666 "Address family\n"
9667 "Detailed information on TCP and BGP neighbor connections\n"
9668 "Neighbor to display information about\n"
9669 "Neighbor to display information about\n"
9670 "Display the received routes from neighbor\n")
9671
9672ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009673 show_bgp_neighbor_advertised_route_cmd,
9674 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9675 SHOW_STR
9676 BGP_STR
9677 "Detailed information on TCP and BGP neighbor connections\n"
9678 "Neighbor to display information about\n"
9679 "Neighbor to display information about\n"
9680 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009681
9682ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009683 show_bgp_ipv6_neighbor_advertised_route_cmd,
9684 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9685 SHOW_STR
9686 BGP_STR
9687 "Address family\n"
9688 "Detailed information on TCP and BGP neighbor connections\n"
9689 "Neighbor to display information about\n"
9690 "Neighbor to display information about\n"
9691 "Display the routes advertised to a BGP neighbor\n")
9692
9693/* old command */
paulbb46e942003-10-24 19:02:03 +00009694ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009695 ipv6_bgp_neighbor_advertised_route_cmd,
9696 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9697 SHOW_STR
9698 IPV6_STR
9699 BGP_STR
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 the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009704
paul718e3742002-12-13 20:15:29 +00009705/* old command */
9706DEFUN (ipv6_mbgp_neighbor_advertised_route,
9707 ipv6_mbgp_neighbor_advertised_route_cmd,
9708 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9709 SHOW_STR
9710 IPV6_STR
9711 MBGP_STR
9712 "Detailed information on TCP and BGP neighbor connections\n"
9713 "Neighbor to display information about\n"
9714 "Neighbor to display information about\n"
9715 "Display the routes advertised to a BGP neighbor\n")
9716{
paulbb46e942003-10-24 19:02:03 +00009717 struct peer *peer;
9718
9719 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9720 if (! peer)
9721 return CMD_WARNING;
9722
9723 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009724}
9725#endif /* HAVE_IPV6 */
9726
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009727DEFUN (show_ip_bgp_view_neighbor_received_routes,
9728 show_ip_bgp_view_neighbor_received_routes_cmd,
9729 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9730 SHOW_STR
9731 IP_STR
9732 BGP_STR
9733 "BGP view\n"
9734 "View name\n"
9735 "Detailed information on TCP and BGP neighbor connections\n"
9736 "Neighbor to display information about\n"
9737 "Neighbor to display information about\n"
9738 "Display the received routes from neighbor\n")
9739{
9740 struct peer *peer;
9741
9742 if (argc == 2)
9743 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9744 else
9745 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9746
9747 if (! peer)
9748 return CMD_WARNING;
9749
9750 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9751}
9752
9753ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009754 show_ip_bgp_neighbor_received_routes_cmd,
9755 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9756 SHOW_STR
9757 IP_STR
9758 BGP_STR
9759 "Detailed information on TCP and BGP neighbor connections\n"
9760 "Neighbor to display information about\n"
9761 "Neighbor to display information about\n"
9762 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009763
9764DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9765 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9766 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9767 SHOW_STR
9768 IP_STR
9769 BGP_STR
9770 "Address family\n"
9771 "Address Family modifier\n"
9772 "Address Family modifier\n"
9773 "Detailed information on TCP and BGP neighbor connections\n"
9774 "Neighbor to display information about\n"
9775 "Neighbor to display information about\n"
9776 "Display the received routes from neighbor\n")
9777{
paulbb46e942003-10-24 19:02:03 +00009778 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009779
paulbb46e942003-10-24 19:02:03 +00009780 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9781 if (! peer)
9782 return CMD_WARNING;
9783
9784 if (strncmp (argv[0], "m", 1) == 0)
9785 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9786
9787 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009788}
9789
9790DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9791 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9792 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9793 SHOW_STR
9794 IP_STR
9795 BGP_STR
9796 "Detailed information on TCP and BGP neighbor connections\n"
9797 "Neighbor to display information about\n"
9798 "Neighbor to display information about\n"
9799 "Display information received from a BGP neighbor\n"
9800 "Display the prefixlist filter\n")
9801{
9802 char name[BUFSIZ];
9803 union sockunion *su;
9804 struct peer *peer;
9805 int count;
9806
9807 su = sockunion_str2su (argv[0]);
9808 if (su == NULL)
9809 return CMD_WARNING;
9810
9811 peer = peer_lookup (NULL, su);
9812 if (! peer)
9813 return CMD_WARNING;
9814
9815 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9816 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9817 if (count)
9818 {
9819 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9820 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9821 }
9822
9823 return CMD_SUCCESS;
9824}
9825
9826DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9827 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9828 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9829 SHOW_STR
9830 IP_STR
9831 BGP_STR
9832 "Address family\n"
9833 "Address Family modifier\n"
9834 "Address Family modifier\n"
9835 "Detailed information on TCP and BGP neighbor connections\n"
9836 "Neighbor to display information about\n"
9837 "Neighbor to display information about\n"
9838 "Display information received from a BGP neighbor\n"
9839 "Display the prefixlist filter\n")
9840{
9841 char name[BUFSIZ];
9842 union sockunion *su;
9843 struct peer *peer;
9844 int count;
9845
9846 su = sockunion_str2su (argv[1]);
9847 if (su == NULL)
9848 return CMD_WARNING;
9849
9850 peer = peer_lookup (NULL, su);
9851 if (! peer)
9852 return CMD_WARNING;
9853
9854 if (strncmp (argv[0], "m", 1) == 0)
9855 {
9856 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9857 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9858 if (count)
9859 {
9860 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9861 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9862 }
9863 }
9864 else
9865 {
9866 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9867 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9868 if (count)
9869 {
9870 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9871 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9872 }
9873 }
9874
9875 return CMD_SUCCESS;
9876}
9877
9878
9879#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009880ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009881 show_bgp_neighbor_received_routes_cmd,
9882 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9883 SHOW_STR
9884 BGP_STR
9885 "Detailed information on TCP and BGP neighbor connections\n"
9886 "Neighbor to display information about\n"
9887 "Neighbor to display information about\n"
9888 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009889
paulbb46e942003-10-24 19:02:03 +00009890ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009891 show_bgp_ipv6_neighbor_received_routes_cmd,
9892 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9893 SHOW_STR
9894 BGP_STR
9895 "Address family\n"
9896 "Detailed information on TCP and BGP neighbor connections\n"
9897 "Neighbor to display information about\n"
9898 "Neighbor to display information about\n"
9899 "Display the received routes from neighbor\n")
9900
9901DEFUN (show_bgp_neighbor_received_prefix_filter,
9902 show_bgp_neighbor_received_prefix_filter_cmd,
9903 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9904 SHOW_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 information received from a BGP neighbor\n"
9910 "Display the prefixlist filter\n")
9911{
9912 char name[BUFSIZ];
9913 union sockunion *su;
9914 struct peer *peer;
9915 int count;
9916
9917 su = sockunion_str2su (argv[0]);
9918 if (su == NULL)
9919 return CMD_WARNING;
9920
9921 peer = peer_lookup (NULL, su);
9922 if (! peer)
9923 return CMD_WARNING;
9924
9925 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9926 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9927 if (count)
9928 {
9929 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9930 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9931 }
9932
9933 return CMD_SUCCESS;
9934}
9935
9936ALIAS (show_bgp_neighbor_received_prefix_filter,
9937 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
9938 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9939 SHOW_STR
9940 BGP_STR
9941 "Address family\n"
9942 "Detailed information on TCP and BGP neighbor connections\n"
9943 "Neighbor to display information about\n"
9944 "Neighbor to display information about\n"
9945 "Display information received from a BGP neighbor\n"
9946 "Display the prefixlist filter\n")
9947
9948/* old command */
paulbb46e942003-10-24 19:02:03 +00009949ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009950 ipv6_bgp_neighbor_received_routes_cmd,
9951 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9952 SHOW_STR
9953 IPV6_STR
9954 BGP_STR
9955 "Detailed information on TCP and BGP neighbor connections\n"
9956 "Neighbor to display information about\n"
9957 "Neighbor to display information about\n"
9958 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009959
9960/* old command */
9961DEFUN (ipv6_mbgp_neighbor_received_routes,
9962 ipv6_mbgp_neighbor_received_routes_cmd,
9963 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9964 SHOW_STR
9965 IPV6_STR
9966 MBGP_STR
9967 "Detailed information on TCP and BGP neighbor connections\n"
9968 "Neighbor to display information about\n"
9969 "Neighbor to display information about\n"
9970 "Display the received routes from neighbor\n")
9971{
paulbb46e942003-10-24 19:02:03 +00009972 struct peer *peer;
9973
9974 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9975 if (! peer)
9976 return CMD_WARNING;
9977
9978 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00009979}
paulbb46e942003-10-24 19:02:03 +00009980
9981DEFUN (show_bgp_view_neighbor_received_prefix_filter,
9982 show_bgp_view_neighbor_received_prefix_filter_cmd,
9983 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9984 SHOW_STR
9985 BGP_STR
9986 "BGP view\n"
9987 "View name\n"
9988 "Detailed information on TCP and BGP neighbor connections\n"
9989 "Neighbor to display information about\n"
9990 "Neighbor to display information about\n"
9991 "Display information received from a BGP neighbor\n"
9992 "Display the prefixlist filter\n")
9993{
9994 char name[BUFSIZ];
9995 union sockunion *su;
9996 struct peer *peer;
9997 struct bgp *bgp;
9998 int count;
9999
10000 /* BGP structure lookup. */
10001 bgp = bgp_lookup_by_name (argv[0]);
10002 if (bgp == NULL)
10003 {
10004 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10005 return CMD_WARNING;
10006 }
10007
10008 su = sockunion_str2su (argv[1]);
10009 if (su == NULL)
10010 return CMD_WARNING;
10011
10012 peer = peer_lookup (bgp, su);
10013 if (! peer)
10014 return CMD_WARNING;
10015
10016 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10017 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10018 if (count)
10019 {
10020 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10021 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10022 }
10023
10024 return CMD_SUCCESS;
10025}
10026
10027ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10028 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10029 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10030 SHOW_STR
10031 BGP_STR
10032 "BGP view\n"
10033 "View name\n"
10034 "Address family\n"
10035 "Detailed information on TCP and BGP neighbor connections\n"
10036 "Neighbor to display information about\n"
10037 "Neighbor to display information about\n"
10038 "Display information received from a BGP neighbor\n"
10039 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010040#endif /* HAVE_IPV6 */
10041
paul94f2b392005-06-28 12:44:16 +000010042static int
paulbb46e942003-10-24 19:02:03 +000010043bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010044 safi_t safi, enum bgp_show_type type)
10045{
paul718e3742002-12-13 20:15:29 +000010046 if (! peer || ! peer->afc[afi][safi])
10047 {
10048 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010049 return CMD_WARNING;
10050 }
10051
ajs5a646652004-11-05 01:25:55 +000010052 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010053}
10054
10055DEFUN (show_ip_bgp_neighbor_routes,
10056 show_ip_bgp_neighbor_routes_cmd,
10057 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10058 SHOW_STR
10059 IP_STR
10060 BGP_STR
10061 "Detailed information on TCP and BGP neighbor connections\n"
10062 "Neighbor to display information about\n"
10063 "Neighbor to display information about\n"
10064 "Display routes learned from neighbor\n")
10065{
paulbb46e942003-10-24 19:02:03 +000010066 struct peer *peer;
10067
10068 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10069 if (! peer)
10070 return CMD_WARNING;
10071
10072 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010073 bgp_show_type_neighbor);
10074}
10075
10076DEFUN (show_ip_bgp_neighbor_flap,
10077 show_ip_bgp_neighbor_flap_cmd,
10078 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10079 SHOW_STR
10080 IP_STR
10081 BGP_STR
10082 "Detailed information on TCP and BGP neighbor connections\n"
10083 "Neighbor to display information about\n"
10084 "Neighbor to display information about\n"
10085 "Display flap statistics of the routes learned from neighbor\n")
10086{
paulbb46e942003-10-24 19:02:03 +000010087 struct peer *peer;
10088
10089 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10090 if (! peer)
10091 return CMD_WARNING;
10092
10093 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010094 bgp_show_type_flap_neighbor);
10095}
10096
10097DEFUN (show_ip_bgp_neighbor_damp,
10098 show_ip_bgp_neighbor_damp_cmd,
10099 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10100 SHOW_STR
10101 IP_STR
10102 BGP_STR
10103 "Detailed information on TCP and BGP neighbor connections\n"
10104 "Neighbor to display information about\n"
10105 "Neighbor to display information about\n"
10106 "Display the dampened routes received from neighbor\n")
10107{
paulbb46e942003-10-24 19:02:03 +000010108 struct peer *peer;
10109
10110 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10111 if (! peer)
10112 return CMD_WARNING;
10113
10114 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010115 bgp_show_type_damp_neighbor);
10116}
10117
10118DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10119 show_ip_bgp_ipv4_neighbor_routes_cmd,
10120 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10121 SHOW_STR
10122 IP_STR
10123 BGP_STR
10124 "Address family\n"
10125 "Address Family modifier\n"
10126 "Address Family modifier\n"
10127 "Detailed information on TCP and BGP neighbor connections\n"
10128 "Neighbor to display information about\n"
10129 "Neighbor to display information about\n"
10130 "Display routes learned from neighbor\n")
10131{
paulbb46e942003-10-24 19:02:03 +000010132 struct peer *peer;
10133
10134 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10135 if (! peer)
10136 return CMD_WARNING;
10137
paul718e3742002-12-13 20:15:29 +000010138 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010139 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010140 bgp_show_type_neighbor);
10141
paulbb46e942003-10-24 19:02:03 +000010142 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010143 bgp_show_type_neighbor);
10144}
paulbb46e942003-10-24 19:02:03 +000010145
paulfee0f4c2004-09-13 05:12:46 +000010146DEFUN (show_ip_bgp_view_rsclient,
10147 show_ip_bgp_view_rsclient_cmd,
10148 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10149 SHOW_STR
10150 IP_STR
10151 BGP_STR
10152 "BGP view\n"
10153 "BGP view name\n"
10154 "Information about Route Server Client\n"
10155 NEIGHBOR_ADDR_STR)
10156{
10157 struct bgp_table *table;
10158 struct peer *peer;
10159
10160 if (argc == 2)
10161 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10162 else
10163 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10164
10165 if (! peer)
10166 return CMD_WARNING;
10167
10168 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10169 {
10170 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10171 VTY_NEWLINE);
10172 return CMD_WARNING;
10173 }
10174
10175 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10176 PEER_FLAG_RSERVER_CLIENT))
10177 {
10178 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10179 VTY_NEWLINE);
10180 return CMD_WARNING;
10181 }
10182
10183 table = peer->rib[AFI_IP][SAFI_UNICAST];
10184
ajs5a646652004-11-05 01:25:55 +000010185 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010186}
10187
10188ALIAS (show_ip_bgp_view_rsclient,
10189 show_ip_bgp_rsclient_cmd,
10190 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10191 SHOW_STR
10192 IP_STR
10193 BGP_STR
10194 "Information about Route Server Client\n"
10195 NEIGHBOR_ADDR_STR)
10196
10197DEFUN (show_ip_bgp_view_rsclient_route,
10198 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010199 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010200 SHOW_STR
10201 IP_STR
10202 BGP_STR
10203 "BGP view\n"
10204 "BGP view name\n"
10205 "Information about Route Server Client\n"
10206 NEIGHBOR_ADDR_STR
10207 "Network in the BGP routing table to display\n")
10208{
10209 struct bgp *bgp;
10210 struct peer *peer;
10211
10212 /* BGP structure lookup. */
10213 if (argc == 3)
10214 {
10215 bgp = bgp_lookup_by_name (argv[0]);
10216 if (bgp == NULL)
10217 {
10218 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10219 return CMD_WARNING;
10220 }
10221 }
10222 else
10223 {
10224 bgp = bgp_get_default ();
10225 if (bgp == NULL)
10226 {
10227 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10228 return CMD_WARNING;
10229 }
10230 }
10231
10232 if (argc == 3)
10233 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10234 else
10235 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10236
10237 if (! peer)
10238 return CMD_WARNING;
10239
10240 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10241 {
10242 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10243 VTY_NEWLINE);
10244 return CMD_WARNING;
10245}
10246
10247 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10248 PEER_FLAG_RSERVER_CLIENT))
10249 {
10250 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10251 VTY_NEWLINE);
10252 return CMD_WARNING;
10253 }
10254
10255 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10256 (argc == 3) ? argv[2] : argv[1],
10257 AFI_IP, SAFI_UNICAST, NULL, 0);
10258}
10259
10260ALIAS (show_ip_bgp_view_rsclient_route,
10261 show_ip_bgp_rsclient_route_cmd,
10262 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10263 SHOW_STR
10264 IP_STR
10265 BGP_STR
10266 "Information about Route Server Client\n"
10267 NEIGHBOR_ADDR_STR
10268 "Network in the BGP routing table to display\n")
10269
10270DEFUN (show_ip_bgp_view_rsclient_prefix,
10271 show_ip_bgp_view_rsclient_prefix_cmd,
10272 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10273 SHOW_STR
10274 IP_STR
10275 BGP_STR
10276 "BGP view\n"
10277 "BGP view name\n"
10278 "Information about Route Server Client\n"
10279 NEIGHBOR_ADDR_STR
10280 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10281{
10282 struct bgp *bgp;
10283 struct peer *peer;
10284
10285 /* BGP structure lookup. */
10286 if (argc == 3)
10287 {
10288 bgp = bgp_lookup_by_name (argv[0]);
10289 if (bgp == NULL)
10290 {
10291 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10292 return CMD_WARNING;
10293 }
10294 }
10295 else
10296 {
10297 bgp = bgp_get_default ();
10298 if (bgp == NULL)
10299 {
10300 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10301 return CMD_WARNING;
10302 }
10303 }
10304
10305 if (argc == 3)
10306 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10307 else
10308 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10309
10310 if (! peer)
10311 return CMD_WARNING;
10312
10313 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10314 {
10315 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10316 VTY_NEWLINE);
10317 return CMD_WARNING;
10318}
10319
10320 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10321 PEER_FLAG_RSERVER_CLIENT))
10322{
10323 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10324 VTY_NEWLINE);
10325 return CMD_WARNING;
10326 }
10327
10328 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10329 (argc == 3) ? argv[2] : argv[1],
10330 AFI_IP, SAFI_UNICAST, NULL, 1);
10331}
10332
10333ALIAS (show_ip_bgp_view_rsclient_prefix,
10334 show_ip_bgp_rsclient_prefix_cmd,
10335 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10336 SHOW_STR
10337 IP_STR
10338 BGP_STR
10339 "Information about Route Server Client\n"
10340 NEIGHBOR_ADDR_STR
10341 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10342
10343
paul718e3742002-12-13 20:15:29 +000010344#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010345DEFUN (show_bgp_view_neighbor_routes,
10346 show_bgp_view_neighbor_routes_cmd,
10347 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10348 SHOW_STR
10349 BGP_STR
10350 "BGP view\n"
10351 "BGP view name\n"
10352 "Detailed information on TCP and BGP neighbor connections\n"
10353 "Neighbor to display information about\n"
10354 "Neighbor to display information about\n"
10355 "Display routes learned from neighbor\n")
10356{
10357 struct peer *peer;
10358
10359 if (argc == 2)
10360 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10361 else
10362 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10363
10364 if (! peer)
10365 return CMD_WARNING;
10366
10367 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10368 bgp_show_type_neighbor);
10369}
10370
10371ALIAS (show_bgp_view_neighbor_routes,
10372 show_bgp_view_ipv6_neighbor_routes_cmd,
10373 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10374 SHOW_STR
10375 BGP_STR
10376 "BGP view\n"
10377 "BGP view name\n"
10378 "Address family\n"
10379 "Detailed information on TCP and BGP neighbor connections\n"
10380 "Neighbor to display information about\n"
10381 "Neighbor to display information about\n"
10382 "Display routes learned from neighbor\n")
10383
10384DEFUN (show_bgp_view_neighbor_damp,
10385 show_bgp_view_neighbor_damp_cmd,
10386 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10387 SHOW_STR
10388 BGP_STR
10389 "BGP view\n"
10390 "BGP view name\n"
10391 "Detailed information on TCP and BGP neighbor connections\n"
10392 "Neighbor to display information about\n"
10393 "Neighbor to display information about\n"
10394 "Display the dampened routes received from neighbor\n")
10395{
10396 struct peer *peer;
10397
10398 if (argc == 2)
10399 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10400 else
10401 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10402
10403 if (! peer)
10404 return CMD_WARNING;
10405
10406 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10407 bgp_show_type_damp_neighbor);
10408}
10409
10410ALIAS (show_bgp_view_neighbor_damp,
10411 show_bgp_view_ipv6_neighbor_damp_cmd,
10412 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10413 SHOW_STR
10414 BGP_STR
10415 "BGP view\n"
10416 "BGP view name\n"
10417 "Address family\n"
10418 "Detailed information on TCP and BGP neighbor connections\n"
10419 "Neighbor to display information about\n"
10420 "Neighbor to display information about\n"
10421 "Display the dampened routes received from neighbor\n")
10422
10423DEFUN (show_bgp_view_neighbor_flap,
10424 show_bgp_view_neighbor_flap_cmd,
10425 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10426 SHOW_STR
10427 BGP_STR
10428 "BGP view\n"
10429 "BGP view name\n"
10430 "Detailed information on TCP and BGP neighbor connections\n"
10431 "Neighbor to display information about\n"
10432 "Neighbor to display information about\n"
10433 "Display flap statistics of the routes learned from neighbor\n")
10434{
10435 struct peer *peer;
10436
10437 if (argc == 2)
10438 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10439 else
10440 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10441
10442 if (! peer)
10443 return CMD_WARNING;
10444
10445 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10446 bgp_show_type_flap_neighbor);
10447}
10448
10449ALIAS (show_bgp_view_neighbor_flap,
10450 show_bgp_view_ipv6_neighbor_flap_cmd,
10451 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10452 SHOW_STR
10453 BGP_STR
10454 "BGP view\n"
10455 "BGP view name\n"
10456 "Address family\n"
10457 "Detailed information on TCP and BGP neighbor connections\n"
10458 "Neighbor to display information about\n"
10459 "Neighbor to display information about\n"
10460 "Display flap statistics of the routes learned from neighbor\n")
10461
10462ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010463 show_bgp_neighbor_routes_cmd,
10464 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10465 SHOW_STR
10466 BGP_STR
10467 "Detailed information on TCP and BGP neighbor connections\n"
10468 "Neighbor to display information about\n"
10469 "Neighbor to display information about\n"
10470 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010471
paulbb46e942003-10-24 19:02:03 +000010472
10473ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010474 show_bgp_ipv6_neighbor_routes_cmd,
10475 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10476 SHOW_STR
10477 BGP_STR
10478 "Address family\n"
10479 "Detailed information on TCP and BGP neighbor connections\n"
10480 "Neighbor to display information about\n"
10481 "Neighbor to display information about\n"
10482 "Display routes learned from neighbor\n")
10483
10484/* old command */
paulbb46e942003-10-24 19:02:03 +000010485ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010486 ipv6_bgp_neighbor_routes_cmd,
10487 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10488 SHOW_STR
10489 IPV6_STR
10490 BGP_STR
10491 "Detailed information on TCP and BGP neighbor connections\n"
10492 "Neighbor to display information about\n"
10493 "Neighbor to display information about\n"
10494 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010495
10496/* old command */
10497DEFUN (ipv6_mbgp_neighbor_routes,
10498 ipv6_mbgp_neighbor_routes_cmd,
10499 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10500 SHOW_STR
10501 IPV6_STR
10502 MBGP_STR
10503 "Detailed information on TCP and BGP neighbor connections\n"
10504 "Neighbor to display information about\n"
10505 "Neighbor to display information about\n"
10506 "Display routes learned from neighbor\n")
10507{
paulbb46e942003-10-24 19:02:03 +000010508 struct peer *peer;
10509
10510 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10511 if (! peer)
10512 return CMD_WARNING;
10513
10514 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010515 bgp_show_type_neighbor);
10516}
paulbb46e942003-10-24 19:02:03 +000010517
10518ALIAS (show_bgp_view_neighbor_flap,
10519 show_bgp_neighbor_flap_cmd,
10520 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10521 SHOW_STR
10522 BGP_STR
10523 "Detailed information on TCP and BGP neighbor connections\n"
10524 "Neighbor to display information about\n"
10525 "Neighbor to display information about\n"
10526 "Display flap statistics of the routes learned from neighbor\n")
10527
10528ALIAS (show_bgp_view_neighbor_flap,
10529 show_bgp_ipv6_neighbor_flap_cmd,
10530 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10531 SHOW_STR
10532 BGP_STR
10533 "Address family\n"
10534 "Detailed information on TCP and BGP neighbor connections\n"
10535 "Neighbor to display information about\n"
10536 "Neighbor to display information about\n"
10537 "Display flap statistics of the routes learned from neighbor\n")
10538
10539ALIAS (show_bgp_view_neighbor_damp,
10540 show_bgp_neighbor_damp_cmd,
10541 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10542 SHOW_STR
10543 BGP_STR
10544 "Detailed information on TCP and BGP neighbor connections\n"
10545 "Neighbor to display information about\n"
10546 "Neighbor to display information about\n"
10547 "Display the dampened routes received from neighbor\n")
10548
10549ALIAS (show_bgp_view_neighbor_damp,
10550 show_bgp_ipv6_neighbor_damp_cmd,
10551 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10552 SHOW_STR
10553 BGP_STR
10554 "Address family\n"
10555 "Detailed information on TCP and BGP neighbor connections\n"
10556 "Neighbor to display information about\n"
10557 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010558 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010559
10560DEFUN (show_bgp_view_rsclient,
10561 show_bgp_view_rsclient_cmd,
10562 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10563 SHOW_STR
10564 BGP_STR
10565 "BGP view\n"
10566 "BGP view name\n"
10567 "Information about Route Server Client\n"
10568 NEIGHBOR_ADDR_STR)
10569{
10570 struct bgp_table *table;
10571 struct peer *peer;
10572
10573 if (argc == 2)
10574 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10575 else
10576 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10577
10578 if (! peer)
10579 return CMD_WARNING;
10580
10581 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10582 {
10583 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10584 VTY_NEWLINE);
10585 return CMD_WARNING;
10586 }
10587
10588 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10589 PEER_FLAG_RSERVER_CLIENT))
10590 {
10591 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10592 VTY_NEWLINE);
10593 return CMD_WARNING;
10594 }
10595
10596 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10597
ajs5a646652004-11-05 01:25:55 +000010598 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010599}
10600
10601ALIAS (show_bgp_view_rsclient,
10602 show_bgp_rsclient_cmd,
10603 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10604 SHOW_STR
10605 BGP_STR
10606 "Information about Route Server Client\n"
10607 NEIGHBOR_ADDR_STR)
10608
10609DEFUN (show_bgp_view_rsclient_route,
10610 show_bgp_view_rsclient_route_cmd,
10611 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10612 SHOW_STR
10613 BGP_STR
10614 "BGP view\n"
10615 "BGP view name\n"
10616 "Information about Route Server Client\n"
10617 NEIGHBOR_ADDR_STR
10618 "Network in the BGP routing table to display\n")
10619{
10620 struct bgp *bgp;
10621 struct peer *peer;
10622
10623 /* BGP structure lookup. */
10624 if (argc == 3)
10625 {
10626 bgp = bgp_lookup_by_name (argv[0]);
10627 if (bgp == NULL)
10628 {
10629 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10630 return CMD_WARNING;
10631 }
10632 }
10633 else
10634 {
10635 bgp = bgp_get_default ();
10636 if (bgp == NULL)
10637 {
10638 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10639 return CMD_WARNING;
10640 }
10641 }
10642
10643 if (argc == 3)
10644 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10645 else
10646 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10647
10648 if (! peer)
10649 return CMD_WARNING;
10650
10651 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10652 {
10653 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10654 VTY_NEWLINE);
10655 return CMD_WARNING;
10656 }
10657
10658 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10659 PEER_FLAG_RSERVER_CLIENT))
10660 {
10661 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10662 VTY_NEWLINE);
10663 return CMD_WARNING;
10664 }
10665
10666 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10667 (argc == 3) ? argv[2] : argv[1],
10668 AFI_IP6, SAFI_UNICAST, NULL, 0);
10669}
10670
10671ALIAS (show_bgp_view_rsclient_route,
10672 show_bgp_rsclient_route_cmd,
10673 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10674 SHOW_STR
10675 BGP_STR
10676 "Information about Route Server Client\n"
10677 NEIGHBOR_ADDR_STR
10678 "Network in the BGP routing table to display\n")
10679
10680DEFUN (show_bgp_view_rsclient_prefix,
10681 show_bgp_view_rsclient_prefix_cmd,
10682 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10683 SHOW_STR
10684 BGP_STR
10685 "BGP view\n"
10686 "BGP view name\n"
10687 "Information about Route Server Client\n"
10688 NEIGHBOR_ADDR_STR
10689 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10690{
10691 struct bgp *bgp;
10692 struct peer *peer;
10693
10694 /* BGP structure lookup. */
10695 if (argc == 3)
10696 {
10697 bgp = bgp_lookup_by_name (argv[0]);
10698 if (bgp == NULL)
10699 {
10700 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10701 return CMD_WARNING;
10702 }
10703 }
10704 else
10705 {
10706 bgp = bgp_get_default ();
10707 if (bgp == NULL)
10708 {
10709 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10710 return CMD_WARNING;
10711 }
10712 }
10713
10714 if (argc == 3)
10715 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10716 else
10717 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10718
10719 if (! peer)
10720 return CMD_WARNING;
10721
10722 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10723 {
10724 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10725 VTY_NEWLINE);
10726 return CMD_WARNING;
10727 }
10728
10729 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10730 PEER_FLAG_RSERVER_CLIENT))
10731 {
10732 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10733 VTY_NEWLINE);
10734 return CMD_WARNING;
10735 }
10736
10737 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10738 (argc == 3) ? argv[2] : argv[1],
10739 AFI_IP6, SAFI_UNICAST, NULL, 1);
10740}
10741
10742ALIAS (show_bgp_view_rsclient_prefix,
10743 show_bgp_rsclient_prefix_cmd,
10744 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10745 SHOW_STR
10746 BGP_STR
10747 "Information about Route Server Client\n"
10748 NEIGHBOR_ADDR_STR
10749 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10750
paul718e3742002-12-13 20:15:29 +000010751#endif /* HAVE_IPV6 */
10752
10753struct bgp_table *bgp_distance_table;
10754
10755struct bgp_distance
10756{
10757 /* Distance value for the IP source prefix. */
10758 u_char distance;
10759
10760 /* Name of the access-list to be matched. */
10761 char *access_list;
10762};
10763
paul94f2b392005-06-28 12:44:16 +000010764static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010765bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010766{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010767 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010768}
10769
paul94f2b392005-06-28 12:44:16 +000010770static void
paul718e3742002-12-13 20:15:29 +000010771bgp_distance_free (struct bgp_distance *bdistance)
10772{
10773 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10774}
10775
paul94f2b392005-06-28 12:44:16 +000010776static int
paulfd79ac92004-10-13 05:06:08 +000010777bgp_distance_set (struct vty *vty, const char *distance_str,
10778 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010779{
10780 int ret;
10781 struct prefix_ipv4 p;
10782 u_char distance;
10783 struct bgp_node *rn;
10784 struct bgp_distance *bdistance;
10785
10786 ret = str2prefix_ipv4 (ip_str, &p);
10787 if (ret == 0)
10788 {
10789 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10790 return CMD_WARNING;
10791 }
10792
10793 distance = atoi (distance_str);
10794
10795 /* Get BGP distance node. */
10796 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10797 if (rn->info)
10798 {
10799 bdistance = rn->info;
10800 bgp_unlock_node (rn);
10801 }
10802 else
10803 {
10804 bdistance = bgp_distance_new ();
10805 rn->info = bdistance;
10806 }
10807
10808 /* Set distance value. */
10809 bdistance->distance = distance;
10810
10811 /* Reset access-list configuration. */
10812 if (bdistance->access_list)
10813 {
10814 free (bdistance->access_list);
10815 bdistance->access_list = NULL;
10816 }
10817 if (access_list_str)
10818 bdistance->access_list = strdup (access_list_str);
10819
10820 return CMD_SUCCESS;
10821}
10822
paul94f2b392005-06-28 12:44:16 +000010823static int
paulfd79ac92004-10-13 05:06:08 +000010824bgp_distance_unset (struct vty *vty, const char *distance_str,
10825 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010826{
10827 int ret;
10828 struct prefix_ipv4 p;
10829 u_char distance;
10830 struct bgp_node *rn;
10831 struct bgp_distance *bdistance;
10832
10833 ret = str2prefix_ipv4 (ip_str, &p);
10834 if (ret == 0)
10835 {
10836 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10837 return CMD_WARNING;
10838 }
10839
10840 distance = atoi (distance_str);
10841
10842 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10843 if (! rn)
10844 {
10845 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10846 return CMD_WARNING;
10847 }
10848
10849 bdistance = rn->info;
10850
10851 if (bdistance->access_list)
10852 free (bdistance->access_list);
10853 bgp_distance_free (bdistance);
10854
10855 rn->info = NULL;
10856 bgp_unlock_node (rn);
10857 bgp_unlock_node (rn);
10858
10859 return CMD_SUCCESS;
10860}
10861
paul718e3742002-12-13 20:15:29 +000010862/* Apply BGP information to distance method. */
10863u_char
10864bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10865{
10866 struct bgp_node *rn;
10867 struct prefix_ipv4 q;
10868 struct peer *peer;
10869 struct bgp_distance *bdistance;
10870 struct access_list *alist;
10871 struct bgp_static *bgp_static;
10872
10873 if (! bgp)
10874 return 0;
10875
10876 if (p->family != AF_INET)
10877 return 0;
10878
10879 peer = rinfo->peer;
10880
10881 if (peer->su.sa.sa_family != AF_INET)
10882 return 0;
10883
10884 memset (&q, 0, sizeof (struct prefix_ipv4));
10885 q.family = AF_INET;
10886 q.prefix = peer->su.sin.sin_addr;
10887 q.prefixlen = IPV4_MAX_BITLEN;
10888
10889 /* Check source address. */
10890 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10891 if (rn)
10892 {
10893 bdistance = rn->info;
10894 bgp_unlock_node (rn);
10895
10896 if (bdistance->access_list)
10897 {
10898 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10899 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10900 return bdistance->distance;
10901 }
10902 else
10903 return bdistance->distance;
10904 }
10905
10906 /* Backdoor check. */
10907 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10908 if (rn)
10909 {
10910 bgp_static = rn->info;
10911 bgp_unlock_node (rn);
10912
10913 if (bgp_static->backdoor)
10914 {
10915 if (bgp->distance_local)
10916 return bgp->distance_local;
10917 else
10918 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10919 }
10920 }
10921
10922 if (peer_sort (peer) == BGP_PEER_EBGP)
10923 {
10924 if (bgp->distance_ebgp)
10925 return bgp->distance_ebgp;
10926 return ZEBRA_EBGP_DISTANCE_DEFAULT;
10927 }
10928 else
10929 {
10930 if (bgp->distance_ibgp)
10931 return bgp->distance_ibgp;
10932 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10933 }
10934}
10935
10936DEFUN (bgp_distance,
10937 bgp_distance_cmd,
10938 "distance bgp <1-255> <1-255> <1-255>",
10939 "Define an administrative distance\n"
10940 "BGP distance\n"
10941 "Distance for routes external to the AS\n"
10942 "Distance for routes internal to the AS\n"
10943 "Distance for local routes\n")
10944{
10945 struct bgp *bgp;
10946
10947 bgp = vty->index;
10948
10949 bgp->distance_ebgp = atoi (argv[0]);
10950 bgp->distance_ibgp = atoi (argv[1]);
10951 bgp->distance_local = atoi (argv[2]);
10952 return CMD_SUCCESS;
10953}
10954
10955DEFUN (no_bgp_distance,
10956 no_bgp_distance_cmd,
10957 "no distance bgp <1-255> <1-255> <1-255>",
10958 NO_STR
10959 "Define an administrative distance\n"
10960 "BGP distance\n"
10961 "Distance for routes external to the AS\n"
10962 "Distance for routes internal to the AS\n"
10963 "Distance for local routes\n")
10964{
10965 struct bgp *bgp;
10966
10967 bgp = vty->index;
10968
10969 bgp->distance_ebgp= 0;
10970 bgp->distance_ibgp = 0;
10971 bgp->distance_local = 0;
10972 return CMD_SUCCESS;
10973}
10974
10975ALIAS (no_bgp_distance,
10976 no_bgp_distance2_cmd,
10977 "no distance bgp",
10978 NO_STR
10979 "Define an administrative distance\n"
10980 "BGP distance\n")
10981
10982DEFUN (bgp_distance_source,
10983 bgp_distance_source_cmd,
10984 "distance <1-255> A.B.C.D/M",
10985 "Define an administrative distance\n"
10986 "Administrative distance\n"
10987 "IP source prefix\n")
10988{
10989 bgp_distance_set (vty, argv[0], argv[1], NULL);
10990 return CMD_SUCCESS;
10991}
10992
10993DEFUN (no_bgp_distance_source,
10994 no_bgp_distance_source_cmd,
10995 "no distance <1-255> A.B.C.D/M",
10996 NO_STR
10997 "Define an administrative distance\n"
10998 "Administrative distance\n"
10999 "IP source prefix\n")
11000{
11001 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11002 return CMD_SUCCESS;
11003}
11004
11005DEFUN (bgp_distance_source_access_list,
11006 bgp_distance_source_access_list_cmd,
11007 "distance <1-255> A.B.C.D/M WORD",
11008 "Define an administrative distance\n"
11009 "Administrative distance\n"
11010 "IP source prefix\n"
11011 "Access list name\n")
11012{
11013 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11014 return CMD_SUCCESS;
11015}
11016
11017DEFUN (no_bgp_distance_source_access_list,
11018 no_bgp_distance_source_access_list_cmd,
11019 "no distance <1-255> A.B.C.D/M WORD",
11020 NO_STR
11021 "Define an administrative distance\n"
11022 "Administrative distance\n"
11023 "IP source prefix\n"
11024 "Access list name\n")
11025{
11026 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11027 return CMD_SUCCESS;
11028}
11029
11030DEFUN (bgp_damp_set,
11031 bgp_damp_set_cmd,
11032 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11033 "BGP Specific commands\n"
11034 "Enable route-flap dampening\n"
11035 "Half-life time for the penalty\n"
11036 "Value to start reusing a route\n"
11037 "Value to start suppressing a route\n"
11038 "Maximum duration to suppress a stable route\n")
11039{
11040 struct bgp *bgp;
11041 int half = DEFAULT_HALF_LIFE * 60;
11042 int reuse = DEFAULT_REUSE;
11043 int suppress = DEFAULT_SUPPRESS;
11044 int max = 4 * half;
11045
11046 if (argc == 4)
11047 {
11048 half = atoi (argv[0]) * 60;
11049 reuse = atoi (argv[1]);
11050 suppress = atoi (argv[2]);
11051 max = atoi (argv[3]) * 60;
11052 }
11053 else if (argc == 1)
11054 {
11055 half = atoi (argv[0]) * 60;
11056 max = 4 * half;
11057 }
11058
11059 bgp = vty->index;
11060 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11061 half, reuse, suppress, max);
11062}
11063
11064ALIAS (bgp_damp_set,
11065 bgp_damp_set2_cmd,
11066 "bgp dampening <1-45>",
11067 "BGP Specific commands\n"
11068 "Enable route-flap dampening\n"
11069 "Half-life time for the penalty\n")
11070
11071ALIAS (bgp_damp_set,
11072 bgp_damp_set3_cmd,
11073 "bgp dampening",
11074 "BGP Specific commands\n"
11075 "Enable route-flap dampening\n")
11076
11077DEFUN (bgp_damp_unset,
11078 bgp_damp_unset_cmd,
11079 "no bgp dampening",
11080 NO_STR
11081 "BGP Specific commands\n"
11082 "Enable route-flap dampening\n")
11083{
11084 struct bgp *bgp;
11085
11086 bgp = vty->index;
11087 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11088}
11089
11090ALIAS (bgp_damp_unset,
11091 bgp_damp_unset2_cmd,
11092 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11093 NO_STR
11094 "BGP Specific commands\n"
11095 "Enable route-flap dampening\n"
11096 "Half-life time for the penalty\n"
11097 "Value to start reusing a route\n"
11098 "Value to start suppressing a route\n"
11099 "Maximum duration to suppress a stable route\n")
11100
11101DEFUN (show_ip_bgp_dampened_paths,
11102 show_ip_bgp_dampened_paths_cmd,
11103 "show ip bgp dampened-paths",
11104 SHOW_STR
11105 IP_STR
11106 BGP_STR
11107 "Display paths suppressed due to dampening\n")
11108{
ajs5a646652004-11-05 01:25:55 +000011109 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11110 NULL);
paul718e3742002-12-13 20:15:29 +000011111}
11112
11113DEFUN (show_ip_bgp_flap_statistics,
11114 show_ip_bgp_flap_statistics_cmd,
11115 "show ip bgp flap-statistics",
11116 SHOW_STR
11117 IP_STR
11118 BGP_STR
11119 "Display flap statistics of routes\n")
11120{
ajs5a646652004-11-05 01:25:55 +000011121 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11122 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011123}
11124
11125/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011126static int
paulfd79ac92004-10-13 05:06:08 +000011127bgp_clear_damp_route (struct vty *vty, const char *view_name,
11128 const char *ip_str, afi_t afi, safi_t safi,
11129 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011130{
11131 int ret;
11132 struct prefix match;
11133 struct bgp_node *rn;
11134 struct bgp_node *rm;
11135 struct bgp_info *ri;
11136 struct bgp_info *ri_temp;
11137 struct bgp *bgp;
11138 struct bgp_table *table;
11139
11140 /* BGP structure lookup. */
11141 if (view_name)
11142 {
11143 bgp = bgp_lookup_by_name (view_name);
11144 if (bgp == NULL)
11145 {
11146 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11147 return CMD_WARNING;
11148 }
11149 }
11150 else
11151 {
11152 bgp = bgp_get_default ();
11153 if (bgp == NULL)
11154 {
11155 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11156 return CMD_WARNING;
11157 }
11158 }
11159
11160 /* Check IP address argument. */
11161 ret = str2prefix (ip_str, &match);
11162 if (! ret)
11163 {
11164 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11165 return CMD_WARNING;
11166 }
11167
11168 match.family = afi2family (afi);
11169
11170 if (safi == SAFI_MPLS_VPN)
11171 {
11172 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11173 {
11174 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11175 continue;
11176
11177 if ((table = rn->info) != NULL)
11178 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011179 {
11180 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11181 {
11182 ri = rm->info;
11183 while (ri)
11184 {
11185 if (ri->extra && ri->extra->damp_info)
11186 {
11187 ri_temp = ri->next;
11188 bgp_damp_info_free (ri->extra->damp_info, 1);
11189 ri = ri_temp;
11190 }
11191 else
11192 ri = ri->next;
11193 }
11194 }
11195
11196 bgp_unlock_node (rm);
11197 }
paul718e3742002-12-13 20:15:29 +000011198 }
11199 }
11200 else
11201 {
11202 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011203 {
11204 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11205 {
11206 ri = rn->info;
11207 while (ri)
11208 {
11209 if (ri->extra && ri->extra->damp_info)
11210 {
11211 ri_temp = ri->next;
11212 bgp_damp_info_free (ri->extra->damp_info, 1);
11213 ri = ri_temp;
11214 }
11215 else
11216 ri = ri->next;
11217 }
11218 }
11219
11220 bgp_unlock_node (rn);
11221 }
paul718e3742002-12-13 20:15:29 +000011222 }
11223
11224 return CMD_SUCCESS;
11225}
11226
11227DEFUN (clear_ip_bgp_dampening,
11228 clear_ip_bgp_dampening_cmd,
11229 "clear ip bgp dampening",
11230 CLEAR_STR
11231 IP_STR
11232 BGP_STR
11233 "Clear route flap dampening information\n")
11234{
11235 bgp_damp_info_clean ();
11236 return CMD_SUCCESS;
11237}
11238
11239DEFUN (clear_ip_bgp_dampening_prefix,
11240 clear_ip_bgp_dampening_prefix_cmd,
11241 "clear ip bgp dampening A.B.C.D/M",
11242 CLEAR_STR
11243 IP_STR
11244 BGP_STR
11245 "Clear route flap dampening information\n"
11246 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11247{
11248 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11249 SAFI_UNICAST, NULL, 1);
11250}
11251
11252DEFUN (clear_ip_bgp_dampening_address,
11253 clear_ip_bgp_dampening_address_cmd,
11254 "clear ip bgp dampening A.B.C.D",
11255 CLEAR_STR
11256 IP_STR
11257 BGP_STR
11258 "Clear route flap dampening information\n"
11259 "Network to clear damping information\n")
11260{
11261 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11262 SAFI_UNICAST, NULL, 0);
11263}
11264
11265DEFUN (clear_ip_bgp_dampening_address_mask,
11266 clear_ip_bgp_dampening_address_mask_cmd,
11267 "clear ip bgp dampening A.B.C.D A.B.C.D",
11268 CLEAR_STR
11269 IP_STR
11270 BGP_STR
11271 "Clear route flap dampening information\n"
11272 "Network to clear damping information\n"
11273 "Network mask\n")
11274{
11275 int ret;
11276 char prefix_str[BUFSIZ];
11277
11278 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11279 if (! ret)
11280 {
11281 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11282 return CMD_WARNING;
11283 }
11284
11285 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11286 SAFI_UNICAST, NULL, 0);
11287}
11288
paul94f2b392005-06-28 12:44:16 +000011289static int
paul718e3742002-12-13 20:15:29 +000011290bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11291 afi_t afi, safi_t safi, int *write)
11292{
11293 struct bgp_node *prn;
11294 struct bgp_node *rn;
11295 struct bgp_table *table;
11296 struct prefix *p;
11297 struct prefix_rd *prd;
11298 struct bgp_static *bgp_static;
11299 u_int32_t label;
11300 char buf[SU_ADDRSTRLEN];
11301 char rdbuf[RD_ADDRSTRLEN];
11302
11303 /* Network configuration. */
11304 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11305 if ((table = prn->info) != NULL)
11306 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11307 if ((bgp_static = rn->info) != NULL)
11308 {
11309 p = &rn->p;
11310 prd = (struct prefix_rd *) &prn->p;
11311
11312 /* "address-family" display. */
11313 bgp_config_write_family_header (vty, afi, safi, write);
11314
11315 /* "network" configuration display. */
11316 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11317 label = decode_label (bgp_static->tag);
11318
11319 vty_out (vty, " network %s/%d rd %s tag %d",
11320 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11321 p->prefixlen,
11322 rdbuf, label);
11323 vty_out (vty, "%s", VTY_NEWLINE);
11324 }
11325 return 0;
11326}
11327
11328/* Configuration of static route announcement and aggregate
11329 information. */
11330int
11331bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11332 afi_t afi, safi_t safi, int *write)
11333{
11334 struct bgp_node *rn;
11335 struct prefix *p;
11336 struct bgp_static *bgp_static;
11337 struct bgp_aggregate *bgp_aggregate;
11338 char buf[SU_ADDRSTRLEN];
11339
11340 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11341 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11342
11343 /* Network configuration. */
11344 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11345 if ((bgp_static = rn->info) != NULL)
11346 {
11347 p = &rn->p;
11348
11349 /* "address-family" display. */
11350 bgp_config_write_family_header (vty, afi, safi, write);
11351
11352 /* "network" configuration display. */
11353 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11354 {
11355 u_int32_t destination;
11356 struct in_addr netmask;
11357
11358 destination = ntohl (p->u.prefix4.s_addr);
11359 masklen2ip (p->prefixlen, &netmask);
11360 vty_out (vty, " network %s",
11361 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11362
11363 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11364 || (IN_CLASSB (destination) && p->prefixlen == 16)
11365 || (IN_CLASSA (destination) && p->prefixlen == 8)
11366 || p->u.prefix4.s_addr == 0)
11367 {
11368 /* Natural mask is not display. */
11369 }
11370 else
11371 vty_out (vty, " mask %s", inet_ntoa (netmask));
11372 }
11373 else
11374 {
11375 vty_out (vty, " network %s/%d",
11376 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11377 p->prefixlen);
11378 }
11379
11380 if (bgp_static->rmap.name)
11381 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011382 else
11383 {
11384 if (bgp_static->backdoor)
11385 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000011386 }
paul718e3742002-12-13 20:15:29 +000011387
11388 vty_out (vty, "%s", VTY_NEWLINE);
11389 }
11390
11391 /* Aggregate-address configuration. */
11392 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11393 if ((bgp_aggregate = rn->info) != NULL)
11394 {
11395 p = &rn->p;
11396
11397 /* "address-family" display. */
11398 bgp_config_write_family_header (vty, afi, safi, write);
11399
11400 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11401 {
11402 struct in_addr netmask;
11403
11404 masklen2ip (p->prefixlen, &netmask);
11405 vty_out (vty, " aggregate-address %s %s",
11406 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11407 inet_ntoa (netmask));
11408 }
11409 else
11410 {
11411 vty_out (vty, " aggregate-address %s/%d",
11412 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11413 p->prefixlen);
11414 }
11415
11416 if (bgp_aggregate->as_set)
11417 vty_out (vty, " as-set");
11418
11419 if (bgp_aggregate->summary_only)
11420 vty_out (vty, " summary-only");
11421
11422 vty_out (vty, "%s", VTY_NEWLINE);
11423 }
11424
11425 return 0;
11426}
11427
11428int
11429bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11430{
11431 struct bgp_node *rn;
11432 struct bgp_distance *bdistance;
11433
11434 /* Distance configuration. */
11435 if (bgp->distance_ebgp
11436 && bgp->distance_ibgp
11437 && bgp->distance_local
11438 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11439 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11440 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11441 vty_out (vty, " distance bgp %d %d %d%s",
11442 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11443 VTY_NEWLINE);
11444
11445 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11446 if ((bdistance = rn->info) != NULL)
11447 {
11448 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11449 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11450 bdistance->access_list ? bdistance->access_list : "",
11451 VTY_NEWLINE);
11452 }
11453
11454 return 0;
11455}
11456
11457/* Allocate routing table structure and install commands. */
11458void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011459bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011460{
11461 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011462 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011463
11464 /* IPv4 BGP commands. */
11465 install_element (BGP_NODE, &bgp_network_cmd);
11466 install_element (BGP_NODE, &bgp_network_mask_cmd);
11467 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11468 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11469 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11470 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11471 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11472 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11473 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11474 install_element (BGP_NODE, &no_bgp_network_cmd);
11475 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11476 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11477 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11478 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11479 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11480 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11481 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11482 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11483
11484 install_element (BGP_NODE, &aggregate_address_cmd);
11485 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11486 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11487 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11488 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11489 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11490 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11491 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11492 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11493 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11494 install_element (BGP_NODE, &no_aggregate_address_cmd);
11495 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11496 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11497 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11498 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11499 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11500 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11501 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11502 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11503 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11504
11505 /* IPv4 unicast configuration. */
11506 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11507 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11508 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11509 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11510 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11511 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000011512 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011513 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11514 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11515 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11516 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11517 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000011518
paul718e3742002-12-13 20:15:29 +000011519 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11520 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11521 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11522 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11523 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11524 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11525 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11526 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11527 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11528 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11529 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11530 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11531 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11532 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11533 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11534 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11535 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11536 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11537 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11538 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11539
11540 /* IPv4 multicast configuration. */
11541 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11542 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11543 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11544 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11545 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11546 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11547 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11548 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11549 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11550 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11551 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11552 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11553 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11554 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11555 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11556 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11557 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11558 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11559 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11560 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11561 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11562 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11563 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11564 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11565 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11566 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11567 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11568 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11569 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11570 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11571 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11572 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11573
11574 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11575 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11576 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11577 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11578 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11579 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11580 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11581 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11582 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11583 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11584 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11585 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11586 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11587 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11588 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11589 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11590 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11591 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11592 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11593 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11594 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11595 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11596 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11597 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11598 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11599 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11600 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11601 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11602 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11603 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11604 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11605 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11606 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11607 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11608 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11609 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11610 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11611 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11612 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11613 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11614 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11615 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11616 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11617 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11618 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11619 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11620 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11621 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11622 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11623 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11624 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11625 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11626 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11627 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11628 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11629 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11630 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11631 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11632 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11633 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11634 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11635 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11636 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11637 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11638 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11639 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11640 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011641 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11642 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11643 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011644 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11645 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011646 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11647 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11648 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011649
11650 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11651 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11652 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11653 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11654 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11655 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11656 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11657 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11658 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11659 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11660 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11661 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11662 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11663 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11664 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11665 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11666 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11667 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11668 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11669 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11670 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11671 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11672 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11673 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11674 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11675 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11676 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11677 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11678 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11679 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011680
11681 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11682 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11683 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11684 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11685 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11686 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11687 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11688 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11689 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11690 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11691 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11692 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11693 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11694 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11695 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11696 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11697 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11698 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11699 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11700 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11701 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11702 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11703 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11704 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11705 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11706 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11707 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11708 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11709 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11710 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11711 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11712 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11713 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11714 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11715 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11716 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11717 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11718 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11719 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11720 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11721 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11722 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11723 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11724 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11725 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11726 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11727 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11728 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11729 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11730 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11731 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11732 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11733 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11734 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11735 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11736 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11737 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11738 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11739 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11740 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11741 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11742 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11743 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11744 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11745 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11746 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11747 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011748 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11749 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11750 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011751 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11752 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011753 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11754 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11755 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011756
11757 /* BGP dampening clear commands */
11758 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11759 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11760 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11761 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11762
Paul Jakmaff7924f2006-09-04 01:10:36 +000011763 /* prefix count */
11764 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11765 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11766 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011767#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011768 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11769
paul718e3742002-12-13 20:15:29 +000011770 /* New config IPv6 BGP commands. */
11771 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11772 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11773 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11774 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11775
11776 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11777 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11778 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11779 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11780
11781 /* Old config IPv6 BGP commands. */
11782 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11783 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11784
11785 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11786 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11787 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11788 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11789
11790 install_element (VIEW_NODE, &show_bgp_cmd);
11791 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11792 install_element (VIEW_NODE, &show_bgp_route_cmd);
11793 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11794 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11795 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11796 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11797 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11798 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11799 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11800 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11801 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11802 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11803 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11804 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11805 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11806 install_element (VIEW_NODE, &show_bgp_community_cmd);
11807 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11808 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11809 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11810 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11811 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11812 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11813 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11814 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11815 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11816 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11817 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11818 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11819 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11820 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11821 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11822 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11823 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11824 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11825 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11826 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11827 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11828 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11829 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11830 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11831 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11832 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11833 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11834 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11835 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011836 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11837 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11838 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11839 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011840 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11841 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11842 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011843 install_element (VIEW_NODE, &show_bgp_view_cmd);
11844 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11845 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11846 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11847 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11848 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11849 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11850 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11851 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11852 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11853 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11854 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11855 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11856 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11857 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11858 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11859 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11860 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011861 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11862 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11863 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011864
11865 /* Restricted:
11866 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
11867 */
11868 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
11869 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
11870 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
11871 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
11872 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
11873 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
11874 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
11875 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
11876 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
11877 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
11878 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
11879 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
11880 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
11881 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
11882 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
11883 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
11884 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
11885 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
11886 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
11887 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
11888 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
11889 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
11890 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
11891 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
11892 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
11893 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
11894 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11895 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11896 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
11897 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011898
11899 install_element (ENABLE_NODE, &show_bgp_cmd);
11900 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11901 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11902 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11903 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11904 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11905 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11906 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11907 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11908 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11909 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11910 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11911 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11912 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11913 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11914 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11915 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11916 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11917 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11918 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11919 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11920 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11921 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11922 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11923 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
11924 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
11925 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
11926 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
11927 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
11928 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
11929 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
11930 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
11931 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
11932 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
11933 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
11934 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11935 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
11936 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11937 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
11938 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11939 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
11940 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11941 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
11942 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11943 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11944 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011945 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
11946 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11947 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
11948 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011949 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
11950 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
11951 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011952 install_element (ENABLE_NODE, &show_bgp_view_cmd);
11953 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
11954 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
11955 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
11956 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
11957 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
11958 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11959 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11960 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11961 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11962 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
11963 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11964 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11965 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11966 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
11967 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11968 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
11969 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011970 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
11971 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
11972 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000011973
11974 /* Statistics */
11975 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
11976 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
11977 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
11978 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
11979
paul718e3742002-12-13 20:15:29 +000011980 /* old command */
11981 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
11982 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
11983 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
11984 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
11985 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
11986 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
11987 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
11988 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
11989 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
11990 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
11991 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
11992 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
11993 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
11994 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
11995 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
11996 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
11997 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11998 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11999 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12000 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12001 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12002 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12003 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12004 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12005 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12006 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12007 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12008 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12009 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12010 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12011 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12012 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12013 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12014 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12015 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12016 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012017
paul718e3742002-12-13 20:15:29 +000012018 /* old command */
12019 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12020 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12021 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12022 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12023 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12024 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12025 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12026 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12027 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12028 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12029 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12030 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12031 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12032 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12033 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12034 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12035 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12036 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12037 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12038 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12039 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12040 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12041 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12042 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12043 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12044 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12045 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12046 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12047 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12048 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12049 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12050 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12051 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12052 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12053 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12054 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12055
12056 /* old command */
12057 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12058 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12059 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12060 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12061
12062 /* old command */
12063 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12064 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12065 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12066 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12067
12068 /* old command */
12069 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12070 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12071 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12072 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12073#endif /* HAVE_IPV6 */
12074
12075 install_element (BGP_NODE, &bgp_distance_cmd);
12076 install_element (BGP_NODE, &no_bgp_distance_cmd);
12077 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12078 install_element (BGP_NODE, &bgp_distance_source_cmd);
12079 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12080 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12081 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12082
12083 install_element (BGP_NODE, &bgp_damp_set_cmd);
12084 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12085 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12086 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12087 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12088 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12089 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12090 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12091 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12092 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012093
12094 /* Deprecated AS-Pathlimit commands */
12095 install_element (BGP_NODE, &bgp_network_ttl_cmd);
12096 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
12097 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
12098 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
12099 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12100 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12101
12102 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
12103 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
12104 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12105 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
12106 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12107 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12108
12109 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
12110 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
12111 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
12112 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
12113 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12114 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12115
12116 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
12117 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
12118 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12119 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
12120 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12121 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12122
12123 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
12124 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
12125 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
12126 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
12127 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12128 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12129
12130 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
12131 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
12132 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12133 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
12134 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12135 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12136
12137 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
12138 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
paul718e3742002-12-13 20:15:29 +000012139}
Chris Caputo228da422009-07-18 05:44:03 +000012140
12141void
12142bgp_route_finish (void)
12143{
12144 bgp_table_unlock (bgp_distance_table);
12145 bgp_distance_table = NULL;
12146}