blob: f3e46221caf0b57a856f10de80bd48bdec731d0b [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;
1319 if (ri1->next)
1320 for (ri2 = ri1->next; ri2; ri2 = ri2->next)
1321 {
1322 if (CHECK_FLAG (ri2->flags, BGP_INFO_DMED_CHECK))
1323 continue;
1324 if (BGP_INFO_HOLDDOWN (ri2))
1325 continue;
1326
1327 if (aspath_cmp_left (ri1->attr->aspath, ri2->attr->aspath)
1328 || aspath_cmp_left_confed (ri1->attr->aspath,
1329 ri2->attr->aspath))
1330 {
Josh Bailey96450fa2011-07-20 20:45:12 -07001331 if (bgp_info_cmp (bgp, ri2, new_select, &paths_eq))
paul718e3742002-12-13 20:15:29 +00001332 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001333 bgp_info_unset_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001334 new_select = ri2;
1335 }
1336
Paul Jakma1a392d42006-09-07 00:24:49 +00001337 bgp_info_set_flag (rn, ri2, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001338 }
1339 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001340 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_CHECK);
1341 bgp_info_set_flag (rn, new_select, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001342 }
1343
1344 /* Check old selected route and new selected route. */
1345 old_select = NULL;
1346 new_select = NULL;
paulb40d9392005-08-22 22:34:41 +00001347 for (ri = rn->info; (ri != NULL) && (nextri = ri->next, 1); ri = nextri)
paul718e3742002-12-13 20:15:29 +00001348 {
1349 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
1350 old_select = ri;
1351
1352 if (BGP_INFO_HOLDDOWN (ri))
paulb40d9392005-08-22 22:34:41 +00001353 {
1354 /* reap REMOVED routes, if needs be
1355 * selected route must stay for a while longer though
1356 */
1357 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
1358 && (ri != old_select))
1359 bgp_info_reap (rn, ri);
1360
1361 continue;
1362 }
paul718e3742002-12-13 20:15:29 +00001363
1364 if (bgp_flag_check (bgp, BGP_FLAG_DETERMINISTIC_MED)
1365 && (! CHECK_FLAG (ri->flags, BGP_INFO_DMED_SELECTED)))
1366 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001367 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
paul718e3742002-12-13 20:15:29 +00001368 continue;
1369 }
Paul Jakma1a392d42006-09-07 00:24:49 +00001370 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_CHECK);
1371 bgp_info_unset_flag (rn, ri, BGP_INFO_DMED_SELECTED);
paul718e3742002-12-13 20:15:29 +00001372
Josh Bailey96450fa2011-07-20 20:45:12 -07001373 if (bgp_info_cmp (bgp, ri, new_select, &paths_eq))
1374 {
1375 new_select = ri;
1376
1377 if (do_mpath && !paths_eq)
1378 {
1379 bgp_mp_list_clear (&mp_list);
1380 bgp_mp_list_add (&mp_list, ri);
1381 }
1382 }
1383
1384 if (do_mpath && paths_eq)
1385 bgp_mp_list_add (&mp_list, ri);
paul718e3742002-12-13 20:15:29 +00001386 }
paulb40d9392005-08-22 22:34:41 +00001387
paulfee0f4c2004-09-13 05:12:46 +00001388
Josh Baileyde8d5df2011-07-20 20:46:01 -07001389 bgp_info_mpath_update (rn, new_select, old_select, &mp_list, mpath_cfg);
Josh Bailey96450fa2011-07-20 20:45:12 -07001390
1391 bgp_mp_list_clear (&mp_list);
1392
1393 result->old = old_select;
1394 result->new = new_select;
1395
1396 return;
paulfee0f4c2004-09-13 05:12:46 +00001397}
1398
paul94f2b392005-06-28 12:44:16 +00001399static int
paulfee0f4c2004-09-13 05:12:46 +00001400bgp_process_announce_selected (struct peer *peer, struct bgp_info *selected,
Paul Jakma9eda90c2007-08-30 13:36:17 +00001401 struct bgp_node *rn, afi_t afi, safi_t safi)
1402{
paulfee0f4c2004-09-13 05:12:46 +00001403 struct prefix *p;
Paul Jakma9eda90c2007-08-30 13:36:17 +00001404 struct attr attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001405
1406 p = &rn->p;
1407
Paul Jakma9eda90c2007-08-30 13:36:17 +00001408 /* Announce route to Established peer. */
1409 if (peer->status != Established)
paulfee0f4c2004-09-13 05:12:46 +00001410 return 0;
1411
Paul Jakma9eda90c2007-08-30 13:36:17 +00001412 /* Address family configuration check. */
1413 if (! peer->afc_nego[afi][safi])
paulfee0f4c2004-09-13 05:12:46 +00001414 return 0;
1415
Paul Jakma9eda90c2007-08-30 13:36:17 +00001416 /* First update is deferred until ORF or ROUTE-REFRESH is received */
paulfee0f4c2004-09-13 05:12:46 +00001417 if (CHECK_FLAG (peer->af_sflags[afi][safi],
1418 PEER_STATUS_ORF_WAIT_REFRESH))
1419 return 0;
1420
1421 switch (rn->table->type)
1422 {
1423 case BGP_TABLE_MAIN:
1424 /* Announcement to peer->conf. If the route is filtered,
1425 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001426 if (selected && bgp_announce_check (selected, peer, p, &attr, afi, safi))
1427 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
paulfee0f4c2004-09-13 05:12:46 +00001428 else
1429 bgp_adj_out_unset (rn, peer, p, afi, safi);
1430 break;
1431 case BGP_TABLE_RSCLIENT:
1432 /* Announcement to peer->conf. If the route is filtered,
1433 withdraw it. */
Paul Jakma9eda90c2007-08-30 13:36:17 +00001434 if (selected &&
1435 bgp_announce_check_rsclient (selected, peer, p, &attr, afi, safi))
1436 bgp_adj_out_set (rn, peer, p, &attr, afi, safi, selected);
1437 else
1438 bgp_adj_out_unset (rn, peer, p, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001439 break;
1440 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001441
1442 bgp_attr_extra_free (&attr);
1443
paulfee0f4c2004-09-13 05:12:46 +00001444 return 0;
paul200df112005-06-01 11:17:05 +00001445}
paulfee0f4c2004-09-13 05:12:46 +00001446
paul200df112005-06-01 11:17:05 +00001447struct bgp_process_queue
paulfee0f4c2004-09-13 05:12:46 +00001448{
paul200df112005-06-01 11:17:05 +00001449 struct bgp *bgp;
1450 struct bgp_node *rn;
1451 afi_t afi;
1452 safi_t safi;
1453};
1454
1455static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001456bgp_process_rsclient (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001457{
paul0fb58d52005-11-14 14:31:49 +00001458 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001459 struct bgp *bgp = pq->bgp;
1460 struct bgp_node *rn = pq->rn;
1461 afi_t afi = pq->afi;
1462 safi_t safi = pq->safi;
paulfee0f4c2004-09-13 05:12:46 +00001463 struct bgp_info *new_select;
1464 struct bgp_info *old_select;
1465 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001466 struct listnode *node, *nnode;
paul200df112005-06-01 11:17:05 +00001467 struct peer *rsclient = rn->table->owner;
1468
paulfee0f4c2004-09-13 05:12:46 +00001469 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001470 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001471 new_select = old_and_new.new;
1472 old_select = old_and_new.old;
1473
paul200df112005-06-01 11:17:05 +00001474 if (CHECK_FLAG (rsclient->sflags, PEER_STATUS_GROUP))
1475 {
Chris Caputo228da422009-07-18 05:44:03 +00001476 if (rsclient->group)
1477 for (ALL_LIST_ELEMENTS (rsclient->group->peer, node, nnode, rsclient))
1478 {
1479 /* Nothing to do. */
1480 if (old_select && old_select == new_select)
1481 if (!CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
1482 continue;
paulfee0f4c2004-09-13 05:12:46 +00001483
Chris Caputo228da422009-07-18 05:44:03 +00001484 if (old_select)
1485 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
1486 if (new_select)
1487 {
1488 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1489 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001490 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
1491 }
paulfee0f4c2004-09-13 05:12:46 +00001492
Chris Caputo228da422009-07-18 05:44:03 +00001493 bgp_process_announce_selected (rsclient, new_select, rn,
1494 afi, safi);
1495 }
paul200df112005-06-01 11:17:05 +00001496 }
1497 else
1498 {
hassob7395792005-08-26 12:58:38 +00001499 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001500 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001501 if (new_select)
1502 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001503 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1504 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001505 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hassob7395792005-08-26 12:58:38 +00001506 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001507 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001508 }
paulfee0f4c2004-09-13 05:12:46 +00001509
paulb40d9392005-08-22 22:34:41 +00001510 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1511 bgp_info_reap (rn, old_select);
1512
paul200df112005-06-01 11:17:05 +00001513 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1514 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001515}
1516
paul200df112005-06-01 11:17:05 +00001517static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001518bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001519{
paul0fb58d52005-11-14 14:31:49 +00001520 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001521 struct bgp *bgp = pq->bgp;
1522 struct bgp_node *rn = pq->rn;
1523 afi_t afi = pq->afi;
1524 safi_t safi = pq->safi;
1525 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001526 struct bgp_info *new_select;
1527 struct bgp_info *old_select;
1528 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001529 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001530 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001531
paulfee0f4c2004-09-13 05:12:46 +00001532 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001533 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001534 old_select = old_and_new.old;
1535 new_select = old_and_new.new;
1536
1537 /* Nothing to do. */
1538 if (old_select && old_select == new_select)
1539 {
1540 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001541 {
Josh Bailey8196f132011-07-20 20:47:07 -07001542 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED) ||
1543 CHECK_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG))
paul200df112005-06-01 11:17:05 +00001544 bgp_zebra_announce (p, old_select, bgp);
1545
Josh Bailey8196f132011-07-20 20:47:07 -07001546 UNSET_FLAG (old_select->flags, BGP_INFO_MULTIPATH_CHG);
paul200df112005-06-01 11:17:05 +00001547 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1548 return WQ_SUCCESS;
1549 }
paulfee0f4c2004-09-13 05:12:46 +00001550 }
paul718e3742002-12-13 20:15:29 +00001551
hasso338b3422005-02-23 14:27:24 +00001552 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001553 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001554 if (new_select)
1555 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001556 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1557 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
Josh Bailey8196f132011-07-20 20:47:07 -07001558 UNSET_FLAG (new_select->flags, BGP_INFO_MULTIPATH_CHG);
hasso338b3422005-02-23 14:27:24 +00001559 }
1560
1561
paul718e3742002-12-13 20:15:29 +00001562 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001563 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001564 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001565 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001566 }
1567
1568 /* FIB update. */
1569 if (safi == SAFI_UNICAST && ! bgp->name &&
1570 ! bgp_option_check (BGP_OPT_NO_FIB))
1571 {
1572 if (new_select
1573 && new_select->type == ZEBRA_ROUTE_BGP
1574 && new_select->sub_type == BGP_ROUTE_NORMAL)
1575 bgp_zebra_announce (p, new_select, bgp);
1576 else
1577 {
1578 /* Withdraw the route from the kernel. */
1579 if (old_select
1580 && old_select->type == ZEBRA_ROUTE_BGP
1581 && old_select->sub_type == BGP_ROUTE_NORMAL)
1582 bgp_zebra_withdraw (p, old_select);
1583 }
1584 }
paulb40d9392005-08-22 22:34:41 +00001585
1586 /* Reap old select bgp_info, it it has been removed */
1587 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1588 bgp_info_reap (rn, old_select);
1589
paul200df112005-06-01 11:17:05 +00001590 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1591 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001592}
1593
paul200df112005-06-01 11:17:05 +00001594static void
paul0fb58d52005-11-14 14:31:49 +00001595bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001596{
paul0fb58d52005-11-14 14:31:49 +00001597 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001598 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001599
Chris Caputo228da422009-07-18 05:44:03 +00001600 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001601 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001602 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001603 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1604}
1605
1606static void
1607bgp_process_queue_init (void)
1608{
1609 bm->process_main_queue
1610 = work_queue_new (bm->master, "process_main_queue");
1611 bm->process_rsclient_queue
1612 = work_queue_new (bm->master, "process_rsclient_queue");
1613
1614 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1615 {
1616 zlog_err ("%s: Failed to allocate work queue", __func__);
1617 exit (1);
1618 }
1619
1620 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001621 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001622 bm->process_main_queue->spec.max_retries = 0;
1623 bm->process_main_queue->spec.hold = 50;
1624
1625 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1626 sizeof (struct work_queue *));
1627 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001628}
1629
1630void
paulfee0f4c2004-09-13 05:12:46 +00001631bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1632{
paul200df112005-06-01 11:17:05 +00001633 struct bgp_process_queue *pqnode;
1634
1635 /* already scheduled for processing? */
1636 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1637 return;
1638
1639 if ( (bm->process_main_queue == NULL) ||
1640 (bm->process_rsclient_queue == NULL) )
1641 bgp_process_queue_init ();
1642
1643 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1644 sizeof (struct bgp_process_queue));
1645 if (!pqnode)
1646 return;
Chris Caputo228da422009-07-18 05:44:03 +00001647
1648 /* all unlocked in bgp_processq_del */
1649 bgp_table_lock (rn->table);
1650 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001651 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001652 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001653 pqnode->afi = afi;
1654 pqnode->safi = safi;
1655
paulfee0f4c2004-09-13 05:12:46 +00001656 switch (rn->table->type)
1657 {
paul200df112005-06-01 11:17:05 +00001658 case BGP_TABLE_MAIN:
1659 work_queue_add (bm->process_main_queue, pqnode);
1660 break;
1661 case BGP_TABLE_RSCLIENT:
1662 work_queue_add (bm->process_rsclient_queue, pqnode);
1663 break;
paulfee0f4c2004-09-13 05:12:46 +00001664 }
paul200df112005-06-01 11:17:05 +00001665
1666 return;
paulfee0f4c2004-09-13 05:12:46 +00001667}
hasso0a486e52005-02-01 20:57:17 +00001668
paul94f2b392005-06-28 12:44:16 +00001669static int
hasso0a486e52005-02-01 20:57:17 +00001670bgp_maximum_prefix_restart_timer (struct thread *thread)
1671{
1672 struct peer *peer;
1673
1674 peer = THREAD_ARG (thread);
1675 peer->t_pmax_restart = NULL;
1676
1677 if (BGP_DEBUG (events, EVENTS))
1678 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1679 peer->host);
1680
1681 peer_clear (peer);
1682
1683 return 0;
1684}
1685
paulfee0f4c2004-09-13 05:12:46 +00001686int
paul5228ad22004-06-04 17:58:18 +00001687bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1688 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001689{
hassoe0701b72004-05-20 09:19:34 +00001690 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1691 return 0;
1692
1693 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001694 {
hassoe0701b72004-05-20 09:19:34 +00001695 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1696 && ! always)
1697 return 0;
paul718e3742002-12-13 20:15:29 +00001698
hassoe0701b72004-05-20 09:19:34 +00001699 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001700 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1701 "limit %ld", afi_safi_print (afi, safi), peer->host,
1702 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001703 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001704
hassoe0701b72004-05-20 09:19:34 +00001705 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1706 return 0;
paul718e3742002-12-13 20:15:29 +00001707
hassoe0701b72004-05-20 09:19:34 +00001708 {
paul5228ad22004-06-04 17:58:18 +00001709 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001710
1711 if (safi == SAFI_MPLS_VPN)
1712 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001713
1714 ndata[0] = (afi >> 8);
1715 ndata[1] = afi;
1716 ndata[2] = safi;
1717 ndata[3] = (peer->pmax[afi][safi] >> 24);
1718 ndata[4] = (peer->pmax[afi][safi] >> 16);
1719 ndata[5] = (peer->pmax[afi][safi] >> 8);
1720 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001721
1722 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1723 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1724 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1725 }
hasso0a486e52005-02-01 20:57:17 +00001726
1727 /* restart timer start */
1728 if (peer->pmax_restart[afi][safi])
1729 {
1730 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1731
1732 if (BGP_DEBUG (events, EVENTS))
1733 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1734 peer->host, peer->v_pmax_restart);
1735
1736 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1737 peer->v_pmax_restart);
1738 }
1739
hassoe0701b72004-05-20 09:19:34 +00001740 return 1;
paul718e3742002-12-13 20:15:29 +00001741 }
hassoe0701b72004-05-20 09:19:34 +00001742 else
1743 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1744
1745 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1746 {
1747 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1748 && ! always)
1749 return 0;
1750
1751 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001752 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1753 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1754 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001755 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1756 }
1757 else
1758 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001759 return 0;
1760}
1761
paulb40d9392005-08-22 22:34:41 +00001762/* Unconditionally remove the route from the RIB, without taking
1763 * damping into consideration (eg, because the session went down)
1764 */
paul94f2b392005-06-28 12:44:16 +00001765static void
paul718e3742002-12-13 20:15:29 +00001766bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1767 afi_t afi, safi_t safi)
1768{
paul902212c2006-02-05 17:51:19 +00001769 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1770
1771 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1772 bgp_info_delete (rn, ri); /* keep historical info */
1773
paulb40d9392005-08-22 22:34:41 +00001774 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001775}
1776
paul94f2b392005-06-28 12:44:16 +00001777static void
paul718e3742002-12-13 20:15:29 +00001778bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001779 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001780{
paul718e3742002-12-13 20:15:29 +00001781 int status = BGP_DAMP_NONE;
1782
paulb40d9392005-08-22 22:34:41 +00001783 /* apply dampening, if result is suppressed, we'll be retaining
1784 * the bgp_info in the RIB for historical reference.
1785 */
1786 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1787 && peer_sort (peer) == BGP_PEER_EBGP)
1788 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1789 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001790 {
paul902212c2006-02-05 17:51:19 +00001791 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1792 return;
1793 }
1794
1795 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001796}
1797
paul94f2b392005-06-28 12:44:16 +00001798static void
paulfee0f4c2004-09-13 05:12:46 +00001799bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1800 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1801 int sub_type, struct prefix_rd *prd, u_char *tag)
1802{
1803 struct bgp_node *rn;
1804 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001805 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001806 struct attr *attr_new;
1807 struct attr *attr_new2;
1808 struct bgp_info *ri;
1809 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001810 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001811 char buf[SU_ADDRSTRLEN];
1812
1813 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1814 if (peer == rsclient)
1815 return;
1816
1817 bgp = peer->bgp;
1818 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1819
1820 /* Check previously received route. */
1821 for (ri = rn->info; ri; ri = ri->next)
1822 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1823 break;
1824
1825 /* AS path loop check. */
1826 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1827 {
1828 reason = "as-path contains our own AS;";
1829 goto filtered;
1830 }
1831
1832 /* Route reflector originator ID check. */
1833 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001834 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001835 {
1836 reason = "originator is us;";
1837 goto filtered;
1838 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001839
1840 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001841
1842 /* Apply export policy. */
1843 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1844 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1845 {
1846 reason = "export-policy;";
1847 goto filtered;
1848 }
1849
1850 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001851
paulfee0f4c2004-09-13 05:12:46 +00001852 /* Apply import policy. */
1853 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1854 {
1855 bgp_attr_unintern (attr_new2);
1856
1857 reason = "import-policy;";
1858 goto filtered;
1859 }
1860
1861 attr_new = bgp_attr_intern (&new_attr);
1862 bgp_attr_unintern (attr_new2);
1863
1864 /* IPv4 unicast next hop check. */
1865 if (afi == AFI_IP && safi == SAFI_UNICAST)
1866 {
1867 /* Next hop must not be 0.0.0.0 nor Class E address. */
1868 if (new_attr.nexthop.s_addr == 0
1869 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1870 {
1871 bgp_attr_unintern (attr_new);
1872
1873 reason = "martian next-hop;";
1874 goto filtered;
1875 }
1876 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001877
1878 /* new_attr isn't passed to any functions after here */
1879 bgp_attr_extra_free (&new_attr);
1880
paulfee0f4c2004-09-13 05:12:46 +00001881 /* If the update is implicit withdraw. */
1882 if (ri)
1883 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001884 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001885
1886 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001887 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1888 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001889 {
1890
Paul Jakma1a392d42006-09-07 00:24:49 +00001891 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001892
1893 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001894 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001895 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1896 peer->host,
1897 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1898 p->prefixlen, rsclient->host);
1899
Chris Caputo228da422009-07-18 05:44:03 +00001900 bgp_unlock_node (rn);
1901 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001902
Chris Caputo228da422009-07-18 05:44:03 +00001903 return;
paulfee0f4c2004-09-13 05:12:46 +00001904 }
1905
Paul Jakma16d2e242007-04-10 19:32:10 +00001906 /* Withdraw/Announce before we fully processed the withdraw */
1907 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1908 bgp_info_restore (rn, ri);
1909
paulfee0f4c2004-09-13 05:12:46 +00001910 /* Received Logging. */
1911 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001912 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001913 peer->host,
1914 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1915 p->prefixlen, rsclient->host);
1916
1917 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001918 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001919
1920 /* Update to new attribute. */
1921 bgp_attr_unintern (ri->attr);
1922 ri->attr = attr_new;
1923
1924 /* Update MPLS tag. */
1925 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001926 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001927
Paul Jakma1a392d42006-09-07 00:24:49 +00001928 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001929
1930 /* Process change. */
1931 bgp_process (bgp, rn, afi, safi);
1932 bgp_unlock_node (rn);
1933
1934 return;
1935 }
1936
1937 /* Received Logging. */
1938 if (BGP_DEBUG (update, UPDATE_IN))
1939 {
ajsd2c1f162004-12-08 21:10:20 +00001940 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001941 peer->host,
1942 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1943 p->prefixlen, rsclient->host);
1944 }
1945
1946 /* Make new BGP info. */
1947 new = bgp_info_new ();
1948 new->type = type;
1949 new->sub_type = sub_type;
1950 new->peer = peer;
1951 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001952 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001953
1954 /* Update MPLS tag. */
1955 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001956 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001957
Paul Jakma1a392d42006-09-07 00:24:49 +00001958 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001959
1960 /* Register new BGP information. */
1961 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001962
1963 /* route_node_get lock */
1964 bgp_unlock_node (rn);
1965
paulfee0f4c2004-09-13 05:12:46 +00001966 /* Process change. */
1967 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001968
1969 bgp_attr_extra_free (&new_attr);
1970
paulfee0f4c2004-09-13 05:12:46 +00001971 return;
1972
1973 filtered:
1974
1975 /* This BGP update is filtered. Log the reason then update BGP entry. */
1976 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001977 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001978 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1979 peer->host,
1980 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1981 p->prefixlen, rsclient->host, reason);
1982
1983 if (ri)
paulb40d9392005-08-22 22:34:41 +00001984 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001985
1986 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001987
1988 if (new_attr.extra)
1989 bgp_attr_extra_free (&new_attr);
1990
paulfee0f4c2004-09-13 05:12:46 +00001991 return;
1992}
1993
paul94f2b392005-06-28 12:44:16 +00001994static void
paulfee0f4c2004-09-13 05:12:46 +00001995bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1996 struct peer *peer, struct prefix *p, int type, int sub_type,
1997 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00001998{
paulfee0f4c2004-09-13 05:12:46 +00001999 struct bgp_node *rn;
2000 struct bgp_info *ri;
2001 char buf[SU_ADDRSTRLEN];
2002
2003 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00002004 return;
paulfee0f4c2004-09-13 05:12:46 +00002005
2006 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2007
2008 /* Lookup withdrawn route. */
2009 for (ri = rn->info; ri; ri = ri->next)
2010 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2011 break;
2012
2013 /* Withdraw specified route from routing table. */
2014 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002015 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002016 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002017 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002018 "%s Can't find the route %s/%d", peer->host,
2019 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2020 p->prefixlen);
2021
2022 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002023 bgp_unlock_node (rn);
2024}
paulfee0f4c2004-09-13 05:12:46 +00002025
paul94f2b392005-06-28 12:44:16 +00002026static int
paulfee0f4c2004-09-13 05:12:46 +00002027bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002028 afi_t afi, safi_t safi, int type, int sub_type,
2029 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2030{
2031 int ret;
2032 int aspath_loop_count = 0;
2033 struct bgp_node *rn;
2034 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002035 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002036 struct attr *attr_new;
2037 struct bgp_info *ri;
2038 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002039 const char *reason;
paul718e3742002-12-13 20:15:29 +00002040 char buf[SU_ADDRSTRLEN];
2041
2042 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002043 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002044
paul718e3742002-12-13 20:15:29 +00002045 /* When peer's soft reconfiguration enabled. Record input packet in
2046 Adj-RIBs-In. */
2047 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2048 && peer != bgp->peer_self && ! soft_reconfig)
2049 bgp_adj_in_set (rn, peer, attr);
2050
2051 /* Check previously received route. */
2052 for (ri = rn->info; ri; ri = ri->next)
2053 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2054 break;
2055
2056 /* AS path local-as loop check. */
2057 if (peer->change_local_as)
2058 {
2059 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2060 aspath_loop_count = 1;
2061
2062 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2063 {
2064 reason = "as-path contains our own AS;";
2065 goto filtered;
2066 }
2067 }
2068
2069 /* AS path loop check. */
2070 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2071 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2072 && aspath_loop_check(attr->aspath, bgp->confed_id)
2073 > peer->allowas_in[afi][safi]))
2074 {
2075 reason = "as-path contains our own AS;";
2076 goto filtered;
2077 }
2078
2079 /* Route reflector originator ID check. */
2080 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002081 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002082 {
2083 reason = "originator is us;";
2084 goto filtered;
2085 }
2086
2087 /* Route reflector cluster ID check. */
2088 if (bgp_cluster_filter (peer, attr))
2089 {
2090 reason = "reflected from the same cluster;";
2091 goto filtered;
2092 }
2093
2094 /* Apply incoming filter. */
2095 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2096 {
2097 reason = "filter;";
2098 goto filtered;
2099 }
2100
2101 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002102 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002103
2104 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2105 {
2106 reason = "route-map;";
2107 goto filtered;
2108 }
2109
2110 /* IPv4 unicast next hop check. */
2111 if (afi == AFI_IP && safi == SAFI_UNICAST)
2112 {
2113 /* If the peer is EBGP and nexthop is not on connected route,
2114 discard it. */
2115 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2116 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002117 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002118 {
2119 reason = "non-connected next-hop;";
2120 goto filtered;
2121 }
2122
2123 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2124 must not be my own address. */
2125 if (bgp_nexthop_self (afi, &new_attr)
2126 || new_attr.nexthop.s_addr == 0
2127 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2128 {
2129 reason = "martian next-hop;";
2130 goto filtered;
2131 }
2132 }
2133
2134 attr_new = bgp_attr_intern (&new_attr);
2135
2136 /* If the update is implicit withdraw. */
2137 if (ri)
2138 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002139 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002140
2141 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002142 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2143 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002144 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002145 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002146
2147 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2148 && peer_sort (peer) == BGP_PEER_EBGP
2149 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2150 {
2151 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002152 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002153 peer->host,
2154 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2155 p->prefixlen);
2156
paul902212c2006-02-05 17:51:19 +00002157 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2158 {
2159 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2160 bgp_process (bgp, rn, afi, safi);
2161 }
paul718e3742002-12-13 20:15:29 +00002162 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002163 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002164 {
2165 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002166 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002167 "%s rcvd %s/%d...duplicate ignored",
2168 peer->host,
2169 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2170 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002171
2172 /* graceful restart STALE flag unset. */
2173 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2174 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002175 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002176 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002177 }
paul718e3742002-12-13 20:15:29 +00002178 }
2179
2180 bgp_unlock_node (rn);
2181 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002182 bgp_attr_extra_free (&new_attr);
2183
paul718e3742002-12-13 20:15:29 +00002184 return 0;
2185 }
2186
Paul Jakma16d2e242007-04-10 19:32:10 +00002187 /* Withdraw/Announce before we fully processed the withdraw */
2188 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2189 {
2190 if (BGP_DEBUG (update, UPDATE_IN))
2191 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2192 peer->host,
2193 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2194 p->prefixlen);
2195 bgp_info_restore (rn, ri);
2196 }
2197
paul718e3742002-12-13 20:15:29 +00002198 /* Received Logging. */
2199 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002200 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002201 peer->host,
2202 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2203 p->prefixlen);
2204
hasso93406d82005-02-02 14:40:33 +00002205 /* graceful restart STALE flag unset. */
2206 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002207 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002208
paul718e3742002-12-13 20:15:29 +00002209 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002210 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002211
2212 /* implicit withdraw, decrement aggregate and pcount here.
2213 * only if update is accepted, they'll increment below.
2214 */
paul902212c2006-02-05 17:51:19 +00002215 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2216
paul718e3742002-12-13 20:15:29 +00002217 /* Update bgp route dampening information. */
2218 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2219 && peer_sort (peer) == BGP_PEER_EBGP)
2220 {
2221 /* This is implicit withdraw so we should update dampening
2222 information. */
2223 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2224 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002225 }
2226
paul718e3742002-12-13 20:15:29 +00002227 /* Update to new attribute. */
2228 bgp_attr_unintern (ri->attr);
2229 ri->attr = attr_new;
2230
2231 /* Update MPLS tag. */
2232 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002233 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002234
2235 /* Update bgp route dampening information. */
2236 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2237 && peer_sort (peer) == BGP_PEER_EBGP)
2238 {
2239 /* Now we do normal update dampening. */
2240 ret = bgp_damp_update (ri, rn, afi, safi);
2241 if (ret == BGP_DAMP_SUPPRESSED)
2242 {
2243 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002244 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002245 return 0;
2246 }
2247 }
2248
2249 /* Nexthop reachability check. */
2250 if ((afi == AFI_IP || afi == AFI_IP6)
2251 && safi == SAFI_UNICAST
2252 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002253 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002254 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002255 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002256 {
2257 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002258 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002259 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002260 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002261 }
2262 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002263 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002264
2265 /* Process change. */
2266 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2267
2268 bgp_process (bgp, rn, afi, safi);
2269 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002270 bgp_attr_extra_free (&new_attr);
2271
paul718e3742002-12-13 20:15:29 +00002272 return 0;
2273 }
2274
2275 /* Received Logging. */
2276 if (BGP_DEBUG (update, UPDATE_IN))
2277 {
ajsd2c1f162004-12-08 21:10:20 +00002278 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002279 peer->host,
2280 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2281 p->prefixlen);
2282 }
2283
paul718e3742002-12-13 20:15:29 +00002284 /* Make new BGP info. */
2285 new = bgp_info_new ();
2286 new->type = type;
2287 new->sub_type = sub_type;
2288 new->peer = peer;
2289 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002290 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002291
2292 /* Update MPLS tag. */
2293 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002294 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002295
2296 /* Nexthop reachability check. */
2297 if ((afi == AFI_IP || afi == AFI_IP6)
2298 && safi == SAFI_UNICAST
2299 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002300 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002301 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002302 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002303 {
2304 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002305 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002306 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002307 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002308 }
2309 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002310 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002311
paul902212c2006-02-05 17:51:19 +00002312 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002313 bgp_aggregate_increment (bgp, p, new, afi, safi);
2314
2315 /* Register new BGP information. */
2316 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002317
2318 /* route_node_get lock */
2319 bgp_unlock_node (rn);
2320
Paul Jakmafb982c22007-05-04 20:15:47 +00002321 bgp_attr_extra_free (&new_attr);
2322
paul718e3742002-12-13 20:15:29 +00002323 /* If maximum prefix count is configured and current prefix
2324 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002325 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2326 return -1;
paul718e3742002-12-13 20:15:29 +00002327
2328 /* Process change. */
2329 bgp_process (bgp, rn, afi, safi);
2330
2331 return 0;
2332
2333 /* This BGP update is filtered. Log the reason then update BGP
2334 entry. */
2335 filtered:
2336 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002337 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002338 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2339 peer->host,
2340 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2341 p->prefixlen, reason);
2342
2343 if (ri)
paulb40d9392005-08-22 22:34:41 +00002344 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002345
2346 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002347
2348 bgp_attr_extra_free (&new_attr);
2349
paul718e3742002-12-13 20:15:29 +00002350 return 0;
2351}
2352
2353int
paulfee0f4c2004-09-13 05:12:46 +00002354bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2355 afi_t afi, safi_t safi, int type, int sub_type,
2356 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2357{
2358 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002359 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002360 struct bgp *bgp;
2361 int ret;
2362
2363 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2364 soft_reconfig);
2365
2366 bgp = peer->bgp;
2367
2368 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002369 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002370 {
2371 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2372 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2373 sub_type, prd, tag);
2374 }
2375
2376 return ret;
2377}
2378
2379int
paul718e3742002-12-13 20:15:29 +00002380bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002381 afi_t afi, safi_t safi, int type, int sub_type,
2382 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002383{
2384 struct bgp *bgp;
2385 char buf[SU_ADDRSTRLEN];
2386 struct bgp_node *rn;
2387 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002388 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002389 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002390
2391 bgp = peer->bgp;
2392
paulfee0f4c2004-09-13 05:12:46 +00002393 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002394 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002395 {
2396 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2397 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2398 }
2399
paul718e3742002-12-13 20:15:29 +00002400 /* Logging. */
2401 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002402 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002403 peer->host,
2404 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2405 p->prefixlen);
2406
2407 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002408 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002409
2410 /* If peer is soft reconfiguration enabled. Record input packet for
2411 further calculation. */
2412 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2413 && peer != bgp->peer_self)
2414 bgp_adj_in_unset (rn, peer);
2415
2416 /* Lookup withdrawn route. */
2417 for (ri = rn->info; ri; ri = ri->next)
2418 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2419 break;
2420
2421 /* Withdraw specified route from routing table. */
2422 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002423 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002424 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002425 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002426 "%s Can't find the route %s/%d", peer->host,
2427 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2428 p->prefixlen);
2429
2430 /* Unlock bgp_node_get() lock. */
2431 bgp_unlock_node (rn);
2432
2433 return 0;
2434}
2435
2436void
2437bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2438{
2439 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002440 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002441 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002442 struct prefix p;
2443 struct bgp_info binfo;
2444 struct peer *from;
2445 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002446
Paul Jakmab2497022007-06-14 11:17:58 +00002447 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002448 return;
2449
paul718e3742002-12-13 20:15:29 +00002450 bgp = peer->bgp;
2451 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002452
paul718e3742002-12-13 20:15:29 +00002453 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2454 aspath = attr.aspath;
2455 attr.local_pref = bgp->default_local_pref;
2456 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2457
2458 if (afi == AFI_IP)
2459 str2prefix ("0.0.0.0/0", &p);
2460#ifdef HAVE_IPV6
2461 else if (afi == AFI_IP6)
2462 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002463 struct attr_extra *ae;
2464 attr.extra = NULL;
2465
2466 ae = bgp_attr_extra_get (&attr);
2467 attr.extra = ae;
2468
paul718e3742002-12-13 20:15:29 +00002469 str2prefix ("::/0", &p);
2470
2471 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002472 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002473 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002474 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002475
2476 /* If the peer is on shared nextwork and we have link-local
2477 nexthop set it. */
2478 if (peer->shared_network
2479 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2480 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002481 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002482 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002483 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002484 }
2485 }
2486#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002487
2488 if (peer->default_rmap[afi][safi].name)
2489 {
2490 binfo.peer = bgp->peer_self;
2491 binfo.attr = &attr;
2492
paulfee0f4c2004-09-13 05:12:46 +00002493 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2494
paul718e3742002-12-13 20:15:29 +00002495 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2496 RMAP_BGP, &binfo);
2497
paulfee0f4c2004-09-13 05:12:46 +00002498 bgp->peer_self->rmap_type = 0;
2499
paul718e3742002-12-13 20:15:29 +00002500 if (ret == RMAP_DENYMATCH)
2501 {
2502 bgp_attr_flush (&attr);
2503 withdraw = 1;
2504 }
2505 }
2506
2507 if (withdraw)
2508 {
2509 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2510 bgp_default_withdraw_send (peer, afi, safi);
2511 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2512 }
2513 else
2514 {
2515 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2516 bgp_default_update_send (peer, &attr, afi, safi, from);
2517 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002518
2519 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002520 aspath_unintern (aspath);
2521}
2522
2523static void
2524bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002525 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002526{
2527 struct bgp_node *rn;
2528 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002529 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002530
paul718e3742002-12-13 20:15:29 +00002531 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002532 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002533
2534 if (safi != SAFI_MPLS_VPN
2535 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2536 bgp_default_originate (peer, afi, safi, 0);
2537
2538 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2539 for (ri = rn->info; ri; ri = ri->next)
2540 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2541 {
paulfee0f4c2004-09-13 05:12:46 +00002542 if ( (rsclient) ?
2543 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2544 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002545 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2546 else
2547 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002548
2549 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002550 }
2551}
2552
2553void
2554bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2555{
2556 struct bgp_node *rn;
2557 struct bgp_table *table;
2558
2559 if (peer->status != Established)
2560 return;
2561
2562 if (! peer->afc_nego[afi][safi])
2563 return;
2564
2565 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2566 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2567 return;
2568
2569 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002570 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002571 else
2572 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2573 rn = bgp_route_next(rn))
2574 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002575 bgp_announce_table (peer, afi, safi, table, 0);
2576
2577 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2578 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002579}
2580
2581void
2582bgp_announce_route_all (struct peer *peer)
2583{
2584 afi_t afi;
2585 safi_t safi;
2586
2587 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2588 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2589 bgp_announce_route (peer, afi, safi);
2590}
2591
2592static void
paulfee0f4c2004-09-13 05:12:46 +00002593bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2594 safi_t safi, struct bgp_table *table)
2595{
2596 struct bgp_node *rn;
2597 struct bgp_adj_in *ain;
2598
2599 if (! table)
2600 table = rsclient->bgp->rib[afi][safi];
2601
2602 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2603 for (ain = rn->adj_in; ain; ain = ain->next)
2604 {
2605 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2606 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2607 }
2608}
2609
2610void
2611bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2612{
2613 struct bgp_table *table;
2614 struct bgp_node *rn;
2615
2616 if (safi != SAFI_MPLS_VPN)
2617 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2618
2619 else
2620 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2621 rn = bgp_route_next (rn))
2622 if ((table = rn->info) != NULL)
2623 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2624}
2625
2626static void
paul718e3742002-12-13 20:15:29 +00002627bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2628 struct bgp_table *table)
2629{
2630 int ret;
2631 struct bgp_node *rn;
2632 struct bgp_adj_in *ain;
2633
2634 if (! table)
2635 table = peer->bgp->rib[afi][safi];
2636
2637 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2638 for (ain = rn->adj_in; ain; ain = ain->next)
2639 {
2640 if (ain->peer == peer)
2641 {
2642 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2643 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2644 NULL, NULL, 1);
2645 if (ret < 0)
2646 {
2647 bgp_unlock_node (rn);
2648 return;
2649 }
2650 continue;
2651 }
2652 }
2653}
2654
2655void
2656bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2657{
2658 struct bgp_node *rn;
2659 struct bgp_table *table;
2660
2661 if (peer->status != Established)
2662 return;
2663
2664 if (safi != SAFI_MPLS_VPN)
2665 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2666 else
2667 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2668 rn = bgp_route_next (rn))
2669 if ((table = rn->info) != NULL)
2670 bgp_soft_reconfig_table (peer, afi, safi, table);
2671}
2672
Chris Caputo228da422009-07-18 05:44:03 +00002673
2674struct bgp_clear_node_queue
2675{
2676 struct bgp_node *rn;
2677 enum bgp_clear_route_type purpose;
2678};
2679
paul200df112005-06-01 11:17:05 +00002680static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002681bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002682{
Chris Caputo228da422009-07-18 05:44:03 +00002683 struct bgp_clear_node_queue *cnq = data;
2684 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002685 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002686 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002687 afi_t afi = rn->table->afi;
2688 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002689
Paul Jakma64e580a2006-02-21 01:09:01 +00002690 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002691
Paul Jakma64e580a2006-02-21 01:09:01 +00002692 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002693 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002694 {
2695 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002696 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2697 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002698 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002699 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2700 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002701 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002702 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002703 break;
2704 }
paul200df112005-06-01 11:17:05 +00002705 return WQ_SUCCESS;
2706}
2707
2708static void
paul0fb58d52005-11-14 14:31:49 +00002709bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002710{
Chris Caputo228da422009-07-18 05:44:03 +00002711 struct bgp_clear_node_queue *cnq = data;
2712 struct bgp_node *rn = cnq->rn;
2713 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002714
2715 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002716 bgp_table_unlock (table);
2717 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002718}
2719
2720static void
paul94f2b392005-06-28 12:44:16 +00002721bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002722{
Paul Jakma64e580a2006-02-21 01:09:01 +00002723 struct peer *peer = wq->spec.data;
2724
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002725 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002726 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002727
2728 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002729}
2730
2731static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002732bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002733{
Paul Jakmaa2943652009-07-21 14:02:04 +01002734 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002735
Paul Jakmaa2943652009-07-21 14:02:04 +01002736 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002737#undef CLEAR_QUEUE_NAME_LEN
2738
2739 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002740 {
2741 zlog_err ("%s: Failed to allocate work queue", __func__);
2742 exit (1);
2743 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002744 peer->clear_node_queue->spec.hold = 10;
2745 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2746 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2747 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2748 peer->clear_node_queue->spec.max_retries = 0;
2749
2750 /* we only 'lock' this peer reference when the queue is actually active */
2751 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002752}
2753
paul718e3742002-12-13 20:15:29 +00002754static void
2755bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002756 struct bgp_table *table, struct peer *rsclient,
2757 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002758{
2759 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002760
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002761
paul718e3742002-12-13 20:15:29 +00002762 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002763 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002764
hasso6cf159b2005-03-21 10:28:14 +00002765 /* If still no table => afi/safi isn't configured at all or smth. */
2766 if (! table)
2767 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002768
2769 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2770 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002771 struct bgp_info *ri;
2772 struct bgp_adj_in *ain;
2773 struct bgp_adj_out *aout;
2774
Paul Jakma65ca75e2006-05-04 08:08:15 +00002775 if (rn->info == NULL)
2776 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002777
2778 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2779 * queued for every clearing peer, regardless of whether it is
2780 * relevant to the peer at hand.
2781 *
2782 * Overview: There are 3 different indices which need to be
2783 * scrubbed, potentially, when a peer is removed:
2784 *
2785 * 1 peer's routes visible via the RIB (ie accepted routes)
2786 * 2 peer's routes visible by the (optional) peer's adj-in index
2787 * 3 other routes visible by the peer's adj-out index
2788 *
2789 * 3 there is no hurry in scrubbing, once the struct peer is
2790 * removed from bgp->peer, we could just GC such deleted peer's
2791 * adj-outs at our leisure.
2792 *
2793 * 1 and 2 must be 'scrubbed' in some way, at least made
2794 * invisible via RIB index before peer session is allowed to be
2795 * brought back up. So one needs to know when such a 'search' is
2796 * complete.
2797 *
2798 * Ideally:
2799 *
2800 * - there'd be a single global queue or a single RIB walker
2801 * - rather than tracking which route_nodes still need to be
2802 * examined on a peer basis, we'd track which peers still
2803 * aren't cleared
2804 *
2805 * Given that our per-peer prefix-counts now should be reliable,
2806 * this may actually be achievable. It doesn't seem to be a huge
2807 * problem at this time,
2808 */
2809 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002810 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002811 {
Chris Caputo228da422009-07-18 05:44:03 +00002812 struct bgp_clear_node_queue *cnq;
2813
2814 /* both unlocked in bgp_clear_node_queue_del */
2815 bgp_table_lock (rn->table);
2816 bgp_lock_node (rn);
2817 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2818 sizeof (struct bgp_clear_node_queue));
2819 cnq->rn = rn;
2820 cnq->purpose = purpose;
2821 work_queue_add (peer->clear_node_queue, cnq);
2822 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002823 }
2824
2825 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002826 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002827 {
2828 bgp_adj_in_remove (rn, ain);
2829 bgp_unlock_node (rn);
2830 break;
2831 }
2832 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002833 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002834 {
2835 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2836 bgp_unlock_node (rn);
2837 break;
2838 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002839 }
2840 return;
2841}
2842
2843void
Chris Caputo228da422009-07-18 05:44:03 +00002844bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2845 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002846{
2847 struct bgp_node *rn;
2848 struct bgp_table *table;
2849 struct peer *rsclient;
2850 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002851
Paul Jakma64e580a2006-02-21 01:09:01 +00002852 if (peer->clear_node_queue == NULL)
2853 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002854
Paul Jakmaca058a32006-09-14 02:58:49 +00002855 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2856 * Idle until it receives a Clearing_Completed event. This protects
2857 * against peers which flap faster than we can we clear, which could
2858 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002859 *
2860 * a) race with routes from the new session being installed before
2861 * clear_route_node visits the node (to delete the route of that
2862 * peer)
2863 * b) resource exhaustion, clear_route_node likely leads to an entry
2864 * on the process_main queue. Fast-flapping could cause that queue
2865 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002866 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002867 if (!peer->clear_node_queue->thread)
2868 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002869
Chris Caputo228da422009-07-18 05:44:03 +00002870 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002871 {
Chris Caputo228da422009-07-18 05:44:03 +00002872 case BGP_CLEAR_ROUTE_NORMAL:
2873 if (safi != SAFI_MPLS_VPN)
2874 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2875 else
2876 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2877 rn = bgp_route_next (rn))
2878 if ((table = rn->info) != NULL)
2879 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2880
2881 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2882 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2883 PEER_FLAG_RSERVER_CLIENT))
2884 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2885 break;
2886
2887 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2888 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2889 break;
2890
2891 default:
2892 assert (0);
2893 break;
paulfee0f4c2004-09-13 05:12:46 +00002894 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002895
Paul Jakmaca058a32006-09-14 02:58:49 +00002896 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002897 * completion function won't be run by workqueue code - call it here.
2898 * XXX: Actually, this assumption doesn't hold, see
2899 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002900 *
2901 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002902 * really needed if peer state is Established - peers in
2903 * pre-Established states shouldn't have any route-update state
2904 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002905 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002906 * We still can get here in pre-Established though, through
2907 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2908 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002909 *
2910 * At some future point, this check could be move to the top of the
2911 * function, and do a quick early-return when state is
2912 * pre-Established, avoiding above list and table scans. Once we're
2913 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002914 */
2915 if (!peer->clear_node_queue->thread)
2916 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002917}
2918
2919void
2920bgp_clear_route_all (struct peer *peer)
2921{
2922 afi_t afi;
2923 safi_t safi;
2924
2925 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2926 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002927 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002928}
2929
2930void
2931bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2932{
2933 struct bgp_table *table;
2934 struct bgp_node *rn;
2935 struct bgp_adj_in *ain;
2936
2937 table = peer->bgp->rib[afi][safi];
2938
2939 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2940 for (ain = rn->adj_in; ain ; ain = ain->next)
2941 if (ain->peer == peer)
2942 {
2943 bgp_adj_in_remove (rn, ain);
2944 bgp_unlock_node (rn);
2945 break;
2946 }
2947}
hasso93406d82005-02-02 14:40:33 +00002948
2949void
2950bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2951{
2952 struct bgp_node *rn;
2953 struct bgp_info *ri;
2954 struct bgp_table *table;
2955
2956 table = peer->bgp->rib[afi][safi];
2957
2958 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2959 {
2960 for (ri = rn->info; ri; ri = ri->next)
2961 if (ri->peer == peer)
2962 {
2963 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2964 bgp_rib_remove (rn, ri, peer, afi, safi);
2965 break;
2966 }
2967 }
2968}
paul718e3742002-12-13 20:15:29 +00002969
2970/* Delete all kernel routes. */
2971void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002972bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002973{
2974 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002975 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002976 struct bgp_node *rn;
2977 struct bgp_table *table;
2978 struct bgp_info *ri;
2979
paul1eb8ef22005-04-07 07:30:20 +00002980 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002981 {
2982 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2983
2984 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2985 for (ri = rn->info; ri; ri = ri->next)
2986 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2987 && ri->type == ZEBRA_ROUTE_BGP
2988 && ri->sub_type == BGP_ROUTE_NORMAL)
2989 bgp_zebra_withdraw (&rn->p, ri);
2990
2991 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2992
2993 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2994 for (ri = rn->info; ri; ri = ri->next)
2995 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2996 && ri->type == ZEBRA_ROUTE_BGP
2997 && ri->sub_type == BGP_ROUTE_NORMAL)
2998 bgp_zebra_withdraw (&rn->p, ri);
2999 }
3000}
3001
3002void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003003bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00003004{
3005 vty_reset ();
3006 bgp_zclient_reset ();
3007 access_list_reset ();
3008 prefix_list_reset ();
3009}
3010
3011/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3012 value. */
3013int
3014bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3015{
3016 u_char *pnt;
3017 u_char *lim;
3018 struct prefix p;
3019 int psize;
3020 int ret;
3021
3022 /* Check peer status. */
3023 if (peer->status != Established)
3024 return 0;
3025
3026 pnt = packet->nlri;
3027 lim = pnt + packet->length;
3028
3029 for (; pnt < lim; pnt += psize)
3030 {
3031 /* Clear prefix structure. */
3032 memset (&p, 0, sizeof (struct prefix));
3033
3034 /* Fetch prefix length. */
3035 p.prefixlen = *pnt++;
3036 p.family = afi2family (packet->afi);
3037
3038 /* Already checked in nlri_sanity_check(). We do double check
3039 here. */
3040 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3041 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3042 return -1;
3043
3044 /* Packet size overflow check. */
3045 psize = PSIZE (p.prefixlen);
3046
3047 /* When packet overflow occur return immediately. */
3048 if (pnt + psize > lim)
3049 return -1;
3050
3051 /* Fetch prefix from NLRI packet. */
3052 memcpy (&p.u.prefix, pnt, psize);
3053
3054 /* Check address. */
3055 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3056 {
3057 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3058 {
paulf5ba3872004-07-09 12:11:31 +00003059 /*
3060 * From draft-ietf-idr-bgp4-22, Section 6.3:
3061 * If a BGP router receives an UPDATE message with a
3062 * semantically incorrect NLRI field, in which a prefix is
3063 * semantically incorrect (eg. an unexpected multicast IP
3064 * address), it should ignore the prefix.
3065 */
paul718e3742002-12-13 20:15:29 +00003066 zlog (peer->log, LOG_ERR,
3067 "IPv4 unicast NLRI is multicast address %s",
3068 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003069
paul718e3742002-12-13 20:15:29 +00003070 return -1;
3071 }
3072 }
3073
3074#ifdef HAVE_IPV6
3075 /* Check address. */
3076 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3077 {
3078 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3079 {
3080 char buf[BUFSIZ];
3081
3082 zlog (peer->log, LOG_WARNING,
3083 "IPv6 link-local NLRI received %s ignore this NLRI",
3084 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3085
3086 continue;
3087 }
3088 }
3089#endif /* HAVE_IPV6 */
3090
3091 /* Normal process. */
3092 if (attr)
3093 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3094 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3095 else
3096 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3097 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3098
3099 /* Address family configuration mismatch or maximum-prefix count
3100 overflow. */
3101 if (ret < 0)
3102 return -1;
3103 }
3104
3105 /* Packet length consistency check. */
3106 if (pnt != lim)
3107 return -1;
3108
3109 return 0;
3110}
3111
3112/* NLRI encode syntax check routine. */
3113int
3114bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3115 bgp_size_t length)
3116{
3117 u_char *end;
3118 u_char prefixlen;
3119 int psize;
3120
3121 end = pnt + length;
3122
3123 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3124 syntactic validity. If the field is syntactically incorrect,
3125 then the Error Subcode is set to Invalid Network Field. */
3126
3127 while (pnt < end)
3128 {
3129 prefixlen = *pnt++;
3130
3131 /* Prefix length check. */
3132 if ((afi == AFI_IP && prefixlen > 32)
3133 || (afi == AFI_IP6 && prefixlen > 128))
3134 {
3135 plog_err (peer->log,
3136 "%s [Error] Update packet error (wrong prefix length %d)",
3137 peer->host, prefixlen);
3138 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3139 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3140 return -1;
3141 }
3142
3143 /* Packet size overflow check. */
3144 psize = PSIZE (prefixlen);
3145
3146 if (pnt + psize > end)
3147 {
3148 plog_err (peer->log,
3149 "%s [Error] Update packet error"
3150 " (prefix data overflow prefix size is %d)",
3151 peer->host, psize);
3152 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3153 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3154 return -1;
3155 }
3156
3157 pnt += psize;
3158 }
3159
3160 /* Packet length consistency check. */
3161 if (pnt != end)
3162 {
3163 plog_err (peer->log,
3164 "%s [Error] Update packet error"
3165 " (prefix length mismatch with total length)",
3166 peer->host);
3167 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3168 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3169 return -1;
3170 }
3171 return 0;
3172}
3173
paul94f2b392005-06-28 12:44:16 +00003174static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003175bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003176{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003177 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003178}
3179
paul94f2b392005-06-28 12:44:16 +00003180static void
paul718e3742002-12-13 20:15:29 +00003181bgp_static_free (struct bgp_static *bgp_static)
3182{
3183 if (bgp_static->rmap.name)
3184 free (bgp_static->rmap.name);
3185 XFREE (MTYPE_BGP_STATIC, bgp_static);
3186}
3187
paul94f2b392005-06-28 12:44:16 +00003188static void
paulfee0f4c2004-09-13 05:12:46 +00003189bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3190 struct prefix *p, afi_t afi, safi_t safi)
3191{
3192 struct bgp_node *rn;
3193 struct bgp_info *ri;
3194
3195 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3196
3197 /* Check selected route and self inserted route. */
3198 for (ri = rn->info; ri; ri = ri->next)
3199 if (ri->peer == bgp->peer_self
3200 && ri->type == ZEBRA_ROUTE_BGP
3201 && ri->sub_type == BGP_ROUTE_STATIC)
3202 break;
3203
3204 /* Withdraw static BGP route from routing table. */
3205 if (ri)
3206 {
paulfee0f4c2004-09-13 05:12:46 +00003207 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003208 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003209 }
3210
3211 /* Unlock bgp_node_lookup. */
3212 bgp_unlock_node (rn);
3213}
3214
paul94f2b392005-06-28 12:44:16 +00003215static void
paulfee0f4c2004-09-13 05:12:46 +00003216bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003217 struct bgp_static *bgp_static,
3218 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003219{
3220 struct bgp_node *rn;
3221 struct bgp_info *ri;
3222 struct bgp_info *new;
3223 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003224 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003225 struct attr attr = {0 };
3226 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003227 struct bgp *bgp;
3228 int ret;
3229 char buf[SU_ADDRSTRLEN];
3230
3231 bgp = rsclient->bgp;
3232
Paul Jakma06e110f2006-05-12 23:29:22 +00003233 assert (bgp_static);
3234 if (!bgp_static)
3235 return;
3236
paulfee0f4c2004-09-13 05:12:46 +00003237 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3238
3239 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003240
3241 attr.nexthop = bgp_static->igpnexthop;
3242 attr.med = bgp_static->igpmetric;
3243 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003244
Paul Jakma41367172007-08-06 15:24:51 +00003245 if (bgp_static->atomic)
3246 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3247
paulfee0f4c2004-09-13 05:12:46 +00003248 /* Apply network route-map for export to this rsclient. */
3249 if (bgp_static->rmap.name)
3250 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003251 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003252 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003253 info.attr = &attr_tmp;
3254
paulfee0f4c2004-09-13 05:12:46 +00003255 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3256 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3257
3258 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3259
3260 rsclient->rmap_type = 0;
3261
3262 if (ret == RMAP_DENYMATCH)
3263 {
3264 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003265 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003266
3267 /* Unintern original. */
3268 aspath_unintern (attr.aspath);
3269 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003270 bgp_attr_extra_free (&attr);
3271
paulfee0f4c2004-09-13 05:12:46 +00003272 return;
3273 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003274 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003275 }
3276 else
3277 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003278
Stephen Hemminger7badc262010-08-05 10:26:31 -07003279 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003280
paulfee0f4c2004-09-13 05:12:46 +00003281 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3282
Paul Jakmafb982c22007-05-04 20:15:47 +00003283 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3284 == RMAP_DENY)
3285 {
paulfee0f4c2004-09-13 05:12:46 +00003286 /* This BGP update is filtered. Log the reason then update BGP entry. */
3287 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003288 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003289 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3290 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3291 p->prefixlen, rsclient->host);
3292
3293 bgp->peer_self->rmap_type = 0;
3294
3295 bgp_attr_unintern (attr_new);
3296 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003297 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003298
3299 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3300
3301 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003302 }
paulfee0f4c2004-09-13 05:12:46 +00003303
3304 bgp->peer_self->rmap_type = 0;
3305
3306 bgp_attr_unintern (attr_new);
3307 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003308 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003309
3310 for (ri = rn->info; ri; ri = ri->next)
3311 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3312 && ri->sub_type == BGP_ROUTE_STATIC)
3313 break;
3314
3315 if (ri)
3316 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003317 if (attrhash_cmp (ri->attr, attr_new) &&
3318 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003319 {
3320 bgp_unlock_node (rn);
3321 bgp_attr_unintern (attr_new);
3322 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003323 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003324 return;
3325 }
3326 else
3327 {
3328 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003329 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003330
3331 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003332 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3333 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003334 bgp_attr_unintern (ri->attr);
3335 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003336 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003337
3338 /* Process change. */
3339 bgp_process (bgp, rn, afi, safi);
3340 bgp_unlock_node (rn);
3341 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003342 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003343 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003344 }
paulfee0f4c2004-09-13 05:12:46 +00003345 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003346
paulfee0f4c2004-09-13 05:12:46 +00003347 /* Make new BGP info. */
3348 new = bgp_info_new ();
3349 new->type = ZEBRA_ROUTE_BGP;
3350 new->sub_type = BGP_ROUTE_STATIC;
3351 new->peer = bgp->peer_self;
3352 SET_FLAG (new->flags, BGP_INFO_VALID);
3353 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003354 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003355
3356 /* Register new BGP information. */
3357 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003358
3359 /* route_node_get lock */
3360 bgp_unlock_node (rn);
3361
paulfee0f4c2004-09-13 05:12:46 +00003362 /* Process change. */
3363 bgp_process (bgp, rn, afi, safi);
3364
3365 /* Unintern original. */
3366 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003367 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003368}
3369
paul94f2b392005-06-28 12:44:16 +00003370static void
paulfee0f4c2004-09-13 05:12:46 +00003371bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003372 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3373{
3374 struct bgp_node *rn;
3375 struct bgp_info *ri;
3376 struct bgp_info *new;
3377 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003378 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003379 struct attr *attr_new;
3380 int ret;
3381
Paul Jakmadd8103a2006-05-12 23:27:30 +00003382 assert (bgp_static);
3383 if (!bgp_static)
3384 return;
3385
paulfee0f4c2004-09-13 05:12:46 +00003386 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003387
3388 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003389
3390 attr.nexthop = bgp_static->igpnexthop;
3391 attr.med = bgp_static->igpmetric;
3392 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003393
Paul Jakma41367172007-08-06 15:24:51 +00003394 if (bgp_static->atomic)
3395 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3396
paul718e3742002-12-13 20:15:29 +00003397 /* Apply route-map. */
3398 if (bgp_static->rmap.name)
3399 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003400 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003401 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003402 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003403
paulfee0f4c2004-09-13 05:12:46 +00003404 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3405
paul718e3742002-12-13 20:15:29 +00003406 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003407
paulfee0f4c2004-09-13 05:12:46 +00003408 bgp->peer_self->rmap_type = 0;
3409
paul718e3742002-12-13 20:15:29 +00003410 if (ret == RMAP_DENYMATCH)
3411 {
3412 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003413 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003414
3415 /* Unintern original. */
3416 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003417 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003418 bgp_static_withdraw (bgp, p, afi, safi);
3419 return;
3420 }
paul286e1e72003-08-08 00:24:31 +00003421 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003422 }
paul286e1e72003-08-08 00:24:31 +00003423 else
3424 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003425
3426 for (ri = rn->info; ri; ri = ri->next)
3427 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3428 && ri->sub_type == BGP_ROUTE_STATIC)
3429 break;
3430
3431 if (ri)
3432 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003433 if (attrhash_cmp (ri->attr, attr_new) &&
3434 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003435 {
3436 bgp_unlock_node (rn);
3437 bgp_attr_unintern (attr_new);
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 return;
3441 }
3442 else
3443 {
3444 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003445 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003446
3447 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003448 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3449 bgp_info_restore(rn, ri);
3450 else
3451 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003452 bgp_attr_unintern (ri->attr);
3453 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003454 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003455
3456 /* Process change. */
3457 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3458 bgp_process (bgp, rn, afi, safi);
3459 bgp_unlock_node (rn);
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 }
3465
3466 /* Make new BGP info. */
3467 new = bgp_info_new ();
3468 new->type = ZEBRA_ROUTE_BGP;
3469 new->sub_type = BGP_ROUTE_STATIC;
3470 new->peer = bgp->peer_self;
3471 SET_FLAG (new->flags, BGP_INFO_VALID);
3472 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003473 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003474
3475 /* Aggregate address increment. */
3476 bgp_aggregate_increment (bgp, p, new, afi, safi);
3477
3478 /* Register new BGP information. */
3479 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003480
3481 /* route_node_get lock */
3482 bgp_unlock_node (rn);
3483
paul718e3742002-12-13 20:15:29 +00003484 /* Process change. */
3485 bgp_process (bgp, rn, afi, safi);
3486
3487 /* Unintern original. */
3488 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003489 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003490}
3491
3492void
paulfee0f4c2004-09-13 05:12:46 +00003493bgp_static_update (struct bgp *bgp, struct prefix *p,
3494 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3495{
3496 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003497 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003498
3499 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3500
paul1eb8ef22005-04-07 07:30:20 +00003501 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003502 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003503 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3504 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003505 }
3506}
3507
paul94f2b392005-06-28 12:44:16 +00003508static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003509bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3510 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003511{
3512 struct bgp_node *rn;
3513 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003514
paulfee0f4c2004-09-13 05:12:46 +00003515 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003516
3517 /* Make new BGP info. */
3518 new = bgp_info_new ();
3519 new->type = ZEBRA_ROUTE_BGP;
3520 new->sub_type = BGP_ROUTE_STATIC;
3521 new->peer = bgp->peer_self;
3522 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3523 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003524 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003525 new->extra = bgp_info_extra_new();
3526 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003527
3528 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003529 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003530
3531 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003532 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003533
paul200df112005-06-01 11:17:05 +00003534 /* route_node_get lock */
3535 bgp_unlock_node (rn);
3536
paul718e3742002-12-13 20:15:29 +00003537 /* Process change. */
3538 bgp_process (bgp, rn, afi, safi);
3539}
3540
3541void
3542bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3543 safi_t safi)
3544{
3545 struct bgp_node *rn;
3546 struct bgp_info *ri;
3547
paulfee0f4c2004-09-13 05:12:46 +00003548 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003549
3550 /* Check selected route and self inserted route. */
3551 for (ri = rn->info; ri; ri = ri->next)
3552 if (ri->peer == bgp->peer_self
3553 && ri->type == ZEBRA_ROUTE_BGP
3554 && ri->sub_type == BGP_ROUTE_STATIC)
3555 break;
3556
3557 /* Withdraw static BGP route from routing table. */
3558 if (ri)
3559 {
3560 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003561 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003562 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003563 }
3564
3565 /* Unlock bgp_node_lookup. */
3566 bgp_unlock_node (rn);
3567}
3568
3569void
paulfee0f4c2004-09-13 05:12:46 +00003570bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3571{
3572 struct bgp_static *bgp_static;
3573 struct bgp *bgp;
3574 struct bgp_node *rn;
3575 struct prefix *p;
3576
3577 bgp = rsclient->bgp;
3578
3579 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3580 if ((bgp_static = rn->info) != NULL)
3581 {
3582 p = &rn->p;
3583
3584 bgp_static_update_rsclient (rsclient, p, bgp_static,
3585 afi, safi);
3586 }
3587}
3588
paul94f2b392005-06-28 12:44:16 +00003589static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003590bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3591 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003592{
3593 struct bgp_node *rn;
3594 struct bgp_info *ri;
3595
paulfee0f4c2004-09-13 05:12:46 +00003596 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003597
3598 /* Check selected route and self inserted route. */
3599 for (ri = rn->info; ri; ri = ri->next)
3600 if (ri->peer == bgp->peer_self
3601 && ri->type == ZEBRA_ROUTE_BGP
3602 && ri->sub_type == BGP_ROUTE_STATIC)
3603 break;
3604
3605 /* Withdraw static BGP route from routing table. */
3606 if (ri)
3607 {
3608 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003609 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003610 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003611 }
3612
3613 /* Unlock bgp_node_lookup. */
3614 bgp_unlock_node (rn);
3615}
3616
3617/* Configure static BGP network. When user don't run zebra, static
3618 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003619static int
paulfd79ac92004-10-13 05:06:08 +00003620bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003621 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003622{
3623 int ret;
3624 struct prefix p;
3625 struct bgp_static *bgp_static;
3626 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003627 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003628
3629 /* Convert IP prefix string to struct prefix. */
3630 ret = str2prefix (ip_str, &p);
3631 if (! ret)
3632 {
3633 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3634 return CMD_WARNING;
3635 }
3636#ifdef HAVE_IPV6
3637 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3638 {
3639 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3640 VTY_NEWLINE);
3641 return CMD_WARNING;
3642 }
3643#endif /* HAVE_IPV6 */
3644
3645 apply_mask (&p);
3646
3647 /* Set BGP static route configuration. */
3648 rn = bgp_node_get (bgp->route[afi][safi], &p);
3649
3650 if (rn->info)
3651 {
3652 /* Configuration change. */
3653 bgp_static = rn->info;
3654
3655 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003656 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3657 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003658
paul718e3742002-12-13 20:15:29 +00003659 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003660
paul718e3742002-12-13 20:15:29 +00003661 if (rmap)
3662 {
3663 if (bgp_static->rmap.name)
3664 free (bgp_static->rmap.name);
3665 bgp_static->rmap.name = strdup (rmap);
3666 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3667 }
3668 else
3669 {
3670 if (bgp_static->rmap.name)
3671 free (bgp_static->rmap.name);
3672 bgp_static->rmap.name = NULL;
3673 bgp_static->rmap.map = NULL;
3674 bgp_static->valid = 0;
3675 }
3676 bgp_unlock_node (rn);
3677 }
3678 else
3679 {
3680 /* New configuration. */
3681 bgp_static = bgp_static_new ();
3682 bgp_static->backdoor = backdoor;
3683 bgp_static->valid = 0;
3684 bgp_static->igpmetric = 0;
3685 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003686
paul718e3742002-12-13 20:15:29 +00003687 if (rmap)
3688 {
3689 if (bgp_static->rmap.name)
3690 free (bgp_static->rmap.name);
3691 bgp_static->rmap.name = strdup (rmap);
3692 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3693 }
3694 rn->info = bgp_static;
3695 }
3696
3697 /* If BGP scan is not enabled, we should install this route here. */
3698 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3699 {
3700 bgp_static->valid = 1;
3701
3702 if (need_update)
3703 bgp_static_withdraw (bgp, &p, afi, safi);
3704
3705 if (! bgp_static->backdoor)
3706 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3707 }
3708
3709 return CMD_SUCCESS;
3710}
3711
3712/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003713static int
paulfd79ac92004-10-13 05:06:08 +00003714bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003715 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003716{
3717 int ret;
3718 struct prefix p;
3719 struct bgp_static *bgp_static;
3720 struct bgp_node *rn;
3721
3722 /* Convert IP prefix string to struct prefix. */
3723 ret = str2prefix (ip_str, &p);
3724 if (! ret)
3725 {
3726 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3727 return CMD_WARNING;
3728 }
3729#ifdef HAVE_IPV6
3730 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3731 {
3732 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3733 VTY_NEWLINE);
3734 return CMD_WARNING;
3735 }
3736#endif /* HAVE_IPV6 */
3737
3738 apply_mask (&p);
3739
3740 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3741 if (! rn)
3742 {
3743 vty_out (vty, "%% Can't find specified static route configuration.%s",
3744 VTY_NEWLINE);
3745 return CMD_WARNING;
3746 }
3747
3748 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003749
paul718e3742002-12-13 20:15:29 +00003750 /* Update BGP RIB. */
3751 if (! bgp_static->backdoor)
3752 bgp_static_withdraw (bgp, &p, afi, safi);
3753
3754 /* Clear configuration. */
3755 bgp_static_free (bgp_static);
3756 rn->info = NULL;
3757 bgp_unlock_node (rn);
3758 bgp_unlock_node (rn);
3759
3760 return CMD_SUCCESS;
3761}
3762
3763/* Called from bgp_delete(). Delete all static routes from the BGP
3764 instance. */
3765void
3766bgp_static_delete (struct bgp *bgp)
3767{
3768 afi_t afi;
3769 safi_t safi;
3770 struct bgp_node *rn;
3771 struct bgp_node *rm;
3772 struct bgp_table *table;
3773 struct bgp_static *bgp_static;
3774
3775 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3776 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3777 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3778 if (rn->info != NULL)
3779 {
3780 if (safi == SAFI_MPLS_VPN)
3781 {
3782 table = rn->info;
3783
3784 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3785 {
3786 bgp_static = rn->info;
3787 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3788 AFI_IP, SAFI_MPLS_VPN,
3789 (struct prefix_rd *)&rn->p,
3790 bgp_static->tag);
3791 bgp_static_free (bgp_static);
3792 rn->info = NULL;
3793 bgp_unlock_node (rn);
3794 }
3795 }
3796 else
3797 {
3798 bgp_static = rn->info;
3799 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3800 bgp_static_free (bgp_static);
3801 rn->info = NULL;
3802 bgp_unlock_node (rn);
3803 }
3804 }
3805}
3806
3807int
paulfd79ac92004-10-13 05:06:08 +00003808bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3809 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003810{
3811 int ret;
3812 struct prefix p;
3813 struct prefix_rd prd;
3814 struct bgp *bgp;
3815 struct bgp_node *prn;
3816 struct bgp_node *rn;
3817 struct bgp_table *table;
3818 struct bgp_static *bgp_static;
3819 u_char tag[3];
3820
3821 bgp = vty->index;
3822
3823 ret = str2prefix (ip_str, &p);
3824 if (! ret)
3825 {
3826 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3827 return CMD_WARNING;
3828 }
3829 apply_mask (&p);
3830
3831 ret = str2prefix_rd (rd_str, &prd);
3832 if (! ret)
3833 {
3834 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3835 return CMD_WARNING;
3836 }
3837
3838 ret = str2tag (tag_str, tag);
3839 if (! ret)
3840 {
3841 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3842 return CMD_WARNING;
3843 }
3844
3845 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3846 (struct prefix *)&prd);
3847 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003848 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003849 else
3850 bgp_unlock_node (prn);
3851 table = prn->info;
3852
3853 rn = bgp_node_get (table, &p);
3854
3855 if (rn->info)
3856 {
3857 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3858 bgp_unlock_node (rn);
3859 }
3860 else
3861 {
3862 /* New configuration. */
3863 bgp_static = bgp_static_new ();
3864 bgp_static->valid = 1;
3865 memcpy (bgp_static->tag, tag, 3);
3866 rn->info = bgp_static;
3867
3868 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3869 }
3870
3871 return CMD_SUCCESS;
3872}
3873
3874/* Configure static BGP network. */
3875int
paulfd79ac92004-10-13 05:06:08 +00003876bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3877 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003878{
3879 int ret;
3880 struct bgp *bgp;
3881 struct prefix p;
3882 struct prefix_rd prd;
3883 struct bgp_node *prn;
3884 struct bgp_node *rn;
3885 struct bgp_table *table;
3886 struct bgp_static *bgp_static;
3887 u_char tag[3];
3888
3889 bgp = vty->index;
3890
3891 /* Convert IP prefix string to struct prefix. */
3892 ret = str2prefix (ip_str, &p);
3893 if (! ret)
3894 {
3895 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3896 return CMD_WARNING;
3897 }
3898 apply_mask (&p);
3899
3900 ret = str2prefix_rd (rd_str, &prd);
3901 if (! ret)
3902 {
3903 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3904 return CMD_WARNING;
3905 }
3906
3907 ret = str2tag (tag_str, tag);
3908 if (! ret)
3909 {
3910 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3911 return CMD_WARNING;
3912 }
3913
3914 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3915 (struct prefix *)&prd);
3916 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003917 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003918 else
3919 bgp_unlock_node (prn);
3920 table = prn->info;
3921
3922 rn = bgp_node_lookup (table, &p);
3923
3924 if (rn)
3925 {
3926 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3927
3928 bgp_static = rn->info;
3929 bgp_static_free (bgp_static);
3930 rn->info = NULL;
3931 bgp_unlock_node (rn);
3932 bgp_unlock_node (rn);
3933 }
3934 else
3935 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3936
3937 return CMD_SUCCESS;
3938}
3939
3940DEFUN (bgp_network,
3941 bgp_network_cmd,
3942 "network A.B.C.D/M",
3943 "Specify a network to announce via BGP\n"
3944 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3945{
3946 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003947 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003948}
3949
3950DEFUN (bgp_network_route_map,
3951 bgp_network_route_map_cmd,
3952 "network A.B.C.D/M route-map WORD",
3953 "Specify a network to announce via BGP\n"
3954 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3955 "Route-map to modify the attributes\n"
3956 "Name of the route map\n")
3957{
3958 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003959 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003960}
3961
3962DEFUN (bgp_network_backdoor,
3963 bgp_network_backdoor_cmd,
3964 "network A.B.C.D/M backdoor",
3965 "Specify a network to announce via BGP\n"
3966 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3967 "Specify a BGP backdoor route\n")
3968{
Paul Jakma41367172007-08-06 15:24:51 +00003969 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003970 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003971}
3972
3973DEFUN (bgp_network_mask,
3974 bgp_network_mask_cmd,
3975 "network A.B.C.D mask A.B.C.D",
3976 "Specify a network to announce via BGP\n"
3977 "Network number\n"
3978 "Network mask\n"
3979 "Network mask\n")
3980{
3981 int ret;
3982 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003983
paul718e3742002-12-13 20:15:29 +00003984 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3985 if (! ret)
3986 {
3987 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3988 return CMD_WARNING;
3989 }
3990
3991 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003992 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003993}
3994
3995DEFUN (bgp_network_mask_route_map,
3996 bgp_network_mask_route_map_cmd,
3997 "network A.B.C.D mask A.B.C.D route-map WORD",
3998 "Specify a network to announce via BGP\n"
3999 "Network number\n"
4000 "Network mask\n"
4001 "Network mask\n"
4002 "Route-map to modify the attributes\n"
4003 "Name of the route map\n")
4004{
4005 int ret;
4006 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004007
paul718e3742002-12-13 20:15:29 +00004008 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4009 if (! ret)
4010 {
4011 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4012 return CMD_WARNING;
4013 }
4014
4015 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004016 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004017}
4018
4019DEFUN (bgp_network_mask_backdoor,
4020 bgp_network_mask_backdoor_cmd,
4021 "network A.B.C.D mask A.B.C.D backdoor",
4022 "Specify a network to announce via BGP\n"
4023 "Network number\n"
4024 "Network mask\n"
4025 "Network mask\n"
4026 "Specify a BGP backdoor route\n")
4027{
4028 int ret;
4029 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004030
paul718e3742002-12-13 20:15:29 +00004031 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4032 if (! ret)
4033 {
4034 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4035 return CMD_WARNING;
4036 }
4037
Paul Jakma41367172007-08-06 15:24:51 +00004038 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004039 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004040}
4041
4042DEFUN (bgp_network_mask_natural,
4043 bgp_network_mask_natural_cmd,
4044 "network A.B.C.D",
4045 "Specify a network to announce via BGP\n"
4046 "Network number\n")
4047{
4048 int ret;
4049 char prefix_str[BUFSIZ];
4050
4051 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4052 if (! ret)
4053 {
4054 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4055 return CMD_WARNING;
4056 }
4057
4058 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004059 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004060}
4061
4062DEFUN (bgp_network_mask_natural_route_map,
4063 bgp_network_mask_natural_route_map_cmd,
4064 "network A.B.C.D route-map WORD",
4065 "Specify a network to announce via BGP\n"
4066 "Network number\n"
4067 "Route-map to modify the attributes\n"
4068 "Name of the route map\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), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004082}
4083
4084DEFUN (bgp_network_mask_natural_backdoor,
4085 bgp_network_mask_natural_backdoor_cmd,
4086 "network A.B.C.D backdoor",
4087 "Specify a network to announce via BGP\n"
4088 "Network number\n"
4089 "Specify a BGP backdoor route\n")
4090{
4091 int ret;
4092 char prefix_str[BUFSIZ];
4093
4094 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4095 if (! ret)
4096 {
4097 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4098 return CMD_WARNING;
4099 }
4100
Paul Jakma41367172007-08-06 15:24:51 +00004101 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004102 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004103}
4104
4105DEFUN (no_bgp_network,
4106 no_bgp_network_cmd,
4107 "no network A.B.C.D/M",
4108 NO_STR
4109 "Specify a network to announce via BGP\n"
4110 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4111{
4112 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4113 bgp_node_safi (vty));
4114}
4115
4116ALIAS (no_bgp_network,
4117 no_bgp_network_route_map_cmd,
4118 "no network A.B.C.D/M route-map WORD",
4119 NO_STR
4120 "Specify a network to announce via BGP\n"
4121 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4122 "Route-map to modify the attributes\n"
4123 "Name of the route map\n")
4124
4125ALIAS (no_bgp_network,
4126 no_bgp_network_backdoor_cmd,
4127 "no network A.B.C.D/M backdoor",
4128 NO_STR
4129 "Specify a network to announce via BGP\n"
4130 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4131 "Specify a BGP backdoor route\n")
4132
4133DEFUN (no_bgp_network_mask,
4134 no_bgp_network_mask_cmd,
4135 "no network A.B.C.D mask A.B.C.D",
4136 NO_STR
4137 "Specify a network to announce via BGP\n"
4138 "Network number\n"
4139 "Network mask\n"
4140 "Network mask\n")
4141{
4142 int ret;
4143 char prefix_str[BUFSIZ];
4144
4145 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4146 if (! ret)
4147 {
4148 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4149 return CMD_WARNING;
4150 }
4151
4152 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4153 bgp_node_safi (vty));
4154}
4155
4156ALIAS (no_bgp_network_mask,
4157 no_bgp_network_mask_route_map_cmd,
4158 "no network A.B.C.D mask A.B.C.D route-map WORD",
4159 NO_STR
4160 "Specify a network to announce via BGP\n"
4161 "Network number\n"
4162 "Network mask\n"
4163 "Network mask\n"
4164 "Route-map to modify the attributes\n"
4165 "Name of the route map\n")
4166
4167ALIAS (no_bgp_network_mask,
4168 no_bgp_network_mask_backdoor_cmd,
4169 "no network A.B.C.D mask A.B.C.D backdoor",
4170 NO_STR
4171 "Specify a network to announce via BGP\n"
4172 "Network number\n"
4173 "Network mask\n"
4174 "Network mask\n"
4175 "Specify a BGP backdoor route\n")
4176
4177DEFUN (no_bgp_network_mask_natural,
4178 no_bgp_network_mask_natural_cmd,
4179 "no network A.B.C.D",
4180 NO_STR
4181 "Specify a network to announce via BGP\n"
4182 "Network number\n")
4183{
4184 int ret;
4185 char prefix_str[BUFSIZ];
4186
4187 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4188 if (! ret)
4189 {
4190 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4191 return CMD_WARNING;
4192 }
4193
4194 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4195 bgp_node_safi (vty));
4196}
4197
4198ALIAS (no_bgp_network_mask_natural,
4199 no_bgp_network_mask_natural_route_map_cmd,
4200 "no network A.B.C.D route-map WORD",
4201 NO_STR
4202 "Specify a network to announce via BGP\n"
4203 "Network number\n"
4204 "Route-map to modify the attributes\n"
4205 "Name of the route map\n")
4206
4207ALIAS (no_bgp_network_mask_natural,
4208 no_bgp_network_mask_natural_backdoor_cmd,
4209 "no network A.B.C.D backdoor",
4210 NO_STR
4211 "Specify a network to announce via BGP\n"
4212 "Network number\n"
4213 "Specify a BGP backdoor route\n")
4214
4215#ifdef HAVE_IPV6
4216DEFUN (ipv6_bgp_network,
4217 ipv6_bgp_network_cmd,
4218 "network X:X::X:X/M",
4219 "Specify a network to announce via BGP\n"
4220 "IPv6 prefix <network>/<length>\n")
4221{
Paul Jakma41367172007-08-06 15:24:51 +00004222 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004223 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004224}
4225
4226DEFUN (ipv6_bgp_network_route_map,
4227 ipv6_bgp_network_route_map_cmd,
4228 "network X:X::X:X/M route-map WORD",
4229 "Specify a network to announce via BGP\n"
4230 "IPv6 prefix <network>/<length>\n"
4231 "Route-map to modify the attributes\n"
4232 "Name of the route map\n")
4233{
4234 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004235 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004236}
4237
4238DEFUN (no_ipv6_bgp_network,
4239 no_ipv6_bgp_network_cmd,
4240 "no network X:X::X:X/M",
4241 NO_STR
4242 "Specify a network to announce via BGP\n"
4243 "IPv6 prefix <network>/<length>\n")
4244{
4245 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4246}
4247
4248ALIAS (no_ipv6_bgp_network,
4249 no_ipv6_bgp_network_route_map_cmd,
4250 "no network X:X::X:X/M route-map WORD",
4251 NO_STR
4252 "Specify a network to announce via BGP\n"
4253 "IPv6 prefix <network>/<length>\n"
4254 "Route-map to modify the attributes\n"
4255 "Name of the route map\n")
4256
4257ALIAS (ipv6_bgp_network,
4258 old_ipv6_bgp_network_cmd,
4259 "ipv6 bgp network X:X::X:X/M",
4260 IPV6_STR
4261 BGP_STR
4262 "Specify a network to announce via BGP\n"
4263 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4264
4265ALIAS (no_ipv6_bgp_network,
4266 old_no_ipv6_bgp_network_cmd,
4267 "no ipv6 bgp network X:X::X:X/M",
4268 NO_STR
4269 IPV6_STR
4270 BGP_STR
4271 "Specify a network to announce via BGP\n"
4272 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4273#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004274
4275/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4276ALIAS_DEPRECATED (bgp_network,
4277 bgp_network_ttl_cmd,
4278 "network A.B.C.D/M pathlimit <0-255>",
4279 "Specify a network to announce via BGP\n"
4280 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4281 "AS-Path hopcount limit attribute\n"
4282 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4283ALIAS_DEPRECATED (bgp_network_backdoor,
4284 bgp_network_backdoor_ttl_cmd,
4285 "network A.B.C.D/M backdoor pathlimit <0-255>",
4286 "Specify a network to announce via BGP\n"
4287 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4288 "Specify a BGP backdoor route\n"
4289 "AS-Path hopcount limit attribute\n"
4290 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4291ALIAS_DEPRECATED (bgp_network_mask,
4292 bgp_network_mask_ttl_cmd,
4293 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4294 "Specify a network to announce via BGP\n"
4295 "Network number\n"
4296 "Network mask\n"
4297 "Network mask\n"
4298 "AS-Path hopcount limit attribute\n"
4299 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4300ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4301 bgp_network_mask_backdoor_ttl_cmd,
4302 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4303 "Specify a network to announce via BGP\n"
4304 "Network number\n"
4305 "Network mask\n"
4306 "Network mask\n"
4307 "Specify a BGP backdoor route\n"
4308 "AS-Path hopcount limit attribute\n"
4309 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4310ALIAS_DEPRECATED (bgp_network_mask_natural,
4311 bgp_network_mask_natural_ttl_cmd,
4312 "network A.B.C.D pathlimit <0-255>",
4313 "Specify a network to announce via BGP\n"
4314 "Network number\n"
4315 "AS-Path hopcount limit attribute\n"
4316 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4317ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4318 bgp_network_mask_natural_backdoor_ttl_cmd,
4319 "network A.B.C.D backdoor pathlimit (1-255>",
4320 "Specify a network to announce via BGP\n"
4321 "Network number\n"
4322 "Specify a BGP backdoor route\n"
4323 "AS-Path hopcount limit attribute\n"
4324 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4325ALIAS_DEPRECATED (no_bgp_network,
4326 no_bgp_network_ttl_cmd,
4327 "no network A.B.C.D/M pathlimit <0-255>",
4328 NO_STR
4329 "Specify a network to announce via BGP\n"
4330 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4331 "AS-Path hopcount limit attribute\n"
4332 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4333ALIAS_DEPRECATED (no_bgp_network,
4334 no_bgp_network_backdoor_ttl_cmd,
4335 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4336 NO_STR
4337 "Specify a network to announce via BGP\n"
4338 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4339 "Specify a BGP backdoor route\n"
4340 "AS-Path hopcount limit attribute\n"
4341 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4342ALIAS_DEPRECATED (no_bgp_network,
4343 no_bgp_network_mask_ttl_cmd,
4344 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4345 NO_STR
4346 "Specify a network to announce via BGP\n"
4347 "Network number\n"
4348 "Network mask\n"
4349 "Network mask\n"
4350 "AS-Path hopcount limit attribute\n"
4351 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4352ALIAS_DEPRECATED (no_bgp_network_mask,
4353 no_bgp_network_mask_backdoor_ttl_cmd,
4354 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4355 NO_STR
4356 "Specify a network to announce via BGP\n"
4357 "Network number\n"
4358 "Network mask\n"
4359 "Network mask\n"
4360 "Specify a BGP backdoor route\n"
4361 "AS-Path hopcount limit attribute\n"
4362 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4363ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4364 no_bgp_network_mask_natural_ttl_cmd,
4365 "no network A.B.C.D pathlimit <0-255>",
4366 NO_STR
4367 "Specify a network to announce via BGP\n"
4368 "Network number\n"
4369 "AS-Path hopcount limit attribute\n"
4370 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4371ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4372 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4373 "no network A.B.C.D backdoor pathlimit <0-255>",
4374 NO_STR
4375 "Specify a network to announce via BGP\n"
4376 "Network number\n"
4377 "Specify a BGP backdoor route\n"
4378 "AS-Path hopcount limit attribute\n"
4379 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004380#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004381ALIAS_DEPRECATED (ipv6_bgp_network,
4382 ipv6_bgp_network_ttl_cmd,
4383 "network X:X::X:X/M pathlimit <0-255>",
4384 "Specify a network to announce via BGP\n"
4385 "IPv6 prefix <network>/<length>\n"
4386 "AS-Path hopcount limit attribute\n"
4387 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4388ALIAS_DEPRECATED (no_ipv6_bgp_network,
4389 no_ipv6_bgp_network_ttl_cmd,
4390 "no network X:X::X:X/M pathlimit <0-255>",
4391 NO_STR
4392 "Specify a network to announce via BGP\n"
4393 "IPv6 prefix <network>/<length>\n"
4394 "AS-Path hopcount limit attribute\n"
4395 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004396#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004397
4398/* Aggreagete address:
4399
4400 advertise-map Set condition to advertise attribute
4401 as-set Generate AS set path information
4402 attribute-map Set attributes of aggregate
4403 route-map Set parameters of aggregate
4404 summary-only Filter more specific routes from updates
4405 suppress-map Conditionally filter more specific routes from updates
4406 <cr>
4407 */
4408struct bgp_aggregate
4409{
4410 /* Summary-only flag. */
4411 u_char summary_only;
4412
4413 /* AS set generation. */
4414 u_char as_set;
4415
4416 /* Route-map for aggregated route. */
4417 struct route_map *map;
4418
4419 /* Suppress-count. */
4420 unsigned long count;
4421
4422 /* SAFI configuration. */
4423 safi_t safi;
4424};
4425
paul94f2b392005-06-28 12:44:16 +00004426static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004427bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004428{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004429 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004430}
4431
paul94f2b392005-06-28 12:44:16 +00004432static void
paul718e3742002-12-13 20:15:29 +00004433bgp_aggregate_free (struct bgp_aggregate *aggregate)
4434{
4435 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4436}
4437
paul94f2b392005-06-28 12:44:16 +00004438static void
paul718e3742002-12-13 20:15:29 +00004439bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4440 afi_t afi, safi_t safi, struct bgp_info *del,
4441 struct bgp_aggregate *aggregate)
4442{
4443 struct bgp_table *table;
4444 struct bgp_node *top;
4445 struct bgp_node *rn;
4446 u_char origin;
4447 struct aspath *aspath = NULL;
4448 struct aspath *asmerge = NULL;
4449 struct community *community = NULL;
4450 struct community *commerge = NULL;
4451 struct in_addr nexthop;
4452 u_int32_t med = 0;
4453 struct bgp_info *ri;
4454 struct bgp_info *new;
4455 int first = 1;
4456 unsigned long match = 0;
4457
4458 /* Record adding route's nexthop and med. */
4459 if (rinew)
4460 {
4461 nexthop = rinew->attr->nexthop;
4462 med = rinew->attr->med;
4463 }
4464
4465 /* ORIGIN attribute: If at least one route among routes that are
4466 aggregated has ORIGIN with the value INCOMPLETE, then the
4467 aggregated route must have the ORIGIN attribute with the value
4468 INCOMPLETE. Otherwise, if at least one route among routes that
4469 are aggregated has ORIGIN with the value EGP, then the aggregated
4470 route must have the origin attribute with the value EGP. In all
4471 other case the value of the ORIGIN attribute of the aggregated
4472 route is INTERNAL. */
4473 origin = BGP_ORIGIN_IGP;
4474
4475 table = bgp->rib[afi][safi];
4476
4477 top = bgp_node_get (table, p);
4478 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4479 if (rn->p.prefixlen > p->prefixlen)
4480 {
4481 match = 0;
4482
4483 for (ri = rn->info; ri; ri = ri->next)
4484 {
4485 if (BGP_INFO_HOLDDOWN (ri))
4486 continue;
4487
4488 if (del && ri == del)
4489 continue;
4490
4491 if (! rinew && first)
4492 {
4493 nexthop = ri->attr->nexthop;
4494 med = ri->attr->med;
4495 first = 0;
4496 }
4497
4498#ifdef AGGREGATE_NEXTHOP_CHECK
4499 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4500 || ri->attr->med != med)
4501 {
4502 if (aspath)
4503 aspath_free (aspath);
4504 if (community)
4505 community_free (community);
4506 bgp_unlock_node (rn);
4507 bgp_unlock_node (top);
4508 return;
4509 }
4510#endif /* AGGREGATE_NEXTHOP_CHECK */
4511
4512 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4513 {
4514 if (aggregate->summary_only)
4515 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004516 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004517 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004518 match++;
4519 }
4520
4521 aggregate->count++;
4522
4523 if (aggregate->as_set)
4524 {
4525 if (origin < ri->attr->origin)
4526 origin = ri->attr->origin;
4527
4528 if (aspath)
4529 {
4530 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4531 aspath_free (aspath);
4532 aspath = asmerge;
4533 }
4534 else
4535 aspath = aspath_dup (ri->attr->aspath);
4536
4537 if (ri->attr->community)
4538 {
4539 if (community)
4540 {
4541 commerge = community_merge (community,
4542 ri->attr->community);
4543 community = community_uniq_sort (commerge);
4544 community_free (commerge);
4545 }
4546 else
4547 community = community_dup (ri->attr->community);
4548 }
4549 }
4550 }
4551 }
4552 if (match)
4553 bgp_process (bgp, rn, afi, safi);
4554 }
4555 bgp_unlock_node (top);
4556
4557 if (rinew)
4558 {
4559 aggregate->count++;
4560
4561 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004562 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004563
4564 if (aggregate->as_set)
4565 {
4566 if (origin < rinew->attr->origin)
4567 origin = rinew->attr->origin;
4568
4569 if (aspath)
4570 {
4571 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4572 aspath_free (aspath);
4573 aspath = asmerge;
4574 }
4575 else
4576 aspath = aspath_dup (rinew->attr->aspath);
4577
4578 if (rinew->attr->community)
4579 {
4580 if (community)
4581 {
4582 commerge = community_merge (community,
4583 rinew->attr->community);
4584 community = community_uniq_sort (commerge);
4585 community_free (commerge);
4586 }
4587 else
4588 community = community_dup (rinew->attr->community);
4589 }
4590 }
4591 }
4592
4593 if (aggregate->count > 0)
4594 {
4595 rn = bgp_node_get (table, p);
4596 new = bgp_info_new ();
4597 new->type = ZEBRA_ROUTE_BGP;
4598 new->sub_type = BGP_ROUTE_AGGREGATE;
4599 new->peer = bgp->peer_self;
4600 SET_FLAG (new->flags, BGP_INFO_VALID);
4601 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004602 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004603
4604 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004605 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004606 bgp_process (bgp, rn, afi, safi);
4607 }
4608 else
4609 {
4610 if (aspath)
4611 aspath_free (aspath);
4612 if (community)
4613 community_free (community);
4614 }
4615}
4616
4617void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4618 struct bgp_aggregate *);
4619
4620void
4621bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4622 struct bgp_info *ri, afi_t afi, safi_t safi)
4623{
4624 struct bgp_node *child;
4625 struct bgp_node *rn;
4626 struct bgp_aggregate *aggregate;
4627
4628 /* MPLS-VPN aggregation is not yet supported. */
4629 if (safi == SAFI_MPLS_VPN)
4630 return;
4631
4632 if (p->prefixlen == 0)
4633 return;
4634
4635 if (BGP_INFO_HOLDDOWN (ri))
4636 return;
4637
4638 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4639
4640 /* Aggregate address configuration check. */
4641 for (rn = child; rn; rn = rn->parent)
4642 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4643 {
4644 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004645 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004646 }
4647 bgp_unlock_node (child);
4648}
4649
4650void
4651bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4652 struct bgp_info *del, afi_t afi, safi_t safi)
4653{
4654 struct bgp_node *child;
4655 struct bgp_node *rn;
4656 struct bgp_aggregate *aggregate;
4657
4658 /* MPLS-VPN aggregation is not yet supported. */
4659 if (safi == SAFI_MPLS_VPN)
4660 return;
4661
4662 if (p->prefixlen == 0)
4663 return;
4664
4665 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4666
4667 /* Aggregate address configuration check. */
4668 for (rn = child; rn; rn = rn->parent)
4669 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4670 {
4671 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004672 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004673 }
4674 bgp_unlock_node (child);
4675}
4676
paul94f2b392005-06-28 12:44:16 +00004677static void
paul718e3742002-12-13 20:15:29 +00004678bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4679 struct bgp_aggregate *aggregate)
4680{
4681 struct bgp_table *table;
4682 struct bgp_node *top;
4683 struct bgp_node *rn;
4684 struct bgp_info *new;
4685 struct bgp_info *ri;
4686 unsigned long match;
4687 u_char origin = BGP_ORIGIN_IGP;
4688 struct aspath *aspath = NULL;
4689 struct aspath *asmerge = NULL;
4690 struct community *community = NULL;
4691 struct community *commerge = NULL;
4692
4693 table = bgp->rib[afi][safi];
4694
4695 /* Sanity check. */
4696 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4697 return;
4698 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4699 return;
4700
4701 /* If routes exists below this node, generate aggregate routes. */
4702 top = bgp_node_get (table, p);
4703 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4704 if (rn->p.prefixlen > p->prefixlen)
4705 {
4706 match = 0;
4707
4708 for (ri = rn->info; ri; ri = ri->next)
4709 {
4710 if (BGP_INFO_HOLDDOWN (ri))
4711 continue;
4712
4713 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4714 {
4715 /* summary-only aggregate route suppress aggregated
4716 route announcement. */
4717 if (aggregate->summary_only)
4718 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004719 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004720 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004721 match++;
4722 }
4723 /* as-set aggregate route generate origin, as path,
4724 community aggregation. */
4725 if (aggregate->as_set)
4726 {
4727 if (origin < ri->attr->origin)
4728 origin = ri->attr->origin;
4729
4730 if (aspath)
4731 {
4732 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4733 aspath_free (aspath);
4734 aspath = asmerge;
4735 }
4736 else
4737 aspath = aspath_dup (ri->attr->aspath);
4738
4739 if (ri->attr->community)
4740 {
4741 if (community)
4742 {
4743 commerge = community_merge (community,
4744 ri->attr->community);
4745 community = community_uniq_sort (commerge);
4746 community_free (commerge);
4747 }
4748 else
4749 community = community_dup (ri->attr->community);
4750 }
4751 }
4752 aggregate->count++;
4753 }
4754 }
4755
4756 /* If this node is suppressed, process the change. */
4757 if (match)
4758 bgp_process (bgp, rn, afi, safi);
4759 }
4760 bgp_unlock_node (top);
4761
4762 /* Add aggregate route to BGP table. */
4763 if (aggregate->count)
4764 {
4765 rn = bgp_node_get (table, p);
4766
4767 new = bgp_info_new ();
4768 new->type = ZEBRA_ROUTE_BGP;
4769 new->sub_type = BGP_ROUTE_AGGREGATE;
4770 new->peer = bgp->peer_self;
4771 SET_FLAG (new->flags, BGP_INFO_VALID);
4772 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004773 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004774
4775 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004776 bgp_unlock_node (rn);
4777
paul718e3742002-12-13 20:15:29 +00004778 /* Process change. */
4779 bgp_process (bgp, rn, afi, safi);
4780 }
4781}
4782
4783void
4784bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4785 safi_t safi, struct bgp_aggregate *aggregate)
4786{
4787 struct bgp_table *table;
4788 struct bgp_node *top;
4789 struct bgp_node *rn;
4790 struct bgp_info *ri;
4791 unsigned long match;
4792
4793 table = bgp->rib[afi][safi];
4794
4795 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4796 return;
4797 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4798 return;
4799
4800 /* If routes exists below this node, generate aggregate routes. */
4801 top = bgp_node_get (table, p);
4802 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4803 if (rn->p.prefixlen > p->prefixlen)
4804 {
4805 match = 0;
4806
4807 for (ri = rn->info; ri; ri = ri->next)
4808 {
4809 if (BGP_INFO_HOLDDOWN (ri))
4810 continue;
4811
4812 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4813 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004814 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004815 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004816 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004817
Paul Jakmafb982c22007-05-04 20:15:47 +00004818 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004819 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004820 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004821 match++;
4822 }
4823 }
4824 aggregate->count--;
4825 }
4826 }
4827
Paul Jakmafb982c22007-05-04 20:15:47 +00004828 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004829 if (match)
4830 bgp_process (bgp, rn, afi, safi);
4831 }
4832 bgp_unlock_node (top);
4833
4834 /* Delete aggregate route from BGP table. */
4835 rn = bgp_node_get (table, p);
4836
4837 for (ri = rn->info; ri; ri = ri->next)
4838 if (ri->peer == bgp->peer_self
4839 && ri->type == ZEBRA_ROUTE_BGP
4840 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4841 break;
4842
4843 /* Withdraw static BGP route from routing table. */
4844 if (ri)
4845 {
paul718e3742002-12-13 20:15:29 +00004846 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004847 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004848 }
4849
4850 /* Unlock bgp_node_lookup. */
4851 bgp_unlock_node (rn);
4852}
4853
4854/* Aggregate route attribute. */
4855#define AGGREGATE_SUMMARY_ONLY 1
4856#define AGGREGATE_AS_SET 1
4857
paul94f2b392005-06-28 12:44:16 +00004858static int
Robert Baysf6269b42010-08-05 10:26:28 -07004859bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4860 afi_t afi, safi_t safi)
4861{
4862 int ret;
4863 struct prefix p;
4864 struct bgp_node *rn;
4865 struct bgp *bgp;
4866 struct bgp_aggregate *aggregate;
4867
4868 /* Convert string to prefix structure. */
4869 ret = str2prefix (prefix_str, &p);
4870 if (!ret)
4871 {
4872 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4873 return CMD_WARNING;
4874 }
4875 apply_mask (&p);
4876
4877 /* Get BGP structure. */
4878 bgp = vty->index;
4879
4880 /* Old configuration check. */
4881 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4882 if (! rn)
4883 {
4884 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4885 VTY_NEWLINE);
4886 return CMD_WARNING;
4887 }
4888
4889 aggregate = rn->info;
4890 if (aggregate->safi & SAFI_UNICAST)
4891 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4892 if (aggregate->safi & SAFI_MULTICAST)
4893 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4894
4895 /* Unlock aggregate address configuration. */
4896 rn->info = NULL;
4897 bgp_aggregate_free (aggregate);
4898 bgp_unlock_node (rn);
4899 bgp_unlock_node (rn);
4900
4901 return CMD_SUCCESS;
4902}
4903
4904static int
4905bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004906 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004907 u_char summary_only, u_char as_set)
4908{
4909 int ret;
4910 struct prefix p;
4911 struct bgp_node *rn;
4912 struct bgp *bgp;
4913 struct bgp_aggregate *aggregate;
4914
4915 /* Convert string to prefix structure. */
4916 ret = str2prefix (prefix_str, &p);
4917 if (!ret)
4918 {
4919 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4920 return CMD_WARNING;
4921 }
4922 apply_mask (&p);
4923
4924 /* Get BGP structure. */
4925 bgp = vty->index;
4926
4927 /* Old configuration check. */
4928 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4929
4930 if (rn->info)
4931 {
4932 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004933 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004934 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4935 if (ret)
4936 {
Robert Bays368473f2010-08-05 10:26:29 -07004937 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4938 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004939 return CMD_WARNING;
4940 }
paul718e3742002-12-13 20:15:29 +00004941 }
4942
4943 /* Make aggregate address structure. */
4944 aggregate = bgp_aggregate_new ();
4945 aggregate->summary_only = summary_only;
4946 aggregate->as_set = as_set;
4947 aggregate->safi = safi;
4948 rn->info = aggregate;
4949
4950 /* Aggregate address insert into BGP routing table. */
4951 if (safi & SAFI_UNICAST)
4952 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4953 if (safi & SAFI_MULTICAST)
4954 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4955
4956 return CMD_SUCCESS;
4957}
4958
paul718e3742002-12-13 20:15:29 +00004959DEFUN (aggregate_address,
4960 aggregate_address_cmd,
4961 "aggregate-address A.B.C.D/M",
4962 "Configure BGP aggregate entries\n"
4963 "Aggregate prefix\n")
4964{
4965 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4966}
4967
4968DEFUN (aggregate_address_mask,
4969 aggregate_address_mask_cmd,
4970 "aggregate-address A.B.C.D A.B.C.D",
4971 "Configure BGP aggregate entries\n"
4972 "Aggregate address\n"
4973 "Aggregate mask\n")
4974{
4975 int ret;
4976 char prefix_str[BUFSIZ];
4977
4978 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4979
4980 if (! ret)
4981 {
4982 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4983 return CMD_WARNING;
4984 }
4985
4986 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4987 0, 0);
4988}
4989
4990DEFUN (aggregate_address_summary_only,
4991 aggregate_address_summary_only_cmd,
4992 "aggregate-address A.B.C.D/M summary-only",
4993 "Configure BGP aggregate entries\n"
4994 "Aggregate prefix\n"
4995 "Filter more specific routes from updates\n")
4996{
4997 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4998 AGGREGATE_SUMMARY_ONLY, 0);
4999}
5000
5001DEFUN (aggregate_address_mask_summary_only,
5002 aggregate_address_mask_summary_only_cmd,
5003 "aggregate-address A.B.C.D A.B.C.D summary-only",
5004 "Configure BGP aggregate entries\n"
5005 "Aggregate address\n"
5006 "Aggregate mask\n"
5007 "Filter more specific routes from updates\n")
5008{
5009 int ret;
5010 char prefix_str[BUFSIZ];
5011
5012 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5013
5014 if (! ret)
5015 {
5016 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5017 return CMD_WARNING;
5018 }
5019
5020 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5021 AGGREGATE_SUMMARY_ONLY, 0);
5022}
5023
5024DEFUN (aggregate_address_as_set,
5025 aggregate_address_as_set_cmd,
5026 "aggregate-address A.B.C.D/M as-set",
5027 "Configure BGP aggregate entries\n"
5028 "Aggregate prefix\n"
5029 "Generate AS set path information\n")
5030{
5031 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5032 0, AGGREGATE_AS_SET);
5033}
5034
5035DEFUN (aggregate_address_mask_as_set,
5036 aggregate_address_mask_as_set_cmd,
5037 "aggregate-address A.B.C.D A.B.C.D as-set",
5038 "Configure BGP aggregate entries\n"
5039 "Aggregate address\n"
5040 "Aggregate mask\n"
5041 "Generate AS set path information\n")
5042{
5043 int ret;
5044 char prefix_str[BUFSIZ];
5045
5046 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5047
5048 if (! ret)
5049 {
5050 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5051 return CMD_WARNING;
5052 }
5053
5054 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5055 0, AGGREGATE_AS_SET);
5056}
5057
5058
5059DEFUN (aggregate_address_as_set_summary,
5060 aggregate_address_as_set_summary_cmd,
5061 "aggregate-address A.B.C.D/M as-set summary-only",
5062 "Configure BGP aggregate entries\n"
5063 "Aggregate prefix\n"
5064 "Generate AS set path information\n"
5065 "Filter more specific routes from updates\n")
5066{
5067 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5068 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5069}
5070
5071ALIAS (aggregate_address_as_set_summary,
5072 aggregate_address_summary_as_set_cmd,
5073 "aggregate-address A.B.C.D/M summary-only as-set",
5074 "Configure BGP aggregate entries\n"
5075 "Aggregate prefix\n"
5076 "Filter more specific routes from updates\n"
5077 "Generate AS set path information\n")
5078
5079DEFUN (aggregate_address_mask_as_set_summary,
5080 aggregate_address_mask_as_set_summary_cmd,
5081 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5082 "Configure BGP aggregate entries\n"
5083 "Aggregate address\n"
5084 "Aggregate mask\n"
5085 "Generate AS set path information\n"
5086 "Filter more specific routes from updates\n")
5087{
5088 int ret;
5089 char prefix_str[BUFSIZ];
5090
5091 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5092
5093 if (! ret)
5094 {
5095 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5096 return CMD_WARNING;
5097 }
5098
5099 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5100 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5101}
5102
5103ALIAS (aggregate_address_mask_as_set_summary,
5104 aggregate_address_mask_summary_as_set_cmd,
5105 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5106 "Configure BGP aggregate entries\n"
5107 "Aggregate address\n"
5108 "Aggregate mask\n"
5109 "Filter more specific routes from updates\n"
5110 "Generate AS set path information\n")
5111
5112DEFUN (no_aggregate_address,
5113 no_aggregate_address_cmd,
5114 "no aggregate-address A.B.C.D/M",
5115 NO_STR
5116 "Configure BGP aggregate entries\n"
5117 "Aggregate prefix\n")
5118{
5119 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5120}
5121
5122ALIAS (no_aggregate_address,
5123 no_aggregate_address_summary_only_cmd,
5124 "no aggregate-address A.B.C.D/M summary-only",
5125 NO_STR
5126 "Configure BGP aggregate entries\n"
5127 "Aggregate prefix\n"
5128 "Filter more specific routes from updates\n")
5129
5130ALIAS (no_aggregate_address,
5131 no_aggregate_address_as_set_cmd,
5132 "no aggregate-address A.B.C.D/M as-set",
5133 NO_STR
5134 "Configure BGP aggregate entries\n"
5135 "Aggregate prefix\n"
5136 "Generate AS set path information\n")
5137
5138ALIAS (no_aggregate_address,
5139 no_aggregate_address_as_set_summary_cmd,
5140 "no aggregate-address A.B.C.D/M as-set summary-only",
5141 NO_STR
5142 "Configure BGP aggregate entries\n"
5143 "Aggregate prefix\n"
5144 "Generate AS set path information\n"
5145 "Filter more specific routes from updates\n")
5146
5147ALIAS (no_aggregate_address,
5148 no_aggregate_address_summary_as_set_cmd,
5149 "no aggregate-address A.B.C.D/M summary-only as-set",
5150 NO_STR
5151 "Configure BGP aggregate entries\n"
5152 "Aggregate prefix\n"
5153 "Filter more specific routes from updates\n"
5154 "Generate AS set path information\n")
5155
5156DEFUN (no_aggregate_address_mask,
5157 no_aggregate_address_mask_cmd,
5158 "no aggregate-address A.B.C.D A.B.C.D",
5159 NO_STR
5160 "Configure BGP aggregate entries\n"
5161 "Aggregate address\n"
5162 "Aggregate mask\n")
5163{
5164 int ret;
5165 char prefix_str[BUFSIZ];
5166
5167 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5168
5169 if (! ret)
5170 {
5171 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5172 return CMD_WARNING;
5173 }
5174
5175 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5176}
5177
5178ALIAS (no_aggregate_address_mask,
5179 no_aggregate_address_mask_summary_only_cmd,
5180 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5181 NO_STR
5182 "Configure BGP aggregate entries\n"
5183 "Aggregate address\n"
5184 "Aggregate mask\n"
5185 "Filter more specific routes from updates\n")
5186
5187ALIAS (no_aggregate_address_mask,
5188 no_aggregate_address_mask_as_set_cmd,
5189 "no aggregate-address A.B.C.D A.B.C.D as-set",
5190 NO_STR
5191 "Configure BGP aggregate entries\n"
5192 "Aggregate address\n"
5193 "Aggregate mask\n"
5194 "Generate AS set path information\n")
5195
5196ALIAS (no_aggregate_address_mask,
5197 no_aggregate_address_mask_as_set_summary_cmd,
5198 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5199 NO_STR
5200 "Configure BGP aggregate entries\n"
5201 "Aggregate address\n"
5202 "Aggregate mask\n"
5203 "Generate AS set path information\n"
5204 "Filter more specific routes from updates\n")
5205
5206ALIAS (no_aggregate_address_mask,
5207 no_aggregate_address_mask_summary_as_set_cmd,
5208 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5209 NO_STR
5210 "Configure BGP aggregate entries\n"
5211 "Aggregate address\n"
5212 "Aggregate mask\n"
5213 "Filter more specific routes from updates\n"
5214 "Generate AS set path information\n")
5215
5216#ifdef HAVE_IPV6
5217DEFUN (ipv6_aggregate_address,
5218 ipv6_aggregate_address_cmd,
5219 "aggregate-address X:X::X:X/M",
5220 "Configure BGP aggregate entries\n"
5221 "Aggregate prefix\n")
5222{
5223 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5224}
5225
5226DEFUN (ipv6_aggregate_address_summary_only,
5227 ipv6_aggregate_address_summary_only_cmd,
5228 "aggregate-address X:X::X:X/M summary-only",
5229 "Configure BGP aggregate entries\n"
5230 "Aggregate prefix\n"
5231 "Filter more specific routes from updates\n")
5232{
5233 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5234 AGGREGATE_SUMMARY_ONLY, 0);
5235}
5236
5237DEFUN (no_ipv6_aggregate_address,
5238 no_ipv6_aggregate_address_cmd,
5239 "no aggregate-address X:X::X:X/M",
5240 NO_STR
5241 "Configure BGP aggregate entries\n"
5242 "Aggregate prefix\n")
5243{
5244 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5245}
5246
5247DEFUN (no_ipv6_aggregate_address_summary_only,
5248 no_ipv6_aggregate_address_summary_only_cmd,
5249 "no aggregate-address X:X::X:X/M summary-only",
5250 NO_STR
5251 "Configure BGP aggregate entries\n"
5252 "Aggregate prefix\n"
5253 "Filter more specific routes from updates\n")
5254{
5255 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5256}
5257
5258ALIAS (ipv6_aggregate_address,
5259 old_ipv6_aggregate_address_cmd,
5260 "ipv6 bgp aggregate-address X:X::X:X/M",
5261 IPV6_STR
5262 BGP_STR
5263 "Configure BGP aggregate entries\n"
5264 "Aggregate prefix\n")
5265
5266ALIAS (ipv6_aggregate_address_summary_only,
5267 old_ipv6_aggregate_address_summary_only_cmd,
5268 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5269 IPV6_STR
5270 BGP_STR
5271 "Configure BGP aggregate entries\n"
5272 "Aggregate prefix\n"
5273 "Filter more specific routes from updates\n")
5274
5275ALIAS (no_ipv6_aggregate_address,
5276 old_no_ipv6_aggregate_address_cmd,
5277 "no ipv6 bgp aggregate-address X:X::X:X/M",
5278 NO_STR
5279 IPV6_STR
5280 BGP_STR
5281 "Configure BGP aggregate entries\n"
5282 "Aggregate prefix\n")
5283
5284ALIAS (no_ipv6_aggregate_address_summary_only,
5285 old_no_ipv6_aggregate_address_summary_only_cmd,
5286 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5287 NO_STR
5288 IPV6_STR
5289 BGP_STR
5290 "Configure BGP aggregate entries\n"
5291 "Aggregate prefix\n"
5292 "Filter more specific routes from updates\n")
5293#endif /* HAVE_IPV6 */
5294
5295/* Redistribute route treatment. */
5296void
5297bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5298 u_int32_t metric, u_char type)
5299{
5300 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005301 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005302 struct bgp_info *new;
5303 struct bgp_info *bi;
5304 struct bgp_info info;
5305 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005306 struct attr attr = { 0 };
5307 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005308 struct attr *new_attr;
5309 afi_t afi;
5310 int ret;
5311
5312 /* Make default attribute. */
5313 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5314 if (nexthop)
5315 attr.nexthop = *nexthop;
5316
5317 attr.med = metric;
5318 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5319
paul1eb8ef22005-04-07 07:30:20 +00005320 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005321 {
5322 afi = family2afi (p->family);
5323
5324 if (bgp->redist[afi][type])
5325 {
5326 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005327 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005328
5329 if (bgp->redist_metric_flag[afi][type])
5330 attr_new.med = bgp->redist_metric[afi][type];
5331
5332 /* Apply route-map. */
5333 if (bgp->rmap[afi][type].map)
5334 {
5335 info.peer = bgp->peer_self;
5336 info.attr = &attr_new;
5337
paulfee0f4c2004-09-13 05:12:46 +00005338 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5339
paul718e3742002-12-13 20:15:29 +00005340 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5341 &info);
paulfee0f4c2004-09-13 05:12:46 +00005342
5343 bgp->peer_self->rmap_type = 0;
5344
paul718e3742002-12-13 20:15:29 +00005345 if (ret == RMAP_DENYMATCH)
5346 {
5347 /* Free uninterned attribute. */
5348 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005349 bgp_attr_extra_free (&attr_new);
5350
paul718e3742002-12-13 20:15:29 +00005351 /* Unintern original. */
5352 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005353 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005354 bgp_redistribute_delete (p, type);
5355 return;
5356 }
5357 }
5358
Paul Jakmafb982c22007-05-04 20:15:47 +00005359 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5360 afi, SAFI_UNICAST, p, NULL);
5361
paul718e3742002-12-13 20:15:29 +00005362 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005363 bgp_attr_extra_free (&attr_new);
5364
paul718e3742002-12-13 20:15:29 +00005365 for (bi = bn->info; bi; bi = bi->next)
5366 if (bi->peer == bgp->peer_self
5367 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5368 break;
5369
5370 if (bi)
5371 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005372 if (attrhash_cmp (bi->attr, new_attr) &&
5373 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005374 {
5375 bgp_attr_unintern (new_attr);
5376 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005377 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005378 bgp_unlock_node (bn);
5379 return;
5380 }
5381 else
5382 {
5383 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005384 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005385
5386 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005387 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5388 bgp_info_restore(bn, bi);
5389 else
5390 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005391 bgp_attr_unintern (bi->attr);
5392 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005393 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005394
5395 /* Process change. */
5396 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5397 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5398 bgp_unlock_node (bn);
5399 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005400 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005401 return;
5402 }
5403 }
5404
5405 new = bgp_info_new ();
5406 new->type = type;
5407 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5408 new->peer = bgp->peer_self;
5409 SET_FLAG (new->flags, BGP_INFO_VALID);
5410 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005411 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005412
5413 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5414 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005415 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005416 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5417 }
5418 }
5419
5420 /* Unintern original. */
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}
5424
5425void
5426bgp_redistribute_delete (struct prefix *p, u_char type)
5427{
5428 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005429 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005430 afi_t afi;
5431 struct bgp_node *rn;
5432 struct bgp_info *ri;
5433
paul1eb8ef22005-04-07 07:30:20 +00005434 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005435 {
5436 afi = family2afi (p->family);
5437
5438 if (bgp->redist[afi][type])
5439 {
paulfee0f4c2004-09-13 05:12:46 +00005440 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005441
5442 for (ri = rn->info; ri; ri = ri->next)
5443 if (ri->peer == bgp->peer_self
5444 && ri->type == type)
5445 break;
5446
5447 if (ri)
5448 {
5449 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005450 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005451 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005452 }
5453 bgp_unlock_node (rn);
5454 }
5455 }
5456}
5457
5458/* Withdraw specified route type's route. */
5459void
5460bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5461{
5462 struct bgp_node *rn;
5463 struct bgp_info *ri;
5464 struct bgp_table *table;
5465
5466 table = bgp->rib[afi][SAFI_UNICAST];
5467
5468 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5469 {
5470 for (ri = rn->info; ri; ri = ri->next)
5471 if (ri->peer == bgp->peer_self
5472 && ri->type == type)
5473 break;
5474
5475 if (ri)
5476 {
5477 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005478 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005479 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005480 }
5481 }
5482}
5483
5484/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005485static void
paul718e3742002-12-13 20:15:29 +00005486route_vty_out_route (struct prefix *p, struct vty *vty)
5487{
5488 int len;
5489 u_int32_t destination;
5490 char buf[BUFSIZ];
5491
5492 if (p->family == AF_INET)
5493 {
5494 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5495 destination = ntohl (p->u.prefix4.s_addr);
5496
5497 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5498 || (IN_CLASSB (destination) && p->prefixlen == 16)
5499 || (IN_CLASSA (destination) && p->prefixlen == 8)
5500 || p->u.prefix4.s_addr == 0)
5501 {
5502 /* When mask is natural, mask is not displayed. */
5503 }
5504 else
5505 len += vty_out (vty, "/%d", p->prefixlen);
5506 }
5507 else
5508 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5509 p->prefixlen);
5510
5511 len = 17 - len;
5512 if (len < 1)
5513 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5514 else
5515 vty_out (vty, "%*s", len, " ");
5516}
5517
paul718e3742002-12-13 20:15:29 +00005518enum bgp_display_type
5519{
5520 normal_list,
5521};
5522
paulb40d9392005-08-22 22:34:41 +00005523/* Print the short form route status for a bgp_info */
5524static void
5525route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005526{
paulb40d9392005-08-22 22:34:41 +00005527 /* Route status display. */
5528 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5529 vty_out (vty, "R");
5530 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005531 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005532 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005533 vty_out (vty, "s");
5534 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5535 vty_out (vty, "*");
5536 else
5537 vty_out (vty, " ");
5538
5539 /* Selected */
5540 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5541 vty_out (vty, "h");
5542 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5543 vty_out (vty, "d");
5544 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5545 vty_out (vty, ">");
5546 else
5547 vty_out (vty, " ");
5548
5549 /* Internal route. */
5550 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5551 vty_out (vty, "i");
5552 else
paulb40d9392005-08-22 22:34:41 +00005553 vty_out (vty, " ");
5554}
5555
5556/* called from terminal list command */
5557void
5558route_vty_out (struct vty *vty, struct prefix *p,
5559 struct bgp_info *binfo, int display, safi_t safi)
5560{
5561 struct attr *attr;
5562
5563 /* short status lead text */
5564 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005565
5566 /* print prefix and mask */
5567 if (! display)
5568 route_vty_out_route (p, vty);
5569 else
5570 vty_out (vty, "%*s", 17, " ");
5571
5572 /* Print attribute */
5573 attr = binfo->attr;
5574 if (attr)
5575 {
5576 if (p->family == AF_INET)
5577 {
5578 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005579 vty_out (vty, "%-16s",
5580 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005581 else
5582 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5583 }
5584#ifdef HAVE_IPV6
5585 else if (p->family == AF_INET6)
5586 {
5587 int len;
5588 char buf[BUFSIZ];
5589
5590 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005591 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5592 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005593 len = 16 - len;
5594 if (len < 1)
5595 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5596 else
5597 vty_out (vty, "%*s", len, " ");
5598 }
5599#endif /* HAVE_IPV6 */
5600
5601 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005602 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005603 else
5604 vty_out (vty, " ");
5605
5606 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005607 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005608 else
5609 vty_out (vty, " ");
5610
Paul Jakmafb982c22007-05-04 20:15:47 +00005611 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005612
Paul Jakmab2518c12006-05-12 23:48:40 +00005613 /* Print aspath */
5614 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005615 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005616
Paul Jakmab2518c12006-05-12 23:48:40 +00005617 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005618 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005619 }
paul718e3742002-12-13 20:15:29 +00005620 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005621}
5622
5623/* called from terminal list command */
5624void
5625route_vty_out_tmp (struct vty *vty, struct prefix *p,
5626 struct attr *attr, safi_t safi)
5627{
5628 /* Route status display. */
5629 vty_out (vty, "*");
5630 vty_out (vty, ">");
5631 vty_out (vty, " ");
5632
5633 /* print prefix and mask */
5634 route_vty_out_route (p, vty);
5635
5636 /* Print attribute */
5637 if (attr)
5638 {
5639 if (p->family == AF_INET)
5640 {
5641 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005642 vty_out (vty, "%-16s",
5643 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005644 else
5645 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5646 }
5647#ifdef HAVE_IPV6
5648 else if (p->family == AF_INET6)
5649 {
5650 int len;
5651 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005652
5653 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005654
5655 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005656 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5657 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005658 len = 16 - len;
5659 if (len < 1)
5660 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5661 else
5662 vty_out (vty, "%*s", len, " ");
5663 }
5664#endif /* HAVE_IPV6 */
5665
5666 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005667 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005668 else
5669 vty_out (vty, " ");
5670
5671 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005672 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005673 else
5674 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005675
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005676 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005677
Paul Jakmab2518c12006-05-12 23:48:40 +00005678 /* Print aspath */
5679 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005680 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005681
Paul Jakmab2518c12006-05-12 23:48:40 +00005682 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005683 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005684 }
paul718e3742002-12-13 20:15:29 +00005685
5686 vty_out (vty, "%s", VTY_NEWLINE);
5687}
5688
ajs5a646652004-11-05 01:25:55 +00005689void
paul718e3742002-12-13 20:15:29 +00005690route_vty_out_tag (struct vty *vty, struct prefix *p,
5691 struct bgp_info *binfo, int display, safi_t safi)
5692{
5693 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005694 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005695
5696 if (!binfo->extra)
5697 return;
5698
paulb40d9392005-08-22 22:34:41 +00005699 /* short status lead text */
5700 route_vty_short_status_out (vty, binfo);
5701
paul718e3742002-12-13 20:15:29 +00005702 /* print prefix and mask */
5703 if (! display)
5704 route_vty_out_route (p, vty);
5705 else
5706 vty_out (vty, "%*s", 17, " ");
5707
5708 /* Print attribute */
5709 attr = binfo->attr;
5710 if (attr)
5711 {
5712 if (p->family == AF_INET)
5713 {
5714 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005715 vty_out (vty, "%-16s",
5716 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005717 else
5718 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5719 }
5720#ifdef HAVE_IPV6
5721 else if (p->family == AF_INET6)
5722 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005723 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005724 char buf[BUFSIZ];
5725 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005726 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005727 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005728 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5729 buf, BUFSIZ));
5730 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005731 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005732 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5733 buf, BUFSIZ),
5734 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5735 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005736
5737 }
5738#endif /* HAVE_IPV6 */
5739 }
5740
Paul Jakmafb982c22007-05-04 20:15:47 +00005741 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005742
5743 vty_out (vty, "notag/%d", label);
5744
5745 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005746}
5747
5748/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005749static void
paul718e3742002-12-13 20:15:29 +00005750damp_route_vty_out (struct vty *vty, struct prefix *p,
5751 struct bgp_info *binfo, int display, safi_t safi)
5752{
5753 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005754 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005755 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005756
paulb40d9392005-08-22 22:34:41 +00005757 /* short status lead text */
5758 route_vty_short_status_out (vty, binfo);
5759
paul718e3742002-12-13 20:15:29 +00005760 /* print prefix and mask */
5761 if (! display)
5762 route_vty_out_route (p, vty);
5763 else
5764 vty_out (vty, "%*s", 17, " ");
5765
5766 len = vty_out (vty, "%s", binfo->peer->host);
5767 len = 17 - len;
5768 if (len < 1)
5769 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5770 else
5771 vty_out (vty, "%*s", len, " ");
5772
Chris Caputo50aef6f2009-06-23 06:06:49 +00005773 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005774
5775 /* Print attribute */
5776 attr = binfo->attr;
5777 if (attr)
5778 {
5779 /* Print aspath */
5780 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005781 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005782
5783 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005784 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005785 }
5786 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005787}
5788
paul718e3742002-12-13 20:15:29 +00005789/* flap route */
ajs5a646652004-11-05 01:25:55 +00005790static void
paul718e3742002-12-13 20:15:29 +00005791flap_route_vty_out (struct vty *vty, struct prefix *p,
5792 struct bgp_info *binfo, int display, safi_t safi)
5793{
5794 struct attr *attr;
5795 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005796 char timebuf[BGP_UPTIME_LEN];
5797 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005798
5799 if (!binfo->extra)
5800 return;
5801
5802 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005803
paulb40d9392005-08-22 22:34:41 +00005804 /* short status lead text */
5805 route_vty_short_status_out (vty, binfo);
5806
paul718e3742002-12-13 20:15:29 +00005807 /* print prefix and mask */
5808 if (! display)
5809 route_vty_out_route (p, vty);
5810 else
5811 vty_out (vty, "%*s", 17, " ");
5812
5813 len = vty_out (vty, "%s", binfo->peer->host);
5814 len = 16 - len;
5815 if (len < 1)
5816 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5817 else
5818 vty_out (vty, "%*s", len, " ");
5819
5820 len = vty_out (vty, "%d", bdi->flap);
5821 len = 5 - len;
5822 if (len < 1)
5823 vty_out (vty, " ");
5824 else
5825 vty_out (vty, "%*s ", len, " ");
5826
5827 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5828 timebuf, BGP_UPTIME_LEN));
5829
5830 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5831 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005832 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005833 else
5834 vty_out (vty, "%*s ", 8, " ");
5835
5836 /* Print attribute */
5837 attr = binfo->attr;
5838 if (attr)
5839 {
5840 /* Print aspath */
5841 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005842 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005843
5844 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005845 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005846 }
5847 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005848}
5849
paul94f2b392005-06-28 12:44:16 +00005850static void
paul718e3742002-12-13 20:15:29 +00005851route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5852 struct bgp_info *binfo, afi_t afi, safi_t safi)
5853{
5854 char buf[INET6_ADDRSTRLEN];
5855 char buf1[BUFSIZ];
5856 struct attr *attr;
5857 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005858#ifdef HAVE_CLOCK_MONOTONIC
5859 time_t tbuf;
5860#endif
paul718e3742002-12-13 20:15:29 +00005861
5862 attr = binfo->attr;
5863
5864 if (attr)
5865 {
5866 /* Line1 display AS-path, Aggregator */
5867 if (attr->aspath)
5868 {
5869 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005870 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005871 vty_out (vty, "Local");
5872 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005873 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005874 }
5875
paulb40d9392005-08-22 22:34:41 +00005876 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5877 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005878 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5879 vty_out (vty, ", (stale)");
5880 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005881 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005882 attr->extra->aggregator_as,
5883 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005884 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5885 vty_out (vty, ", (Received from a RR-client)");
5886 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5887 vty_out (vty, ", (Received from a RS-client)");
5888 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5889 vty_out (vty, ", (history entry)");
5890 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5891 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005892 vty_out (vty, "%s", VTY_NEWLINE);
5893
5894 /* Line2 display Next-hop, Neighbor, Router-id */
5895 if (p->family == AF_INET)
5896 {
5897 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005898 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005899 inet_ntoa (attr->nexthop));
5900 }
5901#ifdef HAVE_IPV6
5902 else
5903 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005904 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005905 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005906 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005907 buf, INET6_ADDRSTRLEN));
5908 }
5909#endif /* HAVE_IPV6 */
5910
5911 if (binfo->peer == bgp->peer_self)
5912 {
5913 vty_out (vty, " from %s ",
5914 p->family == AF_INET ? "0.0.0.0" : "::");
5915 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5916 }
5917 else
5918 {
5919 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5920 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005921 else if (binfo->extra && binfo->extra->igpmetric)
5922 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005923 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005924 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005925 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005926 else
5927 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5928 }
5929 vty_out (vty, "%s", VTY_NEWLINE);
5930
5931#ifdef HAVE_IPV6
5932 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005933 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005934 {
5935 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005936 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005937 buf, INET6_ADDRSTRLEN),
5938 VTY_NEWLINE);
5939 }
5940#endif /* HAVE_IPV6 */
5941
5942 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5943 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5944
5945 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005946 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005947
5948 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005949 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005950 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005951 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005952
Paul Jakmafb982c22007-05-04 20:15:47 +00005953 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005954 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005955
5956 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5957 vty_out (vty, ", valid");
5958
5959 if (binfo->peer != bgp->peer_self)
5960 {
5961 if (binfo->peer->as == binfo->peer->local_as)
5962 vty_out (vty, ", internal");
5963 else
5964 vty_out (vty, ", %s",
5965 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5966 }
5967 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5968 vty_out (vty, ", aggregated, local");
5969 else if (binfo->type != ZEBRA_ROUTE_BGP)
5970 vty_out (vty, ", sourced");
5971 else
5972 vty_out (vty, ", sourced, local");
5973
5974 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5975 vty_out (vty, ", atomic-aggregate");
5976
Josh Baileyde8d5df2011-07-20 20:46:01 -07005977 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
5978 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
5979 bgp_info_mpath_count (binfo)))
5980 vty_out (vty, ", multipath");
5981
paul718e3742002-12-13 20:15:29 +00005982 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5983 vty_out (vty, ", best");
5984
5985 vty_out (vty, "%s", VTY_NEWLINE);
5986
5987 /* Line 4 display Community */
5988 if (attr->community)
5989 vty_out (vty, " Community: %s%s", attr->community->str,
5990 VTY_NEWLINE);
5991
5992 /* Line 5 display Extended-community */
5993 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00005994 vty_out (vty, " Extended Community: %s%s",
5995 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005996
5997 /* Line 6 display Originator, Cluster-id */
5998 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5999 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
6000 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006001 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00006002 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00006003 vty_out (vty, " Originator: %s",
6004 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006005
6006 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6007 {
6008 int i;
6009 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006010 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6011 vty_out (vty, "%s ",
6012 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006013 }
6014 vty_out (vty, "%s", VTY_NEWLINE);
6015 }
Paul Jakma41367172007-08-06 15:24:51 +00006016
Paul Jakmafb982c22007-05-04 20:15:47 +00006017 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006018 bgp_damp_info_vty (vty, binfo);
6019
6020 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006021#ifdef HAVE_CLOCK_MONOTONIC
6022 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006023 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006024#else
6025 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6026#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006027 }
6028 vty_out (vty, "%s", VTY_NEWLINE);
6029}
6030
paulb40d9392005-08-22 22:34:41 +00006031#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 +00006032#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006033#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6034#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6035#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6036
6037enum bgp_show_type
6038{
6039 bgp_show_type_normal,
6040 bgp_show_type_regexp,
6041 bgp_show_type_prefix_list,
6042 bgp_show_type_filter_list,
6043 bgp_show_type_route_map,
6044 bgp_show_type_neighbor,
6045 bgp_show_type_cidr_only,
6046 bgp_show_type_prefix_longer,
6047 bgp_show_type_community_all,
6048 bgp_show_type_community,
6049 bgp_show_type_community_exact,
6050 bgp_show_type_community_list,
6051 bgp_show_type_community_list_exact,
6052 bgp_show_type_flap_statistics,
6053 bgp_show_type_flap_address,
6054 bgp_show_type_flap_prefix,
6055 bgp_show_type_flap_cidr_only,
6056 bgp_show_type_flap_regexp,
6057 bgp_show_type_flap_filter_list,
6058 bgp_show_type_flap_prefix_list,
6059 bgp_show_type_flap_prefix_longer,
6060 bgp_show_type_flap_route_map,
6061 bgp_show_type_flap_neighbor,
6062 bgp_show_type_dampend_paths,
6063 bgp_show_type_damp_neighbor
6064};
6065
ajs5a646652004-11-05 01:25:55 +00006066static int
paulfee0f4c2004-09-13 05:12:46 +00006067bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006068 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006069{
paul718e3742002-12-13 20:15:29 +00006070 struct bgp_info *ri;
6071 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006072 int header = 1;
paul718e3742002-12-13 20:15:29 +00006073 int display;
ajs5a646652004-11-05 01:25:55 +00006074 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006075
6076 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006077 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006078
paul718e3742002-12-13 20:15:29 +00006079 /* Start processing of routes. */
6080 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6081 if (rn->info != NULL)
6082 {
6083 display = 0;
6084
6085 for (ri = rn->info; ri; ri = ri->next)
6086 {
ajs5a646652004-11-05 01:25:55 +00006087 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006088 || type == bgp_show_type_flap_address
6089 || type == bgp_show_type_flap_prefix
6090 || type == bgp_show_type_flap_cidr_only
6091 || type == bgp_show_type_flap_regexp
6092 || type == bgp_show_type_flap_filter_list
6093 || type == bgp_show_type_flap_prefix_list
6094 || type == bgp_show_type_flap_prefix_longer
6095 || type == bgp_show_type_flap_route_map
6096 || type == bgp_show_type_flap_neighbor
6097 || type == bgp_show_type_dampend_paths
6098 || type == bgp_show_type_damp_neighbor)
6099 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006100 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006101 continue;
6102 }
6103 if (type == bgp_show_type_regexp
6104 || type == bgp_show_type_flap_regexp)
6105 {
ajs5a646652004-11-05 01:25:55 +00006106 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006107
6108 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6109 continue;
6110 }
6111 if (type == bgp_show_type_prefix_list
6112 || type == bgp_show_type_flap_prefix_list)
6113 {
ajs5a646652004-11-05 01:25:55 +00006114 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006115
6116 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6117 continue;
6118 }
6119 if (type == bgp_show_type_filter_list
6120 || type == bgp_show_type_flap_filter_list)
6121 {
ajs5a646652004-11-05 01:25:55 +00006122 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006123
6124 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6125 continue;
6126 }
6127 if (type == bgp_show_type_route_map
6128 || type == bgp_show_type_flap_route_map)
6129 {
ajs5a646652004-11-05 01:25:55 +00006130 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006131 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006132 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006133 int ret;
6134
Paul Jakmafb982c22007-05-04 20:15:47 +00006135 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006136 binfo.peer = ri->peer;
6137 binfo.attr = &dummy_attr;
6138
6139 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006140
6141 bgp_attr_extra_free (&dummy_attr);
6142
paul718e3742002-12-13 20:15:29 +00006143 if (ret == RMAP_DENYMATCH)
6144 continue;
6145 }
6146 if (type == bgp_show_type_neighbor
6147 || type == bgp_show_type_flap_neighbor
6148 || type == bgp_show_type_damp_neighbor)
6149 {
ajs5a646652004-11-05 01:25:55 +00006150 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006151
6152 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6153 continue;
6154 }
6155 if (type == bgp_show_type_cidr_only
6156 || type == bgp_show_type_flap_cidr_only)
6157 {
6158 u_int32_t destination;
6159
6160 destination = ntohl (rn->p.u.prefix4.s_addr);
6161 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6162 continue;
6163 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6164 continue;
6165 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6166 continue;
6167 }
6168 if (type == bgp_show_type_prefix_longer
6169 || type == bgp_show_type_flap_prefix_longer)
6170 {
ajs5a646652004-11-05 01:25:55 +00006171 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006172
6173 if (! prefix_match (p, &rn->p))
6174 continue;
6175 }
6176 if (type == bgp_show_type_community_all)
6177 {
6178 if (! ri->attr->community)
6179 continue;
6180 }
6181 if (type == bgp_show_type_community)
6182 {
ajs5a646652004-11-05 01:25:55 +00006183 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006184
6185 if (! ri->attr->community ||
6186 ! community_match (ri->attr->community, com))
6187 continue;
6188 }
6189 if (type == bgp_show_type_community_exact)
6190 {
ajs5a646652004-11-05 01:25:55 +00006191 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006192
6193 if (! ri->attr->community ||
6194 ! community_cmp (ri->attr->community, com))
6195 continue;
6196 }
6197 if (type == bgp_show_type_community_list)
6198 {
ajs5a646652004-11-05 01:25:55 +00006199 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006200
6201 if (! community_list_match (ri->attr->community, list))
6202 continue;
6203 }
6204 if (type == bgp_show_type_community_list_exact)
6205 {
ajs5a646652004-11-05 01:25:55 +00006206 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006207
6208 if (! community_list_exact_match (ri->attr->community, list))
6209 continue;
6210 }
6211 if (type == bgp_show_type_flap_address
6212 || type == bgp_show_type_flap_prefix)
6213 {
ajs5a646652004-11-05 01:25:55 +00006214 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006215
6216 if (! prefix_match (&rn->p, p))
6217 continue;
6218
6219 if (type == bgp_show_type_flap_prefix)
6220 if (p->prefixlen != rn->p.prefixlen)
6221 continue;
6222 }
6223 if (type == bgp_show_type_dampend_paths
6224 || type == bgp_show_type_damp_neighbor)
6225 {
6226 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6227 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6228 continue;
6229 }
6230
6231 if (header)
6232 {
hasso93406d82005-02-02 14:40:33 +00006233 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6234 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6235 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006236 if (type == bgp_show_type_dampend_paths
6237 || type == bgp_show_type_damp_neighbor)
6238 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6239 else if (type == bgp_show_type_flap_statistics
6240 || type == bgp_show_type_flap_address
6241 || type == bgp_show_type_flap_prefix
6242 || type == bgp_show_type_flap_cidr_only
6243 || type == bgp_show_type_flap_regexp
6244 || type == bgp_show_type_flap_filter_list
6245 || type == bgp_show_type_flap_prefix_list
6246 || type == bgp_show_type_flap_prefix_longer
6247 || type == bgp_show_type_flap_route_map
6248 || type == bgp_show_type_flap_neighbor)
6249 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6250 else
6251 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006252 header = 0;
6253 }
6254
6255 if (type == bgp_show_type_dampend_paths
6256 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006257 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006258 else if (type == bgp_show_type_flap_statistics
6259 || type == bgp_show_type_flap_address
6260 || type == bgp_show_type_flap_prefix
6261 || type == bgp_show_type_flap_cidr_only
6262 || type == bgp_show_type_flap_regexp
6263 || type == bgp_show_type_flap_filter_list
6264 || type == bgp_show_type_flap_prefix_list
6265 || type == bgp_show_type_flap_prefix_longer
6266 || type == bgp_show_type_flap_route_map
6267 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006268 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006269 else
ajs5a646652004-11-05 01:25:55 +00006270 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006271 display++;
6272 }
6273 if (display)
ajs5a646652004-11-05 01:25:55 +00006274 output_count++;
paul718e3742002-12-13 20:15:29 +00006275 }
6276
6277 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006278 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006279 {
6280 if (type == bgp_show_type_normal)
6281 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6282 }
6283 else
6284 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006285 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006286
6287 return CMD_SUCCESS;
6288}
6289
ajs5a646652004-11-05 01:25:55 +00006290static int
paulfee0f4c2004-09-13 05:12:46 +00006291bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006292 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006293{
6294 struct bgp_table *table;
6295
6296 if (bgp == NULL) {
6297 bgp = bgp_get_default ();
6298 }
6299
6300 if (bgp == NULL)
6301 {
6302 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6303 return CMD_WARNING;
6304 }
6305
6306
6307 table = bgp->rib[afi][safi];
6308
ajs5a646652004-11-05 01:25:55 +00006309 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006310}
6311
paul718e3742002-12-13 20:15:29 +00006312/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006313static void
paul718e3742002-12-13 20:15:29 +00006314route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6315 struct bgp_node *rn,
6316 struct prefix_rd *prd, afi_t afi, safi_t safi)
6317{
6318 struct bgp_info *ri;
6319 struct prefix *p;
6320 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006321 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006322 char buf1[INET6_ADDRSTRLEN];
6323 char buf2[INET6_ADDRSTRLEN];
6324 int count = 0;
6325 int best = 0;
6326 int suppress = 0;
6327 int no_export = 0;
6328 int no_advertise = 0;
6329 int local_as = 0;
6330 int first = 0;
6331
6332 p = &rn->p;
6333 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6334 (safi == SAFI_MPLS_VPN ?
6335 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6336 safi == SAFI_MPLS_VPN ? ":" : "",
6337 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6338 p->prefixlen, VTY_NEWLINE);
6339
6340 for (ri = rn->info; ri; ri = ri->next)
6341 {
6342 count++;
6343 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6344 {
6345 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006346 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006347 suppress = 1;
6348 if (ri->attr->community != NULL)
6349 {
6350 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6351 no_advertise = 1;
6352 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6353 no_export = 1;
6354 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6355 local_as = 1;
6356 }
6357 }
6358 }
6359
6360 vty_out (vty, "Paths: (%d available", count);
6361 if (best)
6362 {
6363 vty_out (vty, ", best #%d", best);
6364 if (safi == SAFI_UNICAST)
6365 vty_out (vty, ", table Default-IP-Routing-Table");
6366 }
6367 else
6368 vty_out (vty, ", no best path");
6369 if (no_advertise)
6370 vty_out (vty, ", not advertised to any peer");
6371 else if (no_export)
6372 vty_out (vty, ", not advertised to EBGP peer");
6373 else if (local_as)
6374 vty_out (vty, ", not advertised outside local AS");
6375 if (suppress)
6376 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6377 vty_out (vty, ")%s", VTY_NEWLINE);
6378
6379 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006380 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006381 {
6382 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6383 {
6384 if (! first)
6385 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6386 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6387 first = 1;
6388 }
6389 }
6390 if (! first)
6391 vty_out (vty, " Not advertised to any peer");
6392 vty_out (vty, "%s", VTY_NEWLINE);
6393}
6394
6395/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006396static int
paulfee0f4c2004-09-13 05:12:46 +00006397bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006398 struct bgp_table *rib, const char *ip_str,
6399 afi_t afi, safi_t safi, struct prefix_rd *prd,
6400 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006401{
6402 int ret;
6403 int header;
6404 int display = 0;
6405 struct prefix match;
6406 struct bgp_node *rn;
6407 struct bgp_node *rm;
6408 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006409 struct bgp_table *table;
6410
paul718e3742002-12-13 20:15:29 +00006411 /* Check IP address argument. */
6412 ret = str2prefix (ip_str, &match);
6413 if (! ret)
6414 {
6415 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6416 return CMD_WARNING;
6417 }
6418
6419 match.family = afi2family (afi);
6420
6421 if (safi == SAFI_MPLS_VPN)
6422 {
paulfee0f4c2004-09-13 05:12:46 +00006423 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006424 {
6425 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6426 continue;
6427
6428 if ((table = rn->info) != NULL)
6429 {
6430 header = 1;
6431
6432 if ((rm = bgp_node_match (table, &match)) != NULL)
6433 {
6434 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006435 {
6436 bgp_unlock_node (rm);
6437 continue;
6438 }
paul718e3742002-12-13 20:15:29 +00006439
6440 for (ri = rm->info; ri; ri = ri->next)
6441 {
6442 if (header)
6443 {
6444 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6445 AFI_IP, SAFI_MPLS_VPN);
6446
6447 header = 0;
6448 }
6449 display++;
6450 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6451 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006452
6453 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006454 }
6455 }
6456 }
6457 }
6458 else
6459 {
6460 header = 1;
6461
paulfee0f4c2004-09-13 05:12:46 +00006462 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006463 {
6464 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6465 {
6466 for (ri = rn->info; ri; ri = ri->next)
6467 {
6468 if (header)
6469 {
6470 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6471 header = 0;
6472 }
6473 display++;
6474 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6475 }
6476 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006477
6478 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006479 }
6480 }
6481
6482 if (! display)
6483 {
6484 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6485 return CMD_WARNING;
6486 }
6487
6488 return CMD_SUCCESS;
6489}
6490
paulfee0f4c2004-09-13 05:12:46 +00006491/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006492static int
paulfd79ac92004-10-13 05:06:08 +00006493bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006494 afi_t afi, safi_t safi, struct prefix_rd *prd,
6495 int prefix_check)
6496{
6497 struct bgp *bgp;
6498
6499 /* BGP structure lookup. */
6500 if (view_name)
6501 {
6502 bgp = bgp_lookup_by_name (view_name);
6503 if (bgp == NULL)
6504 {
6505 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6506 return CMD_WARNING;
6507 }
6508 }
6509 else
6510 {
6511 bgp = bgp_get_default ();
6512 if (bgp == NULL)
6513 {
6514 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6515 return CMD_WARNING;
6516 }
6517 }
6518
6519 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6520 afi, safi, prd, prefix_check);
6521}
6522
paul718e3742002-12-13 20:15:29 +00006523/* BGP route print out function. */
6524DEFUN (show_ip_bgp,
6525 show_ip_bgp_cmd,
6526 "show ip bgp",
6527 SHOW_STR
6528 IP_STR
6529 BGP_STR)
6530{
ajs5a646652004-11-05 01:25:55 +00006531 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006532}
6533
6534DEFUN (show_ip_bgp_ipv4,
6535 show_ip_bgp_ipv4_cmd,
6536 "show ip bgp ipv4 (unicast|multicast)",
6537 SHOW_STR
6538 IP_STR
6539 BGP_STR
6540 "Address family\n"
6541 "Address Family modifier\n"
6542 "Address Family modifier\n")
6543{
6544 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006545 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6546 NULL);
paul718e3742002-12-13 20:15:29 +00006547
ajs5a646652004-11-05 01:25:55 +00006548 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006549}
6550
Michael Lambert95cbbd22010-07-23 14:43:04 -04006551ALIAS (show_ip_bgp_ipv4,
6552 show_bgp_ipv4_safi_cmd,
6553 "show bgp ipv4 (unicast|multicast)",
6554 SHOW_STR
6555 BGP_STR
6556 "Address family\n"
6557 "Address Family modifier\n"
6558 "Address Family modifier\n")
6559
paul718e3742002-12-13 20:15:29 +00006560DEFUN (show_ip_bgp_route,
6561 show_ip_bgp_route_cmd,
6562 "show ip bgp A.B.C.D",
6563 SHOW_STR
6564 IP_STR
6565 BGP_STR
6566 "Network in the BGP routing table to display\n")
6567{
6568 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6569}
6570
6571DEFUN (show_ip_bgp_ipv4_route,
6572 show_ip_bgp_ipv4_route_cmd,
6573 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6574 SHOW_STR
6575 IP_STR
6576 BGP_STR
6577 "Address family\n"
6578 "Address Family modifier\n"
6579 "Address Family modifier\n"
6580 "Network in the BGP routing table to display\n")
6581{
6582 if (strncmp (argv[0], "m", 1) == 0)
6583 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6584
6585 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6586}
6587
Michael Lambert95cbbd22010-07-23 14:43:04 -04006588ALIAS (show_ip_bgp_ipv4_route,
6589 show_bgp_ipv4_safi_route_cmd,
6590 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6591 SHOW_STR
6592 BGP_STR
6593 "Address family\n"
6594 "Address Family modifier\n"
6595 "Address Family modifier\n"
6596 "Network in the BGP routing table to display\n")
6597
paul718e3742002-12-13 20:15:29 +00006598DEFUN (show_ip_bgp_vpnv4_all_route,
6599 show_ip_bgp_vpnv4_all_route_cmd,
6600 "show ip bgp vpnv4 all A.B.C.D",
6601 SHOW_STR
6602 IP_STR
6603 BGP_STR
6604 "Display VPNv4 NLRI specific information\n"
6605 "Display information about all VPNv4 NLRIs\n"
6606 "Network in the BGP routing table to display\n")
6607{
6608 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6609}
6610
6611DEFUN (show_ip_bgp_vpnv4_rd_route,
6612 show_ip_bgp_vpnv4_rd_route_cmd,
6613 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6614 SHOW_STR
6615 IP_STR
6616 BGP_STR
6617 "Display VPNv4 NLRI specific information\n"
6618 "Display information for a route distinguisher\n"
6619 "VPN Route Distinguisher\n"
6620 "Network in the BGP routing table to display\n")
6621{
6622 int ret;
6623 struct prefix_rd prd;
6624
6625 ret = str2prefix_rd (argv[0], &prd);
6626 if (! ret)
6627 {
6628 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6629 return CMD_WARNING;
6630 }
6631 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6632}
6633
6634DEFUN (show_ip_bgp_prefix,
6635 show_ip_bgp_prefix_cmd,
6636 "show ip bgp A.B.C.D/M",
6637 SHOW_STR
6638 IP_STR
6639 BGP_STR
6640 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6641{
6642 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6643}
6644
6645DEFUN (show_ip_bgp_ipv4_prefix,
6646 show_ip_bgp_ipv4_prefix_cmd,
6647 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6648 SHOW_STR
6649 IP_STR
6650 BGP_STR
6651 "Address family\n"
6652 "Address Family modifier\n"
6653 "Address Family modifier\n"
6654 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6655{
6656 if (strncmp (argv[0], "m", 1) == 0)
6657 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6658
6659 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6660}
6661
Michael Lambert95cbbd22010-07-23 14:43:04 -04006662ALIAS (show_ip_bgp_ipv4_prefix,
6663 show_bgp_ipv4_safi_prefix_cmd,
6664 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6665 SHOW_STR
6666 BGP_STR
6667 "Address family\n"
6668 "Address Family modifier\n"
6669 "Address Family modifier\n"
6670 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6671
paul718e3742002-12-13 20:15:29 +00006672DEFUN (show_ip_bgp_vpnv4_all_prefix,
6673 show_ip_bgp_vpnv4_all_prefix_cmd,
6674 "show ip bgp vpnv4 all A.B.C.D/M",
6675 SHOW_STR
6676 IP_STR
6677 BGP_STR
6678 "Display VPNv4 NLRI specific information\n"
6679 "Display information about all VPNv4 NLRIs\n"
6680 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6681{
6682 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6683}
6684
6685DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6686 show_ip_bgp_vpnv4_rd_prefix_cmd,
6687 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6688 SHOW_STR
6689 IP_STR
6690 BGP_STR
6691 "Display VPNv4 NLRI specific information\n"
6692 "Display information for a route distinguisher\n"
6693 "VPN Route Distinguisher\n"
6694 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6695{
6696 int ret;
6697 struct prefix_rd prd;
6698
6699 ret = str2prefix_rd (argv[0], &prd);
6700 if (! ret)
6701 {
6702 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6703 return CMD_WARNING;
6704 }
6705 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6706}
6707
6708DEFUN (show_ip_bgp_view,
6709 show_ip_bgp_view_cmd,
6710 "show ip bgp view WORD",
6711 SHOW_STR
6712 IP_STR
6713 BGP_STR
6714 "BGP view\n"
6715 "BGP view name\n")
6716{
paulbb46e942003-10-24 19:02:03 +00006717 struct bgp *bgp;
6718
6719 /* BGP structure lookup. */
6720 bgp = bgp_lookup_by_name (argv[0]);
6721 if (bgp == NULL)
6722 {
6723 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6724 return CMD_WARNING;
6725 }
6726
ajs5a646652004-11-05 01:25:55 +00006727 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006728}
6729
6730DEFUN (show_ip_bgp_view_route,
6731 show_ip_bgp_view_route_cmd,
6732 "show ip bgp view WORD A.B.C.D",
6733 SHOW_STR
6734 IP_STR
6735 BGP_STR
6736 "BGP view\n"
6737 "BGP view name\n"
6738 "Network in the BGP routing table to display\n")
6739{
6740 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6741}
6742
6743DEFUN (show_ip_bgp_view_prefix,
6744 show_ip_bgp_view_prefix_cmd,
6745 "show ip bgp view WORD A.B.C.D/M",
6746 SHOW_STR
6747 IP_STR
6748 BGP_STR
6749 "BGP view\n"
6750 "BGP view name\n"
6751 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6752{
6753 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6754}
6755
6756#ifdef HAVE_IPV6
6757DEFUN (show_bgp,
6758 show_bgp_cmd,
6759 "show bgp",
6760 SHOW_STR
6761 BGP_STR)
6762{
ajs5a646652004-11-05 01:25:55 +00006763 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6764 NULL);
paul718e3742002-12-13 20:15:29 +00006765}
6766
6767ALIAS (show_bgp,
6768 show_bgp_ipv6_cmd,
6769 "show bgp ipv6",
6770 SHOW_STR
6771 BGP_STR
6772 "Address family\n")
6773
Michael Lambert95cbbd22010-07-23 14:43:04 -04006774DEFUN (show_bgp_ipv6_safi,
6775 show_bgp_ipv6_safi_cmd,
6776 "show bgp ipv6 (unicast|multicast)",
6777 SHOW_STR
6778 BGP_STR
6779 "Address family\n"
6780 "Address Family modifier\n"
6781 "Address Family modifier\n")
6782{
6783 if (strncmp (argv[0], "m", 1) == 0)
6784 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6785 NULL);
6786
6787 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6788}
6789
paul718e3742002-12-13 20:15:29 +00006790/* old command */
6791DEFUN (show_ipv6_bgp,
6792 show_ipv6_bgp_cmd,
6793 "show ipv6 bgp",
6794 SHOW_STR
6795 IP_STR
6796 BGP_STR)
6797{
ajs5a646652004-11-05 01:25:55 +00006798 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6799 NULL);
paul718e3742002-12-13 20:15:29 +00006800}
6801
6802DEFUN (show_bgp_route,
6803 show_bgp_route_cmd,
6804 "show bgp X:X::X:X",
6805 SHOW_STR
6806 BGP_STR
6807 "Network in the BGP routing table to display\n")
6808{
6809 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6810}
6811
6812ALIAS (show_bgp_route,
6813 show_bgp_ipv6_route_cmd,
6814 "show bgp ipv6 X:X::X:X",
6815 SHOW_STR
6816 BGP_STR
6817 "Address family\n"
6818 "Network in the BGP routing table to display\n")
6819
Michael Lambert95cbbd22010-07-23 14:43:04 -04006820DEFUN (show_bgp_ipv6_safi_route,
6821 show_bgp_ipv6_safi_route_cmd,
6822 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6823 SHOW_STR
6824 BGP_STR
6825 "Address family\n"
6826 "Address Family modifier\n"
6827 "Address Family modifier\n"
6828 "Network in the BGP routing table to display\n")
6829{
6830 if (strncmp (argv[0], "m", 1) == 0)
6831 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6832
6833 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6834}
6835
paul718e3742002-12-13 20:15:29 +00006836/* old command */
6837DEFUN (show_ipv6_bgp_route,
6838 show_ipv6_bgp_route_cmd,
6839 "show ipv6 bgp X:X::X:X",
6840 SHOW_STR
6841 IP_STR
6842 BGP_STR
6843 "Network in the BGP routing table to display\n")
6844{
6845 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6846}
6847
6848DEFUN (show_bgp_prefix,
6849 show_bgp_prefix_cmd,
6850 "show bgp X:X::X:X/M",
6851 SHOW_STR
6852 BGP_STR
6853 "IPv6 prefix <network>/<length>\n")
6854{
6855 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6856}
6857
6858ALIAS (show_bgp_prefix,
6859 show_bgp_ipv6_prefix_cmd,
6860 "show bgp ipv6 X:X::X:X/M",
6861 SHOW_STR
6862 BGP_STR
6863 "Address family\n"
6864 "IPv6 prefix <network>/<length>\n")
6865
Michael Lambert95cbbd22010-07-23 14:43:04 -04006866DEFUN (show_bgp_ipv6_safi_prefix,
6867 show_bgp_ipv6_safi_prefix_cmd,
6868 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6869 SHOW_STR
6870 BGP_STR
6871 "Address family\n"
6872 "Address Family modifier\n"
6873 "Address Family modifier\n"
6874 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6875{
6876 if (strncmp (argv[0], "m", 1) == 0)
6877 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6878
6879 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6880}
6881
paul718e3742002-12-13 20:15:29 +00006882/* old command */
6883DEFUN (show_ipv6_bgp_prefix,
6884 show_ipv6_bgp_prefix_cmd,
6885 "show ipv6 bgp X:X::X:X/M",
6886 SHOW_STR
6887 IP_STR
6888 BGP_STR
6889 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6890{
6891 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6892}
6893
paulbb46e942003-10-24 19:02:03 +00006894DEFUN (show_bgp_view,
6895 show_bgp_view_cmd,
6896 "show bgp view WORD",
6897 SHOW_STR
6898 BGP_STR
6899 "BGP view\n"
6900 "View name\n")
6901{
6902 struct bgp *bgp;
6903
6904 /* BGP structure lookup. */
6905 bgp = bgp_lookup_by_name (argv[0]);
6906 if (bgp == NULL)
6907 {
6908 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6909 return CMD_WARNING;
6910 }
6911
ajs5a646652004-11-05 01:25:55 +00006912 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006913}
6914
6915ALIAS (show_bgp_view,
6916 show_bgp_view_ipv6_cmd,
6917 "show bgp view WORD ipv6",
6918 SHOW_STR
6919 BGP_STR
6920 "BGP view\n"
6921 "View name\n"
6922 "Address family\n")
6923
6924DEFUN (show_bgp_view_route,
6925 show_bgp_view_route_cmd,
6926 "show bgp view WORD X:X::X:X",
6927 SHOW_STR
6928 BGP_STR
6929 "BGP view\n"
6930 "View name\n"
6931 "Network in the BGP routing table to display\n")
6932{
6933 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6934}
6935
6936ALIAS (show_bgp_view_route,
6937 show_bgp_view_ipv6_route_cmd,
6938 "show bgp view WORD ipv6 X:X::X:X",
6939 SHOW_STR
6940 BGP_STR
6941 "BGP view\n"
6942 "View name\n"
6943 "Address family\n"
6944 "Network in the BGP routing table to display\n")
6945
6946DEFUN (show_bgp_view_prefix,
6947 show_bgp_view_prefix_cmd,
6948 "show bgp view WORD X:X::X:X/M",
6949 SHOW_STR
6950 BGP_STR
6951 "BGP view\n"
6952 "View name\n"
6953 "IPv6 prefix <network>/<length>\n")
6954{
6955 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6956}
6957
6958ALIAS (show_bgp_view_prefix,
6959 show_bgp_view_ipv6_prefix_cmd,
6960 "show bgp view WORD ipv6 X:X::X:X/M",
6961 SHOW_STR
6962 BGP_STR
6963 "BGP view\n"
6964 "View name\n"
6965 "Address family\n"
6966 "IPv6 prefix <network>/<length>\n")
6967
paul718e3742002-12-13 20:15:29 +00006968/* old command */
6969DEFUN (show_ipv6_mbgp,
6970 show_ipv6_mbgp_cmd,
6971 "show ipv6 mbgp",
6972 SHOW_STR
6973 IP_STR
6974 MBGP_STR)
6975{
ajs5a646652004-11-05 01:25:55 +00006976 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6977 NULL);
paul718e3742002-12-13 20:15:29 +00006978}
6979
6980/* old command */
6981DEFUN (show_ipv6_mbgp_route,
6982 show_ipv6_mbgp_route_cmd,
6983 "show ipv6 mbgp X:X::X:X",
6984 SHOW_STR
6985 IP_STR
6986 MBGP_STR
6987 "Network in the MBGP routing table to display\n")
6988{
6989 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6990}
6991
6992/* old command */
6993DEFUN (show_ipv6_mbgp_prefix,
6994 show_ipv6_mbgp_prefix_cmd,
6995 "show ipv6 mbgp X:X::X:X/M",
6996 SHOW_STR
6997 IP_STR
6998 MBGP_STR
6999 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
7000{
7001 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
7002}
7003#endif
7004
paul718e3742002-12-13 20:15:29 +00007005
paul94f2b392005-06-28 12:44:16 +00007006static int
paulfd79ac92004-10-13 05:06:08 +00007007bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007008 safi_t safi, enum bgp_show_type type)
7009{
7010 int i;
7011 struct buffer *b;
7012 char *regstr;
7013 int first;
7014 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007015 int rc;
paul718e3742002-12-13 20:15:29 +00007016
7017 first = 0;
7018 b = buffer_new (1024);
7019 for (i = 0; i < argc; i++)
7020 {
7021 if (first)
7022 buffer_putc (b, ' ');
7023 else
7024 {
7025 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7026 continue;
7027 first = 1;
7028 }
7029
7030 buffer_putstr (b, argv[i]);
7031 }
7032 buffer_putc (b, '\0');
7033
7034 regstr = buffer_getstr (b);
7035 buffer_free (b);
7036
7037 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007038 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007039 if (! regex)
7040 {
7041 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7042 VTY_NEWLINE);
7043 return CMD_WARNING;
7044 }
7045
ajs5a646652004-11-05 01:25:55 +00007046 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7047 bgp_regex_free (regex);
7048 return rc;
paul718e3742002-12-13 20:15:29 +00007049}
7050
7051DEFUN (show_ip_bgp_regexp,
7052 show_ip_bgp_regexp_cmd,
7053 "show ip bgp regexp .LINE",
7054 SHOW_STR
7055 IP_STR
7056 BGP_STR
7057 "Display routes matching the AS path regular expression\n"
7058 "A regular-expression to match the BGP AS paths\n")
7059{
7060 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7061 bgp_show_type_regexp);
7062}
7063
7064DEFUN (show_ip_bgp_flap_regexp,
7065 show_ip_bgp_flap_regexp_cmd,
7066 "show ip bgp flap-statistics regexp .LINE",
7067 SHOW_STR
7068 IP_STR
7069 BGP_STR
7070 "Display flap statistics of routes\n"
7071 "Display routes matching the AS path regular expression\n"
7072 "A regular-expression to match the BGP AS paths\n")
7073{
7074 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7075 bgp_show_type_flap_regexp);
7076}
7077
7078DEFUN (show_ip_bgp_ipv4_regexp,
7079 show_ip_bgp_ipv4_regexp_cmd,
7080 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7081 SHOW_STR
7082 IP_STR
7083 BGP_STR
7084 "Address family\n"
7085 "Address Family modifier\n"
7086 "Address Family modifier\n"
7087 "Display routes matching the AS path regular expression\n"
7088 "A regular-expression to match the BGP AS paths\n")
7089{
7090 if (strncmp (argv[0], "m", 1) == 0)
7091 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7092 bgp_show_type_regexp);
7093
7094 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7095 bgp_show_type_regexp);
7096}
7097
7098#ifdef HAVE_IPV6
7099DEFUN (show_bgp_regexp,
7100 show_bgp_regexp_cmd,
7101 "show bgp regexp .LINE",
7102 SHOW_STR
7103 BGP_STR
7104 "Display routes matching the AS path regular expression\n"
7105 "A regular-expression to match the BGP AS paths\n")
7106{
7107 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7108 bgp_show_type_regexp);
7109}
7110
7111ALIAS (show_bgp_regexp,
7112 show_bgp_ipv6_regexp_cmd,
7113 "show bgp ipv6 regexp .LINE",
7114 SHOW_STR
7115 BGP_STR
7116 "Address family\n"
7117 "Display routes matching the AS path regular expression\n"
7118 "A regular-expression to match the BGP AS paths\n")
7119
7120/* old command */
7121DEFUN (show_ipv6_bgp_regexp,
7122 show_ipv6_bgp_regexp_cmd,
7123 "show ipv6 bgp regexp .LINE",
7124 SHOW_STR
7125 IP_STR
7126 BGP_STR
7127 "Display routes matching the AS path regular expression\n"
7128 "A regular-expression to match the BGP AS paths\n")
7129{
7130 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7131 bgp_show_type_regexp);
7132}
7133
7134/* old command */
7135DEFUN (show_ipv6_mbgp_regexp,
7136 show_ipv6_mbgp_regexp_cmd,
7137 "show ipv6 mbgp regexp .LINE",
7138 SHOW_STR
7139 IP_STR
7140 BGP_STR
7141 "Display routes matching the AS path regular expression\n"
7142 "A regular-expression to match the MBGP AS paths\n")
7143{
7144 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7145 bgp_show_type_regexp);
7146}
7147#endif /* HAVE_IPV6 */
7148
paul94f2b392005-06-28 12:44:16 +00007149static int
paulfd79ac92004-10-13 05:06:08 +00007150bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007151 safi_t safi, enum bgp_show_type type)
7152{
7153 struct prefix_list *plist;
7154
7155 plist = prefix_list_lookup (afi, prefix_list_str);
7156 if (plist == NULL)
7157 {
7158 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7159 prefix_list_str, VTY_NEWLINE);
7160 return CMD_WARNING;
7161 }
7162
ajs5a646652004-11-05 01:25:55 +00007163 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007164}
7165
7166DEFUN (show_ip_bgp_prefix_list,
7167 show_ip_bgp_prefix_list_cmd,
7168 "show ip bgp prefix-list WORD",
7169 SHOW_STR
7170 IP_STR
7171 BGP_STR
7172 "Display routes conforming to the prefix-list\n"
7173 "IP prefix-list name\n")
7174{
7175 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7176 bgp_show_type_prefix_list);
7177}
7178
7179DEFUN (show_ip_bgp_flap_prefix_list,
7180 show_ip_bgp_flap_prefix_list_cmd,
7181 "show ip bgp flap-statistics prefix-list WORD",
7182 SHOW_STR
7183 IP_STR
7184 BGP_STR
7185 "Display flap statistics of routes\n"
7186 "Display routes conforming to the prefix-list\n"
7187 "IP prefix-list name\n")
7188{
7189 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7190 bgp_show_type_flap_prefix_list);
7191}
7192
7193DEFUN (show_ip_bgp_ipv4_prefix_list,
7194 show_ip_bgp_ipv4_prefix_list_cmd,
7195 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7196 SHOW_STR
7197 IP_STR
7198 BGP_STR
7199 "Address family\n"
7200 "Address Family modifier\n"
7201 "Address Family modifier\n"
7202 "Display routes conforming to the prefix-list\n"
7203 "IP prefix-list name\n")
7204{
7205 if (strncmp (argv[0], "m", 1) == 0)
7206 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7207 bgp_show_type_prefix_list);
7208
7209 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7210 bgp_show_type_prefix_list);
7211}
7212
7213#ifdef HAVE_IPV6
7214DEFUN (show_bgp_prefix_list,
7215 show_bgp_prefix_list_cmd,
7216 "show bgp prefix-list WORD",
7217 SHOW_STR
7218 BGP_STR
7219 "Display routes conforming to the prefix-list\n"
7220 "IPv6 prefix-list name\n")
7221{
7222 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7223 bgp_show_type_prefix_list);
7224}
7225
7226ALIAS (show_bgp_prefix_list,
7227 show_bgp_ipv6_prefix_list_cmd,
7228 "show bgp ipv6 prefix-list WORD",
7229 SHOW_STR
7230 BGP_STR
7231 "Address family\n"
7232 "Display routes conforming to the prefix-list\n"
7233 "IPv6 prefix-list name\n")
7234
7235/* old command */
7236DEFUN (show_ipv6_bgp_prefix_list,
7237 show_ipv6_bgp_prefix_list_cmd,
7238 "show ipv6 bgp prefix-list WORD",
7239 SHOW_STR
7240 IPV6_STR
7241 BGP_STR
7242 "Display routes matching the prefix-list\n"
7243 "IPv6 prefix-list name\n")
7244{
7245 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7246 bgp_show_type_prefix_list);
7247}
7248
7249/* old command */
7250DEFUN (show_ipv6_mbgp_prefix_list,
7251 show_ipv6_mbgp_prefix_list_cmd,
7252 "show ipv6 mbgp prefix-list WORD",
7253 SHOW_STR
7254 IPV6_STR
7255 MBGP_STR
7256 "Display routes matching the prefix-list\n"
7257 "IPv6 prefix-list name\n")
7258{
7259 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7260 bgp_show_type_prefix_list);
7261}
7262#endif /* HAVE_IPV6 */
7263
paul94f2b392005-06-28 12:44:16 +00007264static int
paulfd79ac92004-10-13 05:06:08 +00007265bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007266 safi_t safi, enum bgp_show_type type)
7267{
7268 struct as_list *as_list;
7269
7270 as_list = as_list_lookup (filter);
7271 if (as_list == NULL)
7272 {
7273 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7274 return CMD_WARNING;
7275 }
7276
ajs5a646652004-11-05 01:25:55 +00007277 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007278}
7279
7280DEFUN (show_ip_bgp_filter_list,
7281 show_ip_bgp_filter_list_cmd,
7282 "show ip bgp filter-list WORD",
7283 SHOW_STR
7284 IP_STR
7285 BGP_STR
7286 "Display routes conforming to the filter-list\n"
7287 "Regular expression access list name\n")
7288{
7289 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7290 bgp_show_type_filter_list);
7291}
7292
7293DEFUN (show_ip_bgp_flap_filter_list,
7294 show_ip_bgp_flap_filter_list_cmd,
7295 "show ip bgp flap-statistics filter-list WORD",
7296 SHOW_STR
7297 IP_STR
7298 BGP_STR
7299 "Display flap statistics of routes\n"
7300 "Display routes conforming to the filter-list\n"
7301 "Regular expression access list name\n")
7302{
7303 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7304 bgp_show_type_flap_filter_list);
7305}
7306
7307DEFUN (show_ip_bgp_ipv4_filter_list,
7308 show_ip_bgp_ipv4_filter_list_cmd,
7309 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7310 SHOW_STR
7311 IP_STR
7312 BGP_STR
7313 "Address family\n"
7314 "Address Family modifier\n"
7315 "Address Family modifier\n"
7316 "Display routes conforming to the filter-list\n"
7317 "Regular expression access list name\n")
7318{
7319 if (strncmp (argv[0], "m", 1) == 0)
7320 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7321 bgp_show_type_filter_list);
7322
7323 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7324 bgp_show_type_filter_list);
7325}
7326
7327#ifdef HAVE_IPV6
7328DEFUN (show_bgp_filter_list,
7329 show_bgp_filter_list_cmd,
7330 "show bgp filter-list WORD",
7331 SHOW_STR
7332 BGP_STR
7333 "Display routes conforming to the filter-list\n"
7334 "Regular expression access list name\n")
7335{
7336 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7337 bgp_show_type_filter_list);
7338}
7339
7340ALIAS (show_bgp_filter_list,
7341 show_bgp_ipv6_filter_list_cmd,
7342 "show bgp ipv6 filter-list WORD",
7343 SHOW_STR
7344 BGP_STR
7345 "Address family\n"
7346 "Display routes conforming to the filter-list\n"
7347 "Regular expression access list name\n")
7348
7349/* old command */
7350DEFUN (show_ipv6_bgp_filter_list,
7351 show_ipv6_bgp_filter_list_cmd,
7352 "show ipv6 bgp filter-list WORD",
7353 SHOW_STR
7354 IPV6_STR
7355 BGP_STR
7356 "Display routes conforming to the filter-list\n"
7357 "Regular expression access list name\n")
7358{
7359 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7360 bgp_show_type_filter_list);
7361}
7362
7363/* old command */
7364DEFUN (show_ipv6_mbgp_filter_list,
7365 show_ipv6_mbgp_filter_list_cmd,
7366 "show ipv6 mbgp filter-list WORD",
7367 SHOW_STR
7368 IPV6_STR
7369 MBGP_STR
7370 "Display routes conforming to the filter-list\n"
7371 "Regular expression access list name\n")
7372{
7373 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7374 bgp_show_type_filter_list);
7375}
7376#endif /* HAVE_IPV6 */
7377
paul94f2b392005-06-28 12:44:16 +00007378static int
paulfd79ac92004-10-13 05:06:08 +00007379bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007380 safi_t safi, enum bgp_show_type type)
7381{
7382 struct route_map *rmap;
7383
7384 rmap = route_map_lookup_by_name (rmap_str);
7385 if (! rmap)
7386 {
7387 vty_out (vty, "%% %s is not a valid route-map name%s",
7388 rmap_str, VTY_NEWLINE);
7389 return CMD_WARNING;
7390 }
7391
ajs5a646652004-11-05 01:25:55 +00007392 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007393}
7394
7395DEFUN (show_ip_bgp_route_map,
7396 show_ip_bgp_route_map_cmd,
7397 "show ip bgp route-map WORD",
7398 SHOW_STR
7399 IP_STR
7400 BGP_STR
7401 "Display routes matching the route-map\n"
7402 "A route-map to match on\n")
7403{
7404 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7405 bgp_show_type_route_map);
7406}
7407
7408DEFUN (show_ip_bgp_flap_route_map,
7409 show_ip_bgp_flap_route_map_cmd,
7410 "show ip bgp flap-statistics route-map WORD",
7411 SHOW_STR
7412 IP_STR
7413 BGP_STR
7414 "Display flap statistics of routes\n"
7415 "Display routes matching the route-map\n"
7416 "A route-map to match on\n")
7417{
7418 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7419 bgp_show_type_flap_route_map);
7420}
7421
7422DEFUN (show_ip_bgp_ipv4_route_map,
7423 show_ip_bgp_ipv4_route_map_cmd,
7424 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7425 SHOW_STR
7426 IP_STR
7427 BGP_STR
7428 "Address family\n"
7429 "Address Family modifier\n"
7430 "Address Family modifier\n"
7431 "Display routes matching the route-map\n"
7432 "A route-map to match on\n")
7433{
7434 if (strncmp (argv[0], "m", 1) == 0)
7435 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7436 bgp_show_type_route_map);
7437
7438 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7439 bgp_show_type_route_map);
7440}
7441
7442DEFUN (show_bgp_route_map,
7443 show_bgp_route_map_cmd,
7444 "show bgp route-map WORD",
7445 SHOW_STR
7446 BGP_STR
7447 "Display routes matching the route-map\n"
7448 "A route-map to match on\n")
7449{
7450 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7451 bgp_show_type_route_map);
7452}
7453
7454ALIAS (show_bgp_route_map,
7455 show_bgp_ipv6_route_map_cmd,
7456 "show bgp ipv6 route-map WORD",
7457 SHOW_STR
7458 BGP_STR
7459 "Address family\n"
7460 "Display routes matching the route-map\n"
7461 "A route-map to match on\n")
7462
7463DEFUN (show_ip_bgp_cidr_only,
7464 show_ip_bgp_cidr_only_cmd,
7465 "show ip bgp cidr-only",
7466 SHOW_STR
7467 IP_STR
7468 BGP_STR
7469 "Display only routes with non-natural netmasks\n")
7470{
7471 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007472 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007473}
7474
7475DEFUN (show_ip_bgp_flap_cidr_only,
7476 show_ip_bgp_flap_cidr_only_cmd,
7477 "show ip bgp flap-statistics cidr-only",
7478 SHOW_STR
7479 IP_STR
7480 BGP_STR
7481 "Display flap statistics of routes\n"
7482 "Display only routes with non-natural netmasks\n")
7483{
7484 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007485 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007486}
7487
7488DEFUN (show_ip_bgp_ipv4_cidr_only,
7489 show_ip_bgp_ipv4_cidr_only_cmd,
7490 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7491 SHOW_STR
7492 IP_STR
7493 BGP_STR
7494 "Address family\n"
7495 "Address Family modifier\n"
7496 "Address Family modifier\n"
7497 "Display only routes with non-natural netmasks\n")
7498{
7499 if (strncmp (argv[0], "m", 1) == 0)
7500 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007501 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007502
7503 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007504 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007505}
7506
7507DEFUN (show_ip_bgp_community_all,
7508 show_ip_bgp_community_all_cmd,
7509 "show ip bgp community",
7510 SHOW_STR
7511 IP_STR
7512 BGP_STR
7513 "Display routes matching the communities\n")
7514{
7515 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007516 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007517}
7518
7519DEFUN (show_ip_bgp_ipv4_community_all,
7520 show_ip_bgp_ipv4_community_all_cmd,
7521 "show ip bgp ipv4 (unicast|multicast) community",
7522 SHOW_STR
7523 IP_STR
7524 BGP_STR
7525 "Address family\n"
7526 "Address Family modifier\n"
7527 "Address Family modifier\n"
7528 "Display routes matching the communities\n")
7529{
7530 if (strncmp (argv[0], "m", 1) == 0)
7531 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007532 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007533
7534 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007535 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007536}
7537
7538#ifdef HAVE_IPV6
7539DEFUN (show_bgp_community_all,
7540 show_bgp_community_all_cmd,
7541 "show bgp community",
7542 SHOW_STR
7543 BGP_STR
7544 "Display routes matching the communities\n")
7545{
7546 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007547 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007548}
7549
7550ALIAS (show_bgp_community_all,
7551 show_bgp_ipv6_community_all_cmd,
7552 "show bgp ipv6 community",
7553 SHOW_STR
7554 BGP_STR
7555 "Address family\n"
7556 "Display routes matching the communities\n")
7557
7558/* old command */
7559DEFUN (show_ipv6_bgp_community_all,
7560 show_ipv6_bgp_community_all_cmd,
7561 "show ipv6 bgp community",
7562 SHOW_STR
7563 IPV6_STR
7564 BGP_STR
7565 "Display routes matching the communities\n")
7566{
7567 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007568 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007569}
7570
7571/* old command */
7572DEFUN (show_ipv6_mbgp_community_all,
7573 show_ipv6_mbgp_community_all_cmd,
7574 "show ipv6 mbgp community",
7575 SHOW_STR
7576 IPV6_STR
7577 MBGP_STR
7578 "Display routes matching the communities\n")
7579{
7580 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007581 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007582}
7583#endif /* HAVE_IPV6 */
7584
paul94f2b392005-06-28 12:44:16 +00007585static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007586bgp_show_community (struct vty *vty, const char *view_name, int argc,
7587 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007588{
7589 struct community *com;
7590 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007591 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007592 int i;
7593 char *str;
7594 int first = 0;
7595
Michael Lambert95cbbd22010-07-23 14:43:04 -04007596 /* BGP structure lookup */
7597 if (view_name)
7598 {
7599 bgp = bgp_lookup_by_name (view_name);
7600 if (bgp == NULL)
7601 {
7602 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7603 return CMD_WARNING;
7604 }
7605 }
7606 else
7607 {
7608 bgp = bgp_get_default ();
7609 if (bgp == NULL)
7610 {
7611 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7612 return CMD_WARNING;
7613 }
7614 }
7615
paul718e3742002-12-13 20:15:29 +00007616 b = buffer_new (1024);
7617 for (i = 0; i < argc; i++)
7618 {
7619 if (first)
7620 buffer_putc (b, ' ');
7621 else
7622 {
7623 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7624 continue;
7625 first = 1;
7626 }
7627
7628 buffer_putstr (b, argv[i]);
7629 }
7630 buffer_putc (b, '\0');
7631
7632 str = buffer_getstr (b);
7633 buffer_free (b);
7634
7635 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007636 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007637 if (! com)
7638 {
7639 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7640 return CMD_WARNING;
7641 }
7642
Michael Lambert95cbbd22010-07-23 14:43:04 -04007643 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007644 (exact ? bgp_show_type_community_exact :
7645 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007646}
7647
7648DEFUN (show_ip_bgp_community,
7649 show_ip_bgp_community_cmd,
7650 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7651 SHOW_STR
7652 IP_STR
7653 BGP_STR
7654 "Display routes matching the communities\n"
7655 "community number\n"
7656 "Do not send outside local AS (well-known community)\n"
7657 "Do not advertise to any peer (well-known community)\n"
7658 "Do not export to next AS (well-known community)\n")
7659{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007660 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007661}
7662
7663ALIAS (show_ip_bgp_community,
7664 show_ip_bgp_community2_cmd,
7665 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7666 SHOW_STR
7667 IP_STR
7668 BGP_STR
7669 "Display routes matching the communities\n"
7670 "community number\n"
7671 "Do not send outside local AS (well-known community)\n"
7672 "Do not advertise to any peer (well-known community)\n"
7673 "Do not export to next AS (well-known community)\n"
7674 "community number\n"
7675 "Do not send outside local AS (well-known community)\n"
7676 "Do not advertise to any peer (well-known community)\n"
7677 "Do not export to next AS (well-known community)\n")
7678
7679ALIAS (show_ip_bgp_community,
7680 show_ip_bgp_community3_cmd,
7681 "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)",
7682 SHOW_STR
7683 IP_STR
7684 BGP_STR
7685 "Display routes matching the communities\n"
7686 "community number\n"
7687 "Do not send outside local AS (well-known community)\n"
7688 "Do not advertise to any peer (well-known community)\n"
7689 "Do not export to next AS (well-known community)\n"
7690 "community number\n"
7691 "Do not send outside local AS (well-known community)\n"
7692 "Do not advertise to any peer (well-known community)\n"
7693 "Do not export to next AS (well-known community)\n"
7694 "community number\n"
7695 "Do not send outside local AS (well-known community)\n"
7696 "Do not advertise to any peer (well-known community)\n"
7697 "Do not export to next AS (well-known community)\n")
7698
7699ALIAS (show_ip_bgp_community,
7700 show_ip_bgp_community4_cmd,
7701 "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)",
7702 SHOW_STR
7703 IP_STR
7704 BGP_STR
7705 "Display routes matching the communities\n"
7706 "community number\n"
7707 "Do not send outside local AS (well-known community)\n"
7708 "Do not advertise to any peer (well-known community)\n"
7709 "Do not export to next AS (well-known community)\n"
7710 "community number\n"
7711 "Do not send outside local AS (well-known community)\n"
7712 "Do not advertise to any peer (well-known community)\n"
7713 "Do not export to next AS (well-known community)\n"
7714 "community number\n"
7715 "Do not send outside local AS (well-known community)\n"
7716 "Do not advertise to any peer (well-known community)\n"
7717 "Do not export to next AS (well-known community)\n"
7718 "community number\n"
7719 "Do not send outside local AS (well-known community)\n"
7720 "Do not advertise to any peer (well-known community)\n"
7721 "Do not export to next AS (well-known community)\n")
7722
7723DEFUN (show_ip_bgp_ipv4_community,
7724 show_ip_bgp_ipv4_community_cmd,
7725 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7726 SHOW_STR
7727 IP_STR
7728 BGP_STR
7729 "Address family\n"
7730 "Address Family modifier\n"
7731 "Address Family modifier\n"
7732 "Display routes matching the communities\n"
7733 "community number\n"
7734 "Do not send outside local AS (well-known community)\n"
7735 "Do not advertise to any peer (well-known community)\n"
7736 "Do not export to next AS (well-known community)\n")
7737{
7738 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007739 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007740
Michael Lambert95cbbd22010-07-23 14:43:04 -04007741 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007742}
7743
7744ALIAS (show_ip_bgp_ipv4_community,
7745 show_ip_bgp_ipv4_community2_cmd,
7746 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7747 SHOW_STR
7748 IP_STR
7749 BGP_STR
7750 "Address family\n"
7751 "Address Family modifier\n"
7752 "Address Family modifier\n"
7753 "Display routes matching the communities\n"
7754 "community number\n"
7755 "Do not send outside local AS (well-known community)\n"
7756 "Do not advertise to any peer (well-known community)\n"
7757 "Do not export to next AS (well-known community)\n"
7758 "community number\n"
7759 "Do not send outside local AS (well-known community)\n"
7760 "Do not advertise to any peer (well-known community)\n"
7761 "Do not export to next AS (well-known community)\n")
7762
7763ALIAS (show_ip_bgp_ipv4_community,
7764 show_ip_bgp_ipv4_community3_cmd,
7765 "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)",
7766 SHOW_STR
7767 IP_STR
7768 BGP_STR
7769 "Address family\n"
7770 "Address Family modifier\n"
7771 "Address Family modifier\n"
7772 "Display routes matching the communities\n"
7773 "community number\n"
7774 "Do not send outside local AS (well-known community)\n"
7775 "Do not advertise to any peer (well-known community)\n"
7776 "Do not export to next AS (well-known community)\n"
7777 "community number\n"
7778 "Do not send outside local AS (well-known community)\n"
7779 "Do not advertise to any peer (well-known community)\n"
7780 "Do not export to next AS (well-known community)\n"
7781 "community number\n"
7782 "Do not send outside local AS (well-known community)\n"
7783 "Do not advertise to any peer (well-known community)\n"
7784 "Do not export to next AS (well-known community)\n")
7785
7786ALIAS (show_ip_bgp_ipv4_community,
7787 show_ip_bgp_ipv4_community4_cmd,
7788 "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)",
7789 SHOW_STR
7790 IP_STR
7791 BGP_STR
7792 "Address family\n"
7793 "Address Family modifier\n"
7794 "Address Family modifier\n"
7795 "Display routes matching the communities\n"
7796 "community number\n"
7797 "Do not send outside local AS (well-known community)\n"
7798 "Do not advertise to any peer (well-known community)\n"
7799 "Do not export to next AS (well-known community)\n"
7800 "community number\n"
7801 "Do not send outside local AS (well-known community)\n"
7802 "Do not advertise to any peer (well-known community)\n"
7803 "Do not export to next AS (well-known community)\n"
7804 "community number\n"
7805 "Do not send outside local AS (well-known community)\n"
7806 "Do not advertise to any peer (well-known community)\n"
7807 "Do not export to next AS (well-known community)\n"
7808 "community number\n"
7809 "Do not send outside local AS (well-known community)\n"
7810 "Do not advertise to any peer (well-known community)\n"
7811 "Do not export to next AS (well-known community)\n")
7812
Michael Lambert95cbbd22010-07-23 14:43:04 -04007813DEFUN (show_bgp_view_afi_safi_community_all,
7814 show_bgp_view_afi_safi_community_all_cmd,
7815#ifdef HAVE_IPV6
7816 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7817#else
7818 "show bgp view WORD ipv4 (unicast|multicast) community",
7819#endif
7820 SHOW_STR
7821 BGP_STR
7822 "BGP view\n"
7823 "BGP view name\n"
7824 "Address family\n"
7825#ifdef HAVE_IPV6
7826 "Address family\n"
7827#endif
7828 "Address Family modifier\n"
7829 "Address Family modifier\n"
7830 "Display routes containing communities\n")
7831{
7832 int afi;
7833 int safi;
7834 struct bgp *bgp;
7835
7836 /* BGP structure lookup. */
7837 bgp = bgp_lookup_by_name (argv[0]);
7838 if (bgp == NULL)
7839 {
7840 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7841 return CMD_WARNING;
7842 }
7843
7844#ifdef HAVE_IPV6
7845 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7846 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7847#else
7848 afi = AFI_IP;
7849 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7850#endif
7851 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7852}
7853
7854DEFUN (show_bgp_view_afi_safi_community,
7855 show_bgp_view_afi_safi_community_cmd,
7856#ifdef HAVE_IPV6
7857 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7858#else
7859 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7860#endif
7861 SHOW_STR
7862 BGP_STR
7863 "BGP view\n"
7864 "BGP view name\n"
7865 "Address family\n"
7866#ifdef HAVE_IPV6
7867 "Address family\n"
7868#endif
7869 "Address family modifier\n"
7870 "Address family modifier\n"
7871 "Display routes matching the communities\n"
7872 "community number\n"
7873 "Do not send outside local AS (well-known community)\n"
7874 "Do not advertise to any peer (well-known community)\n"
7875 "Do not export to next AS (well-known community)\n")
7876{
7877 int afi;
7878 int safi;
7879
7880#ifdef HAVE_IPV6
7881 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7882 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7883 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7884#else
7885 afi = AFI_IP;
7886 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7887 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7888#endif
7889}
7890
7891ALIAS (show_bgp_view_afi_safi_community,
7892 show_bgp_view_afi_safi_community2_cmd,
7893#ifdef HAVE_IPV6
7894 "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)",
7895#else
7896 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7897#endif
7898 SHOW_STR
7899 BGP_STR
7900 "BGP view\n"
7901 "BGP view name\n"
7902 "Address family\n"
7903#ifdef HAVE_IPV6
7904 "Address family\n"
7905#endif
7906 "Address family modifier\n"
7907 "Address family modifier\n"
7908 "Display routes matching the communities\n"
7909 "community number\n"
7910 "Do not send outside local AS (well-known community)\n"
7911 "Do not advertise to any peer (well-known community)\n"
7912 "Do not export to next AS (well-known community)\n"
7913 "community number\n"
7914 "Do not send outside local AS (well-known community)\n"
7915 "Do not advertise to any peer (well-known community)\n"
7916 "Do not export to next AS (well-known community)\n")
7917
7918ALIAS (show_bgp_view_afi_safi_community,
7919 show_bgp_view_afi_safi_community3_cmd,
7920#ifdef HAVE_IPV6
7921 "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)",
7922#else
7923 "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)",
7924#endif
7925 SHOW_STR
7926 BGP_STR
7927 "BGP view\n"
7928 "BGP view name\n"
7929 "Address family\n"
7930#ifdef HAVE_IPV6
7931 "Address family\n"
7932#endif
7933 "Address family modifier\n"
7934 "Address family modifier\n"
7935 "Display routes matching the communities\n"
7936 "community number\n"
7937 "Do not send outside local AS (well-known community)\n"
7938 "Do not advertise to any peer (well-known community)\n"
7939 "Do not export to next AS (well-known community)\n"
7940 "community number\n"
7941 "Do not send outside local AS (well-known community)\n"
7942 "Do not advertise to any peer (well-known community)\n"
7943 "Do not export to next AS (well-known community)\n"
7944 "community number\n"
7945 "Do not send outside local AS (well-known community)\n"
7946 "Do not advertise to any peer (well-known community)\n"
7947 "Do not export to next AS (well-known community)\n")
7948
7949ALIAS (show_bgp_view_afi_safi_community,
7950 show_bgp_view_afi_safi_community4_cmd,
7951#ifdef HAVE_IPV6
7952 "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)",
7953#else
7954 "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)",
7955#endif
7956 SHOW_STR
7957 BGP_STR
7958 "BGP view\n"
7959 "BGP view name\n"
7960 "Address family\n"
7961#ifdef HAVE_IPV6
7962 "Address family\n"
7963#endif
7964 "Address family modifier\n"
7965 "Address family modifier\n"
7966 "Display routes matching the communities\n"
7967 "community number\n"
7968 "Do not send outside local AS (well-known community)\n"
7969 "Do not advertise to any peer (well-known community)\n"
7970 "Do not export to next AS (well-known community)\n"
7971 "community number\n"
7972 "Do not send outside local AS (well-known community)\n"
7973 "Do not advertise to any peer (well-known community)\n"
7974 "Do not export to next AS (well-known community)\n"
7975 "community number\n"
7976 "Do not send outside local AS (well-known community)\n"
7977 "Do not advertise to any peer (well-known community)\n"
7978 "Do not export to next AS (well-known community)\n"
7979 "community number\n"
7980 "Do not send outside local AS (well-known community)\n"
7981 "Do not advertise to any peer (well-known community)\n"
7982 "Do not export to next AS (well-known community)\n")
7983
paul718e3742002-12-13 20:15:29 +00007984DEFUN (show_ip_bgp_community_exact,
7985 show_ip_bgp_community_exact_cmd,
7986 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7987 SHOW_STR
7988 IP_STR
7989 BGP_STR
7990 "Display routes matching the communities\n"
7991 "community number\n"
7992 "Do not send outside local AS (well-known community)\n"
7993 "Do not advertise to any peer (well-known community)\n"
7994 "Do not export to next AS (well-known community)\n"
7995 "Exact match of the communities")
7996{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007997 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007998}
7999
8000ALIAS (show_ip_bgp_community_exact,
8001 show_ip_bgp_community2_exact_cmd,
8002 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8003 SHOW_STR
8004 IP_STR
8005 BGP_STR
8006 "Display routes matching the communities\n"
8007 "community number\n"
8008 "Do not send outside local AS (well-known community)\n"
8009 "Do not advertise to any peer (well-known community)\n"
8010 "Do not export to next AS (well-known community)\n"
8011 "community number\n"
8012 "Do not send outside local AS (well-known community)\n"
8013 "Do not advertise to any peer (well-known community)\n"
8014 "Do not export to next AS (well-known community)\n"
8015 "Exact match of the communities")
8016
8017ALIAS (show_ip_bgp_community_exact,
8018 show_ip_bgp_community3_exact_cmd,
8019 "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",
8020 SHOW_STR
8021 IP_STR
8022 BGP_STR
8023 "Display routes matching the communities\n"
8024 "community number\n"
8025 "Do not send outside local AS (well-known community)\n"
8026 "Do not advertise to any peer (well-known community)\n"
8027 "Do not export to next AS (well-known community)\n"
8028 "community number\n"
8029 "Do not send outside local AS (well-known community)\n"
8030 "Do not advertise to any peer (well-known community)\n"
8031 "Do not export to next AS (well-known community)\n"
8032 "community number\n"
8033 "Do not send outside local AS (well-known community)\n"
8034 "Do not advertise to any peer (well-known community)\n"
8035 "Do not export to next AS (well-known community)\n"
8036 "Exact match of the communities")
8037
8038ALIAS (show_ip_bgp_community_exact,
8039 show_ip_bgp_community4_exact_cmd,
8040 "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",
8041 SHOW_STR
8042 IP_STR
8043 BGP_STR
8044 "Display routes matching the communities\n"
8045 "community number\n"
8046 "Do not send outside local AS (well-known community)\n"
8047 "Do not advertise to any peer (well-known community)\n"
8048 "Do not export to next AS (well-known community)\n"
8049 "community number\n"
8050 "Do not send outside local AS (well-known community)\n"
8051 "Do not advertise to any peer (well-known community)\n"
8052 "Do not export to next AS (well-known community)\n"
8053 "community number\n"
8054 "Do not send outside local AS (well-known community)\n"
8055 "Do not advertise to any peer (well-known community)\n"
8056 "Do not export to next AS (well-known community)\n"
8057 "community number\n"
8058 "Do not send outside local AS (well-known community)\n"
8059 "Do not advertise to any peer (well-known community)\n"
8060 "Do not export to next AS (well-known community)\n"
8061 "Exact match of the communities")
8062
8063DEFUN (show_ip_bgp_ipv4_community_exact,
8064 show_ip_bgp_ipv4_community_exact_cmd,
8065 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8066 SHOW_STR
8067 IP_STR
8068 BGP_STR
8069 "Address family\n"
8070 "Address Family modifier\n"
8071 "Address Family modifier\n"
8072 "Display routes matching the communities\n"
8073 "community number\n"
8074 "Do not send outside local AS (well-known community)\n"
8075 "Do not advertise to any peer (well-known community)\n"
8076 "Do not export to next AS (well-known community)\n"
8077 "Exact match of the communities")
8078{
8079 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008080 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008081
Michael Lambert95cbbd22010-07-23 14:43:04 -04008082 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008083}
8084
8085ALIAS (show_ip_bgp_ipv4_community_exact,
8086 show_ip_bgp_ipv4_community2_exact_cmd,
8087 "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",
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 "community number\n"
8100 "Do not send outside local AS (well-known community)\n"
8101 "Do not advertise to any peer (well-known community)\n"
8102 "Do not export to next AS (well-known community)\n"
8103 "Exact match of the communities")
8104
8105ALIAS (show_ip_bgp_ipv4_community_exact,
8106 show_ip_bgp_ipv4_community3_exact_cmd,
8107 "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",
8108 SHOW_STR
8109 IP_STR
8110 BGP_STR
8111 "Address family\n"
8112 "Address Family modifier\n"
8113 "Address Family modifier\n"
8114 "Display routes matching the communities\n"
8115 "community number\n"
8116 "Do not send outside local AS (well-known community)\n"
8117 "Do not advertise to any peer (well-known community)\n"
8118 "Do not export to next AS (well-known community)\n"
8119 "community number\n"
8120 "Do not send outside local AS (well-known community)\n"
8121 "Do not advertise to any peer (well-known community)\n"
8122 "Do not export to next AS (well-known community)\n"
8123 "community number\n"
8124 "Do not send outside local AS (well-known community)\n"
8125 "Do not advertise to any peer (well-known community)\n"
8126 "Do not export to next AS (well-known community)\n"
8127 "Exact match of the communities")
8128
8129ALIAS (show_ip_bgp_ipv4_community_exact,
8130 show_ip_bgp_ipv4_community4_exact_cmd,
8131 "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",
8132 SHOW_STR
8133 IP_STR
8134 BGP_STR
8135 "Address family\n"
8136 "Address Family modifier\n"
8137 "Address Family modifier\n"
8138 "Display routes matching the communities\n"
8139 "community number\n"
8140 "Do not send outside local AS (well-known community)\n"
8141 "Do not advertise to any peer (well-known community)\n"
8142 "Do not export to next AS (well-known community)\n"
8143 "community number\n"
8144 "Do not send outside local AS (well-known community)\n"
8145 "Do not advertise to any peer (well-known community)\n"
8146 "Do not export to next AS (well-known community)\n"
8147 "community number\n"
8148 "Do not send outside local AS (well-known community)\n"
8149 "Do not advertise to any peer (well-known community)\n"
8150 "Do not export to next AS (well-known community)\n"
8151 "community number\n"
8152 "Do not send outside local AS (well-known community)\n"
8153 "Do not advertise to any peer (well-known community)\n"
8154 "Do not export to next AS (well-known community)\n"
8155 "Exact match of the communities")
8156
8157#ifdef HAVE_IPV6
8158DEFUN (show_bgp_community,
8159 show_bgp_community_cmd,
8160 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8161 SHOW_STR
8162 BGP_STR
8163 "Display routes matching the communities\n"
8164 "community number\n"
8165 "Do not send outside local AS (well-known community)\n"
8166 "Do not advertise to any peer (well-known community)\n"
8167 "Do not export to next AS (well-known community)\n")
8168{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008169 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008170}
8171
8172ALIAS (show_bgp_community,
8173 show_bgp_ipv6_community_cmd,
8174 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8175 SHOW_STR
8176 BGP_STR
8177 "Address family\n"
8178 "Display routes matching the communities\n"
8179 "community number\n"
8180 "Do not send outside local AS (well-known community)\n"
8181 "Do not advertise to any peer (well-known community)\n"
8182 "Do not export to next AS (well-known community)\n")
8183
8184ALIAS (show_bgp_community,
8185 show_bgp_community2_cmd,
8186 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8187 SHOW_STR
8188 BGP_STR
8189 "Display routes matching the communities\n"
8190 "community number\n"
8191 "Do not send outside local AS (well-known community)\n"
8192 "Do not advertise to any peer (well-known community)\n"
8193 "Do not export to next AS (well-known community)\n"
8194 "community number\n"
8195 "Do not send outside local AS (well-known community)\n"
8196 "Do not advertise to any peer (well-known community)\n"
8197 "Do not export to next AS (well-known community)\n")
8198
8199ALIAS (show_bgp_community,
8200 show_bgp_ipv6_community2_cmd,
8201 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8202 SHOW_STR
8203 BGP_STR
8204 "Address family\n"
8205 "Display routes matching the communities\n"
8206 "community number\n"
8207 "Do not send outside local AS (well-known community)\n"
8208 "Do not advertise to any peer (well-known community)\n"
8209 "Do not export to next AS (well-known community)\n"
8210 "community number\n"
8211 "Do not send outside local AS (well-known community)\n"
8212 "Do not advertise to any peer (well-known community)\n"
8213 "Do not export to next AS (well-known community)\n")
8214
8215ALIAS (show_bgp_community,
8216 show_bgp_community3_cmd,
8217 "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)",
8218 SHOW_STR
8219 BGP_STR
8220 "Display routes matching the communities\n"
8221 "community number\n"
8222 "Do not send outside local AS (well-known community)\n"
8223 "Do not advertise to any peer (well-known community)\n"
8224 "Do not export to next AS (well-known community)\n"
8225 "community number\n"
8226 "Do not send outside local AS (well-known community)\n"
8227 "Do not advertise to any peer (well-known community)\n"
8228 "Do not export to next AS (well-known community)\n"
8229 "community number\n"
8230 "Do not send outside local AS (well-known community)\n"
8231 "Do not advertise to any peer (well-known community)\n"
8232 "Do not export to next AS (well-known community)\n")
8233
8234ALIAS (show_bgp_community,
8235 show_bgp_ipv6_community3_cmd,
8236 "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)",
8237 SHOW_STR
8238 BGP_STR
8239 "Address family\n"
8240 "Display routes matching the communities\n"
8241 "community number\n"
8242 "Do not send outside local AS (well-known community)\n"
8243 "Do not advertise to any peer (well-known community)\n"
8244 "Do not export to next AS (well-known community)\n"
8245 "community number\n"
8246 "Do not send outside local AS (well-known community)\n"
8247 "Do not advertise to any peer (well-known community)\n"
8248 "Do not export to next AS (well-known community)\n"
8249 "community number\n"
8250 "Do not send outside local AS (well-known community)\n"
8251 "Do not advertise to any peer (well-known community)\n"
8252 "Do not export to next AS (well-known community)\n")
8253
8254ALIAS (show_bgp_community,
8255 show_bgp_community4_cmd,
8256 "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)",
8257 SHOW_STR
8258 BGP_STR
8259 "Display routes matching the communities\n"
8260 "community number\n"
8261 "Do not send outside local AS (well-known community)\n"
8262 "Do not advertise to any peer (well-known community)\n"
8263 "Do not export to next AS (well-known community)\n"
8264 "community number\n"
8265 "Do not send outside local AS (well-known community)\n"
8266 "Do not advertise to any peer (well-known community)\n"
8267 "Do not export to next AS (well-known community)\n"
8268 "community number\n"
8269 "Do not send outside local AS (well-known community)\n"
8270 "Do not advertise to any peer (well-known community)\n"
8271 "Do not export to next AS (well-known community)\n"
8272 "community number\n"
8273 "Do not send outside local AS (well-known community)\n"
8274 "Do not advertise to any peer (well-known community)\n"
8275 "Do not export to next AS (well-known community)\n")
8276
8277ALIAS (show_bgp_community,
8278 show_bgp_ipv6_community4_cmd,
8279 "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)",
8280 SHOW_STR
8281 BGP_STR
8282 "Address family\n"
8283 "Display routes matching the communities\n"
8284 "community number\n"
8285 "Do not send outside local AS (well-known community)\n"
8286 "Do not advertise to any peer (well-known community)\n"
8287 "Do not export to next AS (well-known community)\n"
8288 "community number\n"
8289 "Do not send outside local AS (well-known community)\n"
8290 "Do not advertise to any peer (well-known community)\n"
8291 "Do not export to next AS (well-known community)\n"
8292 "community number\n"
8293 "Do not send outside local AS (well-known community)\n"
8294 "Do not advertise to any peer (well-known community)\n"
8295 "Do not export to next AS (well-known community)\n"
8296 "community number\n"
8297 "Do not send outside local AS (well-known community)\n"
8298 "Do not advertise to any peer (well-known community)\n"
8299 "Do not export to next AS (well-known community)\n")
8300
8301/* old command */
8302DEFUN (show_ipv6_bgp_community,
8303 show_ipv6_bgp_community_cmd,
8304 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8305 SHOW_STR
8306 IPV6_STR
8307 BGP_STR
8308 "Display routes matching the communities\n"
8309 "community number\n"
8310 "Do not send outside local AS (well-known community)\n"
8311 "Do not advertise to any peer (well-known community)\n"
8312 "Do not export to next AS (well-known community)\n")
8313{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008314 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008315}
8316
8317/* old command */
8318ALIAS (show_ipv6_bgp_community,
8319 show_ipv6_bgp_community2_cmd,
8320 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8321 SHOW_STR
8322 IPV6_STR
8323 BGP_STR
8324 "Display routes matching the communities\n"
8325 "community number\n"
8326 "Do not send outside local AS (well-known community)\n"
8327 "Do not advertise to any peer (well-known community)\n"
8328 "Do not export to next AS (well-known community)\n"
8329 "community number\n"
8330 "Do not send outside local AS (well-known community)\n"
8331 "Do not advertise to any peer (well-known community)\n"
8332 "Do not export to next AS (well-known community)\n")
8333
8334/* old command */
8335ALIAS (show_ipv6_bgp_community,
8336 show_ipv6_bgp_community3_cmd,
8337 "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)",
8338 SHOW_STR
8339 IPV6_STR
8340 BGP_STR
8341 "Display routes matching the communities\n"
8342 "community number\n"
8343 "Do not send outside local AS (well-known community)\n"
8344 "Do not advertise to any peer (well-known community)\n"
8345 "Do not export to next AS (well-known community)\n"
8346 "community number\n"
8347 "Do not send outside local AS (well-known community)\n"
8348 "Do not advertise to any peer (well-known community)\n"
8349 "Do not export to next AS (well-known community)\n"
8350 "community number\n"
8351 "Do not send outside local AS (well-known community)\n"
8352 "Do not advertise to any peer (well-known community)\n"
8353 "Do not export to next AS (well-known community)\n")
8354
8355/* old command */
8356ALIAS (show_ipv6_bgp_community,
8357 show_ipv6_bgp_community4_cmd,
8358 "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)",
8359 SHOW_STR
8360 IPV6_STR
8361 BGP_STR
8362 "Display routes matching the communities\n"
8363 "community number\n"
8364 "Do not send outside local AS (well-known community)\n"
8365 "Do not advertise to any peer (well-known community)\n"
8366 "Do not export to next AS (well-known community)\n"
8367 "community number\n"
8368 "Do not send outside local AS (well-known community)\n"
8369 "Do not advertise to any peer (well-known community)\n"
8370 "Do not export to next AS (well-known community)\n"
8371 "community number\n"
8372 "Do not send outside local AS (well-known community)\n"
8373 "Do not advertise to any peer (well-known community)\n"
8374 "Do not export to next AS (well-known community)\n"
8375 "community number\n"
8376 "Do not send outside local AS (well-known community)\n"
8377 "Do not advertise to any peer (well-known community)\n"
8378 "Do not export to next AS (well-known community)\n")
8379
8380DEFUN (show_bgp_community_exact,
8381 show_bgp_community_exact_cmd,
8382 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8383 SHOW_STR
8384 BGP_STR
8385 "Display routes matching the communities\n"
8386 "community number\n"
8387 "Do not send outside local AS (well-known community)\n"
8388 "Do not advertise to any peer (well-known community)\n"
8389 "Do not export to next AS (well-known community)\n"
8390 "Exact match of the communities")
8391{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008392 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008393}
8394
8395ALIAS (show_bgp_community_exact,
8396 show_bgp_ipv6_community_exact_cmd,
8397 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8398 SHOW_STR
8399 BGP_STR
8400 "Address family\n"
8401 "Display routes matching the communities\n"
8402 "community number\n"
8403 "Do not send outside local AS (well-known community)\n"
8404 "Do not advertise to any peer (well-known community)\n"
8405 "Do not export to next AS (well-known community)\n"
8406 "Exact match of the communities")
8407
8408ALIAS (show_bgp_community_exact,
8409 show_bgp_community2_exact_cmd,
8410 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8411 SHOW_STR
8412 BGP_STR
8413 "Display routes matching the communities\n"
8414 "community number\n"
8415 "Do not send outside local AS (well-known community)\n"
8416 "Do not advertise to any peer (well-known community)\n"
8417 "Do not export to next AS (well-known community)\n"
8418 "community number\n"
8419 "Do not send outside local AS (well-known community)\n"
8420 "Do not advertise to any peer (well-known community)\n"
8421 "Do not export to next AS (well-known community)\n"
8422 "Exact match of the communities")
8423
8424ALIAS (show_bgp_community_exact,
8425 show_bgp_ipv6_community2_exact_cmd,
8426 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8427 SHOW_STR
8428 BGP_STR
8429 "Address family\n"
8430 "Display routes matching the communities\n"
8431 "community number\n"
8432 "Do not send outside local AS (well-known community)\n"
8433 "Do not advertise to any peer (well-known community)\n"
8434 "Do not export to next AS (well-known community)\n"
8435 "community number\n"
8436 "Do not send outside local AS (well-known community)\n"
8437 "Do not advertise to any peer (well-known community)\n"
8438 "Do not export to next AS (well-known community)\n"
8439 "Exact match of the communities")
8440
8441ALIAS (show_bgp_community_exact,
8442 show_bgp_community3_exact_cmd,
8443 "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",
8444 SHOW_STR
8445 BGP_STR
8446 "Display routes matching the communities\n"
8447 "community number\n"
8448 "Do not send outside local AS (well-known community)\n"
8449 "Do not advertise to any peer (well-known community)\n"
8450 "Do not export to next AS (well-known community)\n"
8451 "community number\n"
8452 "Do not send outside local AS (well-known community)\n"
8453 "Do not advertise to any peer (well-known community)\n"
8454 "Do not export to next AS (well-known community)\n"
8455 "community number\n"
8456 "Do not send outside local AS (well-known community)\n"
8457 "Do not advertise to any peer (well-known community)\n"
8458 "Do not export to next AS (well-known community)\n"
8459 "Exact match of the communities")
8460
8461ALIAS (show_bgp_community_exact,
8462 show_bgp_ipv6_community3_exact_cmd,
8463 "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",
8464 SHOW_STR
8465 BGP_STR
8466 "Address family\n"
8467 "Display routes matching the communities\n"
8468 "community number\n"
8469 "Do not send outside local AS (well-known community)\n"
8470 "Do not advertise to any peer (well-known community)\n"
8471 "Do not export to next AS (well-known community)\n"
8472 "community number\n"
8473 "Do not send outside local AS (well-known community)\n"
8474 "Do not advertise to any peer (well-known community)\n"
8475 "Do not export to next AS (well-known community)\n"
8476 "community number\n"
8477 "Do not send outside local AS (well-known community)\n"
8478 "Do not advertise to any peer (well-known community)\n"
8479 "Do not export to next AS (well-known community)\n"
8480 "Exact match of the communities")
8481
8482ALIAS (show_bgp_community_exact,
8483 show_bgp_community4_exact_cmd,
8484 "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",
8485 SHOW_STR
8486 BGP_STR
8487 "Display routes matching the communities\n"
8488 "community number\n"
8489 "Do not send outside local AS (well-known community)\n"
8490 "Do not advertise to any peer (well-known community)\n"
8491 "Do not export to next AS (well-known community)\n"
8492 "community number\n"
8493 "Do not send outside local AS (well-known community)\n"
8494 "Do not advertise to any peer (well-known community)\n"
8495 "Do not export to next AS (well-known community)\n"
8496 "community number\n"
8497 "Do not send outside local AS (well-known community)\n"
8498 "Do not advertise to any peer (well-known community)\n"
8499 "Do not export to next AS (well-known community)\n"
8500 "community number\n"
8501 "Do not send outside local AS (well-known community)\n"
8502 "Do not advertise to any peer (well-known community)\n"
8503 "Do not export to next AS (well-known community)\n"
8504 "Exact match of the communities")
8505
8506ALIAS (show_bgp_community_exact,
8507 show_bgp_ipv6_community4_exact_cmd,
8508 "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",
8509 SHOW_STR
8510 BGP_STR
8511 "Address family\n"
8512 "Display routes matching the communities\n"
8513 "community number\n"
8514 "Do not send outside local AS (well-known community)\n"
8515 "Do not advertise to any peer (well-known community)\n"
8516 "Do not export to next AS (well-known community)\n"
8517 "community number\n"
8518 "Do not send outside local AS (well-known community)\n"
8519 "Do not advertise to any peer (well-known community)\n"
8520 "Do not export to next AS (well-known community)\n"
8521 "community number\n"
8522 "Do not send outside local AS (well-known community)\n"
8523 "Do not advertise to any peer (well-known community)\n"
8524 "Do not export to next AS (well-known community)\n"
8525 "community number\n"
8526 "Do not send outside local AS (well-known community)\n"
8527 "Do not advertise to any peer (well-known community)\n"
8528 "Do not export to next AS (well-known community)\n"
8529 "Exact match of the communities")
8530
8531/* old command */
8532DEFUN (show_ipv6_bgp_community_exact,
8533 show_ipv6_bgp_community_exact_cmd,
8534 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8535 SHOW_STR
8536 IPV6_STR
8537 BGP_STR
8538 "Display routes matching the communities\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 "Exact match of the communities")
8544{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008545 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008546}
8547
8548/* old command */
8549ALIAS (show_ipv6_bgp_community_exact,
8550 show_ipv6_bgp_community2_exact_cmd,
8551 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8552 SHOW_STR
8553 IPV6_STR
8554 BGP_STR
8555 "Display routes matching the communities\n"
8556 "community number\n"
8557 "Do not send outside local AS (well-known community)\n"
8558 "Do not advertise to any peer (well-known community)\n"
8559 "Do not export to next AS (well-known community)\n"
8560 "community number\n"
8561 "Do not send outside local AS (well-known community)\n"
8562 "Do not advertise to any peer (well-known community)\n"
8563 "Do not export to next AS (well-known community)\n"
8564 "Exact match of the communities")
8565
8566/* old command */
8567ALIAS (show_ipv6_bgp_community_exact,
8568 show_ipv6_bgp_community3_exact_cmd,
8569 "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",
8570 SHOW_STR
8571 IPV6_STR
8572 BGP_STR
8573 "Display routes matching the communities\n"
8574 "community number\n"
8575 "Do not send outside local AS (well-known community)\n"
8576 "Do not advertise to any peer (well-known community)\n"
8577 "Do not export to next AS (well-known community)\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_community4_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) (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 "community number\n"
8609 "Do not send outside local AS (well-known community)\n"
8610 "Do not advertise to any peer (well-known community)\n"
8611 "Do not export to next AS (well-known community)\n"
8612 "Exact match of the communities")
8613
8614/* old command */
8615DEFUN (show_ipv6_mbgp_community,
8616 show_ipv6_mbgp_community_cmd,
8617 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8618 SHOW_STR
8619 IPV6_STR
8620 MBGP_STR
8621 "Display routes matching the communities\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{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008627 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008628}
8629
8630/* old command */
8631ALIAS (show_ipv6_mbgp_community,
8632 show_ipv6_mbgp_community2_cmd,
8633 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8634 SHOW_STR
8635 IPV6_STR
8636 MBGP_STR
8637 "Display routes matching the communities\n"
8638 "community number\n"
8639 "Do not send outside local AS (well-known community)\n"
8640 "Do not advertise to any peer (well-known community)\n"
8641 "Do not export to next AS (well-known community)\n"
8642 "community number\n"
8643 "Do not send outside local AS (well-known community)\n"
8644 "Do not advertise to any peer (well-known community)\n"
8645 "Do not export to next AS (well-known community)\n")
8646
8647/* old command */
8648ALIAS (show_ipv6_mbgp_community,
8649 show_ipv6_mbgp_community3_cmd,
8650 "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)",
8651 SHOW_STR
8652 IPV6_STR
8653 MBGP_STR
8654 "Display routes matching the communities\n"
8655 "community number\n"
8656 "Do not send outside local AS (well-known community)\n"
8657 "Do not advertise to any peer (well-known community)\n"
8658 "Do not export to next AS (well-known community)\n"
8659 "community number\n"
8660 "Do not send outside local AS (well-known community)\n"
8661 "Do not advertise to any peer (well-known community)\n"
8662 "Do not export to next AS (well-known community)\n"
8663 "community number\n"
8664 "Do not send outside local AS (well-known community)\n"
8665 "Do not advertise to any peer (well-known community)\n"
8666 "Do not export to next AS (well-known community)\n")
8667
8668/* old command */
8669ALIAS (show_ipv6_mbgp_community,
8670 show_ipv6_mbgp_community4_cmd,
8671 "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)",
8672 SHOW_STR
8673 IPV6_STR
8674 MBGP_STR
8675 "Display routes matching the communities\n"
8676 "community number\n"
8677 "Do not send outside local AS (well-known community)\n"
8678 "Do not advertise to any peer (well-known community)\n"
8679 "Do not export to next AS (well-known community)\n"
8680 "community number\n"
8681 "Do not send outside local AS (well-known community)\n"
8682 "Do not advertise to any peer (well-known community)\n"
8683 "Do not export to next AS (well-known community)\n"
8684 "community number\n"
8685 "Do not send outside local AS (well-known community)\n"
8686 "Do not advertise to any peer (well-known community)\n"
8687 "Do not export to next AS (well-known community)\n"
8688 "community number\n"
8689 "Do not send outside local AS (well-known community)\n"
8690 "Do not advertise to any peer (well-known community)\n"
8691 "Do not export to next AS (well-known community)\n")
8692
8693/* old command */
8694DEFUN (show_ipv6_mbgp_community_exact,
8695 show_ipv6_mbgp_community_exact_cmd,
8696 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8697 SHOW_STR
8698 IPV6_STR
8699 MBGP_STR
8700 "Display routes matching the communities\n"
8701 "community number\n"
8702 "Do not send outside local AS (well-known community)\n"
8703 "Do not advertise to any peer (well-known community)\n"
8704 "Do not export to next AS (well-known community)\n"
8705 "Exact match of the communities")
8706{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008707 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008708}
8709
8710/* old command */
8711ALIAS (show_ipv6_mbgp_community_exact,
8712 show_ipv6_mbgp_community2_exact_cmd,
8713 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8714 SHOW_STR
8715 IPV6_STR
8716 MBGP_STR
8717 "Display routes matching the communities\n"
8718 "community number\n"
8719 "Do not send outside local AS (well-known community)\n"
8720 "Do not advertise to any peer (well-known community)\n"
8721 "Do not export to next AS (well-known community)\n"
8722 "community number\n"
8723 "Do not send outside local AS (well-known community)\n"
8724 "Do not advertise to any peer (well-known community)\n"
8725 "Do not export to next AS (well-known community)\n"
8726 "Exact match of the communities")
8727
8728/* old command */
8729ALIAS (show_ipv6_mbgp_community_exact,
8730 show_ipv6_mbgp_community3_exact_cmd,
8731 "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",
8732 SHOW_STR
8733 IPV6_STR
8734 MBGP_STR
8735 "Display routes matching the communities\n"
8736 "community number\n"
8737 "Do not send outside local AS (well-known community)\n"
8738 "Do not advertise to any peer (well-known community)\n"
8739 "Do not export to next AS (well-known community)\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_community4_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) (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 "community number\n"
8771 "Do not send outside local AS (well-known community)\n"
8772 "Do not advertise to any peer (well-known community)\n"
8773 "Do not export to next AS (well-known community)\n"
8774 "Exact match of the communities")
8775#endif /* HAVE_IPV6 */
8776
paul94f2b392005-06-28 12:44:16 +00008777static int
paulfd79ac92004-10-13 05:06:08 +00008778bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008779 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008780{
8781 struct community_list *list;
8782
hassofee6e4e2005-02-02 16:29:31 +00008783 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008784 if (list == NULL)
8785 {
8786 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8787 VTY_NEWLINE);
8788 return CMD_WARNING;
8789 }
8790
ajs5a646652004-11-05 01:25:55 +00008791 return bgp_show (vty, NULL, afi, safi,
8792 (exact ? bgp_show_type_community_list_exact :
8793 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008794}
8795
8796DEFUN (show_ip_bgp_community_list,
8797 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008798 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008799 SHOW_STR
8800 IP_STR
8801 BGP_STR
8802 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008803 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008804 "community-list name\n")
8805{
8806 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8807}
8808
8809DEFUN (show_ip_bgp_ipv4_community_list,
8810 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008811 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008812 SHOW_STR
8813 IP_STR
8814 BGP_STR
8815 "Address family\n"
8816 "Address Family modifier\n"
8817 "Address Family modifier\n"
8818 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008819 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008820 "community-list name\n")
8821{
8822 if (strncmp (argv[0], "m", 1) == 0)
8823 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8824
8825 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8826}
8827
8828DEFUN (show_ip_bgp_community_list_exact,
8829 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008830 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008831 SHOW_STR
8832 IP_STR
8833 BGP_STR
8834 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008835 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008836 "community-list name\n"
8837 "Exact match of the communities\n")
8838{
8839 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8840}
8841
8842DEFUN (show_ip_bgp_ipv4_community_list_exact,
8843 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008844 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008845 SHOW_STR
8846 IP_STR
8847 BGP_STR
8848 "Address family\n"
8849 "Address Family modifier\n"
8850 "Address Family modifier\n"
8851 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008852 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008853 "community-list name\n"
8854 "Exact match of the communities\n")
8855{
8856 if (strncmp (argv[0], "m", 1) == 0)
8857 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8858
8859 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8860}
8861
8862#ifdef HAVE_IPV6
8863DEFUN (show_bgp_community_list,
8864 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008865 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008866 SHOW_STR
8867 BGP_STR
8868 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008869 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008870 "community-list name\n")
8871{
8872 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8873}
8874
8875ALIAS (show_bgp_community_list,
8876 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008877 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008878 SHOW_STR
8879 BGP_STR
8880 "Address family\n"
8881 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008882 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008883 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008884
8885/* old command */
8886DEFUN (show_ipv6_bgp_community_list,
8887 show_ipv6_bgp_community_list_cmd,
8888 "show ipv6 bgp community-list WORD",
8889 SHOW_STR
8890 IPV6_STR
8891 BGP_STR
8892 "Display routes matching the community-list\n"
8893 "community-list name\n")
8894{
8895 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8896}
8897
8898/* old command */
8899DEFUN (show_ipv6_mbgp_community_list,
8900 show_ipv6_mbgp_community_list_cmd,
8901 "show ipv6 mbgp community-list WORD",
8902 SHOW_STR
8903 IPV6_STR
8904 MBGP_STR
8905 "Display routes matching the community-list\n"
8906 "community-list name\n")
8907{
8908 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8909}
8910
8911DEFUN (show_bgp_community_list_exact,
8912 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008913 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008914 SHOW_STR
8915 BGP_STR
8916 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008917 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008918 "community-list name\n"
8919 "Exact match of the communities\n")
8920{
8921 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8922}
8923
8924ALIAS (show_bgp_community_list_exact,
8925 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008926 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008927 SHOW_STR
8928 BGP_STR
8929 "Address family\n"
8930 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008931 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008932 "community-list name\n"
8933 "Exact match of the communities\n")
8934
8935/* old command */
8936DEFUN (show_ipv6_bgp_community_list_exact,
8937 show_ipv6_bgp_community_list_exact_cmd,
8938 "show ipv6 bgp community-list WORD exact-match",
8939 SHOW_STR
8940 IPV6_STR
8941 BGP_STR
8942 "Display routes matching the community-list\n"
8943 "community-list name\n"
8944 "Exact match of the communities\n")
8945{
8946 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8947}
8948
8949/* old command */
8950DEFUN (show_ipv6_mbgp_community_list_exact,
8951 show_ipv6_mbgp_community_list_exact_cmd,
8952 "show ipv6 mbgp community-list WORD exact-match",
8953 SHOW_STR
8954 IPV6_STR
8955 MBGP_STR
8956 "Display routes matching the community-list\n"
8957 "community-list name\n"
8958 "Exact match of the communities\n")
8959{
8960 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8961}
8962#endif /* HAVE_IPV6 */
8963
paul94f2b392005-06-28 12:44:16 +00008964static int
paulfd79ac92004-10-13 05:06:08 +00008965bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008966 safi_t safi, enum bgp_show_type type)
8967{
8968 int ret;
8969 struct prefix *p;
8970
8971 p = prefix_new();
8972
8973 ret = str2prefix (prefix, p);
8974 if (! ret)
8975 {
8976 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8977 return CMD_WARNING;
8978 }
8979
ajs5a646652004-11-05 01:25:55 +00008980 ret = bgp_show (vty, NULL, afi, safi, type, p);
8981 prefix_free(p);
8982 return ret;
paul718e3742002-12-13 20:15:29 +00008983}
8984
8985DEFUN (show_ip_bgp_prefix_longer,
8986 show_ip_bgp_prefix_longer_cmd,
8987 "show ip bgp A.B.C.D/M longer-prefixes",
8988 SHOW_STR
8989 IP_STR
8990 BGP_STR
8991 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8992 "Display route and more specific routes\n")
8993{
8994 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8995 bgp_show_type_prefix_longer);
8996}
8997
8998DEFUN (show_ip_bgp_flap_prefix_longer,
8999 show_ip_bgp_flap_prefix_longer_cmd,
9000 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
9001 SHOW_STR
9002 IP_STR
9003 BGP_STR
9004 "Display flap statistics of routes\n"
9005 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9006 "Display route and more specific routes\n")
9007{
9008 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9009 bgp_show_type_flap_prefix_longer);
9010}
9011
9012DEFUN (show_ip_bgp_ipv4_prefix_longer,
9013 show_ip_bgp_ipv4_prefix_longer_cmd,
9014 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9015 SHOW_STR
9016 IP_STR
9017 BGP_STR
9018 "Address family\n"
9019 "Address Family modifier\n"
9020 "Address Family modifier\n"
9021 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9022 "Display route and more specific routes\n")
9023{
9024 if (strncmp (argv[0], "m", 1) == 0)
9025 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9026 bgp_show_type_prefix_longer);
9027
9028 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9029 bgp_show_type_prefix_longer);
9030}
9031
9032DEFUN (show_ip_bgp_flap_address,
9033 show_ip_bgp_flap_address_cmd,
9034 "show ip bgp flap-statistics A.B.C.D",
9035 SHOW_STR
9036 IP_STR
9037 BGP_STR
9038 "Display flap statistics of routes\n"
9039 "Network in the BGP routing table to display\n")
9040{
9041 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9042 bgp_show_type_flap_address);
9043}
9044
9045DEFUN (show_ip_bgp_flap_prefix,
9046 show_ip_bgp_flap_prefix_cmd,
9047 "show ip bgp flap-statistics A.B.C.D/M",
9048 SHOW_STR
9049 IP_STR
9050 BGP_STR
9051 "Display flap statistics of routes\n"
9052 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9053{
9054 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9055 bgp_show_type_flap_prefix);
9056}
9057#ifdef HAVE_IPV6
9058DEFUN (show_bgp_prefix_longer,
9059 show_bgp_prefix_longer_cmd,
9060 "show bgp X:X::X:X/M longer-prefixes",
9061 SHOW_STR
9062 BGP_STR
9063 "IPv6 prefix <network>/<length>\n"
9064 "Display route and more specific routes\n")
9065{
9066 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9067 bgp_show_type_prefix_longer);
9068}
9069
9070ALIAS (show_bgp_prefix_longer,
9071 show_bgp_ipv6_prefix_longer_cmd,
9072 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9073 SHOW_STR
9074 BGP_STR
9075 "Address family\n"
9076 "IPv6 prefix <network>/<length>\n"
9077 "Display route and more specific routes\n")
9078
9079/* old command */
9080DEFUN (show_ipv6_bgp_prefix_longer,
9081 show_ipv6_bgp_prefix_longer_cmd,
9082 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9083 SHOW_STR
9084 IPV6_STR
9085 BGP_STR
9086 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9087 "Display route and more specific routes\n")
9088{
9089 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9090 bgp_show_type_prefix_longer);
9091}
9092
9093/* old command */
9094DEFUN (show_ipv6_mbgp_prefix_longer,
9095 show_ipv6_mbgp_prefix_longer_cmd,
9096 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9097 SHOW_STR
9098 IPV6_STR
9099 MBGP_STR
9100 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9101 "Display route and more specific routes\n")
9102{
9103 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9104 bgp_show_type_prefix_longer);
9105}
9106#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009107
paul94f2b392005-06-28 12:44:16 +00009108static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009109peer_lookup_in_view (struct vty *vty, const char *view_name,
9110 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009111{
9112 int ret;
9113 struct bgp *bgp;
9114 struct peer *peer;
9115 union sockunion su;
9116
9117 /* BGP structure lookup. */
9118 if (view_name)
9119 {
9120 bgp = bgp_lookup_by_name (view_name);
9121 if (! bgp)
9122 {
9123 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9124 return NULL;
9125 }
9126 }
paul5228ad22004-06-04 17:58:18 +00009127 else
paulbb46e942003-10-24 19:02:03 +00009128 {
9129 bgp = bgp_get_default ();
9130 if (! bgp)
9131 {
9132 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9133 return NULL;
9134 }
9135 }
9136
9137 /* Get peer sockunion. */
9138 ret = str2sockunion (ip_str, &su);
9139 if (ret < 0)
9140 {
9141 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9142 return NULL;
9143 }
9144
9145 /* Peer structure lookup. */
9146 peer = peer_lookup (bgp, &su);
9147 if (! peer)
9148 {
9149 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9150 return NULL;
9151 }
9152
9153 return peer;
9154}
Paul Jakma2815e612006-09-14 02:56:07 +00009155
9156enum bgp_stats
9157{
9158 BGP_STATS_MAXBITLEN = 0,
9159 BGP_STATS_RIB,
9160 BGP_STATS_PREFIXES,
9161 BGP_STATS_TOTPLEN,
9162 BGP_STATS_UNAGGREGATEABLE,
9163 BGP_STATS_MAX_AGGREGATEABLE,
9164 BGP_STATS_AGGREGATES,
9165 BGP_STATS_SPACE,
9166 BGP_STATS_ASPATH_COUNT,
9167 BGP_STATS_ASPATH_MAXHOPS,
9168 BGP_STATS_ASPATH_TOTHOPS,
9169 BGP_STATS_ASPATH_MAXSIZE,
9170 BGP_STATS_ASPATH_TOTSIZE,
9171 BGP_STATS_ASN_HIGHEST,
9172 BGP_STATS_MAX,
9173};
paulbb46e942003-10-24 19:02:03 +00009174
Paul Jakma2815e612006-09-14 02:56:07 +00009175static const char *table_stats_strs[] =
9176{
9177 [BGP_STATS_PREFIXES] = "Total Prefixes",
9178 [BGP_STATS_TOTPLEN] = "Average prefix length",
9179 [BGP_STATS_RIB] = "Total Advertisements",
9180 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9181 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9182 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9183 [BGP_STATS_SPACE] = "Address space advertised",
9184 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9185 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9186 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9187 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9188 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9189 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9190 [BGP_STATS_MAX] = NULL,
9191};
9192
9193struct bgp_table_stats
9194{
9195 struct bgp_table *table;
9196 unsigned long long counts[BGP_STATS_MAX];
9197};
9198
9199#if 0
9200#define TALLY_SIGFIG 100000
9201static unsigned long
9202ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9203{
9204 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9205 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9206 unsigned long ret = newtot / count;
9207
9208 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9209 return ret + 1;
9210 else
9211 return ret;
9212}
9213#endif
9214
9215static int
9216bgp_table_stats_walker (struct thread *t)
9217{
9218 struct bgp_node *rn;
9219 struct bgp_node *top;
9220 struct bgp_table_stats *ts = THREAD_ARG (t);
9221 unsigned int space = 0;
9222
Paul Jakma53d9f672006-10-15 23:41:16 +00009223 if (!(top = bgp_table_top (ts->table)))
9224 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009225
9226 switch (top->p.family)
9227 {
9228 case AF_INET:
9229 space = IPV4_MAX_BITLEN;
9230 break;
9231 case AF_INET6:
9232 space = IPV6_MAX_BITLEN;
9233 break;
9234 }
9235
9236 ts->counts[BGP_STATS_MAXBITLEN] = space;
9237
9238 for (rn = top; rn; rn = bgp_route_next (rn))
9239 {
9240 struct bgp_info *ri;
9241 struct bgp_node *prn = rn->parent;
9242 unsigned int rinum = 0;
9243
9244 if (rn == top)
9245 continue;
9246
9247 if (!rn->info)
9248 continue;
9249
9250 ts->counts[BGP_STATS_PREFIXES]++;
9251 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9252
9253#if 0
9254 ts->counts[BGP_STATS_AVGPLEN]
9255 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9256 ts->counts[BGP_STATS_AVGPLEN],
9257 rn->p.prefixlen);
9258#endif
9259
9260 /* check if the prefix is included by any other announcements */
9261 while (prn && !prn->info)
9262 prn = prn->parent;
9263
9264 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009265 {
9266 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9267 /* announced address space */
9268 if (space)
9269 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9270 }
Paul Jakma2815e612006-09-14 02:56:07 +00009271 else if (prn->info)
9272 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9273
Paul Jakma2815e612006-09-14 02:56:07 +00009274 for (ri = rn->info; ri; ri = ri->next)
9275 {
9276 rinum++;
9277 ts->counts[BGP_STATS_RIB]++;
9278
9279 if (ri->attr &&
9280 (CHECK_FLAG (ri->attr->flag,
9281 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9282 ts->counts[BGP_STATS_AGGREGATES]++;
9283
9284 /* as-path stats */
9285 if (ri->attr && ri->attr->aspath)
9286 {
9287 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9288 unsigned int size = aspath_size (ri->attr->aspath);
9289 as_t highest = aspath_highest (ri->attr->aspath);
9290
9291 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9292
9293 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9294 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9295
9296 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9297 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9298
9299 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9300 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9301#if 0
9302 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9303 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9304 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9305 hops);
9306 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9307 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9308 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9309 size);
9310#endif
9311 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9312 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9313 }
9314 }
9315 }
9316 return 0;
9317}
9318
9319static int
9320bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9321{
9322 struct bgp_table_stats ts;
9323 unsigned int i;
9324
9325 if (!bgp->rib[afi][safi])
9326 {
9327 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9328 return CMD_WARNING;
9329 }
9330
9331 memset (&ts, 0, sizeof (ts));
9332 ts.table = bgp->rib[afi][safi];
9333 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9334
9335 vty_out (vty, "BGP %s RIB statistics%s%s",
9336 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9337
9338 for (i = 0; i < BGP_STATS_MAX; i++)
9339 {
9340 if (!table_stats_strs[i])
9341 continue;
9342
9343 switch (i)
9344 {
9345#if 0
9346 case BGP_STATS_ASPATH_AVGHOPS:
9347 case BGP_STATS_ASPATH_AVGSIZE:
9348 case BGP_STATS_AVGPLEN:
9349 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9350 vty_out (vty, "%12.2f",
9351 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9352 break;
9353#endif
9354 case BGP_STATS_ASPATH_TOTHOPS:
9355 case BGP_STATS_ASPATH_TOTSIZE:
9356 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9357 vty_out (vty, "%12.2f",
9358 ts.counts[i] ?
9359 (float)ts.counts[i] /
9360 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9361 : 0);
9362 break;
9363 case BGP_STATS_TOTPLEN:
9364 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9365 vty_out (vty, "%12.2f",
9366 ts.counts[i] ?
9367 (float)ts.counts[i] /
9368 (float)ts.counts[BGP_STATS_PREFIXES]
9369 : 0);
9370 break;
9371 case BGP_STATS_SPACE:
9372 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9373 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9374 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9375 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009376 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009377 vty_out (vty, "%12.2f%s",
9378 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009379 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009380 VTY_NEWLINE);
9381 vty_out (vty, "%30s: ", "/8 equivalent ");
9382 vty_out (vty, "%12.2f%s",
9383 (float)ts.counts[BGP_STATS_SPACE] /
9384 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9385 VTY_NEWLINE);
9386 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9387 break;
9388 vty_out (vty, "%30s: ", "/24 equivalent ");
9389 vty_out (vty, "%12.2f",
9390 (float)ts.counts[BGP_STATS_SPACE] /
9391 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9392 break;
9393 default:
9394 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9395 vty_out (vty, "%12llu", ts.counts[i]);
9396 }
9397
9398 vty_out (vty, "%s", VTY_NEWLINE);
9399 }
9400 return CMD_SUCCESS;
9401}
9402
9403static int
9404bgp_table_stats_vty (struct vty *vty, const char *name,
9405 const char *afi_str, const char *safi_str)
9406{
9407 struct bgp *bgp;
9408 afi_t afi;
9409 safi_t safi;
9410
9411 if (name)
9412 bgp = bgp_lookup_by_name (name);
9413 else
9414 bgp = bgp_get_default ();
9415
9416 if (!bgp)
9417 {
9418 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9419 return CMD_WARNING;
9420 }
9421 if (strncmp (afi_str, "ipv", 3) == 0)
9422 {
9423 if (strncmp (afi_str, "ipv4", 4) == 0)
9424 afi = AFI_IP;
9425 else if (strncmp (afi_str, "ipv6", 4) == 0)
9426 afi = AFI_IP6;
9427 else
9428 {
9429 vty_out (vty, "%% Invalid address family %s%s",
9430 afi_str, VTY_NEWLINE);
9431 return CMD_WARNING;
9432 }
9433 if (strncmp (safi_str, "m", 1) == 0)
9434 safi = SAFI_MULTICAST;
9435 else if (strncmp (safi_str, "u", 1) == 0)
9436 safi = SAFI_UNICAST;
9437 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9438 safi = BGP_SAFI_VPNV4;
9439 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9440 safi = BGP_SAFI_VPNV6;
9441 else
9442 {
9443 vty_out (vty, "%% Invalid subsequent address family %s%s",
9444 safi_str, VTY_NEWLINE);
9445 return CMD_WARNING;
9446 }
9447 }
9448 else
9449 {
9450 vty_out (vty, "%% Invalid address family %s%s",
9451 afi_str, VTY_NEWLINE);
9452 return CMD_WARNING;
9453 }
9454
9455 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9456 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9457 {
9458 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9459 afi_str, safi_str, VTY_NEWLINE);
9460 return CMD_WARNING;
9461 }
9462 return bgp_table_stats (vty, bgp, afi, safi);
9463}
9464
9465DEFUN (show_bgp_statistics,
9466 show_bgp_statistics_cmd,
9467 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9468 SHOW_STR
9469 BGP_STR
9470 "Address family\n"
9471 "Address family\n"
9472 "Address Family modifier\n"
9473 "Address Family modifier\n"
9474 "BGP RIB advertisement statistics\n")
9475{
9476 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9477}
9478
9479ALIAS (show_bgp_statistics,
9480 show_bgp_statistics_vpnv4_cmd,
9481 "show bgp (ipv4) (vpnv4) statistics",
9482 SHOW_STR
9483 BGP_STR
9484 "Address family\n"
9485 "Address Family modifier\n"
9486 "BGP RIB advertisement statistics\n")
9487
9488DEFUN (show_bgp_statistics_view,
9489 show_bgp_statistics_view_cmd,
9490 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9491 SHOW_STR
9492 BGP_STR
9493 "BGP view\n"
9494 "Address family\n"
9495 "Address family\n"
9496 "Address Family modifier\n"
9497 "Address Family modifier\n"
9498 "BGP RIB advertisement statistics\n")
9499{
9500 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9501}
9502
9503ALIAS (show_bgp_statistics_view,
9504 show_bgp_statistics_view_vpnv4_cmd,
9505 "show bgp view WORD (ipv4) (vpnv4) statistics",
9506 SHOW_STR
9507 BGP_STR
9508 "BGP view\n"
9509 "Address family\n"
9510 "Address Family modifier\n"
9511 "BGP RIB advertisement statistics\n")
9512
Paul Jakmaff7924f2006-09-04 01:10:36 +00009513enum bgp_pcounts
9514{
9515 PCOUNT_ADJ_IN = 0,
9516 PCOUNT_DAMPED,
9517 PCOUNT_REMOVED,
9518 PCOUNT_HISTORY,
9519 PCOUNT_STALE,
9520 PCOUNT_VALID,
9521 PCOUNT_ALL,
9522 PCOUNT_COUNTED,
9523 PCOUNT_PFCNT, /* the figure we display to users */
9524 PCOUNT_MAX,
9525};
9526
9527static const char *pcount_strs[] =
9528{
9529 [PCOUNT_ADJ_IN] = "Adj-in",
9530 [PCOUNT_DAMPED] = "Damped",
9531 [PCOUNT_REMOVED] = "Removed",
9532 [PCOUNT_HISTORY] = "History",
9533 [PCOUNT_STALE] = "Stale",
9534 [PCOUNT_VALID] = "Valid",
9535 [PCOUNT_ALL] = "All RIB",
9536 [PCOUNT_COUNTED] = "PfxCt counted",
9537 [PCOUNT_PFCNT] = "Useable",
9538 [PCOUNT_MAX] = NULL,
9539};
9540
Paul Jakma2815e612006-09-14 02:56:07 +00009541struct peer_pcounts
9542{
9543 unsigned int count[PCOUNT_MAX];
9544 const struct peer *peer;
9545 const struct bgp_table *table;
9546};
9547
Paul Jakmaff7924f2006-09-04 01:10:36 +00009548static int
Paul Jakma2815e612006-09-14 02:56:07 +00009549bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009550{
9551 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009552 struct peer_pcounts *pc = THREAD_ARG (t);
9553 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009554
Paul Jakma2815e612006-09-14 02:56:07 +00009555 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009556 {
9557 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009558 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009559
9560 for (ain = rn->adj_in; ain; ain = ain->next)
9561 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009562 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009563
Paul Jakmaff7924f2006-09-04 01:10:36 +00009564 for (ri = rn->info; ri; ri = ri->next)
9565 {
9566 char buf[SU_ADDRSTRLEN];
9567
9568 if (ri->peer != peer)
9569 continue;
9570
Paul Jakma2815e612006-09-14 02:56:07 +00009571 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009572
9573 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009574 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009575 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009576 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009577 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009578 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009579 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009580 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009581 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009582 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009583 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009584 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009585
9586 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9587 {
Paul Jakma2815e612006-09-14 02:56:07 +00009588 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009589 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009590 plog_warn (peer->log,
9591 "%s [pcount] %s/%d is counted but flags 0x%x",
9592 peer->host,
9593 inet_ntop(rn->p.family, &rn->p.u.prefix,
9594 buf, SU_ADDRSTRLEN),
9595 rn->p.prefixlen,
9596 ri->flags);
9597 }
9598 else
9599 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009600 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009601 plog_warn (peer->log,
9602 "%s [pcount] %s/%d not counted but flags 0x%x",
9603 peer->host,
9604 inet_ntop(rn->p.family, &rn->p.u.prefix,
9605 buf, SU_ADDRSTRLEN),
9606 rn->p.prefixlen,
9607 ri->flags);
9608 }
9609 }
9610 }
Paul Jakma2815e612006-09-14 02:56:07 +00009611 return 0;
9612}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009613
Paul Jakma2815e612006-09-14 02:56:07 +00009614static int
9615bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9616{
9617 struct peer_pcounts pcounts = { .peer = peer };
9618 unsigned int i;
9619
9620 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9621 || !peer->bgp->rib[afi][safi])
9622 {
9623 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9624 return CMD_WARNING;
9625 }
9626
9627 memset (&pcounts, 0, sizeof(pcounts));
9628 pcounts.peer = peer;
9629 pcounts.table = peer->bgp->rib[afi][safi];
9630
9631 /* in-place call via thread subsystem so as to record execution time
9632 * stats for the thread-walk (i.e. ensure this can't be blamed on
9633 * on just vty_read()).
9634 */
9635 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9636
Paul Jakmaff7924f2006-09-04 01:10:36 +00009637 vty_out (vty, "Prefix counts for %s, %s%s",
9638 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9639 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9640 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9641 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9642
9643 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009644 vty_out (vty, "%20s: %-10d%s",
9645 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009646
Paul Jakma2815e612006-09-14 02:56:07 +00009647 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009648 {
9649 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9650 peer->host, VTY_NEWLINE);
9651 vty_out (vty, "Please report this bug, with the above command output%s",
9652 VTY_NEWLINE);
9653 }
9654
9655 return CMD_SUCCESS;
9656}
9657
9658DEFUN (show_ip_bgp_neighbor_prefix_counts,
9659 show_ip_bgp_neighbor_prefix_counts_cmd,
9660 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9661 SHOW_STR
9662 IP_STR
9663 BGP_STR
9664 "Detailed information on TCP and BGP neighbor connections\n"
9665 "Neighbor to display information about\n"
9666 "Neighbor to display information about\n"
9667 "Display detailed prefix count information\n")
9668{
9669 struct peer *peer;
9670
9671 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9672 if (! peer)
9673 return CMD_WARNING;
9674
9675 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9676}
9677
9678DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9679 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9680 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9681 SHOW_STR
9682 BGP_STR
9683 "Address family\n"
9684 "Detailed information on TCP and BGP neighbor connections\n"
9685 "Neighbor to display information about\n"
9686 "Neighbor to display information about\n"
9687 "Display detailed prefix count information\n")
9688{
9689 struct peer *peer;
9690
9691 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9692 if (! peer)
9693 return CMD_WARNING;
9694
9695 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9696}
9697
9698DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9699 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9700 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9701 SHOW_STR
9702 IP_STR
9703 BGP_STR
9704 "Address family\n"
9705 "Address Family modifier\n"
9706 "Address Family modifier\n"
9707 "Detailed information on TCP and BGP neighbor connections\n"
9708 "Neighbor to display information about\n"
9709 "Neighbor to display information about\n"
9710 "Display detailed prefix count information\n")
9711{
9712 struct peer *peer;
9713
9714 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9715 if (! peer)
9716 return CMD_WARNING;
9717
9718 if (strncmp (argv[0], "m", 1) == 0)
9719 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9720
9721 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9722}
9723
9724DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9725 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9726 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9727 SHOW_STR
9728 IP_STR
9729 BGP_STR
9730 "Address family\n"
9731 "Address Family modifier\n"
9732 "Address Family modifier\n"
9733 "Detailed information on TCP and BGP neighbor connections\n"
9734 "Neighbor to display information about\n"
9735 "Neighbor to display information about\n"
9736 "Display detailed prefix count information\n")
9737{
9738 struct peer *peer;
9739
9740 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9741 if (! peer)
9742 return CMD_WARNING;
9743
9744 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9745}
9746
9747
paul94f2b392005-06-28 12:44:16 +00009748static void
paul718e3742002-12-13 20:15:29 +00009749show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9750 int in)
9751{
9752 struct bgp_table *table;
9753 struct bgp_adj_in *ain;
9754 struct bgp_adj_out *adj;
9755 unsigned long output_count;
9756 struct bgp_node *rn;
9757 int header1 = 1;
9758 struct bgp *bgp;
9759 int header2 = 1;
9760
paulbb46e942003-10-24 19:02:03 +00009761 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009762
9763 if (! bgp)
9764 return;
9765
9766 table = bgp->rib[afi][safi];
9767
9768 output_count = 0;
9769
9770 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9771 PEER_STATUS_DEFAULT_ORIGINATE))
9772 {
9773 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 +00009774 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9775 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009776
9777 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9778 VTY_NEWLINE, VTY_NEWLINE);
9779 header1 = 0;
9780 }
9781
9782 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9783 if (in)
9784 {
9785 for (ain = rn->adj_in; ain; ain = ain->next)
9786 if (ain->peer == peer)
9787 {
9788 if (header1)
9789 {
9790 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 +00009791 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9792 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009793 header1 = 0;
9794 }
9795 if (header2)
9796 {
9797 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9798 header2 = 0;
9799 }
9800 if (ain->attr)
9801 {
9802 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9803 output_count++;
9804 }
9805 }
9806 }
9807 else
9808 {
9809 for (adj = rn->adj_out; adj; adj = adj->next)
9810 if (adj->peer == peer)
9811 {
9812 if (header1)
9813 {
9814 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 +00009815 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9816 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009817 header1 = 0;
9818 }
9819 if (header2)
9820 {
9821 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9822 header2 = 0;
9823 }
9824 if (adj->attr)
9825 {
9826 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9827 output_count++;
9828 }
9829 }
9830 }
9831
9832 if (output_count != 0)
9833 vty_out (vty, "%sTotal number of prefixes %ld%s",
9834 VTY_NEWLINE, output_count, VTY_NEWLINE);
9835}
9836
paul94f2b392005-06-28 12:44:16 +00009837static int
paulbb46e942003-10-24 19:02:03 +00009838peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9839{
paul718e3742002-12-13 20:15:29 +00009840 if (! peer || ! peer->afc[afi][safi])
9841 {
9842 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9843 return CMD_WARNING;
9844 }
9845
9846 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9847 {
9848 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9849 VTY_NEWLINE);
9850 return CMD_WARNING;
9851 }
9852
9853 show_adj_route (vty, peer, afi, safi, in);
9854
9855 return CMD_SUCCESS;
9856}
9857
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009858DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9859 show_ip_bgp_view_neighbor_advertised_route_cmd,
9860 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9861 SHOW_STR
9862 IP_STR
9863 BGP_STR
9864 "BGP view\n"
9865 "View name\n"
9866 "Detailed information on TCP and BGP neighbor connections\n"
9867 "Neighbor to display information about\n"
9868 "Neighbor to display information about\n"
9869 "Display the routes advertised to a BGP neighbor\n")
9870{
9871 struct peer *peer;
9872
9873 if (argc == 2)
9874 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9875 else
9876 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9877
9878 if (! peer)
9879 return CMD_WARNING;
9880
9881 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9882}
9883
9884ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009885 show_ip_bgp_neighbor_advertised_route_cmd,
9886 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9887 SHOW_STR
9888 IP_STR
9889 BGP_STR
9890 "Detailed information on TCP and BGP neighbor connections\n"
9891 "Neighbor to display information about\n"
9892 "Neighbor to display information about\n"
9893 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009894
9895DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9896 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9897 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9898 SHOW_STR
9899 IP_STR
9900 BGP_STR
9901 "Address family\n"
9902 "Address Family modifier\n"
9903 "Address Family modifier\n"
9904 "Detailed information on TCP and BGP neighbor connections\n"
9905 "Neighbor to display information about\n"
9906 "Neighbor to display information about\n"
9907 "Display the routes advertised to a BGP neighbor\n")
9908{
paulbb46e942003-10-24 19:02:03 +00009909 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009910
paulbb46e942003-10-24 19:02:03 +00009911 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9912 if (! peer)
9913 return CMD_WARNING;
9914
9915 if (strncmp (argv[0], "m", 1) == 0)
9916 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9917
9918 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009919}
9920
9921#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009922DEFUN (show_bgp_view_neighbor_advertised_route,
9923 show_bgp_view_neighbor_advertised_route_cmd,
9924 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9925 SHOW_STR
9926 BGP_STR
9927 "BGP view\n"
9928 "View name\n"
9929 "Detailed information on TCP and BGP neighbor connections\n"
9930 "Neighbor to display information about\n"
9931 "Neighbor to display information about\n"
9932 "Display the routes advertised to a BGP neighbor\n")
9933{
9934 struct peer *peer;
9935
9936 if (argc == 2)
9937 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9938 else
9939 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9940
9941 if (! peer)
9942 return CMD_WARNING;
9943
9944 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9945}
9946
9947ALIAS (show_bgp_view_neighbor_advertised_route,
9948 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9949 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9950 SHOW_STR
9951 BGP_STR
9952 "BGP view\n"
9953 "View name\n"
9954 "Address family\n"
9955 "Detailed information on TCP and BGP neighbor connections\n"
9956 "Neighbor to display information about\n"
9957 "Neighbor to display information about\n"
9958 "Display the routes advertised to a BGP neighbor\n")
9959
9960DEFUN (show_bgp_view_neighbor_received_routes,
9961 show_bgp_view_neighbor_received_routes_cmd,
9962 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9963 SHOW_STR
9964 BGP_STR
9965 "BGP view\n"
9966 "View name\n"
9967 "Detailed information on TCP and BGP neighbor connections\n"
9968 "Neighbor to display information about\n"
9969 "Neighbor to display information about\n"
9970 "Display the received routes from neighbor\n")
9971{
9972 struct peer *peer;
9973
9974 if (argc == 2)
9975 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9976 else
9977 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9978
9979 if (! peer)
9980 return CMD_WARNING;
9981
9982 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9983}
9984
9985ALIAS (show_bgp_view_neighbor_received_routes,
9986 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9987 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9988 SHOW_STR
9989 BGP_STR
9990 "BGP view\n"
9991 "View name\n"
9992 "Address family\n"
9993 "Detailed information on TCP and BGP neighbor connections\n"
9994 "Neighbor to display information about\n"
9995 "Neighbor to display information about\n"
9996 "Display the received routes from neighbor\n")
9997
9998ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009999 show_bgp_neighbor_advertised_route_cmd,
10000 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10001 SHOW_STR
10002 BGP_STR
10003 "Detailed information on TCP and BGP neighbor connections\n"
10004 "Neighbor to display information about\n"
10005 "Neighbor to display information about\n"
10006 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010007
10008ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010009 show_bgp_ipv6_neighbor_advertised_route_cmd,
10010 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10011 SHOW_STR
10012 BGP_STR
10013 "Address family\n"
10014 "Detailed information on TCP and BGP neighbor connections\n"
10015 "Neighbor to display information about\n"
10016 "Neighbor to display information about\n"
10017 "Display the routes advertised to a BGP neighbor\n")
10018
10019/* old command */
paulbb46e942003-10-24 19:02:03 +000010020ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010021 ipv6_bgp_neighbor_advertised_route_cmd,
10022 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10023 SHOW_STR
10024 IPV6_STR
10025 BGP_STR
10026 "Detailed information on TCP and BGP neighbor connections\n"
10027 "Neighbor to display information about\n"
10028 "Neighbor to display information about\n"
10029 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010030
paul718e3742002-12-13 20:15:29 +000010031/* old command */
10032DEFUN (ipv6_mbgp_neighbor_advertised_route,
10033 ipv6_mbgp_neighbor_advertised_route_cmd,
10034 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10035 SHOW_STR
10036 IPV6_STR
10037 MBGP_STR
10038 "Detailed information on TCP and BGP neighbor connections\n"
10039 "Neighbor to display information about\n"
10040 "Neighbor to display information about\n"
10041 "Display the routes advertised to a BGP neighbor\n")
10042{
paulbb46e942003-10-24 19:02:03 +000010043 struct peer *peer;
10044
10045 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10046 if (! peer)
10047 return CMD_WARNING;
10048
10049 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010050}
10051#endif /* HAVE_IPV6 */
10052
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010053DEFUN (show_ip_bgp_view_neighbor_received_routes,
10054 show_ip_bgp_view_neighbor_received_routes_cmd,
10055 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10056 SHOW_STR
10057 IP_STR
10058 BGP_STR
10059 "BGP view\n"
10060 "View name\n"
10061 "Detailed information on TCP and BGP neighbor connections\n"
10062 "Neighbor to display information about\n"
10063 "Neighbor to display information about\n"
10064 "Display the received routes from neighbor\n")
10065{
10066 struct peer *peer;
10067
10068 if (argc == 2)
10069 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10070 else
10071 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10072
10073 if (! peer)
10074 return CMD_WARNING;
10075
10076 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10077}
10078
10079ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010080 show_ip_bgp_neighbor_received_routes_cmd,
10081 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10082 SHOW_STR
10083 IP_STR
10084 BGP_STR
10085 "Detailed information on TCP and BGP neighbor connections\n"
10086 "Neighbor to display information about\n"
10087 "Neighbor to display information about\n"
10088 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010089
10090DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10091 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10092 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10093 SHOW_STR
10094 IP_STR
10095 BGP_STR
10096 "Address family\n"
10097 "Address Family modifier\n"
10098 "Address Family modifier\n"
10099 "Detailed information on TCP and BGP neighbor connections\n"
10100 "Neighbor to display information about\n"
10101 "Neighbor to display information about\n"
10102 "Display the received routes from neighbor\n")
10103{
paulbb46e942003-10-24 19:02:03 +000010104 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010105
paulbb46e942003-10-24 19:02:03 +000010106 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10107 if (! peer)
10108 return CMD_WARNING;
10109
10110 if (strncmp (argv[0], "m", 1) == 0)
10111 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10112
10113 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010114}
10115
Michael Lambert95cbbd22010-07-23 14:43:04 -040010116DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10117 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10118#ifdef HAVE_IPV6
10119 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10120#else
10121 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10122#endif
10123 SHOW_STR
10124 BGP_STR
10125 "BGP view\n"
10126 "BGP view name\n"
10127 "Address family\n"
10128#ifdef HAVE_IPV6
10129 "Address family\n"
10130#endif
10131 "Address family modifier\n"
10132 "Address family modifier\n"
10133 "Detailed information on TCP and BGP neighbor connections\n"
10134 "Neighbor to display information about\n"
10135 "Neighbor to display information about\n"
10136 "Display the advertised routes to neighbor\n"
10137 "Display the received routes from neighbor\n")
10138{
10139 int afi;
10140 int safi;
10141 int in;
10142 struct peer *peer;
10143
10144#ifdef HAVE_IPV6
10145 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10146#else
10147 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10148#endif
10149
10150 if (! peer)
10151 return CMD_WARNING;
10152
10153#ifdef HAVE_IPV6
10154 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10155 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10156 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10157#else
10158 afi = AFI_IP;
10159 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10160 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10161#endif
10162
10163 return peer_adj_routes (vty, peer, afi, safi, in);
10164}
10165
paul718e3742002-12-13 20:15:29 +000010166DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10167 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10168 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10169 SHOW_STR
10170 IP_STR
10171 BGP_STR
10172 "Detailed information on TCP and BGP neighbor connections\n"
10173 "Neighbor to display information about\n"
10174 "Neighbor to display information about\n"
10175 "Display information received from a BGP neighbor\n"
10176 "Display the prefixlist filter\n")
10177{
10178 char name[BUFSIZ];
10179 union sockunion *su;
10180 struct peer *peer;
10181 int count;
10182
10183 su = sockunion_str2su (argv[0]);
10184 if (su == NULL)
10185 return CMD_WARNING;
10186
10187 peer = peer_lookup (NULL, su);
10188 if (! peer)
10189 return CMD_WARNING;
10190
10191 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10192 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10193 if (count)
10194 {
10195 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10196 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10197 }
10198
10199 return CMD_SUCCESS;
10200}
10201
10202DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10203 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10204 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10205 SHOW_STR
10206 IP_STR
10207 BGP_STR
10208 "Address family\n"
10209 "Address Family modifier\n"
10210 "Address Family modifier\n"
10211 "Detailed information on TCP and BGP neighbor connections\n"
10212 "Neighbor to display information about\n"
10213 "Neighbor to display information about\n"
10214 "Display information received from a BGP neighbor\n"
10215 "Display the prefixlist filter\n")
10216{
10217 char name[BUFSIZ];
10218 union sockunion *su;
10219 struct peer *peer;
10220 int count;
10221
10222 su = sockunion_str2su (argv[1]);
10223 if (su == NULL)
10224 return CMD_WARNING;
10225
10226 peer = peer_lookup (NULL, su);
10227 if (! peer)
10228 return CMD_WARNING;
10229
10230 if (strncmp (argv[0], "m", 1) == 0)
10231 {
10232 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10233 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10234 if (count)
10235 {
10236 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10237 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10238 }
10239 }
10240 else
10241 {
10242 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10243 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10244 if (count)
10245 {
10246 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10247 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10248 }
10249 }
10250
10251 return CMD_SUCCESS;
10252}
10253
10254
10255#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010256ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010257 show_bgp_neighbor_received_routes_cmd,
10258 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10259 SHOW_STR
10260 BGP_STR
10261 "Detailed information on TCP and BGP neighbor connections\n"
10262 "Neighbor to display information about\n"
10263 "Neighbor to display information about\n"
10264 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010265
paulbb46e942003-10-24 19:02:03 +000010266ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010267 show_bgp_ipv6_neighbor_received_routes_cmd,
10268 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10269 SHOW_STR
10270 BGP_STR
10271 "Address family\n"
10272 "Detailed information on TCP and BGP neighbor connections\n"
10273 "Neighbor to display information about\n"
10274 "Neighbor to display information about\n"
10275 "Display the received routes from neighbor\n")
10276
10277DEFUN (show_bgp_neighbor_received_prefix_filter,
10278 show_bgp_neighbor_received_prefix_filter_cmd,
10279 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10280 SHOW_STR
10281 BGP_STR
10282 "Detailed information on TCP and BGP neighbor connections\n"
10283 "Neighbor to display information about\n"
10284 "Neighbor to display information about\n"
10285 "Display information received from a BGP neighbor\n"
10286 "Display the prefixlist filter\n")
10287{
10288 char name[BUFSIZ];
10289 union sockunion *su;
10290 struct peer *peer;
10291 int count;
10292
10293 su = sockunion_str2su (argv[0]);
10294 if (su == NULL)
10295 return CMD_WARNING;
10296
10297 peer = peer_lookup (NULL, su);
10298 if (! peer)
10299 return CMD_WARNING;
10300
10301 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10302 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10303 if (count)
10304 {
10305 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10306 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10307 }
10308
10309 return CMD_SUCCESS;
10310}
10311
10312ALIAS (show_bgp_neighbor_received_prefix_filter,
10313 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10314 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10315 SHOW_STR
10316 BGP_STR
10317 "Address family\n"
10318 "Detailed information on TCP and BGP neighbor connections\n"
10319 "Neighbor to display information about\n"
10320 "Neighbor to display information about\n"
10321 "Display information received from a BGP neighbor\n"
10322 "Display the prefixlist filter\n")
10323
10324/* old command */
paulbb46e942003-10-24 19:02:03 +000010325ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010326 ipv6_bgp_neighbor_received_routes_cmd,
10327 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10328 SHOW_STR
10329 IPV6_STR
10330 BGP_STR
10331 "Detailed information on TCP and BGP neighbor connections\n"
10332 "Neighbor to display information about\n"
10333 "Neighbor to display information about\n"
10334 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010335
10336/* old command */
10337DEFUN (ipv6_mbgp_neighbor_received_routes,
10338 ipv6_mbgp_neighbor_received_routes_cmd,
10339 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10340 SHOW_STR
10341 IPV6_STR
10342 MBGP_STR
10343 "Detailed information on TCP and BGP neighbor connections\n"
10344 "Neighbor to display information about\n"
10345 "Neighbor to display information about\n"
10346 "Display the received routes from neighbor\n")
10347{
paulbb46e942003-10-24 19:02:03 +000010348 struct peer *peer;
10349
10350 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10351 if (! peer)
10352 return CMD_WARNING;
10353
10354 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010355}
paulbb46e942003-10-24 19:02:03 +000010356
10357DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10358 show_bgp_view_neighbor_received_prefix_filter_cmd,
10359 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10360 SHOW_STR
10361 BGP_STR
10362 "BGP view\n"
10363 "View name\n"
10364 "Detailed information on TCP and BGP neighbor connections\n"
10365 "Neighbor to display information about\n"
10366 "Neighbor to display information about\n"
10367 "Display information received from a BGP neighbor\n"
10368 "Display the prefixlist filter\n")
10369{
10370 char name[BUFSIZ];
10371 union sockunion *su;
10372 struct peer *peer;
10373 struct bgp *bgp;
10374 int count;
10375
10376 /* BGP structure lookup. */
10377 bgp = bgp_lookup_by_name (argv[0]);
10378 if (bgp == NULL)
10379 {
10380 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10381 return CMD_WARNING;
10382 }
10383
10384 su = sockunion_str2su (argv[1]);
10385 if (su == NULL)
10386 return CMD_WARNING;
10387
10388 peer = peer_lookup (bgp, su);
10389 if (! peer)
10390 return CMD_WARNING;
10391
10392 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10393 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10394 if (count)
10395 {
10396 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10397 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10398 }
10399
10400 return CMD_SUCCESS;
10401}
10402
10403ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10404 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10405 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10406 SHOW_STR
10407 BGP_STR
10408 "BGP view\n"
10409 "View name\n"
10410 "Address family\n"
10411 "Detailed information on TCP and BGP neighbor connections\n"
10412 "Neighbor to display information about\n"
10413 "Neighbor to display information about\n"
10414 "Display information received from a BGP neighbor\n"
10415 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010416#endif /* HAVE_IPV6 */
10417
paul94f2b392005-06-28 12:44:16 +000010418static int
paulbb46e942003-10-24 19:02:03 +000010419bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010420 safi_t safi, enum bgp_show_type type)
10421{
paul718e3742002-12-13 20:15:29 +000010422 if (! peer || ! peer->afc[afi][safi])
10423 {
10424 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010425 return CMD_WARNING;
10426 }
10427
ajs5a646652004-11-05 01:25:55 +000010428 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010429}
10430
10431DEFUN (show_ip_bgp_neighbor_routes,
10432 show_ip_bgp_neighbor_routes_cmd,
10433 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10434 SHOW_STR
10435 IP_STR
10436 BGP_STR
10437 "Detailed information on TCP and BGP neighbor connections\n"
10438 "Neighbor to display information about\n"
10439 "Neighbor to display information about\n"
10440 "Display routes learned from neighbor\n")
10441{
paulbb46e942003-10-24 19:02:03 +000010442 struct peer *peer;
10443
10444 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10445 if (! peer)
10446 return CMD_WARNING;
10447
10448 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010449 bgp_show_type_neighbor);
10450}
10451
10452DEFUN (show_ip_bgp_neighbor_flap,
10453 show_ip_bgp_neighbor_flap_cmd,
10454 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10455 SHOW_STR
10456 IP_STR
10457 BGP_STR
10458 "Detailed information on TCP and BGP neighbor connections\n"
10459 "Neighbor to display information about\n"
10460 "Neighbor to display information about\n"
10461 "Display flap statistics of the routes learned from neighbor\n")
10462{
paulbb46e942003-10-24 19:02:03 +000010463 struct peer *peer;
10464
10465 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10466 if (! peer)
10467 return CMD_WARNING;
10468
10469 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010470 bgp_show_type_flap_neighbor);
10471}
10472
10473DEFUN (show_ip_bgp_neighbor_damp,
10474 show_ip_bgp_neighbor_damp_cmd,
10475 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10476 SHOW_STR
10477 IP_STR
10478 BGP_STR
10479 "Detailed information on TCP and BGP neighbor connections\n"
10480 "Neighbor to display information about\n"
10481 "Neighbor to display information about\n"
10482 "Display the dampened routes received from neighbor\n")
10483{
paulbb46e942003-10-24 19:02:03 +000010484 struct peer *peer;
10485
10486 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10487 if (! peer)
10488 return CMD_WARNING;
10489
10490 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010491 bgp_show_type_damp_neighbor);
10492}
10493
10494DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10495 show_ip_bgp_ipv4_neighbor_routes_cmd,
10496 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10497 SHOW_STR
10498 IP_STR
10499 BGP_STR
10500 "Address family\n"
10501 "Address Family modifier\n"
10502 "Address Family modifier\n"
10503 "Detailed information on TCP and BGP neighbor connections\n"
10504 "Neighbor to display information about\n"
10505 "Neighbor to display information about\n"
10506 "Display routes learned from neighbor\n")
10507{
paulbb46e942003-10-24 19:02:03 +000010508 struct peer *peer;
10509
10510 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10511 if (! peer)
10512 return CMD_WARNING;
10513
paul718e3742002-12-13 20:15:29 +000010514 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010515 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010516 bgp_show_type_neighbor);
10517
paulbb46e942003-10-24 19:02:03 +000010518 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010519 bgp_show_type_neighbor);
10520}
paulbb46e942003-10-24 19:02:03 +000010521
paulfee0f4c2004-09-13 05:12:46 +000010522DEFUN (show_ip_bgp_view_rsclient,
10523 show_ip_bgp_view_rsclient_cmd,
10524 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10525 SHOW_STR
10526 IP_STR
10527 BGP_STR
10528 "BGP view\n"
10529 "BGP view name\n"
10530 "Information about Route Server Client\n"
10531 NEIGHBOR_ADDR_STR)
10532{
10533 struct bgp_table *table;
10534 struct peer *peer;
10535
10536 if (argc == 2)
10537 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10538 else
10539 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10540
10541 if (! peer)
10542 return CMD_WARNING;
10543
10544 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10545 {
10546 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10547 VTY_NEWLINE);
10548 return CMD_WARNING;
10549 }
10550
10551 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10552 PEER_FLAG_RSERVER_CLIENT))
10553 {
10554 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10555 VTY_NEWLINE);
10556 return CMD_WARNING;
10557 }
10558
10559 table = peer->rib[AFI_IP][SAFI_UNICAST];
10560
ajs5a646652004-11-05 01:25:55 +000010561 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010562}
10563
10564ALIAS (show_ip_bgp_view_rsclient,
10565 show_ip_bgp_rsclient_cmd,
10566 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10567 SHOW_STR
10568 IP_STR
10569 BGP_STR
10570 "Information about Route Server Client\n"
10571 NEIGHBOR_ADDR_STR)
10572
Michael Lambert95cbbd22010-07-23 14:43:04 -040010573DEFUN (show_bgp_view_ipv4_safi_rsclient,
10574 show_bgp_view_ipv4_safi_rsclient_cmd,
10575 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10576 SHOW_STR
10577 BGP_STR
10578 "BGP view\n"
10579 "BGP view name\n"
10580 "Address family\n"
10581 "Address Family modifier\n"
10582 "Address Family modifier\n"
10583 "Information about Route Server Client\n"
10584 NEIGHBOR_ADDR_STR)
10585{
10586 struct bgp_table *table;
10587 struct peer *peer;
10588 safi_t safi;
10589
10590 if (argc == 3) {
10591 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10592 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10593 } else {
10594 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10595 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10596 }
10597
10598 if (! peer)
10599 return CMD_WARNING;
10600
10601 if (! peer->afc[AFI_IP][safi])
10602 {
10603 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10604 VTY_NEWLINE);
10605 return CMD_WARNING;
10606 }
10607
10608 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10609 PEER_FLAG_RSERVER_CLIENT))
10610 {
10611 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10612 VTY_NEWLINE);
10613 return CMD_WARNING;
10614 }
10615
10616 table = peer->rib[AFI_IP][safi];
10617
10618 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10619}
10620
10621ALIAS (show_bgp_view_ipv4_safi_rsclient,
10622 show_bgp_ipv4_safi_rsclient_cmd,
10623 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10624 SHOW_STR
10625 BGP_STR
10626 "Address family\n"
10627 "Address Family modifier\n"
10628 "Address Family modifier\n"
10629 "Information about Route Server Client\n"
10630 NEIGHBOR_ADDR_STR)
10631
paulfee0f4c2004-09-13 05:12:46 +000010632DEFUN (show_ip_bgp_view_rsclient_route,
10633 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010634 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010635 SHOW_STR
10636 IP_STR
10637 BGP_STR
10638 "BGP view\n"
10639 "BGP view name\n"
10640 "Information about Route Server Client\n"
10641 NEIGHBOR_ADDR_STR
10642 "Network in the BGP routing table to display\n")
10643{
10644 struct bgp *bgp;
10645 struct peer *peer;
10646
10647 /* BGP structure lookup. */
10648 if (argc == 3)
10649 {
10650 bgp = bgp_lookup_by_name (argv[0]);
10651 if (bgp == NULL)
10652 {
10653 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10654 return CMD_WARNING;
10655 }
10656 }
10657 else
10658 {
10659 bgp = bgp_get_default ();
10660 if (bgp == NULL)
10661 {
10662 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10663 return CMD_WARNING;
10664 }
10665 }
10666
10667 if (argc == 3)
10668 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10669 else
10670 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10671
10672 if (! peer)
10673 return CMD_WARNING;
10674
10675 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10676 {
10677 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10678 VTY_NEWLINE);
10679 return CMD_WARNING;
10680}
10681
10682 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10683 PEER_FLAG_RSERVER_CLIENT))
10684 {
10685 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10686 VTY_NEWLINE);
10687 return CMD_WARNING;
10688 }
10689
10690 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10691 (argc == 3) ? argv[2] : argv[1],
10692 AFI_IP, SAFI_UNICAST, NULL, 0);
10693}
10694
10695ALIAS (show_ip_bgp_view_rsclient_route,
10696 show_ip_bgp_rsclient_route_cmd,
10697 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10698 SHOW_STR
10699 IP_STR
10700 BGP_STR
10701 "Information about Route Server Client\n"
10702 NEIGHBOR_ADDR_STR
10703 "Network in the BGP routing table to display\n")
10704
Michael Lambert95cbbd22010-07-23 14:43:04 -040010705DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10706 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10707 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10708 SHOW_STR
10709 BGP_STR
10710 "BGP view\n"
10711 "BGP view name\n"
10712 "Address family\n"
10713 "Address Family modifier\n"
10714 "Address Family modifier\n"
10715 "Information about Route Server Client\n"
10716 NEIGHBOR_ADDR_STR
10717 "Network in the BGP routing table to display\n")
10718{
10719 struct bgp *bgp;
10720 struct peer *peer;
10721 safi_t safi;
10722
10723 /* BGP structure lookup. */
10724 if (argc == 4)
10725 {
10726 bgp = bgp_lookup_by_name (argv[0]);
10727 if (bgp == NULL)
10728 {
10729 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10730 return CMD_WARNING;
10731 }
10732 }
10733 else
10734 {
10735 bgp = bgp_get_default ();
10736 if (bgp == NULL)
10737 {
10738 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10739 return CMD_WARNING;
10740 }
10741 }
10742
10743 if (argc == 4) {
10744 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10745 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10746 } else {
10747 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10748 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10749 }
10750
10751 if (! peer)
10752 return CMD_WARNING;
10753
10754 if (! peer->afc[AFI_IP][safi])
10755 {
10756 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10757 VTY_NEWLINE);
10758 return CMD_WARNING;
10759}
10760
10761 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10762 PEER_FLAG_RSERVER_CLIENT))
10763 {
10764 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10765 VTY_NEWLINE);
10766 return CMD_WARNING;
10767 }
10768
10769 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10770 (argc == 4) ? argv[3] : argv[2],
10771 AFI_IP, safi, NULL, 0);
10772}
10773
10774ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10775 show_bgp_ipv4_safi_rsclient_route_cmd,
10776 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10777 SHOW_STR
10778 BGP_STR
10779 "Address family\n"
10780 "Address Family modifier\n"
10781 "Address Family modifier\n"
10782 "Information about Route Server Client\n"
10783 NEIGHBOR_ADDR_STR
10784 "Network in the BGP routing table to display\n")
10785
paulfee0f4c2004-09-13 05:12:46 +000010786DEFUN (show_ip_bgp_view_rsclient_prefix,
10787 show_ip_bgp_view_rsclient_prefix_cmd,
10788 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10789 SHOW_STR
10790 IP_STR
10791 BGP_STR
10792 "BGP view\n"
10793 "BGP view name\n"
10794 "Information about Route Server Client\n"
10795 NEIGHBOR_ADDR_STR
10796 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10797{
10798 struct bgp *bgp;
10799 struct peer *peer;
10800
10801 /* BGP structure lookup. */
10802 if (argc == 3)
10803 {
10804 bgp = bgp_lookup_by_name (argv[0]);
10805 if (bgp == NULL)
10806 {
10807 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10808 return CMD_WARNING;
10809 }
10810 }
10811 else
10812 {
10813 bgp = bgp_get_default ();
10814 if (bgp == NULL)
10815 {
10816 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10817 return CMD_WARNING;
10818 }
10819 }
10820
10821 if (argc == 3)
10822 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10823 else
10824 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10825
10826 if (! peer)
10827 return CMD_WARNING;
10828
10829 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10830 {
10831 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10832 VTY_NEWLINE);
10833 return CMD_WARNING;
10834}
10835
10836 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10837 PEER_FLAG_RSERVER_CLIENT))
10838{
10839 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10840 VTY_NEWLINE);
10841 return CMD_WARNING;
10842 }
10843
10844 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10845 (argc == 3) ? argv[2] : argv[1],
10846 AFI_IP, SAFI_UNICAST, NULL, 1);
10847}
10848
10849ALIAS (show_ip_bgp_view_rsclient_prefix,
10850 show_ip_bgp_rsclient_prefix_cmd,
10851 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10852 SHOW_STR
10853 IP_STR
10854 BGP_STR
10855 "Information about Route Server Client\n"
10856 NEIGHBOR_ADDR_STR
10857 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10858
Michael Lambert95cbbd22010-07-23 14:43:04 -040010859DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10860 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10861 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10862 SHOW_STR
10863 BGP_STR
10864 "BGP view\n"
10865 "BGP view name\n"
10866 "Address family\n"
10867 "Address Family modifier\n"
10868 "Address Family modifier\n"
10869 "Information about Route Server Client\n"
10870 NEIGHBOR_ADDR_STR
10871 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10872{
10873 struct bgp *bgp;
10874 struct peer *peer;
10875 safi_t safi;
10876
10877 /* BGP structure lookup. */
10878 if (argc == 4)
10879 {
10880 bgp = bgp_lookup_by_name (argv[0]);
10881 if (bgp == NULL)
10882 {
10883 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10884 return CMD_WARNING;
10885 }
10886 }
10887 else
10888 {
10889 bgp = bgp_get_default ();
10890 if (bgp == NULL)
10891 {
10892 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10893 return CMD_WARNING;
10894 }
10895 }
10896
10897 if (argc == 4) {
10898 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10899 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10900 } else {
10901 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10902 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10903 }
10904
10905 if (! peer)
10906 return CMD_WARNING;
10907
10908 if (! peer->afc[AFI_IP][safi])
10909 {
10910 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10911 VTY_NEWLINE);
10912 return CMD_WARNING;
10913}
10914
10915 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10916 PEER_FLAG_RSERVER_CLIENT))
10917{
10918 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10919 VTY_NEWLINE);
10920 return CMD_WARNING;
10921 }
10922
10923 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10924 (argc == 4) ? argv[3] : argv[2],
10925 AFI_IP, safi, NULL, 1);
10926}
10927
10928ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10929 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10930 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10931 SHOW_STR
10932 BGP_STR
10933 "Address family\n"
10934 "Address Family modifier\n"
10935 "Address Family modifier\n"
10936 "Information about Route Server Client\n"
10937 NEIGHBOR_ADDR_STR
10938 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010939
paul718e3742002-12-13 20:15:29 +000010940#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010941DEFUN (show_bgp_view_neighbor_routes,
10942 show_bgp_view_neighbor_routes_cmd,
10943 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10944 SHOW_STR
10945 BGP_STR
10946 "BGP view\n"
10947 "BGP view name\n"
10948 "Detailed information on TCP and BGP neighbor connections\n"
10949 "Neighbor to display information about\n"
10950 "Neighbor to display information about\n"
10951 "Display routes learned from neighbor\n")
10952{
10953 struct peer *peer;
10954
10955 if (argc == 2)
10956 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10957 else
10958 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10959
10960 if (! peer)
10961 return CMD_WARNING;
10962
10963 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10964 bgp_show_type_neighbor);
10965}
10966
10967ALIAS (show_bgp_view_neighbor_routes,
10968 show_bgp_view_ipv6_neighbor_routes_cmd,
10969 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10970 SHOW_STR
10971 BGP_STR
10972 "BGP view\n"
10973 "BGP view name\n"
10974 "Address family\n"
10975 "Detailed information on TCP and BGP neighbor connections\n"
10976 "Neighbor to display information about\n"
10977 "Neighbor to display information about\n"
10978 "Display routes learned from neighbor\n")
10979
10980DEFUN (show_bgp_view_neighbor_damp,
10981 show_bgp_view_neighbor_damp_cmd,
10982 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10983 SHOW_STR
10984 BGP_STR
10985 "BGP view\n"
10986 "BGP view name\n"
10987 "Detailed information on TCP and BGP neighbor connections\n"
10988 "Neighbor to display information about\n"
10989 "Neighbor to display information about\n"
10990 "Display the dampened routes received from neighbor\n")
10991{
10992 struct peer *peer;
10993
10994 if (argc == 2)
10995 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10996 else
10997 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10998
10999 if (! peer)
11000 return CMD_WARNING;
11001
11002 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11003 bgp_show_type_damp_neighbor);
11004}
11005
11006ALIAS (show_bgp_view_neighbor_damp,
11007 show_bgp_view_ipv6_neighbor_damp_cmd,
11008 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11009 SHOW_STR
11010 BGP_STR
11011 "BGP view\n"
11012 "BGP view name\n"
11013 "Address family\n"
11014 "Detailed information on TCP and BGP neighbor connections\n"
11015 "Neighbor to display information about\n"
11016 "Neighbor to display information about\n"
11017 "Display the dampened routes received from neighbor\n")
11018
11019DEFUN (show_bgp_view_neighbor_flap,
11020 show_bgp_view_neighbor_flap_cmd,
11021 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11022 SHOW_STR
11023 BGP_STR
11024 "BGP view\n"
11025 "BGP view name\n"
11026 "Detailed information on TCP and BGP neighbor connections\n"
11027 "Neighbor to display information about\n"
11028 "Neighbor to display information about\n"
11029 "Display flap statistics of the routes learned from neighbor\n")
11030{
11031 struct peer *peer;
11032
11033 if (argc == 2)
11034 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11035 else
11036 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11037
11038 if (! peer)
11039 return CMD_WARNING;
11040
11041 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11042 bgp_show_type_flap_neighbor);
11043}
11044
11045ALIAS (show_bgp_view_neighbor_flap,
11046 show_bgp_view_ipv6_neighbor_flap_cmd,
11047 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11048 SHOW_STR
11049 BGP_STR
11050 "BGP view\n"
11051 "BGP view name\n"
11052 "Address family\n"
11053 "Detailed information on TCP and BGP neighbor connections\n"
11054 "Neighbor to display information about\n"
11055 "Neighbor to display information about\n"
11056 "Display flap statistics of the routes learned from neighbor\n")
11057
11058ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011059 show_bgp_neighbor_routes_cmd,
11060 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11061 SHOW_STR
11062 BGP_STR
11063 "Detailed information on TCP and BGP neighbor connections\n"
11064 "Neighbor to display information about\n"
11065 "Neighbor to display information about\n"
11066 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011067
paulbb46e942003-10-24 19:02:03 +000011068
11069ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011070 show_bgp_ipv6_neighbor_routes_cmd,
11071 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11072 SHOW_STR
11073 BGP_STR
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 routes learned from neighbor\n")
11079
11080/* old command */
paulbb46e942003-10-24 19:02:03 +000011081ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011082 ipv6_bgp_neighbor_routes_cmd,
11083 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11084 SHOW_STR
11085 IPV6_STR
11086 BGP_STR
11087 "Detailed information on TCP and BGP neighbor connections\n"
11088 "Neighbor to display information about\n"
11089 "Neighbor to display information about\n"
11090 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011091
11092/* old command */
11093DEFUN (ipv6_mbgp_neighbor_routes,
11094 ipv6_mbgp_neighbor_routes_cmd,
11095 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11096 SHOW_STR
11097 IPV6_STR
11098 MBGP_STR
11099 "Detailed information on TCP and BGP neighbor connections\n"
11100 "Neighbor to display information about\n"
11101 "Neighbor to display information about\n"
11102 "Display routes learned from neighbor\n")
11103{
paulbb46e942003-10-24 19:02:03 +000011104 struct peer *peer;
11105
11106 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11107 if (! peer)
11108 return CMD_WARNING;
11109
11110 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011111 bgp_show_type_neighbor);
11112}
paulbb46e942003-10-24 19:02:03 +000011113
11114ALIAS (show_bgp_view_neighbor_flap,
11115 show_bgp_neighbor_flap_cmd,
11116 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11117 SHOW_STR
11118 BGP_STR
11119 "Detailed information on TCP and BGP neighbor connections\n"
11120 "Neighbor to display information about\n"
11121 "Neighbor to display information about\n"
11122 "Display flap statistics of the routes learned from neighbor\n")
11123
11124ALIAS (show_bgp_view_neighbor_flap,
11125 show_bgp_ipv6_neighbor_flap_cmd,
11126 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11127 SHOW_STR
11128 BGP_STR
11129 "Address family\n"
11130 "Detailed information on TCP and BGP neighbor connections\n"
11131 "Neighbor to display information about\n"
11132 "Neighbor to display information about\n"
11133 "Display flap statistics of the routes learned from neighbor\n")
11134
11135ALIAS (show_bgp_view_neighbor_damp,
11136 show_bgp_neighbor_damp_cmd,
11137 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11138 SHOW_STR
11139 BGP_STR
11140 "Detailed information on TCP and BGP neighbor connections\n"
11141 "Neighbor to display information about\n"
11142 "Neighbor to display information about\n"
11143 "Display the dampened routes received from neighbor\n")
11144
11145ALIAS (show_bgp_view_neighbor_damp,
11146 show_bgp_ipv6_neighbor_damp_cmd,
11147 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11148 SHOW_STR
11149 BGP_STR
11150 "Address family\n"
11151 "Detailed information on TCP and BGP neighbor connections\n"
11152 "Neighbor to display information about\n"
11153 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011154 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011155
11156DEFUN (show_bgp_view_rsclient,
11157 show_bgp_view_rsclient_cmd,
11158 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11159 SHOW_STR
11160 BGP_STR
11161 "BGP view\n"
11162 "BGP view name\n"
11163 "Information about Route Server Client\n"
11164 NEIGHBOR_ADDR_STR)
11165{
11166 struct bgp_table *table;
11167 struct peer *peer;
11168
11169 if (argc == 2)
11170 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11171 else
11172 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11173
11174 if (! peer)
11175 return CMD_WARNING;
11176
11177 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11178 {
11179 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11180 VTY_NEWLINE);
11181 return CMD_WARNING;
11182 }
11183
11184 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11185 PEER_FLAG_RSERVER_CLIENT))
11186 {
11187 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11188 VTY_NEWLINE);
11189 return CMD_WARNING;
11190 }
11191
11192 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11193
ajs5a646652004-11-05 01:25:55 +000011194 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011195}
11196
11197ALIAS (show_bgp_view_rsclient,
11198 show_bgp_rsclient_cmd,
11199 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11200 SHOW_STR
11201 BGP_STR
11202 "Information about Route Server Client\n"
11203 NEIGHBOR_ADDR_STR)
11204
Michael Lambert95cbbd22010-07-23 14:43:04 -040011205DEFUN (show_bgp_view_ipv6_safi_rsclient,
11206 show_bgp_view_ipv6_safi_rsclient_cmd,
11207 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11208 SHOW_STR
11209 BGP_STR
11210 "BGP view\n"
11211 "BGP view name\n"
11212 "Address family\n"
11213 "Address Family modifier\n"
11214 "Address Family modifier\n"
11215 "Information about Route Server Client\n"
11216 NEIGHBOR_ADDR_STR)
11217{
11218 struct bgp_table *table;
11219 struct peer *peer;
11220 safi_t safi;
11221
11222 if (argc == 3) {
11223 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11224 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11225 } else {
11226 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11227 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11228 }
11229
11230 if (! peer)
11231 return CMD_WARNING;
11232
11233 if (! peer->afc[AFI_IP6][safi])
11234 {
11235 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11236 VTY_NEWLINE);
11237 return CMD_WARNING;
11238 }
11239
11240 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11241 PEER_FLAG_RSERVER_CLIENT))
11242 {
11243 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11244 VTY_NEWLINE);
11245 return CMD_WARNING;
11246 }
11247
11248 table = peer->rib[AFI_IP6][safi];
11249
11250 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11251}
11252
11253ALIAS (show_bgp_view_ipv6_safi_rsclient,
11254 show_bgp_ipv6_safi_rsclient_cmd,
11255 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11256 SHOW_STR
11257 BGP_STR
11258 "Address family\n"
11259 "Address Family modifier\n"
11260 "Address Family modifier\n"
11261 "Information about Route Server Client\n"
11262 NEIGHBOR_ADDR_STR)
11263
paulfee0f4c2004-09-13 05:12:46 +000011264DEFUN (show_bgp_view_rsclient_route,
11265 show_bgp_view_rsclient_route_cmd,
11266 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11267 SHOW_STR
11268 BGP_STR
11269 "BGP view\n"
11270 "BGP view name\n"
11271 "Information about Route Server Client\n"
11272 NEIGHBOR_ADDR_STR
11273 "Network in the BGP routing table to display\n")
11274{
11275 struct bgp *bgp;
11276 struct peer *peer;
11277
11278 /* BGP structure lookup. */
11279 if (argc == 3)
11280 {
11281 bgp = bgp_lookup_by_name (argv[0]);
11282 if (bgp == NULL)
11283 {
11284 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11285 return CMD_WARNING;
11286 }
11287 }
11288 else
11289 {
11290 bgp = bgp_get_default ();
11291 if (bgp == NULL)
11292 {
11293 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11294 return CMD_WARNING;
11295 }
11296 }
11297
11298 if (argc == 3)
11299 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11300 else
11301 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11302
11303 if (! peer)
11304 return CMD_WARNING;
11305
11306 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11307 {
11308 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11309 VTY_NEWLINE);
11310 return CMD_WARNING;
11311 }
11312
11313 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11314 PEER_FLAG_RSERVER_CLIENT))
11315 {
11316 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11317 VTY_NEWLINE);
11318 return CMD_WARNING;
11319 }
11320
11321 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11322 (argc == 3) ? argv[2] : argv[1],
11323 AFI_IP6, SAFI_UNICAST, NULL, 0);
11324}
11325
11326ALIAS (show_bgp_view_rsclient_route,
11327 show_bgp_rsclient_route_cmd,
11328 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11329 SHOW_STR
11330 BGP_STR
11331 "Information about Route Server Client\n"
11332 NEIGHBOR_ADDR_STR
11333 "Network in the BGP routing table to display\n")
11334
Michael Lambert95cbbd22010-07-23 14:43:04 -040011335DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11336 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11337 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11338 SHOW_STR
11339 BGP_STR
11340 "BGP view\n"
11341 "BGP view name\n"
11342 "Address family\n"
11343 "Address Family modifier\n"
11344 "Address Family modifier\n"
11345 "Information about Route Server Client\n"
11346 NEIGHBOR_ADDR_STR
11347 "Network in the BGP routing table to display\n")
11348{
11349 struct bgp *bgp;
11350 struct peer *peer;
11351 safi_t safi;
11352
11353 /* BGP structure lookup. */
11354 if (argc == 4)
11355 {
11356 bgp = bgp_lookup_by_name (argv[0]);
11357 if (bgp == NULL)
11358 {
11359 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11360 return CMD_WARNING;
11361 }
11362 }
11363 else
11364 {
11365 bgp = bgp_get_default ();
11366 if (bgp == NULL)
11367 {
11368 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11369 return CMD_WARNING;
11370 }
11371 }
11372
11373 if (argc == 4) {
11374 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11375 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11376 } else {
11377 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11378 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11379 }
11380
11381 if (! peer)
11382 return CMD_WARNING;
11383
11384 if (! peer->afc[AFI_IP6][safi])
11385 {
11386 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11387 VTY_NEWLINE);
11388 return CMD_WARNING;
11389}
11390
11391 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11392 PEER_FLAG_RSERVER_CLIENT))
11393 {
11394 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11395 VTY_NEWLINE);
11396 return CMD_WARNING;
11397 }
11398
11399 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11400 (argc == 4) ? argv[3] : argv[2],
11401 AFI_IP6, safi, NULL, 0);
11402}
11403
11404ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11405 show_bgp_ipv6_safi_rsclient_route_cmd,
11406 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11407 SHOW_STR
11408 BGP_STR
11409 "Address family\n"
11410 "Address Family modifier\n"
11411 "Address Family modifier\n"
11412 "Information about Route Server Client\n"
11413 NEIGHBOR_ADDR_STR
11414 "Network in the BGP routing table to display\n")
11415
paulfee0f4c2004-09-13 05:12:46 +000011416DEFUN (show_bgp_view_rsclient_prefix,
11417 show_bgp_view_rsclient_prefix_cmd,
11418 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11419 SHOW_STR
11420 BGP_STR
11421 "BGP view\n"
11422 "BGP view name\n"
11423 "Information about Route Server Client\n"
11424 NEIGHBOR_ADDR_STR
11425 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11426{
11427 struct bgp *bgp;
11428 struct peer *peer;
11429
11430 /* BGP structure lookup. */
11431 if (argc == 3)
11432 {
11433 bgp = bgp_lookup_by_name (argv[0]);
11434 if (bgp == NULL)
11435 {
11436 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11437 return CMD_WARNING;
11438 }
11439 }
11440 else
11441 {
11442 bgp = bgp_get_default ();
11443 if (bgp == NULL)
11444 {
11445 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11446 return CMD_WARNING;
11447 }
11448 }
11449
11450 if (argc == 3)
11451 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11452 else
11453 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11454
11455 if (! peer)
11456 return CMD_WARNING;
11457
11458 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11459 {
11460 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11461 VTY_NEWLINE);
11462 return CMD_WARNING;
11463 }
11464
11465 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11466 PEER_FLAG_RSERVER_CLIENT))
11467 {
11468 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11469 VTY_NEWLINE);
11470 return CMD_WARNING;
11471 }
11472
11473 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11474 (argc == 3) ? argv[2] : argv[1],
11475 AFI_IP6, SAFI_UNICAST, NULL, 1);
11476}
11477
11478ALIAS (show_bgp_view_rsclient_prefix,
11479 show_bgp_rsclient_prefix_cmd,
11480 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11481 SHOW_STR
11482 BGP_STR
11483 "Information about Route Server Client\n"
11484 NEIGHBOR_ADDR_STR
11485 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11486
Michael Lambert95cbbd22010-07-23 14:43:04 -040011487DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11488 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11489 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11490 SHOW_STR
11491 BGP_STR
11492 "BGP view\n"
11493 "BGP view name\n"
11494 "Address family\n"
11495 "Address Family modifier\n"
11496 "Address Family modifier\n"
11497 "Information about Route Server Client\n"
11498 NEIGHBOR_ADDR_STR
11499 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11500{
11501 struct bgp *bgp;
11502 struct peer *peer;
11503 safi_t safi;
11504
11505 /* BGP structure lookup. */
11506 if (argc == 4)
11507 {
11508 bgp = bgp_lookup_by_name (argv[0]);
11509 if (bgp == NULL)
11510 {
11511 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11512 return CMD_WARNING;
11513 }
11514 }
11515 else
11516 {
11517 bgp = bgp_get_default ();
11518 if (bgp == NULL)
11519 {
11520 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11521 return CMD_WARNING;
11522 }
11523 }
11524
11525 if (argc == 4) {
11526 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11527 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11528 } else {
11529 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11530 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11531 }
11532
11533 if (! peer)
11534 return CMD_WARNING;
11535
11536 if (! peer->afc[AFI_IP6][safi])
11537 {
11538 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11539 VTY_NEWLINE);
11540 return CMD_WARNING;
11541}
11542
11543 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11544 PEER_FLAG_RSERVER_CLIENT))
11545{
11546 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11547 VTY_NEWLINE);
11548 return CMD_WARNING;
11549 }
11550
11551 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11552 (argc == 4) ? argv[3] : argv[2],
11553 AFI_IP6, safi, NULL, 1);
11554}
11555
11556ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11557 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11558 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11559 SHOW_STR
11560 BGP_STR
11561 "Address family\n"
11562 "Address Family modifier\n"
11563 "Address Family modifier\n"
11564 "Information about Route Server Client\n"
11565 NEIGHBOR_ADDR_STR
11566 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11567
paul718e3742002-12-13 20:15:29 +000011568#endif /* HAVE_IPV6 */
11569
11570struct bgp_table *bgp_distance_table;
11571
11572struct bgp_distance
11573{
11574 /* Distance value for the IP source prefix. */
11575 u_char distance;
11576
11577 /* Name of the access-list to be matched. */
11578 char *access_list;
11579};
11580
paul94f2b392005-06-28 12:44:16 +000011581static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011582bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011583{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011584 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011585}
11586
paul94f2b392005-06-28 12:44:16 +000011587static void
paul718e3742002-12-13 20:15:29 +000011588bgp_distance_free (struct bgp_distance *bdistance)
11589{
11590 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11591}
11592
paul94f2b392005-06-28 12:44:16 +000011593static int
paulfd79ac92004-10-13 05:06:08 +000011594bgp_distance_set (struct vty *vty, const char *distance_str,
11595 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011596{
11597 int ret;
11598 struct prefix_ipv4 p;
11599 u_char distance;
11600 struct bgp_node *rn;
11601 struct bgp_distance *bdistance;
11602
11603 ret = str2prefix_ipv4 (ip_str, &p);
11604 if (ret == 0)
11605 {
11606 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11607 return CMD_WARNING;
11608 }
11609
11610 distance = atoi (distance_str);
11611
11612 /* Get BGP distance node. */
11613 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11614 if (rn->info)
11615 {
11616 bdistance = rn->info;
11617 bgp_unlock_node (rn);
11618 }
11619 else
11620 {
11621 bdistance = bgp_distance_new ();
11622 rn->info = bdistance;
11623 }
11624
11625 /* Set distance value. */
11626 bdistance->distance = distance;
11627
11628 /* Reset access-list configuration. */
11629 if (bdistance->access_list)
11630 {
11631 free (bdistance->access_list);
11632 bdistance->access_list = NULL;
11633 }
11634 if (access_list_str)
11635 bdistance->access_list = strdup (access_list_str);
11636
11637 return CMD_SUCCESS;
11638}
11639
paul94f2b392005-06-28 12:44:16 +000011640static int
paulfd79ac92004-10-13 05:06:08 +000011641bgp_distance_unset (struct vty *vty, const char *distance_str,
11642 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011643{
11644 int ret;
11645 struct prefix_ipv4 p;
11646 u_char distance;
11647 struct bgp_node *rn;
11648 struct bgp_distance *bdistance;
11649
11650 ret = str2prefix_ipv4 (ip_str, &p);
11651 if (ret == 0)
11652 {
11653 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11654 return CMD_WARNING;
11655 }
11656
11657 distance = atoi (distance_str);
11658
11659 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11660 if (! rn)
11661 {
11662 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11663 return CMD_WARNING;
11664 }
11665
11666 bdistance = rn->info;
11667
11668 if (bdistance->access_list)
11669 free (bdistance->access_list);
11670 bgp_distance_free (bdistance);
11671
11672 rn->info = NULL;
11673 bgp_unlock_node (rn);
11674 bgp_unlock_node (rn);
11675
11676 return CMD_SUCCESS;
11677}
11678
paul718e3742002-12-13 20:15:29 +000011679/* Apply BGP information to distance method. */
11680u_char
11681bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11682{
11683 struct bgp_node *rn;
11684 struct prefix_ipv4 q;
11685 struct peer *peer;
11686 struct bgp_distance *bdistance;
11687 struct access_list *alist;
11688 struct bgp_static *bgp_static;
11689
11690 if (! bgp)
11691 return 0;
11692
11693 if (p->family != AF_INET)
11694 return 0;
11695
11696 peer = rinfo->peer;
11697
11698 if (peer->su.sa.sa_family != AF_INET)
11699 return 0;
11700
11701 memset (&q, 0, sizeof (struct prefix_ipv4));
11702 q.family = AF_INET;
11703 q.prefix = peer->su.sin.sin_addr;
11704 q.prefixlen = IPV4_MAX_BITLEN;
11705
11706 /* Check source address. */
11707 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11708 if (rn)
11709 {
11710 bdistance = rn->info;
11711 bgp_unlock_node (rn);
11712
11713 if (bdistance->access_list)
11714 {
11715 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11716 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11717 return bdistance->distance;
11718 }
11719 else
11720 return bdistance->distance;
11721 }
11722
11723 /* Backdoor check. */
11724 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11725 if (rn)
11726 {
11727 bgp_static = rn->info;
11728 bgp_unlock_node (rn);
11729
11730 if (bgp_static->backdoor)
11731 {
11732 if (bgp->distance_local)
11733 return bgp->distance_local;
11734 else
11735 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11736 }
11737 }
11738
11739 if (peer_sort (peer) == BGP_PEER_EBGP)
11740 {
11741 if (bgp->distance_ebgp)
11742 return bgp->distance_ebgp;
11743 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11744 }
11745 else
11746 {
11747 if (bgp->distance_ibgp)
11748 return bgp->distance_ibgp;
11749 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11750 }
11751}
11752
11753DEFUN (bgp_distance,
11754 bgp_distance_cmd,
11755 "distance bgp <1-255> <1-255> <1-255>",
11756 "Define an administrative distance\n"
11757 "BGP distance\n"
11758 "Distance for routes external to the AS\n"
11759 "Distance for routes internal to the AS\n"
11760 "Distance for local routes\n")
11761{
11762 struct bgp *bgp;
11763
11764 bgp = vty->index;
11765
11766 bgp->distance_ebgp = atoi (argv[0]);
11767 bgp->distance_ibgp = atoi (argv[1]);
11768 bgp->distance_local = atoi (argv[2]);
11769 return CMD_SUCCESS;
11770}
11771
11772DEFUN (no_bgp_distance,
11773 no_bgp_distance_cmd,
11774 "no distance bgp <1-255> <1-255> <1-255>",
11775 NO_STR
11776 "Define an administrative distance\n"
11777 "BGP distance\n"
11778 "Distance for routes external to the AS\n"
11779 "Distance for routes internal to the AS\n"
11780 "Distance for local routes\n")
11781{
11782 struct bgp *bgp;
11783
11784 bgp = vty->index;
11785
11786 bgp->distance_ebgp= 0;
11787 bgp->distance_ibgp = 0;
11788 bgp->distance_local = 0;
11789 return CMD_SUCCESS;
11790}
11791
11792ALIAS (no_bgp_distance,
11793 no_bgp_distance2_cmd,
11794 "no distance bgp",
11795 NO_STR
11796 "Define an administrative distance\n"
11797 "BGP distance\n")
11798
11799DEFUN (bgp_distance_source,
11800 bgp_distance_source_cmd,
11801 "distance <1-255> A.B.C.D/M",
11802 "Define an administrative distance\n"
11803 "Administrative distance\n"
11804 "IP source prefix\n")
11805{
11806 bgp_distance_set (vty, argv[0], argv[1], NULL);
11807 return CMD_SUCCESS;
11808}
11809
11810DEFUN (no_bgp_distance_source,
11811 no_bgp_distance_source_cmd,
11812 "no distance <1-255> A.B.C.D/M",
11813 NO_STR
11814 "Define an administrative distance\n"
11815 "Administrative distance\n"
11816 "IP source prefix\n")
11817{
11818 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11819 return CMD_SUCCESS;
11820}
11821
11822DEFUN (bgp_distance_source_access_list,
11823 bgp_distance_source_access_list_cmd,
11824 "distance <1-255> A.B.C.D/M WORD",
11825 "Define an administrative distance\n"
11826 "Administrative distance\n"
11827 "IP source prefix\n"
11828 "Access list name\n")
11829{
11830 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11831 return CMD_SUCCESS;
11832}
11833
11834DEFUN (no_bgp_distance_source_access_list,
11835 no_bgp_distance_source_access_list_cmd,
11836 "no distance <1-255> A.B.C.D/M WORD",
11837 NO_STR
11838 "Define an administrative distance\n"
11839 "Administrative distance\n"
11840 "IP source prefix\n"
11841 "Access list name\n")
11842{
11843 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11844 return CMD_SUCCESS;
11845}
11846
11847DEFUN (bgp_damp_set,
11848 bgp_damp_set_cmd,
11849 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11850 "BGP Specific commands\n"
11851 "Enable route-flap dampening\n"
11852 "Half-life time for the penalty\n"
11853 "Value to start reusing a route\n"
11854 "Value to start suppressing a route\n"
11855 "Maximum duration to suppress a stable route\n")
11856{
11857 struct bgp *bgp;
11858 int half = DEFAULT_HALF_LIFE * 60;
11859 int reuse = DEFAULT_REUSE;
11860 int suppress = DEFAULT_SUPPRESS;
11861 int max = 4 * half;
11862
11863 if (argc == 4)
11864 {
11865 half = atoi (argv[0]) * 60;
11866 reuse = atoi (argv[1]);
11867 suppress = atoi (argv[2]);
11868 max = atoi (argv[3]) * 60;
11869 }
11870 else if (argc == 1)
11871 {
11872 half = atoi (argv[0]) * 60;
11873 max = 4 * half;
11874 }
11875
11876 bgp = vty->index;
11877 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11878 half, reuse, suppress, max);
11879}
11880
11881ALIAS (bgp_damp_set,
11882 bgp_damp_set2_cmd,
11883 "bgp dampening <1-45>",
11884 "BGP Specific commands\n"
11885 "Enable route-flap dampening\n"
11886 "Half-life time for the penalty\n")
11887
11888ALIAS (bgp_damp_set,
11889 bgp_damp_set3_cmd,
11890 "bgp dampening",
11891 "BGP Specific commands\n"
11892 "Enable route-flap dampening\n")
11893
11894DEFUN (bgp_damp_unset,
11895 bgp_damp_unset_cmd,
11896 "no bgp dampening",
11897 NO_STR
11898 "BGP Specific commands\n"
11899 "Enable route-flap dampening\n")
11900{
11901 struct bgp *bgp;
11902
11903 bgp = vty->index;
11904 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11905}
11906
11907ALIAS (bgp_damp_unset,
11908 bgp_damp_unset2_cmd,
11909 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11910 NO_STR
11911 "BGP Specific commands\n"
11912 "Enable route-flap dampening\n"
11913 "Half-life time for the penalty\n"
11914 "Value to start reusing a route\n"
11915 "Value to start suppressing a route\n"
11916 "Maximum duration to suppress a stable route\n")
11917
11918DEFUN (show_ip_bgp_dampened_paths,
11919 show_ip_bgp_dampened_paths_cmd,
11920 "show ip bgp dampened-paths",
11921 SHOW_STR
11922 IP_STR
11923 BGP_STR
11924 "Display paths suppressed due to dampening\n")
11925{
ajs5a646652004-11-05 01:25:55 +000011926 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11927 NULL);
paul718e3742002-12-13 20:15:29 +000011928}
11929
11930DEFUN (show_ip_bgp_flap_statistics,
11931 show_ip_bgp_flap_statistics_cmd,
11932 "show ip bgp flap-statistics",
11933 SHOW_STR
11934 IP_STR
11935 BGP_STR
11936 "Display flap statistics of routes\n")
11937{
ajs5a646652004-11-05 01:25:55 +000011938 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11939 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011940}
11941
11942/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011943static int
paulfd79ac92004-10-13 05:06:08 +000011944bgp_clear_damp_route (struct vty *vty, const char *view_name,
11945 const char *ip_str, afi_t afi, safi_t safi,
11946 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011947{
11948 int ret;
11949 struct prefix match;
11950 struct bgp_node *rn;
11951 struct bgp_node *rm;
11952 struct bgp_info *ri;
11953 struct bgp_info *ri_temp;
11954 struct bgp *bgp;
11955 struct bgp_table *table;
11956
11957 /* BGP structure lookup. */
11958 if (view_name)
11959 {
11960 bgp = bgp_lookup_by_name (view_name);
11961 if (bgp == NULL)
11962 {
11963 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11964 return CMD_WARNING;
11965 }
11966 }
11967 else
11968 {
11969 bgp = bgp_get_default ();
11970 if (bgp == NULL)
11971 {
11972 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11973 return CMD_WARNING;
11974 }
11975 }
11976
11977 /* Check IP address argument. */
11978 ret = str2prefix (ip_str, &match);
11979 if (! ret)
11980 {
11981 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11982 return CMD_WARNING;
11983 }
11984
11985 match.family = afi2family (afi);
11986
11987 if (safi == SAFI_MPLS_VPN)
11988 {
11989 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11990 {
11991 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11992 continue;
11993
11994 if ((table = rn->info) != NULL)
11995 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011996 {
11997 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11998 {
11999 ri = rm->info;
12000 while (ri)
12001 {
12002 if (ri->extra && ri->extra->damp_info)
12003 {
12004 ri_temp = ri->next;
12005 bgp_damp_info_free (ri->extra->damp_info, 1);
12006 ri = ri_temp;
12007 }
12008 else
12009 ri = ri->next;
12010 }
12011 }
12012
12013 bgp_unlock_node (rm);
12014 }
paul718e3742002-12-13 20:15:29 +000012015 }
12016 }
12017 else
12018 {
12019 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012020 {
12021 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12022 {
12023 ri = rn->info;
12024 while (ri)
12025 {
12026 if (ri->extra && ri->extra->damp_info)
12027 {
12028 ri_temp = ri->next;
12029 bgp_damp_info_free (ri->extra->damp_info, 1);
12030 ri = ri_temp;
12031 }
12032 else
12033 ri = ri->next;
12034 }
12035 }
12036
12037 bgp_unlock_node (rn);
12038 }
paul718e3742002-12-13 20:15:29 +000012039 }
12040
12041 return CMD_SUCCESS;
12042}
12043
12044DEFUN (clear_ip_bgp_dampening,
12045 clear_ip_bgp_dampening_cmd,
12046 "clear ip bgp dampening",
12047 CLEAR_STR
12048 IP_STR
12049 BGP_STR
12050 "Clear route flap dampening information\n")
12051{
12052 bgp_damp_info_clean ();
12053 return CMD_SUCCESS;
12054}
12055
12056DEFUN (clear_ip_bgp_dampening_prefix,
12057 clear_ip_bgp_dampening_prefix_cmd,
12058 "clear ip bgp dampening A.B.C.D/M",
12059 CLEAR_STR
12060 IP_STR
12061 BGP_STR
12062 "Clear route flap dampening information\n"
12063 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12064{
12065 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12066 SAFI_UNICAST, NULL, 1);
12067}
12068
12069DEFUN (clear_ip_bgp_dampening_address,
12070 clear_ip_bgp_dampening_address_cmd,
12071 "clear ip bgp dampening A.B.C.D",
12072 CLEAR_STR
12073 IP_STR
12074 BGP_STR
12075 "Clear route flap dampening information\n"
12076 "Network to clear damping information\n")
12077{
12078 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12079 SAFI_UNICAST, NULL, 0);
12080}
12081
12082DEFUN (clear_ip_bgp_dampening_address_mask,
12083 clear_ip_bgp_dampening_address_mask_cmd,
12084 "clear ip bgp dampening A.B.C.D A.B.C.D",
12085 CLEAR_STR
12086 IP_STR
12087 BGP_STR
12088 "Clear route flap dampening information\n"
12089 "Network to clear damping information\n"
12090 "Network mask\n")
12091{
12092 int ret;
12093 char prefix_str[BUFSIZ];
12094
12095 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12096 if (! ret)
12097 {
12098 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12099 return CMD_WARNING;
12100 }
12101
12102 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12103 SAFI_UNICAST, NULL, 0);
12104}
12105
paul94f2b392005-06-28 12:44:16 +000012106static int
paul718e3742002-12-13 20:15:29 +000012107bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12108 afi_t afi, safi_t safi, int *write)
12109{
12110 struct bgp_node *prn;
12111 struct bgp_node *rn;
12112 struct bgp_table *table;
12113 struct prefix *p;
12114 struct prefix_rd *prd;
12115 struct bgp_static *bgp_static;
12116 u_int32_t label;
12117 char buf[SU_ADDRSTRLEN];
12118 char rdbuf[RD_ADDRSTRLEN];
12119
12120 /* Network configuration. */
12121 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12122 if ((table = prn->info) != NULL)
12123 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12124 if ((bgp_static = rn->info) != NULL)
12125 {
12126 p = &rn->p;
12127 prd = (struct prefix_rd *) &prn->p;
12128
12129 /* "address-family" display. */
12130 bgp_config_write_family_header (vty, afi, safi, write);
12131
12132 /* "network" configuration display. */
12133 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12134 label = decode_label (bgp_static->tag);
12135
12136 vty_out (vty, " network %s/%d rd %s tag %d",
12137 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12138 p->prefixlen,
12139 rdbuf, label);
12140 vty_out (vty, "%s", VTY_NEWLINE);
12141 }
12142 return 0;
12143}
12144
12145/* Configuration of static route announcement and aggregate
12146 information. */
12147int
12148bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12149 afi_t afi, safi_t safi, int *write)
12150{
12151 struct bgp_node *rn;
12152 struct prefix *p;
12153 struct bgp_static *bgp_static;
12154 struct bgp_aggregate *bgp_aggregate;
12155 char buf[SU_ADDRSTRLEN];
12156
12157 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12158 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12159
12160 /* Network configuration. */
12161 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12162 if ((bgp_static = rn->info) != NULL)
12163 {
12164 p = &rn->p;
12165
12166 /* "address-family" display. */
12167 bgp_config_write_family_header (vty, afi, safi, write);
12168
12169 /* "network" configuration display. */
12170 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12171 {
12172 u_int32_t destination;
12173 struct in_addr netmask;
12174
12175 destination = ntohl (p->u.prefix4.s_addr);
12176 masklen2ip (p->prefixlen, &netmask);
12177 vty_out (vty, " network %s",
12178 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12179
12180 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12181 || (IN_CLASSB (destination) && p->prefixlen == 16)
12182 || (IN_CLASSA (destination) && p->prefixlen == 8)
12183 || p->u.prefix4.s_addr == 0)
12184 {
12185 /* Natural mask is not display. */
12186 }
12187 else
12188 vty_out (vty, " mask %s", inet_ntoa (netmask));
12189 }
12190 else
12191 {
12192 vty_out (vty, " network %s/%d",
12193 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12194 p->prefixlen);
12195 }
12196
12197 if (bgp_static->rmap.name)
12198 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012199 else
12200 {
12201 if (bgp_static->backdoor)
12202 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012203 }
paul718e3742002-12-13 20:15:29 +000012204
12205 vty_out (vty, "%s", VTY_NEWLINE);
12206 }
12207
12208 /* Aggregate-address configuration. */
12209 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12210 if ((bgp_aggregate = rn->info) != NULL)
12211 {
12212 p = &rn->p;
12213
12214 /* "address-family" display. */
12215 bgp_config_write_family_header (vty, afi, safi, write);
12216
12217 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12218 {
12219 struct in_addr netmask;
12220
12221 masklen2ip (p->prefixlen, &netmask);
12222 vty_out (vty, " aggregate-address %s %s",
12223 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12224 inet_ntoa (netmask));
12225 }
12226 else
12227 {
12228 vty_out (vty, " aggregate-address %s/%d",
12229 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12230 p->prefixlen);
12231 }
12232
12233 if (bgp_aggregate->as_set)
12234 vty_out (vty, " as-set");
12235
12236 if (bgp_aggregate->summary_only)
12237 vty_out (vty, " summary-only");
12238
12239 vty_out (vty, "%s", VTY_NEWLINE);
12240 }
12241
12242 return 0;
12243}
12244
12245int
12246bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12247{
12248 struct bgp_node *rn;
12249 struct bgp_distance *bdistance;
12250
12251 /* Distance configuration. */
12252 if (bgp->distance_ebgp
12253 && bgp->distance_ibgp
12254 && bgp->distance_local
12255 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12256 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12257 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12258 vty_out (vty, " distance bgp %d %d %d%s",
12259 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12260 VTY_NEWLINE);
12261
12262 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12263 if ((bdistance = rn->info) != NULL)
12264 {
12265 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12266 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12267 bdistance->access_list ? bdistance->access_list : "",
12268 VTY_NEWLINE);
12269 }
12270
12271 return 0;
12272}
12273
12274/* Allocate routing table structure and install commands. */
12275void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012276bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012277{
12278 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012279 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012280
12281 /* IPv4 BGP commands. */
12282 install_element (BGP_NODE, &bgp_network_cmd);
12283 install_element (BGP_NODE, &bgp_network_mask_cmd);
12284 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12285 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12286 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12287 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12288 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12289 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12290 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12291 install_element (BGP_NODE, &no_bgp_network_cmd);
12292 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12293 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12294 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12295 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12296 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12297 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12298 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12299 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12300
12301 install_element (BGP_NODE, &aggregate_address_cmd);
12302 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12303 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12304 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12305 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12306 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12307 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12308 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12309 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12310 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12311 install_element (BGP_NODE, &no_aggregate_address_cmd);
12312 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12313 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12314 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12315 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12316 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12317 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12318 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12319 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12320 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12321
12322 /* IPv4 unicast configuration. */
12323 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12324 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12325 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12326 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12327 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12328 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012329 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012330 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12331 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12332 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12333 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12334 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012335
paul718e3742002-12-13 20:15:29 +000012336 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12337 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12338 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12339 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12340 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12341 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12342 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12343 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12344 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12345 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12346 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12347 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12348 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12349 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12350 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12351 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12352 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12353 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12354 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12355 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12356
12357 /* IPv4 multicast configuration. */
12358 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12359 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12360 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12361 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12362 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12363 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12364 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12365 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12366 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12367 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12368 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12369 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12370 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12371 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12372 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12373 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12374 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12375 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12376 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12377 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12378 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12379 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12380 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12381 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12382 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12383 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12384 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12385 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12386 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12387 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12388 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12389 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12390
12391 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12392 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012393 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012394 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12395 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012396 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012397 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12398 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12399 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12400 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012401 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012402 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12403 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12404 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12405 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12406 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12407 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12408 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12409 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12410 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12411 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12412 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12413 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12414 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12415 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12416 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12417 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12418 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12419 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12420 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12421 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12422 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12423 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12424 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12425 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12426 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012427 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12428 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12429 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12430 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12431 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012432 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12433 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12434 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12435 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12436 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12437 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12438 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12439 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12440 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12441 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12442 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12443 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12444 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12445 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12446 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12447 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12448 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12449 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012450 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012451 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12452 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12453 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12454 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12455 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12456 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12457 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12458 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12459 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12460 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12462 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12463 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12464 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12465 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12466 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012467 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012468 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012469 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012470 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012471 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012472 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012473 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12474 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012475 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012476 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012477 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012478 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012479 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012480 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012481
12482 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12483 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12484 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012485 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012486 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12487 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12488 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012489 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012490 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12491 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12492 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12493 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12494 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12495 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12496 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12497 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12498 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12499 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12500 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12501 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012502 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12503 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12504 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12505 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12506 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012507 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12508 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12509 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12510 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12511 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12512 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12513 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12514 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12515 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012516 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012517 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012518 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012519 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012520 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012521 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012522 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012523
12524 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12525 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012526 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012527 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12528 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012529 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012530 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12531 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12532 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12533 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012534 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012535 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12536 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12537 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12538 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12539 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12540 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12541 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12542 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12543 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12544 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12545 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12546 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12547 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12548 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12549 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12550 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12551 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12552 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12553 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12554 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12555 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12556 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12557 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12558 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12559 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012560 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12561 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12562 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12563 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12564 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012565 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12566 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12567 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12568 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12569 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12570 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12571 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12572 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12573 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12574 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12575 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12576 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12577 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12578 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12579 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12580 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12581 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12582 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012583 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012584 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12585 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12586 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12587 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12588 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12589 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12590 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12591 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12592 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12593 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12595 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12596 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12597 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12598 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12599 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012600 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012601 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012602 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012603 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012604 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012605 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012606 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12607 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012608 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012609 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012610 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012611 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012612 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012613 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012614
12615 /* BGP dampening clear commands */
12616 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12617 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12618 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12619 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12620
Paul Jakmaff7924f2006-09-04 01:10:36 +000012621 /* prefix count */
12622 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12623 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12624 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012625#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012626 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12627
paul718e3742002-12-13 20:15:29 +000012628 /* New config IPv6 BGP commands. */
12629 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12630 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12631 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12632 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12633
12634 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12635 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12636 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12637 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12638
12639 /* Old config IPv6 BGP commands. */
12640 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12641 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12642
12643 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12644 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12645 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12646 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12647
12648 install_element (VIEW_NODE, &show_bgp_cmd);
12649 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012650 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012651 install_element (VIEW_NODE, &show_bgp_route_cmd);
12652 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012653 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012654 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12655 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012656 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012657 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12658 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12659 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12660 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12661 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12662 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12663 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12664 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12665 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12666 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12667 install_element (VIEW_NODE, &show_bgp_community_cmd);
12668 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12669 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12670 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12671 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12672 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12673 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12674 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12675 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12676 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12677 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12678 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12679 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12680 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12681 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12682 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12683 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12684 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12685 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12686 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12687 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12688 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12689 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12690 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12691 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12692 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12693 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12694 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12695 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12696 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012697 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12698 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12699 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12700 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012701 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012702 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012703 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012704 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012705 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012706 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012707 install_element (VIEW_NODE, &show_bgp_view_cmd);
12708 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12709 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12710 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12711 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12712 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12713 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12714 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12715 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12716 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12717 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12718 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12719 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12720 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12721 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12722 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12723 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12724 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012725 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012726 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012727 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012728 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012729 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012730 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012731
12732 /* Restricted:
12733 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12734 */
12735 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12736 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012737 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012738 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12739 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012740 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012741 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12742 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12743 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12744 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12745 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12746 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12747 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12748 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12749 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12750 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12751 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12752 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12753 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12754 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12755 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12756 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12757 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012758 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012759 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012760 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012761 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12762 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12763 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12764 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12765 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12766 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12767 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012768 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012769 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012770 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012771
12772 install_element (ENABLE_NODE, &show_bgp_cmd);
12773 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012774 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012775 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12776 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012777 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012778 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12779 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012780 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012781 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12782 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12783 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12784 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12785 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12786 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12787 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12788 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12789 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12790 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12791 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12792 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12793 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12794 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12795 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12796 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12797 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12798 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12799 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12800 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12801 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12802 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12803 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12804 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12805 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12806 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12807 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12808 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12809 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12810 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12811 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12812 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12813 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12814 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12815 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12816 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12817 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12818 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12819 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12820 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012821 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12822 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12823 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12824 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012825 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012826 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012827 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012828 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012829 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012830 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012831 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12832 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12833 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12834 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12835 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12836 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12837 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12838 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12839 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12840 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12841 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12842 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12843 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12844 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12845 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12846 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12847 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12848 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012849 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012850 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012851 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012852 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012853 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012854 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012855
12856 /* Statistics */
12857 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12858 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12859 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12860 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12861
paul718e3742002-12-13 20:15:29 +000012862 /* old command */
12863 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12864 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12865 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12866 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12867 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12868 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12869 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12870 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12871 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12872 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12873 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12874 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12875 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12876 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12877 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12878 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12879 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12880 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12881 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12882 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12883 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12884 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12885 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12886 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12887 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12888 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12889 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12890 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12891 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12892 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12893 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12894 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12895 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12896 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12897 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12898 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012899
paul718e3742002-12-13 20:15:29 +000012900 /* old command */
12901 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12902 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12903 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12904 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12905 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12906 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12907 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12908 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12909 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12910 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12911 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12912 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12913 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12914 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12915 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12916 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12917 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12918 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12919 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12920 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12921 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12922 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12923 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12924 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12925 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12926 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12927 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12928 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12929 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12930 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12931 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12932 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12933 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12934 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12935 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12936 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12937
12938 /* old command */
12939 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12940 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12941 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12942 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12943
12944 /* old command */
12945 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12946 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12947 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12948 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12949
12950 /* old command */
12951 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12952 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12953 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12954 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12955#endif /* HAVE_IPV6 */
12956
12957 install_element (BGP_NODE, &bgp_distance_cmd);
12958 install_element (BGP_NODE, &no_bgp_distance_cmd);
12959 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12960 install_element (BGP_NODE, &bgp_distance_source_cmd);
12961 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12962 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12963 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12964
12965 install_element (BGP_NODE, &bgp_damp_set_cmd);
12966 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12967 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12968 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12969 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12970 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12971 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12972 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12973 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12974 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012975
12976 /* Deprecated AS-Pathlimit commands */
12977 install_element (BGP_NODE, &bgp_network_ttl_cmd);
12978 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
12979 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
12980 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
12981 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12982 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12983
12984 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
12985 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
12986 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12987 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
12988 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12989 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12990
12991 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
12992 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
12993 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
12994 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
12995 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12996 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12997
12998 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
12999 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
13000 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13001 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
13002 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13003 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
13004
13005 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13006 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13007 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13008 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13009 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13010 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13011
13012 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13013 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13014 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13015 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13016 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13017 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013018
13019#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013020 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13021 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013022#endif
paul718e3742002-12-13 20:15:29 +000013023}
Chris Caputo228da422009-07-18 05:44:03 +000013024
13025void
13026bgp_route_finish (void)
13027{
13028 bgp_table_unlock (bgp_distance_table);
13029 bgp_distance_table = NULL;
13030}