blob: 98e49bcdc35e118857efa03dc4a98ef17629158b [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;
1571 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
1572 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
1573 bm->process_rsclient_queue->spec.del_item_data
1574 = bm->process_main_queue->spec.del_item_data;
1575 bm->process_main_queue->spec.max_retries
1576 = bm->process_main_queue->spec.max_retries = 0;
1577 bm->process_rsclient_queue->spec.hold
Paul Jakma09dd5612006-09-14 03:38:16 +00001578 = bm->process_main_queue->spec.hold = 50;
paul200df112005-06-01 11:17:05 +00001579}
1580
1581void
paulfee0f4c2004-09-13 05:12:46 +00001582bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1583{
paul200df112005-06-01 11:17:05 +00001584 struct bgp_process_queue *pqnode;
1585
1586 /* already scheduled for processing? */
1587 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1588 return;
1589
1590 if ( (bm->process_main_queue == NULL) ||
1591 (bm->process_rsclient_queue == NULL) )
1592 bgp_process_queue_init ();
1593
1594 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1595 sizeof (struct bgp_process_queue));
1596 if (!pqnode)
1597 return;
Chris Caputo228da422009-07-18 05:44:03 +00001598
1599 /* all unlocked in bgp_processq_del */
1600 bgp_table_lock (rn->table);
1601 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001602 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001603 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001604 pqnode->afi = afi;
1605 pqnode->safi = safi;
1606
paulfee0f4c2004-09-13 05:12:46 +00001607 switch (rn->table->type)
1608 {
paul200df112005-06-01 11:17:05 +00001609 case BGP_TABLE_MAIN:
1610 work_queue_add (bm->process_main_queue, pqnode);
1611 break;
1612 case BGP_TABLE_RSCLIENT:
1613 work_queue_add (bm->process_rsclient_queue, pqnode);
1614 break;
paulfee0f4c2004-09-13 05:12:46 +00001615 }
paul200df112005-06-01 11:17:05 +00001616
1617 return;
paulfee0f4c2004-09-13 05:12:46 +00001618}
hasso0a486e52005-02-01 20:57:17 +00001619
paul94f2b392005-06-28 12:44:16 +00001620static int
hasso0a486e52005-02-01 20:57:17 +00001621bgp_maximum_prefix_restart_timer (struct thread *thread)
1622{
1623 struct peer *peer;
1624
1625 peer = THREAD_ARG (thread);
1626 peer->t_pmax_restart = NULL;
1627
1628 if (BGP_DEBUG (events, EVENTS))
1629 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1630 peer->host);
1631
1632 peer_clear (peer);
1633
1634 return 0;
1635}
1636
paulfee0f4c2004-09-13 05:12:46 +00001637int
paul5228ad22004-06-04 17:58:18 +00001638bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1639 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001640{
hassoe0701b72004-05-20 09:19:34 +00001641 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1642 return 0;
1643
1644 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001645 {
hassoe0701b72004-05-20 09:19:34 +00001646 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1647 && ! always)
1648 return 0;
paul718e3742002-12-13 20:15:29 +00001649
hassoe0701b72004-05-20 09:19:34 +00001650 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001651 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1652 "limit %ld", afi_safi_print (afi, safi), peer->host,
1653 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001654 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001655
hassoe0701b72004-05-20 09:19:34 +00001656 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1657 return 0;
paul718e3742002-12-13 20:15:29 +00001658
hassoe0701b72004-05-20 09:19:34 +00001659 {
paul5228ad22004-06-04 17:58:18 +00001660 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001661
1662 if (safi == SAFI_MPLS_VPN)
Denis Ovsienkoe81537d2011-07-14 12:36:19 +04001663 safi = SAFI_MPLS_LABELED_VPN;
paul5228ad22004-06-04 17:58:18 +00001664
1665 ndata[0] = (afi >> 8);
1666 ndata[1] = afi;
1667 ndata[2] = safi;
1668 ndata[3] = (peer->pmax[afi][safi] >> 24);
1669 ndata[4] = (peer->pmax[afi][safi] >> 16);
1670 ndata[5] = (peer->pmax[afi][safi] >> 8);
1671 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001672
1673 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1674 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1675 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1676 }
hasso0a486e52005-02-01 20:57:17 +00001677
1678 /* restart timer start */
1679 if (peer->pmax_restart[afi][safi])
1680 {
1681 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1682
1683 if (BGP_DEBUG (events, EVENTS))
1684 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1685 peer->host, peer->v_pmax_restart);
1686
1687 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1688 peer->v_pmax_restart);
1689 }
1690
hassoe0701b72004-05-20 09:19:34 +00001691 return 1;
paul718e3742002-12-13 20:15:29 +00001692 }
hassoe0701b72004-05-20 09:19:34 +00001693 else
1694 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1695
1696 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1697 {
1698 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1699 && ! always)
1700 return 0;
1701
1702 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001703 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1704 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1705 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001706 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1707 }
1708 else
1709 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001710 return 0;
1711}
1712
paulb40d9392005-08-22 22:34:41 +00001713/* Unconditionally remove the route from the RIB, without taking
1714 * damping into consideration (eg, because the session went down)
1715 */
paul94f2b392005-06-28 12:44:16 +00001716static void
paul718e3742002-12-13 20:15:29 +00001717bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1718 afi_t afi, safi_t safi)
1719{
paul902212c2006-02-05 17:51:19 +00001720 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1721
1722 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1723 bgp_info_delete (rn, ri); /* keep historical info */
1724
paulb40d9392005-08-22 22:34:41 +00001725 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001726}
1727
paul94f2b392005-06-28 12:44:16 +00001728static void
paul718e3742002-12-13 20:15:29 +00001729bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001730 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001731{
paul718e3742002-12-13 20:15:29 +00001732 int status = BGP_DAMP_NONE;
1733
paulb40d9392005-08-22 22:34:41 +00001734 /* apply dampening, if result is suppressed, we'll be retaining
1735 * the bgp_info in the RIB for historical reference.
1736 */
1737 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1738 && peer_sort (peer) == BGP_PEER_EBGP)
1739 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1740 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001741 {
paul902212c2006-02-05 17:51:19 +00001742 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1743 return;
1744 }
1745
1746 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001747}
1748
paul94f2b392005-06-28 12:44:16 +00001749static void
paulfee0f4c2004-09-13 05:12:46 +00001750bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1751 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1752 int sub_type, struct prefix_rd *prd, u_char *tag)
1753{
1754 struct bgp_node *rn;
1755 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001756 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001757 struct attr *attr_new;
1758 struct attr *attr_new2;
1759 struct bgp_info *ri;
1760 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001761 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001762 char buf[SU_ADDRSTRLEN];
1763
1764 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1765 if (peer == rsclient)
1766 return;
1767
1768 bgp = peer->bgp;
1769 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1770
1771 /* Check previously received route. */
1772 for (ri = rn->info; ri; ri = ri->next)
1773 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1774 break;
1775
1776 /* AS path loop check. */
1777 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1778 {
1779 reason = "as-path contains our own AS;";
1780 goto filtered;
1781 }
1782
1783 /* Route reflector originator ID check. */
1784 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001785 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001786 {
1787 reason = "originator is us;";
1788 goto filtered;
1789 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001790
1791 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001792
1793 /* Apply export policy. */
1794 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1795 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1796 {
1797 reason = "export-policy;";
1798 goto filtered;
1799 }
1800
1801 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001802
paulfee0f4c2004-09-13 05:12:46 +00001803 /* Apply import policy. */
1804 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1805 {
1806 bgp_attr_unintern (attr_new2);
1807
1808 reason = "import-policy;";
1809 goto filtered;
1810 }
1811
1812 attr_new = bgp_attr_intern (&new_attr);
1813 bgp_attr_unintern (attr_new2);
1814
1815 /* IPv4 unicast next hop check. */
1816 if (afi == AFI_IP && safi == SAFI_UNICAST)
1817 {
1818 /* Next hop must not be 0.0.0.0 nor Class E address. */
1819 if (new_attr.nexthop.s_addr == 0
1820 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1821 {
1822 bgp_attr_unintern (attr_new);
1823
1824 reason = "martian next-hop;";
1825 goto filtered;
1826 }
1827 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001828
1829 /* new_attr isn't passed to any functions after here */
1830 bgp_attr_extra_free (&new_attr);
1831
paulfee0f4c2004-09-13 05:12:46 +00001832 /* If the update is implicit withdraw. */
1833 if (ri)
1834 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001835 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001836
1837 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001838 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1839 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001840 {
1841
Paul Jakma1a392d42006-09-07 00:24:49 +00001842 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001843
1844 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001845 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001846 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1847 peer->host,
1848 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1849 p->prefixlen, rsclient->host);
1850
Chris Caputo228da422009-07-18 05:44:03 +00001851 bgp_unlock_node (rn);
1852 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001853
Chris Caputo228da422009-07-18 05:44:03 +00001854 return;
paulfee0f4c2004-09-13 05:12:46 +00001855 }
1856
Paul Jakma16d2e242007-04-10 19:32:10 +00001857 /* Withdraw/Announce before we fully processed the withdraw */
1858 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1859 bgp_info_restore (rn, ri);
1860
paulfee0f4c2004-09-13 05:12:46 +00001861 /* Received Logging. */
1862 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001863 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001864 peer->host,
1865 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1866 p->prefixlen, rsclient->host);
1867
1868 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001869 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001870
1871 /* Update to new attribute. */
1872 bgp_attr_unintern (ri->attr);
1873 ri->attr = attr_new;
1874
1875 /* Update MPLS tag. */
1876 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001877 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001878
Paul Jakma1a392d42006-09-07 00:24:49 +00001879 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001880
1881 /* Process change. */
1882 bgp_process (bgp, rn, afi, safi);
1883 bgp_unlock_node (rn);
1884
1885 return;
1886 }
1887
1888 /* Received Logging. */
1889 if (BGP_DEBUG (update, UPDATE_IN))
1890 {
ajsd2c1f162004-12-08 21:10:20 +00001891 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001892 peer->host,
1893 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1894 p->prefixlen, rsclient->host);
1895 }
1896
1897 /* Make new BGP info. */
1898 new = bgp_info_new ();
1899 new->type = type;
1900 new->sub_type = sub_type;
1901 new->peer = peer;
1902 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001903 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001904
1905 /* Update MPLS tag. */
1906 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001907 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001908
Paul Jakma1a392d42006-09-07 00:24:49 +00001909 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001910
1911 /* Register new BGP information. */
1912 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001913
1914 /* route_node_get lock */
1915 bgp_unlock_node (rn);
1916
paulfee0f4c2004-09-13 05:12:46 +00001917 /* Process change. */
1918 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001919
1920 bgp_attr_extra_free (&new_attr);
1921
paulfee0f4c2004-09-13 05:12:46 +00001922 return;
1923
1924 filtered:
1925
1926 /* This BGP update is filtered. Log the reason then update BGP entry. */
1927 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001928 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001929 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1930 peer->host,
1931 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1932 p->prefixlen, rsclient->host, reason);
1933
1934 if (ri)
paulb40d9392005-08-22 22:34:41 +00001935 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001936
1937 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001938
1939 if (new_attr.extra)
1940 bgp_attr_extra_free (&new_attr);
1941
paulfee0f4c2004-09-13 05:12:46 +00001942 return;
1943}
1944
paul94f2b392005-06-28 12:44:16 +00001945static void
paulfee0f4c2004-09-13 05:12:46 +00001946bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1947 struct peer *peer, struct prefix *p, int type, int sub_type,
1948 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00001949{
paulfee0f4c2004-09-13 05:12:46 +00001950 struct bgp_node *rn;
1951 struct bgp_info *ri;
1952 char buf[SU_ADDRSTRLEN];
1953
1954 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00001955 return;
paulfee0f4c2004-09-13 05:12:46 +00001956
1957 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1958
1959 /* Lookup withdrawn route. */
1960 for (ri = rn->info; ri; ri = ri->next)
1961 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1962 break;
1963
1964 /* Withdraw specified route from routing table. */
1965 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00001966 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001967 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001968 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001969 "%s Can't find the route %s/%d", peer->host,
1970 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1971 p->prefixlen);
1972
1973 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00001974 bgp_unlock_node (rn);
1975}
paulfee0f4c2004-09-13 05:12:46 +00001976
paul94f2b392005-06-28 12:44:16 +00001977static int
paulfee0f4c2004-09-13 05:12:46 +00001978bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00001979 afi_t afi, safi_t safi, int type, int sub_type,
1980 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
1981{
1982 int ret;
1983 int aspath_loop_count = 0;
1984 struct bgp_node *rn;
1985 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001986 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00001987 struct attr *attr_new;
1988 struct bgp_info *ri;
1989 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001990 const char *reason;
paul718e3742002-12-13 20:15:29 +00001991 char buf[SU_ADDRSTRLEN];
1992
1993 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00001994 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00001995
paul718e3742002-12-13 20:15:29 +00001996 /* When peer's soft reconfiguration enabled. Record input packet in
1997 Adj-RIBs-In. */
1998 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
1999 && peer != bgp->peer_self && ! soft_reconfig)
2000 bgp_adj_in_set (rn, peer, attr);
2001
2002 /* Check previously received route. */
2003 for (ri = rn->info; ri; ri = ri->next)
2004 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2005 break;
2006
2007 /* AS path local-as loop check. */
2008 if (peer->change_local_as)
2009 {
2010 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2011 aspath_loop_count = 1;
2012
2013 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2014 {
2015 reason = "as-path contains our own AS;";
2016 goto filtered;
2017 }
2018 }
2019
2020 /* AS path loop check. */
2021 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2022 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2023 && aspath_loop_check(attr->aspath, bgp->confed_id)
2024 > peer->allowas_in[afi][safi]))
2025 {
2026 reason = "as-path contains our own AS;";
2027 goto filtered;
2028 }
2029
2030 /* Route reflector originator ID check. */
2031 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002032 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002033 {
2034 reason = "originator is us;";
2035 goto filtered;
2036 }
2037
2038 /* Route reflector cluster ID check. */
2039 if (bgp_cluster_filter (peer, attr))
2040 {
2041 reason = "reflected from the same cluster;";
2042 goto filtered;
2043 }
2044
2045 /* Apply incoming filter. */
2046 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2047 {
2048 reason = "filter;";
2049 goto filtered;
2050 }
2051
2052 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002053 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002054
2055 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2056 {
2057 reason = "route-map;";
2058 goto filtered;
2059 }
2060
2061 /* IPv4 unicast next hop check. */
2062 if (afi == AFI_IP && safi == SAFI_UNICAST)
2063 {
2064 /* If the peer is EBGP and nexthop is not on connected route,
2065 discard it. */
2066 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
Denis Ovsienko5c98c5a2011-08-05 18:52:52 +04002067 && ! bgp_nexthop_onlink (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002068 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002069 {
2070 reason = "non-connected next-hop;";
2071 goto filtered;
2072 }
2073
2074 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2075 must not be my own address. */
2076 if (bgp_nexthop_self (afi, &new_attr)
2077 || new_attr.nexthop.s_addr == 0
2078 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2079 {
2080 reason = "martian next-hop;";
2081 goto filtered;
2082 }
2083 }
2084
2085 attr_new = bgp_attr_intern (&new_attr);
2086
2087 /* If the update is implicit withdraw. */
2088 if (ri)
2089 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002090 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002091
2092 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002093 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2094 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002095 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002096 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002097
2098 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2099 && peer_sort (peer) == BGP_PEER_EBGP
2100 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2101 {
2102 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002103 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002104 peer->host,
2105 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2106 p->prefixlen);
2107
paul902212c2006-02-05 17:51:19 +00002108 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2109 {
2110 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2111 bgp_process (bgp, rn, afi, safi);
2112 }
paul718e3742002-12-13 20:15:29 +00002113 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002114 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002115 {
2116 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002117 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002118 "%s rcvd %s/%d...duplicate ignored",
2119 peer->host,
2120 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2121 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002122
2123 /* graceful restart STALE flag unset. */
2124 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2125 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002126 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002127 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002128 }
paul718e3742002-12-13 20:15:29 +00002129 }
2130
2131 bgp_unlock_node (rn);
2132 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002133 bgp_attr_extra_free (&new_attr);
2134
paul718e3742002-12-13 20:15:29 +00002135 return 0;
2136 }
2137
Paul Jakma16d2e242007-04-10 19:32:10 +00002138 /* Withdraw/Announce before we fully processed the withdraw */
2139 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2140 {
2141 if (BGP_DEBUG (update, UPDATE_IN))
2142 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2143 peer->host,
2144 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2145 p->prefixlen);
2146 bgp_info_restore (rn, ri);
2147 }
2148
paul718e3742002-12-13 20:15:29 +00002149 /* Received Logging. */
2150 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002151 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002152 peer->host,
2153 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2154 p->prefixlen);
2155
hasso93406d82005-02-02 14:40:33 +00002156 /* graceful restart STALE flag unset. */
2157 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002158 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002159
paul718e3742002-12-13 20:15:29 +00002160 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002161 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002162
2163 /* implicit withdraw, decrement aggregate and pcount here.
2164 * only if update is accepted, they'll increment below.
2165 */
paul902212c2006-02-05 17:51:19 +00002166 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2167
paul718e3742002-12-13 20:15:29 +00002168 /* Update bgp route dampening information. */
2169 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2170 && peer_sort (peer) == BGP_PEER_EBGP)
2171 {
2172 /* This is implicit withdraw so we should update dampening
2173 information. */
2174 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2175 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002176 }
2177
paul718e3742002-12-13 20:15:29 +00002178 /* Update to new attribute. */
2179 bgp_attr_unintern (ri->attr);
2180 ri->attr = attr_new;
2181
2182 /* Update MPLS tag. */
2183 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002184 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002185
2186 /* Update bgp route dampening information. */
2187 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2188 && peer_sort (peer) == BGP_PEER_EBGP)
2189 {
2190 /* Now we do normal update dampening. */
2191 ret = bgp_damp_update (ri, rn, afi, safi);
2192 if (ret == BGP_DAMP_SUPPRESSED)
2193 {
2194 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002195 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002196 return 0;
2197 }
2198 }
2199
2200 /* Nexthop reachability check. */
2201 if ((afi == AFI_IP || afi == AFI_IP6)
2202 && safi == SAFI_UNICAST
2203 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002204 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002205 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002206 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002207 {
2208 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002209 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002210 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002211 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002212 }
2213 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002214 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002215
2216 /* Process change. */
2217 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2218
2219 bgp_process (bgp, rn, afi, safi);
2220 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002221 bgp_attr_extra_free (&new_attr);
2222
paul718e3742002-12-13 20:15:29 +00002223 return 0;
2224 }
2225
2226 /* Received Logging. */
2227 if (BGP_DEBUG (update, UPDATE_IN))
2228 {
ajsd2c1f162004-12-08 21:10:20 +00002229 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002230 peer->host,
2231 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2232 p->prefixlen);
2233 }
2234
paul718e3742002-12-13 20:15:29 +00002235 /* Make new BGP info. */
2236 new = bgp_info_new ();
2237 new->type = type;
2238 new->sub_type = sub_type;
2239 new->peer = peer;
2240 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002241 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002242
2243 /* Update MPLS tag. */
2244 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002245 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002246
2247 /* Nexthop reachability check. */
2248 if ((afi == AFI_IP || afi == AFI_IP6)
2249 && safi == SAFI_UNICAST
2250 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002251 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002252 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002253 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002254 {
2255 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002256 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002257 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002258 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002259 }
2260 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002261 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002262
paul902212c2006-02-05 17:51:19 +00002263 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002264 bgp_aggregate_increment (bgp, p, new, afi, safi);
2265
2266 /* Register new BGP information. */
2267 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002268
2269 /* route_node_get lock */
2270 bgp_unlock_node (rn);
2271
Paul Jakmafb982c22007-05-04 20:15:47 +00002272 bgp_attr_extra_free (&new_attr);
2273
paul718e3742002-12-13 20:15:29 +00002274 /* If maximum prefix count is configured and current prefix
2275 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002276 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2277 return -1;
paul718e3742002-12-13 20:15:29 +00002278
2279 /* Process change. */
2280 bgp_process (bgp, rn, afi, safi);
2281
2282 return 0;
2283
2284 /* This BGP update is filtered. Log the reason then update BGP
2285 entry. */
2286 filtered:
2287 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002288 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002289 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2290 peer->host,
2291 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2292 p->prefixlen, reason);
2293
2294 if (ri)
paulb40d9392005-08-22 22:34:41 +00002295 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002296
2297 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002298
2299 bgp_attr_extra_free (&new_attr);
2300
paul718e3742002-12-13 20:15:29 +00002301 return 0;
2302}
2303
2304int
paulfee0f4c2004-09-13 05:12:46 +00002305bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2306 afi_t afi, safi_t safi, int type, int sub_type,
2307 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2308{
2309 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002310 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002311 struct bgp *bgp;
2312 int ret;
2313
2314 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2315 soft_reconfig);
2316
2317 bgp = peer->bgp;
2318
2319 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002320 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002321 {
2322 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2323 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2324 sub_type, prd, tag);
2325 }
2326
2327 return ret;
2328}
2329
2330int
paul718e3742002-12-13 20:15:29 +00002331bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002332 afi_t afi, safi_t safi, int type, int sub_type,
2333 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002334{
2335 struct bgp *bgp;
2336 char buf[SU_ADDRSTRLEN];
2337 struct bgp_node *rn;
2338 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002339 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002340 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002341
2342 bgp = peer->bgp;
2343
paulfee0f4c2004-09-13 05:12:46 +00002344 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002345 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002346 {
2347 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2348 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2349 }
2350
paul718e3742002-12-13 20:15:29 +00002351 /* Logging. */
2352 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002353 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002354 peer->host,
2355 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2356 p->prefixlen);
2357
2358 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002359 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002360
2361 /* If peer is soft reconfiguration enabled. Record input packet for
2362 further calculation. */
2363 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2364 && peer != bgp->peer_self)
2365 bgp_adj_in_unset (rn, peer);
2366
2367 /* Lookup withdrawn route. */
2368 for (ri = rn->info; ri; ri = ri->next)
2369 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2370 break;
2371
2372 /* Withdraw specified route from routing table. */
2373 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002374 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002375 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002376 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002377 "%s Can't find the route %s/%d", peer->host,
2378 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2379 p->prefixlen);
2380
2381 /* Unlock bgp_node_get() lock. */
2382 bgp_unlock_node (rn);
2383
2384 return 0;
2385}
2386
2387void
2388bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2389{
2390 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002391 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002392 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002393 struct prefix p;
2394 struct bgp_info binfo;
2395 struct peer *from;
2396 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002397
Paul Jakmab2497022007-06-14 11:17:58 +00002398 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002399 return;
2400
paul718e3742002-12-13 20:15:29 +00002401 bgp = peer->bgp;
2402 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002403
paul718e3742002-12-13 20:15:29 +00002404 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2405 aspath = attr.aspath;
2406 attr.local_pref = bgp->default_local_pref;
2407 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2408
2409 if (afi == AFI_IP)
2410 str2prefix ("0.0.0.0/0", &p);
2411#ifdef HAVE_IPV6
2412 else if (afi == AFI_IP6)
2413 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002414 struct attr_extra *ae;
2415 attr.extra = NULL;
2416
2417 ae = bgp_attr_extra_get (&attr);
2418 attr.extra = ae;
2419
paul718e3742002-12-13 20:15:29 +00002420 str2prefix ("::/0", &p);
2421
2422 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002423 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002424 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002425 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002426
2427 /* If the peer is on shared nextwork and we have link-local
2428 nexthop set it. */
2429 if (peer->shared_network
2430 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2431 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002432 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002433 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002434 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002435 }
2436 }
2437#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002438
2439 if (peer->default_rmap[afi][safi].name)
2440 {
2441 binfo.peer = bgp->peer_self;
2442 binfo.attr = &attr;
2443
paulfee0f4c2004-09-13 05:12:46 +00002444 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2445
paul718e3742002-12-13 20:15:29 +00002446 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2447 RMAP_BGP, &binfo);
2448
paulfee0f4c2004-09-13 05:12:46 +00002449 bgp->peer_self->rmap_type = 0;
2450
paul718e3742002-12-13 20:15:29 +00002451 if (ret == RMAP_DENYMATCH)
2452 {
2453 bgp_attr_flush (&attr);
2454 withdraw = 1;
2455 }
2456 }
2457
2458 if (withdraw)
2459 {
2460 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2461 bgp_default_withdraw_send (peer, afi, safi);
2462 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2463 }
2464 else
2465 {
2466 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2467 bgp_default_update_send (peer, &attr, afi, safi, from);
2468 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002469
2470 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002471 aspath_unintern (aspath);
2472}
2473
2474static void
2475bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002476 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002477{
2478 struct bgp_node *rn;
2479 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002480 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002481
paul718e3742002-12-13 20:15:29 +00002482 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002483 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002484
2485 if (safi != SAFI_MPLS_VPN
2486 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2487 bgp_default_originate (peer, afi, safi, 0);
2488
2489 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2490 for (ri = rn->info; ri; ri = ri->next)
2491 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2492 {
paulfee0f4c2004-09-13 05:12:46 +00002493 if ( (rsclient) ?
2494 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2495 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002496 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2497 else
2498 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002499
2500 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002501 }
2502}
2503
2504void
2505bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2506{
2507 struct bgp_node *rn;
2508 struct bgp_table *table;
2509
2510 if (peer->status != Established)
2511 return;
2512
2513 if (! peer->afc_nego[afi][safi])
2514 return;
2515
2516 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2517 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2518 return;
2519
2520 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002521 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002522 else
2523 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2524 rn = bgp_route_next(rn))
2525 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002526 bgp_announce_table (peer, afi, safi, table, 0);
2527
2528 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2529 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002530}
2531
2532void
2533bgp_announce_route_all (struct peer *peer)
2534{
2535 afi_t afi;
2536 safi_t safi;
2537
2538 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2539 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2540 bgp_announce_route (peer, afi, safi);
2541}
2542
2543static void
paulfee0f4c2004-09-13 05:12:46 +00002544bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2545 safi_t safi, struct bgp_table *table)
2546{
2547 struct bgp_node *rn;
2548 struct bgp_adj_in *ain;
2549
2550 if (! table)
2551 table = rsclient->bgp->rib[afi][safi];
2552
2553 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2554 for (ain = rn->adj_in; ain; ain = ain->next)
2555 {
2556 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2557 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2558 }
2559}
2560
2561void
2562bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2563{
2564 struct bgp_table *table;
2565 struct bgp_node *rn;
2566
2567 if (safi != SAFI_MPLS_VPN)
2568 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2569
2570 else
2571 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2572 rn = bgp_route_next (rn))
2573 if ((table = rn->info) != NULL)
2574 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2575}
2576
2577static void
paul718e3742002-12-13 20:15:29 +00002578bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2579 struct bgp_table *table)
2580{
2581 int ret;
2582 struct bgp_node *rn;
2583 struct bgp_adj_in *ain;
2584
2585 if (! table)
2586 table = peer->bgp->rib[afi][safi];
2587
2588 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2589 for (ain = rn->adj_in; ain; ain = ain->next)
2590 {
2591 if (ain->peer == peer)
2592 {
2593 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2594 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2595 NULL, NULL, 1);
2596 if (ret < 0)
2597 {
2598 bgp_unlock_node (rn);
2599 return;
2600 }
2601 continue;
2602 }
2603 }
2604}
2605
2606void
2607bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2608{
2609 struct bgp_node *rn;
2610 struct bgp_table *table;
2611
2612 if (peer->status != Established)
2613 return;
2614
2615 if (safi != SAFI_MPLS_VPN)
2616 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2617 else
2618 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2619 rn = bgp_route_next (rn))
2620 if ((table = rn->info) != NULL)
2621 bgp_soft_reconfig_table (peer, afi, safi, table);
2622}
2623
Chris Caputo228da422009-07-18 05:44:03 +00002624
2625struct bgp_clear_node_queue
2626{
2627 struct bgp_node *rn;
2628 enum bgp_clear_route_type purpose;
2629};
2630
paul200df112005-06-01 11:17:05 +00002631static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002632bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002633{
Chris Caputo228da422009-07-18 05:44:03 +00002634 struct bgp_clear_node_queue *cnq = data;
2635 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002636 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002637 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002638 afi_t afi = rn->table->afi;
2639 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002640
Paul Jakma64e580a2006-02-21 01:09:01 +00002641 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002642
Paul Jakma64e580a2006-02-21 01:09:01 +00002643 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002644 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002645 {
2646 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002647 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2648 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002649 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002650 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2651 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002652 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002653 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002654 break;
2655 }
paul200df112005-06-01 11:17:05 +00002656 return WQ_SUCCESS;
2657}
2658
2659static void
paul0fb58d52005-11-14 14:31:49 +00002660bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002661{
Chris Caputo228da422009-07-18 05:44:03 +00002662 struct bgp_clear_node_queue *cnq = data;
2663 struct bgp_node *rn = cnq->rn;
2664 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002665
2666 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002667 bgp_table_unlock (table);
2668 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002669}
2670
2671static void
paul94f2b392005-06-28 12:44:16 +00002672bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002673{
Paul Jakma64e580a2006-02-21 01:09:01 +00002674 struct peer *peer = wq->spec.data;
2675
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002676 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002677 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002678
2679 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002680}
2681
2682static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002683bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002684{
Paul Jakmaa2943652009-07-21 14:02:04 +01002685 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002686
Paul Jakmaa2943652009-07-21 14:02:04 +01002687 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002688#undef CLEAR_QUEUE_NAME_LEN
2689
2690 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002691 {
2692 zlog_err ("%s: Failed to allocate work queue", __func__);
2693 exit (1);
2694 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002695 peer->clear_node_queue->spec.hold = 10;
2696 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2697 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2698 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2699 peer->clear_node_queue->spec.max_retries = 0;
2700
2701 /* we only 'lock' this peer reference when the queue is actually active */
2702 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002703}
2704
paul718e3742002-12-13 20:15:29 +00002705static void
2706bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002707 struct bgp_table *table, struct peer *rsclient,
2708 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002709{
2710 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002711
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002712
paul718e3742002-12-13 20:15:29 +00002713 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002714 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002715
hasso6cf159b2005-03-21 10:28:14 +00002716 /* If still no table => afi/safi isn't configured at all or smth. */
2717 if (! table)
2718 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002719
2720 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2721 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002722 struct bgp_info *ri;
2723 struct bgp_adj_in *ain;
2724 struct bgp_adj_out *aout;
2725
Paul Jakma65ca75e2006-05-04 08:08:15 +00002726 if (rn->info == NULL)
2727 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002728
2729 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2730 * queued for every clearing peer, regardless of whether it is
2731 * relevant to the peer at hand.
2732 *
2733 * Overview: There are 3 different indices which need to be
2734 * scrubbed, potentially, when a peer is removed:
2735 *
2736 * 1 peer's routes visible via the RIB (ie accepted routes)
2737 * 2 peer's routes visible by the (optional) peer's adj-in index
2738 * 3 other routes visible by the peer's adj-out index
2739 *
2740 * 3 there is no hurry in scrubbing, once the struct peer is
2741 * removed from bgp->peer, we could just GC such deleted peer's
2742 * adj-outs at our leisure.
2743 *
2744 * 1 and 2 must be 'scrubbed' in some way, at least made
2745 * invisible via RIB index before peer session is allowed to be
2746 * brought back up. So one needs to know when such a 'search' is
2747 * complete.
2748 *
2749 * Ideally:
2750 *
2751 * - there'd be a single global queue or a single RIB walker
2752 * - rather than tracking which route_nodes still need to be
2753 * examined on a peer basis, we'd track which peers still
2754 * aren't cleared
2755 *
2756 * Given that our per-peer prefix-counts now should be reliable,
2757 * this may actually be achievable. It doesn't seem to be a huge
2758 * problem at this time,
2759 */
2760 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002761 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002762 {
Chris Caputo228da422009-07-18 05:44:03 +00002763 struct bgp_clear_node_queue *cnq;
2764
2765 /* both unlocked in bgp_clear_node_queue_del */
2766 bgp_table_lock (rn->table);
2767 bgp_lock_node (rn);
2768 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2769 sizeof (struct bgp_clear_node_queue));
2770 cnq->rn = rn;
2771 cnq->purpose = purpose;
2772 work_queue_add (peer->clear_node_queue, cnq);
2773 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002774 }
2775
2776 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002777 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002778 {
2779 bgp_adj_in_remove (rn, ain);
2780 bgp_unlock_node (rn);
2781 break;
2782 }
2783 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002784 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002785 {
2786 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2787 bgp_unlock_node (rn);
2788 break;
2789 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002790 }
2791 return;
2792}
2793
2794void
Chris Caputo228da422009-07-18 05:44:03 +00002795bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2796 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002797{
2798 struct bgp_node *rn;
2799 struct bgp_table *table;
2800 struct peer *rsclient;
2801 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002802
Paul Jakma64e580a2006-02-21 01:09:01 +00002803 if (peer->clear_node_queue == NULL)
2804 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002805
Paul Jakmaca058a32006-09-14 02:58:49 +00002806 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2807 * Idle until it receives a Clearing_Completed event. This protects
2808 * against peers which flap faster than we can we clear, which could
2809 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002810 *
2811 * a) race with routes from the new session being installed before
2812 * clear_route_node visits the node (to delete the route of that
2813 * peer)
2814 * b) resource exhaustion, clear_route_node likely leads to an entry
2815 * on the process_main queue. Fast-flapping could cause that queue
2816 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002817 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002818 if (!peer->clear_node_queue->thread)
2819 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002820
Chris Caputo228da422009-07-18 05:44:03 +00002821 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002822 {
Chris Caputo228da422009-07-18 05:44:03 +00002823 case BGP_CLEAR_ROUTE_NORMAL:
2824 if (safi != SAFI_MPLS_VPN)
2825 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2826 else
2827 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2828 rn = bgp_route_next (rn))
2829 if ((table = rn->info) != NULL)
2830 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2831
2832 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2833 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2834 PEER_FLAG_RSERVER_CLIENT))
2835 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2836 break;
2837
2838 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2839 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2840 break;
2841
2842 default:
2843 assert (0);
2844 break;
paulfee0f4c2004-09-13 05:12:46 +00002845 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002846
Paul Jakmaca058a32006-09-14 02:58:49 +00002847 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002848 * completion function won't be run by workqueue code - call it here.
2849 * XXX: Actually, this assumption doesn't hold, see
2850 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002851 *
2852 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002853 * really needed if peer state is Established - peers in
2854 * pre-Established states shouldn't have any route-update state
2855 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002856 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002857 * We still can get here in pre-Established though, through
2858 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2859 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002860 *
2861 * At some future point, this check could be move to the top of the
2862 * function, and do a quick early-return when state is
2863 * pre-Established, avoiding above list and table scans. Once we're
2864 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002865 */
2866 if (!peer->clear_node_queue->thread)
2867 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002868}
2869
2870void
2871bgp_clear_route_all (struct peer *peer)
2872{
2873 afi_t afi;
2874 safi_t safi;
2875
2876 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2877 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002878 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002879}
2880
2881void
2882bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2883{
2884 struct bgp_table *table;
2885 struct bgp_node *rn;
2886 struct bgp_adj_in *ain;
2887
2888 table = peer->bgp->rib[afi][safi];
2889
2890 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2891 for (ain = rn->adj_in; ain ; ain = ain->next)
2892 if (ain->peer == peer)
2893 {
2894 bgp_adj_in_remove (rn, ain);
2895 bgp_unlock_node (rn);
2896 break;
2897 }
2898}
hasso93406d82005-02-02 14:40:33 +00002899
2900void
2901bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2902{
2903 struct bgp_node *rn;
2904 struct bgp_info *ri;
2905 struct bgp_table *table;
2906
2907 table = peer->bgp->rib[afi][safi];
2908
2909 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2910 {
2911 for (ri = rn->info; ri; ri = ri->next)
2912 if (ri->peer == peer)
2913 {
2914 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2915 bgp_rib_remove (rn, ri, peer, afi, safi);
2916 break;
2917 }
2918 }
2919}
paul718e3742002-12-13 20:15:29 +00002920
2921/* Delete all kernel routes. */
2922void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002923bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002924{
2925 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002926 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002927 struct bgp_node *rn;
2928 struct bgp_table *table;
2929 struct bgp_info *ri;
2930
paul1eb8ef22005-04-07 07:30:20 +00002931 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002932 {
2933 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2934
2935 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2936 for (ri = rn->info; ri; ri = ri->next)
2937 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2938 && ri->type == ZEBRA_ROUTE_BGP
2939 && ri->sub_type == BGP_ROUTE_NORMAL)
2940 bgp_zebra_withdraw (&rn->p, ri);
2941
2942 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2943
2944 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2945 for (ri = rn->info; ri; ri = ri->next)
2946 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2947 && ri->type == ZEBRA_ROUTE_BGP
2948 && ri->sub_type == BGP_ROUTE_NORMAL)
2949 bgp_zebra_withdraw (&rn->p, ri);
2950 }
2951}
2952
2953void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002954bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00002955{
2956 vty_reset ();
2957 bgp_zclient_reset ();
2958 access_list_reset ();
2959 prefix_list_reset ();
2960}
2961
2962/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
2963 value. */
2964int
2965bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
2966{
2967 u_char *pnt;
2968 u_char *lim;
2969 struct prefix p;
2970 int psize;
2971 int ret;
2972
2973 /* Check peer status. */
2974 if (peer->status != Established)
2975 return 0;
2976
2977 pnt = packet->nlri;
2978 lim = pnt + packet->length;
2979
2980 for (; pnt < lim; pnt += psize)
2981 {
2982 /* Clear prefix structure. */
2983 memset (&p, 0, sizeof (struct prefix));
2984
2985 /* Fetch prefix length. */
2986 p.prefixlen = *pnt++;
2987 p.family = afi2family (packet->afi);
2988
2989 /* Already checked in nlri_sanity_check(). We do double check
2990 here. */
2991 if ((packet->afi == AFI_IP && p.prefixlen > 32)
2992 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
2993 return -1;
2994
2995 /* Packet size overflow check. */
2996 psize = PSIZE (p.prefixlen);
2997
2998 /* When packet overflow occur return immediately. */
2999 if (pnt + psize > lim)
3000 return -1;
3001
3002 /* Fetch prefix from NLRI packet. */
3003 memcpy (&p.u.prefix, pnt, psize);
3004
3005 /* Check address. */
3006 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3007 {
3008 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3009 {
paulf5ba3872004-07-09 12:11:31 +00003010 /*
3011 * From draft-ietf-idr-bgp4-22, Section 6.3:
3012 * If a BGP router receives an UPDATE message with a
3013 * semantically incorrect NLRI field, in which a prefix is
3014 * semantically incorrect (eg. an unexpected multicast IP
3015 * address), it should ignore the prefix.
3016 */
paul718e3742002-12-13 20:15:29 +00003017 zlog (peer->log, LOG_ERR,
3018 "IPv4 unicast NLRI is multicast address %s",
3019 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003020
paul718e3742002-12-13 20:15:29 +00003021 return -1;
3022 }
3023 }
3024
3025#ifdef HAVE_IPV6
3026 /* Check address. */
3027 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3028 {
3029 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3030 {
3031 char buf[BUFSIZ];
3032
3033 zlog (peer->log, LOG_WARNING,
3034 "IPv6 link-local NLRI received %s ignore this NLRI",
3035 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3036
3037 continue;
3038 }
3039 }
3040#endif /* HAVE_IPV6 */
3041
3042 /* Normal process. */
3043 if (attr)
3044 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3045 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3046 else
3047 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3048 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3049
3050 /* Address family configuration mismatch or maximum-prefix count
3051 overflow. */
3052 if (ret < 0)
3053 return -1;
3054 }
3055
3056 /* Packet length consistency check. */
3057 if (pnt != lim)
3058 return -1;
3059
3060 return 0;
3061}
3062
3063/* NLRI encode syntax check routine. */
3064int
3065bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3066 bgp_size_t length)
3067{
3068 u_char *end;
3069 u_char prefixlen;
3070 int psize;
3071
3072 end = pnt + length;
3073
3074 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3075 syntactic validity. If the field is syntactically incorrect,
3076 then the Error Subcode is set to Invalid Network Field. */
3077
3078 while (pnt < end)
3079 {
3080 prefixlen = *pnt++;
3081
3082 /* Prefix length check. */
3083 if ((afi == AFI_IP && prefixlen > 32)
3084 || (afi == AFI_IP6 && prefixlen > 128))
3085 {
3086 plog_err (peer->log,
3087 "%s [Error] Update packet error (wrong prefix length %d)",
3088 peer->host, prefixlen);
3089 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3090 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3091 return -1;
3092 }
3093
3094 /* Packet size overflow check. */
3095 psize = PSIZE (prefixlen);
3096
3097 if (pnt + psize > end)
3098 {
3099 plog_err (peer->log,
3100 "%s [Error] Update packet error"
3101 " (prefix data overflow prefix size is %d)",
3102 peer->host, psize);
3103 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3104 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3105 return -1;
3106 }
3107
3108 pnt += psize;
3109 }
3110
3111 /* Packet length consistency check. */
3112 if (pnt != end)
3113 {
3114 plog_err (peer->log,
3115 "%s [Error] Update packet error"
3116 " (prefix length mismatch with total length)",
3117 peer->host);
3118 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3119 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3120 return -1;
3121 }
3122 return 0;
3123}
3124
paul94f2b392005-06-28 12:44:16 +00003125static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003126bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003127{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003128 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003129}
3130
paul94f2b392005-06-28 12:44:16 +00003131static void
paul718e3742002-12-13 20:15:29 +00003132bgp_static_free (struct bgp_static *bgp_static)
3133{
3134 if (bgp_static->rmap.name)
3135 free (bgp_static->rmap.name);
3136 XFREE (MTYPE_BGP_STATIC, bgp_static);
3137}
3138
paul94f2b392005-06-28 12:44:16 +00003139static void
paulfee0f4c2004-09-13 05:12:46 +00003140bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3141 struct prefix *p, afi_t afi, safi_t safi)
3142{
3143 struct bgp_node *rn;
3144 struct bgp_info *ri;
3145
3146 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3147
3148 /* Check selected route and self inserted route. */
3149 for (ri = rn->info; ri; ri = ri->next)
3150 if (ri->peer == bgp->peer_self
3151 && ri->type == ZEBRA_ROUTE_BGP
3152 && ri->sub_type == BGP_ROUTE_STATIC)
3153 break;
3154
3155 /* Withdraw static BGP route from routing table. */
3156 if (ri)
3157 {
paulfee0f4c2004-09-13 05:12:46 +00003158 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003159 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003160 }
3161
3162 /* Unlock bgp_node_lookup. */
3163 bgp_unlock_node (rn);
3164}
3165
paul94f2b392005-06-28 12:44:16 +00003166static void
paulfee0f4c2004-09-13 05:12:46 +00003167bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003168 struct bgp_static *bgp_static,
3169 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003170{
3171 struct bgp_node *rn;
3172 struct bgp_info *ri;
3173 struct bgp_info *new;
3174 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003175 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003176 struct attr attr = {0 };
3177 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003178 struct bgp *bgp;
3179 int ret;
3180 char buf[SU_ADDRSTRLEN];
3181
3182 bgp = rsclient->bgp;
3183
Paul Jakma06e110f2006-05-12 23:29:22 +00003184 assert (bgp_static);
3185 if (!bgp_static)
3186 return;
3187
paulfee0f4c2004-09-13 05:12:46 +00003188 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3189
3190 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003191
3192 attr.nexthop = bgp_static->igpnexthop;
3193 attr.med = bgp_static->igpmetric;
3194 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003195
Paul Jakma41367172007-08-06 15:24:51 +00003196 if (bgp_static->atomic)
3197 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3198
paulfee0f4c2004-09-13 05:12:46 +00003199 /* Apply network route-map for export to this rsclient. */
3200 if (bgp_static->rmap.name)
3201 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003202 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003203 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003204 info.attr = &attr_tmp;
3205
paulfee0f4c2004-09-13 05:12:46 +00003206 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3207 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3208
3209 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3210
3211 rsclient->rmap_type = 0;
3212
3213 if (ret == RMAP_DENYMATCH)
3214 {
3215 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003216 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003217
3218 /* Unintern original. */
3219 aspath_unintern (attr.aspath);
3220 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003221 bgp_attr_extra_free (&attr);
3222
paulfee0f4c2004-09-13 05:12:46 +00003223 return;
3224 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003225 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003226 }
3227 else
3228 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003229
paulfee0f4c2004-09-13 05:12:46 +00003230 new_attr = *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003231
paulfee0f4c2004-09-13 05:12:46 +00003232 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3233
Paul Jakmafb982c22007-05-04 20:15:47 +00003234 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3235 == RMAP_DENY)
3236 {
paulfee0f4c2004-09-13 05:12:46 +00003237 /* This BGP update is filtered. Log the reason then update BGP entry. */
3238 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003239 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003240 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3241 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3242 p->prefixlen, rsclient->host);
3243
3244 bgp->peer_self->rmap_type = 0;
3245
3246 bgp_attr_unintern (attr_new);
3247 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003248 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003249
3250 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3251
3252 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003253 }
paulfee0f4c2004-09-13 05:12:46 +00003254
3255 bgp->peer_self->rmap_type = 0;
3256
3257 bgp_attr_unintern (attr_new);
3258 attr_new = bgp_attr_intern (&new_attr);
3259
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 Jakmae70e5752011-07-05 00:41:59 +04003571 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 Jakmae70e5752011-07-05 00:41:59 +04003606 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 Jakmae70e5752011-07-05 00:41:59 +04003897 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 Jakmae70e5752011-07-05 00:41:59 +04003909 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 Jakmae70e5752011-07-05 00:41:59 +04003920 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 Jakmae70e5752011-07-05 00:41:59 +04003942 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 Jakmae70e5752011-07-05 00:41:59 +04003966 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 Jakmae70e5752011-07-05 00:41:59 +04003989 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 Jakmae70e5752011-07-05 00:41:59 +04004009 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 Jakmae70e5752011-07-05 00:41:59 +04004031 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 Jakmae70e5752011-07-05 00:41:59 +04004052 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 Jakmae70e5752011-07-05 00:41:59 +04004173 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 Jakmae70e5752011-07-05 00:41:59 +04004185 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 Jakmae70e5752011-07-05 00:41:59 +04004224
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")
Paul Jakmaa8b79422011-03-23 10:30:30 +00004330#ifdef HAVE_IPV6
Paul Jakmae70e5752011-07-05 00:41:59 +04004331ALIAS_DEPRECATED (ipv6_bgp_network,
4332 ipv6_bgp_network_ttl_cmd,
4333 "network X:X::X:X/M pathlimit <0-255>",
4334 "Specify a network to announce via BGP\n"
4335 "IPv6 prefix <network>/<length>\n"
4336 "AS-Path hopcount limit attribute\n"
4337 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4338ALIAS_DEPRECATED (no_ipv6_bgp_network,
4339 no_ipv6_bgp_network_ttl_cmd,
4340 "no network X:X::X:X/M pathlimit <0-255>",
4341 NO_STR
4342 "Specify a network to announce via BGP\n"
4343 "IPv6 prefix <network>/<length>\n"
4344 "AS-Path hopcount limit attribute\n"
4345 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakmaa8b79422011-03-23 10:30:30 +00004346#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004347
4348/* Aggreagete address:
4349
4350 advertise-map Set condition to advertise attribute
4351 as-set Generate AS set path information
4352 attribute-map Set attributes of aggregate
4353 route-map Set parameters of aggregate
4354 summary-only Filter more specific routes from updates
4355 suppress-map Conditionally filter more specific routes from updates
4356 <cr>
4357 */
4358struct bgp_aggregate
4359{
4360 /* Summary-only flag. */
4361 u_char summary_only;
4362
4363 /* AS set generation. */
4364 u_char as_set;
4365
4366 /* Route-map for aggregated route. */
4367 struct route_map *map;
4368
4369 /* Suppress-count. */
4370 unsigned long count;
4371
4372 /* SAFI configuration. */
4373 safi_t safi;
4374};
4375
paul94f2b392005-06-28 12:44:16 +00004376static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004377bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004378{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004379 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004380}
4381
paul94f2b392005-06-28 12:44:16 +00004382static void
paul718e3742002-12-13 20:15:29 +00004383bgp_aggregate_free (struct bgp_aggregate *aggregate)
4384{
4385 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4386}
4387
paul94f2b392005-06-28 12:44:16 +00004388static void
paul718e3742002-12-13 20:15:29 +00004389bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4390 afi_t afi, safi_t safi, struct bgp_info *del,
4391 struct bgp_aggregate *aggregate)
4392{
4393 struct bgp_table *table;
4394 struct bgp_node *top;
4395 struct bgp_node *rn;
4396 u_char origin;
4397 struct aspath *aspath = NULL;
4398 struct aspath *asmerge = NULL;
4399 struct community *community = NULL;
4400 struct community *commerge = NULL;
4401 struct in_addr nexthop;
4402 u_int32_t med = 0;
4403 struct bgp_info *ri;
4404 struct bgp_info *new;
4405 int first = 1;
4406 unsigned long match = 0;
4407
4408 /* Record adding route's nexthop and med. */
4409 if (rinew)
4410 {
4411 nexthop = rinew->attr->nexthop;
4412 med = rinew->attr->med;
4413 }
4414
4415 /* ORIGIN attribute: If at least one route among routes that are
4416 aggregated has ORIGIN with the value INCOMPLETE, then the
4417 aggregated route must have the ORIGIN attribute with the value
4418 INCOMPLETE. Otherwise, if at least one route among routes that
4419 are aggregated has ORIGIN with the value EGP, then the aggregated
4420 route must have the origin attribute with the value EGP. In all
4421 other case the value of the ORIGIN attribute of the aggregated
4422 route is INTERNAL. */
4423 origin = BGP_ORIGIN_IGP;
4424
4425 table = bgp->rib[afi][safi];
4426
4427 top = bgp_node_get (table, p);
4428 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4429 if (rn->p.prefixlen > p->prefixlen)
4430 {
4431 match = 0;
4432
4433 for (ri = rn->info; ri; ri = ri->next)
4434 {
4435 if (BGP_INFO_HOLDDOWN (ri))
4436 continue;
4437
4438 if (del && ri == del)
4439 continue;
4440
4441 if (! rinew && first)
4442 {
4443 nexthop = ri->attr->nexthop;
4444 med = ri->attr->med;
4445 first = 0;
4446 }
4447
4448#ifdef AGGREGATE_NEXTHOP_CHECK
4449 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4450 || ri->attr->med != med)
4451 {
4452 if (aspath)
4453 aspath_free (aspath);
4454 if (community)
4455 community_free (community);
4456 bgp_unlock_node (rn);
4457 bgp_unlock_node (top);
4458 return;
4459 }
4460#endif /* AGGREGATE_NEXTHOP_CHECK */
4461
4462 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4463 {
4464 if (aggregate->summary_only)
4465 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004466 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004467 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004468 match++;
4469 }
4470
4471 aggregate->count++;
4472
4473 if (aggregate->as_set)
4474 {
4475 if (origin < ri->attr->origin)
4476 origin = ri->attr->origin;
4477
4478 if (aspath)
4479 {
4480 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4481 aspath_free (aspath);
4482 aspath = asmerge;
4483 }
4484 else
4485 aspath = aspath_dup (ri->attr->aspath);
4486
4487 if (ri->attr->community)
4488 {
4489 if (community)
4490 {
4491 commerge = community_merge (community,
4492 ri->attr->community);
4493 community = community_uniq_sort (commerge);
4494 community_free (commerge);
4495 }
4496 else
4497 community = community_dup (ri->attr->community);
4498 }
4499 }
4500 }
4501 }
4502 if (match)
4503 bgp_process (bgp, rn, afi, safi);
4504 }
4505 bgp_unlock_node (top);
4506
4507 if (rinew)
4508 {
4509 aggregate->count++;
4510
4511 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004512 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004513
4514 if (aggregate->as_set)
4515 {
4516 if (origin < rinew->attr->origin)
4517 origin = rinew->attr->origin;
4518
4519 if (aspath)
4520 {
4521 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4522 aspath_free (aspath);
4523 aspath = asmerge;
4524 }
4525 else
4526 aspath = aspath_dup (rinew->attr->aspath);
4527
4528 if (rinew->attr->community)
4529 {
4530 if (community)
4531 {
4532 commerge = community_merge (community,
4533 rinew->attr->community);
4534 community = community_uniq_sort (commerge);
4535 community_free (commerge);
4536 }
4537 else
4538 community = community_dup (rinew->attr->community);
4539 }
4540 }
4541 }
4542
4543 if (aggregate->count > 0)
4544 {
4545 rn = bgp_node_get (table, p);
4546 new = bgp_info_new ();
4547 new->type = ZEBRA_ROUTE_BGP;
4548 new->sub_type = BGP_ROUTE_AGGREGATE;
4549 new->peer = bgp->peer_self;
4550 SET_FLAG (new->flags, BGP_INFO_VALID);
4551 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004552 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004553
4554 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004555 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004556 bgp_process (bgp, rn, afi, safi);
4557 }
4558 else
4559 {
4560 if (aspath)
4561 aspath_free (aspath);
4562 if (community)
4563 community_free (community);
4564 }
4565}
4566
4567void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4568 struct bgp_aggregate *);
4569
4570void
4571bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4572 struct bgp_info *ri, afi_t afi, safi_t safi)
4573{
4574 struct bgp_node *child;
4575 struct bgp_node *rn;
4576 struct bgp_aggregate *aggregate;
4577
4578 /* MPLS-VPN aggregation is not yet supported. */
4579 if (safi == SAFI_MPLS_VPN)
4580 return;
4581
4582 if (p->prefixlen == 0)
4583 return;
4584
4585 if (BGP_INFO_HOLDDOWN (ri))
4586 return;
4587
4588 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4589
4590 /* Aggregate address configuration check. */
4591 for (rn = child; rn; rn = rn->parent)
4592 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4593 {
4594 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004595 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004596 }
4597 bgp_unlock_node (child);
4598}
4599
4600void
4601bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4602 struct bgp_info *del, afi_t afi, safi_t safi)
4603{
4604 struct bgp_node *child;
4605 struct bgp_node *rn;
4606 struct bgp_aggregate *aggregate;
4607
4608 /* MPLS-VPN aggregation is not yet supported. */
4609 if (safi == SAFI_MPLS_VPN)
4610 return;
4611
4612 if (p->prefixlen == 0)
4613 return;
4614
4615 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4616
4617 /* Aggregate address configuration check. */
4618 for (rn = child; rn; rn = rn->parent)
4619 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4620 {
4621 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004622 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004623 }
4624 bgp_unlock_node (child);
4625}
4626
paul94f2b392005-06-28 12:44:16 +00004627static void
paul718e3742002-12-13 20:15:29 +00004628bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4629 struct bgp_aggregate *aggregate)
4630{
4631 struct bgp_table *table;
4632 struct bgp_node *top;
4633 struct bgp_node *rn;
4634 struct bgp_info *new;
4635 struct bgp_info *ri;
4636 unsigned long match;
4637 u_char origin = BGP_ORIGIN_IGP;
4638 struct aspath *aspath = NULL;
4639 struct aspath *asmerge = NULL;
4640 struct community *community = NULL;
4641 struct community *commerge = NULL;
4642
4643 table = bgp->rib[afi][safi];
4644
4645 /* Sanity check. */
4646 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4647 return;
4648 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4649 return;
4650
4651 /* If routes exists below this node, generate aggregate routes. */
4652 top = bgp_node_get (table, p);
4653 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4654 if (rn->p.prefixlen > p->prefixlen)
4655 {
4656 match = 0;
4657
4658 for (ri = rn->info; ri; ri = ri->next)
4659 {
4660 if (BGP_INFO_HOLDDOWN (ri))
4661 continue;
4662
4663 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4664 {
4665 /* summary-only aggregate route suppress aggregated
4666 route announcement. */
4667 if (aggregate->summary_only)
4668 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004669 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004670 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004671 match++;
4672 }
4673 /* as-set aggregate route generate origin, as path,
4674 community aggregation. */
4675 if (aggregate->as_set)
4676 {
4677 if (origin < ri->attr->origin)
4678 origin = ri->attr->origin;
4679
4680 if (aspath)
4681 {
4682 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4683 aspath_free (aspath);
4684 aspath = asmerge;
4685 }
4686 else
4687 aspath = aspath_dup (ri->attr->aspath);
4688
4689 if (ri->attr->community)
4690 {
4691 if (community)
4692 {
4693 commerge = community_merge (community,
4694 ri->attr->community);
4695 community = community_uniq_sort (commerge);
4696 community_free (commerge);
4697 }
4698 else
4699 community = community_dup (ri->attr->community);
4700 }
4701 }
4702 aggregate->count++;
4703 }
4704 }
4705
4706 /* If this node is suppressed, process the change. */
4707 if (match)
4708 bgp_process (bgp, rn, afi, safi);
4709 }
4710 bgp_unlock_node (top);
4711
4712 /* Add aggregate route to BGP table. */
4713 if (aggregate->count)
4714 {
4715 rn = bgp_node_get (table, p);
4716
4717 new = bgp_info_new ();
4718 new->type = ZEBRA_ROUTE_BGP;
4719 new->sub_type = BGP_ROUTE_AGGREGATE;
4720 new->peer = bgp->peer_self;
4721 SET_FLAG (new->flags, BGP_INFO_VALID);
4722 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004723 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004724
4725 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004726 bgp_unlock_node (rn);
4727
paul718e3742002-12-13 20:15:29 +00004728 /* Process change. */
4729 bgp_process (bgp, rn, afi, safi);
4730 }
4731}
4732
4733void
4734bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4735 safi_t safi, struct bgp_aggregate *aggregate)
4736{
4737 struct bgp_table *table;
4738 struct bgp_node *top;
4739 struct bgp_node *rn;
4740 struct bgp_info *ri;
4741 unsigned long match;
4742
4743 table = bgp->rib[afi][safi];
4744
4745 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4746 return;
4747 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4748 return;
4749
4750 /* If routes exists below this node, generate aggregate routes. */
4751 top = bgp_node_get (table, p);
4752 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4753 if (rn->p.prefixlen > p->prefixlen)
4754 {
4755 match = 0;
4756
4757 for (ri = rn->info; ri; ri = ri->next)
4758 {
4759 if (BGP_INFO_HOLDDOWN (ri))
4760 continue;
4761
4762 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4763 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004764 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004765 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004766 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004767
Paul Jakmafb982c22007-05-04 20:15:47 +00004768 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004769 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004770 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004771 match++;
4772 }
4773 }
4774 aggregate->count--;
4775 }
4776 }
4777
Paul Jakmafb982c22007-05-04 20:15:47 +00004778 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004779 if (match)
4780 bgp_process (bgp, rn, afi, safi);
4781 }
4782 bgp_unlock_node (top);
4783
4784 /* Delete aggregate route from BGP table. */
4785 rn = bgp_node_get (table, p);
4786
4787 for (ri = rn->info; ri; ri = ri->next)
4788 if (ri->peer == bgp->peer_self
4789 && ri->type == ZEBRA_ROUTE_BGP
4790 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4791 break;
4792
4793 /* Withdraw static BGP route from routing table. */
4794 if (ri)
4795 {
paul718e3742002-12-13 20:15:29 +00004796 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004797 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004798 }
4799
4800 /* Unlock bgp_node_lookup. */
4801 bgp_unlock_node (rn);
4802}
4803
4804/* Aggregate route attribute. */
4805#define AGGREGATE_SUMMARY_ONLY 1
4806#define AGGREGATE_AS_SET 1
4807
paul94f2b392005-06-28 12:44:16 +00004808static int
paulfd79ac92004-10-13 05:06:08 +00004809bgp_aggregate_set (struct vty *vty, const char *prefix_str,
4810 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004811 u_char summary_only, u_char as_set)
4812{
4813 int ret;
4814 struct prefix p;
4815 struct bgp_node *rn;
4816 struct bgp *bgp;
4817 struct bgp_aggregate *aggregate;
4818
4819 /* Convert string to prefix structure. */
4820 ret = str2prefix (prefix_str, &p);
4821 if (!ret)
4822 {
4823 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4824 return CMD_WARNING;
4825 }
4826 apply_mask (&p);
4827
4828 /* Get BGP structure. */
4829 bgp = vty->index;
4830
4831 /* Old configuration check. */
4832 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4833
4834 if (rn->info)
4835 {
4836 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
4837 bgp_unlock_node (rn);
4838 return CMD_WARNING;
4839 }
4840
4841 /* Make aggregate address structure. */
4842 aggregate = bgp_aggregate_new ();
4843 aggregate->summary_only = summary_only;
4844 aggregate->as_set = as_set;
4845 aggregate->safi = safi;
4846 rn->info = aggregate;
4847
4848 /* Aggregate address insert into BGP routing table. */
4849 if (safi & SAFI_UNICAST)
4850 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4851 if (safi & SAFI_MULTICAST)
4852 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4853
4854 return CMD_SUCCESS;
4855}
4856
paul94f2b392005-06-28 12:44:16 +00004857static int
paulfd79ac92004-10-13 05:06:08 +00004858bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4859 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00004860{
4861 int ret;
4862 struct prefix p;
4863 struct bgp_node *rn;
4864 struct bgp *bgp;
4865 struct bgp_aggregate *aggregate;
4866
4867 /* Convert string to prefix structure. */
4868 ret = str2prefix (prefix_str, &p);
4869 if (!ret)
4870 {
4871 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4872 return CMD_WARNING;
4873 }
4874 apply_mask (&p);
4875
4876 /* Get BGP structure. */
4877 bgp = vty->index;
4878
4879 /* Old configuration check. */
4880 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4881 if (! rn)
4882 {
4883 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4884 VTY_NEWLINE);
4885 return CMD_WARNING;
4886 }
4887
4888 aggregate = rn->info;
4889 if (aggregate->safi & SAFI_UNICAST)
4890 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4891 if (aggregate->safi & SAFI_MULTICAST)
4892 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4893
4894 /* Unlock aggregate address configuration. */
4895 rn->info = NULL;
4896 bgp_aggregate_free (aggregate);
4897 bgp_unlock_node (rn);
4898 bgp_unlock_node (rn);
4899
4900 return CMD_SUCCESS;
4901}
4902
4903DEFUN (aggregate_address,
4904 aggregate_address_cmd,
4905 "aggregate-address A.B.C.D/M",
4906 "Configure BGP aggregate entries\n"
4907 "Aggregate prefix\n")
4908{
4909 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4910}
4911
4912DEFUN (aggregate_address_mask,
4913 aggregate_address_mask_cmd,
4914 "aggregate-address A.B.C.D A.B.C.D",
4915 "Configure BGP aggregate entries\n"
4916 "Aggregate address\n"
4917 "Aggregate mask\n")
4918{
4919 int ret;
4920 char prefix_str[BUFSIZ];
4921
4922 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4923
4924 if (! ret)
4925 {
4926 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4927 return CMD_WARNING;
4928 }
4929
4930 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4931 0, 0);
4932}
4933
4934DEFUN (aggregate_address_summary_only,
4935 aggregate_address_summary_only_cmd,
4936 "aggregate-address A.B.C.D/M summary-only",
4937 "Configure BGP aggregate entries\n"
4938 "Aggregate prefix\n"
4939 "Filter more specific routes from updates\n")
4940{
4941 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4942 AGGREGATE_SUMMARY_ONLY, 0);
4943}
4944
4945DEFUN (aggregate_address_mask_summary_only,
4946 aggregate_address_mask_summary_only_cmd,
4947 "aggregate-address A.B.C.D A.B.C.D summary-only",
4948 "Configure BGP aggregate entries\n"
4949 "Aggregate address\n"
4950 "Aggregate mask\n"
4951 "Filter more specific routes from updates\n")
4952{
4953 int ret;
4954 char prefix_str[BUFSIZ];
4955
4956 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4957
4958 if (! ret)
4959 {
4960 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4961 return CMD_WARNING;
4962 }
4963
4964 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4965 AGGREGATE_SUMMARY_ONLY, 0);
4966}
4967
4968DEFUN (aggregate_address_as_set,
4969 aggregate_address_as_set_cmd,
4970 "aggregate-address A.B.C.D/M as-set",
4971 "Configure BGP aggregate entries\n"
4972 "Aggregate prefix\n"
4973 "Generate AS set path information\n")
4974{
4975 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4976 0, AGGREGATE_AS_SET);
4977}
4978
4979DEFUN (aggregate_address_mask_as_set,
4980 aggregate_address_mask_as_set_cmd,
4981 "aggregate-address A.B.C.D A.B.C.D as-set",
4982 "Configure BGP aggregate entries\n"
4983 "Aggregate address\n"
4984 "Aggregate mask\n"
4985 "Generate AS set path information\n")
4986{
4987 int ret;
4988 char prefix_str[BUFSIZ];
4989
4990 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4991
4992 if (! ret)
4993 {
4994 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4995 return CMD_WARNING;
4996 }
4997
4998 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4999 0, AGGREGATE_AS_SET);
5000}
5001
5002
5003DEFUN (aggregate_address_as_set_summary,
5004 aggregate_address_as_set_summary_cmd,
5005 "aggregate-address A.B.C.D/M as-set summary-only",
5006 "Configure BGP aggregate entries\n"
5007 "Aggregate prefix\n"
5008 "Generate AS set path information\n"
5009 "Filter more specific routes from updates\n")
5010{
5011 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5012 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5013}
5014
5015ALIAS (aggregate_address_as_set_summary,
5016 aggregate_address_summary_as_set_cmd,
5017 "aggregate-address A.B.C.D/M summary-only as-set",
5018 "Configure BGP aggregate entries\n"
5019 "Aggregate prefix\n"
5020 "Filter more specific routes from updates\n"
5021 "Generate AS set path information\n")
5022
5023DEFUN (aggregate_address_mask_as_set_summary,
5024 aggregate_address_mask_as_set_summary_cmd,
5025 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5026 "Configure BGP aggregate entries\n"
5027 "Aggregate address\n"
5028 "Aggregate mask\n"
5029 "Generate AS set path information\n"
5030 "Filter more specific routes from updates\n")
5031{
5032 int ret;
5033 char prefix_str[BUFSIZ];
5034
5035 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5036
5037 if (! ret)
5038 {
5039 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5040 return CMD_WARNING;
5041 }
5042
5043 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5044 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5045}
5046
5047ALIAS (aggregate_address_mask_as_set_summary,
5048 aggregate_address_mask_summary_as_set_cmd,
5049 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5050 "Configure BGP aggregate entries\n"
5051 "Aggregate address\n"
5052 "Aggregate mask\n"
5053 "Filter more specific routes from updates\n"
5054 "Generate AS set path information\n")
5055
5056DEFUN (no_aggregate_address,
5057 no_aggregate_address_cmd,
5058 "no aggregate-address A.B.C.D/M",
5059 NO_STR
5060 "Configure BGP aggregate entries\n"
5061 "Aggregate prefix\n")
5062{
5063 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5064}
5065
5066ALIAS (no_aggregate_address,
5067 no_aggregate_address_summary_only_cmd,
5068 "no aggregate-address A.B.C.D/M summary-only",
5069 NO_STR
5070 "Configure BGP aggregate entries\n"
5071 "Aggregate prefix\n"
5072 "Filter more specific routes from updates\n")
5073
5074ALIAS (no_aggregate_address,
5075 no_aggregate_address_as_set_cmd,
5076 "no aggregate-address A.B.C.D/M as-set",
5077 NO_STR
5078 "Configure BGP aggregate entries\n"
5079 "Aggregate prefix\n"
5080 "Generate AS set path information\n")
5081
5082ALIAS (no_aggregate_address,
5083 no_aggregate_address_as_set_summary_cmd,
5084 "no aggregate-address A.B.C.D/M as-set summary-only",
5085 NO_STR
5086 "Configure BGP aggregate entries\n"
5087 "Aggregate prefix\n"
5088 "Generate AS set path information\n"
5089 "Filter more specific routes from updates\n")
5090
5091ALIAS (no_aggregate_address,
5092 no_aggregate_address_summary_as_set_cmd,
5093 "no aggregate-address A.B.C.D/M summary-only as-set",
5094 NO_STR
5095 "Configure BGP aggregate entries\n"
5096 "Aggregate prefix\n"
5097 "Filter more specific routes from updates\n"
5098 "Generate AS set path information\n")
5099
5100DEFUN (no_aggregate_address_mask,
5101 no_aggregate_address_mask_cmd,
5102 "no aggregate-address A.B.C.D A.B.C.D",
5103 NO_STR
5104 "Configure BGP aggregate entries\n"
5105 "Aggregate address\n"
5106 "Aggregate mask\n")
5107{
5108 int ret;
5109 char prefix_str[BUFSIZ];
5110
5111 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5112
5113 if (! ret)
5114 {
5115 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5116 return CMD_WARNING;
5117 }
5118
5119 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5120}
5121
5122ALIAS (no_aggregate_address_mask,
5123 no_aggregate_address_mask_summary_only_cmd,
5124 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5125 NO_STR
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate address\n"
5128 "Aggregate mask\n"
5129 "Filter more specific routes from updates\n")
5130
5131ALIAS (no_aggregate_address_mask,
5132 no_aggregate_address_mask_as_set_cmd,
5133 "no aggregate-address A.B.C.D A.B.C.D as-set",
5134 NO_STR
5135 "Configure BGP aggregate entries\n"
5136 "Aggregate address\n"
5137 "Aggregate mask\n"
5138 "Generate AS set path information\n")
5139
5140ALIAS (no_aggregate_address_mask,
5141 no_aggregate_address_mask_as_set_summary_cmd,
5142 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5143 NO_STR
5144 "Configure BGP aggregate entries\n"
5145 "Aggregate address\n"
5146 "Aggregate mask\n"
5147 "Generate AS set path information\n"
5148 "Filter more specific routes from updates\n")
5149
5150ALIAS (no_aggregate_address_mask,
5151 no_aggregate_address_mask_summary_as_set_cmd,
5152 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5153 NO_STR
5154 "Configure BGP aggregate entries\n"
5155 "Aggregate address\n"
5156 "Aggregate mask\n"
5157 "Filter more specific routes from updates\n"
5158 "Generate AS set path information\n")
5159
5160#ifdef HAVE_IPV6
5161DEFUN (ipv6_aggregate_address,
5162 ipv6_aggregate_address_cmd,
5163 "aggregate-address X:X::X:X/M",
5164 "Configure BGP aggregate entries\n"
5165 "Aggregate prefix\n")
5166{
5167 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5168}
5169
5170DEFUN (ipv6_aggregate_address_summary_only,
5171 ipv6_aggregate_address_summary_only_cmd,
5172 "aggregate-address X:X::X:X/M summary-only",
5173 "Configure BGP aggregate entries\n"
5174 "Aggregate prefix\n"
5175 "Filter more specific routes from updates\n")
5176{
5177 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5178 AGGREGATE_SUMMARY_ONLY, 0);
5179}
5180
5181DEFUN (no_ipv6_aggregate_address,
5182 no_ipv6_aggregate_address_cmd,
5183 "no aggregate-address X:X::X:X/M",
5184 NO_STR
5185 "Configure BGP aggregate entries\n"
5186 "Aggregate prefix\n")
5187{
5188 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5189}
5190
5191DEFUN (no_ipv6_aggregate_address_summary_only,
5192 no_ipv6_aggregate_address_summary_only_cmd,
5193 "no aggregate-address X:X::X:X/M summary-only",
5194 NO_STR
5195 "Configure BGP aggregate entries\n"
5196 "Aggregate prefix\n"
5197 "Filter more specific routes from updates\n")
5198{
5199 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5200}
5201
5202ALIAS (ipv6_aggregate_address,
5203 old_ipv6_aggregate_address_cmd,
5204 "ipv6 bgp aggregate-address X:X::X:X/M",
5205 IPV6_STR
5206 BGP_STR
5207 "Configure BGP aggregate entries\n"
5208 "Aggregate prefix\n")
5209
5210ALIAS (ipv6_aggregate_address_summary_only,
5211 old_ipv6_aggregate_address_summary_only_cmd,
5212 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5213 IPV6_STR
5214 BGP_STR
5215 "Configure BGP aggregate entries\n"
5216 "Aggregate prefix\n"
5217 "Filter more specific routes from updates\n")
5218
5219ALIAS (no_ipv6_aggregate_address,
5220 old_no_ipv6_aggregate_address_cmd,
5221 "no ipv6 bgp aggregate-address X:X::X:X/M",
5222 NO_STR
5223 IPV6_STR
5224 BGP_STR
5225 "Configure BGP aggregate entries\n"
5226 "Aggregate prefix\n")
5227
5228ALIAS (no_ipv6_aggregate_address_summary_only,
5229 old_no_ipv6_aggregate_address_summary_only_cmd,
5230 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5231 NO_STR
5232 IPV6_STR
5233 BGP_STR
5234 "Configure BGP aggregate entries\n"
5235 "Aggregate prefix\n"
5236 "Filter more specific routes from updates\n")
5237#endif /* HAVE_IPV6 */
5238
5239/* Redistribute route treatment. */
5240void
Stephen Hemminger840faae2011-12-06 14:51:10 +04005241bgp_redistribute_add (struct prefix *p, const struct in_addr *nexthop,
5242 const struct in6_addr *nexthop6,
paul718e3742002-12-13 20:15:29 +00005243 u_int32_t metric, u_char type)
5244{
5245 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005246 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005247 struct bgp_info *new;
5248 struct bgp_info *bi;
5249 struct bgp_info info;
5250 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005251 struct attr attr = { 0 };
5252 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005253 struct attr *new_attr;
5254 afi_t afi;
5255 int ret;
5256
5257 /* Make default attribute. */
5258 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5259 if (nexthop)
5260 attr.nexthop = *nexthop;
5261
Stephen Hemminger840faae2011-12-06 14:51:10 +04005262#ifdef HAVE_IPV6
5263 if (nexthop6)
5264 {
5265 struct attr_extra *extra = bgp_attr_extra_get(&attr);
5266 extra->mp_nexthop_global = *nexthop6;
5267 extra->mp_nexthop_len = 16;
5268 }
5269#endif
5270
paul718e3742002-12-13 20:15:29 +00005271 attr.med = metric;
5272 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5273
paul1eb8ef22005-04-07 07:30:20 +00005274 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005275 {
5276 afi = family2afi (p->family);
5277
5278 if (bgp->redist[afi][type])
5279 {
5280 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005281 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005282
5283 if (bgp->redist_metric_flag[afi][type])
5284 attr_new.med = bgp->redist_metric[afi][type];
5285
5286 /* Apply route-map. */
5287 if (bgp->rmap[afi][type].map)
5288 {
5289 info.peer = bgp->peer_self;
5290 info.attr = &attr_new;
5291
paulfee0f4c2004-09-13 05:12:46 +00005292 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5293
paul718e3742002-12-13 20:15:29 +00005294 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5295 &info);
paulfee0f4c2004-09-13 05:12:46 +00005296
5297 bgp->peer_self->rmap_type = 0;
5298
paul718e3742002-12-13 20:15:29 +00005299 if (ret == RMAP_DENYMATCH)
5300 {
5301 /* Free uninterned attribute. */
5302 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005303 bgp_attr_extra_free (&attr_new);
5304
paul718e3742002-12-13 20:15:29 +00005305 /* Unintern original. */
5306 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005307 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005308 bgp_redistribute_delete (p, type);
5309 return;
5310 }
5311 }
5312
Paul Jakmafb982c22007-05-04 20:15:47 +00005313 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5314 afi, SAFI_UNICAST, p, NULL);
5315
paul718e3742002-12-13 20:15:29 +00005316 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005317 bgp_attr_extra_free (&attr_new);
5318
paul718e3742002-12-13 20:15:29 +00005319 for (bi = bn->info; bi; bi = bi->next)
5320 if (bi->peer == bgp->peer_self
5321 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5322 break;
5323
5324 if (bi)
5325 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005326 if (attrhash_cmp (bi->attr, new_attr) &&
5327 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005328 {
5329 bgp_attr_unintern (new_attr);
5330 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005331 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005332 bgp_unlock_node (bn);
5333 return;
5334 }
5335 else
5336 {
5337 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005338 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005339
5340 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005341 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5342 bgp_info_restore(bn, bi);
5343 else
5344 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005345 bgp_attr_unintern (bi->attr);
5346 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005347 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005348
5349 /* Process change. */
5350 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5351 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5352 bgp_unlock_node (bn);
5353 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005354 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005355 return;
5356 }
5357 }
5358
5359 new = bgp_info_new ();
5360 new->type = type;
5361 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5362 new->peer = bgp->peer_self;
5363 SET_FLAG (new->flags, BGP_INFO_VALID);
5364 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005365 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005366
5367 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5368 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005369 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005370 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5371 }
5372 }
5373
5374 /* Unintern original. */
5375 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005376 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005377}
5378
5379void
5380bgp_redistribute_delete (struct prefix *p, u_char type)
5381{
5382 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005383 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005384 afi_t afi;
5385 struct bgp_node *rn;
5386 struct bgp_info *ri;
5387
paul1eb8ef22005-04-07 07:30:20 +00005388 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005389 {
5390 afi = family2afi (p->family);
5391
5392 if (bgp->redist[afi][type])
5393 {
paulfee0f4c2004-09-13 05:12:46 +00005394 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005395
5396 for (ri = rn->info; ri; ri = ri->next)
5397 if (ri->peer == bgp->peer_self
5398 && ri->type == type)
5399 break;
5400
5401 if (ri)
5402 {
5403 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005404 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005405 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005406 }
5407 bgp_unlock_node (rn);
5408 }
5409 }
5410}
5411
5412/* Withdraw specified route type's route. */
5413void
5414bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5415{
5416 struct bgp_node *rn;
5417 struct bgp_info *ri;
5418 struct bgp_table *table;
5419
5420 table = bgp->rib[afi][SAFI_UNICAST];
5421
5422 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5423 {
5424 for (ri = rn->info; ri; ri = ri->next)
5425 if (ri->peer == bgp->peer_self
5426 && ri->type == type)
5427 break;
5428
5429 if (ri)
5430 {
5431 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005432 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005433 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005434 }
5435 }
5436}
5437
5438/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005439static void
paul718e3742002-12-13 20:15:29 +00005440route_vty_out_route (struct prefix *p, struct vty *vty)
5441{
5442 int len;
5443 u_int32_t destination;
5444 char buf[BUFSIZ];
5445
5446 if (p->family == AF_INET)
5447 {
5448 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5449 destination = ntohl (p->u.prefix4.s_addr);
5450
5451 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5452 || (IN_CLASSB (destination) && p->prefixlen == 16)
5453 || (IN_CLASSA (destination) && p->prefixlen == 8)
5454 || p->u.prefix4.s_addr == 0)
5455 {
5456 /* When mask is natural, mask is not displayed. */
5457 }
5458 else
5459 len += vty_out (vty, "/%d", p->prefixlen);
5460 }
5461 else
5462 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5463 p->prefixlen);
5464
5465 len = 17 - len;
5466 if (len < 1)
5467 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5468 else
5469 vty_out (vty, "%*s", len, " ");
5470}
5471
paul718e3742002-12-13 20:15:29 +00005472enum bgp_display_type
5473{
5474 normal_list,
5475};
5476
paulb40d9392005-08-22 22:34:41 +00005477/* Print the short form route status for a bgp_info */
5478static void
5479route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005480{
paulb40d9392005-08-22 22:34:41 +00005481 /* Route status display. */
5482 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5483 vty_out (vty, "R");
5484 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005485 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005486 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005487 vty_out (vty, "s");
5488 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5489 vty_out (vty, "*");
5490 else
5491 vty_out (vty, " ");
5492
5493 /* Selected */
5494 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5495 vty_out (vty, "h");
5496 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5497 vty_out (vty, "d");
5498 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5499 vty_out (vty, ">");
5500 else
5501 vty_out (vty, " ");
5502
5503 /* Internal route. */
5504 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5505 vty_out (vty, "i");
5506 else
paulb40d9392005-08-22 22:34:41 +00005507 vty_out (vty, " ");
5508}
5509
5510/* called from terminal list command */
5511void
5512route_vty_out (struct vty *vty, struct prefix *p,
5513 struct bgp_info *binfo, int display, safi_t safi)
5514{
5515 struct attr *attr;
5516
5517 /* short status lead text */
5518 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005519
5520 /* print prefix and mask */
5521 if (! display)
5522 route_vty_out_route (p, vty);
5523 else
5524 vty_out (vty, "%*s", 17, " ");
5525
5526 /* Print attribute */
5527 attr = binfo->attr;
5528 if (attr)
5529 {
5530 if (p->family == AF_INET)
5531 {
5532 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005533 vty_out (vty, "%-16s",
5534 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005535 else
5536 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5537 }
5538#ifdef HAVE_IPV6
5539 else if (p->family == AF_INET6)
5540 {
5541 int len;
5542 char buf[BUFSIZ];
5543
5544 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005545 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5546 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005547 len = 16 - len;
5548 if (len < 1)
5549 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5550 else
5551 vty_out (vty, "%*s", len, " ");
5552 }
5553#endif /* HAVE_IPV6 */
5554
5555 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005556 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005557 else
5558 vty_out (vty, " ");
5559
5560 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005561 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005562 else
5563 vty_out (vty, " ");
5564
Paul Jakmafb982c22007-05-04 20:15:47 +00005565 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005566
Paul Jakmab2518c12006-05-12 23:48:40 +00005567 /* Print aspath */
5568 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005569 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005570
Paul Jakmab2518c12006-05-12 23:48:40 +00005571 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005572 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005573 }
paul718e3742002-12-13 20:15:29 +00005574 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005575}
5576
5577/* called from terminal list command */
5578void
5579route_vty_out_tmp (struct vty *vty, struct prefix *p,
5580 struct attr *attr, safi_t safi)
5581{
5582 /* Route status display. */
5583 vty_out (vty, "*");
5584 vty_out (vty, ">");
5585 vty_out (vty, " ");
5586
5587 /* print prefix and mask */
5588 route_vty_out_route (p, vty);
5589
5590 /* Print attribute */
5591 if (attr)
5592 {
5593 if (p->family == AF_INET)
5594 {
5595 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005596 vty_out (vty, "%-16s",
5597 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005598 else
5599 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5600 }
5601#ifdef HAVE_IPV6
5602 else if (p->family == AF_INET6)
5603 {
5604 int len;
5605 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005606
5607 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005608
5609 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005610 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5611 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005612 len = 16 - len;
5613 if (len < 1)
5614 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5615 else
5616 vty_out (vty, "%*s", len, " ");
5617 }
5618#endif /* HAVE_IPV6 */
5619
5620 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005621 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005622 else
5623 vty_out (vty, " ");
5624
5625 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005626 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005627 else
5628 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005629
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005630 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005631
Paul Jakmab2518c12006-05-12 23:48:40 +00005632 /* Print aspath */
5633 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005634 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005635
Paul Jakmab2518c12006-05-12 23:48:40 +00005636 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005637 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005638 }
paul718e3742002-12-13 20:15:29 +00005639
5640 vty_out (vty, "%s", VTY_NEWLINE);
5641}
5642
ajs5a646652004-11-05 01:25:55 +00005643void
paul718e3742002-12-13 20:15:29 +00005644route_vty_out_tag (struct vty *vty, struct prefix *p,
5645 struct bgp_info *binfo, int display, safi_t safi)
5646{
5647 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005648 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005649
5650 if (!binfo->extra)
5651 return;
5652
paulb40d9392005-08-22 22:34:41 +00005653 /* short status lead text */
5654 route_vty_short_status_out (vty, binfo);
5655
paul718e3742002-12-13 20:15:29 +00005656 /* print prefix and mask */
5657 if (! display)
5658 route_vty_out_route (p, vty);
5659 else
5660 vty_out (vty, "%*s", 17, " ");
5661
5662 /* Print attribute */
5663 attr = binfo->attr;
5664 if (attr)
5665 {
5666 if (p->family == AF_INET)
5667 {
5668 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005669 vty_out (vty, "%-16s",
5670 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005671 else
5672 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5673 }
5674#ifdef HAVE_IPV6
5675 else if (p->family == AF_INET6)
5676 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005677 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005678 char buf[BUFSIZ];
5679 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005680 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005681 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005682 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5683 buf, BUFSIZ));
5684 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005685 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005686 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5687 buf, BUFSIZ),
5688 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5689 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005690
5691 }
5692#endif /* HAVE_IPV6 */
5693 }
5694
Paul Jakmafb982c22007-05-04 20:15:47 +00005695 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005696
5697 vty_out (vty, "notag/%d", label);
5698
5699 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005700}
5701
5702/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005703static void
paul718e3742002-12-13 20:15:29 +00005704damp_route_vty_out (struct vty *vty, struct prefix *p,
5705 struct bgp_info *binfo, int display, safi_t safi)
5706{
5707 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005708 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005709 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005710
paulb40d9392005-08-22 22:34:41 +00005711 /* short status lead text */
5712 route_vty_short_status_out (vty, binfo);
5713
paul718e3742002-12-13 20:15:29 +00005714 /* print prefix and mask */
5715 if (! display)
5716 route_vty_out_route (p, vty);
5717 else
5718 vty_out (vty, "%*s", 17, " ");
5719
5720 len = vty_out (vty, "%s", binfo->peer->host);
5721 len = 17 - len;
5722 if (len < 1)
5723 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5724 else
5725 vty_out (vty, "%*s", len, " ");
5726
Chris Caputo50aef6f2009-06-23 06:06:49 +00005727 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005728
5729 /* Print attribute */
5730 attr = binfo->attr;
5731 if (attr)
5732 {
5733 /* Print aspath */
5734 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005735 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005736
5737 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005738 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005739 }
5740 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005741}
5742
paul718e3742002-12-13 20:15:29 +00005743/* flap route */
ajs5a646652004-11-05 01:25:55 +00005744static void
paul718e3742002-12-13 20:15:29 +00005745flap_route_vty_out (struct vty *vty, struct prefix *p,
5746 struct bgp_info *binfo, int display, safi_t safi)
5747{
5748 struct attr *attr;
5749 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005750 char timebuf[BGP_UPTIME_LEN];
5751 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005752
5753 if (!binfo->extra)
5754 return;
5755
5756 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005757
paulb40d9392005-08-22 22:34:41 +00005758 /* short status lead text */
5759 route_vty_short_status_out (vty, binfo);
5760
paul718e3742002-12-13 20:15:29 +00005761 /* print prefix and mask */
5762 if (! display)
5763 route_vty_out_route (p, vty);
5764 else
5765 vty_out (vty, "%*s", 17, " ");
5766
5767 len = vty_out (vty, "%s", binfo->peer->host);
5768 len = 16 - len;
5769 if (len < 1)
5770 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5771 else
5772 vty_out (vty, "%*s", len, " ");
5773
5774 len = vty_out (vty, "%d", bdi->flap);
5775 len = 5 - len;
5776 if (len < 1)
5777 vty_out (vty, " ");
5778 else
5779 vty_out (vty, "%*s ", len, " ");
5780
5781 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5782 timebuf, BGP_UPTIME_LEN));
5783
5784 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5785 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005786 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005787 else
5788 vty_out (vty, "%*s ", 8, " ");
5789
5790 /* Print attribute */
5791 attr = binfo->attr;
5792 if (attr)
5793 {
5794 /* Print aspath */
5795 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005796 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005797
5798 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005799 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005800 }
5801 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005802}
5803
paul94f2b392005-06-28 12:44:16 +00005804static void
paul718e3742002-12-13 20:15:29 +00005805route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5806 struct bgp_info *binfo, afi_t afi, safi_t safi)
5807{
5808 char buf[INET6_ADDRSTRLEN];
5809 char buf1[BUFSIZ];
5810 struct attr *attr;
5811 int sockunion_vty_out (struct vty *, union sockunion *);
John Kempcc0b6c12011-03-18 17:52:18 +03005812#ifdef HAVE_CLOCK_MONOTONIC
5813 time_t tbuf;
5814#endif
paul718e3742002-12-13 20:15:29 +00005815
5816 attr = binfo->attr;
5817
5818 if (attr)
5819 {
5820 /* Line1 display AS-path, Aggregator */
5821 if (attr->aspath)
5822 {
5823 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005824 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005825 vty_out (vty, "Local");
5826 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005827 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005828 }
5829
paulb40d9392005-08-22 22:34:41 +00005830 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5831 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005832 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5833 vty_out (vty, ", (stale)");
5834 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005835 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005836 attr->extra->aggregator_as,
5837 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005838 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5839 vty_out (vty, ", (Received from a RR-client)");
5840 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5841 vty_out (vty, ", (Received from a RS-client)");
5842 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5843 vty_out (vty, ", (history entry)");
5844 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5845 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005846 vty_out (vty, "%s", VTY_NEWLINE);
5847
5848 /* Line2 display Next-hop, Neighbor, Router-id */
5849 if (p->family == AF_INET)
5850 {
5851 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005852 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005853 inet_ntoa (attr->nexthop));
5854 }
5855#ifdef HAVE_IPV6
5856 else
5857 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005858 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005859 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005860 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005861 buf, INET6_ADDRSTRLEN));
5862 }
5863#endif /* HAVE_IPV6 */
5864
5865 if (binfo->peer == bgp->peer_self)
5866 {
5867 vty_out (vty, " from %s ",
5868 p->family == AF_INET ? "0.0.0.0" : "::");
5869 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5870 }
5871 else
5872 {
5873 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5874 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005875 else if (binfo->extra && binfo->extra->igpmetric)
5876 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005877 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005878 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005879 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005880 else
5881 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5882 }
5883 vty_out (vty, "%s", VTY_NEWLINE);
5884
5885#ifdef HAVE_IPV6
5886 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005887 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005888 {
5889 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005890 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005891 buf, INET6_ADDRSTRLEN),
5892 VTY_NEWLINE);
5893 }
5894#endif /* HAVE_IPV6 */
5895
5896 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5897 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5898
5899 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005900 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005901
5902 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005903 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005904 else
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005905 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005906
Paul Jakmafb982c22007-05-04 20:15:47 +00005907 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005908 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005909
5910 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5911 vty_out (vty, ", valid");
5912
5913 if (binfo->peer != bgp->peer_self)
5914 {
5915 if (binfo->peer->as == binfo->peer->local_as)
5916 vty_out (vty, ", internal");
5917 else
5918 vty_out (vty, ", %s",
5919 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5920 }
5921 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5922 vty_out (vty, ", aggregated, local");
5923 else if (binfo->type != ZEBRA_ROUTE_BGP)
5924 vty_out (vty, ", sourced");
5925 else
5926 vty_out (vty, ", sourced, local");
5927
5928 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5929 vty_out (vty, ", atomic-aggregate");
5930
5931 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5932 vty_out (vty, ", best");
5933
5934 vty_out (vty, "%s", VTY_NEWLINE);
5935
5936 /* Line 4 display Community */
5937 if (attr->community)
5938 vty_out (vty, " Community: %s%s", attr->community->str,
5939 VTY_NEWLINE);
5940
5941 /* Line 5 display Extended-community */
5942 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00005943 vty_out (vty, " Extended Community: %s%s",
5944 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005945
5946 /* Line 6 display Originator, Cluster-id */
5947 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5948 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5949 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005950 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005951 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005952 vty_out (vty, " Originator: %s",
5953 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005954
5955 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5956 {
5957 int i;
5958 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005959 for (i = 0; i < attr->extra->cluster->length / 4; i++)
5960 vty_out (vty, "%s ",
5961 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00005962 }
5963 vty_out (vty, "%s", VTY_NEWLINE);
5964 }
Paul Jakma41367172007-08-06 15:24:51 +00005965
Paul Jakmafb982c22007-05-04 20:15:47 +00005966 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00005967 bgp_damp_info_vty (vty, binfo);
5968
5969 /* Line 7 display Uptime */
John Kempcc0b6c12011-03-18 17:52:18 +03005970#ifdef HAVE_CLOCK_MONOTONIC
5971 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04005972 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kempcc0b6c12011-03-18 17:52:18 +03005973#else
5974 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
5975#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00005976 }
5977 vty_out (vty, "%s", VTY_NEWLINE);
5978}
5979
paulb40d9392005-08-22 22:34:41 +00005980#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 +00005981#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005982#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5983#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5984#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5985
5986enum bgp_show_type
5987{
5988 bgp_show_type_normal,
5989 bgp_show_type_regexp,
5990 bgp_show_type_prefix_list,
5991 bgp_show_type_filter_list,
5992 bgp_show_type_route_map,
5993 bgp_show_type_neighbor,
5994 bgp_show_type_cidr_only,
5995 bgp_show_type_prefix_longer,
5996 bgp_show_type_community_all,
5997 bgp_show_type_community,
5998 bgp_show_type_community_exact,
5999 bgp_show_type_community_list,
6000 bgp_show_type_community_list_exact,
6001 bgp_show_type_flap_statistics,
6002 bgp_show_type_flap_address,
6003 bgp_show_type_flap_prefix,
6004 bgp_show_type_flap_cidr_only,
6005 bgp_show_type_flap_regexp,
6006 bgp_show_type_flap_filter_list,
6007 bgp_show_type_flap_prefix_list,
6008 bgp_show_type_flap_prefix_longer,
6009 bgp_show_type_flap_route_map,
6010 bgp_show_type_flap_neighbor,
6011 bgp_show_type_dampend_paths,
6012 bgp_show_type_damp_neighbor
6013};
6014
ajs5a646652004-11-05 01:25:55 +00006015static int
paulfee0f4c2004-09-13 05:12:46 +00006016bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006017 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006018{
paul718e3742002-12-13 20:15:29 +00006019 struct bgp_info *ri;
6020 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006021 int header = 1;
paul718e3742002-12-13 20:15:29 +00006022 int display;
ajs5a646652004-11-05 01:25:55 +00006023 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006024
6025 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006026 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006027
paul718e3742002-12-13 20:15:29 +00006028 /* Start processing of routes. */
6029 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6030 if (rn->info != NULL)
6031 {
6032 display = 0;
6033
6034 for (ri = rn->info; ri; ri = ri->next)
6035 {
ajs5a646652004-11-05 01:25:55 +00006036 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006037 || type == bgp_show_type_flap_address
6038 || type == bgp_show_type_flap_prefix
6039 || type == bgp_show_type_flap_cidr_only
6040 || type == bgp_show_type_flap_regexp
6041 || type == bgp_show_type_flap_filter_list
6042 || type == bgp_show_type_flap_prefix_list
6043 || type == bgp_show_type_flap_prefix_longer
6044 || type == bgp_show_type_flap_route_map
6045 || type == bgp_show_type_flap_neighbor
6046 || type == bgp_show_type_dampend_paths
6047 || type == bgp_show_type_damp_neighbor)
6048 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006049 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006050 continue;
6051 }
6052 if (type == bgp_show_type_regexp
6053 || type == bgp_show_type_flap_regexp)
6054 {
ajs5a646652004-11-05 01:25:55 +00006055 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006056
6057 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6058 continue;
6059 }
6060 if (type == bgp_show_type_prefix_list
6061 || type == bgp_show_type_flap_prefix_list)
6062 {
ajs5a646652004-11-05 01:25:55 +00006063 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006064
6065 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6066 continue;
6067 }
6068 if (type == bgp_show_type_filter_list
6069 || type == bgp_show_type_flap_filter_list)
6070 {
ajs5a646652004-11-05 01:25:55 +00006071 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006072
6073 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6074 continue;
6075 }
6076 if (type == bgp_show_type_route_map
6077 || type == bgp_show_type_flap_route_map)
6078 {
ajs5a646652004-11-05 01:25:55 +00006079 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006080 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006081 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006082 int ret;
6083
Paul Jakmafb982c22007-05-04 20:15:47 +00006084 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006085 binfo.peer = ri->peer;
6086 binfo.attr = &dummy_attr;
6087
6088 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006089
6090 bgp_attr_extra_free (&dummy_attr);
6091
paul718e3742002-12-13 20:15:29 +00006092 if (ret == RMAP_DENYMATCH)
6093 continue;
6094 }
6095 if (type == bgp_show_type_neighbor
6096 || type == bgp_show_type_flap_neighbor
6097 || type == bgp_show_type_damp_neighbor)
6098 {
ajs5a646652004-11-05 01:25:55 +00006099 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006100
6101 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6102 continue;
6103 }
6104 if (type == bgp_show_type_cidr_only
6105 || type == bgp_show_type_flap_cidr_only)
6106 {
6107 u_int32_t destination;
6108
6109 destination = ntohl (rn->p.u.prefix4.s_addr);
6110 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6111 continue;
6112 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6113 continue;
6114 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6115 continue;
6116 }
6117 if (type == bgp_show_type_prefix_longer
6118 || type == bgp_show_type_flap_prefix_longer)
6119 {
ajs5a646652004-11-05 01:25:55 +00006120 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006121
6122 if (! prefix_match (p, &rn->p))
6123 continue;
6124 }
6125 if (type == bgp_show_type_community_all)
6126 {
6127 if (! ri->attr->community)
6128 continue;
6129 }
6130 if (type == bgp_show_type_community)
6131 {
ajs5a646652004-11-05 01:25:55 +00006132 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006133
6134 if (! ri->attr->community ||
6135 ! community_match (ri->attr->community, com))
6136 continue;
6137 }
6138 if (type == bgp_show_type_community_exact)
6139 {
ajs5a646652004-11-05 01:25:55 +00006140 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006141
6142 if (! ri->attr->community ||
6143 ! community_cmp (ri->attr->community, com))
6144 continue;
6145 }
6146 if (type == bgp_show_type_community_list)
6147 {
ajs5a646652004-11-05 01:25:55 +00006148 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006149
6150 if (! community_list_match (ri->attr->community, list))
6151 continue;
6152 }
6153 if (type == bgp_show_type_community_list_exact)
6154 {
ajs5a646652004-11-05 01:25:55 +00006155 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006156
6157 if (! community_list_exact_match (ri->attr->community, list))
6158 continue;
6159 }
6160 if (type == bgp_show_type_flap_address
6161 || type == bgp_show_type_flap_prefix)
6162 {
ajs5a646652004-11-05 01:25:55 +00006163 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006164
6165 if (! prefix_match (&rn->p, p))
6166 continue;
6167
6168 if (type == bgp_show_type_flap_prefix)
6169 if (p->prefixlen != rn->p.prefixlen)
6170 continue;
6171 }
6172 if (type == bgp_show_type_dampend_paths
6173 || type == bgp_show_type_damp_neighbor)
6174 {
6175 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6176 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6177 continue;
6178 }
6179
6180 if (header)
6181 {
hasso93406d82005-02-02 14:40:33 +00006182 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6183 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6184 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006185 if (type == bgp_show_type_dampend_paths
6186 || type == bgp_show_type_damp_neighbor)
6187 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6188 else if (type == bgp_show_type_flap_statistics
6189 || type == bgp_show_type_flap_address
6190 || type == bgp_show_type_flap_prefix
6191 || type == bgp_show_type_flap_cidr_only
6192 || type == bgp_show_type_flap_regexp
6193 || type == bgp_show_type_flap_filter_list
6194 || type == bgp_show_type_flap_prefix_list
6195 || type == bgp_show_type_flap_prefix_longer
6196 || type == bgp_show_type_flap_route_map
6197 || type == bgp_show_type_flap_neighbor)
6198 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6199 else
6200 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006201 header = 0;
6202 }
6203
6204 if (type == bgp_show_type_dampend_paths
6205 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006206 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006207 else if (type == bgp_show_type_flap_statistics
6208 || type == bgp_show_type_flap_address
6209 || type == bgp_show_type_flap_prefix
6210 || type == bgp_show_type_flap_cidr_only
6211 || type == bgp_show_type_flap_regexp
6212 || type == bgp_show_type_flap_filter_list
6213 || type == bgp_show_type_flap_prefix_list
6214 || type == bgp_show_type_flap_prefix_longer
6215 || type == bgp_show_type_flap_route_map
6216 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006217 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006218 else
ajs5a646652004-11-05 01:25:55 +00006219 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006220 display++;
6221 }
6222 if (display)
ajs5a646652004-11-05 01:25:55 +00006223 output_count++;
paul718e3742002-12-13 20:15:29 +00006224 }
6225
6226 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006227 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006228 {
6229 if (type == bgp_show_type_normal)
6230 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6231 }
6232 else
6233 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006234 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006235
6236 return CMD_SUCCESS;
6237}
6238
ajs5a646652004-11-05 01:25:55 +00006239static int
paulfee0f4c2004-09-13 05:12:46 +00006240bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006241 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006242{
6243 struct bgp_table *table;
6244
6245 if (bgp == NULL) {
6246 bgp = bgp_get_default ();
6247 }
6248
6249 if (bgp == NULL)
6250 {
6251 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6252 return CMD_WARNING;
6253 }
6254
6255
6256 table = bgp->rib[afi][safi];
6257
ajs5a646652004-11-05 01:25:55 +00006258 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006259}
6260
paul718e3742002-12-13 20:15:29 +00006261/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006262static void
paul718e3742002-12-13 20:15:29 +00006263route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6264 struct bgp_node *rn,
6265 struct prefix_rd *prd, afi_t afi, safi_t safi)
6266{
6267 struct bgp_info *ri;
6268 struct prefix *p;
6269 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006270 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006271 char buf1[INET6_ADDRSTRLEN];
6272 char buf2[INET6_ADDRSTRLEN];
6273 int count = 0;
6274 int best = 0;
6275 int suppress = 0;
6276 int no_export = 0;
6277 int no_advertise = 0;
6278 int local_as = 0;
6279 int first = 0;
6280
6281 p = &rn->p;
6282 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6283 (safi == SAFI_MPLS_VPN ?
6284 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6285 safi == SAFI_MPLS_VPN ? ":" : "",
6286 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6287 p->prefixlen, VTY_NEWLINE);
6288
6289 for (ri = rn->info; ri; ri = ri->next)
6290 {
6291 count++;
6292 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6293 {
6294 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006295 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006296 suppress = 1;
6297 if (ri->attr->community != NULL)
6298 {
6299 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6300 no_advertise = 1;
6301 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6302 no_export = 1;
6303 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6304 local_as = 1;
6305 }
6306 }
6307 }
6308
6309 vty_out (vty, "Paths: (%d available", count);
6310 if (best)
6311 {
6312 vty_out (vty, ", best #%d", best);
6313 if (safi == SAFI_UNICAST)
6314 vty_out (vty, ", table Default-IP-Routing-Table");
6315 }
6316 else
6317 vty_out (vty, ", no best path");
6318 if (no_advertise)
6319 vty_out (vty, ", not advertised to any peer");
6320 else if (no_export)
6321 vty_out (vty, ", not advertised to EBGP peer");
6322 else if (local_as)
6323 vty_out (vty, ", not advertised outside local AS");
6324 if (suppress)
6325 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6326 vty_out (vty, ")%s", VTY_NEWLINE);
6327
6328 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006329 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006330 {
6331 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6332 {
6333 if (! first)
6334 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6335 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6336 first = 1;
6337 }
6338 }
6339 if (! first)
6340 vty_out (vty, " Not advertised to any peer");
6341 vty_out (vty, "%s", VTY_NEWLINE);
6342}
6343
6344/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006345static int
paulfee0f4c2004-09-13 05:12:46 +00006346bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006347 struct bgp_table *rib, const char *ip_str,
6348 afi_t afi, safi_t safi, struct prefix_rd *prd,
6349 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006350{
6351 int ret;
6352 int header;
6353 int display = 0;
6354 struct prefix match;
6355 struct bgp_node *rn;
6356 struct bgp_node *rm;
6357 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006358 struct bgp_table *table;
6359
paul718e3742002-12-13 20:15:29 +00006360 /* Check IP address argument. */
6361 ret = str2prefix (ip_str, &match);
6362 if (! ret)
6363 {
6364 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6365 return CMD_WARNING;
6366 }
6367
6368 match.family = afi2family (afi);
6369
6370 if (safi == SAFI_MPLS_VPN)
6371 {
paulfee0f4c2004-09-13 05:12:46 +00006372 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006373 {
6374 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6375 continue;
6376
6377 if ((table = rn->info) != NULL)
6378 {
6379 header = 1;
6380
6381 if ((rm = bgp_node_match (table, &match)) != NULL)
6382 {
6383 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6384 continue;
6385
6386 for (ri = rm->info; ri; ri = ri->next)
6387 {
6388 if (header)
6389 {
6390 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6391 AFI_IP, SAFI_MPLS_VPN);
6392
6393 header = 0;
6394 }
6395 display++;
6396 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6397 }
6398 }
6399 }
6400 }
6401 }
6402 else
6403 {
6404 header = 1;
6405
paulfee0f4c2004-09-13 05:12:46 +00006406 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006407 {
6408 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6409 {
6410 for (ri = rn->info; ri; ri = ri->next)
6411 {
6412 if (header)
6413 {
6414 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6415 header = 0;
6416 }
6417 display++;
6418 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6419 }
6420 }
6421 }
6422 }
6423
6424 if (! display)
6425 {
6426 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6427 return CMD_WARNING;
6428 }
6429
6430 return CMD_SUCCESS;
6431}
6432
paulfee0f4c2004-09-13 05:12:46 +00006433/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006434static int
paulfd79ac92004-10-13 05:06:08 +00006435bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006436 afi_t afi, safi_t safi, struct prefix_rd *prd,
6437 int prefix_check)
6438{
6439 struct bgp *bgp;
6440
6441 /* BGP structure lookup. */
6442 if (view_name)
6443 {
6444 bgp = bgp_lookup_by_name (view_name);
6445 if (bgp == NULL)
6446 {
6447 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6448 return CMD_WARNING;
6449 }
6450 }
6451 else
6452 {
6453 bgp = bgp_get_default ();
6454 if (bgp == NULL)
6455 {
6456 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6457 return CMD_WARNING;
6458 }
6459 }
6460
6461 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6462 afi, safi, prd, prefix_check);
6463}
6464
paul718e3742002-12-13 20:15:29 +00006465/* BGP route print out function. */
6466DEFUN (show_ip_bgp,
6467 show_ip_bgp_cmd,
6468 "show ip bgp",
6469 SHOW_STR
6470 IP_STR
6471 BGP_STR)
6472{
ajs5a646652004-11-05 01:25:55 +00006473 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006474}
6475
6476DEFUN (show_ip_bgp_ipv4,
6477 show_ip_bgp_ipv4_cmd,
6478 "show ip bgp ipv4 (unicast|multicast)",
6479 SHOW_STR
6480 IP_STR
6481 BGP_STR
6482 "Address family\n"
6483 "Address Family modifier\n"
6484 "Address Family modifier\n")
6485{
6486 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006487 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6488 NULL);
paul718e3742002-12-13 20:15:29 +00006489
ajs5a646652004-11-05 01:25:55 +00006490 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006491}
6492
6493DEFUN (show_ip_bgp_route,
6494 show_ip_bgp_route_cmd,
6495 "show ip bgp A.B.C.D",
6496 SHOW_STR
6497 IP_STR
6498 BGP_STR
6499 "Network in the BGP routing table to display\n")
6500{
6501 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6502}
6503
6504DEFUN (show_ip_bgp_ipv4_route,
6505 show_ip_bgp_ipv4_route_cmd,
6506 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6507 SHOW_STR
6508 IP_STR
6509 BGP_STR
6510 "Address family\n"
6511 "Address Family modifier\n"
6512 "Address Family modifier\n"
6513 "Network in the BGP routing table to display\n")
6514{
6515 if (strncmp (argv[0], "m", 1) == 0)
6516 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6517
6518 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6519}
6520
6521DEFUN (show_ip_bgp_vpnv4_all_route,
6522 show_ip_bgp_vpnv4_all_route_cmd,
6523 "show ip bgp vpnv4 all A.B.C.D",
6524 SHOW_STR
6525 IP_STR
6526 BGP_STR
6527 "Display VPNv4 NLRI specific information\n"
6528 "Display information about all VPNv4 NLRIs\n"
6529 "Network in the BGP routing table to display\n")
6530{
6531 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6532}
6533
6534DEFUN (show_ip_bgp_vpnv4_rd_route,
6535 show_ip_bgp_vpnv4_rd_route_cmd,
6536 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6537 SHOW_STR
6538 IP_STR
6539 BGP_STR
6540 "Display VPNv4 NLRI specific information\n"
6541 "Display information for a route distinguisher\n"
6542 "VPN Route Distinguisher\n"
6543 "Network in the BGP routing table to display\n")
6544{
6545 int ret;
6546 struct prefix_rd prd;
6547
6548 ret = str2prefix_rd (argv[0], &prd);
6549 if (! ret)
6550 {
6551 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6552 return CMD_WARNING;
6553 }
6554 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6555}
6556
6557DEFUN (show_ip_bgp_prefix,
6558 show_ip_bgp_prefix_cmd,
6559 "show ip bgp A.B.C.D/M",
6560 SHOW_STR
6561 IP_STR
6562 BGP_STR
6563 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6564{
6565 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6566}
6567
6568DEFUN (show_ip_bgp_ipv4_prefix,
6569 show_ip_bgp_ipv4_prefix_cmd,
6570 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6571 SHOW_STR
6572 IP_STR
6573 BGP_STR
6574 "Address family\n"
6575 "Address Family modifier\n"
6576 "Address Family modifier\n"
6577 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6578{
6579 if (strncmp (argv[0], "m", 1) == 0)
6580 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6581
6582 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6583}
6584
6585DEFUN (show_ip_bgp_vpnv4_all_prefix,
6586 show_ip_bgp_vpnv4_all_prefix_cmd,
6587 "show ip bgp vpnv4 all A.B.C.D/M",
6588 SHOW_STR
6589 IP_STR
6590 BGP_STR
6591 "Display VPNv4 NLRI specific information\n"
6592 "Display information about all VPNv4 NLRIs\n"
6593 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6594{
6595 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6596}
6597
6598DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6599 show_ip_bgp_vpnv4_rd_prefix_cmd,
6600 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6601 SHOW_STR
6602 IP_STR
6603 BGP_STR
6604 "Display VPNv4 NLRI specific information\n"
6605 "Display information for a route distinguisher\n"
6606 "VPN Route Distinguisher\n"
6607 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6608{
6609 int ret;
6610 struct prefix_rd prd;
6611
6612 ret = str2prefix_rd (argv[0], &prd);
6613 if (! ret)
6614 {
6615 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6616 return CMD_WARNING;
6617 }
6618 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6619}
6620
6621DEFUN (show_ip_bgp_view,
6622 show_ip_bgp_view_cmd,
6623 "show ip bgp view WORD",
6624 SHOW_STR
6625 IP_STR
6626 BGP_STR
6627 "BGP view\n"
6628 "BGP view name\n")
6629{
paulbb46e942003-10-24 19:02:03 +00006630 struct bgp *bgp;
6631
6632 /* BGP structure lookup. */
6633 bgp = bgp_lookup_by_name (argv[0]);
6634 if (bgp == NULL)
6635 {
6636 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6637 return CMD_WARNING;
6638 }
6639
ajs5a646652004-11-05 01:25:55 +00006640 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006641}
6642
6643DEFUN (show_ip_bgp_view_route,
6644 show_ip_bgp_view_route_cmd,
6645 "show ip bgp view WORD A.B.C.D",
6646 SHOW_STR
6647 IP_STR
6648 BGP_STR
6649 "BGP view\n"
6650 "BGP view name\n"
6651 "Network in the BGP routing table to display\n")
6652{
6653 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6654}
6655
6656DEFUN (show_ip_bgp_view_prefix,
6657 show_ip_bgp_view_prefix_cmd,
6658 "show ip bgp view WORD A.B.C.D/M",
6659 SHOW_STR
6660 IP_STR
6661 BGP_STR
6662 "BGP view\n"
6663 "BGP view name\n"
6664 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6665{
6666 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6667}
6668
6669#ifdef HAVE_IPV6
6670DEFUN (show_bgp,
6671 show_bgp_cmd,
6672 "show bgp",
6673 SHOW_STR
6674 BGP_STR)
6675{
ajs5a646652004-11-05 01:25:55 +00006676 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6677 NULL);
paul718e3742002-12-13 20:15:29 +00006678}
6679
6680ALIAS (show_bgp,
6681 show_bgp_ipv6_cmd,
6682 "show bgp ipv6",
6683 SHOW_STR
6684 BGP_STR
6685 "Address family\n")
6686
6687/* old command */
6688DEFUN (show_ipv6_bgp,
6689 show_ipv6_bgp_cmd,
6690 "show ipv6 bgp",
6691 SHOW_STR
6692 IP_STR
6693 BGP_STR)
6694{
ajs5a646652004-11-05 01:25:55 +00006695 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6696 NULL);
paul718e3742002-12-13 20:15:29 +00006697}
6698
6699DEFUN (show_bgp_route,
6700 show_bgp_route_cmd,
6701 "show bgp X:X::X:X",
6702 SHOW_STR
6703 BGP_STR
6704 "Network in the BGP routing table to display\n")
6705{
6706 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6707}
6708
6709ALIAS (show_bgp_route,
6710 show_bgp_ipv6_route_cmd,
6711 "show bgp ipv6 X:X::X:X",
6712 SHOW_STR
6713 BGP_STR
6714 "Address family\n"
6715 "Network in the BGP routing table to display\n")
6716
6717/* old command */
6718DEFUN (show_ipv6_bgp_route,
6719 show_ipv6_bgp_route_cmd,
6720 "show ipv6 bgp X:X::X:X",
6721 SHOW_STR
6722 IP_STR
6723 BGP_STR
6724 "Network in the BGP routing table to display\n")
6725{
6726 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6727}
6728
6729DEFUN (show_bgp_prefix,
6730 show_bgp_prefix_cmd,
6731 "show bgp X:X::X:X/M",
6732 SHOW_STR
6733 BGP_STR
6734 "IPv6 prefix <network>/<length>\n")
6735{
6736 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6737}
6738
6739ALIAS (show_bgp_prefix,
6740 show_bgp_ipv6_prefix_cmd,
6741 "show bgp ipv6 X:X::X:X/M",
6742 SHOW_STR
6743 BGP_STR
6744 "Address family\n"
6745 "IPv6 prefix <network>/<length>\n")
6746
6747/* old command */
6748DEFUN (show_ipv6_bgp_prefix,
6749 show_ipv6_bgp_prefix_cmd,
6750 "show ipv6 bgp X:X::X:X/M",
6751 SHOW_STR
6752 IP_STR
6753 BGP_STR
6754 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6755{
6756 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6757}
6758
paulbb46e942003-10-24 19:02:03 +00006759DEFUN (show_bgp_view,
6760 show_bgp_view_cmd,
6761 "show bgp view WORD",
6762 SHOW_STR
6763 BGP_STR
6764 "BGP view\n"
6765 "View name\n")
6766{
6767 struct bgp *bgp;
6768
6769 /* BGP structure lookup. */
6770 bgp = bgp_lookup_by_name (argv[0]);
6771 if (bgp == NULL)
6772 {
6773 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6774 return CMD_WARNING;
6775 }
6776
ajs5a646652004-11-05 01:25:55 +00006777 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006778}
6779
6780ALIAS (show_bgp_view,
6781 show_bgp_view_ipv6_cmd,
6782 "show bgp view WORD ipv6",
6783 SHOW_STR
6784 BGP_STR
6785 "BGP view\n"
6786 "View name\n"
6787 "Address family\n")
6788
6789DEFUN (show_bgp_view_route,
6790 show_bgp_view_route_cmd,
6791 "show bgp view WORD X:X::X:X",
6792 SHOW_STR
6793 BGP_STR
6794 "BGP view\n"
6795 "View name\n"
6796 "Network in the BGP routing table to display\n")
6797{
6798 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6799}
6800
6801ALIAS (show_bgp_view_route,
6802 show_bgp_view_ipv6_route_cmd,
6803 "show bgp view WORD ipv6 X:X::X:X",
6804 SHOW_STR
6805 BGP_STR
6806 "BGP view\n"
6807 "View name\n"
6808 "Address family\n"
6809 "Network in the BGP routing table to display\n")
6810
6811DEFUN (show_bgp_view_prefix,
6812 show_bgp_view_prefix_cmd,
6813 "show bgp view WORD X:X::X:X/M",
6814 SHOW_STR
6815 BGP_STR
6816 "BGP view\n"
6817 "View name\n"
6818 "IPv6 prefix <network>/<length>\n")
6819{
6820 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6821}
6822
6823ALIAS (show_bgp_view_prefix,
6824 show_bgp_view_ipv6_prefix_cmd,
6825 "show bgp view WORD ipv6 X:X::X:X/M",
6826 SHOW_STR
6827 BGP_STR
6828 "BGP view\n"
6829 "View name\n"
6830 "Address family\n"
6831 "IPv6 prefix <network>/<length>\n")
6832
paul718e3742002-12-13 20:15:29 +00006833/* old command */
6834DEFUN (show_ipv6_mbgp,
6835 show_ipv6_mbgp_cmd,
6836 "show ipv6 mbgp",
6837 SHOW_STR
6838 IP_STR
6839 MBGP_STR)
6840{
ajs5a646652004-11-05 01:25:55 +00006841 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6842 NULL);
paul718e3742002-12-13 20:15:29 +00006843}
6844
6845/* old command */
6846DEFUN (show_ipv6_mbgp_route,
6847 show_ipv6_mbgp_route_cmd,
6848 "show ipv6 mbgp X:X::X:X",
6849 SHOW_STR
6850 IP_STR
6851 MBGP_STR
6852 "Network in the MBGP routing table to display\n")
6853{
6854 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6855}
6856
6857/* old command */
6858DEFUN (show_ipv6_mbgp_prefix,
6859 show_ipv6_mbgp_prefix_cmd,
6860 "show ipv6 mbgp X:X::X:X/M",
6861 SHOW_STR
6862 IP_STR
6863 MBGP_STR
6864 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6865{
6866 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6867}
6868#endif
6869
paul718e3742002-12-13 20:15:29 +00006870
paul94f2b392005-06-28 12:44:16 +00006871static int
paulfd79ac92004-10-13 05:06:08 +00006872bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006873 safi_t safi, enum bgp_show_type type)
6874{
6875 int i;
6876 struct buffer *b;
6877 char *regstr;
6878 int first;
6879 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006880 int rc;
paul718e3742002-12-13 20:15:29 +00006881
6882 first = 0;
6883 b = buffer_new (1024);
6884 for (i = 0; i < argc; i++)
6885 {
6886 if (first)
6887 buffer_putc (b, ' ');
6888 else
6889 {
6890 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6891 continue;
6892 first = 1;
6893 }
6894
6895 buffer_putstr (b, argv[i]);
6896 }
6897 buffer_putc (b, '\0');
6898
6899 regstr = buffer_getstr (b);
6900 buffer_free (b);
6901
6902 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006903 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006904 if (! regex)
6905 {
6906 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6907 VTY_NEWLINE);
6908 return CMD_WARNING;
6909 }
6910
ajs5a646652004-11-05 01:25:55 +00006911 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6912 bgp_regex_free (regex);
6913 return rc;
paul718e3742002-12-13 20:15:29 +00006914}
6915
6916DEFUN (show_ip_bgp_regexp,
6917 show_ip_bgp_regexp_cmd,
6918 "show ip bgp regexp .LINE",
6919 SHOW_STR
6920 IP_STR
6921 BGP_STR
6922 "Display routes matching the AS path regular expression\n"
6923 "A regular-expression to match the BGP AS paths\n")
6924{
6925 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6926 bgp_show_type_regexp);
6927}
6928
6929DEFUN (show_ip_bgp_flap_regexp,
6930 show_ip_bgp_flap_regexp_cmd,
6931 "show ip bgp flap-statistics regexp .LINE",
6932 SHOW_STR
6933 IP_STR
6934 BGP_STR
6935 "Display flap statistics of routes\n"
6936 "Display routes matching the AS path regular expression\n"
6937 "A regular-expression to match the BGP AS paths\n")
6938{
6939 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6940 bgp_show_type_flap_regexp);
6941}
6942
6943DEFUN (show_ip_bgp_ipv4_regexp,
6944 show_ip_bgp_ipv4_regexp_cmd,
6945 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6946 SHOW_STR
6947 IP_STR
6948 BGP_STR
6949 "Address family\n"
6950 "Address Family modifier\n"
6951 "Address Family modifier\n"
6952 "Display routes matching the AS path regular expression\n"
6953 "A regular-expression to match the BGP AS paths\n")
6954{
6955 if (strncmp (argv[0], "m", 1) == 0)
6956 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6957 bgp_show_type_regexp);
6958
6959 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6960 bgp_show_type_regexp);
6961}
6962
6963#ifdef HAVE_IPV6
6964DEFUN (show_bgp_regexp,
6965 show_bgp_regexp_cmd,
6966 "show bgp regexp .LINE",
6967 SHOW_STR
6968 BGP_STR
6969 "Display routes matching the AS path regular expression\n"
6970 "A regular-expression to match the BGP AS paths\n")
6971{
6972 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6973 bgp_show_type_regexp);
6974}
6975
6976ALIAS (show_bgp_regexp,
6977 show_bgp_ipv6_regexp_cmd,
6978 "show bgp ipv6 regexp .LINE",
6979 SHOW_STR
6980 BGP_STR
6981 "Address family\n"
6982 "Display routes matching the AS path regular expression\n"
6983 "A regular-expression to match the BGP AS paths\n")
6984
6985/* old command */
6986DEFUN (show_ipv6_bgp_regexp,
6987 show_ipv6_bgp_regexp_cmd,
6988 "show ipv6 bgp regexp .LINE",
6989 SHOW_STR
6990 IP_STR
6991 BGP_STR
6992 "Display routes matching the AS path regular expression\n"
6993 "A regular-expression to match the BGP AS paths\n")
6994{
6995 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6996 bgp_show_type_regexp);
6997}
6998
6999/* old command */
7000DEFUN (show_ipv6_mbgp_regexp,
7001 show_ipv6_mbgp_regexp_cmd,
7002 "show ipv6 mbgp regexp .LINE",
7003 SHOW_STR
7004 IP_STR
7005 BGP_STR
7006 "Display routes matching the AS path regular expression\n"
7007 "A regular-expression to match the MBGP AS paths\n")
7008{
7009 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7010 bgp_show_type_regexp);
7011}
7012#endif /* HAVE_IPV6 */
7013
paul94f2b392005-06-28 12:44:16 +00007014static int
paulfd79ac92004-10-13 05:06:08 +00007015bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007016 safi_t safi, enum bgp_show_type type)
7017{
7018 struct prefix_list *plist;
7019
7020 plist = prefix_list_lookup (afi, prefix_list_str);
7021 if (plist == NULL)
7022 {
7023 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7024 prefix_list_str, VTY_NEWLINE);
7025 return CMD_WARNING;
7026 }
7027
ajs5a646652004-11-05 01:25:55 +00007028 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007029}
7030
7031DEFUN (show_ip_bgp_prefix_list,
7032 show_ip_bgp_prefix_list_cmd,
7033 "show ip bgp prefix-list WORD",
7034 SHOW_STR
7035 IP_STR
7036 BGP_STR
7037 "Display routes conforming to the prefix-list\n"
7038 "IP prefix-list name\n")
7039{
7040 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7041 bgp_show_type_prefix_list);
7042}
7043
7044DEFUN (show_ip_bgp_flap_prefix_list,
7045 show_ip_bgp_flap_prefix_list_cmd,
7046 "show ip bgp flap-statistics prefix-list WORD",
7047 SHOW_STR
7048 IP_STR
7049 BGP_STR
7050 "Display flap statistics of routes\n"
7051 "Display routes conforming to the prefix-list\n"
7052 "IP prefix-list name\n")
7053{
7054 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7055 bgp_show_type_flap_prefix_list);
7056}
7057
7058DEFUN (show_ip_bgp_ipv4_prefix_list,
7059 show_ip_bgp_ipv4_prefix_list_cmd,
7060 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7061 SHOW_STR
7062 IP_STR
7063 BGP_STR
7064 "Address family\n"
7065 "Address Family modifier\n"
7066 "Address Family modifier\n"
7067 "Display routes conforming to the prefix-list\n"
7068 "IP prefix-list name\n")
7069{
7070 if (strncmp (argv[0], "m", 1) == 0)
7071 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7072 bgp_show_type_prefix_list);
7073
7074 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7075 bgp_show_type_prefix_list);
7076}
7077
7078#ifdef HAVE_IPV6
7079DEFUN (show_bgp_prefix_list,
7080 show_bgp_prefix_list_cmd,
7081 "show bgp prefix-list WORD",
7082 SHOW_STR
7083 BGP_STR
7084 "Display routes conforming to the prefix-list\n"
7085 "IPv6 prefix-list name\n")
7086{
7087 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7088 bgp_show_type_prefix_list);
7089}
7090
7091ALIAS (show_bgp_prefix_list,
7092 show_bgp_ipv6_prefix_list_cmd,
7093 "show bgp ipv6 prefix-list WORD",
7094 SHOW_STR
7095 BGP_STR
7096 "Address family\n"
7097 "Display routes conforming to the prefix-list\n"
7098 "IPv6 prefix-list name\n")
7099
7100/* old command */
7101DEFUN (show_ipv6_bgp_prefix_list,
7102 show_ipv6_bgp_prefix_list_cmd,
7103 "show ipv6 bgp prefix-list WORD",
7104 SHOW_STR
7105 IPV6_STR
7106 BGP_STR
7107 "Display routes matching the prefix-list\n"
7108 "IPv6 prefix-list name\n")
7109{
7110 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7111 bgp_show_type_prefix_list);
7112}
7113
7114/* old command */
7115DEFUN (show_ipv6_mbgp_prefix_list,
7116 show_ipv6_mbgp_prefix_list_cmd,
7117 "show ipv6 mbgp prefix-list WORD",
7118 SHOW_STR
7119 IPV6_STR
7120 MBGP_STR
7121 "Display routes matching the prefix-list\n"
7122 "IPv6 prefix-list name\n")
7123{
7124 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7125 bgp_show_type_prefix_list);
7126}
7127#endif /* HAVE_IPV6 */
7128
paul94f2b392005-06-28 12:44:16 +00007129static int
paulfd79ac92004-10-13 05:06:08 +00007130bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007131 safi_t safi, enum bgp_show_type type)
7132{
7133 struct as_list *as_list;
7134
7135 as_list = as_list_lookup (filter);
7136 if (as_list == NULL)
7137 {
7138 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7139 return CMD_WARNING;
7140 }
7141
ajs5a646652004-11-05 01:25:55 +00007142 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007143}
7144
7145DEFUN (show_ip_bgp_filter_list,
7146 show_ip_bgp_filter_list_cmd,
7147 "show ip bgp filter-list WORD",
7148 SHOW_STR
7149 IP_STR
7150 BGP_STR
7151 "Display routes conforming to the filter-list\n"
7152 "Regular expression access list name\n")
7153{
7154 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7155 bgp_show_type_filter_list);
7156}
7157
7158DEFUN (show_ip_bgp_flap_filter_list,
7159 show_ip_bgp_flap_filter_list_cmd,
7160 "show ip bgp flap-statistics filter-list WORD",
7161 SHOW_STR
7162 IP_STR
7163 BGP_STR
7164 "Display flap statistics of routes\n"
7165 "Display routes conforming to the filter-list\n"
7166 "Regular expression access list name\n")
7167{
7168 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7169 bgp_show_type_flap_filter_list);
7170}
7171
7172DEFUN (show_ip_bgp_ipv4_filter_list,
7173 show_ip_bgp_ipv4_filter_list_cmd,
7174 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7175 SHOW_STR
7176 IP_STR
7177 BGP_STR
7178 "Address family\n"
7179 "Address Family modifier\n"
7180 "Address Family modifier\n"
7181 "Display routes conforming to the filter-list\n"
7182 "Regular expression access list name\n")
7183{
7184 if (strncmp (argv[0], "m", 1) == 0)
7185 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7186 bgp_show_type_filter_list);
7187
7188 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7189 bgp_show_type_filter_list);
7190}
7191
7192#ifdef HAVE_IPV6
7193DEFUN (show_bgp_filter_list,
7194 show_bgp_filter_list_cmd,
7195 "show bgp filter-list WORD",
7196 SHOW_STR
7197 BGP_STR
7198 "Display routes conforming to the filter-list\n"
7199 "Regular expression access list name\n")
7200{
7201 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7202 bgp_show_type_filter_list);
7203}
7204
7205ALIAS (show_bgp_filter_list,
7206 show_bgp_ipv6_filter_list_cmd,
7207 "show bgp ipv6 filter-list WORD",
7208 SHOW_STR
7209 BGP_STR
7210 "Address family\n"
7211 "Display routes conforming to the filter-list\n"
7212 "Regular expression access list name\n")
7213
7214/* old command */
7215DEFUN (show_ipv6_bgp_filter_list,
7216 show_ipv6_bgp_filter_list_cmd,
7217 "show ipv6 bgp filter-list WORD",
7218 SHOW_STR
7219 IPV6_STR
7220 BGP_STR
7221 "Display routes conforming to the filter-list\n"
7222 "Regular expression access list name\n")
7223{
7224 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7225 bgp_show_type_filter_list);
7226}
7227
7228/* old command */
7229DEFUN (show_ipv6_mbgp_filter_list,
7230 show_ipv6_mbgp_filter_list_cmd,
7231 "show ipv6 mbgp filter-list WORD",
7232 SHOW_STR
7233 IPV6_STR
7234 MBGP_STR
7235 "Display routes conforming to the filter-list\n"
7236 "Regular expression access list name\n")
7237{
7238 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7239 bgp_show_type_filter_list);
7240}
7241#endif /* HAVE_IPV6 */
7242
paul94f2b392005-06-28 12:44:16 +00007243static int
paulfd79ac92004-10-13 05:06:08 +00007244bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007245 safi_t safi, enum bgp_show_type type)
7246{
7247 struct route_map *rmap;
7248
7249 rmap = route_map_lookup_by_name (rmap_str);
7250 if (! rmap)
7251 {
7252 vty_out (vty, "%% %s is not a valid route-map name%s",
7253 rmap_str, VTY_NEWLINE);
7254 return CMD_WARNING;
7255 }
7256
ajs5a646652004-11-05 01:25:55 +00007257 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007258}
7259
7260DEFUN (show_ip_bgp_route_map,
7261 show_ip_bgp_route_map_cmd,
7262 "show ip bgp route-map WORD",
7263 SHOW_STR
7264 IP_STR
7265 BGP_STR
7266 "Display routes matching the route-map\n"
7267 "A route-map to match on\n")
7268{
7269 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7270 bgp_show_type_route_map);
7271}
7272
7273DEFUN (show_ip_bgp_flap_route_map,
7274 show_ip_bgp_flap_route_map_cmd,
7275 "show ip bgp flap-statistics route-map WORD",
7276 SHOW_STR
7277 IP_STR
7278 BGP_STR
7279 "Display flap statistics of routes\n"
7280 "Display routes matching the route-map\n"
7281 "A route-map to match on\n")
7282{
7283 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7284 bgp_show_type_flap_route_map);
7285}
7286
7287DEFUN (show_ip_bgp_ipv4_route_map,
7288 show_ip_bgp_ipv4_route_map_cmd,
7289 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7290 SHOW_STR
7291 IP_STR
7292 BGP_STR
7293 "Address family\n"
7294 "Address Family modifier\n"
7295 "Address Family modifier\n"
7296 "Display routes matching the route-map\n"
7297 "A route-map to match on\n")
7298{
7299 if (strncmp (argv[0], "m", 1) == 0)
7300 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7301 bgp_show_type_route_map);
7302
7303 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7304 bgp_show_type_route_map);
7305}
7306
7307DEFUN (show_bgp_route_map,
7308 show_bgp_route_map_cmd,
7309 "show bgp route-map WORD",
7310 SHOW_STR
7311 BGP_STR
7312 "Display routes matching the route-map\n"
7313 "A route-map to match on\n")
7314{
7315 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7316 bgp_show_type_route_map);
7317}
7318
7319ALIAS (show_bgp_route_map,
7320 show_bgp_ipv6_route_map_cmd,
7321 "show bgp ipv6 route-map WORD",
7322 SHOW_STR
7323 BGP_STR
7324 "Address family\n"
7325 "Display routes matching the route-map\n"
7326 "A route-map to match on\n")
7327
7328DEFUN (show_ip_bgp_cidr_only,
7329 show_ip_bgp_cidr_only_cmd,
7330 "show ip bgp cidr-only",
7331 SHOW_STR
7332 IP_STR
7333 BGP_STR
7334 "Display only routes with non-natural netmasks\n")
7335{
7336 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007337 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007338}
7339
7340DEFUN (show_ip_bgp_flap_cidr_only,
7341 show_ip_bgp_flap_cidr_only_cmd,
7342 "show ip bgp flap-statistics cidr-only",
7343 SHOW_STR
7344 IP_STR
7345 BGP_STR
7346 "Display flap statistics of routes\n"
7347 "Display only routes with non-natural netmasks\n")
7348{
7349 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007350 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007351}
7352
7353DEFUN (show_ip_bgp_ipv4_cidr_only,
7354 show_ip_bgp_ipv4_cidr_only_cmd,
7355 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7356 SHOW_STR
7357 IP_STR
7358 BGP_STR
7359 "Address family\n"
7360 "Address Family modifier\n"
7361 "Address Family modifier\n"
7362 "Display only routes with non-natural netmasks\n")
7363{
7364 if (strncmp (argv[0], "m", 1) == 0)
7365 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007366 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007367
7368 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007369 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007370}
7371
7372DEFUN (show_ip_bgp_community_all,
7373 show_ip_bgp_community_all_cmd,
7374 "show ip bgp community",
7375 SHOW_STR
7376 IP_STR
7377 BGP_STR
7378 "Display routes matching the communities\n")
7379{
7380 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007381 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007382}
7383
7384DEFUN (show_ip_bgp_ipv4_community_all,
7385 show_ip_bgp_ipv4_community_all_cmd,
7386 "show ip bgp ipv4 (unicast|multicast) community",
7387 SHOW_STR
7388 IP_STR
7389 BGP_STR
7390 "Address family\n"
7391 "Address Family modifier\n"
7392 "Address Family modifier\n"
7393 "Display routes matching the communities\n")
7394{
7395 if (strncmp (argv[0], "m", 1) == 0)
7396 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007397 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007398
7399 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007400 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007401}
7402
7403#ifdef HAVE_IPV6
7404DEFUN (show_bgp_community_all,
7405 show_bgp_community_all_cmd,
7406 "show bgp community",
7407 SHOW_STR
7408 BGP_STR
7409 "Display routes matching the communities\n")
7410{
7411 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007412 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007413}
7414
7415ALIAS (show_bgp_community_all,
7416 show_bgp_ipv6_community_all_cmd,
7417 "show bgp ipv6 community",
7418 SHOW_STR
7419 BGP_STR
7420 "Address family\n"
7421 "Display routes matching the communities\n")
7422
7423/* old command */
7424DEFUN (show_ipv6_bgp_community_all,
7425 show_ipv6_bgp_community_all_cmd,
7426 "show ipv6 bgp community",
7427 SHOW_STR
7428 IPV6_STR
7429 BGP_STR
7430 "Display routes matching the communities\n")
7431{
7432 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007433 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007434}
7435
7436/* old command */
7437DEFUN (show_ipv6_mbgp_community_all,
7438 show_ipv6_mbgp_community_all_cmd,
7439 "show ipv6 mbgp community",
7440 SHOW_STR
7441 IPV6_STR
7442 MBGP_STR
7443 "Display routes matching the communities\n")
7444{
7445 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007446 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007447}
7448#endif /* HAVE_IPV6 */
7449
paul94f2b392005-06-28 12:44:16 +00007450static int
paulfd79ac92004-10-13 05:06:08 +00007451bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04007452 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007453{
7454 struct community *com;
7455 struct buffer *b;
7456 int i;
7457 char *str;
7458 int first = 0;
7459
7460 b = buffer_new (1024);
7461 for (i = 0; i < argc; i++)
7462 {
7463 if (first)
7464 buffer_putc (b, ' ');
7465 else
7466 {
7467 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7468 continue;
7469 first = 1;
7470 }
7471
7472 buffer_putstr (b, argv[i]);
7473 }
7474 buffer_putc (b, '\0');
7475
7476 str = buffer_getstr (b);
7477 buffer_free (b);
7478
7479 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007480 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007481 if (! com)
7482 {
7483 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7484 return CMD_WARNING;
7485 }
7486
ajs5a646652004-11-05 01:25:55 +00007487 return bgp_show (vty, NULL, afi, safi,
7488 (exact ? bgp_show_type_community_exact :
7489 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007490}
7491
7492DEFUN (show_ip_bgp_community,
7493 show_ip_bgp_community_cmd,
7494 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7495 SHOW_STR
7496 IP_STR
7497 BGP_STR
7498 "Display routes matching the communities\n"
7499 "community number\n"
7500 "Do not send outside local AS (well-known community)\n"
7501 "Do not advertise to any peer (well-known community)\n"
7502 "Do not export to next AS (well-known community)\n")
7503{
7504 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7505}
7506
7507ALIAS (show_ip_bgp_community,
7508 show_ip_bgp_community2_cmd,
7509 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7510 SHOW_STR
7511 IP_STR
7512 BGP_STR
7513 "Display routes matching the communities\n"
7514 "community number\n"
7515 "Do not send outside local AS (well-known community)\n"
7516 "Do not advertise to any peer (well-known community)\n"
7517 "Do not export to next AS (well-known community)\n"
7518 "community number\n"
7519 "Do not send outside local AS (well-known community)\n"
7520 "Do not advertise to any peer (well-known community)\n"
7521 "Do not export to next AS (well-known community)\n")
7522
7523ALIAS (show_ip_bgp_community,
7524 show_ip_bgp_community3_cmd,
7525 "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)",
7526 SHOW_STR
7527 IP_STR
7528 BGP_STR
7529 "Display routes matching the communities\n"
7530 "community number\n"
7531 "Do not send outside local AS (well-known community)\n"
7532 "Do not advertise to any peer (well-known community)\n"
7533 "Do not export to next AS (well-known community)\n"
7534 "community number\n"
7535 "Do not send outside local AS (well-known community)\n"
7536 "Do not advertise to any peer (well-known community)\n"
7537 "Do not export to next AS (well-known community)\n"
7538 "community number\n"
7539 "Do not send outside local AS (well-known community)\n"
7540 "Do not advertise to any peer (well-known community)\n"
7541 "Do not export to next AS (well-known community)\n")
7542
7543ALIAS (show_ip_bgp_community,
7544 show_ip_bgp_community4_cmd,
7545 "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)",
7546 SHOW_STR
7547 IP_STR
7548 BGP_STR
7549 "Display routes matching the communities\n"
7550 "community number\n"
7551 "Do not send outside local AS (well-known community)\n"
7552 "Do not advertise to any peer (well-known community)\n"
7553 "Do not export to next AS (well-known community)\n"
7554 "community number\n"
7555 "Do not send outside local AS (well-known community)\n"
7556 "Do not advertise to any peer (well-known community)\n"
7557 "Do not export to next AS (well-known community)\n"
7558 "community number\n"
7559 "Do not send outside local AS (well-known community)\n"
7560 "Do not advertise to any peer (well-known community)\n"
7561 "Do not export to next AS (well-known community)\n"
7562 "community number\n"
7563 "Do not send outside local AS (well-known community)\n"
7564 "Do not advertise to any peer (well-known community)\n"
7565 "Do not export to next AS (well-known community)\n")
7566
7567DEFUN (show_ip_bgp_ipv4_community,
7568 show_ip_bgp_ipv4_community_cmd,
7569 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7570 SHOW_STR
7571 IP_STR
7572 BGP_STR
7573 "Address family\n"
7574 "Address Family modifier\n"
7575 "Address Family modifier\n"
7576 "Display routes matching the communities\n"
7577 "community number\n"
7578 "Do not send outside local AS (well-known community)\n"
7579 "Do not advertise to any peer (well-known community)\n"
7580 "Do not export to next AS (well-known community)\n")
7581{
7582 if (strncmp (argv[0], "m", 1) == 0)
7583 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7584
7585 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7586}
7587
7588ALIAS (show_ip_bgp_ipv4_community,
7589 show_ip_bgp_ipv4_community2_cmd,
7590 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7591 SHOW_STR
7592 IP_STR
7593 BGP_STR
7594 "Address family\n"
7595 "Address Family modifier\n"
7596 "Address Family modifier\n"
7597 "Display routes matching the communities\n"
7598 "community number\n"
7599 "Do not send outside local AS (well-known community)\n"
7600 "Do not advertise to any peer (well-known community)\n"
7601 "Do not export to next AS (well-known community)\n"
7602 "community number\n"
7603 "Do not send outside local AS (well-known community)\n"
7604 "Do not advertise to any peer (well-known community)\n"
7605 "Do not export to next AS (well-known community)\n")
7606
7607ALIAS (show_ip_bgp_ipv4_community,
7608 show_ip_bgp_ipv4_community3_cmd,
7609 "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)",
7610 SHOW_STR
7611 IP_STR
7612 BGP_STR
7613 "Address family\n"
7614 "Address Family modifier\n"
7615 "Address Family modifier\n"
7616 "Display routes matching the communities\n"
7617 "community number\n"
7618 "Do not send outside local AS (well-known community)\n"
7619 "Do not advertise to any peer (well-known community)\n"
7620 "Do not export to next AS (well-known community)\n"
7621 "community number\n"
7622 "Do not send outside local AS (well-known community)\n"
7623 "Do not advertise to any peer (well-known community)\n"
7624 "Do not export to next AS (well-known community)\n"
7625 "community number\n"
7626 "Do not send outside local AS (well-known community)\n"
7627 "Do not advertise to any peer (well-known community)\n"
7628 "Do not export to next AS (well-known community)\n")
7629
7630ALIAS (show_ip_bgp_ipv4_community,
7631 show_ip_bgp_ipv4_community4_cmd,
7632 "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)",
7633 SHOW_STR
7634 IP_STR
7635 BGP_STR
7636 "Address family\n"
7637 "Address Family modifier\n"
7638 "Address Family modifier\n"
7639 "Display routes matching the communities\n"
7640 "community number\n"
7641 "Do not send outside local AS (well-known community)\n"
7642 "Do not advertise to any peer (well-known community)\n"
7643 "Do not export to next AS (well-known community)\n"
7644 "community number\n"
7645 "Do not send outside local AS (well-known community)\n"
7646 "Do not advertise to any peer (well-known community)\n"
7647 "Do not export to next AS (well-known community)\n"
7648 "community number\n"
7649 "Do not send outside local AS (well-known community)\n"
7650 "Do not advertise to any peer (well-known community)\n"
7651 "Do not export to next AS (well-known community)\n"
7652 "community number\n"
7653 "Do not send outside local AS (well-known community)\n"
7654 "Do not advertise to any peer (well-known community)\n"
7655 "Do not export to next AS (well-known community)\n")
7656
7657DEFUN (show_ip_bgp_community_exact,
7658 show_ip_bgp_community_exact_cmd,
7659 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7660 SHOW_STR
7661 IP_STR
7662 BGP_STR
7663 "Display routes matching the communities\n"
7664 "community number\n"
7665 "Do not send outside local AS (well-known community)\n"
7666 "Do not advertise to any peer (well-known community)\n"
7667 "Do not export to next AS (well-known community)\n"
7668 "Exact match of the communities")
7669{
7670 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7671}
7672
7673ALIAS (show_ip_bgp_community_exact,
7674 show_ip_bgp_community2_exact_cmd,
7675 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7676 SHOW_STR
7677 IP_STR
7678 BGP_STR
7679 "Display routes matching the communities\n"
7680 "community number\n"
7681 "Do not send outside local AS (well-known community)\n"
7682 "Do not advertise to any peer (well-known community)\n"
7683 "Do not export to next AS (well-known community)\n"
7684 "community number\n"
7685 "Do not send outside local AS (well-known community)\n"
7686 "Do not advertise to any peer (well-known community)\n"
7687 "Do not export to next AS (well-known community)\n"
7688 "Exact match of the communities")
7689
7690ALIAS (show_ip_bgp_community_exact,
7691 show_ip_bgp_community3_exact_cmd,
7692 "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",
7693 SHOW_STR
7694 IP_STR
7695 BGP_STR
7696 "Display routes matching the communities\n"
7697 "community number\n"
7698 "Do not send outside local AS (well-known community)\n"
7699 "Do not advertise to any peer (well-known community)\n"
7700 "Do not export to next AS (well-known community)\n"
7701 "community number\n"
7702 "Do not send outside local AS (well-known community)\n"
7703 "Do not advertise to any peer (well-known community)\n"
7704 "Do not export to next AS (well-known community)\n"
7705 "community number\n"
7706 "Do not send outside local AS (well-known community)\n"
7707 "Do not advertise to any peer (well-known community)\n"
7708 "Do not export to next AS (well-known community)\n"
7709 "Exact match of the communities")
7710
7711ALIAS (show_ip_bgp_community_exact,
7712 show_ip_bgp_community4_exact_cmd,
7713 "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",
7714 SHOW_STR
7715 IP_STR
7716 BGP_STR
7717 "Display routes matching the communities\n"
7718 "community number\n"
7719 "Do not send outside local AS (well-known community)\n"
7720 "Do not advertise to any peer (well-known community)\n"
7721 "Do not export to next AS (well-known community)\n"
7722 "community number\n"
7723 "Do not send outside local AS (well-known community)\n"
7724 "Do not advertise to any peer (well-known community)\n"
7725 "Do not export to next AS (well-known community)\n"
7726 "community number\n"
7727 "Do not send outside local AS (well-known community)\n"
7728 "Do not advertise to any peer (well-known community)\n"
7729 "Do not export to next AS (well-known community)\n"
7730 "community number\n"
7731 "Do not send outside local AS (well-known community)\n"
7732 "Do not advertise to any peer (well-known community)\n"
7733 "Do not export to next AS (well-known community)\n"
7734 "Exact match of the communities")
7735
7736DEFUN (show_ip_bgp_ipv4_community_exact,
7737 show_ip_bgp_ipv4_community_exact_cmd,
7738 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7739 SHOW_STR
7740 IP_STR
7741 BGP_STR
7742 "Address family\n"
7743 "Address Family modifier\n"
7744 "Address Family modifier\n"
7745 "Display routes matching the communities\n"
7746 "community number\n"
7747 "Do not send outside local AS (well-known community)\n"
7748 "Do not advertise to any peer (well-known community)\n"
7749 "Do not export to next AS (well-known community)\n"
7750 "Exact match of the communities")
7751{
7752 if (strncmp (argv[0], "m", 1) == 0)
7753 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7754
7755 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7756}
7757
7758ALIAS (show_ip_bgp_ipv4_community_exact,
7759 show_ip_bgp_ipv4_community2_exact_cmd,
7760 "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",
7761 SHOW_STR
7762 IP_STR
7763 BGP_STR
7764 "Address family\n"
7765 "Address Family modifier\n"
7766 "Address Family modifier\n"
7767 "Display routes matching the communities\n"
7768 "community number\n"
7769 "Do not send outside local AS (well-known community)\n"
7770 "Do not advertise to any peer (well-known community)\n"
7771 "Do not export to next AS (well-known community)\n"
7772 "community number\n"
7773 "Do not send outside local AS (well-known community)\n"
7774 "Do not advertise to any peer (well-known community)\n"
7775 "Do not export to next AS (well-known community)\n"
7776 "Exact match of the communities")
7777
7778ALIAS (show_ip_bgp_ipv4_community_exact,
7779 show_ip_bgp_ipv4_community3_exact_cmd,
7780 "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",
7781 SHOW_STR
7782 IP_STR
7783 BGP_STR
7784 "Address family\n"
7785 "Address Family modifier\n"
7786 "Address Family modifier\n"
7787 "Display routes matching the communities\n"
7788 "community number\n"
7789 "Do not send outside local AS (well-known community)\n"
7790 "Do not advertise to any peer (well-known community)\n"
7791 "Do not export to next AS (well-known community)\n"
7792 "community number\n"
7793 "Do not send outside local AS (well-known community)\n"
7794 "Do not advertise to any peer (well-known community)\n"
7795 "Do not export to next AS (well-known community)\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n"
7800 "Exact match of the communities")
7801
7802ALIAS (show_ip_bgp_ipv4_community_exact,
7803 show_ip_bgp_ipv4_community4_exact_cmd,
7804 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7805 SHOW_STR
7806 IP_STR
7807 BGP_STR
7808 "Address family\n"
7809 "Address Family modifier\n"
7810 "Address Family modifier\n"
7811 "Display routes matching the communities\n"
7812 "community number\n"
7813 "Do not send outside local AS (well-known community)\n"
7814 "Do not advertise to any peer (well-known community)\n"
7815 "Do not export to next AS (well-known community)\n"
7816 "community number\n"
7817 "Do not send outside local AS (well-known community)\n"
7818 "Do not advertise to any peer (well-known community)\n"
7819 "Do not export to next AS (well-known community)\n"
7820 "community number\n"
7821 "Do not send outside local AS (well-known community)\n"
7822 "Do not advertise to any peer (well-known community)\n"
7823 "Do not export to next AS (well-known community)\n"
7824 "community number\n"
7825 "Do not send outside local AS (well-known community)\n"
7826 "Do not advertise to any peer (well-known community)\n"
7827 "Do not export to next AS (well-known community)\n"
7828 "Exact match of the communities")
7829
7830#ifdef HAVE_IPV6
7831DEFUN (show_bgp_community,
7832 show_bgp_community_cmd,
7833 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7834 SHOW_STR
7835 BGP_STR
7836 "Display routes matching the communities\n"
7837 "community number\n"
7838 "Do not send outside local AS (well-known community)\n"
7839 "Do not advertise to any peer (well-known community)\n"
7840 "Do not export to next AS (well-known community)\n")
7841{
7842 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7843}
7844
7845ALIAS (show_bgp_community,
7846 show_bgp_ipv6_community_cmd,
7847 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7848 SHOW_STR
7849 BGP_STR
7850 "Address family\n"
7851 "Display routes matching the communities\n"
7852 "community number\n"
7853 "Do not send outside local AS (well-known community)\n"
7854 "Do not advertise to any peer (well-known community)\n"
7855 "Do not export to next AS (well-known community)\n")
7856
7857ALIAS (show_bgp_community,
7858 show_bgp_community2_cmd,
7859 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7860 SHOW_STR
7861 BGP_STR
7862 "Display routes matching the communities\n"
7863 "community number\n"
7864 "Do not send outside local AS (well-known community)\n"
7865 "Do not advertise to any peer (well-known community)\n"
7866 "Do not export to next AS (well-known community)\n"
7867 "community number\n"
7868 "Do not send outside local AS (well-known community)\n"
7869 "Do not advertise to any peer (well-known community)\n"
7870 "Do not export to next AS (well-known community)\n")
7871
7872ALIAS (show_bgp_community,
7873 show_bgp_ipv6_community2_cmd,
7874 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7875 SHOW_STR
7876 BGP_STR
7877 "Address family\n"
7878 "Display routes matching the communities\n"
7879 "community number\n"
7880 "Do not send outside local AS (well-known community)\n"
7881 "Do not advertise to any peer (well-known community)\n"
7882 "Do not export to next AS (well-known community)\n"
7883 "community number\n"
7884 "Do not send outside local AS (well-known community)\n"
7885 "Do not advertise to any peer (well-known community)\n"
7886 "Do not export to next AS (well-known community)\n")
7887
7888ALIAS (show_bgp_community,
7889 show_bgp_community3_cmd,
7890 "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)",
7891 SHOW_STR
7892 BGP_STR
7893 "Display routes matching the communities\n"
7894 "community number\n"
7895 "Do not send outside local AS (well-known community)\n"
7896 "Do not advertise to any peer (well-known community)\n"
7897 "Do not export to next AS (well-known community)\n"
7898 "community number\n"
7899 "Do not send outside local AS (well-known community)\n"
7900 "Do not advertise to any peer (well-known community)\n"
7901 "Do not export to next AS (well-known community)\n"
7902 "community number\n"
7903 "Do not send outside local AS (well-known community)\n"
7904 "Do not advertise to any peer (well-known community)\n"
7905 "Do not export to next AS (well-known community)\n")
7906
7907ALIAS (show_bgp_community,
7908 show_bgp_ipv6_community3_cmd,
7909 "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)",
7910 SHOW_STR
7911 BGP_STR
7912 "Address family\n"
7913 "Display routes matching the communities\n"
7914 "community number\n"
7915 "Do not send outside local AS (well-known community)\n"
7916 "Do not advertise to any peer (well-known community)\n"
7917 "Do not export to next AS (well-known community)\n"
7918 "community number\n"
7919 "Do not send outside local AS (well-known community)\n"
7920 "Do not advertise to any peer (well-known community)\n"
7921 "Do not export to next AS (well-known community)\n"
7922 "community number\n"
7923 "Do not send outside local AS (well-known community)\n"
7924 "Do not advertise to any peer (well-known community)\n"
7925 "Do not export to next AS (well-known community)\n")
7926
7927ALIAS (show_bgp_community,
7928 show_bgp_community4_cmd,
7929 "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)",
7930 SHOW_STR
7931 BGP_STR
7932 "Display routes matching the communities\n"
7933 "community number\n"
7934 "Do not send outside local AS (well-known community)\n"
7935 "Do not advertise to any peer (well-known community)\n"
7936 "Do not export to next AS (well-known community)\n"
7937 "community number\n"
7938 "Do not send outside local AS (well-known community)\n"
7939 "Do not advertise to any peer (well-known community)\n"
7940 "Do not export to next AS (well-known community)\n"
7941 "community number\n"
7942 "Do not send outside local AS (well-known community)\n"
7943 "Do not advertise to any peer (well-known community)\n"
7944 "Do not export to next AS (well-known community)\n"
7945 "community number\n"
7946 "Do not send outside local AS (well-known community)\n"
7947 "Do not advertise to any peer (well-known community)\n"
7948 "Do not export to next AS (well-known community)\n")
7949
7950ALIAS (show_bgp_community,
7951 show_bgp_ipv6_community4_cmd,
7952 "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)",
7953 SHOW_STR
7954 BGP_STR
7955 "Address family\n"
7956 "Display routes matching the communities\n"
7957 "community number\n"
7958 "Do not send outside local AS (well-known community)\n"
7959 "Do not advertise to any peer (well-known community)\n"
7960 "Do not export to next AS (well-known community)\n"
7961 "community number\n"
7962 "Do not send outside local AS (well-known community)\n"
7963 "Do not advertise to any peer (well-known community)\n"
7964 "Do not export to next AS (well-known community)\n"
7965 "community number\n"
7966 "Do not send outside local AS (well-known community)\n"
7967 "Do not advertise to any peer (well-known community)\n"
7968 "Do not export to next AS (well-known community)\n"
7969 "community number\n"
7970 "Do not send outside local AS (well-known community)\n"
7971 "Do not advertise to any peer (well-known community)\n"
7972 "Do not export to next AS (well-known community)\n")
7973
7974/* old command */
7975DEFUN (show_ipv6_bgp_community,
7976 show_ipv6_bgp_community_cmd,
7977 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7978 SHOW_STR
7979 IPV6_STR
7980 BGP_STR
7981 "Display routes matching the communities\n"
7982 "community number\n"
7983 "Do not send outside local AS (well-known community)\n"
7984 "Do not advertise to any peer (well-known community)\n"
7985 "Do not export to next AS (well-known community)\n")
7986{
7987 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7988}
7989
7990/* old command */
7991ALIAS (show_ipv6_bgp_community,
7992 show_ipv6_bgp_community2_cmd,
7993 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7994 SHOW_STR
7995 IPV6_STR
7996 BGP_STR
7997 "Display routes matching the communities\n"
7998 "community number\n"
7999 "Do not send outside local AS (well-known community)\n"
8000 "Do not advertise to any peer (well-known community)\n"
8001 "Do not export to next AS (well-known community)\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n")
8006
8007/* old command */
8008ALIAS (show_ipv6_bgp_community,
8009 show_ipv6_bgp_community3_cmd,
8010 "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)",
8011 SHOW_STR
8012 IPV6_STR
8013 BGP_STR
8014 "Display routes matching the communities\n"
8015 "community number\n"
8016 "Do not send outside local AS (well-known community)\n"
8017 "Do not advertise to any peer (well-known community)\n"
8018 "Do not export to next AS (well-known community)\n"
8019 "community number\n"
8020 "Do not send outside local AS (well-known community)\n"
8021 "Do not advertise to any peer (well-known community)\n"
8022 "Do not export to next AS (well-known community)\n"
8023 "community number\n"
8024 "Do not send outside local AS (well-known community)\n"
8025 "Do not advertise to any peer (well-known community)\n"
8026 "Do not export to next AS (well-known community)\n")
8027
8028/* old command */
8029ALIAS (show_ipv6_bgp_community,
8030 show_ipv6_bgp_community4_cmd,
8031 "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)",
8032 SHOW_STR
8033 IPV6_STR
8034 BGP_STR
8035 "Display routes matching the communities\n"
8036 "community number\n"
8037 "Do not send outside local AS (well-known community)\n"
8038 "Do not advertise to any peer (well-known community)\n"
8039 "Do not export to next AS (well-known community)\n"
8040 "community number\n"
8041 "Do not send outside local AS (well-known community)\n"
8042 "Do not advertise to any peer (well-known community)\n"
8043 "Do not export to next AS (well-known community)\n"
8044 "community number\n"
8045 "Do not send outside local AS (well-known community)\n"
8046 "Do not advertise to any peer (well-known community)\n"
8047 "Do not export to next AS (well-known community)\n"
8048 "community number\n"
8049 "Do not send outside local AS (well-known community)\n"
8050 "Do not advertise to any peer (well-known community)\n"
8051 "Do not export to next AS (well-known community)\n")
8052
8053DEFUN (show_bgp_community_exact,
8054 show_bgp_community_exact_cmd,
8055 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8056 SHOW_STR
8057 BGP_STR
8058 "Display routes matching the communities\n"
8059 "community number\n"
8060 "Do not send outside local AS (well-known community)\n"
8061 "Do not advertise to any peer (well-known community)\n"
8062 "Do not export to next AS (well-known community)\n"
8063 "Exact match of the communities")
8064{
8065 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8066}
8067
8068ALIAS (show_bgp_community_exact,
8069 show_bgp_ipv6_community_exact_cmd,
8070 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8071 SHOW_STR
8072 BGP_STR
8073 "Address family\n"
8074 "Display routes matching the communities\n"
8075 "community number\n"
8076 "Do not send outside local AS (well-known community)\n"
8077 "Do not advertise to any peer (well-known community)\n"
8078 "Do not export to next AS (well-known community)\n"
8079 "Exact match of the communities")
8080
8081ALIAS (show_bgp_community_exact,
8082 show_bgp_community2_exact_cmd,
8083 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8084 SHOW_STR
8085 BGP_STR
8086 "Display routes matching the communities\n"
8087 "community number\n"
8088 "Do not send outside local AS (well-known community)\n"
8089 "Do not advertise to any peer (well-known community)\n"
8090 "Do not export to next AS (well-known community)\n"
8091 "community number\n"
8092 "Do not send outside local AS (well-known community)\n"
8093 "Do not advertise to any peer (well-known community)\n"
8094 "Do not export to next AS (well-known community)\n"
8095 "Exact match of the communities")
8096
8097ALIAS (show_bgp_community_exact,
8098 show_bgp_ipv6_community2_exact_cmd,
8099 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8100 SHOW_STR
8101 BGP_STR
8102 "Address family\n"
8103 "Display routes matching the communities\n"
8104 "community number\n"
8105 "Do not send outside local AS (well-known community)\n"
8106 "Do not advertise to any peer (well-known community)\n"
8107 "Do not export to next AS (well-known community)\n"
8108 "community number\n"
8109 "Do not send outside local AS (well-known community)\n"
8110 "Do not advertise to any peer (well-known community)\n"
8111 "Do not export to next AS (well-known community)\n"
8112 "Exact match of the communities")
8113
8114ALIAS (show_bgp_community_exact,
8115 show_bgp_community3_exact_cmd,
8116 "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",
8117 SHOW_STR
8118 BGP_STR
8119 "Display routes matching the communities\n"
8120 "community number\n"
8121 "Do not send outside local AS (well-known community)\n"
8122 "Do not advertise to any peer (well-known community)\n"
8123 "Do not export to next AS (well-known community)\n"
8124 "community number\n"
8125 "Do not send outside local AS (well-known community)\n"
8126 "Do not advertise to any peer (well-known community)\n"
8127 "Do not export to next AS (well-known community)\n"
8128 "community number\n"
8129 "Do not send outside local AS (well-known community)\n"
8130 "Do not advertise to any peer (well-known community)\n"
8131 "Do not export to next AS (well-known community)\n"
8132 "Exact match of the communities")
8133
8134ALIAS (show_bgp_community_exact,
8135 show_bgp_ipv6_community3_exact_cmd,
8136 "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",
8137 SHOW_STR
8138 BGP_STR
8139 "Address family\n"
8140 "Display routes matching the communities\n"
8141 "community number\n"
8142 "Do not send outside local AS (well-known community)\n"
8143 "Do not advertise to any peer (well-known community)\n"
8144 "Do not export to next AS (well-known community)\n"
8145 "community number\n"
8146 "Do not send outside local AS (well-known community)\n"
8147 "Do not advertise to any peer (well-known community)\n"
8148 "Do not export to next AS (well-known community)\n"
8149 "community number\n"
8150 "Do not send outside local AS (well-known community)\n"
8151 "Do not advertise to any peer (well-known community)\n"
8152 "Do not export to next AS (well-known community)\n"
8153 "Exact match of the communities")
8154
8155ALIAS (show_bgp_community_exact,
8156 show_bgp_community4_exact_cmd,
8157 "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",
8158 SHOW_STR
8159 BGP_STR
8160 "Display routes matching the communities\n"
8161 "community number\n"
8162 "Do not send outside local AS (well-known community)\n"
8163 "Do not advertise to any peer (well-known community)\n"
8164 "Do not export to next AS (well-known community)\n"
8165 "community number\n"
8166 "Do not send outside local AS (well-known community)\n"
8167 "Do not advertise to any peer (well-known community)\n"
8168 "Do not export to next AS (well-known community)\n"
8169 "community number\n"
8170 "Do not send outside local AS (well-known community)\n"
8171 "Do not advertise to any peer (well-known community)\n"
8172 "Do not export to next AS (well-known community)\n"
8173 "community number\n"
8174 "Do not send outside local AS (well-known community)\n"
8175 "Do not advertise to any peer (well-known community)\n"
8176 "Do not export to next AS (well-known community)\n"
8177 "Exact match of the communities")
8178
8179ALIAS (show_bgp_community_exact,
8180 show_bgp_ipv6_community4_exact_cmd,
8181 "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",
8182 SHOW_STR
8183 BGP_STR
8184 "Address family\n"
8185 "Display routes matching the communities\n"
8186 "community number\n"
8187 "Do not send outside local AS (well-known community)\n"
8188 "Do not advertise to any peer (well-known community)\n"
8189 "Do not export to next AS (well-known community)\n"
8190 "community number\n"
8191 "Do not send outside local AS (well-known community)\n"
8192 "Do not advertise to any peer (well-known community)\n"
8193 "Do not export to next AS (well-known community)\n"
8194 "community number\n"
8195 "Do not send outside local AS (well-known community)\n"
8196 "Do not advertise to any peer (well-known community)\n"
8197 "Do not export to next AS (well-known community)\n"
8198 "community number\n"
8199 "Do not send outside local AS (well-known community)\n"
8200 "Do not advertise to any peer (well-known community)\n"
8201 "Do not export to next AS (well-known community)\n"
8202 "Exact match of the communities")
8203
8204/* old command */
8205DEFUN (show_ipv6_bgp_community_exact,
8206 show_ipv6_bgp_community_exact_cmd,
8207 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8208 SHOW_STR
8209 IPV6_STR
8210 BGP_STR
8211 "Display routes matching the communities\n"
8212 "community number\n"
8213 "Do not send outside local AS (well-known community)\n"
8214 "Do not advertise to any peer (well-known community)\n"
8215 "Do not export to next AS (well-known community)\n"
8216 "Exact match of the communities")
8217{
8218 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8219}
8220
8221/* old command */
8222ALIAS (show_ipv6_bgp_community_exact,
8223 show_ipv6_bgp_community2_exact_cmd,
8224 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8225 SHOW_STR
8226 IPV6_STR
8227 BGP_STR
8228 "Display routes matching the communities\n"
8229 "community number\n"
8230 "Do not send outside local AS (well-known community)\n"
8231 "Do not advertise to any peer (well-known community)\n"
8232 "Do not export to next AS (well-known community)\n"
8233 "community number\n"
8234 "Do not send outside local AS (well-known community)\n"
8235 "Do not advertise to any peer (well-known community)\n"
8236 "Do not export to next AS (well-known community)\n"
8237 "Exact match of the communities")
8238
8239/* old command */
8240ALIAS (show_ipv6_bgp_community_exact,
8241 show_ipv6_bgp_community3_exact_cmd,
8242 "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",
8243 SHOW_STR
8244 IPV6_STR
8245 BGP_STR
8246 "Display routes matching the communities\n"
8247 "community number\n"
8248 "Do not send outside local AS (well-known community)\n"
8249 "Do not advertise to any peer (well-known community)\n"
8250 "Do not export to next AS (well-known community)\n"
8251 "community number\n"
8252 "Do not send outside local AS (well-known community)\n"
8253 "Do not advertise to any peer (well-known community)\n"
8254 "Do not export to next AS (well-known community)\n"
8255 "community number\n"
8256 "Do not send outside local AS (well-known community)\n"
8257 "Do not advertise to any peer (well-known community)\n"
8258 "Do not export to next AS (well-known community)\n"
8259 "Exact match of the communities")
8260
8261/* old command */
8262ALIAS (show_ipv6_bgp_community_exact,
8263 show_ipv6_bgp_community4_exact_cmd,
8264 "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",
8265 SHOW_STR
8266 IPV6_STR
8267 BGP_STR
8268 "Display routes matching the communities\n"
8269 "community number\n"
8270 "Do not send outside local AS (well-known community)\n"
8271 "Do not advertise to any peer (well-known community)\n"
8272 "Do not export to next AS (well-known community)\n"
8273 "community number\n"
8274 "Do not send outside local AS (well-known community)\n"
8275 "Do not advertise to any peer (well-known community)\n"
8276 "Do not export to next AS (well-known community)\n"
8277 "community number\n"
8278 "Do not send outside local AS (well-known community)\n"
8279 "Do not advertise to any peer (well-known community)\n"
8280 "Do not export to next AS (well-known community)\n"
8281 "community number\n"
8282 "Do not send outside local AS (well-known community)\n"
8283 "Do not advertise to any peer (well-known community)\n"
8284 "Do not export to next AS (well-known community)\n"
8285 "Exact match of the communities")
8286
8287/* old command */
8288DEFUN (show_ipv6_mbgp_community,
8289 show_ipv6_mbgp_community_cmd,
8290 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8291 SHOW_STR
8292 IPV6_STR
8293 MBGP_STR
8294 "Display routes matching the communities\n"
8295 "community number\n"
8296 "Do not send outside local AS (well-known community)\n"
8297 "Do not advertise to any peer (well-known community)\n"
8298 "Do not export to next AS (well-known community)\n")
8299{
8300 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8301}
8302
8303/* old command */
8304ALIAS (show_ipv6_mbgp_community,
8305 show_ipv6_mbgp_community2_cmd,
8306 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8307 SHOW_STR
8308 IPV6_STR
8309 MBGP_STR
8310 "Display routes matching the communities\n"
8311 "community number\n"
8312 "Do not send outside local AS (well-known community)\n"
8313 "Do not advertise to any peer (well-known community)\n"
8314 "Do not export to next AS (well-known community)\n"
8315 "community number\n"
8316 "Do not send outside local AS (well-known community)\n"
8317 "Do not advertise to any peer (well-known community)\n"
8318 "Do not export to next AS (well-known community)\n")
8319
8320/* old command */
8321ALIAS (show_ipv6_mbgp_community,
8322 show_ipv6_mbgp_community3_cmd,
8323 "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)",
8324 SHOW_STR
8325 IPV6_STR
8326 MBGP_STR
8327 "Display routes matching the communities\n"
8328 "community number\n"
8329 "Do not send outside local AS (well-known community)\n"
8330 "Do not advertise to any peer (well-known community)\n"
8331 "Do not export to next AS (well-known community)\n"
8332 "community number\n"
8333 "Do not send outside local AS (well-known community)\n"
8334 "Do not advertise to any peer (well-known community)\n"
8335 "Do not export to next AS (well-known community)\n"
8336 "community number\n"
8337 "Do not send outside local AS (well-known community)\n"
8338 "Do not advertise to any peer (well-known community)\n"
8339 "Do not export to next AS (well-known community)\n")
8340
8341/* old command */
8342ALIAS (show_ipv6_mbgp_community,
8343 show_ipv6_mbgp_community4_cmd,
8344 "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)",
8345 SHOW_STR
8346 IPV6_STR
8347 MBGP_STR
8348 "Display routes matching the communities\n"
8349 "community number\n"
8350 "Do not send outside local AS (well-known community)\n"
8351 "Do not advertise to any peer (well-known community)\n"
8352 "Do not export to next AS (well-known community)\n"
8353 "community number\n"
8354 "Do not send outside local AS (well-known community)\n"
8355 "Do not advertise to any peer (well-known community)\n"
8356 "Do not export to next AS (well-known community)\n"
8357 "community number\n"
8358 "Do not send outside local AS (well-known community)\n"
8359 "Do not advertise to any peer (well-known community)\n"
8360 "Do not export to next AS (well-known community)\n"
8361 "community number\n"
8362 "Do not send outside local AS (well-known community)\n"
8363 "Do not advertise to any peer (well-known community)\n"
8364 "Do not export to next AS (well-known community)\n")
8365
8366/* old command */
8367DEFUN (show_ipv6_mbgp_community_exact,
8368 show_ipv6_mbgp_community_exact_cmd,
8369 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8370 SHOW_STR
8371 IPV6_STR
8372 MBGP_STR
8373 "Display routes matching the communities\n"
8374 "community number\n"
8375 "Do not send outside local AS (well-known community)\n"
8376 "Do not advertise to any peer (well-known community)\n"
8377 "Do not export to next AS (well-known community)\n"
8378 "Exact match of the communities")
8379{
8380 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8381}
8382
8383/* old command */
8384ALIAS (show_ipv6_mbgp_community_exact,
8385 show_ipv6_mbgp_community2_exact_cmd,
8386 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8387 SHOW_STR
8388 IPV6_STR
8389 MBGP_STR
8390 "Display routes matching the communities\n"
8391 "community number\n"
8392 "Do not send outside local AS (well-known community)\n"
8393 "Do not advertise to any peer (well-known community)\n"
8394 "Do not export to next AS (well-known community)\n"
8395 "community number\n"
8396 "Do not send outside local AS (well-known community)\n"
8397 "Do not advertise to any peer (well-known community)\n"
8398 "Do not export to next AS (well-known community)\n"
8399 "Exact match of the communities")
8400
8401/* old command */
8402ALIAS (show_ipv6_mbgp_community_exact,
8403 show_ipv6_mbgp_community3_exact_cmd,
8404 "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",
8405 SHOW_STR
8406 IPV6_STR
8407 MBGP_STR
8408 "Display routes matching the communities\n"
8409 "community number\n"
8410 "Do not send outside local AS (well-known community)\n"
8411 "Do not advertise to any peer (well-known community)\n"
8412 "Do not export to next AS (well-known community)\n"
8413 "community number\n"
8414 "Do not send outside local AS (well-known community)\n"
8415 "Do not advertise to any peer (well-known community)\n"
8416 "Do not export to next AS (well-known community)\n"
8417 "community number\n"
8418 "Do not send outside local AS (well-known community)\n"
8419 "Do not advertise to any peer (well-known community)\n"
8420 "Do not export to next AS (well-known community)\n"
8421 "Exact match of the communities")
8422
8423/* old command */
8424ALIAS (show_ipv6_mbgp_community_exact,
8425 show_ipv6_mbgp_community4_exact_cmd,
8426 "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",
8427 SHOW_STR
8428 IPV6_STR
8429 MBGP_STR
8430 "Display routes matching the communities\n"
8431 "community number\n"
8432 "Do not send outside local AS (well-known community)\n"
8433 "Do not advertise to any peer (well-known community)\n"
8434 "Do not export to next AS (well-known community)\n"
8435 "community number\n"
8436 "Do not send outside local AS (well-known community)\n"
8437 "Do not advertise to any peer (well-known community)\n"
8438 "Do not export to next AS (well-known community)\n"
8439 "community number\n"
8440 "Do not send outside local AS (well-known community)\n"
8441 "Do not advertise to any peer (well-known community)\n"
8442 "Do not export to next AS (well-known community)\n"
8443 "community number\n"
8444 "Do not send outside local AS (well-known community)\n"
8445 "Do not advertise to any peer (well-known community)\n"
8446 "Do not export to next AS (well-known community)\n"
8447 "Exact match of the communities")
8448#endif /* HAVE_IPV6 */
8449
paul94f2b392005-06-28 12:44:16 +00008450static int
paulfd79ac92004-10-13 05:06:08 +00008451bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008452 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008453{
8454 struct community_list *list;
8455
hassofee6e4e2005-02-02 16:29:31 +00008456 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008457 if (list == NULL)
8458 {
8459 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8460 VTY_NEWLINE);
8461 return CMD_WARNING;
8462 }
8463
ajs5a646652004-11-05 01:25:55 +00008464 return bgp_show (vty, NULL, afi, safi,
8465 (exact ? bgp_show_type_community_list_exact :
8466 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008467}
8468
8469DEFUN (show_ip_bgp_community_list,
8470 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008471 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008472 SHOW_STR
8473 IP_STR
8474 BGP_STR
8475 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008476 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008477 "community-list name\n")
8478{
8479 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8480}
8481
8482DEFUN (show_ip_bgp_ipv4_community_list,
8483 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008484 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008485 SHOW_STR
8486 IP_STR
8487 BGP_STR
8488 "Address family\n"
8489 "Address Family modifier\n"
8490 "Address Family modifier\n"
8491 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008492 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008493 "community-list name\n")
8494{
8495 if (strncmp (argv[0], "m", 1) == 0)
8496 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8497
8498 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8499}
8500
8501DEFUN (show_ip_bgp_community_list_exact,
8502 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008503 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008504 SHOW_STR
8505 IP_STR
8506 BGP_STR
8507 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008508 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008509 "community-list name\n"
8510 "Exact match of the communities\n")
8511{
8512 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8513}
8514
8515DEFUN (show_ip_bgp_ipv4_community_list_exact,
8516 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008517 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008518 SHOW_STR
8519 IP_STR
8520 BGP_STR
8521 "Address family\n"
8522 "Address Family modifier\n"
8523 "Address Family modifier\n"
8524 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008525 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008526 "community-list name\n"
8527 "Exact match of the communities\n")
8528{
8529 if (strncmp (argv[0], "m", 1) == 0)
8530 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8531
8532 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8533}
8534
8535#ifdef HAVE_IPV6
8536DEFUN (show_bgp_community_list,
8537 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008538 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008539 SHOW_STR
8540 BGP_STR
8541 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008542 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008543 "community-list name\n")
8544{
8545 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8546}
8547
8548ALIAS (show_bgp_community_list,
8549 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008550 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008551 SHOW_STR
8552 BGP_STR
8553 "Address family\n"
8554 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008555 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008556 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008557
8558/* old command */
8559DEFUN (show_ipv6_bgp_community_list,
8560 show_ipv6_bgp_community_list_cmd,
8561 "show ipv6 bgp community-list WORD",
8562 SHOW_STR
8563 IPV6_STR
8564 BGP_STR
8565 "Display routes matching the community-list\n"
8566 "community-list name\n")
8567{
8568 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8569}
8570
8571/* old command */
8572DEFUN (show_ipv6_mbgp_community_list,
8573 show_ipv6_mbgp_community_list_cmd,
8574 "show ipv6 mbgp community-list WORD",
8575 SHOW_STR
8576 IPV6_STR
8577 MBGP_STR
8578 "Display routes matching the community-list\n"
8579 "community-list name\n")
8580{
8581 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8582}
8583
8584DEFUN (show_bgp_community_list_exact,
8585 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008586 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008587 SHOW_STR
8588 BGP_STR
8589 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008590 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008591 "community-list name\n"
8592 "Exact match of the communities\n")
8593{
8594 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8595}
8596
8597ALIAS (show_bgp_community_list_exact,
8598 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008599 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008600 SHOW_STR
8601 BGP_STR
8602 "Address family\n"
8603 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008604 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008605 "community-list name\n"
8606 "Exact match of the communities\n")
8607
8608/* old command */
8609DEFUN (show_ipv6_bgp_community_list_exact,
8610 show_ipv6_bgp_community_list_exact_cmd,
8611 "show ipv6 bgp community-list WORD exact-match",
8612 SHOW_STR
8613 IPV6_STR
8614 BGP_STR
8615 "Display routes matching the community-list\n"
8616 "community-list name\n"
8617 "Exact match of the communities\n")
8618{
8619 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8620}
8621
8622/* old command */
8623DEFUN (show_ipv6_mbgp_community_list_exact,
8624 show_ipv6_mbgp_community_list_exact_cmd,
8625 "show ipv6 mbgp community-list WORD exact-match",
8626 SHOW_STR
8627 IPV6_STR
8628 MBGP_STR
8629 "Display routes matching the community-list\n"
8630 "community-list name\n"
8631 "Exact match of the communities\n")
8632{
8633 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8634}
8635#endif /* HAVE_IPV6 */
8636
paul94f2b392005-06-28 12:44:16 +00008637static int
paulfd79ac92004-10-13 05:06:08 +00008638bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008639 safi_t safi, enum bgp_show_type type)
8640{
8641 int ret;
8642 struct prefix *p;
8643
8644 p = prefix_new();
8645
8646 ret = str2prefix (prefix, p);
8647 if (! ret)
8648 {
8649 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8650 return CMD_WARNING;
8651 }
8652
ajs5a646652004-11-05 01:25:55 +00008653 ret = bgp_show (vty, NULL, afi, safi, type, p);
8654 prefix_free(p);
8655 return ret;
paul718e3742002-12-13 20:15:29 +00008656}
8657
8658DEFUN (show_ip_bgp_prefix_longer,
8659 show_ip_bgp_prefix_longer_cmd,
8660 "show ip bgp A.B.C.D/M longer-prefixes",
8661 SHOW_STR
8662 IP_STR
8663 BGP_STR
8664 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8665 "Display route and more specific routes\n")
8666{
8667 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8668 bgp_show_type_prefix_longer);
8669}
8670
8671DEFUN (show_ip_bgp_flap_prefix_longer,
8672 show_ip_bgp_flap_prefix_longer_cmd,
8673 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8674 SHOW_STR
8675 IP_STR
8676 BGP_STR
8677 "Display flap statistics of routes\n"
8678 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8679 "Display route and more specific routes\n")
8680{
8681 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8682 bgp_show_type_flap_prefix_longer);
8683}
8684
8685DEFUN (show_ip_bgp_ipv4_prefix_longer,
8686 show_ip_bgp_ipv4_prefix_longer_cmd,
8687 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8688 SHOW_STR
8689 IP_STR
8690 BGP_STR
8691 "Address family\n"
8692 "Address Family modifier\n"
8693 "Address Family modifier\n"
8694 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8695 "Display route and more specific routes\n")
8696{
8697 if (strncmp (argv[0], "m", 1) == 0)
8698 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8699 bgp_show_type_prefix_longer);
8700
8701 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8702 bgp_show_type_prefix_longer);
8703}
8704
8705DEFUN (show_ip_bgp_flap_address,
8706 show_ip_bgp_flap_address_cmd,
8707 "show ip bgp flap-statistics A.B.C.D",
8708 SHOW_STR
8709 IP_STR
8710 BGP_STR
8711 "Display flap statistics of routes\n"
8712 "Network in the BGP routing table to display\n")
8713{
8714 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8715 bgp_show_type_flap_address);
8716}
8717
8718DEFUN (show_ip_bgp_flap_prefix,
8719 show_ip_bgp_flap_prefix_cmd,
8720 "show ip bgp flap-statistics A.B.C.D/M",
8721 SHOW_STR
8722 IP_STR
8723 BGP_STR
8724 "Display flap statistics of routes\n"
8725 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8726{
8727 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8728 bgp_show_type_flap_prefix);
8729}
8730#ifdef HAVE_IPV6
8731DEFUN (show_bgp_prefix_longer,
8732 show_bgp_prefix_longer_cmd,
8733 "show bgp X:X::X:X/M longer-prefixes",
8734 SHOW_STR
8735 BGP_STR
8736 "IPv6 prefix <network>/<length>\n"
8737 "Display route and more specific routes\n")
8738{
8739 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8740 bgp_show_type_prefix_longer);
8741}
8742
8743ALIAS (show_bgp_prefix_longer,
8744 show_bgp_ipv6_prefix_longer_cmd,
8745 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8746 SHOW_STR
8747 BGP_STR
8748 "Address family\n"
8749 "IPv6 prefix <network>/<length>\n"
8750 "Display route and more specific routes\n")
8751
8752/* old command */
8753DEFUN (show_ipv6_bgp_prefix_longer,
8754 show_ipv6_bgp_prefix_longer_cmd,
8755 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8756 SHOW_STR
8757 IPV6_STR
8758 BGP_STR
8759 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8760 "Display route and more specific routes\n")
8761{
8762 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8763 bgp_show_type_prefix_longer);
8764}
8765
8766/* old command */
8767DEFUN (show_ipv6_mbgp_prefix_longer,
8768 show_ipv6_mbgp_prefix_longer_cmd,
8769 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8770 SHOW_STR
8771 IPV6_STR
8772 MBGP_STR
8773 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8774 "Display route and more specific routes\n")
8775{
8776 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8777 bgp_show_type_prefix_longer);
8778}
8779#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008780
paul94f2b392005-06-28 12:44:16 +00008781static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008782peer_lookup_in_view (struct vty *vty, const char *view_name,
8783 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008784{
8785 int ret;
8786 struct bgp *bgp;
8787 struct peer *peer;
8788 union sockunion su;
8789
8790 /* BGP structure lookup. */
8791 if (view_name)
8792 {
8793 bgp = bgp_lookup_by_name (view_name);
8794 if (! bgp)
8795 {
8796 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8797 return NULL;
8798 }
8799 }
paul5228ad22004-06-04 17:58:18 +00008800 else
paulbb46e942003-10-24 19:02:03 +00008801 {
8802 bgp = bgp_get_default ();
8803 if (! bgp)
8804 {
8805 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8806 return NULL;
8807 }
8808 }
8809
8810 /* Get peer sockunion. */
8811 ret = str2sockunion (ip_str, &su);
8812 if (ret < 0)
8813 {
8814 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8815 return NULL;
8816 }
8817
8818 /* Peer structure lookup. */
8819 peer = peer_lookup (bgp, &su);
8820 if (! peer)
8821 {
8822 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8823 return NULL;
8824 }
8825
8826 return peer;
8827}
Paul Jakma2815e612006-09-14 02:56:07 +00008828
8829enum bgp_stats
8830{
8831 BGP_STATS_MAXBITLEN = 0,
8832 BGP_STATS_RIB,
8833 BGP_STATS_PREFIXES,
8834 BGP_STATS_TOTPLEN,
8835 BGP_STATS_UNAGGREGATEABLE,
8836 BGP_STATS_MAX_AGGREGATEABLE,
8837 BGP_STATS_AGGREGATES,
8838 BGP_STATS_SPACE,
8839 BGP_STATS_ASPATH_COUNT,
8840 BGP_STATS_ASPATH_MAXHOPS,
8841 BGP_STATS_ASPATH_TOTHOPS,
8842 BGP_STATS_ASPATH_MAXSIZE,
8843 BGP_STATS_ASPATH_TOTSIZE,
8844 BGP_STATS_ASN_HIGHEST,
8845 BGP_STATS_MAX,
8846};
paulbb46e942003-10-24 19:02:03 +00008847
Paul Jakma2815e612006-09-14 02:56:07 +00008848static const char *table_stats_strs[] =
8849{
8850 [BGP_STATS_PREFIXES] = "Total Prefixes",
8851 [BGP_STATS_TOTPLEN] = "Average prefix length",
8852 [BGP_STATS_RIB] = "Total Advertisements",
8853 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8854 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8855 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8856 [BGP_STATS_SPACE] = "Address space advertised",
8857 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8858 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8859 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8860 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8861 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8862 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8863 [BGP_STATS_MAX] = NULL,
8864};
8865
8866struct bgp_table_stats
8867{
8868 struct bgp_table *table;
8869 unsigned long long counts[BGP_STATS_MAX];
8870};
8871
8872#if 0
8873#define TALLY_SIGFIG 100000
8874static unsigned long
8875ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8876{
8877 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8878 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8879 unsigned long ret = newtot / count;
8880
8881 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8882 return ret + 1;
8883 else
8884 return ret;
8885}
8886#endif
8887
8888static int
8889bgp_table_stats_walker (struct thread *t)
8890{
8891 struct bgp_node *rn;
8892 struct bgp_node *top;
8893 struct bgp_table_stats *ts = THREAD_ARG (t);
8894 unsigned int space = 0;
8895
Paul Jakma53d9f672006-10-15 23:41:16 +00008896 if (!(top = bgp_table_top (ts->table)))
8897 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00008898
8899 switch (top->p.family)
8900 {
8901 case AF_INET:
8902 space = IPV4_MAX_BITLEN;
8903 break;
8904 case AF_INET6:
8905 space = IPV6_MAX_BITLEN;
8906 break;
8907 }
8908
8909 ts->counts[BGP_STATS_MAXBITLEN] = space;
8910
8911 for (rn = top; rn; rn = bgp_route_next (rn))
8912 {
8913 struct bgp_info *ri;
8914 struct bgp_node *prn = rn->parent;
8915 unsigned int rinum = 0;
8916
8917 if (rn == top)
8918 continue;
8919
8920 if (!rn->info)
8921 continue;
8922
8923 ts->counts[BGP_STATS_PREFIXES]++;
8924 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
8925
8926#if 0
8927 ts->counts[BGP_STATS_AVGPLEN]
8928 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
8929 ts->counts[BGP_STATS_AVGPLEN],
8930 rn->p.prefixlen);
8931#endif
8932
8933 /* check if the prefix is included by any other announcements */
8934 while (prn && !prn->info)
8935 prn = prn->parent;
8936
8937 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00008938 {
8939 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
8940 /* announced address space */
8941 if (space)
8942 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
8943 }
Paul Jakma2815e612006-09-14 02:56:07 +00008944 else if (prn->info)
8945 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
8946
Paul Jakma2815e612006-09-14 02:56:07 +00008947 for (ri = rn->info; ri; ri = ri->next)
8948 {
8949 rinum++;
8950 ts->counts[BGP_STATS_RIB]++;
8951
8952 if (ri->attr &&
8953 (CHECK_FLAG (ri->attr->flag,
8954 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
8955 ts->counts[BGP_STATS_AGGREGATES]++;
8956
8957 /* as-path stats */
8958 if (ri->attr && ri->attr->aspath)
8959 {
8960 unsigned int hops = aspath_count_hops (ri->attr->aspath);
8961 unsigned int size = aspath_size (ri->attr->aspath);
8962 as_t highest = aspath_highest (ri->attr->aspath);
8963
8964 ts->counts[BGP_STATS_ASPATH_COUNT]++;
8965
8966 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
8967 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
8968
8969 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
8970 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
8971
8972 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
8973 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
8974#if 0
8975 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
8976 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8977 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
8978 hops);
8979 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
8980 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8981 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
8982 size);
8983#endif
8984 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
8985 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
8986 }
8987 }
8988 }
8989 return 0;
8990}
8991
8992static int
8993bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
8994{
8995 struct bgp_table_stats ts;
8996 unsigned int i;
8997
8998 if (!bgp->rib[afi][safi])
8999 {
9000 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9001 return CMD_WARNING;
9002 }
9003
9004 memset (&ts, 0, sizeof (ts));
9005 ts.table = bgp->rib[afi][safi];
9006 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9007
9008 vty_out (vty, "BGP %s RIB statistics%s%s",
9009 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9010
9011 for (i = 0; i < BGP_STATS_MAX; i++)
9012 {
9013 if (!table_stats_strs[i])
9014 continue;
9015
9016 switch (i)
9017 {
9018#if 0
9019 case BGP_STATS_ASPATH_AVGHOPS:
9020 case BGP_STATS_ASPATH_AVGSIZE:
9021 case BGP_STATS_AVGPLEN:
9022 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9023 vty_out (vty, "%12.2f",
9024 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9025 break;
9026#endif
9027 case BGP_STATS_ASPATH_TOTHOPS:
9028 case BGP_STATS_ASPATH_TOTSIZE:
9029 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9030 vty_out (vty, "%12.2f",
9031 ts.counts[i] ?
9032 (float)ts.counts[i] /
9033 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9034 : 0);
9035 break;
9036 case BGP_STATS_TOTPLEN:
9037 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9038 vty_out (vty, "%12.2f",
9039 ts.counts[i] ?
9040 (float)ts.counts[i] /
9041 (float)ts.counts[BGP_STATS_PREFIXES]
9042 : 0);
9043 break;
9044 case BGP_STATS_SPACE:
9045 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9046 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9047 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9048 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009049 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009050 vty_out (vty, "%12.2f%s",
9051 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009052 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009053 VTY_NEWLINE);
9054 vty_out (vty, "%30s: ", "/8 equivalent ");
9055 vty_out (vty, "%12.2f%s",
9056 (float)ts.counts[BGP_STATS_SPACE] /
9057 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9058 VTY_NEWLINE);
9059 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9060 break;
9061 vty_out (vty, "%30s: ", "/24 equivalent ");
9062 vty_out (vty, "%12.2f",
9063 (float)ts.counts[BGP_STATS_SPACE] /
9064 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9065 break;
9066 default:
9067 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9068 vty_out (vty, "%12llu", ts.counts[i]);
9069 }
9070
9071 vty_out (vty, "%s", VTY_NEWLINE);
9072 }
9073 return CMD_SUCCESS;
9074}
9075
9076static int
9077bgp_table_stats_vty (struct vty *vty, const char *name,
9078 const char *afi_str, const char *safi_str)
9079{
9080 struct bgp *bgp;
9081 afi_t afi;
9082 safi_t safi;
9083
9084 if (name)
9085 bgp = bgp_lookup_by_name (name);
9086 else
9087 bgp = bgp_get_default ();
9088
9089 if (!bgp)
9090 {
9091 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9092 return CMD_WARNING;
9093 }
9094 if (strncmp (afi_str, "ipv", 3) == 0)
9095 {
9096 if (strncmp (afi_str, "ipv4", 4) == 0)
9097 afi = AFI_IP;
9098 else if (strncmp (afi_str, "ipv6", 4) == 0)
9099 afi = AFI_IP6;
9100 else
9101 {
9102 vty_out (vty, "%% Invalid address family %s%s",
9103 afi_str, VTY_NEWLINE);
9104 return CMD_WARNING;
9105 }
9106 if (strncmp (safi_str, "m", 1) == 0)
9107 safi = SAFI_MULTICAST;
9108 else if (strncmp (safi_str, "u", 1) == 0)
9109 safi = SAFI_UNICAST;
Denis Ovsienkoe81537d2011-07-14 12:36:19 +04009110 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9111 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009112 else
9113 {
9114 vty_out (vty, "%% Invalid subsequent address family %s%s",
9115 safi_str, VTY_NEWLINE);
9116 return CMD_WARNING;
9117 }
9118 }
9119 else
9120 {
9121 vty_out (vty, "%% Invalid address family %s%s",
9122 afi_str, VTY_NEWLINE);
9123 return CMD_WARNING;
9124 }
9125
Paul Jakma2815e612006-09-14 02:56:07 +00009126 return bgp_table_stats (vty, bgp, afi, safi);
9127}
9128
9129DEFUN (show_bgp_statistics,
9130 show_bgp_statistics_cmd,
9131 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9132 SHOW_STR
9133 BGP_STR
9134 "Address family\n"
9135 "Address family\n"
9136 "Address Family modifier\n"
9137 "Address Family modifier\n"
9138 "BGP RIB advertisement statistics\n")
9139{
9140 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9141}
9142
9143ALIAS (show_bgp_statistics,
9144 show_bgp_statistics_vpnv4_cmd,
9145 "show bgp (ipv4) (vpnv4) statistics",
9146 SHOW_STR
9147 BGP_STR
9148 "Address family\n"
9149 "Address Family modifier\n"
9150 "BGP RIB advertisement statistics\n")
9151
9152DEFUN (show_bgp_statistics_view,
9153 show_bgp_statistics_view_cmd,
9154 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9155 SHOW_STR
9156 BGP_STR
9157 "BGP view\n"
9158 "Address family\n"
9159 "Address family\n"
9160 "Address Family modifier\n"
9161 "Address Family modifier\n"
9162 "BGP RIB advertisement statistics\n")
9163{
9164 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9165}
9166
9167ALIAS (show_bgp_statistics_view,
9168 show_bgp_statistics_view_vpnv4_cmd,
9169 "show bgp view WORD (ipv4) (vpnv4) statistics",
9170 SHOW_STR
9171 BGP_STR
9172 "BGP view\n"
9173 "Address family\n"
9174 "Address Family modifier\n"
9175 "BGP RIB advertisement statistics\n")
9176
Paul Jakmaff7924f2006-09-04 01:10:36 +00009177enum bgp_pcounts
9178{
9179 PCOUNT_ADJ_IN = 0,
9180 PCOUNT_DAMPED,
9181 PCOUNT_REMOVED,
9182 PCOUNT_HISTORY,
9183 PCOUNT_STALE,
9184 PCOUNT_VALID,
9185 PCOUNT_ALL,
9186 PCOUNT_COUNTED,
9187 PCOUNT_PFCNT, /* the figure we display to users */
9188 PCOUNT_MAX,
9189};
9190
9191static const char *pcount_strs[] =
9192{
9193 [PCOUNT_ADJ_IN] = "Adj-in",
9194 [PCOUNT_DAMPED] = "Damped",
9195 [PCOUNT_REMOVED] = "Removed",
9196 [PCOUNT_HISTORY] = "History",
9197 [PCOUNT_STALE] = "Stale",
9198 [PCOUNT_VALID] = "Valid",
9199 [PCOUNT_ALL] = "All RIB",
9200 [PCOUNT_COUNTED] = "PfxCt counted",
9201 [PCOUNT_PFCNT] = "Useable",
9202 [PCOUNT_MAX] = NULL,
9203};
9204
Paul Jakma2815e612006-09-14 02:56:07 +00009205struct peer_pcounts
9206{
9207 unsigned int count[PCOUNT_MAX];
9208 const struct peer *peer;
9209 const struct bgp_table *table;
9210};
9211
Paul Jakmaff7924f2006-09-04 01:10:36 +00009212static int
Paul Jakma2815e612006-09-14 02:56:07 +00009213bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009214{
9215 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009216 struct peer_pcounts *pc = THREAD_ARG (t);
9217 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009218
Paul Jakma2815e612006-09-14 02:56:07 +00009219 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009220 {
9221 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009222 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009223
9224 for (ain = rn->adj_in; ain; ain = ain->next)
9225 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009226 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009227
Paul Jakmaff7924f2006-09-04 01:10:36 +00009228 for (ri = rn->info; ri; ri = ri->next)
9229 {
9230 char buf[SU_ADDRSTRLEN];
9231
9232 if (ri->peer != peer)
9233 continue;
9234
Paul Jakma2815e612006-09-14 02:56:07 +00009235 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009236
9237 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009238 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009239 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009240 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009241 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009242 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009243 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009244 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009245 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009246 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009247 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009248 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009249
9250 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9251 {
Paul Jakma2815e612006-09-14 02:56:07 +00009252 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009253 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009254 plog_warn (peer->log,
9255 "%s [pcount] %s/%d is counted but flags 0x%x",
9256 peer->host,
9257 inet_ntop(rn->p.family, &rn->p.u.prefix,
9258 buf, SU_ADDRSTRLEN),
9259 rn->p.prefixlen,
9260 ri->flags);
9261 }
9262 else
9263 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009264 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009265 plog_warn (peer->log,
9266 "%s [pcount] %s/%d not counted but flags 0x%x",
9267 peer->host,
9268 inet_ntop(rn->p.family, &rn->p.u.prefix,
9269 buf, SU_ADDRSTRLEN),
9270 rn->p.prefixlen,
9271 ri->flags);
9272 }
9273 }
9274 }
Paul Jakma2815e612006-09-14 02:56:07 +00009275 return 0;
9276}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009277
Paul Jakma2815e612006-09-14 02:56:07 +00009278static int
9279bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9280{
9281 struct peer_pcounts pcounts = { .peer = peer };
9282 unsigned int i;
9283
9284 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9285 || !peer->bgp->rib[afi][safi])
9286 {
9287 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9288 return CMD_WARNING;
9289 }
9290
9291 memset (&pcounts, 0, sizeof(pcounts));
9292 pcounts.peer = peer;
9293 pcounts.table = peer->bgp->rib[afi][safi];
9294
9295 /* in-place call via thread subsystem so as to record execution time
9296 * stats for the thread-walk (i.e. ensure this can't be blamed on
9297 * on just vty_read()).
9298 */
9299 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9300
Paul Jakmaff7924f2006-09-04 01:10:36 +00009301 vty_out (vty, "Prefix counts for %s, %s%s",
9302 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9303 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9304 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9305 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9306
9307 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009308 vty_out (vty, "%20s: %-10d%s",
9309 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009310
Paul Jakma2815e612006-09-14 02:56:07 +00009311 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009312 {
9313 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9314 peer->host, VTY_NEWLINE);
9315 vty_out (vty, "Please report this bug, with the above command output%s",
9316 VTY_NEWLINE);
9317 }
9318
9319 return CMD_SUCCESS;
9320}
9321
9322DEFUN (show_ip_bgp_neighbor_prefix_counts,
9323 show_ip_bgp_neighbor_prefix_counts_cmd,
9324 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9325 SHOW_STR
9326 IP_STR
9327 BGP_STR
9328 "Detailed information on TCP and BGP neighbor connections\n"
9329 "Neighbor to display information about\n"
9330 "Neighbor to display information about\n"
9331 "Display detailed prefix count information\n")
9332{
9333 struct peer *peer;
9334
9335 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9336 if (! peer)
9337 return CMD_WARNING;
9338
9339 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9340}
9341
9342DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9343 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9344 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9345 SHOW_STR
9346 BGP_STR
9347 "Address family\n"
9348 "Detailed information on TCP and BGP neighbor connections\n"
9349 "Neighbor to display information about\n"
9350 "Neighbor to display information about\n"
9351 "Display detailed prefix count information\n")
9352{
9353 struct peer *peer;
9354
9355 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9356 if (! peer)
9357 return CMD_WARNING;
9358
9359 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9360}
9361
9362DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9363 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9364 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9365 SHOW_STR
9366 IP_STR
9367 BGP_STR
9368 "Address family\n"
9369 "Address Family modifier\n"
9370 "Address Family modifier\n"
9371 "Detailed information on TCP and BGP neighbor connections\n"
9372 "Neighbor to display information about\n"
9373 "Neighbor to display information about\n"
9374 "Display detailed prefix count information\n")
9375{
9376 struct peer *peer;
9377
9378 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9379 if (! peer)
9380 return CMD_WARNING;
9381
9382 if (strncmp (argv[0], "m", 1) == 0)
9383 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9384
9385 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9386}
9387
9388DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9389 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9390 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9391 SHOW_STR
9392 IP_STR
9393 BGP_STR
9394 "Address family\n"
9395 "Address Family modifier\n"
9396 "Address Family modifier\n"
9397 "Detailed information on TCP and BGP neighbor connections\n"
9398 "Neighbor to display information about\n"
9399 "Neighbor to display information about\n"
9400 "Display detailed prefix count information\n")
9401{
9402 struct peer *peer;
9403
9404 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9405 if (! peer)
9406 return CMD_WARNING;
9407
9408 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9409}
9410
9411
paul94f2b392005-06-28 12:44:16 +00009412static void
paul718e3742002-12-13 20:15:29 +00009413show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9414 int in)
9415{
9416 struct bgp_table *table;
9417 struct bgp_adj_in *ain;
9418 struct bgp_adj_out *adj;
9419 unsigned long output_count;
9420 struct bgp_node *rn;
9421 int header1 = 1;
9422 struct bgp *bgp;
9423 int header2 = 1;
9424
paulbb46e942003-10-24 19:02:03 +00009425 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009426
9427 if (! bgp)
9428 return;
9429
9430 table = bgp->rib[afi][safi];
9431
9432 output_count = 0;
9433
9434 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9435 PEER_STATUS_DEFAULT_ORIGINATE))
9436 {
9437 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 +00009438 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9439 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009440
9441 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9442 VTY_NEWLINE, VTY_NEWLINE);
9443 header1 = 0;
9444 }
9445
9446 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9447 if (in)
9448 {
9449 for (ain = rn->adj_in; ain; ain = ain->next)
9450 if (ain->peer == peer)
9451 {
9452 if (header1)
9453 {
9454 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 +00009455 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9456 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009457 header1 = 0;
9458 }
9459 if (header2)
9460 {
9461 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9462 header2 = 0;
9463 }
9464 if (ain->attr)
9465 {
9466 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9467 output_count++;
9468 }
9469 }
9470 }
9471 else
9472 {
9473 for (adj = rn->adj_out; adj; adj = adj->next)
9474 if (adj->peer == peer)
9475 {
9476 if (header1)
9477 {
9478 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 +00009479 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9480 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009481 header1 = 0;
9482 }
9483 if (header2)
9484 {
9485 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9486 header2 = 0;
9487 }
9488 if (adj->attr)
9489 {
9490 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9491 output_count++;
9492 }
9493 }
9494 }
9495
9496 if (output_count != 0)
9497 vty_out (vty, "%sTotal number of prefixes %ld%s",
9498 VTY_NEWLINE, output_count, VTY_NEWLINE);
9499}
9500
paul94f2b392005-06-28 12:44:16 +00009501static int
paulbb46e942003-10-24 19:02:03 +00009502peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9503{
paul718e3742002-12-13 20:15:29 +00009504 if (! peer || ! peer->afc[afi][safi])
9505 {
9506 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9507 return CMD_WARNING;
9508 }
9509
9510 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9511 {
9512 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9513 VTY_NEWLINE);
9514 return CMD_WARNING;
9515 }
9516
9517 show_adj_route (vty, peer, afi, safi, in);
9518
9519 return CMD_SUCCESS;
9520}
9521
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009522DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9523 show_ip_bgp_view_neighbor_advertised_route_cmd,
9524 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9525 SHOW_STR
9526 IP_STR
9527 BGP_STR
9528 "BGP view\n"
9529 "View name\n"
9530 "Detailed information on TCP and BGP neighbor connections\n"
9531 "Neighbor to display information about\n"
9532 "Neighbor to display information about\n"
9533 "Display the routes advertised to a BGP neighbor\n")
9534{
9535 struct peer *peer;
9536
9537 if (argc == 2)
9538 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9539 else
9540 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9541
9542 if (! peer)
9543 return CMD_WARNING;
9544
9545 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9546}
9547
9548ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009549 show_ip_bgp_neighbor_advertised_route_cmd,
9550 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9551 SHOW_STR
9552 IP_STR
9553 BGP_STR
9554 "Detailed information on TCP and BGP neighbor connections\n"
9555 "Neighbor to display information about\n"
9556 "Neighbor to display information about\n"
9557 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009558
9559DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9560 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9561 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9562 SHOW_STR
9563 IP_STR
9564 BGP_STR
9565 "Address family\n"
9566 "Address Family modifier\n"
9567 "Address Family modifier\n"
9568 "Detailed information on TCP and BGP neighbor connections\n"
9569 "Neighbor to display information about\n"
9570 "Neighbor to display information about\n"
9571 "Display the routes advertised to a BGP neighbor\n")
9572{
paulbb46e942003-10-24 19:02:03 +00009573 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009574
paulbb46e942003-10-24 19:02:03 +00009575 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9576 if (! peer)
9577 return CMD_WARNING;
9578
9579 if (strncmp (argv[0], "m", 1) == 0)
9580 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9581
9582 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009583}
9584
9585#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009586DEFUN (show_bgp_view_neighbor_advertised_route,
9587 show_bgp_view_neighbor_advertised_route_cmd,
9588 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9589 SHOW_STR
9590 BGP_STR
9591 "BGP view\n"
9592 "View name\n"
9593 "Detailed information on TCP and BGP neighbor connections\n"
9594 "Neighbor to display information about\n"
9595 "Neighbor to display information about\n"
9596 "Display the routes advertised to a BGP neighbor\n")
9597{
9598 struct peer *peer;
9599
9600 if (argc == 2)
9601 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9602 else
9603 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9604
9605 if (! peer)
9606 return CMD_WARNING;
9607
9608 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9609}
9610
9611ALIAS (show_bgp_view_neighbor_advertised_route,
9612 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9613 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9614 SHOW_STR
9615 BGP_STR
9616 "BGP view\n"
9617 "View name\n"
9618 "Address family\n"
9619 "Detailed information on TCP and BGP neighbor connections\n"
9620 "Neighbor to display information about\n"
9621 "Neighbor to display information about\n"
9622 "Display the routes advertised to a BGP neighbor\n")
9623
9624DEFUN (show_bgp_view_neighbor_received_routes,
9625 show_bgp_view_neighbor_received_routes_cmd,
9626 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9627 SHOW_STR
9628 BGP_STR
9629 "BGP view\n"
9630 "View name\n"
9631 "Detailed information on TCP and BGP neighbor connections\n"
9632 "Neighbor to display information about\n"
9633 "Neighbor to display information about\n"
9634 "Display the received routes from neighbor\n")
9635{
9636 struct peer *peer;
9637
9638 if (argc == 2)
9639 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9640 else
9641 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9642
9643 if (! peer)
9644 return CMD_WARNING;
9645
9646 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9647}
9648
9649ALIAS (show_bgp_view_neighbor_received_routes,
9650 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9651 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9652 SHOW_STR
9653 BGP_STR
9654 "BGP view\n"
9655 "View name\n"
9656 "Address family\n"
9657 "Detailed information on TCP and BGP neighbor connections\n"
9658 "Neighbor to display information about\n"
9659 "Neighbor to display information about\n"
9660 "Display the received routes from neighbor\n")
9661
9662ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009663 show_bgp_neighbor_advertised_route_cmd,
9664 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9665 SHOW_STR
9666 BGP_STR
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 routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009671
9672ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009673 show_bgp_ipv6_neighbor_advertised_route_cmd,
9674 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9675 SHOW_STR
9676 BGP_STR
9677 "Address family\n"
9678 "Detailed information on TCP and BGP neighbor connections\n"
9679 "Neighbor to display information about\n"
9680 "Neighbor to display information about\n"
9681 "Display the routes advertised to a BGP neighbor\n")
9682
9683/* old command */
paulbb46e942003-10-24 19:02:03 +00009684ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009685 ipv6_bgp_neighbor_advertised_route_cmd,
9686 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9687 SHOW_STR
9688 IPV6_STR
9689 BGP_STR
9690 "Detailed information on TCP and BGP neighbor connections\n"
9691 "Neighbor to display information about\n"
9692 "Neighbor to display information about\n"
9693 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009694
paul718e3742002-12-13 20:15:29 +00009695/* old command */
9696DEFUN (ipv6_mbgp_neighbor_advertised_route,
9697 ipv6_mbgp_neighbor_advertised_route_cmd,
9698 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9699 SHOW_STR
9700 IPV6_STR
9701 MBGP_STR
9702 "Detailed information on TCP and BGP neighbor connections\n"
9703 "Neighbor to display information about\n"
9704 "Neighbor to display information about\n"
9705 "Display the routes advertised to a BGP neighbor\n")
9706{
paulbb46e942003-10-24 19:02:03 +00009707 struct peer *peer;
9708
9709 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9710 if (! peer)
9711 return CMD_WARNING;
9712
9713 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009714}
9715#endif /* HAVE_IPV6 */
9716
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009717DEFUN (show_ip_bgp_view_neighbor_received_routes,
9718 show_ip_bgp_view_neighbor_received_routes_cmd,
9719 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9720 SHOW_STR
9721 IP_STR
9722 BGP_STR
9723 "BGP view\n"
9724 "View name\n"
9725 "Detailed information on TCP and BGP neighbor connections\n"
9726 "Neighbor to display information about\n"
9727 "Neighbor to display information about\n"
9728 "Display the received routes from neighbor\n")
9729{
9730 struct peer *peer;
9731
9732 if (argc == 2)
9733 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9734 else
9735 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9736
9737 if (! peer)
9738 return CMD_WARNING;
9739
9740 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9741}
9742
9743ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009744 show_ip_bgp_neighbor_received_routes_cmd,
9745 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9746 SHOW_STR
9747 IP_STR
9748 BGP_STR
9749 "Detailed information on TCP and BGP neighbor connections\n"
9750 "Neighbor to display information about\n"
9751 "Neighbor to display information about\n"
9752 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009753
9754DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9755 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9756 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9757 SHOW_STR
9758 IP_STR
9759 BGP_STR
9760 "Address family\n"
9761 "Address Family modifier\n"
9762 "Address Family modifier\n"
9763 "Detailed information on TCP and BGP neighbor connections\n"
9764 "Neighbor to display information about\n"
9765 "Neighbor to display information about\n"
9766 "Display the received routes from neighbor\n")
9767{
paulbb46e942003-10-24 19:02:03 +00009768 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009769
paulbb46e942003-10-24 19:02:03 +00009770 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9771 if (! peer)
9772 return CMD_WARNING;
9773
9774 if (strncmp (argv[0], "m", 1) == 0)
9775 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9776
9777 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009778}
9779
9780DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9781 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9782 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9783 SHOW_STR
9784 IP_STR
9785 BGP_STR
9786 "Detailed information on TCP and BGP neighbor connections\n"
9787 "Neighbor to display information about\n"
9788 "Neighbor to display information about\n"
9789 "Display information received from a BGP neighbor\n"
9790 "Display the prefixlist filter\n")
9791{
9792 char name[BUFSIZ];
9793 union sockunion *su;
9794 struct peer *peer;
9795 int count;
9796
9797 su = sockunion_str2su (argv[0]);
9798 if (su == NULL)
9799 return CMD_WARNING;
9800
9801 peer = peer_lookup (NULL, su);
9802 if (! peer)
9803 return CMD_WARNING;
9804
9805 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9806 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9807 if (count)
9808 {
9809 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9810 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9811 }
9812
9813 return CMD_SUCCESS;
9814}
9815
9816DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9817 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9818 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9819 SHOW_STR
9820 IP_STR
9821 BGP_STR
9822 "Address family\n"
9823 "Address Family modifier\n"
9824 "Address Family modifier\n"
9825 "Detailed information on TCP and BGP neighbor connections\n"
9826 "Neighbor to display information about\n"
9827 "Neighbor to display information about\n"
9828 "Display information received from a BGP neighbor\n"
9829 "Display the prefixlist filter\n")
9830{
9831 char name[BUFSIZ];
9832 union sockunion *su;
9833 struct peer *peer;
9834 int count;
9835
9836 su = sockunion_str2su (argv[1]);
9837 if (su == NULL)
9838 return CMD_WARNING;
9839
9840 peer = peer_lookup (NULL, su);
9841 if (! peer)
9842 return CMD_WARNING;
9843
9844 if (strncmp (argv[0], "m", 1) == 0)
9845 {
9846 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9847 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9848 if (count)
9849 {
9850 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9851 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9852 }
9853 }
9854 else
9855 {
9856 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9857 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9858 if (count)
9859 {
9860 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9861 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9862 }
9863 }
9864
9865 return CMD_SUCCESS;
9866}
9867
9868
9869#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009870ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009871 show_bgp_neighbor_received_routes_cmd,
9872 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9873 SHOW_STR
9874 BGP_STR
9875 "Detailed information on TCP and BGP neighbor connections\n"
9876 "Neighbor to display information about\n"
9877 "Neighbor to display information about\n"
9878 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009879
paulbb46e942003-10-24 19:02:03 +00009880ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009881 show_bgp_ipv6_neighbor_received_routes_cmd,
9882 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9883 SHOW_STR
9884 BGP_STR
9885 "Address family\n"
9886 "Detailed information on TCP and BGP neighbor connections\n"
9887 "Neighbor to display information about\n"
9888 "Neighbor to display information about\n"
9889 "Display the received routes from neighbor\n")
9890
9891DEFUN (show_bgp_neighbor_received_prefix_filter,
9892 show_bgp_neighbor_received_prefix_filter_cmd,
9893 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9894 SHOW_STR
9895 BGP_STR
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 information received from a BGP neighbor\n"
9900 "Display the prefixlist filter\n")
9901{
9902 char name[BUFSIZ];
9903 union sockunion *su;
9904 struct peer *peer;
9905 int count;
9906
9907 su = sockunion_str2su (argv[0]);
9908 if (su == NULL)
9909 return CMD_WARNING;
9910
9911 peer = peer_lookup (NULL, su);
9912 if (! peer)
9913 return CMD_WARNING;
9914
9915 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9916 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9917 if (count)
9918 {
9919 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9920 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9921 }
9922
9923 return CMD_SUCCESS;
9924}
9925
9926ALIAS (show_bgp_neighbor_received_prefix_filter,
9927 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
9928 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9929 SHOW_STR
9930 BGP_STR
9931 "Address family\n"
9932 "Detailed information on TCP and BGP neighbor connections\n"
9933 "Neighbor to display information about\n"
9934 "Neighbor to display information about\n"
9935 "Display information received from a BGP neighbor\n"
9936 "Display the prefixlist filter\n")
9937
9938/* old command */
paulbb46e942003-10-24 19:02:03 +00009939ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009940 ipv6_bgp_neighbor_received_routes_cmd,
9941 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9942 SHOW_STR
9943 IPV6_STR
9944 BGP_STR
9945 "Detailed information on TCP and BGP neighbor connections\n"
9946 "Neighbor to display information about\n"
9947 "Neighbor to display information about\n"
9948 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009949
9950/* old command */
9951DEFUN (ipv6_mbgp_neighbor_received_routes,
9952 ipv6_mbgp_neighbor_received_routes_cmd,
9953 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9954 SHOW_STR
9955 IPV6_STR
9956 MBGP_STR
9957 "Detailed information on TCP and BGP neighbor connections\n"
9958 "Neighbor to display information about\n"
9959 "Neighbor to display information about\n"
9960 "Display the received routes from neighbor\n")
9961{
paulbb46e942003-10-24 19:02:03 +00009962 struct peer *peer;
9963
9964 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9965 if (! peer)
9966 return CMD_WARNING;
9967
9968 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00009969}
paulbb46e942003-10-24 19:02:03 +00009970
9971DEFUN (show_bgp_view_neighbor_received_prefix_filter,
9972 show_bgp_view_neighbor_received_prefix_filter_cmd,
9973 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9974 SHOW_STR
9975 BGP_STR
9976 "BGP view\n"
9977 "View name\n"
9978 "Detailed information on TCP and BGP neighbor connections\n"
9979 "Neighbor to display information about\n"
9980 "Neighbor to display information about\n"
9981 "Display information received from a BGP neighbor\n"
9982 "Display the prefixlist filter\n")
9983{
9984 char name[BUFSIZ];
9985 union sockunion *su;
9986 struct peer *peer;
9987 struct bgp *bgp;
9988 int count;
9989
9990 /* BGP structure lookup. */
9991 bgp = bgp_lookup_by_name (argv[0]);
9992 if (bgp == NULL)
9993 {
9994 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9995 return CMD_WARNING;
9996 }
9997
9998 su = sockunion_str2su (argv[1]);
9999 if (su == NULL)
10000 return CMD_WARNING;
10001
10002 peer = peer_lookup (bgp, su);
10003 if (! peer)
10004 return CMD_WARNING;
10005
10006 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10007 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10008 if (count)
10009 {
10010 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10011 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10012 }
10013
10014 return CMD_SUCCESS;
10015}
10016
10017ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10018 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10019 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10020 SHOW_STR
10021 BGP_STR
10022 "BGP view\n"
10023 "View name\n"
10024 "Address family\n"
10025 "Detailed information on TCP and BGP neighbor connections\n"
10026 "Neighbor to display information about\n"
10027 "Neighbor to display information about\n"
10028 "Display information received from a BGP neighbor\n"
10029 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010030#endif /* HAVE_IPV6 */
10031
paul94f2b392005-06-28 12:44:16 +000010032static int
paulbb46e942003-10-24 19:02:03 +000010033bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010034 safi_t safi, enum bgp_show_type type)
10035{
paul718e3742002-12-13 20:15:29 +000010036 if (! peer || ! peer->afc[afi][safi])
10037 {
10038 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010039 return CMD_WARNING;
10040 }
10041
ajs5a646652004-11-05 01:25:55 +000010042 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010043}
10044
10045DEFUN (show_ip_bgp_neighbor_routes,
10046 show_ip_bgp_neighbor_routes_cmd,
10047 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10048 SHOW_STR
10049 IP_STR
10050 BGP_STR
10051 "Detailed information on TCP and BGP neighbor connections\n"
10052 "Neighbor to display information about\n"
10053 "Neighbor to display information about\n"
10054 "Display routes learned from neighbor\n")
10055{
paulbb46e942003-10-24 19:02:03 +000010056 struct peer *peer;
10057
10058 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10059 if (! peer)
10060 return CMD_WARNING;
10061
10062 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010063 bgp_show_type_neighbor);
10064}
10065
10066DEFUN (show_ip_bgp_neighbor_flap,
10067 show_ip_bgp_neighbor_flap_cmd,
10068 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10069 SHOW_STR
10070 IP_STR
10071 BGP_STR
10072 "Detailed information on TCP and BGP neighbor connections\n"
10073 "Neighbor to display information about\n"
10074 "Neighbor to display information about\n"
10075 "Display flap statistics of the routes learned from neighbor\n")
10076{
paulbb46e942003-10-24 19:02:03 +000010077 struct peer *peer;
10078
10079 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10080 if (! peer)
10081 return CMD_WARNING;
10082
10083 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010084 bgp_show_type_flap_neighbor);
10085}
10086
10087DEFUN (show_ip_bgp_neighbor_damp,
10088 show_ip_bgp_neighbor_damp_cmd,
10089 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10090 SHOW_STR
10091 IP_STR
10092 BGP_STR
10093 "Detailed information on TCP and BGP neighbor connections\n"
10094 "Neighbor to display information about\n"
10095 "Neighbor to display information about\n"
10096 "Display the dampened routes received from neighbor\n")
10097{
paulbb46e942003-10-24 19:02:03 +000010098 struct peer *peer;
10099
10100 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10101 if (! peer)
10102 return CMD_WARNING;
10103
10104 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010105 bgp_show_type_damp_neighbor);
10106}
10107
10108DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10109 show_ip_bgp_ipv4_neighbor_routes_cmd,
10110 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10111 SHOW_STR
10112 IP_STR
10113 BGP_STR
10114 "Address family\n"
10115 "Address Family modifier\n"
10116 "Address Family modifier\n"
10117 "Detailed information on TCP and BGP neighbor connections\n"
10118 "Neighbor to display information about\n"
10119 "Neighbor to display information about\n"
10120 "Display routes learned from neighbor\n")
10121{
paulbb46e942003-10-24 19:02:03 +000010122 struct peer *peer;
10123
10124 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10125 if (! peer)
10126 return CMD_WARNING;
10127
paul718e3742002-12-13 20:15:29 +000010128 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010129 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010130 bgp_show_type_neighbor);
10131
paulbb46e942003-10-24 19:02:03 +000010132 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010133 bgp_show_type_neighbor);
10134}
paulbb46e942003-10-24 19:02:03 +000010135
paulfee0f4c2004-09-13 05:12:46 +000010136DEFUN (show_ip_bgp_view_rsclient,
10137 show_ip_bgp_view_rsclient_cmd,
10138 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10139 SHOW_STR
10140 IP_STR
10141 BGP_STR
10142 "BGP view\n"
10143 "BGP view name\n"
10144 "Information about Route Server Client\n"
10145 NEIGHBOR_ADDR_STR)
10146{
10147 struct bgp_table *table;
10148 struct peer *peer;
10149
10150 if (argc == 2)
10151 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10152 else
10153 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10154
10155 if (! peer)
10156 return CMD_WARNING;
10157
10158 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10159 {
10160 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10161 VTY_NEWLINE);
10162 return CMD_WARNING;
10163 }
10164
10165 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10166 PEER_FLAG_RSERVER_CLIENT))
10167 {
10168 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10169 VTY_NEWLINE);
10170 return CMD_WARNING;
10171 }
10172
10173 table = peer->rib[AFI_IP][SAFI_UNICAST];
10174
ajs5a646652004-11-05 01:25:55 +000010175 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010176}
10177
10178ALIAS (show_ip_bgp_view_rsclient,
10179 show_ip_bgp_rsclient_cmd,
10180 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10181 SHOW_STR
10182 IP_STR
10183 BGP_STR
10184 "Information about Route Server Client\n"
10185 NEIGHBOR_ADDR_STR)
10186
10187DEFUN (show_ip_bgp_view_rsclient_route,
10188 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010189 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010190 SHOW_STR
10191 IP_STR
10192 BGP_STR
10193 "BGP view\n"
10194 "BGP view name\n"
10195 "Information about Route Server Client\n"
10196 NEIGHBOR_ADDR_STR
10197 "Network in the BGP routing table to display\n")
10198{
10199 struct bgp *bgp;
10200 struct peer *peer;
10201
10202 /* BGP structure lookup. */
10203 if (argc == 3)
10204 {
10205 bgp = bgp_lookup_by_name (argv[0]);
10206 if (bgp == NULL)
10207 {
10208 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10209 return CMD_WARNING;
10210 }
10211 }
10212 else
10213 {
10214 bgp = bgp_get_default ();
10215 if (bgp == NULL)
10216 {
10217 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10218 return CMD_WARNING;
10219 }
10220 }
10221
10222 if (argc == 3)
10223 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10224 else
10225 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10226
10227 if (! peer)
10228 return CMD_WARNING;
10229
10230 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10231 {
10232 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10233 VTY_NEWLINE);
10234 return CMD_WARNING;
10235}
10236
10237 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10238 PEER_FLAG_RSERVER_CLIENT))
10239 {
10240 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10241 VTY_NEWLINE);
10242 return CMD_WARNING;
10243 }
10244
10245 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10246 (argc == 3) ? argv[2] : argv[1],
10247 AFI_IP, SAFI_UNICAST, NULL, 0);
10248}
10249
10250ALIAS (show_ip_bgp_view_rsclient_route,
10251 show_ip_bgp_rsclient_route_cmd,
10252 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10253 SHOW_STR
10254 IP_STR
10255 BGP_STR
10256 "Information about Route Server Client\n"
10257 NEIGHBOR_ADDR_STR
10258 "Network in the BGP routing table to display\n")
10259
10260DEFUN (show_ip_bgp_view_rsclient_prefix,
10261 show_ip_bgp_view_rsclient_prefix_cmd,
10262 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10263 SHOW_STR
10264 IP_STR
10265 BGP_STR
10266 "BGP view\n"
10267 "BGP view name\n"
10268 "Information about Route Server Client\n"
10269 NEIGHBOR_ADDR_STR
10270 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10271{
10272 struct bgp *bgp;
10273 struct peer *peer;
10274
10275 /* BGP structure lookup. */
10276 if (argc == 3)
10277 {
10278 bgp = bgp_lookup_by_name (argv[0]);
10279 if (bgp == NULL)
10280 {
10281 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10282 return CMD_WARNING;
10283 }
10284 }
10285 else
10286 {
10287 bgp = bgp_get_default ();
10288 if (bgp == NULL)
10289 {
10290 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10291 return CMD_WARNING;
10292 }
10293 }
10294
10295 if (argc == 3)
10296 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10297 else
10298 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10299
10300 if (! peer)
10301 return CMD_WARNING;
10302
10303 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10304 {
10305 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10306 VTY_NEWLINE);
10307 return CMD_WARNING;
10308}
10309
10310 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10311 PEER_FLAG_RSERVER_CLIENT))
10312{
10313 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10314 VTY_NEWLINE);
10315 return CMD_WARNING;
10316 }
10317
10318 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10319 (argc == 3) ? argv[2] : argv[1],
10320 AFI_IP, SAFI_UNICAST, NULL, 1);
10321}
10322
10323ALIAS (show_ip_bgp_view_rsclient_prefix,
10324 show_ip_bgp_rsclient_prefix_cmd,
10325 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10326 SHOW_STR
10327 IP_STR
10328 BGP_STR
10329 "Information about Route Server Client\n"
10330 NEIGHBOR_ADDR_STR
10331 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10332
10333
paul718e3742002-12-13 20:15:29 +000010334#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010335DEFUN (show_bgp_view_neighbor_routes,
10336 show_bgp_view_neighbor_routes_cmd,
10337 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10338 SHOW_STR
10339 BGP_STR
10340 "BGP view\n"
10341 "BGP view name\n"
10342 "Detailed information on TCP and BGP neighbor connections\n"
10343 "Neighbor to display information about\n"
10344 "Neighbor to display information about\n"
10345 "Display routes learned from neighbor\n")
10346{
10347 struct peer *peer;
10348
10349 if (argc == 2)
10350 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10351 else
10352 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10353
10354 if (! peer)
10355 return CMD_WARNING;
10356
10357 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10358 bgp_show_type_neighbor);
10359}
10360
10361ALIAS (show_bgp_view_neighbor_routes,
10362 show_bgp_view_ipv6_neighbor_routes_cmd,
10363 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10364 SHOW_STR
10365 BGP_STR
10366 "BGP view\n"
10367 "BGP view name\n"
10368 "Address family\n"
10369 "Detailed information on TCP and BGP neighbor connections\n"
10370 "Neighbor to display information about\n"
10371 "Neighbor to display information about\n"
10372 "Display routes learned from neighbor\n")
10373
10374DEFUN (show_bgp_view_neighbor_damp,
10375 show_bgp_view_neighbor_damp_cmd,
10376 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10377 SHOW_STR
10378 BGP_STR
10379 "BGP view\n"
10380 "BGP view name\n"
10381 "Detailed information on TCP and BGP neighbor connections\n"
10382 "Neighbor to display information about\n"
10383 "Neighbor to display information about\n"
10384 "Display the dampened routes received from neighbor\n")
10385{
10386 struct peer *peer;
10387
10388 if (argc == 2)
10389 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10390 else
10391 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10392
10393 if (! peer)
10394 return CMD_WARNING;
10395
10396 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10397 bgp_show_type_damp_neighbor);
10398}
10399
10400ALIAS (show_bgp_view_neighbor_damp,
10401 show_bgp_view_ipv6_neighbor_damp_cmd,
10402 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10403 SHOW_STR
10404 BGP_STR
10405 "BGP view\n"
10406 "BGP view name\n"
10407 "Address family\n"
10408 "Detailed information on TCP and BGP neighbor connections\n"
10409 "Neighbor to display information about\n"
10410 "Neighbor to display information about\n"
10411 "Display the dampened routes received from neighbor\n")
10412
10413DEFUN (show_bgp_view_neighbor_flap,
10414 show_bgp_view_neighbor_flap_cmd,
10415 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10416 SHOW_STR
10417 BGP_STR
10418 "BGP view\n"
10419 "BGP view name\n"
10420 "Detailed information on TCP and BGP neighbor connections\n"
10421 "Neighbor to display information about\n"
10422 "Neighbor to display information about\n"
10423 "Display flap statistics of the routes learned from neighbor\n")
10424{
10425 struct peer *peer;
10426
10427 if (argc == 2)
10428 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10429 else
10430 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10431
10432 if (! peer)
10433 return CMD_WARNING;
10434
10435 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10436 bgp_show_type_flap_neighbor);
10437}
10438
10439ALIAS (show_bgp_view_neighbor_flap,
10440 show_bgp_view_ipv6_neighbor_flap_cmd,
10441 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10442 SHOW_STR
10443 BGP_STR
10444 "BGP view\n"
10445 "BGP view name\n"
10446 "Address family\n"
10447 "Detailed information on TCP and BGP neighbor connections\n"
10448 "Neighbor to display information about\n"
10449 "Neighbor to display information about\n"
10450 "Display flap statistics of the routes learned from neighbor\n")
10451
10452ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010453 show_bgp_neighbor_routes_cmd,
10454 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10455 SHOW_STR
10456 BGP_STR
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 routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010461
paulbb46e942003-10-24 19:02:03 +000010462
10463ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010464 show_bgp_ipv6_neighbor_routes_cmd,
10465 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10466 SHOW_STR
10467 BGP_STR
10468 "Address family\n"
10469 "Detailed information on TCP and BGP neighbor connections\n"
10470 "Neighbor to display information about\n"
10471 "Neighbor to display information about\n"
10472 "Display routes learned from neighbor\n")
10473
10474/* old command */
paulbb46e942003-10-24 19:02:03 +000010475ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010476 ipv6_bgp_neighbor_routes_cmd,
10477 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10478 SHOW_STR
10479 IPV6_STR
10480 BGP_STR
10481 "Detailed information on TCP and BGP neighbor connections\n"
10482 "Neighbor to display information about\n"
10483 "Neighbor to display information about\n"
10484 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010485
10486/* old command */
10487DEFUN (ipv6_mbgp_neighbor_routes,
10488 ipv6_mbgp_neighbor_routes_cmd,
10489 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10490 SHOW_STR
10491 IPV6_STR
10492 MBGP_STR
10493 "Detailed information on TCP and BGP neighbor connections\n"
10494 "Neighbor to display information about\n"
10495 "Neighbor to display information about\n"
10496 "Display routes learned from neighbor\n")
10497{
paulbb46e942003-10-24 19:02:03 +000010498 struct peer *peer;
10499
10500 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10501 if (! peer)
10502 return CMD_WARNING;
10503
10504 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010505 bgp_show_type_neighbor);
10506}
paulbb46e942003-10-24 19:02:03 +000010507
10508ALIAS (show_bgp_view_neighbor_flap,
10509 show_bgp_neighbor_flap_cmd,
10510 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10511 SHOW_STR
10512 BGP_STR
10513 "Detailed information on TCP and BGP neighbor connections\n"
10514 "Neighbor to display information about\n"
10515 "Neighbor to display information about\n"
10516 "Display flap statistics of the routes learned from neighbor\n")
10517
10518ALIAS (show_bgp_view_neighbor_flap,
10519 show_bgp_ipv6_neighbor_flap_cmd,
10520 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10521 SHOW_STR
10522 BGP_STR
10523 "Address family\n"
10524 "Detailed information on TCP and BGP neighbor connections\n"
10525 "Neighbor to display information about\n"
10526 "Neighbor to display information about\n"
10527 "Display flap statistics of the routes learned from neighbor\n")
10528
10529ALIAS (show_bgp_view_neighbor_damp,
10530 show_bgp_neighbor_damp_cmd,
10531 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10532 SHOW_STR
10533 BGP_STR
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 the dampened routes received from neighbor\n")
10538
10539ALIAS (show_bgp_view_neighbor_damp,
10540 show_bgp_ipv6_neighbor_damp_cmd,
10541 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10542 SHOW_STR
10543 BGP_STR
10544 "Address family\n"
10545 "Detailed information on TCP and BGP neighbor connections\n"
10546 "Neighbor to display information about\n"
10547 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010548 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010549
10550DEFUN (show_bgp_view_rsclient,
10551 show_bgp_view_rsclient_cmd,
10552 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10553 SHOW_STR
10554 BGP_STR
10555 "BGP view\n"
10556 "BGP view name\n"
10557 "Information about Route Server Client\n"
10558 NEIGHBOR_ADDR_STR)
10559{
10560 struct bgp_table *table;
10561 struct peer *peer;
10562
10563 if (argc == 2)
10564 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10565 else
10566 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10567
10568 if (! peer)
10569 return CMD_WARNING;
10570
10571 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10572 {
10573 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10574 VTY_NEWLINE);
10575 return CMD_WARNING;
10576 }
10577
10578 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10579 PEER_FLAG_RSERVER_CLIENT))
10580 {
10581 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10582 VTY_NEWLINE);
10583 return CMD_WARNING;
10584 }
10585
10586 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10587
ajs5a646652004-11-05 01:25:55 +000010588 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010589}
10590
10591ALIAS (show_bgp_view_rsclient,
10592 show_bgp_rsclient_cmd,
10593 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10594 SHOW_STR
10595 BGP_STR
10596 "Information about Route Server Client\n"
10597 NEIGHBOR_ADDR_STR)
10598
10599DEFUN (show_bgp_view_rsclient_route,
10600 show_bgp_view_rsclient_route_cmd,
10601 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10602 SHOW_STR
10603 BGP_STR
10604 "BGP view\n"
10605 "BGP view name\n"
10606 "Information about Route Server Client\n"
10607 NEIGHBOR_ADDR_STR
10608 "Network in the BGP routing table to display\n")
10609{
10610 struct bgp *bgp;
10611 struct peer *peer;
10612
10613 /* BGP structure lookup. */
10614 if (argc == 3)
10615 {
10616 bgp = bgp_lookup_by_name (argv[0]);
10617 if (bgp == NULL)
10618 {
10619 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10620 return CMD_WARNING;
10621 }
10622 }
10623 else
10624 {
10625 bgp = bgp_get_default ();
10626 if (bgp == NULL)
10627 {
10628 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10629 return CMD_WARNING;
10630 }
10631 }
10632
10633 if (argc == 3)
10634 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10635 else
10636 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10637
10638 if (! peer)
10639 return CMD_WARNING;
10640
10641 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10642 {
10643 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10644 VTY_NEWLINE);
10645 return CMD_WARNING;
10646 }
10647
10648 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10649 PEER_FLAG_RSERVER_CLIENT))
10650 {
10651 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10652 VTY_NEWLINE);
10653 return CMD_WARNING;
10654 }
10655
10656 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10657 (argc == 3) ? argv[2] : argv[1],
10658 AFI_IP6, SAFI_UNICAST, NULL, 0);
10659}
10660
10661ALIAS (show_bgp_view_rsclient_route,
10662 show_bgp_rsclient_route_cmd,
10663 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10664 SHOW_STR
10665 BGP_STR
10666 "Information about Route Server Client\n"
10667 NEIGHBOR_ADDR_STR
10668 "Network in the BGP routing table to display\n")
10669
10670DEFUN (show_bgp_view_rsclient_prefix,
10671 show_bgp_view_rsclient_prefix_cmd,
10672 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10673 SHOW_STR
10674 BGP_STR
10675 "BGP view\n"
10676 "BGP view name\n"
10677 "Information about Route Server Client\n"
10678 NEIGHBOR_ADDR_STR
10679 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10680{
10681 struct bgp *bgp;
10682 struct peer *peer;
10683
10684 /* BGP structure lookup. */
10685 if (argc == 3)
10686 {
10687 bgp = bgp_lookup_by_name (argv[0]);
10688 if (bgp == NULL)
10689 {
10690 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10691 return CMD_WARNING;
10692 }
10693 }
10694 else
10695 {
10696 bgp = bgp_get_default ();
10697 if (bgp == NULL)
10698 {
10699 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10700 return CMD_WARNING;
10701 }
10702 }
10703
10704 if (argc == 3)
10705 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10706 else
10707 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10708
10709 if (! peer)
10710 return CMD_WARNING;
10711
10712 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10713 {
10714 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10715 VTY_NEWLINE);
10716 return CMD_WARNING;
10717 }
10718
10719 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10720 PEER_FLAG_RSERVER_CLIENT))
10721 {
10722 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10723 VTY_NEWLINE);
10724 return CMD_WARNING;
10725 }
10726
10727 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10728 (argc == 3) ? argv[2] : argv[1],
10729 AFI_IP6, SAFI_UNICAST, NULL, 1);
10730}
10731
10732ALIAS (show_bgp_view_rsclient_prefix,
10733 show_bgp_rsclient_prefix_cmd,
10734 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10735 SHOW_STR
10736 BGP_STR
10737 "Information about Route Server Client\n"
10738 NEIGHBOR_ADDR_STR
10739 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10740
paul718e3742002-12-13 20:15:29 +000010741#endif /* HAVE_IPV6 */
10742
10743struct bgp_table *bgp_distance_table;
10744
10745struct bgp_distance
10746{
10747 /* Distance value for the IP source prefix. */
10748 u_char distance;
10749
10750 /* Name of the access-list to be matched. */
10751 char *access_list;
10752};
10753
paul94f2b392005-06-28 12:44:16 +000010754static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010755bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010756{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010757 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010758}
10759
paul94f2b392005-06-28 12:44:16 +000010760static void
paul718e3742002-12-13 20:15:29 +000010761bgp_distance_free (struct bgp_distance *bdistance)
10762{
10763 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10764}
10765
paul94f2b392005-06-28 12:44:16 +000010766static int
paulfd79ac92004-10-13 05:06:08 +000010767bgp_distance_set (struct vty *vty, const char *distance_str,
10768 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010769{
10770 int ret;
10771 struct prefix_ipv4 p;
10772 u_char distance;
10773 struct bgp_node *rn;
10774 struct bgp_distance *bdistance;
10775
10776 ret = str2prefix_ipv4 (ip_str, &p);
10777 if (ret == 0)
10778 {
10779 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10780 return CMD_WARNING;
10781 }
10782
10783 distance = atoi (distance_str);
10784
10785 /* Get BGP distance node. */
10786 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10787 if (rn->info)
10788 {
10789 bdistance = rn->info;
10790 bgp_unlock_node (rn);
10791 }
10792 else
10793 {
10794 bdistance = bgp_distance_new ();
10795 rn->info = bdistance;
10796 }
10797
10798 /* Set distance value. */
10799 bdistance->distance = distance;
10800
10801 /* Reset access-list configuration. */
10802 if (bdistance->access_list)
10803 {
10804 free (bdistance->access_list);
10805 bdistance->access_list = NULL;
10806 }
10807 if (access_list_str)
10808 bdistance->access_list = strdup (access_list_str);
10809
10810 return CMD_SUCCESS;
10811}
10812
paul94f2b392005-06-28 12:44:16 +000010813static int
paulfd79ac92004-10-13 05:06:08 +000010814bgp_distance_unset (struct vty *vty, const char *distance_str,
10815 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010816{
10817 int ret;
10818 struct prefix_ipv4 p;
10819 u_char distance;
10820 struct bgp_node *rn;
10821 struct bgp_distance *bdistance;
10822
10823 ret = str2prefix_ipv4 (ip_str, &p);
10824 if (ret == 0)
10825 {
10826 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10827 return CMD_WARNING;
10828 }
10829
10830 distance = atoi (distance_str);
10831
10832 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10833 if (! rn)
10834 {
10835 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10836 return CMD_WARNING;
10837 }
10838
10839 bdistance = rn->info;
10840
10841 if (bdistance->access_list)
10842 free (bdistance->access_list);
10843 bgp_distance_free (bdistance);
10844
10845 rn->info = NULL;
10846 bgp_unlock_node (rn);
10847 bgp_unlock_node (rn);
10848
10849 return CMD_SUCCESS;
10850}
10851
paul718e3742002-12-13 20:15:29 +000010852/* Apply BGP information to distance method. */
10853u_char
10854bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10855{
10856 struct bgp_node *rn;
10857 struct prefix_ipv4 q;
10858 struct peer *peer;
10859 struct bgp_distance *bdistance;
10860 struct access_list *alist;
10861 struct bgp_static *bgp_static;
10862
10863 if (! bgp)
10864 return 0;
10865
10866 if (p->family != AF_INET)
10867 return 0;
10868
10869 peer = rinfo->peer;
10870
10871 if (peer->su.sa.sa_family != AF_INET)
10872 return 0;
10873
10874 memset (&q, 0, sizeof (struct prefix_ipv4));
10875 q.family = AF_INET;
10876 q.prefix = peer->su.sin.sin_addr;
10877 q.prefixlen = IPV4_MAX_BITLEN;
10878
10879 /* Check source address. */
10880 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10881 if (rn)
10882 {
10883 bdistance = rn->info;
10884 bgp_unlock_node (rn);
10885
10886 if (bdistance->access_list)
10887 {
10888 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10889 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10890 return bdistance->distance;
10891 }
10892 else
10893 return bdistance->distance;
10894 }
10895
10896 /* Backdoor check. */
10897 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10898 if (rn)
10899 {
10900 bgp_static = rn->info;
10901 bgp_unlock_node (rn);
10902
10903 if (bgp_static->backdoor)
10904 {
10905 if (bgp->distance_local)
10906 return bgp->distance_local;
10907 else
10908 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10909 }
10910 }
10911
10912 if (peer_sort (peer) == BGP_PEER_EBGP)
10913 {
10914 if (bgp->distance_ebgp)
10915 return bgp->distance_ebgp;
10916 return ZEBRA_EBGP_DISTANCE_DEFAULT;
10917 }
10918 else
10919 {
10920 if (bgp->distance_ibgp)
10921 return bgp->distance_ibgp;
10922 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10923 }
10924}
10925
10926DEFUN (bgp_distance,
10927 bgp_distance_cmd,
10928 "distance bgp <1-255> <1-255> <1-255>",
10929 "Define an administrative distance\n"
10930 "BGP distance\n"
10931 "Distance for routes external to the AS\n"
10932 "Distance for routes internal to the AS\n"
10933 "Distance for local routes\n")
10934{
10935 struct bgp *bgp;
10936
10937 bgp = vty->index;
10938
10939 bgp->distance_ebgp = atoi (argv[0]);
10940 bgp->distance_ibgp = atoi (argv[1]);
10941 bgp->distance_local = atoi (argv[2]);
10942 return CMD_SUCCESS;
10943}
10944
10945DEFUN (no_bgp_distance,
10946 no_bgp_distance_cmd,
10947 "no distance bgp <1-255> <1-255> <1-255>",
10948 NO_STR
10949 "Define an administrative distance\n"
10950 "BGP distance\n"
10951 "Distance for routes external to the AS\n"
10952 "Distance for routes internal to the AS\n"
10953 "Distance for local routes\n")
10954{
10955 struct bgp *bgp;
10956
10957 bgp = vty->index;
10958
10959 bgp->distance_ebgp= 0;
10960 bgp->distance_ibgp = 0;
10961 bgp->distance_local = 0;
10962 return CMD_SUCCESS;
10963}
10964
10965ALIAS (no_bgp_distance,
10966 no_bgp_distance2_cmd,
10967 "no distance bgp",
10968 NO_STR
10969 "Define an administrative distance\n"
10970 "BGP distance\n")
10971
10972DEFUN (bgp_distance_source,
10973 bgp_distance_source_cmd,
10974 "distance <1-255> A.B.C.D/M",
10975 "Define an administrative distance\n"
10976 "Administrative distance\n"
10977 "IP source prefix\n")
10978{
10979 bgp_distance_set (vty, argv[0], argv[1], NULL);
10980 return CMD_SUCCESS;
10981}
10982
10983DEFUN (no_bgp_distance_source,
10984 no_bgp_distance_source_cmd,
10985 "no distance <1-255> A.B.C.D/M",
10986 NO_STR
10987 "Define an administrative distance\n"
10988 "Administrative distance\n"
10989 "IP source prefix\n")
10990{
10991 bgp_distance_unset (vty, argv[0], argv[1], NULL);
10992 return CMD_SUCCESS;
10993}
10994
10995DEFUN (bgp_distance_source_access_list,
10996 bgp_distance_source_access_list_cmd,
10997 "distance <1-255> A.B.C.D/M WORD",
10998 "Define an administrative distance\n"
10999 "Administrative distance\n"
11000 "IP source prefix\n"
11001 "Access list name\n")
11002{
11003 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11004 return CMD_SUCCESS;
11005}
11006
11007DEFUN (no_bgp_distance_source_access_list,
11008 no_bgp_distance_source_access_list_cmd,
11009 "no distance <1-255> A.B.C.D/M WORD",
11010 NO_STR
11011 "Define an administrative distance\n"
11012 "Administrative distance\n"
11013 "IP source prefix\n"
11014 "Access list name\n")
11015{
11016 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11017 return CMD_SUCCESS;
11018}
11019
11020DEFUN (bgp_damp_set,
11021 bgp_damp_set_cmd,
11022 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11023 "BGP Specific commands\n"
11024 "Enable route-flap dampening\n"
11025 "Half-life time for the penalty\n"
11026 "Value to start reusing a route\n"
11027 "Value to start suppressing a route\n"
11028 "Maximum duration to suppress a stable route\n")
11029{
11030 struct bgp *bgp;
11031 int half = DEFAULT_HALF_LIFE * 60;
11032 int reuse = DEFAULT_REUSE;
11033 int suppress = DEFAULT_SUPPRESS;
11034 int max = 4 * half;
11035
11036 if (argc == 4)
11037 {
11038 half = atoi (argv[0]) * 60;
11039 reuse = atoi (argv[1]);
11040 suppress = atoi (argv[2]);
11041 max = atoi (argv[3]) * 60;
11042 }
11043 else if (argc == 1)
11044 {
11045 half = atoi (argv[0]) * 60;
11046 max = 4 * half;
11047 }
11048
11049 bgp = vty->index;
11050 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11051 half, reuse, suppress, max);
11052}
11053
11054ALIAS (bgp_damp_set,
11055 bgp_damp_set2_cmd,
11056 "bgp dampening <1-45>",
11057 "BGP Specific commands\n"
11058 "Enable route-flap dampening\n"
11059 "Half-life time for the penalty\n")
11060
11061ALIAS (bgp_damp_set,
11062 bgp_damp_set3_cmd,
11063 "bgp dampening",
11064 "BGP Specific commands\n"
11065 "Enable route-flap dampening\n")
11066
11067DEFUN (bgp_damp_unset,
11068 bgp_damp_unset_cmd,
11069 "no bgp dampening",
11070 NO_STR
11071 "BGP Specific commands\n"
11072 "Enable route-flap dampening\n")
11073{
11074 struct bgp *bgp;
11075
11076 bgp = vty->index;
11077 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11078}
11079
11080ALIAS (bgp_damp_unset,
11081 bgp_damp_unset2_cmd,
11082 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11083 NO_STR
11084 "BGP Specific commands\n"
11085 "Enable route-flap dampening\n"
11086 "Half-life time for the penalty\n"
11087 "Value to start reusing a route\n"
11088 "Value to start suppressing a route\n"
11089 "Maximum duration to suppress a stable route\n")
11090
11091DEFUN (show_ip_bgp_dampened_paths,
11092 show_ip_bgp_dampened_paths_cmd,
11093 "show ip bgp dampened-paths",
11094 SHOW_STR
11095 IP_STR
11096 BGP_STR
11097 "Display paths suppressed due to dampening\n")
11098{
ajs5a646652004-11-05 01:25:55 +000011099 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11100 NULL);
paul718e3742002-12-13 20:15:29 +000011101}
11102
11103DEFUN (show_ip_bgp_flap_statistics,
11104 show_ip_bgp_flap_statistics_cmd,
11105 "show ip bgp flap-statistics",
11106 SHOW_STR
11107 IP_STR
11108 BGP_STR
11109 "Display flap statistics of routes\n")
11110{
ajs5a646652004-11-05 01:25:55 +000011111 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11112 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011113}
11114
11115/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011116static int
paulfd79ac92004-10-13 05:06:08 +000011117bgp_clear_damp_route (struct vty *vty, const char *view_name,
11118 const char *ip_str, afi_t afi, safi_t safi,
11119 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011120{
11121 int ret;
11122 struct prefix match;
11123 struct bgp_node *rn;
11124 struct bgp_node *rm;
11125 struct bgp_info *ri;
11126 struct bgp_info *ri_temp;
11127 struct bgp *bgp;
11128 struct bgp_table *table;
11129
11130 /* BGP structure lookup. */
11131 if (view_name)
11132 {
11133 bgp = bgp_lookup_by_name (view_name);
11134 if (bgp == NULL)
11135 {
11136 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11137 return CMD_WARNING;
11138 }
11139 }
11140 else
11141 {
11142 bgp = bgp_get_default ();
11143 if (bgp == NULL)
11144 {
11145 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11146 return CMD_WARNING;
11147 }
11148 }
11149
11150 /* Check IP address argument. */
11151 ret = str2prefix (ip_str, &match);
11152 if (! ret)
11153 {
11154 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11155 return CMD_WARNING;
11156 }
11157
11158 match.family = afi2family (afi);
11159
11160 if (safi == SAFI_MPLS_VPN)
11161 {
11162 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11163 {
11164 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11165 continue;
11166
11167 if ((table = rn->info) != NULL)
11168 if ((rm = bgp_node_match (table, &match)) != NULL)
11169 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11170 {
11171 ri = rm->info;
11172 while (ri)
11173 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011174 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011175 {
11176 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011177 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011178 ri = ri_temp;
11179 }
11180 else
11181 ri = ri->next;
11182 }
11183 }
11184 }
11185 }
11186 else
11187 {
11188 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11189 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11190 {
11191 ri = rn->info;
11192 while (ri)
11193 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011194 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011195 {
11196 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011197 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011198 ri = ri_temp;
11199 }
11200 else
11201 ri = ri->next;
11202 }
11203 }
11204 }
11205
11206 return CMD_SUCCESS;
11207}
11208
11209DEFUN (clear_ip_bgp_dampening,
11210 clear_ip_bgp_dampening_cmd,
11211 "clear ip bgp dampening",
11212 CLEAR_STR
11213 IP_STR
11214 BGP_STR
11215 "Clear route flap dampening information\n")
11216{
11217 bgp_damp_info_clean ();
11218 return CMD_SUCCESS;
11219}
11220
11221DEFUN (clear_ip_bgp_dampening_prefix,
11222 clear_ip_bgp_dampening_prefix_cmd,
11223 "clear ip bgp dampening A.B.C.D/M",
11224 CLEAR_STR
11225 IP_STR
11226 BGP_STR
11227 "Clear route flap dampening information\n"
11228 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11229{
11230 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11231 SAFI_UNICAST, NULL, 1);
11232}
11233
11234DEFUN (clear_ip_bgp_dampening_address,
11235 clear_ip_bgp_dampening_address_cmd,
11236 "clear ip bgp dampening A.B.C.D",
11237 CLEAR_STR
11238 IP_STR
11239 BGP_STR
11240 "Clear route flap dampening information\n"
11241 "Network to clear damping information\n")
11242{
11243 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11244 SAFI_UNICAST, NULL, 0);
11245}
11246
11247DEFUN (clear_ip_bgp_dampening_address_mask,
11248 clear_ip_bgp_dampening_address_mask_cmd,
11249 "clear ip bgp dampening A.B.C.D A.B.C.D",
11250 CLEAR_STR
11251 IP_STR
11252 BGP_STR
11253 "Clear route flap dampening information\n"
11254 "Network to clear damping information\n"
11255 "Network mask\n")
11256{
11257 int ret;
11258 char prefix_str[BUFSIZ];
11259
11260 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11261 if (! ret)
11262 {
11263 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11264 return CMD_WARNING;
11265 }
11266
11267 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11268 SAFI_UNICAST, NULL, 0);
11269}
11270
paul94f2b392005-06-28 12:44:16 +000011271static int
paul718e3742002-12-13 20:15:29 +000011272bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11273 afi_t afi, safi_t safi, int *write)
11274{
11275 struct bgp_node *prn;
11276 struct bgp_node *rn;
11277 struct bgp_table *table;
11278 struct prefix *p;
11279 struct prefix_rd *prd;
11280 struct bgp_static *bgp_static;
11281 u_int32_t label;
11282 char buf[SU_ADDRSTRLEN];
11283 char rdbuf[RD_ADDRSTRLEN];
11284
11285 /* Network configuration. */
11286 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11287 if ((table = prn->info) != NULL)
11288 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11289 if ((bgp_static = rn->info) != NULL)
11290 {
11291 p = &rn->p;
11292 prd = (struct prefix_rd *) &prn->p;
11293
11294 /* "address-family" display. */
11295 bgp_config_write_family_header (vty, afi, safi, write);
11296
11297 /* "network" configuration display. */
11298 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11299 label = decode_label (bgp_static->tag);
11300
11301 vty_out (vty, " network %s/%d rd %s tag %d",
11302 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11303 p->prefixlen,
11304 rdbuf, label);
11305 vty_out (vty, "%s", VTY_NEWLINE);
11306 }
11307 return 0;
11308}
11309
11310/* Configuration of static route announcement and aggregate
11311 information. */
11312int
11313bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11314 afi_t afi, safi_t safi, int *write)
11315{
11316 struct bgp_node *rn;
11317 struct prefix *p;
11318 struct bgp_static *bgp_static;
11319 struct bgp_aggregate *bgp_aggregate;
11320 char buf[SU_ADDRSTRLEN];
11321
11322 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11323 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11324
11325 /* Network configuration. */
11326 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11327 if ((bgp_static = rn->info) != NULL)
11328 {
11329 p = &rn->p;
11330
11331 /* "address-family" display. */
11332 bgp_config_write_family_header (vty, afi, safi, write);
11333
11334 /* "network" configuration display. */
11335 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11336 {
11337 u_int32_t destination;
11338 struct in_addr netmask;
11339
11340 destination = ntohl (p->u.prefix4.s_addr);
11341 masklen2ip (p->prefixlen, &netmask);
11342 vty_out (vty, " network %s",
11343 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11344
11345 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11346 || (IN_CLASSB (destination) && p->prefixlen == 16)
11347 || (IN_CLASSA (destination) && p->prefixlen == 8)
11348 || p->u.prefix4.s_addr == 0)
11349 {
11350 /* Natural mask is not display. */
11351 }
11352 else
11353 vty_out (vty, " mask %s", inet_ntoa (netmask));
11354 }
11355 else
11356 {
11357 vty_out (vty, " network %s/%d",
11358 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11359 p->prefixlen);
11360 }
11361
11362 if (bgp_static->rmap.name)
11363 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011364 else
11365 {
11366 if (bgp_static->backdoor)
11367 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000011368 }
paul718e3742002-12-13 20:15:29 +000011369
11370 vty_out (vty, "%s", VTY_NEWLINE);
11371 }
11372
11373 /* Aggregate-address configuration. */
11374 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11375 if ((bgp_aggregate = rn->info) != NULL)
11376 {
11377 p = &rn->p;
11378
11379 /* "address-family" display. */
11380 bgp_config_write_family_header (vty, afi, safi, write);
11381
11382 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11383 {
11384 struct in_addr netmask;
11385
11386 masklen2ip (p->prefixlen, &netmask);
11387 vty_out (vty, " aggregate-address %s %s",
11388 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11389 inet_ntoa (netmask));
11390 }
11391 else
11392 {
11393 vty_out (vty, " aggregate-address %s/%d",
11394 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11395 p->prefixlen);
11396 }
11397
11398 if (bgp_aggregate->as_set)
11399 vty_out (vty, " as-set");
11400
11401 if (bgp_aggregate->summary_only)
11402 vty_out (vty, " summary-only");
11403
11404 vty_out (vty, "%s", VTY_NEWLINE);
11405 }
11406
11407 return 0;
11408}
11409
11410int
11411bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11412{
11413 struct bgp_node *rn;
11414 struct bgp_distance *bdistance;
11415
11416 /* Distance configuration. */
11417 if (bgp->distance_ebgp
11418 && bgp->distance_ibgp
11419 && bgp->distance_local
11420 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11421 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11422 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11423 vty_out (vty, " distance bgp %d %d %d%s",
11424 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11425 VTY_NEWLINE);
11426
11427 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11428 if ((bdistance = rn->info) != NULL)
11429 {
11430 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11431 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11432 bdistance->access_list ? bdistance->access_list : "",
11433 VTY_NEWLINE);
11434 }
11435
11436 return 0;
11437}
11438
11439/* Allocate routing table structure and install commands. */
11440void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011441bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011442{
11443 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011444 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011445
11446 /* IPv4 BGP commands. */
11447 install_element (BGP_NODE, &bgp_network_cmd);
11448 install_element (BGP_NODE, &bgp_network_mask_cmd);
11449 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11450 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11451 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11452 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11453 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11454 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11455 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11456 install_element (BGP_NODE, &no_bgp_network_cmd);
11457 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11458 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11459 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11460 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11461 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11462 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11463 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11464 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11465
11466 install_element (BGP_NODE, &aggregate_address_cmd);
11467 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11468 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11469 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11470 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11471 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11472 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11473 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11474 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11475 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11476 install_element (BGP_NODE, &no_aggregate_address_cmd);
11477 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11478 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11479 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11480 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11481 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11482 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11483 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11484 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11485 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11486
11487 /* IPv4 unicast configuration. */
11488 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11489 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11490 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11491 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11492 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11493 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmae70e5752011-07-05 00:41:59 +040011494 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011495 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11496 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11497 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11498 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11499 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmae70e5752011-07-05 00:41:59 +040011500
paul718e3742002-12-13 20:15:29 +000011501 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11502 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11503 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11504 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11505 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11506 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11507 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11508 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11509 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11510 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11511 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11512 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11513 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11514 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11515 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11516 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11517 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11518 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11519 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11520 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11521
11522 /* IPv4 multicast configuration. */
11523 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11524 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11525 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11526 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11527 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11528 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11529 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11530 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11531 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11532 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11533 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11534 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11535 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11536 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11537 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11538 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11539 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11540 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11541 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11542 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11543 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11544 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11545 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11546 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11547 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11548 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11549 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11550 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11551 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11552 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11553 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11554 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11555
11556 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11557 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11558 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11559 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11560 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11561 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11562 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11563 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11564 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11565 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11566 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11567 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11568 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11569 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11570 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11571 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11572 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11573 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11574 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11575 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11576 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11577 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11578 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11579 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11580 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11581 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11582 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11583 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11584 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11585 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11586 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11587 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11588 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11589 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11590 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11591 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11592 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11593 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11594 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11595 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11596 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11597 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11598 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11599 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11600 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11601 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11602 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11603 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11604 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11605 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11606 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11607 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11608 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11609 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11610 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11611 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11612 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11613 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11614 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11615 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11616 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11617 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11618 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11619 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11620 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11621 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11622 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011623 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11624 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11625 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011626 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11627 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011628 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11629 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11630 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011631
11632 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11633 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11634 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11635 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11636 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11637 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11638 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11639 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11640 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11641 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11642 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11643 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11644 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11645 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11646 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11647 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11648 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11649 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11650 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11651 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11652 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11653 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11654 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11655 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11656 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11657 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11658 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11659 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11660 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11661 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011662
11663 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11664 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11665 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11666 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11667 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11668 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11669 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11670 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11671 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11672 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11673 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11674 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11675 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11676 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11677 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11678 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11679 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11680 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11681 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11682 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11683 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11684 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11686 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11687 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11688 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11689 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11690 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11691 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11692 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11693 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11694 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11695 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11696 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11697 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11698 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11699 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11700 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11701 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11702 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11703 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11704 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11705 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11706 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11707 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11708 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11709 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11710 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11711 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11712 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11713 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11714 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11715 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11716 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11717 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11718 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11719 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11720 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11721 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11722 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11723 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11724 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11725 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11726 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11727 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11728 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11729 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011730 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11731 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11732 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011733 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11734 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011735 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11736 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11737 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011738
11739 /* BGP dampening clear commands */
11740 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11741 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11742 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11743 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11744
Paul Jakmaff7924f2006-09-04 01:10:36 +000011745 /* prefix count */
11746 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11747 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11748 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011749#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011750 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11751
paul718e3742002-12-13 20:15:29 +000011752 /* New config IPv6 BGP commands. */
11753 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11754 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11755 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11756 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11757
11758 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11759 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11760 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11761 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11762
11763 /* Old config IPv6 BGP commands. */
11764 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11765 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11766
11767 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11768 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11769 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11770 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11771
11772 install_element (VIEW_NODE, &show_bgp_cmd);
11773 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11774 install_element (VIEW_NODE, &show_bgp_route_cmd);
11775 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11776 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11777 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11778 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11779 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11780 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11781 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11782 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11783 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11784 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11785 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11786 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11787 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11788 install_element (VIEW_NODE, &show_bgp_community_cmd);
11789 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11790 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11791 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11792 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11793 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11794 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11795 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11796 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11797 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11798 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11799 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11800 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11801 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11802 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11803 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11804 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11805 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11806 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11807 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11808 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11809 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11810 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11811 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11812 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11813 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11814 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11815 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11816 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11817 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011818 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11819 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11820 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11821 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011822 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11823 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11824 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011825 install_element (VIEW_NODE, &show_bgp_view_cmd);
11826 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11827 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11828 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11829 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11830 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11831 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11832 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11833 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11834 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11835 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11836 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11837 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11838 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11839 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11840 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11841 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11842 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011843 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11844 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11845 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011846
11847 /* Restricted:
11848 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
11849 */
11850 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
11851 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
11852 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
11853 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
11854 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
11855 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
11856 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
11857 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
11858 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
11859 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
11860 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
11861 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
11862 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
11863 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
11864 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
11865 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
11866 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
11867 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
11868 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
11869 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
11870 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
11871 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
11872 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
11873 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
11874 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
11875 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
11876 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11877 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11878 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
11879 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011880
11881 install_element (ENABLE_NODE, &show_bgp_cmd);
11882 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11883 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11884 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11885 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11886 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11887 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11888 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11889 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11890 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11891 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11892 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11893 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11894 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11895 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11896 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11897 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11898 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11899 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11900 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11901 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11902 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11903 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11904 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11905 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
11906 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
11907 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
11908 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
11909 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
11910 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
11911 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
11912 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
11913 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
11914 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
11915 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
11916 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11917 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
11918 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11919 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
11920 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11921 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
11922 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11923 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
11924 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11925 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11926 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011927 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
11928 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11929 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
11930 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011931 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
11932 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
11933 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011934 install_element (ENABLE_NODE, &show_bgp_view_cmd);
11935 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
11936 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
11937 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
11938 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
11939 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
11940 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11941 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11942 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11943 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11944 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
11945 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11946 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11947 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11948 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
11949 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11950 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
11951 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011952 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
11953 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
11954 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000011955
11956 /* Statistics */
11957 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
11958 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
11959 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
11960 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
11961
paul718e3742002-12-13 20:15:29 +000011962 /* old command */
11963 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
11964 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
11965 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
11966 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
11967 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
11968 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
11969 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
11970 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
11971 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
11972 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
11973 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
11974 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
11975 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
11976 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
11977 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
11978 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
11979 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11980 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11981 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
11982 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
11983 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
11984 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
11985 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11986 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
11987 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
11988 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
11989 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
11990 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
11991 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
11992 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
11993 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11994 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11995 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11996 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
11997 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11998 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000011999
paul718e3742002-12-13 20:15:29 +000012000 /* old command */
12001 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12002 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12003 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12004 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12005 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12006 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12007 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12008 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12009 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12010 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12011 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12012 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12013 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12014 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12015 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12016 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12017 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12018 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12019 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12020 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12021 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12022 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12023 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12024 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12025 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12026 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12027 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12028 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12029 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12030 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12031 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12032 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12033 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12034 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12035 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12036 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12037
12038 /* old command */
12039 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12040 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12041 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12042 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12043
12044 /* old command */
12045 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12046 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12047 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12048 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12049
12050 /* old command */
12051 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12052 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12053 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12054 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12055#endif /* HAVE_IPV6 */
12056
12057 install_element (BGP_NODE, &bgp_distance_cmd);
12058 install_element (BGP_NODE, &no_bgp_distance_cmd);
12059 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12060 install_element (BGP_NODE, &bgp_distance_source_cmd);
12061 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12062 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12063 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12064
12065 install_element (BGP_NODE, &bgp_damp_set_cmd);
12066 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12067 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12068 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12069 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12070 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12071 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12072 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12073 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12074 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmae70e5752011-07-05 00:41:59 +040012075
12076 /* Deprecated AS-Pathlimit commands */
12077 install_element (BGP_NODE, &bgp_network_ttl_cmd);
12078 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
12079 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
12080 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
12081 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12082 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12083
12084 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
12085 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
12086 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12087 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
12088 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12089 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12090
12091 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
12092 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
12093 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
12094 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
12095 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12096 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12097
12098 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
12099 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
12100 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12101 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
12102 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12103 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12104
12105 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
12106 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
12107 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
12108 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
12109 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12110 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12111
12112 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
12113 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
12114 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12115 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
12116 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12117 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakmaa8b79422011-03-23 10:30:30 +000012118
12119#ifdef HAVE_IPV6
Paul Jakmae70e5752011-07-05 00:41:59 +040012120 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
12121 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakmaa8b79422011-03-23 10:30:30 +000012122#endif
paul718e3742002-12-13 20:15:29 +000012123}
Chris Caputo228da422009-07-18 05:44:03 +000012124
12125void
12126bgp_route_finish (void)
12127{
12128 bgp_table_unlock (bgp_distance_table);
12129 bgp_distance_table = NULL;
12130}