blob: 5c4ab266634de4170ad68f03ad61acf6c8f38748 [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/* BGP routing information
2 Copyright (C) 1996, 97, 98, 99 Kunihiro Ishiguro
3
4This file is part of GNU Zebra.
5
6GNU Zebra is free software; you can redistribute it and/or modify it
7under the terms of the GNU General Public License as published by the
8Free Software Foundation; either version 2, or (at your option) any
9later version.
10
11GNU Zebra is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Zebra; see the file COPYING. If not, write to the Free
18Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
1902111-1307, USA. */
20
21#include <zebra.h>
22
23#include "prefix.h"
24#include "linklist.h"
25#include "memory.h"
26#include "command.h"
27#include "stream.h"
28#include "filter.h"
29#include "str.h"
30#include "log.h"
31#include "routemap.h"
32#include "buffer.h"
33#include "sockunion.h"
34#include "plist.h"
35#include "thread.h"
paul200df112005-06-01 11:17:05 +000036#include "workqueue.h"
paul718e3742002-12-13 20:15:29 +000037
38#include "bgpd/bgpd.h"
39#include "bgpd/bgp_table.h"
40#include "bgpd/bgp_route.h"
41#include "bgpd/bgp_attr.h"
42#include "bgpd/bgp_debug.h"
43#include "bgpd/bgp_aspath.h"
44#include "bgpd/bgp_regex.h"
45#include "bgpd/bgp_community.h"
46#include "bgpd/bgp_ecommunity.h"
47#include "bgpd/bgp_clist.h"
48#include "bgpd/bgp_packet.h"
49#include "bgpd/bgp_filter.h"
50#include "bgpd/bgp_fsm.h"
51#include "bgpd/bgp_mplsvpn.h"
52#include "bgpd/bgp_nexthop.h"
53#include "bgpd/bgp_damp.h"
54#include "bgpd/bgp_advertise.h"
55#include "bgpd/bgp_zebra.h"
hasso0a486e52005-02-01 20:57:17 +000056#include "bgpd/bgp_vty.h"
Josh Bailey96450fa2011-07-20 20:45:12 -070057#include "bgpd/bgp_mpath.h"
paul718e3742002-12-13 20:15:29 +000058
59/* Extern from bgp_dump.c */
Stephen Hemmingerdde72582009-05-08 15:19:07 -070060extern const char *bgp_origin_str[];
61extern const char *bgp_origin_long_str[];
paul718e3742002-12-13 20:15:29 +000062
paul94f2b392005-06-28 12:44:16 +000063static struct bgp_node *
paulfee0f4c2004-09-13 05:12:46 +000064bgp_afi_node_get (struct bgp_table *table, afi_t afi, safi_t safi, struct prefix *p,
paul718e3742002-12-13 20:15:29 +000065 struct prefix_rd *prd)
66{
67 struct bgp_node *rn;
68 struct bgp_node *prn = NULL;
Paul Jakmada5b30f2006-05-08 14:37:17 +000069
70 assert (table);
71 if (!table)
72 return NULL;
73
paul718e3742002-12-13 20:15:29 +000074 if (safi == SAFI_MPLS_VPN)
75 {
paulfee0f4c2004-09-13 05:12:46 +000076 prn = bgp_node_get (table, (struct prefix *) prd);
paul718e3742002-12-13 20:15:29 +000077
78 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +000079 prn->info = bgp_table_init (afi, safi);
paul718e3742002-12-13 20:15:29 +000080 else
81 bgp_unlock_node (prn);
82 table = prn->info;
83 }
paul718e3742002-12-13 20:15:29 +000084
85 rn = bgp_node_get (table, p);
86
87 if (safi == SAFI_MPLS_VPN)
88 rn->prn = prn;
89
90 return rn;
91}
92
Paul Jakmafb982c22007-05-04 20:15:47 +000093/* Allocate bgp_info_extra */
94static struct bgp_info_extra *
95bgp_info_extra_new (void)
96{
97 struct bgp_info_extra *new;
98 new = XCALLOC (MTYPE_BGP_ROUTE_EXTRA, sizeof (struct bgp_info_extra));
99 return new;
100}
101
102static void
103bgp_info_extra_free (struct bgp_info_extra **extra)
104{
105 if (extra && *extra)
106 {
107 if ((*extra)->damp_info)
108 bgp_damp_info_free ((*extra)->damp_info, 0);
109
110 (*extra)->damp_info = NULL;
111
112 XFREE (MTYPE_BGP_ROUTE_EXTRA, *extra);
113
114 *extra = NULL;
115 }
116}
117
118/* Get bgp_info extra information for the given bgp_info, lazy allocated
119 * if required.
120 */
121struct bgp_info_extra *
122bgp_info_extra_get (struct bgp_info *ri)
123{
124 if (!ri->extra)
125 ri->extra = bgp_info_extra_new();
126 return ri->extra;
127}
128
paul718e3742002-12-13 20:15:29 +0000129/* Allocate new bgp info structure. */
paul200df112005-06-01 11:17:05 +0000130static struct bgp_info *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -0800131bgp_info_new (void)
paul718e3742002-12-13 20:15:29 +0000132{
Stephen Hemminger393deb92008-08-18 14:13:29 -0700133 return XCALLOC (MTYPE_BGP_ROUTE, sizeof (struct bgp_info));
paul718e3742002-12-13 20:15:29 +0000134}
135
136/* Free bgp route information. */
paul200df112005-06-01 11:17:05 +0000137static void
paul718e3742002-12-13 20:15:29 +0000138bgp_info_free (struct bgp_info *binfo)
139{
140 if (binfo->attr)
141 bgp_attr_unintern (binfo->attr);
Paul Jakmafb982c22007-05-04 20:15:47 +0000142
143 bgp_info_extra_free (&binfo->extra);
Josh Baileyde8d5df2011-07-20 20:46:01 -0700144 bgp_info_mpath_free (&binfo->mpath);
paul718e3742002-12-13 20:15:29 +0000145
paul200df112005-06-01 11:17:05 +0000146 peer_unlock (binfo->peer); /* bgp_info peer reference */
147
paul718e3742002-12-13 20:15:29 +0000148 XFREE (MTYPE_BGP_ROUTE, binfo);
149}
150
paul200df112005-06-01 11:17:05 +0000151struct bgp_info *
152bgp_info_lock (struct bgp_info *binfo)
153{
154 binfo->lock++;
155 return binfo;
156}
157
158struct bgp_info *
159bgp_info_unlock (struct bgp_info *binfo)
160{
161 assert (binfo && binfo->lock > 0);
162 binfo->lock--;
163
164 if (binfo->lock == 0)
165 {
166#if 0
167 zlog_debug ("%s: unlocked and freeing", __func__);
168 zlog_backtrace (LOG_DEBUG);
169#endif
170 bgp_info_free (binfo);
171 return NULL;
172 }
173
174#if 0
175 if (binfo->lock == 1)
176 {
177 zlog_debug ("%s: unlocked to 1", __func__);
178 zlog_backtrace (LOG_DEBUG);
179 }
180#endif
181
182 return binfo;
183}
184
paul718e3742002-12-13 20:15:29 +0000185void
186bgp_info_add (struct bgp_node *rn, struct bgp_info *ri)
187{
188 struct bgp_info *top;
189
190 top = rn->info;
paul200df112005-06-01 11:17:05 +0000191
paul718e3742002-12-13 20:15:29 +0000192 ri->next = rn->info;
193 ri->prev = NULL;
194 if (top)
195 top->prev = ri;
196 rn->info = ri;
paul200df112005-06-01 11:17:05 +0000197
198 bgp_info_lock (ri);
199 bgp_lock_node (rn);
200 peer_lock (ri->peer); /* bgp_info peer reference */
paul718e3742002-12-13 20:15:29 +0000201}
202
paulb40d9392005-08-22 22:34:41 +0000203/* Do the actual removal of info from RIB, for use by bgp_process
204 completion callback *only* */
205static void
206bgp_info_reap (struct bgp_node *rn, struct bgp_info *ri)
paul718e3742002-12-13 20:15:29 +0000207{
208 if (ri->next)
209 ri->next->prev = ri->prev;
210 if (ri->prev)
211 ri->prev->next = ri->next;
212 else
213 rn->info = ri->next;
paul200df112005-06-01 11:17:05 +0000214
Josh Baileyde8d5df2011-07-20 20:46:01 -0700215 bgp_info_mpath_dequeue (ri);
paul200df112005-06-01 11:17:05 +0000216 bgp_info_unlock (ri);
217 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +0000218}
219
paulb40d9392005-08-22 22:34:41 +0000220void
221bgp_info_delete (struct bgp_node *rn, struct bgp_info *ri)
222{
Paul Jakma1a392d42006-09-07 00:24:49 +0000223 bgp_info_set_flag (rn, ri, BGP_INFO_REMOVED);
224 /* set of previous already took care of pcount */
paulb40d9392005-08-22 22:34:41 +0000225 UNSET_FLAG (ri->flags, BGP_INFO_VALID);
226}
227
Andrew J. Schorr8d452102006-11-28 19:50:46 +0000228/* undo the effects of a previous call to bgp_info_delete; typically
229 called when a route is deleted and then quickly re-added before the
230 deletion has been processed */
231static void
232bgp_info_restore (struct bgp_node *rn, struct bgp_info *ri)
233{
234 bgp_info_unset_flag (rn, ri, BGP_INFO_REMOVED);
235 /* unset of previous already took care of pcount */
236 SET_FLAG (ri->flags, BGP_INFO_VALID);
237}
238
Paul Jakma1a392d42006-09-07 00:24:49 +0000239/* Adjust pcount as required */
240static void
241bgp_pcount_adjust (struct bgp_node *rn, struct bgp_info *ri)
242{
Paul Jakma6f585442006-10-22 19:13:07 +0000243 assert (rn && rn->table);
244 assert (ri && ri->peer && ri->peer->bgp);
245
Paul Jakma1a392d42006-09-07 00:24:49 +0000246 /* Ignore 'pcount' for RS-client tables */
247 if (rn->table->type != BGP_TABLE_MAIN
248 || ri->peer == ri->peer->bgp->peer_self)
249 return;
250
251 if (BGP_INFO_HOLDDOWN (ri)
252 && CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
253 {
254
255 UNSET_FLAG (ri->flags, BGP_INFO_COUNTED);
256
257 /* slight hack, but more robust against errors. */
258 if (ri->peer->pcount[rn->table->afi][rn->table->safi])
259 ri->peer->pcount[rn->table->afi][rn->table->safi]--;
260 else
261 {
262 zlog_warn ("%s: Asked to decrement 0 prefix count for peer %s",
263 __func__, ri->peer->host);
264 zlog_backtrace (LOG_WARNING);
265 zlog_warn ("%s: Please report to Quagga bugzilla", __func__);
266 }
267 }
268 else if (!BGP_INFO_HOLDDOWN (ri)
269 && !CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
270 {
271 SET_FLAG (ri->flags, BGP_INFO_COUNTED);
272 ri->peer->pcount[rn->table->afi][rn->table->safi]++;
273 }
274}
275
276
277/* Set/unset bgp_info flags, adjusting any other state as needed.
278 * This is here primarily to keep prefix-count in check.
279 */
280void
281bgp_info_set_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
282{
283 SET_FLAG (ri->flags, flag);
284
285 /* early bath if we know it's not a flag that changes useability state */
286 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
287 return;
288
289 bgp_pcount_adjust (rn, ri);
290}
291
292void
293bgp_info_unset_flag (struct bgp_node *rn, struct bgp_info *ri, u_int32_t flag)
294{
295 UNSET_FLAG (ri->flags, flag);
296
297 /* early bath if we know it's not a flag that changes useability state */
298 if (!CHECK_FLAG (flag, BGP_INFO_VALID|BGP_INFO_UNUSEABLE))
299 return;
300
301 bgp_pcount_adjust (rn, ri);
302}
303
paul718e3742002-12-13 20:15:29 +0000304/* Get MED value. If MED value is missing and "bgp bestpath
305 missing-as-worst" is specified, treat it as the worst value. */
paul94f2b392005-06-28 12:44:16 +0000306static u_int32_t
paul718e3742002-12-13 20:15:29 +0000307bgp_med_value (struct attr *attr, struct bgp *bgp)
308{
309 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
310 return attr->med;
311 else
312 {
313 if (bgp_flag_check (bgp, BGP_FLAG_MED_MISSING_AS_WORST))
paul3b424972003-10-13 09:47:32 +0000314 return BGP_MED_MAX;
paul718e3742002-12-13 20:15:29 +0000315 else
316 return 0;
317 }
318}
319
320/* Compare two bgp route entity. br is preferable then return 1. */
paul94f2b392005-06-28 12:44:16 +0000321static int
Josh Bailey96450fa2011-07-20 20:45:12 -0700322bgp_info_cmp (struct bgp *bgp, struct bgp_info *new, struct bgp_info *exist,
323 int *paths_eq)
paul718e3742002-12-13 20:15:29 +0000324{
325 u_int32_t new_pref;
326 u_int32_t exist_pref;
327 u_int32_t new_med;
328 u_int32_t exist_med;
Paul Jakmafb982c22007-05-04 20:15:47 +0000329 u_int32_t new_weight = 0;
330 u_int32_t exist_weight = 0;
paul718e3742002-12-13 20:15:29 +0000331 struct in_addr new_id;
332 struct in_addr exist_id;
333 int new_cluster;
334 int exist_cluster;
335 int internal_as_route = 0;
336 int confed_as_route = 0;
337 int ret;
Josh Bailey96450fa2011-07-20 20:45:12 -0700338 uint32_t newm, existm;
339
340 *paths_eq = 0;
paul718e3742002-12-13 20:15:29 +0000341
342 /* 0. Null check. */
343 if (new == NULL)
344 return 0;
345 if (exist == NULL)
346 return 1;
347
348 /* 1. Weight check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000349 if (new->attr->extra)
350 new_weight = new->attr->extra->weight;
351 if (exist->attr->extra)
352 exist_weight = exist->attr->extra->weight;
353 if (new_weight > exist_weight)
paul718e3742002-12-13 20:15:29 +0000354 return 1;
Paul Jakmafb982c22007-05-04 20:15:47 +0000355 if (new_weight < exist_weight)
paul718e3742002-12-13 20:15:29 +0000356 return 0;
357
358 /* 2. Local preference check. */
359 if (new->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
360 new_pref = new->attr->local_pref;
361 else
362 new_pref = bgp->default_local_pref;
363
364 if (exist->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
365 exist_pref = exist->attr->local_pref;
366 else
367 exist_pref = bgp->default_local_pref;
368
369 if (new_pref > exist_pref)
370 return 1;
371 if (new_pref < exist_pref)
372 return 0;
373
374 /* 3. Local route check. */
375 if (new->sub_type == BGP_ROUTE_STATIC)
376 return 1;
377 if (exist->sub_type == BGP_ROUTE_STATIC)
378 return 0;
379
380 if (new->sub_type == BGP_ROUTE_REDISTRIBUTE)
381 return 1;
382 if (exist->sub_type == BGP_ROUTE_REDISTRIBUTE)
383 return 0;
384
385 if (new->sub_type == BGP_ROUTE_AGGREGATE)
386 return 1;
387 if (exist->sub_type == BGP_ROUTE_AGGREGATE)
388 return 0;
389
390 /* 4. AS path length check. */
391 if (! bgp_flag_check (bgp, BGP_FLAG_ASPATH_IGNORE))
392 {
paulfe69a502005-09-10 16:55:02 +0000393 int exist_hops = aspath_count_hops (exist->attr->aspath);
394 int exist_confeds = aspath_count_confeds (exist->attr->aspath);
395
hasso68118452005-04-08 15:40:36 +0000396 if (bgp_flag_check (bgp, BGP_FLAG_ASPATH_CONFED))
397 {
paulfe69a502005-09-10 16:55:02 +0000398 int aspath_hops;
399
400 aspath_hops = aspath_count_hops (new->attr->aspath);
401 aspath_hops += aspath_count_confeds (new->attr->aspath);
402
403 if ( aspath_hops < (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000404 return 1;
paulfe69a502005-09-10 16:55:02 +0000405 if ( aspath_hops > (exist_hops + exist_confeds))
hasso68118452005-04-08 15:40:36 +0000406 return 0;
407 }
408 else
409 {
paulfe69a502005-09-10 16:55:02 +0000410 int newhops = aspath_count_hops (new->attr->aspath);
411
412 if (newhops < exist_hops)
hasso68118452005-04-08 15:40:36 +0000413 return 1;
paulfe69a502005-09-10 16:55:02 +0000414 if (newhops > exist_hops)
hasso68118452005-04-08 15:40:36 +0000415 return 0;
416 }
paul718e3742002-12-13 20:15:29 +0000417 }
418
419 /* 5. Origin check. */
420 if (new->attr->origin < exist->attr->origin)
421 return 1;
422 if (new->attr->origin > exist->attr->origin)
423 return 0;
424
425 /* 6. MED check. */
paulfe69a502005-09-10 16:55:02 +0000426 internal_as_route = (aspath_count_hops (new->attr->aspath) == 0
427 && aspath_count_hops (exist->attr->aspath) == 0);
428 confed_as_route = (aspath_count_confeds (new->attr->aspath) > 0
429 && aspath_count_confeds (exist->attr->aspath) > 0
430 && aspath_count_hops (new->attr->aspath) == 0
431 && aspath_count_hops (exist->attr->aspath) == 0);
paul718e3742002-12-13 20:15:29 +0000432
433 if (bgp_flag_check (bgp, BGP_FLAG_ALWAYS_COMPARE_MED)
434 || (bgp_flag_check (bgp, BGP_FLAG_MED_CONFED)
435 && confed_as_route)
436 || aspath_cmp_left (new->attr->aspath, exist->attr->aspath)
437 || aspath_cmp_left_confed (new->attr->aspath, exist->attr->aspath)
438 || internal_as_route)
439 {
440 new_med = bgp_med_value (new->attr, bgp);
441 exist_med = bgp_med_value (exist->attr, bgp);
442
443 if (new_med < exist_med)
444 return 1;
445 if (new_med > exist_med)
446 return 0;
447 }
448
449 /* 7. Peer type check. */
450 if (peer_sort (new->peer) == BGP_PEER_EBGP
451 && peer_sort (exist->peer) == BGP_PEER_IBGP)
452 return 1;
453 if (peer_sort (new->peer) == BGP_PEER_EBGP
454 && peer_sort (exist->peer) == BGP_PEER_CONFED)
455 return 1;
456 if (peer_sort (new->peer) == BGP_PEER_IBGP
457 && peer_sort (exist->peer) == BGP_PEER_EBGP)
458 return 0;
459 if (peer_sort (new->peer) == BGP_PEER_CONFED
460 && peer_sort (exist->peer) == BGP_PEER_EBGP)
461 return 0;
462
463 /* 8. IGP metric check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700464 newm = (new->extra ? new->extra->igpmetric : 0);
465 existm = (exist->extra ? exist->extra->igpmetric : 0);
466 if (newm < existm)
467 ret = 1;
468 if (newm > existm)
469 ret = 0;
paul718e3742002-12-13 20:15:29 +0000470
471 /* 9. Maximum path check. */
Josh Bailey96450fa2011-07-20 20:45:12 -0700472 if (newm == existm)
473 {
474 if ((peer_sort (new->peer) == BGP_PEER_IBGP))
475 {
476 if (aspath_cmp (new->attr->aspath, exist->attr->aspath))
477 *paths_eq = 1;
478 }
479 else if (new->peer->as == exist->peer->as)
480 *paths_eq = 1;
481 }
482 else
483 {
484 /*
485 * TODO: If unequal cost ibgp multipath is enabled we can
486 * mark the paths as equal here instead of returning
487 */
488 return ret;
489 }
paul718e3742002-12-13 20:15:29 +0000490
491 /* 10. If both paths are external, prefer the path that was received
492 first (the oldest one). This step minimizes route-flap, since a
493 newer path won't displace an older one, even if it was the
494 preferred route based on the additional decision criteria below. */
495 if (! bgp_flag_check (bgp, BGP_FLAG_COMPARE_ROUTER_ID)
496 && peer_sort (new->peer) == BGP_PEER_EBGP
497 && peer_sort (exist->peer) == BGP_PEER_EBGP)
498 {
499 if (CHECK_FLAG (new->flags, BGP_INFO_SELECTED))
500 return 1;
501 if (CHECK_FLAG (exist->flags, BGP_INFO_SELECTED))
502 return 0;
503 }
504
505 /* 11. Rourter-ID comparision. */
506 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000507 new_id.s_addr = new->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000508 else
509 new_id.s_addr = new->peer->remote_id.s_addr;
510 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +0000511 exist_id.s_addr = exist->attr->extra->originator_id.s_addr;
paul718e3742002-12-13 20:15:29 +0000512 else
513 exist_id.s_addr = exist->peer->remote_id.s_addr;
514
515 if (ntohl (new_id.s_addr) < ntohl (exist_id.s_addr))
516 return 1;
517 if (ntohl (new_id.s_addr) > ntohl (exist_id.s_addr))
518 return 0;
519
520 /* 12. Cluster length comparision. */
521 if (new->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000522 new_cluster = new->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000523 else
524 new_cluster = 0;
525 if (exist->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
Paul Jakmafb982c22007-05-04 20:15:47 +0000526 exist_cluster = exist->attr->extra->cluster->length;
paul718e3742002-12-13 20:15:29 +0000527 else
528 exist_cluster = 0;
529
530 if (new_cluster < exist_cluster)
531 return 1;
532 if (new_cluster > exist_cluster)
533 return 0;
534
535 /* 13. Neighbor address comparision. */
536 ret = sockunion_cmp (new->peer->su_remote, exist->peer->su_remote);
537
538 if (ret == 1)
539 return 0;
540 if (ret == -1)
541 return 1;
542
543 return 1;
544}
545
paul94f2b392005-06-28 12:44:16 +0000546static enum filter_type
paul718e3742002-12-13 20:15:29 +0000547bgp_input_filter (struct peer *peer, struct prefix *p, struct attr *attr,
548 afi_t afi, safi_t safi)
549{
550 struct bgp_filter *filter;
551
552 filter = &peer->filter[afi][safi];
553
Paul Jakma650f76c2009-06-25 18:06:31 +0100554#define FILTER_EXIST_WARN(F,f,filter) \
555 if (BGP_DEBUG (update, UPDATE_IN) \
556 && !(F ## _IN (filter))) \
557 plog_warn (peer->log, "%s: Could not find configured input %s-list %s!", \
558 peer->host, #f, F ## _IN_NAME(filter));
559
560 if (DISTRIBUTE_IN_NAME (filter)) {
561 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
562
paul718e3742002-12-13 20:15:29 +0000563 if (access_list_apply (DISTRIBUTE_IN (filter), p) == FILTER_DENY)
564 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100565 }
paul718e3742002-12-13 20:15:29 +0000566
Paul Jakma650f76c2009-06-25 18:06:31 +0100567 if (PREFIX_LIST_IN_NAME (filter)) {
568 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
569
paul718e3742002-12-13 20:15:29 +0000570 if (prefix_list_apply (PREFIX_LIST_IN (filter), p) == PREFIX_DENY)
571 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100572 }
paul718e3742002-12-13 20:15:29 +0000573
Paul Jakma650f76c2009-06-25 18:06:31 +0100574 if (FILTER_LIST_IN_NAME (filter)) {
575 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
576
paul718e3742002-12-13 20:15:29 +0000577 if (as_list_apply (FILTER_LIST_IN (filter), attr->aspath)== AS_FILTER_DENY)
578 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100579 }
580
paul718e3742002-12-13 20:15:29 +0000581 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100582#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000583}
584
paul94f2b392005-06-28 12:44:16 +0000585static enum filter_type
paul718e3742002-12-13 20:15:29 +0000586bgp_output_filter (struct peer *peer, struct prefix *p, struct attr *attr,
587 afi_t afi, safi_t safi)
588{
589 struct bgp_filter *filter;
590
591 filter = &peer->filter[afi][safi];
592
Paul Jakma650f76c2009-06-25 18:06:31 +0100593#define FILTER_EXIST_WARN(F,f,filter) \
594 if (BGP_DEBUG (update, UPDATE_OUT) \
595 && !(F ## _OUT (filter))) \
596 plog_warn (peer->log, "%s: Could not find configured output %s-list %s!", \
597 peer->host, #f, F ## _OUT_NAME(filter));
598
599 if (DISTRIBUTE_OUT_NAME (filter)) {
600 FILTER_EXIST_WARN(DISTRIBUTE, distribute, filter);
601
paul718e3742002-12-13 20:15:29 +0000602 if (access_list_apply (DISTRIBUTE_OUT (filter), p) == FILTER_DENY)
603 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100604 }
paul718e3742002-12-13 20:15:29 +0000605
Paul Jakma650f76c2009-06-25 18:06:31 +0100606 if (PREFIX_LIST_OUT_NAME (filter)) {
607 FILTER_EXIST_WARN(PREFIX_LIST, prefix, filter);
608
paul718e3742002-12-13 20:15:29 +0000609 if (prefix_list_apply (PREFIX_LIST_OUT (filter), p) == PREFIX_DENY)
610 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100611 }
paul718e3742002-12-13 20:15:29 +0000612
Paul Jakma650f76c2009-06-25 18:06:31 +0100613 if (FILTER_LIST_OUT_NAME (filter)) {
614 FILTER_EXIST_WARN(FILTER_LIST, as, filter);
615
paul718e3742002-12-13 20:15:29 +0000616 if (as_list_apply (FILTER_LIST_OUT (filter), attr->aspath) == AS_FILTER_DENY)
617 return FILTER_DENY;
Paul Jakma650f76c2009-06-25 18:06:31 +0100618 }
paul718e3742002-12-13 20:15:29 +0000619
620 return FILTER_PERMIT;
Paul Jakma650f76c2009-06-25 18:06:31 +0100621#undef FILTER_EXIST_WARN
paul718e3742002-12-13 20:15:29 +0000622}
623
624/* If community attribute includes no_export then return 1. */
paul94f2b392005-06-28 12:44:16 +0000625static int
paul718e3742002-12-13 20:15:29 +0000626bgp_community_filter (struct peer *peer, struct attr *attr)
627{
628 if (attr->community)
629 {
630 /* NO_ADVERTISE check. */
631 if (community_include (attr->community, COMMUNITY_NO_ADVERTISE))
632 return 1;
633
634 /* NO_EXPORT check. */
635 if (peer_sort (peer) == BGP_PEER_EBGP &&
636 community_include (attr->community, COMMUNITY_NO_EXPORT))
637 return 1;
638
639 /* NO_EXPORT_SUBCONFED check. */
640 if (peer_sort (peer) == BGP_PEER_EBGP
641 || peer_sort (peer) == BGP_PEER_CONFED)
642 if (community_include (attr->community, COMMUNITY_NO_EXPORT_SUBCONFED))
643 return 1;
644 }
645 return 0;
646}
647
648/* Route reflection loop check. */
649static int
650bgp_cluster_filter (struct peer *peer, struct attr *attr)
651{
652 struct in_addr cluster_id;
653
Paul Jakmafb982c22007-05-04 20:15:47 +0000654 if (attr->extra && attr->extra->cluster)
paul718e3742002-12-13 20:15:29 +0000655 {
656 if (peer->bgp->config & BGP_CONFIG_CLUSTER_ID)
657 cluster_id = peer->bgp->cluster_id;
658 else
659 cluster_id = peer->bgp->router_id;
660
Paul Jakmafb982c22007-05-04 20:15:47 +0000661 if (cluster_loop_check (attr->extra->cluster, cluster_id))
paul718e3742002-12-13 20:15:29 +0000662 return 1;
663 }
664 return 0;
665}
666
paul94f2b392005-06-28 12:44:16 +0000667static int
paul718e3742002-12-13 20:15:29 +0000668bgp_input_modifier (struct peer *peer, struct prefix *p, struct attr *attr,
669 afi_t afi, safi_t safi)
670{
671 struct bgp_filter *filter;
672 struct bgp_info info;
673 route_map_result_t ret;
674
675 filter = &peer->filter[afi][safi];
676
677 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000678 if (peer->weight)
679 (bgp_attr_extra_get (attr))->weight = peer->weight;
paul718e3742002-12-13 20:15:29 +0000680
681 /* Route map apply. */
682 if (ROUTE_MAP_IN_NAME (filter))
683 {
684 /* Duplicate current value to new strucutre for modification. */
685 info.peer = peer;
686 info.attr = attr;
687
paulac41b2a2003-08-12 05:32:27 +0000688 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IN);
689
paul718e3742002-12-13 20:15:29 +0000690 /* Apply BGP route map to the attribute. */
691 ret = route_map_apply (ROUTE_MAP_IN (filter), p, RMAP_BGP, &info);
paulac41b2a2003-08-12 05:32:27 +0000692
693 peer->rmap_type = 0;
694
paul718e3742002-12-13 20:15:29 +0000695 if (ret == RMAP_DENYMATCH)
696 {
697 /* Free newly generated AS path and community by route-map. */
698 bgp_attr_flush (attr);
699 return RMAP_DENY;
700 }
701 }
702 return RMAP_PERMIT;
703}
704
paul94f2b392005-06-28 12:44:16 +0000705static int
paulfee0f4c2004-09-13 05:12:46 +0000706bgp_export_modifier (struct peer *rsclient, struct peer *peer,
707 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
708{
709 struct bgp_filter *filter;
710 struct bgp_info info;
711 route_map_result_t ret;
712
713 filter = &peer->filter[afi][safi];
714
715 /* Route map apply. */
716 if (ROUTE_MAP_EXPORT_NAME (filter))
717 {
718 /* Duplicate current value to new strucutre for modification. */
719 info.peer = rsclient;
720 info.attr = attr;
721
722 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
723
724 /* Apply BGP route map to the attribute. */
725 ret = route_map_apply (ROUTE_MAP_EXPORT (filter), p, RMAP_BGP, &info);
726
727 rsclient->rmap_type = 0;
728
729 if (ret == RMAP_DENYMATCH)
730 {
731 /* Free newly generated AS path and community by route-map. */
732 bgp_attr_flush (attr);
733 return RMAP_DENY;
734 }
735 }
736 return RMAP_PERMIT;
737}
738
paul94f2b392005-06-28 12:44:16 +0000739static int
paulfee0f4c2004-09-13 05:12:46 +0000740bgp_import_modifier (struct peer *rsclient, struct peer *peer,
741 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
742{
743 struct bgp_filter *filter;
744 struct bgp_info info;
745 route_map_result_t ret;
746
747 filter = &rsclient->filter[afi][safi];
748
749 /* Apply default weight value. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000750 if (peer->weight)
751 (bgp_attr_extra_get (attr))->weight = peer->weight;
paulfee0f4c2004-09-13 05:12:46 +0000752
753 /* Route map apply. */
754 if (ROUTE_MAP_IMPORT_NAME (filter))
755 {
756 /* Duplicate current value to new strucutre for modification. */
757 info.peer = peer;
758 info.attr = attr;
759
760 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_IMPORT);
761
762 /* Apply BGP route map to the attribute. */
763 ret = route_map_apply (ROUTE_MAP_IMPORT (filter), p, RMAP_BGP, &info);
764
765 peer->rmap_type = 0;
766
767 if (ret == RMAP_DENYMATCH)
768 {
769 /* Free newly generated AS path and community by route-map. */
770 bgp_attr_flush (attr);
771 return RMAP_DENY;
772 }
773 }
774 return RMAP_PERMIT;
775}
776
paul94f2b392005-06-28 12:44:16 +0000777static int
paul718e3742002-12-13 20:15:29 +0000778bgp_announce_check (struct bgp_info *ri, struct peer *peer, struct prefix *p,
779 struct attr *attr, afi_t afi, safi_t safi)
780{
781 int ret;
782 char buf[SU_ADDRSTRLEN];
783 struct bgp_filter *filter;
paul718e3742002-12-13 20:15:29 +0000784 struct peer *from;
785 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +0000786 int transparent;
787 int reflect;
788
789 from = ri->peer;
790 filter = &peer->filter[afi][safi];
791 bgp = peer->bgp;
792
Paul Jakma750e8142008-07-22 21:11:48 +0000793 if (DISABLE_BGP_ANNOUNCE)
794 return 0;
paul718e3742002-12-13 20:15:29 +0000795
paulfee0f4c2004-09-13 05:12:46 +0000796 /* Do not send announces to RS-clients from the 'normal' bgp_table. */
797 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
798 return 0;
799
paul718e3742002-12-13 20:15:29 +0000800 /* Do not send back route to sender. */
801 if (from == peer)
802 return 0;
803
paul35be31b2004-05-01 18:17:04 +0000804 /* If peer's id and route's nexthop are same. draft-ietf-idr-bgp4-23 5.1.3 */
805 if (p->family == AF_INET
806 && IPV4_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
807 return 0;
808#ifdef HAVE_IPV6
809 if (p->family == AF_INET6
810 && IPV6_ADDR_SAME(&peer->remote_id, &ri->attr->nexthop))
811 return 0;
812#endif
813
paul718e3742002-12-13 20:15:29 +0000814 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000815 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +0000816 if (! UNSUPPRESS_MAP_NAME (filter))
817 return 0;
818
819 /* Default route check. */
820 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
821 {
822 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
823 return 0;
824#ifdef HAVE_IPV6
825 else if (p->family == AF_INET6 && p->prefixlen == 0)
826 return 0;
827#endif /* HAVE_IPV6 */
828 }
829
paul286e1e72003-08-08 00:24:31 +0000830 /* Transparency check. */
831 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT)
832 && CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
833 transparent = 1;
834 else
835 transparent = 0;
836
paul718e3742002-12-13 20:15:29 +0000837 /* If community is not disabled check the no-export and local. */
paul286e1e72003-08-08 00:24:31 +0000838 if (! transparent && bgp_community_filter (peer, ri->attr))
paul718e3742002-12-13 20:15:29 +0000839 return 0;
840
841 /* If the attribute has originator-id and it is same as remote
842 peer's id. */
843 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
844 {
Paul Jakmafb982c22007-05-04 20:15:47 +0000845 if (IPV4_ADDR_SAME (&peer->remote_id, &ri->attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +0000846 {
847 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000848 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000849 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
850 peer->host,
851 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
852 p->prefixlen);
853 return 0;
854 }
855 }
856
857 /* ORF prefix-list filter check */
858 if (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
859 && (CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
860 || CHECK_FLAG (peer->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
861 if (peer->orf_plist[afi][safi])
862 {
863 if (prefix_list_apply (peer->orf_plist[afi][safi], p) == PREFIX_DENY)
864 return 0;
865 }
866
867 /* Output filter check. */
868 if (bgp_output_filter (peer, p, ri->attr, afi, safi) == FILTER_DENY)
869 {
870 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000871 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +0000872 "%s [Update:SEND] %s/%d is filtered",
873 peer->host,
874 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
875 p->prefixlen);
876 return 0;
877 }
878
879#ifdef BGP_SEND_ASPATH_CHECK
880 /* AS path loop check. */
881 if (aspath_loop_check (ri->attr->aspath, peer->as))
882 {
883 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000884 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400885 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000886 peer->host, peer->as);
887 return 0;
888 }
889#endif /* BGP_SEND_ASPATH_CHECK */
890
891 /* If we're a CONFED we need to loop check the CONFED ID too */
892 if (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION))
893 {
894 if (aspath_loop_check(ri->attr->aspath, bgp->confed_id))
895 {
896 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +0000897 zlog (peer->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +0400898 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paul718e3742002-12-13 20:15:29 +0000899 peer->host,
900 bgp->confed_id);
901 return 0;
902 }
903 }
904
905 /* Route-Reflect check. */
906 if (peer_sort (from) == BGP_PEER_IBGP && peer_sort (peer) == BGP_PEER_IBGP)
907 reflect = 1;
908 else
909 reflect = 0;
910
911 /* IBGP reflection check. */
912 if (reflect)
913 {
914 /* A route from a Client peer. */
915 if (CHECK_FLAG (from->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
916 {
917 /* Reflect to all the Non-Client peers and also to the
918 Client peers other than the originator. Originator check
919 is already done. So there is noting to do. */
920 /* no bgp client-to-client reflection check. */
921 if (bgp_flag_check (bgp, BGP_FLAG_NO_CLIENT_TO_CLIENT))
922 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
923 return 0;
924 }
925 else
926 {
927 /* A route from a Non-client peer. Reflect to all other
928 clients. */
929 if (! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
930 return 0;
931 }
932 }
Paul Jakma41367172007-08-06 15:24:51 +0000933
paul718e3742002-12-13 20:15:29 +0000934 /* For modify attribute, copy it to temporary structure. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000935 bgp_attr_dup (attr, ri->attr);
936
paul718e3742002-12-13 20:15:29 +0000937 /* If local-preference is not set. */
938 if ((peer_sort (peer) == BGP_PEER_IBGP
939 || peer_sort (peer) == BGP_PEER_CONFED)
940 && (! (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))))
941 {
942 attr->flag |= ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF);
943 attr->local_pref = bgp->default_local_pref;
944 }
945
paul718e3742002-12-13 20:15:29 +0000946 /* Remove MED if its an EBGP peer - will get overwritten by route-maps */
947 if (peer_sort (peer) == BGP_PEER_EBGP
948 && attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
949 {
950 if (ri->peer != bgp->peer_self && ! transparent
951 && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED))
952 attr->flag &= ~(ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC));
953 }
954
955 /* next-hop-set */
956 if (transparent || reflect
957 || (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_UNCHANGED)
958 && ((p->family == AF_INET && attr->nexthop.s_addr)
paul286e1e72003-08-08 00:24:31 +0000959#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000960 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000961 ! IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul286e1e72003-08-08 00:24:31 +0000962#endif /* HAVE_IPV6 */
963 )))
paul718e3742002-12-13 20:15:29 +0000964 {
965 /* NEXT-HOP Unchanged. */
966 }
967 else if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_NEXTHOP_SELF)
968 || (p->family == AF_INET && attr->nexthop.s_addr == 0)
969#ifdef HAVE_IPV6
paulfee0f4c2004-09-13 05:12:46 +0000970 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +0000971 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paul718e3742002-12-13 20:15:29 +0000972#endif /* HAVE_IPV6 */
973 || (peer_sort (peer) == BGP_PEER_EBGP
974 && bgp_multiaccess_check_v4 (attr->nexthop, peer->host) == 0))
975 {
976 /* Set IPv4 nexthop. */
977 if (p->family == AF_INET)
978 {
979 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +0000980 memcpy (&attr->extra->mp_nexthop_global_in, &peer->nexthop.v4,
981 IPV4_MAX_BYTELEN);
paul718e3742002-12-13 20:15:29 +0000982 else
983 memcpy (&attr->nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
984 }
985#ifdef HAVE_IPV6
986 /* Set IPv6 nexthop. */
987 if (p->family == AF_INET6)
988 {
989 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +0000990 memcpy (&attr->extra->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +0000991 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +0000992 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +0000993 }
994#endif /* HAVE_IPV6 */
995 }
996
997#ifdef HAVE_IPV6
998 if (p->family == AF_INET6)
999 {
paulfee0f4c2004-09-13 05:12:46 +00001000 /* Left nexthop_local unchanged if so configured. */
1001 if ( CHECK_FLAG (peer->af_flags[afi][safi],
1002 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1003 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001004 if ( IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_local) )
1005 attr->extra->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001006 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001007 attr->extra->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001008 }
1009
1010 /* Default nexthop_local treatment for non-RS-Clients */
1011 else
1012 {
paul718e3742002-12-13 20:15:29 +00001013 /* Link-local address should not be transit to different peer. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001014 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001015
1016 /* Set link-local address for shared network peer. */
1017 if (peer->shared_network
1018 && ! IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
1019 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001020 memcpy (&attr->extra->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00001021 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001022 attr->extra->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00001023 }
1024
1025 /* If bgpd act as BGP-4+ route-reflector, do not send link-local
1026 address.*/
1027 if (reflect)
Paul Jakmafb982c22007-05-04 20:15:47 +00001028 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001029
1030 /* If BGP-4+ link-local nexthop is not link-local nexthop. */
1031 if (! IN6_IS_ADDR_LINKLOCAL (&peer->nexthop.v6_local))
Paul Jakmafb982c22007-05-04 20:15:47 +00001032 attr->extra->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00001033 }
paulfee0f4c2004-09-13 05:12:46 +00001034
1035 }
paul718e3742002-12-13 20:15:29 +00001036#endif /* HAVE_IPV6 */
1037
1038 /* If this is EBGP peer and remove-private-AS is set. */
1039 if (peer_sort (peer) == BGP_PEER_EBGP
1040 && peer_af_flag_check (peer, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1041 && aspath_private_as_check (attr->aspath))
1042 attr->aspath = aspath_empty_get ();
1043
1044 /* Route map & unsuppress-map apply. */
1045 if (ROUTE_MAP_OUT_NAME (filter)
Paul Jakmafb982c22007-05-04 20:15:47 +00001046 || (ri->extra && ri->extra->suppress) )
paul718e3742002-12-13 20:15:29 +00001047 {
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001048 struct bgp_info info;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001049 struct attr dummy_attr = { 0 };
Paul Jakma7c7fa1b2006-02-18 10:52:09 +00001050
paul718e3742002-12-13 20:15:29 +00001051 info.peer = peer;
1052 info.attr = attr;
1053
1054 /* The route reflector is not allowed to modify the attributes
1055 of the reflected IBGP routes. */
1056 if (peer_sort (from) == BGP_PEER_IBGP
1057 && peer_sort (peer) == BGP_PEER_IBGP)
1058 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001059 bgp_attr_dup (&dummy_attr, attr);
Paul Jakma9eda90c2007-08-30 13:36:17 +00001060 info.attr = &dummy_attr;
paul718e3742002-12-13 20:15:29 +00001061 }
paulac41b2a2003-08-12 05:32:27 +00001062
1063 SET_FLAG (peer->rmap_type, PEER_RMAP_TYPE_OUT);
1064
Paul Jakmafb982c22007-05-04 20:15:47 +00001065 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00001066 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1067 else
1068 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1069
paulac41b2a2003-08-12 05:32:27 +00001070 peer->rmap_type = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00001071
Paul Jakma9eda90c2007-08-30 13:36:17 +00001072 if (dummy_attr.extra)
1073 bgp_attr_extra_free (&dummy_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001074
paul718e3742002-12-13 20:15:29 +00001075 if (ret == RMAP_DENYMATCH)
1076 {
1077 bgp_attr_flush (attr);
1078 return 0;
1079 }
1080 }
1081 return 1;
1082}
1083
paul94f2b392005-06-28 12:44:16 +00001084static int
paulfee0f4c2004-09-13 05:12:46 +00001085bgp_announce_check_rsclient (struct bgp_info *ri, struct peer *rsclient,
1086 struct prefix *p, struct attr *attr, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001087{
paulfee0f4c2004-09-13 05:12:46 +00001088 int ret;
1089 char buf[SU_ADDRSTRLEN];
1090 struct bgp_filter *filter;
1091 struct bgp_info info;
1092 struct peer *from;
1093 struct bgp *bgp;
1094
1095 from = ri->peer;
1096 filter = &rsclient->filter[afi][safi];
1097 bgp = rsclient->bgp;
1098
Paul Jakma750e8142008-07-22 21:11:48 +00001099 if (DISABLE_BGP_ANNOUNCE)
1100 return 0;
paulfee0f4c2004-09-13 05:12:46 +00001101
1102 /* Do not send back route to sender. */
1103 if (from == rsclient)
1104 return 0;
1105
1106 /* Aggregate-address suppress check. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001107 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001108 if (! UNSUPPRESS_MAP_NAME (filter))
1109 return 0;
1110
1111 /* Default route check. */
1112 if (CHECK_FLAG (rsclient->af_sflags[afi][safi],
1113 PEER_STATUS_DEFAULT_ORIGINATE))
1114 {
1115 if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY)
1116 return 0;
1117#ifdef HAVE_IPV6
1118 else if (p->family == AF_INET6 && p->prefixlen == 0)
1119 return 0;
1120#endif /* HAVE_IPV6 */
1121 }
1122
1123 /* If the attribute has originator-id and it is same as remote
1124 peer's id. */
1125 if (ri->attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID))
1126 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001127 if (IPV4_ADDR_SAME (&rsclient->remote_id,
1128 &ri->attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001129 {
1130 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001131 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001132 "%s [Update:SEND] %s/%d originator-id is same as remote router-id",
1133 rsclient->host,
1134 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1135 p->prefixlen);
1136 return 0;
1137 }
1138 }
1139
1140 /* ORF prefix-list filter check */
1141 if (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_RM_ADV)
1142 && (CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_RCV)
1143 || CHECK_FLAG (rsclient->af_cap[afi][safi], PEER_CAP_ORF_PREFIX_SM_OLD_RCV)))
1144 if (rsclient->orf_plist[afi][safi])
1145 {
1146 if (prefix_list_apply (rsclient->orf_plist[afi][safi], p) == PREFIX_DENY)
1147 return 0;
1148 }
1149
1150 /* Output filter check. */
1151 if (bgp_output_filter (rsclient, p, ri->attr, afi, safi) == FILTER_DENY)
1152 {
1153 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001154 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001155 "%s [Update:SEND] %s/%d is filtered",
1156 rsclient->host,
1157 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1158 p->prefixlen);
1159 return 0;
1160 }
1161
1162#ifdef BGP_SEND_ASPATH_CHECK
1163 /* AS path loop check. */
1164 if (aspath_loop_check (ri->attr->aspath, rsclient->as))
1165 {
1166 if (BGP_DEBUG (filter, FILTER))
ajsd2c1f162004-12-08 21:10:20 +00001167 zlog (rsclient->log, LOG_DEBUG,
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04001168 "%s [Update:SEND] suppress announcement to peer AS %u is AS path.",
paulfee0f4c2004-09-13 05:12:46 +00001169 rsclient->host, rsclient->as);
1170 return 0;
1171 }
1172#endif /* BGP_SEND_ASPATH_CHECK */
1173
1174 /* For modify attribute, copy it to temporary structure. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001175 bgp_attr_dup (attr, ri->attr);
paulfee0f4c2004-09-13 05:12:46 +00001176
1177 /* next-hop-set */
1178 if ((p->family == AF_INET && attr->nexthop.s_addr == 0)
1179#ifdef HAVE_IPV6
1180 || (p->family == AF_INET6 &&
Paul Jakmafb982c22007-05-04 20:15:47 +00001181 IN6_IS_ADDR_UNSPECIFIED(&attr->extra->mp_nexthop_global))
paulfee0f4c2004-09-13 05:12:46 +00001182#endif /* HAVE_IPV6 */
1183 )
1184 {
1185 /* Set IPv4 nexthop. */
1186 if (p->family == AF_INET)
1187 {
1188 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001189 memcpy (&attr->extra->mp_nexthop_global_in, &rsclient->nexthop.v4,
paulfee0f4c2004-09-13 05:12:46 +00001190 IPV4_MAX_BYTELEN);
1191 else
1192 memcpy (&attr->nexthop, &rsclient->nexthop.v4, IPV4_MAX_BYTELEN);
1193 }
1194#ifdef HAVE_IPV6
1195 /* Set IPv6 nexthop. */
1196 if (p->family == AF_INET6)
1197 {
1198 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001199 memcpy (&attr->extra->mp_nexthop_global, &rsclient->nexthop.v6_global,
paulfee0f4c2004-09-13 05:12:46 +00001200 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001201 attr->extra->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001202 }
1203#endif /* HAVE_IPV6 */
1204 }
1205
1206#ifdef HAVE_IPV6
1207 if (p->family == AF_INET6)
1208 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001209 struct attr_extra *attre = attr->extra;
1210
1211 assert (attr->extra);
1212
paulfee0f4c2004-09-13 05:12:46 +00001213 /* Left nexthop_local unchanged if so configured. */
1214 if ( CHECK_FLAG (rsclient->af_flags[afi][safi],
1215 PEER_FLAG_NEXTHOP_LOCAL_UNCHANGED) )
1216 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001217 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1218 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001219 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001220 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001221 }
1222
1223 /* Default nexthop_local treatment for RS-Clients */
1224 else
1225 {
1226 /* Announcer and RS-Client are both in the same network */
1227 if (rsclient->shared_network && from->shared_network &&
1228 (rsclient->ifindex == from->ifindex))
1229 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001230 if ( IN6_IS_ADDR_LINKLOCAL (&attre->mp_nexthop_local) )
1231 attre->mp_nexthop_len=32;
paulfee0f4c2004-09-13 05:12:46 +00001232 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001233 attre->mp_nexthop_len=16;
paulfee0f4c2004-09-13 05:12:46 +00001234 }
1235
1236 /* Set link-local address for shared network peer. */
1237 else if (rsclient->shared_network
1238 && IN6_IS_ADDR_LINKLOCAL (&rsclient->nexthop.v6_local))
1239 {
Paul Jakmafb982c22007-05-04 20:15:47 +00001240 memcpy (&attre->mp_nexthop_local, &rsclient->nexthop.v6_local,
paulfee0f4c2004-09-13 05:12:46 +00001241 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00001242 attre->mp_nexthop_len = 32;
paulfee0f4c2004-09-13 05:12:46 +00001243 }
1244
1245 else
Paul Jakmafb982c22007-05-04 20:15:47 +00001246 attre->mp_nexthop_len = 16;
paulfee0f4c2004-09-13 05:12:46 +00001247 }
1248
1249 }
1250#endif /* HAVE_IPV6 */
1251
1252
1253 /* If this is EBGP peer and remove-private-AS is set. */
1254 if (peer_sort (rsclient) == BGP_PEER_EBGP
1255 && peer_af_flag_check (rsclient, afi, safi, PEER_FLAG_REMOVE_PRIVATE_AS)
1256 && aspath_private_as_check (attr->aspath))
1257 attr->aspath = aspath_empty_get ();
1258
1259 /* Route map & unsuppress-map apply. */
Paul Jakmafb982c22007-05-04 20:15:47 +00001260 if (ROUTE_MAP_OUT_NAME (filter) || (ri->extra && ri->extra->suppress) )
paulfee0f4c2004-09-13 05:12:46 +00001261 {
1262 info.peer = rsclient;
1263 info.attr = attr;
1264
1265 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_OUT);
1266
Paul Jakmafb982c22007-05-04 20:15:47 +00001267 if (ri->extra && ri->extra->suppress)
paulfee0f4c2004-09-13 05:12:46 +00001268 ret = route_map_apply (UNSUPPRESS_MAP (filter), p, RMAP_BGP, &info);
1269 else
1270 ret = route_map_apply (ROUTE_MAP_OUT (filter), p, RMAP_BGP, &info);
1271
1272 rsclient->rmap_type = 0;
1273
1274 if (ret == RMAP_DENYMATCH)
1275 {
1276 bgp_attr_flush (attr);
1277 return 0;
1278 }
1279 }
1280
1281 return 1;
1282}
1283
1284struct bgp_info_pair
1285{
1286 struct bgp_info *old;
1287 struct bgp_info *new;
1288};
1289
paul94f2b392005-06-28 12:44:16 +00001290static void
Josh Bailey96450fa2011-07-20 20:45:12 -07001291bgp_best_selection (struct bgp *bgp, struct bgp_node *rn,
1292 struct bgp_maxpaths_cfg *mpath_cfg,
1293 struct bgp_info_pair *result)
paulfee0f4c2004-09-13 05:12:46 +00001294{
paul718e3742002-12-13 20:15:29 +00001295 struct bgp_info *new_select;
1296 struct bgp_info *old_select;
paulfee0f4c2004-09-13 05:12:46 +00001297 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00001298 struct bgp_info *ri1;
1299 struct bgp_info *ri2;
paulb40d9392005-08-22 22:34:41 +00001300 struct bgp_info *nextri = NULL;
Josh Bailey96450fa2011-07-20 20:45:12 -07001301 int paths_eq, do_mpath;
1302 struct list mp_list;
1303
1304 bgp_mp_list_init (&mp_list);
1305 do_mpath = (mpath_cfg->maxpaths_ebgp != BGP_DEFAULT_MAXPATHS ||
1306 mpath_cfg->maxpaths_ibgp != BGP_DEFAULT_MAXPATHS);
1307
paul718e3742002-12-13 20:15:29 +00001308 /* bgp deterministic-med */
1309 new_select = NULL;
1310 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1311 for (ri1 = rn->info; ri1; ri1 = ri1->next)
1312 {
1313 if (CHECK_FLAG (ri1->flags, BGP_INFO_DMED_CHECK))
1314 continue;
1315 if (BGP_INFO_HOLDDOWN (ri1))
1316 continue;
1317
1318 new_select = ri1;
Josh Bailey6918e742011-07-20 20:48:20 -07001319 if (do_mpath)
1320 bgp_mp_list_add (&mp_list, ri1);
1321 old_select = CHECK_FLAG (ri1->flags, BGP_INFO_SELECTED) ? ri1 : NULL;
paul718e3742002-12-13 20:15:29 +00001322 if (ri1->next)
1323 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1324 {
1325 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1326 continue;
1327 if (BGP_INFO_HOLDDOWN (ri2))
1328 continue;
1329
1330 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1331 || aspath_cmp_left_confed (ri1->attr->aspath,
1332 ri2->attr->aspath))
1333 {
Josh Bailey6918e742011-07-20 20:48:20 -07001334 if (CHECK_FLAG (ri2->flags, BGP_INFO_SELECTED))
1335 old_select = ri2;
Josh Bailey96450fa2011-07-20 20:45:12 -07001336 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001337 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001338 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001339 new_select = ri2;
Josh Bailey6918e742011-07-20 20:48:20 -07001340 if (do_mpath && !paths_eq)
1341 {
1342 bgp_mp_list_clear (&mp_list);
1343 bgp_mp_list_add (&mp_list, ri2);
1344 }
paul718e3742002-12-13 20:15:29 +00001345 }
1346
Josh Bailey6918e742011-07-20 20:48:20 -07001347 if (do_mpath && paths_eq)
1348 bgp_mp_list_add (&mp_list, ri2);
1349
Paul Jakma1a392d42006-09-07 00:24:49 +00001350 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001351 }
1352 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001353 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1354 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
Josh Bailey6918e742011-07-20 20:48:20 -07001355
1356 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
1357 bgp_mp_list_clear (&mp_list);
paul718e3742002-12-13 20:15:29 +00001358 }
1359
1360 /* Check old selected route and new selected route. */
1361 old_select = NULL;
1362 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001363 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001364 {
1365 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1366 old_select = ri;
1367
1368 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001369 {
1370 /* reap REMOVED routes, if needs be
1371 * selected route must stay for a while longer though
1372 */
1373 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1374 && (ri != old_select))
1375 bgp_info_reap (rn, ri);
1376
1377 continue;
1378 }
paul718e3742002-12-13 20:15:29 +00001379
1380 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1381 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1382 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001383 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001384 continue;
1385 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001386 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1387 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001388
Josh Bailey96450fa2011-07-20 20:45:12 -07001389 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1390 {
Josh Bailey6918e742011-07-20 20:48:20 -07001391 if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1392 bgp_mp_dmed_deselect (new_select);
1393
Josh Bailey96450fa2011-07-20 20:45:12 -07001394 new_select = ri;
1395
1396 if (do_mpath && !paths_eq)
1397 {
1398 bgp_mp_list_clear (&mp_list);
1399 bgp_mp_list_add (&mp_list, ri);
1400 }
1401 }
Josh Bailey6918e742011-07-20 20:48:20 -07001402 else if (do_mpath && bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1403 bgp_mp_dmed_deselect (ri);
Josh Bailey96450fa2011-07-20 20:45:12 -07001404
1405 if (do_mpath && paths_eq)
1406 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001407 }
paulb40d9392005-08-22 22:34:41 +00001408
paulfee0f4c2004-09-13 05:12:46 +00001409
Josh Bailey6918e742011-07-20 20:48:20 -07001410 if (!bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED))
1411 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001412
1413 bgp_mp_list_clear (&mp_list);
1414
1415 result->old = old_select;
1416 result->new = new_select;
1417
1418 return;
paulfee0f4c2004-09-13 05:12:46 +00001419}
1420
paul94f2b392005-06-28 12:44:16 +00001421static int
paulfee0f4c2004-09-13 05:12:46 +00001422bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001423 struct bgp_node *rn, afi_t afi, safi_t safi)
1424{
paulfee0f4c2004-09-13 05:12:46 +00001425 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001426 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001427
1428 p = &rn->p;
1429
Paul Jakma9eda90c2007-08-30 13:36:17 +00001430 /* Announce route to Established peer. */
1431 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001432 return 0;
1433
Paul Jakma9eda90c2007-08-30 13:36:17 +00001434 /* Address family configuration check. */
1435 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001436 return 0;
1437
Paul Jakma9eda90c2007-08-30 13:36:17 +00001438 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001439 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1440 PEER_STATUS_ORF_WAIT_REFRESH))
1441 return 0;
1442
1443 switch (rn->table->type)
1444 {
1445 case BGP_TABLE_MAIN:
1446 /* Announcement to peer->conf. If the route is filtered,
1447 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001448 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1449 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001450 else
1451 bgp_adj_out_unset (rn, peer, p, afi, safi);
1452 break;
1453 case BGP_TABLE_RSCLIENT:
1454 /* Announcement to peer->conf. If the route is filtered,
1455 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001456 if (selected &&
1457 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1458 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1459 else
1460 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001461 break;
1462 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001463
1464 bgp_attr_extra_free (&attr);
1465
paulfee0f4c2004-09-13 05:12:46 +00001466 return 0;
paul200df112005-06-01 11:17:05 +00001467}
paulfee0f4c2004-09-13 05:12:46 +00001468
paul200df112005-06-01 11:17:05 +00001469struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001470{
paul200df112005-06-01 11:17:05 +00001471 struct bgp *bgp;
1472 struct bgp_node *rn;
1473 afi_t afi;
1474 safi_t safi;
1475};
1476
1477static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001478bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001479{
paul0fb58d52005-11-14 14:31:49 +00001480 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001481 struct bgp *bgp = pq->bgp;
1482 struct bgp_node *rn = pq->rn;
1483 afi_t afi = pq->afi;
1484 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001485 struct bgp_info *new_select;
1486 struct bgp_info *old_select;
1487 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001488 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001489 struct peer *rsclient = rn->table->owner;
1490
paulfee0f4c2004-09-13 05:12:46 +00001491 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001492 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001493 new_select = old_and_new.new;
1494 old_select = old_and_new.old;
1495
paul200df112005-06-01 11:17:05 +00001496 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1497 {
Chris Caputo228da422009-07-18 05:44:03 +00001498 if (rsclient->group)
1499 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1500 {
1501 /* Nothing to do. */
1502 if (old_select && old_select == new_select)
1503 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1504 continue;
paulfee0f4c2004-09-13 05:12:46 +00001505
Chris Caputo228da422009-07-18 05:44:03 +00001506 if (old_select)
1507 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1508 if (new_select)
1509 {
1510 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1511 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001512 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1513 }
paulfee0f4c2004-09-13 05:12:46 +00001514
Chris Caputo228da422009-07-18 05:44:03 +00001515 bgp_process_announce_selected (rsclient, new_select, rn,
1516 afi, safi);
1517 }
paul200df112005-06-01 11:17:05 +00001518 }
1519 else
1520 {
hassob7395792005-08-26 12:58:38 +00001521 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001522 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001523 if (new_select)
1524 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001525 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1526 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001527 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001528 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001529 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001530 }
paulfee0f4c2004-09-13 05:12:46 +00001531
paulb40d9392005-08-22 22:34:41 +00001532 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1533 bgp_info_reap (rn, old_select);
1534
paul200df112005-06-01 11:17:05 +00001535 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1536 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001537}
1538
paul200df112005-06-01 11:17:05 +00001539static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001540bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001541{
paul0fb58d52005-11-14 14:31:49 +00001542 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001543 struct bgp *bgp = pq->bgp;
1544 struct bgp_node *rn = pq->rn;
1545 afi_t afi = pq->afi;
1546 safi_t safi = pq->safi;
1547 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001548 struct bgp_info *new_select;
1549 struct bgp_info *old_select;
1550 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001551 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001552 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001553
paulfee0f4c2004-09-13 05:12:46 +00001554 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001555 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001556 old_select = old_and_new.old;
1557 new_select = old_and_new.new;
1558
1559 /* Nothing to do. */
1560 if (old_select && old_select == new_select)
1561 {
1562 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001563 {
Josh Bailey8196f132011-07-20 20:47:07 -07001564 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1565 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
paul200df112005-06-01 11:17:05 +00001566 bgp_zebra_announce (p, old_select, bgp);
1567
Josh Bailey8196f132011-07-20 20:47:07 -07001568 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001569 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1570 return WQ_SUCCESS;
1571 }
paulfee0f4c2004-09-13 05:12:46 +00001572 }
paul718e3742002-12-13 20:15:29 +00001573
hasso338b3422005-02-23 14:27:24 +00001574 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001575 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001576 if (new_select)
1577 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001578 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1579 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001580 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001581 }
1582
1583
paul718e3742002-12-13 20:15:29 +00001584 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001585 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001586 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001587 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001588 }
1589
1590 /* FIB update. */
1591 if (safi == SAFI_UNICAST && ! bgp->name &&
1592 ! bgp_option_check (BGP_OPT_NO_FIB))
1593 {
1594 if (new_select
1595 && new_select->type == ZEBRA_ROUTE_BGP
1596 && new_select->sub_type == BGP_ROUTE_NORMAL)
1597 bgp_zebra_announce (p, new_select, bgp);
1598 else
1599 {
1600 /* Withdraw the route from the kernel. */
1601 if (old_select
1602 && old_select->type == ZEBRA_ROUTE_BGP
1603 && old_select->sub_type == BGP_ROUTE_NORMAL)
1604 bgp_zebra_withdraw (p, old_select);
1605 }
1606 }
paulb40d9392005-08-22 22:34:41 +00001607
1608 /* Reap old select bgp_info, it it has been removed */
1609 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1610 bgp_info_reap (rn, old_select);
1611
paul200df112005-06-01 11:17:05 +00001612 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1613 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001614}
1615
paul200df112005-06-01 11:17:05 +00001616static void
paul0fb58d52005-11-14 14:31:49 +00001617bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001618{
paul0fb58d52005-11-14 14:31:49 +00001619 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001620 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001621
Chris Caputo228da422009-07-18 05:44:03 +00001622 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001623 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001624 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001625 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1626}
1627
1628static void
1629bgp_process_queue_init (void)
1630{
1631 bm->process_main_queue
1632 = work_queue_new (bm->master, "process_main_queue");
1633 bm->process_rsclient_queue
1634 = work_queue_new (bm->master, "process_rsclient_queue");
1635
1636 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1637 {
1638 zlog_err ("%s: Failed to allocate work queue", __func__);
1639 exit (1);
1640 }
1641
1642 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001643 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001644 bm->process_main_queue->spec.max_retries = 0;
1645 bm->process_main_queue->spec.hold = 50;
1646
1647 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1648 sizeof (struct work_queue *));
1649 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001650}
1651
1652void
paulfee0f4c2004-09-13 05:12:46 +00001653bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1654{
paul200df112005-06-01 11:17:05 +00001655 struct bgp_process_queue *pqnode;
1656
1657 /* already scheduled for processing? */
1658 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1659 return;
1660
1661 if ( (bm->process_main_queue == NULL) ||
1662 (bm->process_rsclient_queue == NULL) )
1663 bgp_process_queue_init ();
1664
1665 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1666 sizeof (struct bgp_process_queue));
1667 if (!pqnode)
1668 return;
Chris Caputo228da422009-07-18 05:44:03 +00001669
1670 /* all unlocked in bgp_processq_del */
1671 bgp_table_lock (rn->table);
1672 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001673 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001674 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001675 pqnode->afi = afi;
1676 pqnode->safi = safi;
1677
paulfee0f4c2004-09-13 05:12:46 +00001678 switch (rn->table->type)
1679 {
paul200df112005-06-01 11:17:05 +00001680 case BGP_TABLE_MAIN:
1681 work_queue_add (bm->process_main_queue, pqnode);
1682 break;
1683 case BGP_TABLE_RSCLIENT:
1684 work_queue_add (bm->process_rsclient_queue, pqnode);
1685 break;
paulfee0f4c2004-09-13 05:12:46 +00001686 }
paul200df112005-06-01 11:17:05 +00001687
1688 return;
paulfee0f4c2004-09-13 05:12:46 +00001689}
hasso0a486e52005-02-01 20:57:17 +00001690
paul94f2b392005-06-28 12:44:16 +00001691static int
hasso0a486e52005-02-01 20:57:17 +00001692bgp_maximum_prefix_restart_timer (struct thread *thread)
1693{
1694 struct peer *peer;
1695
1696 peer = THREAD_ARG (thread);
1697 peer->t_pmax_restart = NULL;
1698
1699 if (BGP_DEBUG (events, EVENTS))
1700 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1701 peer->host);
1702
1703 peer_clear (peer);
1704
1705 return 0;
1706}
1707
paulfee0f4c2004-09-13 05:12:46 +00001708int
paul5228ad22004-06-04 17:58:18 +00001709bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1710 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001711{
hassoe0701b72004-05-20 09:19:34 +00001712 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1713 return 0;
1714
1715 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001716 {
hassoe0701b72004-05-20 09:19:34 +00001717 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1718 && ! always)
1719 return 0;
paul718e3742002-12-13 20:15:29 +00001720
hassoe0701b72004-05-20 09:19:34 +00001721 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001722 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1723 "limit %ld", afi_safi_print (afi, safi), peer->host,
1724 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001725 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001726
hassoe0701b72004-05-20 09:19:34 +00001727 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1728 return 0;
paul718e3742002-12-13 20:15:29 +00001729
hassoe0701b72004-05-20 09:19:34 +00001730 {
paul5228ad22004-06-04 17:58:18 +00001731 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001732
1733 if (safi == SAFI_MPLS_VPN)
1734 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001735
1736 ndata[0] = (afi >> 8);
1737 ndata[1] = afi;
1738 ndata[2] = safi;
1739 ndata[3] = (peer->pmax[afi][safi] >> 24);
1740 ndata[4] = (peer->pmax[afi][safi] >> 16);
1741 ndata[5] = (peer->pmax[afi][safi] >> 8);
1742 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001743
1744 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1745 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1746 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1747 }
hasso0a486e52005-02-01 20:57:17 +00001748
1749 /* restart timer start */
1750 if (peer->pmax_restart[afi][safi])
1751 {
1752 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1753
1754 if (BGP_DEBUG (events, EVENTS))
1755 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1756 peer->host, peer->v_pmax_restart);
1757
1758 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1759 peer->v_pmax_restart);
1760 }
1761
hassoe0701b72004-05-20 09:19:34 +00001762 return 1;
paul718e3742002-12-13 20:15:29 +00001763 }
hassoe0701b72004-05-20 09:19:34 +00001764 else
1765 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1766
1767 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1768 {
1769 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1770 && ! always)
1771 return 0;
1772
1773 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001774 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1775 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1776 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001777 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1778 }
1779 else
1780 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001781 return 0;
1782}
1783
paulb40d9392005-08-22 22:34:41 +00001784/* Unconditionally remove the route from the RIB, without taking
1785 * damping into consideration (eg, because the session went down)
1786 */
paul94f2b392005-06-28 12:44:16 +00001787static void
paul718e3742002-12-13 20:15:29 +00001788bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1789 afi_t afi, safi_t safi)
1790{
paul902212c2006-02-05 17:51:19 +00001791 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1792
1793 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1794 bgp_info_delete (rn, ri); /* keep historical info */
1795
paulb40d9392005-08-22 22:34:41 +00001796 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001797}
1798
paul94f2b392005-06-28 12:44:16 +00001799static void
paul718e3742002-12-13 20:15:29 +00001800bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001801 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001802{
paul718e3742002-12-13 20:15:29 +00001803 int status = BGP_DAMP_NONE;
1804
paulb40d9392005-08-22 22:34:41 +00001805 /* apply dampening, if result is suppressed, we'll be retaining
1806 * the bgp_info in the RIB for historical reference.
1807 */
1808 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1809 && peer_sort (peer) == BGP_PEER_EBGP)
1810 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1811 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001812 {
paul902212c2006-02-05 17:51:19 +00001813 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1814 return;
1815 }
1816
1817 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001818}
1819
paul94f2b392005-06-28 12:44:16 +00001820static void
paulfee0f4c2004-09-13 05:12:46 +00001821bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1822 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1823 int sub_type, struct prefix_rd *prd, u_char *tag)
1824{
1825 struct bgp_node *rn;
1826 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001827 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001828 struct attr *attr_new;
1829 struct attr *attr_new2;
1830 struct bgp_info *ri;
1831 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001832 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001833 char buf[SU_ADDRSTRLEN];
1834
1835 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1836 if (peer == rsclient)
1837 return;
1838
1839 bgp = peer->bgp;
1840 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1841
1842 /* Check previously received route. */
1843 for (ri = rn->info; ri; ri = ri->next)
1844 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1845 break;
1846
1847 /* AS path loop check. */
1848 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1849 {
1850 reason = "as-path contains our own AS;";
1851 goto filtered;
1852 }
1853
1854 /* Route reflector originator ID check. */
1855 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001856 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001857 {
1858 reason = "originator is us;";
1859 goto filtered;
1860 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001861
1862 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001863
1864 /* Apply export policy. */
1865 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1866 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1867 {
1868 reason = "export-policy;";
1869 goto filtered;
1870 }
1871
1872 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001873
paulfee0f4c2004-09-13 05:12:46 +00001874 /* Apply import policy. */
1875 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1876 {
1877 bgp_attr_unintern (attr_new2);
1878
1879 reason = "import-policy;";
1880 goto filtered;
1881 }
1882
1883 attr_new = bgp_attr_intern (&new_attr);
1884 bgp_attr_unintern (attr_new2);
1885
1886 /* IPv4 unicast next hop check. */
1887 if (afi == AFI_IP && safi == SAFI_UNICAST)
1888 {
1889 /* Next hop must not be 0.0.0.0 nor Class E address. */
1890 if (new_attr.nexthop.s_addr == 0
1891 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1892 {
1893 bgp_attr_unintern (attr_new);
1894
1895 reason = "martian next-hop;";
1896 goto filtered;
1897 }
1898 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001899
1900 /* new_attr isn't passed to any functions after here */
1901 bgp_attr_extra_free (&new_attr);
1902
paulfee0f4c2004-09-13 05:12:46 +00001903 /* If the update is implicit withdraw. */
1904 if (ri)
1905 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001906 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001907
1908 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001909 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1910 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001911 {
1912
Paul Jakma1a392d42006-09-07 00:24:49 +00001913 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001914
1915 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001916 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001917 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1918 peer->host,
1919 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1920 p->prefixlen, rsclient->host);
1921
Chris Caputo228da422009-07-18 05:44:03 +00001922 bgp_unlock_node (rn);
1923 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001924
Chris Caputo228da422009-07-18 05:44:03 +00001925 return;
paulfee0f4c2004-09-13 05:12:46 +00001926 }
1927
Paul Jakma16d2e242007-04-10 19:32:10 +00001928 /* Withdraw/Announce before we fully processed the withdraw */
1929 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1930 bgp_info_restore (rn, ri);
1931
paulfee0f4c2004-09-13 05:12:46 +00001932 /* Received Logging. */
1933 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001934 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001935 peer->host,
1936 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1937 p->prefixlen, rsclient->host);
1938
1939 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001940 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001941
1942 /* Update to new attribute. */
1943 bgp_attr_unintern (ri->attr);
1944 ri->attr = attr_new;
1945
1946 /* Update MPLS tag. */
1947 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001948 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001949
Paul Jakma1a392d42006-09-07 00:24:49 +00001950 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001951
1952 /* Process change. */
1953 bgp_process (bgp, rn, afi, safi);
1954 bgp_unlock_node (rn);
1955
1956 return;
1957 }
1958
1959 /* Received Logging. */
1960 if (BGP_DEBUG (update, UPDATE_IN))
1961 {
ajsd2c1f162004-12-08 21:10:20 +00001962 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001963 peer->host,
1964 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1965 p->prefixlen, rsclient->host);
1966 }
1967
1968 /* Make new BGP info. */
1969 new = bgp_info_new ();
1970 new->type = type;
1971 new->sub_type = sub_type;
1972 new->peer = peer;
1973 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001974 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001975
1976 /* Update MPLS tag. */
1977 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001978 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001979
Paul Jakma1a392d42006-09-07 00:24:49 +00001980 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001981
1982 /* Register new BGP information. */
1983 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001984
1985 /* route_node_get lock */
1986 bgp_unlock_node (rn);
1987
paulfee0f4c2004-09-13 05:12:46 +00001988 /* Process change. */
1989 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001990
1991 bgp_attr_extra_free (&new_attr);
1992
paulfee0f4c2004-09-13 05:12:46 +00001993 return;
1994
1995 filtered:
1996
1997 /* This BGP update is filtered. Log the reason then update BGP entry. */
1998 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001999 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002000 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
2001 peer->host,
2002 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2003 p->prefixlen, rsclient->host, reason);
2004
2005 if (ri)
paulb40d9392005-08-22 22:34:41 +00002006 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002007
2008 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002009
2010 if (new_attr.extra)
2011 bgp_attr_extra_free (&new_attr);
2012
paulfee0f4c2004-09-13 05:12:46 +00002013 return;
2014}
2015
paul94f2b392005-06-28 12:44:16 +00002016static void
paulfee0f4c2004-09-13 05:12:46 +00002017bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
2018 struct peer *peer, struct prefix *p, int type, int sub_type,
2019 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00002020{
paulfee0f4c2004-09-13 05:12:46 +00002021 struct bgp_node *rn;
2022 struct bgp_info *ri;
2023 char buf[SU_ADDRSTRLEN];
2024
2025 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002026 return;
paulfee0f4c2004-09-13 05:12:46 +00002027
2028 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2029
2030 /* Lookup withdrawn route. */
2031 for (ri = rn->info; ri; ri = ri->next)
2032 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2033 break;
2034
2035 /* Withdraw specified route from routing table. */
2036 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002037 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002038 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002039 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002040 "%s Can't find the route %s/%d", peer->host,
2041 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2042 p->prefixlen);
2043
2044 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002045 bgp_unlock_node (rn);
2046}
paulfee0f4c2004-09-13 05:12:46 +00002047
paul94f2b392005-06-28 12:44:16 +00002048static int
paulfee0f4c2004-09-13 05:12:46 +00002049bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002050 afi_t afi, safi_t safi, int type, int sub_type,
2051 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2052{
2053 int ret;
2054 int aspath_loop_count = 0;
2055 struct bgp_node *rn;
2056 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002057 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002058 struct attr *attr_new;
2059 struct bgp_info *ri;
2060 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002061 const char *reason;
paul718e3742002-12-13 20:15:29 +00002062 char buf[SU_ADDRSTRLEN];
2063
2064 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002065 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002066
paul718e3742002-12-13 20:15:29 +00002067 /* When peer's soft reconfiguration enabled. Record input packet in
2068 Adj-RIBs-In. */
2069 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2070 && peer != bgp->peer_self && ! soft_reconfig)
2071 bgp_adj_in_set (rn, peer, attr);
2072
2073 /* Check previously received route. */
2074 for (ri = rn->info; ri; ri = ri->next)
2075 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2076 break;
2077
2078 /* AS path local-as loop check. */
2079 if (peer->change_local_as)
2080 {
2081 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2082 aspath_loop_count = 1;
2083
2084 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2085 {
2086 reason = "as-path contains our own AS;";
2087 goto filtered;
2088 }
2089 }
2090
2091 /* AS path loop check. */
2092 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2093 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2094 && aspath_loop_check(attr->aspath, bgp->confed_id)
2095 > peer->allowas_in[afi][safi]))
2096 {
2097 reason = "as-path contains our own AS;";
2098 goto filtered;
2099 }
2100
2101 /* Route reflector originator ID check. */
2102 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002103 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002104 {
2105 reason = "originator is us;";
2106 goto filtered;
2107 }
2108
2109 /* Route reflector cluster ID check. */
2110 if (bgp_cluster_filter (peer, attr))
2111 {
2112 reason = "reflected from the same cluster;";
2113 goto filtered;
2114 }
2115
2116 /* Apply incoming filter. */
2117 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2118 {
2119 reason = "filter;";
2120 goto filtered;
2121 }
2122
2123 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002124 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002125
2126 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2127 {
2128 reason = "route-map;";
2129 goto filtered;
2130 }
2131
2132 /* IPv4 unicast next hop check. */
2133 if (afi == AFI_IP && safi == SAFI_UNICAST)
2134 {
2135 /* If the peer is EBGP and nexthop is not on connected route,
2136 discard it. */
2137 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2138 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002139 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002140 {
2141 reason = "non-connected next-hop;";
2142 goto filtered;
2143 }
2144
2145 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2146 must not be my own address. */
2147 if (bgp_nexthop_self (afi, &new_attr)
2148 || new_attr.nexthop.s_addr == 0
2149 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2150 {
2151 reason = "martian next-hop;";
2152 goto filtered;
2153 }
2154 }
2155
2156 attr_new = bgp_attr_intern (&new_attr);
2157
2158 /* If the update is implicit withdraw. */
2159 if (ri)
2160 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002161 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002162
2163 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002164 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2165 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002166 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002167 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002168
2169 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2170 && peer_sort (peer) == BGP_PEER_EBGP
2171 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2172 {
2173 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002174 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002175 peer->host,
2176 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2177 p->prefixlen);
2178
paul902212c2006-02-05 17:51:19 +00002179 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2180 {
2181 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2182 bgp_process (bgp, rn, afi, safi);
2183 }
paul718e3742002-12-13 20:15:29 +00002184 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002185 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002186 {
2187 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002188 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002189 "%s rcvd %s/%d...duplicate ignored",
2190 peer->host,
2191 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2192 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002193
2194 /* graceful restart STALE flag unset. */
2195 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2196 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002197 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002198 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002199 }
paul718e3742002-12-13 20:15:29 +00002200 }
2201
2202 bgp_unlock_node (rn);
2203 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002204 bgp_attr_extra_free (&new_attr);
2205
paul718e3742002-12-13 20:15:29 +00002206 return 0;
2207 }
2208
Paul Jakma16d2e242007-04-10 19:32:10 +00002209 /* Withdraw/Announce before we fully processed the withdraw */
2210 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2211 {
2212 if (BGP_DEBUG (update, UPDATE_IN))
2213 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2214 peer->host,
2215 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2216 p->prefixlen);
2217 bgp_info_restore (rn, ri);
2218 }
2219
paul718e3742002-12-13 20:15:29 +00002220 /* Received Logging. */
2221 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002222 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002223 peer->host,
2224 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2225 p->prefixlen);
2226
hasso93406d82005-02-02 14:40:33 +00002227 /* graceful restart STALE flag unset. */
2228 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002229 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002230
paul718e3742002-12-13 20:15:29 +00002231 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002232 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002233
2234 /* implicit withdraw, decrement aggregate and pcount here.
2235 * only if update is accepted, they'll increment below.
2236 */
paul902212c2006-02-05 17:51:19 +00002237 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2238
paul718e3742002-12-13 20:15:29 +00002239 /* Update bgp route dampening information. */
2240 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2241 && peer_sort (peer) == BGP_PEER_EBGP)
2242 {
2243 /* This is implicit withdraw so we should update dampening
2244 information. */
2245 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2246 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002247 }
2248
paul718e3742002-12-13 20:15:29 +00002249 /* Update to new attribute. */
2250 bgp_attr_unintern (ri->attr);
2251 ri->attr = attr_new;
2252
2253 /* Update MPLS tag. */
2254 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002255 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002256
2257 /* Update bgp route dampening information. */
2258 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2259 && peer_sort (peer) == BGP_PEER_EBGP)
2260 {
2261 /* Now we do normal update dampening. */
2262 ret = bgp_damp_update (ri, rn, afi, safi);
2263 if (ret == BGP_DAMP_SUPPRESSED)
2264 {
2265 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002266 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002267 return 0;
2268 }
2269 }
2270
2271 /* Nexthop reachability check. */
2272 if ((afi == AFI_IP || afi == AFI_IP6)
2273 && safi == SAFI_UNICAST
2274 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002275 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002276 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002277 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002278 {
2279 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002280 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002281 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002282 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002283 }
2284 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002285 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002286
2287 /* Process change. */
2288 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2289
2290 bgp_process (bgp, rn, afi, safi);
2291 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002292 bgp_attr_extra_free (&new_attr);
2293
paul718e3742002-12-13 20:15:29 +00002294 return 0;
2295 }
2296
2297 /* Received Logging. */
2298 if (BGP_DEBUG (update, UPDATE_IN))
2299 {
ajsd2c1f162004-12-08 21:10:20 +00002300 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002301 peer->host,
2302 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2303 p->prefixlen);
2304 }
2305
paul718e3742002-12-13 20:15:29 +00002306 /* Make new BGP info. */
2307 new = bgp_info_new ();
2308 new->type = type;
2309 new->sub_type = sub_type;
2310 new->peer = peer;
2311 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002312 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002313
2314 /* Update MPLS tag. */
2315 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002316 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002317
2318 /* Nexthop reachability check. */
2319 if ((afi == AFI_IP || afi == AFI_IP6)
2320 && safi == SAFI_UNICAST
2321 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002322 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002323 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002324 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002325 {
2326 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002327 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002328 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002329 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002330 }
2331 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002332 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002333
paul902212c2006-02-05 17:51:19 +00002334 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002335 bgp_aggregate_increment (bgp, p, new, afi, safi);
2336
2337 /* Register new BGP information. */
2338 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002339
2340 /* route_node_get lock */
2341 bgp_unlock_node (rn);
2342
Paul Jakmafb982c22007-05-04 20:15:47 +00002343 bgp_attr_extra_free (&new_attr);
2344
paul718e3742002-12-13 20:15:29 +00002345 /* If maximum prefix count is configured and current prefix
2346 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002347 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2348 return -1;
paul718e3742002-12-13 20:15:29 +00002349
2350 /* Process change. */
2351 bgp_process (bgp, rn, afi, safi);
2352
2353 return 0;
2354
2355 /* This BGP update is filtered. Log the reason then update BGP
2356 entry. */
2357 filtered:
2358 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002359 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002360 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2361 peer->host,
2362 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2363 p->prefixlen, reason);
2364
2365 if (ri)
paulb40d9392005-08-22 22:34:41 +00002366 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002367
2368 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002369
2370 bgp_attr_extra_free (&new_attr);
2371
paul718e3742002-12-13 20:15:29 +00002372 return 0;
2373}
2374
2375int
paulfee0f4c2004-09-13 05:12:46 +00002376bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2377 afi_t afi, safi_t safi, int type, int sub_type,
2378 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2379{
2380 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002381 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002382 struct bgp *bgp;
2383 int ret;
2384
2385 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2386 soft_reconfig);
2387
2388 bgp = peer->bgp;
2389
2390 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002391 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002392 {
2393 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2394 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2395 sub_type, prd, tag);
2396 }
2397
2398 return ret;
2399}
2400
2401int
paul718e3742002-12-13 20:15:29 +00002402bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002403 afi_t afi, safi_t safi, int type, int sub_type,
2404 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002405{
2406 struct bgp *bgp;
2407 char buf[SU_ADDRSTRLEN];
2408 struct bgp_node *rn;
2409 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002410 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002411 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002412
2413 bgp = peer->bgp;
2414
paulfee0f4c2004-09-13 05:12:46 +00002415 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002416 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002417 {
2418 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2419 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2420 }
2421
paul718e3742002-12-13 20:15:29 +00002422 /* Logging. */
2423 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002424 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002425 peer->host,
2426 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2427 p->prefixlen);
2428
2429 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002430 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002431
2432 /* If peer is soft reconfiguration enabled. Record input packet for
2433 further calculation. */
2434 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2435 && peer != bgp->peer_self)
2436 bgp_adj_in_unset (rn, peer);
2437
2438 /* Lookup withdrawn route. */
2439 for (ri = rn->info; ri; ri = ri->next)
2440 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2441 break;
2442
2443 /* Withdraw specified route from routing table. */
2444 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002445 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002446 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002447 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002448 "%s Can't find the route %s/%d", peer->host,
2449 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2450 p->prefixlen);
2451
2452 /* Unlock bgp_node_get() lock. */
2453 bgp_unlock_node (rn);
2454
2455 return 0;
2456}
2457
2458void
2459bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2460{
2461 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002462 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002463 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002464 struct prefix p;
2465 struct bgp_info binfo;
2466 struct peer *from;
2467 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002468
Paul Jakmab2497022007-06-14 11:17:58 +00002469 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002470 return;
2471
paul718e3742002-12-13 20:15:29 +00002472 bgp = peer->bgp;
2473 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002474
paul718e3742002-12-13 20:15:29 +00002475 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2476 aspath = attr.aspath;
2477 attr.local_pref = bgp->default_local_pref;
2478 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2479
2480 if (afi == AFI_IP)
2481 str2prefix ("0.0.0.0/0", &p);
2482#ifdef HAVE_IPV6
2483 else if (afi == AFI_IP6)
2484 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002485 struct attr_extra *ae;
2486 attr.extra = NULL;
2487
2488 ae = bgp_attr_extra_get (&attr);
2489 attr.extra = ae;
2490
paul718e3742002-12-13 20:15:29 +00002491 str2prefix ("::/0", &p);
2492
2493 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002494 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002495 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002496 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002497
2498 /* If the peer is on shared nextwork and we have link-local
2499 nexthop set it. */
2500 if (peer->shared_network
2501 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2502 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002503 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002504 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002505 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002506 }
2507 }
2508#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002509
2510 if (peer->default_rmap[afi][safi].name)
2511 {
2512 binfo.peer = bgp->peer_self;
2513 binfo.attr = &attr;
2514
paulfee0f4c2004-09-13 05:12:46 +00002515 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2516
paul718e3742002-12-13 20:15:29 +00002517 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2518 RMAP_BGP, &binfo);
2519
paulfee0f4c2004-09-13 05:12:46 +00002520 bgp->peer_self->rmap_type = 0;
2521
paul718e3742002-12-13 20:15:29 +00002522 if (ret == RMAP_DENYMATCH)
2523 {
2524 bgp_attr_flush (&attr);
2525 withdraw = 1;
2526 }
2527 }
2528
2529 if (withdraw)
2530 {
2531 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2532 bgp_default_withdraw_send (peer, afi, safi);
2533 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2534 }
2535 else
2536 {
2537 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2538 bgp_default_update_send (peer, &attr, afi, safi, from);
2539 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002540
2541 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002542 aspath_unintern (aspath);
2543}
2544
2545static void
2546bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002547 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002548{
2549 struct bgp_node *rn;
2550 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002551 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002552
paul718e3742002-12-13 20:15:29 +00002553 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002554 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002555
2556 if (safi != SAFI_MPLS_VPN
2557 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2558 bgp_default_originate (peer, afi, safi, 0);
2559
2560 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2561 for (ri = rn->info; ri; ri = ri->next)
2562 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2563 {
paulfee0f4c2004-09-13 05:12:46 +00002564 if ( (rsclient) ?
2565 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2566 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002567 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2568 else
2569 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002570
2571 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002572 }
2573}
2574
2575void
2576bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2577{
2578 struct bgp_node *rn;
2579 struct bgp_table *table;
2580
2581 if (peer->status != Established)
2582 return;
2583
2584 if (! peer->afc_nego[afi][safi])
2585 return;
2586
2587 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2588 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2589 return;
2590
2591 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002592 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002593 else
2594 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2595 rn = bgp_route_next(rn))
2596 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002597 bgp_announce_table (peer, afi, safi, table, 0);
2598
2599 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2600 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002601}
2602
2603void
2604bgp_announce_route_all (struct peer *peer)
2605{
2606 afi_t afi;
2607 safi_t safi;
2608
2609 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2610 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2611 bgp_announce_route (peer, afi, safi);
2612}
2613
2614static void
paulfee0f4c2004-09-13 05:12:46 +00002615bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2616 safi_t safi, struct bgp_table *table)
2617{
2618 struct bgp_node *rn;
2619 struct bgp_adj_in *ain;
2620
2621 if (! table)
2622 table = rsclient->bgp->rib[afi][safi];
2623
2624 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2625 for (ain = rn->adj_in; ain; ain = ain->next)
2626 {
2627 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2628 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2629 }
2630}
2631
2632void
2633bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2634{
2635 struct bgp_table *table;
2636 struct bgp_node *rn;
2637
2638 if (safi != SAFI_MPLS_VPN)
2639 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2640
2641 else
2642 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2643 rn = bgp_route_next (rn))
2644 if ((table = rn->info) != NULL)
2645 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2646}
2647
2648static void
paul718e3742002-12-13 20:15:29 +00002649bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2650 struct bgp_table *table)
2651{
2652 int ret;
2653 struct bgp_node *rn;
2654 struct bgp_adj_in *ain;
2655
2656 if (! table)
2657 table = peer->bgp->rib[afi][safi];
2658
2659 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2660 for (ain = rn->adj_in; ain; ain = ain->next)
2661 {
2662 if (ain->peer == peer)
2663 {
2664 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2665 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2666 NULL, NULL, 1);
2667 if (ret < 0)
2668 {
2669 bgp_unlock_node (rn);
2670 return;
2671 }
2672 continue;
2673 }
2674 }
2675}
2676
2677void
2678bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2679{
2680 struct bgp_node *rn;
2681 struct bgp_table *table;
2682
2683 if (peer->status != Established)
2684 return;
2685
2686 if (safi != SAFI_MPLS_VPN)
2687 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2688 else
2689 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2690 rn = bgp_route_next (rn))
2691 if ((table = rn->info) != NULL)
2692 bgp_soft_reconfig_table (peer, afi, safi, table);
2693}
2694
Chris Caputo228da422009-07-18 05:44:03 +00002695
2696struct bgp_clear_node_queue
2697{
2698 struct bgp_node *rn;
2699 enum bgp_clear_route_type purpose;
2700};
2701
paul200df112005-06-01 11:17:05 +00002702static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002703bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002704{
Chris Caputo228da422009-07-18 05:44:03 +00002705 struct bgp_clear_node_queue *cnq = data;
2706 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002707 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002708 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002709 afi_t afi = rn->table->afi;
2710 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002711
Paul Jakma64e580a2006-02-21 01:09:01 +00002712 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002713
Paul Jakma64e580a2006-02-21 01:09:01 +00002714 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002715 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002716 {
2717 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002718 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2719 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002720 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002721 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2722 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002723 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002724 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002725 break;
2726 }
paul200df112005-06-01 11:17:05 +00002727 return WQ_SUCCESS;
2728}
2729
2730static void
paul0fb58d52005-11-14 14:31:49 +00002731bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002732{
Chris Caputo228da422009-07-18 05:44:03 +00002733 struct bgp_clear_node_queue *cnq = data;
2734 struct bgp_node *rn = cnq->rn;
2735 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002736
2737 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002738 bgp_table_unlock (table);
2739 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002740}
2741
2742static void
paul94f2b392005-06-28 12:44:16 +00002743bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002744{
Paul Jakma64e580a2006-02-21 01:09:01 +00002745 struct peer *peer = wq->spec.data;
2746
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002747 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002748 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002749
2750 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002751}
2752
2753static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002754bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002755{
Paul Jakmaa2943652009-07-21 14:02:04 +01002756 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002757
Paul Jakmaa2943652009-07-21 14:02:04 +01002758 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002759#undef CLEAR_QUEUE_NAME_LEN
2760
2761 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002762 {
2763 zlog_err ("%s: Failed to allocate work queue", __func__);
2764 exit (1);
2765 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002766 peer->clear_node_queue->spec.hold = 10;
2767 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2768 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2769 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2770 peer->clear_node_queue->spec.max_retries = 0;
2771
2772 /* we only 'lock' this peer reference when the queue is actually active */
2773 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002774}
2775
paul718e3742002-12-13 20:15:29 +00002776static void
2777bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002778 struct bgp_table *table, struct peer *rsclient,
2779 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002780{
2781 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002782
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002783
paul718e3742002-12-13 20:15:29 +00002784 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002785 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002786
hasso6cf159b2005-03-21 10:28:14 +00002787 /* If still no table => afi/safi isn't configured at all or smth. */
2788 if (! table)
2789 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002790
2791 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2792 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002793 struct bgp_info *ri;
2794 struct bgp_adj_in *ain;
2795 struct bgp_adj_out *aout;
2796
Paul Jakma65ca75e2006-05-04 08:08:15 +00002797 if (rn->info == NULL)
2798 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002799
2800 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2801 * queued for every clearing peer, regardless of whether it is
2802 * relevant to the peer at hand.
2803 *
2804 * Overview: There are 3 different indices which need to be
2805 * scrubbed, potentially, when a peer is removed:
2806 *
2807 * 1 peer's routes visible via the RIB (ie accepted routes)
2808 * 2 peer's routes visible by the (optional) peer's adj-in index
2809 * 3 other routes visible by the peer's adj-out index
2810 *
2811 * 3 there is no hurry in scrubbing, once the struct peer is
2812 * removed from bgp->peer, we could just GC such deleted peer's
2813 * adj-outs at our leisure.
2814 *
2815 * 1 and 2 must be 'scrubbed' in some way, at least made
2816 * invisible via RIB index before peer session is allowed to be
2817 * brought back up. So one needs to know when such a 'search' is
2818 * complete.
2819 *
2820 * Ideally:
2821 *
2822 * - there'd be a single global queue or a single RIB walker
2823 * - rather than tracking which route_nodes still need to be
2824 * examined on a peer basis, we'd track which peers still
2825 * aren't cleared
2826 *
2827 * Given that our per-peer prefix-counts now should be reliable,
2828 * this may actually be achievable. It doesn't seem to be a huge
2829 * problem at this time,
2830 */
2831 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002832 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002833 {
Chris Caputo228da422009-07-18 05:44:03 +00002834 struct bgp_clear_node_queue *cnq;
2835
2836 /* both unlocked in bgp_clear_node_queue_del */
2837 bgp_table_lock (rn->table);
2838 bgp_lock_node (rn);
2839 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2840 sizeof (struct bgp_clear_node_queue));
2841 cnq->rn = rn;
2842 cnq->purpose = purpose;
2843 work_queue_add (peer->clear_node_queue, cnq);
2844 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002845 }
2846
2847 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002848 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002849 {
2850 bgp_adj_in_remove (rn, ain);
2851 bgp_unlock_node (rn);
2852 break;
2853 }
2854 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002855 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002856 {
2857 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2858 bgp_unlock_node (rn);
2859 break;
2860 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002861 }
2862 return;
2863}
2864
2865void
Chris Caputo228da422009-07-18 05:44:03 +00002866bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2867 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002868{
2869 struct bgp_node *rn;
2870 struct bgp_table *table;
2871 struct peer *rsclient;
2872 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002873
Paul Jakma64e580a2006-02-21 01:09:01 +00002874 if (peer->clear_node_queue == NULL)
2875 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002876
Paul Jakmaca058a32006-09-14 02:58:49 +00002877 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2878 * Idle until it receives a Clearing_Completed event. This protects
2879 * against peers which flap faster than we can we clear, which could
2880 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002881 *
2882 * a) race with routes from the new session being installed before
2883 * clear_route_node visits the node (to delete the route of that
2884 * peer)
2885 * b) resource exhaustion, clear_route_node likely leads to an entry
2886 * on the process_main queue. Fast-flapping could cause that queue
2887 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002888 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002889 if (!peer->clear_node_queue->thread)
2890 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002891
Chris Caputo228da422009-07-18 05:44:03 +00002892 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002893 {
Chris Caputo228da422009-07-18 05:44:03 +00002894 case BGP_CLEAR_ROUTE_NORMAL:
2895 if (safi != SAFI_MPLS_VPN)
2896 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2897 else
2898 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2899 rn = bgp_route_next (rn))
2900 if ((table = rn->info) != NULL)
2901 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2902
2903 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2904 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2905 PEER_FLAG_RSERVER_CLIENT))
2906 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2907 break;
2908
2909 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2910 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2911 break;
2912
2913 default:
2914 assert (0);
2915 break;
paulfee0f4c2004-09-13 05:12:46 +00002916 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002917
Paul Jakmaca058a32006-09-14 02:58:49 +00002918 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002919 * completion function won't be run by workqueue code - call it here.
2920 * XXX: Actually, this assumption doesn't hold, see
2921 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002922 *
2923 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002924 * really needed if peer state is Established - peers in
2925 * pre-Established states shouldn't have any route-update state
2926 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002927 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002928 * We still can get here in pre-Established though, through
2929 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2930 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002931 *
2932 * At some future point, this check could be move to the top of the
2933 * function, and do a quick early-return when state is
2934 * pre-Established, avoiding above list and table scans. Once we're
2935 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002936 */
2937 if (!peer->clear_node_queue->thread)
2938 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002939}
2940
2941void
2942bgp_clear_route_all (struct peer *peer)
2943{
2944 afi_t afi;
2945 safi_t safi;
2946
2947 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2948 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002949 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002950}
2951
2952void
2953bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2954{
2955 struct bgp_table *table;
2956 struct bgp_node *rn;
2957 struct bgp_adj_in *ain;
2958
2959 table = peer->bgp->rib[afi][safi];
2960
2961 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2962 for (ain = rn->adj_in; ain ; ain = ain->next)
2963 if (ain->peer == peer)
2964 {
2965 bgp_adj_in_remove (rn, ain);
2966 bgp_unlock_node (rn);
2967 break;
2968 }
2969}
hasso93406d82005-02-02 14:40:33 +00002970
2971void
2972bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2973{
2974 struct bgp_node *rn;
2975 struct bgp_info *ri;
2976 struct bgp_table *table;
2977
2978 table = peer->bgp->rib[afi][safi];
2979
2980 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2981 {
2982 for (ri = rn->info; ri; ri = ri->next)
2983 if (ri->peer == peer)
2984 {
2985 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2986 bgp_rib_remove (rn, ri, peer, afi, safi);
2987 break;
2988 }
2989 }
2990}
paul718e3742002-12-13 20:15:29 +00002991
2992/* Delete all kernel routes. */
2993void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002994bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002995{
2996 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002997 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002998 struct bgp_node *rn;
2999 struct bgp_table *table;
3000 struct bgp_info *ri;
3001
paul1eb8ef22005-04-07 07:30:20 +00003002 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00003003 {
3004 table = bgp->rib[AFI_IP][SAFI_UNICAST];
3005
3006 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3007 for (ri = rn->info; ri; ri = ri->next)
3008 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3009 && ri->type == ZEBRA_ROUTE_BGP
3010 && ri->sub_type == BGP_ROUTE_NORMAL)
3011 bgp_zebra_withdraw (&rn->p, ri);
3012
3013 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
3014
3015 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
3016 for (ri = rn->info; ri; ri = ri->next)
3017 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
3018 && ri->type == ZEBRA_ROUTE_BGP
3019 && ri->sub_type == BGP_ROUTE_NORMAL)
3020 bgp_zebra_withdraw (&rn->p, ri);
3021 }
3022}
3023
3024void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003025bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003026{
3027 vty_reset ();
3028 bgp_zclient_reset ();
3029 access_list_reset ();
3030 prefix_list_reset ();
3031}
3032
3033/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3034 value. */
3035int
3036bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3037{
3038 u_char *pnt;
3039 u_char *lim;
3040 struct prefix p;
3041 int psize;
3042 int ret;
3043
3044 /* Check peer status. */
3045 if (peer->status != Established)
3046 return 0;
3047
3048 pnt = packet->nlri;
3049 lim = pnt + packet->length;
3050
3051 for (; pnt < lim; pnt += psize)
3052 {
3053 /* Clear prefix structure. */
3054 memset (&p, 0, sizeof (struct prefix));
3055
3056 /* Fetch prefix length. */
3057 p.prefixlen = *pnt++;
3058 p.family = afi2family (packet->afi);
3059
3060 /* Already checked in nlri_sanity_check(). We do double check
3061 here. */
3062 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3063 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3064 return -1;
3065
3066 /* Packet size overflow check. */
3067 psize = PSIZE (p.prefixlen);
3068
3069 /* When packet overflow occur return immediately. */
3070 if (pnt + psize > lim)
3071 return -1;
3072
3073 /* Fetch prefix from NLRI packet. */
3074 memcpy (&p.u.prefix, pnt, psize);
3075
3076 /* Check address. */
3077 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3078 {
3079 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3080 {
paulf5ba3872004-07-09 12:11:31 +00003081 /*
3082 * From draft-ietf-idr-bgp4-22, Section 6.3:
3083 * If a BGP router receives an UPDATE message with a
3084 * semantically incorrect NLRI field, in which a prefix is
3085 * semantically incorrect (eg. an unexpected multicast IP
3086 * address), it should ignore the prefix.
3087 */
paul718e3742002-12-13 20:15:29 +00003088 zlog (peer->log, LOG_ERR,
3089 "IPv4 unicast NLRI is multicast address %s",
3090 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003091
paul718e3742002-12-13 20:15:29 +00003092 return -1;
3093 }
3094 }
3095
3096#ifdef HAVE_IPV6
3097 /* Check address. */
3098 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3099 {
3100 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3101 {
3102 char buf[BUFSIZ];
3103
3104 zlog (peer->log, LOG_WARNING,
3105 "IPv6 link-local NLRI received %s ignore this NLRI",
3106 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3107
3108 continue;
3109 }
3110 }
3111#endif /* HAVE_IPV6 */
3112
3113 /* Normal process. */
3114 if (attr)
3115 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3116 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3117 else
3118 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3119 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3120
3121 /* Address family configuration mismatch or maximum-prefix count
3122 overflow. */
3123 if (ret < 0)
3124 return -1;
3125 }
3126
3127 /* Packet length consistency check. */
3128 if (pnt != lim)
3129 return -1;
3130
3131 return 0;
3132}
3133
3134/* NLRI encode syntax check routine. */
3135int
3136bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3137 bgp_size_t length)
3138{
3139 u_char *end;
3140 u_char prefixlen;
3141 int psize;
3142
3143 end = pnt + length;
3144
3145 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3146 syntactic validity. If the field is syntactically incorrect,
3147 then the Error Subcode is set to Invalid Network Field. */
3148
3149 while (pnt < end)
3150 {
3151 prefixlen = *pnt++;
3152
3153 /* Prefix length check. */
3154 if ((afi == AFI_IP && prefixlen > 32)
3155 || (afi == AFI_IP6 && prefixlen > 128))
3156 {
3157 plog_err (peer->log,
3158 "%s [Error] Update packet error (wrong prefix length %d)",
3159 peer->host, prefixlen);
3160 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3161 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3162 return -1;
3163 }
3164
3165 /* Packet size overflow check. */
3166 psize = PSIZE (prefixlen);
3167
3168 if (pnt + psize > end)
3169 {
3170 plog_err (peer->log,
3171 "%s [Error] Update packet error"
3172 " (prefix data overflow prefix size is %d)",
3173 peer->host, psize);
3174 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3175 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3176 return -1;
3177 }
3178
3179 pnt += psize;
3180 }
3181
3182 /* Packet length consistency check. */
3183 if (pnt != end)
3184 {
3185 plog_err (peer->log,
3186 "%s [Error] Update packet error"
3187 " (prefix length mismatch with total length)",
3188 peer->host);
3189 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3190 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3191 return -1;
3192 }
3193 return 0;
3194}
3195
paul94f2b392005-06-28 12:44:16 +00003196static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003197bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003198{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003199 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003200}
3201
paul94f2b392005-06-28 12:44:16 +00003202static void
paul718e3742002-12-13 20:15:29 +00003203bgp_static_free (struct bgp_static *bgp_static)
3204{
3205 if (bgp_static->rmap.name)
3206 free (bgp_static->rmap.name);
3207 XFREE (MTYPE_BGP_STATIC, bgp_static);
3208}
3209
paul94f2b392005-06-28 12:44:16 +00003210static void
paulfee0f4c2004-09-13 05:12:46 +00003211bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3212 struct prefix *p, afi_t afi, safi_t safi)
3213{
3214 struct bgp_node *rn;
3215 struct bgp_info *ri;
3216
3217 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3218
3219 /* Check selected route and self inserted route. */
3220 for (ri = rn->info; ri; ri = ri->next)
3221 if (ri->peer == bgp->peer_self
3222 && ri->type == ZEBRA_ROUTE_BGP
3223 && ri->sub_type == BGP_ROUTE_STATIC)
3224 break;
3225
3226 /* Withdraw static BGP route from routing table. */
3227 if (ri)
3228 {
paulfee0f4c2004-09-13 05:12:46 +00003229 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003230 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003231 }
3232
3233 /* Unlock bgp_node_lookup. */
3234 bgp_unlock_node (rn);
3235}
3236
paul94f2b392005-06-28 12:44:16 +00003237static void
paulfee0f4c2004-09-13 05:12:46 +00003238bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003239 struct bgp_static *bgp_static,
3240 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003241{
3242 struct bgp_node *rn;
3243 struct bgp_info *ri;
3244 struct bgp_info *new;
3245 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003246 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003247 struct attr attr = {0 };
3248 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003249 struct bgp *bgp;
3250 int ret;
3251 char buf[SU_ADDRSTRLEN];
3252
3253 bgp = rsclient->bgp;
3254
Paul Jakma06e110f2006-05-12 23:29:22 +00003255 assert (bgp_static);
3256 if (!bgp_static)
3257 return;
3258
paulfee0f4c2004-09-13 05:12:46 +00003259 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3260
3261 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003262
3263 attr.nexthop = bgp_static->igpnexthop;
3264 attr.med = bgp_static->igpmetric;
3265 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003266
Paul Jakma41367172007-08-06 15:24:51 +00003267 if (bgp_static->atomic)
3268 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3269
paulfee0f4c2004-09-13 05:12:46 +00003270 /* Apply network route-map for export to this rsclient. */
3271 if (bgp_static->rmap.name)
3272 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003273 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003274 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003275 info.attr = &attr_tmp;
3276
paulfee0f4c2004-09-13 05:12:46 +00003277 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3278 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3279
3280 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3281
3282 rsclient->rmap_type = 0;
3283
3284 if (ret == RMAP_DENYMATCH)
3285 {
3286 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003287 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003288
3289 /* Unintern original. */
3290 aspath_unintern (attr.aspath);
3291 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003292 bgp_attr_extra_free (&attr);
3293
paulfee0f4c2004-09-13 05:12:46 +00003294 return;
3295 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003296 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003297 }
3298 else
3299 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003300
Stephen Hemminger7badc262010-08-05 10:26:31 -07003301 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003302
paulfee0f4c2004-09-13 05:12:46 +00003303 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3304
Paul Jakmafb982c22007-05-04 20:15:47 +00003305 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3306 == RMAP_DENY)
3307 {
paulfee0f4c2004-09-13 05:12:46 +00003308 /* This BGP update is filtered. Log the reason then update BGP entry. */
3309 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003310 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003311 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3312 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3313 p->prefixlen, rsclient->host);
3314
3315 bgp->peer_self->rmap_type = 0;
3316
3317 bgp_attr_unintern (attr_new);
3318 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003319 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003320
3321 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3322
3323 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003324 }
paulfee0f4c2004-09-13 05:12:46 +00003325
3326 bgp->peer_self->rmap_type = 0;
3327
3328 bgp_attr_unintern (attr_new);
3329 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003330 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003331
3332 for (ri = rn->info; ri; ri = ri->next)
3333 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3334 && ri->sub_type == BGP_ROUTE_STATIC)
3335 break;
3336
3337 if (ri)
3338 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003339 if (attrhash_cmp (ri->attr, attr_new) &&
3340 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003341 {
3342 bgp_unlock_node (rn);
3343 bgp_attr_unintern (attr_new);
3344 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003345 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003346 return;
3347 }
3348 else
3349 {
3350 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003351 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003352
3353 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003354 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3355 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003356 bgp_attr_unintern (ri->attr);
3357 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003358 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003359
3360 /* Process change. */
3361 bgp_process (bgp, rn, afi, safi);
3362 bgp_unlock_node (rn);
3363 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003364 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003365 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003366 }
paulfee0f4c2004-09-13 05:12:46 +00003367 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003368
paulfee0f4c2004-09-13 05:12:46 +00003369 /* Make new BGP info. */
3370 new = bgp_info_new ();
3371 new->type = ZEBRA_ROUTE_BGP;
3372 new->sub_type = BGP_ROUTE_STATIC;
3373 new->peer = bgp->peer_self;
3374 SET_FLAG (new->flags, BGP_INFO_VALID);
3375 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003376 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003377
3378 /* Register new BGP information. */
3379 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003380
3381 /* route_node_get lock */
3382 bgp_unlock_node (rn);
3383
paulfee0f4c2004-09-13 05:12:46 +00003384 /* Process change. */
3385 bgp_process (bgp, rn, afi, safi);
3386
3387 /* Unintern original. */
3388 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003389 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003390}
3391
paul94f2b392005-06-28 12:44:16 +00003392static void
paulfee0f4c2004-09-13 05:12:46 +00003393bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003394 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3395{
3396 struct bgp_node *rn;
3397 struct bgp_info *ri;
3398 struct bgp_info *new;
3399 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003400 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003401 struct attr *attr_new;
3402 int ret;
3403
Paul Jakmadd8103a2006-05-12 23:27:30 +00003404 assert (bgp_static);
3405 if (!bgp_static)
3406 return;
3407
paulfee0f4c2004-09-13 05:12:46 +00003408 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003409
3410 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003411
3412 attr.nexthop = bgp_static->igpnexthop;
3413 attr.med = bgp_static->igpmetric;
3414 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003415
Paul Jakma41367172007-08-06 15:24:51 +00003416 if (bgp_static->atomic)
3417 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3418
paul718e3742002-12-13 20:15:29 +00003419 /* Apply route-map. */
3420 if (bgp_static->rmap.name)
3421 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003422 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003423 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003424 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003425
paulfee0f4c2004-09-13 05:12:46 +00003426 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3427
paul718e3742002-12-13 20:15:29 +00003428 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003429
paulfee0f4c2004-09-13 05:12:46 +00003430 bgp->peer_self->rmap_type = 0;
3431
paul718e3742002-12-13 20:15:29 +00003432 if (ret == RMAP_DENYMATCH)
3433 {
3434 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003435 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003436
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 bgp_static_withdraw (bgp, p, afi, safi);
3441 return;
3442 }
paul286e1e72003-08-08 00:24:31 +00003443 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003444 }
paul286e1e72003-08-08 00:24:31 +00003445 else
3446 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003447
3448 for (ri = rn->info; ri; ri = ri->next)
3449 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3450 && ri->sub_type == BGP_ROUTE_STATIC)
3451 break;
3452
3453 if (ri)
3454 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003455 if (attrhash_cmp (ri->attr, attr_new) &&
3456 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003457 {
3458 bgp_unlock_node (rn);
3459 bgp_attr_unintern (attr_new);
3460 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003461 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003462 return;
3463 }
3464 else
3465 {
3466 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003467 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003468
3469 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003470 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3471 bgp_info_restore(rn, ri);
3472 else
3473 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003474 bgp_attr_unintern (ri->attr);
3475 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003476 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003477
3478 /* Process change. */
3479 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3480 bgp_process (bgp, rn, afi, safi);
3481 bgp_unlock_node (rn);
3482 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003483 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003484 return;
3485 }
3486 }
3487
3488 /* Make new BGP info. */
3489 new = bgp_info_new ();
3490 new->type = ZEBRA_ROUTE_BGP;
3491 new->sub_type = BGP_ROUTE_STATIC;
3492 new->peer = bgp->peer_self;
3493 SET_FLAG (new->flags, BGP_INFO_VALID);
3494 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003495 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003496
3497 /* Aggregate address increment. */
3498 bgp_aggregate_increment (bgp, p, new, afi, safi);
3499
3500 /* Register new BGP information. */
3501 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003502
3503 /* route_node_get lock */
3504 bgp_unlock_node (rn);
3505
paul718e3742002-12-13 20:15:29 +00003506 /* Process change. */
3507 bgp_process (bgp, rn, afi, safi);
3508
3509 /* Unintern original. */
3510 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003511 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003512}
3513
3514void
paulfee0f4c2004-09-13 05:12:46 +00003515bgp_static_update (struct bgp *bgp, struct prefix *p,
3516 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3517{
3518 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003519 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003520
3521 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3522
paul1eb8ef22005-04-07 07:30:20 +00003523 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003524 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003525 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3526 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003527 }
3528}
3529
paul94f2b392005-06-28 12:44:16 +00003530static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003531bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3532 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003533{
3534 struct bgp_node *rn;
3535 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003536
paulfee0f4c2004-09-13 05:12:46 +00003537 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003538
3539 /* Make new BGP info. */
3540 new = bgp_info_new ();
3541 new->type = ZEBRA_ROUTE_BGP;
3542 new->sub_type = BGP_ROUTE_STATIC;
3543 new->peer = bgp->peer_self;
3544 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3545 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003546 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003547 new->extra = bgp_info_extra_new();
3548 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003549
3550 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003551 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003552
3553 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003554 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003555
paul200df112005-06-01 11:17:05 +00003556 /* route_node_get lock */
3557 bgp_unlock_node (rn);
3558
paul718e3742002-12-13 20:15:29 +00003559 /* Process change. */
3560 bgp_process (bgp, rn, afi, safi);
3561}
3562
3563void
3564bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3565 safi_t safi)
3566{
3567 struct bgp_node *rn;
3568 struct bgp_info *ri;
3569
paulfee0f4c2004-09-13 05:12:46 +00003570 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003571
3572 /* Check selected route and self inserted route. */
3573 for (ri = rn->info; ri; ri = ri->next)
3574 if (ri->peer == bgp->peer_self
3575 && ri->type == ZEBRA_ROUTE_BGP
3576 && ri->sub_type == BGP_ROUTE_STATIC)
3577 break;
3578
3579 /* Withdraw static BGP route from routing table. */
3580 if (ri)
3581 {
3582 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003583 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003584 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003585 }
3586
3587 /* Unlock bgp_node_lookup. */
3588 bgp_unlock_node (rn);
3589}
3590
3591void
paulfee0f4c2004-09-13 05:12:46 +00003592bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3593{
3594 struct bgp_static *bgp_static;
3595 struct bgp *bgp;
3596 struct bgp_node *rn;
3597 struct prefix *p;
3598
3599 bgp = rsclient->bgp;
3600
3601 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3602 if ((bgp_static = rn->info) != NULL)
3603 {
3604 p = &rn->p;
3605
3606 bgp_static_update_rsclient (rsclient, p, bgp_static,
3607 afi, safi);
3608 }
3609}
3610
paul94f2b392005-06-28 12:44:16 +00003611static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003612bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3613 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003614{
3615 struct bgp_node *rn;
3616 struct bgp_info *ri;
3617
paulfee0f4c2004-09-13 05:12:46 +00003618 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003619
3620 /* Check selected route and self inserted route. */
3621 for (ri = rn->info; ri; ri = ri->next)
3622 if (ri->peer == bgp->peer_self
3623 && ri->type == ZEBRA_ROUTE_BGP
3624 && ri->sub_type == BGP_ROUTE_STATIC)
3625 break;
3626
3627 /* Withdraw static BGP route from routing table. */
3628 if (ri)
3629 {
3630 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003631 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003632 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003633 }
3634
3635 /* Unlock bgp_node_lookup. */
3636 bgp_unlock_node (rn);
3637}
3638
3639/* Configure static BGP network. When user don't run zebra, static
3640 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003641static int
paulfd79ac92004-10-13 05:06:08 +00003642bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003643 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003644{
3645 int ret;
3646 struct prefix p;
3647 struct bgp_static *bgp_static;
3648 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003649 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003650
3651 /* Convert IP prefix string to struct prefix. */
3652 ret = str2prefix (ip_str, &p);
3653 if (! ret)
3654 {
3655 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3656 return CMD_WARNING;
3657 }
3658#ifdef HAVE_IPV6
3659 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3660 {
3661 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3662 VTY_NEWLINE);
3663 return CMD_WARNING;
3664 }
3665#endif /* HAVE_IPV6 */
3666
3667 apply_mask (&p);
3668
3669 /* Set BGP static route configuration. */
3670 rn = bgp_node_get (bgp->route[afi][safi], &p);
3671
3672 if (rn->info)
3673 {
3674 /* Configuration change. */
3675 bgp_static = rn->info;
3676
3677 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003678 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3679 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003680
paul718e3742002-12-13 20:15:29 +00003681 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003682
paul718e3742002-12-13 20:15:29 +00003683 if (rmap)
3684 {
3685 if (bgp_static->rmap.name)
3686 free (bgp_static->rmap.name);
3687 bgp_static->rmap.name = strdup (rmap);
3688 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3689 }
3690 else
3691 {
3692 if (bgp_static->rmap.name)
3693 free (bgp_static->rmap.name);
3694 bgp_static->rmap.name = NULL;
3695 bgp_static->rmap.map = NULL;
3696 bgp_static->valid = 0;
3697 }
3698 bgp_unlock_node (rn);
3699 }
3700 else
3701 {
3702 /* New configuration. */
3703 bgp_static = bgp_static_new ();
3704 bgp_static->backdoor = backdoor;
3705 bgp_static->valid = 0;
3706 bgp_static->igpmetric = 0;
3707 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003708
paul718e3742002-12-13 20:15:29 +00003709 if (rmap)
3710 {
3711 if (bgp_static->rmap.name)
3712 free (bgp_static->rmap.name);
3713 bgp_static->rmap.name = strdup (rmap);
3714 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3715 }
3716 rn->info = bgp_static;
3717 }
3718
3719 /* If BGP scan is not enabled, we should install this route here. */
3720 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3721 {
3722 bgp_static->valid = 1;
3723
3724 if (need_update)
3725 bgp_static_withdraw (bgp, &p, afi, safi);
3726
3727 if (! bgp_static->backdoor)
3728 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3729 }
3730
3731 return CMD_SUCCESS;
3732}
3733
3734/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003735static int
paulfd79ac92004-10-13 05:06:08 +00003736bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003737 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003738{
3739 int ret;
3740 struct prefix p;
3741 struct bgp_static *bgp_static;
3742 struct bgp_node *rn;
3743
3744 /* Convert IP prefix string to struct prefix. */
3745 ret = str2prefix (ip_str, &p);
3746 if (! ret)
3747 {
3748 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3749 return CMD_WARNING;
3750 }
3751#ifdef HAVE_IPV6
3752 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3753 {
3754 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3755 VTY_NEWLINE);
3756 return CMD_WARNING;
3757 }
3758#endif /* HAVE_IPV6 */
3759
3760 apply_mask (&p);
3761
3762 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3763 if (! rn)
3764 {
3765 vty_out (vty, "%% Can't find specified static route configuration.%s",
3766 VTY_NEWLINE);
3767 return CMD_WARNING;
3768 }
3769
3770 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003771
paul718e3742002-12-13 20:15:29 +00003772 /* Update BGP RIB. */
3773 if (! bgp_static->backdoor)
3774 bgp_static_withdraw (bgp, &p, afi, safi);
3775
3776 /* Clear configuration. */
3777 bgp_static_free (bgp_static);
3778 rn->info = NULL;
3779 bgp_unlock_node (rn);
3780 bgp_unlock_node (rn);
3781
3782 return CMD_SUCCESS;
3783}
3784
3785/* Called from bgp_delete(). Delete all static routes from the BGP
3786 instance. */
3787void
3788bgp_static_delete (struct bgp *bgp)
3789{
3790 afi_t afi;
3791 safi_t safi;
3792 struct bgp_node *rn;
3793 struct bgp_node *rm;
3794 struct bgp_table *table;
3795 struct bgp_static *bgp_static;
3796
3797 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3798 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3799 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3800 if (rn->info != NULL)
3801 {
3802 if (safi == SAFI_MPLS_VPN)
3803 {
3804 table = rn->info;
3805
3806 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3807 {
3808 bgp_static = rn->info;
3809 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3810 AFI_IP, SAFI_MPLS_VPN,
3811 (struct prefix_rd *)&rn->p,
3812 bgp_static->tag);
3813 bgp_static_free (bgp_static);
3814 rn->info = NULL;
3815 bgp_unlock_node (rn);
3816 }
3817 }
3818 else
3819 {
3820 bgp_static = rn->info;
3821 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3822 bgp_static_free (bgp_static);
3823 rn->info = NULL;
3824 bgp_unlock_node (rn);
3825 }
3826 }
3827}
3828
3829int
paulfd79ac92004-10-13 05:06:08 +00003830bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3831 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003832{
3833 int ret;
3834 struct prefix p;
3835 struct prefix_rd prd;
3836 struct bgp *bgp;
3837 struct bgp_node *prn;
3838 struct bgp_node *rn;
3839 struct bgp_table *table;
3840 struct bgp_static *bgp_static;
3841 u_char tag[3];
3842
3843 bgp = vty->index;
3844
3845 ret = str2prefix (ip_str, &p);
3846 if (! ret)
3847 {
3848 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3849 return CMD_WARNING;
3850 }
3851 apply_mask (&p);
3852
3853 ret = str2prefix_rd (rd_str, &prd);
3854 if (! ret)
3855 {
3856 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3857 return CMD_WARNING;
3858 }
3859
3860 ret = str2tag (tag_str, tag);
3861 if (! ret)
3862 {
3863 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3864 return CMD_WARNING;
3865 }
3866
3867 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3868 (struct prefix *)&prd);
3869 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003870 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003871 else
3872 bgp_unlock_node (prn);
3873 table = prn->info;
3874
3875 rn = bgp_node_get (table, &p);
3876
3877 if (rn->info)
3878 {
3879 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3880 bgp_unlock_node (rn);
3881 }
3882 else
3883 {
3884 /* New configuration. */
3885 bgp_static = bgp_static_new ();
3886 bgp_static->valid = 1;
3887 memcpy (bgp_static->tag, tag, 3);
3888 rn->info = bgp_static;
3889
3890 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3891 }
3892
3893 return CMD_SUCCESS;
3894}
3895
3896/* Configure static BGP network. */
3897int
paulfd79ac92004-10-13 05:06:08 +00003898bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3899 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003900{
3901 int ret;
3902 struct bgp *bgp;
3903 struct prefix p;
3904 struct prefix_rd prd;
3905 struct bgp_node *prn;
3906 struct bgp_node *rn;
3907 struct bgp_table *table;
3908 struct bgp_static *bgp_static;
3909 u_char tag[3];
3910
3911 bgp = vty->index;
3912
3913 /* Convert IP prefix string to struct prefix. */
3914 ret = str2prefix (ip_str, &p);
3915 if (! ret)
3916 {
3917 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3918 return CMD_WARNING;
3919 }
3920 apply_mask (&p);
3921
3922 ret = str2prefix_rd (rd_str, &prd);
3923 if (! ret)
3924 {
3925 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3926 return CMD_WARNING;
3927 }
3928
3929 ret = str2tag (tag_str, tag);
3930 if (! ret)
3931 {
3932 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3933 return CMD_WARNING;
3934 }
3935
3936 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3937 (struct prefix *)&prd);
3938 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003939 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003940 else
3941 bgp_unlock_node (prn);
3942 table = prn->info;
3943
3944 rn = bgp_node_lookup (table, &p);
3945
3946 if (rn)
3947 {
3948 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3949
3950 bgp_static = rn->info;
3951 bgp_static_free (bgp_static);
3952 rn->info = NULL;
3953 bgp_unlock_node (rn);
3954 bgp_unlock_node (rn);
3955 }
3956 else
3957 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3958
3959 return CMD_SUCCESS;
3960}
3961
3962DEFUN (bgp_network,
3963 bgp_network_cmd,
3964 "network A.B.C.D/M",
3965 "Specify a network to announce via BGP\n"
3966 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3967{
3968 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003969 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003970}
3971
3972DEFUN (bgp_network_route_map,
3973 bgp_network_route_map_cmd,
3974 "network A.B.C.D/M route-map WORD",
3975 "Specify a network to announce via BGP\n"
3976 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3977 "Route-map to modify the attributes\n"
3978 "Name of the route map\n")
3979{
3980 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003981 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003982}
3983
3984DEFUN (bgp_network_backdoor,
3985 bgp_network_backdoor_cmd,
3986 "network A.B.C.D/M backdoor",
3987 "Specify a network to announce via BGP\n"
3988 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3989 "Specify a BGP backdoor route\n")
3990{
Paul Jakma41367172007-08-06 15:24:51 +00003991 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003992 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003993}
3994
3995DEFUN (bgp_network_mask,
3996 bgp_network_mask_cmd,
3997 "network A.B.C.D mask A.B.C.D",
3998 "Specify a network to announce via BGP\n"
3999 "Network number\n"
4000 "Network mask\n"
4001 "Network mask\n")
4002{
4003 int ret;
4004 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004005
paul718e3742002-12-13 20:15:29 +00004006 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4007 if (! ret)
4008 {
4009 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4010 return CMD_WARNING;
4011 }
4012
4013 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004014 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004015}
4016
4017DEFUN (bgp_network_mask_route_map,
4018 bgp_network_mask_route_map_cmd,
4019 "network A.B.C.D mask A.B.C.D route-map WORD",
4020 "Specify a network to announce via BGP\n"
4021 "Network number\n"
4022 "Network mask\n"
4023 "Network mask\n"
4024 "Route-map to modify the attributes\n"
4025 "Name of the route map\n")
4026{
4027 int ret;
4028 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004029
paul718e3742002-12-13 20:15:29 +00004030 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4031 if (! ret)
4032 {
4033 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4034 return CMD_WARNING;
4035 }
4036
4037 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004038 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004039}
4040
4041DEFUN (bgp_network_mask_backdoor,
4042 bgp_network_mask_backdoor_cmd,
4043 "network A.B.C.D mask A.B.C.D backdoor",
4044 "Specify a network to announce via BGP\n"
4045 "Network number\n"
4046 "Network mask\n"
4047 "Network mask\n"
4048 "Specify a BGP backdoor route\n")
4049{
4050 int ret;
4051 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004052
paul718e3742002-12-13 20:15:29 +00004053 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4054 if (! ret)
4055 {
4056 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4057 return CMD_WARNING;
4058 }
4059
Paul Jakma41367172007-08-06 15:24:51 +00004060 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004061 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004062}
4063
4064DEFUN (bgp_network_mask_natural,
4065 bgp_network_mask_natural_cmd,
4066 "network A.B.C.D",
4067 "Specify a network to announce via BGP\n"
4068 "Network number\n")
4069{
4070 int ret;
4071 char prefix_str[BUFSIZ];
4072
4073 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4074 if (! ret)
4075 {
4076 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4077 return CMD_WARNING;
4078 }
4079
4080 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004081 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004082}
4083
4084DEFUN (bgp_network_mask_natural_route_map,
4085 bgp_network_mask_natural_route_map_cmd,
4086 "network A.B.C.D route-map WORD",
4087 "Specify a network to announce via BGP\n"
4088 "Network number\n"
4089 "Route-map to modify the attributes\n"
4090 "Name of the route map\n")
4091{
4092 int ret;
4093 char prefix_str[BUFSIZ];
4094
4095 ret = netmask_str2prefix_str (argv[0], NULL, 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_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004103 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004104}
4105
4106DEFUN (bgp_network_mask_natural_backdoor,
4107 bgp_network_mask_natural_backdoor_cmd,
4108 "network A.B.C.D backdoor",
4109 "Specify a network to announce via BGP\n"
4110 "Network number\n"
4111 "Specify a BGP backdoor route\n")
4112{
4113 int ret;
4114 char prefix_str[BUFSIZ];
4115
4116 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4117 if (! ret)
4118 {
4119 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4120 return CMD_WARNING;
4121 }
4122
Paul Jakma41367172007-08-06 15:24:51 +00004123 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004124 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004125}
4126
4127DEFUN (no_bgp_network,
4128 no_bgp_network_cmd,
4129 "no network A.B.C.D/M",
4130 NO_STR
4131 "Specify a network to announce via BGP\n"
4132 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4133{
4134 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4135 bgp_node_safi (vty));
4136}
4137
4138ALIAS (no_bgp_network,
4139 no_bgp_network_route_map_cmd,
4140 "no network A.B.C.D/M route-map WORD",
4141 NO_STR
4142 "Specify a network to announce via BGP\n"
4143 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4144 "Route-map to modify the attributes\n"
4145 "Name of the route map\n")
4146
4147ALIAS (no_bgp_network,
4148 no_bgp_network_backdoor_cmd,
4149 "no network A.B.C.D/M backdoor",
4150 NO_STR
4151 "Specify a network to announce via BGP\n"
4152 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4153 "Specify a BGP backdoor route\n")
4154
4155DEFUN (no_bgp_network_mask,
4156 no_bgp_network_mask_cmd,
4157 "no network A.B.C.D mask A.B.C.D",
4158 NO_STR
4159 "Specify a network to announce via BGP\n"
4160 "Network number\n"
4161 "Network mask\n"
4162 "Network mask\n")
4163{
4164 int ret;
4165 char prefix_str[BUFSIZ];
4166
4167 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4168 if (! ret)
4169 {
4170 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4171 return CMD_WARNING;
4172 }
4173
4174 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4175 bgp_node_safi (vty));
4176}
4177
4178ALIAS (no_bgp_network_mask,
4179 no_bgp_network_mask_route_map_cmd,
4180 "no network A.B.C.D mask A.B.C.D route-map WORD",
4181 NO_STR
4182 "Specify a network to announce via BGP\n"
4183 "Network number\n"
4184 "Network mask\n"
4185 "Network mask\n"
4186 "Route-map to modify the attributes\n"
4187 "Name of the route map\n")
4188
4189ALIAS (no_bgp_network_mask,
4190 no_bgp_network_mask_backdoor_cmd,
4191 "no network A.B.C.D mask A.B.C.D backdoor",
4192 NO_STR
4193 "Specify a network to announce via BGP\n"
4194 "Network number\n"
4195 "Network mask\n"
4196 "Network mask\n"
4197 "Specify a BGP backdoor route\n")
4198
4199DEFUN (no_bgp_network_mask_natural,
4200 no_bgp_network_mask_natural_cmd,
4201 "no network A.B.C.D",
4202 NO_STR
4203 "Specify a network to announce via BGP\n"
4204 "Network number\n")
4205{
4206 int ret;
4207 char prefix_str[BUFSIZ];
4208
4209 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4210 if (! ret)
4211 {
4212 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4213 return CMD_WARNING;
4214 }
4215
4216 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4217 bgp_node_safi (vty));
4218}
4219
4220ALIAS (no_bgp_network_mask_natural,
4221 no_bgp_network_mask_natural_route_map_cmd,
4222 "no network A.B.C.D route-map WORD",
4223 NO_STR
4224 "Specify a network to announce via BGP\n"
4225 "Network number\n"
4226 "Route-map to modify the attributes\n"
4227 "Name of the route map\n")
4228
4229ALIAS (no_bgp_network_mask_natural,
4230 no_bgp_network_mask_natural_backdoor_cmd,
4231 "no network A.B.C.D backdoor",
4232 NO_STR
4233 "Specify a network to announce via BGP\n"
4234 "Network number\n"
4235 "Specify a BGP backdoor route\n")
4236
4237#ifdef HAVE_IPV6
4238DEFUN (ipv6_bgp_network,
4239 ipv6_bgp_network_cmd,
4240 "network X:X::X:X/M",
4241 "Specify a network to announce via BGP\n"
4242 "IPv6 prefix <network>/<length>\n")
4243{
Paul Jakma41367172007-08-06 15:24:51 +00004244 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004245 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004246}
4247
4248DEFUN (ipv6_bgp_network_route_map,
4249 ipv6_bgp_network_route_map_cmd,
4250 "network X:X::X:X/M route-map WORD",
4251 "Specify a network to announce via BGP\n"
4252 "IPv6 prefix <network>/<length>\n"
4253 "Route-map to modify the attributes\n"
4254 "Name of the route map\n")
4255{
4256 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004257 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004258}
4259
4260DEFUN (no_ipv6_bgp_network,
4261 no_ipv6_bgp_network_cmd,
4262 "no network X:X::X:X/M",
4263 NO_STR
4264 "Specify a network to announce via BGP\n"
4265 "IPv6 prefix <network>/<length>\n")
4266{
4267 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4268}
4269
4270ALIAS (no_ipv6_bgp_network,
4271 no_ipv6_bgp_network_route_map_cmd,
4272 "no network X:X::X:X/M route-map WORD",
4273 NO_STR
4274 "Specify a network to announce via BGP\n"
4275 "IPv6 prefix <network>/<length>\n"
4276 "Route-map to modify the attributes\n"
4277 "Name of the route map\n")
4278
4279ALIAS (ipv6_bgp_network,
4280 old_ipv6_bgp_network_cmd,
4281 "ipv6 bgp network X:X::X:X/M",
4282 IPV6_STR
4283 BGP_STR
4284 "Specify a network to announce via BGP\n"
4285 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4286
4287ALIAS (no_ipv6_bgp_network,
4288 old_no_ipv6_bgp_network_cmd,
4289 "no ipv6 bgp network X:X::X:X/M",
4290 NO_STR
4291 IPV6_STR
4292 BGP_STR
4293 "Specify a network to announce via BGP\n"
4294 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4295#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004296
4297/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4298ALIAS_DEPRECATED (bgp_network,
4299 bgp_network_ttl_cmd,
4300 "network A.B.C.D/M pathlimit <0-255>",
4301 "Specify a network to announce via BGP\n"
4302 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4303 "AS-Path hopcount limit attribute\n"
4304 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4305ALIAS_DEPRECATED (bgp_network_backdoor,
4306 bgp_network_backdoor_ttl_cmd,
4307 "network A.B.C.D/M backdoor pathlimit <0-255>",
4308 "Specify a network to announce via BGP\n"
4309 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\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 (bgp_network_mask,
4314 bgp_network_mask_ttl_cmd,
4315 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4316 "Specify a network to announce via BGP\n"
4317 "Network number\n"
4318 "Network mask\n"
4319 "Network mask\n"
4320 "AS-Path hopcount limit attribute\n"
4321 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4322ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4323 bgp_network_mask_backdoor_ttl_cmd,
4324 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4325 "Specify a network to announce via BGP\n"
4326 "Network number\n"
4327 "Network mask\n"
4328 "Network mask\n"
4329 "Specify a BGP backdoor route\n"
4330 "AS-Path hopcount limit attribute\n"
4331 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4332ALIAS_DEPRECATED (bgp_network_mask_natural,
4333 bgp_network_mask_natural_ttl_cmd,
4334 "network A.B.C.D pathlimit <0-255>",
4335 "Specify a network to announce via BGP\n"
4336 "Network number\n"
4337 "AS-Path hopcount limit attribute\n"
4338 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4339ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4340 bgp_network_mask_natural_backdoor_ttl_cmd,
4341 "network A.B.C.D backdoor pathlimit (1-255>",
4342 "Specify a network to announce via BGP\n"
4343 "Network number\n"
4344 "Specify a BGP backdoor route\n"
4345 "AS-Path hopcount limit attribute\n"
4346 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4347ALIAS_DEPRECATED (no_bgp_network,
4348 no_bgp_network_ttl_cmd,
4349 "no network A.B.C.D/M pathlimit <0-255>",
4350 NO_STR
4351 "Specify a network to announce via BGP\n"
4352 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4353 "AS-Path hopcount limit attribute\n"
4354 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4355ALIAS_DEPRECATED (no_bgp_network,
4356 no_bgp_network_backdoor_ttl_cmd,
4357 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4358 NO_STR
4359 "Specify a network to announce via BGP\n"
4360 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4361 "Specify a BGP backdoor route\n"
4362 "AS-Path hopcount limit attribute\n"
4363 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4364ALIAS_DEPRECATED (no_bgp_network,
4365 no_bgp_network_mask_ttl_cmd,
4366 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4367 NO_STR
4368 "Specify a network to announce via BGP\n"
4369 "Network number\n"
4370 "Network mask\n"
4371 "Network mask\n"
4372 "AS-Path hopcount limit attribute\n"
4373 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4374ALIAS_DEPRECATED (no_bgp_network_mask,
4375 no_bgp_network_mask_backdoor_ttl_cmd,
4376 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4377 NO_STR
4378 "Specify a network to announce via BGP\n"
4379 "Network number\n"
4380 "Network mask\n"
4381 "Network mask\n"
4382 "Specify a BGP backdoor route\n"
4383 "AS-Path hopcount limit attribute\n"
4384 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4385ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4386 no_bgp_network_mask_natural_ttl_cmd,
4387 "no network A.B.C.D pathlimit <0-255>",
4388 NO_STR
4389 "Specify a network to announce via BGP\n"
4390 "Network number\n"
4391 "AS-Path hopcount limit attribute\n"
4392 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4393ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4394 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4395 "no network A.B.C.D backdoor pathlimit <0-255>",
4396 NO_STR
4397 "Specify a network to announce via BGP\n"
4398 "Network number\n"
4399 "Specify a BGP backdoor route\n"
4400 "AS-Path hopcount limit attribute\n"
4401 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004402#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004403ALIAS_DEPRECATED (ipv6_bgp_network,
4404 ipv6_bgp_network_ttl_cmd,
4405 "network X:X::X:X/M pathlimit <0-255>",
4406 "Specify a network to announce via BGP\n"
4407 "IPv6 prefix <network>/<length>\n"
4408 "AS-Path hopcount limit attribute\n"
4409 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4410ALIAS_DEPRECATED (no_ipv6_bgp_network,
4411 no_ipv6_bgp_network_ttl_cmd,
4412 "no network X:X::X:X/M pathlimit <0-255>",
4413 NO_STR
4414 "Specify a network to announce via BGP\n"
4415 "IPv6 prefix <network>/<length>\n"
4416 "AS-Path hopcount limit attribute\n"
4417 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004418#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004419
4420/* Aggreagete address:
4421
4422 advertise-map Set condition to advertise attribute
4423 as-set Generate AS set path information
4424 attribute-map Set attributes of aggregate
4425 route-map Set parameters of aggregate
4426 summary-only Filter more specific routes from updates
4427 suppress-map Conditionally filter more specific routes from updates
4428 <cr>
4429 */
4430struct bgp_aggregate
4431{
4432 /* Summary-only flag. */
4433 u_char summary_only;
4434
4435 /* AS set generation. */
4436 u_char as_set;
4437
4438 /* Route-map for aggregated route. */
4439 struct route_map *map;
4440
4441 /* Suppress-count. */
4442 unsigned long count;
4443
4444 /* SAFI configuration. */
4445 safi_t safi;
4446};
4447
paul94f2b392005-06-28 12:44:16 +00004448static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004449bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004450{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004451 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004452}
4453
paul94f2b392005-06-28 12:44:16 +00004454static void
paul718e3742002-12-13 20:15:29 +00004455bgp_aggregate_free (struct bgp_aggregate *aggregate)
4456{
4457 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4458}
4459
paul94f2b392005-06-28 12:44:16 +00004460static void
paul718e3742002-12-13 20:15:29 +00004461bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4462 afi_t afi, safi_t safi, struct bgp_info *del,
4463 struct bgp_aggregate *aggregate)
4464{
4465 struct bgp_table *table;
4466 struct bgp_node *top;
4467 struct bgp_node *rn;
4468 u_char origin;
4469 struct aspath *aspath = NULL;
4470 struct aspath *asmerge = NULL;
4471 struct community *community = NULL;
4472 struct community *commerge = NULL;
4473 struct in_addr nexthop;
4474 u_int32_t med = 0;
4475 struct bgp_info *ri;
4476 struct bgp_info *new;
4477 int first = 1;
4478 unsigned long match = 0;
4479
4480 /* Record adding route's nexthop and med. */
4481 if (rinew)
4482 {
4483 nexthop = rinew->attr->nexthop;
4484 med = rinew->attr->med;
4485 }
4486
4487 /* ORIGIN attribute: If at least one route among routes that are
4488 aggregated has ORIGIN with the value INCOMPLETE, then the
4489 aggregated route must have the ORIGIN attribute with the value
4490 INCOMPLETE. Otherwise, if at least one route among routes that
4491 are aggregated has ORIGIN with the value EGP, then the aggregated
4492 route must have the origin attribute with the value EGP. In all
4493 other case the value of the ORIGIN attribute of the aggregated
4494 route is INTERNAL. */
4495 origin = BGP_ORIGIN_IGP;
4496
4497 table = bgp->rib[afi][safi];
4498
4499 top = bgp_node_get (table, p);
4500 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4501 if (rn->p.prefixlen > p->prefixlen)
4502 {
4503 match = 0;
4504
4505 for (ri = rn->info; ri; ri = ri->next)
4506 {
4507 if (BGP_INFO_HOLDDOWN (ri))
4508 continue;
4509
4510 if (del && ri == del)
4511 continue;
4512
4513 if (! rinew && first)
4514 {
4515 nexthop = ri->attr->nexthop;
4516 med = ri->attr->med;
4517 first = 0;
4518 }
4519
4520#ifdef AGGREGATE_NEXTHOP_CHECK
4521 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4522 || ri->attr->med != med)
4523 {
4524 if (aspath)
4525 aspath_free (aspath);
4526 if (community)
4527 community_free (community);
4528 bgp_unlock_node (rn);
4529 bgp_unlock_node (top);
4530 return;
4531 }
4532#endif /* AGGREGATE_NEXTHOP_CHECK */
4533
4534 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4535 {
4536 if (aggregate->summary_only)
4537 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004538 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004539 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004540 match++;
4541 }
4542
4543 aggregate->count++;
4544
4545 if (aggregate->as_set)
4546 {
4547 if (origin < ri->attr->origin)
4548 origin = ri->attr->origin;
4549
4550 if (aspath)
4551 {
4552 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4553 aspath_free (aspath);
4554 aspath = asmerge;
4555 }
4556 else
4557 aspath = aspath_dup (ri->attr->aspath);
4558
4559 if (ri->attr->community)
4560 {
4561 if (community)
4562 {
4563 commerge = community_merge (community,
4564 ri->attr->community);
4565 community = community_uniq_sort (commerge);
4566 community_free (commerge);
4567 }
4568 else
4569 community = community_dup (ri->attr->community);
4570 }
4571 }
4572 }
4573 }
4574 if (match)
4575 bgp_process (bgp, rn, afi, safi);
4576 }
4577 bgp_unlock_node (top);
4578
4579 if (rinew)
4580 {
4581 aggregate->count++;
4582
4583 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004584 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004585
4586 if (aggregate->as_set)
4587 {
4588 if (origin < rinew->attr->origin)
4589 origin = rinew->attr->origin;
4590
4591 if (aspath)
4592 {
4593 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4594 aspath_free (aspath);
4595 aspath = asmerge;
4596 }
4597 else
4598 aspath = aspath_dup (rinew->attr->aspath);
4599
4600 if (rinew->attr->community)
4601 {
4602 if (community)
4603 {
4604 commerge = community_merge (community,
4605 rinew->attr->community);
4606 community = community_uniq_sort (commerge);
4607 community_free (commerge);
4608 }
4609 else
4610 community = community_dup (rinew->attr->community);
4611 }
4612 }
4613 }
4614
4615 if (aggregate->count > 0)
4616 {
4617 rn = bgp_node_get (table, p);
4618 new = bgp_info_new ();
4619 new->type = ZEBRA_ROUTE_BGP;
4620 new->sub_type = BGP_ROUTE_AGGREGATE;
4621 new->peer = bgp->peer_self;
4622 SET_FLAG (new->flags, BGP_INFO_VALID);
4623 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004624 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004625
4626 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004627 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004628 bgp_process (bgp, rn, afi, safi);
4629 }
4630 else
4631 {
4632 if (aspath)
4633 aspath_free (aspath);
4634 if (community)
4635 community_free (community);
4636 }
4637}
4638
4639void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4640 struct bgp_aggregate *);
4641
4642void
4643bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4644 struct bgp_info *ri, afi_t afi, safi_t safi)
4645{
4646 struct bgp_node *child;
4647 struct bgp_node *rn;
4648 struct bgp_aggregate *aggregate;
4649
4650 /* MPLS-VPN aggregation is not yet supported. */
4651 if (safi == SAFI_MPLS_VPN)
4652 return;
4653
4654 if (p->prefixlen == 0)
4655 return;
4656
4657 if (BGP_INFO_HOLDDOWN (ri))
4658 return;
4659
4660 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4661
4662 /* Aggregate address configuration check. */
4663 for (rn = child; rn; rn = rn->parent)
4664 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4665 {
4666 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004667 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004668 }
4669 bgp_unlock_node (child);
4670}
4671
4672void
4673bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4674 struct bgp_info *del, afi_t afi, safi_t safi)
4675{
4676 struct bgp_node *child;
4677 struct bgp_node *rn;
4678 struct bgp_aggregate *aggregate;
4679
4680 /* MPLS-VPN aggregation is not yet supported. */
4681 if (safi == SAFI_MPLS_VPN)
4682 return;
4683
4684 if (p->prefixlen == 0)
4685 return;
4686
4687 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4688
4689 /* Aggregate address configuration check. */
4690 for (rn = child; rn; rn = rn->parent)
4691 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4692 {
4693 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004694 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004695 }
4696 bgp_unlock_node (child);
4697}
4698
paul94f2b392005-06-28 12:44:16 +00004699static void
paul718e3742002-12-13 20:15:29 +00004700bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4701 struct bgp_aggregate *aggregate)
4702{
4703 struct bgp_table *table;
4704 struct bgp_node *top;
4705 struct bgp_node *rn;
4706 struct bgp_info *new;
4707 struct bgp_info *ri;
4708 unsigned long match;
4709 u_char origin = BGP_ORIGIN_IGP;
4710 struct aspath *aspath = NULL;
4711 struct aspath *asmerge = NULL;
4712 struct community *community = NULL;
4713 struct community *commerge = NULL;
4714
4715 table = bgp->rib[afi][safi];
4716
4717 /* Sanity check. */
4718 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4719 return;
4720 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4721 return;
4722
4723 /* If routes exists below this node, generate aggregate routes. */
4724 top = bgp_node_get (table, p);
4725 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4726 if (rn->p.prefixlen > p->prefixlen)
4727 {
4728 match = 0;
4729
4730 for (ri = rn->info; ri; ri = ri->next)
4731 {
4732 if (BGP_INFO_HOLDDOWN (ri))
4733 continue;
4734
4735 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4736 {
4737 /* summary-only aggregate route suppress aggregated
4738 route announcement. */
4739 if (aggregate->summary_only)
4740 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004741 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004742 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004743 match++;
4744 }
4745 /* as-set aggregate route generate origin, as path,
4746 community aggregation. */
4747 if (aggregate->as_set)
4748 {
4749 if (origin < ri->attr->origin)
4750 origin = ri->attr->origin;
4751
4752 if (aspath)
4753 {
4754 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4755 aspath_free (aspath);
4756 aspath = asmerge;
4757 }
4758 else
4759 aspath = aspath_dup (ri->attr->aspath);
4760
4761 if (ri->attr->community)
4762 {
4763 if (community)
4764 {
4765 commerge = community_merge (community,
4766 ri->attr->community);
4767 community = community_uniq_sort (commerge);
4768 community_free (commerge);
4769 }
4770 else
4771 community = community_dup (ri->attr->community);
4772 }
4773 }
4774 aggregate->count++;
4775 }
4776 }
4777
4778 /* If this node is suppressed, process the change. */
4779 if (match)
4780 bgp_process (bgp, rn, afi, safi);
4781 }
4782 bgp_unlock_node (top);
4783
4784 /* Add aggregate route to BGP table. */
4785 if (aggregate->count)
4786 {
4787 rn = bgp_node_get (table, p);
4788
4789 new = bgp_info_new ();
4790 new->type = ZEBRA_ROUTE_BGP;
4791 new->sub_type = BGP_ROUTE_AGGREGATE;
4792 new->peer = bgp->peer_self;
4793 SET_FLAG (new->flags, BGP_INFO_VALID);
4794 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004795 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004796
4797 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004798 bgp_unlock_node (rn);
4799
paul718e3742002-12-13 20:15:29 +00004800 /* Process change. */
4801 bgp_process (bgp, rn, afi, safi);
4802 }
4803}
4804
4805void
4806bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4807 safi_t safi, struct bgp_aggregate *aggregate)
4808{
4809 struct bgp_table *table;
4810 struct bgp_node *top;
4811 struct bgp_node *rn;
4812 struct bgp_info *ri;
4813 unsigned long match;
4814
4815 table = bgp->rib[afi][safi];
4816
4817 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4818 return;
4819 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4820 return;
4821
4822 /* If routes exists below this node, generate aggregate routes. */
4823 top = bgp_node_get (table, p);
4824 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4825 if (rn->p.prefixlen > p->prefixlen)
4826 {
4827 match = 0;
4828
4829 for (ri = rn->info; ri; ri = ri->next)
4830 {
4831 if (BGP_INFO_HOLDDOWN (ri))
4832 continue;
4833
4834 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4835 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004836 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004837 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004838 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004839
Paul Jakmafb982c22007-05-04 20:15:47 +00004840 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004841 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004842 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004843 match++;
4844 }
4845 }
4846 aggregate->count--;
4847 }
4848 }
4849
Paul Jakmafb982c22007-05-04 20:15:47 +00004850 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004851 if (match)
4852 bgp_process (bgp, rn, afi, safi);
4853 }
4854 bgp_unlock_node (top);
4855
4856 /* Delete aggregate route from BGP table. */
4857 rn = bgp_node_get (table, p);
4858
4859 for (ri = rn->info; ri; ri = ri->next)
4860 if (ri->peer == bgp->peer_self
4861 && ri->type == ZEBRA_ROUTE_BGP
4862 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4863 break;
4864
4865 /* Withdraw static BGP route from routing table. */
4866 if (ri)
4867 {
paul718e3742002-12-13 20:15:29 +00004868 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004869 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004870 }
4871
4872 /* Unlock bgp_node_lookup. */
4873 bgp_unlock_node (rn);
4874}
4875
4876/* Aggregate route attribute. */
4877#define AGGREGATE_SUMMARY_ONLY 1
4878#define AGGREGATE_AS_SET 1
4879
paul94f2b392005-06-28 12:44:16 +00004880static int
Robert Baysf6269b42010-08-05 10:26:28 -07004881bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4882 afi_t afi, safi_t safi)
4883{
4884 int ret;
4885 struct prefix p;
4886 struct bgp_node *rn;
4887 struct bgp *bgp;
4888 struct bgp_aggregate *aggregate;
4889
4890 /* Convert string to prefix structure. */
4891 ret = str2prefix (prefix_str, &p);
4892 if (!ret)
4893 {
4894 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4895 return CMD_WARNING;
4896 }
4897 apply_mask (&p);
4898
4899 /* Get BGP structure. */
4900 bgp = vty->index;
4901
4902 /* Old configuration check. */
4903 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4904 if (! rn)
4905 {
4906 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4907 VTY_NEWLINE);
4908 return CMD_WARNING;
4909 }
4910
4911 aggregate = rn->info;
4912 if (aggregate->safi & SAFI_UNICAST)
4913 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4914 if (aggregate->safi & SAFI_MULTICAST)
4915 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4916
4917 /* Unlock aggregate address configuration. */
4918 rn->info = NULL;
4919 bgp_aggregate_free (aggregate);
4920 bgp_unlock_node (rn);
4921 bgp_unlock_node (rn);
4922
4923 return CMD_SUCCESS;
4924}
4925
4926static int
4927bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004928 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004929 u_char summary_only, u_char as_set)
4930{
4931 int ret;
4932 struct prefix p;
4933 struct bgp_node *rn;
4934 struct bgp *bgp;
4935 struct bgp_aggregate *aggregate;
4936
4937 /* Convert string to prefix structure. */
4938 ret = str2prefix (prefix_str, &p);
4939 if (!ret)
4940 {
4941 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4942 return CMD_WARNING;
4943 }
4944 apply_mask (&p);
4945
4946 /* Get BGP structure. */
4947 bgp = vty->index;
4948
4949 /* Old configuration check. */
4950 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4951
4952 if (rn->info)
4953 {
4954 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004955 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004956 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4957 if (ret)
4958 {
Robert Bays368473f2010-08-05 10:26:29 -07004959 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4960 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004961 return CMD_WARNING;
4962 }
paul718e3742002-12-13 20:15:29 +00004963 }
4964
4965 /* Make aggregate address structure. */
4966 aggregate = bgp_aggregate_new ();
4967 aggregate->summary_only = summary_only;
4968 aggregate->as_set = as_set;
4969 aggregate->safi = safi;
4970 rn->info = aggregate;
4971
4972 /* Aggregate address insert into BGP routing table. */
4973 if (safi & SAFI_UNICAST)
4974 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4975 if (safi & SAFI_MULTICAST)
4976 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4977
4978 return CMD_SUCCESS;
4979}
4980
paul718e3742002-12-13 20:15:29 +00004981DEFUN (aggregate_address,
4982 aggregate_address_cmd,
4983 "aggregate-address A.B.C.D/M",
4984 "Configure BGP aggregate entries\n"
4985 "Aggregate prefix\n")
4986{
4987 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4988}
4989
4990DEFUN (aggregate_address_mask,
4991 aggregate_address_mask_cmd,
4992 "aggregate-address A.B.C.D A.B.C.D",
4993 "Configure BGP aggregate entries\n"
4994 "Aggregate address\n"
4995 "Aggregate mask\n")
4996{
4997 int ret;
4998 char prefix_str[BUFSIZ];
4999
5000 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5001
5002 if (! ret)
5003 {
5004 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5005 return CMD_WARNING;
5006 }
5007
5008 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5009 0, 0);
5010}
5011
5012DEFUN (aggregate_address_summary_only,
5013 aggregate_address_summary_only_cmd,
5014 "aggregate-address A.B.C.D/M summary-only",
5015 "Configure BGP aggregate entries\n"
5016 "Aggregate prefix\n"
5017 "Filter more specific routes from updates\n")
5018{
5019 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5020 AGGREGATE_SUMMARY_ONLY, 0);
5021}
5022
5023DEFUN (aggregate_address_mask_summary_only,
5024 aggregate_address_mask_summary_only_cmd,
5025 "aggregate-address A.B.C.D A.B.C.D summary-only",
5026 "Configure BGP aggregate entries\n"
5027 "Aggregate address\n"
5028 "Aggregate mask\n"
5029 "Filter more specific routes from updates\n")
5030{
5031 int ret;
5032 char prefix_str[BUFSIZ];
5033
5034 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5035
5036 if (! ret)
5037 {
5038 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5039 return CMD_WARNING;
5040 }
5041
5042 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5043 AGGREGATE_SUMMARY_ONLY, 0);
5044}
5045
5046DEFUN (aggregate_address_as_set,
5047 aggregate_address_as_set_cmd,
5048 "aggregate-address A.B.C.D/M as-set",
5049 "Configure BGP aggregate entries\n"
5050 "Aggregate prefix\n"
5051 "Generate AS set path information\n")
5052{
5053 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5054 0, AGGREGATE_AS_SET);
5055}
5056
5057DEFUN (aggregate_address_mask_as_set,
5058 aggregate_address_mask_as_set_cmd,
5059 "aggregate-address A.B.C.D A.B.C.D as-set",
5060 "Configure BGP aggregate entries\n"
5061 "Aggregate address\n"
5062 "Aggregate mask\n"
5063 "Generate AS set path information\n")
5064{
5065 int ret;
5066 char prefix_str[BUFSIZ];
5067
5068 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5069
5070 if (! ret)
5071 {
5072 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5073 return CMD_WARNING;
5074 }
5075
5076 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5077 0, AGGREGATE_AS_SET);
5078}
5079
5080
5081DEFUN (aggregate_address_as_set_summary,
5082 aggregate_address_as_set_summary_cmd,
5083 "aggregate-address A.B.C.D/M as-set summary-only",
5084 "Configure BGP aggregate entries\n"
5085 "Aggregate prefix\n"
5086 "Generate AS set path information\n"
5087 "Filter more specific routes from updates\n")
5088{
5089 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5090 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5091}
5092
5093ALIAS (aggregate_address_as_set_summary,
5094 aggregate_address_summary_as_set_cmd,
5095 "aggregate-address A.B.C.D/M summary-only as-set",
5096 "Configure BGP aggregate entries\n"
5097 "Aggregate prefix\n"
5098 "Filter more specific routes from updates\n"
5099 "Generate AS set path information\n")
5100
5101DEFUN (aggregate_address_mask_as_set_summary,
5102 aggregate_address_mask_as_set_summary_cmd,
5103 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5104 "Configure BGP aggregate entries\n"
5105 "Aggregate address\n"
5106 "Aggregate mask\n"
5107 "Generate AS set path information\n"
5108 "Filter more specific routes from updates\n")
5109{
5110 int ret;
5111 char prefix_str[BUFSIZ];
5112
5113 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5114
5115 if (! ret)
5116 {
5117 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5118 return CMD_WARNING;
5119 }
5120
5121 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5122 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5123}
5124
5125ALIAS (aggregate_address_mask_as_set_summary,
5126 aggregate_address_mask_summary_as_set_cmd,
5127 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5128 "Configure BGP aggregate entries\n"
5129 "Aggregate address\n"
5130 "Aggregate mask\n"
5131 "Filter more specific routes from updates\n"
5132 "Generate AS set path information\n")
5133
5134DEFUN (no_aggregate_address,
5135 no_aggregate_address_cmd,
5136 "no aggregate-address A.B.C.D/M",
5137 NO_STR
5138 "Configure BGP aggregate entries\n"
5139 "Aggregate prefix\n")
5140{
5141 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5142}
5143
5144ALIAS (no_aggregate_address,
5145 no_aggregate_address_summary_only_cmd,
5146 "no aggregate-address A.B.C.D/M summary-only",
5147 NO_STR
5148 "Configure BGP aggregate entries\n"
5149 "Aggregate prefix\n"
5150 "Filter more specific routes from updates\n")
5151
5152ALIAS (no_aggregate_address,
5153 no_aggregate_address_as_set_cmd,
5154 "no aggregate-address A.B.C.D/M as-set",
5155 NO_STR
5156 "Configure BGP aggregate entries\n"
5157 "Aggregate prefix\n"
5158 "Generate AS set path information\n")
5159
5160ALIAS (no_aggregate_address,
5161 no_aggregate_address_as_set_summary_cmd,
5162 "no aggregate-address A.B.C.D/M as-set summary-only",
5163 NO_STR
5164 "Configure BGP aggregate entries\n"
5165 "Aggregate prefix\n"
5166 "Generate AS set path information\n"
5167 "Filter more specific routes from updates\n")
5168
5169ALIAS (no_aggregate_address,
5170 no_aggregate_address_summary_as_set_cmd,
5171 "no aggregate-address A.B.C.D/M summary-only as-set",
5172 NO_STR
5173 "Configure BGP aggregate entries\n"
5174 "Aggregate prefix\n"
5175 "Filter more specific routes from updates\n"
5176 "Generate AS set path information\n")
5177
5178DEFUN (no_aggregate_address_mask,
5179 no_aggregate_address_mask_cmd,
5180 "no aggregate-address A.B.C.D A.B.C.D",
5181 NO_STR
5182 "Configure BGP aggregate entries\n"
5183 "Aggregate address\n"
5184 "Aggregate mask\n")
5185{
5186 int ret;
5187 char prefix_str[BUFSIZ];
5188
5189 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5190
5191 if (! ret)
5192 {
5193 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5194 return CMD_WARNING;
5195 }
5196
5197 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5198}
5199
5200ALIAS (no_aggregate_address_mask,
5201 no_aggregate_address_mask_summary_only_cmd,
5202 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5203 NO_STR
5204 "Configure BGP aggregate entries\n"
5205 "Aggregate address\n"
5206 "Aggregate mask\n"
5207 "Filter more specific routes from updates\n")
5208
5209ALIAS (no_aggregate_address_mask,
5210 no_aggregate_address_mask_as_set_cmd,
5211 "no aggregate-address A.B.C.D A.B.C.D as-set",
5212 NO_STR
5213 "Configure BGP aggregate entries\n"
5214 "Aggregate address\n"
5215 "Aggregate mask\n"
5216 "Generate AS set path information\n")
5217
5218ALIAS (no_aggregate_address_mask,
5219 no_aggregate_address_mask_as_set_summary_cmd,
5220 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5221 NO_STR
5222 "Configure BGP aggregate entries\n"
5223 "Aggregate address\n"
5224 "Aggregate mask\n"
5225 "Generate AS set path information\n"
5226 "Filter more specific routes from updates\n")
5227
5228ALIAS (no_aggregate_address_mask,
5229 no_aggregate_address_mask_summary_as_set_cmd,
5230 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5231 NO_STR
5232 "Configure BGP aggregate entries\n"
5233 "Aggregate address\n"
5234 "Aggregate mask\n"
5235 "Filter more specific routes from updates\n"
5236 "Generate AS set path information\n")
5237
5238#ifdef HAVE_IPV6
5239DEFUN (ipv6_aggregate_address,
5240 ipv6_aggregate_address_cmd,
5241 "aggregate-address X:X::X:X/M",
5242 "Configure BGP aggregate entries\n"
5243 "Aggregate prefix\n")
5244{
5245 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5246}
5247
5248DEFUN (ipv6_aggregate_address_summary_only,
5249 ipv6_aggregate_address_summary_only_cmd,
5250 "aggregate-address X:X::X:X/M summary-only",
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate prefix\n"
5253 "Filter more specific routes from updates\n")
5254{
5255 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5256 AGGREGATE_SUMMARY_ONLY, 0);
5257}
5258
5259DEFUN (no_ipv6_aggregate_address,
5260 no_ipv6_aggregate_address_cmd,
5261 "no aggregate-address X:X::X:X/M",
5262 NO_STR
5263 "Configure BGP aggregate entries\n"
5264 "Aggregate prefix\n")
5265{
5266 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5267}
5268
5269DEFUN (no_ipv6_aggregate_address_summary_only,
5270 no_ipv6_aggregate_address_summary_only_cmd,
5271 "no aggregate-address X:X::X:X/M summary-only",
5272 NO_STR
5273 "Configure BGP aggregate entries\n"
5274 "Aggregate prefix\n"
5275 "Filter more specific routes from updates\n")
5276{
5277 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5278}
5279
5280ALIAS (ipv6_aggregate_address,
5281 old_ipv6_aggregate_address_cmd,
5282 "ipv6 bgp aggregate-address X:X::X:X/M",
5283 IPV6_STR
5284 BGP_STR
5285 "Configure BGP aggregate entries\n"
5286 "Aggregate prefix\n")
5287
5288ALIAS (ipv6_aggregate_address_summary_only,
5289 old_ipv6_aggregate_address_summary_only_cmd,
5290 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5291 IPV6_STR
5292 BGP_STR
5293 "Configure BGP aggregate entries\n"
5294 "Aggregate prefix\n"
5295 "Filter more specific routes from updates\n")
5296
5297ALIAS (no_ipv6_aggregate_address,
5298 old_no_ipv6_aggregate_address_cmd,
5299 "no ipv6 bgp aggregate-address X:X::X:X/M",
5300 NO_STR
5301 IPV6_STR
5302 BGP_STR
5303 "Configure BGP aggregate entries\n"
5304 "Aggregate prefix\n")
5305
5306ALIAS (no_ipv6_aggregate_address_summary_only,
5307 old_no_ipv6_aggregate_address_summary_only_cmd,
5308 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5309 NO_STR
5310 IPV6_STR
5311 BGP_STR
5312 "Configure BGP aggregate entries\n"
5313 "Aggregate prefix\n"
5314 "Filter more specific routes from updates\n")
5315#endif /* HAVE_IPV6 */
5316
5317/* Redistribute route treatment. */
5318void
5319bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5320 u_int32_t metric, u_char type)
5321{
5322 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005323 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005324 struct bgp_info *new;
5325 struct bgp_info *bi;
5326 struct bgp_info info;
5327 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005328 struct attr attr = { 0 };
5329 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005330 struct attr *new_attr;
5331 afi_t afi;
5332 int ret;
5333
5334 /* Make default attribute. */
5335 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5336 if (nexthop)
5337 attr.nexthop = *nexthop;
5338
5339 attr.med = metric;
5340 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5341
paul1eb8ef22005-04-07 07:30:20 +00005342 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005343 {
5344 afi = family2afi (p->family);
5345
5346 if (bgp->redist[afi][type])
5347 {
5348 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005349 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005350
5351 if (bgp->redist_metric_flag[afi][type])
5352 attr_new.med = bgp->redist_metric[afi][type];
5353
5354 /* Apply route-map. */
5355 if (bgp->rmap[afi][type].map)
5356 {
5357 info.peer = bgp->peer_self;
5358 info.attr = &attr_new;
5359
paulfee0f4c2004-09-13 05:12:46 +00005360 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5361
paul718e3742002-12-13 20:15:29 +00005362 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5363 &info);
paulfee0f4c2004-09-13 05:12:46 +00005364
5365 bgp->peer_self->rmap_type = 0;
5366
paul718e3742002-12-13 20:15:29 +00005367 if (ret == RMAP_DENYMATCH)
5368 {
5369 /* Free uninterned attribute. */
5370 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005371 bgp_attr_extra_free (&attr_new);
5372
paul718e3742002-12-13 20:15:29 +00005373 /* Unintern original. */
5374 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005375 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005376 bgp_redistribute_delete (p, type);
5377 return;
5378 }
5379 }
5380
Paul Jakmafb982c22007-05-04 20:15:47 +00005381 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5382 afi, SAFI_UNICAST, p, NULL);
5383
paul718e3742002-12-13 20:15:29 +00005384 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005385 bgp_attr_extra_free (&attr_new);
5386
paul718e3742002-12-13 20:15:29 +00005387 for (bi = bn->info; bi; bi = bi->next)
5388 if (bi->peer == bgp->peer_self
5389 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5390 break;
5391
5392 if (bi)
5393 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005394 if (attrhash_cmp (bi->attr, new_attr) &&
5395 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005396 {
5397 bgp_attr_unintern (new_attr);
5398 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005399 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005400 bgp_unlock_node (bn);
5401 return;
5402 }
5403 else
5404 {
5405 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005406 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005407
5408 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005409 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5410 bgp_info_restore(bn, bi);
5411 else
5412 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005413 bgp_attr_unintern (bi->attr);
5414 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005415 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005416
5417 /* Process change. */
5418 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5419 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5420 bgp_unlock_node (bn);
5421 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005422 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005423 return;
5424 }
5425 }
5426
5427 new = bgp_info_new ();
5428 new->type = type;
5429 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5430 new->peer = bgp->peer_self;
5431 SET_FLAG (new->flags, BGP_INFO_VALID);
5432 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005433 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005434
5435 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5436 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005437 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005438 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5439 }
5440 }
5441
5442 /* Unintern original. */
5443 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005444 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005445}
5446
5447void
5448bgp_redistribute_delete (struct prefix *p, u_char type)
5449{
5450 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005451 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005452 afi_t afi;
5453 struct bgp_node *rn;
5454 struct bgp_info *ri;
5455
paul1eb8ef22005-04-07 07:30:20 +00005456 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005457 {
5458 afi = family2afi (p->family);
5459
5460 if (bgp->redist[afi][type])
5461 {
paulfee0f4c2004-09-13 05:12:46 +00005462 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005463
5464 for (ri = rn->info; ri; ri = ri->next)
5465 if (ri->peer == bgp->peer_self
5466 && ri->type == type)
5467 break;
5468
5469 if (ri)
5470 {
5471 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005472 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005473 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005474 }
5475 bgp_unlock_node (rn);
5476 }
5477 }
5478}
5479
5480/* Withdraw specified route type's route. */
5481void
5482bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5483{
5484 struct bgp_node *rn;
5485 struct bgp_info *ri;
5486 struct bgp_table *table;
5487
5488 table = bgp->rib[afi][SAFI_UNICAST];
5489
5490 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5491 {
5492 for (ri = rn->info; ri; ri = ri->next)
5493 if (ri->peer == bgp->peer_self
5494 && ri->type == type)
5495 break;
5496
5497 if (ri)
5498 {
5499 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005500 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005501 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005502 }
5503 }
5504}
5505
5506/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005507static void
paul718e3742002-12-13 20:15:29 +00005508route_vty_out_route (struct prefix *p, struct vty *vty)
5509{
5510 int len;
5511 u_int32_t destination;
5512 char buf[BUFSIZ];
5513
5514 if (p->family == AF_INET)
5515 {
5516 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5517 destination = ntohl (p->u.prefix4.s_addr);
5518
5519 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5520 || (IN_CLASSB (destination) && p->prefixlen == 16)
5521 || (IN_CLASSA (destination) && p->prefixlen == 8)
5522 || p->u.prefix4.s_addr == 0)
5523 {
5524 /* When mask is natural, mask is not displayed. */
5525 }
5526 else
5527 len += vty_out (vty, "/%d", p->prefixlen);
5528 }
5529 else
5530 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5531 p->prefixlen);
5532
5533 len = 17 - len;
5534 if (len < 1)
5535 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5536 else
5537 vty_out (vty, "%*s", len, " ");
5538}
5539
paul718e3742002-12-13 20:15:29 +00005540enum bgp_display_type
5541{
5542 normal_list,
5543};
5544
paulb40d9392005-08-22 22:34:41 +00005545/* Print the short form route status for a bgp_info */
5546static void
5547route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005548{
paulb40d9392005-08-22 22:34:41 +00005549 /* Route status display. */
5550 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5551 vty_out (vty, "R");
5552 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005553 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005554 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005555 vty_out (vty, "s");
5556 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5557 vty_out (vty, "*");
5558 else
5559 vty_out (vty, " ");
5560
5561 /* Selected */
5562 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5563 vty_out (vty, "h");
5564 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5565 vty_out (vty, "d");
5566 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5567 vty_out (vty, ">");
5568 else
5569 vty_out (vty, " ");
5570
5571 /* Internal route. */
5572 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5573 vty_out (vty, "i");
5574 else
paulb40d9392005-08-22 22:34:41 +00005575 vty_out (vty, " ");
5576}
5577
5578/* called from terminal list command */
5579void
5580route_vty_out (struct vty *vty, struct prefix *p,
5581 struct bgp_info *binfo, int display, safi_t safi)
5582{
5583 struct attr *attr;
5584
5585 /* short status lead text */
5586 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005587
5588 /* print prefix and mask */
5589 if (! display)
5590 route_vty_out_route (p, vty);
5591 else
5592 vty_out (vty, "%*s", 17, " ");
5593
5594 /* Print attribute */
5595 attr = binfo->attr;
5596 if (attr)
5597 {
5598 if (p->family == AF_INET)
5599 {
5600 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005601 vty_out (vty, "%-16s",
5602 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005603 else
5604 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5605 }
5606#ifdef HAVE_IPV6
5607 else if (p->family == AF_INET6)
5608 {
5609 int len;
5610 char buf[BUFSIZ];
5611
5612 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005613 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5614 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005615 len = 16 - len;
5616 if (len < 1)
5617 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5618 else
5619 vty_out (vty, "%*s", len, " ");
5620 }
5621#endif /* HAVE_IPV6 */
5622
5623 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005624 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005625 else
5626 vty_out (vty, " ");
5627
5628 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005629 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005630 else
5631 vty_out (vty, " ");
5632
Paul Jakmafb982c22007-05-04 20:15:47 +00005633 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005634
Paul Jakmab2518c12006-05-12 23:48:40 +00005635 /* Print aspath */
5636 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005637 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005638
Paul Jakmab2518c12006-05-12 23:48:40 +00005639 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005640 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005641 }
paul718e3742002-12-13 20:15:29 +00005642 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005643}
5644
5645/* called from terminal list command */
5646void
5647route_vty_out_tmp (struct vty *vty, struct prefix *p,
5648 struct attr *attr, safi_t safi)
5649{
5650 /* Route status display. */
5651 vty_out (vty, "*");
5652 vty_out (vty, ">");
5653 vty_out (vty, " ");
5654
5655 /* print prefix and mask */
5656 route_vty_out_route (p, vty);
5657
5658 /* Print attribute */
5659 if (attr)
5660 {
5661 if (p->family == AF_INET)
5662 {
5663 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005664 vty_out (vty, "%-16s",
5665 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005666 else
5667 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5668 }
5669#ifdef HAVE_IPV6
5670 else if (p->family == AF_INET6)
5671 {
5672 int len;
5673 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005674
5675 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005676
5677 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005678 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5679 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005680 len = 16 - len;
5681 if (len < 1)
5682 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5683 else
5684 vty_out (vty, "%*s", len, " ");
5685 }
5686#endif /* HAVE_IPV6 */
5687
5688 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005689 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005690 else
5691 vty_out (vty, " ");
5692
5693 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005694 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005695 else
5696 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005697
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005698 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005699
Paul Jakmab2518c12006-05-12 23:48:40 +00005700 /* Print aspath */
5701 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005702 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005703
Paul Jakmab2518c12006-05-12 23:48:40 +00005704 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005705 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005706 }
paul718e3742002-12-13 20:15:29 +00005707
5708 vty_out (vty, "%s", VTY_NEWLINE);
5709}
5710
ajs5a646652004-11-05 01:25:55 +00005711void
paul718e3742002-12-13 20:15:29 +00005712route_vty_out_tag (struct vty *vty, struct prefix *p,
5713 struct bgp_info *binfo, int display, safi_t safi)
5714{
5715 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005716 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005717
5718 if (!binfo->extra)
5719 return;
5720
paulb40d9392005-08-22 22:34:41 +00005721 /* short status lead text */
5722 route_vty_short_status_out (vty, binfo);
5723
paul718e3742002-12-13 20:15:29 +00005724 /* print prefix and mask */
5725 if (! display)
5726 route_vty_out_route (p, vty);
5727 else
5728 vty_out (vty, "%*s", 17, " ");
5729
5730 /* Print attribute */
5731 attr = binfo->attr;
5732 if (attr)
5733 {
5734 if (p->family == AF_INET)
5735 {
5736 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005737 vty_out (vty, "%-16s",
5738 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005739 else
5740 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5741 }
5742#ifdef HAVE_IPV6
5743 else if (p->family == AF_INET6)
5744 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005745 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005746 char buf[BUFSIZ];
5747 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005748 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005749 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005750 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5751 buf, BUFSIZ));
5752 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005753 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005754 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5755 buf, BUFSIZ),
5756 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5757 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005758
5759 }
5760#endif /* HAVE_IPV6 */
5761 }
5762
Paul Jakmafb982c22007-05-04 20:15:47 +00005763 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005764
5765 vty_out (vty, "notag/%d", label);
5766
5767 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005768}
5769
5770/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005771static void
paul718e3742002-12-13 20:15:29 +00005772damp_route_vty_out (struct vty *vty, struct prefix *p,
5773 struct bgp_info *binfo, int display, safi_t safi)
5774{
5775 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005776 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005777 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005778
paulb40d9392005-08-22 22:34:41 +00005779 /* short status lead text */
5780 route_vty_short_status_out (vty, binfo);
5781
paul718e3742002-12-13 20:15:29 +00005782 /* print prefix and mask */
5783 if (! display)
5784 route_vty_out_route (p, vty);
5785 else
5786 vty_out (vty, "%*s", 17, " ");
5787
5788 len = vty_out (vty, "%s", binfo->peer->host);
5789 len = 17 - len;
5790 if (len < 1)
5791 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5792 else
5793 vty_out (vty, "%*s", len, " ");
5794
Chris Caputo50aef6f2009-06-23 06:06:49 +00005795 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005796
5797 /* Print attribute */
5798 attr = binfo->attr;
5799 if (attr)
5800 {
5801 /* Print aspath */
5802 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005803 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005804
5805 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005806 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005807 }
5808 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005809}
5810
paul718e3742002-12-13 20:15:29 +00005811/* flap route */
ajs5a646652004-11-05 01:25:55 +00005812static void
paul718e3742002-12-13 20:15:29 +00005813flap_route_vty_out (struct vty *vty, struct prefix *p,
5814 struct bgp_info *binfo, int display, safi_t safi)
5815{
5816 struct attr *attr;
5817 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005818 char timebuf[BGP_UPTIME_LEN];
5819 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005820
5821 if (!binfo->extra)
5822 return;
5823
5824 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005825
paulb40d9392005-08-22 22:34:41 +00005826 /* short status lead text */
5827 route_vty_short_status_out (vty, binfo);
5828
paul718e3742002-12-13 20:15:29 +00005829 /* print prefix and mask */
5830 if (! display)
5831 route_vty_out_route (p, vty);
5832 else
5833 vty_out (vty, "%*s", 17, " ");
5834
5835 len = vty_out (vty, "%s", binfo->peer->host);
5836 len = 16 - len;
5837 if (len < 1)
5838 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5839 else
5840 vty_out (vty, "%*s", len, " ");
5841
5842 len = vty_out (vty, "%d", bdi->flap);
5843 len = 5 - len;
5844 if (len < 1)
5845 vty_out (vty, " ");
5846 else
5847 vty_out (vty, "%*s ", len, " ");
5848
5849 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5850 timebuf, BGP_UPTIME_LEN));
5851
5852 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5853 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005854 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005855 else
5856 vty_out (vty, "%*s ", 8, " ");
5857
5858 /* Print attribute */
5859 attr = binfo->attr;
5860 if (attr)
5861 {
5862 /* Print aspath */
5863 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005864 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005865
5866 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005867 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005868 }
5869 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005870}
5871
paul94f2b392005-06-28 12:44:16 +00005872static void
paul718e3742002-12-13 20:15:29 +00005873route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5874 struct bgp_info *binfo, afi_t afi, safi_t safi)
5875{
5876 char buf[INET6_ADDRSTRLEN];
5877 char buf1[BUFSIZ];
5878 struct attr *attr;
5879 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005880#ifdef HAVE_CLOCK_MONOTONIC
5881 time_t tbuf;
5882#endif
paul718e3742002-12-13 20:15:29 +00005883
5884 attr = binfo->attr;
5885
5886 if (attr)
5887 {
5888 /* Line1 display AS-path, Aggregator */
5889 if (attr->aspath)
5890 {
5891 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005892 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005893 vty_out (vty, "Local");
5894 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005895 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005896 }
5897
paulb40d9392005-08-22 22:34:41 +00005898 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5899 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005900 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5901 vty_out (vty, ", (stale)");
5902 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005903 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005904 attr->extra->aggregator_as,
5905 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005906 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5907 vty_out (vty, ", (Received from a RR-client)");
5908 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5909 vty_out (vty, ", (Received from a RS-client)");
5910 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5911 vty_out (vty, ", (history entry)");
5912 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5913 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005914 vty_out (vty, "%s", VTY_NEWLINE);
5915
5916 /* Line2 display Next-hop, Neighbor, Router-id */
5917 if (p->family == AF_INET)
5918 {
5919 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005920 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005921 inet_ntoa (attr->nexthop));
5922 }
5923#ifdef HAVE_IPV6
5924 else
5925 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005926 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005927 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005928 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005929 buf, INET6_ADDRSTRLEN));
5930 }
5931#endif /* HAVE_IPV6 */
5932
5933 if (binfo->peer == bgp->peer_self)
5934 {
5935 vty_out (vty, " from %s ",
5936 p->family == AF_INET ? "0.0.0.0" : "::");
5937 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5938 }
5939 else
5940 {
5941 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5942 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005943 else if (binfo->extra && binfo->extra->igpmetric)
5944 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005945 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005946 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005947 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005948 else
5949 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5950 }
5951 vty_out (vty, "%s", VTY_NEWLINE);
5952
5953#ifdef HAVE_IPV6
5954 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005955 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005956 {
5957 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005958 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005959 buf, INET6_ADDRSTRLEN),
5960 VTY_NEWLINE);
5961 }
5962#endif /* HAVE_IPV6 */
5963
5964 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5965 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5966
5967 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005968 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005969
5970 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005971 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005972 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005973 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005974
Paul Jakmafb982c22007-05-04 20:15:47 +00005975 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005976 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005977
5978 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5979 vty_out (vty, ", valid");
5980
5981 if (binfo->peer != bgp->peer_self)
5982 {
5983 if (binfo->peer->as == binfo->peer->local_as)
5984 vty_out (vty, ", internal");
5985 else
5986 vty_out (vty, ", %s",
5987 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5988 }
5989 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5990 vty_out (vty, ", aggregated, local");
5991 else if (binfo->type != ZEBRA_ROUTE_BGP)
5992 vty_out (vty, ", sourced");
5993 else
5994 vty_out (vty, ", sourced, local");
5995
5996 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5997 vty_out (vty, ", atomic-aggregate");
5998
Josh Baileyde8d5df2011-07-20 20:46:01 -07005999 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
6000 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
6001 bgp_info_mpath_count (binfo)))
6002 vty_out (vty, ", multipath");
6003
paul718e3742002-12-13 20:15:29 +00006004 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
6005 vty_out (vty, ", best");
6006
6007 vty_out (vty, "%s", VTY_NEWLINE);
6008
6009 /* Line 4 display Community */
6010 if (attr->community)
6011 vty_out (vty, " Community: %s%s", attr->community->str,
6012 VTY_NEWLINE);
6013
6014 /* Line 5 display Extended-community */
6015 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00006016 vty_out (vty, " Extended Community: %s%s",
6017 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006018
6019 /* Line 6 display Originator, Cluster-id */
6020 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
6021 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6022 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006023 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006024 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006025 vty_out (vty, " Originator: %s",
6026 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006027
6028 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6029 {
6030 int i;
6031 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006032 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6033 vty_out (vty, "%s ",
6034 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006035 }
6036 vty_out (vty, "%s", VTY_NEWLINE);
6037 }
Paul Jakma41367172007-08-06 15:24:51 +00006038
Paul Jakmafb982c22007-05-04 20:15:47 +00006039 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006040 bgp_damp_info_vty (vty, binfo);
6041
6042 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006043#ifdef HAVE_CLOCK_MONOTONIC
6044 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006045 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006046#else
6047 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6048#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006049 }
6050 vty_out (vty, "%s", VTY_NEWLINE);
6051}
6052
paulb40d9392005-08-22 22:34:41 +00006053#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 +00006054#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006055#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6056#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6057#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6058
6059enum bgp_show_type
6060{
6061 bgp_show_type_normal,
6062 bgp_show_type_regexp,
6063 bgp_show_type_prefix_list,
6064 bgp_show_type_filter_list,
6065 bgp_show_type_route_map,
6066 bgp_show_type_neighbor,
6067 bgp_show_type_cidr_only,
6068 bgp_show_type_prefix_longer,
6069 bgp_show_type_community_all,
6070 bgp_show_type_community,
6071 bgp_show_type_community_exact,
6072 bgp_show_type_community_list,
6073 bgp_show_type_community_list_exact,
6074 bgp_show_type_flap_statistics,
6075 bgp_show_type_flap_address,
6076 bgp_show_type_flap_prefix,
6077 bgp_show_type_flap_cidr_only,
6078 bgp_show_type_flap_regexp,
6079 bgp_show_type_flap_filter_list,
6080 bgp_show_type_flap_prefix_list,
6081 bgp_show_type_flap_prefix_longer,
6082 bgp_show_type_flap_route_map,
6083 bgp_show_type_flap_neighbor,
6084 bgp_show_type_dampend_paths,
6085 bgp_show_type_damp_neighbor
6086};
6087
ajs5a646652004-11-05 01:25:55 +00006088static int
paulfee0f4c2004-09-13 05:12:46 +00006089bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006090 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006091{
paul718e3742002-12-13 20:15:29 +00006092 struct bgp_info *ri;
6093 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006094 int header = 1;
paul718e3742002-12-13 20:15:29 +00006095 int display;
ajs5a646652004-11-05 01:25:55 +00006096 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006097
6098 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006099 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006100
paul718e3742002-12-13 20:15:29 +00006101 /* Start processing of routes. */
6102 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6103 if (rn->info != NULL)
6104 {
6105 display = 0;
6106
6107 for (ri = rn->info; ri; ri = ri->next)
6108 {
ajs5a646652004-11-05 01:25:55 +00006109 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006110 || type == bgp_show_type_flap_address
6111 || type == bgp_show_type_flap_prefix
6112 || type == bgp_show_type_flap_cidr_only
6113 || type == bgp_show_type_flap_regexp
6114 || type == bgp_show_type_flap_filter_list
6115 || type == bgp_show_type_flap_prefix_list
6116 || type == bgp_show_type_flap_prefix_longer
6117 || type == bgp_show_type_flap_route_map
6118 || type == bgp_show_type_flap_neighbor
6119 || type == bgp_show_type_dampend_paths
6120 || type == bgp_show_type_damp_neighbor)
6121 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006122 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006123 continue;
6124 }
6125 if (type == bgp_show_type_regexp
6126 || type == bgp_show_type_flap_regexp)
6127 {
ajs5a646652004-11-05 01:25:55 +00006128 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006129
6130 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6131 continue;
6132 }
6133 if (type == bgp_show_type_prefix_list
6134 || type == bgp_show_type_flap_prefix_list)
6135 {
ajs5a646652004-11-05 01:25:55 +00006136 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006137
6138 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6139 continue;
6140 }
6141 if (type == bgp_show_type_filter_list
6142 || type == bgp_show_type_flap_filter_list)
6143 {
ajs5a646652004-11-05 01:25:55 +00006144 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006145
6146 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6147 continue;
6148 }
6149 if (type == bgp_show_type_route_map
6150 || type == bgp_show_type_flap_route_map)
6151 {
ajs5a646652004-11-05 01:25:55 +00006152 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006153 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006154 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006155 int ret;
6156
Paul Jakmafb982c22007-05-04 20:15:47 +00006157 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006158 binfo.peer = ri->peer;
6159 binfo.attr = &dummy_attr;
6160
6161 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006162
6163 bgp_attr_extra_free (&dummy_attr);
6164
paul718e3742002-12-13 20:15:29 +00006165 if (ret == RMAP_DENYMATCH)
6166 continue;
6167 }
6168 if (type == bgp_show_type_neighbor
6169 || type == bgp_show_type_flap_neighbor
6170 || type == bgp_show_type_damp_neighbor)
6171 {
ajs5a646652004-11-05 01:25:55 +00006172 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006173
6174 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6175 continue;
6176 }
6177 if (type == bgp_show_type_cidr_only
6178 || type == bgp_show_type_flap_cidr_only)
6179 {
6180 u_int32_t destination;
6181
6182 destination = ntohl (rn->p.u.prefix4.s_addr);
6183 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6184 continue;
6185 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6186 continue;
6187 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6188 continue;
6189 }
6190 if (type == bgp_show_type_prefix_longer
6191 || type == bgp_show_type_flap_prefix_longer)
6192 {
ajs5a646652004-11-05 01:25:55 +00006193 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006194
6195 if (! prefix_match (p, &rn->p))
6196 continue;
6197 }
6198 if (type == bgp_show_type_community_all)
6199 {
6200 if (! ri->attr->community)
6201 continue;
6202 }
6203 if (type == bgp_show_type_community)
6204 {
ajs5a646652004-11-05 01:25:55 +00006205 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006206
6207 if (! ri->attr->community ||
6208 ! community_match (ri->attr->community, com))
6209 continue;
6210 }
6211 if (type == bgp_show_type_community_exact)
6212 {
ajs5a646652004-11-05 01:25:55 +00006213 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006214
6215 if (! ri->attr->community ||
6216 ! community_cmp (ri->attr->community, com))
6217 continue;
6218 }
6219 if (type == bgp_show_type_community_list)
6220 {
ajs5a646652004-11-05 01:25:55 +00006221 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006222
6223 if (! community_list_match (ri->attr->community, list))
6224 continue;
6225 }
6226 if (type == bgp_show_type_community_list_exact)
6227 {
ajs5a646652004-11-05 01:25:55 +00006228 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006229
6230 if (! community_list_exact_match (ri->attr->community, list))
6231 continue;
6232 }
6233 if (type == bgp_show_type_flap_address
6234 || type == bgp_show_type_flap_prefix)
6235 {
ajs5a646652004-11-05 01:25:55 +00006236 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006237
6238 if (! prefix_match (&rn->p, p))
6239 continue;
6240
6241 if (type == bgp_show_type_flap_prefix)
6242 if (p->prefixlen != rn->p.prefixlen)
6243 continue;
6244 }
6245 if (type == bgp_show_type_dampend_paths
6246 || type == bgp_show_type_damp_neighbor)
6247 {
6248 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6249 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6250 continue;
6251 }
6252
6253 if (header)
6254 {
hasso93406d82005-02-02 14:40:33 +00006255 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6256 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6257 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006258 if (type == bgp_show_type_dampend_paths
6259 || type == bgp_show_type_damp_neighbor)
6260 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6261 else if (type == bgp_show_type_flap_statistics
6262 || type == bgp_show_type_flap_address
6263 || type == bgp_show_type_flap_prefix
6264 || type == bgp_show_type_flap_cidr_only
6265 || type == bgp_show_type_flap_regexp
6266 || type == bgp_show_type_flap_filter_list
6267 || type == bgp_show_type_flap_prefix_list
6268 || type == bgp_show_type_flap_prefix_longer
6269 || type == bgp_show_type_flap_route_map
6270 || type == bgp_show_type_flap_neighbor)
6271 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6272 else
6273 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006274 header = 0;
6275 }
6276
6277 if (type == bgp_show_type_dampend_paths
6278 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006279 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006280 else if (type == bgp_show_type_flap_statistics
6281 || type == bgp_show_type_flap_address
6282 || type == bgp_show_type_flap_prefix
6283 || type == bgp_show_type_flap_cidr_only
6284 || type == bgp_show_type_flap_regexp
6285 || type == bgp_show_type_flap_filter_list
6286 || type == bgp_show_type_flap_prefix_list
6287 || type == bgp_show_type_flap_prefix_longer
6288 || type == bgp_show_type_flap_route_map
6289 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006290 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006291 else
ajs5a646652004-11-05 01:25:55 +00006292 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006293 display++;
6294 }
6295 if (display)
ajs5a646652004-11-05 01:25:55 +00006296 output_count++;
paul718e3742002-12-13 20:15:29 +00006297 }
6298
6299 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006300 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006301 {
6302 if (type == bgp_show_type_normal)
6303 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6304 }
6305 else
6306 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006307 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006308
6309 return CMD_SUCCESS;
6310}
6311
ajs5a646652004-11-05 01:25:55 +00006312static int
paulfee0f4c2004-09-13 05:12:46 +00006313bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006314 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006315{
6316 struct bgp_table *table;
6317
6318 if (bgp == NULL) {
6319 bgp = bgp_get_default ();
6320 }
6321
6322 if (bgp == NULL)
6323 {
6324 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6325 return CMD_WARNING;
6326 }
6327
6328
6329 table = bgp->rib[afi][safi];
6330
ajs5a646652004-11-05 01:25:55 +00006331 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006332}
6333
paul718e3742002-12-13 20:15:29 +00006334/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006335static void
paul718e3742002-12-13 20:15:29 +00006336route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6337 struct bgp_node *rn,
6338 struct prefix_rd *prd, afi_t afi, safi_t safi)
6339{
6340 struct bgp_info *ri;
6341 struct prefix *p;
6342 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006343 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006344 char buf1[INET6_ADDRSTRLEN];
6345 char buf2[INET6_ADDRSTRLEN];
6346 int count = 0;
6347 int best = 0;
6348 int suppress = 0;
6349 int no_export = 0;
6350 int no_advertise = 0;
6351 int local_as = 0;
6352 int first = 0;
6353
6354 p = &rn->p;
6355 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6356 (safi == SAFI_MPLS_VPN ?
6357 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6358 safi == SAFI_MPLS_VPN ? ":" : "",
6359 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6360 p->prefixlen, VTY_NEWLINE);
6361
6362 for (ri = rn->info; ri; ri = ri->next)
6363 {
6364 count++;
6365 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6366 {
6367 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006368 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006369 suppress = 1;
6370 if (ri->attr->community != NULL)
6371 {
6372 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6373 no_advertise = 1;
6374 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6375 no_export = 1;
6376 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6377 local_as = 1;
6378 }
6379 }
6380 }
6381
6382 vty_out (vty, "Paths: (%d available", count);
6383 if (best)
6384 {
6385 vty_out (vty, ", best #%d", best);
6386 if (safi == SAFI_UNICAST)
6387 vty_out (vty, ", table Default-IP-Routing-Table");
6388 }
6389 else
6390 vty_out (vty, ", no best path");
6391 if (no_advertise)
6392 vty_out (vty, ", not advertised to any peer");
6393 else if (no_export)
6394 vty_out (vty, ", not advertised to EBGP peer");
6395 else if (local_as)
6396 vty_out (vty, ", not advertised outside local AS");
6397 if (suppress)
6398 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6399 vty_out (vty, ")%s", VTY_NEWLINE);
6400
6401 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006402 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006403 {
6404 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6405 {
6406 if (! first)
6407 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6408 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6409 first = 1;
6410 }
6411 }
6412 if (! first)
6413 vty_out (vty, " Not advertised to any peer");
6414 vty_out (vty, "%s", VTY_NEWLINE);
6415}
6416
6417/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006418static int
paulfee0f4c2004-09-13 05:12:46 +00006419bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006420 struct bgp_table *rib, const char *ip_str,
6421 afi_t afi, safi_t safi, struct prefix_rd *prd,
6422 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006423{
6424 int ret;
6425 int header;
6426 int display = 0;
6427 struct prefix match;
6428 struct bgp_node *rn;
6429 struct bgp_node *rm;
6430 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006431 struct bgp_table *table;
6432
paul718e3742002-12-13 20:15:29 +00006433 /* Check IP address argument. */
6434 ret = str2prefix (ip_str, &match);
6435 if (! ret)
6436 {
6437 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6438 return CMD_WARNING;
6439 }
6440
6441 match.family = afi2family (afi);
6442
6443 if (safi == SAFI_MPLS_VPN)
6444 {
paulfee0f4c2004-09-13 05:12:46 +00006445 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006446 {
6447 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6448 continue;
6449
6450 if ((table = rn->info) != NULL)
6451 {
6452 header = 1;
6453
6454 if ((rm = bgp_node_match (table, &match)) != NULL)
6455 {
6456 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006457 {
6458 bgp_unlock_node (rm);
6459 continue;
6460 }
paul718e3742002-12-13 20:15:29 +00006461
6462 for (ri = rm->info; ri; ri = ri->next)
6463 {
6464 if (header)
6465 {
6466 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6467 AFI_IP, SAFI_MPLS_VPN);
6468
6469 header = 0;
6470 }
6471 display++;
6472 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6473 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006474
6475 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006476 }
6477 }
6478 }
6479 }
6480 else
6481 {
6482 header = 1;
6483
paulfee0f4c2004-09-13 05:12:46 +00006484 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006485 {
6486 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6487 {
6488 for (ri = rn->info; ri; ri = ri->next)
6489 {
6490 if (header)
6491 {
6492 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6493 header = 0;
6494 }
6495 display++;
6496 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6497 }
6498 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006499
6500 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006501 }
6502 }
6503
6504 if (! display)
6505 {
6506 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6507 return CMD_WARNING;
6508 }
6509
6510 return CMD_SUCCESS;
6511}
6512
paulfee0f4c2004-09-13 05:12:46 +00006513/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006514static int
paulfd79ac92004-10-13 05:06:08 +00006515bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006516 afi_t afi, safi_t safi, struct prefix_rd *prd,
6517 int prefix_check)
6518{
6519 struct bgp *bgp;
6520
6521 /* BGP structure lookup. */
6522 if (view_name)
6523 {
6524 bgp = bgp_lookup_by_name (view_name);
6525 if (bgp == NULL)
6526 {
6527 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6528 return CMD_WARNING;
6529 }
6530 }
6531 else
6532 {
6533 bgp = bgp_get_default ();
6534 if (bgp == NULL)
6535 {
6536 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6537 return CMD_WARNING;
6538 }
6539 }
6540
6541 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6542 afi, safi, prd, prefix_check);
6543}
6544
paul718e3742002-12-13 20:15:29 +00006545/* BGP route print out function. */
6546DEFUN (show_ip_bgp,
6547 show_ip_bgp_cmd,
6548 "show ip bgp",
6549 SHOW_STR
6550 IP_STR
6551 BGP_STR)
6552{
ajs5a646652004-11-05 01:25:55 +00006553 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006554}
6555
6556DEFUN (show_ip_bgp_ipv4,
6557 show_ip_bgp_ipv4_cmd,
6558 "show ip bgp ipv4 (unicast|multicast)",
6559 SHOW_STR
6560 IP_STR
6561 BGP_STR
6562 "Address family\n"
6563 "Address Family modifier\n"
6564 "Address Family modifier\n")
6565{
6566 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006567 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6568 NULL);
paul718e3742002-12-13 20:15:29 +00006569
ajs5a646652004-11-05 01:25:55 +00006570 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006571}
6572
Michael Lambert95cbbd22010-07-23 14:43:04 -04006573ALIAS (show_ip_bgp_ipv4,
6574 show_bgp_ipv4_safi_cmd,
6575 "show bgp ipv4 (unicast|multicast)",
6576 SHOW_STR
6577 BGP_STR
6578 "Address family\n"
6579 "Address Family modifier\n"
6580 "Address Family modifier\n")
6581
paul718e3742002-12-13 20:15:29 +00006582DEFUN (show_ip_bgp_route,
6583 show_ip_bgp_route_cmd,
6584 "show ip bgp A.B.C.D",
6585 SHOW_STR
6586 IP_STR
6587 BGP_STR
6588 "Network in the BGP routing table to display\n")
6589{
6590 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6591}
6592
6593DEFUN (show_ip_bgp_ipv4_route,
6594 show_ip_bgp_ipv4_route_cmd,
6595 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6596 SHOW_STR
6597 IP_STR
6598 BGP_STR
6599 "Address family\n"
6600 "Address Family modifier\n"
6601 "Address Family modifier\n"
6602 "Network in the BGP routing table to display\n")
6603{
6604 if (strncmp (argv[0], "m", 1) == 0)
6605 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6606
6607 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6608}
6609
Michael Lambert95cbbd22010-07-23 14:43:04 -04006610ALIAS (show_ip_bgp_ipv4_route,
6611 show_bgp_ipv4_safi_route_cmd,
6612 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6613 SHOW_STR
6614 BGP_STR
6615 "Address family\n"
6616 "Address Family modifier\n"
6617 "Address Family modifier\n"
6618 "Network in the BGP routing table to display\n")
6619
paul718e3742002-12-13 20:15:29 +00006620DEFUN (show_ip_bgp_vpnv4_all_route,
6621 show_ip_bgp_vpnv4_all_route_cmd,
6622 "show ip bgp vpnv4 all A.B.C.D",
6623 SHOW_STR
6624 IP_STR
6625 BGP_STR
6626 "Display VPNv4 NLRI specific information\n"
6627 "Display information about all VPNv4 NLRIs\n"
6628 "Network in the BGP routing table to display\n")
6629{
6630 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6631}
6632
6633DEFUN (show_ip_bgp_vpnv4_rd_route,
6634 show_ip_bgp_vpnv4_rd_route_cmd,
6635 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6636 SHOW_STR
6637 IP_STR
6638 BGP_STR
6639 "Display VPNv4 NLRI specific information\n"
6640 "Display information for a route distinguisher\n"
6641 "VPN Route Distinguisher\n"
6642 "Network in the BGP routing table to display\n")
6643{
6644 int ret;
6645 struct prefix_rd prd;
6646
6647 ret = str2prefix_rd (argv[0], &prd);
6648 if (! ret)
6649 {
6650 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6651 return CMD_WARNING;
6652 }
6653 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6654}
6655
6656DEFUN (show_ip_bgp_prefix,
6657 show_ip_bgp_prefix_cmd,
6658 "show ip bgp A.B.C.D/M",
6659 SHOW_STR
6660 IP_STR
6661 BGP_STR
6662 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6663{
6664 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6665}
6666
6667DEFUN (show_ip_bgp_ipv4_prefix,
6668 show_ip_bgp_ipv4_prefix_cmd,
6669 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6670 SHOW_STR
6671 IP_STR
6672 BGP_STR
6673 "Address family\n"
6674 "Address Family modifier\n"
6675 "Address Family modifier\n"
6676 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6677{
6678 if (strncmp (argv[0], "m", 1) == 0)
6679 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6680
6681 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6682}
6683
Michael Lambert95cbbd22010-07-23 14:43:04 -04006684ALIAS (show_ip_bgp_ipv4_prefix,
6685 show_bgp_ipv4_safi_prefix_cmd,
6686 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6687 SHOW_STR
6688 BGP_STR
6689 "Address family\n"
6690 "Address Family modifier\n"
6691 "Address Family modifier\n"
6692 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6693
paul718e3742002-12-13 20:15:29 +00006694DEFUN (show_ip_bgp_vpnv4_all_prefix,
6695 show_ip_bgp_vpnv4_all_prefix_cmd,
6696 "show ip bgp vpnv4 all A.B.C.D/M",
6697 SHOW_STR
6698 IP_STR
6699 BGP_STR
6700 "Display VPNv4 NLRI specific information\n"
6701 "Display information about all VPNv4 NLRIs\n"
6702 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6703{
6704 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6705}
6706
6707DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6708 show_ip_bgp_vpnv4_rd_prefix_cmd,
6709 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6710 SHOW_STR
6711 IP_STR
6712 BGP_STR
6713 "Display VPNv4 NLRI specific information\n"
6714 "Display information for a route distinguisher\n"
6715 "VPN Route Distinguisher\n"
6716 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6717{
6718 int ret;
6719 struct prefix_rd prd;
6720
6721 ret = str2prefix_rd (argv[0], &prd);
6722 if (! ret)
6723 {
6724 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6725 return CMD_WARNING;
6726 }
6727 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6728}
6729
6730DEFUN (show_ip_bgp_view,
6731 show_ip_bgp_view_cmd,
6732 "show ip bgp view WORD",
6733 SHOW_STR
6734 IP_STR
6735 BGP_STR
6736 "BGP view\n"
6737 "BGP view name\n")
6738{
paulbb46e942003-10-24 19:02:03 +00006739 struct bgp *bgp;
6740
6741 /* BGP structure lookup. */
6742 bgp = bgp_lookup_by_name (argv[0]);
6743 if (bgp == NULL)
6744 {
6745 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6746 return CMD_WARNING;
6747 }
6748
ajs5a646652004-11-05 01:25:55 +00006749 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006750}
6751
6752DEFUN (show_ip_bgp_view_route,
6753 show_ip_bgp_view_route_cmd,
6754 "show ip bgp view WORD A.B.C.D",
6755 SHOW_STR
6756 IP_STR
6757 BGP_STR
6758 "BGP view\n"
6759 "BGP view name\n"
6760 "Network in the BGP routing table to display\n")
6761{
6762 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6763}
6764
6765DEFUN (show_ip_bgp_view_prefix,
6766 show_ip_bgp_view_prefix_cmd,
6767 "show ip bgp view WORD A.B.C.D/M",
6768 SHOW_STR
6769 IP_STR
6770 BGP_STR
6771 "BGP view\n"
6772 "BGP view name\n"
6773 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6774{
6775 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6776}
6777
6778#ifdef HAVE_IPV6
6779DEFUN (show_bgp,
6780 show_bgp_cmd,
6781 "show bgp",
6782 SHOW_STR
6783 BGP_STR)
6784{
ajs5a646652004-11-05 01:25:55 +00006785 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6786 NULL);
paul718e3742002-12-13 20:15:29 +00006787}
6788
6789ALIAS (show_bgp,
6790 show_bgp_ipv6_cmd,
6791 "show bgp ipv6",
6792 SHOW_STR
6793 BGP_STR
6794 "Address family\n")
6795
Michael Lambert95cbbd22010-07-23 14:43:04 -04006796DEFUN (show_bgp_ipv6_safi,
6797 show_bgp_ipv6_safi_cmd,
6798 "show bgp ipv6 (unicast|multicast)",
6799 SHOW_STR
6800 BGP_STR
6801 "Address family\n"
6802 "Address Family modifier\n"
6803 "Address Family modifier\n")
6804{
6805 if (strncmp (argv[0], "m", 1) == 0)
6806 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6807 NULL);
6808
6809 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6810}
6811
paul718e3742002-12-13 20:15:29 +00006812/* old command */
6813DEFUN (show_ipv6_bgp,
6814 show_ipv6_bgp_cmd,
6815 "show ipv6 bgp",
6816 SHOW_STR
6817 IP_STR
6818 BGP_STR)
6819{
ajs5a646652004-11-05 01:25:55 +00006820 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6821 NULL);
paul718e3742002-12-13 20:15:29 +00006822}
6823
6824DEFUN (show_bgp_route,
6825 show_bgp_route_cmd,
6826 "show bgp X:X::X:X",
6827 SHOW_STR
6828 BGP_STR
6829 "Network in the BGP routing table to display\n")
6830{
6831 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6832}
6833
6834ALIAS (show_bgp_route,
6835 show_bgp_ipv6_route_cmd,
6836 "show bgp ipv6 X:X::X:X",
6837 SHOW_STR
6838 BGP_STR
6839 "Address family\n"
6840 "Network in the BGP routing table to display\n")
6841
Michael Lambert95cbbd22010-07-23 14:43:04 -04006842DEFUN (show_bgp_ipv6_safi_route,
6843 show_bgp_ipv6_safi_route_cmd,
6844 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6845 SHOW_STR
6846 BGP_STR
6847 "Address family\n"
6848 "Address Family modifier\n"
6849 "Address Family modifier\n"
6850 "Network in the BGP routing table to display\n")
6851{
6852 if (strncmp (argv[0], "m", 1) == 0)
6853 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6854
6855 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6856}
6857
paul718e3742002-12-13 20:15:29 +00006858/* old command */
6859DEFUN (show_ipv6_bgp_route,
6860 show_ipv6_bgp_route_cmd,
6861 "show ipv6 bgp X:X::X:X",
6862 SHOW_STR
6863 IP_STR
6864 BGP_STR
6865 "Network in the BGP routing table to display\n")
6866{
6867 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6868}
6869
6870DEFUN (show_bgp_prefix,
6871 show_bgp_prefix_cmd,
6872 "show bgp X:X::X:X/M",
6873 SHOW_STR
6874 BGP_STR
6875 "IPv6 prefix <network>/<length>\n")
6876{
6877 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6878}
6879
6880ALIAS (show_bgp_prefix,
6881 show_bgp_ipv6_prefix_cmd,
6882 "show bgp ipv6 X:X::X:X/M",
6883 SHOW_STR
6884 BGP_STR
6885 "Address family\n"
6886 "IPv6 prefix <network>/<length>\n")
6887
Michael Lambert95cbbd22010-07-23 14:43:04 -04006888DEFUN (show_bgp_ipv6_safi_prefix,
6889 show_bgp_ipv6_safi_prefix_cmd,
6890 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6891 SHOW_STR
6892 BGP_STR
6893 "Address family\n"
6894 "Address Family modifier\n"
6895 "Address Family modifier\n"
6896 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6897{
6898 if (strncmp (argv[0], "m", 1) == 0)
6899 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6900
6901 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6902}
6903
paul718e3742002-12-13 20:15:29 +00006904/* old command */
6905DEFUN (show_ipv6_bgp_prefix,
6906 show_ipv6_bgp_prefix_cmd,
6907 "show ipv6 bgp X:X::X:X/M",
6908 SHOW_STR
6909 IP_STR
6910 BGP_STR
6911 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6912{
6913 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6914}
6915
paulbb46e942003-10-24 19:02:03 +00006916DEFUN (show_bgp_view,
6917 show_bgp_view_cmd,
6918 "show bgp view WORD",
6919 SHOW_STR
6920 BGP_STR
6921 "BGP view\n"
6922 "View name\n")
6923{
6924 struct bgp *bgp;
6925
6926 /* BGP structure lookup. */
6927 bgp = bgp_lookup_by_name (argv[0]);
6928 if (bgp == NULL)
6929 {
6930 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6931 return CMD_WARNING;
6932 }
6933
ajs5a646652004-11-05 01:25:55 +00006934 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006935}
6936
6937ALIAS (show_bgp_view,
6938 show_bgp_view_ipv6_cmd,
6939 "show bgp view WORD ipv6",
6940 SHOW_STR
6941 BGP_STR
6942 "BGP view\n"
6943 "View name\n"
6944 "Address family\n")
6945
6946DEFUN (show_bgp_view_route,
6947 show_bgp_view_route_cmd,
6948 "show bgp view WORD X:X::X:X",
6949 SHOW_STR
6950 BGP_STR
6951 "BGP view\n"
6952 "View name\n"
6953 "Network in the BGP routing table to display\n")
6954{
6955 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6956}
6957
6958ALIAS (show_bgp_view_route,
6959 show_bgp_view_ipv6_route_cmd,
6960 "show bgp view WORD ipv6 X:X::X:X",
6961 SHOW_STR
6962 BGP_STR
6963 "BGP view\n"
6964 "View name\n"
6965 "Address family\n"
6966 "Network in the BGP routing table to display\n")
6967
6968DEFUN (show_bgp_view_prefix,
6969 show_bgp_view_prefix_cmd,
6970 "show bgp view WORD X:X::X:X/M",
6971 SHOW_STR
6972 BGP_STR
6973 "BGP view\n"
6974 "View name\n"
6975 "IPv6 prefix <network>/<length>\n")
6976{
6977 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6978}
6979
6980ALIAS (show_bgp_view_prefix,
6981 show_bgp_view_ipv6_prefix_cmd,
6982 "show bgp view WORD ipv6 X:X::X:X/M",
6983 SHOW_STR
6984 BGP_STR
6985 "BGP view\n"
6986 "View name\n"
6987 "Address family\n"
6988 "IPv6 prefix <network>/<length>\n")
6989
paul718e3742002-12-13 20:15:29 +00006990/* old command */
6991DEFUN (show_ipv6_mbgp,
6992 show_ipv6_mbgp_cmd,
6993 "show ipv6 mbgp",
6994 SHOW_STR
6995 IP_STR
6996 MBGP_STR)
6997{
ajs5a646652004-11-05 01:25:55 +00006998 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6999 NULL);
paul718e3742002-12-13 20:15:29 +00007000}
7001
7002/* old command */
7003DEFUN (show_ipv6_mbgp_route,
7004 show_ipv6_mbgp_route_cmd,
7005 "show ipv6 mbgp X:X::X:X",
7006 SHOW_STR
7007 IP_STR
7008 MBGP_STR
7009 "Network in the MBGP routing table to display\n")
7010{
7011 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
7012}
7013
7014/* old command */
7015DEFUN (show_ipv6_mbgp_prefix,
7016 show_ipv6_mbgp_prefix_cmd,
7017 "show ipv6 mbgp X:X::X:X/M",
7018 SHOW_STR
7019 IP_STR
7020 MBGP_STR
7021 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7022{
7023 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7024}
7025#endif
7026
paul718e3742002-12-13 20:15:29 +00007027
paul94f2b392005-06-28 12:44:16 +00007028static int
paulfd79ac92004-10-13 05:06:08 +00007029bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007030 safi_t safi, enum bgp_show_type type)
7031{
7032 int i;
7033 struct buffer *b;
7034 char *regstr;
7035 int first;
7036 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007037 int rc;
paul718e3742002-12-13 20:15:29 +00007038
7039 first = 0;
7040 b = buffer_new (1024);
7041 for (i = 0; i < argc; i++)
7042 {
7043 if (first)
7044 buffer_putc (b, ' ');
7045 else
7046 {
7047 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7048 continue;
7049 first = 1;
7050 }
7051
7052 buffer_putstr (b, argv[i]);
7053 }
7054 buffer_putc (b, '\0');
7055
7056 regstr = buffer_getstr (b);
7057 buffer_free (b);
7058
7059 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007060 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007061 if (! regex)
7062 {
7063 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7064 VTY_NEWLINE);
7065 return CMD_WARNING;
7066 }
7067
ajs5a646652004-11-05 01:25:55 +00007068 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7069 bgp_regex_free (regex);
7070 return rc;
paul718e3742002-12-13 20:15:29 +00007071}
7072
7073DEFUN (show_ip_bgp_regexp,
7074 show_ip_bgp_regexp_cmd,
7075 "show ip bgp regexp .LINE",
7076 SHOW_STR
7077 IP_STR
7078 BGP_STR
7079 "Display routes matching the AS path regular expression\n"
7080 "A regular-expression to match the BGP AS paths\n")
7081{
7082 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7083 bgp_show_type_regexp);
7084}
7085
7086DEFUN (show_ip_bgp_flap_regexp,
7087 show_ip_bgp_flap_regexp_cmd,
7088 "show ip bgp flap-statistics regexp .LINE",
7089 SHOW_STR
7090 IP_STR
7091 BGP_STR
7092 "Display flap statistics of routes\n"
7093 "Display routes matching the AS path regular expression\n"
7094 "A regular-expression to match the BGP AS paths\n")
7095{
7096 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7097 bgp_show_type_flap_regexp);
7098}
7099
7100DEFUN (show_ip_bgp_ipv4_regexp,
7101 show_ip_bgp_ipv4_regexp_cmd,
7102 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7103 SHOW_STR
7104 IP_STR
7105 BGP_STR
7106 "Address family\n"
7107 "Address Family modifier\n"
7108 "Address Family modifier\n"
7109 "Display routes matching the AS path regular expression\n"
7110 "A regular-expression to match the BGP AS paths\n")
7111{
7112 if (strncmp (argv[0], "m", 1) == 0)
7113 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7114 bgp_show_type_regexp);
7115
7116 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7117 bgp_show_type_regexp);
7118}
7119
7120#ifdef HAVE_IPV6
7121DEFUN (show_bgp_regexp,
7122 show_bgp_regexp_cmd,
7123 "show bgp regexp .LINE",
7124 SHOW_STR
7125 BGP_STR
7126 "Display routes matching the AS path regular expression\n"
7127 "A regular-expression to match the BGP AS paths\n")
7128{
7129 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7130 bgp_show_type_regexp);
7131}
7132
7133ALIAS (show_bgp_regexp,
7134 show_bgp_ipv6_regexp_cmd,
7135 "show bgp ipv6 regexp .LINE",
7136 SHOW_STR
7137 BGP_STR
7138 "Address family\n"
7139 "Display routes matching the AS path regular expression\n"
7140 "A regular-expression to match the BGP AS paths\n")
7141
7142/* old command */
7143DEFUN (show_ipv6_bgp_regexp,
7144 show_ipv6_bgp_regexp_cmd,
7145 "show ipv6 bgp regexp .LINE",
7146 SHOW_STR
7147 IP_STR
7148 BGP_STR
7149 "Display routes matching the AS path regular expression\n"
7150 "A regular-expression to match the BGP AS paths\n")
7151{
7152 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7153 bgp_show_type_regexp);
7154}
7155
7156/* old command */
7157DEFUN (show_ipv6_mbgp_regexp,
7158 show_ipv6_mbgp_regexp_cmd,
7159 "show ipv6 mbgp regexp .LINE",
7160 SHOW_STR
7161 IP_STR
7162 BGP_STR
7163 "Display routes matching the AS path regular expression\n"
7164 "A regular-expression to match the MBGP AS paths\n")
7165{
7166 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7167 bgp_show_type_regexp);
7168}
7169#endif /* HAVE_IPV6 */
7170
paul94f2b392005-06-28 12:44:16 +00007171static int
paulfd79ac92004-10-13 05:06:08 +00007172bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007173 safi_t safi, enum bgp_show_type type)
7174{
7175 struct prefix_list *plist;
7176
7177 plist = prefix_list_lookup (afi, prefix_list_str);
7178 if (plist == NULL)
7179 {
7180 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7181 prefix_list_str, VTY_NEWLINE);
7182 return CMD_WARNING;
7183 }
7184
ajs5a646652004-11-05 01:25:55 +00007185 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007186}
7187
7188DEFUN (show_ip_bgp_prefix_list,
7189 show_ip_bgp_prefix_list_cmd,
7190 "show ip bgp prefix-list WORD",
7191 SHOW_STR
7192 IP_STR
7193 BGP_STR
7194 "Display routes conforming to the prefix-list\n"
7195 "IP prefix-list name\n")
7196{
7197 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7198 bgp_show_type_prefix_list);
7199}
7200
7201DEFUN (show_ip_bgp_flap_prefix_list,
7202 show_ip_bgp_flap_prefix_list_cmd,
7203 "show ip bgp flap-statistics prefix-list WORD",
7204 SHOW_STR
7205 IP_STR
7206 BGP_STR
7207 "Display flap statistics of routes\n"
7208 "Display routes conforming to the prefix-list\n"
7209 "IP prefix-list name\n")
7210{
7211 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7212 bgp_show_type_flap_prefix_list);
7213}
7214
7215DEFUN (show_ip_bgp_ipv4_prefix_list,
7216 show_ip_bgp_ipv4_prefix_list_cmd,
7217 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7218 SHOW_STR
7219 IP_STR
7220 BGP_STR
7221 "Address family\n"
7222 "Address Family modifier\n"
7223 "Address Family modifier\n"
7224 "Display routes conforming to the prefix-list\n"
7225 "IP prefix-list name\n")
7226{
7227 if (strncmp (argv[0], "m", 1) == 0)
7228 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7229 bgp_show_type_prefix_list);
7230
7231 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7232 bgp_show_type_prefix_list);
7233}
7234
7235#ifdef HAVE_IPV6
7236DEFUN (show_bgp_prefix_list,
7237 show_bgp_prefix_list_cmd,
7238 "show bgp prefix-list WORD",
7239 SHOW_STR
7240 BGP_STR
7241 "Display routes conforming to the prefix-list\n"
7242 "IPv6 prefix-list name\n")
7243{
7244 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7245 bgp_show_type_prefix_list);
7246}
7247
7248ALIAS (show_bgp_prefix_list,
7249 show_bgp_ipv6_prefix_list_cmd,
7250 "show bgp ipv6 prefix-list WORD",
7251 SHOW_STR
7252 BGP_STR
7253 "Address family\n"
7254 "Display routes conforming to the prefix-list\n"
7255 "IPv6 prefix-list name\n")
7256
7257/* old command */
7258DEFUN (show_ipv6_bgp_prefix_list,
7259 show_ipv6_bgp_prefix_list_cmd,
7260 "show ipv6 bgp prefix-list WORD",
7261 SHOW_STR
7262 IPV6_STR
7263 BGP_STR
7264 "Display routes matching the prefix-list\n"
7265 "IPv6 prefix-list name\n")
7266{
7267 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7268 bgp_show_type_prefix_list);
7269}
7270
7271/* old command */
7272DEFUN (show_ipv6_mbgp_prefix_list,
7273 show_ipv6_mbgp_prefix_list_cmd,
7274 "show ipv6 mbgp prefix-list WORD",
7275 SHOW_STR
7276 IPV6_STR
7277 MBGP_STR
7278 "Display routes matching the prefix-list\n"
7279 "IPv6 prefix-list name\n")
7280{
7281 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7282 bgp_show_type_prefix_list);
7283}
7284#endif /* HAVE_IPV6 */
7285
paul94f2b392005-06-28 12:44:16 +00007286static int
paulfd79ac92004-10-13 05:06:08 +00007287bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007288 safi_t safi, enum bgp_show_type type)
7289{
7290 struct as_list *as_list;
7291
7292 as_list = as_list_lookup (filter);
7293 if (as_list == NULL)
7294 {
7295 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7296 return CMD_WARNING;
7297 }
7298
ajs5a646652004-11-05 01:25:55 +00007299 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007300}
7301
7302DEFUN (show_ip_bgp_filter_list,
7303 show_ip_bgp_filter_list_cmd,
7304 "show ip bgp filter-list WORD",
7305 SHOW_STR
7306 IP_STR
7307 BGP_STR
7308 "Display routes conforming to the filter-list\n"
7309 "Regular expression access list name\n")
7310{
7311 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7312 bgp_show_type_filter_list);
7313}
7314
7315DEFUN (show_ip_bgp_flap_filter_list,
7316 show_ip_bgp_flap_filter_list_cmd,
7317 "show ip bgp flap-statistics filter-list WORD",
7318 SHOW_STR
7319 IP_STR
7320 BGP_STR
7321 "Display flap statistics of routes\n"
7322 "Display routes conforming to the filter-list\n"
7323 "Regular expression access list name\n")
7324{
7325 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7326 bgp_show_type_flap_filter_list);
7327}
7328
7329DEFUN (show_ip_bgp_ipv4_filter_list,
7330 show_ip_bgp_ipv4_filter_list_cmd,
7331 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7332 SHOW_STR
7333 IP_STR
7334 BGP_STR
7335 "Address family\n"
7336 "Address Family modifier\n"
7337 "Address Family modifier\n"
7338 "Display routes conforming to the filter-list\n"
7339 "Regular expression access list name\n")
7340{
7341 if (strncmp (argv[0], "m", 1) == 0)
7342 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7343 bgp_show_type_filter_list);
7344
7345 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7346 bgp_show_type_filter_list);
7347}
7348
7349#ifdef HAVE_IPV6
7350DEFUN (show_bgp_filter_list,
7351 show_bgp_filter_list_cmd,
7352 "show bgp filter-list WORD",
7353 SHOW_STR
7354 BGP_STR
7355 "Display routes conforming to the filter-list\n"
7356 "Regular expression access list name\n")
7357{
7358 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7359 bgp_show_type_filter_list);
7360}
7361
7362ALIAS (show_bgp_filter_list,
7363 show_bgp_ipv6_filter_list_cmd,
7364 "show bgp ipv6 filter-list WORD",
7365 SHOW_STR
7366 BGP_STR
7367 "Address family\n"
7368 "Display routes conforming to the filter-list\n"
7369 "Regular expression access list name\n")
7370
7371/* old command */
7372DEFUN (show_ipv6_bgp_filter_list,
7373 show_ipv6_bgp_filter_list_cmd,
7374 "show ipv6 bgp filter-list WORD",
7375 SHOW_STR
7376 IPV6_STR
7377 BGP_STR
7378 "Display routes conforming to the filter-list\n"
7379 "Regular expression access list name\n")
7380{
7381 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7382 bgp_show_type_filter_list);
7383}
7384
7385/* old command */
7386DEFUN (show_ipv6_mbgp_filter_list,
7387 show_ipv6_mbgp_filter_list_cmd,
7388 "show ipv6 mbgp filter-list WORD",
7389 SHOW_STR
7390 IPV6_STR
7391 MBGP_STR
7392 "Display routes conforming to the filter-list\n"
7393 "Regular expression access list name\n")
7394{
7395 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7396 bgp_show_type_filter_list);
7397}
7398#endif /* HAVE_IPV6 */
7399
paul94f2b392005-06-28 12:44:16 +00007400static int
paulfd79ac92004-10-13 05:06:08 +00007401bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007402 safi_t safi, enum bgp_show_type type)
7403{
7404 struct route_map *rmap;
7405
7406 rmap = route_map_lookup_by_name (rmap_str);
7407 if (! rmap)
7408 {
7409 vty_out (vty, "%% %s is not a valid route-map name%s",
7410 rmap_str, VTY_NEWLINE);
7411 return CMD_WARNING;
7412 }
7413
ajs5a646652004-11-05 01:25:55 +00007414 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007415}
7416
7417DEFUN (show_ip_bgp_route_map,
7418 show_ip_bgp_route_map_cmd,
7419 "show ip bgp route-map WORD",
7420 SHOW_STR
7421 IP_STR
7422 BGP_STR
7423 "Display routes matching the route-map\n"
7424 "A route-map to match on\n")
7425{
7426 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7427 bgp_show_type_route_map);
7428}
7429
7430DEFUN (show_ip_bgp_flap_route_map,
7431 show_ip_bgp_flap_route_map_cmd,
7432 "show ip bgp flap-statistics route-map WORD",
7433 SHOW_STR
7434 IP_STR
7435 BGP_STR
7436 "Display flap statistics of routes\n"
7437 "Display routes matching the route-map\n"
7438 "A route-map to match on\n")
7439{
7440 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7441 bgp_show_type_flap_route_map);
7442}
7443
7444DEFUN (show_ip_bgp_ipv4_route_map,
7445 show_ip_bgp_ipv4_route_map_cmd,
7446 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7447 SHOW_STR
7448 IP_STR
7449 BGP_STR
7450 "Address family\n"
7451 "Address Family modifier\n"
7452 "Address Family modifier\n"
7453 "Display routes matching the route-map\n"
7454 "A route-map to match on\n")
7455{
7456 if (strncmp (argv[0], "m", 1) == 0)
7457 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7458 bgp_show_type_route_map);
7459
7460 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7461 bgp_show_type_route_map);
7462}
7463
7464DEFUN (show_bgp_route_map,
7465 show_bgp_route_map_cmd,
7466 "show bgp route-map WORD",
7467 SHOW_STR
7468 BGP_STR
7469 "Display routes matching the route-map\n"
7470 "A route-map to match on\n")
7471{
7472 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7473 bgp_show_type_route_map);
7474}
7475
7476ALIAS (show_bgp_route_map,
7477 show_bgp_ipv6_route_map_cmd,
7478 "show bgp ipv6 route-map WORD",
7479 SHOW_STR
7480 BGP_STR
7481 "Address family\n"
7482 "Display routes matching the route-map\n"
7483 "A route-map to match on\n")
7484
7485DEFUN (show_ip_bgp_cidr_only,
7486 show_ip_bgp_cidr_only_cmd,
7487 "show ip bgp cidr-only",
7488 SHOW_STR
7489 IP_STR
7490 BGP_STR
7491 "Display only routes with non-natural netmasks\n")
7492{
7493 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007494 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007495}
7496
7497DEFUN (show_ip_bgp_flap_cidr_only,
7498 show_ip_bgp_flap_cidr_only_cmd,
7499 "show ip bgp flap-statistics cidr-only",
7500 SHOW_STR
7501 IP_STR
7502 BGP_STR
7503 "Display flap statistics of routes\n"
7504 "Display only routes with non-natural netmasks\n")
7505{
7506 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007507 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007508}
7509
7510DEFUN (show_ip_bgp_ipv4_cidr_only,
7511 show_ip_bgp_ipv4_cidr_only_cmd,
7512 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7513 SHOW_STR
7514 IP_STR
7515 BGP_STR
7516 "Address family\n"
7517 "Address Family modifier\n"
7518 "Address Family modifier\n"
7519 "Display only routes with non-natural netmasks\n")
7520{
7521 if (strncmp (argv[0], "m", 1) == 0)
7522 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007523 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007524
7525 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007526 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007527}
7528
7529DEFUN (show_ip_bgp_community_all,
7530 show_ip_bgp_community_all_cmd,
7531 "show ip bgp community",
7532 SHOW_STR
7533 IP_STR
7534 BGP_STR
7535 "Display routes matching the communities\n")
7536{
7537 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007538 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007539}
7540
7541DEFUN (show_ip_bgp_ipv4_community_all,
7542 show_ip_bgp_ipv4_community_all_cmd,
7543 "show ip bgp ipv4 (unicast|multicast) community",
7544 SHOW_STR
7545 IP_STR
7546 BGP_STR
7547 "Address family\n"
7548 "Address Family modifier\n"
7549 "Address Family modifier\n"
7550 "Display routes matching the communities\n")
7551{
7552 if (strncmp (argv[0], "m", 1) == 0)
7553 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007554 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007555
7556 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007557 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007558}
7559
7560#ifdef HAVE_IPV6
7561DEFUN (show_bgp_community_all,
7562 show_bgp_community_all_cmd,
7563 "show bgp community",
7564 SHOW_STR
7565 BGP_STR
7566 "Display routes matching the communities\n")
7567{
7568 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007569 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007570}
7571
7572ALIAS (show_bgp_community_all,
7573 show_bgp_ipv6_community_all_cmd,
7574 "show bgp ipv6 community",
7575 SHOW_STR
7576 BGP_STR
7577 "Address family\n"
7578 "Display routes matching the communities\n")
7579
7580/* old command */
7581DEFUN (show_ipv6_bgp_community_all,
7582 show_ipv6_bgp_community_all_cmd,
7583 "show ipv6 bgp community",
7584 SHOW_STR
7585 IPV6_STR
7586 BGP_STR
7587 "Display routes matching the communities\n")
7588{
7589 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007590 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007591}
7592
7593/* old command */
7594DEFUN (show_ipv6_mbgp_community_all,
7595 show_ipv6_mbgp_community_all_cmd,
7596 "show ipv6 mbgp community",
7597 SHOW_STR
7598 IPV6_STR
7599 MBGP_STR
7600 "Display routes matching the communities\n")
7601{
7602 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007603 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007604}
7605#endif /* HAVE_IPV6 */
7606
paul94f2b392005-06-28 12:44:16 +00007607static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007608bgp_show_community (struct vty *vty, const char *view_name, int argc,
7609 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007610{
7611 struct community *com;
7612 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007613 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007614 int i;
7615 char *str;
7616 int first = 0;
7617
Michael Lambert95cbbd22010-07-23 14:43:04 -04007618 /* BGP structure lookup */
7619 if (view_name)
7620 {
7621 bgp = bgp_lookup_by_name (view_name);
7622 if (bgp == NULL)
7623 {
7624 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7625 return CMD_WARNING;
7626 }
7627 }
7628 else
7629 {
7630 bgp = bgp_get_default ();
7631 if (bgp == NULL)
7632 {
7633 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7634 return CMD_WARNING;
7635 }
7636 }
7637
paul718e3742002-12-13 20:15:29 +00007638 b = buffer_new (1024);
7639 for (i = 0; i < argc; i++)
7640 {
7641 if (first)
7642 buffer_putc (b, ' ');
7643 else
7644 {
7645 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7646 continue;
7647 first = 1;
7648 }
7649
7650 buffer_putstr (b, argv[i]);
7651 }
7652 buffer_putc (b, '\0');
7653
7654 str = buffer_getstr (b);
7655 buffer_free (b);
7656
7657 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007658 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007659 if (! com)
7660 {
7661 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7662 return CMD_WARNING;
7663 }
7664
Michael Lambert95cbbd22010-07-23 14:43:04 -04007665 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007666 (exact ? bgp_show_type_community_exact :
7667 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007668}
7669
7670DEFUN (show_ip_bgp_community,
7671 show_ip_bgp_community_cmd,
7672 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7673 SHOW_STR
7674 IP_STR
7675 BGP_STR
7676 "Display routes matching the communities\n"
7677 "community number\n"
7678 "Do not send outside local AS (well-known community)\n"
7679 "Do not advertise to any peer (well-known community)\n"
7680 "Do not export to next AS (well-known community)\n")
7681{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007682 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007683}
7684
7685ALIAS (show_ip_bgp_community,
7686 show_ip_bgp_community2_cmd,
7687 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7688 SHOW_STR
7689 IP_STR
7690 BGP_STR
7691 "Display routes matching the communities\n"
7692 "community number\n"
7693 "Do not send outside local AS (well-known community)\n"
7694 "Do not advertise to any peer (well-known community)\n"
7695 "Do not export to next AS (well-known community)\n"
7696 "community number\n"
7697 "Do not send outside local AS (well-known community)\n"
7698 "Do not advertise to any peer (well-known community)\n"
7699 "Do not export to next AS (well-known community)\n")
7700
7701ALIAS (show_ip_bgp_community,
7702 show_ip_bgp_community3_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)",
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
7721ALIAS (show_ip_bgp_community,
7722 show_ip_bgp_community4_cmd,
7723 "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)",
7724 SHOW_STR
7725 IP_STR
7726 BGP_STR
7727 "Display routes matching the communities\n"
7728 "community number\n"
7729 "Do not send outside local AS (well-known community)\n"
7730 "Do not advertise to any peer (well-known community)\n"
7731 "Do not export to next AS (well-known community)\n"
7732 "community number\n"
7733 "Do not send outside local AS (well-known community)\n"
7734 "Do not advertise to any peer (well-known community)\n"
7735 "Do not export to next AS (well-known community)\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 "community number\n"
7741 "Do not send outside local AS (well-known community)\n"
7742 "Do not advertise to any peer (well-known community)\n"
7743 "Do not export to next AS (well-known community)\n")
7744
7745DEFUN (show_ip_bgp_ipv4_community,
7746 show_ip_bgp_ipv4_community_cmd,
7747 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7748 SHOW_STR
7749 IP_STR
7750 BGP_STR
7751 "Address family\n"
7752 "Address Family modifier\n"
7753 "Address Family modifier\n"
7754 "Display routes matching the communities\n"
7755 "community number\n"
7756 "Do not send outside local AS (well-known community)\n"
7757 "Do not advertise to any peer (well-known community)\n"
7758 "Do not export to next AS (well-known community)\n")
7759{
7760 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007761 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007762
Michael Lambert95cbbd22010-07-23 14:43:04 -04007763 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007764}
7765
7766ALIAS (show_ip_bgp_ipv4_community,
7767 show_ip_bgp_ipv4_community2_cmd,
7768 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7769 SHOW_STR
7770 IP_STR
7771 BGP_STR
7772 "Address family\n"
7773 "Address Family modifier\n"
7774 "Address Family modifier\n"
7775 "Display routes matching the communities\n"
7776 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n"
7780 "community number\n"
7781 "Do not send outside local AS (well-known community)\n"
7782 "Do not advertise to any peer (well-known community)\n"
7783 "Do not export to next AS (well-known community)\n")
7784
7785ALIAS (show_ip_bgp_ipv4_community,
7786 show_ip_bgp_ipv4_community3_cmd,
7787 "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)",
7788 SHOW_STR
7789 IP_STR
7790 BGP_STR
7791 "Address family\n"
7792 "Address Family modifier\n"
7793 "Address Family modifier\n"
7794 "Display routes matching the communities\n"
7795 "community number\n"
7796 "Do not send outside local AS (well-known community)\n"
7797 "Do not advertise to any peer (well-known community)\n"
7798 "Do not export to next AS (well-known community)\n"
7799 "community number\n"
7800 "Do not send outside local AS (well-known community)\n"
7801 "Do not advertise to any peer (well-known community)\n"
7802 "Do not export to next AS (well-known community)\n"
7803 "community number\n"
7804 "Do not send outside local AS (well-known community)\n"
7805 "Do not advertise to any peer (well-known community)\n"
7806 "Do not export to next AS (well-known community)\n")
7807
7808ALIAS (show_ip_bgp_ipv4_community,
7809 show_ip_bgp_ipv4_community4_cmd,
7810 "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)",
7811 SHOW_STR
7812 IP_STR
7813 BGP_STR
7814 "Address family\n"
7815 "Address Family modifier\n"
7816 "Address Family modifier\n"
7817 "Display routes matching the communities\n"
7818 "community number\n"
7819 "Do not send outside local AS (well-known community)\n"
7820 "Do not advertise to any peer (well-known community)\n"
7821 "Do not export to next AS (well-known community)\n"
7822 "community number\n"
7823 "Do not send outside local AS (well-known community)\n"
7824 "Do not advertise to any peer (well-known community)\n"
7825 "Do not export to next AS (well-known community)\n"
7826 "community number\n"
7827 "Do not send outside local AS (well-known community)\n"
7828 "Do not advertise to any peer (well-known community)\n"
7829 "Do not export to next AS (well-known community)\n"
7830 "community number\n"
7831 "Do not send outside local AS (well-known community)\n"
7832 "Do not advertise to any peer (well-known community)\n"
7833 "Do not export to next AS (well-known community)\n")
7834
Michael Lambert95cbbd22010-07-23 14:43:04 -04007835DEFUN (show_bgp_view_afi_safi_community_all,
7836 show_bgp_view_afi_safi_community_all_cmd,
7837#ifdef HAVE_IPV6
7838 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7839#else
7840 "show bgp view WORD ipv4 (unicast|multicast) community",
7841#endif
7842 SHOW_STR
7843 BGP_STR
7844 "BGP view\n"
7845 "BGP view name\n"
7846 "Address family\n"
7847#ifdef HAVE_IPV6
7848 "Address family\n"
7849#endif
7850 "Address Family modifier\n"
7851 "Address Family modifier\n"
7852 "Display routes containing communities\n")
7853{
7854 int afi;
7855 int safi;
7856 struct bgp *bgp;
7857
7858 /* BGP structure lookup. */
7859 bgp = bgp_lookup_by_name (argv[0]);
7860 if (bgp == NULL)
7861 {
7862 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7863 return CMD_WARNING;
7864 }
7865
7866#ifdef HAVE_IPV6
7867 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7868 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7869#else
7870 afi = AFI_IP;
7871 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7872#endif
7873 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7874}
7875
7876DEFUN (show_bgp_view_afi_safi_community,
7877 show_bgp_view_afi_safi_community_cmd,
7878#ifdef HAVE_IPV6
7879 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7880#else
7881 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7882#endif
7883 SHOW_STR
7884 BGP_STR
7885 "BGP view\n"
7886 "BGP view name\n"
7887 "Address family\n"
7888#ifdef HAVE_IPV6
7889 "Address family\n"
7890#endif
7891 "Address family modifier\n"
7892 "Address family modifier\n"
7893 "Display routes matching the communities\n"
7894 "community number\n"
7895 "Do not send outside local AS (well-known community)\n"
7896 "Do not advertise to any peer (well-known community)\n"
7897 "Do not export to next AS (well-known community)\n")
7898{
7899 int afi;
7900 int safi;
7901
7902#ifdef HAVE_IPV6
7903 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7904 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7905 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7906#else
7907 afi = AFI_IP;
7908 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7909 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7910#endif
7911}
7912
7913ALIAS (show_bgp_view_afi_safi_community,
7914 show_bgp_view_afi_safi_community2_cmd,
7915#ifdef HAVE_IPV6
7916 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7917#else
7918 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7919#endif
7920 SHOW_STR
7921 BGP_STR
7922 "BGP view\n"
7923 "BGP view name\n"
7924 "Address family\n"
7925#ifdef HAVE_IPV6
7926 "Address family\n"
7927#endif
7928 "Address family modifier\n"
7929 "Address family modifier\n"
7930 "Display routes matching the communities\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_view_afi_safi_community,
7941 show_bgp_view_afi_safi_community3_cmd,
7942#ifdef HAVE_IPV6
7943 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7944#else
7945 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7946#endif
7947 SHOW_STR
7948 BGP_STR
7949 "BGP view\n"
7950 "BGP view name\n"
7951 "Address family\n"
7952#ifdef HAVE_IPV6
7953 "Address family\n"
7954#endif
7955 "Address family modifier\n"
7956 "Address family modifier\n"
7957 "Display routes matching the communities\n"
7958 "community number\n"
7959 "Do not send outside local AS (well-known community)\n"
7960 "Do not advertise to any peer (well-known community)\n"
7961 "Do not export to next AS (well-known community)\n"
7962 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n")
7970
7971ALIAS (show_bgp_view_afi_safi_community,
7972 show_bgp_view_afi_safi_community4_cmd,
7973#ifdef HAVE_IPV6
7974 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7975#else
7976 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7977#endif
7978 SHOW_STR
7979 BGP_STR
7980 "BGP view\n"
7981 "BGP view name\n"
7982 "Address family\n"
7983#ifdef HAVE_IPV6
7984 "Address family\n"
7985#endif
7986 "Address family modifier\n"
7987 "Address family modifier\n"
7988 "Display routes matching the communities\n"
7989 "community number\n"
7990 "Do not send outside local AS (well-known community)\n"
7991 "Do not advertise to any peer (well-known community)\n"
7992 "Do not export to next AS (well-known community)\n"
7993 "community number\n"
7994 "Do not send outside local AS (well-known community)\n"
7995 "Do not advertise to any peer (well-known community)\n"
7996 "Do not export to next AS (well-known community)\n"
7997 "community number\n"
7998 "Do not send outside local AS (well-known community)\n"
7999 "Do not advertise to any peer (well-known community)\n"
8000 "Do not export to next AS (well-known community)\n"
8001 "community number\n"
8002 "Do not send outside local AS (well-known community)\n"
8003 "Do not advertise to any peer (well-known community)\n"
8004 "Do not export to next AS (well-known community)\n")
8005
paul718e3742002-12-13 20:15:29 +00008006DEFUN (show_ip_bgp_community_exact,
8007 show_ip_bgp_community_exact_cmd,
8008 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8009 SHOW_STR
8010 IP_STR
8011 BGP_STR
8012 "Display routes matching the communities\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 "Exact match of the communities")
8018{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008019 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008020}
8021
8022ALIAS (show_ip_bgp_community_exact,
8023 show_ip_bgp_community2_exact_cmd,
8024 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8025 SHOW_STR
8026 IP_STR
8027 BGP_STR
8028 "Display routes matching the communities\n"
8029 "community number\n"
8030 "Do not send outside local AS (well-known community)\n"
8031 "Do not advertise to any peer (well-known community)\n"
8032 "Do not export to next AS (well-known community)\n"
8033 "community number\n"
8034 "Do not send outside local AS (well-known community)\n"
8035 "Do not advertise to any peer (well-known community)\n"
8036 "Do not export to next AS (well-known community)\n"
8037 "Exact match of the communities")
8038
8039ALIAS (show_ip_bgp_community_exact,
8040 show_ip_bgp_community3_exact_cmd,
8041 "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",
8042 SHOW_STR
8043 IP_STR
8044 BGP_STR
8045 "Display routes matching the communities\n"
8046 "community number\n"
8047 "Do not send outside local AS (well-known community)\n"
8048 "Do not advertise to any peer (well-known community)\n"
8049 "Do not export to next AS (well-known community)\n"
8050 "community number\n"
8051 "Do not send outside local AS (well-known community)\n"
8052 "Do not advertise to any peer (well-known community)\n"
8053 "Do not export to next AS (well-known community)\n"
8054 "community number\n"
8055 "Do not send outside local AS (well-known community)\n"
8056 "Do not advertise to any peer (well-known community)\n"
8057 "Do not export to next AS (well-known community)\n"
8058 "Exact match of the communities")
8059
8060ALIAS (show_ip_bgp_community_exact,
8061 show_ip_bgp_community4_exact_cmd,
8062 "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",
8063 SHOW_STR
8064 IP_STR
8065 BGP_STR
8066 "Display routes matching the communities\n"
8067 "community number\n"
8068 "Do not send outside local AS (well-known community)\n"
8069 "Do not advertise to any peer (well-known community)\n"
8070 "Do not export to next AS (well-known community)\n"
8071 "community number\n"
8072 "Do not send outside local AS (well-known community)\n"
8073 "Do not advertise to any peer (well-known community)\n"
8074 "Do not export to next AS (well-known community)\n"
8075 "community number\n"
8076 "Do not send outside local AS (well-known community)\n"
8077 "Do not advertise to any peer (well-known community)\n"
8078 "Do not export to next AS (well-known community)\n"
8079 "community number\n"
8080 "Do not send outside local AS (well-known community)\n"
8081 "Do not advertise to any peer (well-known community)\n"
8082 "Do not export to next AS (well-known community)\n"
8083 "Exact match of the communities")
8084
8085DEFUN (show_ip_bgp_ipv4_community_exact,
8086 show_ip_bgp_ipv4_community_exact_cmd,
8087 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8088 SHOW_STR
8089 IP_STR
8090 BGP_STR
8091 "Address family\n"
8092 "Address Family modifier\n"
8093 "Address Family modifier\n"
8094 "Display routes matching the communities\n"
8095 "community number\n"
8096 "Do not send outside local AS (well-known community)\n"
8097 "Do not advertise to any peer (well-known community)\n"
8098 "Do not export to next AS (well-known community)\n"
8099 "Exact match of the communities")
8100{
8101 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008102 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008103
Michael Lambert95cbbd22010-07-23 14:43:04 -04008104 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008105}
8106
8107ALIAS (show_ip_bgp_ipv4_community_exact,
8108 show_ip_bgp_ipv4_community2_exact_cmd,
8109 "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",
8110 SHOW_STR
8111 IP_STR
8112 BGP_STR
8113 "Address family\n"
8114 "Address Family modifier\n"
8115 "Address Family modifier\n"
8116 "Display routes matching the communities\n"
8117 "community number\n"
8118 "Do not send outside local AS (well-known community)\n"
8119 "Do not advertise to any peer (well-known community)\n"
8120 "Do not export to next AS (well-known community)\n"
8121 "community number\n"
8122 "Do not send outside local AS (well-known community)\n"
8123 "Do not advertise to any peer (well-known community)\n"
8124 "Do not export to next AS (well-known community)\n"
8125 "Exact match of the communities")
8126
8127ALIAS (show_ip_bgp_ipv4_community_exact,
8128 show_ip_bgp_ipv4_community3_exact_cmd,
8129 "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",
8130 SHOW_STR
8131 IP_STR
8132 BGP_STR
8133 "Address family\n"
8134 "Address Family modifier\n"
8135 "Address Family modifier\n"
8136 "Display routes matching the communities\n"
8137 "community number\n"
8138 "Do not send outside local AS (well-known community)\n"
8139 "Do not advertise to any peer (well-known community)\n"
8140 "Do not export to next AS (well-known community)\n"
8141 "community number\n"
8142 "Do not send outside local AS (well-known community)\n"
8143 "Do not advertise to any peer (well-known community)\n"
8144 "Do not export to next AS (well-known community)\n"
8145 "community number\n"
8146 "Do not send outside local AS (well-known community)\n"
8147 "Do not advertise to any peer (well-known community)\n"
8148 "Do not export to next AS (well-known community)\n"
8149 "Exact match of the communities")
8150
8151ALIAS (show_ip_bgp_ipv4_community_exact,
8152 show_ip_bgp_ipv4_community4_exact_cmd,
8153 "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",
8154 SHOW_STR
8155 IP_STR
8156 BGP_STR
8157 "Address family\n"
8158 "Address Family modifier\n"
8159 "Address Family modifier\n"
8160 "Display routes matching the communities\n"
8161 "community number\n"
8162 "Do not send outside local AS (well-known community)\n"
8163 "Do not advertise to any peer (well-known community)\n"
8164 "Do not export to next AS (well-known community)\n"
8165 "community number\n"
8166 "Do not send outside local AS (well-known community)\n"
8167 "Do not advertise to any peer (well-known community)\n"
8168 "Do not export to next AS (well-known community)\n"
8169 "community number\n"
8170 "Do not send outside local AS (well-known community)\n"
8171 "Do not advertise to any peer (well-known community)\n"
8172 "Do not export to next AS (well-known community)\n"
8173 "community number\n"
8174 "Do not send outside local AS (well-known community)\n"
8175 "Do not advertise to any peer (well-known community)\n"
8176 "Do not export to next AS (well-known community)\n"
8177 "Exact match of the communities")
8178
8179#ifdef HAVE_IPV6
8180DEFUN (show_bgp_community,
8181 show_bgp_community_cmd,
8182 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8183 SHOW_STR
8184 BGP_STR
8185 "Display routes matching the communities\n"
8186 "community number\n"
8187 "Do not send outside local AS (well-known community)\n"
8188 "Do not advertise to any peer (well-known community)\n"
8189 "Do not export to next AS (well-known community)\n")
8190{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008191 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008192}
8193
8194ALIAS (show_bgp_community,
8195 show_bgp_ipv6_community_cmd,
8196 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8197 SHOW_STR
8198 BGP_STR
8199 "Address family\n"
8200 "Display routes matching the communities\n"
8201 "community number\n"
8202 "Do not send outside local AS (well-known community)\n"
8203 "Do not advertise to any peer (well-known community)\n"
8204 "Do not export to next AS (well-known community)\n")
8205
8206ALIAS (show_bgp_community,
8207 show_bgp_community2_cmd,
8208 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8209 SHOW_STR
8210 BGP_STR
8211 "Display routes matching the communities\n"
8212 "community number\n"
8213 "Do not send outside local AS (well-known community)\n"
8214 "Do not advertise to any peer (well-known community)\n"
8215 "Do not export to next AS (well-known community)\n"
8216 "community number\n"
8217 "Do not send outside local AS (well-known community)\n"
8218 "Do not advertise to any peer (well-known community)\n"
8219 "Do not export to next AS (well-known community)\n")
8220
8221ALIAS (show_bgp_community,
8222 show_bgp_ipv6_community2_cmd,
8223 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8224 SHOW_STR
8225 BGP_STR
8226 "Address family\n"
8227 "Display routes matching the communities\n"
8228 "community number\n"
8229 "Do not send outside local AS (well-known community)\n"
8230 "Do not advertise to any peer (well-known community)\n"
8231 "Do not export to next AS (well-known community)\n"
8232 "community number\n"
8233 "Do not send outside local AS (well-known community)\n"
8234 "Do not advertise to any peer (well-known community)\n"
8235 "Do not export to next AS (well-known community)\n")
8236
8237ALIAS (show_bgp_community,
8238 show_bgp_community3_cmd,
8239 "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)",
8240 SHOW_STR
8241 BGP_STR
8242 "Display routes matching the communities\n"
8243 "community number\n"
8244 "Do not send outside local AS (well-known community)\n"
8245 "Do not advertise to any peer (well-known community)\n"
8246 "Do not export to next AS (well-known community)\n"
8247 "community number\n"
8248 "Do not send outside local AS (well-known community)\n"
8249 "Do not advertise to any peer (well-known community)\n"
8250 "Do not export to next AS (well-known community)\n"
8251 "community number\n"
8252 "Do not send outside local AS (well-known community)\n"
8253 "Do not advertise to any peer (well-known community)\n"
8254 "Do not export to next AS (well-known community)\n")
8255
8256ALIAS (show_bgp_community,
8257 show_bgp_ipv6_community3_cmd,
8258 "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)",
8259 SHOW_STR
8260 BGP_STR
8261 "Address family\n"
8262 "Display routes matching the communities\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
8276ALIAS (show_bgp_community,
8277 show_bgp_community4_cmd,
8278 "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)",
8279 SHOW_STR
8280 BGP_STR
8281 "Display routes matching the communities\n"
8282 "community number\n"
8283 "Do not send outside local AS (well-known community)\n"
8284 "Do not advertise to any peer (well-known community)\n"
8285 "Do not export to next AS (well-known community)\n"
8286 "community number\n"
8287 "Do not send outside local AS (well-known community)\n"
8288 "Do not advertise to any peer (well-known community)\n"
8289 "Do not export to next AS (well-known community)\n"
8290 "community number\n"
8291 "Do not send outside local AS (well-known community)\n"
8292 "Do not advertise to any peer (well-known community)\n"
8293 "Do not export to next AS (well-known community)\n"
8294 "community number\n"
8295 "Do not send outside local AS (well-known community)\n"
8296 "Do not advertise to any peer (well-known community)\n"
8297 "Do not export to next AS (well-known community)\n")
8298
8299ALIAS (show_bgp_community,
8300 show_bgp_ipv6_community4_cmd,
8301 "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)",
8302 SHOW_STR
8303 BGP_STR
8304 "Address family\n"
8305 "Display routes matching the communities\n"
8306 "community number\n"
8307 "Do not send outside local AS (well-known community)\n"
8308 "Do not advertise to any peer (well-known community)\n"
8309 "Do not export to next AS (well-known community)\n"
8310 "community number\n"
8311 "Do not send outside local AS (well-known community)\n"
8312 "Do not advertise to any peer (well-known community)\n"
8313 "Do not export to next AS (well-known community)\n"
8314 "community number\n"
8315 "Do not send outside local AS (well-known community)\n"
8316 "Do not advertise to any peer (well-known community)\n"
8317 "Do not export to next AS (well-known community)\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
8323/* old command */
8324DEFUN (show_ipv6_bgp_community,
8325 show_ipv6_bgp_community_cmd,
8326 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8327 SHOW_STR
8328 IPV6_STR
8329 BGP_STR
8330 "Display routes matching the communities\n"
8331 "community number\n"
8332 "Do not send outside local AS (well-known community)\n"
8333 "Do not advertise to any peer (well-known community)\n"
8334 "Do not export to next AS (well-known community)\n")
8335{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008336 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008337}
8338
8339/* old command */
8340ALIAS (show_ipv6_bgp_community,
8341 show_ipv6_bgp_community2_cmd,
8342 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8343 SHOW_STR
8344 IPV6_STR
8345 BGP_STR
8346 "Display routes matching the communities\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 */
8357ALIAS (show_ipv6_bgp_community,
8358 show_ipv6_bgp_community3_cmd,
8359 "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)",
8360 SHOW_STR
8361 IPV6_STR
8362 BGP_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 "community number\n"
8369 "Do not send outside local AS (well-known community)\n"
8370 "Do not advertise to any peer (well-known community)\n"
8371 "Do not export to next AS (well-known community)\n"
8372 "community number\n"
8373 "Do not send outside local AS (well-known community)\n"
8374 "Do not advertise to any peer (well-known community)\n"
8375 "Do not export to next AS (well-known community)\n")
8376
8377/* old command */
8378ALIAS (show_ipv6_bgp_community,
8379 show_ipv6_bgp_community4_cmd,
8380 "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)",
8381 SHOW_STR
8382 IPV6_STR
8383 BGP_STR
8384 "Display routes matching the communities\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 "community number\n"
8390 "Do not send outside local AS (well-known community)\n"
8391 "Do not advertise to any peer (well-known community)\n"
8392 "Do not export to next AS (well-known community)\n"
8393 "community number\n"
8394 "Do not send outside local AS (well-known community)\n"
8395 "Do not advertise to any peer (well-known community)\n"
8396 "Do not export to next AS (well-known community)\n"
8397 "community number\n"
8398 "Do not send outside local AS (well-known community)\n"
8399 "Do not advertise to any peer (well-known community)\n"
8400 "Do not export to next AS (well-known community)\n")
8401
8402DEFUN (show_bgp_community_exact,
8403 show_bgp_community_exact_cmd,
8404 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8405 SHOW_STR
8406 BGP_STR
8407 "Display routes matching the communities\n"
8408 "community number\n"
8409 "Do not send outside local AS (well-known community)\n"
8410 "Do not advertise to any peer (well-known community)\n"
8411 "Do not export to next AS (well-known community)\n"
8412 "Exact match of the communities")
8413{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008414 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008415}
8416
8417ALIAS (show_bgp_community_exact,
8418 show_bgp_ipv6_community_exact_cmd,
8419 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8420 SHOW_STR
8421 BGP_STR
8422 "Address family\n"
8423 "Display routes matching the communities\n"
8424 "community number\n"
8425 "Do not send outside local AS (well-known community)\n"
8426 "Do not advertise to any peer (well-known community)\n"
8427 "Do not export to next AS (well-known community)\n"
8428 "Exact match of the communities")
8429
8430ALIAS (show_bgp_community_exact,
8431 show_bgp_community2_exact_cmd,
8432 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8433 SHOW_STR
8434 BGP_STR
8435 "Display routes matching the communities\n"
8436 "community number\n"
8437 "Do not send outside local AS (well-known community)\n"
8438 "Do not advertise to any peer (well-known community)\n"
8439 "Do not export to next AS (well-known community)\n"
8440 "community number\n"
8441 "Do not send outside local AS (well-known community)\n"
8442 "Do not advertise to any peer (well-known community)\n"
8443 "Do not export to next AS (well-known community)\n"
8444 "Exact match of the communities")
8445
8446ALIAS (show_bgp_community_exact,
8447 show_bgp_ipv6_community2_exact_cmd,
8448 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8449 SHOW_STR
8450 BGP_STR
8451 "Address family\n"
8452 "Display routes matching the communities\n"
8453 "community number\n"
8454 "Do not send outside local AS (well-known community)\n"
8455 "Do not advertise to any peer (well-known community)\n"
8456 "Do not export to next AS (well-known community)\n"
8457 "community number\n"
8458 "Do not send outside local AS (well-known community)\n"
8459 "Do not advertise to any peer (well-known community)\n"
8460 "Do not export to next AS (well-known community)\n"
8461 "Exact match of the communities")
8462
8463ALIAS (show_bgp_community_exact,
8464 show_bgp_community3_exact_cmd,
8465 "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",
8466 SHOW_STR
8467 BGP_STR
8468 "Display routes matching the communities\n"
8469 "community number\n"
8470 "Do not send outside local AS (well-known community)\n"
8471 "Do not advertise to any peer (well-known community)\n"
8472 "Do not export to next AS (well-known community)\n"
8473 "community number\n"
8474 "Do not send outside local AS (well-known community)\n"
8475 "Do not advertise to any peer (well-known community)\n"
8476 "Do not export to next AS (well-known community)\n"
8477 "community number\n"
8478 "Do not send outside local AS (well-known community)\n"
8479 "Do not advertise to any peer (well-known community)\n"
8480 "Do not export to next AS (well-known community)\n"
8481 "Exact match of the communities")
8482
8483ALIAS (show_bgp_community_exact,
8484 show_bgp_ipv6_community3_exact_cmd,
8485 "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",
8486 SHOW_STR
8487 BGP_STR
8488 "Address family\n"
8489 "Display routes matching the communities\n"
8490 "community number\n"
8491 "Do not send outside local AS (well-known community)\n"
8492 "Do not advertise to any peer (well-known community)\n"
8493 "Do not export to next AS (well-known community)\n"
8494 "community number\n"
8495 "Do not send outside local AS (well-known community)\n"
8496 "Do not advertise to any peer (well-known community)\n"
8497 "Do not export to next AS (well-known community)\n"
8498 "community number\n"
8499 "Do not send outside local AS (well-known community)\n"
8500 "Do not advertise to any peer (well-known community)\n"
8501 "Do not export to next AS (well-known community)\n"
8502 "Exact match of the communities")
8503
8504ALIAS (show_bgp_community_exact,
8505 show_bgp_community4_exact_cmd,
8506 "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",
8507 SHOW_STR
8508 BGP_STR
8509 "Display routes matching the communities\n"
8510 "community number\n"
8511 "Do not send outside local AS (well-known community)\n"
8512 "Do not advertise to any peer (well-known community)\n"
8513 "Do not export to next AS (well-known community)\n"
8514 "community number\n"
8515 "Do not send outside local AS (well-known community)\n"
8516 "Do not advertise to any peer (well-known community)\n"
8517 "Do not export to next AS (well-known community)\n"
8518 "community number\n"
8519 "Do not send outside local AS (well-known community)\n"
8520 "Do not advertise to any peer (well-known community)\n"
8521 "Do not export to next AS (well-known community)\n"
8522 "community number\n"
8523 "Do not send outside local AS (well-known community)\n"
8524 "Do not advertise to any peer (well-known community)\n"
8525 "Do not export to next AS (well-known community)\n"
8526 "Exact match of the communities")
8527
8528ALIAS (show_bgp_community_exact,
8529 show_bgp_ipv6_community4_exact_cmd,
8530 "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",
8531 SHOW_STR
8532 BGP_STR
8533 "Address family\n"
8534 "Display routes matching the communities\n"
8535 "community number\n"
8536 "Do not send outside local AS (well-known community)\n"
8537 "Do not advertise to any peer (well-known community)\n"
8538 "Do not export to next AS (well-known community)\n"
8539 "community number\n"
8540 "Do not send outside local AS (well-known community)\n"
8541 "Do not advertise to any peer (well-known community)\n"
8542 "Do not export to next AS (well-known community)\n"
8543 "community number\n"
8544 "Do not send outside local AS (well-known community)\n"
8545 "Do not advertise to any peer (well-known community)\n"
8546 "Do not export to next AS (well-known community)\n"
8547 "community number\n"
8548 "Do not send outside local AS (well-known community)\n"
8549 "Do not advertise to any peer (well-known community)\n"
8550 "Do not export to next AS (well-known community)\n"
8551 "Exact match of the communities")
8552
8553/* old command */
8554DEFUN (show_ipv6_bgp_community_exact,
8555 show_ipv6_bgp_community_exact_cmd,
8556 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8557 SHOW_STR
8558 IPV6_STR
8559 BGP_STR
8560 "Display routes matching the communities\n"
8561 "community number\n"
8562 "Do not send outside local AS (well-known community)\n"
8563 "Do not advertise to any peer (well-known community)\n"
8564 "Do not export to next AS (well-known community)\n"
8565 "Exact match of the communities")
8566{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008567 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008568}
8569
8570/* old command */
8571ALIAS (show_ipv6_bgp_community_exact,
8572 show_ipv6_bgp_community2_exact_cmd,
8573 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8574 SHOW_STR
8575 IPV6_STR
8576 BGP_STR
8577 "Display routes matching the communities\n"
8578 "community number\n"
8579 "Do not send outside local AS (well-known community)\n"
8580 "Do not advertise to any peer (well-known community)\n"
8581 "Do not export to next AS (well-known community)\n"
8582 "community number\n"
8583 "Do not send outside local AS (well-known community)\n"
8584 "Do not advertise to any peer (well-known community)\n"
8585 "Do not export to next AS (well-known community)\n"
8586 "Exact match of the communities")
8587
8588/* old command */
8589ALIAS (show_ipv6_bgp_community_exact,
8590 show_ipv6_bgp_community3_exact_cmd,
8591 "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",
8592 SHOW_STR
8593 IPV6_STR
8594 BGP_STR
8595 "Display routes matching the communities\n"
8596 "community number\n"
8597 "Do not send outside local AS (well-known community)\n"
8598 "Do not advertise to any peer (well-known community)\n"
8599 "Do not export to next AS (well-known community)\n"
8600 "community number\n"
8601 "Do not send outside local AS (well-known community)\n"
8602 "Do not advertise to any peer (well-known community)\n"
8603 "Do not export to next AS (well-known community)\n"
8604 "community number\n"
8605 "Do not send outside local AS (well-known community)\n"
8606 "Do not advertise to any peer (well-known community)\n"
8607 "Do not export to next AS (well-known community)\n"
8608 "Exact match of the communities")
8609
8610/* old command */
8611ALIAS (show_ipv6_bgp_community_exact,
8612 show_ipv6_bgp_community4_exact_cmd,
8613 "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",
8614 SHOW_STR
8615 IPV6_STR
8616 BGP_STR
8617 "Display routes matching the communities\n"
8618 "community number\n"
8619 "Do not send outside local AS (well-known community)\n"
8620 "Do not advertise to any peer (well-known community)\n"
8621 "Do not export to next AS (well-known community)\n"
8622 "community number\n"
8623 "Do not send outside local AS (well-known community)\n"
8624 "Do not advertise to any peer (well-known community)\n"
8625 "Do not export to next AS (well-known community)\n"
8626 "community number\n"
8627 "Do not send outside local AS (well-known community)\n"
8628 "Do not advertise to any peer (well-known community)\n"
8629 "Do not export to next AS (well-known community)\n"
8630 "community number\n"
8631 "Do not send outside local AS (well-known community)\n"
8632 "Do not advertise to any peer (well-known community)\n"
8633 "Do not export to next AS (well-known community)\n"
8634 "Exact match of the communities")
8635
8636/* old command */
8637DEFUN (show_ipv6_mbgp_community,
8638 show_ipv6_mbgp_community_cmd,
8639 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8640 SHOW_STR
8641 IPV6_STR
8642 MBGP_STR
8643 "Display routes matching the communities\n"
8644 "community number\n"
8645 "Do not send outside local AS (well-known community)\n"
8646 "Do not advertise to any peer (well-known community)\n"
8647 "Do not export to next AS (well-known community)\n")
8648{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008649 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008650}
8651
8652/* old command */
8653ALIAS (show_ipv6_mbgp_community,
8654 show_ipv6_mbgp_community2_cmd,
8655 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8656 SHOW_STR
8657 IPV6_STR
8658 MBGP_STR
8659 "Display routes matching the communities\n"
8660 "community number\n"
8661 "Do not send outside local AS (well-known community)\n"
8662 "Do not advertise to any peer (well-known community)\n"
8663 "Do not export to next AS (well-known community)\n"
8664 "community number\n"
8665 "Do not send outside local AS (well-known community)\n"
8666 "Do not advertise to any peer (well-known community)\n"
8667 "Do not export to next AS (well-known community)\n")
8668
8669/* old command */
8670ALIAS (show_ipv6_mbgp_community,
8671 show_ipv6_mbgp_community3_cmd,
8672 "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)",
8673 SHOW_STR
8674 IPV6_STR
8675 MBGP_STR
8676 "Display routes matching the communities\n"
8677 "community number\n"
8678 "Do not send outside local AS (well-known community)\n"
8679 "Do not advertise to any peer (well-known community)\n"
8680 "Do not export to next AS (well-known community)\n"
8681 "community number\n"
8682 "Do not send outside local AS (well-known community)\n"
8683 "Do not advertise to any peer (well-known community)\n"
8684 "Do not export to next AS (well-known community)\n"
8685 "community number\n"
8686 "Do not send outside local AS (well-known community)\n"
8687 "Do not advertise to any peer (well-known community)\n"
8688 "Do not export to next AS (well-known community)\n")
8689
8690/* old command */
8691ALIAS (show_ipv6_mbgp_community,
8692 show_ipv6_mbgp_community4_cmd,
8693 "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)",
8694 SHOW_STR
8695 IPV6_STR
8696 MBGP_STR
8697 "Display routes matching the communities\n"
8698 "community number\n"
8699 "Do not send outside local AS (well-known community)\n"
8700 "Do not advertise to any peer (well-known community)\n"
8701 "Do not export to next AS (well-known community)\n"
8702 "community number\n"
8703 "Do not send outside local AS (well-known community)\n"
8704 "Do not advertise to any peer (well-known community)\n"
8705 "Do not export to next AS (well-known community)\n"
8706 "community number\n"
8707 "Do not send outside local AS (well-known community)\n"
8708 "Do not advertise to any peer (well-known community)\n"
8709 "Do not export to next AS (well-known community)\n"
8710 "community number\n"
8711 "Do not send outside local AS (well-known community)\n"
8712 "Do not advertise to any peer (well-known community)\n"
8713 "Do not export to next AS (well-known community)\n")
8714
8715/* old command */
8716DEFUN (show_ipv6_mbgp_community_exact,
8717 show_ipv6_mbgp_community_exact_cmd,
8718 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8719 SHOW_STR
8720 IPV6_STR
8721 MBGP_STR
8722 "Display routes matching the communities\n"
8723 "community number\n"
8724 "Do not send outside local AS (well-known community)\n"
8725 "Do not advertise to any peer (well-known community)\n"
8726 "Do not export to next AS (well-known community)\n"
8727 "Exact match of the communities")
8728{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008729 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008730}
8731
8732/* old command */
8733ALIAS (show_ipv6_mbgp_community_exact,
8734 show_ipv6_mbgp_community2_exact_cmd,
8735 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8736 SHOW_STR
8737 IPV6_STR
8738 MBGP_STR
8739 "Display routes matching the communities\n"
8740 "community number\n"
8741 "Do not send outside local AS (well-known community)\n"
8742 "Do not advertise to any peer (well-known community)\n"
8743 "Do not export to next AS (well-known community)\n"
8744 "community number\n"
8745 "Do not send outside local AS (well-known community)\n"
8746 "Do not advertise to any peer (well-known community)\n"
8747 "Do not export to next AS (well-known community)\n"
8748 "Exact match of the communities")
8749
8750/* old command */
8751ALIAS (show_ipv6_mbgp_community_exact,
8752 show_ipv6_mbgp_community3_exact_cmd,
8753 "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",
8754 SHOW_STR
8755 IPV6_STR
8756 MBGP_STR
8757 "Display routes matching the communities\n"
8758 "community number\n"
8759 "Do not send outside local AS (well-known community)\n"
8760 "Do not advertise to any peer (well-known community)\n"
8761 "Do not export to next AS (well-known community)\n"
8762 "community number\n"
8763 "Do not send outside local AS (well-known community)\n"
8764 "Do not advertise to any peer (well-known community)\n"
8765 "Do not export to next AS (well-known community)\n"
8766 "community number\n"
8767 "Do not send outside local AS (well-known community)\n"
8768 "Do not advertise to any peer (well-known community)\n"
8769 "Do not export to next AS (well-known community)\n"
8770 "Exact match of the communities")
8771
8772/* old command */
8773ALIAS (show_ipv6_mbgp_community_exact,
8774 show_ipv6_mbgp_community4_exact_cmd,
8775 "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",
8776 SHOW_STR
8777 IPV6_STR
8778 MBGP_STR
8779 "Display routes matching the communities\n"
8780 "community number\n"
8781 "Do not send outside local AS (well-known community)\n"
8782 "Do not advertise to any peer (well-known community)\n"
8783 "Do not export to next AS (well-known community)\n"
8784 "community number\n"
8785 "Do not send outside local AS (well-known community)\n"
8786 "Do not advertise to any peer (well-known community)\n"
8787 "Do not export to next AS (well-known community)\n"
8788 "community number\n"
8789 "Do not send outside local AS (well-known community)\n"
8790 "Do not advertise to any peer (well-known community)\n"
8791 "Do not export to next AS (well-known community)\n"
8792 "community number\n"
8793 "Do not send outside local AS (well-known community)\n"
8794 "Do not advertise to any peer (well-known community)\n"
8795 "Do not export to next AS (well-known community)\n"
8796 "Exact match of the communities")
8797#endif /* HAVE_IPV6 */
8798
paul94f2b392005-06-28 12:44:16 +00008799static int
paulfd79ac92004-10-13 05:06:08 +00008800bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008801 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008802{
8803 struct community_list *list;
8804
hassofee6e4e2005-02-02 16:29:31 +00008805 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008806 if (list == NULL)
8807 {
8808 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8809 VTY_NEWLINE);
8810 return CMD_WARNING;
8811 }
8812
ajs5a646652004-11-05 01:25:55 +00008813 return bgp_show (vty, NULL, afi, safi,
8814 (exact ? bgp_show_type_community_list_exact :
8815 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008816}
8817
8818DEFUN (show_ip_bgp_community_list,
8819 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008820 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008821 SHOW_STR
8822 IP_STR
8823 BGP_STR
8824 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008825 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008826 "community-list name\n")
8827{
8828 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8829}
8830
8831DEFUN (show_ip_bgp_ipv4_community_list,
8832 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008833 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008834 SHOW_STR
8835 IP_STR
8836 BGP_STR
8837 "Address family\n"
8838 "Address Family modifier\n"
8839 "Address Family modifier\n"
8840 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008841 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008842 "community-list name\n")
8843{
8844 if (strncmp (argv[0], "m", 1) == 0)
8845 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8846
8847 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8848}
8849
8850DEFUN (show_ip_bgp_community_list_exact,
8851 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008852 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008853 SHOW_STR
8854 IP_STR
8855 BGP_STR
8856 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008857 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008858 "community-list name\n"
8859 "Exact match of the communities\n")
8860{
8861 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8862}
8863
8864DEFUN (show_ip_bgp_ipv4_community_list_exact,
8865 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008866 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008867 SHOW_STR
8868 IP_STR
8869 BGP_STR
8870 "Address family\n"
8871 "Address Family modifier\n"
8872 "Address Family modifier\n"
8873 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008874 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008875 "community-list name\n"
8876 "Exact match of the communities\n")
8877{
8878 if (strncmp (argv[0], "m", 1) == 0)
8879 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8880
8881 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8882}
8883
8884#ifdef HAVE_IPV6
8885DEFUN (show_bgp_community_list,
8886 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008887 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008888 SHOW_STR
8889 BGP_STR
8890 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008891 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008892 "community-list name\n")
8893{
8894 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8895}
8896
8897ALIAS (show_bgp_community_list,
8898 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008899 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008900 SHOW_STR
8901 BGP_STR
8902 "Address family\n"
8903 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008904 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008905 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008906
8907/* old command */
8908DEFUN (show_ipv6_bgp_community_list,
8909 show_ipv6_bgp_community_list_cmd,
8910 "show ipv6 bgp community-list WORD",
8911 SHOW_STR
8912 IPV6_STR
8913 BGP_STR
8914 "Display routes matching the community-list\n"
8915 "community-list name\n")
8916{
8917 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8918}
8919
8920/* old command */
8921DEFUN (show_ipv6_mbgp_community_list,
8922 show_ipv6_mbgp_community_list_cmd,
8923 "show ipv6 mbgp community-list WORD",
8924 SHOW_STR
8925 IPV6_STR
8926 MBGP_STR
8927 "Display routes matching the community-list\n"
8928 "community-list name\n")
8929{
8930 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8931}
8932
8933DEFUN (show_bgp_community_list_exact,
8934 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008935 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008936 SHOW_STR
8937 BGP_STR
8938 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008939 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008940 "community-list name\n"
8941 "Exact match of the communities\n")
8942{
8943 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8944}
8945
8946ALIAS (show_bgp_community_list_exact,
8947 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008948 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008949 SHOW_STR
8950 BGP_STR
8951 "Address family\n"
8952 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008953 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008954 "community-list name\n"
8955 "Exact match of the communities\n")
8956
8957/* old command */
8958DEFUN (show_ipv6_bgp_community_list_exact,
8959 show_ipv6_bgp_community_list_exact_cmd,
8960 "show ipv6 bgp community-list WORD exact-match",
8961 SHOW_STR
8962 IPV6_STR
8963 BGP_STR
8964 "Display routes matching the community-list\n"
8965 "community-list name\n"
8966 "Exact match of the communities\n")
8967{
8968 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8969}
8970
8971/* old command */
8972DEFUN (show_ipv6_mbgp_community_list_exact,
8973 show_ipv6_mbgp_community_list_exact_cmd,
8974 "show ipv6 mbgp community-list WORD exact-match",
8975 SHOW_STR
8976 IPV6_STR
8977 MBGP_STR
8978 "Display routes matching the community-list\n"
8979 "community-list name\n"
8980 "Exact match of the communities\n")
8981{
8982 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8983}
8984#endif /* HAVE_IPV6 */
8985
paul94f2b392005-06-28 12:44:16 +00008986static int
paulfd79ac92004-10-13 05:06:08 +00008987bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008988 safi_t safi, enum bgp_show_type type)
8989{
8990 int ret;
8991 struct prefix *p;
8992
8993 p = prefix_new();
8994
8995 ret = str2prefix (prefix, p);
8996 if (! ret)
8997 {
8998 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8999 return CMD_WARNING;
9000 }
9001
ajs5a646652004-11-05 01:25:55 +00009002 ret = bgp_show (vty, NULL, afi, safi, type, p);
9003 prefix_free(p);
9004 return ret;
paul718e3742002-12-13 20:15:29 +00009005}
9006
9007DEFUN (show_ip_bgp_prefix_longer,
9008 show_ip_bgp_prefix_longer_cmd,
9009 "show ip bgp A.B.C.D/M longer-prefixes",
9010 SHOW_STR
9011 IP_STR
9012 BGP_STR
9013 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9014 "Display route and more specific routes\n")
9015{
9016 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9017 bgp_show_type_prefix_longer);
9018}
9019
9020DEFUN (show_ip_bgp_flap_prefix_longer,
9021 show_ip_bgp_flap_prefix_longer_cmd,
9022 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9023 SHOW_STR
9024 IP_STR
9025 BGP_STR
9026 "Display flap statistics of routes\n"
9027 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9028 "Display route and more specific routes\n")
9029{
9030 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9031 bgp_show_type_flap_prefix_longer);
9032}
9033
9034DEFUN (show_ip_bgp_ipv4_prefix_longer,
9035 show_ip_bgp_ipv4_prefix_longer_cmd,
9036 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9037 SHOW_STR
9038 IP_STR
9039 BGP_STR
9040 "Address family\n"
9041 "Address Family modifier\n"
9042 "Address Family modifier\n"
9043 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9044 "Display route and more specific routes\n")
9045{
9046 if (strncmp (argv[0], "m", 1) == 0)
9047 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9048 bgp_show_type_prefix_longer);
9049
9050 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9051 bgp_show_type_prefix_longer);
9052}
9053
9054DEFUN (show_ip_bgp_flap_address,
9055 show_ip_bgp_flap_address_cmd,
9056 "show ip bgp flap-statistics A.B.C.D",
9057 SHOW_STR
9058 IP_STR
9059 BGP_STR
9060 "Display flap statistics of routes\n"
9061 "Network in the BGP routing table to display\n")
9062{
9063 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9064 bgp_show_type_flap_address);
9065}
9066
9067DEFUN (show_ip_bgp_flap_prefix,
9068 show_ip_bgp_flap_prefix_cmd,
9069 "show ip bgp flap-statistics A.B.C.D/M",
9070 SHOW_STR
9071 IP_STR
9072 BGP_STR
9073 "Display flap statistics of routes\n"
9074 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9075{
9076 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9077 bgp_show_type_flap_prefix);
9078}
9079#ifdef HAVE_IPV6
9080DEFUN (show_bgp_prefix_longer,
9081 show_bgp_prefix_longer_cmd,
9082 "show bgp X:X::X:X/M longer-prefixes",
9083 SHOW_STR
9084 BGP_STR
9085 "IPv6 prefix <network>/<length>\n"
9086 "Display route and more specific routes\n")
9087{
9088 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9089 bgp_show_type_prefix_longer);
9090}
9091
9092ALIAS (show_bgp_prefix_longer,
9093 show_bgp_ipv6_prefix_longer_cmd,
9094 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9095 SHOW_STR
9096 BGP_STR
9097 "Address family\n"
9098 "IPv6 prefix <network>/<length>\n"
9099 "Display route and more specific routes\n")
9100
9101/* old command */
9102DEFUN (show_ipv6_bgp_prefix_longer,
9103 show_ipv6_bgp_prefix_longer_cmd,
9104 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9105 SHOW_STR
9106 IPV6_STR
9107 BGP_STR
9108 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9109 "Display route and more specific routes\n")
9110{
9111 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9112 bgp_show_type_prefix_longer);
9113}
9114
9115/* old command */
9116DEFUN (show_ipv6_mbgp_prefix_longer,
9117 show_ipv6_mbgp_prefix_longer_cmd,
9118 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9119 SHOW_STR
9120 IPV6_STR
9121 MBGP_STR
9122 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9123 "Display route and more specific routes\n")
9124{
9125 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9126 bgp_show_type_prefix_longer);
9127}
9128#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009129
paul94f2b392005-06-28 12:44:16 +00009130static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009131peer_lookup_in_view (struct vty *vty, const char *view_name,
9132 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009133{
9134 int ret;
9135 struct bgp *bgp;
9136 struct peer *peer;
9137 union sockunion su;
9138
9139 /* BGP structure lookup. */
9140 if (view_name)
9141 {
9142 bgp = bgp_lookup_by_name (view_name);
9143 if (! bgp)
9144 {
9145 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9146 return NULL;
9147 }
9148 }
paul5228ad22004-06-04 17:58:18 +00009149 else
paulbb46e942003-10-24 19:02:03 +00009150 {
9151 bgp = bgp_get_default ();
9152 if (! bgp)
9153 {
9154 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9155 return NULL;
9156 }
9157 }
9158
9159 /* Get peer sockunion. */
9160 ret = str2sockunion (ip_str, &su);
9161 if (ret < 0)
9162 {
9163 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9164 return NULL;
9165 }
9166
9167 /* Peer structure lookup. */
9168 peer = peer_lookup (bgp, &su);
9169 if (! peer)
9170 {
9171 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9172 return NULL;
9173 }
9174
9175 return peer;
9176}
Paul Jakma2815e612006-09-14 02:56:07 +00009177
9178enum bgp_stats
9179{
9180 BGP_STATS_MAXBITLEN = 0,
9181 BGP_STATS_RIB,
9182 BGP_STATS_PREFIXES,
9183 BGP_STATS_TOTPLEN,
9184 BGP_STATS_UNAGGREGATEABLE,
9185 BGP_STATS_MAX_AGGREGATEABLE,
9186 BGP_STATS_AGGREGATES,
9187 BGP_STATS_SPACE,
9188 BGP_STATS_ASPATH_COUNT,
9189 BGP_STATS_ASPATH_MAXHOPS,
9190 BGP_STATS_ASPATH_TOTHOPS,
9191 BGP_STATS_ASPATH_MAXSIZE,
9192 BGP_STATS_ASPATH_TOTSIZE,
9193 BGP_STATS_ASN_HIGHEST,
9194 BGP_STATS_MAX,
9195};
paulbb46e942003-10-24 19:02:03 +00009196
Paul Jakma2815e612006-09-14 02:56:07 +00009197static const char *table_stats_strs[] =
9198{
9199 [BGP_STATS_PREFIXES] = "Total Prefixes",
9200 [BGP_STATS_TOTPLEN] = "Average prefix length",
9201 [BGP_STATS_RIB] = "Total Advertisements",
9202 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9203 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9204 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9205 [BGP_STATS_SPACE] = "Address space advertised",
9206 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9207 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9208 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9209 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9210 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9211 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9212 [BGP_STATS_MAX] = NULL,
9213};
9214
9215struct bgp_table_stats
9216{
9217 struct bgp_table *table;
9218 unsigned long long counts[BGP_STATS_MAX];
9219};
9220
9221#if 0
9222#define TALLY_SIGFIG 100000
9223static unsigned long
9224ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9225{
9226 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9227 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9228 unsigned long ret = newtot / count;
9229
9230 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9231 return ret + 1;
9232 else
9233 return ret;
9234}
9235#endif
9236
9237static int
9238bgp_table_stats_walker (struct thread *t)
9239{
9240 struct bgp_node *rn;
9241 struct bgp_node *top;
9242 struct bgp_table_stats *ts = THREAD_ARG (t);
9243 unsigned int space = 0;
9244
Paul Jakma53d9f672006-10-15 23:41:16 +00009245 if (!(top = bgp_table_top (ts->table)))
9246 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009247
9248 switch (top->p.family)
9249 {
9250 case AF_INET:
9251 space = IPV4_MAX_BITLEN;
9252 break;
9253 case AF_INET6:
9254 space = IPV6_MAX_BITLEN;
9255 break;
9256 }
9257
9258 ts->counts[BGP_STATS_MAXBITLEN] = space;
9259
9260 for (rn = top; rn; rn = bgp_route_next (rn))
9261 {
9262 struct bgp_info *ri;
9263 struct bgp_node *prn = rn->parent;
9264 unsigned int rinum = 0;
9265
9266 if (rn == top)
9267 continue;
9268
9269 if (!rn->info)
9270 continue;
9271
9272 ts->counts[BGP_STATS_PREFIXES]++;
9273 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9274
9275#if 0
9276 ts->counts[BGP_STATS_AVGPLEN]
9277 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9278 ts->counts[BGP_STATS_AVGPLEN],
9279 rn->p.prefixlen);
9280#endif
9281
9282 /* check if the prefix is included by any other announcements */
9283 while (prn && !prn->info)
9284 prn = prn->parent;
9285
9286 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009287 {
9288 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9289 /* announced address space */
9290 if (space)
9291 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9292 }
Paul Jakma2815e612006-09-14 02:56:07 +00009293 else if (prn->info)
9294 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9295
Paul Jakma2815e612006-09-14 02:56:07 +00009296 for (ri = rn->info; ri; ri = ri->next)
9297 {
9298 rinum++;
9299 ts->counts[BGP_STATS_RIB]++;
9300
9301 if (ri->attr &&
9302 (CHECK_FLAG (ri->attr->flag,
9303 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9304 ts->counts[BGP_STATS_AGGREGATES]++;
9305
9306 /* as-path stats */
9307 if (ri->attr && ri->attr->aspath)
9308 {
9309 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9310 unsigned int size = aspath_size (ri->attr->aspath);
9311 as_t highest = aspath_highest (ri->attr->aspath);
9312
9313 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9314
9315 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9316 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9317
9318 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9319 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9320
9321 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9322 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9323#if 0
9324 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9325 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9326 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9327 hops);
9328 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9329 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9330 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9331 size);
9332#endif
9333 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9334 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9335 }
9336 }
9337 }
9338 return 0;
9339}
9340
9341static int
9342bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9343{
9344 struct bgp_table_stats ts;
9345 unsigned int i;
9346
9347 if (!bgp->rib[afi][safi])
9348 {
9349 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9350 return CMD_WARNING;
9351 }
9352
9353 memset (&ts, 0, sizeof (ts));
9354 ts.table = bgp->rib[afi][safi];
9355 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9356
9357 vty_out (vty, "BGP %s RIB statistics%s%s",
9358 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9359
9360 for (i = 0; i < BGP_STATS_MAX; i++)
9361 {
9362 if (!table_stats_strs[i])
9363 continue;
9364
9365 switch (i)
9366 {
9367#if 0
9368 case BGP_STATS_ASPATH_AVGHOPS:
9369 case BGP_STATS_ASPATH_AVGSIZE:
9370 case BGP_STATS_AVGPLEN:
9371 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9372 vty_out (vty, "%12.2f",
9373 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9374 break;
9375#endif
9376 case BGP_STATS_ASPATH_TOTHOPS:
9377 case BGP_STATS_ASPATH_TOTSIZE:
9378 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9379 vty_out (vty, "%12.2f",
9380 ts.counts[i] ?
9381 (float)ts.counts[i] /
9382 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9383 : 0);
9384 break;
9385 case BGP_STATS_TOTPLEN:
9386 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9387 vty_out (vty, "%12.2f",
9388 ts.counts[i] ?
9389 (float)ts.counts[i] /
9390 (float)ts.counts[BGP_STATS_PREFIXES]
9391 : 0);
9392 break;
9393 case BGP_STATS_SPACE:
9394 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9395 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9396 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9397 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009398 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009399 vty_out (vty, "%12.2f%s",
9400 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009401 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009402 VTY_NEWLINE);
9403 vty_out (vty, "%30s: ", "/8 equivalent ");
9404 vty_out (vty, "%12.2f%s",
9405 (float)ts.counts[BGP_STATS_SPACE] /
9406 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9407 VTY_NEWLINE);
9408 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9409 break;
9410 vty_out (vty, "%30s: ", "/24 equivalent ");
9411 vty_out (vty, "%12.2f",
9412 (float)ts.counts[BGP_STATS_SPACE] /
9413 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9414 break;
9415 default:
9416 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9417 vty_out (vty, "%12llu", ts.counts[i]);
9418 }
9419
9420 vty_out (vty, "%s", VTY_NEWLINE);
9421 }
9422 return CMD_SUCCESS;
9423}
9424
9425static int
9426bgp_table_stats_vty (struct vty *vty, const char *name,
9427 const char *afi_str, const char *safi_str)
9428{
9429 struct bgp *bgp;
9430 afi_t afi;
9431 safi_t safi;
9432
9433 if (name)
9434 bgp = bgp_lookup_by_name (name);
9435 else
9436 bgp = bgp_get_default ();
9437
9438 if (!bgp)
9439 {
9440 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9441 return CMD_WARNING;
9442 }
9443 if (strncmp (afi_str, "ipv", 3) == 0)
9444 {
9445 if (strncmp (afi_str, "ipv4", 4) == 0)
9446 afi = AFI_IP;
9447 else if (strncmp (afi_str, "ipv6", 4) == 0)
9448 afi = AFI_IP6;
9449 else
9450 {
9451 vty_out (vty, "%% Invalid address family %s%s",
9452 afi_str, VTY_NEWLINE);
9453 return CMD_WARNING;
9454 }
9455 if (strncmp (safi_str, "m", 1) == 0)
9456 safi = SAFI_MULTICAST;
9457 else if (strncmp (safi_str, "u", 1) == 0)
9458 safi = SAFI_UNICAST;
9459 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9460 safi = BGP_SAFI_VPNV4;
9461 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9462 safi = BGP_SAFI_VPNV6;
9463 else
9464 {
9465 vty_out (vty, "%% Invalid subsequent address family %s%s",
9466 safi_str, VTY_NEWLINE);
9467 return CMD_WARNING;
9468 }
9469 }
9470 else
9471 {
9472 vty_out (vty, "%% Invalid address family %s%s",
9473 afi_str, VTY_NEWLINE);
9474 return CMD_WARNING;
9475 }
9476
9477 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9478 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9479 {
9480 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9481 afi_str, safi_str, VTY_NEWLINE);
9482 return CMD_WARNING;
9483 }
9484 return bgp_table_stats (vty, bgp, afi, safi);
9485}
9486
9487DEFUN (show_bgp_statistics,
9488 show_bgp_statistics_cmd,
9489 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9490 SHOW_STR
9491 BGP_STR
9492 "Address family\n"
9493 "Address family\n"
9494 "Address Family modifier\n"
9495 "Address Family modifier\n"
9496 "BGP RIB advertisement statistics\n")
9497{
9498 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9499}
9500
9501ALIAS (show_bgp_statistics,
9502 show_bgp_statistics_vpnv4_cmd,
9503 "show bgp (ipv4) (vpnv4) statistics",
9504 SHOW_STR
9505 BGP_STR
9506 "Address family\n"
9507 "Address Family modifier\n"
9508 "BGP RIB advertisement statistics\n")
9509
9510DEFUN (show_bgp_statistics_view,
9511 show_bgp_statistics_view_cmd,
9512 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9513 SHOW_STR
9514 BGP_STR
9515 "BGP view\n"
9516 "Address family\n"
9517 "Address family\n"
9518 "Address Family modifier\n"
9519 "Address Family modifier\n"
9520 "BGP RIB advertisement statistics\n")
9521{
9522 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9523}
9524
9525ALIAS (show_bgp_statistics_view,
9526 show_bgp_statistics_view_vpnv4_cmd,
9527 "show bgp view WORD (ipv4) (vpnv4) statistics",
9528 SHOW_STR
9529 BGP_STR
9530 "BGP view\n"
9531 "Address family\n"
9532 "Address Family modifier\n"
9533 "BGP RIB advertisement statistics\n")
9534
Paul Jakmaff7924f2006-09-04 01:10:36 +00009535enum bgp_pcounts
9536{
9537 PCOUNT_ADJ_IN = 0,
9538 PCOUNT_DAMPED,
9539 PCOUNT_REMOVED,
9540 PCOUNT_HISTORY,
9541 PCOUNT_STALE,
9542 PCOUNT_VALID,
9543 PCOUNT_ALL,
9544 PCOUNT_COUNTED,
9545 PCOUNT_PFCNT, /* the figure we display to users */
9546 PCOUNT_MAX,
9547};
9548
9549static const char *pcount_strs[] =
9550{
9551 [PCOUNT_ADJ_IN] = "Adj-in",
9552 [PCOUNT_DAMPED] = "Damped",
9553 [PCOUNT_REMOVED] = "Removed",
9554 [PCOUNT_HISTORY] = "History",
9555 [PCOUNT_STALE] = "Stale",
9556 [PCOUNT_VALID] = "Valid",
9557 [PCOUNT_ALL] = "All RIB",
9558 [PCOUNT_COUNTED] = "PfxCt counted",
9559 [PCOUNT_PFCNT] = "Useable",
9560 [PCOUNT_MAX] = NULL,
9561};
9562
Paul Jakma2815e612006-09-14 02:56:07 +00009563struct peer_pcounts
9564{
9565 unsigned int count[PCOUNT_MAX];
9566 const struct peer *peer;
9567 const struct bgp_table *table;
9568};
9569
Paul Jakmaff7924f2006-09-04 01:10:36 +00009570static int
Paul Jakma2815e612006-09-14 02:56:07 +00009571bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009572{
9573 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009574 struct peer_pcounts *pc = THREAD_ARG (t);
9575 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009576
Paul Jakma2815e612006-09-14 02:56:07 +00009577 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009578 {
9579 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009580 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009581
9582 for (ain = rn->adj_in; ain; ain = ain->next)
9583 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009584 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009585
Paul Jakmaff7924f2006-09-04 01:10:36 +00009586 for (ri = rn->info; ri; ri = ri->next)
9587 {
9588 char buf[SU_ADDRSTRLEN];
9589
9590 if (ri->peer != peer)
9591 continue;
9592
Paul Jakma2815e612006-09-14 02:56:07 +00009593 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009594
9595 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009596 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009597 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009598 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009599 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009600 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009601 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009602 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009603 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009604 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009605 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009606 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009607
9608 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9609 {
Paul Jakma2815e612006-09-14 02:56:07 +00009610 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009611 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009612 plog_warn (peer->log,
9613 "%s [pcount] %s/%d is counted but flags 0x%x",
9614 peer->host,
9615 inet_ntop(rn->p.family, &rn->p.u.prefix,
9616 buf, SU_ADDRSTRLEN),
9617 rn->p.prefixlen,
9618 ri->flags);
9619 }
9620 else
9621 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009622 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009623 plog_warn (peer->log,
9624 "%s [pcount] %s/%d not counted but flags 0x%x",
9625 peer->host,
9626 inet_ntop(rn->p.family, &rn->p.u.prefix,
9627 buf, SU_ADDRSTRLEN),
9628 rn->p.prefixlen,
9629 ri->flags);
9630 }
9631 }
9632 }
Paul Jakma2815e612006-09-14 02:56:07 +00009633 return 0;
9634}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009635
Paul Jakma2815e612006-09-14 02:56:07 +00009636static int
9637bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9638{
9639 struct peer_pcounts pcounts = { .peer = peer };
9640 unsigned int i;
9641
9642 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9643 || !peer->bgp->rib[afi][safi])
9644 {
9645 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9646 return CMD_WARNING;
9647 }
9648
9649 memset (&pcounts, 0, sizeof(pcounts));
9650 pcounts.peer = peer;
9651 pcounts.table = peer->bgp->rib[afi][safi];
9652
9653 /* in-place call via thread subsystem so as to record execution time
9654 * stats for the thread-walk (i.e. ensure this can't be blamed on
9655 * on just vty_read()).
9656 */
9657 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9658
Paul Jakmaff7924f2006-09-04 01:10:36 +00009659 vty_out (vty, "Prefix counts for %s, %s%s",
9660 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9661 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9662 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9663 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9664
9665 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009666 vty_out (vty, "%20s: %-10d%s",
9667 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009668
Paul Jakma2815e612006-09-14 02:56:07 +00009669 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009670 {
9671 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9672 peer->host, VTY_NEWLINE);
9673 vty_out (vty, "Please report this bug, with the above command output%s",
9674 VTY_NEWLINE);
9675 }
9676
9677 return CMD_SUCCESS;
9678}
9679
9680DEFUN (show_ip_bgp_neighbor_prefix_counts,
9681 show_ip_bgp_neighbor_prefix_counts_cmd,
9682 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9683 SHOW_STR
9684 IP_STR
9685 BGP_STR
9686 "Detailed information on TCP and BGP neighbor connections\n"
9687 "Neighbor to display information about\n"
9688 "Neighbor to display information about\n"
9689 "Display detailed prefix count information\n")
9690{
9691 struct peer *peer;
9692
9693 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9694 if (! peer)
9695 return CMD_WARNING;
9696
9697 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9698}
9699
9700DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9701 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9702 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9703 SHOW_STR
9704 BGP_STR
9705 "Address family\n"
9706 "Detailed information on TCP and BGP neighbor connections\n"
9707 "Neighbor to display information about\n"
9708 "Neighbor to display information about\n"
9709 "Display detailed prefix count information\n")
9710{
9711 struct peer *peer;
9712
9713 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9714 if (! peer)
9715 return CMD_WARNING;
9716
9717 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9718}
9719
9720DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9721 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9722 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9723 SHOW_STR
9724 IP_STR
9725 BGP_STR
9726 "Address family\n"
9727 "Address Family modifier\n"
9728 "Address Family modifier\n"
9729 "Detailed information on TCP and BGP neighbor connections\n"
9730 "Neighbor to display information about\n"
9731 "Neighbor to display information about\n"
9732 "Display detailed prefix count information\n")
9733{
9734 struct peer *peer;
9735
9736 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9737 if (! peer)
9738 return CMD_WARNING;
9739
9740 if (strncmp (argv[0], "m", 1) == 0)
9741 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9742
9743 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9744}
9745
9746DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9747 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9748 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9749 SHOW_STR
9750 IP_STR
9751 BGP_STR
9752 "Address family\n"
9753 "Address Family modifier\n"
9754 "Address Family modifier\n"
9755 "Detailed information on TCP and BGP neighbor connections\n"
9756 "Neighbor to display information about\n"
9757 "Neighbor to display information about\n"
9758 "Display detailed prefix count information\n")
9759{
9760 struct peer *peer;
9761
9762 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9763 if (! peer)
9764 return CMD_WARNING;
9765
9766 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9767}
9768
9769
paul94f2b392005-06-28 12:44:16 +00009770static void
paul718e3742002-12-13 20:15:29 +00009771show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9772 int in)
9773{
9774 struct bgp_table *table;
9775 struct bgp_adj_in *ain;
9776 struct bgp_adj_out *adj;
9777 unsigned long output_count;
9778 struct bgp_node *rn;
9779 int header1 = 1;
9780 struct bgp *bgp;
9781 int header2 = 1;
9782
paulbb46e942003-10-24 19:02:03 +00009783 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009784
9785 if (! bgp)
9786 return;
9787
9788 table = bgp->rib[afi][safi];
9789
9790 output_count = 0;
9791
9792 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9793 PEER_STATUS_DEFAULT_ORIGINATE))
9794 {
9795 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 +00009796 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9797 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009798
9799 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9800 VTY_NEWLINE, VTY_NEWLINE);
9801 header1 = 0;
9802 }
9803
9804 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9805 if (in)
9806 {
9807 for (ain = rn->adj_in; ain; ain = ain->next)
9808 if (ain->peer == peer)
9809 {
9810 if (header1)
9811 {
9812 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 +00009813 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9814 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009815 header1 = 0;
9816 }
9817 if (header2)
9818 {
9819 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9820 header2 = 0;
9821 }
9822 if (ain->attr)
9823 {
9824 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9825 output_count++;
9826 }
9827 }
9828 }
9829 else
9830 {
9831 for (adj = rn->adj_out; adj; adj = adj->next)
9832 if (adj->peer == peer)
9833 {
9834 if (header1)
9835 {
9836 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 +00009837 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9838 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009839 header1 = 0;
9840 }
9841 if (header2)
9842 {
9843 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9844 header2 = 0;
9845 }
9846 if (adj->attr)
9847 {
9848 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9849 output_count++;
9850 }
9851 }
9852 }
9853
9854 if (output_count != 0)
9855 vty_out (vty, "%sTotal number of prefixes %ld%s",
9856 VTY_NEWLINE, output_count, VTY_NEWLINE);
9857}
9858
paul94f2b392005-06-28 12:44:16 +00009859static int
paulbb46e942003-10-24 19:02:03 +00009860peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9861{
paul718e3742002-12-13 20:15:29 +00009862 if (! peer || ! peer->afc[afi][safi])
9863 {
9864 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9865 return CMD_WARNING;
9866 }
9867
9868 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9869 {
9870 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9871 VTY_NEWLINE);
9872 return CMD_WARNING;
9873 }
9874
9875 show_adj_route (vty, peer, afi, safi, in);
9876
9877 return CMD_SUCCESS;
9878}
9879
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009880DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9881 show_ip_bgp_view_neighbor_advertised_route_cmd,
9882 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9883 SHOW_STR
9884 IP_STR
9885 BGP_STR
9886 "BGP view\n"
9887 "View name\n"
9888 "Detailed information on TCP and BGP neighbor connections\n"
9889 "Neighbor to display information about\n"
9890 "Neighbor to display information about\n"
9891 "Display the routes advertised to a BGP neighbor\n")
9892{
9893 struct peer *peer;
9894
9895 if (argc == 2)
9896 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9897 else
9898 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9899
9900 if (! peer)
9901 return CMD_WARNING;
9902
9903 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9904}
9905
9906ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009907 show_ip_bgp_neighbor_advertised_route_cmd,
9908 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9909 SHOW_STR
9910 IP_STR
9911 BGP_STR
9912 "Detailed information on TCP and BGP neighbor connections\n"
9913 "Neighbor to display information about\n"
9914 "Neighbor to display information about\n"
9915 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009916
9917DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9918 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9919 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9920 SHOW_STR
9921 IP_STR
9922 BGP_STR
9923 "Address family\n"
9924 "Address Family modifier\n"
9925 "Address Family modifier\n"
9926 "Detailed information on TCP and BGP neighbor connections\n"
9927 "Neighbor to display information about\n"
9928 "Neighbor to display information about\n"
9929 "Display the routes advertised to a BGP neighbor\n")
9930{
paulbb46e942003-10-24 19:02:03 +00009931 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009932
paulbb46e942003-10-24 19:02:03 +00009933 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9934 if (! peer)
9935 return CMD_WARNING;
9936
9937 if (strncmp (argv[0], "m", 1) == 0)
9938 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9939
9940 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009941}
9942
9943#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009944DEFUN (show_bgp_view_neighbor_advertised_route,
9945 show_bgp_view_neighbor_advertised_route_cmd,
9946 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9947 SHOW_STR
9948 BGP_STR
9949 "BGP view\n"
9950 "View name\n"
9951 "Detailed information on TCP and BGP neighbor connections\n"
9952 "Neighbor to display information about\n"
9953 "Neighbor to display information about\n"
9954 "Display the routes advertised to a BGP neighbor\n")
9955{
9956 struct peer *peer;
9957
9958 if (argc == 2)
9959 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9960 else
9961 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9962
9963 if (! peer)
9964 return CMD_WARNING;
9965
9966 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9967}
9968
9969ALIAS (show_bgp_view_neighbor_advertised_route,
9970 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9971 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9972 SHOW_STR
9973 BGP_STR
9974 "BGP view\n"
9975 "View name\n"
9976 "Address family\n"
9977 "Detailed information on TCP and BGP neighbor connections\n"
9978 "Neighbor to display information about\n"
9979 "Neighbor to display information about\n"
9980 "Display the routes advertised to a BGP neighbor\n")
9981
9982DEFUN (show_bgp_view_neighbor_received_routes,
9983 show_bgp_view_neighbor_received_routes_cmd,
9984 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9985 SHOW_STR
9986 BGP_STR
9987 "BGP view\n"
9988 "View name\n"
9989 "Detailed information on TCP and BGP neighbor connections\n"
9990 "Neighbor to display information about\n"
9991 "Neighbor to display information about\n"
9992 "Display the received routes from neighbor\n")
9993{
9994 struct peer *peer;
9995
9996 if (argc == 2)
9997 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9998 else
9999 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10000
10001 if (! peer)
10002 return CMD_WARNING;
10003
10004 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
10005}
10006
10007ALIAS (show_bgp_view_neighbor_received_routes,
10008 show_bgp_view_ipv6_neighbor_received_routes_cmd,
10009 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
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 the received routes from neighbor\n")
10019
10020ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010021 show_bgp_neighbor_advertised_route_cmd,
10022 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10023 SHOW_STR
10024 BGP_STR
10025 "Detailed information on TCP and BGP neighbor connections\n"
10026 "Neighbor to display information about\n"
10027 "Neighbor to display information about\n"
10028 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010029
10030ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010031 show_bgp_ipv6_neighbor_advertised_route_cmd,
10032 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10033 SHOW_STR
10034 BGP_STR
10035 "Address family\n"
10036 "Detailed information on TCP and BGP neighbor connections\n"
10037 "Neighbor to display information about\n"
10038 "Neighbor to display information about\n"
10039 "Display the routes advertised to a BGP neighbor\n")
10040
10041/* old command */
paulbb46e942003-10-24 19:02:03 +000010042ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010043 ipv6_bgp_neighbor_advertised_route_cmd,
10044 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10045 SHOW_STR
10046 IPV6_STR
10047 BGP_STR
10048 "Detailed information on TCP and BGP neighbor connections\n"
10049 "Neighbor to display information about\n"
10050 "Neighbor to display information about\n"
10051 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010052
paul718e3742002-12-13 20:15:29 +000010053/* old command */
10054DEFUN (ipv6_mbgp_neighbor_advertised_route,
10055 ipv6_mbgp_neighbor_advertised_route_cmd,
10056 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10057 SHOW_STR
10058 IPV6_STR
10059 MBGP_STR
10060 "Detailed information on TCP and BGP neighbor connections\n"
10061 "Neighbor to display information about\n"
10062 "Neighbor to display information about\n"
10063 "Display the routes advertised to a BGP neighbor\n")
10064{
paulbb46e942003-10-24 19:02:03 +000010065 struct peer *peer;
10066
10067 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10068 if (! peer)
10069 return CMD_WARNING;
10070
10071 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010072}
10073#endif /* HAVE_IPV6 */
10074
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010075DEFUN (show_ip_bgp_view_neighbor_received_routes,
10076 show_ip_bgp_view_neighbor_received_routes_cmd,
10077 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10078 SHOW_STR
10079 IP_STR
10080 BGP_STR
10081 "BGP view\n"
10082 "View name\n"
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 received routes from neighbor\n")
10087{
10088 struct peer *peer;
10089
10090 if (argc == 2)
10091 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10092 else
10093 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10094
10095 if (! peer)
10096 return CMD_WARNING;
10097
10098 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10099}
10100
10101ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010102 show_ip_bgp_neighbor_received_routes_cmd,
10103 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10104 SHOW_STR
10105 IP_STR
10106 BGP_STR
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 the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010111
10112DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10113 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10114 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10115 SHOW_STR
10116 IP_STR
10117 BGP_STR
10118 "Address family\n"
10119 "Address Family modifier\n"
10120 "Address Family modifier\n"
10121 "Detailed information on TCP and BGP neighbor connections\n"
10122 "Neighbor to display information about\n"
10123 "Neighbor to display information about\n"
10124 "Display the received routes from neighbor\n")
10125{
paulbb46e942003-10-24 19:02:03 +000010126 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010127
paulbb46e942003-10-24 19:02:03 +000010128 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10129 if (! peer)
10130 return CMD_WARNING;
10131
10132 if (strncmp (argv[0], "m", 1) == 0)
10133 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10134
10135 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010136}
10137
Michael Lambert95cbbd22010-07-23 14:43:04 -040010138DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10139 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10140#ifdef HAVE_IPV6
10141 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10142#else
10143 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10144#endif
10145 SHOW_STR
10146 BGP_STR
10147 "BGP view\n"
10148 "BGP view name\n"
10149 "Address family\n"
10150#ifdef HAVE_IPV6
10151 "Address family\n"
10152#endif
10153 "Address family modifier\n"
10154 "Address family modifier\n"
10155 "Detailed information on TCP and BGP neighbor connections\n"
10156 "Neighbor to display information about\n"
10157 "Neighbor to display information about\n"
10158 "Display the advertised routes to neighbor\n"
10159 "Display the received routes from neighbor\n")
10160{
10161 int afi;
10162 int safi;
10163 int in;
10164 struct peer *peer;
10165
10166#ifdef HAVE_IPV6
10167 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10168#else
10169 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10170#endif
10171
10172 if (! peer)
10173 return CMD_WARNING;
10174
10175#ifdef HAVE_IPV6
10176 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10177 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10178 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10179#else
10180 afi = AFI_IP;
10181 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10182 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10183#endif
10184
10185 return peer_adj_routes (vty, peer, afi, safi, in);
10186}
10187
paul718e3742002-12-13 20:15:29 +000010188DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10189 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10190 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10191 SHOW_STR
10192 IP_STR
10193 BGP_STR
10194 "Detailed information on TCP and BGP neighbor connections\n"
10195 "Neighbor to display information about\n"
10196 "Neighbor to display information about\n"
10197 "Display information received from a BGP neighbor\n"
10198 "Display the prefixlist filter\n")
10199{
10200 char name[BUFSIZ];
10201 union sockunion *su;
10202 struct peer *peer;
10203 int count;
10204
10205 su = sockunion_str2su (argv[0]);
10206 if (su == NULL)
10207 return CMD_WARNING;
10208
10209 peer = peer_lookup (NULL, su);
10210 if (! peer)
10211 return CMD_WARNING;
10212
10213 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10214 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10215 if (count)
10216 {
10217 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10218 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10219 }
10220
10221 return CMD_SUCCESS;
10222}
10223
10224DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10225 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10226 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10227 SHOW_STR
10228 IP_STR
10229 BGP_STR
10230 "Address family\n"
10231 "Address Family modifier\n"
10232 "Address Family modifier\n"
10233 "Detailed information on TCP and BGP neighbor connections\n"
10234 "Neighbor to display information about\n"
10235 "Neighbor to display information about\n"
10236 "Display information received from a BGP neighbor\n"
10237 "Display the prefixlist filter\n")
10238{
10239 char name[BUFSIZ];
10240 union sockunion *su;
10241 struct peer *peer;
10242 int count;
10243
10244 su = sockunion_str2su (argv[1]);
10245 if (su == NULL)
10246 return CMD_WARNING;
10247
10248 peer = peer_lookup (NULL, su);
10249 if (! peer)
10250 return CMD_WARNING;
10251
10252 if (strncmp (argv[0], "m", 1) == 0)
10253 {
10254 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10255 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10256 if (count)
10257 {
10258 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10259 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10260 }
10261 }
10262 else
10263 {
10264 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10265 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10266 if (count)
10267 {
10268 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10269 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10270 }
10271 }
10272
10273 return CMD_SUCCESS;
10274}
10275
10276
10277#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010278ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010279 show_bgp_neighbor_received_routes_cmd,
10280 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10281 SHOW_STR
10282 BGP_STR
10283 "Detailed information on TCP and BGP neighbor connections\n"
10284 "Neighbor to display information about\n"
10285 "Neighbor to display information about\n"
10286 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010287
paulbb46e942003-10-24 19:02:03 +000010288ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010289 show_bgp_ipv6_neighbor_received_routes_cmd,
10290 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10291 SHOW_STR
10292 BGP_STR
10293 "Address family\n"
10294 "Detailed information on TCP and BGP neighbor connections\n"
10295 "Neighbor to display information about\n"
10296 "Neighbor to display information about\n"
10297 "Display the received routes from neighbor\n")
10298
10299DEFUN (show_bgp_neighbor_received_prefix_filter,
10300 show_bgp_neighbor_received_prefix_filter_cmd,
10301 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10302 SHOW_STR
10303 BGP_STR
10304 "Detailed information on TCP and BGP neighbor connections\n"
10305 "Neighbor to display information about\n"
10306 "Neighbor to display information about\n"
10307 "Display information received from a BGP neighbor\n"
10308 "Display the prefixlist filter\n")
10309{
10310 char name[BUFSIZ];
10311 union sockunion *su;
10312 struct peer *peer;
10313 int count;
10314
10315 su = sockunion_str2su (argv[0]);
10316 if (su == NULL)
10317 return CMD_WARNING;
10318
10319 peer = peer_lookup (NULL, su);
10320 if (! peer)
10321 return CMD_WARNING;
10322
10323 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10324 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10325 if (count)
10326 {
10327 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10328 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10329 }
10330
10331 return CMD_SUCCESS;
10332}
10333
10334ALIAS (show_bgp_neighbor_received_prefix_filter,
10335 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10336 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10337 SHOW_STR
10338 BGP_STR
10339 "Address family\n"
10340 "Detailed information on TCP and BGP neighbor connections\n"
10341 "Neighbor to display information about\n"
10342 "Neighbor to display information about\n"
10343 "Display information received from a BGP neighbor\n"
10344 "Display the prefixlist filter\n")
10345
10346/* old command */
paulbb46e942003-10-24 19:02:03 +000010347ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010348 ipv6_bgp_neighbor_received_routes_cmd,
10349 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10350 SHOW_STR
10351 IPV6_STR
10352 BGP_STR
10353 "Detailed information on TCP and BGP neighbor connections\n"
10354 "Neighbor to display information about\n"
10355 "Neighbor to display information about\n"
10356 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010357
10358/* old command */
10359DEFUN (ipv6_mbgp_neighbor_received_routes,
10360 ipv6_mbgp_neighbor_received_routes_cmd,
10361 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10362 SHOW_STR
10363 IPV6_STR
10364 MBGP_STR
10365 "Detailed information on TCP and BGP neighbor connections\n"
10366 "Neighbor to display information about\n"
10367 "Neighbor to display information about\n"
10368 "Display the received routes from neighbor\n")
10369{
paulbb46e942003-10-24 19:02:03 +000010370 struct peer *peer;
10371
10372 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10373 if (! peer)
10374 return CMD_WARNING;
10375
10376 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010377}
paulbb46e942003-10-24 19:02:03 +000010378
10379DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10380 show_bgp_view_neighbor_received_prefix_filter_cmd,
10381 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10382 SHOW_STR
10383 BGP_STR
10384 "BGP view\n"
10385 "View name\n"
10386 "Detailed information on TCP and BGP neighbor connections\n"
10387 "Neighbor to display information about\n"
10388 "Neighbor to display information about\n"
10389 "Display information received from a BGP neighbor\n"
10390 "Display the prefixlist filter\n")
10391{
10392 char name[BUFSIZ];
10393 union sockunion *su;
10394 struct peer *peer;
10395 struct bgp *bgp;
10396 int count;
10397
10398 /* BGP structure lookup. */
10399 bgp = bgp_lookup_by_name (argv[0]);
10400 if (bgp == NULL)
10401 {
10402 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10403 return CMD_WARNING;
10404 }
10405
10406 su = sockunion_str2su (argv[1]);
10407 if (su == NULL)
10408 return CMD_WARNING;
10409
10410 peer = peer_lookup (bgp, su);
10411 if (! peer)
10412 return CMD_WARNING;
10413
10414 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10415 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10416 if (count)
10417 {
10418 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10419 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10420 }
10421
10422 return CMD_SUCCESS;
10423}
10424
10425ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10426 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10427 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10428 SHOW_STR
10429 BGP_STR
10430 "BGP view\n"
10431 "View name\n"
10432 "Address family\n"
10433 "Detailed information on TCP and BGP neighbor connections\n"
10434 "Neighbor to display information about\n"
10435 "Neighbor to display information about\n"
10436 "Display information received from a BGP neighbor\n"
10437 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010438#endif /* HAVE_IPV6 */
10439
paul94f2b392005-06-28 12:44:16 +000010440static int
paulbb46e942003-10-24 19:02:03 +000010441bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010442 safi_t safi, enum bgp_show_type type)
10443{
paul718e3742002-12-13 20:15:29 +000010444 if (! peer || ! peer->afc[afi][safi])
10445 {
10446 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010447 return CMD_WARNING;
10448 }
10449
ajs5a646652004-11-05 01:25:55 +000010450 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010451}
10452
10453DEFUN (show_ip_bgp_neighbor_routes,
10454 show_ip_bgp_neighbor_routes_cmd,
10455 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10456 SHOW_STR
10457 IP_STR
10458 BGP_STR
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{
paulbb46e942003-10-24 19:02:03 +000010464 struct peer *peer;
10465
10466 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10467 if (! peer)
10468 return CMD_WARNING;
10469
10470 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010471 bgp_show_type_neighbor);
10472}
10473
10474DEFUN (show_ip_bgp_neighbor_flap,
10475 show_ip_bgp_neighbor_flap_cmd,
10476 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10477 SHOW_STR
10478 IP_STR
10479 BGP_STR
10480 "Detailed information on TCP and BGP neighbor connections\n"
10481 "Neighbor to display information about\n"
10482 "Neighbor to display information about\n"
10483 "Display flap statistics of the routes learned from neighbor\n")
10484{
paulbb46e942003-10-24 19:02:03 +000010485 struct peer *peer;
10486
10487 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10488 if (! peer)
10489 return CMD_WARNING;
10490
10491 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010492 bgp_show_type_flap_neighbor);
10493}
10494
10495DEFUN (show_ip_bgp_neighbor_damp,
10496 show_ip_bgp_neighbor_damp_cmd,
10497 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10498 SHOW_STR
10499 IP_STR
10500 BGP_STR
10501 "Detailed information on TCP and BGP neighbor connections\n"
10502 "Neighbor to display information about\n"
10503 "Neighbor to display information about\n"
10504 "Display the dampened routes received from neighbor\n")
10505{
paulbb46e942003-10-24 19:02:03 +000010506 struct peer *peer;
10507
10508 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10509 if (! peer)
10510 return CMD_WARNING;
10511
10512 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010513 bgp_show_type_damp_neighbor);
10514}
10515
10516DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10517 show_ip_bgp_ipv4_neighbor_routes_cmd,
10518 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10519 SHOW_STR
10520 IP_STR
10521 BGP_STR
10522 "Address family\n"
10523 "Address Family modifier\n"
10524 "Address Family modifier\n"
10525 "Detailed information on TCP and BGP neighbor connections\n"
10526 "Neighbor to display information about\n"
10527 "Neighbor to display information about\n"
10528 "Display routes learned from neighbor\n")
10529{
paulbb46e942003-10-24 19:02:03 +000010530 struct peer *peer;
10531
10532 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10533 if (! peer)
10534 return CMD_WARNING;
10535
paul718e3742002-12-13 20:15:29 +000010536 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010537 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010538 bgp_show_type_neighbor);
10539
paulbb46e942003-10-24 19:02:03 +000010540 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010541 bgp_show_type_neighbor);
10542}
paulbb46e942003-10-24 19:02:03 +000010543
paulfee0f4c2004-09-13 05:12:46 +000010544DEFUN (show_ip_bgp_view_rsclient,
10545 show_ip_bgp_view_rsclient_cmd,
10546 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10547 SHOW_STR
10548 IP_STR
10549 BGP_STR
10550 "BGP view\n"
10551 "BGP view name\n"
10552 "Information about Route Server Client\n"
10553 NEIGHBOR_ADDR_STR)
10554{
10555 struct bgp_table *table;
10556 struct peer *peer;
10557
10558 if (argc == 2)
10559 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10560 else
10561 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10562
10563 if (! peer)
10564 return CMD_WARNING;
10565
10566 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10567 {
10568 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10569 VTY_NEWLINE);
10570 return CMD_WARNING;
10571 }
10572
10573 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10574 PEER_FLAG_RSERVER_CLIENT))
10575 {
10576 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10577 VTY_NEWLINE);
10578 return CMD_WARNING;
10579 }
10580
10581 table = peer->rib[AFI_IP][SAFI_UNICAST];
10582
ajs5a646652004-11-05 01:25:55 +000010583 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010584}
10585
10586ALIAS (show_ip_bgp_view_rsclient,
10587 show_ip_bgp_rsclient_cmd,
10588 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10589 SHOW_STR
10590 IP_STR
10591 BGP_STR
10592 "Information about Route Server Client\n"
10593 NEIGHBOR_ADDR_STR)
10594
Michael Lambert95cbbd22010-07-23 14:43:04 -040010595DEFUN (show_bgp_view_ipv4_safi_rsclient,
10596 show_bgp_view_ipv4_safi_rsclient_cmd,
10597 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10598 SHOW_STR
10599 BGP_STR
10600 "BGP view\n"
10601 "BGP view name\n"
10602 "Address family\n"
10603 "Address Family modifier\n"
10604 "Address Family modifier\n"
10605 "Information about Route Server Client\n"
10606 NEIGHBOR_ADDR_STR)
10607{
10608 struct bgp_table *table;
10609 struct peer *peer;
10610 safi_t safi;
10611
10612 if (argc == 3) {
10613 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10614 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10615 } else {
10616 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10617 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10618 }
10619
10620 if (! peer)
10621 return CMD_WARNING;
10622
10623 if (! peer->afc[AFI_IP][safi])
10624 {
10625 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10626 VTY_NEWLINE);
10627 return CMD_WARNING;
10628 }
10629
10630 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10631 PEER_FLAG_RSERVER_CLIENT))
10632 {
10633 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10634 VTY_NEWLINE);
10635 return CMD_WARNING;
10636 }
10637
10638 table = peer->rib[AFI_IP][safi];
10639
10640 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10641}
10642
10643ALIAS (show_bgp_view_ipv4_safi_rsclient,
10644 show_bgp_ipv4_safi_rsclient_cmd,
10645 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10646 SHOW_STR
10647 BGP_STR
10648 "Address family\n"
10649 "Address Family modifier\n"
10650 "Address Family modifier\n"
10651 "Information about Route Server Client\n"
10652 NEIGHBOR_ADDR_STR)
10653
paulfee0f4c2004-09-13 05:12:46 +000010654DEFUN (show_ip_bgp_view_rsclient_route,
10655 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010656 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010657 SHOW_STR
10658 IP_STR
10659 BGP_STR
10660 "BGP view\n"
10661 "BGP view name\n"
10662 "Information about Route Server Client\n"
10663 NEIGHBOR_ADDR_STR
10664 "Network in the BGP routing table to display\n")
10665{
10666 struct bgp *bgp;
10667 struct peer *peer;
10668
10669 /* BGP structure lookup. */
10670 if (argc == 3)
10671 {
10672 bgp = bgp_lookup_by_name (argv[0]);
10673 if (bgp == NULL)
10674 {
10675 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10676 return CMD_WARNING;
10677 }
10678 }
10679 else
10680 {
10681 bgp = bgp_get_default ();
10682 if (bgp == NULL)
10683 {
10684 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10685 return CMD_WARNING;
10686 }
10687 }
10688
10689 if (argc == 3)
10690 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10691 else
10692 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10693
10694 if (! peer)
10695 return CMD_WARNING;
10696
10697 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10698 {
10699 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10700 VTY_NEWLINE);
10701 return CMD_WARNING;
10702}
10703
10704 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10705 PEER_FLAG_RSERVER_CLIENT))
10706 {
10707 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10708 VTY_NEWLINE);
10709 return CMD_WARNING;
10710 }
10711
10712 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10713 (argc == 3) ? argv[2] : argv[1],
10714 AFI_IP, SAFI_UNICAST, NULL, 0);
10715}
10716
10717ALIAS (show_ip_bgp_view_rsclient_route,
10718 show_ip_bgp_rsclient_route_cmd,
10719 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10720 SHOW_STR
10721 IP_STR
10722 BGP_STR
10723 "Information about Route Server Client\n"
10724 NEIGHBOR_ADDR_STR
10725 "Network in the BGP routing table to display\n")
10726
Michael Lambert95cbbd22010-07-23 14:43:04 -040010727DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10728 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10729 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10730 SHOW_STR
10731 BGP_STR
10732 "BGP view\n"
10733 "BGP view name\n"
10734 "Address family\n"
10735 "Address Family modifier\n"
10736 "Address Family modifier\n"
10737 "Information about Route Server Client\n"
10738 NEIGHBOR_ADDR_STR
10739 "Network in the BGP routing table to display\n")
10740{
10741 struct bgp *bgp;
10742 struct peer *peer;
10743 safi_t safi;
10744
10745 /* BGP structure lookup. */
10746 if (argc == 4)
10747 {
10748 bgp = bgp_lookup_by_name (argv[0]);
10749 if (bgp == NULL)
10750 {
10751 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10752 return CMD_WARNING;
10753 }
10754 }
10755 else
10756 {
10757 bgp = bgp_get_default ();
10758 if (bgp == NULL)
10759 {
10760 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10761 return CMD_WARNING;
10762 }
10763 }
10764
10765 if (argc == 4) {
10766 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10767 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10768 } else {
10769 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10770 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10771 }
10772
10773 if (! peer)
10774 return CMD_WARNING;
10775
10776 if (! peer->afc[AFI_IP][safi])
10777 {
10778 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10779 VTY_NEWLINE);
10780 return CMD_WARNING;
10781}
10782
10783 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10784 PEER_FLAG_RSERVER_CLIENT))
10785 {
10786 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10787 VTY_NEWLINE);
10788 return CMD_WARNING;
10789 }
10790
10791 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10792 (argc == 4) ? argv[3] : argv[2],
10793 AFI_IP, safi, NULL, 0);
10794}
10795
10796ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10797 show_bgp_ipv4_safi_rsclient_route_cmd,
10798 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10799 SHOW_STR
10800 BGP_STR
10801 "Address family\n"
10802 "Address Family modifier\n"
10803 "Address Family modifier\n"
10804 "Information about Route Server Client\n"
10805 NEIGHBOR_ADDR_STR
10806 "Network in the BGP routing table to display\n")
10807
paulfee0f4c2004-09-13 05:12:46 +000010808DEFUN (show_ip_bgp_view_rsclient_prefix,
10809 show_ip_bgp_view_rsclient_prefix_cmd,
10810 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10811 SHOW_STR
10812 IP_STR
10813 BGP_STR
10814 "BGP view\n"
10815 "BGP view name\n"
10816 "Information about Route Server Client\n"
10817 NEIGHBOR_ADDR_STR
10818 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10819{
10820 struct bgp *bgp;
10821 struct peer *peer;
10822
10823 /* BGP structure lookup. */
10824 if (argc == 3)
10825 {
10826 bgp = bgp_lookup_by_name (argv[0]);
10827 if (bgp == NULL)
10828 {
10829 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10830 return CMD_WARNING;
10831 }
10832 }
10833 else
10834 {
10835 bgp = bgp_get_default ();
10836 if (bgp == NULL)
10837 {
10838 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10839 return CMD_WARNING;
10840 }
10841 }
10842
10843 if (argc == 3)
10844 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10845 else
10846 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10847
10848 if (! peer)
10849 return CMD_WARNING;
10850
10851 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10852 {
10853 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10854 VTY_NEWLINE);
10855 return CMD_WARNING;
10856}
10857
10858 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10859 PEER_FLAG_RSERVER_CLIENT))
10860{
10861 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10862 VTY_NEWLINE);
10863 return CMD_WARNING;
10864 }
10865
10866 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10867 (argc == 3) ? argv[2] : argv[1],
10868 AFI_IP, SAFI_UNICAST, NULL, 1);
10869}
10870
10871ALIAS (show_ip_bgp_view_rsclient_prefix,
10872 show_ip_bgp_rsclient_prefix_cmd,
10873 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10874 SHOW_STR
10875 IP_STR
10876 BGP_STR
10877 "Information about Route Server Client\n"
10878 NEIGHBOR_ADDR_STR
10879 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10880
Michael Lambert95cbbd22010-07-23 14:43:04 -040010881DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10882 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10883 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10884 SHOW_STR
10885 BGP_STR
10886 "BGP view\n"
10887 "BGP view name\n"
10888 "Address family\n"
10889 "Address Family modifier\n"
10890 "Address Family modifier\n"
10891 "Information about Route Server Client\n"
10892 NEIGHBOR_ADDR_STR
10893 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10894{
10895 struct bgp *bgp;
10896 struct peer *peer;
10897 safi_t safi;
10898
10899 /* BGP structure lookup. */
10900 if (argc == 4)
10901 {
10902 bgp = bgp_lookup_by_name (argv[0]);
10903 if (bgp == NULL)
10904 {
10905 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10906 return CMD_WARNING;
10907 }
10908 }
10909 else
10910 {
10911 bgp = bgp_get_default ();
10912 if (bgp == NULL)
10913 {
10914 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10915 return CMD_WARNING;
10916 }
10917 }
10918
10919 if (argc == 4) {
10920 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10921 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10922 } else {
10923 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10924 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10925 }
10926
10927 if (! peer)
10928 return CMD_WARNING;
10929
10930 if (! peer->afc[AFI_IP][safi])
10931 {
10932 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10933 VTY_NEWLINE);
10934 return CMD_WARNING;
10935}
10936
10937 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10938 PEER_FLAG_RSERVER_CLIENT))
10939{
10940 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10941 VTY_NEWLINE);
10942 return CMD_WARNING;
10943 }
10944
10945 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10946 (argc == 4) ? argv[3] : argv[2],
10947 AFI_IP, safi, NULL, 1);
10948}
10949
10950ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10951 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10952 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10953 SHOW_STR
10954 BGP_STR
10955 "Address family\n"
10956 "Address Family modifier\n"
10957 "Address Family modifier\n"
10958 "Information about Route Server Client\n"
10959 NEIGHBOR_ADDR_STR
10960 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010961
paul718e3742002-12-13 20:15:29 +000010962#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010963DEFUN (show_bgp_view_neighbor_routes,
10964 show_bgp_view_neighbor_routes_cmd,
10965 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10966 SHOW_STR
10967 BGP_STR
10968 "BGP view\n"
10969 "BGP view name\n"
10970 "Detailed information on TCP and BGP neighbor connections\n"
10971 "Neighbor to display information about\n"
10972 "Neighbor to display information about\n"
10973 "Display routes learned from neighbor\n")
10974{
10975 struct peer *peer;
10976
10977 if (argc == 2)
10978 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10979 else
10980 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10981
10982 if (! peer)
10983 return CMD_WARNING;
10984
10985 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10986 bgp_show_type_neighbor);
10987}
10988
10989ALIAS (show_bgp_view_neighbor_routes,
10990 show_bgp_view_ipv6_neighbor_routes_cmd,
10991 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10992 SHOW_STR
10993 BGP_STR
10994 "BGP view\n"
10995 "BGP view name\n"
10996 "Address family\n"
10997 "Detailed information on TCP and BGP neighbor connections\n"
10998 "Neighbor to display information about\n"
10999 "Neighbor to display information about\n"
11000 "Display routes learned from neighbor\n")
11001
11002DEFUN (show_bgp_view_neighbor_damp,
11003 show_bgp_view_neighbor_damp_cmd,
11004 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11005 SHOW_STR
11006 BGP_STR
11007 "BGP view\n"
11008 "BGP view name\n"
11009 "Detailed information on TCP and BGP neighbor connections\n"
11010 "Neighbor to display information about\n"
11011 "Neighbor to display information about\n"
11012 "Display the dampened routes received from neighbor\n")
11013{
11014 struct peer *peer;
11015
11016 if (argc == 2)
11017 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11018 else
11019 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11020
11021 if (! peer)
11022 return CMD_WARNING;
11023
11024 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11025 bgp_show_type_damp_neighbor);
11026}
11027
11028ALIAS (show_bgp_view_neighbor_damp,
11029 show_bgp_view_ipv6_neighbor_damp_cmd,
11030 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11031 SHOW_STR
11032 BGP_STR
11033 "BGP view\n"
11034 "BGP view name\n"
11035 "Address family\n"
11036 "Detailed information on TCP and BGP neighbor connections\n"
11037 "Neighbor to display information about\n"
11038 "Neighbor to display information about\n"
11039 "Display the dampened routes received from neighbor\n")
11040
11041DEFUN (show_bgp_view_neighbor_flap,
11042 show_bgp_view_neighbor_flap_cmd,
11043 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11044 SHOW_STR
11045 BGP_STR
11046 "BGP view\n"
11047 "BGP view name\n"
11048 "Detailed information on TCP and BGP neighbor connections\n"
11049 "Neighbor to display information about\n"
11050 "Neighbor to display information about\n"
11051 "Display flap statistics of the routes learned from neighbor\n")
11052{
11053 struct peer *peer;
11054
11055 if (argc == 2)
11056 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11057 else
11058 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11059
11060 if (! peer)
11061 return CMD_WARNING;
11062
11063 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11064 bgp_show_type_flap_neighbor);
11065}
11066
11067ALIAS (show_bgp_view_neighbor_flap,
11068 show_bgp_view_ipv6_neighbor_flap_cmd,
11069 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11070 SHOW_STR
11071 BGP_STR
11072 "BGP view\n"
11073 "BGP view name\n"
11074 "Address family\n"
11075 "Detailed information on TCP and BGP neighbor connections\n"
11076 "Neighbor to display information about\n"
11077 "Neighbor to display information about\n"
11078 "Display flap statistics of the routes learned from neighbor\n")
11079
11080ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011081 show_bgp_neighbor_routes_cmd,
11082 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11083 SHOW_STR
11084 BGP_STR
11085 "Detailed information on TCP and BGP neighbor connections\n"
11086 "Neighbor to display information about\n"
11087 "Neighbor to display information about\n"
11088 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011089
paulbb46e942003-10-24 19:02:03 +000011090
11091ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011092 show_bgp_ipv6_neighbor_routes_cmd,
11093 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11094 SHOW_STR
11095 BGP_STR
11096 "Address family\n"
11097 "Detailed information on TCP and BGP neighbor connections\n"
11098 "Neighbor to display information about\n"
11099 "Neighbor to display information about\n"
11100 "Display routes learned from neighbor\n")
11101
11102/* old command */
paulbb46e942003-10-24 19:02:03 +000011103ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011104 ipv6_bgp_neighbor_routes_cmd,
11105 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11106 SHOW_STR
11107 IPV6_STR
11108 BGP_STR
11109 "Detailed information on TCP and BGP neighbor connections\n"
11110 "Neighbor to display information about\n"
11111 "Neighbor to display information about\n"
11112 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011113
11114/* old command */
11115DEFUN (ipv6_mbgp_neighbor_routes,
11116 ipv6_mbgp_neighbor_routes_cmd,
11117 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11118 SHOW_STR
11119 IPV6_STR
11120 MBGP_STR
11121 "Detailed information on TCP and BGP neighbor connections\n"
11122 "Neighbor to display information about\n"
11123 "Neighbor to display information about\n"
11124 "Display routes learned from neighbor\n")
11125{
paulbb46e942003-10-24 19:02:03 +000011126 struct peer *peer;
11127
11128 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11129 if (! peer)
11130 return CMD_WARNING;
11131
11132 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011133 bgp_show_type_neighbor);
11134}
paulbb46e942003-10-24 19:02:03 +000011135
11136ALIAS (show_bgp_view_neighbor_flap,
11137 show_bgp_neighbor_flap_cmd,
11138 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11139 SHOW_STR
11140 BGP_STR
11141 "Detailed information on TCP and BGP neighbor connections\n"
11142 "Neighbor to display information about\n"
11143 "Neighbor to display information about\n"
11144 "Display flap statistics of the routes learned from neighbor\n")
11145
11146ALIAS (show_bgp_view_neighbor_flap,
11147 show_bgp_ipv6_neighbor_flap_cmd,
11148 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11149 SHOW_STR
11150 BGP_STR
11151 "Address family\n"
11152 "Detailed information on TCP and BGP neighbor connections\n"
11153 "Neighbor to display information about\n"
11154 "Neighbor to display information about\n"
11155 "Display flap statistics of the routes learned from neighbor\n")
11156
11157ALIAS (show_bgp_view_neighbor_damp,
11158 show_bgp_neighbor_damp_cmd,
11159 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11160 SHOW_STR
11161 BGP_STR
11162 "Detailed information on TCP and BGP neighbor connections\n"
11163 "Neighbor to display information about\n"
11164 "Neighbor to display information about\n"
11165 "Display the dampened routes received from neighbor\n")
11166
11167ALIAS (show_bgp_view_neighbor_damp,
11168 show_bgp_ipv6_neighbor_damp_cmd,
11169 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11170 SHOW_STR
11171 BGP_STR
11172 "Address family\n"
11173 "Detailed information on TCP and BGP neighbor connections\n"
11174 "Neighbor to display information about\n"
11175 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011176 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011177
11178DEFUN (show_bgp_view_rsclient,
11179 show_bgp_view_rsclient_cmd,
11180 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11181 SHOW_STR
11182 BGP_STR
11183 "BGP view\n"
11184 "BGP view name\n"
11185 "Information about Route Server Client\n"
11186 NEIGHBOR_ADDR_STR)
11187{
11188 struct bgp_table *table;
11189 struct peer *peer;
11190
11191 if (argc == 2)
11192 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11193 else
11194 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11195
11196 if (! peer)
11197 return CMD_WARNING;
11198
11199 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11200 {
11201 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11202 VTY_NEWLINE);
11203 return CMD_WARNING;
11204 }
11205
11206 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11207 PEER_FLAG_RSERVER_CLIENT))
11208 {
11209 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11210 VTY_NEWLINE);
11211 return CMD_WARNING;
11212 }
11213
11214 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11215
ajs5a646652004-11-05 01:25:55 +000011216 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011217}
11218
11219ALIAS (show_bgp_view_rsclient,
11220 show_bgp_rsclient_cmd,
11221 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11222 SHOW_STR
11223 BGP_STR
11224 "Information about Route Server Client\n"
11225 NEIGHBOR_ADDR_STR)
11226
Michael Lambert95cbbd22010-07-23 14:43:04 -040011227DEFUN (show_bgp_view_ipv6_safi_rsclient,
11228 show_bgp_view_ipv6_safi_rsclient_cmd,
11229 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11230 SHOW_STR
11231 BGP_STR
11232 "BGP view\n"
11233 "BGP view name\n"
11234 "Address family\n"
11235 "Address Family modifier\n"
11236 "Address Family modifier\n"
11237 "Information about Route Server Client\n"
11238 NEIGHBOR_ADDR_STR)
11239{
11240 struct bgp_table *table;
11241 struct peer *peer;
11242 safi_t safi;
11243
11244 if (argc == 3) {
11245 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11246 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11247 } else {
11248 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11249 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11250 }
11251
11252 if (! peer)
11253 return CMD_WARNING;
11254
11255 if (! peer->afc[AFI_IP6][safi])
11256 {
11257 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11258 VTY_NEWLINE);
11259 return CMD_WARNING;
11260 }
11261
11262 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11263 PEER_FLAG_RSERVER_CLIENT))
11264 {
11265 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11266 VTY_NEWLINE);
11267 return CMD_WARNING;
11268 }
11269
11270 table = peer->rib[AFI_IP6][safi];
11271
11272 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11273}
11274
11275ALIAS (show_bgp_view_ipv6_safi_rsclient,
11276 show_bgp_ipv6_safi_rsclient_cmd,
11277 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11278 SHOW_STR
11279 BGP_STR
11280 "Address family\n"
11281 "Address Family modifier\n"
11282 "Address Family modifier\n"
11283 "Information about Route Server Client\n"
11284 NEIGHBOR_ADDR_STR)
11285
paulfee0f4c2004-09-13 05:12:46 +000011286DEFUN (show_bgp_view_rsclient_route,
11287 show_bgp_view_rsclient_route_cmd,
11288 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11289 SHOW_STR
11290 BGP_STR
11291 "BGP view\n"
11292 "BGP view name\n"
11293 "Information about Route Server Client\n"
11294 NEIGHBOR_ADDR_STR
11295 "Network in the BGP routing table to display\n")
11296{
11297 struct bgp *bgp;
11298 struct peer *peer;
11299
11300 /* BGP structure lookup. */
11301 if (argc == 3)
11302 {
11303 bgp = bgp_lookup_by_name (argv[0]);
11304 if (bgp == NULL)
11305 {
11306 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11307 return CMD_WARNING;
11308 }
11309 }
11310 else
11311 {
11312 bgp = bgp_get_default ();
11313 if (bgp == NULL)
11314 {
11315 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11316 return CMD_WARNING;
11317 }
11318 }
11319
11320 if (argc == 3)
11321 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11322 else
11323 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11324
11325 if (! peer)
11326 return CMD_WARNING;
11327
11328 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11329 {
11330 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11331 VTY_NEWLINE);
11332 return CMD_WARNING;
11333 }
11334
11335 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11336 PEER_FLAG_RSERVER_CLIENT))
11337 {
11338 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11339 VTY_NEWLINE);
11340 return CMD_WARNING;
11341 }
11342
11343 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11344 (argc == 3) ? argv[2] : argv[1],
11345 AFI_IP6, SAFI_UNICAST, NULL, 0);
11346}
11347
11348ALIAS (show_bgp_view_rsclient_route,
11349 show_bgp_rsclient_route_cmd,
11350 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11351 SHOW_STR
11352 BGP_STR
11353 "Information about Route Server Client\n"
11354 NEIGHBOR_ADDR_STR
11355 "Network in the BGP routing table to display\n")
11356
Michael Lambert95cbbd22010-07-23 14:43:04 -040011357DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11358 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11359 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11360 SHOW_STR
11361 BGP_STR
11362 "BGP view\n"
11363 "BGP view name\n"
11364 "Address family\n"
11365 "Address Family modifier\n"
11366 "Address Family modifier\n"
11367 "Information about Route Server Client\n"
11368 NEIGHBOR_ADDR_STR
11369 "Network in the BGP routing table to display\n")
11370{
11371 struct bgp *bgp;
11372 struct peer *peer;
11373 safi_t safi;
11374
11375 /* BGP structure lookup. */
11376 if (argc == 4)
11377 {
11378 bgp = bgp_lookup_by_name (argv[0]);
11379 if (bgp == NULL)
11380 {
11381 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11382 return CMD_WARNING;
11383 }
11384 }
11385 else
11386 {
11387 bgp = bgp_get_default ();
11388 if (bgp == NULL)
11389 {
11390 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11391 return CMD_WARNING;
11392 }
11393 }
11394
11395 if (argc == 4) {
11396 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11397 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11398 } else {
11399 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11400 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11401 }
11402
11403 if (! peer)
11404 return CMD_WARNING;
11405
11406 if (! peer->afc[AFI_IP6][safi])
11407 {
11408 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11409 VTY_NEWLINE);
11410 return CMD_WARNING;
11411}
11412
11413 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11414 PEER_FLAG_RSERVER_CLIENT))
11415 {
11416 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11417 VTY_NEWLINE);
11418 return CMD_WARNING;
11419 }
11420
11421 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11422 (argc == 4) ? argv[3] : argv[2],
11423 AFI_IP6, safi, NULL, 0);
11424}
11425
11426ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11427 show_bgp_ipv6_safi_rsclient_route_cmd,
11428 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11429 SHOW_STR
11430 BGP_STR
11431 "Address family\n"
11432 "Address Family modifier\n"
11433 "Address Family modifier\n"
11434 "Information about Route Server Client\n"
11435 NEIGHBOR_ADDR_STR
11436 "Network in the BGP routing table to display\n")
11437
paulfee0f4c2004-09-13 05:12:46 +000011438DEFUN (show_bgp_view_rsclient_prefix,
11439 show_bgp_view_rsclient_prefix_cmd,
11440 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11441 SHOW_STR
11442 BGP_STR
11443 "BGP view\n"
11444 "BGP view name\n"
11445 "Information about Route Server Client\n"
11446 NEIGHBOR_ADDR_STR
11447 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11448{
11449 struct bgp *bgp;
11450 struct peer *peer;
11451
11452 /* BGP structure lookup. */
11453 if (argc == 3)
11454 {
11455 bgp = bgp_lookup_by_name (argv[0]);
11456 if (bgp == NULL)
11457 {
11458 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11459 return CMD_WARNING;
11460 }
11461 }
11462 else
11463 {
11464 bgp = bgp_get_default ();
11465 if (bgp == NULL)
11466 {
11467 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11468 return CMD_WARNING;
11469 }
11470 }
11471
11472 if (argc == 3)
11473 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11474 else
11475 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11476
11477 if (! peer)
11478 return CMD_WARNING;
11479
11480 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11481 {
11482 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11483 VTY_NEWLINE);
11484 return CMD_WARNING;
11485 }
11486
11487 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11488 PEER_FLAG_RSERVER_CLIENT))
11489 {
11490 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11491 VTY_NEWLINE);
11492 return CMD_WARNING;
11493 }
11494
11495 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11496 (argc == 3) ? argv[2] : argv[1],
11497 AFI_IP6, SAFI_UNICAST, NULL, 1);
11498}
11499
11500ALIAS (show_bgp_view_rsclient_prefix,
11501 show_bgp_rsclient_prefix_cmd,
11502 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11503 SHOW_STR
11504 BGP_STR
11505 "Information about Route Server Client\n"
11506 NEIGHBOR_ADDR_STR
11507 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11508
Michael Lambert95cbbd22010-07-23 14:43:04 -040011509DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11510 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11511 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11512 SHOW_STR
11513 BGP_STR
11514 "BGP view\n"
11515 "BGP view name\n"
11516 "Address family\n"
11517 "Address Family modifier\n"
11518 "Address Family modifier\n"
11519 "Information about Route Server Client\n"
11520 NEIGHBOR_ADDR_STR
11521 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11522{
11523 struct bgp *bgp;
11524 struct peer *peer;
11525 safi_t safi;
11526
11527 /* BGP structure lookup. */
11528 if (argc == 4)
11529 {
11530 bgp = bgp_lookup_by_name (argv[0]);
11531 if (bgp == NULL)
11532 {
11533 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11534 return CMD_WARNING;
11535 }
11536 }
11537 else
11538 {
11539 bgp = bgp_get_default ();
11540 if (bgp == NULL)
11541 {
11542 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11543 return CMD_WARNING;
11544 }
11545 }
11546
11547 if (argc == 4) {
11548 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11549 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11550 } else {
11551 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11552 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11553 }
11554
11555 if (! peer)
11556 return CMD_WARNING;
11557
11558 if (! peer->afc[AFI_IP6][safi])
11559 {
11560 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11561 VTY_NEWLINE);
11562 return CMD_WARNING;
11563}
11564
11565 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11566 PEER_FLAG_RSERVER_CLIENT))
11567{
11568 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11569 VTY_NEWLINE);
11570 return CMD_WARNING;
11571 }
11572
11573 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11574 (argc == 4) ? argv[3] : argv[2],
11575 AFI_IP6, safi, NULL, 1);
11576}
11577
11578ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11579 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11580 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11581 SHOW_STR
11582 BGP_STR
11583 "Address family\n"
11584 "Address Family modifier\n"
11585 "Address Family modifier\n"
11586 "Information about Route Server Client\n"
11587 NEIGHBOR_ADDR_STR
11588 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11589
paul718e3742002-12-13 20:15:29 +000011590#endif /* HAVE_IPV6 */
11591
11592struct bgp_table *bgp_distance_table;
11593
11594struct bgp_distance
11595{
11596 /* Distance value for the IP source prefix. */
11597 u_char distance;
11598
11599 /* Name of the access-list to be matched. */
11600 char *access_list;
11601};
11602
paul94f2b392005-06-28 12:44:16 +000011603static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011604bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011605{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011606 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011607}
11608
paul94f2b392005-06-28 12:44:16 +000011609static void
paul718e3742002-12-13 20:15:29 +000011610bgp_distance_free (struct bgp_distance *bdistance)
11611{
11612 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11613}
11614
paul94f2b392005-06-28 12:44:16 +000011615static int
paulfd79ac92004-10-13 05:06:08 +000011616bgp_distance_set (struct vty *vty, const char *distance_str,
11617 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011618{
11619 int ret;
11620 struct prefix_ipv4 p;
11621 u_char distance;
11622 struct bgp_node *rn;
11623 struct bgp_distance *bdistance;
11624
11625 ret = str2prefix_ipv4 (ip_str, &p);
11626 if (ret == 0)
11627 {
11628 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11629 return CMD_WARNING;
11630 }
11631
11632 distance = atoi (distance_str);
11633
11634 /* Get BGP distance node. */
11635 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11636 if (rn->info)
11637 {
11638 bdistance = rn->info;
11639 bgp_unlock_node (rn);
11640 }
11641 else
11642 {
11643 bdistance = bgp_distance_new ();
11644 rn->info = bdistance;
11645 }
11646
11647 /* Set distance value. */
11648 bdistance->distance = distance;
11649
11650 /* Reset access-list configuration. */
11651 if (bdistance->access_list)
11652 {
11653 free (bdistance->access_list);
11654 bdistance->access_list = NULL;
11655 }
11656 if (access_list_str)
11657 bdistance->access_list = strdup (access_list_str);
11658
11659 return CMD_SUCCESS;
11660}
11661
paul94f2b392005-06-28 12:44:16 +000011662static int
paulfd79ac92004-10-13 05:06:08 +000011663bgp_distance_unset (struct vty *vty, const char *distance_str,
11664 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011665{
11666 int ret;
11667 struct prefix_ipv4 p;
11668 u_char distance;
11669 struct bgp_node *rn;
11670 struct bgp_distance *bdistance;
11671
11672 ret = str2prefix_ipv4 (ip_str, &p);
11673 if (ret == 0)
11674 {
11675 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11676 return CMD_WARNING;
11677 }
11678
11679 distance = atoi (distance_str);
11680
11681 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11682 if (! rn)
11683 {
11684 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11685 return CMD_WARNING;
11686 }
11687
11688 bdistance = rn->info;
11689
11690 if (bdistance->access_list)
11691 free (bdistance->access_list);
11692 bgp_distance_free (bdistance);
11693
11694 rn->info = NULL;
11695 bgp_unlock_node (rn);
11696 bgp_unlock_node (rn);
11697
11698 return CMD_SUCCESS;
11699}
11700
paul718e3742002-12-13 20:15:29 +000011701/* Apply BGP information to distance method. */
11702u_char
11703bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11704{
11705 struct bgp_node *rn;
11706 struct prefix_ipv4 q;
11707 struct peer *peer;
11708 struct bgp_distance *bdistance;
11709 struct access_list *alist;
11710 struct bgp_static *bgp_static;
11711
11712 if (! bgp)
11713 return 0;
11714
11715 if (p->family != AF_INET)
11716 return 0;
11717
11718 peer = rinfo->peer;
11719
11720 if (peer->su.sa.sa_family != AF_INET)
11721 return 0;
11722
11723 memset (&q, 0, sizeof (struct prefix_ipv4));
11724 q.family = AF_INET;
11725 q.prefix = peer->su.sin.sin_addr;
11726 q.prefixlen = IPV4_MAX_BITLEN;
11727
11728 /* Check source address. */
11729 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11730 if (rn)
11731 {
11732 bdistance = rn->info;
11733 bgp_unlock_node (rn);
11734
11735 if (bdistance->access_list)
11736 {
11737 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11738 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11739 return bdistance->distance;
11740 }
11741 else
11742 return bdistance->distance;
11743 }
11744
11745 /* Backdoor check. */
11746 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11747 if (rn)
11748 {
11749 bgp_static = rn->info;
11750 bgp_unlock_node (rn);
11751
11752 if (bgp_static->backdoor)
11753 {
11754 if (bgp->distance_local)
11755 return bgp->distance_local;
11756 else
11757 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11758 }
11759 }
11760
11761 if (peer_sort (peer) == BGP_PEER_EBGP)
11762 {
11763 if (bgp->distance_ebgp)
11764 return bgp->distance_ebgp;
11765 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11766 }
11767 else
11768 {
11769 if (bgp->distance_ibgp)
11770 return bgp->distance_ibgp;
11771 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11772 }
11773}
11774
11775DEFUN (bgp_distance,
11776 bgp_distance_cmd,
11777 "distance bgp <1-255> <1-255> <1-255>",
11778 "Define an administrative distance\n"
11779 "BGP distance\n"
11780 "Distance for routes external to the AS\n"
11781 "Distance for routes internal to the AS\n"
11782 "Distance for local routes\n")
11783{
11784 struct bgp *bgp;
11785
11786 bgp = vty->index;
11787
11788 bgp->distance_ebgp = atoi (argv[0]);
11789 bgp->distance_ibgp = atoi (argv[1]);
11790 bgp->distance_local = atoi (argv[2]);
11791 return CMD_SUCCESS;
11792}
11793
11794DEFUN (no_bgp_distance,
11795 no_bgp_distance_cmd,
11796 "no distance bgp <1-255> <1-255> <1-255>",
11797 NO_STR
11798 "Define an administrative distance\n"
11799 "BGP distance\n"
11800 "Distance for routes external to the AS\n"
11801 "Distance for routes internal to the AS\n"
11802 "Distance for local routes\n")
11803{
11804 struct bgp *bgp;
11805
11806 bgp = vty->index;
11807
11808 bgp->distance_ebgp= 0;
11809 bgp->distance_ibgp = 0;
11810 bgp->distance_local = 0;
11811 return CMD_SUCCESS;
11812}
11813
11814ALIAS (no_bgp_distance,
11815 no_bgp_distance2_cmd,
11816 "no distance bgp",
11817 NO_STR
11818 "Define an administrative distance\n"
11819 "BGP distance\n")
11820
11821DEFUN (bgp_distance_source,
11822 bgp_distance_source_cmd,
11823 "distance <1-255> A.B.C.D/M",
11824 "Define an administrative distance\n"
11825 "Administrative distance\n"
11826 "IP source prefix\n")
11827{
11828 bgp_distance_set (vty, argv[0], argv[1], NULL);
11829 return CMD_SUCCESS;
11830}
11831
11832DEFUN (no_bgp_distance_source,
11833 no_bgp_distance_source_cmd,
11834 "no distance <1-255> A.B.C.D/M",
11835 NO_STR
11836 "Define an administrative distance\n"
11837 "Administrative distance\n"
11838 "IP source prefix\n")
11839{
11840 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11841 return CMD_SUCCESS;
11842}
11843
11844DEFUN (bgp_distance_source_access_list,
11845 bgp_distance_source_access_list_cmd,
11846 "distance <1-255> A.B.C.D/M WORD",
11847 "Define an administrative distance\n"
11848 "Administrative distance\n"
11849 "IP source prefix\n"
11850 "Access list name\n")
11851{
11852 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11853 return CMD_SUCCESS;
11854}
11855
11856DEFUN (no_bgp_distance_source_access_list,
11857 no_bgp_distance_source_access_list_cmd,
11858 "no distance <1-255> A.B.C.D/M WORD",
11859 NO_STR
11860 "Define an administrative distance\n"
11861 "Administrative distance\n"
11862 "IP source prefix\n"
11863 "Access list name\n")
11864{
11865 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11866 return CMD_SUCCESS;
11867}
11868
11869DEFUN (bgp_damp_set,
11870 bgp_damp_set_cmd,
11871 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11872 "BGP Specific commands\n"
11873 "Enable route-flap dampening\n"
11874 "Half-life time for the penalty\n"
11875 "Value to start reusing a route\n"
11876 "Value to start suppressing a route\n"
11877 "Maximum duration to suppress a stable route\n")
11878{
11879 struct bgp *bgp;
11880 int half = DEFAULT_HALF_LIFE * 60;
11881 int reuse = DEFAULT_REUSE;
11882 int suppress = DEFAULT_SUPPRESS;
11883 int max = 4 * half;
11884
11885 if (argc == 4)
11886 {
11887 half = atoi (argv[0]) * 60;
11888 reuse = atoi (argv[1]);
11889 suppress = atoi (argv[2]);
11890 max = atoi (argv[3]) * 60;
11891 }
11892 else if (argc == 1)
11893 {
11894 half = atoi (argv[0]) * 60;
11895 max = 4 * half;
11896 }
11897
11898 bgp = vty->index;
11899 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11900 half, reuse, suppress, max);
11901}
11902
11903ALIAS (bgp_damp_set,
11904 bgp_damp_set2_cmd,
11905 "bgp dampening <1-45>",
11906 "BGP Specific commands\n"
11907 "Enable route-flap dampening\n"
11908 "Half-life time for the penalty\n")
11909
11910ALIAS (bgp_damp_set,
11911 bgp_damp_set3_cmd,
11912 "bgp dampening",
11913 "BGP Specific commands\n"
11914 "Enable route-flap dampening\n")
11915
11916DEFUN (bgp_damp_unset,
11917 bgp_damp_unset_cmd,
11918 "no bgp dampening",
11919 NO_STR
11920 "BGP Specific commands\n"
11921 "Enable route-flap dampening\n")
11922{
11923 struct bgp *bgp;
11924
11925 bgp = vty->index;
11926 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11927}
11928
11929ALIAS (bgp_damp_unset,
11930 bgp_damp_unset2_cmd,
11931 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11932 NO_STR
11933 "BGP Specific commands\n"
11934 "Enable route-flap dampening\n"
11935 "Half-life time for the penalty\n"
11936 "Value to start reusing a route\n"
11937 "Value to start suppressing a route\n"
11938 "Maximum duration to suppress a stable route\n")
11939
11940DEFUN (show_ip_bgp_dampened_paths,
11941 show_ip_bgp_dampened_paths_cmd,
11942 "show ip bgp dampened-paths",
11943 SHOW_STR
11944 IP_STR
11945 BGP_STR
11946 "Display paths suppressed due to dampening\n")
11947{
ajs5a646652004-11-05 01:25:55 +000011948 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11949 NULL);
paul718e3742002-12-13 20:15:29 +000011950}
11951
11952DEFUN (show_ip_bgp_flap_statistics,
11953 show_ip_bgp_flap_statistics_cmd,
11954 "show ip bgp flap-statistics",
11955 SHOW_STR
11956 IP_STR
11957 BGP_STR
11958 "Display flap statistics of routes\n")
11959{
ajs5a646652004-11-05 01:25:55 +000011960 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11961 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011962}
11963
11964/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011965static int
paulfd79ac92004-10-13 05:06:08 +000011966bgp_clear_damp_route (struct vty *vty, const char *view_name,
11967 const char *ip_str, afi_t afi, safi_t safi,
11968 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011969{
11970 int ret;
11971 struct prefix match;
11972 struct bgp_node *rn;
11973 struct bgp_node *rm;
11974 struct bgp_info *ri;
11975 struct bgp_info *ri_temp;
11976 struct bgp *bgp;
11977 struct bgp_table *table;
11978
11979 /* BGP structure lookup. */
11980 if (view_name)
11981 {
11982 bgp = bgp_lookup_by_name (view_name);
11983 if (bgp == NULL)
11984 {
11985 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11986 return CMD_WARNING;
11987 }
11988 }
11989 else
11990 {
11991 bgp = bgp_get_default ();
11992 if (bgp == NULL)
11993 {
11994 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11995 return CMD_WARNING;
11996 }
11997 }
11998
11999 /* Check IP address argument. */
12000 ret = str2prefix (ip_str, &match);
12001 if (! ret)
12002 {
12003 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
12004 return CMD_WARNING;
12005 }
12006
12007 match.family = afi2family (afi);
12008
12009 if (safi == SAFI_MPLS_VPN)
12010 {
12011 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
12012 {
12013 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
12014 continue;
12015
12016 if ((table = rn->info) != NULL)
12017 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012018 {
12019 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
12020 {
12021 ri = rm->info;
12022 while (ri)
12023 {
12024 if (ri->extra && ri->extra->damp_info)
12025 {
12026 ri_temp = ri->next;
12027 bgp_damp_info_free (ri->extra->damp_info, 1);
12028 ri = ri_temp;
12029 }
12030 else
12031 ri = ri->next;
12032 }
12033 }
12034
12035 bgp_unlock_node (rm);
12036 }
paul718e3742002-12-13 20:15:29 +000012037 }
12038 }
12039 else
12040 {
12041 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012042 {
12043 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12044 {
12045 ri = rn->info;
12046 while (ri)
12047 {
12048 if (ri->extra && ri->extra->damp_info)
12049 {
12050 ri_temp = ri->next;
12051 bgp_damp_info_free (ri->extra->damp_info, 1);
12052 ri = ri_temp;
12053 }
12054 else
12055 ri = ri->next;
12056 }
12057 }
12058
12059 bgp_unlock_node (rn);
12060 }
paul718e3742002-12-13 20:15:29 +000012061 }
12062
12063 return CMD_SUCCESS;
12064}
12065
12066DEFUN (clear_ip_bgp_dampening,
12067 clear_ip_bgp_dampening_cmd,
12068 "clear ip bgp dampening",
12069 CLEAR_STR
12070 IP_STR
12071 BGP_STR
12072 "Clear route flap dampening information\n")
12073{
12074 bgp_damp_info_clean ();
12075 return CMD_SUCCESS;
12076}
12077
12078DEFUN (clear_ip_bgp_dampening_prefix,
12079 clear_ip_bgp_dampening_prefix_cmd,
12080 "clear ip bgp dampening A.B.C.D/M",
12081 CLEAR_STR
12082 IP_STR
12083 BGP_STR
12084 "Clear route flap dampening information\n"
12085 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12086{
12087 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12088 SAFI_UNICAST, NULL, 1);
12089}
12090
12091DEFUN (clear_ip_bgp_dampening_address,
12092 clear_ip_bgp_dampening_address_cmd,
12093 "clear ip bgp dampening A.B.C.D",
12094 CLEAR_STR
12095 IP_STR
12096 BGP_STR
12097 "Clear route flap dampening information\n"
12098 "Network to clear damping information\n")
12099{
12100 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12101 SAFI_UNICAST, NULL, 0);
12102}
12103
12104DEFUN (clear_ip_bgp_dampening_address_mask,
12105 clear_ip_bgp_dampening_address_mask_cmd,
12106 "clear ip bgp dampening A.B.C.D A.B.C.D",
12107 CLEAR_STR
12108 IP_STR
12109 BGP_STR
12110 "Clear route flap dampening information\n"
12111 "Network to clear damping information\n"
12112 "Network mask\n")
12113{
12114 int ret;
12115 char prefix_str[BUFSIZ];
12116
12117 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12118 if (! ret)
12119 {
12120 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12121 return CMD_WARNING;
12122 }
12123
12124 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12125 SAFI_UNICAST, NULL, 0);
12126}
12127
paul94f2b392005-06-28 12:44:16 +000012128static int
paul718e3742002-12-13 20:15:29 +000012129bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12130 afi_t afi, safi_t safi, int *write)
12131{
12132 struct bgp_node *prn;
12133 struct bgp_node *rn;
12134 struct bgp_table *table;
12135 struct prefix *p;
12136 struct prefix_rd *prd;
12137 struct bgp_static *bgp_static;
12138 u_int32_t label;
12139 char buf[SU_ADDRSTRLEN];
12140 char rdbuf[RD_ADDRSTRLEN];
12141
12142 /* Network configuration. */
12143 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12144 if ((table = prn->info) != NULL)
12145 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12146 if ((bgp_static = rn->info) != NULL)
12147 {
12148 p = &rn->p;
12149 prd = (struct prefix_rd *) &prn->p;
12150
12151 /* "address-family" display. */
12152 bgp_config_write_family_header (vty, afi, safi, write);
12153
12154 /* "network" configuration display. */
12155 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12156 label = decode_label (bgp_static->tag);
12157
12158 vty_out (vty, " network %s/%d rd %s tag %d",
12159 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12160 p->prefixlen,
12161 rdbuf, label);
12162 vty_out (vty, "%s", VTY_NEWLINE);
12163 }
12164 return 0;
12165}
12166
12167/* Configuration of static route announcement and aggregate
12168 information. */
12169int
12170bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12171 afi_t afi, safi_t safi, int *write)
12172{
12173 struct bgp_node *rn;
12174 struct prefix *p;
12175 struct bgp_static *bgp_static;
12176 struct bgp_aggregate *bgp_aggregate;
12177 char buf[SU_ADDRSTRLEN];
12178
12179 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12180 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12181
12182 /* Network configuration. */
12183 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12184 if ((bgp_static = rn->info) != NULL)
12185 {
12186 p = &rn->p;
12187
12188 /* "address-family" display. */
12189 bgp_config_write_family_header (vty, afi, safi, write);
12190
12191 /* "network" configuration display. */
12192 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12193 {
12194 u_int32_t destination;
12195 struct in_addr netmask;
12196
12197 destination = ntohl (p->u.prefix4.s_addr);
12198 masklen2ip (p->prefixlen, &netmask);
12199 vty_out (vty, " network %s",
12200 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12201
12202 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12203 || (IN_CLASSB (destination) && p->prefixlen == 16)
12204 || (IN_CLASSA (destination) && p->prefixlen == 8)
12205 || p->u.prefix4.s_addr == 0)
12206 {
12207 /* Natural mask is not display. */
12208 }
12209 else
12210 vty_out (vty, " mask %s", inet_ntoa (netmask));
12211 }
12212 else
12213 {
12214 vty_out (vty, " network %s/%d",
12215 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12216 p->prefixlen);
12217 }
12218
12219 if (bgp_static->rmap.name)
12220 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012221 else
12222 {
12223 if (bgp_static->backdoor)
12224 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012225 }
paul718e3742002-12-13 20:15:29 +000012226
12227 vty_out (vty, "%s", VTY_NEWLINE);
12228 }
12229
12230 /* Aggregate-address configuration. */
12231 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12232 if ((bgp_aggregate = rn->info) != NULL)
12233 {
12234 p = &rn->p;
12235
12236 /* "address-family" display. */
12237 bgp_config_write_family_header (vty, afi, safi, write);
12238
12239 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12240 {
12241 struct in_addr netmask;
12242
12243 masklen2ip (p->prefixlen, &netmask);
12244 vty_out (vty, " aggregate-address %s %s",
12245 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12246 inet_ntoa (netmask));
12247 }
12248 else
12249 {
12250 vty_out (vty, " aggregate-address %s/%d",
12251 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12252 p->prefixlen);
12253 }
12254
12255 if (bgp_aggregate->as_set)
12256 vty_out (vty, " as-set");
12257
12258 if (bgp_aggregate->summary_only)
12259 vty_out (vty, " summary-only");
12260
12261 vty_out (vty, "%s", VTY_NEWLINE);
12262 }
12263
12264 return 0;
12265}
12266
12267int
12268bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12269{
12270 struct bgp_node *rn;
12271 struct bgp_distance *bdistance;
12272
12273 /* Distance configuration. */
12274 if (bgp->distance_ebgp
12275 && bgp->distance_ibgp
12276 && bgp->distance_local
12277 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12278 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12279 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12280 vty_out (vty, " distance bgp %d %d %d%s",
12281 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12282 VTY_NEWLINE);
12283
12284 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12285 if ((bdistance = rn->info) != NULL)
12286 {
12287 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12288 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12289 bdistance->access_list ? bdistance->access_list : "",
12290 VTY_NEWLINE);
12291 }
12292
12293 return 0;
12294}
12295
12296/* Allocate routing table structure and install commands. */
12297void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012298bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012299{
12300 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012301 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012302
12303 /* IPv4 BGP commands. */
12304 install_element (BGP_NODE, &bgp_network_cmd);
12305 install_element (BGP_NODE, &bgp_network_mask_cmd);
12306 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12307 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12308 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12309 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12310 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12311 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12312 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12313 install_element (BGP_NODE, &no_bgp_network_cmd);
12314 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12315 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12316 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12317 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12318 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12319 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12320 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12321 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12322
12323 install_element (BGP_NODE, &aggregate_address_cmd);
12324 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12325 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12326 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12327 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12328 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12329 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12330 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12331 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12332 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12333 install_element (BGP_NODE, &no_aggregate_address_cmd);
12334 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12335 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12336 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12337 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12338 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12339 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12340 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12341 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12342 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12343
12344 /* IPv4 unicast configuration. */
12345 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12346 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12347 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12348 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12349 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12350 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012351 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012352 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12353 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12354 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12355 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12356 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012357
paul718e3742002-12-13 20:15:29 +000012358 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12359 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12360 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12361 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12362 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12363 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12364 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12365 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12366 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12367 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12368 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12369 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12370 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12371 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12372 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12373 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12374 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12375 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12376 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12377 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12378
12379 /* IPv4 multicast configuration. */
12380 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12381 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12382 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12383 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12384 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12385 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12386 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12387 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12388 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12389 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12390 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12391 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12392 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12393 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12394 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12395 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12396 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12397 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12398 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12399 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12400 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12401 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12402 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12403 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12404 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12405 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12406 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12407 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12408 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12409 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12410 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12411 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12412
12413 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12414 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012415 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012416 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12417 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012418 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012419 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12420 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12421 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12422 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012423 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012424 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12425 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12426 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12427 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12428 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12429 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12430 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12431 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12432 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12433 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12434 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12435 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12436 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12437 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12438 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12439 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12440 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12441 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12442 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12443 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12444 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12445 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12446 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12447 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12448 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012449 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12450 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12451 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12452 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12453 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012454 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12455 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12456 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12457 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12458 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12459 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12460 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12462 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12463 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12466 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12467 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12468 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12470 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12471 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012472 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012473 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12475 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12476 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12477 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12478 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12479 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12480 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12481 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12482 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12483 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12484 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12485 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12486 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12487 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12488 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012489 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012490 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012491 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012492 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012493 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012494 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012495 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12496 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012497 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012498 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012499 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012500 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012501 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012502 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012503
12504 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12505 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12506 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012507 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012508 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12509 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12510 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012511 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012512 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12513 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12514 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12515 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12516 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12517 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12518 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12519 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12520 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12521 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12522 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12523 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012524 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12525 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12526 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12527 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12528 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012529 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12530 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12531 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12532 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12533 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12534 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12535 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12536 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12537 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012538 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012539 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012540 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012541 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012542 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012543 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012544 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012545
12546 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12547 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012548 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012549 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12550 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012551 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012552 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12553 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12554 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12555 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012556 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012557 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12558 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12559 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12560 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12561 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12562 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12563 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12564 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12565 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12566 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12567 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12568 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12569 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12570 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12571 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12572 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12573 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12574 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12575 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12576 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12577 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12578 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12579 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12580 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12581 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012582 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12583 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12584 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12585 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12586 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012587 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12588 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12589 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12590 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12591 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12592 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12593 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12595 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12596 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12599 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12600 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12601 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12603 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12604 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012605 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012606 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12608 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12609 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12610 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12611 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12612 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12613 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12614 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12615 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12616 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12617 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12620 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12621 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012622 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012623 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012624 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012625 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012626 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012627 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012628 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12629 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012630 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012631 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012632 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012633 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012634 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012635 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012636
12637 /* BGP dampening clear commands */
12638 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12639 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12640 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12641 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12642
Paul Jakmaff7924f2006-09-04 01:10:36 +000012643 /* prefix count */
12644 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12645 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12646 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012647#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012648 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12649
paul718e3742002-12-13 20:15:29 +000012650 /* New config IPv6 BGP commands. */
12651 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12652 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12653 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12654 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12655
12656 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12657 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12658 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12659 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12660
12661 /* Old config IPv6 BGP commands. */
12662 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12663 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12664
12665 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12666 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12667 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12668 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12669
12670 install_element (VIEW_NODE, &show_bgp_cmd);
12671 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012672 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012673 install_element (VIEW_NODE, &show_bgp_route_cmd);
12674 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012675 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012676 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12677 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012678 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012679 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12680 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12681 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12682 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12683 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12684 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12685 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12686 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12687 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12688 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12689 install_element (VIEW_NODE, &show_bgp_community_cmd);
12690 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12691 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12692 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12693 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12694 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12695 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12696 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12697 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12698 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12699 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12700 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12701 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12702 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12703 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12704 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12705 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12706 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12707 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12708 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12709 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12710 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12711 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12712 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12713 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12714 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12715 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12716 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12717 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12718 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012719 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12720 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12721 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12722 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012723 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012724 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012725 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012726 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012727 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012728 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012729 install_element (VIEW_NODE, &show_bgp_view_cmd);
12730 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12731 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12732 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12733 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12734 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12735 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12736 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12737 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12738 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12739 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12740 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12741 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12742 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12743 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12744 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12745 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12746 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012747 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012748 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012749 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012750 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012751 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012752 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012753
12754 /* Restricted:
12755 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12756 */
12757 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12758 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012759 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012760 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12761 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012762 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012763 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12764 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12765 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12766 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12767 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12768 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12769 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12770 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12771 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12772 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12773 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12774 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12775 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12776 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12777 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12778 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12779 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012780 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012781 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012782 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012783 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12784 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12785 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12786 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12787 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12788 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12789 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012790 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012791 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012792 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012793
12794 install_element (ENABLE_NODE, &show_bgp_cmd);
12795 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012796 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012797 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12798 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012799 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012800 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12801 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012802 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012803 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12804 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12805 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12806 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12807 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12808 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12809 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12810 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12811 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12812 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12813 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12814 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12815 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12816 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12817 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12818 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12819 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12820 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12821 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12822 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12823 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12824 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12825 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12826 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12827 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12828 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12829 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12830 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12831 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12832 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12833 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12834 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12835 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12836 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12837 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12838 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12839 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12840 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12841 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12842 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012843 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12844 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12845 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12846 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012847 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012848 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012849 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012850 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012851 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012852 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012853 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12856 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12857 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12861 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12862 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12863 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12864 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12865 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12866 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12867 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12868 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12869 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12870 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012871 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012872 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012873 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012874 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012875 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012876 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012877
12878 /* Statistics */
12879 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12880 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12881 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12882 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12883
paul718e3742002-12-13 20:15:29 +000012884 /* old command */
12885 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12886 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12887 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12888 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12889 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12890 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12891 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12892 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12893 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12894 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12895 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12896 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12897 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12898 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12899 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12900 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12901 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12902 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12903 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12904 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12905 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12906 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12907 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12908 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12909 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12910 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12911 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12912 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12913 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12914 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12915 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12916 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12917 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12918 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12919 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12920 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012921
paul718e3742002-12-13 20:15:29 +000012922 /* old command */
12923 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12924 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12925 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12926 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12927 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12928 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12929 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12930 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12931 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12932 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12933 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12934 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12935 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12936 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12937 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12938 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12939 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12940 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12941 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12942 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12943 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12944 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12945 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12946 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12947 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12948 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12949 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12950 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12951 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12952 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12953 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12954 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12955 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12956 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12957 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12958 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12959
12960 /* old command */
12961 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12962 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12963 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12964 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12965
12966 /* old command */
12967 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12968 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12969 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12970 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12971
12972 /* old command */
12973 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12974 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12975 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12976 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12977#endif /* HAVE_IPV6 */
12978
12979 install_element (BGP_NODE, &bgp_distance_cmd);
12980 install_element (BGP_NODE, &no_bgp_distance_cmd);
12981 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12982 install_element (BGP_NODE, &bgp_distance_source_cmd);
12983 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12984 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12985 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12986
12987 install_element (BGP_NODE, &bgp_damp_set_cmd);
12988 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12989 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12990 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12991 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12992 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12993 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12994 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12995 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12996 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012997
12998 /* Deprecated AS-Pathlimit commands */
12999 install_element (BGP_NODE, &bgp_network_ttl_cmd);
13000 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
13001 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
13002 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
13003 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13004 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13005
13006 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
13007 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
13008 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13009 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
13010 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13011 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13012
13013 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
13014 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
13015 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
13016 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
13017 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13018 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13019
13020 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
13021 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13022 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13023 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13024 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13025 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13026
13027 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13028 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13029 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13030 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13031 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13032 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13033
13034 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13035 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13036 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13037 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13038 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13039 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013040
13041#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013042 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13043 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013044#endif
paul718e3742002-12-13 20:15:29 +000013045}
Chris Caputo228da422009-07-18 05:44:03 +000013046
13047void
13048bgp_route_finish (void)
13049{
13050 bgp_table_unlock (bgp_distance_table);
13051 bgp_distance_table = NULL;
13052}