blob: b771633069903cedc89d2e886e11bbb036e07821 [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
5241bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5242 u_int32_t metric, u_char type)
5243{
5244 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005245 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005246 struct bgp_info *new;
5247 struct bgp_info *bi;
5248 struct bgp_info info;
5249 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005250 struct attr attr = { 0 };
5251 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005252 struct attr *new_attr;
5253 afi_t afi;
5254 int ret;
5255
5256 /* Make default attribute. */
5257 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5258 if (nexthop)
5259 attr.nexthop = *nexthop;
5260
5261 attr.med = metric;
5262 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5263
paul1eb8ef22005-04-07 07:30:20 +00005264 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005265 {
5266 afi = family2afi (p->family);
5267
5268 if (bgp->redist[afi][type])
5269 {
5270 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005271 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005272
5273 if (bgp->redist_metric_flag[afi][type])
5274 attr_new.med = bgp->redist_metric[afi][type];
5275
5276 /* Apply route-map. */
5277 if (bgp->rmap[afi][type].map)
5278 {
5279 info.peer = bgp->peer_self;
5280 info.attr = &attr_new;
5281
paulfee0f4c2004-09-13 05:12:46 +00005282 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5283
paul718e3742002-12-13 20:15:29 +00005284 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5285 &info);
paulfee0f4c2004-09-13 05:12:46 +00005286
5287 bgp->peer_self->rmap_type = 0;
5288
paul718e3742002-12-13 20:15:29 +00005289 if (ret == RMAP_DENYMATCH)
5290 {
5291 /* Free uninterned attribute. */
5292 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005293 bgp_attr_extra_free (&attr_new);
5294
paul718e3742002-12-13 20:15:29 +00005295 /* Unintern original. */
5296 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005297 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005298 bgp_redistribute_delete (p, type);
5299 return;
5300 }
5301 }
5302
Paul Jakmafb982c22007-05-04 20:15:47 +00005303 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5304 afi, SAFI_UNICAST, p, NULL);
5305
paul718e3742002-12-13 20:15:29 +00005306 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005307 bgp_attr_extra_free (&attr_new);
5308
paul718e3742002-12-13 20:15:29 +00005309 for (bi = bn->info; bi; bi = bi->next)
5310 if (bi->peer == bgp->peer_self
5311 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5312 break;
5313
5314 if (bi)
5315 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005316 if (attrhash_cmp (bi->attr, new_attr) &&
5317 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005318 {
5319 bgp_attr_unintern (new_attr);
5320 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005321 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005322 bgp_unlock_node (bn);
5323 return;
5324 }
5325 else
5326 {
5327 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005328 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005329
5330 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005331 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5332 bgp_info_restore(bn, bi);
5333 else
5334 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005335 bgp_attr_unintern (bi->attr);
5336 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005337 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005338
5339 /* Process change. */
5340 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5341 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5342 bgp_unlock_node (bn);
5343 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005344 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005345 return;
5346 }
5347 }
5348
5349 new = bgp_info_new ();
5350 new->type = type;
5351 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5352 new->peer = bgp->peer_self;
5353 SET_FLAG (new->flags, BGP_INFO_VALID);
5354 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005355 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005356
5357 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5358 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005359 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005360 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5361 }
5362 }
5363
5364 /* Unintern original. */
5365 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005366 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005367}
5368
5369void
5370bgp_redistribute_delete (struct prefix *p, u_char type)
5371{
5372 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005373 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005374 afi_t afi;
5375 struct bgp_node *rn;
5376 struct bgp_info *ri;
5377
paul1eb8ef22005-04-07 07:30:20 +00005378 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005379 {
5380 afi = family2afi (p->family);
5381
5382 if (bgp->redist[afi][type])
5383 {
paulfee0f4c2004-09-13 05:12:46 +00005384 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005385
5386 for (ri = rn->info; ri; ri = ri->next)
5387 if (ri->peer == bgp->peer_self
5388 && ri->type == type)
5389 break;
5390
5391 if (ri)
5392 {
5393 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005394 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005395 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005396 }
5397 bgp_unlock_node (rn);
5398 }
5399 }
5400}
5401
5402/* Withdraw specified route type's route. */
5403void
5404bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5405{
5406 struct bgp_node *rn;
5407 struct bgp_info *ri;
5408 struct bgp_table *table;
5409
5410 table = bgp->rib[afi][SAFI_UNICAST];
5411
5412 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5413 {
5414 for (ri = rn->info; ri; ri = ri->next)
5415 if (ri->peer == bgp->peer_self
5416 && ri->type == type)
5417 break;
5418
5419 if (ri)
5420 {
5421 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005422 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005423 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005424 }
5425 }
5426}
5427
5428/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005429static void
paul718e3742002-12-13 20:15:29 +00005430route_vty_out_route (struct prefix *p, struct vty *vty)
5431{
5432 int len;
5433 u_int32_t destination;
5434 char buf[BUFSIZ];
5435
5436 if (p->family == AF_INET)
5437 {
5438 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5439 destination = ntohl (p->u.prefix4.s_addr);
5440
5441 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5442 || (IN_CLASSB (destination) && p->prefixlen == 16)
5443 || (IN_CLASSA (destination) && p->prefixlen == 8)
5444 || p->u.prefix4.s_addr == 0)
5445 {
5446 /* When mask is natural, mask is not displayed. */
5447 }
5448 else
5449 len += vty_out (vty, "/%d", p->prefixlen);
5450 }
5451 else
5452 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5453 p->prefixlen);
5454
5455 len = 17 - len;
5456 if (len < 1)
5457 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5458 else
5459 vty_out (vty, "%*s", len, " ");
5460}
5461
paul718e3742002-12-13 20:15:29 +00005462enum bgp_display_type
5463{
5464 normal_list,
5465};
5466
paulb40d9392005-08-22 22:34:41 +00005467/* Print the short form route status for a bgp_info */
5468static void
5469route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005470{
paulb40d9392005-08-22 22:34:41 +00005471 /* Route status display. */
5472 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5473 vty_out (vty, "R");
5474 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005475 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005476 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005477 vty_out (vty, "s");
5478 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5479 vty_out (vty, "*");
5480 else
5481 vty_out (vty, " ");
5482
5483 /* Selected */
5484 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5485 vty_out (vty, "h");
5486 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5487 vty_out (vty, "d");
5488 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5489 vty_out (vty, ">");
5490 else
5491 vty_out (vty, " ");
5492
5493 /* Internal route. */
5494 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5495 vty_out (vty, "i");
5496 else
paulb40d9392005-08-22 22:34:41 +00005497 vty_out (vty, " ");
5498}
5499
5500/* called from terminal list command */
5501void
5502route_vty_out (struct vty *vty, struct prefix *p,
5503 struct bgp_info *binfo, int display, safi_t safi)
5504{
5505 struct attr *attr;
5506
5507 /* short status lead text */
5508 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005509
5510 /* print prefix and mask */
5511 if (! display)
5512 route_vty_out_route (p, vty);
5513 else
5514 vty_out (vty, "%*s", 17, " ");
5515
5516 /* Print attribute */
5517 attr = binfo->attr;
5518 if (attr)
5519 {
5520 if (p->family == AF_INET)
5521 {
5522 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005523 vty_out (vty, "%-16s",
5524 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005525 else
5526 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5527 }
5528#ifdef HAVE_IPV6
5529 else if (p->family == AF_INET6)
5530 {
5531 int len;
5532 char buf[BUFSIZ];
5533
5534 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005535 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5536 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005537 len = 16 - len;
5538 if (len < 1)
5539 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5540 else
5541 vty_out (vty, "%*s", len, " ");
5542 }
5543#endif /* HAVE_IPV6 */
5544
5545 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005546 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005547 else
5548 vty_out (vty, " ");
5549
5550 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005551 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005552 else
5553 vty_out (vty, " ");
5554
Paul Jakmafb982c22007-05-04 20:15:47 +00005555 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005556
Paul Jakmab2518c12006-05-12 23:48:40 +00005557 /* Print aspath */
5558 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005559 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005560
Paul Jakmab2518c12006-05-12 23:48:40 +00005561 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005562 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005563 }
paul718e3742002-12-13 20:15:29 +00005564 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005565}
5566
5567/* called from terminal list command */
5568void
5569route_vty_out_tmp (struct vty *vty, struct prefix *p,
5570 struct attr *attr, safi_t safi)
5571{
5572 /* Route status display. */
5573 vty_out (vty, "*");
5574 vty_out (vty, ">");
5575 vty_out (vty, " ");
5576
5577 /* print prefix and mask */
5578 route_vty_out_route (p, vty);
5579
5580 /* Print attribute */
5581 if (attr)
5582 {
5583 if (p->family == AF_INET)
5584 {
5585 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005586 vty_out (vty, "%-16s",
5587 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005588 else
5589 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5590 }
5591#ifdef HAVE_IPV6
5592 else if (p->family == AF_INET6)
5593 {
5594 int len;
5595 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005596
5597 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005598
5599 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005600 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5601 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005602 len = 16 - len;
5603 if (len < 1)
5604 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5605 else
5606 vty_out (vty, "%*s", len, " ");
5607 }
5608#endif /* HAVE_IPV6 */
5609
5610 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005611 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005612 else
5613 vty_out (vty, " ");
5614
5615 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005616 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005617 else
5618 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005619
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005620 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005621
Paul Jakmab2518c12006-05-12 23:48:40 +00005622 /* Print aspath */
5623 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005624 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005625
Paul Jakmab2518c12006-05-12 23:48:40 +00005626 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005627 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005628 }
paul718e3742002-12-13 20:15:29 +00005629
5630 vty_out (vty, "%s", VTY_NEWLINE);
5631}
5632
ajs5a646652004-11-05 01:25:55 +00005633void
paul718e3742002-12-13 20:15:29 +00005634route_vty_out_tag (struct vty *vty, struct prefix *p,
5635 struct bgp_info *binfo, int display, safi_t safi)
5636{
5637 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005638 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005639
5640 if (!binfo->extra)
5641 return;
5642
paulb40d9392005-08-22 22:34:41 +00005643 /* short status lead text */
5644 route_vty_short_status_out (vty, binfo);
5645
paul718e3742002-12-13 20:15:29 +00005646 /* print prefix and mask */
5647 if (! display)
5648 route_vty_out_route (p, vty);
5649 else
5650 vty_out (vty, "%*s", 17, " ");
5651
5652 /* Print attribute */
5653 attr = binfo->attr;
5654 if (attr)
5655 {
5656 if (p->family == AF_INET)
5657 {
5658 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005659 vty_out (vty, "%-16s",
5660 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005661 else
5662 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5663 }
5664#ifdef HAVE_IPV6
5665 else if (p->family == AF_INET6)
5666 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005667 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005668 char buf[BUFSIZ];
5669 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005670 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005671 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005672 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5673 buf, BUFSIZ));
5674 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005675 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005676 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5677 buf, BUFSIZ),
5678 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5679 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005680
5681 }
5682#endif /* HAVE_IPV6 */
5683 }
5684
Paul Jakmafb982c22007-05-04 20:15:47 +00005685 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005686
5687 vty_out (vty, "notag/%d", label);
5688
5689 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005690}
5691
5692/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005693static void
paul718e3742002-12-13 20:15:29 +00005694damp_route_vty_out (struct vty *vty, struct prefix *p,
5695 struct bgp_info *binfo, int display, safi_t safi)
5696{
5697 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005698 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005699 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005700
paulb40d9392005-08-22 22:34:41 +00005701 /* short status lead text */
5702 route_vty_short_status_out (vty, binfo);
5703
paul718e3742002-12-13 20:15:29 +00005704 /* print prefix and mask */
5705 if (! display)
5706 route_vty_out_route (p, vty);
5707 else
5708 vty_out (vty, "%*s", 17, " ");
5709
5710 len = vty_out (vty, "%s", binfo->peer->host);
5711 len = 17 - len;
5712 if (len < 1)
5713 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5714 else
5715 vty_out (vty, "%*s", len, " ");
5716
Chris Caputo50aef6f2009-06-23 06:06:49 +00005717 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005718
5719 /* Print attribute */
5720 attr = binfo->attr;
5721 if (attr)
5722 {
5723 /* Print aspath */
5724 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005725 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005726
5727 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005728 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005729 }
5730 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005731}
5732
paul718e3742002-12-13 20:15:29 +00005733/* flap route */
ajs5a646652004-11-05 01:25:55 +00005734static void
paul718e3742002-12-13 20:15:29 +00005735flap_route_vty_out (struct vty *vty, struct prefix *p,
5736 struct bgp_info *binfo, int display, safi_t safi)
5737{
5738 struct attr *attr;
5739 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005740 char timebuf[BGP_UPTIME_LEN];
5741 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005742
5743 if (!binfo->extra)
5744 return;
5745
5746 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005747
paulb40d9392005-08-22 22:34:41 +00005748 /* short status lead text */
5749 route_vty_short_status_out (vty, binfo);
5750
paul718e3742002-12-13 20:15:29 +00005751 /* print prefix and mask */
5752 if (! display)
5753 route_vty_out_route (p, vty);
5754 else
5755 vty_out (vty, "%*s", 17, " ");
5756
5757 len = vty_out (vty, "%s", binfo->peer->host);
5758 len = 16 - len;
5759 if (len < 1)
5760 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5761 else
5762 vty_out (vty, "%*s", len, " ");
5763
5764 len = vty_out (vty, "%d", bdi->flap);
5765 len = 5 - len;
5766 if (len < 1)
5767 vty_out (vty, " ");
5768 else
5769 vty_out (vty, "%*s ", len, " ");
5770
5771 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5772 timebuf, BGP_UPTIME_LEN));
5773
5774 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5775 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005776 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005777 else
5778 vty_out (vty, "%*s ", 8, " ");
5779
5780 /* Print attribute */
5781 attr = binfo->attr;
5782 if (attr)
5783 {
5784 /* Print aspath */
5785 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005786 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005787
5788 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005789 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005790 }
5791 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005792}
5793
paul94f2b392005-06-28 12:44:16 +00005794static void
paul718e3742002-12-13 20:15:29 +00005795route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5796 struct bgp_info *binfo, afi_t afi, safi_t safi)
5797{
5798 char buf[INET6_ADDRSTRLEN];
5799 char buf1[BUFSIZ];
5800 struct attr *attr;
5801 int sockunion_vty_out (struct vty *, union sockunion *);
John Kempcc0b6c12011-03-18 17:52:18 +03005802#ifdef HAVE_CLOCK_MONOTONIC
5803 time_t tbuf;
5804#endif
paul718e3742002-12-13 20:15:29 +00005805
5806 attr = binfo->attr;
5807
5808 if (attr)
5809 {
5810 /* Line1 display AS-path, Aggregator */
5811 if (attr->aspath)
5812 {
5813 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005814 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005815 vty_out (vty, "Local");
5816 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005817 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005818 }
5819
paulb40d9392005-08-22 22:34:41 +00005820 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5821 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005822 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5823 vty_out (vty, ", (stale)");
5824 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005825 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005826 attr->extra->aggregator_as,
5827 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005828 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5829 vty_out (vty, ", (Received from a RR-client)");
5830 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5831 vty_out (vty, ", (Received from a RS-client)");
5832 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5833 vty_out (vty, ", (history entry)");
5834 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5835 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005836 vty_out (vty, "%s", VTY_NEWLINE);
5837
5838 /* Line2 display Next-hop, Neighbor, Router-id */
5839 if (p->family == AF_INET)
5840 {
5841 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005842 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005843 inet_ntoa (attr->nexthop));
5844 }
5845#ifdef HAVE_IPV6
5846 else
5847 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005848 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005849 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005850 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005851 buf, INET6_ADDRSTRLEN));
5852 }
5853#endif /* HAVE_IPV6 */
5854
5855 if (binfo->peer == bgp->peer_self)
5856 {
5857 vty_out (vty, " from %s ",
5858 p->family == AF_INET ? "0.0.0.0" : "::");
5859 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5860 }
5861 else
5862 {
5863 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5864 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005865 else if (binfo->extra && binfo->extra->igpmetric)
5866 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005867 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005868 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005869 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005870 else
5871 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5872 }
5873 vty_out (vty, "%s", VTY_NEWLINE);
5874
5875#ifdef HAVE_IPV6
5876 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005877 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005878 {
5879 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005880 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005881 buf, INET6_ADDRSTRLEN),
5882 VTY_NEWLINE);
5883 }
5884#endif /* HAVE_IPV6 */
5885
5886 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5887 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5888
5889 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005890 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005891
5892 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005893 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005894 else
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005895 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005896
Paul Jakmafb982c22007-05-04 20:15:47 +00005897 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuf4ac0fe2010-09-10 09:47:56 -07005898 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005899
5900 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5901 vty_out (vty, ", valid");
5902
5903 if (binfo->peer != bgp->peer_self)
5904 {
5905 if (binfo->peer->as == binfo->peer->local_as)
5906 vty_out (vty, ", internal");
5907 else
5908 vty_out (vty, ", %s",
5909 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5910 }
5911 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5912 vty_out (vty, ", aggregated, local");
5913 else if (binfo->type != ZEBRA_ROUTE_BGP)
5914 vty_out (vty, ", sourced");
5915 else
5916 vty_out (vty, ", sourced, local");
5917
5918 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5919 vty_out (vty, ", atomic-aggregate");
5920
5921 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5922 vty_out (vty, ", best");
5923
5924 vty_out (vty, "%s", VTY_NEWLINE);
5925
5926 /* Line 4 display Community */
5927 if (attr->community)
5928 vty_out (vty, " Community: %s%s", attr->community->str,
5929 VTY_NEWLINE);
5930
5931 /* Line 5 display Extended-community */
5932 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00005933 vty_out (vty, " Extended Community: %s%s",
5934 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005935
5936 /* Line 6 display Originator, Cluster-id */
5937 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5938 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5939 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005940 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005941 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005942 vty_out (vty, " Originator: %s",
5943 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005944
5945 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
5946 {
5947 int i;
5948 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005949 for (i = 0; i < attr->extra->cluster->length / 4; i++)
5950 vty_out (vty, "%s ",
5951 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00005952 }
5953 vty_out (vty, "%s", VTY_NEWLINE);
5954 }
Paul Jakma41367172007-08-06 15:24:51 +00005955
Paul Jakmafb982c22007-05-04 20:15:47 +00005956 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00005957 bgp_damp_info_vty (vty, binfo);
5958
5959 /* Line 7 display Uptime */
John Kempcc0b6c12011-03-18 17:52:18 +03005960#ifdef HAVE_CLOCK_MONOTONIC
5961 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04005962 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kempcc0b6c12011-03-18 17:52:18 +03005963#else
5964 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
5965#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00005966 }
5967 vty_out (vty, "%s", VTY_NEWLINE);
5968}
5969
paulb40d9392005-08-22 22:34:41 +00005970#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 +00005971#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00005972#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
5973#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
5974#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
5975
5976enum bgp_show_type
5977{
5978 bgp_show_type_normal,
5979 bgp_show_type_regexp,
5980 bgp_show_type_prefix_list,
5981 bgp_show_type_filter_list,
5982 bgp_show_type_route_map,
5983 bgp_show_type_neighbor,
5984 bgp_show_type_cidr_only,
5985 bgp_show_type_prefix_longer,
5986 bgp_show_type_community_all,
5987 bgp_show_type_community,
5988 bgp_show_type_community_exact,
5989 bgp_show_type_community_list,
5990 bgp_show_type_community_list_exact,
5991 bgp_show_type_flap_statistics,
5992 bgp_show_type_flap_address,
5993 bgp_show_type_flap_prefix,
5994 bgp_show_type_flap_cidr_only,
5995 bgp_show_type_flap_regexp,
5996 bgp_show_type_flap_filter_list,
5997 bgp_show_type_flap_prefix_list,
5998 bgp_show_type_flap_prefix_longer,
5999 bgp_show_type_flap_route_map,
6000 bgp_show_type_flap_neighbor,
6001 bgp_show_type_dampend_paths,
6002 bgp_show_type_damp_neighbor
6003};
6004
ajs5a646652004-11-05 01:25:55 +00006005static int
paulfee0f4c2004-09-13 05:12:46 +00006006bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006007 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006008{
paul718e3742002-12-13 20:15:29 +00006009 struct bgp_info *ri;
6010 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006011 int header = 1;
paul718e3742002-12-13 20:15:29 +00006012 int display;
ajs5a646652004-11-05 01:25:55 +00006013 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006014
6015 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006016 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006017
paul718e3742002-12-13 20:15:29 +00006018 /* Start processing of routes. */
6019 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6020 if (rn->info != NULL)
6021 {
6022 display = 0;
6023
6024 for (ri = rn->info; ri; ri = ri->next)
6025 {
ajs5a646652004-11-05 01:25:55 +00006026 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006027 || type == bgp_show_type_flap_address
6028 || type == bgp_show_type_flap_prefix
6029 || type == bgp_show_type_flap_cidr_only
6030 || type == bgp_show_type_flap_regexp
6031 || type == bgp_show_type_flap_filter_list
6032 || type == bgp_show_type_flap_prefix_list
6033 || type == bgp_show_type_flap_prefix_longer
6034 || type == bgp_show_type_flap_route_map
6035 || type == bgp_show_type_flap_neighbor
6036 || type == bgp_show_type_dampend_paths
6037 || type == bgp_show_type_damp_neighbor)
6038 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006039 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006040 continue;
6041 }
6042 if (type == bgp_show_type_regexp
6043 || type == bgp_show_type_flap_regexp)
6044 {
ajs5a646652004-11-05 01:25:55 +00006045 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006046
6047 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6048 continue;
6049 }
6050 if (type == bgp_show_type_prefix_list
6051 || type == bgp_show_type_flap_prefix_list)
6052 {
ajs5a646652004-11-05 01:25:55 +00006053 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006054
6055 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6056 continue;
6057 }
6058 if (type == bgp_show_type_filter_list
6059 || type == bgp_show_type_flap_filter_list)
6060 {
ajs5a646652004-11-05 01:25:55 +00006061 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006062
6063 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6064 continue;
6065 }
6066 if (type == bgp_show_type_route_map
6067 || type == bgp_show_type_flap_route_map)
6068 {
ajs5a646652004-11-05 01:25:55 +00006069 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006070 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006071 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006072 int ret;
6073
Paul Jakmafb982c22007-05-04 20:15:47 +00006074 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006075 binfo.peer = ri->peer;
6076 binfo.attr = &dummy_attr;
6077
6078 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006079
6080 bgp_attr_extra_free (&dummy_attr);
6081
paul718e3742002-12-13 20:15:29 +00006082 if (ret == RMAP_DENYMATCH)
6083 continue;
6084 }
6085 if (type == bgp_show_type_neighbor
6086 || type == bgp_show_type_flap_neighbor
6087 || type == bgp_show_type_damp_neighbor)
6088 {
ajs5a646652004-11-05 01:25:55 +00006089 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006090
6091 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6092 continue;
6093 }
6094 if (type == bgp_show_type_cidr_only
6095 || type == bgp_show_type_flap_cidr_only)
6096 {
6097 u_int32_t destination;
6098
6099 destination = ntohl (rn->p.u.prefix4.s_addr);
6100 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6101 continue;
6102 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6103 continue;
6104 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6105 continue;
6106 }
6107 if (type == bgp_show_type_prefix_longer
6108 || type == bgp_show_type_flap_prefix_longer)
6109 {
ajs5a646652004-11-05 01:25:55 +00006110 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006111
6112 if (! prefix_match (p, &rn->p))
6113 continue;
6114 }
6115 if (type == bgp_show_type_community_all)
6116 {
6117 if (! ri->attr->community)
6118 continue;
6119 }
6120 if (type == bgp_show_type_community)
6121 {
ajs5a646652004-11-05 01:25:55 +00006122 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006123
6124 if (! ri->attr->community ||
6125 ! community_match (ri->attr->community, com))
6126 continue;
6127 }
6128 if (type == bgp_show_type_community_exact)
6129 {
ajs5a646652004-11-05 01:25:55 +00006130 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006131
6132 if (! ri->attr->community ||
6133 ! community_cmp (ri->attr->community, com))
6134 continue;
6135 }
6136 if (type == bgp_show_type_community_list)
6137 {
ajs5a646652004-11-05 01:25:55 +00006138 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006139
6140 if (! community_list_match (ri->attr->community, list))
6141 continue;
6142 }
6143 if (type == bgp_show_type_community_list_exact)
6144 {
ajs5a646652004-11-05 01:25:55 +00006145 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006146
6147 if (! community_list_exact_match (ri->attr->community, list))
6148 continue;
6149 }
6150 if (type == bgp_show_type_flap_address
6151 || type == bgp_show_type_flap_prefix)
6152 {
ajs5a646652004-11-05 01:25:55 +00006153 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006154
6155 if (! prefix_match (&rn->p, p))
6156 continue;
6157
6158 if (type == bgp_show_type_flap_prefix)
6159 if (p->prefixlen != rn->p.prefixlen)
6160 continue;
6161 }
6162 if (type == bgp_show_type_dampend_paths
6163 || type == bgp_show_type_damp_neighbor)
6164 {
6165 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6166 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6167 continue;
6168 }
6169
6170 if (header)
6171 {
hasso93406d82005-02-02 14:40:33 +00006172 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6173 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6174 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006175 if (type == bgp_show_type_dampend_paths
6176 || type == bgp_show_type_damp_neighbor)
6177 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6178 else if (type == bgp_show_type_flap_statistics
6179 || type == bgp_show_type_flap_address
6180 || type == bgp_show_type_flap_prefix
6181 || type == bgp_show_type_flap_cidr_only
6182 || type == bgp_show_type_flap_regexp
6183 || type == bgp_show_type_flap_filter_list
6184 || type == bgp_show_type_flap_prefix_list
6185 || type == bgp_show_type_flap_prefix_longer
6186 || type == bgp_show_type_flap_route_map
6187 || type == bgp_show_type_flap_neighbor)
6188 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6189 else
6190 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006191 header = 0;
6192 }
6193
6194 if (type == bgp_show_type_dampend_paths
6195 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006196 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006197 else if (type == bgp_show_type_flap_statistics
6198 || type == bgp_show_type_flap_address
6199 || type == bgp_show_type_flap_prefix
6200 || type == bgp_show_type_flap_cidr_only
6201 || type == bgp_show_type_flap_regexp
6202 || type == bgp_show_type_flap_filter_list
6203 || type == bgp_show_type_flap_prefix_list
6204 || type == bgp_show_type_flap_prefix_longer
6205 || type == bgp_show_type_flap_route_map
6206 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006207 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006208 else
ajs5a646652004-11-05 01:25:55 +00006209 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006210 display++;
6211 }
6212 if (display)
ajs5a646652004-11-05 01:25:55 +00006213 output_count++;
paul718e3742002-12-13 20:15:29 +00006214 }
6215
6216 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006217 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006218 {
6219 if (type == bgp_show_type_normal)
6220 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6221 }
6222 else
6223 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006224 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006225
6226 return CMD_SUCCESS;
6227}
6228
ajs5a646652004-11-05 01:25:55 +00006229static int
paulfee0f4c2004-09-13 05:12:46 +00006230bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006231 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006232{
6233 struct bgp_table *table;
6234
6235 if (bgp == NULL) {
6236 bgp = bgp_get_default ();
6237 }
6238
6239 if (bgp == NULL)
6240 {
6241 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6242 return CMD_WARNING;
6243 }
6244
6245
6246 table = bgp->rib[afi][safi];
6247
ajs5a646652004-11-05 01:25:55 +00006248 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006249}
6250
paul718e3742002-12-13 20:15:29 +00006251/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006252static void
paul718e3742002-12-13 20:15:29 +00006253route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6254 struct bgp_node *rn,
6255 struct prefix_rd *prd, afi_t afi, safi_t safi)
6256{
6257 struct bgp_info *ri;
6258 struct prefix *p;
6259 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006260 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006261 char buf1[INET6_ADDRSTRLEN];
6262 char buf2[INET6_ADDRSTRLEN];
6263 int count = 0;
6264 int best = 0;
6265 int suppress = 0;
6266 int no_export = 0;
6267 int no_advertise = 0;
6268 int local_as = 0;
6269 int first = 0;
6270
6271 p = &rn->p;
6272 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6273 (safi == SAFI_MPLS_VPN ?
6274 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6275 safi == SAFI_MPLS_VPN ? ":" : "",
6276 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6277 p->prefixlen, VTY_NEWLINE);
6278
6279 for (ri = rn->info; ri; ri = ri->next)
6280 {
6281 count++;
6282 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6283 {
6284 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006285 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006286 suppress = 1;
6287 if (ri->attr->community != NULL)
6288 {
6289 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6290 no_advertise = 1;
6291 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6292 no_export = 1;
6293 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6294 local_as = 1;
6295 }
6296 }
6297 }
6298
6299 vty_out (vty, "Paths: (%d available", count);
6300 if (best)
6301 {
6302 vty_out (vty, ", best #%d", best);
6303 if (safi == SAFI_UNICAST)
6304 vty_out (vty, ", table Default-IP-Routing-Table");
6305 }
6306 else
6307 vty_out (vty, ", no best path");
6308 if (no_advertise)
6309 vty_out (vty, ", not advertised to any peer");
6310 else if (no_export)
6311 vty_out (vty, ", not advertised to EBGP peer");
6312 else if (local_as)
6313 vty_out (vty, ", not advertised outside local AS");
6314 if (suppress)
6315 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6316 vty_out (vty, ")%s", VTY_NEWLINE);
6317
6318 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006319 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006320 {
6321 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6322 {
6323 if (! first)
6324 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6325 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6326 first = 1;
6327 }
6328 }
6329 if (! first)
6330 vty_out (vty, " Not advertised to any peer");
6331 vty_out (vty, "%s", VTY_NEWLINE);
6332}
6333
6334/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006335static int
paulfee0f4c2004-09-13 05:12:46 +00006336bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006337 struct bgp_table *rib, const char *ip_str,
6338 afi_t afi, safi_t safi, struct prefix_rd *prd,
6339 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006340{
6341 int ret;
6342 int header;
6343 int display = 0;
6344 struct prefix match;
6345 struct bgp_node *rn;
6346 struct bgp_node *rm;
6347 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006348 struct bgp_table *table;
6349
paul718e3742002-12-13 20:15:29 +00006350 /* Check IP address argument. */
6351 ret = str2prefix (ip_str, &match);
6352 if (! ret)
6353 {
6354 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6355 return CMD_WARNING;
6356 }
6357
6358 match.family = afi2family (afi);
6359
6360 if (safi == SAFI_MPLS_VPN)
6361 {
paulfee0f4c2004-09-13 05:12:46 +00006362 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006363 {
6364 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6365 continue;
6366
6367 if ((table = rn->info) != NULL)
6368 {
6369 header = 1;
6370
6371 if ((rm = bgp_node_match (table, &match)) != NULL)
6372 {
6373 if (prefix_check && rm->p.prefixlen != match.prefixlen)
6374 continue;
6375
6376 for (ri = rm->info; ri; ri = ri->next)
6377 {
6378 if (header)
6379 {
6380 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6381 AFI_IP, SAFI_MPLS_VPN);
6382
6383 header = 0;
6384 }
6385 display++;
6386 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6387 }
6388 }
6389 }
6390 }
6391 }
6392 else
6393 {
6394 header = 1;
6395
paulfee0f4c2004-09-13 05:12:46 +00006396 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006397 {
6398 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6399 {
6400 for (ri = rn->info; ri; ri = ri->next)
6401 {
6402 if (header)
6403 {
6404 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6405 header = 0;
6406 }
6407 display++;
6408 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6409 }
6410 }
6411 }
6412 }
6413
6414 if (! display)
6415 {
6416 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6417 return CMD_WARNING;
6418 }
6419
6420 return CMD_SUCCESS;
6421}
6422
paulfee0f4c2004-09-13 05:12:46 +00006423/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006424static int
paulfd79ac92004-10-13 05:06:08 +00006425bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006426 afi_t afi, safi_t safi, struct prefix_rd *prd,
6427 int prefix_check)
6428{
6429 struct bgp *bgp;
6430
6431 /* BGP structure lookup. */
6432 if (view_name)
6433 {
6434 bgp = bgp_lookup_by_name (view_name);
6435 if (bgp == NULL)
6436 {
6437 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6438 return CMD_WARNING;
6439 }
6440 }
6441 else
6442 {
6443 bgp = bgp_get_default ();
6444 if (bgp == NULL)
6445 {
6446 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6447 return CMD_WARNING;
6448 }
6449 }
6450
6451 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6452 afi, safi, prd, prefix_check);
6453}
6454
paul718e3742002-12-13 20:15:29 +00006455/* BGP route print out function. */
6456DEFUN (show_ip_bgp,
6457 show_ip_bgp_cmd,
6458 "show ip bgp",
6459 SHOW_STR
6460 IP_STR
6461 BGP_STR)
6462{
ajs5a646652004-11-05 01:25:55 +00006463 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006464}
6465
6466DEFUN (show_ip_bgp_ipv4,
6467 show_ip_bgp_ipv4_cmd,
6468 "show ip bgp ipv4 (unicast|multicast)",
6469 SHOW_STR
6470 IP_STR
6471 BGP_STR
6472 "Address family\n"
6473 "Address Family modifier\n"
6474 "Address Family modifier\n")
6475{
6476 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006477 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6478 NULL);
paul718e3742002-12-13 20:15:29 +00006479
ajs5a646652004-11-05 01:25:55 +00006480 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006481}
6482
6483DEFUN (show_ip_bgp_route,
6484 show_ip_bgp_route_cmd,
6485 "show ip bgp A.B.C.D",
6486 SHOW_STR
6487 IP_STR
6488 BGP_STR
6489 "Network in the BGP routing table to display\n")
6490{
6491 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6492}
6493
6494DEFUN (show_ip_bgp_ipv4_route,
6495 show_ip_bgp_ipv4_route_cmd,
6496 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6497 SHOW_STR
6498 IP_STR
6499 BGP_STR
6500 "Address family\n"
6501 "Address Family modifier\n"
6502 "Address Family modifier\n"
6503 "Network in the BGP routing table to display\n")
6504{
6505 if (strncmp (argv[0], "m", 1) == 0)
6506 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6507
6508 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6509}
6510
6511DEFUN (show_ip_bgp_vpnv4_all_route,
6512 show_ip_bgp_vpnv4_all_route_cmd,
6513 "show ip bgp vpnv4 all A.B.C.D",
6514 SHOW_STR
6515 IP_STR
6516 BGP_STR
6517 "Display VPNv4 NLRI specific information\n"
6518 "Display information about all VPNv4 NLRIs\n"
6519 "Network in the BGP routing table to display\n")
6520{
6521 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6522}
6523
6524DEFUN (show_ip_bgp_vpnv4_rd_route,
6525 show_ip_bgp_vpnv4_rd_route_cmd,
6526 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6527 SHOW_STR
6528 IP_STR
6529 BGP_STR
6530 "Display VPNv4 NLRI specific information\n"
6531 "Display information for a route distinguisher\n"
6532 "VPN Route Distinguisher\n"
6533 "Network in the BGP routing table to display\n")
6534{
6535 int ret;
6536 struct prefix_rd prd;
6537
6538 ret = str2prefix_rd (argv[0], &prd);
6539 if (! ret)
6540 {
6541 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6542 return CMD_WARNING;
6543 }
6544 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6545}
6546
6547DEFUN (show_ip_bgp_prefix,
6548 show_ip_bgp_prefix_cmd,
6549 "show ip bgp A.B.C.D/M",
6550 SHOW_STR
6551 IP_STR
6552 BGP_STR
6553 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6554{
6555 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6556}
6557
6558DEFUN (show_ip_bgp_ipv4_prefix,
6559 show_ip_bgp_ipv4_prefix_cmd,
6560 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6561 SHOW_STR
6562 IP_STR
6563 BGP_STR
6564 "Address family\n"
6565 "Address Family modifier\n"
6566 "Address Family modifier\n"
6567 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6568{
6569 if (strncmp (argv[0], "m", 1) == 0)
6570 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6571
6572 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6573}
6574
6575DEFUN (show_ip_bgp_vpnv4_all_prefix,
6576 show_ip_bgp_vpnv4_all_prefix_cmd,
6577 "show ip bgp vpnv4 all A.B.C.D/M",
6578 SHOW_STR
6579 IP_STR
6580 BGP_STR
6581 "Display VPNv4 NLRI specific information\n"
6582 "Display information about all VPNv4 NLRIs\n"
6583 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6584{
6585 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6586}
6587
6588DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6589 show_ip_bgp_vpnv4_rd_prefix_cmd,
6590 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6591 SHOW_STR
6592 IP_STR
6593 BGP_STR
6594 "Display VPNv4 NLRI specific information\n"
6595 "Display information for a route distinguisher\n"
6596 "VPN Route Distinguisher\n"
6597 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6598{
6599 int ret;
6600 struct prefix_rd prd;
6601
6602 ret = str2prefix_rd (argv[0], &prd);
6603 if (! ret)
6604 {
6605 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6606 return CMD_WARNING;
6607 }
6608 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6609}
6610
6611DEFUN (show_ip_bgp_view,
6612 show_ip_bgp_view_cmd,
6613 "show ip bgp view WORD",
6614 SHOW_STR
6615 IP_STR
6616 BGP_STR
6617 "BGP view\n"
6618 "BGP view name\n")
6619{
paulbb46e942003-10-24 19:02:03 +00006620 struct bgp *bgp;
6621
6622 /* BGP structure lookup. */
6623 bgp = bgp_lookup_by_name (argv[0]);
6624 if (bgp == NULL)
6625 {
6626 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6627 return CMD_WARNING;
6628 }
6629
ajs5a646652004-11-05 01:25:55 +00006630 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006631}
6632
6633DEFUN (show_ip_bgp_view_route,
6634 show_ip_bgp_view_route_cmd,
6635 "show ip bgp view WORD A.B.C.D",
6636 SHOW_STR
6637 IP_STR
6638 BGP_STR
6639 "BGP view\n"
6640 "BGP view name\n"
6641 "Network in the BGP routing table to display\n")
6642{
6643 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6644}
6645
6646DEFUN (show_ip_bgp_view_prefix,
6647 show_ip_bgp_view_prefix_cmd,
6648 "show ip bgp view WORD A.B.C.D/M",
6649 SHOW_STR
6650 IP_STR
6651 BGP_STR
6652 "BGP view\n"
6653 "BGP view name\n"
6654 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6655{
6656 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6657}
6658
6659#ifdef HAVE_IPV6
6660DEFUN (show_bgp,
6661 show_bgp_cmd,
6662 "show bgp",
6663 SHOW_STR
6664 BGP_STR)
6665{
ajs5a646652004-11-05 01:25:55 +00006666 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6667 NULL);
paul718e3742002-12-13 20:15:29 +00006668}
6669
6670ALIAS (show_bgp,
6671 show_bgp_ipv6_cmd,
6672 "show bgp ipv6",
6673 SHOW_STR
6674 BGP_STR
6675 "Address family\n")
6676
6677/* old command */
6678DEFUN (show_ipv6_bgp,
6679 show_ipv6_bgp_cmd,
6680 "show ipv6 bgp",
6681 SHOW_STR
6682 IP_STR
6683 BGP_STR)
6684{
ajs5a646652004-11-05 01:25:55 +00006685 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6686 NULL);
paul718e3742002-12-13 20:15:29 +00006687}
6688
6689DEFUN (show_bgp_route,
6690 show_bgp_route_cmd,
6691 "show bgp X:X::X:X",
6692 SHOW_STR
6693 BGP_STR
6694 "Network in the BGP routing table to display\n")
6695{
6696 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6697}
6698
6699ALIAS (show_bgp_route,
6700 show_bgp_ipv6_route_cmd,
6701 "show bgp ipv6 X:X::X:X",
6702 SHOW_STR
6703 BGP_STR
6704 "Address family\n"
6705 "Network in the BGP routing table to display\n")
6706
6707/* old command */
6708DEFUN (show_ipv6_bgp_route,
6709 show_ipv6_bgp_route_cmd,
6710 "show ipv6 bgp X:X::X:X",
6711 SHOW_STR
6712 IP_STR
6713 BGP_STR
6714 "Network in the BGP routing table to display\n")
6715{
6716 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6717}
6718
6719DEFUN (show_bgp_prefix,
6720 show_bgp_prefix_cmd,
6721 "show bgp X:X::X:X/M",
6722 SHOW_STR
6723 BGP_STR
6724 "IPv6 prefix <network>/<length>\n")
6725{
6726 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6727}
6728
6729ALIAS (show_bgp_prefix,
6730 show_bgp_ipv6_prefix_cmd,
6731 "show bgp ipv6 X:X::X:X/M",
6732 SHOW_STR
6733 BGP_STR
6734 "Address family\n"
6735 "IPv6 prefix <network>/<length>\n")
6736
6737/* old command */
6738DEFUN (show_ipv6_bgp_prefix,
6739 show_ipv6_bgp_prefix_cmd,
6740 "show ipv6 bgp X:X::X:X/M",
6741 SHOW_STR
6742 IP_STR
6743 BGP_STR
6744 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6745{
6746 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6747}
6748
paulbb46e942003-10-24 19:02:03 +00006749DEFUN (show_bgp_view,
6750 show_bgp_view_cmd,
6751 "show bgp view WORD",
6752 SHOW_STR
6753 BGP_STR
6754 "BGP view\n"
6755 "View name\n")
6756{
6757 struct bgp *bgp;
6758
6759 /* BGP structure lookup. */
6760 bgp = bgp_lookup_by_name (argv[0]);
6761 if (bgp == NULL)
6762 {
6763 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6764 return CMD_WARNING;
6765 }
6766
ajs5a646652004-11-05 01:25:55 +00006767 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006768}
6769
6770ALIAS (show_bgp_view,
6771 show_bgp_view_ipv6_cmd,
6772 "show bgp view WORD ipv6",
6773 SHOW_STR
6774 BGP_STR
6775 "BGP view\n"
6776 "View name\n"
6777 "Address family\n")
6778
6779DEFUN (show_bgp_view_route,
6780 show_bgp_view_route_cmd,
6781 "show bgp view WORD X:X::X:X",
6782 SHOW_STR
6783 BGP_STR
6784 "BGP view\n"
6785 "View name\n"
6786 "Network in the BGP routing table to display\n")
6787{
6788 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6789}
6790
6791ALIAS (show_bgp_view_route,
6792 show_bgp_view_ipv6_route_cmd,
6793 "show bgp view WORD ipv6 X:X::X:X",
6794 SHOW_STR
6795 BGP_STR
6796 "BGP view\n"
6797 "View name\n"
6798 "Address family\n"
6799 "Network in the BGP routing table to display\n")
6800
6801DEFUN (show_bgp_view_prefix,
6802 show_bgp_view_prefix_cmd,
6803 "show bgp view WORD X:X::X:X/M",
6804 SHOW_STR
6805 BGP_STR
6806 "BGP view\n"
6807 "View name\n"
6808 "IPv6 prefix <network>/<length>\n")
6809{
6810 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6811}
6812
6813ALIAS (show_bgp_view_prefix,
6814 show_bgp_view_ipv6_prefix_cmd,
6815 "show bgp view WORD ipv6 X:X::X:X/M",
6816 SHOW_STR
6817 BGP_STR
6818 "BGP view\n"
6819 "View name\n"
6820 "Address family\n"
6821 "IPv6 prefix <network>/<length>\n")
6822
paul718e3742002-12-13 20:15:29 +00006823/* old command */
6824DEFUN (show_ipv6_mbgp,
6825 show_ipv6_mbgp_cmd,
6826 "show ipv6 mbgp",
6827 SHOW_STR
6828 IP_STR
6829 MBGP_STR)
6830{
ajs5a646652004-11-05 01:25:55 +00006831 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6832 NULL);
paul718e3742002-12-13 20:15:29 +00006833}
6834
6835/* old command */
6836DEFUN (show_ipv6_mbgp_route,
6837 show_ipv6_mbgp_route_cmd,
6838 "show ipv6 mbgp X:X::X:X",
6839 SHOW_STR
6840 IP_STR
6841 MBGP_STR
6842 "Network in the MBGP routing table to display\n")
6843{
6844 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6845}
6846
6847/* old command */
6848DEFUN (show_ipv6_mbgp_prefix,
6849 show_ipv6_mbgp_prefix_cmd,
6850 "show ipv6 mbgp X:X::X:X/M",
6851 SHOW_STR
6852 IP_STR
6853 MBGP_STR
6854 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6855{
6856 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6857}
6858#endif
6859
paul718e3742002-12-13 20:15:29 +00006860
paul94f2b392005-06-28 12:44:16 +00006861static int
paulfd79ac92004-10-13 05:06:08 +00006862bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00006863 safi_t safi, enum bgp_show_type type)
6864{
6865 int i;
6866 struct buffer *b;
6867 char *regstr;
6868 int first;
6869 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00006870 int rc;
paul718e3742002-12-13 20:15:29 +00006871
6872 first = 0;
6873 b = buffer_new (1024);
6874 for (i = 0; i < argc; i++)
6875 {
6876 if (first)
6877 buffer_putc (b, ' ');
6878 else
6879 {
6880 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
6881 continue;
6882 first = 1;
6883 }
6884
6885 buffer_putstr (b, argv[i]);
6886 }
6887 buffer_putc (b, '\0');
6888
6889 regstr = buffer_getstr (b);
6890 buffer_free (b);
6891
6892 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00006893 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00006894 if (! regex)
6895 {
6896 vty_out (vty, "Can't compile regexp %s%s", argv[0],
6897 VTY_NEWLINE);
6898 return CMD_WARNING;
6899 }
6900
ajs5a646652004-11-05 01:25:55 +00006901 rc = bgp_show (vty, NULL, afi, safi, type, regex);
6902 bgp_regex_free (regex);
6903 return rc;
paul718e3742002-12-13 20:15:29 +00006904}
6905
6906DEFUN (show_ip_bgp_regexp,
6907 show_ip_bgp_regexp_cmd,
6908 "show ip bgp regexp .LINE",
6909 SHOW_STR
6910 IP_STR
6911 BGP_STR
6912 "Display routes matching the AS path regular expression\n"
6913 "A regular-expression to match the BGP AS paths\n")
6914{
6915 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6916 bgp_show_type_regexp);
6917}
6918
6919DEFUN (show_ip_bgp_flap_regexp,
6920 show_ip_bgp_flap_regexp_cmd,
6921 "show ip bgp flap-statistics regexp .LINE",
6922 SHOW_STR
6923 IP_STR
6924 BGP_STR
6925 "Display flap statistics of routes\n"
6926 "Display routes matching the AS path regular expression\n"
6927 "A regular-expression to match the BGP AS paths\n")
6928{
6929 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6930 bgp_show_type_flap_regexp);
6931}
6932
6933DEFUN (show_ip_bgp_ipv4_regexp,
6934 show_ip_bgp_ipv4_regexp_cmd,
6935 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
6936 SHOW_STR
6937 IP_STR
6938 BGP_STR
6939 "Address family\n"
6940 "Address Family modifier\n"
6941 "Address Family modifier\n"
6942 "Display routes matching the AS path regular expression\n"
6943 "A regular-expression to match the BGP AS paths\n")
6944{
6945 if (strncmp (argv[0], "m", 1) == 0)
6946 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
6947 bgp_show_type_regexp);
6948
6949 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
6950 bgp_show_type_regexp);
6951}
6952
6953#ifdef HAVE_IPV6
6954DEFUN (show_bgp_regexp,
6955 show_bgp_regexp_cmd,
6956 "show bgp regexp .LINE",
6957 SHOW_STR
6958 BGP_STR
6959 "Display routes matching the AS path regular expression\n"
6960 "A regular-expression to match the BGP AS paths\n")
6961{
6962 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6963 bgp_show_type_regexp);
6964}
6965
6966ALIAS (show_bgp_regexp,
6967 show_bgp_ipv6_regexp_cmd,
6968 "show bgp ipv6 regexp .LINE",
6969 SHOW_STR
6970 BGP_STR
6971 "Address family\n"
6972 "Display routes matching the AS path regular expression\n"
6973 "A regular-expression to match the BGP AS paths\n")
6974
6975/* old command */
6976DEFUN (show_ipv6_bgp_regexp,
6977 show_ipv6_bgp_regexp_cmd,
6978 "show ipv6 bgp regexp .LINE",
6979 SHOW_STR
6980 IP_STR
6981 BGP_STR
6982 "Display routes matching the AS path regular expression\n"
6983 "A regular-expression to match the BGP AS paths\n")
6984{
6985 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
6986 bgp_show_type_regexp);
6987}
6988
6989/* old command */
6990DEFUN (show_ipv6_mbgp_regexp,
6991 show_ipv6_mbgp_regexp_cmd,
6992 "show ipv6 mbgp regexp .LINE",
6993 SHOW_STR
6994 IP_STR
6995 BGP_STR
6996 "Display routes matching the AS path regular expression\n"
6997 "A regular-expression to match the MBGP AS paths\n")
6998{
6999 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7000 bgp_show_type_regexp);
7001}
7002#endif /* HAVE_IPV6 */
7003
paul94f2b392005-06-28 12:44:16 +00007004static int
paulfd79ac92004-10-13 05:06:08 +00007005bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007006 safi_t safi, enum bgp_show_type type)
7007{
7008 struct prefix_list *plist;
7009
7010 plist = prefix_list_lookup (afi, prefix_list_str);
7011 if (plist == NULL)
7012 {
7013 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7014 prefix_list_str, VTY_NEWLINE);
7015 return CMD_WARNING;
7016 }
7017
ajs5a646652004-11-05 01:25:55 +00007018 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007019}
7020
7021DEFUN (show_ip_bgp_prefix_list,
7022 show_ip_bgp_prefix_list_cmd,
7023 "show ip bgp prefix-list WORD",
7024 SHOW_STR
7025 IP_STR
7026 BGP_STR
7027 "Display routes conforming to the prefix-list\n"
7028 "IP prefix-list name\n")
7029{
7030 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7031 bgp_show_type_prefix_list);
7032}
7033
7034DEFUN (show_ip_bgp_flap_prefix_list,
7035 show_ip_bgp_flap_prefix_list_cmd,
7036 "show ip bgp flap-statistics prefix-list WORD",
7037 SHOW_STR
7038 IP_STR
7039 BGP_STR
7040 "Display flap statistics of routes\n"
7041 "Display routes conforming to the prefix-list\n"
7042 "IP prefix-list name\n")
7043{
7044 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7045 bgp_show_type_flap_prefix_list);
7046}
7047
7048DEFUN (show_ip_bgp_ipv4_prefix_list,
7049 show_ip_bgp_ipv4_prefix_list_cmd,
7050 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7051 SHOW_STR
7052 IP_STR
7053 BGP_STR
7054 "Address family\n"
7055 "Address Family modifier\n"
7056 "Address Family modifier\n"
7057 "Display routes conforming to the prefix-list\n"
7058 "IP prefix-list name\n")
7059{
7060 if (strncmp (argv[0], "m", 1) == 0)
7061 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7062 bgp_show_type_prefix_list);
7063
7064 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7065 bgp_show_type_prefix_list);
7066}
7067
7068#ifdef HAVE_IPV6
7069DEFUN (show_bgp_prefix_list,
7070 show_bgp_prefix_list_cmd,
7071 "show bgp prefix-list WORD",
7072 SHOW_STR
7073 BGP_STR
7074 "Display routes conforming to the prefix-list\n"
7075 "IPv6 prefix-list name\n")
7076{
7077 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7078 bgp_show_type_prefix_list);
7079}
7080
7081ALIAS (show_bgp_prefix_list,
7082 show_bgp_ipv6_prefix_list_cmd,
7083 "show bgp ipv6 prefix-list WORD",
7084 SHOW_STR
7085 BGP_STR
7086 "Address family\n"
7087 "Display routes conforming to the prefix-list\n"
7088 "IPv6 prefix-list name\n")
7089
7090/* old command */
7091DEFUN (show_ipv6_bgp_prefix_list,
7092 show_ipv6_bgp_prefix_list_cmd,
7093 "show ipv6 bgp prefix-list WORD",
7094 SHOW_STR
7095 IPV6_STR
7096 BGP_STR
7097 "Display routes matching the prefix-list\n"
7098 "IPv6 prefix-list name\n")
7099{
7100 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7101 bgp_show_type_prefix_list);
7102}
7103
7104/* old command */
7105DEFUN (show_ipv6_mbgp_prefix_list,
7106 show_ipv6_mbgp_prefix_list_cmd,
7107 "show ipv6 mbgp prefix-list WORD",
7108 SHOW_STR
7109 IPV6_STR
7110 MBGP_STR
7111 "Display routes matching the prefix-list\n"
7112 "IPv6 prefix-list name\n")
7113{
7114 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7115 bgp_show_type_prefix_list);
7116}
7117#endif /* HAVE_IPV6 */
7118
paul94f2b392005-06-28 12:44:16 +00007119static int
paulfd79ac92004-10-13 05:06:08 +00007120bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007121 safi_t safi, enum bgp_show_type type)
7122{
7123 struct as_list *as_list;
7124
7125 as_list = as_list_lookup (filter);
7126 if (as_list == NULL)
7127 {
7128 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7129 return CMD_WARNING;
7130 }
7131
ajs5a646652004-11-05 01:25:55 +00007132 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007133}
7134
7135DEFUN (show_ip_bgp_filter_list,
7136 show_ip_bgp_filter_list_cmd,
7137 "show ip bgp filter-list WORD",
7138 SHOW_STR
7139 IP_STR
7140 BGP_STR
7141 "Display routes conforming to the filter-list\n"
7142 "Regular expression access list name\n")
7143{
7144 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7145 bgp_show_type_filter_list);
7146}
7147
7148DEFUN (show_ip_bgp_flap_filter_list,
7149 show_ip_bgp_flap_filter_list_cmd,
7150 "show ip bgp flap-statistics filter-list WORD",
7151 SHOW_STR
7152 IP_STR
7153 BGP_STR
7154 "Display flap statistics of routes\n"
7155 "Display routes conforming to the filter-list\n"
7156 "Regular expression access list name\n")
7157{
7158 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7159 bgp_show_type_flap_filter_list);
7160}
7161
7162DEFUN (show_ip_bgp_ipv4_filter_list,
7163 show_ip_bgp_ipv4_filter_list_cmd,
7164 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7165 SHOW_STR
7166 IP_STR
7167 BGP_STR
7168 "Address family\n"
7169 "Address Family modifier\n"
7170 "Address Family modifier\n"
7171 "Display routes conforming to the filter-list\n"
7172 "Regular expression access list name\n")
7173{
7174 if (strncmp (argv[0], "m", 1) == 0)
7175 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7176 bgp_show_type_filter_list);
7177
7178 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7179 bgp_show_type_filter_list);
7180}
7181
7182#ifdef HAVE_IPV6
7183DEFUN (show_bgp_filter_list,
7184 show_bgp_filter_list_cmd,
7185 "show bgp filter-list WORD",
7186 SHOW_STR
7187 BGP_STR
7188 "Display routes conforming to the filter-list\n"
7189 "Regular expression access list name\n")
7190{
7191 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7192 bgp_show_type_filter_list);
7193}
7194
7195ALIAS (show_bgp_filter_list,
7196 show_bgp_ipv6_filter_list_cmd,
7197 "show bgp ipv6 filter-list WORD",
7198 SHOW_STR
7199 BGP_STR
7200 "Address family\n"
7201 "Display routes conforming to the filter-list\n"
7202 "Regular expression access list name\n")
7203
7204/* old command */
7205DEFUN (show_ipv6_bgp_filter_list,
7206 show_ipv6_bgp_filter_list_cmd,
7207 "show ipv6 bgp filter-list WORD",
7208 SHOW_STR
7209 IPV6_STR
7210 BGP_STR
7211 "Display routes conforming to the filter-list\n"
7212 "Regular expression access list name\n")
7213{
7214 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7215 bgp_show_type_filter_list);
7216}
7217
7218/* old command */
7219DEFUN (show_ipv6_mbgp_filter_list,
7220 show_ipv6_mbgp_filter_list_cmd,
7221 "show ipv6 mbgp filter-list WORD",
7222 SHOW_STR
7223 IPV6_STR
7224 MBGP_STR
7225 "Display routes conforming to the filter-list\n"
7226 "Regular expression access list name\n")
7227{
7228 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7229 bgp_show_type_filter_list);
7230}
7231#endif /* HAVE_IPV6 */
7232
paul94f2b392005-06-28 12:44:16 +00007233static int
paulfd79ac92004-10-13 05:06:08 +00007234bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007235 safi_t safi, enum bgp_show_type type)
7236{
7237 struct route_map *rmap;
7238
7239 rmap = route_map_lookup_by_name (rmap_str);
7240 if (! rmap)
7241 {
7242 vty_out (vty, "%% %s is not a valid route-map name%s",
7243 rmap_str, VTY_NEWLINE);
7244 return CMD_WARNING;
7245 }
7246
ajs5a646652004-11-05 01:25:55 +00007247 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007248}
7249
7250DEFUN (show_ip_bgp_route_map,
7251 show_ip_bgp_route_map_cmd,
7252 "show ip bgp route-map WORD",
7253 SHOW_STR
7254 IP_STR
7255 BGP_STR
7256 "Display routes matching the route-map\n"
7257 "A route-map to match on\n")
7258{
7259 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7260 bgp_show_type_route_map);
7261}
7262
7263DEFUN (show_ip_bgp_flap_route_map,
7264 show_ip_bgp_flap_route_map_cmd,
7265 "show ip bgp flap-statistics route-map WORD",
7266 SHOW_STR
7267 IP_STR
7268 BGP_STR
7269 "Display flap statistics of routes\n"
7270 "Display routes matching the route-map\n"
7271 "A route-map to match on\n")
7272{
7273 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7274 bgp_show_type_flap_route_map);
7275}
7276
7277DEFUN (show_ip_bgp_ipv4_route_map,
7278 show_ip_bgp_ipv4_route_map_cmd,
7279 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7280 SHOW_STR
7281 IP_STR
7282 BGP_STR
7283 "Address family\n"
7284 "Address Family modifier\n"
7285 "Address Family modifier\n"
7286 "Display routes matching the route-map\n"
7287 "A route-map to match on\n")
7288{
7289 if (strncmp (argv[0], "m", 1) == 0)
7290 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7291 bgp_show_type_route_map);
7292
7293 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7294 bgp_show_type_route_map);
7295}
7296
7297DEFUN (show_bgp_route_map,
7298 show_bgp_route_map_cmd,
7299 "show bgp route-map WORD",
7300 SHOW_STR
7301 BGP_STR
7302 "Display routes matching the route-map\n"
7303 "A route-map to match on\n")
7304{
7305 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7306 bgp_show_type_route_map);
7307}
7308
7309ALIAS (show_bgp_route_map,
7310 show_bgp_ipv6_route_map_cmd,
7311 "show bgp ipv6 route-map WORD",
7312 SHOW_STR
7313 BGP_STR
7314 "Address family\n"
7315 "Display routes matching the route-map\n"
7316 "A route-map to match on\n")
7317
7318DEFUN (show_ip_bgp_cidr_only,
7319 show_ip_bgp_cidr_only_cmd,
7320 "show ip bgp cidr-only",
7321 SHOW_STR
7322 IP_STR
7323 BGP_STR
7324 "Display only routes with non-natural netmasks\n")
7325{
7326 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007327 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007328}
7329
7330DEFUN (show_ip_bgp_flap_cidr_only,
7331 show_ip_bgp_flap_cidr_only_cmd,
7332 "show ip bgp flap-statistics cidr-only",
7333 SHOW_STR
7334 IP_STR
7335 BGP_STR
7336 "Display flap statistics of routes\n"
7337 "Display only routes with non-natural netmasks\n")
7338{
7339 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007340 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007341}
7342
7343DEFUN (show_ip_bgp_ipv4_cidr_only,
7344 show_ip_bgp_ipv4_cidr_only_cmd,
7345 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7346 SHOW_STR
7347 IP_STR
7348 BGP_STR
7349 "Address family\n"
7350 "Address Family modifier\n"
7351 "Address Family modifier\n"
7352 "Display only routes with non-natural netmasks\n")
7353{
7354 if (strncmp (argv[0], "m", 1) == 0)
7355 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007356 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007357
7358 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007359 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007360}
7361
7362DEFUN (show_ip_bgp_community_all,
7363 show_ip_bgp_community_all_cmd,
7364 "show ip bgp community",
7365 SHOW_STR
7366 IP_STR
7367 BGP_STR
7368 "Display routes matching the communities\n")
7369{
7370 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007371 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007372}
7373
7374DEFUN (show_ip_bgp_ipv4_community_all,
7375 show_ip_bgp_ipv4_community_all_cmd,
7376 "show ip bgp ipv4 (unicast|multicast) community",
7377 SHOW_STR
7378 IP_STR
7379 BGP_STR
7380 "Address family\n"
7381 "Address Family modifier\n"
7382 "Address Family modifier\n"
7383 "Display routes matching the communities\n")
7384{
7385 if (strncmp (argv[0], "m", 1) == 0)
7386 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007387 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007388
7389 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007390 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007391}
7392
7393#ifdef HAVE_IPV6
7394DEFUN (show_bgp_community_all,
7395 show_bgp_community_all_cmd,
7396 "show bgp community",
7397 SHOW_STR
7398 BGP_STR
7399 "Display routes matching the communities\n")
7400{
7401 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007402 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007403}
7404
7405ALIAS (show_bgp_community_all,
7406 show_bgp_ipv6_community_all_cmd,
7407 "show bgp ipv6 community",
7408 SHOW_STR
7409 BGP_STR
7410 "Address family\n"
7411 "Display routes matching the communities\n")
7412
7413/* old command */
7414DEFUN (show_ipv6_bgp_community_all,
7415 show_ipv6_bgp_community_all_cmd,
7416 "show ipv6 bgp community",
7417 SHOW_STR
7418 IPV6_STR
7419 BGP_STR
7420 "Display routes matching the communities\n")
7421{
7422 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007423 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007424}
7425
7426/* old command */
7427DEFUN (show_ipv6_mbgp_community_all,
7428 show_ipv6_mbgp_community_all_cmd,
7429 "show ipv6 mbgp community",
7430 SHOW_STR
7431 IPV6_STR
7432 MBGP_STR
7433 "Display routes matching the communities\n")
7434{
7435 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007436 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007437}
7438#endif /* HAVE_IPV6 */
7439
paul94f2b392005-06-28 12:44:16 +00007440static int
paulfd79ac92004-10-13 05:06:08 +00007441bgp_show_community (struct vty *vty, int argc, const char **argv, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04007442 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007443{
7444 struct community *com;
7445 struct buffer *b;
7446 int i;
7447 char *str;
7448 int first = 0;
7449
7450 b = buffer_new (1024);
7451 for (i = 0; i < argc; i++)
7452 {
7453 if (first)
7454 buffer_putc (b, ' ');
7455 else
7456 {
7457 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7458 continue;
7459 first = 1;
7460 }
7461
7462 buffer_putstr (b, argv[i]);
7463 }
7464 buffer_putc (b, '\0');
7465
7466 str = buffer_getstr (b);
7467 buffer_free (b);
7468
7469 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007470 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007471 if (! com)
7472 {
7473 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7474 return CMD_WARNING;
7475 }
7476
ajs5a646652004-11-05 01:25:55 +00007477 return bgp_show (vty, NULL, afi, safi,
7478 (exact ? bgp_show_type_community_exact :
7479 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007480}
7481
7482DEFUN (show_ip_bgp_community,
7483 show_ip_bgp_community_cmd,
7484 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7485 SHOW_STR
7486 IP_STR
7487 BGP_STR
7488 "Display routes matching the communities\n"
7489 "community number\n"
7490 "Do not send outside local AS (well-known community)\n"
7491 "Do not advertise to any peer (well-known community)\n"
7492 "Do not export to next AS (well-known community)\n")
7493{
7494 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7495}
7496
7497ALIAS (show_ip_bgp_community,
7498 show_ip_bgp_community2_cmd,
7499 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7500 SHOW_STR
7501 IP_STR
7502 BGP_STR
7503 "Display routes matching the communities\n"
7504 "community number\n"
7505 "Do not send outside local AS (well-known community)\n"
7506 "Do not advertise to any peer (well-known community)\n"
7507 "Do not export to next AS (well-known community)\n"
7508 "community number\n"
7509 "Do not send outside local AS (well-known community)\n"
7510 "Do not advertise to any peer (well-known community)\n"
7511 "Do not export to next AS (well-known community)\n")
7512
7513ALIAS (show_ip_bgp_community,
7514 show_ip_bgp_community3_cmd,
7515 "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)",
7516 SHOW_STR
7517 IP_STR
7518 BGP_STR
7519 "Display routes matching the communities\n"
7520 "community number\n"
7521 "Do not send outside local AS (well-known community)\n"
7522 "Do not advertise to any peer (well-known community)\n"
7523 "Do not export to next AS (well-known community)\n"
7524 "community number\n"
7525 "Do not send outside local AS (well-known community)\n"
7526 "Do not advertise to any peer (well-known community)\n"
7527 "Do not export to next AS (well-known community)\n"
7528 "community number\n"
7529 "Do not send outside local AS (well-known community)\n"
7530 "Do not advertise to any peer (well-known community)\n"
7531 "Do not export to next AS (well-known community)\n")
7532
7533ALIAS (show_ip_bgp_community,
7534 show_ip_bgp_community4_cmd,
7535 "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)",
7536 SHOW_STR
7537 IP_STR
7538 BGP_STR
7539 "Display routes matching the communities\n"
7540 "community number\n"
7541 "Do not send outside local AS (well-known community)\n"
7542 "Do not advertise to any peer (well-known community)\n"
7543 "Do not export to next AS (well-known community)\n"
7544 "community number\n"
7545 "Do not send outside local AS (well-known community)\n"
7546 "Do not advertise to any peer (well-known community)\n"
7547 "Do not export to next AS (well-known community)\n"
7548 "community number\n"
7549 "Do not send outside local AS (well-known community)\n"
7550 "Do not advertise to any peer (well-known community)\n"
7551 "Do not export to next AS (well-known community)\n"
7552 "community number\n"
7553 "Do not send outside local AS (well-known community)\n"
7554 "Do not advertise to any peer (well-known community)\n"
7555 "Do not export to next AS (well-known community)\n")
7556
7557DEFUN (show_ip_bgp_ipv4_community,
7558 show_ip_bgp_ipv4_community_cmd,
7559 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7560 SHOW_STR
7561 IP_STR
7562 BGP_STR
7563 "Address family\n"
7564 "Address Family modifier\n"
7565 "Address Family modifier\n"
7566 "Display routes matching the communities\n"
7567 "community number\n"
7568 "Do not send outside local AS (well-known community)\n"
7569 "Do not advertise to any peer (well-known community)\n"
7570 "Do not export to next AS (well-known community)\n")
7571{
7572 if (strncmp (argv[0], "m", 1) == 0)
7573 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
7574
7575 return bgp_show_community (vty, argc, argv, 0, AFI_IP, SAFI_UNICAST);
7576}
7577
7578ALIAS (show_ip_bgp_ipv4_community,
7579 show_ip_bgp_ipv4_community2_cmd,
7580 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7581 SHOW_STR
7582 IP_STR
7583 BGP_STR
7584 "Address family\n"
7585 "Address Family modifier\n"
7586 "Address Family modifier\n"
7587 "Display routes matching the communities\n"
7588 "community number\n"
7589 "Do not send outside local AS (well-known community)\n"
7590 "Do not advertise to any peer (well-known community)\n"
7591 "Do not export to next AS (well-known community)\n"
7592 "community number\n"
7593 "Do not send outside local AS (well-known community)\n"
7594 "Do not advertise to any peer (well-known community)\n"
7595 "Do not export to next AS (well-known community)\n")
7596
7597ALIAS (show_ip_bgp_ipv4_community,
7598 show_ip_bgp_ipv4_community3_cmd,
7599 "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)",
7600 SHOW_STR
7601 IP_STR
7602 BGP_STR
7603 "Address family\n"
7604 "Address Family modifier\n"
7605 "Address Family modifier\n"
7606 "Display routes matching the communities\n"
7607 "community number\n"
7608 "Do not send outside local AS (well-known community)\n"
7609 "Do not advertise to any peer (well-known community)\n"
7610 "Do not export to next AS (well-known community)\n"
7611 "community number\n"
7612 "Do not send outside local AS (well-known community)\n"
7613 "Do not advertise to any peer (well-known community)\n"
7614 "Do not export to next AS (well-known community)\n"
7615 "community number\n"
7616 "Do not send outside local AS (well-known community)\n"
7617 "Do not advertise to any peer (well-known community)\n"
7618 "Do not export to next AS (well-known community)\n")
7619
7620ALIAS (show_ip_bgp_ipv4_community,
7621 show_ip_bgp_ipv4_community4_cmd,
7622 "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)",
7623 SHOW_STR
7624 IP_STR
7625 BGP_STR
7626 "Address family\n"
7627 "Address Family modifier\n"
7628 "Address Family modifier\n"
7629 "Display routes matching the communities\n"
7630 "community number\n"
7631 "Do not send outside local AS (well-known community)\n"
7632 "Do not advertise to any peer (well-known community)\n"
7633 "Do not export to next AS (well-known community)\n"
7634 "community number\n"
7635 "Do not send outside local AS (well-known community)\n"
7636 "Do not advertise to any peer (well-known community)\n"
7637 "Do not export to next AS (well-known community)\n"
7638 "community number\n"
7639 "Do not send outside local AS (well-known community)\n"
7640 "Do not advertise to any peer (well-known community)\n"
7641 "Do not export to next AS (well-known community)\n"
7642 "community number\n"
7643 "Do not send outside local AS (well-known community)\n"
7644 "Do not advertise to any peer (well-known community)\n"
7645 "Do not export to next AS (well-known community)\n")
7646
7647DEFUN (show_ip_bgp_community_exact,
7648 show_ip_bgp_community_exact_cmd,
7649 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7650 SHOW_STR
7651 IP_STR
7652 BGP_STR
7653 "Display routes matching the communities\n"
7654 "community number\n"
7655 "Do not send outside local AS (well-known community)\n"
7656 "Do not advertise to any peer (well-known community)\n"
7657 "Do not export to next AS (well-known community)\n"
7658 "Exact match of the communities")
7659{
7660 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7661}
7662
7663ALIAS (show_ip_bgp_community_exact,
7664 show_ip_bgp_community2_exact_cmd,
7665 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7666 SHOW_STR
7667 IP_STR
7668 BGP_STR
7669 "Display routes matching the communities\n"
7670 "community number\n"
7671 "Do not send outside local AS (well-known community)\n"
7672 "Do not advertise to any peer (well-known community)\n"
7673 "Do not export to next AS (well-known community)\n"
7674 "community number\n"
7675 "Do not send outside local AS (well-known community)\n"
7676 "Do not advertise to any peer (well-known community)\n"
7677 "Do not export to next AS (well-known community)\n"
7678 "Exact match of the communities")
7679
7680ALIAS (show_ip_bgp_community_exact,
7681 show_ip_bgp_community3_exact_cmd,
7682 "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",
7683 SHOW_STR
7684 IP_STR
7685 BGP_STR
7686 "Display routes matching the communities\n"
7687 "community number\n"
7688 "Do not send outside local AS (well-known community)\n"
7689 "Do not advertise to any peer (well-known community)\n"
7690 "Do not export to next AS (well-known community)\n"
7691 "community number\n"
7692 "Do not send outside local AS (well-known community)\n"
7693 "Do not advertise to any peer (well-known community)\n"
7694 "Do not export to next AS (well-known community)\n"
7695 "community number\n"
7696 "Do not send outside local AS (well-known community)\n"
7697 "Do not advertise to any peer (well-known community)\n"
7698 "Do not export to next AS (well-known community)\n"
7699 "Exact match of the communities")
7700
7701ALIAS (show_ip_bgp_community_exact,
7702 show_ip_bgp_community4_exact_cmd,
7703 "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",
7704 SHOW_STR
7705 IP_STR
7706 BGP_STR
7707 "Display routes matching the communities\n"
7708 "community number\n"
7709 "Do not send outside local AS (well-known community)\n"
7710 "Do not advertise to any peer (well-known community)\n"
7711 "Do not export to next AS (well-known community)\n"
7712 "community number\n"
7713 "Do not send outside local AS (well-known community)\n"
7714 "Do not advertise to any peer (well-known community)\n"
7715 "Do not export to next AS (well-known community)\n"
7716 "community number\n"
7717 "Do not send outside local AS (well-known community)\n"
7718 "Do not advertise to any peer (well-known community)\n"
7719 "Do not export to next AS (well-known community)\n"
7720 "community number\n"
7721 "Do not send outside local AS (well-known community)\n"
7722 "Do not advertise to any peer (well-known community)\n"
7723 "Do not export to next AS (well-known community)\n"
7724 "Exact match of the communities")
7725
7726DEFUN (show_ip_bgp_ipv4_community_exact,
7727 show_ip_bgp_ipv4_community_exact_cmd,
7728 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7729 SHOW_STR
7730 IP_STR
7731 BGP_STR
7732 "Address family\n"
7733 "Address Family modifier\n"
7734 "Address Family modifier\n"
7735 "Display routes matching the communities\n"
7736 "community number\n"
7737 "Do not send outside local AS (well-known community)\n"
7738 "Do not advertise to any peer (well-known community)\n"
7739 "Do not export to next AS (well-known community)\n"
7740 "Exact match of the communities")
7741{
7742 if (strncmp (argv[0], "m", 1) == 0)
7743 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
7744
7745 return bgp_show_community (vty, argc, argv, 1, AFI_IP, SAFI_UNICAST);
7746}
7747
7748ALIAS (show_ip_bgp_ipv4_community_exact,
7749 show_ip_bgp_ipv4_community2_exact_cmd,
7750 "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",
7751 SHOW_STR
7752 IP_STR
7753 BGP_STR
7754 "Address family\n"
7755 "Address Family modifier\n"
7756 "Address Family modifier\n"
7757 "Display routes matching the communities\n"
7758 "community number\n"
7759 "Do not send outside local AS (well-known community)\n"
7760 "Do not advertise to any peer (well-known community)\n"
7761 "Do not export to next AS (well-known community)\n"
7762 "community number\n"
7763 "Do not send outside local AS (well-known community)\n"
7764 "Do not advertise to any peer (well-known community)\n"
7765 "Do not export to next AS (well-known community)\n"
7766 "Exact match of the communities")
7767
7768ALIAS (show_ip_bgp_ipv4_community_exact,
7769 show_ip_bgp_ipv4_community3_exact_cmd,
7770 "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",
7771 SHOW_STR
7772 IP_STR
7773 BGP_STR
7774 "Address family\n"
7775 "Address Family modifier\n"
7776 "Address Family modifier\n"
7777 "Display routes matching the communities\n"
7778 "community number\n"
7779 "Do not send outside local AS (well-known community)\n"
7780 "Do not advertise to any peer (well-known community)\n"
7781 "Do not export to next AS (well-known community)\n"
7782 "community number\n"
7783 "Do not send outside local AS (well-known community)\n"
7784 "Do not advertise to any peer (well-known community)\n"
7785 "Do not export to next AS (well-known community)\n"
7786 "community number\n"
7787 "Do not send outside local AS (well-known community)\n"
7788 "Do not advertise to any peer (well-known community)\n"
7789 "Do not export to next AS (well-known community)\n"
7790 "Exact match of the communities")
7791
7792ALIAS (show_ip_bgp_ipv4_community_exact,
7793 show_ip_bgp_ipv4_community4_exact_cmd,
7794 "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",
7795 SHOW_STR
7796 IP_STR
7797 BGP_STR
7798 "Address family\n"
7799 "Address Family modifier\n"
7800 "Address Family modifier\n"
7801 "Display routes matching the communities\n"
7802 "community number\n"
7803 "Do not send outside local AS (well-known community)\n"
7804 "Do not advertise to any peer (well-known community)\n"
7805 "Do not export to next AS (well-known community)\n"
7806 "community number\n"
7807 "Do not send outside local AS (well-known community)\n"
7808 "Do not advertise to any peer (well-known community)\n"
7809 "Do not export to next AS (well-known community)\n"
7810 "community number\n"
7811 "Do not send outside local AS (well-known community)\n"
7812 "Do not advertise to any peer (well-known community)\n"
7813 "Do not export to next AS (well-known community)\n"
7814 "community number\n"
7815 "Do not send outside local AS (well-known community)\n"
7816 "Do not advertise to any peer (well-known community)\n"
7817 "Do not export to next AS (well-known community)\n"
7818 "Exact match of the communities")
7819
7820#ifdef HAVE_IPV6
7821DEFUN (show_bgp_community,
7822 show_bgp_community_cmd,
7823 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
7824 SHOW_STR
7825 BGP_STR
7826 "Display routes matching the communities\n"
7827 "community number\n"
7828 "Do not send outside local AS (well-known community)\n"
7829 "Do not advertise to any peer (well-known community)\n"
7830 "Do not export to next AS (well-known community)\n")
7831{
7832 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7833}
7834
7835ALIAS (show_bgp_community,
7836 show_bgp_ipv6_community_cmd,
7837 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
7838 SHOW_STR
7839 BGP_STR
7840 "Address family\n"
7841 "Display routes matching the communities\n"
7842 "community number\n"
7843 "Do not send outside local AS (well-known community)\n"
7844 "Do not advertise to any peer (well-known community)\n"
7845 "Do not export to next AS (well-known community)\n")
7846
7847ALIAS (show_bgp_community,
7848 show_bgp_community2_cmd,
7849 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7850 SHOW_STR
7851 BGP_STR
7852 "Display routes matching the communities\n"
7853 "community number\n"
7854 "Do not send outside local AS (well-known community)\n"
7855 "Do not advertise to any peer (well-known community)\n"
7856 "Do not export to next AS (well-known community)\n"
7857 "community number\n"
7858 "Do not send outside local AS (well-known community)\n"
7859 "Do not advertise to any peer (well-known community)\n"
7860 "Do not export to next AS (well-known community)\n")
7861
7862ALIAS (show_bgp_community,
7863 show_bgp_ipv6_community2_cmd,
7864 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7865 SHOW_STR
7866 BGP_STR
7867 "Address family\n"
7868 "Display routes matching the communities\n"
7869 "community number\n"
7870 "Do not send outside local AS (well-known community)\n"
7871 "Do not advertise to any peer (well-known community)\n"
7872 "Do not export to next AS (well-known community)\n"
7873 "community number\n"
7874 "Do not send outside local AS (well-known community)\n"
7875 "Do not advertise to any peer (well-known community)\n"
7876 "Do not export to next AS (well-known community)\n")
7877
7878ALIAS (show_bgp_community,
7879 show_bgp_community3_cmd,
7880 "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)",
7881 SHOW_STR
7882 BGP_STR
7883 "Display routes matching the communities\n"
7884 "community number\n"
7885 "Do not send outside local AS (well-known community)\n"
7886 "Do not advertise to any peer (well-known community)\n"
7887 "Do not export to next AS (well-known community)\n"
7888 "community number\n"
7889 "Do not send outside local AS (well-known community)\n"
7890 "Do not advertise to any peer (well-known community)\n"
7891 "Do not export to next AS (well-known community)\n"
7892 "community number\n"
7893 "Do not send outside local AS (well-known community)\n"
7894 "Do not advertise to any peer (well-known community)\n"
7895 "Do not export to next AS (well-known community)\n")
7896
7897ALIAS (show_bgp_community,
7898 show_bgp_ipv6_community3_cmd,
7899 "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)",
7900 SHOW_STR
7901 BGP_STR
7902 "Address family\n"
7903 "Display routes matching the communities\n"
7904 "community number\n"
7905 "Do not send outside local AS (well-known community)\n"
7906 "Do not advertise to any peer (well-known community)\n"
7907 "Do not export to next AS (well-known community)\n"
7908 "community number\n"
7909 "Do not send outside local AS (well-known community)\n"
7910 "Do not advertise to any peer (well-known community)\n"
7911 "Do not export to next AS (well-known community)\n"
7912 "community number\n"
7913 "Do not send outside local AS (well-known community)\n"
7914 "Do not advertise to any peer (well-known community)\n"
7915 "Do not export to next AS (well-known community)\n")
7916
7917ALIAS (show_bgp_community,
7918 show_bgp_community4_cmd,
7919 "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)",
7920 SHOW_STR
7921 BGP_STR
7922 "Display routes matching the communities\n"
7923 "community number\n"
7924 "Do not send outside local AS (well-known community)\n"
7925 "Do not advertise to any peer (well-known community)\n"
7926 "Do not export to next AS (well-known community)\n"
7927 "community number\n"
7928 "Do not send outside local AS (well-known community)\n"
7929 "Do not advertise to any peer (well-known community)\n"
7930 "Do not export to next AS (well-known community)\n"
7931 "community number\n"
7932 "Do not send outside local AS (well-known community)\n"
7933 "Do not advertise to any peer (well-known community)\n"
7934 "Do not export to next AS (well-known community)\n"
7935 "community number\n"
7936 "Do not send outside local AS (well-known community)\n"
7937 "Do not advertise to any peer (well-known community)\n"
7938 "Do not export to next AS (well-known community)\n")
7939
7940ALIAS (show_bgp_community,
7941 show_bgp_ipv6_community4_cmd,
7942 "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)",
7943 SHOW_STR
7944 BGP_STR
7945 "Address family\n"
7946 "Display routes matching the communities\n"
7947 "community number\n"
7948 "Do not send outside local AS (well-known community)\n"
7949 "Do not advertise to any peer (well-known community)\n"
7950 "Do not export to next AS (well-known community)\n"
7951 "community number\n"
7952 "Do not send outside local AS (well-known community)\n"
7953 "Do not advertise to any peer (well-known community)\n"
7954 "Do not export to next AS (well-known community)\n"
7955 "community number\n"
7956 "Do not send outside local AS (well-known community)\n"
7957 "Do not advertise to any peer (well-known community)\n"
7958 "Do not export to next AS (well-known community)\n"
7959 "community number\n"
7960 "Do not send outside local AS (well-known community)\n"
7961 "Do not advertise to any peer (well-known community)\n"
7962 "Do not export to next AS (well-known community)\n")
7963
7964/* old command */
7965DEFUN (show_ipv6_bgp_community,
7966 show_ipv6_bgp_community_cmd,
7967 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
7968 SHOW_STR
7969 IPV6_STR
7970 BGP_STR
7971 "Display routes matching the communities\n"
7972 "community number\n"
7973 "Do not send outside local AS (well-known community)\n"
7974 "Do not advertise to any peer (well-known community)\n"
7975 "Do not export to next AS (well-known community)\n")
7976{
7977 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
7978}
7979
7980/* old command */
7981ALIAS (show_ipv6_bgp_community,
7982 show_ipv6_bgp_community2_cmd,
7983 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7984 SHOW_STR
7985 IPV6_STR
7986 BGP_STR
7987 "Display routes matching the communities\n"
7988 "community number\n"
7989 "Do not send outside local AS (well-known community)\n"
7990 "Do not advertise to any peer (well-known community)\n"
7991 "Do not export to next AS (well-known community)\n"
7992 "community number\n"
7993 "Do not send outside local AS (well-known community)\n"
7994 "Do not advertise to any peer (well-known community)\n"
7995 "Do not export to next AS (well-known community)\n")
7996
7997/* old command */
7998ALIAS (show_ipv6_bgp_community,
7999 show_ipv6_bgp_community3_cmd,
8000 "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)",
8001 SHOW_STR
8002 IPV6_STR
8003 BGP_STR
8004 "Display routes matching the communities\n"
8005 "community number\n"
8006 "Do not send outside local AS (well-known community)\n"
8007 "Do not advertise to any peer (well-known community)\n"
8008 "Do not export to next AS (well-known community)\n"
8009 "community number\n"
8010 "Do not send outside local AS (well-known community)\n"
8011 "Do not advertise to any peer (well-known community)\n"
8012 "Do not export to next AS (well-known community)\n"
8013 "community number\n"
8014 "Do not send outside local AS (well-known community)\n"
8015 "Do not advertise to any peer (well-known community)\n"
8016 "Do not export to next AS (well-known community)\n")
8017
8018/* old command */
8019ALIAS (show_ipv6_bgp_community,
8020 show_ipv6_bgp_community4_cmd,
8021 "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)",
8022 SHOW_STR
8023 IPV6_STR
8024 BGP_STR
8025 "Display routes matching the communities\n"
8026 "community number\n"
8027 "Do not send outside local AS (well-known community)\n"
8028 "Do not advertise to any peer (well-known community)\n"
8029 "Do not export to next AS (well-known community)\n"
8030 "community number\n"
8031 "Do not send outside local AS (well-known community)\n"
8032 "Do not advertise to any peer (well-known community)\n"
8033 "Do not export to next AS (well-known community)\n"
8034 "community number\n"
8035 "Do not send outside local AS (well-known community)\n"
8036 "Do not advertise to any peer (well-known community)\n"
8037 "Do not export to next AS (well-known community)\n"
8038 "community number\n"
8039 "Do not send outside local AS (well-known community)\n"
8040 "Do not advertise to any peer (well-known community)\n"
8041 "Do not export to next AS (well-known community)\n")
8042
8043DEFUN (show_bgp_community_exact,
8044 show_bgp_community_exact_cmd,
8045 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8046 SHOW_STR
8047 BGP_STR
8048 "Display routes matching the communities\n"
8049 "community number\n"
8050 "Do not send outside local AS (well-known community)\n"
8051 "Do not advertise to any peer (well-known community)\n"
8052 "Do not export to next AS (well-known community)\n"
8053 "Exact match of the communities")
8054{
8055 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8056}
8057
8058ALIAS (show_bgp_community_exact,
8059 show_bgp_ipv6_community_exact_cmd,
8060 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8061 SHOW_STR
8062 BGP_STR
8063 "Address family\n"
8064 "Display routes matching the communities\n"
8065 "community number\n"
8066 "Do not send outside local AS (well-known community)\n"
8067 "Do not advertise to any peer (well-known community)\n"
8068 "Do not export to next AS (well-known community)\n"
8069 "Exact match of the communities")
8070
8071ALIAS (show_bgp_community_exact,
8072 show_bgp_community2_exact_cmd,
8073 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8074 SHOW_STR
8075 BGP_STR
8076 "Display routes matching the communities\n"
8077 "community number\n"
8078 "Do not send outside local AS (well-known community)\n"
8079 "Do not advertise to any peer (well-known community)\n"
8080 "Do not export to next AS (well-known community)\n"
8081 "community number\n"
8082 "Do not send outside local AS (well-known community)\n"
8083 "Do not advertise to any peer (well-known community)\n"
8084 "Do not export to next AS (well-known community)\n"
8085 "Exact match of the communities")
8086
8087ALIAS (show_bgp_community_exact,
8088 show_bgp_ipv6_community2_exact_cmd,
8089 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8090 SHOW_STR
8091 BGP_STR
8092 "Address family\n"
8093 "Display routes matching the communities\n"
8094 "community number\n"
8095 "Do not send outside local AS (well-known community)\n"
8096 "Do not advertise to any peer (well-known community)\n"
8097 "Do not export to next AS (well-known community)\n"
8098 "community number\n"
8099 "Do not send outside local AS (well-known community)\n"
8100 "Do not advertise to any peer (well-known community)\n"
8101 "Do not export to next AS (well-known community)\n"
8102 "Exact match of the communities")
8103
8104ALIAS (show_bgp_community_exact,
8105 show_bgp_community3_exact_cmd,
8106 "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",
8107 SHOW_STR
8108 BGP_STR
8109 "Display routes matching the communities\n"
8110 "community number\n"
8111 "Do not send outside local AS (well-known community)\n"
8112 "Do not advertise to any peer (well-known community)\n"
8113 "Do not export to next AS (well-known community)\n"
8114 "community number\n"
8115 "Do not send outside local AS (well-known community)\n"
8116 "Do not advertise to any peer (well-known community)\n"
8117 "Do not export to next AS (well-known community)\n"
8118 "community number\n"
8119 "Do not send outside local AS (well-known community)\n"
8120 "Do not advertise to any peer (well-known community)\n"
8121 "Do not export to next AS (well-known community)\n"
8122 "Exact match of the communities")
8123
8124ALIAS (show_bgp_community_exact,
8125 show_bgp_ipv6_community3_exact_cmd,
8126 "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",
8127 SHOW_STR
8128 BGP_STR
8129 "Address family\n"
8130 "Display routes matching the communities\n"
8131 "community number\n"
8132 "Do not send outside local AS (well-known community)\n"
8133 "Do not advertise to any peer (well-known community)\n"
8134 "Do not export to next AS (well-known community)\n"
8135 "community number\n"
8136 "Do not send outside local AS (well-known community)\n"
8137 "Do not advertise to any peer (well-known community)\n"
8138 "Do not export to next AS (well-known community)\n"
8139 "community number\n"
8140 "Do not send outside local AS (well-known community)\n"
8141 "Do not advertise to any peer (well-known community)\n"
8142 "Do not export to next AS (well-known community)\n"
8143 "Exact match of the communities")
8144
8145ALIAS (show_bgp_community_exact,
8146 show_bgp_community4_exact_cmd,
8147 "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",
8148 SHOW_STR
8149 BGP_STR
8150 "Display routes matching the communities\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "community number\n"
8156 "Do not send outside local AS (well-known community)\n"
8157 "Do not advertise to any peer (well-known community)\n"
8158 "Do not export to next AS (well-known community)\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n"
8163 "community number\n"
8164 "Do not send outside local AS (well-known community)\n"
8165 "Do not advertise to any peer (well-known community)\n"
8166 "Do not export to next AS (well-known community)\n"
8167 "Exact match of the communities")
8168
8169ALIAS (show_bgp_community_exact,
8170 show_bgp_ipv6_community4_exact_cmd,
8171 "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",
8172 SHOW_STR
8173 BGP_STR
8174 "Address family\n"
8175 "Display routes matching the communities\n"
8176 "community number\n"
8177 "Do not send outside local AS (well-known community)\n"
8178 "Do not advertise to any peer (well-known community)\n"
8179 "Do not export to next AS (well-known community)\n"
8180 "community number\n"
8181 "Do not send outside local AS (well-known community)\n"
8182 "Do not advertise to any peer (well-known community)\n"
8183 "Do not export to next AS (well-known community)\n"
8184 "community number\n"
8185 "Do not send outside local AS (well-known community)\n"
8186 "Do not advertise to any peer (well-known community)\n"
8187 "Do not export to next AS (well-known community)\n"
8188 "community number\n"
8189 "Do not send outside local AS (well-known community)\n"
8190 "Do not advertise to any peer (well-known community)\n"
8191 "Do not export to next AS (well-known community)\n"
8192 "Exact match of the communities")
8193
8194/* old command */
8195DEFUN (show_ipv6_bgp_community_exact,
8196 show_ipv6_bgp_community_exact_cmd,
8197 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8198 SHOW_STR
8199 IPV6_STR
8200 BGP_STR
8201 "Display routes matching the communities\n"
8202 "community number\n"
8203 "Do not send outside local AS (well-known community)\n"
8204 "Do not advertise to any peer (well-known community)\n"
8205 "Do not export to next AS (well-known community)\n"
8206 "Exact match of the communities")
8207{
8208 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
8209}
8210
8211/* old command */
8212ALIAS (show_ipv6_bgp_community_exact,
8213 show_ipv6_bgp_community2_exact_cmd,
8214 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8215 SHOW_STR
8216 IPV6_STR
8217 BGP_STR
8218 "Display routes matching the communities\n"
8219 "community number\n"
8220 "Do not send outside local AS (well-known community)\n"
8221 "Do not advertise to any peer (well-known community)\n"
8222 "Do not export to next AS (well-known community)\n"
8223 "community number\n"
8224 "Do not send outside local AS (well-known community)\n"
8225 "Do not advertise to any peer (well-known community)\n"
8226 "Do not export to next AS (well-known community)\n"
8227 "Exact match of the communities")
8228
8229/* old command */
8230ALIAS (show_ipv6_bgp_community_exact,
8231 show_ipv6_bgp_community3_exact_cmd,
8232 "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",
8233 SHOW_STR
8234 IPV6_STR
8235 BGP_STR
8236 "Display routes matching the communities\n"
8237 "community number\n"
8238 "Do not send outside local AS (well-known community)\n"
8239 "Do not advertise to any peer (well-known community)\n"
8240 "Do not export to next AS (well-known community)\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n"
8245 "community number\n"
8246 "Do not send outside local AS (well-known community)\n"
8247 "Do not advertise to any peer (well-known community)\n"
8248 "Do not export to next AS (well-known community)\n"
8249 "Exact match of the communities")
8250
8251/* old command */
8252ALIAS (show_ipv6_bgp_community_exact,
8253 show_ipv6_bgp_community4_exact_cmd,
8254 "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",
8255 SHOW_STR
8256 IPV6_STR
8257 BGP_STR
8258 "Display routes matching the communities\n"
8259 "community number\n"
8260 "Do not send outside local AS (well-known community)\n"
8261 "Do not advertise to any peer (well-known community)\n"
8262 "Do not export to next AS (well-known community)\n"
8263 "community number\n"
8264 "Do not send outside local AS (well-known community)\n"
8265 "Do not advertise to any peer (well-known community)\n"
8266 "Do not export to next AS (well-known community)\n"
8267 "community number\n"
8268 "Do not send outside local AS (well-known community)\n"
8269 "Do not advertise to any peer (well-known community)\n"
8270 "Do not export to next AS (well-known community)\n"
8271 "community number\n"
8272 "Do not send outside local AS (well-known community)\n"
8273 "Do not advertise to any peer (well-known community)\n"
8274 "Do not export to next AS (well-known community)\n"
8275 "Exact match of the communities")
8276
8277/* old command */
8278DEFUN (show_ipv6_mbgp_community,
8279 show_ipv6_mbgp_community_cmd,
8280 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8281 SHOW_STR
8282 IPV6_STR
8283 MBGP_STR
8284 "Display routes matching the communities\n"
8285 "community number\n"
8286 "Do not send outside local AS (well-known community)\n"
8287 "Do not advertise to any peer (well-known community)\n"
8288 "Do not export to next AS (well-known community)\n")
8289{
8290 return bgp_show_community (vty, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
8291}
8292
8293/* old command */
8294ALIAS (show_ipv6_mbgp_community,
8295 show_ipv6_mbgp_community2_cmd,
8296 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8297 SHOW_STR
8298 IPV6_STR
8299 MBGP_STR
8300 "Display routes matching the communities\n"
8301 "community number\n"
8302 "Do not send outside local AS (well-known community)\n"
8303 "Do not advertise to any peer (well-known community)\n"
8304 "Do not export to next AS (well-known community)\n"
8305 "community number\n"
8306 "Do not send outside local AS (well-known community)\n"
8307 "Do not advertise to any peer (well-known community)\n"
8308 "Do not export to next AS (well-known community)\n")
8309
8310/* old command */
8311ALIAS (show_ipv6_mbgp_community,
8312 show_ipv6_mbgp_community3_cmd,
8313 "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)",
8314 SHOW_STR
8315 IPV6_STR
8316 MBGP_STR
8317 "Display routes matching the communities\n"
8318 "community number\n"
8319 "Do not send outside local AS (well-known community)\n"
8320 "Do not advertise to any peer (well-known community)\n"
8321 "Do not export to next AS (well-known community)\n"
8322 "community number\n"
8323 "Do not send outside local AS (well-known community)\n"
8324 "Do not advertise to any peer (well-known community)\n"
8325 "Do not export to next AS (well-known community)\n"
8326 "community number\n"
8327 "Do not send outside local AS (well-known community)\n"
8328 "Do not advertise to any peer (well-known community)\n"
8329 "Do not export to next AS (well-known community)\n")
8330
8331/* old command */
8332ALIAS (show_ipv6_mbgp_community,
8333 show_ipv6_mbgp_community4_cmd,
8334 "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)",
8335 SHOW_STR
8336 IPV6_STR
8337 MBGP_STR
8338 "Display routes matching the communities\n"
8339 "community number\n"
8340 "Do not send outside local AS (well-known community)\n"
8341 "Do not advertise to any peer (well-known community)\n"
8342 "Do not export to next AS (well-known community)\n"
8343 "community number\n"
8344 "Do not send outside local AS (well-known community)\n"
8345 "Do not advertise to any peer (well-known community)\n"
8346 "Do not export to next AS (well-known community)\n"
8347 "community number\n"
8348 "Do not send outside local AS (well-known community)\n"
8349 "Do not advertise to any peer (well-known community)\n"
8350 "Do not export to next AS (well-known community)\n"
8351 "community number\n"
8352 "Do not send outside local AS (well-known community)\n"
8353 "Do not advertise to any peer (well-known community)\n"
8354 "Do not export to next AS (well-known community)\n")
8355
8356/* old command */
8357DEFUN (show_ipv6_mbgp_community_exact,
8358 show_ipv6_mbgp_community_exact_cmd,
8359 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8360 SHOW_STR
8361 IPV6_STR
8362 MBGP_STR
8363 "Display routes matching the communities\n"
8364 "community number\n"
8365 "Do not send outside local AS (well-known community)\n"
8366 "Do not advertise to any peer (well-known community)\n"
8367 "Do not export to next AS (well-known community)\n"
8368 "Exact match of the communities")
8369{
8370 return bgp_show_community (vty, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
8371}
8372
8373/* old command */
8374ALIAS (show_ipv6_mbgp_community_exact,
8375 show_ipv6_mbgp_community2_exact_cmd,
8376 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8377 SHOW_STR
8378 IPV6_STR
8379 MBGP_STR
8380 "Display routes matching the communities\n"
8381 "community number\n"
8382 "Do not send outside local AS (well-known community)\n"
8383 "Do not advertise to any peer (well-known community)\n"
8384 "Do not export to next AS (well-known community)\n"
8385 "community number\n"
8386 "Do not send outside local AS (well-known community)\n"
8387 "Do not advertise to any peer (well-known community)\n"
8388 "Do not export to next AS (well-known community)\n"
8389 "Exact match of the communities")
8390
8391/* old command */
8392ALIAS (show_ipv6_mbgp_community_exact,
8393 show_ipv6_mbgp_community3_exact_cmd,
8394 "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",
8395 SHOW_STR
8396 IPV6_STR
8397 MBGP_STR
8398 "Display routes matching the communities\n"
8399 "community number\n"
8400 "Do not send outside local AS (well-known community)\n"
8401 "Do not advertise to any peer (well-known community)\n"
8402 "Do not export to next AS (well-known community)\n"
8403 "community number\n"
8404 "Do not send outside local AS (well-known community)\n"
8405 "Do not advertise to any peer (well-known community)\n"
8406 "Do not export to next AS (well-known community)\n"
8407 "community number\n"
8408 "Do not send outside local AS (well-known community)\n"
8409 "Do not advertise to any peer (well-known community)\n"
8410 "Do not export to next AS (well-known community)\n"
8411 "Exact match of the communities")
8412
8413/* old command */
8414ALIAS (show_ipv6_mbgp_community_exact,
8415 show_ipv6_mbgp_community4_exact_cmd,
8416 "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",
8417 SHOW_STR
8418 IPV6_STR
8419 MBGP_STR
8420 "Display routes matching the communities\n"
8421 "community number\n"
8422 "Do not send outside local AS (well-known community)\n"
8423 "Do not advertise to any peer (well-known community)\n"
8424 "Do not export to next AS (well-known community)\n"
8425 "community number\n"
8426 "Do not send outside local AS (well-known community)\n"
8427 "Do not advertise to any peer (well-known community)\n"
8428 "Do not export to next AS (well-known community)\n"
8429 "community number\n"
8430 "Do not send outside local AS (well-known community)\n"
8431 "Do not advertise to any peer (well-known community)\n"
8432 "Do not export to next AS (well-known community)\n"
8433 "community number\n"
8434 "Do not send outside local AS (well-known community)\n"
8435 "Do not advertise to any peer (well-known community)\n"
8436 "Do not export to next AS (well-known community)\n"
8437 "Exact match of the communities")
8438#endif /* HAVE_IPV6 */
8439
paul94f2b392005-06-28 12:44:16 +00008440static int
paulfd79ac92004-10-13 05:06:08 +00008441bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008442 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008443{
8444 struct community_list *list;
8445
hassofee6e4e2005-02-02 16:29:31 +00008446 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008447 if (list == NULL)
8448 {
8449 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8450 VTY_NEWLINE);
8451 return CMD_WARNING;
8452 }
8453
ajs5a646652004-11-05 01:25:55 +00008454 return bgp_show (vty, NULL, afi, safi,
8455 (exact ? bgp_show_type_community_list_exact :
8456 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008457}
8458
8459DEFUN (show_ip_bgp_community_list,
8460 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008461 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008462 SHOW_STR
8463 IP_STR
8464 BGP_STR
8465 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008466 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008467 "community-list name\n")
8468{
8469 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8470}
8471
8472DEFUN (show_ip_bgp_ipv4_community_list,
8473 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008474 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008475 SHOW_STR
8476 IP_STR
8477 BGP_STR
8478 "Address family\n"
8479 "Address Family modifier\n"
8480 "Address Family modifier\n"
8481 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008482 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008483 "community-list name\n")
8484{
8485 if (strncmp (argv[0], "m", 1) == 0)
8486 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8487
8488 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8489}
8490
8491DEFUN (show_ip_bgp_community_list_exact,
8492 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008493 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008494 SHOW_STR
8495 IP_STR
8496 BGP_STR
8497 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008498 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008499 "community-list name\n"
8500 "Exact match of the communities\n")
8501{
8502 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8503}
8504
8505DEFUN (show_ip_bgp_ipv4_community_list_exact,
8506 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008507 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008508 SHOW_STR
8509 IP_STR
8510 BGP_STR
8511 "Address family\n"
8512 "Address Family modifier\n"
8513 "Address Family modifier\n"
8514 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008515 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008516 "community-list name\n"
8517 "Exact match of the communities\n")
8518{
8519 if (strncmp (argv[0], "m", 1) == 0)
8520 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8521
8522 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8523}
8524
8525#ifdef HAVE_IPV6
8526DEFUN (show_bgp_community_list,
8527 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008528 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008529 SHOW_STR
8530 BGP_STR
8531 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008532 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008533 "community-list name\n")
8534{
8535 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8536}
8537
8538ALIAS (show_bgp_community_list,
8539 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008540 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008541 SHOW_STR
8542 BGP_STR
8543 "Address family\n"
8544 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008545 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008546 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008547
8548/* old command */
8549DEFUN (show_ipv6_bgp_community_list,
8550 show_ipv6_bgp_community_list_cmd,
8551 "show ipv6 bgp community-list WORD",
8552 SHOW_STR
8553 IPV6_STR
8554 BGP_STR
8555 "Display routes matching the community-list\n"
8556 "community-list name\n")
8557{
8558 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8559}
8560
8561/* old command */
8562DEFUN (show_ipv6_mbgp_community_list,
8563 show_ipv6_mbgp_community_list_cmd,
8564 "show ipv6 mbgp community-list WORD",
8565 SHOW_STR
8566 IPV6_STR
8567 MBGP_STR
8568 "Display routes matching the community-list\n"
8569 "community-list name\n")
8570{
8571 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8572}
8573
8574DEFUN (show_bgp_community_list_exact,
8575 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008576 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008577 SHOW_STR
8578 BGP_STR
8579 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008580 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008581 "community-list name\n"
8582 "Exact match of the communities\n")
8583{
8584 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8585}
8586
8587ALIAS (show_bgp_community_list_exact,
8588 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008589 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008590 SHOW_STR
8591 BGP_STR
8592 "Address family\n"
8593 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008594 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008595 "community-list name\n"
8596 "Exact match of the communities\n")
8597
8598/* old command */
8599DEFUN (show_ipv6_bgp_community_list_exact,
8600 show_ipv6_bgp_community_list_exact_cmd,
8601 "show ipv6 bgp community-list WORD exact-match",
8602 SHOW_STR
8603 IPV6_STR
8604 BGP_STR
8605 "Display routes matching the community-list\n"
8606 "community-list name\n"
8607 "Exact match of the communities\n")
8608{
8609 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8610}
8611
8612/* old command */
8613DEFUN (show_ipv6_mbgp_community_list_exact,
8614 show_ipv6_mbgp_community_list_exact_cmd,
8615 "show ipv6 mbgp community-list WORD exact-match",
8616 SHOW_STR
8617 IPV6_STR
8618 MBGP_STR
8619 "Display routes matching the community-list\n"
8620 "community-list name\n"
8621 "Exact match of the communities\n")
8622{
8623 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8624}
8625#endif /* HAVE_IPV6 */
8626
paul94f2b392005-06-28 12:44:16 +00008627static int
paulfd79ac92004-10-13 05:06:08 +00008628bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008629 safi_t safi, enum bgp_show_type type)
8630{
8631 int ret;
8632 struct prefix *p;
8633
8634 p = prefix_new();
8635
8636 ret = str2prefix (prefix, p);
8637 if (! ret)
8638 {
8639 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8640 return CMD_WARNING;
8641 }
8642
ajs5a646652004-11-05 01:25:55 +00008643 ret = bgp_show (vty, NULL, afi, safi, type, p);
8644 prefix_free(p);
8645 return ret;
paul718e3742002-12-13 20:15:29 +00008646}
8647
8648DEFUN (show_ip_bgp_prefix_longer,
8649 show_ip_bgp_prefix_longer_cmd,
8650 "show ip bgp A.B.C.D/M longer-prefixes",
8651 SHOW_STR
8652 IP_STR
8653 BGP_STR
8654 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8655 "Display route and more specific routes\n")
8656{
8657 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8658 bgp_show_type_prefix_longer);
8659}
8660
8661DEFUN (show_ip_bgp_flap_prefix_longer,
8662 show_ip_bgp_flap_prefix_longer_cmd,
8663 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8664 SHOW_STR
8665 IP_STR
8666 BGP_STR
8667 "Display flap statistics of routes\n"
8668 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8669 "Display route and more specific routes\n")
8670{
8671 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8672 bgp_show_type_flap_prefix_longer);
8673}
8674
8675DEFUN (show_ip_bgp_ipv4_prefix_longer,
8676 show_ip_bgp_ipv4_prefix_longer_cmd,
8677 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
8678 SHOW_STR
8679 IP_STR
8680 BGP_STR
8681 "Address family\n"
8682 "Address Family modifier\n"
8683 "Address Family modifier\n"
8684 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8685 "Display route and more specific routes\n")
8686{
8687 if (strncmp (argv[0], "m", 1) == 0)
8688 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
8689 bgp_show_type_prefix_longer);
8690
8691 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
8692 bgp_show_type_prefix_longer);
8693}
8694
8695DEFUN (show_ip_bgp_flap_address,
8696 show_ip_bgp_flap_address_cmd,
8697 "show ip bgp flap-statistics A.B.C.D",
8698 SHOW_STR
8699 IP_STR
8700 BGP_STR
8701 "Display flap statistics of routes\n"
8702 "Network in the BGP routing table to display\n")
8703{
8704 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8705 bgp_show_type_flap_address);
8706}
8707
8708DEFUN (show_ip_bgp_flap_prefix,
8709 show_ip_bgp_flap_prefix_cmd,
8710 "show ip bgp flap-statistics A.B.C.D/M",
8711 SHOW_STR
8712 IP_STR
8713 BGP_STR
8714 "Display flap statistics of routes\n"
8715 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
8716{
8717 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8718 bgp_show_type_flap_prefix);
8719}
8720#ifdef HAVE_IPV6
8721DEFUN (show_bgp_prefix_longer,
8722 show_bgp_prefix_longer_cmd,
8723 "show bgp X:X::X:X/M longer-prefixes",
8724 SHOW_STR
8725 BGP_STR
8726 "IPv6 prefix <network>/<length>\n"
8727 "Display route and more specific routes\n")
8728{
8729 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8730 bgp_show_type_prefix_longer);
8731}
8732
8733ALIAS (show_bgp_prefix_longer,
8734 show_bgp_ipv6_prefix_longer_cmd,
8735 "show bgp ipv6 X:X::X:X/M longer-prefixes",
8736 SHOW_STR
8737 BGP_STR
8738 "Address family\n"
8739 "IPv6 prefix <network>/<length>\n"
8740 "Display route and more specific routes\n")
8741
8742/* old command */
8743DEFUN (show_ipv6_bgp_prefix_longer,
8744 show_ipv6_bgp_prefix_longer_cmd,
8745 "show ipv6 bgp X:X::X:X/M longer-prefixes",
8746 SHOW_STR
8747 IPV6_STR
8748 BGP_STR
8749 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8750 "Display route and more specific routes\n")
8751{
8752 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
8753 bgp_show_type_prefix_longer);
8754}
8755
8756/* old command */
8757DEFUN (show_ipv6_mbgp_prefix_longer,
8758 show_ipv6_mbgp_prefix_longer_cmd,
8759 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
8760 SHOW_STR
8761 IPV6_STR
8762 MBGP_STR
8763 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
8764 "Display route and more specific routes\n")
8765{
8766 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
8767 bgp_show_type_prefix_longer);
8768}
8769#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00008770
paul94f2b392005-06-28 12:44:16 +00008771static struct peer *
paulfd79ac92004-10-13 05:06:08 +00008772peer_lookup_in_view (struct vty *vty, const char *view_name,
8773 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00008774{
8775 int ret;
8776 struct bgp *bgp;
8777 struct peer *peer;
8778 union sockunion su;
8779
8780 /* BGP structure lookup. */
8781 if (view_name)
8782 {
8783 bgp = bgp_lookup_by_name (view_name);
8784 if (! bgp)
8785 {
8786 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
8787 return NULL;
8788 }
8789 }
paul5228ad22004-06-04 17:58:18 +00008790 else
paulbb46e942003-10-24 19:02:03 +00008791 {
8792 bgp = bgp_get_default ();
8793 if (! bgp)
8794 {
8795 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
8796 return NULL;
8797 }
8798 }
8799
8800 /* Get peer sockunion. */
8801 ret = str2sockunion (ip_str, &su);
8802 if (ret < 0)
8803 {
8804 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
8805 return NULL;
8806 }
8807
8808 /* Peer structure lookup. */
8809 peer = peer_lookup (bgp, &su);
8810 if (! peer)
8811 {
8812 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
8813 return NULL;
8814 }
8815
8816 return peer;
8817}
Paul Jakma2815e612006-09-14 02:56:07 +00008818
8819enum bgp_stats
8820{
8821 BGP_STATS_MAXBITLEN = 0,
8822 BGP_STATS_RIB,
8823 BGP_STATS_PREFIXES,
8824 BGP_STATS_TOTPLEN,
8825 BGP_STATS_UNAGGREGATEABLE,
8826 BGP_STATS_MAX_AGGREGATEABLE,
8827 BGP_STATS_AGGREGATES,
8828 BGP_STATS_SPACE,
8829 BGP_STATS_ASPATH_COUNT,
8830 BGP_STATS_ASPATH_MAXHOPS,
8831 BGP_STATS_ASPATH_TOTHOPS,
8832 BGP_STATS_ASPATH_MAXSIZE,
8833 BGP_STATS_ASPATH_TOTSIZE,
8834 BGP_STATS_ASN_HIGHEST,
8835 BGP_STATS_MAX,
8836};
paulbb46e942003-10-24 19:02:03 +00008837
Paul Jakma2815e612006-09-14 02:56:07 +00008838static const char *table_stats_strs[] =
8839{
8840 [BGP_STATS_PREFIXES] = "Total Prefixes",
8841 [BGP_STATS_TOTPLEN] = "Average prefix length",
8842 [BGP_STATS_RIB] = "Total Advertisements",
8843 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
8844 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
8845 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
8846 [BGP_STATS_SPACE] = "Address space advertised",
8847 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
8848 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
8849 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
8850 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
8851 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
8852 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
8853 [BGP_STATS_MAX] = NULL,
8854};
8855
8856struct bgp_table_stats
8857{
8858 struct bgp_table *table;
8859 unsigned long long counts[BGP_STATS_MAX];
8860};
8861
8862#if 0
8863#define TALLY_SIGFIG 100000
8864static unsigned long
8865ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
8866{
8867 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
8868 unsigned long res = (newtot * TALLY_SIGFIG) / count;
8869 unsigned long ret = newtot / count;
8870
8871 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
8872 return ret + 1;
8873 else
8874 return ret;
8875}
8876#endif
8877
8878static int
8879bgp_table_stats_walker (struct thread *t)
8880{
8881 struct bgp_node *rn;
8882 struct bgp_node *top;
8883 struct bgp_table_stats *ts = THREAD_ARG (t);
8884 unsigned int space = 0;
8885
Paul Jakma53d9f672006-10-15 23:41:16 +00008886 if (!(top = bgp_table_top (ts->table)))
8887 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00008888
8889 switch (top->p.family)
8890 {
8891 case AF_INET:
8892 space = IPV4_MAX_BITLEN;
8893 break;
8894 case AF_INET6:
8895 space = IPV6_MAX_BITLEN;
8896 break;
8897 }
8898
8899 ts->counts[BGP_STATS_MAXBITLEN] = space;
8900
8901 for (rn = top; rn; rn = bgp_route_next (rn))
8902 {
8903 struct bgp_info *ri;
8904 struct bgp_node *prn = rn->parent;
8905 unsigned int rinum = 0;
8906
8907 if (rn == top)
8908 continue;
8909
8910 if (!rn->info)
8911 continue;
8912
8913 ts->counts[BGP_STATS_PREFIXES]++;
8914 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
8915
8916#if 0
8917 ts->counts[BGP_STATS_AVGPLEN]
8918 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
8919 ts->counts[BGP_STATS_AVGPLEN],
8920 rn->p.prefixlen);
8921#endif
8922
8923 /* check if the prefix is included by any other announcements */
8924 while (prn && !prn->info)
8925 prn = prn->parent;
8926
8927 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00008928 {
8929 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
8930 /* announced address space */
8931 if (space)
8932 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
8933 }
Paul Jakma2815e612006-09-14 02:56:07 +00008934 else if (prn->info)
8935 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
8936
Paul Jakma2815e612006-09-14 02:56:07 +00008937 for (ri = rn->info; ri; ri = ri->next)
8938 {
8939 rinum++;
8940 ts->counts[BGP_STATS_RIB]++;
8941
8942 if (ri->attr &&
8943 (CHECK_FLAG (ri->attr->flag,
8944 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
8945 ts->counts[BGP_STATS_AGGREGATES]++;
8946
8947 /* as-path stats */
8948 if (ri->attr && ri->attr->aspath)
8949 {
8950 unsigned int hops = aspath_count_hops (ri->attr->aspath);
8951 unsigned int size = aspath_size (ri->attr->aspath);
8952 as_t highest = aspath_highest (ri->attr->aspath);
8953
8954 ts->counts[BGP_STATS_ASPATH_COUNT]++;
8955
8956 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
8957 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
8958
8959 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
8960 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
8961
8962 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
8963 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
8964#if 0
8965 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
8966 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8967 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
8968 hops);
8969 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
8970 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
8971 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
8972 size);
8973#endif
8974 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
8975 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
8976 }
8977 }
8978 }
8979 return 0;
8980}
8981
8982static int
8983bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
8984{
8985 struct bgp_table_stats ts;
8986 unsigned int i;
8987
8988 if (!bgp->rib[afi][safi])
8989 {
8990 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
8991 return CMD_WARNING;
8992 }
8993
8994 memset (&ts, 0, sizeof (ts));
8995 ts.table = bgp->rib[afi][safi];
8996 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
8997
8998 vty_out (vty, "BGP %s RIB statistics%s%s",
8999 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9000
9001 for (i = 0; i < BGP_STATS_MAX; i++)
9002 {
9003 if (!table_stats_strs[i])
9004 continue;
9005
9006 switch (i)
9007 {
9008#if 0
9009 case BGP_STATS_ASPATH_AVGHOPS:
9010 case BGP_STATS_ASPATH_AVGSIZE:
9011 case BGP_STATS_AVGPLEN:
9012 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9013 vty_out (vty, "%12.2f",
9014 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9015 break;
9016#endif
9017 case BGP_STATS_ASPATH_TOTHOPS:
9018 case BGP_STATS_ASPATH_TOTSIZE:
9019 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9020 vty_out (vty, "%12.2f",
9021 ts.counts[i] ?
9022 (float)ts.counts[i] /
9023 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9024 : 0);
9025 break;
9026 case BGP_STATS_TOTPLEN:
9027 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9028 vty_out (vty, "%12.2f",
9029 ts.counts[i] ?
9030 (float)ts.counts[i] /
9031 (float)ts.counts[BGP_STATS_PREFIXES]
9032 : 0);
9033 break;
9034 case BGP_STATS_SPACE:
9035 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9036 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9037 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9038 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009039 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009040 vty_out (vty, "%12.2f%s",
9041 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009042 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009043 VTY_NEWLINE);
9044 vty_out (vty, "%30s: ", "/8 equivalent ");
9045 vty_out (vty, "%12.2f%s",
9046 (float)ts.counts[BGP_STATS_SPACE] /
9047 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9048 VTY_NEWLINE);
9049 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9050 break;
9051 vty_out (vty, "%30s: ", "/24 equivalent ");
9052 vty_out (vty, "%12.2f",
9053 (float)ts.counts[BGP_STATS_SPACE] /
9054 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9055 break;
9056 default:
9057 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9058 vty_out (vty, "%12llu", ts.counts[i]);
9059 }
9060
9061 vty_out (vty, "%s", VTY_NEWLINE);
9062 }
9063 return CMD_SUCCESS;
9064}
9065
9066static int
9067bgp_table_stats_vty (struct vty *vty, const char *name,
9068 const char *afi_str, const char *safi_str)
9069{
9070 struct bgp *bgp;
9071 afi_t afi;
9072 safi_t safi;
9073
9074 if (name)
9075 bgp = bgp_lookup_by_name (name);
9076 else
9077 bgp = bgp_get_default ();
9078
9079 if (!bgp)
9080 {
9081 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9082 return CMD_WARNING;
9083 }
9084 if (strncmp (afi_str, "ipv", 3) == 0)
9085 {
9086 if (strncmp (afi_str, "ipv4", 4) == 0)
9087 afi = AFI_IP;
9088 else if (strncmp (afi_str, "ipv6", 4) == 0)
9089 afi = AFI_IP6;
9090 else
9091 {
9092 vty_out (vty, "%% Invalid address family %s%s",
9093 afi_str, VTY_NEWLINE);
9094 return CMD_WARNING;
9095 }
9096 if (strncmp (safi_str, "m", 1) == 0)
9097 safi = SAFI_MULTICAST;
9098 else if (strncmp (safi_str, "u", 1) == 0)
9099 safi = SAFI_UNICAST;
Denis Ovsienkoe81537d2011-07-14 12:36:19 +04009100 else if (strncmp (safi_str, "vpnv4", 5) == 0 || strncmp (safi_str, "vpnv6", 5) == 0)
9101 safi = SAFI_MPLS_LABELED_VPN;
Paul Jakma2815e612006-09-14 02:56:07 +00009102 else
9103 {
9104 vty_out (vty, "%% Invalid subsequent address family %s%s",
9105 safi_str, VTY_NEWLINE);
9106 return CMD_WARNING;
9107 }
9108 }
9109 else
9110 {
9111 vty_out (vty, "%% Invalid address family %s%s",
9112 afi_str, VTY_NEWLINE);
9113 return CMD_WARNING;
9114 }
9115
Paul Jakma2815e612006-09-14 02:56:07 +00009116 return bgp_table_stats (vty, bgp, afi, safi);
9117}
9118
9119DEFUN (show_bgp_statistics,
9120 show_bgp_statistics_cmd,
9121 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9122 SHOW_STR
9123 BGP_STR
9124 "Address family\n"
9125 "Address family\n"
9126 "Address Family modifier\n"
9127 "Address Family modifier\n"
9128 "BGP RIB advertisement statistics\n")
9129{
9130 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9131}
9132
9133ALIAS (show_bgp_statistics,
9134 show_bgp_statistics_vpnv4_cmd,
9135 "show bgp (ipv4) (vpnv4) statistics",
9136 SHOW_STR
9137 BGP_STR
9138 "Address family\n"
9139 "Address Family modifier\n"
9140 "BGP RIB advertisement statistics\n")
9141
9142DEFUN (show_bgp_statistics_view,
9143 show_bgp_statistics_view_cmd,
9144 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9145 SHOW_STR
9146 BGP_STR
9147 "BGP view\n"
9148 "Address family\n"
9149 "Address family\n"
9150 "Address Family modifier\n"
9151 "Address Family modifier\n"
9152 "BGP RIB advertisement statistics\n")
9153{
9154 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9155}
9156
9157ALIAS (show_bgp_statistics_view,
9158 show_bgp_statistics_view_vpnv4_cmd,
9159 "show bgp view WORD (ipv4) (vpnv4) statistics",
9160 SHOW_STR
9161 BGP_STR
9162 "BGP view\n"
9163 "Address family\n"
9164 "Address Family modifier\n"
9165 "BGP RIB advertisement statistics\n")
9166
Paul Jakmaff7924f2006-09-04 01:10:36 +00009167enum bgp_pcounts
9168{
9169 PCOUNT_ADJ_IN = 0,
9170 PCOUNT_DAMPED,
9171 PCOUNT_REMOVED,
9172 PCOUNT_HISTORY,
9173 PCOUNT_STALE,
9174 PCOUNT_VALID,
9175 PCOUNT_ALL,
9176 PCOUNT_COUNTED,
9177 PCOUNT_PFCNT, /* the figure we display to users */
9178 PCOUNT_MAX,
9179};
9180
9181static const char *pcount_strs[] =
9182{
9183 [PCOUNT_ADJ_IN] = "Adj-in",
9184 [PCOUNT_DAMPED] = "Damped",
9185 [PCOUNT_REMOVED] = "Removed",
9186 [PCOUNT_HISTORY] = "History",
9187 [PCOUNT_STALE] = "Stale",
9188 [PCOUNT_VALID] = "Valid",
9189 [PCOUNT_ALL] = "All RIB",
9190 [PCOUNT_COUNTED] = "PfxCt counted",
9191 [PCOUNT_PFCNT] = "Useable",
9192 [PCOUNT_MAX] = NULL,
9193};
9194
Paul Jakma2815e612006-09-14 02:56:07 +00009195struct peer_pcounts
9196{
9197 unsigned int count[PCOUNT_MAX];
9198 const struct peer *peer;
9199 const struct bgp_table *table;
9200};
9201
Paul Jakmaff7924f2006-09-04 01:10:36 +00009202static int
Paul Jakma2815e612006-09-14 02:56:07 +00009203bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009204{
9205 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009206 struct peer_pcounts *pc = THREAD_ARG (t);
9207 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009208
Paul Jakma2815e612006-09-14 02:56:07 +00009209 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009210 {
9211 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009212 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009213
9214 for (ain = rn->adj_in; ain; ain = ain->next)
9215 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009216 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009217
Paul Jakmaff7924f2006-09-04 01:10:36 +00009218 for (ri = rn->info; ri; ri = ri->next)
9219 {
9220 char buf[SU_ADDRSTRLEN];
9221
9222 if (ri->peer != peer)
9223 continue;
9224
Paul Jakma2815e612006-09-14 02:56:07 +00009225 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009226
9227 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009228 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009229 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009230 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009231 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009232 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009233 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009234 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009235 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009236 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009237 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009238 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009239
9240 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9241 {
Paul Jakma2815e612006-09-14 02:56:07 +00009242 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009243 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009244 plog_warn (peer->log,
9245 "%s [pcount] %s/%d is counted but flags 0x%x",
9246 peer->host,
9247 inet_ntop(rn->p.family, &rn->p.u.prefix,
9248 buf, SU_ADDRSTRLEN),
9249 rn->p.prefixlen,
9250 ri->flags);
9251 }
9252 else
9253 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009254 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009255 plog_warn (peer->log,
9256 "%s [pcount] %s/%d not counted but flags 0x%x",
9257 peer->host,
9258 inet_ntop(rn->p.family, &rn->p.u.prefix,
9259 buf, SU_ADDRSTRLEN),
9260 rn->p.prefixlen,
9261 ri->flags);
9262 }
9263 }
9264 }
Paul Jakma2815e612006-09-14 02:56:07 +00009265 return 0;
9266}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009267
Paul Jakma2815e612006-09-14 02:56:07 +00009268static int
9269bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9270{
9271 struct peer_pcounts pcounts = { .peer = peer };
9272 unsigned int i;
9273
9274 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9275 || !peer->bgp->rib[afi][safi])
9276 {
9277 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9278 return CMD_WARNING;
9279 }
9280
9281 memset (&pcounts, 0, sizeof(pcounts));
9282 pcounts.peer = peer;
9283 pcounts.table = peer->bgp->rib[afi][safi];
9284
9285 /* in-place call via thread subsystem so as to record execution time
9286 * stats for the thread-walk (i.e. ensure this can't be blamed on
9287 * on just vty_read()).
9288 */
9289 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9290
Paul Jakmaff7924f2006-09-04 01:10:36 +00009291 vty_out (vty, "Prefix counts for %s, %s%s",
9292 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9293 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9294 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9295 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9296
9297 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009298 vty_out (vty, "%20s: %-10d%s",
9299 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009300
Paul Jakma2815e612006-09-14 02:56:07 +00009301 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009302 {
9303 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9304 peer->host, VTY_NEWLINE);
9305 vty_out (vty, "Please report this bug, with the above command output%s",
9306 VTY_NEWLINE);
9307 }
9308
9309 return CMD_SUCCESS;
9310}
9311
9312DEFUN (show_ip_bgp_neighbor_prefix_counts,
9313 show_ip_bgp_neighbor_prefix_counts_cmd,
9314 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9315 SHOW_STR
9316 IP_STR
9317 BGP_STR
9318 "Detailed information on TCP and BGP neighbor connections\n"
9319 "Neighbor to display information about\n"
9320 "Neighbor to display information about\n"
9321 "Display detailed prefix count information\n")
9322{
9323 struct peer *peer;
9324
9325 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9326 if (! peer)
9327 return CMD_WARNING;
9328
9329 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9330}
9331
9332DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9333 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9334 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9335 SHOW_STR
9336 BGP_STR
9337 "Address family\n"
9338 "Detailed information on TCP and BGP neighbor connections\n"
9339 "Neighbor to display information about\n"
9340 "Neighbor to display information about\n"
9341 "Display detailed prefix count information\n")
9342{
9343 struct peer *peer;
9344
9345 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9346 if (! peer)
9347 return CMD_WARNING;
9348
9349 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9350}
9351
9352DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9353 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9354 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9355 SHOW_STR
9356 IP_STR
9357 BGP_STR
9358 "Address family\n"
9359 "Address Family modifier\n"
9360 "Address Family modifier\n"
9361 "Detailed information on TCP and BGP neighbor connections\n"
9362 "Neighbor to display information about\n"
9363 "Neighbor to display information about\n"
9364 "Display detailed prefix count information\n")
9365{
9366 struct peer *peer;
9367
9368 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9369 if (! peer)
9370 return CMD_WARNING;
9371
9372 if (strncmp (argv[0], "m", 1) == 0)
9373 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9374
9375 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9376}
9377
9378DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9379 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9380 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9381 SHOW_STR
9382 IP_STR
9383 BGP_STR
9384 "Address family\n"
9385 "Address Family modifier\n"
9386 "Address Family modifier\n"
9387 "Detailed information on TCP and BGP neighbor connections\n"
9388 "Neighbor to display information about\n"
9389 "Neighbor to display information about\n"
9390 "Display detailed prefix count information\n")
9391{
9392 struct peer *peer;
9393
9394 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9395 if (! peer)
9396 return CMD_WARNING;
9397
9398 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9399}
9400
9401
paul94f2b392005-06-28 12:44:16 +00009402static void
paul718e3742002-12-13 20:15:29 +00009403show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9404 int in)
9405{
9406 struct bgp_table *table;
9407 struct bgp_adj_in *ain;
9408 struct bgp_adj_out *adj;
9409 unsigned long output_count;
9410 struct bgp_node *rn;
9411 int header1 = 1;
9412 struct bgp *bgp;
9413 int header2 = 1;
9414
paulbb46e942003-10-24 19:02:03 +00009415 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009416
9417 if (! bgp)
9418 return;
9419
9420 table = bgp->rib[afi][safi];
9421
9422 output_count = 0;
9423
9424 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9425 PEER_STATUS_DEFAULT_ORIGINATE))
9426 {
9427 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 +00009428 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9429 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009430
9431 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9432 VTY_NEWLINE, VTY_NEWLINE);
9433 header1 = 0;
9434 }
9435
9436 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9437 if (in)
9438 {
9439 for (ain = rn->adj_in; ain; ain = ain->next)
9440 if (ain->peer == peer)
9441 {
9442 if (header1)
9443 {
9444 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 +00009445 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9446 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009447 header1 = 0;
9448 }
9449 if (header2)
9450 {
9451 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9452 header2 = 0;
9453 }
9454 if (ain->attr)
9455 {
9456 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9457 output_count++;
9458 }
9459 }
9460 }
9461 else
9462 {
9463 for (adj = rn->adj_out; adj; adj = adj->next)
9464 if (adj->peer == peer)
9465 {
9466 if (header1)
9467 {
9468 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 +00009469 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9470 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009471 header1 = 0;
9472 }
9473 if (header2)
9474 {
9475 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9476 header2 = 0;
9477 }
9478 if (adj->attr)
9479 {
9480 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9481 output_count++;
9482 }
9483 }
9484 }
9485
9486 if (output_count != 0)
9487 vty_out (vty, "%sTotal number of prefixes %ld%s",
9488 VTY_NEWLINE, output_count, VTY_NEWLINE);
9489}
9490
paul94f2b392005-06-28 12:44:16 +00009491static int
paulbb46e942003-10-24 19:02:03 +00009492peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9493{
paul718e3742002-12-13 20:15:29 +00009494 if (! peer || ! peer->afc[afi][safi])
9495 {
9496 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9497 return CMD_WARNING;
9498 }
9499
9500 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9501 {
9502 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9503 VTY_NEWLINE);
9504 return CMD_WARNING;
9505 }
9506
9507 show_adj_route (vty, peer, afi, safi, in);
9508
9509 return CMD_SUCCESS;
9510}
9511
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009512DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9513 show_ip_bgp_view_neighbor_advertised_route_cmd,
9514 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9515 SHOW_STR
9516 IP_STR
9517 BGP_STR
9518 "BGP view\n"
9519 "View name\n"
9520 "Detailed information on TCP and BGP neighbor connections\n"
9521 "Neighbor to display information about\n"
9522 "Neighbor to display information about\n"
9523 "Display the routes advertised to a BGP neighbor\n")
9524{
9525 struct peer *peer;
9526
9527 if (argc == 2)
9528 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9529 else
9530 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9531
9532 if (! peer)
9533 return CMD_WARNING;
9534
9535 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9536}
9537
9538ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009539 show_ip_bgp_neighbor_advertised_route_cmd,
9540 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9541 SHOW_STR
9542 IP_STR
9543 BGP_STR
9544 "Detailed information on TCP and BGP neighbor connections\n"
9545 "Neighbor to display information about\n"
9546 "Neighbor to display information about\n"
9547 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009548
9549DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9550 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9551 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9552 SHOW_STR
9553 IP_STR
9554 BGP_STR
9555 "Address family\n"
9556 "Address Family modifier\n"
9557 "Address Family modifier\n"
9558 "Detailed information on TCP and BGP neighbor connections\n"
9559 "Neighbor to display information about\n"
9560 "Neighbor to display information about\n"
9561 "Display the routes advertised to a BGP neighbor\n")
9562{
paulbb46e942003-10-24 19:02:03 +00009563 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009564
paulbb46e942003-10-24 19:02:03 +00009565 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9566 if (! peer)
9567 return CMD_WARNING;
9568
9569 if (strncmp (argv[0], "m", 1) == 0)
9570 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9571
9572 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009573}
9574
9575#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009576DEFUN (show_bgp_view_neighbor_advertised_route,
9577 show_bgp_view_neighbor_advertised_route_cmd,
9578 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9579 SHOW_STR
9580 BGP_STR
9581 "BGP view\n"
9582 "View name\n"
9583 "Detailed information on TCP and BGP neighbor connections\n"
9584 "Neighbor to display information about\n"
9585 "Neighbor to display information about\n"
9586 "Display the routes advertised to a BGP neighbor\n")
9587{
9588 struct peer *peer;
9589
9590 if (argc == 2)
9591 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9592 else
9593 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9594
9595 if (! peer)
9596 return CMD_WARNING;
9597
9598 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9599}
9600
9601ALIAS (show_bgp_view_neighbor_advertised_route,
9602 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9603 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9604 SHOW_STR
9605 BGP_STR
9606 "BGP view\n"
9607 "View name\n"
9608 "Address family\n"
9609 "Detailed information on TCP and BGP neighbor connections\n"
9610 "Neighbor to display information about\n"
9611 "Neighbor to display information about\n"
9612 "Display the routes advertised to a BGP neighbor\n")
9613
9614DEFUN (show_bgp_view_neighbor_received_routes,
9615 show_bgp_view_neighbor_received_routes_cmd,
9616 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9617 SHOW_STR
9618 BGP_STR
9619 "BGP view\n"
9620 "View name\n"
9621 "Detailed information on TCP and BGP neighbor connections\n"
9622 "Neighbor to display information about\n"
9623 "Neighbor to display information about\n"
9624 "Display the received routes from neighbor\n")
9625{
9626 struct peer *peer;
9627
9628 if (argc == 2)
9629 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9630 else
9631 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9632
9633 if (! peer)
9634 return CMD_WARNING;
9635
9636 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9637}
9638
9639ALIAS (show_bgp_view_neighbor_received_routes,
9640 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9641 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9642 SHOW_STR
9643 BGP_STR
9644 "BGP view\n"
9645 "View name\n"
9646 "Address family\n"
9647 "Detailed information on TCP and BGP neighbor connections\n"
9648 "Neighbor to display information about\n"
9649 "Neighbor to display information about\n"
9650 "Display the received routes from neighbor\n")
9651
9652ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009653 show_bgp_neighbor_advertised_route_cmd,
9654 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9655 SHOW_STR
9656 BGP_STR
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 routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009661
9662ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009663 show_bgp_ipv6_neighbor_advertised_route_cmd,
9664 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9665 SHOW_STR
9666 BGP_STR
9667 "Address family\n"
9668 "Detailed information on TCP and BGP neighbor connections\n"
9669 "Neighbor to display information about\n"
9670 "Neighbor to display information about\n"
9671 "Display the routes advertised to a BGP neighbor\n")
9672
9673/* old command */
paulbb46e942003-10-24 19:02:03 +00009674ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009675 ipv6_bgp_neighbor_advertised_route_cmd,
9676 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9677 SHOW_STR
9678 IPV6_STR
9679 BGP_STR
9680 "Detailed information on TCP and BGP neighbor connections\n"
9681 "Neighbor to display information about\n"
9682 "Neighbor to display information about\n"
9683 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +00009684
paul718e3742002-12-13 20:15:29 +00009685/* old command */
9686DEFUN (ipv6_mbgp_neighbor_advertised_route,
9687 ipv6_mbgp_neighbor_advertised_route_cmd,
9688 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9689 SHOW_STR
9690 IPV6_STR
9691 MBGP_STR
9692 "Detailed information on TCP and BGP neighbor connections\n"
9693 "Neighbor to display information about\n"
9694 "Neighbor to display information about\n"
9695 "Display the routes advertised to a BGP neighbor\n")
9696{
paulbb46e942003-10-24 19:02:03 +00009697 struct peer *peer;
9698
9699 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9700 if (! peer)
9701 return CMD_WARNING;
9702
9703 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +00009704}
9705#endif /* HAVE_IPV6 */
9706
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009707DEFUN (show_ip_bgp_view_neighbor_received_routes,
9708 show_ip_bgp_view_neighbor_received_routes_cmd,
9709 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9710 SHOW_STR
9711 IP_STR
9712 BGP_STR
9713 "BGP view\n"
9714 "View name\n"
9715 "Detailed information on TCP and BGP neighbor connections\n"
9716 "Neighbor to display information about\n"
9717 "Neighbor to display information about\n"
9718 "Display the received routes from neighbor\n")
9719{
9720 struct peer *peer;
9721
9722 if (argc == 2)
9723 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9724 else
9725 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9726
9727 if (! peer)
9728 return CMD_WARNING;
9729
9730 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
9731}
9732
9733ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009734 show_ip_bgp_neighbor_received_routes_cmd,
9735 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9736 SHOW_STR
9737 IP_STR
9738 BGP_STR
9739 "Detailed information on TCP and BGP neighbor connections\n"
9740 "Neighbor to display information about\n"
9741 "Neighbor to display information about\n"
9742 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009743
9744DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
9745 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
9746 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
9747 SHOW_STR
9748 IP_STR
9749 BGP_STR
9750 "Address family\n"
9751 "Address Family modifier\n"
9752 "Address Family modifier\n"
9753 "Detailed information on TCP and BGP neighbor connections\n"
9754 "Neighbor to display information about\n"
9755 "Neighbor to display information about\n"
9756 "Display the received routes from neighbor\n")
9757{
paulbb46e942003-10-24 19:02:03 +00009758 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009759
paulbb46e942003-10-24 19:02:03 +00009760 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9761 if (! peer)
9762 return CMD_WARNING;
9763
9764 if (strncmp (argv[0], "m", 1) == 0)
9765 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
9766
9767 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +00009768}
9769
9770DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
9771 show_ip_bgp_neighbor_received_prefix_filter_cmd,
9772 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9773 SHOW_STR
9774 IP_STR
9775 BGP_STR
9776 "Detailed information on TCP and BGP neighbor connections\n"
9777 "Neighbor to display information about\n"
9778 "Neighbor to display information about\n"
9779 "Display information received from a BGP neighbor\n"
9780 "Display the prefixlist filter\n")
9781{
9782 char name[BUFSIZ];
9783 union sockunion *su;
9784 struct peer *peer;
9785 int count;
9786
9787 su = sockunion_str2su (argv[0]);
9788 if (su == NULL)
9789 return CMD_WARNING;
9790
9791 peer = peer_lookup (NULL, su);
9792 if (! peer)
9793 return CMD_WARNING;
9794
9795 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9796 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9797 if (count)
9798 {
9799 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9800 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9801 }
9802
9803 return CMD_SUCCESS;
9804}
9805
9806DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
9807 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
9808 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9809 SHOW_STR
9810 IP_STR
9811 BGP_STR
9812 "Address family\n"
9813 "Address Family modifier\n"
9814 "Address Family modifier\n"
9815 "Detailed information on TCP and BGP neighbor connections\n"
9816 "Neighbor to display information about\n"
9817 "Neighbor to display information about\n"
9818 "Display information received from a BGP neighbor\n"
9819 "Display the prefixlist filter\n")
9820{
9821 char name[BUFSIZ];
9822 union sockunion *su;
9823 struct peer *peer;
9824 int count;
9825
9826 su = sockunion_str2su (argv[1]);
9827 if (su == NULL)
9828 return CMD_WARNING;
9829
9830 peer = peer_lookup (NULL, su);
9831 if (! peer)
9832 return CMD_WARNING;
9833
9834 if (strncmp (argv[0], "m", 1) == 0)
9835 {
9836 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
9837 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9838 if (count)
9839 {
9840 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
9841 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9842 }
9843 }
9844 else
9845 {
9846 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
9847 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
9848 if (count)
9849 {
9850 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
9851 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
9852 }
9853 }
9854
9855 return CMD_SUCCESS;
9856}
9857
9858
9859#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009860ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009861 show_bgp_neighbor_received_routes_cmd,
9862 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9863 SHOW_STR
9864 BGP_STR
9865 "Detailed information on TCP and BGP neighbor connections\n"
9866 "Neighbor to display information about\n"
9867 "Neighbor to display information about\n"
9868 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009869
paulbb46e942003-10-24 19:02:03 +00009870ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009871 show_bgp_ipv6_neighbor_received_routes_cmd,
9872 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9873 SHOW_STR
9874 BGP_STR
9875 "Address family\n"
9876 "Detailed information on TCP and BGP neighbor connections\n"
9877 "Neighbor to display information about\n"
9878 "Neighbor to display information about\n"
9879 "Display the received routes from neighbor\n")
9880
9881DEFUN (show_bgp_neighbor_received_prefix_filter,
9882 show_bgp_neighbor_received_prefix_filter_cmd,
9883 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9884 SHOW_STR
9885 BGP_STR
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 information received from a BGP neighbor\n"
9890 "Display the prefixlist filter\n")
9891{
9892 char name[BUFSIZ];
9893 union sockunion *su;
9894 struct peer *peer;
9895 int count;
9896
9897 su = sockunion_str2su (argv[0]);
9898 if (su == NULL)
9899 return CMD_WARNING;
9900
9901 peer = peer_lookup (NULL, su);
9902 if (! peer)
9903 return CMD_WARNING;
9904
9905 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9906 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9907 if (count)
9908 {
9909 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
9910 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
9911 }
9912
9913 return CMD_SUCCESS;
9914}
9915
9916ALIAS (show_bgp_neighbor_received_prefix_filter,
9917 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
9918 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9919 SHOW_STR
9920 BGP_STR
9921 "Address family\n"
9922 "Detailed information on TCP and BGP neighbor connections\n"
9923 "Neighbor to display information about\n"
9924 "Neighbor to display information about\n"
9925 "Display information received from a BGP neighbor\n"
9926 "Display the prefixlist filter\n")
9927
9928/* old command */
paulbb46e942003-10-24 19:02:03 +00009929ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +00009930 ipv6_bgp_neighbor_received_routes_cmd,
9931 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9932 SHOW_STR
9933 IPV6_STR
9934 BGP_STR
9935 "Detailed information on TCP and BGP neighbor connections\n"
9936 "Neighbor to display information about\n"
9937 "Neighbor to display information about\n"
9938 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +00009939
9940/* old command */
9941DEFUN (ipv6_mbgp_neighbor_received_routes,
9942 ipv6_mbgp_neighbor_received_routes_cmd,
9943 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
9944 SHOW_STR
9945 IPV6_STR
9946 MBGP_STR
9947 "Detailed information on TCP and BGP neighbor connections\n"
9948 "Neighbor to display information about\n"
9949 "Neighbor to display information about\n"
9950 "Display the received routes from neighbor\n")
9951{
paulbb46e942003-10-24 19:02:03 +00009952 struct peer *peer;
9953
9954 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9955 if (! peer)
9956 return CMD_WARNING;
9957
9958 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +00009959}
paulbb46e942003-10-24 19:02:03 +00009960
9961DEFUN (show_bgp_view_neighbor_received_prefix_filter,
9962 show_bgp_view_neighbor_received_prefix_filter_cmd,
9963 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
9964 SHOW_STR
9965 BGP_STR
9966 "BGP view\n"
9967 "View name\n"
9968 "Detailed information on TCP and BGP neighbor connections\n"
9969 "Neighbor to display information about\n"
9970 "Neighbor to display information about\n"
9971 "Display information received from a BGP neighbor\n"
9972 "Display the prefixlist filter\n")
9973{
9974 char name[BUFSIZ];
9975 union sockunion *su;
9976 struct peer *peer;
9977 struct bgp *bgp;
9978 int count;
9979
9980 /* BGP structure lookup. */
9981 bgp = bgp_lookup_by_name (argv[0]);
9982 if (bgp == NULL)
9983 {
9984 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
9985 return CMD_WARNING;
9986 }
9987
9988 su = sockunion_str2su (argv[1]);
9989 if (su == NULL)
9990 return CMD_WARNING;
9991
9992 peer = peer_lookup (bgp, su);
9993 if (! peer)
9994 return CMD_WARNING;
9995
9996 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
9997 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
9998 if (count)
9999 {
10000 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10001 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10002 }
10003
10004 return CMD_SUCCESS;
10005}
10006
10007ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10008 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10009 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10010 SHOW_STR
10011 BGP_STR
10012 "BGP view\n"
10013 "View name\n"
10014 "Address family\n"
10015 "Detailed information on TCP and BGP neighbor connections\n"
10016 "Neighbor to display information about\n"
10017 "Neighbor to display information about\n"
10018 "Display information received from a BGP neighbor\n"
10019 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010020#endif /* HAVE_IPV6 */
10021
paul94f2b392005-06-28 12:44:16 +000010022static int
paulbb46e942003-10-24 19:02:03 +000010023bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010024 safi_t safi, enum bgp_show_type type)
10025{
paul718e3742002-12-13 20:15:29 +000010026 if (! peer || ! peer->afc[afi][safi])
10027 {
10028 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010029 return CMD_WARNING;
10030 }
10031
ajs5a646652004-11-05 01:25:55 +000010032 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010033}
10034
10035DEFUN (show_ip_bgp_neighbor_routes,
10036 show_ip_bgp_neighbor_routes_cmd,
10037 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10038 SHOW_STR
10039 IP_STR
10040 BGP_STR
10041 "Detailed information on TCP and BGP neighbor connections\n"
10042 "Neighbor to display information about\n"
10043 "Neighbor to display information about\n"
10044 "Display routes learned from neighbor\n")
10045{
paulbb46e942003-10-24 19:02:03 +000010046 struct peer *peer;
10047
10048 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10049 if (! peer)
10050 return CMD_WARNING;
10051
10052 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010053 bgp_show_type_neighbor);
10054}
10055
10056DEFUN (show_ip_bgp_neighbor_flap,
10057 show_ip_bgp_neighbor_flap_cmd,
10058 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10059 SHOW_STR
10060 IP_STR
10061 BGP_STR
10062 "Detailed information on TCP and BGP neighbor connections\n"
10063 "Neighbor to display information about\n"
10064 "Neighbor to display information about\n"
10065 "Display flap statistics of the routes learned from neighbor\n")
10066{
paulbb46e942003-10-24 19:02:03 +000010067 struct peer *peer;
10068
10069 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10070 if (! peer)
10071 return CMD_WARNING;
10072
10073 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010074 bgp_show_type_flap_neighbor);
10075}
10076
10077DEFUN (show_ip_bgp_neighbor_damp,
10078 show_ip_bgp_neighbor_damp_cmd,
10079 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10080 SHOW_STR
10081 IP_STR
10082 BGP_STR
10083 "Detailed information on TCP and BGP neighbor connections\n"
10084 "Neighbor to display information about\n"
10085 "Neighbor to display information about\n"
10086 "Display the dampened routes received from neighbor\n")
10087{
paulbb46e942003-10-24 19:02:03 +000010088 struct peer *peer;
10089
10090 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10091 if (! peer)
10092 return CMD_WARNING;
10093
10094 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010095 bgp_show_type_damp_neighbor);
10096}
10097
10098DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10099 show_ip_bgp_ipv4_neighbor_routes_cmd,
10100 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10101 SHOW_STR
10102 IP_STR
10103 BGP_STR
10104 "Address family\n"
10105 "Address Family modifier\n"
10106 "Address Family modifier\n"
10107 "Detailed information on TCP and BGP neighbor connections\n"
10108 "Neighbor to display information about\n"
10109 "Neighbor to display information about\n"
10110 "Display routes learned from neighbor\n")
10111{
paulbb46e942003-10-24 19:02:03 +000010112 struct peer *peer;
10113
10114 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10115 if (! peer)
10116 return CMD_WARNING;
10117
paul718e3742002-12-13 20:15:29 +000010118 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010119 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010120 bgp_show_type_neighbor);
10121
paulbb46e942003-10-24 19:02:03 +000010122 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010123 bgp_show_type_neighbor);
10124}
paulbb46e942003-10-24 19:02:03 +000010125
paulfee0f4c2004-09-13 05:12:46 +000010126DEFUN (show_ip_bgp_view_rsclient,
10127 show_ip_bgp_view_rsclient_cmd,
10128 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10129 SHOW_STR
10130 IP_STR
10131 BGP_STR
10132 "BGP view\n"
10133 "BGP view name\n"
10134 "Information about Route Server Client\n"
10135 NEIGHBOR_ADDR_STR)
10136{
10137 struct bgp_table *table;
10138 struct peer *peer;
10139
10140 if (argc == 2)
10141 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10142 else
10143 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10144
10145 if (! peer)
10146 return CMD_WARNING;
10147
10148 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10149 {
10150 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10151 VTY_NEWLINE);
10152 return CMD_WARNING;
10153 }
10154
10155 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10156 PEER_FLAG_RSERVER_CLIENT))
10157 {
10158 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10159 VTY_NEWLINE);
10160 return CMD_WARNING;
10161 }
10162
10163 table = peer->rib[AFI_IP][SAFI_UNICAST];
10164
ajs5a646652004-11-05 01:25:55 +000010165 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010166}
10167
10168ALIAS (show_ip_bgp_view_rsclient,
10169 show_ip_bgp_rsclient_cmd,
10170 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10171 SHOW_STR
10172 IP_STR
10173 BGP_STR
10174 "Information about Route Server Client\n"
10175 NEIGHBOR_ADDR_STR)
10176
10177DEFUN (show_ip_bgp_view_rsclient_route,
10178 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010179 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010180 SHOW_STR
10181 IP_STR
10182 BGP_STR
10183 "BGP view\n"
10184 "BGP view name\n"
10185 "Information about Route Server Client\n"
10186 NEIGHBOR_ADDR_STR
10187 "Network in the BGP routing table to display\n")
10188{
10189 struct bgp *bgp;
10190 struct peer *peer;
10191
10192 /* BGP structure lookup. */
10193 if (argc == 3)
10194 {
10195 bgp = bgp_lookup_by_name (argv[0]);
10196 if (bgp == NULL)
10197 {
10198 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10199 return CMD_WARNING;
10200 }
10201 }
10202 else
10203 {
10204 bgp = bgp_get_default ();
10205 if (bgp == NULL)
10206 {
10207 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10208 return CMD_WARNING;
10209 }
10210 }
10211
10212 if (argc == 3)
10213 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10214 else
10215 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10216
10217 if (! peer)
10218 return CMD_WARNING;
10219
10220 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10221 {
10222 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10223 VTY_NEWLINE);
10224 return CMD_WARNING;
10225}
10226
10227 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10228 PEER_FLAG_RSERVER_CLIENT))
10229 {
10230 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10231 VTY_NEWLINE);
10232 return CMD_WARNING;
10233 }
10234
10235 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10236 (argc == 3) ? argv[2] : argv[1],
10237 AFI_IP, SAFI_UNICAST, NULL, 0);
10238}
10239
10240ALIAS (show_ip_bgp_view_rsclient_route,
10241 show_ip_bgp_rsclient_route_cmd,
10242 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10243 SHOW_STR
10244 IP_STR
10245 BGP_STR
10246 "Information about Route Server Client\n"
10247 NEIGHBOR_ADDR_STR
10248 "Network in the BGP routing table to display\n")
10249
10250DEFUN (show_ip_bgp_view_rsclient_prefix,
10251 show_ip_bgp_view_rsclient_prefix_cmd,
10252 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10253 SHOW_STR
10254 IP_STR
10255 BGP_STR
10256 "BGP view\n"
10257 "BGP view name\n"
10258 "Information about Route Server Client\n"
10259 NEIGHBOR_ADDR_STR
10260 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10261{
10262 struct bgp *bgp;
10263 struct peer *peer;
10264
10265 /* BGP structure lookup. */
10266 if (argc == 3)
10267 {
10268 bgp = bgp_lookup_by_name (argv[0]);
10269 if (bgp == NULL)
10270 {
10271 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10272 return CMD_WARNING;
10273 }
10274 }
10275 else
10276 {
10277 bgp = bgp_get_default ();
10278 if (bgp == NULL)
10279 {
10280 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10281 return CMD_WARNING;
10282 }
10283 }
10284
10285 if (argc == 3)
10286 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10287 else
10288 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10289
10290 if (! peer)
10291 return CMD_WARNING;
10292
10293 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10294 {
10295 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10296 VTY_NEWLINE);
10297 return CMD_WARNING;
10298}
10299
10300 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10301 PEER_FLAG_RSERVER_CLIENT))
10302{
10303 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10304 VTY_NEWLINE);
10305 return CMD_WARNING;
10306 }
10307
10308 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10309 (argc == 3) ? argv[2] : argv[1],
10310 AFI_IP, SAFI_UNICAST, NULL, 1);
10311}
10312
10313ALIAS (show_ip_bgp_view_rsclient_prefix,
10314 show_ip_bgp_rsclient_prefix_cmd,
10315 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10316 SHOW_STR
10317 IP_STR
10318 BGP_STR
10319 "Information about Route Server Client\n"
10320 NEIGHBOR_ADDR_STR
10321 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10322
10323
paul718e3742002-12-13 20:15:29 +000010324#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010325DEFUN (show_bgp_view_neighbor_routes,
10326 show_bgp_view_neighbor_routes_cmd,
10327 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10328 SHOW_STR
10329 BGP_STR
10330 "BGP view\n"
10331 "BGP view name\n"
10332 "Detailed information on TCP and BGP neighbor connections\n"
10333 "Neighbor to display information about\n"
10334 "Neighbor to display information about\n"
10335 "Display routes learned from neighbor\n")
10336{
10337 struct peer *peer;
10338
10339 if (argc == 2)
10340 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10341 else
10342 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10343
10344 if (! peer)
10345 return CMD_WARNING;
10346
10347 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10348 bgp_show_type_neighbor);
10349}
10350
10351ALIAS (show_bgp_view_neighbor_routes,
10352 show_bgp_view_ipv6_neighbor_routes_cmd,
10353 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10354 SHOW_STR
10355 BGP_STR
10356 "BGP view\n"
10357 "BGP view name\n"
10358 "Address family\n"
10359 "Detailed information on TCP and BGP neighbor connections\n"
10360 "Neighbor to display information about\n"
10361 "Neighbor to display information about\n"
10362 "Display routes learned from neighbor\n")
10363
10364DEFUN (show_bgp_view_neighbor_damp,
10365 show_bgp_view_neighbor_damp_cmd,
10366 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10367 SHOW_STR
10368 BGP_STR
10369 "BGP view\n"
10370 "BGP view name\n"
10371 "Detailed information on TCP and BGP neighbor connections\n"
10372 "Neighbor to display information about\n"
10373 "Neighbor to display information about\n"
10374 "Display the dampened routes received from neighbor\n")
10375{
10376 struct peer *peer;
10377
10378 if (argc == 2)
10379 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10380 else
10381 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10382
10383 if (! peer)
10384 return CMD_WARNING;
10385
10386 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10387 bgp_show_type_damp_neighbor);
10388}
10389
10390ALIAS (show_bgp_view_neighbor_damp,
10391 show_bgp_view_ipv6_neighbor_damp_cmd,
10392 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10393 SHOW_STR
10394 BGP_STR
10395 "BGP view\n"
10396 "BGP view name\n"
10397 "Address family\n"
10398 "Detailed information on TCP and BGP neighbor connections\n"
10399 "Neighbor to display information about\n"
10400 "Neighbor to display information about\n"
10401 "Display the dampened routes received from neighbor\n")
10402
10403DEFUN (show_bgp_view_neighbor_flap,
10404 show_bgp_view_neighbor_flap_cmd,
10405 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10406 SHOW_STR
10407 BGP_STR
10408 "BGP view\n"
10409 "BGP view name\n"
10410 "Detailed information on TCP and BGP neighbor connections\n"
10411 "Neighbor to display information about\n"
10412 "Neighbor to display information about\n"
10413 "Display flap statistics of the routes learned from neighbor\n")
10414{
10415 struct peer *peer;
10416
10417 if (argc == 2)
10418 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10419 else
10420 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10421
10422 if (! peer)
10423 return CMD_WARNING;
10424
10425 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10426 bgp_show_type_flap_neighbor);
10427}
10428
10429ALIAS (show_bgp_view_neighbor_flap,
10430 show_bgp_view_ipv6_neighbor_flap_cmd,
10431 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10432 SHOW_STR
10433 BGP_STR
10434 "BGP view\n"
10435 "BGP view name\n"
10436 "Address family\n"
10437 "Detailed information on TCP and BGP neighbor connections\n"
10438 "Neighbor to display information about\n"
10439 "Neighbor to display information about\n"
10440 "Display flap statistics of the routes learned from neighbor\n")
10441
10442ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010443 show_bgp_neighbor_routes_cmd,
10444 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
10445 SHOW_STR
10446 BGP_STR
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 routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010451
paulbb46e942003-10-24 19:02:03 +000010452
10453ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010454 show_bgp_ipv6_neighbor_routes_cmd,
10455 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10456 SHOW_STR
10457 BGP_STR
10458 "Address family\n"
10459 "Detailed information on TCP and BGP neighbor connections\n"
10460 "Neighbor to display information about\n"
10461 "Neighbor to display information about\n"
10462 "Display routes learned from neighbor\n")
10463
10464/* old command */
paulbb46e942003-10-24 19:02:03 +000010465ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000010466 ipv6_bgp_neighbor_routes_cmd,
10467 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
10468 SHOW_STR
10469 IPV6_STR
10470 BGP_STR
10471 "Detailed information on TCP and BGP neighbor connections\n"
10472 "Neighbor to display information about\n"
10473 "Neighbor to display information about\n"
10474 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010475
10476/* old command */
10477DEFUN (ipv6_mbgp_neighbor_routes,
10478 ipv6_mbgp_neighbor_routes_cmd,
10479 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
10480 SHOW_STR
10481 IPV6_STR
10482 MBGP_STR
10483 "Detailed information on TCP and BGP neighbor connections\n"
10484 "Neighbor to display information about\n"
10485 "Neighbor to display information about\n"
10486 "Display routes learned from neighbor\n")
10487{
paulbb46e942003-10-24 19:02:03 +000010488 struct peer *peer;
10489
10490 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10491 if (! peer)
10492 return CMD_WARNING;
10493
10494 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010495 bgp_show_type_neighbor);
10496}
paulbb46e942003-10-24 19:02:03 +000010497
10498ALIAS (show_bgp_view_neighbor_flap,
10499 show_bgp_neighbor_flap_cmd,
10500 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10501 SHOW_STR
10502 BGP_STR
10503 "Detailed information on TCP and BGP neighbor connections\n"
10504 "Neighbor to display information about\n"
10505 "Neighbor to display information about\n"
10506 "Display flap statistics of the routes learned from neighbor\n")
10507
10508ALIAS (show_bgp_view_neighbor_flap,
10509 show_bgp_ipv6_neighbor_flap_cmd,
10510 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10511 SHOW_STR
10512 BGP_STR
10513 "Address family\n"
10514 "Detailed information on TCP and BGP neighbor connections\n"
10515 "Neighbor to display information about\n"
10516 "Neighbor to display information about\n"
10517 "Display flap statistics of the routes learned from neighbor\n")
10518
10519ALIAS (show_bgp_view_neighbor_damp,
10520 show_bgp_neighbor_damp_cmd,
10521 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10522 SHOW_STR
10523 BGP_STR
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 the dampened routes received from neighbor\n")
10528
10529ALIAS (show_bgp_view_neighbor_damp,
10530 show_bgp_ipv6_neighbor_damp_cmd,
10531 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10532 SHOW_STR
10533 BGP_STR
10534 "Address family\n"
10535 "Detailed information on TCP and BGP neighbor connections\n"
10536 "Neighbor to display information about\n"
10537 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000010538 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000010539
10540DEFUN (show_bgp_view_rsclient,
10541 show_bgp_view_rsclient_cmd,
10542 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10543 SHOW_STR
10544 BGP_STR
10545 "BGP view\n"
10546 "BGP view name\n"
10547 "Information about Route Server Client\n"
10548 NEIGHBOR_ADDR_STR)
10549{
10550 struct bgp_table *table;
10551 struct peer *peer;
10552
10553 if (argc == 2)
10554 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10555 else
10556 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10557
10558 if (! peer)
10559 return CMD_WARNING;
10560
10561 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10562 {
10563 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10564 VTY_NEWLINE);
10565 return CMD_WARNING;
10566 }
10567
10568 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10569 PEER_FLAG_RSERVER_CLIENT))
10570 {
10571 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10572 VTY_NEWLINE);
10573 return CMD_WARNING;
10574 }
10575
10576 table = peer->rib[AFI_IP6][SAFI_UNICAST];
10577
ajs5a646652004-11-05 01:25:55 +000010578 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010579}
10580
10581ALIAS (show_bgp_view_rsclient,
10582 show_bgp_rsclient_cmd,
10583 "show bgp rsclient (A.B.C.D|X:X::X:X)",
10584 SHOW_STR
10585 BGP_STR
10586 "Information about Route Server Client\n"
10587 NEIGHBOR_ADDR_STR)
10588
10589DEFUN (show_bgp_view_rsclient_route,
10590 show_bgp_view_rsclient_route_cmd,
10591 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10592 SHOW_STR
10593 BGP_STR
10594 "BGP view\n"
10595 "BGP view name\n"
10596 "Information about Route Server Client\n"
10597 NEIGHBOR_ADDR_STR
10598 "Network in the BGP routing table to display\n")
10599{
10600 struct bgp *bgp;
10601 struct peer *peer;
10602
10603 /* BGP structure lookup. */
10604 if (argc == 3)
10605 {
10606 bgp = bgp_lookup_by_name (argv[0]);
10607 if (bgp == NULL)
10608 {
10609 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10610 return CMD_WARNING;
10611 }
10612 }
10613 else
10614 {
10615 bgp = bgp_get_default ();
10616 if (bgp == NULL)
10617 {
10618 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10619 return CMD_WARNING;
10620 }
10621 }
10622
10623 if (argc == 3)
10624 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10625 else
10626 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10627
10628 if (! peer)
10629 return CMD_WARNING;
10630
10631 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10632 {
10633 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10634 VTY_NEWLINE);
10635 return CMD_WARNING;
10636 }
10637
10638 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10639 PEER_FLAG_RSERVER_CLIENT))
10640 {
10641 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10642 VTY_NEWLINE);
10643 return CMD_WARNING;
10644 }
10645
10646 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10647 (argc == 3) ? argv[2] : argv[1],
10648 AFI_IP6, SAFI_UNICAST, NULL, 0);
10649}
10650
10651ALIAS (show_bgp_view_rsclient_route,
10652 show_bgp_rsclient_route_cmd,
10653 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
10654 SHOW_STR
10655 BGP_STR
10656 "Information about Route Server Client\n"
10657 NEIGHBOR_ADDR_STR
10658 "Network in the BGP routing table to display\n")
10659
10660DEFUN (show_bgp_view_rsclient_prefix,
10661 show_bgp_view_rsclient_prefix_cmd,
10662 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10663 SHOW_STR
10664 BGP_STR
10665 "BGP view\n"
10666 "BGP view name\n"
10667 "Information about Route Server Client\n"
10668 NEIGHBOR_ADDR_STR
10669 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10670{
10671 struct bgp *bgp;
10672 struct peer *peer;
10673
10674 /* BGP structure lookup. */
10675 if (argc == 3)
10676 {
10677 bgp = bgp_lookup_by_name (argv[0]);
10678 if (bgp == NULL)
10679 {
10680 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10681 return CMD_WARNING;
10682 }
10683 }
10684 else
10685 {
10686 bgp = bgp_get_default ();
10687 if (bgp == NULL)
10688 {
10689 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10690 return CMD_WARNING;
10691 }
10692 }
10693
10694 if (argc == 3)
10695 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10696 else
10697 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10698
10699 if (! peer)
10700 return CMD_WARNING;
10701
10702 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
10703 {
10704 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10705 VTY_NEWLINE);
10706 return CMD_WARNING;
10707 }
10708
10709 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
10710 PEER_FLAG_RSERVER_CLIENT))
10711 {
10712 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10713 VTY_NEWLINE);
10714 return CMD_WARNING;
10715 }
10716
10717 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
10718 (argc == 3) ? argv[2] : argv[1],
10719 AFI_IP6, SAFI_UNICAST, NULL, 1);
10720}
10721
10722ALIAS (show_bgp_view_rsclient_prefix,
10723 show_bgp_rsclient_prefix_cmd,
10724 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
10725 SHOW_STR
10726 BGP_STR
10727 "Information about Route Server Client\n"
10728 NEIGHBOR_ADDR_STR
10729 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
10730
paul718e3742002-12-13 20:15:29 +000010731#endif /* HAVE_IPV6 */
10732
10733struct bgp_table *bgp_distance_table;
10734
10735struct bgp_distance
10736{
10737 /* Distance value for the IP source prefix. */
10738 u_char distance;
10739
10740 /* Name of the access-list to be matched. */
10741 char *access_list;
10742};
10743
paul94f2b392005-06-28 12:44:16 +000010744static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080010745bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000010746{
Stephen Hemminger393deb92008-08-18 14:13:29 -070010747 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000010748}
10749
paul94f2b392005-06-28 12:44:16 +000010750static void
paul718e3742002-12-13 20:15:29 +000010751bgp_distance_free (struct bgp_distance *bdistance)
10752{
10753 XFREE (MTYPE_BGP_DISTANCE, bdistance);
10754}
10755
paul94f2b392005-06-28 12:44:16 +000010756static int
paulfd79ac92004-10-13 05:06:08 +000010757bgp_distance_set (struct vty *vty, const char *distance_str,
10758 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010759{
10760 int ret;
10761 struct prefix_ipv4 p;
10762 u_char distance;
10763 struct bgp_node *rn;
10764 struct bgp_distance *bdistance;
10765
10766 ret = str2prefix_ipv4 (ip_str, &p);
10767 if (ret == 0)
10768 {
10769 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10770 return CMD_WARNING;
10771 }
10772
10773 distance = atoi (distance_str);
10774
10775 /* Get BGP distance node. */
10776 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
10777 if (rn->info)
10778 {
10779 bdistance = rn->info;
10780 bgp_unlock_node (rn);
10781 }
10782 else
10783 {
10784 bdistance = bgp_distance_new ();
10785 rn->info = bdistance;
10786 }
10787
10788 /* Set distance value. */
10789 bdistance->distance = distance;
10790
10791 /* Reset access-list configuration. */
10792 if (bdistance->access_list)
10793 {
10794 free (bdistance->access_list);
10795 bdistance->access_list = NULL;
10796 }
10797 if (access_list_str)
10798 bdistance->access_list = strdup (access_list_str);
10799
10800 return CMD_SUCCESS;
10801}
10802
paul94f2b392005-06-28 12:44:16 +000010803static int
paulfd79ac92004-10-13 05:06:08 +000010804bgp_distance_unset (struct vty *vty, const char *distance_str,
10805 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000010806{
10807 int ret;
10808 struct prefix_ipv4 p;
10809 u_char distance;
10810 struct bgp_node *rn;
10811 struct bgp_distance *bdistance;
10812
10813 ret = str2prefix_ipv4 (ip_str, &p);
10814 if (ret == 0)
10815 {
10816 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
10817 return CMD_WARNING;
10818 }
10819
10820 distance = atoi (distance_str);
10821
10822 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
10823 if (! rn)
10824 {
10825 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
10826 return CMD_WARNING;
10827 }
10828
10829 bdistance = rn->info;
10830
10831 if (bdistance->access_list)
10832 free (bdistance->access_list);
10833 bgp_distance_free (bdistance);
10834
10835 rn->info = NULL;
10836 bgp_unlock_node (rn);
10837 bgp_unlock_node (rn);
10838
10839 return CMD_SUCCESS;
10840}
10841
paul718e3742002-12-13 20:15:29 +000010842/* Apply BGP information to distance method. */
10843u_char
10844bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
10845{
10846 struct bgp_node *rn;
10847 struct prefix_ipv4 q;
10848 struct peer *peer;
10849 struct bgp_distance *bdistance;
10850 struct access_list *alist;
10851 struct bgp_static *bgp_static;
10852
10853 if (! bgp)
10854 return 0;
10855
10856 if (p->family != AF_INET)
10857 return 0;
10858
10859 peer = rinfo->peer;
10860
10861 if (peer->su.sa.sa_family != AF_INET)
10862 return 0;
10863
10864 memset (&q, 0, sizeof (struct prefix_ipv4));
10865 q.family = AF_INET;
10866 q.prefix = peer->su.sin.sin_addr;
10867 q.prefixlen = IPV4_MAX_BITLEN;
10868
10869 /* Check source address. */
10870 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
10871 if (rn)
10872 {
10873 bdistance = rn->info;
10874 bgp_unlock_node (rn);
10875
10876 if (bdistance->access_list)
10877 {
10878 alist = access_list_lookup (AFI_IP, bdistance->access_list);
10879 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
10880 return bdistance->distance;
10881 }
10882 else
10883 return bdistance->distance;
10884 }
10885
10886 /* Backdoor check. */
10887 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
10888 if (rn)
10889 {
10890 bgp_static = rn->info;
10891 bgp_unlock_node (rn);
10892
10893 if (bgp_static->backdoor)
10894 {
10895 if (bgp->distance_local)
10896 return bgp->distance_local;
10897 else
10898 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10899 }
10900 }
10901
10902 if (peer_sort (peer) == BGP_PEER_EBGP)
10903 {
10904 if (bgp->distance_ebgp)
10905 return bgp->distance_ebgp;
10906 return ZEBRA_EBGP_DISTANCE_DEFAULT;
10907 }
10908 else
10909 {
10910 if (bgp->distance_ibgp)
10911 return bgp->distance_ibgp;
10912 return ZEBRA_IBGP_DISTANCE_DEFAULT;
10913 }
10914}
10915
10916DEFUN (bgp_distance,
10917 bgp_distance_cmd,
10918 "distance bgp <1-255> <1-255> <1-255>",
10919 "Define an administrative distance\n"
10920 "BGP distance\n"
10921 "Distance for routes external to the AS\n"
10922 "Distance for routes internal to the AS\n"
10923 "Distance for local routes\n")
10924{
10925 struct bgp *bgp;
10926
10927 bgp = vty->index;
10928
10929 bgp->distance_ebgp = atoi (argv[0]);
10930 bgp->distance_ibgp = atoi (argv[1]);
10931 bgp->distance_local = atoi (argv[2]);
10932 return CMD_SUCCESS;
10933}
10934
10935DEFUN (no_bgp_distance,
10936 no_bgp_distance_cmd,
10937 "no distance bgp <1-255> <1-255> <1-255>",
10938 NO_STR
10939 "Define an administrative distance\n"
10940 "BGP distance\n"
10941 "Distance for routes external to the AS\n"
10942 "Distance for routes internal to the AS\n"
10943 "Distance for local routes\n")
10944{
10945 struct bgp *bgp;
10946
10947 bgp = vty->index;
10948
10949 bgp->distance_ebgp= 0;
10950 bgp->distance_ibgp = 0;
10951 bgp->distance_local = 0;
10952 return CMD_SUCCESS;
10953}
10954
10955ALIAS (no_bgp_distance,
10956 no_bgp_distance2_cmd,
10957 "no distance bgp",
10958 NO_STR
10959 "Define an administrative distance\n"
10960 "BGP distance\n")
10961
10962DEFUN (bgp_distance_source,
10963 bgp_distance_source_cmd,
10964 "distance <1-255> A.B.C.D/M",
10965 "Define an administrative distance\n"
10966 "Administrative distance\n"
10967 "IP source prefix\n")
10968{
10969 bgp_distance_set (vty, argv[0], argv[1], NULL);
10970 return CMD_SUCCESS;
10971}
10972
10973DEFUN (no_bgp_distance_source,
10974 no_bgp_distance_source_cmd,
10975 "no distance <1-255> A.B.C.D/M",
10976 NO_STR
10977 "Define an administrative distance\n"
10978 "Administrative distance\n"
10979 "IP source prefix\n")
10980{
10981 bgp_distance_unset (vty, argv[0], argv[1], NULL);
10982 return CMD_SUCCESS;
10983}
10984
10985DEFUN (bgp_distance_source_access_list,
10986 bgp_distance_source_access_list_cmd,
10987 "distance <1-255> A.B.C.D/M WORD",
10988 "Define an administrative distance\n"
10989 "Administrative distance\n"
10990 "IP source prefix\n"
10991 "Access list name\n")
10992{
10993 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
10994 return CMD_SUCCESS;
10995}
10996
10997DEFUN (no_bgp_distance_source_access_list,
10998 no_bgp_distance_source_access_list_cmd,
10999 "no distance <1-255> A.B.C.D/M WORD",
11000 NO_STR
11001 "Define an administrative distance\n"
11002 "Administrative distance\n"
11003 "IP source prefix\n"
11004 "Access list name\n")
11005{
11006 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11007 return CMD_SUCCESS;
11008}
11009
11010DEFUN (bgp_damp_set,
11011 bgp_damp_set_cmd,
11012 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11013 "BGP Specific commands\n"
11014 "Enable route-flap dampening\n"
11015 "Half-life time for the penalty\n"
11016 "Value to start reusing a route\n"
11017 "Value to start suppressing a route\n"
11018 "Maximum duration to suppress a stable route\n")
11019{
11020 struct bgp *bgp;
11021 int half = DEFAULT_HALF_LIFE * 60;
11022 int reuse = DEFAULT_REUSE;
11023 int suppress = DEFAULT_SUPPRESS;
11024 int max = 4 * half;
11025
11026 if (argc == 4)
11027 {
11028 half = atoi (argv[0]) * 60;
11029 reuse = atoi (argv[1]);
11030 suppress = atoi (argv[2]);
11031 max = atoi (argv[3]) * 60;
11032 }
11033 else if (argc == 1)
11034 {
11035 half = atoi (argv[0]) * 60;
11036 max = 4 * half;
11037 }
11038
11039 bgp = vty->index;
11040 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11041 half, reuse, suppress, max);
11042}
11043
11044ALIAS (bgp_damp_set,
11045 bgp_damp_set2_cmd,
11046 "bgp dampening <1-45>",
11047 "BGP Specific commands\n"
11048 "Enable route-flap dampening\n"
11049 "Half-life time for the penalty\n")
11050
11051ALIAS (bgp_damp_set,
11052 bgp_damp_set3_cmd,
11053 "bgp dampening",
11054 "BGP Specific commands\n"
11055 "Enable route-flap dampening\n")
11056
11057DEFUN (bgp_damp_unset,
11058 bgp_damp_unset_cmd,
11059 "no bgp dampening",
11060 NO_STR
11061 "BGP Specific commands\n"
11062 "Enable route-flap dampening\n")
11063{
11064 struct bgp *bgp;
11065
11066 bgp = vty->index;
11067 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11068}
11069
11070ALIAS (bgp_damp_unset,
11071 bgp_damp_unset2_cmd,
11072 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11073 NO_STR
11074 "BGP Specific commands\n"
11075 "Enable route-flap dampening\n"
11076 "Half-life time for the penalty\n"
11077 "Value to start reusing a route\n"
11078 "Value to start suppressing a route\n"
11079 "Maximum duration to suppress a stable route\n")
11080
11081DEFUN (show_ip_bgp_dampened_paths,
11082 show_ip_bgp_dampened_paths_cmd,
11083 "show ip bgp dampened-paths",
11084 SHOW_STR
11085 IP_STR
11086 BGP_STR
11087 "Display paths suppressed due to dampening\n")
11088{
ajs5a646652004-11-05 01:25:55 +000011089 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11090 NULL);
paul718e3742002-12-13 20:15:29 +000011091}
11092
11093DEFUN (show_ip_bgp_flap_statistics,
11094 show_ip_bgp_flap_statistics_cmd,
11095 "show ip bgp flap-statistics",
11096 SHOW_STR
11097 IP_STR
11098 BGP_STR
11099 "Display flap statistics of routes\n")
11100{
ajs5a646652004-11-05 01:25:55 +000011101 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11102 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011103}
11104
11105/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011106static int
paulfd79ac92004-10-13 05:06:08 +000011107bgp_clear_damp_route (struct vty *vty, const char *view_name,
11108 const char *ip_str, afi_t afi, safi_t safi,
11109 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011110{
11111 int ret;
11112 struct prefix match;
11113 struct bgp_node *rn;
11114 struct bgp_node *rm;
11115 struct bgp_info *ri;
11116 struct bgp_info *ri_temp;
11117 struct bgp *bgp;
11118 struct bgp_table *table;
11119
11120 /* BGP structure lookup. */
11121 if (view_name)
11122 {
11123 bgp = bgp_lookup_by_name (view_name);
11124 if (bgp == NULL)
11125 {
11126 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11127 return CMD_WARNING;
11128 }
11129 }
11130 else
11131 {
11132 bgp = bgp_get_default ();
11133 if (bgp == NULL)
11134 {
11135 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11136 return CMD_WARNING;
11137 }
11138 }
11139
11140 /* Check IP address argument. */
11141 ret = str2prefix (ip_str, &match);
11142 if (! ret)
11143 {
11144 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11145 return CMD_WARNING;
11146 }
11147
11148 match.family = afi2family (afi);
11149
11150 if (safi == SAFI_MPLS_VPN)
11151 {
11152 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11153 {
11154 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11155 continue;
11156
11157 if ((table = rn->info) != NULL)
11158 if ((rm = bgp_node_match (table, &match)) != NULL)
11159 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11160 {
11161 ri = rm->info;
11162 while (ri)
11163 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011164 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011165 {
11166 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011167 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011168 ri = ri_temp;
11169 }
11170 else
11171 ri = ri->next;
11172 }
11173 }
11174 }
11175 }
11176 else
11177 {
11178 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
11179 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
11180 {
11181 ri = rn->info;
11182 while (ri)
11183 {
Paul Jakmafb982c22007-05-04 20:15:47 +000011184 if (ri->extra && ri->extra->damp_info)
paul718e3742002-12-13 20:15:29 +000011185 {
11186 ri_temp = ri->next;
Paul Jakmafb982c22007-05-04 20:15:47 +000011187 bgp_damp_info_free (ri->extra->damp_info, 1);
paul718e3742002-12-13 20:15:29 +000011188 ri = ri_temp;
11189 }
11190 else
11191 ri = ri->next;
11192 }
11193 }
11194 }
11195
11196 return CMD_SUCCESS;
11197}
11198
11199DEFUN (clear_ip_bgp_dampening,
11200 clear_ip_bgp_dampening_cmd,
11201 "clear ip bgp dampening",
11202 CLEAR_STR
11203 IP_STR
11204 BGP_STR
11205 "Clear route flap dampening information\n")
11206{
11207 bgp_damp_info_clean ();
11208 return CMD_SUCCESS;
11209}
11210
11211DEFUN (clear_ip_bgp_dampening_prefix,
11212 clear_ip_bgp_dampening_prefix_cmd,
11213 "clear ip bgp dampening A.B.C.D/M",
11214 CLEAR_STR
11215 IP_STR
11216 BGP_STR
11217 "Clear route flap dampening information\n"
11218 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
11219{
11220 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11221 SAFI_UNICAST, NULL, 1);
11222}
11223
11224DEFUN (clear_ip_bgp_dampening_address,
11225 clear_ip_bgp_dampening_address_cmd,
11226 "clear ip bgp dampening A.B.C.D",
11227 CLEAR_STR
11228 IP_STR
11229 BGP_STR
11230 "Clear route flap dampening information\n"
11231 "Network to clear damping information\n")
11232{
11233 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
11234 SAFI_UNICAST, NULL, 0);
11235}
11236
11237DEFUN (clear_ip_bgp_dampening_address_mask,
11238 clear_ip_bgp_dampening_address_mask_cmd,
11239 "clear ip bgp dampening A.B.C.D A.B.C.D",
11240 CLEAR_STR
11241 IP_STR
11242 BGP_STR
11243 "Clear route flap dampening information\n"
11244 "Network to clear damping information\n"
11245 "Network mask\n")
11246{
11247 int ret;
11248 char prefix_str[BUFSIZ];
11249
11250 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
11251 if (! ret)
11252 {
11253 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
11254 return CMD_WARNING;
11255 }
11256
11257 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
11258 SAFI_UNICAST, NULL, 0);
11259}
11260
paul94f2b392005-06-28 12:44:16 +000011261static int
paul718e3742002-12-13 20:15:29 +000011262bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
11263 afi_t afi, safi_t safi, int *write)
11264{
11265 struct bgp_node *prn;
11266 struct bgp_node *rn;
11267 struct bgp_table *table;
11268 struct prefix *p;
11269 struct prefix_rd *prd;
11270 struct bgp_static *bgp_static;
11271 u_int32_t label;
11272 char buf[SU_ADDRSTRLEN];
11273 char rdbuf[RD_ADDRSTRLEN];
11274
11275 /* Network configuration. */
11276 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
11277 if ((table = prn->info) != NULL)
11278 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
11279 if ((bgp_static = rn->info) != NULL)
11280 {
11281 p = &rn->p;
11282 prd = (struct prefix_rd *) &prn->p;
11283
11284 /* "address-family" display. */
11285 bgp_config_write_family_header (vty, afi, safi, write);
11286
11287 /* "network" configuration display. */
11288 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
11289 label = decode_label (bgp_static->tag);
11290
11291 vty_out (vty, " network %s/%d rd %s tag %d",
11292 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11293 p->prefixlen,
11294 rdbuf, label);
11295 vty_out (vty, "%s", VTY_NEWLINE);
11296 }
11297 return 0;
11298}
11299
11300/* Configuration of static route announcement and aggregate
11301 information. */
11302int
11303bgp_config_write_network (struct vty *vty, struct bgp *bgp,
11304 afi_t afi, safi_t safi, int *write)
11305{
11306 struct bgp_node *rn;
11307 struct prefix *p;
11308 struct bgp_static *bgp_static;
11309 struct bgp_aggregate *bgp_aggregate;
11310 char buf[SU_ADDRSTRLEN];
11311
11312 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
11313 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
11314
11315 /* Network configuration. */
11316 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
11317 if ((bgp_static = rn->info) != NULL)
11318 {
11319 p = &rn->p;
11320
11321 /* "address-family" display. */
11322 bgp_config_write_family_header (vty, afi, safi, write);
11323
11324 /* "network" configuration display. */
11325 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11326 {
11327 u_int32_t destination;
11328 struct in_addr netmask;
11329
11330 destination = ntohl (p->u.prefix4.s_addr);
11331 masklen2ip (p->prefixlen, &netmask);
11332 vty_out (vty, " network %s",
11333 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
11334
11335 if ((IN_CLASSC (destination) && p->prefixlen == 24)
11336 || (IN_CLASSB (destination) && p->prefixlen == 16)
11337 || (IN_CLASSA (destination) && p->prefixlen == 8)
11338 || p->u.prefix4.s_addr == 0)
11339 {
11340 /* Natural mask is not display. */
11341 }
11342 else
11343 vty_out (vty, " mask %s", inet_ntoa (netmask));
11344 }
11345 else
11346 {
11347 vty_out (vty, " network %s/%d",
11348 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11349 p->prefixlen);
11350 }
11351
11352 if (bgp_static->rmap.name)
11353 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000011354 else
11355 {
11356 if (bgp_static->backdoor)
11357 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000011358 }
paul718e3742002-12-13 20:15:29 +000011359
11360 vty_out (vty, "%s", VTY_NEWLINE);
11361 }
11362
11363 /* Aggregate-address configuration. */
11364 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
11365 if ((bgp_aggregate = rn->info) != NULL)
11366 {
11367 p = &rn->p;
11368
11369 /* "address-family" display. */
11370 bgp_config_write_family_header (vty, afi, safi, write);
11371
11372 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
11373 {
11374 struct in_addr netmask;
11375
11376 masklen2ip (p->prefixlen, &netmask);
11377 vty_out (vty, " aggregate-address %s %s",
11378 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11379 inet_ntoa (netmask));
11380 }
11381 else
11382 {
11383 vty_out (vty, " aggregate-address %s/%d",
11384 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
11385 p->prefixlen);
11386 }
11387
11388 if (bgp_aggregate->as_set)
11389 vty_out (vty, " as-set");
11390
11391 if (bgp_aggregate->summary_only)
11392 vty_out (vty, " summary-only");
11393
11394 vty_out (vty, "%s", VTY_NEWLINE);
11395 }
11396
11397 return 0;
11398}
11399
11400int
11401bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
11402{
11403 struct bgp_node *rn;
11404 struct bgp_distance *bdistance;
11405
11406 /* Distance configuration. */
11407 if (bgp->distance_ebgp
11408 && bgp->distance_ibgp
11409 && bgp->distance_local
11410 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
11411 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
11412 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
11413 vty_out (vty, " distance bgp %d %d %d%s",
11414 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
11415 VTY_NEWLINE);
11416
11417 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
11418 if ((bdistance = rn->info) != NULL)
11419 {
11420 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
11421 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
11422 bdistance->access_list ? bdistance->access_list : "",
11423 VTY_NEWLINE);
11424 }
11425
11426 return 0;
11427}
11428
11429/* Allocate routing table structure and install commands. */
11430void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011431bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000011432{
11433 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000011434 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000011435
11436 /* IPv4 BGP commands. */
11437 install_element (BGP_NODE, &bgp_network_cmd);
11438 install_element (BGP_NODE, &bgp_network_mask_cmd);
11439 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
11440 install_element (BGP_NODE, &bgp_network_route_map_cmd);
11441 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
11442 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
11443 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
11444 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
11445 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
11446 install_element (BGP_NODE, &no_bgp_network_cmd);
11447 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
11448 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
11449 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
11450 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
11451 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11452 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
11453 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
11454 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
11455
11456 install_element (BGP_NODE, &aggregate_address_cmd);
11457 install_element (BGP_NODE, &aggregate_address_mask_cmd);
11458 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
11459 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
11460 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
11461 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
11462 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
11463 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
11464 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
11465 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
11466 install_element (BGP_NODE, &no_aggregate_address_cmd);
11467 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
11468 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
11469 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
11470 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
11471 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
11472 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
11473 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
11474 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11475 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11476
11477 /* IPv4 unicast configuration. */
11478 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
11479 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
11480 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
11481 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
11482 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
11483 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmae70e5752011-07-05 00:41:59 +040011484 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000011485 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
11486 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
11487 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
11488 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
11489 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmae70e5752011-07-05 00:41:59 +040011490
paul718e3742002-12-13 20:15:29 +000011491 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
11492 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
11493 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
11494 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
11495 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
11496 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
11497 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
11498 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
11499 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
11500 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
11501 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
11502 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
11503 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
11504 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
11505 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
11506 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
11507 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
11508 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
11509 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11510 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11511
11512 /* IPv4 multicast configuration. */
11513 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
11514 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
11515 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
11516 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
11517 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
11518 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
11519 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
11520 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
11521 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
11522 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
11523 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
11524 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
11525 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
11526 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
11527 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
11528 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
11529 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
11530 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
11531 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
11532 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
11533 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
11534 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
11535 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
11536 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
11537 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
11538 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
11539 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
11540 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
11541 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
11542 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
11543 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
11544 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
11545
11546 install_element (VIEW_NODE, &show_ip_bgp_cmd);
11547 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
11548 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
11549 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
11550 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11551 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11552 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
11553 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11554 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11555 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11556 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
11557 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
11558 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
11559 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
11560 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11561 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
11562 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11563 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
11564 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11565 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
11566 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11567 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
11568 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11569 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
11570 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11571 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
11572 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
11573 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
11574 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
11575 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
11576 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
11577 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
11578 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
11579 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
11580 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
11581 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
11582 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
11583 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11584 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11585 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11586 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11587 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
11588 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11589 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
11590 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11591 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
11592 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11593 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11594 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11595 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11596 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11597 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
11598 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11599 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11600 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11601 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
11602 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
11603 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
11604 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
11605 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11606 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
11607 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
11608 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11609 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11610 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
11611 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
11612 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011613 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
11614 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
11615 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011616 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11617 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011618 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
11619 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11620 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011621
11622 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
11623 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
11624 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
11625 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11626 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
11627 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11628 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11629 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11630 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
11631 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
11632 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
11633 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
11634 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
11635 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
11636 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
11637 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
11638 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
11639 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
11640 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
11641 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
11642 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
11643 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
11644 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11645 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11646 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11647 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11648 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
11649 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
11650 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11651 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011652
11653 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
11654 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
11655 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
11656 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
11657 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
11658 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
11659 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
11660 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
11661 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
11662 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
11663 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
11664 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
11665 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
11666 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
11667 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
11668 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
11669 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
11670 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
11671 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
11672 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
11673 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
11674 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
11675 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
11676 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
11677 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
11678 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
11679 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
11680 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
11681 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
11682 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
11683 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
11684 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
11685 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
11686 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
11687 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
11688 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
11689 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
11690 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
11691 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
11692 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
11693 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
11694 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
11695 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
11696 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
11697 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
11698 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
11699 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
11700 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
11701 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
11702 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
11703 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
11704 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
11705 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
11706 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
11707 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
11708 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
11709 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
11710 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
11711 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
11712 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
11713 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
11714 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
11715 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
11716 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
11717 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
11718 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
11719 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011720 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
11721 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
11722 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010011723 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
11724 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011725 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
11726 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
11727 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011728
11729 /* BGP dampening clear commands */
11730 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
11731 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
11732 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
11733 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
11734
Paul Jakmaff7924f2006-09-04 01:10:36 +000011735 /* prefix count */
11736 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
11737 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
11738 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000011739#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000011740 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
11741
paul718e3742002-12-13 20:15:29 +000011742 /* New config IPv6 BGP commands. */
11743 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
11744 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
11745 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
11746 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
11747
11748 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
11749 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
11750 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
11751 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
11752
11753 /* Old config IPv6 BGP commands. */
11754 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
11755 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
11756
11757 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
11758 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
11759 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
11760 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
11761
11762 install_element (VIEW_NODE, &show_bgp_cmd);
11763 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
11764 install_element (VIEW_NODE, &show_bgp_route_cmd);
11765 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
11766 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
11767 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
11768 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
11769 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
11770 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
11771 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
11772 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
11773 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
11774 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
11775 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
11776 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
11777 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
11778 install_element (VIEW_NODE, &show_bgp_community_cmd);
11779 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
11780 install_element (VIEW_NODE, &show_bgp_community2_cmd);
11781 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
11782 install_element (VIEW_NODE, &show_bgp_community3_cmd);
11783 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
11784 install_element (VIEW_NODE, &show_bgp_community4_cmd);
11785 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
11786 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
11787 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
11788 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
11789 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
11790 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
11791 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
11792 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
11793 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
11794 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
11795 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
11796 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
11797 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11798 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
11799 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11800 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
11801 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11802 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
11803 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11804 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
11805 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11806 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11807 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011808 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
11809 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11810 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
11811 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011812 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
11813 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
11814 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011815 install_element (VIEW_NODE, &show_bgp_view_cmd);
11816 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
11817 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
11818 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
11819 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
11820 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
11821 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11822 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11823 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11824 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11825 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
11826 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11827 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11828 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11829 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
11830 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11831 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
11832 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011833 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
11834 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
11835 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010011836
11837 /* Restricted:
11838 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
11839 */
11840 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
11841 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
11842 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
11843 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
11844 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
11845 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
11846 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
11847 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
11848 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
11849 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
11850 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
11851 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
11852 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
11853 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
11854 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
11855 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
11856 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
11857 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
11858 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
11859 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
11860 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
11861 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
11862 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
11863 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
11864 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
11865 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
11866 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11867 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11868 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
11869 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000011870
11871 install_element (ENABLE_NODE, &show_bgp_cmd);
11872 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
11873 install_element (ENABLE_NODE, &show_bgp_route_cmd);
11874 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
11875 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
11876 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
11877 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
11878 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
11879 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
11880 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
11881 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
11882 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
11883 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
11884 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
11885 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
11886 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
11887 install_element (ENABLE_NODE, &show_bgp_community_cmd);
11888 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
11889 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
11890 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
11891 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
11892 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
11893 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
11894 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
11895 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
11896 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
11897 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
11898 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
11899 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
11900 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
11901 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
11902 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
11903 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
11904 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
11905 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
11906 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
11907 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
11908 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
11909 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
11910 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
11911 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
11912 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
11913 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
11914 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
11915 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
11916 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000011917 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
11918 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
11919 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
11920 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011921 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
11922 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
11923 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000011924 install_element (ENABLE_NODE, &show_bgp_view_cmd);
11925 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
11926 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
11927 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
11928 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
11929 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
11930 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
11931 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
11932 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
11933 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
11934 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
11935 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
11936 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
11937 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
11938 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
11939 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
11940 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
11941 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000011942 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
11943 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
11944 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000011945
11946 /* Statistics */
11947 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
11948 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
11949 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
11950 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
11951
paul718e3742002-12-13 20:15:29 +000011952 /* old command */
11953 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
11954 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
11955 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
11956 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
11957 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
11958 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
11959 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
11960 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
11961 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
11962 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
11963 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
11964 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
11965 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
11966 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
11967 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
11968 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
11969 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
11970 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
11971 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
11972 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
11973 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
11974 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
11975 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
11976 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
11977 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
11978 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
11979 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
11980 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
11981 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
11982 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
11983 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
11984 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
11985 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
11986 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
11987 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
11988 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000011989
paul718e3742002-12-13 20:15:29 +000011990 /* old command */
11991 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
11992 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
11993 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
11994 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
11995 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
11996 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
11997 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
11998 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
11999 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12000 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12001 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12002 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12003 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12004 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12005 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12006 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12007 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12008 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12009 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12010 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12011 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12012 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12013 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12014 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12015 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12016 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12017 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12018 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12019 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12020 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12021 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12022 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12023 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12024 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12025 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12026 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12027
12028 /* old command */
12029 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12030 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12031 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12032 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12033
12034 /* old command */
12035 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12036 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12037 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12038 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12039
12040 /* old command */
12041 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12042 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12043 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12044 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12045#endif /* HAVE_IPV6 */
12046
12047 install_element (BGP_NODE, &bgp_distance_cmd);
12048 install_element (BGP_NODE, &no_bgp_distance_cmd);
12049 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12050 install_element (BGP_NODE, &bgp_distance_source_cmd);
12051 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12052 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12053 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12054
12055 install_element (BGP_NODE, &bgp_damp_set_cmd);
12056 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12057 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12058 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12059 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12060 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12061 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12062 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12063 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12064 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmae70e5752011-07-05 00:41:59 +040012065
12066 /* Deprecated AS-Pathlimit commands */
12067 install_element (BGP_NODE, &bgp_network_ttl_cmd);
12068 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
12069 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
12070 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
12071 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12072 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12073
12074 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
12075 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
12076 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12077 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
12078 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12079 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12080
12081 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
12082 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
12083 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
12084 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
12085 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12086 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12087
12088 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
12089 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
12090 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12091 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
12092 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12093 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12094
12095 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
12096 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
12097 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
12098 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
12099 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12100 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12101
12102 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
12103 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
12104 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12105 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
12106 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12107 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakmaa8b79422011-03-23 10:30:30 +000012108
12109#ifdef HAVE_IPV6
Paul Jakmae70e5752011-07-05 00:41:59 +040012110 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
12111 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakmaa8b79422011-03-23 10:30:30 +000012112#endif
paul718e3742002-12-13 20:15:29 +000012113}
Chris Caputo228da422009-07-18 05:44:03 +000012114
12115void
12116bgp_route_finish (void)
12117{
12118 bgp_table_unlock (bgp_distance_table);
12119 bgp_distance_table = NULL;
12120}