blob: ec17dc61296b29ab22087c7a8aec66c3aec4835a [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);
1490 }
paulfee0f4c2004-09-13 05:12:46 +00001491
Chris Caputo228da422009-07-18 05:44:03 +00001492 bgp_process_announce_selected (rsclient, new_select, rn,
1493 afi, safi);
1494 }
paul200df112005-06-01 11:17:05 +00001495 }
1496 else
1497 {
hassob7395792005-08-26 12:58:38 +00001498 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001499 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hassob7395792005-08-26 12:58:38 +00001500 if (new_select)
1501 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001502 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1503 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hassob7395792005-08-26 12:58:38 +00001504 }
Paul Jakma9eda90c2007-08-30 13:36:17 +00001505 bgp_process_announce_selected (rsclient, new_select, rn, afi, safi);
paul200df112005-06-01 11:17:05 +00001506 }
paulfee0f4c2004-09-13 05:12:46 +00001507
paulb40d9392005-08-22 22:34:41 +00001508 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1509 bgp_info_reap (rn, old_select);
1510
paul200df112005-06-01 11:17:05 +00001511 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1512 return WQ_SUCCESS;
paulfee0f4c2004-09-13 05:12:46 +00001513}
1514
paul200df112005-06-01 11:17:05 +00001515static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00001516bgp_process_main (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001517{
paul0fb58d52005-11-14 14:31:49 +00001518 struct bgp_process_queue *pq = data;
paul200df112005-06-01 11:17:05 +00001519 struct bgp *bgp = pq->bgp;
1520 struct bgp_node *rn = pq->rn;
1521 afi_t afi = pq->afi;
1522 safi_t safi = pq->safi;
1523 struct prefix *p = &rn->p;
paulfee0f4c2004-09-13 05:12:46 +00001524 struct bgp_info *new_select;
1525 struct bgp_info *old_select;
1526 struct bgp_info_pair old_and_new;
paul1eb8ef22005-04-07 07:30:20 +00001527 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00001528 struct peer *peer;
Paul Jakmafb982c22007-05-04 20:15:47 +00001529
paulfee0f4c2004-09-13 05:12:46 +00001530 /* Best path selection. */
Josh Bailey96450fa2011-07-20 20:45:12 -07001531 bgp_best_selection (bgp, rn, &bgp->maxpaths[afi][safi], &old_and_new);
paulfee0f4c2004-09-13 05:12:46 +00001532 old_select = old_and_new.old;
1533 new_select = old_and_new.new;
1534
1535 /* Nothing to do. */
1536 if (old_select && old_select == new_select)
1537 {
1538 if (! CHECK_FLAG (old_select->flags, BGP_INFO_ATTR_CHANGED))
paul200df112005-06-01 11:17:05 +00001539 {
1540 if (CHECK_FLAG (old_select->flags, BGP_INFO_IGP_CHANGED))
1541 bgp_zebra_announce (p, old_select, bgp);
1542
1543 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1544 return WQ_SUCCESS;
1545 }
paulfee0f4c2004-09-13 05:12:46 +00001546 }
paul718e3742002-12-13 20:15:29 +00001547
hasso338b3422005-02-23 14:27:24 +00001548 if (old_select)
Paul Jakma1a392d42006-09-07 00:24:49 +00001549 bgp_info_unset_flag (rn, old_select, BGP_INFO_SELECTED);
hasso338b3422005-02-23 14:27:24 +00001550 if (new_select)
1551 {
Paul Jakma1a392d42006-09-07 00:24:49 +00001552 bgp_info_set_flag (rn, new_select, BGP_INFO_SELECTED);
1553 bgp_info_unset_flag (rn, new_select, BGP_INFO_ATTR_CHANGED);
hasso338b3422005-02-23 14:27:24 +00001554 }
1555
1556
paul718e3742002-12-13 20:15:29 +00001557 /* Check each BGP peer. */
paul1eb8ef22005-04-07 07:30:20 +00001558 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00001559 {
Paul Jakma9eda90c2007-08-30 13:36:17 +00001560 bgp_process_announce_selected (peer, new_select, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001561 }
1562
1563 /* FIB update. */
1564 if (safi == SAFI_UNICAST && ! bgp->name &&
1565 ! bgp_option_check (BGP_OPT_NO_FIB))
1566 {
1567 if (new_select
1568 && new_select->type == ZEBRA_ROUTE_BGP
1569 && new_select->sub_type == BGP_ROUTE_NORMAL)
1570 bgp_zebra_announce (p, new_select, bgp);
1571 else
1572 {
1573 /* Withdraw the route from the kernel. */
1574 if (old_select
1575 && old_select->type == ZEBRA_ROUTE_BGP
1576 && old_select->sub_type == BGP_ROUTE_NORMAL)
1577 bgp_zebra_withdraw (p, old_select);
1578 }
1579 }
paulb40d9392005-08-22 22:34:41 +00001580
1581 /* Reap old select bgp_info, it it has been removed */
1582 if (old_select && CHECK_FLAG (old_select->flags, BGP_INFO_REMOVED))
1583 bgp_info_reap (rn, old_select);
1584
paul200df112005-06-01 11:17:05 +00001585 UNSET_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED);
1586 return WQ_SUCCESS;
paul718e3742002-12-13 20:15:29 +00001587}
1588
paul200df112005-06-01 11:17:05 +00001589static void
paul0fb58d52005-11-14 14:31:49 +00001590bgp_processq_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00001591{
paul0fb58d52005-11-14 14:31:49 +00001592 struct bgp_process_queue *pq = data;
Chris Caputo228da422009-07-18 05:44:03 +00001593 struct bgp_table *table = pq->rn->table;
paul0fb58d52005-11-14 14:31:49 +00001594
Chris Caputo228da422009-07-18 05:44:03 +00001595 bgp_unlock (pq->bgp);
paul200df112005-06-01 11:17:05 +00001596 bgp_unlock_node (pq->rn);
Chris Caputo228da422009-07-18 05:44:03 +00001597 bgp_table_unlock (table);
paul200df112005-06-01 11:17:05 +00001598 XFREE (MTYPE_BGP_PROCESS_QUEUE, pq);
1599}
1600
1601static void
1602bgp_process_queue_init (void)
1603{
1604 bm->process_main_queue
1605 = work_queue_new (bm->master, "process_main_queue");
1606 bm->process_rsclient_queue
1607 = work_queue_new (bm->master, "process_rsclient_queue");
1608
1609 if ( !(bm->process_main_queue && bm->process_rsclient_queue) )
1610 {
1611 zlog_err ("%s: Failed to allocate work queue", __func__);
1612 exit (1);
1613 }
1614
1615 bm->process_main_queue->spec.workfunc = &bgp_process_main;
paul200df112005-06-01 11:17:05 +00001616 bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
Paul Jakma838bbde2010-01-08 14:05:32 +00001617 bm->process_main_queue->spec.max_retries = 0;
1618 bm->process_main_queue->spec.hold = 50;
1619
1620 memcpy (bm->process_rsclient_queue, bm->process_main_queue,
1621 sizeof (struct work_queue *));
1622 bm->process_rsclient_queue->spec.workfunc = &bgp_process_rsclient;
paul200df112005-06-01 11:17:05 +00001623}
1624
1625void
paulfee0f4c2004-09-13 05:12:46 +00001626bgp_process (struct bgp *bgp, struct bgp_node *rn, afi_t afi, safi_t safi)
1627{
paul200df112005-06-01 11:17:05 +00001628 struct bgp_process_queue *pqnode;
1629
1630 /* already scheduled for processing? */
1631 if (CHECK_FLAG (rn->flags, BGP_NODE_PROCESS_SCHEDULED))
1632 return;
1633
1634 if ( (bm->process_main_queue == NULL) ||
1635 (bm->process_rsclient_queue == NULL) )
1636 bgp_process_queue_init ();
1637
1638 pqnode = XCALLOC (MTYPE_BGP_PROCESS_QUEUE,
1639 sizeof (struct bgp_process_queue));
1640 if (!pqnode)
1641 return;
Chris Caputo228da422009-07-18 05:44:03 +00001642
1643 /* all unlocked in bgp_processq_del */
1644 bgp_table_lock (rn->table);
1645 pqnode->rn = bgp_lock_node (rn);
paul200df112005-06-01 11:17:05 +00001646 pqnode->bgp = bgp;
Chris Caputo228da422009-07-18 05:44:03 +00001647 bgp_lock (bgp);
paul200df112005-06-01 11:17:05 +00001648 pqnode->afi = afi;
1649 pqnode->safi = safi;
1650
paulfee0f4c2004-09-13 05:12:46 +00001651 switch (rn->table->type)
1652 {
paul200df112005-06-01 11:17:05 +00001653 case BGP_TABLE_MAIN:
1654 work_queue_add (bm->process_main_queue, pqnode);
1655 break;
1656 case BGP_TABLE_RSCLIENT:
1657 work_queue_add (bm->process_rsclient_queue, pqnode);
1658 break;
paulfee0f4c2004-09-13 05:12:46 +00001659 }
paul200df112005-06-01 11:17:05 +00001660
1661 return;
paulfee0f4c2004-09-13 05:12:46 +00001662}
hasso0a486e52005-02-01 20:57:17 +00001663
paul94f2b392005-06-28 12:44:16 +00001664static int
hasso0a486e52005-02-01 20:57:17 +00001665bgp_maximum_prefix_restart_timer (struct thread *thread)
1666{
1667 struct peer *peer;
1668
1669 peer = THREAD_ARG (thread);
1670 peer->t_pmax_restart = NULL;
1671
1672 if (BGP_DEBUG (events, EVENTS))
1673 zlog_debug ("%s Maximum-prefix restart timer expired, restore peering",
1674 peer->host);
1675
1676 peer_clear (peer);
1677
1678 return 0;
1679}
1680
paulfee0f4c2004-09-13 05:12:46 +00001681int
paul5228ad22004-06-04 17:58:18 +00001682bgp_maximum_prefix_overflow (struct peer *peer, afi_t afi,
1683 safi_t safi, int always)
paul718e3742002-12-13 20:15:29 +00001684{
hassoe0701b72004-05-20 09:19:34 +00001685 if (!CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX))
1686 return 0;
1687
1688 if (peer->pcount[afi][safi] > peer->pmax[afi][safi])
paul718e3742002-12-13 20:15:29 +00001689 {
hassoe0701b72004-05-20 09:19:34 +00001690 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT)
1691 && ! always)
1692 return 0;
paul718e3742002-12-13 20:15:29 +00001693
hassoe0701b72004-05-20 09:19:34 +00001694 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001695 "%%MAXPFXEXCEED: No. of %s prefix received from %s %ld exceed, "
1696 "limit %ld", afi_safi_print (afi, safi), peer->host,
1697 peer->pcount[afi][safi], peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001698 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
paul718e3742002-12-13 20:15:29 +00001699
hassoe0701b72004-05-20 09:19:34 +00001700 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING))
1701 return 0;
paul718e3742002-12-13 20:15:29 +00001702
hassoe0701b72004-05-20 09:19:34 +00001703 {
paul5228ad22004-06-04 17:58:18 +00001704 u_int8_t ndata[7];
hassoe0701b72004-05-20 09:19:34 +00001705
1706 if (safi == SAFI_MPLS_VPN)
1707 safi = BGP_SAFI_VPNV4;
paul5228ad22004-06-04 17:58:18 +00001708
1709 ndata[0] = (afi >> 8);
1710 ndata[1] = afi;
1711 ndata[2] = safi;
1712 ndata[3] = (peer->pmax[afi][safi] >> 24);
1713 ndata[4] = (peer->pmax[afi][safi] >> 16);
1714 ndata[5] = (peer->pmax[afi][safi] >> 8);
1715 ndata[6] = (peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001716
1717 SET_FLAG (peer->sflags, PEER_STATUS_PREFIX_OVERFLOW);
1718 bgp_notify_send_with_data (peer, BGP_NOTIFY_CEASE,
1719 BGP_NOTIFY_CEASE_MAX_PREFIX, ndata, 7);
1720 }
hasso0a486e52005-02-01 20:57:17 +00001721
1722 /* restart timer start */
1723 if (peer->pmax_restart[afi][safi])
1724 {
1725 peer->v_pmax_restart = peer->pmax_restart[afi][safi] * 60;
1726
1727 if (BGP_DEBUG (events, EVENTS))
1728 zlog_debug ("%s Maximum-prefix restart timer started for %d secs",
1729 peer->host, peer->v_pmax_restart);
1730
1731 BGP_TIMER_ON (peer->t_pmax_restart, bgp_maximum_prefix_restart_timer,
1732 peer->v_pmax_restart);
1733 }
1734
hassoe0701b72004-05-20 09:19:34 +00001735 return 1;
paul718e3742002-12-13 20:15:29 +00001736 }
hassoe0701b72004-05-20 09:19:34 +00001737 else
1738 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT);
1739
1740 if (peer->pcount[afi][safi] > (peer->pmax[afi][safi] * peer->pmax_threshold[afi][safi] / 100))
1741 {
1742 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD)
1743 && ! always)
1744 return 0;
1745
1746 zlog (peer->log, LOG_INFO,
hasso0a486e52005-02-01 20:57:17 +00001747 "%%MAXPFX: No. of %s prefix received from %s reaches %ld, max %ld",
1748 afi_safi_print (afi, safi), peer->host, peer->pcount[afi][safi],
1749 peer->pmax[afi][safi]);
hassoe0701b72004-05-20 09:19:34 +00001750 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
1751 }
1752 else
1753 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD);
paul718e3742002-12-13 20:15:29 +00001754 return 0;
1755}
1756
paulb40d9392005-08-22 22:34:41 +00001757/* Unconditionally remove the route from the RIB, without taking
1758 * damping into consideration (eg, because the session went down)
1759 */
paul94f2b392005-06-28 12:44:16 +00001760static void
paul718e3742002-12-13 20:15:29 +00001761bgp_rib_remove (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
1762 afi_t afi, safi_t safi)
1763{
paul902212c2006-02-05 17:51:19 +00001764 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1765
1766 if (!CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
1767 bgp_info_delete (rn, ri); /* keep historical info */
1768
paulb40d9392005-08-22 22:34:41 +00001769 bgp_process (peer->bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00001770}
1771
paul94f2b392005-06-28 12:44:16 +00001772static void
paul718e3742002-12-13 20:15:29 +00001773bgp_rib_withdraw (struct bgp_node *rn, struct bgp_info *ri, struct peer *peer,
paulb40d9392005-08-22 22:34:41 +00001774 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00001775{
paul718e3742002-12-13 20:15:29 +00001776 int status = BGP_DAMP_NONE;
1777
paulb40d9392005-08-22 22:34:41 +00001778 /* apply dampening, if result is suppressed, we'll be retaining
1779 * the bgp_info in the RIB for historical reference.
1780 */
1781 if (CHECK_FLAG (peer->bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
1782 && peer_sort (peer) == BGP_PEER_EBGP)
1783 if ( (status = bgp_damp_withdraw (ri, rn, afi, safi, 0))
1784 == BGP_DAMP_SUPPRESSED)
paul902212c2006-02-05 17:51:19 +00001785 {
paul902212c2006-02-05 17:51:19 +00001786 bgp_aggregate_decrement (peer->bgp, &rn->p, ri, afi, safi);
1787 return;
1788 }
1789
1790 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00001791}
1792
paul94f2b392005-06-28 12:44:16 +00001793static void
paulfee0f4c2004-09-13 05:12:46 +00001794bgp_update_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1795 struct attr *attr, struct peer *peer, struct prefix *p, int type,
1796 int sub_type, struct prefix_rd *prd, u_char *tag)
1797{
1798 struct bgp_node *rn;
1799 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00001800 struct attr new_attr = { 0 };
paulfee0f4c2004-09-13 05:12:46 +00001801 struct attr *attr_new;
1802 struct attr *attr_new2;
1803 struct bgp_info *ri;
1804 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00001805 const char *reason;
paulfee0f4c2004-09-13 05:12:46 +00001806 char buf[SU_ADDRSTRLEN];
1807
1808 /* Do not insert announces from a rsclient into its own 'bgp_table'. */
1809 if (peer == rsclient)
1810 return;
1811
1812 bgp = peer->bgp;
1813 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
1814
1815 /* Check previously received route. */
1816 for (ri = rn->info; ri; ri = ri->next)
1817 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
1818 break;
1819
1820 /* AS path loop check. */
1821 if (aspath_loop_check (attr->aspath, rsclient->as) > peer->allowas_in[afi][safi])
1822 {
1823 reason = "as-path contains our own AS;";
1824 goto filtered;
1825 }
1826
1827 /* Route reflector originator ID check. */
1828 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00001829 && IPV4_ADDR_SAME (&rsclient->remote_id, &attr->extra->originator_id))
paulfee0f4c2004-09-13 05:12:46 +00001830 {
1831 reason = "originator is us;";
1832 goto filtered;
1833 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001834
1835 bgp_attr_dup (&new_attr, attr);
paulfee0f4c2004-09-13 05:12:46 +00001836
1837 /* Apply export policy. */
1838 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT) &&
1839 bgp_export_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1840 {
1841 reason = "export-policy;";
1842 goto filtered;
1843 }
1844
1845 attr_new2 = bgp_attr_intern (&new_attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00001846
paulfee0f4c2004-09-13 05:12:46 +00001847 /* Apply import policy. */
1848 if (bgp_import_modifier (rsclient, peer, p, &new_attr, afi, safi) == RMAP_DENY)
1849 {
1850 bgp_attr_unintern (attr_new2);
1851
1852 reason = "import-policy;";
1853 goto filtered;
1854 }
1855
1856 attr_new = bgp_attr_intern (&new_attr);
1857 bgp_attr_unintern (attr_new2);
1858
1859 /* IPv4 unicast next hop check. */
1860 if (afi == AFI_IP && safi == SAFI_UNICAST)
1861 {
1862 /* Next hop must not be 0.0.0.0 nor Class E address. */
1863 if (new_attr.nexthop.s_addr == 0
1864 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
1865 {
1866 bgp_attr_unintern (attr_new);
1867
1868 reason = "martian next-hop;";
1869 goto filtered;
1870 }
1871 }
Paul Jakmafb982c22007-05-04 20:15:47 +00001872
1873 /* new_attr isn't passed to any functions after here */
1874 bgp_attr_extra_free (&new_attr);
1875
paulfee0f4c2004-09-13 05:12:46 +00001876 /* If the update is implicit withdraw. */
1877 if (ri)
1878 {
Stephen Hemminger65957882010-01-15 16:22:10 +03001879 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001880
1881 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00001882 if (!CHECK_FLAG(ri->flags, BGP_INFO_REMOVED)
1883 && attrhash_cmp (ri->attr, attr_new))
paulfee0f4c2004-09-13 05:12:46 +00001884 {
1885
Paul Jakma1a392d42006-09-07 00:24:49 +00001886 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001887
1888 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001889 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001890 "%s rcvd %s/%d for RS-client %s...duplicate ignored",
1891 peer->host,
1892 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1893 p->prefixlen, rsclient->host);
1894
Chris Caputo228da422009-07-18 05:44:03 +00001895 bgp_unlock_node (rn);
1896 bgp_attr_unintern (attr_new);
paulfee0f4c2004-09-13 05:12:46 +00001897
Chris Caputo228da422009-07-18 05:44:03 +00001898 return;
paulfee0f4c2004-09-13 05:12:46 +00001899 }
1900
Paul Jakma16d2e242007-04-10 19:32:10 +00001901 /* Withdraw/Announce before we fully processed the withdraw */
1902 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
1903 bgp_info_restore (rn, ri);
1904
paulfee0f4c2004-09-13 05:12:46 +00001905 /* Received Logging. */
1906 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001907 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001908 peer->host,
1909 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1910 p->prefixlen, rsclient->host);
1911
1912 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00001913 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00001914
1915 /* Update to new attribute. */
1916 bgp_attr_unintern (ri->attr);
1917 ri->attr = attr_new;
1918
1919 /* Update MPLS tag. */
1920 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001921 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001922
Paul Jakma1a392d42006-09-07 00:24:49 +00001923 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001924
1925 /* Process change. */
1926 bgp_process (bgp, rn, afi, safi);
1927 bgp_unlock_node (rn);
1928
1929 return;
1930 }
1931
1932 /* Received Logging. */
1933 if (BGP_DEBUG (update, UPDATE_IN))
1934 {
ajsd2c1f162004-12-08 21:10:20 +00001935 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d for RS-client %s",
paulfee0f4c2004-09-13 05:12:46 +00001936 peer->host,
1937 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1938 p->prefixlen, rsclient->host);
1939 }
1940
1941 /* Make new BGP info. */
1942 new = bgp_info_new ();
1943 new->type = type;
1944 new->sub_type = sub_type;
1945 new->peer = peer;
1946 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03001947 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00001948
1949 /* Update MPLS tag. */
1950 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00001951 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paulfee0f4c2004-09-13 05:12:46 +00001952
Paul Jakma1a392d42006-09-07 00:24:49 +00001953 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paulfee0f4c2004-09-13 05:12:46 +00001954
1955 /* Register new BGP information. */
1956 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00001957
1958 /* route_node_get lock */
1959 bgp_unlock_node (rn);
1960
paulfee0f4c2004-09-13 05:12:46 +00001961 /* Process change. */
1962 bgp_process (bgp, rn, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00001963
1964 bgp_attr_extra_free (&new_attr);
1965
paulfee0f4c2004-09-13 05:12:46 +00001966 return;
1967
1968 filtered:
1969
1970 /* This BGP update is filtered. Log the reason then update BGP entry. */
1971 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00001972 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00001973 "%s rcvd UPDATE about %s/%d -- DENIED for RS-client %s due to: %s",
1974 peer->host,
1975 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
1976 p->prefixlen, rsclient->host, reason);
1977
1978 if (ri)
paulb40d9392005-08-22 22:34:41 +00001979 bgp_rib_remove (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00001980
1981 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00001982
1983 if (new_attr.extra)
1984 bgp_attr_extra_free (&new_attr);
1985
paulfee0f4c2004-09-13 05:12:46 +00001986 return;
1987}
1988
paul94f2b392005-06-28 12:44:16 +00001989static void
paulfee0f4c2004-09-13 05:12:46 +00001990bgp_withdraw_rsclient (struct peer *rsclient, afi_t afi, safi_t safi,
1991 struct peer *peer, struct prefix *p, int type, int sub_type,
1992 struct prefix_rd *prd, u_char *tag)
Chris Caputo228da422009-07-18 05:44:03 +00001993{
paulfee0f4c2004-09-13 05:12:46 +00001994 struct bgp_node *rn;
1995 struct bgp_info *ri;
1996 char buf[SU_ADDRSTRLEN];
1997
1998 if (rsclient == peer)
Chris Caputo228da422009-07-18 05:44:03 +00001999 return;
paulfee0f4c2004-09-13 05:12:46 +00002000
2001 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, prd);
2002
2003 /* Lookup withdrawn route. */
2004 for (ri = rn->info; ri; ri = ri->next)
2005 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2006 break;
2007
2008 /* Withdraw specified route from routing table. */
2009 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002010 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00002011 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002012 zlog (peer->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00002013 "%s Can't find the route %s/%d", peer->host,
2014 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2015 p->prefixlen);
2016
2017 /* Unlock bgp_node_get() lock. */
Chris Caputo228da422009-07-18 05:44:03 +00002018 bgp_unlock_node (rn);
2019}
paulfee0f4c2004-09-13 05:12:46 +00002020
paul94f2b392005-06-28 12:44:16 +00002021static int
paulfee0f4c2004-09-13 05:12:46 +00002022bgp_update_main (struct peer *peer, struct prefix *p, struct attr *attr,
paul718e3742002-12-13 20:15:29 +00002023 afi_t afi, safi_t safi, int type, int sub_type,
2024 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2025{
2026 int ret;
2027 int aspath_loop_count = 0;
2028 struct bgp_node *rn;
2029 struct bgp *bgp;
Paul Jakmafb982c22007-05-04 20:15:47 +00002030 struct attr new_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00002031 struct attr *attr_new;
2032 struct bgp_info *ri;
2033 struct bgp_info *new;
paulfd79ac92004-10-13 05:06:08 +00002034 const char *reason;
paul718e3742002-12-13 20:15:29 +00002035 char buf[SU_ADDRSTRLEN];
2036
2037 bgp = peer->bgp;
paulfee0f4c2004-09-13 05:12:46 +00002038 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
Paul Jakmafb982c22007-05-04 20:15:47 +00002039
paul718e3742002-12-13 20:15:29 +00002040 /* When peer's soft reconfiguration enabled. Record input packet in
2041 Adj-RIBs-In. */
2042 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2043 && peer != bgp->peer_self && ! soft_reconfig)
2044 bgp_adj_in_set (rn, peer, attr);
2045
2046 /* Check previously received route. */
2047 for (ri = rn->info; ri; ri = ri->next)
2048 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2049 break;
2050
2051 /* AS path local-as loop check. */
2052 if (peer->change_local_as)
2053 {
2054 if (! CHECK_FLAG (peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND))
2055 aspath_loop_count = 1;
2056
2057 if (aspath_loop_check (attr->aspath, peer->change_local_as) > aspath_loop_count)
2058 {
2059 reason = "as-path contains our own AS;";
2060 goto filtered;
2061 }
2062 }
2063
2064 /* AS path loop check. */
2065 if (aspath_loop_check (attr->aspath, bgp->as) > peer->allowas_in[afi][safi]
2066 || (CHECK_FLAG(bgp->config, BGP_CONFIG_CONFEDERATION)
2067 && aspath_loop_check(attr->aspath, bgp->confed_id)
2068 > peer->allowas_in[afi][safi]))
2069 {
2070 reason = "as-path contains our own AS;";
2071 goto filtered;
2072 }
2073
2074 /* Route reflector originator ID check. */
2075 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_ORIGINATOR_ID)
Paul Jakmafb982c22007-05-04 20:15:47 +00002076 && IPV4_ADDR_SAME (&bgp->router_id, &attr->extra->originator_id))
paul718e3742002-12-13 20:15:29 +00002077 {
2078 reason = "originator is us;";
2079 goto filtered;
2080 }
2081
2082 /* Route reflector cluster ID check. */
2083 if (bgp_cluster_filter (peer, attr))
2084 {
2085 reason = "reflected from the same cluster;";
2086 goto filtered;
2087 }
2088
2089 /* Apply incoming filter. */
2090 if (bgp_input_filter (peer, p, attr, afi, safi) == FILTER_DENY)
2091 {
2092 reason = "filter;";
2093 goto filtered;
2094 }
2095
2096 /* Apply incoming route-map. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002097 bgp_attr_dup (&new_attr, attr);
paul718e3742002-12-13 20:15:29 +00002098
2099 if (bgp_input_modifier (peer, p, &new_attr, afi, safi) == RMAP_DENY)
2100 {
2101 reason = "route-map;";
2102 goto filtered;
2103 }
2104
2105 /* IPv4 unicast next hop check. */
2106 if (afi == AFI_IP && safi == SAFI_UNICAST)
2107 {
2108 /* If the peer is EBGP and nexthop is not on connected route,
2109 discard it. */
2110 if (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl == 1
2111 && ! bgp_nexthop_check_ebgp (afi, &new_attr)
hasso6ffd2072005-02-02 14:50:11 +00002112 && ! CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK))
paul718e3742002-12-13 20:15:29 +00002113 {
2114 reason = "non-connected next-hop;";
2115 goto filtered;
2116 }
2117
2118 /* Next hop must not be 0.0.0.0 nor Class E address. Next hop
2119 must not be my own address. */
2120 if (bgp_nexthop_self (afi, &new_attr)
2121 || new_attr.nexthop.s_addr == 0
2122 || ntohl (new_attr.nexthop.s_addr) >= 0xe0000000)
2123 {
2124 reason = "martian next-hop;";
2125 goto filtered;
2126 }
2127 }
2128
2129 attr_new = bgp_attr_intern (&new_attr);
2130
2131 /* If the update is implicit withdraw. */
2132 if (ri)
2133 {
Stephen Hemminger65957882010-01-15 16:22:10 +03002134 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002135
2136 /* Same attribute comes in. */
Paul Jakma16d2e242007-04-10 19:32:10 +00002137 if (!CHECK_FLAG (ri->flags, BGP_INFO_REMOVED)
2138 && attrhash_cmp (ri->attr, attr_new))
paul718e3742002-12-13 20:15:29 +00002139 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002140 bgp_info_unset_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00002141
2142 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2143 && peer_sort (peer) == BGP_PEER_EBGP
2144 && CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2145 {
2146 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002147 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002148 peer->host,
2149 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2150 p->prefixlen);
2151
paul902212c2006-02-05 17:51:19 +00002152 if (bgp_damp_update (ri, rn, afi, safi) != BGP_DAMP_SUPPRESSED)
2153 {
2154 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2155 bgp_process (bgp, rn, afi, safi);
2156 }
paul718e3742002-12-13 20:15:29 +00002157 }
Paul Jakma16d2e242007-04-10 19:32:10 +00002158 else /* Duplicate - odd */
paul718e3742002-12-13 20:15:29 +00002159 {
2160 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002161 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002162 "%s rcvd %s/%d...duplicate ignored",
2163 peer->host,
2164 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2165 p->prefixlen);
hasso93406d82005-02-02 14:40:33 +00002166
2167 /* graceful restart STALE flag unset. */
2168 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2169 {
Paul Jakma1a392d42006-09-07 00:24:49 +00002170 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
paul902212c2006-02-05 17:51:19 +00002171 bgp_process (bgp, rn, afi, safi);
hasso93406d82005-02-02 14:40:33 +00002172 }
paul718e3742002-12-13 20:15:29 +00002173 }
2174
2175 bgp_unlock_node (rn);
2176 bgp_attr_unintern (attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00002177 bgp_attr_extra_free (&new_attr);
2178
paul718e3742002-12-13 20:15:29 +00002179 return 0;
2180 }
2181
Paul Jakma16d2e242007-04-10 19:32:10 +00002182 /* Withdraw/Announce before we fully processed the withdraw */
2183 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
2184 {
2185 if (BGP_DEBUG (update, UPDATE_IN))
2186 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d, flapped quicker than processing",
2187 peer->host,
2188 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2189 p->prefixlen);
2190 bgp_info_restore (rn, ri);
2191 }
2192
paul718e3742002-12-13 20:15:29 +00002193 /* Received Logging. */
2194 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002195 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002196 peer->host,
2197 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2198 p->prefixlen);
2199
hasso93406d82005-02-02 14:40:33 +00002200 /* graceful restart STALE flag unset. */
2201 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma1a392d42006-09-07 00:24:49 +00002202 bgp_info_unset_flag (rn, ri, BGP_INFO_STALE);
hasso93406d82005-02-02 14:40:33 +00002203
paul718e3742002-12-13 20:15:29 +00002204 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00002205 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul902212c2006-02-05 17:51:19 +00002206
2207 /* implicit withdraw, decrement aggregate and pcount here.
2208 * only if update is accepted, they'll increment below.
2209 */
paul902212c2006-02-05 17:51:19 +00002210 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
2211
paul718e3742002-12-13 20:15:29 +00002212 /* Update bgp route dampening information. */
2213 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2214 && peer_sort (peer) == BGP_PEER_EBGP)
2215 {
2216 /* This is implicit withdraw so we should update dampening
2217 information. */
2218 if (! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
2219 bgp_damp_withdraw (ri, rn, afi, safi, 1);
paul718e3742002-12-13 20:15:29 +00002220 }
2221
paul718e3742002-12-13 20:15:29 +00002222 /* Update to new attribute. */
2223 bgp_attr_unintern (ri->attr);
2224 ri->attr = attr_new;
2225
2226 /* Update MPLS tag. */
2227 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002228 memcpy ((bgp_info_extra_get (ri))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002229
2230 /* Update bgp route dampening information. */
2231 if (CHECK_FLAG (bgp->af_flags[afi][safi], BGP_CONFIG_DAMPENING)
2232 && peer_sort (peer) == BGP_PEER_EBGP)
2233 {
2234 /* Now we do normal update dampening. */
2235 ret = bgp_damp_update (ri, rn, afi, safi);
2236 if (ret == BGP_DAMP_SUPPRESSED)
2237 {
2238 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002239 bgp_attr_extra_free (&new_attr);
paul718e3742002-12-13 20:15:29 +00002240 return 0;
2241 }
2242 }
2243
2244 /* Nexthop reachability check. */
2245 if ((afi == AFI_IP || afi == AFI_IP6)
2246 && safi == SAFI_UNICAST
2247 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002248 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002249 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002250 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002251 {
2252 if (bgp_nexthop_lookup (afi, peer, ri, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002253 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002254 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002255 bgp_info_unset_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002256 }
2257 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002258 bgp_info_set_flag (rn, ri, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002259
2260 /* Process change. */
2261 bgp_aggregate_increment (bgp, p, ri, afi, safi);
2262
2263 bgp_process (bgp, rn, afi, safi);
2264 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002265 bgp_attr_extra_free (&new_attr);
2266
paul718e3742002-12-13 20:15:29 +00002267 return 0;
2268 }
2269
2270 /* Received Logging. */
2271 if (BGP_DEBUG (update, UPDATE_IN))
2272 {
ajsd2c1f162004-12-08 21:10:20 +00002273 zlog (peer->log, LOG_DEBUG, "%s rcvd %s/%d",
paul718e3742002-12-13 20:15:29 +00002274 peer->host,
2275 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2276 p->prefixlen);
2277 }
2278
paul718e3742002-12-13 20:15:29 +00002279 /* Make new BGP info. */
2280 new = bgp_info_new ();
2281 new->type = type;
2282 new->sub_type = sub_type;
2283 new->peer = peer;
2284 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03002285 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00002286
2287 /* Update MPLS tag. */
2288 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00002289 memcpy ((bgp_info_extra_get (new))->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00002290
2291 /* Nexthop reachability check. */
2292 if ((afi == AFI_IP || afi == AFI_IP6)
2293 && safi == SAFI_UNICAST
2294 && (peer_sort (peer) == BGP_PEER_IBGP
Vasilis Tsiligiannis638b70b2009-07-20 01:25:16 +03002295 || peer_sort (peer) == BGP_PEER_CONFED
paul718e3742002-12-13 20:15:29 +00002296 || (peer_sort (peer) == BGP_PEER_EBGP && peer->ttl != 1)
hasso6ffd2072005-02-02 14:50:11 +00002297 || CHECK_FLAG (peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)))
paul718e3742002-12-13 20:15:29 +00002298 {
2299 if (bgp_nexthop_lookup (afi, peer, new, NULL, NULL))
Paul Jakma1a392d42006-09-07 00:24:49 +00002300 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002301 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002302 bgp_info_unset_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002303 }
2304 else
Paul Jakma1a392d42006-09-07 00:24:49 +00002305 bgp_info_set_flag (rn, new, BGP_INFO_VALID);
paul718e3742002-12-13 20:15:29 +00002306
paul902212c2006-02-05 17:51:19 +00002307 /* Increment prefix */
paul718e3742002-12-13 20:15:29 +00002308 bgp_aggregate_increment (bgp, p, new, afi, safi);
2309
2310 /* Register new BGP information. */
2311 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00002312
2313 /* route_node_get lock */
2314 bgp_unlock_node (rn);
2315
Paul Jakmafb982c22007-05-04 20:15:47 +00002316 bgp_attr_extra_free (&new_attr);
2317
paul718e3742002-12-13 20:15:29 +00002318 /* If maximum prefix count is configured and current prefix
2319 count exeed it. */
hassoe0701b72004-05-20 09:19:34 +00002320 if (bgp_maximum_prefix_overflow (peer, afi, safi, 0))
2321 return -1;
paul718e3742002-12-13 20:15:29 +00002322
2323 /* Process change. */
2324 bgp_process (bgp, rn, afi, safi);
2325
2326 return 0;
2327
2328 /* This BGP update is filtered. Log the reason then update BGP
2329 entry. */
2330 filtered:
2331 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002332 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002333 "%s rcvd UPDATE about %s/%d -- DENIED due to: %s",
2334 peer->host,
2335 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2336 p->prefixlen, reason);
2337
2338 if (ri)
paulb40d9392005-08-22 22:34:41 +00002339 bgp_rib_remove (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002340
2341 bgp_unlock_node (rn);
Paul Jakmafb982c22007-05-04 20:15:47 +00002342
2343 bgp_attr_extra_free (&new_attr);
2344
paul718e3742002-12-13 20:15:29 +00002345 return 0;
2346}
2347
2348int
paulfee0f4c2004-09-13 05:12:46 +00002349bgp_update (struct peer *peer, struct prefix *p, struct attr *attr,
2350 afi_t afi, safi_t safi, int type, int sub_type,
2351 struct prefix_rd *prd, u_char *tag, int soft_reconfig)
2352{
2353 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002354 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00002355 struct bgp *bgp;
2356 int ret;
2357
2358 ret = bgp_update_main (peer, p, attr, afi, safi, type, sub_type, prd, tag,
2359 soft_reconfig);
2360
2361 bgp = peer->bgp;
2362
2363 /* Process the update for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002364 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002365 {
2366 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2367 bgp_update_rsclient (rsclient, afi, safi, attr, peer, p, type,
2368 sub_type, prd, tag);
2369 }
2370
2371 return ret;
2372}
2373
2374int
paul718e3742002-12-13 20:15:29 +00002375bgp_withdraw (struct peer *peer, struct prefix *p, struct attr *attr,
paul94f2b392005-06-28 12:44:16 +00002376 afi_t afi, safi_t safi, int type, int sub_type,
2377 struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00002378{
2379 struct bgp *bgp;
2380 char buf[SU_ADDRSTRLEN];
2381 struct bgp_node *rn;
2382 struct bgp_info *ri;
paulfee0f4c2004-09-13 05:12:46 +00002383 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00002384 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002385
2386 bgp = peer->bgp;
2387
paulfee0f4c2004-09-13 05:12:46 +00002388 /* Process the withdraw for each RS-client. */
paul1eb8ef22005-04-07 07:30:20 +00002389 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00002390 {
2391 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2392 bgp_withdraw_rsclient (rsclient, afi, safi, peer, p, type, sub_type, prd, tag);
2393 }
2394
paul718e3742002-12-13 20:15:29 +00002395 /* Logging. */
2396 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002397 zlog (peer->log, LOG_DEBUG, "%s rcvd UPDATE about %s/%d -- withdrawn",
paul718e3742002-12-13 20:15:29 +00002398 peer->host,
2399 inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2400 p->prefixlen);
2401
2402 /* Lookup node. */
paulfee0f4c2004-09-13 05:12:46 +00002403 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00002404
2405 /* If peer is soft reconfiguration enabled. Record input packet for
2406 further calculation. */
2407 if (CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG)
2408 && peer != bgp->peer_self)
2409 bgp_adj_in_unset (rn, peer);
2410
2411 /* Lookup withdrawn route. */
2412 for (ri = rn->info; ri; ri = ri->next)
2413 if (ri->peer == peer && ri->type == type && ri->sub_type == sub_type)
2414 break;
2415
2416 /* Withdraw specified route from routing table. */
2417 if (ri && ! CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
paulb40d9392005-08-22 22:34:41 +00002418 bgp_rib_withdraw (rn, ri, peer, afi, safi);
paul718e3742002-12-13 20:15:29 +00002419 else if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00002420 zlog (peer->log, LOG_DEBUG,
paul718e3742002-12-13 20:15:29 +00002421 "%s Can't find the route %s/%d", peer->host,
2422 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
2423 p->prefixlen);
2424
2425 /* Unlock bgp_node_get() lock. */
2426 bgp_unlock_node (rn);
2427
2428 return 0;
2429}
2430
2431void
2432bgp_default_originate (struct peer *peer, afi_t afi, safi_t safi, int withdraw)
2433{
2434 struct bgp *bgp;
Chris Caputo228da422009-07-18 05:44:03 +00002435 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002436 struct aspath *aspath = { 0 };
paul718e3742002-12-13 20:15:29 +00002437 struct prefix p;
2438 struct bgp_info binfo;
2439 struct peer *from;
2440 int ret = RMAP_DENYMATCH;
Paul Jakmafb982c22007-05-04 20:15:47 +00002441
Paul Jakmab2497022007-06-14 11:17:58 +00002442 if (!(afi == AFI_IP || afi == AFI_IP6))
Paul Jakmafb982c22007-05-04 20:15:47 +00002443 return;
2444
paul718e3742002-12-13 20:15:29 +00002445 bgp = peer->bgp;
2446 from = bgp->peer_self;
Paul Jakmafb982c22007-05-04 20:15:47 +00002447
paul718e3742002-12-13 20:15:29 +00002448 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
2449 aspath = attr.aspath;
2450 attr.local_pref = bgp->default_local_pref;
2451 memcpy (&attr.nexthop, &peer->nexthop.v4, IPV4_MAX_BYTELEN);
2452
2453 if (afi == AFI_IP)
2454 str2prefix ("0.0.0.0/0", &p);
2455#ifdef HAVE_IPV6
2456 else if (afi == AFI_IP6)
2457 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002458 struct attr_extra *ae;
2459 attr.extra = NULL;
2460
2461 ae = bgp_attr_extra_get (&attr);
2462 attr.extra = ae;
2463
paul718e3742002-12-13 20:15:29 +00002464 str2prefix ("::/0", &p);
2465
2466 /* IPv6 global nexthop must be included. */
Paul Jakmafb982c22007-05-04 20:15:47 +00002467 memcpy (&ae->mp_nexthop_global, &peer->nexthop.v6_global,
paul718e3742002-12-13 20:15:29 +00002468 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002469 ae->mp_nexthop_len = 16;
paul718e3742002-12-13 20:15:29 +00002470
2471 /* If the peer is on shared nextwork and we have link-local
2472 nexthop set it. */
2473 if (peer->shared_network
2474 && !IN6_IS_ADDR_UNSPECIFIED (&peer->nexthop.v6_local))
2475 {
Paul Jakmafb982c22007-05-04 20:15:47 +00002476 memcpy (&ae->mp_nexthop_local, &peer->nexthop.v6_local,
paul718e3742002-12-13 20:15:29 +00002477 IPV6_MAX_BYTELEN);
Paul Jakmafb982c22007-05-04 20:15:47 +00002478 ae->mp_nexthop_len = 32;
paul718e3742002-12-13 20:15:29 +00002479 }
2480 }
2481#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00002482
2483 if (peer->default_rmap[afi][safi].name)
2484 {
2485 binfo.peer = bgp->peer_self;
2486 binfo.attr = &attr;
2487
paulfee0f4c2004-09-13 05:12:46 +00002488 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT);
2489
paul718e3742002-12-13 20:15:29 +00002490 ret = route_map_apply (peer->default_rmap[afi][safi].map, &p,
2491 RMAP_BGP, &binfo);
2492
paulfee0f4c2004-09-13 05:12:46 +00002493 bgp->peer_self->rmap_type = 0;
2494
paul718e3742002-12-13 20:15:29 +00002495 if (ret == RMAP_DENYMATCH)
2496 {
2497 bgp_attr_flush (&attr);
2498 withdraw = 1;
2499 }
2500 }
2501
2502 if (withdraw)
2503 {
2504 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE))
2505 bgp_default_withdraw_send (peer, afi, safi);
2506 UNSET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2507 }
2508 else
2509 {
2510 SET_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_DEFAULT_ORIGINATE);
2511 bgp_default_update_send (peer, &attr, afi, safi, from);
2512 }
Paul Jakmafb982c22007-05-04 20:15:47 +00002513
2514 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002515 aspath_unintern (aspath);
2516}
2517
2518static void
2519bgp_announce_table (struct peer *peer, afi_t afi, safi_t safi,
paulfee0f4c2004-09-13 05:12:46 +00002520 struct bgp_table *table, int rsclient)
paul718e3742002-12-13 20:15:29 +00002521{
2522 struct bgp_node *rn;
2523 struct bgp_info *ri;
Chris Caputo228da422009-07-18 05:44:03 +00002524 struct attr attr = { 0 };
Paul Jakmafb982c22007-05-04 20:15:47 +00002525
paul718e3742002-12-13 20:15:29 +00002526 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002527 table = (rsclient) ? peer->rib[afi][safi] : peer->bgp->rib[afi][safi];
paul718e3742002-12-13 20:15:29 +00002528
2529 if (safi != SAFI_MPLS_VPN
2530 && CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE))
2531 bgp_default_originate (peer, afi, safi, 0);
2532
2533 for (rn = bgp_table_top (table); rn; rn = bgp_route_next(rn))
2534 for (ri = rn->info; ri; ri = ri->next)
2535 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED) && ri->peer != peer)
2536 {
paulfee0f4c2004-09-13 05:12:46 +00002537 if ( (rsclient) ?
2538 (bgp_announce_check_rsclient (ri, peer, &rn->p, &attr, afi, safi))
2539 : (bgp_announce_check (ri, peer, &rn->p, &attr, afi, safi)))
paul718e3742002-12-13 20:15:29 +00002540 bgp_adj_out_set (rn, peer, &rn->p, &attr, afi, safi, ri);
2541 else
2542 bgp_adj_out_unset (rn, peer, &rn->p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00002543
2544 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00002545 }
2546}
2547
2548void
2549bgp_announce_route (struct peer *peer, afi_t afi, safi_t safi)
2550{
2551 struct bgp_node *rn;
2552 struct bgp_table *table;
2553
2554 if (peer->status != Established)
2555 return;
2556
2557 if (! peer->afc_nego[afi][safi])
2558 return;
2559
2560 /* First update is deferred until ORF or ROUTE-REFRESH is received */
2561 if (CHECK_FLAG (peer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH))
2562 return;
2563
2564 if (safi != SAFI_MPLS_VPN)
paulfee0f4c2004-09-13 05:12:46 +00002565 bgp_announce_table (peer, afi, safi, NULL, 0);
paul718e3742002-12-13 20:15:29 +00002566 else
2567 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2568 rn = bgp_route_next(rn))
2569 if ((table = (rn->info)) != NULL)
paulfee0f4c2004-09-13 05:12:46 +00002570 bgp_announce_table (peer, afi, safi, table, 0);
2571
2572 if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
2573 bgp_announce_table (peer, afi, safi, NULL, 1);
paul718e3742002-12-13 20:15:29 +00002574}
2575
2576void
2577bgp_announce_route_all (struct peer *peer)
2578{
2579 afi_t afi;
2580 safi_t safi;
2581
2582 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2583 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
2584 bgp_announce_route (peer, afi, safi);
2585}
2586
2587static void
paulfee0f4c2004-09-13 05:12:46 +00002588bgp_soft_reconfig_table_rsclient (struct peer *rsclient, afi_t afi,
2589 safi_t safi, struct bgp_table *table)
2590{
2591 struct bgp_node *rn;
2592 struct bgp_adj_in *ain;
2593
2594 if (! table)
2595 table = rsclient->bgp->rib[afi][safi];
2596
2597 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2598 for (ain = rn->adj_in; ain; ain = ain->next)
2599 {
2600 bgp_update_rsclient (rsclient, afi, safi, ain->attr, ain->peer,
2601 &rn->p, ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
2602 }
2603}
2604
2605void
2606bgp_soft_reconfig_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
2607{
2608 struct bgp_table *table;
2609 struct bgp_node *rn;
2610
2611 if (safi != SAFI_MPLS_VPN)
2612 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, NULL);
2613
2614 else
2615 for (rn = bgp_table_top (rsclient->bgp->rib[afi][safi]); rn;
2616 rn = bgp_route_next (rn))
2617 if ((table = rn->info) != NULL)
2618 bgp_soft_reconfig_table_rsclient (rsclient, afi, safi, table);
2619}
2620
2621static void
paul718e3742002-12-13 20:15:29 +00002622bgp_soft_reconfig_table (struct peer *peer, afi_t afi, safi_t safi,
2623 struct bgp_table *table)
2624{
2625 int ret;
2626 struct bgp_node *rn;
2627 struct bgp_adj_in *ain;
2628
2629 if (! table)
2630 table = peer->bgp->rib[afi][safi];
2631
2632 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2633 for (ain = rn->adj_in; ain; ain = ain->next)
2634 {
2635 if (ain->peer == peer)
2636 {
2637 ret = bgp_update (peer, &rn->p, ain->attr, afi, safi,
2638 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
2639 NULL, NULL, 1);
2640 if (ret < 0)
2641 {
2642 bgp_unlock_node (rn);
2643 return;
2644 }
2645 continue;
2646 }
2647 }
2648}
2649
2650void
2651bgp_soft_reconfig_in (struct peer *peer, afi_t afi, safi_t safi)
2652{
2653 struct bgp_node *rn;
2654 struct bgp_table *table;
2655
2656 if (peer->status != Established)
2657 return;
2658
2659 if (safi != SAFI_MPLS_VPN)
2660 bgp_soft_reconfig_table (peer, afi, safi, NULL);
2661 else
2662 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2663 rn = bgp_route_next (rn))
2664 if ((table = rn->info) != NULL)
2665 bgp_soft_reconfig_table (peer, afi, safi, table);
2666}
2667
Chris Caputo228da422009-07-18 05:44:03 +00002668
2669struct bgp_clear_node_queue
2670{
2671 struct bgp_node *rn;
2672 enum bgp_clear_route_type purpose;
2673};
2674
paul200df112005-06-01 11:17:05 +00002675static wq_item_status
paul0fb58d52005-11-14 14:31:49 +00002676bgp_clear_route_node (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002677{
Chris Caputo228da422009-07-18 05:44:03 +00002678 struct bgp_clear_node_queue *cnq = data;
2679 struct bgp_node *rn = cnq->rn;
Paul Jakma64e580a2006-02-21 01:09:01 +00002680 struct peer *peer = wq->spec.data;
paul200df112005-06-01 11:17:05 +00002681 struct bgp_info *ri;
Paul Jakma64e580a2006-02-21 01:09:01 +00002682 afi_t afi = rn->table->afi;
2683 safi_t safi = rn->table->safi;
paul200df112005-06-01 11:17:05 +00002684
Paul Jakma64e580a2006-02-21 01:09:01 +00002685 assert (rn && peer);
paul200df112005-06-01 11:17:05 +00002686
Paul Jakma64e580a2006-02-21 01:09:01 +00002687 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002688 if (ri->peer == peer || cnq->purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
paul200df112005-06-01 11:17:05 +00002689 {
2690 /* graceful restart STALE flag set. */
Paul Jakma64e580a2006-02-21 01:09:01 +00002691 if (CHECK_FLAG (peer->sflags, PEER_STATUS_NSF_WAIT)
2692 && peer->nsf[afi][safi]
paul200df112005-06-01 11:17:05 +00002693 && ! CHECK_FLAG (ri->flags, BGP_INFO_STALE)
Paul Jakma1a392d42006-09-07 00:24:49 +00002694 && ! CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
2695 bgp_info_set_flag (rn, ri, BGP_INFO_STALE);
paul200df112005-06-01 11:17:05 +00002696 else
Paul Jakma64e580a2006-02-21 01:09:01 +00002697 bgp_rib_remove (rn, ri, peer, afi, safi);
paul200df112005-06-01 11:17:05 +00002698 break;
2699 }
paul200df112005-06-01 11:17:05 +00002700 return WQ_SUCCESS;
2701}
2702
2703static void
paul0fb58d52005-11-14 14:31:49 +00002704bgp_clear_node_queue_del (struct work_queue *wq, void *data)
paul200df112005-06-01 11:17:05 +00002705{
Chris Caputo228da422009-07-18 05:44:03 +00002706 struct bgp_clear_node_queue *cnq = data;
2707 struct bgp_node *rn = cnq->rn;
2708 struct bgp_table *table = rn->table;
Paul Jakma64e580a2006-02-21 01:09:01 +00002709
2710 bgp_unlock_node (rn);
Chris Caputo228da422009-07-18 05:44:03 +00002711 bgp_table_unlock (table);
2712 XFREE (MTYPE_BGP_CLEAR_NODE_QUEUE, cnq);
paul200df112005-06-01 11:17:05 +00002713}
2714
2715static void
paul94f2b392005-06-28 12:44:16 +00002716bgp_clear_node_complete (struct work_queue *wq)
paul200df112005-06-01 11:17:05 +00002717{
Paul Jakma64e580a2006-02-21 01:09:01 +00002718 struct peer *peer = wq->spec.data;
2719
Paul Jakma3e0c78e2006-03-06 18:06:53 +00002720 /* Tickle FSM to start moving again */
Paul Jakmaca058a32006-09-14 02:58:49 +00002721 BGP_EVENT_ADD (peer, Clearing_Completed);
Chris Caputo228da422009-07-18 05:44:03 +00002722
2723 peer_unlock (peer); /* bgp_clear_route */
paul200df112005-06-01 11:17:05 +00002724}
2725
2726static void
Paul Jakma64e580a2006-02-21 01:09:01 +00002727bgp_clear_node_queue_init (struct peer *peer)
paul200df112005-06-01 11:17:05 +00002728{
Paul Jakmaa2943652009-07-21 14:02:04 +01002729 char wname[sizeof("clear xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx")];
Paul Jakma64e580a2006-02-21 01:09:01 +00002730
Paul Jakmaa2943652009-07-21 14:02:04 +01002731 snprintf (wname, sizeof(wname), "clear %s", peer->host);
Paul Jakma64e580a2006-02-21 01:09:01 +00002732#undef CLEAR_QUEUE_NAME_LEN
2733
2734 if ( (peer->clear_node_queue = work_queue_new (bm->master, wname)) == NULL)
paul200df112005-06-01 11:17:05 +00002735 {
2736 zlog_err ("%s: Failed to allocate work queue", __func__);
2737 exit (1);
2738 }
Paul Jakma64e580a2006-02-21 01:09:01 +00002739 peer->clear_node_queue->spec.hold = 10;
2740 peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
2741 peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
2742 peer->clear_node_queue->spec.completion_func = &bgp_clear_node_complete;
2743 peer->clear_node_queue->spec.max_retries = 0;
2744
2745 /* we only 'lock' this peer reference when the queue is actually active */
2746 peer->clear_node_queue->spec.data = peer;
paul200df112005-06-01 11:17:05 +00002747}
2748
paul718e3742002-12-13 20:15:29 +00002749static void
2750bgp_clear_route_table (struct peer *peer, afi_t afi, safi_t safi,
Chris Caputo228da422009-07-18 05:44:03 +00002751 struct bgp_table *table, struct peer *rsclient,
2752 enum bgp_clear_route_type purpose)
paul718e3742002-12-13 20:15:29 +00002753{
2754 struct bgp_node *rn;
paul200df112005-06-01 11:17:05 +00002755
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002756
paul718e3742002-12-13 20:15:29 +00002757 if (! table)
paulfee0f4c2004-09-13 05:12:46 +00002758 table = (rsclient) ? rsclient->rib[afi][safi] : peer->bgp->rib[afi][safi];
Paul Jakma64e580a2006-02-21 01:09:01 +00002759
hasso6cf159b2005-03-21 10:28:14 +00002760 /* If still no table => afi/safi isn't configured at all or smth. */
2761 if (! table)
2762 return;
Paul Jakma65ca75e2006-05-04 08:08:15 +00002763
2764 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2765 {
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002766 struct bgp_info *ri;
2767 struct bgp_adj_in *ain;
2768 struct bgp_adj_out *aout;
2769
Paul Jakma65ca75e2006-05-04 08:08:15 +00002770 if (rn->info == NULL)
2771 continue;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002772
2773 /* XXX:TODO: This is suboptimal, every non-empty route_node is
2774 * queued for every clearing peer, regardless of whether it is
2775 * relevant to the peer at hand.
2776 *
2777 * Overview: There are 3 different indices which need to be
2778 * scrubbed, potentially, when a peer is removed:
2779 *
2780 * 1 peer's routes visible via the RIB (ie accepted routes)
2781 * 2 peer's routes visible by the (optional) peer's adj-in index
2782 * 3 other routes visible by the peer's adj-out index
2783 *
2784 * 3 there is no hurry in scrubbing, once the struct peer is
2785 * removed from bgp->peer, we could just GC such deleted peer's
2786 * adj-outs at our leisure.
2787 *
2788 * 1 and 2 must be 'scrubbed' in some way, at least made
2789 * invisible via RIB index before peer session is allowed to be
2790 * brought back up. So one needs to know when such a 'search' is
2791 * complete.
2792 *
2793 * Ideally:
2794 *
2795 * - there'd be a single global queue or a single RIB walker
2796 * - rather than tracking which route_nodes still need to be
2797 * examined on a peer basis, we'd track which peers still
2798 * aren't cleared
2799 *
2800 * Given that our per-peer prefix-counts now should be reliable,
2801 * this may actually be achievable. It doesn't seem to be a huge
2802 * problem at this time,
2803 */
2804 for (ri = rn->info; ri; ri = ri->next)
Chris Caputo228da422009-07-18 05:44:03 +00002805 if (ri->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002806 {
Chris Caputo228da422009-07-18 05:44:03 +00002807 struct bgp_clear_node_queue *cnq;
2808
2809 /* both unlocked in bgp_clear_node_queue_del */
2810 bgp_table_lock (rn->table);
2811 bgp_lock_node (rn);
2812 cnq = XCALLOC (MTYPE_BGP_CLEAR_NODE_QUEUE,
2813 sizeof (struct bgp_clear_node_queue));
2814 cnq->rn = rn;
2815 cnq->purpose = purpose;
2816 work_queue_add (peer->clear_node_queue, cnq);
2817 break;
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002818 }
2819
2820 for (ain = rn->adj_in; ain; ain = ain->next)
Chris Caputo228da422009-07-18 05:44:03 +00002821 if (ain->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002822 {
2823 bgp_adj_in_remove (rn, ain);
2824 bgp_unlock_node (rn);
2825 break;
2826 }
2827 for (aout = rn->adj_out; aout; aout = aout->next)
Chris Caputo228da422009-07-18 05:44:03 +00002828 if (aout->peer == peer || purpose == BGP_CLEAR_ROUTE_MY_RSCLIENT)
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002829 {
2830 bgp_adj_out_remove (rn, aout, peer, afi, safi);
2831 bgp_unlock_node (rn);
2832 break;
2833 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002834 }
2835 return;
2836}
2837
2838void
Chris Caputo228da422009-07-18 05:44:03 +00002839bgp_clear_route (struct peer *peer, afi_t afi, safi_t safi,
2840 enum bgp_clear_route_type purpose)
Paul Jakma65ca75e2006-05-04 08:08:15 +00002841{
2842 struct bgp_node *rn;
2843 struct bgp_table *table;
2844 struct peer *rsclient;
2845 struct listnode *node, *nnode;
hasso6cf159b2005-03-21 10:28:14 +00002846
Paul Jakma64e580a2006-02-21 01:09:01 +00002847 if (peer->clear_node_queue == NULL)
2848 bgp_clear_node_queue_init (peer);
paul200df112005-06-01 11:17:05 +00002849
Paul Jakmaca058a32006-09-14 02:58:49 +00002850 /* bgp_fsm.c keeps sessions in state Clearing, not transitioning to
2851 * Idle until it receives a Clearing_Completed event. This protects
2852 * against peers which flap faster than we can we clear, which could
2853 * lead to:
Paul Jakma64e580a2006-02-21 01:09:01 +00002854 *
2855 * a) race with routes from the new session being installed before
2856 * clear_route_node visits the node (to delete the route of that
2857 * peer)
2858 * b) resource exhaustion, clear_route_node likely leads to an entry
2859 * on the process_main queue. Fast-flapping could cause that queue
2860 * to grow and grow.
paul200df112005-06-01 11:17:05 +00002861 */
Paul Jakmaca058a32006-09-14 02:58:49 +00002862 if (!peer->clear_node_queue->thread)
2863 peer_lock (peer); /* bgp_clear_node_complete */
paulfee0f4c2004-09-13 05:12:46 +00002864
Chris Caputo228da422009-07-18 05:44:03 +00002865 switch (purpose)
paulfee0f4c2004-09-13 05:12:46 +00002866 {
Chris Caputo228da422009-07-18 05:44:03 +00002867 case BGP_CLEAR_ROUTE_NORMAL:
2868 if (safi != SAFI_MPLS_VPN)
2869 bgp_clear_route_table (peer, afi, safi, NULL, NULL, purpose);
2870 else
2871 for (rn = bgp_table_top (peer->bgp->rib[afi][safi]); rn;
2872 rn = bgp_route_next (rn))
2873 if ((table = rn->info) != NULL)
2874 bgp_clear_route_table (peer, afi, safi, table, NULL, purpose);
2875
2876 for (ALL_LIST_ELEMENTS (peer->bgp->rsclient, node, nnode, rsclient))
2877 if (CHECK_FLAG(rsclient->af_flags[afi][safi],
2878 PEER_FLAG_RSERVER_CLIENT))
2879 bgp_clear_route_table (peer, afi, safi, NULL, rsclient, purpose);
2880 break;
2881
2882 case BGP_CLEAR_ROUTE_MY_RSCLIENT:
2883 bgp_clear_route_table (peer, afi, safi, NULL, peer, purpose);
2884 break;
2885
2886 default:
2887 assert (0);
2888 break;
paulfee0f4c2004-09-13 05:12:46 +00002889 }
Paul Jakma65ca75e2006-05-04 08:08:15 +00002890
Paul Jakmaca058a32006-09-14 02:58:49 +00002891 /* If no routes were cleared, nothing was added to workqueue, the
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002892 * completion function won't be run by workqueue code - call it here.
2893 * XXX: Actually, this assumption doesn't hold, see
2894 * bgp_clear_route_table(), we queue all non-empty nodes.
Paul Jakmaca058a32006-09-14 02:58:49 +00002895 *
2896 * Additionally, there is a presumption in FSM that clearing is only
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002897 * really needed if peer state is Established - peers in
2898 * pre-Established states shouldn't have any route-update state
2899 * associated with them (in or out).
Paul Jakmaca058a32006-09-14 02:58:49 +00002900 *
Paul Jakmaf2c31ac2007-02-22 17:48:42 +00002901 * We still can get here in pre-Established though, through
2902 * peer_delete -> bgp_fsm_change_status, so this is a useful sanity
2903 * check to ensure the assumption above holds.
Paul Jakmaca058a32006-09-14 02:58:49 +00002904 *
2905 * At some future point, this check could be move to the top of the
2906 * function, and do a quick early-return when state is
2907 * pre-Established, avoiding above list and table scans. Once we're
2908 * sure it is safe..
Paul Jakma65ca75e2006-05-04 08:08:15 +00002909 */
2910 if (!peer->clear_node_queue->thread)
2911 bgp_clear_node_complete (peer->clear_node_queue);
paul718e3742002-12-13 20:15:29 +00002912}
2913
2914void
2915bgp_clear_route_all (struct peer *peer)
2916{
2917 afi_t afi;
2918 safi_t safi;
2919
2920 for (afi = AFI_IP; afi < AFI_MAX; afi++)
2921 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
Chris Caputo228da422009-07-18 05:44:03 +00002922 bgp_clear_route (peer, afi, safi, BGP_CLEAR_ROUTE_NORMAL);
paul718e3742002-12-13 20:15:29 +00002923}
2924
2925void
2926bgp_clear_adj_in (struct peer *peer, afi_t afi, safi_t safi)
2927{
2928 struct bgp_table *table;
2929 struct bgp_node *rn;
2930 struct bgp_adj_in *ain;
2931
2932 table = peer->bgp->rib[afi][safi];
2933
2934 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2935 for (ain = rn->adj_in; ain ; ain = ain->next)
2936 if (ain->peer == peer)
2937 {
2938 bgp_adj_in_remove (rn, ain);
2939 bgp_unlock_node (rn);
2940 break;
2941 }
2942}
hasso93406d82005-02-02 14:40:33 +00002943
2944void
2945bgp_clear_stale_route (struct peer *peer, afi_t afi, safi_t safi)
2946{
2947 struct bgp_node *rn;
2948 struct bgp_info *ri;
2949 struct bgp_table *table;
2950
2951 table = peer->bgp->rib[afi][safi];
2952
2953 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2954 {
2955 for (ri = rn->info; ri; ri = ri->next)
2956 if (ri->peer == peer)
2957 {
2958 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
2959 bgp_rib_remove (rn, ri, peer, afi, safi);
2960 break;
2961 }
2962 }
2963}
paul718e3742002-12-13 20:15:29 +00002964
2965/* Delete all kernel routes. */
2966void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002967bgp_cleanup_routes (void)
paul718e3742002-12-13 20:15:29 +00002968{
2969 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00002970 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00002971 struct bgp_node *rn;
2972 struct bgp_table *table;
2973 struct bgp_info *ri;
2974
paul1eb8ef22005-04-07 07:30:20 +00002975 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00002976 {
2977 table = bgp->rib[AFI_IP][SAFI_UNICAST];
2978
2979 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2980 for (ri = rn->info; ri; ri = ri->next)
2981 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2982 && ri->type == ZEBRA_ROUTE_BGP
2983 && ri->sub_type == BGP_ROUTE_NORMAL)
2984 bgp_zebra_withdraw (&rn->p, ri);
2985
2986 table = bgp->rib[AFI_IP6][SAFI_UNICAST];
2987
2988 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
2989 for (ri = rn->info; ri; ri = ri->next)
2990 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED)
2991 && ri->type == ZEBRA_ROUTE_BGP
2992 && ri->sub_type == BGP_ROUTE_NORMAL)
2993 bgp_zebra_withdraw (&rn->p, ri);
2994 }
2995}
2996
2997void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08002998bgp_reset (void)
paul718e3742002-12-13 20:15:29 +00002999{
3000 vty_reset ();
3001 bgp_zclient_reset ();
3002 access_list_reset ();
3003 prefix_list_reset ();
3004}
3005
3006/* Parse NLRI stream. Withdraw NLRI is recognized by NULL attr
3007 value. */
3008int
3009bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
3010{
3011 u_char *pnt;
3012 u_char *lim;
3013 struct prefix p;
3014 int psize;
3015 int ret;
3016
3017 /* Check peer status. */
3018 if (peer->status != Established)
3019 return 0;
3020
3021 pnt = packet->nlri;
3022 lim = pnt + packet->length;
3023
3024 for (; pnt < lim; pnt += psize)
3025 {
3026 /* Clear prefix structure. */
3027 memset (&p, 0, sizeof (struct prefix));
3028
3029 /* Fetch prefix length. */
3030 p.prefixlen = *pnt++;
3031 p.family = afi2family (packet->afi);
3032
3033 /* Already checked in nlri_sanity_check(). We do double check
3034 here. */
3035 if ((packet->afi == AFI_IP && p.prefixlen > 32)
3036 || (packet->afi == AFI_IP6 && p.prefixlen > 128))
3037 return -1;
3038
3039 /* Packet size overflow check. */
3040 psize = PSIZE (p.prefixlen);
3041
3042 /* When packet overflow occur return immediately. */
3043 if (pnt + psize > lim)
3044 return -1;
3045
3046 /* Fetch prefix from NLRI packet. */
3047 memcpy (&p.u.prefix, pnt, psize);
3048
3049 /* Check address. */
3050 if (packet->afi == AFI_IP && packet->safi == SAFI_UNICAST)
3051 {
3052 if (IN_CLASSD (ntohl (p.u.prefix4.s_addr)))
3053 {
paulf5ba3872004-07-09 12:11:31 +00003054 /*
3055 * From draft-ietf-idr-bgp4-22, Section 6.3:
3056 * If a BGP router receives an UPDATE message with a
3057 * semantically incorrect NLRI field, in which a prefix is
3058 * semantically incorrect (eg. an unexpected multicast IP
3059 * address), it should ignore the prefix.
3060 */
paul718e3742002-12-13 20:15:29 +00003061 zlog (peer->log, LOG_ERR,
3062 "IPv4 unicast NLRI is multicast address %s",
3063 inet_ntoa (p.u.prefix4));
paulf5ba3872004-07-09 12:11:31 +00003064
paul718e3742002-12-13 20:15:29 +00003065 return -1;
3066 }
3067 }
3068
3069#ifdef HAVE_IPV6
3070 /* Check address. */
3071 if (packet->afi == AFI_IP6 && packet->safi == SAFI_UNICAST)
3072 {
3073 if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3074 {
3075 char buf[BUFSIZ];
3076
3077 zlog (peer->log, LOG_WARNING,
3078 "IPv6 link-local NLRI received %s ignore this NLRI",
3079 inet_ntop (AF_INET6, &p.u.prefix6, buf, BUFSIZ));
3080
3081 continue;
3082 }
3083 }
3084#endif /* HAVE_IPV6 */
3085
3086 /* Normal process. */
3087 if (attr)
3088 ret = bgp_update (peer, &p, attr, packet->afi, packet->safi,
3089 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL, 0);
3090 else
3091 ret = bgp_withdraw (peer, &p, attr, packet->afi, packet->safi,
3092 ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL, NULL, NULL);
3093
3094 /* Address family configuration mismatch or maximum-prefix count
3095 overflow. */
3096 if (ret < 0)
3097 return -1;
3098 }
3099
3100 /* Packet length consistency check. */
3101 if (pnt != lim)
3102 return -1;
3103
3104 return 0;
3105}
3106
3107/* NLRI encode syntax check routine. */
3108int
3109bgp_nlri_sanity_check (struct peer *peer, int afi, u_char *pnt,
3110 bgp_size_t length)
3111{
3112 u_char *end;
3113 u_char prefixlen;
3114 int psize;
3115
3116 end = pnt + length;
3117
3118 /* RFC1771 6.3 The NLRI field in the UPDATE message is checked for
3119 syntactic validity. If the field is syntactically incorrect,
3120 then the Error Subcode is set to Invalid Network Field. */
3121
3122 while (pnt < end)
3123 {
3124 prefixlen = *pnt++;
3125
3126 /* Prefix length check. */
3127 if ((afi == AFI_IP && prefixlen > 32)
3128 || (afi == AFI_IP6 && prefixlen > 128))
3129 {
3130 plog_err (peer->log,
3131 "%s [Error] Update packet error (wrong prefix length %d)",
3132 peer->host, prefixlen);
3133 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3134 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3135 return -1;
3136 }
3137
3138 /* Packet size overflow check. */
3139 psize = PSIZE (prefixlen);
3140
3141 if (pnt + psize > end)
3142 {
3143 plog_err (peer->log,
3144 "%s [Error] Update packet error"
3145 " (prefix data overflow prefix size is %d)",
3146 peer->host, psize);
3147 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3148 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3149 return -1;
3150 }
3151
3152 pnt += psize;
3153 }
3154
3155 /* Packet length consistency check. */
3156 if (pnt != end)
3157 {
3158 plog_err (peer->log,
3159 "%s [Error] Update packet error"
3160 " (prefix length mismatch with total length)",
3161 peer->host);
3162 bgp_notify_send (peer, BGP_NOTIFY_UPDATE_ERR,
3163 BGP_NOTIFY_UPDATE_INVAL_NETWORK);
3164 return -1;
3165 }
3166 return 0;
3167}
3168
paul94f2b392005-06-28 12:44:16 +00003169static struct bgp_static *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08003170bgp_static_new (void)
paul718e3742002-12-13 20:15:29 +00003171{
Stephen Hemminger393deb92008-08-18 14:13:29 -07003172 return XCALLOC (MTYPE_BGP_STATIC, sizeof (struct bgp_static));
paul718e3742002-12-13 20:15:29 +00003173}
3174
paul94f2b392005-06-28 12:44:16 +00003175static void
paul718e3742002-12-13 20:15:29 +00003176bgp_static_free (struct bgp_static *bgp_static)
3177{
3178 if (bgp_static->rmap.name)
3179 free (bgp_static->rmap.name);
3180 XFREE (MTYPE_BGP_STATIC, bgp_static);
3181}
3182
paul94f2b392005-06-28 12:44:16 +00003183static void
paulfee0f4c2004-09-13 05:12:46 +00003184bgp_static_withdraw_rsclient (struct bgp *bgp, struct peer *rsclient,
3185 struct prefix *p, afi_t afi, safi_t safi)
3186{
3187 struct bgp_node *rn;
3188 struct bgp_info *ri;
3189
3190 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3191
3192 /* Check selected route and self inserted route. */
3193 for (ri = rn->info; ri; ri = ri->next)
3194 if (ri->peer == bgp->peer_self
3195 && ri->type == ZEBRA_ROUTE_BGP
3196 && ri->sub_type == BGP_ROUTE_STATIC)
3197 break;
3198
3199 /* Withdraw static BGP route from routing table. */
3200 if (ri)
3201 {
paulfee0f4c2004-09-13 05:12:46 +00003202 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003203 bgp_process (bgp, rn, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003204 }
3205
3206 /* Unlock bgp_node_lookup. */
3207 bgp_unlock_node (rn);
3208}
3209
paul94f2b392005-06-28 12:44:16 +00003210static void
paulfee0f4c2004-09-13 05:12:46 +00003211bgp_static_update_rsclient (struct peer *rsclient, struct prefix *p,
Paul Jakmafb982c22007-05-04 20:15:47 +00003212 struct bgp_static *bgp_static,
3213 afi_t afi, safi_t safi)
paulfee0f4c2004-09-13 05:12:46 +00003214{
3215 struct bgp_node *rn;
3216 struct bgp_info *ri;
3217 struct bgp_info *new;
3218 struct bgp_info info;
paulfee0f4c2004-09-13 05:12:46 +00003219 struct attr *attr_new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003220 struct attr attr = {0 };
3221 struct attr new_attr = { .extra = 0 };
paulfee0f4c2004-09-13 05:12:46 +00003222 struct bgp *bgp;
3223 int ret;
3224 char buf[SU_ADDRSTRLEN];
3225
3226 bgp = rsclient->bgp;
3227
Paul Jakma06e110f2006-05-12 23:29:22 +00003228 assert (bgp_static);
3229 if (!bgp_static)
3230 return;
3231
paulfee0f4c2004-09-13 05:12:46 +00003232 rn = bgp_afi_node_get (rsclient->rib[afi][safi], afi, safi, p, NULL);
3233
3234 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakma06e110f2006-05-12 23:29:22 +00003235
3236 attr.nexthop = bgp_static->igpnexthop;
3237 attr.med = bgp_static->igpmetric;
3238 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
Paul Jakma41367172007-08-06 15:24:51 +00003239
Paul Jakma41367172007-08-06 15:24:51 +00003240 if (bgp_static->atomic)
3241 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3242
paulfee0f4c2004-09-13 05:12:46 +00003243 /* Apply network route-map for export to this rsclient. */
3244 if (bgp_static->rmap.name)
3245 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003246 struct attr attr_tmp = attr;
paulfee0f4c2004-09-13 05:12:46 +00003247 info.peer = rsclient;
Paul Jakmafb982c22007-05-04 20:15:47 +00003248 info.attr = &attr_tmp;
3249
paulfee0f4c2004-09-13 05:12:46 +00003250 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_EXPORT);
3251 SET_FLAG (rsclient->rmap_type, PEER_RMAP_TYPE_NETWORK);
3252
3253 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
3254
3255 rsclient->rmap_type = 0;
3256
3257 if (ret == RMAP_DENYMATCH)
3258 {
3259 /* Free uninterned attribute. */
Paul Jakmafb982c22007-05-04 20:15:47 +00003260 bgp_attr_flush (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003261
3262 /* Unintern original. */
3263 aspath_unintern (attr.aspath);
3264 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
Paul Jakmafb982c22007-05-04 20:15:47 +00003265 bgp_attr_extra_free (&attr);
3266
paulfee0f4c2004-09-13 05:12:46 +00003267 return;
3268 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003269 attr_new = bgp_attr_intern (&attr_tmp);
paulfee0f4c2004-09-13 05:12:46 +00003270 }
3271 else
3272 attr_new = bgp_attr_intern (&attr);
Paul Jakmafb982c22007-05-04 20:15:47 +00003273
Stephen Hemminger7badc262010-08-05 10:26:31 -07003274 bgp_attr_dup(&new_attr, attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00003275
paulfee0f4c2004-09-13 05:12:46 +00003276 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3277
Paul Jakmafb982c22007-05-04 20:15:47 +00003278 if (bgp_import_modifier (rsclient, bgp->peer_self, p, &new_attr, afi, safi)
3279 == RMAP_DENY)
3280 {
paulfee0f4c2004-09-13 05:12:46 +00003281 /* This BGP update is filtered. Log the reason then update BGP entry. */
3282 if (BGP_DEBUG (update, UPDATE_IN))
ajsd2c1f162004-12-08 21:10:20 +00003283 zlog (rsclient->log, LOG_DEBUG,
paulfee0f4c2004-09-13 05:12:46 +00003284 "Static UPDATE about %s/%d -- DENIED for RS-client %s due to: import-policy",
3285 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
3286 p->prefixlen, rsclient->host);
3287
3288 bgp->peer_self->rmap_type = 0;
3289
3290 bgp_attr_unintern (attr_new);
3291 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003292 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003293
3294 bgp_static_withdraw_rsclient (bgp, rsclient, p, afi, safi);
3295
3296 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003297 }
paulfee0f4c2004-09-13 05:12:46 +00003298
3299 bgp->peer_self->rmap_type = 0;
3300
3301 bgp_attr_unintern (attr_new);
3302 attr_new = bgp_attr_intern (&new_attr);
Stephen Hemminger7badc262010-08-05 10:26:31 -07003303 bgp_attr_extra_free (&new_attr);
paulfee0f4c2004-09-13 05:12:46 +00003304
3305 for (ri = rn->info; ri; ri = ri->next)
3306 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3307 && ri->sub_type == BGP_ROUTE_STATIC)
3308 break;
3309
3310 if (ri)
3311 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003312 if (attrhash_cmp (ri->attr, attr_new) &&
3313 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paulfee0f4c2004-09-13 05:12:46 +00003314 {
3315 bgp_unlock_node (rn);
3316 bgp_attr_unintern (attr_new);
3317 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003318 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003319 return;
3320 }
3321 else
3322 {
3323 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003324 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paulfee0f4c2004-09-13 05:12:46 +00003325
3326 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003327 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3328 bgp_info_restore(rn, ri);
paulfee0f4c2004-09-13 05:12:46 +00003329 bgp_attr_unintern (ri->attr);
3330 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003331 ri->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003332
3333 /* Process change. */
3334 bgp_process (bgp, rn, afi, safi);
3335 bgp_unlock_node (rn);
3336 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003337 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003338 return;
Paul Jakmafb982c22007-05-04 20:15:47 +00003339 }
paulfee0f4c2004-09-13 05:12:46 +00003340 }
Paul Jakmafb982c22007-05-04 20:15:47 +00003341
paulfee0f4c2004-09-13 05:12:46 +00003342 /* Make new BGP info. */
3343 new = bgp_info_new ();
3344 new->type = ZEBRA_ROUTE_BGP;
3345 new->sub_type = BGP_ROUTE_STATIC;
3346 new->peer = bgp->peer_self;
3347 SET_FLAG (new->flags, BGP_INFO_VALID);
3348 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003349 new->uptime = bgp_clock ();
paulfee0f4c2004-09-13 05:12:46 +00003350
3351 /* Register new BGP information. */
3352 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003353
3354 /* route_node_get lock */
3355 bgp_unlock_node (rn);
3356
paulfee0f4c2004-09-13 05:12:46 +00003357 /* Process change. */
3358 bgp_process (bgp, rn, afi, safi);
3359
3360 /* Unintern original. */
3361 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003362 bgp_attr_extra_free (&attr);
paulfee0f4c2004-09-13 05:12:46 +00003363}
3364
paul94f2b392005-06-28 12:44:16 +00003365static void
paulfee0f4c2004-09-13 05:12:46 +00003366bgp_static_update_main (struct bgp *bgp, struct prefix *p,
paul718e3742002-12-13 20:15:29 +00003367 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3368{
3369 struct bgp_node *rn;
3370 struct bgp_info *ri;
3371 struct bgp_info *new;
3372 struct bgp_info info;
Paul Jakmafb982c22007-05-04 20:15:47 +00003373 struct attr attr = { 0 };
paul718e3742002-12-13 20:15:29 +00003374 struct attr *attr_new;
3375 int ret;
3376
Paul Jakmadd8103a2006-05-12 23:27:30 +00003377 assert (bgp_static);
3378 if (!bgp_static)
3379 return;
3380
paulfee0f4c2004-09-13 05:12:46 +00003381 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003382
3383 bgp_attr_default_set (&attr, BGP_ORIGIN_IGP);
Paul Jakmadd8103a2006-05-12 23:27:30 +00003384
3385 attr.nexthop = bgp_static->igpnexthop;
3386 attr.med = bgp_static->igpmetric;
3387 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
paul718e3742002-12-13 20:15:29 +00003388
Paul Jakma41367172007-08-06 15:24:51 +00003389 if (bgp_static->atomic)
3390 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE);
3391
paul718e3742002-12-13 20:15:29 +00003392 /* Apply route-map. */
3393 if (bgp_static->rmap.name)
3394 {
Paul Jakmafb982c22007-05-04 20:15:47 +00003395 struct attr attr_tmp = attr;
paul718e3742002-12-13 20:15:29 +00003396 info.peer = bgp->peer_self;
paul286e1e72003-08-08 00:24:31 +00003397 info.attr = &attr_tmp;
paul718e3742002-12-13 20:15:29 +00003398
paulfee0f4c2004-09-13 05:12:46 +00003399 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_NETWORK);
3400
paul718e3742002-12-13 20:15:29 +00003401 ret = route_map_apply (bgp_static->rmap.map, p, RMAP_BGP, &info);
paul286e1e72003-08-08 00:24:31 +00003402
paulfee0f4c2004-09-13 05:12:46 +00003403 bgp->peer_self->rmap_type = 0;
3404
paul718e3742002-12-13 20:15:29 +00003405 if (ret == RMAP_DENYMATCH)
3406 {
3407 /* Free uninterned attribute. */
paul286e1e72003-08-08 00:24:31 +00003408 bgp_attr_flush (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003409
3410 /* Unintern original. */
3411 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003412 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003413 bgp_static_withdraw (bgp, p, afi, safi);
3414 return;
3415 }
paul286e1e72003-08-08 00:24:31 +00003416 attr_new = bgp_attr_intern (&attr_tmp);
paul718e3742002-12-13 20:15:29 +00003417 }
paul286e1e72003-08-08 00:24:31 +00003418 else
3419 attr_new = bgp_attr_intern (&attr);
paul718e3742002-12-13 20:15:29 +00003420
3421 for (ri = rn->info; ri; ri = ri->next)
3422 if (ri->peer == bgp->peer_self && ri->type == ZEBRA_ROUTE_BGP
3423 && ri->sub_type == BGP_ROUTE_STATIC)
3424 break;
3425
3426 if (ri)
3427 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003428 if (attrhash_cmp (ri->attr, attr_new) &&
3429 !CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00003430 {
3431 bgp_unlock_node (rn);
3432 bgp_attr_unintern (attr_new);
3433 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003434 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003435 return;
3436 }
3437 else
3438 {
3439 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00003440 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00003441
3442 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00003443 if (CHECK_FLAG(ri->flags, BGP_INFO_REMOVED))
3444 bgp_info_restore(rn, ri);
3445 else
3446 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003447 bgp_attr_unintern (ri->attr);
3448 ri->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003449 ri->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003450
3451 /* Process change. */
3452 bgp_aggregate_increment (bgp, p, ri, afi, safi);
3453 bgp_process (bgp, rn, afi, safi);
3454 bgp_unlock_node (rn);
3455 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003456 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003457 return;
3458 }
3459 }
3460
3461 /* Make new BGP info. */
3462 new = bgp_info_new ();
3463 new->type = ZEBRA_ROUTE_BGP;
3464 new->sub_type = BGP_ROUTE_STATIC;
3465 new->peer = bgp->peer_self;
3466 SET_FLAG (new->flags, BGP_INFO_VALID);
3467 new->attr = attr_new;
Stephen Hemminger65957882010-01-15 16:22:10 +03003468 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00003469
3470 /* Aggregate address increment. */
3471 bgp_aggregate_increment (bgp, p, new, afi, safi);
3472
3473 /* Register new BGP information. */
3474 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00003475
3476 /* route_node_get lock */
3477 bgp_unlock_node (rn);
3478
paul718e3742002-12-13 20:15:29 +00003479 /* Process change. */
3480 bgp_process (bgp, rn, afi, safi);
3481
3482 /* Unintern original. */
3483 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00003484 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00003485}
3486
3487void
paulfee0f4c2004-09-13 05:12:46 +00003488bgp_static_update (struct bgp *bgp, struct prefix *p,
3489 struct bgp_static *bgp_static, afi_t afi, safi_t safi)
3490{
3491 struct peer *rsclient;
paul1eb8ef22005-04-07 07:30:20 +00003492 struct listnode *node, *nnode;
paulfee0f4c2004-09-13 05:12:46 +00003493
3494 bgp_static_update_main (bgp, p, bgp_static, afi, safi);
3495
paul1eb8ef22005-04-07 07:30:20 +00003496 for (ALL_LIST_ELEMENTS (bgp->rsclient, node, nnode, rsclient))
paulfee0f4c2004-09-13 05:12:46 +00003497 {
Paul Jakmada5b30f2006-05-08 14:37:17 +00003498 if (CHECK_FLAG (rsclient->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
3499 bgp_static_update_rsclient (rsclient, p, bgp_static, afi, safi);
paulfee0f4c2004-09-13 05:12:46 +00003500 }
3501}
3502
paul94f2b392005-06-28 12:44:16 +00003503static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003504bgp_static_update_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3505 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003506{
3507 struct bgp_node *rn;
3508 struct bgp_info *new;
Paul Jakmafb982c22007-05-04 20:15:47 +00003509
paulfee0f4c2004-09-13 05:12:46 +00003510 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003511
3512 /* Make new BGP info. */
3513 new = bgp_info_new ();
3514 new->type = ZEBRA_ROUTE_BGP;
3515 new->sub_type = BGP_ROUTE_STATIC;
3516 new->peer = bgp->peer_self;
3517 new->attr = bgp_attr_default_intern (BGP_ORIGIN_IGP);
3518 SET_FLAG (new->flags, BGP_INFO_VALID);
Stephen Hemminger65957882010-01-15 16:22:10 +03003519 new->uptime = bgp_clock ();
Paul Jakmafb982c22007-05-04 20:15:47 +00003520 new->extra = bgp_info_extra_new();
3521 memcpy (new->extra->tag, tag, 3);
paul718e3742002-12-13 20:15:29 +00003522
3523 /* Aggregate address increment. */
paul200df112005-06-01 11:17:05 +00003524 bgp_aggregate_increment (bgp, p, new, afi, safi);
paul718e3742002-12-13 20:15:29 +00003525
3526 /* Register new BGP information. */
paul200df112005-06-01 11:17:05 +00003527 bgp_info_add (rn, new);
paul718e3742002-12-13 20:15:29 +00003528
paul200df112005-06-01 11:17:05 +00003529 /* route_node_get lock */
3530 bgp_unlock_node (rn);
3531
paul718e3742002-12-13 20:15:29 +00003532 /* Process change. */
3533 bgp_process (bgp, rn, afi, safi);
3534}
3535
3536void
3537bgp_static_withdraw (struct bgp *bgp, struct prefix *p, afi_t afi,
3538 safi_t safi)
3539{
3540 struct bgp_node *rn;
3541 struct bgp_info *ri;
3542
paulfee0f4c2004-09-13 05:12:46 +00003543 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, NULL);
paul718e3742002-12-13 20:15:29 +00003544
3545 /* Check selected route and self inserted route. */
3546 for (ri = rn->info; ri; ri = ri->next)
3547 if (ri->peer == bgp->peer_self
3548 && ri->type == ZEBRA_ROUTE_BGP
3549 && ri->sub_type == BGP_ROUTE_STATIC)
3550 break;
3551
3552 /* Withdraw static BGP route from routing table. */
3553 if (ri)
3554 {
3555 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003556 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003557 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003558 }
3559
3560 /* Unlock bgp_node_lookup. */
3561 bgp_unlock_node (rn);
3562}
3563
3564void
paulfee0f4c2004-09-13 05:12:46 +00003565bgp_check_local_routes_rsclient (struct peer *rsclient, afi_t afi, safi_t safi)
3566{
3567 struct bgp_static *bgp_static;
3568 struct bgp *bgp;
3569 struct bgp_node *rn;
3570 struct prefix *p;
3571
3572 bgp = rsclient->bgp;
3573
3574 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3575 if ((bgp_static = rn->info) != NULL)
3576 {
3577 p = &rn->p;
3578
3579 bgp_static_update_rsclient (rsclient, p, bgp_static,
3580 afi, safi);
3581 }
3582}
3583
paul94f2b392005-06-28 12:44:16 +00003584static void
Michael Lambert4c9641b2010-07-22 13:20:55 -04003585bgp_static_withdraw_vpnv4 (struct bgp *bgp, struct prefix *p, afi_t afi,
3586 safi_t safi, struct prefix_rd *prd, u_char *tag)
paul718e3742002-12-13 20:15:29 +00003587{
3588 struct bgp_node *rn;
3589 struct bgp_info *ri;
3590
paulfee0f4c2004-09-13 05:12:46 +00003591 rn = bgp_afi_node_get (bgp->rib[afi][safi], afi, safi, p, prd);
paul718e3742002-12-13 20:15:29 +00003592
3593 /* Check selected route and self inserted route. */
3594 for (ri = rn->info; ri; ri = ri->next)
3595 if (ri->peer == bgp->peer_self
3596 && ri->type == ZEBRA_ROUTE_BGP
3597 && ri->sub_type == BGP_ROUTE_STATIC)
3598 break;
3599
3600 /* Withdraw static BGP route from routing table. */
3601 if (ri)
3602 {
3603 bgp_aggregate_decrement (bgp, p, ri, afi, safi);
paul718e3742002-12-13 20:15:29 +00003604 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00003605 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00003606 }
3607
3608 /* Unlock bgp_node_lookup. */
3609 bgp_unlock_node (rn);
3610}
3611
3612/* Configure static BGP network. When user don't run zebra, static
3613 route should be installed as valid. */
paul94f2b392005-06-28 12:44:16 +00003614static int
paulfd79ac92004-10-13 05:06:08 +00003615bgp_static_set (struct vty *vty, struct bgp *bgp, const char *ip_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003616 afi_t afi, safi_t safi, const char *rmap, int backdoor)
paul718e3742002-12-13 20:15:29 +00003617{
3618 int ret;
3619 struct prefix p;
3620 struct bgp_static *bgp_static;
3621 struct bgp_node *rn;
Paul Jakma41367172007-08-06 15:24:51 +00003622 u_char need_update = 0;
paul718e3742002-12-13 20:15:29 +00003623
3624 /* Convert IP prefix string to struct prefix. */
3625 ret = str2prefix (ip_str, &p);
3626 if (! ret)
3627 {
3628 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3629 return CMD_WARNING;
3630 }
3631#ifdef HAVE_IPV6
3632 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3633 {
3634 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3635 VTY_NEWLINE);
3636 return CMD_WARNING;
3637 }
3638#endif /* HAVE_IPV6 */
3639
3640 apply_mask (&p);
3641
3642 /* Set BGP static route configuration. */
3643 rn = bgp_node_get (bgp->route[afi][safi], &p);
3644
3645 if (rn->info)
3646 {
3647 /* Configuration change. */
3648 bgp_static = rn->info;
3649
3650 /* Check previous routes are installed into BGP. */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003651 if (bgp_static->valid && bgp_static->backdoor != backdoor)
3652 need_update = 1;
Paul Jakma41367172007-08-06 15:24:51 +00003653
paul718e3742002-12-13 20:15:29 +00003654 bgp_static->backdoor = backdoor;
Paul Jakma41367172007-08-06 15:24:51 +00003655
paul718e3742002-12-13 20:15:29 +00003656 if (rmap)
3657 {
3658 if (bgp_static->rmap.name)
3659 free (bgp_static->rmap.name);
3660 bgp_static->rmap.name = strdup (rmap);
3661 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3662 }
3663 else
3664 {
3665 if (bgp_static->rmap.name)
3666 free (bgp_static->rmap.name);
3667 bgp_static->rmap.name = NULL;
3668 bgp_static->rmap.map = NULL;
3669 bgp_static->valid = 0;
3670 }
3671 bgp_unlock_node (rn);
3672 }
3673 else
3674 {
3675 /* New configuration. */
3676 bgp_static = bgp_static_new ();
3677 bgp_static->backdoor = backdoor;
3678 bgp_static->valid = 0;
3679 bgp_static->igpmetric = 0;
3680 bgp_static->igpnexthop.s_addr = 0;
Paul Jakma41367172007-08-06 15:24:51 +00003681
paul718e3742002-12-13 20:15:29 +00003682 if (rmap)
3683 {
3684 if (bgp_static->rmap.name)
3685 free (bgp_static->rmap.name);
3686 bgp_static->rmap.name = strdup (rmap);
3687 bgp_static->rmap.map = route_map_lookup_by_name (rmap);
3688 }
3689 rn->info = bgp_static;
3690 }
3691
3692 /* If BGP scan is not enabled, we should install this route here. */
3693 if (! bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK))
3694 {
3695 bgp_static->valid = 1;
3696
3697 if (need_update)
3698 bgp_static_withdraw (bgp, &p, afi, safi);
3699
3700 if (! bgp_static->backdoor)
3701 bgp_static_update (bgp, &p, bgp_static, afi, safi);
3702 }
3703
3704 return CMD_SUCCESS;
3705}
3706
3707/* Configure static BGP network. */
paul94f2b392005-06-28 12:44:16 +00003708static int
paulfd79ac92004-10-13 05:06:08 +00003709bgp_static_unset (struct vty *vty, struct bgp *bgp, const char *ip_str,
Michael Lambert4c9641b2010-07-22 13:20:55 -04003710 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00003711{
3712 int ret;
3713 struct prefix p;
3714 struct bgp_static *bgp_static;
3715 struct bgp_node *rn;
3716
3717 /* Convert IP prefix string to struct prefix. */
3718 ret = str2prefix (ip_str, &p);
3719 if (! ret)
3720 {
3721 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3722 return CMD_WARNING;
3723 }
3724#ifdef HAVE_IPV6
3725 if (afi == AFI_IP6 && IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6))
3726 {
3727 vty_out (vty, "%% Malformed prefix (link-local address)%s",
3728 VTY_NEWLINE);
3729 return CMD_WARNING;
3730 }
3731#endif /* HAVE_IPV6 */
3732
3733 apply_mask (&p);
3734
3735 rn = bgp_node_lookup (bgp->route[afi][safi], &p);
3736 if (! rn)
3737 {
3738 vty_out (vty, "%% Can't find specified static route configuration.%s",
3739 VTY_NEWLINE);
3740 return CMD_WARNING;
3741 }
3742
3743 bgp_static = rn->info;
Paul Jakma41367172007-08-06 15:24:51 +00003744
paul718e3742002-12-13 20:15:29 +00003745 /* Update BGP RIB. */
3746 if (! bgp_static->backdoor)
3747 bgp_static_withdraw (bgp, &p, afi, safi);
3748
3749 /* Clear configuration. */
3750 bgp_static_free (bgp_static);
3751 rn->info = NULL;
3752 bgp_unlock_node (rn);
3753 bgp_unlock_node (rn);
3754
3755 return CMD_SUCCESS;
3756}
3757
3758/* Called from bgp_delete(). Delete all static routes from the BGP
3759 instance. */
3760void
3761bgp_static_delete (struct bgp *bgp)
3762{
3763 afi_t afi;
3764 safi_t safi;
3765 struct bgp_node *rn;
3766 struct bgp_node *rm;
3767 struct bgp_table *table;
3768 struct bgp_static *bgp_static;
3769
3770 for (afi = AFI_IP; afi < AFI_MAX; afi++)
3771 for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
3772 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
3773 if (rn->info != NULL)
3774 {
3775 if (safi == SAFI_MPLS_VPN)
3776 {
3777 table = rn->info;
3778
3779 for (rm = bgp_table_top (table); rm; rm = bgp_route_next (rm))
3780 {
3781 bgp_static = rn->info;
3782 bgp_static_withdraw_vpnv4 (bgp, &rm->p,
3783 AFI_IP, SAFI_MPLS_VPN,
3784 (struct prefix_rd *)&rn->p,
3785 bgp_static->tag);
3786 bgp_static_free (bgp_static);
3787 rn->info = NULL;
3788 bgp_unlock_node (rn);
3789 }
3790 }
3791 else
3792 {
3793 bgp_static = rn->info;
3794 bgp_static_withdraw (bgp, &rn->p, afi, safi);
3795 bgp_static_free (bgp_static);
3796 rn->info = NULL;
3797 bgp_unlock_node (rn);
3798 }
3799 }
3800}
3801
3802int
paulfd79ac92004-10-13 05:06:08 +00003803bgp_static_set_vpnv4 (struct vty *vty, const char *ip_str, const char *rd_str,
3804 const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003805{
3806 int ret;
3807 struct prefix p;
3808 struct prefix_rd prd;
3809 struct bgp *bgp;
3810 struct bgp_node *prn;
3811 struct bgp_node *rn;
3812 struct bgp_table *table;
3813 struct bgp_static *bgp_static;
3814 u_char tag[3];
3815
3816 bgp = vty->index;
3817
3818 ret = str2prefix (ip_str, &p);
3819 if (! ret)
3820 {
3821 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3822 return CMD_WARNING;
3823 }
3824 apply_mask (&p);
3825
3826 ret = str2prefix_rd (rd_str, &prd);
3827 if (! ret)
3828 {
3829 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3830 return CMD_WARNING;
3831 }
3832
3833 ret = str2tag (tag_str, tag);
3834 if (! ret)
3835 {
3836 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3837 return CMD_WARNING;
3838 }
3839
3840 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3841 (struct prefix *)&prd);
3842 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003843 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003844 else
3845 bgp_unlock_node (prn);
3846 table = prn->info;
3847
3848 rn = bgp_node_get (table, &p);
3849
3850 if (rn->info)
3851 {
3852 vty_out (vty, "%% Same network configuration exists%s", VTY_NEWLINE);
3853 bgp_unlock_node (rn);
3854 }
3855 else
3856 {
3857 /* New configuration. */
3858 bgp_static = bgp_static_new ();
3859 bgp_static->valid = 1;
3860 memcpy (bgp_static->tag, tag, 3);
3861 rn->info = bgp_static;
3862
3863 bgp_static_update_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3864 }
3865
3866 return CMD_SUCCESS;
3867}
3868
3869/* Configure static BGP network. */
3870int
paulfd79ac92004-10-13 05:06:08 +00003871bgp_static_unset_vpnv4 (struct vty *vty, const char *ip_str,
3872 const char *rd_str, const char *tag_str)
paul718e3742002-12-13 20:15:29 +00003873{
3874 int ret;
3875 struct bgp *bgp;
3876 struct prefix p;
3877 struct prefix_rd prd;
3878 struct bgp_node *prn;
3879 struct bgp_node *rn;
3880 struct bgp_table *table;
3881 struct bgp_static *bgp_static;
3882 u_char tag[3];
3883
3884 bgp = vty->index;
3885
3886 /* Convert IP prefix string to struct prefix. */
3887 ret = str2prefix (ip_str, &p);
3888 if (! ret)
3889 {
3890 vty_out (vty, "%% Malformed prefix%s", VTY_NEWLINE);
3891 return CMD_WARNING;
3892 }
3893 apply_mask (&p);
3894
3895 ret = str2prefix_rd (rd_str, &prd);
3896 if (! ret)
3897 {
3898 vty_out (vty, "%% Malformed rd%s", VTY_NEWLINE);
3899 return CMD_WARNING;
3900 }
3901
3902 ret = str2tag (tag_str, tag);
3903 if (! ret)
3904 {
3905 vty_out (vty, "%% Malformed tag%s", VTY_NEWLINE);
3906 return CMD_WARNING;
3907 }
3908
3909 prn = bgp_node_get (bgp->route[AFI_IP][SAFI_MPLS_VPN],
3910 (struct prefix *)&prd);
3911 if (prn->info == NULL)
Paul Jakma64e580a2006-02-21 01:09:01 +00003912 prn->info = bgp_table_init (AFI_IP, SAFI_MPLS_VPN);
paul718e3742002-12-13 20:15:29 +00003913 else
3914 bgp_unlock_node (prn);
3915 table = prn->info;
3916
3917 rn = bgp_node_lookup (table, &p);
3918
3919 if (rn)
3920 {
3921 bgp_static_withdraw_vpnv4 (bgp, &p, AFI_IP, SAFI_MPLS_VPN, &prd, tag);
3922
3923 bgp_static = rn->info;
3924 bgp_static_free (bgp_static);
3925 rn->info = NULL;
3926 bgp_unlock_node (rn);
3927 bgp_unlock_node (rn);
3928 }
3929 else
3930 vty_out (vty, "%% Can't find the route%s", VTY_NEWLINE);
3931
3932 return CMD_SUCCESS;
3933}
3934
3935DEFUN (bgp_network,
3936 bgp_network_cmd,
3937 "network A.B.C.D/M",
3938 "Specify a network to announce via BGP\n"
3939 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
3940{
3941 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003942 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003943}
3944
3945DEFUN (bgp_network_route_map,
3946 bgp_network_route_map_cmd,
3947 "network A.B.C.D/M route-map WORD",
3948 "Specify a network to announce via BGP\n"
3949 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3950 "Route-map to modify the attributes\n"
3951 "Name of the route map\n")
3952{
3953 return bgp_static_set (vty, vty->index, argv[0],
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003954 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00003955}
3956
3957DEFUN (bgp_network_backdoor,
3958 bgp_network_backdoor_cmd,
3959 "network A.B.C.D/M backdoor",
3960 "Specify a network to announce via BGP\n"
3961 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
3962 "Specify a BGP backdoor route\n")
3963{
Paul Jakma41367172007-08-06 15:24:51 +00003964 return bgp_static_set (vty, vty->index, argv[0], AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003965 NULL, 1);
paul718e3742002-12-13 20:15:29 +00003966}
3967
3968DEFUN (bgp_network_mask,
3969 bgp_network_mask_cmd,
3970 "network A.B.C.D mask A.B.C.D",
3971 "Specify a network to announce via BGP\n"
3972 "Network number\n"
3973 "Network mask\n"
3974 "Network mask\n")
3975{
3976 int ret;
3977 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00003978
paul718e3742002-12-13 20:15:29 +00003979 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
3980 if (! ret)
3981 {
3982 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
3983 return CMD_WARNING;
3984 }
3985
3986 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00003987 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00003988}
3989
3990DEFUN (bgp_network_mask_route_map,
3991 bgp_network_mask_route_map_cmd,
3992 "network A.B.C.D mask A.B.C.D route-map WORD",
3993 "Specify a network to announce via BGP\n"
3994 "Network number\n"
3995 "Network mask\n"
3996 "Network mask\n"
3997 "Route-map to modify the attributes\n"
3998 "Name of the route map\n")
3999{
4000 int ret;
4001 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004002
paul718e3742002-12-13 20:15:29 +00004003 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4004 if (! ret)
4005 {
4006 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4007 return CMD_WARNING;
4008 }
4009
4010 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004011 AFI_IP, bgp_node_safi (vty), argv[2], 0);
paul718e3742002-12-13 20:15:29 +00004012}
4013
4014DEFUN (bgp_network_mask_backdoor,
4015 bgp_network_mask_backdoor_cmd,
4016 "network A.B.C.D mask A.B.C.D backdoor",
4017 "Specify a network to announce via BGP\n"
4018 "Network number\n"
4019 "Network mask\n"
4020 "Network mask\n"
4021 "Specify a BGP backdoor route\n")
4022{
4023 int ret;
4024 char prefix_str[BUFSIZ];
Paul Jakma41367172007-08-06 15:24:51 +00004025
paul718e3742002-12-13 20:15:29 +00004026 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4027 if (! ret)
4028 {
4029 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4030 return CMD_WARNING;
4031 }
4032
Paul Jakma41367172007-08-06 15:24:51 +00004033 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004034 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004035}
4036
4037DEFUN (bgp_network_mask_natural,
4038 bgp_network_mask_natural_cmd,
4039 "network A.B.C.D",
4040 "Specify a network to announce via BGP\n"
4041 "Network number\n")
4042{
4043 int ret;
4044 char prefix_str[BUFSIZ];
4045
4046 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4047 if (! ret)
4048 {
4049 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4050 return CMD_WARNING;
4051 }
4052
4053 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004054 AFI_IP, bgp_node_safi (vty), NULL, 0);
paul718e3742002-12-13 20:15:29 +00004055}
4056
4057DEFUN (bgp_network_mask_natural_route_map,
4058 bgp_network_mask_natural_route_map_cmd,
4059 "network A.B.C.D route-map WORD",
4060 "Specify a network to announce via BGP\n"
4061 "Network number\n"
4062 "Route-map to modify the attributes\n"
4063 "Name of the route map\n")
4064{
4065 int ret;
4066 char prefix_str[BUFSIZ];
4067
4068 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4069 if (! ret)
4070 {
4071 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4072 return CMD_WARNING;
4073 }
4074
4075 return bgp_static_set (vty, vty->index, prefix_str,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004076 AFI_IP, bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004077}
4078
4079DEFUN (bgp_network_mask_natural_backdoor,
4080 bgp_network_mask_natural_backdoor_cmd,
4081 "network A.B.C.D backdoor",
4082 "Specify a network to announce via BGP\n"
4083 "Network number\n"
4084 "Specify a BGP backdoor route\n")
4085{
4086 int ret;
4087 char prefix_str[BUFSIZ];
4088
4089 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4090 if (! ret)
4091 {
4092 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4093 return CMD_WARNING;
4094 }
4095
Paul Jakma41367172007-08-06 15:24:51 +00004096 return bgp_static_set (vty, vty->index, prefix_str, AFI_IP, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004097 NULL, 1);
paul718e3742002-12-13 20:15:29 +00004098}
4099
4100DEFUN (no_bgp_network,
4101 no_bgp_network_cmd,
4102 "no network A.B.C.D/M",
4103 NO_STR
4104 "Specify a network to announce via BGP\n"
4105 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
4106{
4107 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP,
4108 bgp_node_safi (vty));
4109}
4110
4111ALIAS (no_bgp_network,
4112 no_bgp_network_route_map_cmd,
4113 "no network A.B.C.D/M route-map WORD",
4114 NO_STR
4115 "Specify a network to announce via BGP\n"
4116 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4117 "Route-map to modify the attributes\n"
4118 "Name of the route map\n")
4119
4120ALIAS (no_bgp_network,
4121 no_bgp_network_backdoor_cmd,
4122 "no network A.B.C.D/M backdoor",
4123 NO_STR
4124 "Specify a network to announce via BGP\n"
4125 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4126 "Specify a BGP backdoor route\n")
4127
4128DEFUN (no_bgp_network_mask,
4129 no_bgp_network_mask_cmd,
4130 "no network A.B.C.D mask A.B.C.D",
4131 NO_STR
4132 "Specify a network to announce via BGP\n"
4133 "Network number\n"
4134 "Network mask\n"
4135 "Network mask\n")
4136{
4137 int ret;
4138 char prefix_str[BUFSIZ];
4139
4140 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4141 if (! ret)
4142 {
4143 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4144 return CMD_WARNING;
4145 }
4146
4147 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4148 bgp_node_safi (vty));
4149}
4150
4151ALIAS (no_bgp_network_mask,
4152 no_bgp_network_mask_route_map_cmd,
4153 "no network A.B.C.D mask A.B.C.D route-map WORD",
4154 NO_STR
4155 "Specify a network to announce via BGP\n"
4156 "Network number\n"
4157 "Network mask\n"
4158 "Network mask\n"
4159 "Route-map to modify the attributes\n"
4160 "Name of the route map\n")
4161
4162ALIAS (no_bgp_network_mask,
4163 no_bgp_network_mask_backdoor_cmd,
4164 "no network A.B.C.D mask A.B.C.D backdoor",
4165 NO_STR
4166 "Specify a network to announce via BGP\n"
4167 "Network number\n"
4168 "Network mask\n"
4169 "Network mask\n"
4170 "Specify a BGP backdoor route\n")
4171
4172DEFUN (no_bgp_network_mask_natural,
4173 no_bgp_network_mask_natural_cmd,
4174 "no network A.B.C.D",
4175 NO_STR
4176 "Specify a network to announce via BGP\n"
4177 "Network number\n")
4178{
4179 int ret;
4180 char prefix_str[BUFSIZ];
4181
4182 ret = netmask_str2prefix_str (argv[0], NULL, prefix_str);
4183 if (! ret)
4184 {
4185 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4186 return CMD_WARNING;
4187 }
4188
4189 return bgp_static_unset (vty, vty->index, prefix_str, AFI_IP,
4190 bgp_node_safi (vty));
4191}
4192
4193ALIAS (no_bgp_network_mask_natural,
4194 no_bgp_network_mask_natural_route_map_cmd,
4195 "no network A.B.C.D route-map WORD",
4196 NO_STR
4197 "Specify a network to announce via BGP\n"
4198 "Network number\n"
4199 "Route-map to modify the attributes\n"
4200 "Name of the route map\n")
4201
4202ALIAS (no_bgp_network_mask_natural,
4203 no_bgp_network_mask_natural_backdoor_cmd,
4204 "no network A.B.C.D backdoor",
4205 NO_STR
4206 "Specify a network to announce via BGP\n"
4207 "Network number\n"
4208 "Specify a BGP backdoor route\n")
4209
4210#ifdef HAVE_IPV6
4211DEFUN (ipv6_bgp_network,
4212 ipv6_bgp_network_cmd,
4213 "network X:X::X:X/M",
4214 "Specify a network to announce via BGP\n"
4215 "IPv6 prefix <network>/<length>\n")
4216{
Paul Jakma41367172007-08-06 15:24:51 +00004217 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004218 NULL, 0);
paul718e3742002-12-13 20:15:29 +00004219}
4220
4221DEFUN (ipv6_bgp_network_route_map,
4222 ipv6_bgp_network_route_map_cmd,
4223 "network X:X::X:X/M route-map WORD",
4224 "Specify a network to announce via BGP\n"
4225 "IPv6 prefix <network>/<length>\n"
4226 "Route-map to modify the attributes\n"
4227 "Name of the route map\n")
4228{
4229 return bgp_static_set (vty, vty->index, argv[0], AFI_IP6,
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004230 bgp_node_safi (vty), argv[1], 0);
paul718e3742002-12-13 20:15:29 +00004231}
4232
4233DEFUN (no_ipv6_bgp_network,
4234 no_ipv6_bgp_network_cmd,
4235 "no network X:X::X:X/M",
4236 NO_STR
4237 "Specify a network to announce via BGP\n"
4238 "IPv6 prefix <network>/<length>\n")
4239{
4240 return bgp_static_unset (vty, vty->index, argv[0], AFI_IP6, SAFI_UNICAST);
4241}
4242
4243ALIAS (no_ipv6_bgp_network,
4244 no_ipv6_bgp_network_route_map_cmd,
4245 "no network X:X::X:X/M route-map WORD",
4246 NO_STR
4247 "Specify a network to announce via BGP\n"
4248 "IPv6 prefix <network>/<length>\n"
4249 "Route-map to modify the attributes\n"
4250 "Name of the route map\n")
4251
4252ALIAS (ipv6_bgp_network,
4253 old_ipv6_bgp_network_cmd,
4254 "ipv6 bgp network X:X::X:X/M",
4255 IPV6_STR
4256 BGP_STR
4257 "Specify a network to announce via BGP\n"
4258 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4259
4260ALIAS (no_ipv6_bgp_network,
4261 old_no_ipv6_bgp_network_cmd,
4262 "no ipv6 bgp network X:X::X:X/M",
4263 NO_STR
4264 IPV6_STR
4265 BGP_STR
4266 "Specify a network to announce via BGP\n"
4267 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
4268#endif /* HAVE_IPV6 */
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004269
4270/* stubs for removed AS-Pathlimit commands, kept for config compatibility */
4271ALIAS_DEPRECATED (bgp_network,
4272 bgp_network_ttl_cmd,
4273 "network A.B.C.D/M pathlimit <0-255>",
4274 "Specify a network to announce via BGP\n"
4275 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4276 "AS-Path hopcount limit attribute\n"
4277 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4278ALIAS_DEPRECATED (bgp_network_backdoor,
4279 bgp_network_backdoor_ttl_cmd,
4280 "network A.B.C.D/M backdoor pathlimit <0-255>",
4281 "Specify a network to announce via BGP\n"
4282 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4283 "Specify a BGP backdoor route\n"
4284 "AS-Path hopcount limit attribute\n"
4285 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4286ALIAS_DEPRECATED (bgp_network_mask,
4287 bgp_network_mask_ttl_cmd,
4288 "network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4289 "Specify a network to announce via BGP\n"
4290 "Network number\n"
4291 "Network mask\n"
4292 "Network mask\n"
4293 "AS-Path hopcount limit attribute\n"
4294 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4295ALIAS_DEPRECATED (bgp_network_mask_backdoor,
4296 bgp_network_mask_backdoor_ttl_cmd,
4297 "network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4298 "Specify a network to announce via BGP\n"
4299 "Network number\n"
4300 "Network mask\n"
4301 "Network mask\n"
4302 "Specify a BGP backdoor route\n"
4303 "AS-Path hopcount limit attribute\n"
4304 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4305ALIAS_DEPRECATED (bgp_network_mask_natural,
4306 bgp_network_mask_natural_ttl_cmd,
4307 "network A.B.C.D pathlimit <0-255>",
4308 "Specify a network to announce via BGP\n"
4309 "Network number\n"
4310 "AS-Path hopcount limit attribute\n"
4311 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4312ALIAS_DEPRECATED (bgp_network_mask_natural_backdoor,
4313 bgp_network_mask_natural_backdoor_ttl_cmd,
4314 "network A.B.C.D backdoor pathlimit (1-255>",
4315 "Specify a network to announce via BGP\n"
4316 "Network number\n"
4317 "Specify a BGP backdoor route\n"
4318 "AS-Path hopcount limit attribute\n"
4319 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4320ALIAS_DEPRECATED (no_bgp_network,
4321 no_bgp_network_ttl_cmd,
4322 "no network A.B.C.D/M pathlimit <0-255>",
4323 NO_STR
4324 "Specify a network to announce via BGP\n"
4325 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4326 "AS-Path hopcount limit attribute\n"
4327 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4328ALIAS_DEPRECATED (no_bgp_network,
4329 no_bgp_network_backdoor_ttl_cmd,
4330 "no network A.B.C.D/M backdoor pathlimit <0-255>",
4331 NO_STR
4332 "Specify a network to announce via BGP\n"
4333 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
4334 "Specify a BGP backdoor route\n"
4335 "AS-Path hopcount limit attribute\n"
4336 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4337ALIAS_DEPRECATED (no_bgp_network,
4338 no_bgp_network_mask_ttl_cmd,
4339 "no network A.B.C.D mask A.B.C.D pathlimit <0-255>",
4340 NO_STR
4341 "Specify a network to announce via BGP\n"
4342 "Network number\n"
4343 "Network mask\n"
4344 "Network mask\n"
4345 "AS-Path hopcount limit attribute\n"
4346 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4347ALIAS_DEPRECATED (no_bgp_network_mask,
4348 no_bgp_network_mask_backdoor_ttl_cmd,
4349 "no network A.B.C.D mask A.B.C.D backdoor pathlimit <0-255>",
4350 NO_STR
4351 "Specify a network to announce via BGP\n"
4352 "Network number\n"
4353 "Network mask\n"
4354 "Network mask\n"
4355 "Specify a BGP backdoor route\n"
4356 "AS-Path hopcount limit attribute\n"
4357 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4358ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4359 no_bgp_network_mask_natural_ttl_cmd,
4360 "no network A.B.C.D pathlimit <0-255>",
4361 NO_STR
4362 "Specify a network to announce via BGP\n"
4363 "Network number\n"
4364 "AS-Path hopcount limit attribute\n"
4365 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4366ALIAS_DEPRECATED (no_bgp_network_mask_natural,
4367 no_bgp_network_mask_natural_backdoor_ttl_cmd,
4368 "no network A.B.C.D backdoor pathlimit <0-255>",
4369 NO_STR
4370 "Specify a network to announce via BGP\n"
4371 "Network number\n"
4372 "Specify a BGP backdoor route\n"
4373 "AS-Path hopcount limit attribute\n"
4374 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004375#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +00004376ALIAS_DEPRECATED (ipv6_bgp_network,
4377 ipv6_bgp_network_ttl_cmd,
4378 "network X:X::X:X/M pathlimit <0-255>",
4379 "Specify a network to announce via BGP\n"
4380 "IPv6 prefix <network>/<length>\n"
4381 "AS-Path hopcount limit attribute\n"
4382 "AS-Pathlimit TTL, in number of AS-Path hops\n")
4383ALIAS_DEPRECATED (no_ipv6_bgp_network,
4384 no_ipv6_bgp_network_ttl_cmd,
4385 "no network X:X::X:X/M pathlimit <0-255>",
4386 NO_STR
4387 "Specify a network to announce via BGP\n"
4388 "IPv6 prefix <network>/<length>\n"
4389 "AS-Path hopcount limit attribute\n"
4390 "AS-Pathlimit TTL, in number of AS-Path hops\n")
Paul Jakma3bde17f2011-03-23 10:30:30 +00004391#endif /* HAVE_IPV6 */
paul718e3742002-12-13 20:15:29 +00004392
4393/* Aggreagete address:
4394
4395 advertise-map Set condition to advertise attribute
4396 as-set Generate AS set path information
4397 attribute-map Set attributes of aggregate
4398 route-map Set parameters of aggregate
4399 summary-only Filter more specific routes from updates
4400 suppress-map Conditionally filter more specific routes from updates
4401 <cr>
4402 */
4403struct bgp_aggregate
4404{
4405 /* Summary-only flag. */
4406 u_char summary_only;
4407
4408 /* AS set generation. */
4409 u_char as_set;
4410
4411 /* Route-map for aggregated route. */
4412 struct route_map *map;
4413
4414 /* Suppress-count. */
4415 unsigned long count;
4416
4417 /* SAFI configuration. */
4418 safi_t safi;
4419};
4420
paul94f2b392005-06-28 12:44:16 +00004421static struct bgp_aggregate *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -08004422bgp_aggregate_new (void)
paul718e3742002-12-13 20:15:29 +00004423{
Stephen Hemminger393deb92008-08-18 14:13:29 -07004424 return XCALLOC (MTYPE_BGP_AGGREGATE, sizeof (struct bgp_aggregate));
paul718e3742002-12-13 20:15:29 +00004425}
4426
paul94f2b392005-06-28 12:44:16 +00004427static void
paul718e3742002-12-13 20:15:29 +00004428bgp_aggregate_free (struct bgp_aggregate *aggregate)
4429{
4430 XFREE (MTYPE_BGP_AGGREGATE, aggregate);
4431}
4432
paul94f2b392005-06-28 12:44:16 +00004433static void
paul718e3742002-12-13 20:15:29 +00004434bgp_aggregate_route (struct bgp *bgp, struct prefix *p, struct bgp_info *rinew,
4435 afi_t afi, safi_t safi, struct bgp_info *del,
4436 struct bgp_aggregate *aggregate)
4437{
4438 struct bgp_table *table;
4439 struct bgp_node *top;
4440 struct bgp_node *rn;
4441 u_char origin;
4442 struct aspath *aspath = NULL;
4443 struct aspath *asmerge = NULL;
4444 struct community *community = NULL;
4445 struct community *commerge = NULL;
4446 struct in_addr nexthop;
4447 u_int32_t med = 0;
4448 struct bgp_info *ri;
4449 struct bgp_info *new;
4450 int first = 1;
4451 unsigned long match = 0;
4452
4453 /* Record adding route's nexthop and med. */
4454 if (rinew)
4455 {
4456 nexthop = rinew->attr->nexthop;
4457 med = rinew->attr->med;
4458 }
4459
4460 /* ORIGIN attribute: If at least one route among routes that are
4461 aggregated has ORIGIN with the value INCOMPLETE, then the
4462 aggregated route must have the ORIGIN attribute with the value
4463 INCOMPLETE. Otherwise, if at least one route among routes that
4464 are aggregated has ORIGIN with the value EGP, then the aggregated
4465 route must have the origin attribute with the value EGP. In all
4466 other case the value of the ORIGIN attribute of the aggregated
4467 route is INTERNAL. */
4468 origin = BGP_ORIGIN_IGP;
4469
4470 table = bgp->rib[afi][safi];
4471
4472 top = bgp_node_get (table, p);
4473 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4474 if (rn->p.prefixlen > p->prefixlen)
4475 {
4476 match = 0;
4477
4478 for (ri = rn->info; ri; ri = ri->next)
4479 {
4480 if (BGP_INFO_HOLDDOWN (ri))
4481 continue;
4482
4483 if (del && ri == del)
4484 continue;
4485
4486 if (! rinew && first)
4487 {
4488 nexthop = ri->attr->nexthop;
4489 med = ri->attr->med;
4490 first = 0;
4491 }
4492
4493#ifdef AGGREGATE_NEXTHOP_CHECK
4494 if (! IPV4_ADDR_SAME (&ri->attr->nexthop, &nexthop)
4495 || ri->attr->med != med)
4496 {
4497 if (aspath)
4498 aspath_free (aspath);
4499 if (community)
4500 community_free (community);
4501 bgp_unlock_node (rn);
4502 bgp_unlock_node (top);
4503 return;
4504 }
4505#endif /* AGGREGATE_NEXTHOP_CHECK */
4506
4507 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4508 {
4509 if (aggregate->summary_only)
4510 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004511 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004512 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004513 match++;
4514 }
4515
4516 aggregate->count++;
4517
4518 if (aggregate->as_set)
4519 {
4520 if (origin < ri->attr->origin)
4521 origin = ri->attr->origin;
4522
4523 if (aspath)
4524 {
4525 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4526 aspath_free (aspath);
4527 aspath = asmerge;
4528 }
4529 else
4530 aspath = aspath_dup (ri->attr->aspath);
4531
4532 if (ri->attr->community)
4533 {
4534 if (community)
4535 {
4536 commerge = community_merge (community,
4537 ri->attr->community);
4538 community = community_uniq_sort (commerge);
4539 community_free (commerge);
4540 }
4541 else
4542 community = community_dup (ri->attr->community);
4543 }
4544 }
4545 }
4546 }
4547 if (match)
4548 bgp_process (bgp, rn, afi, safi);
4549 }
4550 bgp_unlock_node (top);
4551
4552 if (rinew)
4553 {
4554 aggregate->count++;
4555
4556 if (aggregate->summary_only)
Paul Jakmafb982c22007-05-04 20:15:47 +00004557 (bgp_info_extra_get (rinew))->suppress++;
paul718e3742002-12-13 20:15:29 +00004558
4559 if (aggregate->as_set)
4560 {
4561 if (origin < rinew->attr->origin)
4562 origin = rinew->attr->origin;
4563
4564 if (aspath)
4565 {
4566 asmerge = aspath_aggregate (aspath, rinew->attr->aspath);
4567 aspath_free (aspath);
4568 aspath = asmerge;
4569 }
4570 else
4571 aspath = aspath_dup (rinew->attr->aspath);
4572
4573 if (rinew->attr->community)
4574 {
4575 if (community)
4576 {
4577 commerge = community_merge (community,
4578 rinew->attr->community);
4579 community = community_uniq_sort (commerge);
4580 community_free (commerge);
4581 }
4582 else
4583 community = community_dup (rinew->attr->community);
4584 }
4585 }
4586 }
4587
4588 if (aggregate->count > 0)
4589 {
4590 rn = bgp_node_get (table, p);
4591 new = bgp_info_new ();
4592 new->type = ZEBRA_ROUTE_BGP;
4593 new->sub_type = BGP_ROUTE_AGGREGATE;
4594 new->peer = bgp->peer_self;
4595 SET_FLAG (new->flags, BGP_INFO_VALID);
4596 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004597 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004598
4599 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004600 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00004601 bgp_process (bgp, rn, afi, safi);
4602 }
4603 else
4604 {
4605 if (aspath)
4606 aspath_free (aspath);
4607 if (community)
4608 community_free (community);
4609 }
4610}
4611
4612void bgp_aggregate_delete (struct bgp *, struct prefix *, afi_t, safi_t,
4613 struct bgp_aggregate *);
4614
4615void
4616bgp_aggregate_increment (struct bgp *bgp, struct prefix *p,
4617 struct bgp_info *ri, afi_t afi, safi_t safi)
4618{
4619 struct bgp_node *child;
4620 struct bgp_node *rn;
4621 struct bgp_aggregate *aggregate;
4622
4623 /* MPLS-VPN aggregation is not yet supported. */
4624 if (safi == SAFI_MPLS_VPN)
4625 return;
4626
4627 if (p->prefixlen == 0)
4628 return;
4629
4630 if (BGP_INFO_HOLDDOWN (ri))
4631 return;
4632
4633 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4634
4635 /* Aggregate address configuration check. */
4636 for (rn = child; rn; rn = rn->parent)
4637 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4638 {
4639 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004640 bgp_aggregate_route (bgp, &rn->p, ri, afi, safi, NULL, aggregate);
paul718e3742002-12-13 20:15:29 +00004641 }
4642 bgp_unlock_node (child);
4643}
4644
4645void
4646bgp_aggregate_decrement (struct bgp *bgp, struct prefix *p,
4647 struct bgp_info *del, afi_t afi, safi_t safi)
4648{
4649 struct bgp_node *child;
4650 struct bgp_node *rn;
4651 struct bgp_aggregate *aggregate;
4652
4653 /* MPLS-VPN aggregation is not yet supported. */
4654 if (safi == SAFI_MPLS_VPN)
4655 return;
4656
4657 if (p->prefixlen == 0)
4658 return;
4659
4660 child = bgp_node_get (bgp->aggregate[afi][safi], p);
4661
4662 /* Aggregate address configuration check. */
4663 for (rn = child; rn; rn = rn->parent)
4664 if ((aggregate = rn->info) != NULL && rn->p.prefixlen < p->prefixlen)
4665 {
4666 bgp_aggregate_delete (bgp, &rn->p, afi, safi, aggregate);
paul286e1e72003-08-08 00:24:31 +00004667 bgp_aggregate_route (bgp, &rn->p, NULL, afi, safi, del, aggregate);
paul718e3742002-12-13 20:15:29 +00004668 }
4669 bgp_unlock_node (child);
4670}
4671
paul94f2b392005-06-28 12:44:16 +00004672static void
paul718e3742002-12-13 20:15:29 +00004673bgp_aggregate_add (struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi,
4674 struct bgp_aggregate *aggregate)
4675{
4676 struct bgp_table *table;
4677 struct bgp_node *top;
4678 struct bgp_node *rn;
4679 struct bgp_info *new;
4680 struct bgp_info *ri;
4681 unsigned long match;
4682 u_char origin = BGP_ORIGIN_IGP;
4683 struct aspath *aspath = NULL;
4684 struct aspath *asmerge = NULL;
4685 struct community *community = NULL;
4686 struct community *commerge = NULL;
4687
4688 table = bgp->rib[afi][safi];
4689
4690 /* Sanity check. */
4691 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4692 return;
4693 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4694 return;
4695
4696 /* If routes exists below this node, generate aggregate routes. */
4697 top = bgp_node_get (table, p);
4698 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4699 if (rn->p.prefixlen > p->prefixlen)
4700 {
4701 match = 0;
4702
4703 for (ri = rn->info; ri; ri = ri->next)
4704 {
4705 if (BGP_INFO_HOLDDOWN (ri))
4706 continue;
4707
4708 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4709 {
4710 /* summary-only aggregate route suppress aggregated
4711 route announcement. */
4712 if (aggregate->summary_only)
4713 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004714 (bgp_info_extra_get (ri))->suppress++;
Paul Jakma1a392d42006-09-07 00:24:49 +00004715 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004716 match++;
4717 }
4718 /* as-set aggregate route generate origin, as path,
4719 community aggregation. */
4720 if (aggregate->as_set)
4721 {
4722 if (origin < ri->attr->origin)
4723 origin = ri->attr->origin;
4724
4725 if (aspath)
4726 {
4727 asmerge = aspath_aggregate (aspath, ri->attr->aspath);
4728 aspath_free (aspath);
4729 aspath = asmerge;
4730 }
4731 else
4732 aspath = aspath_dup (ri->attr->aspath);
4733
4734 if (ri->attr->community)
4735 {
4736 if (community)
4737 {
4738 commerge = community_merge (community,
4739 ri->attr->community);
4740 community = community_uniq_sort (commerge);
4741 community_free (commerge);
4742 }
4743 else
4744 community = community_dup (ri->attr->community);
4745 }
4746 }
4747 aggregate->count++;
4748 }
4749 }
4750
4751 /* If this node is suppressed, process the change. */
4752 if (match)
4753 bgp_process (bgp, rn, afi, safi);
4754 }
4755 bgp_unlock_node (top);
4756
4757 /* Add aggregate route to BGP table. */
4758 if (aggregate->count)
4759 {
4760 rn = bgp_node_get (table, p);
4761
4762 new = bgp_info_new ();
4763 new->type = ZEBRA_ROUTE_BGP;
4764 new->sub_type = BGP_ROUTE_AGGREGATE;
4765 new->peer = bgp->peer_self;
4766 SET_FLAG (new->flags, BGP_INFO_VALID);
4767 new->attr = bgp_attr_aggregate_intern (bgp, origin, aspath, community, aggregate->as_set);
Stephen Hemminger65957882010-01-15 16:22:10 +03004768 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00004769
4770 bgp_info_add (rn, new);
paul200df112005-06-01 11:17:05 +00004771 bgp_unlock_node (rn);
4772
paul718e3742002-12-13 20:15:29 +00004773 /* Process change. */
4774 bgp_process (bgp, rn, afi, safi);
4775 }
4776}
4777
4778void
4779bgp_aggregate_delete (struct bgp *bgp, struct prefix *p, afi_t afi,
4780 safi_t safi, struct bgp_aggregate *aggregate)
4781{
4782 struct bgp_table *table;
4783 struct bgp_node *top;
4784 struct bgp_node *rn;
4785 struct bgp_info *ri;
4786 unsigned long match;
4787
4788 table = bgp->rib[afi][safi];
4789
4790 if (afi == AFI_IP && p->prefixlen == IPV4_MAX_BITLEN)
4791 return;
4792 if (afi == AFI_IP6 && p->prefixlen == IPV6_MAX_BITLEN)
4793 return;
4794
4795 /* If routes exists below this node, generate aggregate routes. */
4796 top = bgp_node_get (table, p);
4797 for (rn = bgp_node_get (table, p); rn; rn = bgp_route_next_until (rn, top))
4798 if (rn->p.prefixlen > p->prefixlen)
4799 {
4800 match = 0;
4801
4802 for (ri = rn->info; ri; ri = ri->next)
4803 {
4804 if (BGP_INFO_HOLDDOWN (ri))
4805 continue;
4806
4807 if (ri->sub_type != BGP_ROUTE_AGGREGATE)
4808 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004809 if (aggregate->summary_only && ri->extra)
paul718e3742002-12-13 20:15:29 +00004810 {
Paul Jakmafb982c22007-05-04 20:15:47 +00004811 ri->extra->suppress--;
paul718e3742002-12-13 20:15:29 +00004812
Paul Jakmafb982c22007-05-04 20:15:47 +00004813 if (ri->extra->suppress == 0)
paul718e3742002-12-13 20:15:29 +00004814 {
Paul Jakma1a392d42006-09-07 00:24:49 +00004815 bgp_info_set_flag (rn, ri, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00004816 match++;
4817 }
4818 }
4819 aggregate->count--;
4820 }
4821 }
4822
Paul Jakmafb982c22007-05-04 20:15:47 +00004823 /* If this node was suppressed, process the change. */
paul718e3742002-12-13 20:15:29 +00004824 if (match)
4825 bgp_process (bgp, rn, afi, safi);
4826 }
4827 bgp_unlock_node (top);
4828
4829 /* Delete aggregate route from BGP table. */
4830 rn = bgp_node_get (table, p);
4831
4832 for (ri = rn->info; ri; ri = ri->next)
4833 if (ri->peer == bgp->peer_self
4834 && ri->type == ZEBRA_ROUTE_BGP
4835 && ri->sub_type == BGP_ROUTE_AGGREGATE)
4836 break;
4837
4838 /* Withdraw static BGP route from routing table. */
4839 if (ri)
4840 {
paul718e3742002-12-13 20:15:29 +00004841 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00004842 bgp_process (bgp, rn, afi, safi);
paul718e3742002-12-13 20:15:29 +00004843 }
4844
4845 /* Unlock bgp_node_lookup. */
4846 bgp_unlock_node (rn);
4847}
4848
4849/* Aggregate route attribute. */
4850#define AGGREGATE_SUMMARY_ONLY 1
4851#define AGGREGATE_AS_SET 1
4852
paul94f2b392005-06-28 12:44:16 +00004853static int
Robert Baysf6269b42010-08-05 10:26:28 -07004854bgp_aggregate_unset (struct vty *vty, const char *prefix_str,
4855 afi_t afi, safi_t safi)
4856{
4857 int ret;
4858 struct prefix p;
4859 struct bgp_node *rn;
4860 struct bgp *bgp;
4861 struct bgp_aggregate *aggregate;
4862
4863 /* Convert string to prefix structure. */
4864 ret = str2prefix (prefix_str, &p);
4865 if (!ret)
4866 {
4867 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4868 return CMD_WARNING;
4869 }
4870 apply_mask (&p);
4871
4872 /* Get BGP structure. */
4873 bgp = vty->index;
4874
4875 /* Old configuration check. */
4876 rn = bgp_node_lookup (bgp->aggregate[afi][safi], &p);
4877 if (! rn)
4878 {
4879 vty_out (vty, "%% There is no aggregate-address configuration.%s",
4880 VTY_NEWLINE);
4881 return CMD_WARNING;
4882 }
4883
4884 aggregate = rn->info;
4885 if (aggregate->safi & SAFI_UNICAST)
4886 bgp_aggregate_delete (bgp, &p, afi, SAFI_UNICAST, aggregate);
4887 if (aggregate->safi & SAFI_MULTICAST)
4888 bgp_aggregate_delete (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4889
4890 /* Unlock aggregate address configuration. */
4891 rn->info = NULL;
4892 bgp_aggregate_free (aggregate);
4893 bgp_unlock_node (rn);
4894 bgp_unlock_node (rn);
4895
4896 return CMD_SUCCESS;
4897}
4898
4899static int
4900bgp_aggregate_set (struct vty *vty, const char *prefix_str,
paulfd79ac92004-10-13 05:06:08 +00004901 afi_t afi, safi_t safi,
paul718e3742002-12-13 20:15:29 +00004902 u_char summary_only, u_char as_set)
4903{
4904 int ret;
4905 struct prefix p;
4906 struct bgp_node *rn;
4907 struct bgp *bgp;
4908 struct bgp_aggregate *aggregate;
4909
4910 /* Convert string to prefix structure. */
4911 ret = str2prefix (prefix_str, &p);
4912 if (!ret)
4913 {
4914 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
4915 return CMD_WARNING;
4916 }
4917 apply_mask (&p);
4918
4919 /* Get BGP structure. */
4920 bgp = vty->index;
4921
4922 /* Old configuration check. */
4923 rn = bgp_node_get (bgp->aggregate[afi][safi], &p);
4924
4925 if (rn->info)
4926 {
4927 vty_out (vty, "There is already same aggregate network.%s", VTY_NEWLINE);
Robert Bays368473f2010-08-05 10:26:29 -07004928 /* try to remove the old entry */
Robert Baysf6269b42010-08-05 10:26:28 -07004929 ret = bgp_aggregate_unset (vty, prefix_str, afi, safi);
4930 if (ret)
4931 {
Robert Bays368473f2010-08-05 10:26:29 -07004932 vty_out (vty, "Error deleting aggregate.%s", VTY_NEWLINE);
4933 bgp_unlock_node (rn);
Robert Baysf6269b42010-08-05 10:26:28 -07004934 return CMD_WARNING;
4935 }
paul718e3742002-12-13 20:15:29 +00004936 }
4937
4938 /* Make aggregate address structure. */
4939 aggregate = bgp_aggregate_new ();
4940 aggregate->summary_only = summary_only;
4941 aggregate->as_set = as_set;
4942 aggregate->safi = safi;
4943 rn->info = aggregate;
4944
4945 /* Aggregate address insert into BGP routing table. */
4946 if (safi & SAFI_UNICAST)
4947 bgp_aggregate_add (bgp, &p, afi, SAFI_UNICAST, aggregate);
4948 if (safi & SAFI_MULTICAST)
4949 bgp_aggregate_add (bgp, &p, afi, SAFI_MULTICAST, aggregate);
4950
4951 return CMD_SUCCESS;
4952}
4953
paul718e3742002-12-13 20:15:29 +00004954DEFUN (aggregate_address,
4955 aggregate_address_cmd,
4956 "aggregate-address A.B.C.D/M",
4957 "Configure BGP aggregate entries\n"
4958 "Aggregate prefix\n")
4959{
4960 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty), 0, 0);
4961}
4962
4963DEFUN (aggregate_address_mask,
4964 aggregate_address_mask_cmd,
4965 "aggregate-address A.B.C.D A.B.C.D",
4966 "Configure BGP aggregate entries\n"
4967 "Aggregate address\n"
4968 "Aggregate mask\n")
4969{
4970 int ret;
4971 char prefix_str[BUFSIZ];
4972
4973 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
4974
4975 if (! ret)
4976 {
4977 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
4978 return CMD_WARNING;
4979 }
4980
4981 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
4982 0, 0);
4983}
4984
4985DEFUN (aggregate_address_summary_only,
4986 aggregate_address_summary_only_cmd,
4987 "aggregate-address A.B.C.D/M summary-only",
4988 "Configure BGP aggregate entries\n"
4989 "Aggregate prefix\n"
4990 "Filter more specific routes from updates\n")
4991{
4992 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
4993 AGGREGATE_SUMMARY_ONLY, 0);
4994}
4995
4996DEFUN (aggregate_address_mask_summary_only,
4997 aggregate_address_mask_summary_only_cmd,
4998 "aggregate-address A.B.C.D A.B.C.D summary-only",
4999 "Configure BGP aggregate entries\n"
5000 "Aggregate address\n"
5001 "Aggregate mask\n"
5002 "Filter more specific routes from updates\n")
5003{
5004 int ret;
5005 char prefix_str[BUFSIZ];
5006
5007 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5008
5009 if (! ret)
5010 {
5011 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5012 return CMD_WARNING;
5013 }
5014
5015 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5016 AGGREGATE_SUMMARY_ONLY, 0);
5017}
5018
5019DEFUN (aggregate_address_as_set,
5020 aggregate_address_as_set_cmd,
5021 "aggregate-address A.B.C.D/M as-set",
5022 "Configure BGP aggregate entries\n"
5023 "Aggregate prefix\n"
5024 "Generate AS set path information\n")
5025{
5026 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5027 0, AGGREGATE_AS_SET);
5028}
5029
5030DEFUN (aggregate_address_mask_as_set,
5031 aggregate_address_mask_as_set_cmd,
5032 "aggregate-address A.B.C.D A.B.C.D as-set",
5033 "Configure BGP aggregate entries\n"
5034 "Aggregate address\n"
5035 "Aggregate mask\n"
5036 "Generate AS set path information\n")
5037{
5038 int ret;
5039 char prefix_str[BUFSIZ];
5040
5041 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5042
5043 if (! ret)
5044 {
5045 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5046 return CMD_WARNING;
5047 }
5048
5049 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5050 0, AGGREGATE_AS_SET);
5051}
5052
5053
5054DEFUN (aggregate_address_as_set_summary,
5055 aggregate_address_as_set_summary_cmd,
5056 "aggregate-address A.B.C.D/M as-set summary-only",
5057 "Configure BGP aggregate entries\n"
5058 "Aggregate prefix\n"
5059 "Generate AS set path information\n"
5060 "Filter more specific routes from updates\n")
5061{
5062 return bgp_aggregate_set (vty, argv[0], AFI_IP, bgp_node_safi (vty),
5063 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5064}
5065
5066ALIAS (aggregate_address_as_set_summary,
5067 aggregate_address_summary_as_set_cmd,
5068 "aggregate-address A.B.C.D/M summary-only as-set",
5069 "Configure BGP aggregate entries\n"
5070 "Aggregate prefix\n"
5071 "Filter more specific routes from updates\n"
5072 "Generate AS set path information\n")
5073
5074DEFUN (aggregate_address_mask_as_set_summary,
5075 aggregate_address_mask_as_set_summary_cmd,
5076 "aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5077 "Configure BGP aggregate entries\n"
5078 "Aggregate address\n"
5079 "Aggregate mask\n"
5080 "Generate AS set path information\n"
5081 "Filter more specific routes from updates\n")
5082{
5083 int ret;
5084 char prefix_str[BUFSIZ];
5085
5086 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5087
5088 if (! ret)
5089 {
5090 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5091 return CMD_WARNING;
5092 }
5093
5094 return bgp_aggregate_set (vty, prefix_str, AFI_IP, bgp_node_safi (vty),
5095 AGGREGATE_SUMMARY_ONLY, AGGREGATE_AS_SET);
5096}
5097
5098ALIAS (aggregate_address_mask_as_set_summary,
5099 aggregate_address_mask_summary_as_set_cmd,
5100 "aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5101 "Configure BGP aggregate entries\n"
5102 "Aggregate address\n"
5103 "Aggregate mask\n"
5104 "Filter more specific routes from updates\n"
5105 "Generate AS set path information\n")
5106
5107DEFUN (no_aggregate_address,
5108 no_aggregate_address_cmd,
5109 "no aggregate-address A.B.C.D/M",
5110 NO_STR
5111 "Configure BGP aggregate entries\n"
5112 "Aggregate prefix\n")
5113{
5114 return bgp_aggregate_unset (vty, argv[0], AFI_IP, bgp_node_safi (vty));
5115}
5116
5117ALIAS (no_aggregate_address,
5118 no_aggregate_address_summary_only_cmd,
5119 "no aggregate-address A.B.C.D/M summary-only",
5120 NO_STR
5121 "Configure BGP aggregate entries\n"
5122 "Aggregate prefix\n"
5123 "Filter more specific routes from updates\n")
5124
5125ALIAS (no_aggregate_address,
5126 no_aggregate_address_as_set_cmd,
5127 "no aggregate-address A.B.C.D/M as-set",
5128 NO_STR
5129 "Configure BGP aggregate entries\n"
5130 "Aggregate prefix\n"
5131 "Generate AS set path information\n")
5132
5133ALIAS (no_aggregate_address,
5134 no_aggregate_address_as_set_summary_cmd,
5135 "no aggregate-address A.B.C.D/M as-set summary-only",
5136 NO_STR
5137 "Configure BGP aggregate entries\n"
5138 "Aggregate prefix\n"
5139 "Generate AS set path information\n"
5140 "Filter more specific routes from updates\n")
5141
5142ALIAS (no_aggregate_address,
5143 no_aggregate_address_summary_as_set_cmd,
5144 "no aggregate-address A.B.C.D/M summary-only as-set",
5145 NO_STR
5146 "Configure BGP aggregate entries\n"
5147 "Aggregate prefix\n"
5148 "Filter more specific routes from updates\n"
5149 "Generate AS set path information\n")
5150
5151DEFUN (no_aggregate_address_mask,
5152 no_aggregate_address_mask_cmd,
5153 "no aggregate-address A.B.C.D A.B.C.D",
5154 NO_STR
5155 "Configure BGP aggregate entries\n"
5156 "Aggregate address\n"
5157 "Aggregate mask\n")
5158{
5159 int ret;
5160 char prefix_str[BUFSIZ];
5161
5162 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
5163
5164 if (! ret)
5165 {
5166 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
5167 return CMD_WARNING;
5168 }
5169
5170 return bgp_aggregate_unset (vty, prefix_str, AFI_IP, bgp_node_safi (vty));
5171}
5172
5173ALIAS (no_aggregate_address_mask,
5174 no_aggregate_address_mask_summary_only_cmd,
5175 "no aggregate-address A.B.C.D A.B.C.D summary-only",
5176 NO_STR
5177 "Configure BGP aggregate entries\n"
5178 "Aggregate address\n"
5179 "Aggregate mask\n"
5180 "Filter more specific routes from updates\n")
5181
5182ALIAS (no_aggregate_address_mask,
5183 no_aggregate_address_mask_as_set_cmd,
5184 "no aggregate-address A.B.C.D A.B.C.D as-set",
5185 NO_STR
5186 "Configure BGP aggregate entries\n"
5187 "Aggregate address\n"
5188 "Aggregate mask\n"
5189 "Generate AS set path information\n")
5190
5191ALIAS (no_aggregate_address_mask,
5192 no_aggregate_address_mask_as_set_summary_cmd,
5193 "no aggregate-address A.B.C.D A.B.C.D as-set summary-only",
5194 NO_STR
5195 "Configure BGP aggregate entries\n"
5196 "Aggregate address\n"
5197 "Aggregate mask\n"
5198 "Generate AS set path information\n"
5199 "Filter more specific routes from updates\n")
5200
5201ALIAS (no_aggregate_address_mask,
5202 no_aggregate_address_mask_summary_as_set_cmd,
5203 "no aggregate-address A.B.C.D A.B.C.D summary-only as-set",
5204 NO_STR
5205 "Configure BGP aggregate entries\n"
5206 "Aggregate address\n"
5207 "Aggregate mask\n"
5208 "Filter more specific routes from updates\n"
5209 "Generate AS set path information\n")
5210
5211#ifdef HAVE_IPV6
5212DEFUN (ipv6_aggregate_address,
5213 ipv6_aggregate_address_cmd,
5214 "aggregate-address X:X::X:X/M",
5215 "Configure BGP aggregate entries\n"
5216 "Aggregate prefix\n")
5217{
5218 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST, 0, 0);
5219}
5220
5221DEFUN (ipv6_aggregate_address_summary_only,
5222 ipv6_aggregate_address_summary_only_cmd,
5223 "aggregate-address X:X::X:X/M summary-only",
5224 "Configure BGP aggregate entries\n"
5225 "Aggregate prefix\n"
5226 "Filter more specific routes from updates\n")
5227{
5228 return bgp_aggregate_set (vty, argv[0], AFI_IP6, SAFI_UNICAST,
5229 AGGREGATE_SUMMARY_ONLY, 0);
5230}
5231
5232DEFUN (no_ipv6_aggregate_address,
5233 no_ipv6_aggregate_address_cmd,
5234 "no aggregate-address X:X::X:X/M",
5235 NO_STR
5236 "Configure BGP aggregate entries\n"
5237 "Aggregate prefix\n")
5238{
5239 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5240}
5241
5242DEFUN (no_ipv6_aggregate_address_summary_only,
5243 no_ipv6_aggregate_address_summary_only_cmd,
5244 "no aggregate-address X:X::X:X/M summary-only",
5245 NO_STR
5246 "Configure BGP aggregate entries\n"
5247 "Aggregate prefix\n"
5248 "Filter more specific routes from updates\n")
5249{
5250 return bgp_aggregate_unset (vty, argv[0], AFI_IP6, SAFI_UNICAST);
5251}
5252
5253ALIAS (ipv6_aggregate_address,
5254 old_ipv6_aggregate_address_cmd,
5255 "ipv6 bgp aggregate-address X:X::X:X/M",
5256 IPV6_STR
5257 BGP_STR
5258 "Configure BGP aggregate entries\n"
5259 "Aggregate prefix\n")
5260
5261ALIAS (ipv6_aggregate_address_summary_only,
5262 old_ipv6_aggregate_address_summary_only_cmd,
5263 "ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5264 IPV6_STR
5265 BGP_STR
5266 "Configure BGP aggregate entries\n"
5267 "Aggregate prefix\n"
5268 "Filter more specific routes from updates\n")
5269
5270ALIAS (no_ipv6_aggregate_address,
5271 old_no_ipv6_aggregate_address_cmd,
5272 "no ipv6 bgp aggregate-address X:X::X:X/M",
5273 NO_STR
5274 IPV6_STR
5275 BGP_STR
5276 "Configure BGP aggregate entries\n"
5277 "Aggregate prefix\n")
5278
5279ALIAS (no_ipv6_aggregate_address_summary_only,
5280 old_no_ipv6_aggregate_address_summary_only_cmd,
5281 "no ipv6 bgp aggregate-address X:X::X:X/M summary-only",
5282 NO_STR
5283 IPV6_STR
5284 BGP_STR
5285 "Configure BGP aggregate entries\n"
5286 "Aggregate prefix\n"
5287 "Filter more specific routes from updates\n")
5288#endif /* HAVE_IPV6 */
5289
5290/* Redistribute route treatment. */
5291void
5292bgp_redistribute_add (struct prefix *p, struct in_addr *nexthop,
5293 u_int32_t metric, u_char type)
5294{
5295 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005296 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005297 struct bgp_info *new;
5298 struct bgp_info *bi;
5299 struct bgp_info info;
5300 struct bgp_node *bn;
Paul Jakmafb982c22007-05-04 20:15:47 +00005301 struct attr attr = { 0 };
5302 struct attr attr_new = { 0 };
paul718e3742002-12-13 20:15:29 +00005303 struct attr *new_attr;
5304 afi_t afi;
5305 int ret;
5306
5307 /* Make default attribute. */
5308 bgp_attr_default_set (&attr, BGP_ORIGIN_INCOMPLETE);
5309 if (nexthop)
5310 attr.nexthop = *nexthop;
5311
5312 attr.med = metric;
5313 attr.flag |= ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC);
5314
paul1eb8ef22005-04-07 07:30:20 +00005315 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005316 {
5317 afi = family2afi (p->family);
5318
5319 if (bgp->redist[afi][type])
5320 {
5321 /* Copy attribute for modification. */
Paul Jakmafb982c22007-05-04 20:15:47 +00005322 bgp_attr_dup (&attr_new, &attr);
paul718e3742002-12-13 20:15:29 +00005323
5324 if (bgp->redist_metric_flag[afi][type])
5325 attr_new.med = bgp->redist_metric[afi][type];
5326
5327 /* Apply route-map. */
5328 if (bgp->rmap[afi][type].map)
5329 {
5330 info.peer = bgp->peer_self;
5331 info.attr = &attr_new;
5332
paulfee0f4c2004-09-13 05:12:46 +00005333 SET_FLAG (bgp->peer_self->rmap_type, PEER_RMAP_TYPE_REDISTRIBUTE);
5334
paul718e3742002-12-13 20:15:29 +00005335 ret = route_map_apply (bgp->rmap[afi][type].map, p, RMAP_BGP,
5336 &info);
paulfee0f4c2004-09-13 05:12:46 +00005337
5338 bgp->peer_self->rmap_type = 0;
5339
paul718e3742002-12-13 20:15:29 +00005340 if (ret == RMAP_DENYMATCH)
5341 {
5342 /* Free uninterned attribute. */
5343 bgp_attr_flush (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005344 bgp_attr_extra_free (&attr_new);
5345
paul718e3742002-12-13 20:15:29 +00005346 /* Unintern original. */
5347 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005348 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005349 bgp_redistribute_delete (p, type);
5350 return;
5351 }
5352 }
5353
Paul Jakmafb982c22007-05-04 20:15:47 +00005354 bn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST],
5355 afi, SAFI_UNICAST, p, NULL);
5356
paul718e3742002-12-13 20:15:29 +00005357 new_attr = bgp_attr_intern (&attr_new);
Paul Jakmafb982c22007-05-04 20:15:47 +00005358 bgp_attr_extra_free (&attr_new);
5359
paul718e3742002-12-13 20:15:29 +00005360 for (bi = bn->info; bi; bi = bi->next)
5361 if (bi->peer == bgp->peer_self
5362 && bi->sub_type == BGP_ROUTE_REDISTRIBUTE)
5363 break;
5364
5365 if (bi)
5366 {
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005367 if (attrhash_cmp (bi->attr, new_attr) &&
5368 !CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
paul718e3742002-12-13 20:15:29 +00005369 {
5370 bgp_attr_unintern (new_attr);
5371 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005372 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005373 bgp_unlock_node (bn);
5374 return;
5375 }
5376 else
5377 {
5378 /* The attribute is changed. */
Paul Jakma1a392d42006-09-07 00:24:49 +00005379 bgp_info_set_flag (bn, bi, BGP_INFO_ATTR_CHANGED);
paul718e3742002-12-13 20:15:29 +00005380
5381 /* Rewrite BGP route information. */
Andrew J. Schorr8d452102006-11-28 19:50:46 +00005382 if (CHECK_FLAG(bi->flags, BGP_INFO_REMOVED))
5383 bgp_info_restore(bn, bi);
5384 else
5385 bgp_aggregate_decrement (bgp, p, bi, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005386 bgp_attr_unintern (bi->attr);
5387 bi->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005388 bi->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005389
5390 /* Process change. */
5391 bgp_aggregate_increment (bgp, p, bi, afi, SAFI_UNICAST);
5392 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5393 bgp_unlock_node (bn);
5394 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005395 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005396 return;
5397 }
5398 }
5399
5400 new = bgp_info_new ();
5401 new->type = type;
5402 new->sub_type = BGP_ROUTE_REDISTRIBUTE;
5403 new->peer = bgp->peer_self;
5404 SET_FLAG (new->flags, BGP_INFO_VALID);
5405 new->attr = new_attr;
Stephen Hemminger65957882010-01-15 16:22:10 +03005406 new->uptime = bgp_clock ();
paul718e3742002-12-13 20:15:29 +00005407
5408 bgp_aggregate_increment (bgp, p, new, afi, SAFI_UNICAST);
5409 bgp_info_add (bn, new);
paul200df112005-06-01 11:17:05 +00005410 bgp_unlock_node (bn);
paul718e3742002-12-13 20:15:29 +00005411 bgp_process (bgp, bn, afi, SAFI_UNICAST);
5412 }
5413 }
5414
5415 /* Unintern original. */
5416 aspath_unintern (attr.aspath);
Paul Jakmafb982c22007-05-04 20:15:47 +00005417 bgp_attr_extra_free (&attr);
paul718e3742002-12-13 20:15:29 +00005418}
5419
5420void
5421bgp_redistribute_delete (struct prefix *p, u_char type)
5422{
5423 struct bgp *bgp;
paul1eb8ef22005-04-07 07:30:20 +00005424 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00005425 afi_t afi;
5426 struct bgp_node *rn;
5427 struct bgp_info *ri;
5428
paul1eb8ef22005-04-07 07:30:20 +00005429 for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp))
paul718e3742002-12-13 20:15:29 +00005430 {
5431 afi = family2afi (p->family);
5432
5433 if (bgp->redist[afi][type])
5434 {
paulfee0f4c2004-09-13 05:12:46 +00005435 rn = bgp_afi_node_get (bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL);
paul718e3742002-12-13 20:15:29 +00005436
5437 for (ri = rn->info; ri; ri = ri->next)
5438 if (ri->peer == bgp->peer_self
5439 && ri->type == type)
5440 break;
5441
5442 if (ri)
5443 {
5444 bgp_aggregate_decrement (bgp, p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005445 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005446 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005447 }
5448 bgp_unlock_node (rn);
5449 }
5450 }
5451}
5452
5453/* Withdraw specified route type's route. */
5454void
5455bgp_redistribute_withdraw (struct bgp *bgp, afi_t afi, int type)
5456{
5457 struct bgp_node *rn;
5458 struct bgp_info *ri;
5459 struct bgp_table *table;
5460
5461 table = bgp->rib[afi][SAFI_UNICAST];
5462
5463 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
5464 {
5465 for (ri = rn->info; ri; ri = ri->next)
5466 if (ri->peer == bgp->peer_self
5467 && ri->type == type)
5468 break;
5469
5470 if (ri)
5471 {
5472 bgp_aggregate_decrement (bgp, &rn->p, ri, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005473 bgp_info_delete (rn, ri);
Paul Jakma1a392d42006-09-07 00:24:49 +00005474 bgp_process (bgp, rn, afi, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00005475 }
5476 }
5477}
5478
5479/* Static function to display route. */
paul94f2b392005-06-28 12:44:16 +00005480static void
paul718e3742002-12-13 20:15:29 +00005481route_vty_out_route (struct prefix *p, struct vty *vty)
5482{
5483 int len;
5484 u_int32_t destination;
5485 char buf[BUFSIZ];
5486
5487 if (p->family == AF_INET)
5488 {
5489 len = vty_out (vty, "%s", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ));
5490 destination = ntohl (p->u.prefix4.s_addr);
5491
5492 if ((IN_CLASSC (destination) && p->prefixlen == 24)
5493 || (IN_CLASSB (destination) && p->prefixlen == 16)
5494 || (IN_CLASSA (destination) && p->prefixlen == 8)
5495 || p->u.prefix4.s_addr == 0)
5496 {
5497 /* When mask is natural, mask is not displayed. */
5498 }
5499 else
5500 len += vty_out (vty, "/%d", p->prefixlen);
5501 }
5502 else
5503 len = vty_out (vty, "%s/%d", inet_ntop (p->family, &p->u.prefix, buf, BUFSIZ),
5504 p->prefixlen);
5505
5506 len = 17 - len;
5507 if (len < 1)
5508 vty_out (vty, "%s%*s", VTY_NEWLINE, 20, " ");
5509 else
5510 vty_out (vty, "%*s", len, " ");
5511}
5512
paul718e3742002-12-13 20:15:29 +00005513enum bgp_display_type
5514{
5515 normal_list,
5516};
5517
paulb40d9392005-08-22 22:34:41 +00005518/* Print the short form route status for a bgp_info */
5519static void
5520route_vty_short_status_out (struct vty *vty, struct bgp_info *binfo)
paul718e3742002-12-13 20:15:29 +00005521{
paulb40d9392005-08-22 22:34:41 +00005522 /* Route status display. */
5523 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5524 vty_out (vty, "R");
5525 else if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
hasso93406d82005-02-02 14:40:33 +00005526 vty_out (vty, "S");
Paul Jakmafb982c22007-05-04 20:15:47 +00005527 else if (binfo->extra && binfo->extra->suppress)
paul718e3742002-12-13 20:15:29 +00005528 vty_out (vty, "s");
5529 else if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5530 vty_out (vty, "*");
5531 else
5532 vty_out (vty, " ");
5533
5534 /* Selected */
5535 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5536 vty_out (vty, "h");
5537 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5538 vty_out (vty, "d");
5539 else if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5540 vty_out (vty, ">");
5541 else
5542 vty_out (vty, " ");
5543
5544 /* Internal route. */
5545 if ((binfo->peer->as) && (binfo->peer->as == binfo->peer->local_as))
5546 vty_out (vty, "i");
5547 else
paulb40d9392005-08-22 22:34:41 +00005548 vty_out (vty, " ");
5549}
5550
5551/* called from terminal list command */
5552void
5553route_vty_out (struct vty *vty, struct prefix *p,
5554 struct bgp_info *binfo, int display, safi_t safi)
5555{
5556 struct attr *attr;
5557
5558 /* short status lead text */
5559 route_vty_short_status_out (vty, binfo);
paul718e3742002-12-13 20:15:29 +00005560
5561 /* print prefix and mask */
5562 if (! display)
5563 route_vty_out_route (p, vty);
5564 else
5565 vty_out (vty, "%*s", 17, " ");
5566
5567 /* Print attribute */
5568 attr = binfo->attr;
5569 if (attr)
5570 {
5571 if (p->family == AF_INET)
5572 {
5573 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005574 vty_out (vty, "%-16s",
5575 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005576 else
5577 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5578 }
5579#ifdef HAVE_IPV6
5580 else if (p->family == AF_INET6)
5581 {
5582 int len;
5583 char buf[BUFSIZ];
5584
5585 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005586 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5587 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005588 len = 16 - len;
5589 if (len < 1)
5590 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5591 else
5592 vty_out (vty, "%*s", len, " ");
5593 }
5594#endif /* HAVE_IPV6 */
5595
5596 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005597 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005598 else
5599 vty_out (vty, " ");
5600
5601 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005602 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005603 else
5604 vty_out (vty, " ");
5605
Paul Jakmafb982c22007-05-04 20:15:47 +00005606 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
paul718e3742002-12-13 20:15:29 +00005607
Paul Jakmab2518c12006-05-12 23:48:40 +00005608 /* Print aspath */
5609 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005610 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005611
Paul Jakmab2518c12006-05-12 23:48:40 +00005612 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005613 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005614 }
paul718e3742002-12-13 20:15:29 +00005615 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005616}
5617
5618/* called from terminal list command */
5619void
5620route_vty_out_tmp (struct vty *vty, struct prefix *p,
5621 struct attr *attr, safi_t safi)
5622{
5623 /* Route status display. */
5624 vty_out (vty, "*");
5625 vty_out (vty, ">");
5626 vty_out (vty, " ");
5627
5628 /* print prefix and mask */
5629 route_vty_out_route (p, vty);
5630
5631 /* Print attribute */
5632 if (attr)
5633 {
5634 if (p->family == AF_INET)
5635 {
5636 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005637 vty_out (vty, "%-16s",
5638 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005639 else
5640 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5641 }
5642#ifdef HAVE_IPV6
5643 else if (p->family == AF_INET6)
5644 {
5645 int len;
5646 char buf[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005647
5648 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005649
5650 len = vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005651 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5652 buf, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005653 len = 16 - len;
5654 if (len < 1)
5655 vty_out (vty, "%s%*s", VTY_NEWLINE, 36, " ");
5656 else
5657 vty_out (vty, "%*s", len, " ");
5658 }
5659#endif /* HAVE_IPV6 */
5660
5661 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005662 vty_out (vty, "%10u", attr->med);
paul718e3742002-12-13 20:15:29 +00005663 else
5664 vty_out (vty, " ");
5665
5666 if (attr->flag & ATTR_FLAG_BIT (BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005667 vty_out (vty, "%7u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005668 else
5669 vty_out (vty, " ");
Paul Jakmafb982c22007-05-04 20:15:47 +00005670
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005671 vty_out (vty, "%7u ", (attr->extra ? attr->extra->weight : 0));
Paul Jakmafb982c22007-05-04 20:15:47 +00005672
Paul Jakmab2518c12006-05-12 23:48:40 +00005673 /* Print aspath */
5674 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005675 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005676
Paul Jakmab2518c12006-05-12 23:48:40 +00005677 /* Print origin */
paul718e3742002-12-13 20:15:29 +00005678 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
Paul Jakmab2518c12006-05-12 23:48:40 +00005679 }
paul718e3742002-12-13 20:15:29 +00005680
5681 vty_out (vty, "%s", VTY_NEWLINE);
5682}
5683
ajs5a646652004-11-05 01:25:55 +00005684void
paul718e3742002-12-13 20:15:29 +00005685route_vty_out_tag (struct vty *vty, struct prefix *p,
5686 struct bgp_info *binfo, int display, safi_t safi)
5687{
5688 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005689 u_int32_t label = 0;
Paul Jakmafb982c22007-05-04 20:15:47 +00005690
5691 if (!binfo->extra)
5692 return;
5693
paulb40d9392005-08-22 22:34:41 +00005694 /* short status lead text */
5695 route_vty_short_status_out (vty, binfo);
5696
paul718e3742002-12-13 20:15:29 +00005697 /* print prefix and mask */
5698 if (! display)
5699 route_vty_out_route (p, vty);
5700 else
5701 vty_out (vty, "%*s", 17, " ");
5702
5703 /* Print attribute */
5704 attr = binfo->attr;
5705 if (attr)
5706 {
5707 if (p->family == AF_INET)
5708 {
5709 if (safi == SAFI_MPLS_VPN)
Paul Jakmafb982c22007-05-04 20:15:47 +00005710 vty_out (vty, "%-16s",
5711 inet_ntoa (attr->extra->mp_nexthop_global_in));
paul718e3742002-12-13 20:15:29 +00005712 else
5713 vty_out (vty, "%-16s", inet_ntoa (attr->nexthop));
5714 }
5715#ifdef HAVE_IPV6
5716 else if (p->family == AF_INET6)
5717 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005718 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005719 char buf[BUFSIZ];
5720 char buf1[BUFSIZ];
Paul Jakmafb982c22007-05-04 20:15:47 +00005721 if (attr->extra->mp_nexthop_len == 16)
paul718e3742002-12-13 20:15:29 +00005722 vty_out (vty, "%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005723 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5724 buf, BUFSIZ));
5725 else if (attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005726 vty_out (vty, "%s(%s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005727 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
5728 buf, BUFSIZ),
5729 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
5730 buf1, BUFSIZ));
paul718e3742002-12-13 20:15:29 +00005731
5732 }
5733#endif /* HAVE_IPV6 */
5734 }
5735
Paul Jakmafb982c22007-05-04 20:15:47 +00005736 label = decode_label (binfo->extra->tag);
paul718e3742002-12-13 20:15:29 +00005737
5738 vty_out (vty, "notag/%d", label);
5739
5740 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005741}
5742
5743/* dampening route */
ajs5a646652004-11-05 01:25:55 +00005744static void
paul718e3742002-12-13 20:15:29 +00005745damp_route_vty_out (struct vty *vty, struct prefix *p,
5746 struct bgp_info *binfo, int display, safi_t safi)
5747{
5748 struct attr *attr;
paul718e3742002-12-13 20:15:29 +00005749 int len;
Chris Caputo50aef6f2009-06-23 06:06:49 +00005750 char timebuf[BGP_UPTIME_LEN];
paul718e3742002-12-13 20:15:29 +00005751
paulb40d9392005-08-22 22:34:41 +00005752 /* short status lead text */
5753 route_vty_short_status_out (vty, binfo);
5754
paul718e3742002-12-13 20:15:29 +00005755 /* print prefix and mask */
5756 if (! display)
5757 route_vty_out_route (p, vty);
5758 else
5759 vty_out (vty, "%*s", 17, " ");
5760
5761 len = vty_out (vty, "%s", binfo->peer->host);
5762 len = 17 - len;
5763 if (len < 1)
5764 vty_out (vty, "%s%*s", VTY_NEWLINE, 34, " ");
5765 else
5766 vty_out (vty, "%*s", len, " ");
5767
Chris Caputo50aef6f2009-06-23 06:06:49 +00005768 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005769
5770 /* Print attribute */
5771 attr = binfo->attr;
5772 if (attr)
5773 {
5774 /* Print aspath */
5775 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005776 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005777
5778 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005779 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005780 }
5781 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005782}
5783
paul718e3742002-12-13 20:15:29 +00005784/* flap route */
ajs5a646652004-11-05 01:25:55 +00005785static void
paul718e3742002-12-13 20:15:29 +00005786flap_route_vty_out (struct vty *vty, struct prefix *p,
5787 struct bgp_info *binfo, int display, safi_t safi)
5788{
5789 struct attr *attr;
5790 struct bgp_damp_info *bdi;
paul718e3742002-12-13 20:15:29 +00005791 char timebuf[BGP_UPTIME_LEN];
5792 int len;
Paul Jakmafb982c22007-05-04 20:15:47 +00005793
5794 if (!binfo->extra)
5795 return;
5796
5797 bdi = binfo->extra->damp_info;
paul718e3742002-12-13 20:15:29 +00005798
paulb40d9392005-08-22 22:34:41 +00005799 /* short status lead text */
5800 route_vty_short_status_out (vty, binfo);
5801
paul718e3742002-12-13 20:15:29 +00005802 /* print prefix and mask */
5803 if (! display)
5804 route_vty_out_route (p, vty);
5805 else
5806 vty_out (vty, "%*s", 17, " ");
5807
5808 len = vty_out (vty, "%s", binfo->peer->host);
5809 len = 16 - len;
5810 if (len < 1)
5811 vty_out (vty, "%s%*s", VTY_NEWLINE, 33, " ");
5812 else
5813 vty_out (vty, "%*s", len, " ");
5814
5815 len = vty_out (vty, "%d", bdi->flap);
5816 len = 5 - len;
5817 if (len < 1)
5818 vty_out (vty, " ");
5819 else
5820 vty_out (vty, "%*s ", len, " ");
5821
5822 vty_out (vty, "%s ", peer_uptime (bdi->start_time,
5823 timebuf, BGP_UPTIME_LEN));
5824
5825 if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED)
5826 && ! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
Chris Caputo50aef6f2009-06-23 06:06:49 +00005827 vty_out (vty, "%s ", bgp_damp_reuse_time_vty (vty, binfo, timebuf, BGP_UPTIME_LEN));
paul718e3742002-12-13 20:15:29 +00005828 else
5829 vty_out (vty, "%*s ", 8, " ");
5830
5831 /* Print attribute */
5832 attr = binfo->attr;
5833 if (attr)
5834 {
5835 /* Print aspath */
5836 if (attr->aspath)
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005837 aspath_print_vty (vty, "%s", attr->aspath, " ");
paul718e3742002-12-13 20:15:29 +00005838
5839 /* Print origin */
Paul Jakmab2518c12006-05-12 23:48:40 +00005840 vty_out (vty, "%s", bgp_origin_str[attr->origin]);
paul718e3742002-12-13 20:15:29 +00005841 }
5842 vty_out (vty, "%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005843}
5844
paul94f2b392005-06-28 12:44:16 +00005845static void
paul718e3742002-12-13 20:15:29 +00005846route_vty_out_detail (struct vty *vty, struct bgp *bgp, struct prefix *p,
5847 struct bgp_info *binfo, afi_t afi, safi_t safi)
5848{
5849 char buf[INET6_ADDRSTRLEN];
5850 char buf1[BUFSIZ];
5851 struct attr *attr;
5852 int sockunion_vty_out (struct vty *, union sockunion *);
John Kemp30b00172011-03-18 17:52:18 +03005853#ifdef HAVE_CLOCK_MONOTONIC
5854 time_t tbuf;
5855#endif
paul718e3742002-12-13 20:15:29 +00005856
5857 attr = binfo->attr;
5858
5859 if (attr)
5860 {
5861 /* Line1 display AS-path, Aggregator */
5862 if (attr->aspath)
5863 {
5864 vty_out (vty, " ");
paulfe69a502005-09-10 16:55:02 +00005865 if (aspath_count_hops (attr->aspath) == 0)
paul718e3742002-12-13 20:15:29 +00005866 vty_out (vty, "Local");
5867 else
Denis Ovsienko841f7a52008-04-10 11:47:45 +00005868 aspath_print_vty (vty, "%s", attr->aspath, "");
paul718e3742002-12-13 20:15:29 +00005869 }
5870
paulb40d9392005-08-22 22:34:41 +00005871 if (CHECK_FLAG (binfo->flags, BGP_INFO_REMOVED))
5872 vty_out (vty, ", (removed)");
hasso93406d82005-02-02 14:40:33 +00005873 if (CHECK_FLAG (binfo->flags, BGP_INFO_STALE))
5874 vty_out (vty, ", (stale)");
5875 if (CHECK_FLAG (attr->flag, ATTR_FLAG_BIT (BGP_ATTR_AGGREGATOR)))
Denis Ovsienkoaea339f2009-04-30 17:16:22 +04005876 vty_out (vty, ", (aggregated by %u %s)",
Paul Jakmafb982c22007-05-04 20:15:47 +00005877 attr->extra->aggregator_as,
5878 inet_ntoa (attr->extra->aggregator_addr));
hasso93406d82005-02-02 14:40:33 +00005879 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT))
5880 vty_out (vty, ", (Received from a RR-client)");
5881 if (CHECK_FLAG (binfo->peer->af_flags[afi][safi], PEER_FLAG_RSERVER_CLIENT))
5882 vty_out (vty, ", (Received from a RS-client)");
5883 if (CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5884 vty_out (vty, ", (history entry)");
5885 else if (CHECK_FLAG (binfo->flags, BGP_INFO_DAMPED))
5886 vty_out (vty, ", (suppressed due to dampening)");
paul718e3742002-12-13 20:15:29 +00005887 vty_out (vty, "%s", VTY_NEWLINE);
5888
5889 /* Line2 display Next-hop, Neighbor, Router-id */
5890 if (p->family == AF_INET)
5891 {
5892 vty_out (vty, " %s", safi == SAFI_MPLS_VPN ?
Paul Jakmafb982c22007-05-04 20:15:47 +00005893 inet_ntoa (attr->extra->mp_nexthop_global_in) :
paul718e3742002-12-13 20:15:29 +00005894 inet_ntoa (attr->nexthop));
5895 }
5896#ifdef HAVE_IPV6
5897 else
5898 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005899 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005900 vty_out (vty, " %s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005901 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_global,
paul718e3742002-12-13 20:15:29 +00005902 buf, INET6_ADDRSTRLEN));
5903 }
5904#endif /* HAVE_IPV6 */
5905
5906 if (binfo->peer == bgp->peer_self)
5907 {
5908 vty_out (vty, " from %s ",
5909 p->family == AF_INET ? "0.0.0.0" : "::");
5910 vty_out (vty, "(%s)", inet_ntoa(bgp->router_id));
5911 }
5912 else
5913 {
5914 if (! CHECK_FLAG (binfo->flags, BGP_INFO_VALID))
5915 vty_out (vty, " (inaccessible)");
Paul Jakmafb982c22007-05-04 20:15:47 +00005916 else if (binfo->extra && binfo->extra->igpmetric)
5917 vty_out (vty, " (metric %d)", binfo->extra->igpmetric);
pauleb821182004-05-01 08:44:08 +00005918 vty_out (vty, " from %s", sockunion2str (&binfo->peer->su, buf, SU_ADDRSTRLEN));
paul718e3742002-12-13 20:15:29 +00005919 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005920 vty_out (vty, " (%s)", inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00005921 else
5922 vty_out (vty, " (%s)", inet_ntop (AF_INET, &binfo->peer->remote_id, buf1, BUFSIZ));
5923 }
5924 vty_out (vty, "%s", VTY_NEWLINE);
5925
5926#ifdef HAVE_IPV6
5927 /* display nexthop local */
Paul Jakmafb982c22007-05-04 20:15:47 +00005928 if (attr->extra && attr->extra->mp_nexthop_len == 32)
paul718e3742002-12-13 20:15:29 +00005929 {
5930 vty_out (vty, " (%s)%s",
Paul Jakmafb982c22007-05-04 20:15:47 +00005931 inet_ntop (AF_INET6, &attr->extra->mp_nexthop_local,
paul718e3742002-12-13 20:15:29 +00005932 buf, INET6_ADDRSTRLEN),
5933 VTY_NEWLINE);
5934 }
5935#endif /* HAVE_IPV6 */
5936
5937 /* Line 3 display Origin, Med, Locpref, Weight, valid, Int/Ext/Local, Atomic, best */
5938 vty_out (vty, " Origin %s", bgp_origin_long_str[attr->origin]);
5939
5940 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_MULTI_EXIT_DISC))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005941 vty_out (vty, ", metric %u", attr->med);
paul718e3742002-12-13 20:15:29 +00005942
5943 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_LOCAL_PREF))
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005944 vty_out (vty, ", localpref %u", attr->local_pref);
paul718e3742002-12-13 20:15:29 +00005945 else
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005946 vty_out (vty, ", localpref %u", bgp->default_local_pref);
paul718e3742002-12-13 20:15:29 +00005947
Paul Jakmafb982c22007-05-04 20:15:47 +00005948 if (attr->extra && attr->extra->weight != 0)
Wataru Tanitsuc099baf2010-09-10 09:47:56 -07005949 vty_out (vty, ", weight %u", attr->extra->weight);
paul718e3742002-12-13 20:15:29 +00005950
5951 if (! CHECK_FLAG (binfo->flags, BGP_INFO_HISTORY))
5952 vty_out (vty, ", valid");
5953
5954 if (binfo->peer != bgp->peer_self)
5955 {
5956 if (binfo->peer->as == binfo->peer->local_as)
5957 vty_out (vty, ", internal");
5958 else
5959 vty_out (vty, ", %s",
5960 (bgp_confederation_peers_check(bgp, binfo->peer->as) ? "confed-external" : "external"));
5961 }
5962 else if (binfo->sub_type == BGP_ROUTE_AGGREGATE)
5963 vty_out (vty, ", aggregated, local");
5964 else if (binfo->type != ZEBRA_ROUTE_BGP)
5965 vty_out (vty, ", sourced");
5966 else
5967 vty_out (vty, ", sourced, local");
5968
5969 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ATOMIC_AGGREGATE))
5970 vty_out (vty, ", atomic-aggregate");
5971
Josh Baileyde8d5df2011-07-20 20:46:01 -07005972 if (CHECK_FLAG (binfo->flags, BGP_INFO_MULTIPATH) ||
5973 (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED) &&
5974 bgp_info_mpath_count (binfo)))
5975 vty_out (vty, ", multipath");
5976
paul718e3742002-12-13 20:15:29 +00005977 if (CHECK_FLAG (binfo->flags, BGP_INFO_SELECTED))
5978 vty_out (vty, ", best");
5979
5980 vty_out (vty, "%s", VTY_NEWLINE);
5981
5982 /* Line 4 display Community */
5983 if (attr->community)
5984 vty_out (vty, " Community: %s%s", attr->community->str,
5985 VTY_NEWLINE);
5986
5987 /* Line 5 display Extended-community */
5988 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_EXT_COMMUNITIES))
Paul Jakmafb982c22007-05-04 20:15:47 +00005989 vty_out (vty, " Extended Community: %s%s",
5990 attr->extra->ecommunity->str, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00005991
5992 /* Line 6 display Originator, Cluster-id */
5993 if ((attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID)) ||
5994 (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST)))
5995 {
Paul Jakmafb982c22007-05-04 20:15:47 +00005996 assert (attr->extra);
paul718e3742002-12-13 20:15:29 +00005997 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_ORIGINATOR_ID))
Paul Jakmafb982c22007-05-04 20:15:47 +00005998 vty_out (vty, " Originator: %s",
5999 inet_ntoa (attr->extra->originator_id));
paul718e3742002-12-13 20:15:29 +00006000
6001 if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_CLUSTER_LIST))
6002 {
6003 int i;
6004 vty_out (vty, ", Cluster list: ");
Paul Jakmafb982c22007-05-04 20:15:47 +00006005 for (i = 0; i < attr->extra->cluster->length / 4; i++)
6006 vty_out (vty, "%s ",
6007 inet_ntoa (attr->extra->cluster->list[i]));
paul718e3742002-12-13 20:15:29 +00006008 }
6009 vty_out (vty, "%s", VTY_NEWLINE);
6010 }
Paul Jakma41367172007-08-06 15:24:51 +00006011
Paul Jakmafb982c22007-05-04 20:15:47 +00006012 if (binfo->extra && binfo->extra->damp_info)
paul718e3742002-12-13 20:15:29 +00006013 bgp_damp_info_vty (vty, binfo);
6014
6015 /* Line 7 display Uptime */
John Kemp30b00172011-03-18 17:52:18 +03006016#ifdef HAVE_CLOCK_MONOTONIC
6017 tbuf = time(NULL) - (bgp_clock() - binfo->uptime);
Vladimir L Ivanov213b6cd2010-10-21 14:59:54 +04006018 vty_out (vty, " Last update: %s", ctime(&tbuf));
John Kemp30b00172011-03-18 17:52:18 +03006019#else
6020 vty_out (vty, " Last update: %s", ctime(&binfo->uptime));
6021#endif /* HAVE_CLOCK_MONOTONIC */
paul718e3742002-12-13 20:15:29 +00006022 }
6023 vty_out (vty, "%s", VTY_NEWLINE);
6024}
6025
paulb40d9392005-08-22 22:34:41 +00006026#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 +00006027#define BGP_SHOW_OCODE_HEADER "Origin codes: i - IGP, e - EGP, ? - incomplete%s%s"
paul718e3742002-12-13 20:15:29 +00006028#define BGP_SHOW_HEADER " Network Next Hop Metric LocPrf Weight Path%s"
6029#define BGP_SHOW_DAMP_HEADER " Network From Reuse Path%s"
6030#define BGP_SHOW_FLAP_HEADER " Network From Flaps Duration Reuse Path%s"
6031
6032enum bgp_show_type
6033{
6034 bgp_show_type_normal,
6035 bgp_show_type_regexp,
6036 bgp_show_type_prefix_list,
6037 bgp_show_type_filter_list,
6038 bgp_show_type_route_map,
6039 bgp_show_type_neighbor,
6040 bgp_show_type_cidr_only,
6041 bgp_show_type_prefix_longer,
6042 bgp_show_type_community_all,
6043 bgp_show_type_community,
6044 bgp_show_type_community_exact,
6045 bgp_show_type_community_list,
6046 bgp_show_type_community_list_exact,
6047 bgp_show_type_flap_statistics,
6048 bgp_show_type_flap_address,
6049 bgp_show_type_flap_prefix,
6050 bgp_show_type_flap_cidr_only,
6051 bgp_show_type_flap_regexp,
6052 bgp_show_type_flap_filter_list,
6053 bgp_show_type_flap_prefix_list,
6054 bgp_show_type_flap_prefix_longer,
6055 bgp_show_type_flap_route_map,
6056 bgp_show_type_flap_neighbor,
6057 bgp_show_type_dampend_paths,
6058 bgp_show_type_damp_neighbor
6059};
6060
ajs5a646652004-11-05 01:25:55 +00006061static int
paulfee0f4c2004-09-13 05:12:46 +00006062bgp_show_table (struct vty *vty, struct bgp_table *table, struct in_addr *router_id,
ajs5a646652004-11-05 01:25:55 +00006063 enum bgp_show_type type, void *output_arg)
paul718e3742002-12-13 20:15:29 +00006064{
paul718e3742002-12-13 20:15:29 +00006065 struct bgp_info *ri;
6066 struct bgp_node *rn;
paul718e3742002-12-13 20:15:29 +00006067 int header = 1;
paul718e3742002-12-13 20:15:29 +00006068 int display;
ajs5a646652004-11-05 01:25:55 +00006069 unsigned long output_count;
paul718e3742002-12-13 20:15:29 +00006070
6071 /* This is first entry point, so reset total line. */
ajs5a646652004-11-05 01:25:55 +00006072 output_count = 0;
paul718e3742002-12-13 20:15:29 +00006073
paul718e3742002-12-13 20:15:29 +00006074 /* Start processing of routes. */
6075 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
6076 if (rn->info != NULL)
6077 {
6078 display = 0;
6079
6080 for (ri = rn->info; ri; ri = ri->next)
6081 {
ajs5a646652004-11-05 01:25:55 +00006082 if (type == bgp_show_type_flap_statistics
paul718e3742002-12-13 20:15:29 +00006083 || type == bgp_show_type_flap_address
6084 || type == bgp_show_type_flap_prefix
6085 || type == bgp_show_type_flap_cidr_only
6086 || type == bgp_show_type_flap_regexp
6087 || type == bgp_show_type_flap_filter_list
6088 || type == bgp_show_type_flap_prefix_list
6089 || type == bgp_show_type_flap_prefix_longer
6090 || type == bgp_show_type_flap_route_map
6091 || type == bgp_show_type_flap_neighbor
6092 || type == bgp_show_type_dampend_paths
6093 || type == bgp_show_type_damp_neighbor)
6094 {
Paul Jakmafb982c22007-05-04 20:15:47 +00006095 if (!(ri->extra && ri->extra->damp_info))
paul718e3742002-12-13 20:15:29 +00006096 continue;
6097 }
6098 if (type == bgp_show_type_regexp
6099 || type == bgp_show_type_flap_regexp)
6100 {
ajs5a646652004-11-05 01:25:55 +00006101 regex_t *regex = output_arg;
paul718e3742002-12-13 20:15:29 +00006102
6103 if (bgp_regexec (regex, ri->attr->aspath) == REG_NOMATCH)
6104 continue;
6105 }
6106 if (type == bgp_show_type_prefix_list
6107 || type == bgp_show_type_flap_prefix_list)
6108 {
ajs5a646652004-11-05 01:25:55 +00006109 struct prefix_list *plist = output_arg;
paul718e3742002-12-13 20:15:29 +00006110
6111 if (prefix_list_apply (plist, &rn->p) != PREFIX_PERMIT)
6112 continue;
6113 }
6114 if (type == bgp_show_type_filter_list
6115 || type == bgp_show_type_flap_filter_list)
6116 {
ajs5a646652004-11-05 01:25:55 +00006117 struct as_list *as_list = output_arg;
paul718e3742002-12-13 20:15:29 +00006118
6119 if (as_list_apply (as_list, ri->attr->aspath) != AS_FILTER_PERMIT)
6120 continue;
6121 }
6122 if (type == bgp_show_type_route_map
6123 || type == bgp_show_type_flap_route_map)
6124 {
ajs5a646652004-11-05 01:25:55 +00006125 struct route_map *rmap = output_arg;
paul718e3742002-12-13 20:15:29 +00006126 struct bgp_info binfo;
Paul Jakma9eda90c2007-08-30 13:36:17 +00006127 struct attr dummy_attr = { 0 };
paul718e3742002-12-13 20:15:29 +00006128 int ret;
6129
Paul Jakmafb982c22007-05-04 20:15:47 +00006130 bgp_attr_dup (&dummy_attr, ri->attr);
paul718e3742002-12-13 20:15:29 +00006131 binfo.peer = ri->peer;
6132 binfo.attr = &dummy_attr;
6133
6134 ret = route_map_apply (rmap, &rn->p, RMAP_BGP, &binfo);
Paul Jakmafb982c22007-05-04 20:15:47 +00006135
6136 bgp_attr_extra_free (&dummy_attr);
6137
paul718e3742002-12-13 20:15:29 +00006138 if (ret == RMAP_DENYMATCH)
6139 continue;
6140 }
6141 if (type == bgp_show_type_neighbor
6142 || type == bgp_show_type_flap_neighbor
6143 || type == bgp_show_type_damp_neighbor)
6144 {
ajs5a646652004-11-05 01:25:55 +00006145 union sockunion *su = output_arg;
paul718e3742002-12-13 20:15:29 +00006146
6147 if (ri->peer->su_remote == NULL || ! sockunion_same(ri->peer->su_remote, su))
6148 continue;
6149 }
6150 if (type == bgp_show_type_cidr_only
6151 || type == bgp_show_type_flap_cidr_only)
6152 {
6153 u_int32_t destination;
6154
6155 destination = ntohl (rn->p.u.prefix4.s_addr);
6156 if (IN_CLASSC (destination) && rn->p.prefixlen == 24)
6157 continue;
6158 if (IN_CLASSB (destination) && rn->p.prefixlen == 16)
6159 continue;
6160 if (IN_CLASSA (destination) && rn->p.prefixlen == 8)
6161 continue;
6162 }
6163 if (type == bgp_show_type_prefix_longer
6164 || type == bgp_show_type_flap_prefix_longer)
6165 {
ajs5a646652004-11-05 01:25:55 +00006166 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006167
6168 if (! prefix_match (p, &rn->p))
6169 continue;
6170 }
6171 if (type == bgp_show_type_community_all)
6172 {
6173 if (! ri->attr->community)
6174 continue;
6175 }
6176 if (type == bgp_show_type_community)
6177 {
ajs5a646652004-11-05 01:25:55 +00006178 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006179
6180 if (! ri->attr->community ||
6181 ! community_match (ri->attr->community, com))
6182 continue;
6183 }
6184 if (type == bgp_show_type_community_exact)
6185 {
ajs5a646652004-11-05 01:25:55 +00006186 struct community *com = output_arg;
paul718e3742002-12-13 20:15:29 +00006187
6188 if (! ri->attr->community ||
6189 ! community_cmp (ri->attr->community, com))
6190 continue;
6191 }
6192 if (type == bgp_show_type_community_list)
6193 {
ajs5a646652004-11-05 01:25:55 +00006194 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006195
6196 if (! community_list_match (ri->attr->community, list))
6197 continue;
6198 }
6199 if (type == bgp_show_type_community_list_exact)
6200 {
ajs5a646652004-11-05 01:25:55 +00006201 struct community_list *list = output_arg;
paul718e3742002-12-13 20:15:29 +00006202
6203 if (! community_list_exact_match (ri->attr->community, list))
6204 continue;
6205 }
6206 if (type == bgp_show_type_flap_address
6207 || type == bgp_show_type_flap_prefix)
6208 {
ajs5a646652004-11-05 01:25:55 +00006209 struct prefix *p = output_arg;
paul718e3742002-12-13 20:15:29 +00006210
6211 if (! prefix_match (&rn->p, p))
6212 continue;
6213
6214 if (type == bgp_show_type_flap_prefix)
6215 if (p->prefixlen != rn->p.prefixlen)
6216 continue;
6217 }
6218 if (type == bgp_show_type_dampend_paths
6219 || type == bgp_show_type_damp_neighbor)
6220 {
6221 if (! CHECK_FLAG (ri->flags, BGP_INFO_DAMPED)
6222 || CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
6223 continue;
6224 }
6225
6226 if (header)
6227 {
hasso93406d82005-02-02 14:40:33 +00006228 vty_out (vty, "BGP table version is 0, local router ID is %s%s", inet_ntoa (*router_id), VTY_NEWLINE);
6229 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
6230 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006231 if (type == bgp_show_type_dampend_paths
6232 || type == bgp_show_type_damp_neighbor)
6233 vty_out (vty, BGP_SHOW_DAMP_HEADER, VTY_NEWLINE);
6234 else if (type == bgp_show_type_flap_statistics
6235 || type == bgp_show_type_flap_address
6236 || type == bgp_show_type_flap_prefix
6237 || type == bgp_show_type_flap_cidr_only
6238 || type == bgp_show_type_flap_regexp
6239 || type == bgp_show_type_flap_filter_list
6240 || type == bgp_show_type_flap_prefix_list
6241 || type == bgp_show_type_flap_prefix_longer
6242 || type == bgp_show_type_flap_route_map
6243 || type == bgp_show_type_flap_neighbor)
6244 vty_out (vty, BGP_SHOW_FLAP_HEADER, VTY_NEWLINE);
6245 else
6246 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006247 header = 0;
6248 }
6249
6250 if (type == bgp_show_type_dampend_paths
6251 || type == bgp_show_type_damp_neighbor)
ajs5a646652004-11-05 01:25:55 +00006252 damp_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006253 else if (type == bgp_show_type_flap_statistics
6254 || type == bgp_show_type_flap_address
6255 || type == bgp_show_type_flap_prefix
6256 || type == bgp_show_type_flap_cidr_only
6257 || type == bgp_show_type_flap_regexp
6258 || type == bgp_show_type_flap_filter_list
6259 || type == bgp_show_type_flap_prefix_list
6260 || type == bgp_show_type_flap_prefix_longer
6261 || type == bgp_show_type_flap_route_map
6262 || type == bgp_show_type_flap_neighbor)
ajs5a646652004-11-05 01:25:55 +00006263 flap_route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006264 else
ajs5a646652004-11-05 01:25:55 +00006265 route_vty_out (vty, &rn->p, ri, display, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00006266 display++;
6267 }
6268 if (display)
ajs5a646652004-11-05 01:25:55 +00006269 output_count++;
paul718e3742002-12-13 20:15:29 +00006270 }
6271
6272 /* No route is displayed */
ajs5a646652004-11-05 01:25:55 +00006273 if (output_count == 0)
paul718e3742002-12-13 20:15:29 +00006274 {
6275 if (type == bgp_show_type_normal)
6276 vty_out (vty, "No BGP network exists%s", VTY_NEWLINE);
6277 }
6278 else
6279 vty_out (vty, "%sTotal number of prefixes %ld%s",
ajs5a646652004-11-05 01:25:55 +00006280 VTY_NEWLINE, output_count, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00006281
6282 return CMD_SUCCESS;
6283}
6284
ajs5a646652004-11-05 01:25:55 +00006285static int
paulfee0f4c2004-09-13 05:12:46 +00006286bgp_show (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi,
ajs5a646652004-11-05 01:25:55 +00006287 enum bgp_show_type type, void *output_arg)
paulfee0f4c2004-09-13 05:12:46 +00006288{
6289 struct bgp_table *table;
6290
6291 if (bgp == NULL) {
6292 bgp = bgp_get_default ();
6293 }
6294
6295 if (bgp == NULL)
6296 {
6297 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6298 return CMD_WARNING;
6299 }
6300
6301
6302 table = bgp->rib[afi][safi];
6303
ajs5a646652004-11-05 01:25:55 +00006304 return bgp_show_table (vty, table, &bgp->router_id, type, output_arg);
paulfee0f4c2004-09-13 05:12:46 +00006305}
6306
paul718e3742002-12-13 20:15:29 +00006307/* Header of detailed BGP route information */
paul94f2b392005-06-28 12:44:16 +00006308static void
paul718e3742002-12-13 20:15:29 +00006309route_vty_out_detail_header (struct vty *vty, struct bgp *bgp,
6310 struct bgp_node *rn,
6311 struct prefix_rd *prd, afi_t afi, safi_t safi)
6312{
6313 struct bgp_info *ri;
6314 struct prefix *p;
6315 struct peer *peer;
paul1eb8ef22005-04-07 07:30:20 +00006316 struct listnode *node, *nnode;
paul718e3742002-12-13 20:15:29 +00006317 char buf1[INET6_ADDRSTRLEN];
6318 char buf2[INET6_ADDRSTRLEN];
6319 int count = 0;
6320 int best = 0;
6321 int suppress = 0;
6322 int no_export = 0;
6323 int no_advertise = 0;
6324 int local_as = 0;
6325 int first = 0;
6326
6327 p = &rn->p;
6328 vty_out (vty, "BGP routing table entry for %s%s%s/%d%s",
6329 (safi == SAFI_MPLS_VPN ?
6330 prefix_rd2str (prd, buf1, RD_ADDRSTRLEN) : ""),
6331 safi == SAFI_MPLS_VPN ? ":" : "",
6332 inet_ntop (p->family, &p->u.prefix, buf2, INET6_ADDRSTRLEN),
6333 p->prefixlen, VTY_NEWLINE);
6334
6335 for (ri = rn->info; ri; ri = ri->next)
6336 {
6337 count++;
6338 if (CHECK_FLAG (ri->flags, BGP_INFO_SELECTED))
6339 {
6340 best = count;
Paul Jakmafb982c22007-05-04 20:15:47 +00006341 if (ri->extra && ri->extra->suppress)
paul718e3742002-12-13 20:15:29 +00006342 suppress = 1;
6343 if (ri->attr->community != NULL)
6344 {
6345 if (community_include (ri->attr->community, COMMUNITY_NO_ADVERTISE))
6346 no_advertise = 1;
6347 if (community_include (ri->attr->community, COMMUNITY_NO_EXPORT))
6348 no_export = 1;
6349 if (community_include (ri->attr->community, COMMUNITY_LOCAL_AS))
6350 local_as = 1;
6351 }
6352 }
6353 }
6354
6355 vty_out (vty, "Paths: (%d available", count);
6356 if (best)
6357 {
6358 vty_out (vty, ", best #%d", best);
6359 if (safi == SAFI_UNICAST)
6360 vty_out (vty, ", table Default-IP-Routing-Table");
6361 }
6362 else
6363 vty_out (vty, ", no best path");
6364 if (no_advertise)
6365 vty_out (vty, ", not advertised to any peer");
6366 else if (no_export)
6367 vty_out (vty, ", not advertised to EBGP peer");
6368 else if (local_as)
6369 vty_out (vty, ", not advertised outside local AS");
6370 if (suppress)
6371 vty_out (vty, ", Advertisements suppressed by an aggregate.");
6372 vty_out (vty, ")%s", VTY_NEWLINE);
6373
6374 /* advertised peer */
paul1eb8ef22005-04-07 07:30:20 +00006375 for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer))
paul718e3742002-12-13 20:15:29 +00006376 {
6377 if (bgp_adj_out_lookup (peer, p, afi, safi, rn))
6378 {
6379 if (! first)
6380 vty_out (vty, " Advertised to non peer-group peers:%s ", VTY_NEWLINE);
6381 vty_out (vty, " %s", sockunion2str (&peer->su, buf1, SU_ADDRSTRLEN));
6382 first = 1;
6383 }
6384 }
6385 if (! first)
6386 vty_out (vty, " Not advertised to any peer");
6387 vty_out (vty, "%s", VTY_NEWLINE);
6388}
6389
6390/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +00006391static int
paulfee0f4c2004-09-13 05:12:46 +00006392bgp_show_route_in_table (struct vty *vty, struct bgp *bgp,
paulfd79ac92004-10-13 05:06:08 +00006393 struct bgp_table *rib, const char *ip_str,
6394 afi_t afi, safi_t safi, struct prefix_rd *prd,
6395 int prefix_check)
paul718e3742002-12-13 20:15:29 +00006396{
6397 int ret;
6398 int header;
6399 int display = 0;
6400 struct prefix match;
6401 struct bgp_node *rn;
6402 struct bgp_node *rm;
6403 struct bgp_info *ri;
paul718e3742002-12-13 20:15:29 +00006404 struct bgp_table *table;
6405
paul718e3742002-12-13 20:15:29 +00006406 /* Check IP address argument. */
6407 ret = str2prefix (ip_str, &match);
6408 if (! ret)
6409 {
6410 vty_out (vty, "address is malformed%s", VTY_NEWLINE);
6411 return CMD_WARNING;
6412 }
6413
6414 match.family = afi2family (afi);
6415
6416 if (safi == SAFI_MPLS_VPN)
6417 {
paulfee0f4c2004-09-13 05:12:46 +00006418 for (rn = bgp_table_top (rib); rn; rn = bgp_route_next (rn))
paul718e3742002-12-13 20:15:29 +00006419 {
6420 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
6421 continue;
6422
6423 if ((table = rn->info) != NULL)
6424 {
6425 header = 1;
6426
6427 if ((rm = bgp_node_match (table, &match)) != NULL)
6428 {
6429 if (prefix_check && rm->p.prefixlen != match.prefixlen)
Chris Caputo6c88b442010-07-27 16:28:55 +00006430 {
6431 bgp_unlock_node (rm);
6432 continue;
6433 }
paul718e3742002-12-13 20:15:29 +00006434
6435 for (ri = rm->info; ri; ri = ri->next)
6436 {
6437 if (header)
6438 {
6439 route_vty_out_detail_header (vty, bgp, rm, (struct prefix_rd *)&rn->p,
6440 AFI_IP, SAFI_MPLS_VPN);
6441
6442 header = 0;
6443 }
6444 display++;
6445 route_vty_out_detail (vty, bgp, &rm->p, ri, AFI_IP, SAFI_MPLS_VPN);
6446 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006447
6448 bgp_unlock_node (rm);
paul718e3742002-12-13 20:15:29 +00006449 }
6450 }
6451 }
6452 }
6453 else
6454 {
6455 header = 1;
6456
paulfee0f4c2004-09-13 05:12:46 +00006457 if ((rn = bgp_node_match (rib, &match)) != NULL)
paul718e3742002-12-13 20:15:29 +00006458 {
6459 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
6460 {
6461 for (ri = rn->info; ri; ri = ri->next)
6462 {
6463 if (header)
6464 {
6465 route_vty_out_detail_header (vty, bgp, rn, NULL, afi, safi);
6466 header = 0;
6467 }
6468 display++;
6469 route_vty_out_detail (vty, bgp, &rn->p, ri, afi, safi);
6470 }
6471 }
Chris Caputo6c88b442010-07-27 16:28:55 +00006472
6473 bgp_unlock_node (rn);
paul718e3742002-12-13 20:15:29 +00006474 }
6475 }
6476
6477 if (! display)
6478 {
6479 vty_out (vty, "%% Network not in table%s", VTY_NEWLINE);
6480 return CMD_WARNING;
6481 }
6482
6483 return CMD_SUCCESS;
6484}
6485
paulfee0f4c2004-09-13 05:12:46 +00006486/* Display specified route of Main RIB */
paul94f2b392005-06-28 12:44:16 +00006487static int
paulfd79ac92004-10-13 05:06:08 +00006488bgp_show_route (struct vty *vty, const char *view_name, const char *ip_str,
paulfee0f4c2004-09-13 05:12:46 +00006489 afi_t afi, safi_t safi, struct prefix_rd *prd,
6490 int prefix_check)
6491{
6492 struct bgp *bgp;
6493
6494 /* BGP structure lookup. */
6495 if (view_name)
6496 {
6497 bgp = bgp_lookup_by_name (view_name);
6498 if (bgp == NULL)
6499 {
6500 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
6501 return CMD_WARNING;
6502 }
6503 }
6504 else
6505 {
6506 bgp = bgp_get_default ();
6507 if (bgp == NULL)
6508 {
6509 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
6510 return CMD_WARNING;
6511 }
6512 }
6513
6514 return bgp_show_route_in_table (vty, bgp, bgp->rib[afi][safi], ip_str,
6515 afi, safi, prd, prefix_check);
6516}
6517
paul718e3742002-12-13 20:15:29 +00006518/* BGP route print out function. */
6519DEFUN (show_ip_bgp,
6520 show_ip_bgp_cmd,
6521 "show ip bgp",
6522 SHOW_STR
6523 IP_STR
6524 BGP_STR)
6525{
ajs5a646652004-11-05 01:25:55 +00006526 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006527}
6528
6529DEFUN (show_ip_bgp_ipv4,
6530 show_ip_bgp_ipv4_cmd,
6531 "show ip bgp ipv4 (unicast|multicast)",
6532 SHOW_STR
6533 IP_STR
6534 BGP_STR
6535 "Address family\n"
6536 "Address Family modifier\n"
6537 "Address Family modifier\n")
6538{
6539 if (strncmp (argv[0], "m", 1) == 0)
ajs5a646652004-11-05 01:25:55 +00006540 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST, bgp_show_type_normal,
6541 NULL);
paul718e3742002-12-13 20:15:29 +00006542
ajs5a646652004-11-05 01:25:55 +00006543 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006544}
6545
Michael Lambert95cbbd22010-07-23 14:43:04 -04006546ALIAS (show_ip_bgp_ipv4,
6547 show_bgp_ipv4_safi_cmd,
6548 "show bgp ipv4 (unicast|multicast)",
6549 SHOW_STR
6550 BGP_STR
6551 "Address family\n"
6552 "Address Family modifier\n"
6553 "Address Family modifier\n")
6554
paul718e3742002-12-13 20:15:29 +00006555DEFUN (show_ip_bgp_route,
6556 show_ip_bgp_route_cmd,
6557 "show ip bgp A.B.C.D",
6558 SHOW_STR
6559 IP_STR
6560 BGP_STR
6561 "Network in the BGP routing table to display\n")
6562{
6563 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 0);
6564}
6565
6566DEFUN (show_ip_bgp_ipv4_route,
6567 show_ip_bgp_ipv4_route_cmd,
6568 "show ip bgp ipv4 (unicast|multicast) A.B.C.D",
6569 SHOW_STR
6570 IP_STR
6571 BGP_STR
6572 "Address family\n"
6573 "Address Family modifier\n"
6574 "Address Family modifier\n"
6575 "Network in the BGP routing table to display\n")
6576{
6577 if (strncmp (argv[0], "m", 1) == 0)
6578 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 0);
6579
6580 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6581}
6582
Michael Lambert95cbbd22010-07-23 14:43:04 -04006583ALIAS (show_ip_bgp_ipv4_route,
6584 show_bgp_ipv4_safi_route_cmd,
6585 "show bgp ipv4 (unicast|multicast) A.B.C.D",
6586 SHOW_STR
6587 BGP_STR
6588 "Address family\n"
6589 "Address Family modifier\n"
6590 "Address Family modifier\n"
6591 "Network in the BGP routing table to display\n")
6592
paul718e3742002-12-13 20:15:29 +00006593DEFUN (show_ip_bgp_vpnv4_all_route,
6594 show_ip_bgp_vpnv4_all_route_cmd,
6595 "show ip bgp vpnv4 all A.B.C.D",
6596 SHOW_STR
6597 IP_STR
6598 BGP_STR
6599 "Display VPNv4 NLRI specific information\n"
6600 "Display information about all VPNv4 NLRIs\n"
6601 "Network in the BGP routing table to display\n")
6602{
6603 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 0);
6604}
6605
6606DEFUN (show_ip_bgp_vpnv4_rd_route,
6607 show_ip_bgp_vpnv4_rd_route_cmd,
6608 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D",
6609 SHOW_STR
6610 IP_STR
6611 BGP_STR
6612 "Display VPNv4 NLRI specific information\n"
6613 "Display information for a route distinguisher\n"
6614 "VPN Route Distinguisher\n"
6615 "Network in the BGP routing table to display\n")
6616{
6617 int ret;
6618 struct prefix_rd prd;
6619
6620 ret = str2prefix_rd (argv[0], &prd);
6621 if (! ret)
6622 {
6623 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6624 return CMD_WARNING;
6625 }
6626 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 0);
6627}
6628
6629DEFUN (show_ip_bgp_prefix,
6630 show_ip_bgp_prefix_cmd,
6631 "show ip bgp A.B.C.D/M",
6632 SHOW_STR
6633 IP_STR
6634 BGP_STR
6635 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6636{
6637 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_UNICAST, NULL, 1);
6638}
6639
6640DEFUN (show_ip_bgp_ipv4_prefix,
6641 show_ip_bgp_ipv4_prefix_cmd,
6642 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M",
6643 SHOW_STR
6644 IP_STR
6645 BGP_STR
6646 "Address family\n"
6647 "Address Family modifier\n"
6648 "Address Family modifier\n"
6649 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6650{
6651 if (strncmp (argv[0], "m", 1) == 0)
6652 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MULTICAST, NULL, 1);
6653
6654 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6655}
6656
Michael Lambert95cbbd22010-07-23 14:43:04 -04006657ALIAS (show_ip_bgp_ipv4_prefix,
6658 show_bgp_ipv4_safi_prefix_cmd,
6659 "show bgp ipv4 (unicast|multicast) A.B.C.D/M",
6660 SHOW_STR
6661 BGP_STR
6662 "Address family\n"
6663 "Address Family modifier\n"
6664 "Address Family modifier\n"
6665 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6666
paul718e3742002-12-13 20:15:29 +00006667DEFUN (show_ip_bgp_vpnv4_all_prefix,
6668 show_ip_bgp_vpnv4_all_prefix_cmd,
6669 "show ip bgp vpnv4 all A.B.C.D/M",
6670 SHOW_STR
6671 IP_STR
6672 BGP_STR
6673 "Display VPNv4 NLRI specific information\n"
6674 "Display information about all VPNv4 NLRIs\n"
6675 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6676{
6677 return bgp_show_route (vty, NULL, argv[0], AFI_IP, SAFI_MPLS_VPN, NULL, 1);
6678}
6679
6680DEFUN (show_ip_bgp_vpnv4_rd_prefix,
6681 show_ip_bgp_vpnv4_rd_prefix_cmd,
6682 "show ip bgp vpnv4 rd ASN:nn_or_IP-address:nn A.B.C.D/M",
6683 SHOW_STR
6684 IP_STR
6685 BGP_STR
6686 "Display VPNv4 NLRI specific information\n"
6687 "Display information for a route distinguisher\n"
6688 "VPN Route Distinguisher\n"
6689 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6690{
6691 int ret;
6692 struct prefix_rd prd;
6693
6694 ret = str2prefix_rd (argv[0], &prd);
6695 if (! ret)
6696 {
6697 vty_out (vty, "%% Malformed Route Distinguisher%s", VTY_NEWLINE);
6698 return CMD_WARNING;
6699 }
6700 return bgp_show_route (vty, NULL, argv[1], AFI_IP, SAFI_MPLS_VPN, &prd, 1);
6701}
6702
6703DEFUN (show_ip_bgp_view,
6704 show_ip_bgp_view_cmd,
6705 "show ip bgp view WORD",
6706 SHOW_STR
6707 IP_STR
6708 BGP_STR
6709 "BGP view\n"
6710 "BGP view name\n")
6711{
paulbb46e942003-10-24 19:02:03 +00006712 struct bgp *bgp;
6713
6714 /* BGP structure lookup. */
6715 bgp = bgp_lookup_by_name (argv[0]);
6716 if (bgp == NULL)
6717 {
6718 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6719 return CMD_WARNING;
6720 }
6721
ajs5a646652004-11-05 01:25:55 +00006722 return bgp_show (vty, bgp, AFI_IP, SAFI_UNICAST, bgp_show_type_normal, NULL);
paul718e3742002-12-13 20:15:29 +00006723}
6724
6725DEFUN (show_ip_bgp_view_route,
6726 show_ip_bgp_view_route_cmd,
6727 "show ip bgp view WORD A.B.C.D",
6728 SHOW_STR
6729 IP_STR
6730 BGP_STR
6731 "BGP view\n"
6732 "BGP view name\n"
6733 "Network in the BGP routing table to display\n")
6734{
6735 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 0);
6736}
6737
6738DEFUN (show_ip_bgp_view_prefix,
6739 show_ip_bgp_view_prefix_cmd,
6740 "show ip bgp view WORD A.B.C.D/M",
6741 SHOW_STR
6742 IP_STR
6743 BGP_STR
6744 "BGP view\n"
6745 "BGP view name\n"
6746 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
6747{
6748 return bgp_show_route (vty, argv[0], argv[1], AFI_IP, SAFI_UNICAST, NULL, 1);
6749}
6750
6751#ifdef HAVE_IPV6
6752DEFUN (show_bgp,
6753 show_bgp_cmd,
6754 "show bgp",
6755 SHOW_STR
6756 BGP_STR)
6757{
ajs5a646652004-11-05 01:25:55 +00006758 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6759 NULL);
paul718e3742002-12-13 20:15:29 +00006760}
6761
6762ALIAS (show_bgp,
6763 show_bgp_ipv6_cmd,
6764 "show bgp ipv6",
6765 SHOW_STR
6766 BGP_STR
6767 "Address family\n")
6768
Michael Lambert95cbbd22010-07-23 14:43:04 -04006769DEFUN (show_bgp_ipv6_safi,
6770 show_bgp_ipv6_safi_cmd,
6771 "show bgp ipv6 (unicast|multicast)",
6772 SHOW_STR
6773 BGP_STR
6774 "Address family\n"
6775 "Address Family modifier\n"
6776 "Address Family modifier\n")
6777{
6778 if (strncmp (argv[0], "m", 1) == 0)
6779 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6780 NULL);
6781
6782 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
6783}
6784
paul718e3742002-12-13 20:15:29 +00006785/* old command */
6786DEFUN (show_ipv6_bgp,
6787 show_ipv6_bgp_cmd,
6788 "show ipv6 bgp",
6789 SHOW_STR
6790 IP_STR
6791 BGP_STR)
6792{
ajs5a646652004-11-05 01:25:55 +00006793 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal,
6794 NULL);
paul718e3742002-12-13 20:15:29 +00006795}
6796
6797DEFUN (show_bgp_route,
6798 show_bgp_route_cmd,
6799 "show bgp X:X::X:X",
6800 SHOW_STR
6801 BGP_STR
6802 "Network in the BGP routing table to display\n")
6803{
6804 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6805}
6806
6807ALIAS (show_bgp_route,
6808 show_bgp_ipv6_route_cmd,
6809 "show bgp ipv6 X:X::X:X",
6810 SHOW_STR
6811 BGP_STR
6812 "Address family\n"
6813 "Network in the BGP routing table to display\n")
6814
Michael Lambert95cbbd22010-07-23 14:43:04 -04006815DEFUN (show_bgp_ipv6_safi_route,
6816 show_bgp_ipv6_safi_route_cmd,
6817 "show bgp ipv6 (unicast|multicast) X:X::X:X",
6818 SHOW_STR
6819 BGP_STR
6820 "Address family\n"
6821 "Address Family modifier\n"
6822 "Address Family modifier\n"
6823 "Network in the BGP routing table to display\n")
6824{
6825 if (strncmp (argv[0], "m", 1) == 0)
6826 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6827
6828 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6829}
6830
paul718e3742002-12-13 20:15:29 +00006831/* old command */
6832DEFUN (show_ipv6_bgp_route,
6833 show_ipv6_bgp_route_cmd,
6834 "show ipv6 bgp X:X::X:X",
6835 SHOW_STR
6836 IP_STR
6837 BGP_STR
6838 "Network in the BGP routing table to display\n")
6839{
6840 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 0);
6841}
6842
6843DEFUN (show_bgp_prefix,
6844 show_bgp_prefix_cmd,
6845 "show bgp X:X::X:X/M",
6846 SHOW_STR
6847 BGP_STR
6848 "IPv6 prefix <network>/<length>\n")
6849{
6850 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6851}
6852
6853ALIAS (show_bgp_prefix,
6854 show_bgp_ipv6_prefix_cmd,
6855 "show bgp ipv6 X:X::X:X/M",
6856 SHOW_STR
6857 BGP_STR
6858 "Address family\n"
6859 "IPv6 prefix <network>/<length>\n")
6860
Michael Lambert95cbbd22010-07-23 14:43:04 -04006861DEFUN (show_bgp_ipv6_safi_prefix,
6862 show_bgp_ipv6_safi_prefix_cmd,
6863 "show bgp ipv6 (unicast|multicast) X:X::X:X/M",
6864 SHOW_STR
6865 BGP_STR
6866 "Address family\n"
6867 "Address Family modifier\n"
6868 "Address Family modifier\n"
6869 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6870{
6871 if (strncmp (argv[0], "m", 1) == 0)
6872 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6873
6874 return bgp_show_route (vty, NULL, argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6875}
6876
paul718e3742002-12-13 20:15:29 +00006877/* old command */
6878DEFUN (show_ipv6_bgp_prefix,
6879 show_ipv6_bgp_prefix_cmd,
6880 "show ipv6 bgp X:X::X:X/M",
6881 SHOW_STR
6882 IP_STR
6883 BGP_STR
6884 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6885{
6886 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_UNICAST, NULL, 1);
6887}
6888
paulbb46e942003-10-24 19:02:03 +00006889DEFUN (show_bgp_view,
6890 show_bgp_view_cmd,
6891 "show bgp view WORD",
6892 SHOW_STR
6893 BGP_STR
6894 "BGP view\n"
6895 "View name\n")
6896{
6897 struct bgp *bgp;
6898
6899 /* BGP structure lookup. */
6900 bgp = bgp_lookup_by_name (argv[0]);
6901 if (bgp == NULL)
6902 {
6903 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
6904 return CMD_WARNING;
6905 }
6906
ajs5a646652004-11-05 01:25:55 +00006907 return bgp_show (vty, bgp, AFI_IP6, SAFI_UNICAST, bgp_show_type_normal, NULL);
paulbb46e942003-10-24 19:02:03 +00006908}
6909
6910ALIAS (show_bgp_view,
6911 show_bgp_view_ipv6_cmd,
6912 "show bgp view WORD ipv6",
6913 SHOW_STR
6914 BGP_STR
6915 "BGP view\n"
6916 "View name\n"
6917 "Address family\n")
6918
6919DEFUN (show_bgp_view_route,
6920 show_bgp_view_route_cmd,
6921 "show bgp view WORD X:X::X:X",
6922 SHOW_STR
6923 BGP_STR
6924 "BGP view\n"
6925 "View name\n"
6926 "Network in the BGP routing table to display\n")
6927{
6928 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 0);
6929}
6930
6931ALIAS (show_bgp_view_route,
6932 show_bgp_view_ipv6_route_cmd,
6933 "show bgp view WORD ipv6 X:X::X:X",
6934 SHOW_STR
6935 BGP_STR
6936 "BGP view\n"
6937 "View name\n"
6938 "Address family\n"
6939 "Network in the BGP routing table to display\n")
6940
6941DEFUN (show_bgp_view_prefix,
6942 show_bgp_view_prefix_cmd,
6943 "show bgp view WORD X:X::X:X/M",
6944 SHOW_STR
6945 BGP_STR
6946 "BGP view\n"
6947 "View name\n"
6948 "IPv6 prefix <network>/<length>\n")
6949{
6950 return bgp_show_route (vty, argv[0], argv[1], AFI_IP6, SAFI_UNICAST, NULL, 1);
6951}
6952
6953ALIAS (show_bgp_view_prefix,
6954 show_bgp_view_ipv6_prefix_cmd,
6955 "show bgp view WORD ipv6 X:X::X:X/M",
6956 SHOW_STR
6957 BGP_STR
6958 "BGP view\n"
6959 "View name\n"
6960 "Address family\n"
6961 "IPv6 prefix <network>/<length>\n")
6962
paul718e3742002-12-13 20:15:29 +00006963/* old command */
6964DEFUN (show_ipv6_mbgp,
6965 show_ipv6_mbgp_cmd,
6966 "show ipv6 mbgp",
6967 SHOW_STR
6968 IP_STR
6969 MBGP_STR)
6970{
ajs5a646652004-11-05 01:25:55 +00006971 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST, bgp_show_type_normal,
6972 NULL);
paul718e3742002-12-13 20:15:29 +00006973}
6974
6975/* old command */
6976DEFUN (show_ipv6_mbgp_route,
6977 show_ipv6_mbgp_route_cmd,
6978 "show ipv6 mbgp X:X::X:X",
6979 SHOW_STR
6980 IP_STR
6981 MBGP_STR
6982 "Network in the MBGP routing table to display\n")
6983{
6984 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 0);
6985}
6986
6987/* old command */
6988DEFUN (show_ipv6_mbgp_prefix,
6989 show_ipv6_mbgp_prefix_cmd,
6990 "show ipv6 mbgp X:X::X:X/M",
6991 SHOW_STR
6992 IP_STR
6993 MBGP_STR
6994 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
6995{
6996 return bgp_show_route (vty, NULL, argv[0], AFI_IP6, SAFI_MULTICAST, NULL, 1);
6997}
6998#endif
6999
paul718e3742002-12-13 20:15:29 +00007000
paul94f2b392005-06-28 12:44:16 +00007001static int
paulfd79ac92004-10-13 05:06:08 +00007002bgp_show_regexp (struct vty *vty, int argc, const char **argv, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007003 safi_t safi, enum bgp_show_type type)
7004{
7005 int i;
7006 struct buffer *b;
7007 char *regstr;
7008 int first;
7009 regex_t *regex;
ajs5a646652004-11-05 01:25:55 +00007010 int rc;
paul718e3742002-12-13 20:15:29 +00007011
7012 first = 0;
7013 b = buffer_new (1024);
7014 for (i = 0; i < argc; i++)
7015 {
7016 if (first)
7017 buffer_putc (b, ' ');
7018 else
7019 {
7020 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7021 continue;
7022 first = 1;
7023 }
7024
7025 buffer_putstr (b, argv[i]);
7026 }
7027 buffer_putc (b, '\0');
7028
7029 regstr = buffer_getstr (b);
7030 buffer_free (b);
7031
7032 regex = bgp_regcomp (regstr);
ajs3b8b1852005-01-29 18:19:13 +00007033 XFREE(MTYPE_TMP, regstr);
paul718e3742002-12-13 20:15:29 +00007034 if (! regex)
7035 {
7036 vty_out (vty, "Can't compile regexp %s%s", argv[0],
7037 VTY_NEWLINE);
7038 return CMD_WARNING;
7039 }
7040
ajs5a646652004-11-05 01:25:55 +00007041 rc = bgp_show (vty, NULL, afi, safi, type, regex);
7042 bgp_regex_free (regex);
7043 return rc;
paul718e3742002-12-13 20:15:29 +00007044}
7045
7046DEFUN (show_ip_bgp_regexp,
7047 show_ip_bgp_regexp_cmd,
7048 "show ip bgp regexp .LINE",
7049 SHOW_STR
7050 IP_STR
7051 BGP_STR
7052 "Display routes matching the AS path regular expression\n"
7053 "A regular-expression to match the BGP AS paths\n")
7054{
7055 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7056 bgp_show_type_regexp);
7057}
7058
7059DEFUN (show_ip_bgp_flap_regexp,
7060 show_ip_bgp_flap_regexp_cmd,
7061 "show ip bgp flap-statistics regexp .LINE",
7062 SHOW_STR
7063 IP_STR
7064 BGP_STR
7065 "Display flap statistics of routes\n"
7066 "Display routes matching the AS path regular expression\n"
7067 "A regular-expression to match the BGP AS paths\n")
7068{
7069 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7070 bgp_show_type_flap_regexp);
7071}
7072
7073DEFUN (show_ip_bgp_ipv4_regexp,
7074 show_ip_bgp_ipv4_regexp_cmd,
7075 "show ip bgp ipv4 (unicast|multicast) regexp .LINE",
7076 SHOW_STR
7077 IP_STR
7078 BGP_STR
7079 "Address family\n"
7080 "Address Family modifier\n"
7081 "Address Family modifier\n"
7082 "Display routes matching the AS path regular expression\n"
7083 "A regular-expression to match the BGP AS paths\n")
7084{
7085 if (strncmp (argv[0], "m", 1) == 0)
7086 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_MULTICAST,
7087 bgp_show_type_regexp);
7088
7089 return bgp_show_regexp (vty, argc, argv, AFI_IP, SAFI_UNICAST,
7090 bgp_show_type_regexp);
7091}
7092
7093#ifdef HAVE_IPV6
7094DEFUN (show_bgp_regexp,
7095 show_bgp_regexp_cmd,
7096 "show bgp regexp .LINE",
7097 SHOW_STR
7098 BGP_STR
7099 "Display routes matching the AS path regular expression\n"
7100 "A regular-expression to match the BGP AS paths\n")
7101{
7102 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7103 bgp_show_type_regexp);
7104}
7105
7106ALIAS (show_bgp_regexp,
7107 show_bgp_ipv6_regexp_cmd,
7108 "show bgp ipv6 regexp .LINE",
7109 SHOW_STR
7110 BGP_STR
7111 "Address family\n"
7112 "Display routes matching the AS path regular expression\n"
7113 "A regular-expression to match the BGP AS paths\n")
7114
7115/* old command */
7116DEFUN (show_ipv6_bgp_regexp,
7117 show_ipv6_bgp_regexp_cmd,
7118 "show ipv6 bgp regexp .LINE",
7119 SHOW_STR
7120 IP_STR
7121 BGP_STR
7122 "Display routes matching the AS path regular expression\n"
7123 "A regular-expression to match the BGP AS paths\n")
7124{
7125 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_UNICAST,
7126 bgp_show_type_regexp);
7127}
7128
7129/* old command */
7130DEFUN (show_ipv6_mbgp_regexp,
7131 show_ipv6_mbgp_regexp_cmd,
7132 "show ipv6 mbgp regexp .LINE",
7133 SHOW_STR
7134 IP_STR
7135 BGP_STR
7136 "Display routes matching the AS path regular expression\n"
7137 "A regular-expression to match the MBGP AS paths\n")
7138{
7139 return bgp_show_regexp (vty, argc, argv, AFI_IP6, SAFI_MULTICAST,
7140 bgp_show_type_regexp);
7141}
7142#endif /* HAVE_IPV6 */
7143
paul94f2b392005-06-28 12:44:16 +00007144static int
paulfd79ac92004-10-13 05:06:08 +00007145bgp_show_prefix_list (struct vty *vty, const char *prefix_list_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007146 safi_t safi, enum bgp_show_type type)
7147{
7148 struct prefix_list *plist;
7149
7150 plist = prefix_list_lookup (afi, prefix_list_str);
7151 if (plist == NULL)
7152 {
7153 vty_out (vty, "%% %s is not a valid prefix-list name%s",
7154 prefix_list_str, VTY_NEWLINE);
7155 return CMD_WARNING;
7156 }
7157
ajs5a646652004-11-05 01:25:55 +00007158 return bgp_show (vty, NULL, afi, safi, type, plist);
paul718e3742002-12-13 20:15:29 +00007159}
7160
7161DEFUN (show_ip_bgp_prefix_list,
7162 show_ip_bgp_prefix_list_cmd,
7163 "show ip bgp prefix-list WORD",
7164 SHOW_STR
7165 IP_STR
7166 BGP_STR
7167 "Display routes conforming to the prefix-list\n"
7168 "IP prefix-list name\n")
7169{
7170 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7171 bgp_show_type_prefix_list);
7172}
7173
7174DEFUN (show_ip_bgp_flap_prefix_list,
7175 show_ip_bgp_flap_prefix_list_cmd,
7176 "show ip bgp flap-statistics prefix-list WORD",
7177 SHOW_STR
7178 IP_STR
7179 BGP_STR
7180 "Display flap statistics of routes\n"
7181 "Display routes conforming to the prefix-list\n"
7182 "IP prefix-list name\n")
7183{
7184 return bgp_show_prefix_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7185 bgp_show_type_flap_prefix_list);
7186}
7187
7188DEFUN (show_ip_bgp_ipv4_prefix_list,
7189 show_ip_bgp_ipv4_prefix_list_cmd,
7190 "show ip bgp ipv4 (unicast|multicast) prefix-list WORD",
7191 SHOW_STR
7192 IP_STR
7193 BGP_STR
7194 "Address family\n"
7195 "Address Family modifier\n"
7196 "Address Family modifier\n"
7197 "Display routes conforming to the prefix-list\n"
7198 "IP prefix-list name\n")
7199{
7200 if (strncmp (argv[0], "m", 1) == 0)
7201 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7202 bgp_show_type_prefix_list);
7203
7204 return bgp_show_prefix_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7205 bgp_show_type_prefix_list);
7206}
7207
7208#ifdef HAVE_IPV6
7209DEFUN (show_bgp_prefix_list,
7210 show_bgp_prefix_list_cmd,
7211 "show bgp prefix-list WORD",
7212 SHOW_STR
7213 BGP_STR
7214 "Display routes conforming to the prefix-list\n"
7215 "IPv6 prefix-list name\n")
7216{
7217 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7218 bgp_show_type_prefix_list);
7219}
7220
7221ALIAS (show_bgp_prefix_list,
7222 show_bgp_ipv6_prefix_list_cmd,
7223 "show bgp ipv6 prefix-list WORD",
7224 SHOW_STR
7225 BGP_STR
7226 "Address family\n"
7227 "Display routes conforming to the prefix-list\n"
7228 "IPv6 prefix-list name\n")
7229
7230/* old command */
7231DEFUN (show_ipv6_bgp_prefix_list,
7232 show_ipv6_bgp_prefix_list_cmd,
7233 "show ipv6 bgp prefix-list WORD",
7234 SHOW_STR
7235 IPV6_STR
7236 BGP_STR
7237 "Display routes matching the prefix-list\n"
7238 "IPv6 prefix-list name\n")
7239{
7240 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7241 bgp_show_type_prefix_list);
7242}
7243
7244/* old command */
7245DEFUN (show_ipv6_mbgp_prefix_list,
7246 show_ipv6_mbgp_prefix_list_cmd,
7247 "show ipv6 mbgp prefix-list WORD",
7248 SHOW_STR
7249 IPV6_STR
7250 MBGP_STR
7251 "Display routes matching the prefix-list\n"
7252 "IPv6 prefix-list name\n")
7253{
7254 return bgp_show_prefix_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7255 bgp_show_type_prefix_list);
7256}
7257#endif /* HAVE_IPV6 */
7258
paul94f2b392005-06-28 12:44:16 +00007259static int
paulfd79ac92004-10-13 05:06:08 +00007260bgp_show_filter_list (struct vty *vty, const char *filter, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007261 safi_t safi, enum bgp_show_type type)
7262{
7263 struct as_list *as_list;
7264
7265 as_list = as_list_lookup (filter);
7266 if (as_list == NULL)
7267 {
7268 vty_out (vty, "%% %s is not a valid AS-path access-list name%s", filter, VTY_NEWLINE);
7269 return CMD_WARNING;
7270 }
7271
ajs5a646652004-11-05 01:25:55 +00007272 return bgp_show (vty, NULL, afi, safi, type, as_list);
paul718e3742002-12-13 20:15:29 +00007273}
7274
7275DEFUN (show_ip_bgp_filter_list,
7276 show_ip_bgp_filter_list_cmd,
7277 "show ip bgp filter-list WORD",
7278 SHOW_STR
7279 IP_STR
7280 BGP_STR
7281 "Display routes conforming to the filter-list\n"
7282 "Regular expression access list name\n")
7283{
7284 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7285 bgp_show_type_filter_list);
7286}
7287
7288DEFUN (show_ip_bgp_flap_filter_list,
7289 show_ip_bgp_flap_filter_list_cmd,
7290 "show ip bgp flap-statistics filter-list WORD",
7291 SHOW_STR
7292 IP_STR
7293 BGP_STR
7294 "Display flap statistics of routes\n"
7295 "Display routes conforming to the filter-list\n"
7296 "Regular expression access list name\n")
7297{
7298 return bgp_show_filter_list (vty, argv[0], AFI_IP, SAFI_UNICAST,
7299 bgp_show_type_flap_filter_list);
7300}
7301
7302DEFUN (show_ip_bgp_ipv4_filter_list,
7303 show_ip_bgp_ipv4_filter_list_cmd,
7304 "show ip bgp ipv4 (unicast|multicast) filter-list WORD",
7305 SHOW_STR
7306 IP_STR
7307 BGP_STR
7308 "Address family\n"
7309 "Address Family modifier\n"
7310 "Address Family modifier\n"
7311 "Display routes conforming to the filter-list\n"
7312 "Regular expression access list name\n")
7313{
7314 if (strncmp (argv[0], "m", 1) == 0)
7315 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7316 bgp_show_type_filter_list);
7317
7318 return bgp_show_filter_list (vty, argv[1], AFI_IP, SAFI_UNICAST,
7319 bgp_show_type_filter_list);
7320}
7321
7322#ifdef HAVE_IPV6
7323DEFUN (show_bgp_filter_list,
7324 show_bgp_filter_list_cmd,
7325 "show bgp filter-list WORD",
7326 SHOW_STR
7327 BGP_STR
7328 "Display routes conforming to the filter-list\n"
7329 "Regular expression access list name\n")
7330{
7331 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7332 bgp_show_type_filter_list);
7333}
7334
7335ALIAS (show_bgp_filter_list,
7336 show_bgp_ipv6_filter_list_cmd,
7337 "show bgp ipv6 filter-list WORD",
7338 SHOW_STR
7339 BGP_STR
7340 "Address family\n"
7341 "Display routes conforming to the filter-list\n"
7342 "Regular expression access list name\n")
7343
7344/* old command */
7345DEFUN (show_ipv6_bgp_filter_list,
7346 show_ipv6_bgp_filter_list_cmd,
7347 "show ipv6 bgp filter-list WORD",
7348 SHOW_STR
7349 IPV6_STR
7350 BGP_STR
7351 "Display routes conforming to the filter-list\n"
7352 "Regular expression access list name\n")
7353{
7354 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7355 bgp_show_type_filter_list);
7356}
7357
7358/* old command */
7359DEFUN (show_ipv6_mbgp_filter_list,
7360 show_ipv6_mbgp_filter_list_cmd,
7361 "show ipv6 mbgp filter-list WORD",
7362 SHOW_STR
7363 IPV6_STR
7364 MBGP_STR
7365 "Display routes conforming to the filter-list\n"
7366 "Regular expression access list name\n")
7367{
7368 return bgp_show_filter_list (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
7369 bgp_show_type_filter_list);
7370}
7371#endif /* HAVE_IPV6 */
7372
paul94f2b392005-06-28 12:44:16 +00007373static int
paulfd79ac92004-10-13 05:06:08 +00007374bgp_show_route_map (struct vty *vty, const char *rmap_str, afi_t afi,
paul718e3742002-12-13 20:15:29 +00007375 safi_t safi, enum bgp_show_type type)
7376{
7377 struct route_map *rmap;
7378
7379 rmap = route_map_lookup_by_name (rmap_str);
7380 if (! rmap)
7381 {
7382 vty_out (vty, "%% %s is not a valid route-map name%s",
7383 rmap_str, VTY_NEWLINE);
7384 return CMD_WARNING;
7385 }
7386
ajs5a646652004-11-05 01:25:55 +00007387 return bgp_show (vty, NULL, afi, safi, type, rmap);
paul718e3742002-12-13 20:15:29 +00007388}
7389
7390DEFUN (show_ip_bgp_route_map,
7391 show_ip_bgp_route_map_cmd,
7392 "show ip bgp route-map WORD",
7393 SHOW_STR
7394 IP_STR
7395 BGP_STR
7396 "Display routes matching the route-map\n"
7397 "A route-map to match on\n")
7398{
7399 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7400 bgp_show_type_route_map);
7401}
7402
7403DEFUN (show_ip_bgp_flap_route_map,
7404 show_ip_bgp_flap_route_map_cmd,
7405 "show ip bgp flap-statistics route-map WORD",
7406 SHOW_STR
7407 IP_STR
7408 BGP_STR
7409 "Display flap statistics of routes\n"
7410 "Display routes matching the route-map\n"
7411 "A route-map to match on\n")
7412{
7413 return bgp_show_route_map (vty, argv[0], AFI_IP, SAFI_UNICAST,
7414 bgp_show_type_flap_route_map);
7415}
7416
7417DEFUN (show_ip_bgp_ipv4_route_map,
7418 show_ip_bgp_ipv4_route_map_cmd,
7419 "show ip bgp ipv4 (unicast|multicast) route-map WORD",
7420 SHOW_STR
7421 IP_STR
7422 BGP_STR
7423 "Address family\n"
7424 "Address Family modifier\n"
7425 "Address Family modifier\n"
7426 "Display routes matching the route-map\n"
7427 "A route-map to match on\n")
7428{
7429 if (strncmp (argv[0], "m", 1) == 0)
7430 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_MULTICAST,
7431 bgp_show_type_route_map);
7432
7433 return bgp_show_route_map (vty, argv[1], AFI_IP, SAFI_UNICAST,
7434 bgp_show_type_route_map);
7435}
7436
7437DEFUN (show_bgp_route_map,
7438 show_bgp_route_map_cmd,
7439 "show bgp route-map WORD",
7440 SHOW_STR
7441 BGP_STR
7442 "Display routes matching the route-map\n"
7443 "A route-map to match on\n")
7444{
7445 return bgp_show_route_map (vty, argv[0], AFI_IP6, SAFI_UNICAST,
7446 bgp_show_type_route_map);
7447}
7448
7449ALIAS (show_bgp_route_map,
7450 show_bgp_ipv6_route_map_cmd,
7451 "show bgp ipv6 route-map WORD",
7452 SHOW_STR
7453 BGP_STR
7454 "Address family\n"
7455 "Display routes matching the route-map\n"
7456 "A route-map to match on\n")
7457
7458DEFUN (show_ip_bgp_cidr_only,
7459 show_ip_bgp_cidr_only_cmd,
7460 "show ip bgp cidr-only",
7461 SHOW_STR
7462 IP_STR
7463 BGP_STR
7464 "Display only routes with non-natural netmasks\n")
7465{
7466 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007467 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007468}
7469
7470DEFUN (show_ip_bgp_flap_cidr_only,
7471 show_ip_bgp_flap_cidr_only_cmd,
7472 "show ip bgp flap-statistics cidr-only",
7473 SHOW_STR
7474 IP_STR
7475 BGP_STR
7476 "Display flap statistics of routes\n"
7477 "Display only routes with non-natural netmasks\n")
7478{
7479 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007480 bgp_show_type_flap_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007481}
7482
7483DEFUN (show_ip_bgp_ipv4_cidr_only,
7484 show_ip_bgp_ipv4_cidr_only_cmd,
7485 "show ip bgp ipv4 (unicast|multicast) cidr-only",
7486 SHOW_STR
7487 IP_STR
7488 BGP_STR
7489 "Address family\n"
7490 "Address Family modifier\n"
7491 "Address Family modifier\n"
7492 "Display only routes with non-natural netmasks\n")
7493{
7494 if (strncmp (argv[0], "m", 1) == 0)
7495 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007496 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007497
7498 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007499 bgp_show_type_cidr_only, NULL);
paul718e3742002-12-13 20:15:29 +00007500}
7501
7502DEFUN (show_ip_bgp_community_all,
7503 show_ip_bgp_community_all_cmd,
7504 "show ip bgp community",
7505 SHOW_STR
7506 IP_STR
7507 BGP_STR
7508 "Display routes matching the communities\n")
7509{
7510 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007511 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007512}
7513
7514DEFUN (show_ip_bgp_ipv4_community_all,
7515 show_ip_bgp_ipv4_community_all_cmd,
7516 "show ip bgp ipv4 (unicast|multicast) community",
7517 SHOW_STR
7518 IP_STR
7519 BGP_STR
7520 "Address family\n"
7521 "Address Family modifier\n"
7522 "Address Family modifier\n"
7523 "Display routes matching the communities\n")
7524{
7525 if (strncmp (argv[0], "m", 1) == 0)
7526 return bgp_show (vty, NULL, AFI_IP, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007527 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007528
7529 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007530 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007531}
7532
7533#ifdef HAVE_IPV6
7534DEFUN (show_bgp_community_all,
7535 show_bgp_community_all_cmd,
7536 "show bgp community",
7537 SHOW_STR
7538 BGP_STR
7539 "Display routes matching the communities\n")
7540{
7541 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007542 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007543}
7544
7545ALIAS (show_bgp_community_all,
7546 show_bgp_ipv6_community_all_cmd,
7547 "show bgp ipv6 community",
7548 SHOW_STR
7549 BGP_STR
7550 "Address family\n"
7551 "Display routes matching the communities\n")
7552
7553/* old command */
7554DEFUN (show_ipv6_bgp_community_all,
7555 show_ipv6_bgp_community_all_cmd,
7556 "show ipv6 bgp community",
7557 SHOW_STR
7558 IPV6_STR
7559 BGP_STR
7560 "Display routes matching the communities\n")
7561{
7562 return bgp_show (vty, NULL, AFI_IP6, SAFI_UNICAST,
ajs5a646652004-11-05 01:25:55 +00007563 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007564}
7565
7566/* old command */
7567DEFUN (show_ipv6_mbgp_community_all,
7568 show_ipv6_mbgp_community_all_cmd,
7569 "show ipv6 mbgp community",
7570 SHOW_STR
7571 IPV6_STR
7572 MBGP_STR
7573 "Display routes matching the communities\n")
7574{
7575 return bgp_show (vty, NULL, AFI_IP6, SAFI_MULTICAST,
ajs5a646652004-11-05 01:25:55 +00007576 bgp_show_type_community_all, NULL);
paul718e3742002-12-13 20:15:29 +00007577}
7578#endif /* HAVE_IPV6 */
7579
paul94f2b392005-06-28 12:44:16 +00007580static int
Michael Lambert95cbbd22010-07-23 14:43:04 -04007581bgp_show_community (struct vty *vty, const char *view_name, int argc,
7582 const char **argv, int exact, afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00007583{
7584 struct community *com;
7585 struct buffer *b;
Michael Lambert95cbbd22010-07-23 14:43:04 -04007586 struct bgp *bgp;
paul718e3742002-12-13 20:15:29 +00007587 int i;
7588 char *str;
7589 int first = 0;
7590
Michael Lambert95cbbd22010-07-23 14:43:04 -04007591 /* BGP structure lookup */
7592 if (view_name)
7593 {
7594 bgp = bgp_lookup_by_name (view_name);
7595 if (bgp == NULL)
7596 {
7597 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
7598 return CMD_WARNING;
7599 }
7600 }
7601 else
7602 {
7603 bgp = bgp_get_default ();
7604 if (bgp == NULL)
7605 {
7606 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
7607 return CMD_WARNING;
7608 }
7609 }
7610
paul718e3742002-12-13 20:15:29 +00007611 b = buffer_new (1024);
7612 for (i = 0; i < argc; i++)
7613 {
7614 if (first)
7615 buffer_putc (b, ' ');
7616 else
7617 {
7618 if ((strcmp (argv[i], "unicast") == 0) || (strcmp (argv[i], "multicast") == 0))
7619 continue;
7620 first = 1;
7621 }
7622
7623 buffer_putstr (b, argv[i]);
7624 }
7625 buffer_putc (b, '\0');
7626
7627 str = buffer_getstr (b);
7628 buffer_free (b);
7629
7630 com = community_str2com (str);
ajs3b8b1852005-01-29 18:19:13 +00007631 XFREE (MTYPE_TMP, str);
paul718e3742002-12-13 20:15:29 +00007632 if (! com)
7633 {
7634 vty_out (vty, "%% Community malformed: %s", VTY_NEWLINE);
7635 return CMD_WARNING;
7636 }
7637
Michael Lambert95cbbd22010-07-23 14:43:04 -04007638 return bgp_show (vty, bgp, afi, safi,
ajs5a646652004-11-05 01:25:55 +00007639 (exact ? bgp_show_type_community_exact :
7640 bgp_show_type_community), com);
paul718e3742002-12-13 20:15:29 +00007641}
7642
7643DEFUN (show_ip_bgp_community,
7644 show_ip_bgp_community_cmd,
7645 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export)",
7646 SHOW_STR
7647 IP_STR
7648 BGP_STR
7649 "Display routes matching the communities\n"
7650 "community number\n"
7651 "Do not send outside local AS (well-known community)\n"
7652 "Do not advertise to any peer (well-known community)\n"
7653 "Do not export to next AS (well-known community)\n")
7654{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007655 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007656}
7657
7658ALIAS (show_ip_bgp_community,
7659 show_ip_bgp_community2_cmd,
7660 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7661 SHOW_STR
7662 IP_STR
7663 BGP_STR
7664 "Display routes matching the communities\n"
7665 "community number\n"
7666 "Do not send outside local AS (well-known community)\n"
7667 "Do not advertise to any peer (well-known community)\n"
7668 "Do not export to next AS (well-known community)\n"
7669 "community number\n"
7670 "Do not send outside local AS (well-known community)\n"
7671 "Do not advertise to any peer (well-known community)\n"
7672 "Do not export to next AS (well-known community)\n")
7673
7674ALIAS (show_ip_bgp_community,
7675 show_ip_bgp_community3_cmd,
7676 "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)",
7677 SHOW_STR
7678 IP_STR
7679 BGP_STR
7680 "Display routes matching the communities\n"
7681 "community number\n"
7682 "Do not send outside local AS (well-known community)\n"
7683 "Do not advertise to any peer (well-known community)\n"
7684 "Do not export to next AS (well-known community)\n"
7685 "community number\n"
7686 "Do not send outside local AS (well-known community)\n"
7687 "Do not advertise to any peer (well-known community)\n"
7688 "Do not export to next AS (well-known community)\n"
7689 "community number\n"
7690 "Do not send outside local AS (well-known community)\n"
7691 "Do not advertise to any peer (well-known community)\n"
7692 "Do not export to next AS (well-known community)\n")
7693
7694ALIAS (show_ip_bgp_community,
7695 show_ip_bgp_community4_cmd,
7696 "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)",
7697 SHOW_STR
7698 IP_STR
7699 BGP_STR
7700 "Display routes matching the communities\n"
7701 "community number\n"
7702 "Do not send outside local AS (well-known community)\n"
7703 "Do not advertise to any peer (well-known community)\n"
7704 "Do not export to next AS (well-known community)\n"
7705 "community number\n"
7706 "Do not send outside local AS (well-known community)\n"
7707 "Do not advertise to any peer (well-known community)\n"
7708 "Do not export to next AS (well-known community)\n"
7709 "community number\n"
7710 "Do not send outside local AS (well-known community)\n"
7711 "Do not advertise to any peer (well-known community)\n"
7712 "Do not export to next AS (well-known community)\n"
7713 "community number\n"
7714 "Do not send outside local AS (well-known community)\n"
7715 "Do not advertise to any peer (well-known community)\n"
7716 "Do not export to next AS (well-known community)\n")
7717
7718DEFUN (show_ip_bgp_ipv4_community,
7719 show_ip_bgp_ipv4_community_cmd,
7720 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7721 SHOW_STR
7722 IP_STR
7723 BGP_STR
7724 "Address family\n"
7725 "Address Family modifier\n"
7726 "Address Family modifier\n"
7727 "Display routes matching the communities\n"
7728 "community number\n"
7729 "Do not send outside local AS (well-known community)\n"
7730 "Do not advertise to any peer (well-known community)\n"
7731 "Do not export to next AS (well-known community)\n")
7732{
7733 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04007734 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00007735
Michael Lambert95cbbd22010-07-23 14:43:04 -04007736 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007737}
7738
7739ALIAS (show_ip_bgp_ipv4_community,
7740 show_ip_bgp_ipv4_community2_cmd,
7741 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7742 SHOW_STR
7743 IP_STR
7744 BGP_STR
7745 "Address family\n"
7746 "Address Family modifier\n"
7747 "Address Family modifier\n"
7748 "Display routes matching the communities\n"
7749 "community number\n"
7750 "Do not send outside local AS (well-known community)\n"
7751 "Do not advertise to any peer (well-known community)\n"
7752 "Do not export to next AS (well-known community)\n"
7753 "community number\n"
7754 "Do not send outside local AS (well-known community)\n"
7755 "Do not advertise to any peer (well-known community)\n"
7756 "Do not export to next AS (well-known community)\n")
7757
7758ALIAS (show_ip_bgp_ipv4_community,
7759 show_ip_bgp_ipv4_community3_cmd,
7760 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7761 SHOW_STR
7762 IP_STR
7763 BGP_STR
7764 "Address family\n"
7765 "Address Family modifier\n"
7766 "Address Family modifier\n"
7767 "Display routes matching the communities\n"
7768 "community number\n"
7769 "Do not send outside local AS (well-known community)\n"
7770 "Do not advertise to any peer (well-known community)\n"
7771 "Do not export to next AS (well-known community)\n"
7772 "community number\n"
7773 "Do not send outside local AS (well-known community)\n"
7774 "Do not advertise to any peer (well-known community)\n"
7775 "Do not export to next AS (well-known community)\n"
7776 "community number\n"
7777 "Do not send outside local AS (well-known community)\n"
7778 "Do not advertise to any peer (well-known community)\n"
7779 "Do not export to next AS (well-known community)\n")
7780
7781ALIAS (show_ip_bgp_ipv4_community,
7782 show_ip_bgp_ipv4_community4_cmd,
7783 "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)",
7784 SHOW_STR
7785 IP_STR
7786 BGP_STR
7787 "Address family\n"
7788 "Address Family modifier\n"
7789 "Address Family modifier\n"
7790 "Display routes matching the communities\n"
7791 "community number\n"
7792 "Do not send outside local AS (well-known community)\n"
7793 "Do not advertise to any peer (well-known community)\n"
7794 "Do not export to next AS (well-known community)\n"
7795 "community number\n"
7796 "Do not send outside local AS (well-known community)\n"
7797 "Do not advertise to any peer (well-known community)\n"
7798 "Do not export to next AS (well-known community)\n"
7799 "community number\n"
7800 "Do not send outside local AS (well-known community)\n"
7801 "Do not advertise to any peer (well-known community)\n"
7802 "Do not export to next AS (well-known community)\n"
7803 "community number\n"
7804 "Do not send outside local AS (well-known community)\n"
7805 "Do not advertise to any peer (well-known community)\n"
7806 "Do not export to next AS (well-known community)\n")
7807
Michael Lambert95cbbd22010-07-23 14:43:04 -04007808DEFUN (show_bgp_view_afi_safi_community_all,
7809 show_bgp_view_afi_safi_community_all_cmd,
7810#ifdef HAVE_IPV6
7811 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community",
7812#else
7813 "show bgp view WORD ipv4 (unicast|multicast) community",
7814#endif
7815 SHOW_STR
7816 BGP_STR
7817 "BGP view\n"
7818 "BGP view name\n"
7819 "Address family\n"
7820#ifdef HAVE_IPV6
7821 "Address family\n"
7822#endif
7823 "Address Family modifier\n"
7824 "Address Family modifier\n"
7825 "Display routes containing communities\n")
7826{
7827 int afi;
7828 int safi;
7829 struct bgp *bgp;
7830
7831 /* BGP structure lookup. */
7832 bgp = bgp_lookup_by_name (argv[0]);
7833 if (bgp == NULL)
7834 {
7835 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
7836 return CMD_WARNING;
7837 }
7838
7839#ifdef HAVE_IPV6
7840 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7841 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7842#else
7843 afi = AFI_IP;
7844 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7845#endif
7846 return bgp_show (vty, bgp, afi, safi, bgp_show_type_community_all, NULL);
7847}
7848
7849DEFUN (show_bgp_view_afi_safi_community,
7850 show_bgp_view_afi_safi_community_cmd,
7851#ifdef HAVE_IPV6
7852 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7853#else
7854 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export)",
7855#endif
7856 SHOW_STR
7857 BGP_STR
7858 "BGP view\n"
7859 "BGP view name\n"
7860 "Address family\n"
7861#ifdef HAVE_IPV6
7862 "Address family\n"
7863#endif
7864 "Address family modifier\n"
7865 "Address family modifier\n"
7866 "Display routes matching the communities\n"
7867 "community number\n"
7868 "Do not send outside local AS (well-known community)\n"
7869 "Do not advertise to any peer (well-known community)\n"
7870 "Do not export to next AS (well-known community)\n")
7871{
7872 int afi;
7873 int safi;
7874
7875#ifdef HAVE_IPV6
7876 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
7877 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7878 return bgp_show_community (vty, argv[0], argc-3, &argv[3], 0, afi, safi);
7879#else
7880 afi = AFI_IP;
7881 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
7882 return bgp_show_community (vty, argv[0], argc-2, &argv[2], 0, afi, safi);
7883#endif
7884}
7885
7886ALIAS (show_bgp_view_afi_safi_community,
7887 show_bgp_view_afi_safi_community2_cmd,
7888#ifdef HAVE_IPV6
7889 "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)",
7890#else
7891 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7892#endif
7893 SHOW_STR
7894 BGP_STR
7895 "BGP view\n"
7896 "BGP view name\n"
7897 "Address family\n"
7898#ifdef HAVE_IPV6
7899 "Address family\n"
7900#endif
7901 "Address family modifier\n"
7902 "Address family modifier\n"
7903 "Display routes matching the communities\n"
7904 "community number\n"
7905 "Do not send outside local AS (well-known community)\n"
7906 "Do not advertise to any peer (well-known community)\n"
7907 "Do not export to next AS (well-known community)\n"
7908 "community number\n"
7909 "Do not send outside local AS (well-known community)\n"
7910 "Do not advertise to any peer (well-known community)\n"
7911 "Do not export to next AS (well-known community)\n")
7912
7913ALIAS (show_bgp_view_afi_safi_community,
7914 show_bgp_view_afi_safi_community3_cmd,
7915#ifdef HAVE_IPV6
7916 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7917#else
7918 "show bgp view WORD ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
7919#endif
7920 SHOW_STR
7921 BGP_STR
7922 "BGP view\n"
7923 "BGP view name\n"
7924 "Address family\n"
7925#ifdef HAVE_IPV6
7926 "Address family\n"
7927#endif
7928 "Address family modifier\n"
7929 "Address family modifier\n"
7930 "Display routes matching the communities\n"
7931 "community number\n"
7932 "Do not send outside local AS (well-known community)\n"
7933 "Do not advertise to any peer (well-known community)\n"
7934 "Do not export to next AS (well-known community)\n"
7935 "community number\n"
7936 "Do not send outside local AS (well-known community)\n"
7937 "Do not advertise to any peer (well-known community)\n"
7938 "Do not export to next AS (well-known community)\n"
7939 "community number\n"
7940 "Do not send outside local AS (well-known community)\n"
7941 "Do not advertise to any peer (well-known community)\n"
7942 "Do not export to next AS (well-known community)\n")
7943
7944ALIAS (show_bgp_view_afi_safi_community,
7945 show_bgp_view_afi_safi_community4_cmd,
7946#ifdef HAVE_IPV6
7947 "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)",
7948#else
7949 "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)",
7950#endif
7951 SHOW_STR
7952 BGP_STR
7953 "BGP view\n"
7954 "BGP view name\n"
7955 "Address family\n"
7956#ifdef HAVE_IPV6
7957 "Address family\n"
7958#endif
7959 "Address family modifier\n"
7960 "Address family modifier\n"
7961 "Display routes matching the communities\n"
7962 "community number\n"
7963 "Do not send outside local AS (well-known community)\n"
7964 "Do not advertise to any peer (well-known community)\n"
7965 "Do not export to next AS (well-known community)\n"
7966 "community number\n"
7967 "Do not send outside local AS (well-known community)\n"
7968 "Do not advertise to any peer (well-known community)\n"
7969 "Do not export to next AS (well-known community)\n"
7970 "community number\n"
7971 "Do not send outside local AS (well-known community)\n"
7972 "Do not advertise to any peer (well-known community)\n"
7973 "Do not export to next AS (well-known community)\n"
7974 "community number\n"
7975 "Do not send outside local AS (well-known community)\n"
7976 "Do not advertise to any peer (well-known community)\n"
7977 "Do not export to next AS (well-known community)\n")
7978
paul718e3742002-12-13 20:15:29 +00007979DEFUN (show_ip_bgp_community_exact,
7980 show_ip_bgp_community_exact_cmd,
7981 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
7982 SHOW_STR
7983 IP_STR
7984 BGP_STR
7985 "Display routes matching the communities\n"
7986 "community number\n"
7987 "Do not send outside local AS (well-known community)\n"
7988 "Do not advertise to any peer (well-known community)\n"
7989 "Do not export to next AS (well-known community)\n"
7990 "Exact match of the communities")
7991{
Michael Lambert95cbbd22010-07-23 14:43:04 -04007992 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00007993}
7994
7995ALIAS (show_ip_bgp_community_exact,
7996 show_ip_bgp_community2_exact_cmd,
7997 "show ip bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
7998 SHOW_STR
7999 IP_STR
8000 BGP_STR
8001 "Display routes matching the communities\n"
8002 "community number\n"
8003 "Do not send outside local AS (well-known community)\n"
8004 "Do not advertise to any peer (well-known community)\n"
8005 "Do not export to next AS (well-known community)\n"
8006 "community number\n"
8007 "Do not send outside local AS (well-known community)\n"
8008 "Do not advertise to any peer (well-known community)\n"
8009 "Do not export to next AS (well-known community)\n"
8010 "Exact match of the communities")
8011
8012ALIAS (show_ip_bgp_community_exact,
8013 show_ip_bgp_community3_exact_cmd,
8014 "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",
8015 SHOW_STR
8016 IP_STR
8017 BGP_STR
8018 "Display routes matching the communities\n"
8019 "community number\n"
8020 "Do not send outside local AS (well-known community)\n"
8021 "Do not advertise to any peer (well-known community)\n"
8022 "Do not export to next AS (well-known community)\n"
8023 "community number\n"
8024 "Do not send outside local AS (well-known community)\n"
8025 "Do not advertise to any peer (well-known community)\n"
8026 "Do not export to next AS (well-known community)\n"
8027 "community number\n"
8028 "Do not send outside local AS (well-known community)\n"
8029 "Do not advertise to any peer (well-known community)\n"
8030 "Do not export to next AS (well-known community)\n"
8031 "Exact match of the communities")
8032
8033ALIAS (show_ip_bgp_community_exact,
8034 show_ip_bgp_community4_exact_cmd,
8035 "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",
8036 SHOW_STR
8037 IP_STR
8038 BGP_STR
8039 "Display routes matching the communities\n"
8040 "community number\n"
8041 "Do not send outside local AS (well-known community)\n"
8042 "Do not advertise to any peer (well-known community)\n"
8043 "Do not export to next AS (well-known community)\n"
8044 "community number\n"
8045 "Do not send outside local AS (well-known community)\n"
8046 "Do not advertise to any peer (well-known community)\n"
8047 "Do not export to next AS (well-known community)\n"
8048 "community number\n"
8049 "Do not send outside local AS (well-known community)\n"
8050 "Do not advertise to any peer (well-known community)\n"
8051 "Do not export to next AS (well-known community)\n"
8052 "community number\n"
8053 "Do not send outside local AS (well-known community)\n"
8054 "Do not advertise to any peer (well-known community)\n"
8055 "Do not export to next AS (well-known community)\n"
8056 "Exact match of the communities")
8057
8058DEFUN (show_ip_bgp_ipv4_community_exact,
8059 show_ip_bgp_ipv4_community_exact_cmd,
8060 "show ip bgp ipv4 (unicast|multicast) community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8061 SHOW_STR
8062 IP_STR
8063 BGP_STR
8064 "Address family\n"
8065 "Address Family modifier\n"
8066 "Address Family modifier\n"
8067 "Display routes matching the communities\n"
8068 "community number\n"
8069 "Do not send outside local AS (well-known community)\n"
8070 "Do not advertise to any peer (well-known community)\n"
8071 "Do not export to next AS (well-known community)\n"
8072 "Exact match of the communities")
8073{
8074 if (strncmp (argv[0], "m", 1) == 0)
Michael Lambert95cbbd22010-07-23 14:43:04 -04008075 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008076
Michael Lambert95cbbd22010-07-23 14:43:04 -04008077 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008078}
8079
8080ALIAS (show_ip_bgp_ipv4_community_exact,
8081 show_ip_bgp_ipv4_community2_exact_cmd,
8082 "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",
8083 SHOW_STR
8084 IP_STR
8085 BGP_STR
8086 "Address family\n"
8087 "Address Family modifier\n"
8088 "Address Family modifier\n"
8089 "Display routes matching the communities\n"
8090 "community number\n"
8091 "Do not send outside local AS (well-known community)\n"
8092 "Do not advertise to any peer (well-known community)\n"
8093 "Do not export to next AS (well-known community)\n"
8094 "community number\n"
8095 "Do not send outside local AS (well-known community)\n"
8096 "Do not advertise to any peer (well-known community)\n"
8097 "Do not export to next AS (well-known community)\n"
8098 "Exact match of the communities")
8099
8100ALIAS (show_ip_bgp_ipv4_community_exact,
8101 show_ip_bgp_ipv4_community3_exact_cmd,
8102 "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",
8103 SHOW_STR
8104 IP_STR
8105 BGP_STR
8106 "Address family\n"
8107 "Address Family modifier\n"
8108 "Address Family modifier\n"
8109 "Display routes matching the communities\n"
8110 "community number\n"
8111 "Do not send outside local AS (well-known community)\n"
8112 "Do not advertise to any peer (well-known community)\n"
8113 "Do not export to next AS (well-known community)\n"
8114 "community number\n"
8115 "Do not send outside local AS (well-known community)\n"
8116 "Do not advertise to any peer (well-known community)\n"
8117 "Do not export to next AS (well-known community)\n"
8118 "community number\n"
8119 "Do not send outside local AS (well-known community)\n"
8120 "Do not advertise to any peer (well-known community)\n"
8121 "Do not export to next AS (well-known community)\n"
8122 "Exact match of the communities")
8123
8124ALIAS (show_ip_bgp_ipv4_community_exact,
8125 show_ip_bgp_ipv4_community4_exact_cmd,
8126 "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",
8127 SHOW_STR
8128 IP_STR
8129 BGP_STR
8130 "Address family\n"
8131 "Address Family modifier\n"
8132 "Address Family modifier\n"
8133 "Display routes matching the communities\n"
8134 "community number\n"
8135 "Do not send outside local AS (well-known community)\n"
8136 "Do not advertise to any peer (well-known community)\n"
8137 "Do not export to next AS (well-known community)\n"
8138 "community number\n"
8139 "Do not send outside local AS (well-known community)\n"
8140 "Do not advertise to any peer (well-known community)\n"
8141 "Do not export to next AS (well-known community)\n"
8142 "community number\n"
8143 "Do not send outside local AS (well-known community)\n"
8144 "Do not advertise to any peer (well-known community)\n"
8145 "Do not export to next AS (well-known community)\n"
8146 "community number\n"
8147 "Do not send outside local AS (well-known community)\n"
8148 "Do not advertise to any peer (well-known community)\n"
8149 "Do not export to next AS (well-known community)\n"
8150 "Exact match of the communities")
8151
8152#ifdef HAVE_IPV6
8153DEFUN (show_bgp_community,
8154 show_bgp_community_cmd,
8155 "show bgp community (AA:NN|local-AS|no-advertise|no-export)",
8156 SHOW_STR
8157 BGP_STR
8158 "Display routes matching the communities\n"
8159 "community number\n"
8160 "Do not send outside local AS (well-known community)\n"
8161 "Do not advertise to any peer (well-known community)\n"
8162 "Do not export to next AS (well-known community)\n")
8163{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008164 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008165}
8166
8167ALIAS (show_bgp_community,
8168 show_bgp_ipv6_community_cmd,
8169 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export)",
8170 SHOW_STR
8171 BGP_STR
8172 "Address family\n"
8173 "Display routes matching the communities\n"
8174 "community number\n"
8175 "Do not send outside local AS (well-known community)\n"
8176 "Do not advertise to any peer (well-known community)\n"
8177 "Do not export to next AS (well-known community)\n")
8178
8179ALIAS (show_bgp_community,
8180 show_bgp_community2_cmd,
8181 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8182 SHOW_STR
8183 BGP_STR
8184 "Display routes matching the communities\n"
8185 "community number\n"
8186 "Do not send outside local AS (well-known community)\n"
8187 "Do not advertise to any peer (well-known community)\n"
8188 "Do not export to next AS (well-known community)\n"
8189 "community number\n"
8190 "Do not send outside local AS (well-known community)\n"
8191 "Do not advertise to any peer (well-known community)\n"
8192 "Do not export to next AS (well-known community)\n")
8193
8194ALIAS (show_bgp_community,
8195 show_bgp_ipv6_community2_cmd,
8196 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8197 SHOW_STR
8198 BGP_STR
8199 "Address family\n"
8200 "Display routes matching the communities\n"
8201 "community number\n"
8202 "Do not send outside local AS (well-known community)\n"
8203 "Do not advertise to any peer (well-known community)\n"
8204 "Do not export to next AS (well-known community)\n"
8205 "community number\n"
8206 "Do not send outside local AS (well-known community)\n"
8207 "Do not advertise to any peer (well-known community)\n"
8208 "Do not export to next AS (well-known community)\n")
8209
8210ALIAS (show_bgp_community,
8211 show_bgp_community3_cmd,
8212 "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)",
8213 SHOW_STR
8214 BGP_STR
8215 "Display routes matching the communities\n"
8216 "community number\n"
8217 "Do not send outside local AS (well-known community)\n"
8218 "Do not advertise to any peer (well-known community)\n"
8219 "Do not export to next AS (well-known community)\n"
8220 "community number\n"
8221 "Do not send outside local AS (well-known community)\n"
8222 "Do not advertise to any peer (well-known community)\n"
8223 "Do not export to next AS (well-known community)\n"
8224 "community number\n"
8225 "Do not send outside local AS (well-known community)\n"
8226 "Do not advertise to any peer (well-known community)\n"
8227 "Do not export to next AS (well-known community)\n")
8228
8229ALIAS (show_bgp_community,
8230 show_bgp_ipv6_community3_cmd,
8231 "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)",
8232 SHOW_STR
8233 BGP_STR
8234 "Address family\n"
8235 "Display routes matching the communities\n"
8236 "community number\n"
8237 "Do not send outside local AS (well-known community)\n"
8238 "Do not advertise to any peer (well-known community)\n"
8239 "Do not export to next AS (well-known community)\n"
8240 "community number\n"
8241 "Do not send outside local AS (well-known community)\n"
8242 "Do not advertise to any peer (well-known community)\n"
8243 "Do not export to next AS (well-known community)\n"
8244 "community number\n"
8245 "Do not send outside local AS (well-known community)\n"
8246 "Do not advertise to any peer (well-known community)\n"
8247 "Do not export to next AS (well-known community)\n")
8248
8249ALIAS (show_bgp_community,
8250 show_bgp_community4_cmd,
8251 "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)",
8252 SHOW_STR
8253 BGP_STR
8254 "Display routes matching the communities\n"
8255 "community number\n"
8256 "Do not send outside local AS (well-known community)\n"
8257 "Do not advertise to any peer (well-known community)\n"
8258 "Do not export to next AS (well-known community)\n"
8259 "community number\n"
8260 "Do not send outside local AS (well-known community)\n"
8261 "Do not advertise to any peer (well-known community)\n"
8262 "Do not export to next AS (well-known community)\n"
8263 "community number\n"
8264 "Do not send outside local AS (well-known community)\n"
8265 "Do not advertise to any peer (well-known community)\n"
8266 "Do not export to next AS (well-known community)\n"
8267 "community number\n"
8268 "Do not send outside local AS (well-known community)\n"
8269 "Do not advertise to any peer (well-known community)\n"
8270 "Do not export to next AS (well-known community)\n")
8271
8272ALIAS (show_bgp_community,
8273 show_bgp_ipv6_community4_cmd,
8274 "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)",
8275 SHOW_STR
8276 BGP_STR
8277 "Address family\n"
8278 "Display routes matching the communities\n"
8279 "community number\n"
8280 "Do not send outside local AS (well-known community)\n"
8281 "Do not advertise to any peer (well-known community)\n"
8282 "Do not export to next AS (well-known community)\n"
8283 "community number\n"
8284 "Do not send outside local AS (well-known community)\n"
8285 "Do not advertise to any peer (well-known community)\n"
8286 "Do not export to next AS (well-known community)\n"
8287 "community number\n"
8288 "Do not send outside local AS (well-known community)\n"
8289 "Do not advertise to any peer (well-known community)\n"
8290 "Do not export to next AS (well-known community)\n"
8291 "community number\n"
8292 "Do not send outside local AS (well-known community)\n"
8293 "Do not advertise to any peer (well-known community)\n"
8294 "Do not export to next AS (well-known community)\n")
8295
8296/* old command */
8297DEFUN (show_ipv6_bgp_community,
8298 show_ipv6_bgp_community_cmd,
8299 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export)",
8300 SHOW_STR
8301 IPV6_STR
8302 BGP_STR
8303 "Display routes matching the communities\n"
8304 "community number\n"
8305 "Do not send outside local AS (well-known community)\n"
8306 "Do not advertise to any peer (well-known community)\n"
8307 "Do not export to next AS (well-known community)\n")
8308{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008309 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008310}
8311
8312/* old command */
8313ALIAS (show_ipv6_bgp_community,
8314 show_ipv6_bgp_community2_cmd,
8315 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8316 SHOW_STR
8317 IPV6_STR
8318 BGP_STR
8319 "Display routes matching the communities\n"
8320 "community number\n"
8321 "Do not send outside local AS (well-known community)\n"
8322 "Do not advertise to any peer (well-known community)\n"
8323 "Do not export to next AS (well-known community)\n"
8324 "community number\n"
8325 "Do not send outside local AS (well-known community)\n"
8326 "Do not advertise to any peer (well-known community)\n"
8327 "Do not export to next AS (well-known community)\n")
8328
8329/* old command */
8330ALIAS (show_ipv6_bgp_community,
8331 show_ipv6_bgp_community3_cmd,
8332 "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)",
8333 SHOW_STR
8334 IPV6_STR
8335 BGP_STR
8336 "Display routes matching the communities\n"
8337 "community number\n"
8338 "Do not send outside local AS (well-known community)\n"
8339 "Do not advertise to any peer (well-known community)\n"
8340 "Do not export to next AS (well-known community)\n"
8341 "community number\n"
8342 "Do not send outside local AS (well-known community)\n"
8343 "Do not advertise to any peer (well-known community)\n"
8344 "Do not export to next AS (well-known community)\n"
8345 "community number\n"
8346 "Do not send outside local AS (well-known community)\n"
8347 "Do not advertise to any peer (well-known community)\n"
8348 "Do not export to next AS (well-known community)\n")
8349
8350/* old command */
8351ALIAS (show_ipv6_bgp_community,
8352 show_ipv6_bgp_community4_cmd,
8353 "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)",
8354 SHOW_STR
8355 IPV6_STR
8356 BGP_STR
8357 "Display routes matching the communities\n"
8358 "community number\n"
8359 "Do not send outside local AS (well-known community)\n"
8360 "Do not advertise to any peer (well-known community)\n"
8361 "Do not export to next AS (well-known community)\n"
8362 "community number\n"
8363 "Do not send outside local AS (well-known community)\n"
8364 "Do not advertise to any peer (well-known community)\n"
8365 "Do not export to next AS (well-known community)\n"
8366 "community number\n"
8367 "Do not send outside local AS (well-known community)\n"
8368 "Do not advertise to any peer (well-known community)\n"
8369 "Do not export to next AS (well-known community)\n"
8370 "community number\n"
8371 "Do not send outside local AS (well-known community)\n"
8372 "Do not advertise to any peer (well-known community)\n"
8373 "Do not export to next AS (well-known community)\n")
8374
8375DEFUN (show_bgp_community_exact,
8376 show_bgp_community_exact_cmd,
8377 "show bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8378 SHOW_STR
8379 BGP_STR
8380 "Display routes matching the communities\n"
8381 "community number\n"
8382 "Do not send outside local AS (well-known community)\n"
8383 "Do not advertise to any peer (well-known community)\n"
8384 "Do not export to next AS (well-known community)\n"
8385 "Exact match of the communities")
8386{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008387 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008388}
8389
8390ALIAS (show_bgp_community_exact,
8391 show_bgp_ipv6_community_exact_cmd,
8392 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8393 SHOW_STR
8394 BGP_STR
8395 "Address family\n"
8396 "Display routes matching the communities\n"
8397 "community number\n"
8398 "Do not send outside local AS (well-known community)\n"
8399 "Do not advertise to any peer (well-known community)\n"
8400 "Do not export to next AS (well-known community)\n"
8401 "Exact match of the communities")
8402
8403ALIAS (show_bgp_community_exact,
8404 show_bgp_community2_exact_cmd,
8405 "show bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8406 SHOW_STR
8407 BGP_STR
8408 "Display routes matching the communities\n"
8409 "community number\n"
8410 "Do not send outside local AS (well-known community)\n"
8411 "Do not advertise to any peer (well-known community)\n"
8412 "Do not export to next AS (well-known community)\n"
8413 "community number\n"
8414 "Do not send outside local AS (well-known community)\n"
8415 "Do not advertise to any peer (well-known community)\n"
8416 "Do not export to next AS (well-known community)\n"
8417 "Exact match of the communities")
8418
8419ALIAS (show_bgp_community_exact,
8420 show_bgp_ipv6_community2_exact_cmd,
8421 "show bgp ipv6 community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8422 SHOW_STR
8423 BGP_STR
8424 "Address family\n"
8425 "Display routes matching the communities\n"
8426 "community number\n"
8427 "Do not send outside local AS (well-known community)\n"
8428 "Do not advertise to any peer (well-known community)\n"
8429 "Do not export to next AS (well-known community)\n"
8430 "community number\n"
8431 "Do not send outside local AS (well-known community)\n"
8432 "Do not advertise to any peer (well-known community)\n"
8433 "Do not export to next AS (well-known community)\n"
8434 "Exact match of the communities")
8435
8436ALIAS (show_bgp_community_exact,
8437 show_bgp_community3_exact_cmd,
8438 "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",
8439 SHOW_STR
8440 BGP_STR
8441 "Display routes matching the communities\n"
8442 "community number\n"
8443 "Do not send outside local AS (well-known community)\n"
8444 "Do not advertise to any peer (well-known community)\n"
8445 "Do not export to next AS (well-known community)\n"
8446 "community number\n"
8447 "Do not send outside local AS (well-known community)\n"
8448 "Do not advertise to any peer (well-known community)\n"
8449 "Do not export to next AS (well-known community)\n"
8450 "community number\n"
8451 "Do not send outside local AS (well-known community)\n"
8452 "Do not advertise to any peer (well-known community)\n"
8453 "Do not export to next AS (well-known community)\n"
8454 "Exact match of the communities")
8455
8456ALIAS (show_bgp_community_exact,
8457 show_bgp_ipv6_community3_exact_cmd,
8458 "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",
8459 SHOW_STR
8460 BGP_STR
8461 "Address family\n"
8462 "Display routes matching the communities\n"
8463 "community number\n"
8464 "Do not send outside local AS (well-known community)\n"
8465 "Do not advertise to any peer (well-known community)\n"
8466 "Do not export to next AS (well-known community)\n"
8467 "community number\n"
8468 "Do not send outside local AS (well-known community)\n"
8469 "Do not advertise to any peer (well-known community)\n"
8470 "Do not export to next AS (well-known community)\n"
8471 "community number\n"
8472 "Do not send outside local AS (well-known community)\n"
8473 "Do not advertise to any peer (well-known community)\n"
8474 "Do not export to next AS (well-known community)\n"
8475 "Exact match of the communities")
8476
8477ALIAS (show_bgp_community_exact,
8478 show_bgp_community4_exact_cmd,
8479 "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",
8480 SHOW_STR
8481 BGP_STR
8482 "Display routes matching the communities\n"
8483 "community number\n"
8484 "Do not send outside local AS (well-known community)\n"
8485 "Do not advertise to any peer (well-known community)\n"
8486 "Do not export to next AS (well-known community)\n"
8487 "community number\n"
8488 "Do not send outside local AS (well-known community)\n"
8489 "Do not advertise to any peer (well-known community)\n"
8490 "Do not export to next AS (well-known community)\n"
8491 "community number\n"
8492 "Do not send outside local AS (well-known community)\n"
8493 "Do not advertise to any peer (well-known community)\n"
8494 "Do not export to next AS (well-known community)\n"
8495 "community number\n"
8496 "Do not send outside local AS (well-known community)\n"
8497 "Do not advertise to any peer (well-known community)\n"
8498 "Do not export to next AS (well-known community)\n"
8499 "Exact match of the communities")
8500
8501ALIAS (show_bgp_community_exact,
8502 show_bgp_ipv6_community4_exact_cmd,
8503 "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",
8504 SHOW_STR
8505 BGP_STR
8506 "Address family\n"
8507 "Display routes matching the communities\n"
8508 "community number\n"
8509 "Do not send outside local AS (well-known community)\n"
8510 "Do not advertise to any peer (well-known community)\n"
8511 "Do not export to next AS (well-known community)\n"
8512 "community number\n"
8513 "Do not send outside local AS (well-known community)\n"
8514 "Do not advertise to any peer (well-known community)\n"
8515 "Do not export to next AS (well-known community)\n"
8516 "community number\n"
8517 "Do not send outside local AS (well-known community)\n"
8518 "Do not advertise to any peer (well-known community)\n"
8519 "Do not export to next AS (well-known community)\n"
8520 "community number\n"
8521 "Do not send outside local AS (well-known community)\n"
8522 "Do not advertise to any peer (well-known community)\n"
8523 "Do not export to next AS (well-known community)\n"
8524 "Exact match of the communities")
8525
8526/* old command */
8527DEFUN (show_ipv6_bgp_community_exact,
8528 show_ipv6_bgp_community_exact_cmd,
8529 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8530 SHOW_STR
8531 IPV6_STR
8532 BGP_STR
8533 "Display routes matching the communities\n"
8534 "community number\n"
8535 "Do not send outside local AS (well-known community)\n"
8536 "Do not advertise to any peer (well-known community)\n"
8537 "Do not export to next AS (well-known community)\n"
8538 "Exact match of the communities")
8539{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008540 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +00008541}
8542
8543/* old command */
8544ALIAS (show_ipv6_bgp_community_exact,
8545 show_ipv6_bgp_community2_exact_cmd,
8546 "show ipv6 bgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8547 SHOW_STR
8548 IPV6_STR
8549 BGP_STR
8550 "Display routes matching the communities\n"
8551 "community number\n"
8552 "Do not send outside local AS (well-known community)\n"
8553 "Do not advertise to any peer (well-known community)\n"
8554 "Do not export to next AS (well-known community)\n"
8555 "community number\n"
8556 "Do not send outside local AS (well-known community)\n"
8557 "Do not advertise to any peer (well-known community)\n"
8558 "Do not export to next AS (well-known community)\n"
8559 "Exact match of the communities")
8560
8561/* old command */
8562ALIAS (show_ipv6_bgp_community_exact,
8563 show_ipv6_bgp_community3_exact_cmd,
8564 "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",
8565 SHOW_STR
8566 IPV6_STR
8567 BGP_STR
8568 "Display routes matching the communities\n"
8569 "community number\n"
8570 "Do not send outside local AS (well-known community)\n"
8571 "Do not advertise to any peer (well-known community)\n"
8572 "Do not export to next AS (well-known community)\n"
8573 "community number\n"
8574 "Do not send outside local AS (well-known community)\n"
8575 "Do not advertise to any peer (well-known community)\n"
8576 "Do not export to next AS (well-known community)\n"
8577 "community number\n"
8578 "Do not send outside local AS (well-known community)\n"
8579 "Do not advertise to any peer (well-known community)\n"
8580 "Do not export to next AS (well-known community)\n"
8581 "Exact match of the communities")
8582
8583/* old command */
8584ALIAS (show_ipv6_bgp_community_exact,
8585 show_ipv6_bgp_community4_exact_cmd,
8586 "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",
8587 SHOW_STR
8588 IPV6_STR
8589 BGP_STR
8590 "Display routes matching the communities\n"
8591 "community number\n"
8592 "Do not send outside local AS (well-known community)\n"
8593 "Do not advertise to any peer (well-known community)\n"
8594 "Do not export to next AS (well-known community)\n"
8595 "community number\n"
8596 "Do not send outside local AS (well-known community)\n"
8597 "Do not advertise to any peer (well-known community)\n"
8598 "Do not export to next AS (well-known community)\n"
8599 "community number\n"
8600 "Do not send outside local AS (well-known community)\n"
8601 "Do not advertise to any peer (well-known community)\n"
8602 "Do not export to next AS (well-known community)\n"
8603 "community number\n"
8604 "Do not send outside local AS (well-known community)\n"
8605 "Do not advertise to any peer (well-known community)\n"
8606 "Do not export to next AS (well-known community)\n"
8607 "Exact match of the communities")
8608
8609/* old command */
8610DEFUN (show_ipv6_mbgp_community,
8611 show_ipv6_mbgp_community_cmd,
8612 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export)",
8613 SHOW_STR
8614 IPV6_STR
8615 MBGP_STR
8616 "Display routes matching the communities\n"
8617 "community number\n"
8618 "Do not send outside local AS (well-known community)\n"
8619 "Do not advertise to any peer (well-known community)\n"
8620 "Do not export to next AS (well-known community)\n")
8621{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008622 return bgp_show_community (vty, NULL, argc, argv, 0, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008623}
8624
8625/* old command */
8626ALIAS (show_ipv6_mbgp_community,
8627 show_ipv6_mbgp_community2_cmd,
8628 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export)",
8629 SHOW_STR
8630 IPV6_STR
8631 MBGP_STR
8632 "Display routes matching the communities\n"
8633 "community number\n"
8634 "Do not send outside local AS (well-known community)\n"
8635 "Do not advertise to any peer (well-known community)\n"
8636 "Do not export to next AS (well-known community)\n"
8637 "community number\n"
8638 "Do not send outside local AS (well-known community)\n"
8639 "Do not advertise to any peer (well-known community)\n"
8640 "Do not export to next AS (well-known community)\n")
8641
8642/* old command */
8643ALIAS (show_ipv6_mbgp_community,
8644 show_ipv6_mbgp_community3_cmd,
8645 "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)",
8646 SHOW_STR
8647 IPV6_STR
8648 MBGP_STR
8649 "Display routes matching the communities\n"
8650 "community number\n"
8651 "Do not send outside local AS (well-known community)\n"
8652 "Do not advertise to any peer (well-known community)\n"
8653 "Do not export to next AS (well-known community)\n"
8654 "community number\n"
8655 "Do not send outside local AS (well-known community)\n"
8656 "Do not advertise to any peer (well-known community)\n"
8657 "Do not export to next AS (well-known community)\n"
8658 "community number\n"
8659 "Do not send outside local AS (well-known community)\n"
8660 "Do not advertise to any peer (well-known community)\n"
8661 "Do not export to next AS (well-known community)\n")
8662
8663/* old command */
8664ALIAS (show_ipv6_mbgp_community,
8665 show_ipv6_mbgp_community4_cmd,
8666 "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)",
8667 SHOW_STR
8668 IPV6_STR
8669 MBGP_STR
8670 "Display routes matching the communities\n"
8671 "community number\n"
8672 "Do not send outside local AS (well-known community)\n"
8673 "Do not advertise to any peer (well-known community)\n"
8674 "Do not export to next AS (well-known community)\n"
8675 "community number\n"
8676 "Do not send outside local AS (well-known community)\n"
8677 "Do not advertise to any peer (well-known community)\n"
8678 "Do not export to next AS (well-known community)\n"
8679 "community number\n"
8680 "Do not send outside local AS (well-known community)\n"
8681 "Do not advertise to any peer (well-known community)\n"
8682 "Do not export to next AS (well-known community)\n"
8683 "community number\n"
8684 "Do not send outside local AS (well-known community)\n"
8685 "Do not advertise to any peer (well-known community)\n"
8686 "Do not export to next AS (well-known community)\n")
8687
8688/* old command */
8689DEFUN (show_ipv6_mbgp_community_exact,
8690 show_ipv6_mbgp_community_exact_cmd,
8691 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) exact-match",
8692 SHOW_STR
8693 IPV6_STR
8694 MBGP_STR
8695 "Display routes matching the communities\n"
8696 "community number\n"
8697 "Do not send outside local AS (well-known community)\n"
8698 "Do not advertise to any peer (well-known community)\n"
8699 "Do not export to next AS (well-known community)\n"
8700 "Exact match of the communities")
8701{
Michael Lambert95cbbd22010-07-23 14:43:04 -04008702 return bgp_show_community (vty, NULL, argc, argv, 1, AFI_IP6, SAFI_MULTICAST);
paul718e3742002-12-13 20:15:29 +00008703}
8704
8705/* old command */
8706ALIAS (show_ipv6_mbgp_community_exact,
8707 show_ipv6_mbgp_community2_exact_cmd,
8708 "show ipv6 mbgp community (AA:NN|local-AS|no-advertise|no-export) (AA:NN|local-AS|no-advertise|no-export) exact-match",
8709 SHOW_STR
8710 IPV6_STR
8711 MBGP_STR
8712 "Display routes matching the communities\n"
8713 "community number\n"
8714 "Do not send outside local AS (well-known community)\n"
8715 "Do not advertise to any peer (well-known community)\n"
8716 "Do not export to next AS (well-known community)\n"
8717 "community number\n"
8718 "Do not send outside local AS (well-known community)\n"
8719 "Do not advertise to any peer (well-known community)\n"
8720 "Do not export to next AS (well-known community)\n"
8721 "Exact match of the communities")
8722
8723/* old command */
8724ALIAS (show_ipv6_mbgp_community_exact,
8725 show_ipv6_mbgp_community3_exact_cmd,
8726 "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",
8727 SHOW_STR
8728 IPV6_STR
8729 MBGP_STR
8730 "Display routes matching the communities\n"
8731 "community number\n"
8732 "Do not send outside local AS (well-known community)\n"
8733 "Do not advertise to any peer (well-known community)\n"
8734 "Do not export to next AS (well-known community)\n"
8735 "community number\n"
8736 "Do not send outside local AS (well-known community)\n"
8737 "Do not advertise to any peer (well-known community)\n"
8738 "Do not export to next AS (well-known community)\n"
8739 "community number\n"
8740 "Do not send outside local AS (well-known community)\n"
8741 "Do not advertise to any peer (well-known community)\n"
8742 "Do not export to next AS (well-known community)\n"
8743 "Exact match of the communities")
8744
8745/* old command */
8746ALIAS (show_ipv6_mbgp_community_exact,
8747 show_ipv6_mbgp_community4_exact_cmd,
8748 "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",
8749 SHOW_STR
8750 IPV6_STR
8751 MBGP_STR
8752 "Display routes matching the communities\n"
8753 "community number\n"
8754 "Do not send outside local AS (well-known community)\n"
8755 "Do not advertise to any peer (well-known community)\n"
8756 "Do not export to next AS (well-known community)\n"
8757 "community number\n"
8758 "Do not send outside local AS (well-known community)\n"
8759 "Do not advertise to any peer (well-known community)\n"
8760 "Do not export to next AS (well-known community)\n"
8761 "community number\n"
8762 "Do not send outside local AS (well-known community)\n"
8763 "Do not advertise to any peer (well-known community)\n"
8764 "Do not export to next AS (well-known community)\n"
8765 "community number\n"
8766 "Do not send outside local AS (well-known community)\n"
8767 "Do not advertise to any peer (well-known community)\n"
8768 "Do not export to next AS (well-known community)\n"
8769 "Exact match of the communities")
8770#endif /* HAVE_IPV6 */
8771
paul94f2b392005-06-28 12:44:16 +00008772static int
paulfd79ac92004-10-13 05:06:08 +00008773bgp_show_community_list (struct vty *vty, const char *com, int exact,
Michael Lambert4c9641b2010-07-22 13:20:55 -04008774 afi_t afi, safi_t safi)
paul718e3742002-12-13 20:15:29 +00008775{
8776 struct community_list *list;
8777
hassofee6e4e2005-02-02 16:29:31 +00008778 list = community_list_lookup (bgp_clist, com, COMMUNITY_LIST_MASTER);
paul718e3742002-12-13 20:15:29 +00008779 if (list == NULL)
8780 {
8781 vty_out (vty, "%% %s is not a valid community-list name%s", com,
8782 VTY_NEWLINE);
8783 return CMD_WARNING;
8784 }
8785
ajs5a646652004-11-05 01:25:55 +00008786 return bgp_show (vty, NULL, afi, safi,
8787 (exact ? bgp_show_type_community_list_exact :
8788 bgp_show_type_community_list), list);
paul718e3742002-12-13 20:15:29 +00008789}
8790
8791DEFUN (show_ip_bgp_community_list,
8792 show_ip_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008793 "show ip bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008794 SHOW_STR
8795 IP_STR
8796 BGP_STR
8797 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008798 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008799 "community-list name\n")
8800{
8801 return bgp_show_community_list (vty, argv[0], 0, AFI_IP, SAFI_UNICAST);
8802}
8803
8804DEFUN (show_ip_bgp_ipv4_community_list,
8805 show_ip_bgp_ipv4_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008806 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008807 SHOW_STR
8808 IP_STR
8809 BGP_STR
8810 "Address family\n"
8811 "Address Family modifier\n"
8812 "Address Family modifier\n"
8813 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008814 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008815 "community-list name\n")
8816{
8817 if (strncmp (argv[0], "m", 1) == 0)
8818 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_MULTICAST);
8819
8820 return bgp_show_community_list (vty, argv[1], 0, AFI_IP, SAFI_UNICAST);
8821}
8822
8823DEFUN (show_ip_bgp_community_list_exact,
8824 show_ip_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008825 "show ip bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008826 SHOW_STR
8827 IP_STR
8828 BGP_STR
8829 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008830 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008831 "community-list name\n"
8832 "Exact match of the communities\n")
8833{
8834 return bgp_show_community_list (vty, argv[0], 1, AFI_IP, SAFI_UNICAST);
8835}
8836
8837DEFUN (show_ip_bgp_ipv4_community_list_exact,
8838 show_ip_bgp_ipv4_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008839 "show ip bgp ipv4 (unicast|multicast) community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008840 SHOW_STR
8841 IP_STR
8842 BGP_STR
8843 "Address family\n"
8844 "Address Family modifier\n"
8845 "Address Family modifier\n"
8846 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008847 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008848 "community-list name\n"
8849 "Exact match of the communities\n")
8850{
8851 if (strncmp (argv[0], "m", 1) == 0)
8852 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_MULTICAST);
8853
8854 return bgp_show_community_list (vty, argv[1], 1, AFI_IP, SAFI_UNICAST);
8855}
8856
8857#ifdef HAVE_IPV6
8858DEFUN (show_bgp_community_list,
8859 show_bgp_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008860 "show bgp community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008861 SHOW_STR
8862 BGP_STR
8863 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008864 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008865 "community-list name\n")
8866{
8867 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8868}
8869
8870ALIAS (show_bgp_community_list,
8871 show_bgp_ipv6_community_list_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008872 "show bgp ipv6 community-list (<1-500>|WORD)",
paul718e3742002-12-13 20:15:29 +00008873 SHOW_STR
8874 BGP_STR
8875 "Address family\n"
8876 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008877 "community-list number\n"
paule8e19462006-01-19 20:16:55 +00008878 "community-list name\n")
paul718e3742002-12-13 20:15:29 +00008879
8880/* old command */
8881DEFUN (show_ipv6_bgp_community_list,
8882 show_ipv6_bgp_community_list_cmd,
8883 "show ipv6 bgp community-list WORD",
8884 SHOW_STR
8885 IPV6_STR
8886 BGP_STR
8887 "Display routes matching the community-list\n"
8888 "community-list name\n")
8889{
8890 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_UNICAST);
8891}
8892
8893/* old command */
8894DEFUN (show_ipv6_mbgp_community_list,
8895 show_ipv6_mbgp_community_list_cmd,
8896 "show ipv6 mbgp community-list WORD",
8897 SHOW_STR
8898 IPV6_STR
8899 MBGP_STR
8900 "Display routes matching the community-list\n"
8901 "community-list name\n")
8902{
8903 return bgp_show_community_list (vty, argv[0], 0, AFI_IP6, SAFI_MULTICAST);
8904}
8905
8906DEFUN (show_bgp_community_list_exact,
8907 show_bgp_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008908 "show bgp community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008909 SHOW_STR
8910 BGP_STR
8911 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008912 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008913 "community-list name\n"
8914 "Exact match of the communities\n")
8915{
8916 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8917}
8918
8919ALIAS (show_bgp_community_list_exact,
8920 show_bgp_ipv6_community_list_exact_cmd,
hassofee6e4e2005-02-02 16:29:31 +00008921 "show bgp ipv6 community-list (<1-500>|WORD) exact-match",
paul718e3742002-12-13 20:15:29 +00008922 SHOW_STR
8923 BGP_STR
8924 "Address family\n"
8925 "Display routes matching the community-list\n"
hassofee6e4e2005-02-02 16:29:31 +00008926 "community-list number\n"
paul718e3742002-12-13 20:15:29 +00008927 "community-list name\n"
8928 "Exact match of the communities\n")
8929
8930/* old command */
8931DEFUN (show_ipv6_bgp_community_list_exact,
8932 show_ipv6_bgp_community_list_exact_cmd,
8933 "show ipv6 bgp community-list WORD exact-match",
8934 SHOW_STR
8935 IPV6_STR
8936 BGP_STR
8937 "Display routes matching the community-list\n"
8938 "community-list name\n"
8939 "Exact match of the communities\n")
8940{
8941 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_UNICAST);
8942}
8943
8944/* old command */
8945DEFUN (show_ipv6_mbgp_community_list_exact,
8946 show_ipv6_mbgp_community_list_exact_cmd,
8947 "show ipv6 mbgp community-list WORD exact-match",
8948 SHOW_STR
8949 IPV6_STR
8950 MBGP_STR
8951 "Display routes matching the community-list\n"
8952 "community-list name\n"
8953 "Exact match of the communities\n")
8954{
8955 return bgp_show_community_list (vty, argv[0], 1, AFI_IP6, SAFI_MULTICAST);
8956}
8957#endif /* HAVE_IPV6 */
8958
paul94f2b392005-06-28 12:44:16 +00008959static int
paulfd79ac92004-10-13 05:06:08 +00008960bgp_show_prefix_longer (struct vty *vty, const char *prefix, afi_t afi,
paul718e3742002-12-13 20:15:29 +00008961 safi_t safi, enum bgp_show_type type)
8962{
8963 int ret;
8964 struct prefix *p;
8965
8966 p = prefix_new();
8967
8968 ret = str2prefix (prefix, p);
8969 if (! ret)
8970 {
8971 vty_out (vty, "%% Malformed Prefix%s", VTY_NEWLINE);
8972 return CMD_WARNING;
8973 }
8974
ajs5a646652004-11-05 01:25:55 +00008975 ret = bgp_show (vty, NULL, afi, safi, type, p);
8976 prefix_free(p);
8977 return ret;
paul718e3742002-12-13 20:15:29 +00008978}
8979
8980DEFUN (show_ip_bgp_prefix_longer,
8981 show_ip_bgp_prefix_longer_cmd,
8982 "show ip bgp A.B.C.D/M longer-prefixes",
8983 SHOW_STR
8984 IP_STR
8985 BGP_STR
8986 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
8987 "Display route and more specific routes\n")
8988{
8989 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
8990 bgp_show_type_prefix_longer);
8991}
8992
8993DEFUN (show_ip_bgp_flap_prefix_longer,
8994 show_ip_bgp_flap_prefix_longer_cmd,
8995 "show ip bgp flap-statistics A.B.C.D/M longer-prefixes",
8996 SHOW_STR
8997 IP_STR
8998 BGP_STR
8999 "Display flap statistics of routes\n"
9000 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9001 "Display route and more specific routes\n")
9002{
9003 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9004 bgp_show_type_flap_prefix_longer);
9005}
9006
9007DEFUN (show_ip_bgp_ipv4_prefix_longer,
9008 show_ip_bgp_ipv4_prefix_longer_cmd,
9009 "show ip bgp ipv4 (unicast|multicast) A.B.C.D/M longer-prefixes",
9010 SHOW_STR
9011 IP_STR
9012 BGP_STR
9013 "Address family\n"
9014 "Address Family modifier\n"
9015 "Address Family modifier\n"
9016 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n"
9017 "Display route and more specific routes\n")
9018{
9019 if (strncmp (argv[0], "m", 1) == 0)
9020 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_MULTICAST,
9021 bgp_show_type_prefix_longer);
9022
9023 return bgp_show_prefix_longer (vty, argv[1], AFI_IP, SAFI_UNICAST,
9024 bgp_show_type_prefix_longer);
9025}
9026
9027DEFUN (show_ip_bgp_flap_address,
9028 show_ip_bgp_flap_address_cmd,
9029 "show ip bgp flap-statistics A.B.C.D",
9030 SHOW_STR
9031 IP_STR
9032 BGP_STR
9033 "Display flap statistics of routes\n"
9034 "Network in the BGP routing table to display\n")
9035{
9036 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9037 bgp_show_type_flap_address);
9038}
9039
9040DEFUN (show_ip_bgp_flap_prefix,
9041 show_ip_bgp_flap_prefix_cmd,
9042 "show ip bgp flap-statistics A.B.C.D/M",
9043 SHOW_STR
9044 IP_STR
9045 BGP_STR
9046 "Display flap statistics of routes\n"
9047 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
9048{
9049 return bgp_show_prefix_longer (vty, argv[0], AFI_IP, SAFI_UNICAST,
9050 bgp_show_type_flap_prefix);
9051}
9052#ifdef HAVE_IPV6
9053DEFUN (show_bgp_prefix_longer,
9054 show_bgp_prefix_longer_cmd,
9055 "show bgp X:X::X:X/M longer-prefixes",
9056 SHOW_STR
9057 BGP_STR
9058 "IPv6 prefix <network>/<length>\n"
9059 "Display route and more specific routes\n")
9060{
9061 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9062 bgp_show_type_prefix_longer);
9063}
9064
9065ALIAS (show_bgp_prefix_longer,
9066 show_bgp_ipv6_prefix_longer_cmd,
9067 "show bgp ipv6 X:X::X:X/M longer-prefixes",
9068 SHOW_STR
9069 BGP_STR
9070 "Address family\n"
9071 "IPv6 prefix <network>/<length>\n"
9072 "Display route and more specific routes\n")
9073
9074/* old command */
9075DEFUN (show_ipv6_bgp_prefix_longer,
9076 show_ipv6_bgp_prefix_longer_cmd,
9077 "show ipv6 bgp X:X::X:X/M longer-prefixes",
9078 SHOW_STR
9079 IPV6_STR
9080 BGP_STR
9081 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9082 "Display route and more specific routes\n")
9083{
9084 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_UNICAST,
9085 bgp_show_type_prefix_longer);
9086}
9087
9088/* old command */
9089DEFUN (show_ipv6_mbgp_prefix_longer,
9090 show_ipv6_mbgp_prefix_longer_cmd,
9091 "show ipv6 mbgp X:X::X:X/M longer-prefixes",
9092 SHOW_STR
9093 IPV6_STR
9094 MBGP_STR
9095 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n"
9096 "Display route and more specific routes\n")
9097{
9098 return bgp_show_prefix_longer (vty, argv[0], AFI_IP6, SAFI_MULTICAST,
9099 bgp_show_type_prefix_longer);
9100}
9101#endif /* HAVE_IPV6 */
paulbb46e942003-10-24 19:02:03 +00009102
paul94f2b392005-06-28 12:44:16 +00009103static struct peer *
paulfd79ac92004-10-13 05:06:08 +00009104peer_lookup_in_view (struct vty *vty, const char *view_name,
9105 const char *ip_str)
paulbb46e942003-10-24 19:02:03 +00009106{
9107 int ret;
9108 struct bgp *bgp;
9109 struct peer *peer;
9110 union sockunion su;
9111
9112 /* BGP structure lookup. */
9113 if (view_name)
9114 {
9115 bgp = bgp_lookup_by_name (view_name);
9116 if (! bgp)
9117 {
9118 vty_out (vty, "Can't find BGP view %s%s", view_name, VTY_NEWLINE);
9119 return NULL;
9120 }
9121 }
paul5228ad22004-06-04 17:58:18 +00009122 else
paulbb46e942003-10-24 19:02:03 +00009123 {
9124 bgp = bgp_get_default ();
9125 if (! bgp)
9126 {
9127 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
9128 return NULL;
9129 }
9130 }
9131
9132 /* Get peer sockunion. */
9133 ret = str2sockunion (ip_str, &su);
9134 if (ret < 0)
9135 {
9136 vty_out (vty, "Malformed address: %s%s", ip_str, VTY_NEWLINE);
9137 return NULL;
9138 }
9139
9140 /* Peer structure lookup. */
9141 peer = peer_lookup (bgp, &su);
9142 if (! peer)
9143 {
9144 vty_out (vty, "No such neighbor%s", VTY_NEWLINE);
9145 return NULL;
9146 }
9147
9148 return peer;
9149}
Paul Jakma2815e612006-09-14 02:56:07 +00009150
9151enum bgp_stats
9152{
9153 BGP_STATS_MAXBITLEN = 0,
9154 BGP_STATS_RIB,
9155 BGP_STATS_PREFIXES,
9156 BGP_STATS_TOTPLEN,
9157 BGP_STATS_UNAGGREGATEABLE,
9158 BGP_STATS_MAX_AGGREGATEABLE,
9159 BGP_STATS_AGGREGATES,
9160 BGP_STATS_SPACE,
9161 BGP_STATS_ASPATH_COUNT,
9162 BGP_STATS_ASPATH_MAXHOPS,
9163 BGP_STATS_ASPATH_TOTHOPS,
9164 BGP_STATS_ASPATH_MAXSIZE,
9165 BGP_STATS_ASPATH_TOTSIZE,
9166 BGP_STATS_ASN_HIGHEST,
9167 BGP_STATS_MAX,
9168};
paulbb46e942003-10-24 19:02:03 +00009169
Paul Jakma2815e612006-09-14 02:56:07 +00009170static const char *table_stats_strs[] =
9171{
9172 [BGP_STATS_PREFIXES] = "Total Prefixes",
9173 [BGP_STATS_TOTPLEN] = "Average prefix length",
9174 [BGP_STATS_RIB] = "Total Advertisements",
9175 [BGP_STATS_UNAGGREGATEABLE] = "Unaggregateable prefixes",
9176 [BGP_STATS_MAX_AGGREGATEABLE] = "Maximum aggregateable prefixes",
9177 [BGP_STATS_AGGREGATES] = "BGP Aggregate advertisements",
9178 [BGP_STATS_SPACE] = "Address space advertised",
9179 [BGP_STATS_ASPATH_COUNT] = "Advertisements with paths",
9180 [BGP_STATS_ASPATH_MAXHOPS] = "Longest AS-Path (hops)",
9181 [BGP_STATS_ASPATH_MAXSIZE] = "Largest AS-Path (bytes)",
9182 [BGP_STATS_ASPATH_TOTHOPS] = "Average AS-Path length (hops)",
9183 [BGP_STATS_ASPATH_TOTSIZE] = "Average AS-Path size (bytes)",
9184 [BGP_STATS_ASN_HIGHEST] = "Highest public ASN",
9185 [BGP_STATS_MAX] = NULL,
9186};
9187
9188struct bgp_table_stats
9189{
9190 struct bgp_table *table;
9191 unsigned long long counts[BGP_STATS_MAX];
9192};
9193
9194#if 0
9195#define TALLY_SIGFIG 100000
9196static unsigned long
9197ravg_tally (unsigned long count, unsigned long oldavg, unsigned long newval)
9198{
9199 unsigned long newtot = (count-1) * oldavg + (newval * TALLY_SIGFIG);
9200 unsigned long res = (newtot * TALLY_SIGFIG) / count;
9201 unsigned long ret = newtot / count;
9202
9203 if ((res % TALLY_SIGFIG) > (TALLY_SIGFIG/2))
9204 return ret + 1;
9205 else
9206 return ret;
9207}
9208#endif
9209
9210static int
9211bgp_table_stats_walker (struct thread *t)
9212{
9213 struct bgp_node *rn;
9214 struct bgp_node *top;
9215 struct bgp_table_stats *ts = THREAD_ARG (t);
9216 unsigned int space = 0;
9217
Paul Jakma53d9f672006-10-15 23:41:16 +00009218 if (!(top = bgp_table_top (ts->table)))
9219 return 0;
Paul Jakma2815e612006-09-14 02:56:07 +00009220
9221 switch (top->p.family)
9222 {
9223 case AF_INET:
9224 space = IPV4_MAX_BITLEN;
9225 break;
9226 case AF_INET6:
9227 space = IPV6_MAX_BITLEN;
9228 break;
9229 }
9230
9231 ts->counts[BGP_STATS_MAXBITLEN] = space;
9232
9233 for (rn = top; rn; rn = bgp_route_next (rn))
9234 {
9235 struct bgp_info *ri;
9236 struct bgp_node *prn = rn->parent;
9237 unsigned int rinum = 0;
9238
9239 if (rn == top)
9240 continue;
9241
9242 if (!rn->info)
9243 continue;
9244
9245 ts->counts[BGP_STATS_PREFIXES]++;
9246 ts->counts[BGP_STATS_TOTPLEN] += rn->p.prefixlen;
9247
9248#if 0
9249 ts->counts[BGP_STATS_AVGPLEN]
9250 = ravg_tally (ts->counts[BGP_STATS_PREFIXES],
9251 ts->counts[BGP_STATS_AVGPLEN],
9252 rn->p.prefixlen);
9253#endif
9254
9255 /* check if the prefix is included by any other announcements */
9256 while (prn && !prn->info)
9257 prn = prn->parent;
9258
9259 if (prn == NULL || prn == top)
Paul Jakma8383a9b2006-09-14 03:06:54 +00009260 {
9261 ts->counts[BGP_STATS_UNAGGREGATEABLE]++;
9262 /* announced address space */
9263 if (space)
9264 ts->counts[BGP_STATS_SPACE] += 1 << (space - rn->p.prefixlen);
9265 }
Paul Jakma2815e612006-09-14 02:56:07 +00009266 else if (prn->info)
9267 ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++;
9268
Paul Jakma2815e612006-09-14 02:56:07 +00009269 for (ri = rn->info; ri; ri = ri->next)
9270 {
9271 rinum++;
9272 ts->counts[BGP_STATS_RIB]++;
9273
9274 if (ri->attr &&
9275 (CHECK_FLAG (ri->attr->flag,
9276 ATTR_FLAG_BIT (BGP_ATTR_ATOMIC_AGGREGATE))))
9277 ts->counts[BGP_STATS_AGGREGATES]++;
9278
9279 /* as-path stats */
9280 if (ri->attr && ri->attr->aspath)
9281 {
9282 unsigned int hops = aspath_count_hops (ri->attr->aspath);
9283 unsigned int size = aspath_size (ri->attr->aspath);
9284 as_t highest = aspath_highest (ri->attr->aspath);
9285
9286 ts->counts[BGP_STATS_ASPATH_COUNT]++;
9287
9288 if (hops > ts->counts[BGP_STATS_ASPATH_MAXHOPS])
9289 ts->counts[BGP_STATS_ASPATH_MAXHOPS] = hops;
9290
9291 if (size > ts->counts[BGP_STATS_ASPATH_MAXSIZE])
9292 ts->counts[BGP_STATS_ASPATH_MAXSIZE] = size;
9293
9294 ts->counts[BGP_STATS_ASPATH_TOTHOPS] += hops;
9295 ts->counts[BGP_STATS_ASPATH_TOTSIZE] += size;
9296#if 0
9297 ts->counts[BGP_STATS_ASPATH_AVGHOPS]
9298 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9299 ts->counts[BGP_STATS_ASPATH_AVGHOPS],
9300 hops);
9301 ts->counts[BGP_STATS_ASPATH_AVGSIZE]
9302 = ravg_tally (ts->counts[BGP_STATS_ASPATH_COUNT],
9303 ts->counts[BGP_STATS_ASPATH_AVGSIZE],
9304 size);
9305#endif
9306 if (highest > ts->counts[BGP_STATS_ASN_HIGHEST])
9307 ts->counts[BGP_STATS_ASN_HIGHEST] = highest;
9308 }
9309 }
9310 }
9311 return 0;
9312}
9313
9314static int
9315bgp_table_stats (struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi)
9316{
9317 struct bgp_table_stats ts;
9318 unsigned int i;
9319
9320 if (!bgp->rib[afi][safi])
9321 {
9322 vty_out (vty, "%% No RIB exist for the AFI/SAFI%s", VTY_NEWLINE);
9323 return CMD_WARNING;
9324 }
9325
9326 memset (&ts, 0, sizeof (ts));
9327 ts.table = bgp->rib[afi][safi];
9328 thread_execute (bm->master, bgp_table_stats_walker, &ts, 0);
9329
9330 vty_out (vty, "BGP %s RIB statistics%s%s",
9331 afi_safi_print (afi, safi), VTY_NEWLINE, VTY_NEWLINE);
9332
9333 for (i = 0; i < BGP_STATS_MAX; i++)
9334 {
9335 if (!table_stats_strs[i])
9336 continue;
9337
9338 switch (i)
9339 {
9340#if 0
9341 case BGP_STATS_ASPATH_AVGHOPS:
9342 case BGP_STATS_ASPATH_AVGSIZE:
9343 case BGP_STATS_AVGPLEN:
9344 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9345 vty_out (vty, "%12.2f",
9346 (float)ts.counts[i] / (float)TALLY_SIGFIG);
9347 break;
9348#endif
9349 case BGP_STATS_ASPATH_TOTHOPS:
9350 case BGP_STATS_ASPATH_TOTSIZE:
9351 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9352 vty_out (vty, "%12.2f",
9353 ts.counts[i] ?
9354 (float)ts.counts[i] /
9355 (float)ts.counts[BGP_STATS_ASPATH_COUNT]
9356 : 0);
9357 break;
9358 case BGP_STATS_TOTPLEN:
9359 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9360 vty_out (vty, "%12.2f",
9361 ts.counts[i] ?
9362 (float)ts.counts[i] /
9363 (float)ts.counts[BGP_STATS_PREFIXES]
9364 : 0);
9365 break;
9366 case BGP_STATS_SPACE:
9367 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9368 vty_out (vty, "%12llu%s", ts.counts[i], VTY_NEWLINE);
9369 if (ts.counts[BGP_STATS_MAXBITLEN] < 9)
9370 break;
Paul Jakma30a22312008-08-15 14:05:22 +01009371 vty_out (vty, "%30s: ", "%% announced ");
Paul Jakma2815e612006-09-14 02:56:07 +00009372 vty_out (vty, "%12.2f%s",
9373 100 * (float)ts.counts[BGP_STATS_SPACE] /
Paul Jakma56395af2006-10-27 16:58:20 +00009374 (float)((uint64_t)1UL << ts.counts[BGP_STATS_MAXBITLEN]),
Paul Jakma2815e612006-09-14 02:56:07 +00009375 VTY_NEWLINE);
9376 vty_out (vty, "%30s: ", "/8 equivalent ");
9377 vty_out (vty, "%12.2f%s",
9378 (float)ts.counts[BGP_STATS_SPACE] /
9379 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 8)),
9380 VTY_NEWLINE);
9381 if (ts.counts[BGP_STATS_MAXBITLEN] < 25)
9382 break;
9383 vty_out (vty, "%30s: ", "/24 equivalent ");
9384 vty_out (vty, "%12.2f",
9385 (float)ts.counts[BGP_STATS_SPACE] /
9386 (float)(1UL << (ts.counts[BGP_STATS_MAXBITLEN] - 24)));
9387 break;
9388 default:
9389 vty_out (vty, "%-30s: ", table_stats_strs[i]);
9390 vty_out (vty, "%12llu", ts.counts[i]);
9391 }
9392
9393 vty_out (vty, "%s", VTY_NEWLINE);
9394 }
9395 return CMD_SUCCESS;
9396}
9397
9398static int
9399bgp_table_stats_vty (struct vty *vty, const char *name,
9400 const char *afi_str, const char *safi_str)
9401{
9402 struct bgp *bgp;
9403 afi_t afi;
9404 safi_t safi;
9405
9406 if (name)
9407 bgp = bgp_lookup_by_name (name);
9408 else
9409 bgp = bgp_get_default ();
9410
9411 if (!bgp)
9412 {
9413 vty_out (vty, "%% No such BGP instance exist%s", VTY_NEWLINE);
9414 return CMD_WARNING;
9415 }
9416 if (strncmp (afi_str, "ipv", 3) == 0)
9417 {
9418 if (strncmp (afi_str, "ipv4", 4) == 0)
9419 afi = AFI_IP;
9420 else if (strncmp (afi_str, "ipv6", 4) == 0)
9421 afi = AFI_IP6;
9422 else
9423 {
9424 vty_out (vty, "%% Invalid address family %s%s",
9425 afi_str, VTY_NEWLINE);
9426 return CMD_WARNING;
9427 }
9428 if (strncmp (safi_str, "m", 1) == 0)
9429 safi = SAFI_MULTICAST;
9430 else if (strncmp (safi_str, "u", 1) == 0)
9431 safi = SAFI_UNICAST;
9432 else if (strncmp (safi_str, "vpnv4", 5) == 0)
9433 safi = BGP_SAFI_VPNV4;
9434 else if (strncmp (safi_str, "vpnv6", 6) == 0)
9435 safi = BGP_SAFI_VPNV6;
9436 else
9437 {
9438 vty_out (vty, "%% Invalid subsequent address family %s%s",
9439 safi_str, VTY_NEWLINE);
9440 return CMD_WARNING;
9441 }
9442 }
9443 else
9444 {
9445 vty_out (vty, "%% Invalid address family %s%s",
9446 afi_str, VTY_NEWLINE);
9447 return CMD_WARNING;
9448 }
9449
9450 if ((afi == AFI_IP && safi == BGP_SAFI_VPNV6)
9451 || (afi == AFI_IP6 && safi == BGP_SAFI_VPNV4))
9452 {
9453 vty_out (vty, "%% Invalid subsequent address family %s for %s%s",
9454 afi_str, safi_str, VTY_NEWLINE);
9455 return CMD_WARNING;
9456 }
9457 return bgp_table_stats (vty, bgp, afi, safi);
9458}
9459
9460DEFUN (show_bgp_statistics,
9461 show_bgp_statistics_cmd,
9462 "show bgp (ipv4|ipv6) (unicast|multicast) statistics",
9463 SHOW_STR
9464 BGP_STR
9465 "Address family\n"
9466 "Address family\n"
9467 "Address Family modifier\n"
9468 "Address Family modifier\n"
9469 "BGP RIB advertisement statistics\n")
9470{
9471 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9472}
9473
9474ALIAS (show_bgp_statistics,
9475 show_bgp_statistics_vpnv4_cmd,
9476 "show bgp (ipv4) (vpnv4) statistics",
9477 SHOW_STR
9478 BGP_STR
9479 "Address family\n"
9480 "Address Family modifier\n"
9481 "BGP RIB advertisement statistics\n")
9482
9483DEFUN (show_bgp_statistics_view,
9484 show_bgp_statistics_view_cmd,
9485 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) statistics",
9486 SHOW_STR
9487 BGP_STR
9488 "BGP view\n"
9489 "Address family\n"
9490 "Address family\n"
9491 "Address Family modifier\n"
9492 "Address Family modifier\n"
9493 "BGP RIB advertisement statistics\n")
9494{
9495 return bgp_table_stats_vty (vty, NULL, argv[0], argv[1]);
9496}
9497
9498ALIAS (show_bgp_statistics_view,
9499 show_bgp_statistics_view_vpnv4_cmd,
9500 "show bgp view WORD (ipv4) (vpnv4) statistics",
9501 SHOW_STR
9502 BGP_STR
9503 "BGP view\n"
9504 "Address family\n"
9505 "Address Family modifier\n"
9506 "BGP RIB advertisement statistics\n")
9507
Paul Jakmaff7924f2006-09-04 01:10:36 +00009508enum bgp_pcounts
9509{
9510 PCOUNT_ADJ_IN = 0,
9511 PCOUNT_DAMPED,
9512 PCOUNT_REMOVED,
9513 PCOUNT_HISTORY,
9514 PCOUNT_STALE,
9515 PCOUNT_VALID,
9516 PCOUNT_ALL,
9517 PCOUNT_COUNTED,
9518 PCOUNT_PFCNT, /* the figure we display to users */
9519 PCOUNT_MAX,
9520};
9521
9522static const char *pcount_strs[] =
9523{
9524 [PCOUNT_ADJ_IN] = "Adj-in",
9525 [PCOUNT_DAMPED] = "Damped",
9526 [PCOUNT_REMOVED] = "Removed",
9527 [PCOUNT_HISTORY] = "History",
9528 [PCOUNT_STALE] = "Stale",
9529 [PCOUNT_VALID] = "Valid",
9530 [PCOUNT_ALL] = "All RIB",
9531 [PCOUNT_COUNTED] = "PfxCt counted",
9532 [PCOUNT_PFCNT] = "Useable",
9533 [PCOUNT_MAX] = NULL,
9534};
9535
Paul Jakma2815e612006-09-14 02:56:07 +00009536struct peer_pcounts
9537{
9538 unsigned int count[PCOUNT_MAX];
9539 const struct peer *peer;
9540 const struct bgp_table *table;
9541};
9542
Paul Jakmaff7924f2006-09-04 01:10:36 +00009543static int
Paul Jakma2815e612006-09-14 02:56:07 +00009544bgp_peer_count_walker (struct thread *t)
Paul Jakmaff7924f2006-09-04 01:10:36 +00009545{
9546 struct bgp_node *rn;
Paul Jakma2815e612006-09-14 02:56:07 +00009547 struct peer_pcounts *pc = THREAD_ARG (t);
9548 const struct peer *peer = pc->peer;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009549
Paul Jakma2815e612006-09-14 02:56:07 +00009550 for (rn = bgp_table_top (pc->table); rn; rn = bgp_route_next (rn))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009551 {
9552 struct bgp_adj_in *ain;
Paul Jakma2815e612006-09-14 02:56:07 +00009553 struct bgp_info *ri;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009554
9555 for (ain = rn->adj_in; ain; ain = ain->next)
9556 if (ain->peer == peer)
Paul Jakma2815e612006-09-14 02:56:07 +00009557 pc->count[PCOUNT_ADJ_IN]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009558
Paul Jakmaff7924f2006-09-04 01:10:36 +00009559 for (ri = rn->info; ri; ri = ri->next)
9560 {
9561 char buf[SU_ADDRSTRLEN];
9562
9563 if (ri->peer != peer)
9564 continue;
9565
Paul Jakma2815e612006-09-14 02:56:07 +00009566 pc->count[PCOUNT_ALL]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009567
9568 if (CHECK_FLAG (ri->flags, BGP_INFO_DAMPED))
Paul Jakma2815e612006-09-14 02:56:07 +00009569 pc->count[PCOUNT_DAMPED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009570 if (CHECK_FLAG (ri->flags, BGP_INFO_HISTORY))
Paul Jakma2815e612006-09-14 02:56:07 +00009571 pc->count[PCOUNT_HISTORY]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009572 if (CHECK_FLAG (ri->flags, BGP_INFO_REMOVED))
Paul Jakma2815e612006-09-14 02:56:07 +00009573 pc->count[PCOUNT_REMOVED]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009574 if (CHECK_FLAG (ri->flags, BGP_INFO_STALE))
Paul Jakma2815e612006-09-14 02:56:07 +00009575 pc->count[PCOUNT_STALE]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009576 if (CHECK_FLAG (ri->flags, BGP_INFO_VALID))
Paul Jakma2815e612006-09-14 02:56:07 +00009577 pc->count[PCOUNT_VALID]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009578 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakma2815e612006-09-14 02:56:07 +00009579 pc->count[PCOUNT_PFCNT]++;
Paul Jakmaff7924f2006-09-04 01:10:36 +00009580
9581 if (CHECK_FLAG (ri->flags, BGP_INFO_COUNTED))
9582 {
Paul Jakma2815e612006-09-14 02:56:07 +00009583 pc->count[PCOUNT_COUNTED]++;
Paul Jakma1a392d42006-09-07 00:24:49 +00009584 if (CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009585 plog_warn (peer->log,
9586 "%s [pcount] %s/%d is counted but flags 0x%x",
9587 peer->host,
9588 inet_ntop(rn->p.family, &rn->p.u.prefix,
9589 buf, SU_ADDRSTRLEN),
9590 rn->p.prefixlen,
9591 ri->flags);
9592 }
9593 else
9594 {
Paul Jakma1a392d42006-09-07 00:24:49 +00009595 if (!CHECK_FLAG (ri->flags, BGP_INFO_UNUSEABLE))
Paul Jakmaff7924f2006-09-04 01:10:36 +00009596 plog_warn (peer->log,
9597 "%s [pcount] %s/%d not counted but flags 0x%x",
9598 peer->host,
9599 inet_ntop(rn->p.family, &rn->p.u.prefix,
9600 buf, SU_ADDRSTRLEN),
9601 rn->p.prefixlen,
9602 ri->flags);
9603 }
9604 }
9605 }
Paul Jakma2815e612006-09-14 02:56:07 +00009606 return 0;
9607}
Paul Jakmaff7924f2006-09-04 01:10:36 +00009608
Paul Jakma2815e612006-09-14 02:56:07 +00009609static int
9610bgp_peer_counts (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi)
9611{
9612 struct peer_pcounts pcounts = { .peer = peer };
9613 unsigned int i;
9614
9615 if (!peer || !peer->bgp || !peer->afc[afi][safi]
9616 || !peer->bgp->rib[afi][safi])
9617 {
9618 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9619 return CMD_WARNING;
9620 }
9621
9622 memset (&pcounts, 0, sizeof(pcounts));
9623 pcounts.peer = peer;
9624 pcounts.table = peer->bgp->rib[afi][safi];
9625
9626 /* in-place call via thread subsystem so as to record execution time
9627 * stats for the thread-walk (i.e. ensure this can't be blamed on
9628 * on just vty_read()).
9629 */
9630 thread_execute (bm->master, bgp_peer_count_walker, &pcounts, 0);
9631
Paul Jakmaff7924f2006-09-04 01:10:36 +00009632 vty_out (vty, "Prefix counts for %s, %s%s",
9633 peer->host, afi_safi_print (afi, safi), VTY_NEWLINE);
9634 vty_out (vty, "PfxCt: %ld%s", peer->pcount[afi][safi], VTY_NEWLINE);
9635 vty_out (vty, "%sCounts from RIB table walk:%s%s",
9636 VTY_NEWLINE, VTY_NEWLINE, VTY_NEWLINE);
9637
9638 for (i = 0; i < PCOUNT_MAX; i++)
Paul Jakma2815e612006-09-14 02:56:07 +00009639 vty_out (vty, "%20s: %-10d%s",
9640 pcount_strs[i], pcounts.count[i], VTY_NEWLINE);
Paul Jakmaff7924f2006-09-04 01:10:36 +00009641
Paul Jakma2815e612006-09-14 02:56:07 +00009642 if (pcounts.count[PCOUNT_PFCNT] != peer->pcount[afi][safi])
Paul Jakmaff7924f2006-09-04 01:10:36 +00009643 {
9644 vty_out (vty, "%s [pcount] PfxCt drift!%s",
9645 peer->host, VTY_NEWLINE);
9646 vty_out (vty, "Please report this bug, with the above command output%s",
9647 VTY_NEWLINE);
9648 }
9649
9650 return CMD_SUCCESS;
9651}
9652
9653DEFUN (show_ip_bgp_neighbor_prefix_counts,
9654 show_ip_bgp_neighbor_prefix_counts_cmd,
9655 "show ip bgp neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9656 SHOW_STR
9657 IP_STR
9658 BGP_STR
9659 "Detailed information on TCP and BGP neighbor connections\n"
9660 "Neighbor to display information about\n"
9661 "Neighbor to display information about\n"
9662 "Display detailed prefix count information\n")
9663{
9664 struct peer *peer;
9665
9666 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9667 if (! peer)
9668 return CMD_WARNING;
9669
9670 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9671}
9672
9673DEFUN (show_bgp_ipv6_neighbor_prefix_counts,
9674 show_bgp_ipv6_neighbor_prefix_counts_cmd,
9675 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9676 SHOW_STR
9677 BGP_STR
9678 "Address family\n"
9679 "Detailed information on TCP and BGP neighbor connections\n"
9680 "Neighbor to display information about\n"
9681 "Neighbor to display information about\n"
9682 "Display detailed prefix count information\n")
9683{
9684 struct peer *peer;
9685
9686 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9687 if (! peer)
9688 return CMD_WARNING;
9689
9690 return bgp_peer_counts (vty, peer, AFI_IP6, SAFI_UNICAST);
9691}
9692
9693DEFUN (show_ip_bgp_ipv4_neighbor_prefix_counts,
9694 show_ip_bgp_ipv4_neighbor_prefix_counts_cmd,
9695 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9696 SHOW_STR
9697 IP_STR
9698 BGP_STR
9699 "Address family\n"
9700 "Address Family modifier\n"
9701 "Address Family modifier\n"
9702 "Detailed information on TCP and BGP neighbor connections\n"
9703 "Neighbor to display information about\n"
9704 "Neighbor to display information about\n"
9705 "Display detailed prefix count information\n")
9706{
9707 struct peer *peer;
9708
9709 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9710 if (! peer)
9711 return CMD_WARNING;
9712
9713 if (strncmp (argv[0], "m", 1) == 0)
9714 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MULTICAST);
9715
9716 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_UNICAST);
9717}
9718
9719DEFUN (show_ip_bgp_vpnv4_neighbor_prefix_counts,
9720 show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd,
9721 "show ip bgp vpnv4 all neighbors (A.B.C.D|X:X::X:X) prefix-counts",
9722 SHOW_STR
9723 IP_STR
9724 BGP_STR
9725 "Address family\n"
9726 "Address Family modifier\n"
9727 "Address Family modifier\n"
9728 "Detailed information on TCP and BGP neighbor connections\n"
9729 "Neighbor to display information about\n"
9730 "Neighbor to display information about\n"
9731 "Display detailed prefix count information\n")
9732{
9733 struct peer *peer;
9734
9735 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9736 if (! peer)
9737 return CMD_WARNING;
9738
9739 return bgp_peer_counts (vty, peer, AFI_IP, SAFI_MPLS_VPN);
9740}
9741
9742
paul94f2b392005-06-28 12:44:16 +00009743static void
paul718e3742002-12-13 20:15:29 +00009744show_adj_route (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi,
9745 int in)
9746{
9747 struct bgp_table *table;
9748 struct bgp_adj_in *ain;
9749 struct bgp_adj_out *adj;
9750 unsigned long output_count;
9751 struct bgp_node *rn;
9752 int header1 = 1;
9753 struct bgp *bgp;
9754 int header2 = 1;
9755
paulbb46e942003-10-24 19:02:03 +00009756 bgp = peer->bgp;
paul718e3742002-12-13 20:15:29 +00009757
9758 if (! bgp)
9759 return;
9760
9761 table = bgp->rib[afi][safi];
9762
9763 output_count = 0;
9764
9765 if (! in && CHECK_FLAG (peer->af_sflags[afi][safi],
9766 PEER_STATUS_DEFAULT_ORIGINATE))
9767 {
9768 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 +00009769 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9770 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009771
9772 vty_out (vty, "Originating default network 0.0.0.0%s%s",
9773 VTY_NEWLINE, VTY_NEWLINE);
9774 header1 = 0;
9775 }
9776
9777 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
9778 if (in)
9779 {
9780 for (ain = rn->adj_in; ain; ain = ain->next)
9781 if (ain->peer == peer)
9782 {
9783 if (header1)
9784 {
9785 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 +00009786 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9787 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009788 header1 = 0;
9789 }
9790 if (header2)
9791 {
9792 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9793 header2 = 0;
9794 }
9795 if (ain->attr)
9796 {
9797 route_vty_out_tmp (vty, &rn->p, ain->attr, safi);
9798 output_count++;
9799 }
9800 }
9801 }
9802 else
9803 {
9804 for (adj = rn->adj_out; adj; adj = adj->next)
9805 if (adj->peer == peer)
9806 {
9807 if (header1)
9808 {
9809 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 +00009810 vty_out (vty, BGP_SHOW_SCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
9811 vty_out (vty, BGP_SHOW_OCODE_HEADER, VTY_NEWLINE, VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +00009812 header1 = 0;
9813 }
9814 if (header2)
9815 {
9816 vty_out (vty, BGP_SHOW_HEADER, VTY_NEWLINE);
9817 header2 = 0;
9818 }
9819 if (adj->attr)
9820 {
9821 route_vty_out_tmp (vty, &rn->p, adj->attr, safi);
9822 output_count++;
9823 }
9824 }
9825 }
9826
9827 if (output_count != 0)
9828 vty_out (vty, "%sTotal number of prefixes %ld%s",
9829 VTY_NEWLINE, output_count, VTY_NEWLINE);
9830}
9831
paul94f2b392005-06-28 12:44:16 +00009832static int
paulbb46e942003-10-24 19:02:03 +00009833peer_adj_routes (struct vty *vty, struct peer *peer, afi_t afi, safi_t safi, int in)
9834{
paul718e3742002-12-13 20:15:29 +00009835 if (! peer || ! peer->afc[afi][safi])
9836 {
9837 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
9838 return CMD_WARNING;
9839 }
9840
9841 if (in && ! CHECK_FLAG (peer->af_flags[afi][safi], PEER_FLAG_SOFT_RECONFIG))
9842 {
9843 vty_out (vty, "%% Inbound soft reconfiguration not enabled%s",
9844 VTY_NEWLINE);
9845 return CMD_WARNING;
9846 }
9847
9848 show_adj_route (vty, peer, afi, safi, in);
9849
9850 return CMD_SUCCESS;
9851}
9852
Tomasz Pala2a71e9c2009-06-24 21:36:50 +01009853DEFUN (show_ip_bgp_view_neighbor_advertised_route,
9854 show_ip_bgp_view_neighbor_advertised_route_cmd,
9855 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9856 SHOW_STR
9857 IP_STR
9858 BGP_STR
9859 "BGP view\n"
9860 "View name\n"
9861 "Detailed information on TCP and BGP neighbor connections\n"
9862 "Neighbor to display information about\n"
9863 "Neighbor to display information about\n"
9864 "Display the routes advertised to a BGP neighbor\n")
9865{
9866 struct peer *peer;
9867
9868 if (argc == 2)
9869 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9870 else
9871 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9872
9873 if (! peer)
9874 return CMD_WARNING;
9875
9876 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
9877}
9878
9879ALIAS (show_ip_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009880 show_ip_bgp_neighbor_advertised_route_cmd,
9881 "show ip bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9882 SHOW_STR
9883 IP_STR
9884 BGP_STR
9885 "Detailed information on TCP and BGP neighbor connections\n"
9886 "Neighbor to display information about\n"
9887 "Neighbor to display information about\n"
9888 "Display the routes advertised to a BGP neighbor\n")
paul718e3742002-12-13 20:15:29 +00009889
9890DEFUN (show_ip_bgp_ipv4_neighbor_advertised_route,
9891 show_ip_bgp_ipv4_neighbor_advertised_route_cmd,
9892 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9893 SHOW_STR
9894 IP_STR
9895 BGP_STR
9896 "Address family\n"
9897 "Address Family modifier\n"
9898 "Address Family modifier\n"
9899 "Detailed information on TCP and BGP neighbor connections\n"
9900 "Neighbor to display information about\n"
9901 "Neighbor to display information about\n"
9902 "Display the routes advertised to a BGP neighbor\n")
9903{
paulbb46e942003-10-24 19:02:03 +00009904 struct peer *peer;
paul718e3742002-12-13 20:15:29 +00009905
paulbb46e942003-10-24 19:02:03 +00009906 peer = peer_lookup_in_view (vty, NULL, argv[1]);
9907 if (! peer)
9908 return CMD_WARNING;
9909
9910 if (strncmp (argv[0], "m", 1) == 0)
9911 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 0);
9912
9913 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 0);
paul718e3742002-12-13 20:15:29 +00009914}
9915
9916#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +00009917DEFUN (show_bgp_view_neighbor_advertised_route,
9918 show_bgp_view_neighbor_advertised_route_cmd,
9919 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9920 SHOW_STR
9921 BGP_STR
9922 "BGP view\n"
9923 "View name\n"
9924 "Detailed information on TCP and BGP neighbor connections\n"
9925 "Neighbor to display information about\n"
9926 "Neighbor to display information about\n"
9927 "Display the routes advertised to a BGP neighbor\n")
9928{
9929 struct peer *peer;
9930
9931 if (argc == 2)
9932 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9933 else
9934 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9935
9936 if (! peer)
9937 return CMD_WARNING;
9938
9939 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 0);
9940}
9941
9942ALIAS (show_bgp_view_neighbor_advertised_route,
9943 show_bgp_view_ipv6_neighbor_advertised_route_cmd,
9944 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9945 SHOW_STR
9946 BGP_STR
9947 "BGP view\n"
9948 "View name\n"
9949 "Address family\n"
9950 "Detailed information on TCP and BGP neighbor connections\n"
9951 "Neighbor to display information about\n"
9952 "Neighbor to display information about\n"
9953 "Display the routes advertised to a BGP neighbor\n")
9954
9955DEFUN (show_bgp_view_neighbor_received_routes,
9956 show_bgp_view_neighbor_received_routes_cmd,
9957 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
9958 SHOW_STR
9959 BGP_STR
9960 "BGP view\n"
9961 "View name\n"
9962 "Detailed information on TCP and BGP neighbor connections\n"
9963 "Neighbor to display information about\n"
9964 "Neighbor to display information about\n"
9965 "Display the received routes from neighbor\n")
9966{
9967 struct peer *peer;
9968
9969 if (argc == 2)
9970 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
9971 else
9972 peer = peer_lookup_in_view (vty, NULL, argv[0]);
9973
9974 if (! peer)
9975 return CMD_WARNING;
9976
9977 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_UNICAST, 1);
9978}
9979
9980ALIAS (show_bgp_view_neighbor_received_routes,
9981 show_bgp_view_ipv6_neighbor_received_routes_cmd,
9982 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
9983 SHOW_STR
9984 BGP_STR
9985 "BGP view\n"
9986 "View name\n"
9987 "Address family\n"
9988 "Detailed information on TCP and BGP neighbor connections\n"
9989 "Neighbor to display information about\n"
9990 "Neighbor to display information about\n"
9991 "Display the received routes from neighbor\n")
9992
9993ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +00009994 show_bgp_neighbor_advertised_route_cmd,
9995 "show bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
9996 SHOW_STR
9997 BGP_STR
9998 "Detailed information on TCP and BGP neighbor connections\n"
9999 "Neighbor to display information about\n"
10000 "Neighbor to display information about\n"
10001 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010002
10003ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010004 show_bgp_ipv6_neighbor_advertised_route_cmd,
10005 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10006 SHOW_STR
10007 BGP_STR
10008 "Address family\n"
10009 "Detailed information on TCP and BGP neighbor connections\n"
10010 "Neighbor to display information about\n"
10011 "Neighbor to display information about\n"
10012 "Display the routes advertised to a BGP neighbor\n")
10013
10014/* old command */
paulbb46e942003-10-24 19:02:03 +000010015ALIAS (show_bgp_view_neighbor_advertised_route,
paul718e3742002-12-13 20:15:29 +000010016 ipv6_bgp_neighbor_advertised_route_cmd,
10017 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10018 SHOW_STR
10019 IPV6_STR
10020 BGP_STR
10021 "Detailed information on TCP and BGP neighbor connections\n"
10022 "Neighbor to display information about\n"
10023 "Neighbor to display information about\n"
10024 "Display the routes advertised to a BGP neighbor\n")
paulbb46e942003-10-24 19:02:03 +000010025
paul718e3742002-12-13 20:15:29 +000010026/* old command */
10027DEFUN (ipv6_mbgp_neighbor_advertised_route,
10028 ipv6_mbgp_neighbor_advertised_route_cmd,
10029 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) advertised-routes",
10030 SHOW_STR
10031 IPV6_STR
10032 MBGP_STR
10033 "Detailed information on TCP and BGP neighbor connections\n"
10034 "Neighbor to display information about\n"
10035 "Neighbor to display information about\n"
10036 "Display the routes advertised to a BGP neighbor\n")
10037{
paulbb46e942003-10-24 19:02:03 +000010038 struct peer *peer;
10039
10040 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10041 if (! peer)
10042 return CMD_WARNING;
10043
10044 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 0);
paul718e3742002-12-13 20:15:29 +000010045}
10046#endif /* HAVE_IPV6 */
10047
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010010048DEFUN (show_ip_bgp_view_neighbor_received_routes,
10049 show_ip_bgp_view_neighbor_received_routes_cmd,
10050 "show ip bgp view WORD neighbors (A.B.C.D|X:X::X:X) received-routes",
10051 SHOW_STR
10052 IP_STR
10053 BGP_STR
10054 "BGP view\n"
10055 "View name\n"
10056 "Detailed information on TCP and BGP neighbor connections\n"
10057 "Neighbor to display information about\n"
10058 "Neighbor to display information about\n"
10059 "Display the received routes from neighbor\n")
10060{
10061 struct peer *peer;
10062
10063 if (argc == 2)
10064 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10065 else
10066 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10067
10068 if (! peer)
10069 return CMD_WARNING;
10070
10071 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
10072}
10073
10074ALIAS (show_ip_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010075 show_ip_bgp_neighbor_received_routes_cmd,
10076 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10077 SHOW_STR
10078 IP_STR
10079 BGP_STR
10080 "Detailed information on TCP and BGP neighbor connections\n"
10081 "Neighbor to display information about\n"
10082 "Neighbor to display information about\n"
10083 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010084
10085DEFUN (show_ip_bgp_ipv4_neighbor_received_routes,
10086 show_ip_bgp_ipv4_neighbor_received_routes_cmd,
10087 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received-routes",
10088 SHOW_STR
10089 IP_STR
10090 BGP_STR
10091 "Address family\n"
10092 "Address Family modifier\n"
10093 "Address Family modifier\n"
10094 "Detailed information on TCP and BGP neighbor connections\n"
10095 "Neighbor to display information about\n"
10096 "Neighbor to display information about\n"
10097 "Display the received routes from neighbor\n")
10098{
paulbb46e942003-10-24 19:02:03 +000010099 struct peer *peer;
paul718e3742002-12-13 20:15:29 +000010100
paulbb46e942003-10-24 19:02:03 +000010101 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10102 if (! peer)
10103 return CMD_WARNING;
10104
10105 if (strncmp (argv[0], "m", 1) == 0)
10106 return peer_adj_routes (vty, peer, AFI_IP, SAFI_MULTICAST, 1);
10107
10108 return peer_adj_routes (vty, peer, AFI_IP, SAFI_UNICAST, 1);
paul718e3742002-12-13 20:15:29 +000010109}
10110
Michael Lambert95cbbd22010-07-23 14:43:04 -040010111DEFUN (show_bgp_view_afi_safi_neighbor_adv_recd_routes,
10112 show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd,
10113#ifdef HAVE_IPV6
10114 "show bgp view WORD (ipv4|ipv6) (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10115#else
10116 "show bgp view WORD ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) (advertised-routes|received-routes)",
10117#endif
10118 SHOW_STR
10119 BGP_STR
10120 "BGP view\n"
10121 "BGP view name\n"
10122 "Address family\n"
10123#ifdef HAVE_IPV6
10124 "Address family\n"
10125#endif
10126 "Address family modifier\n"
10127 "Address family modifier\n"
10128 "Detailed information on TCP and BGP neighbor connections\n"
10129 "Neighbor to display information about\n"
10130 "Neighbor to display information about\n"
10131 "Display the advertised routes to neighbor\n"
10132 "Display the received routes from neighbor\n")
10133{
10134 int afi;
10135 int safi;
10136 int in;
10137 struct peer *peer;
10138
10139#ifdef HAVE_IPV6
10140 peer = peer_lookup_in_view (vty, argv[0], argv[3]);
10141#else
10142 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10143#endif
10144
10145 if (! peer)
10146 return CMD_WARNING;
10147
10148#ifdef HAVE_IPV6
10149 afi = (strncmp (argv[1], "ipv6", 4) == 0) ? AFI_IP6 : AFI_IP;
10150 safi = (strncmp (argv[2], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10151 in = (strncmp (argv[4], "r", 1) == 0) ? 1 : 0;
10152#else
10153 afi = AFI_IP;
10154 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10155 in = (strncmp (argv[3], "r", 1) == 0) ? 1 : 0;
10156#endif
10157
10158 return peer_adj_routes (vty, peer, afi, safi, in);
10159}
10160
paul718e3742002-12-13 20:15:29 +000010161DEFUN (show_ip_bgp_neighbor_received_prefix_filter,
10162 show_ip_bgp_neighbor_received_prefix_filter_cmd,
10163 "show ip bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10164 SHOW_STR
10165 IP_STR
10166 BGP_STR
10167 "Detailed information on TCP and BGP neighbor connections\n"
10168 "Neighbor to display information about\n"
10169 "Neighbor to display information about\n"
10170 "Display information received from a BGP neighbor\n"
10171 "Display the prefixlist filter\n")
10172{
10173 char name[BUFSIZ];
10174 union sockunion *su;
10175 struct peer *peer;
10176 int count;
10177
10178 su = sockunion_str2su (argv[0]);
10179 if (su == NULL)
10180 return CMD_WARNING;
10181
10182 peer = peer_lookup (NULL, su);
10183 if (! peer)
10184 return CMD_WARNING;
10185
10186 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10187 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10188 if (count)
10189 {
10190 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10191 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10192 }
10193
10194 return CMD_SUCCESS;
10195}
10196
10197DEFUN (show_ip_bgp_ipv4_neighbor_received_prefix_filter,
10198 show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd,
10199 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10200 SHOW_STR
10201 IP_STR
10202 BGP_STR
10203 "Address family\n"
10204 "Address Family modifier\n"
10205 "Address Family modifier\n"
10206 "Detailed information on TCP and BGP neighbor connections\n"
10207 "Neighbor to display information about\n"
10208 "Neighbor to display information about\n"
10209 "Display information received from a BGP neighbor\n"
10210 "Display the prefixlist filter\n")
10211{
10212 char name[BUFSIZ];
10213 union sockunion *su;
10214 struct peer *peer;
10215 int count;
10216
10217 su = sockunion_str2su (argv[1]);
10218 if (su == NULL)
10219 return CMD_WARNING;
10220
10221 peer = peer_lookup (NULL, su);
10222 if (! peer)
10223 return CMD_WARNING;
10224
10225 if (strncmp (argv[0], "m", 1) == 0)
10226 {
10227 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_MULTICAST);
10228 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10229 if (count)
10230 {
10231 vty_out (vty, "Address family: IPv4 Multicast%s", VTY_NEWLINE);
10232 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10233 }
10234 }
10235 else
10236 {
10237 sprintf (name, "%s.%d.%d", peer->host, AFI_IP, SAFI_UNICAST);
10238 count = prefix_bgp_show_prefix_list (NULL, AFI_IP, name);
10239 if (count)
10240 {
10241 vty_out (vty, "Address family: IPv4 Unicast%s", VTY_NEWLINE);
10242 prefix_bgp_show_prefix_list (vty, AFI_IP, name);
10243 }
10244 }
10245
10246 return CMD_SUCCESS;
10247}
10248
10249
10250#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010251ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010252 show_bgp_neighbor_received_routes_cmd,
10253 "show bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10254 SHOW_STR
10255 BGP_STR
10256 "Detailed information on TCP and BGP neighbor connections\n"
10257 "Neighbor to display information about\n"
10258 "Neighbor to display information about\n"
10259 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010260
paulbb46e942003-10-24 19:02:03 +000010261ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010262 show_bgp_ipv6_neighbor_received_routes_cmd,
10263 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received-routes",
10264 SHOW_STR
10265 BGP_STR
10266 "Address family\n"
10267 "Detailed information on TCP and BGP neighbor connections\n"
10268 "Neighbor to display information about\n"
10269 "Neighbor to display information about\n"
10270 "Display the received routes from neighbor\n")
10271
10272DEFUN (show_bgp_neighbor_received_prefix_filter,
10273 show_bgp_neighbor_received_prefix_filter_cmd,
10274 "show bgp neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10275 SHOW_STR
10276 BGP_STR
10277 "Detailed information on TCP and BGP neighbor connections\n"
10278 "Neighbor to display information about\n"
10279 "Neighbor to display information about\n"
10280 "Display information received from a BGP neighbor\n"
10281 "Display the prefixlist filter\n")
10282{
10283 char name[BUFSIZ];
10284 union sockunion *su;
10285 struct peer *peer;
10286 int count;
10287
10288 su = sockunion_str2su (argv[0]);
10289 if (su == NULL)
10290 return CMD_WARNING;
10291
10292 peer = peer_lookup (NULL, su);
10293 if (! peer)
10294 return CMD_WARNING;
10295
10296 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10297 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10298 if (count)
10299 {
10300 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10301 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10302 }
10303
10304 return CMD_SUCCESS;
10305}
10306
10307ALIAS (show_bgp_neighbor_received_prefix_filter,
10308 show_bgp_ipv6_neighbor_received_prefix_filter_cmd,
10309 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10310 SHOW_STR
10311 BGP_STR
10312 "Address family\n"
10313 "Detailed information on TCP and BGP neighbor connections\n"
10314 "Neighbor to display information about\n"
10315 "Neighbor to display information about\n"
10316 "Display information received from a BGP neighbor\n"
10317 "Display the prefixlist filter\n")
10318
10319/* old command */
paulbb46e942003-10-24 19:02:03 +000010320ALIAS (show_bgp_view_neighbor_received_routes,
paul718e3742002-12-13 20:15:29 +000010321 ipv6_bgp_neighbor_received_routes_cmd,
10322 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10323 SHOW_STR
10324 IPV6_STR
10325 BGP_STR
10326 "Detailed information on TCP and BGP neighbor connections\n"
10327 "Neighbor to display information about\n"
10328 "Neighbor to display information about\n"
10329 "Display the received routes from neighbor\n")
paul718e3742002-12-13 20:15:29 +000010330
10331/* old command */
10332DEFUN (ipv6_mbgp_neighbor_received_routes,
10333 ipv6_mbgp_neighbor_received_routes_cmd,
10334 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) received-routes",
10335 SHOW_STR
10336 IPV6_STR
10337 MBGP_STR
10338 "Detailed information on TCP and BGP neighbor connections\n"
10339 "Neighbor to display information about\n"
10340 "Neighbor to display information about\n"
10341 "Display the received routes from neighbor\n")
10342{
paulbb46e942003-10-24 19:02:03 +000010343 struct peer *peer;
10344
10345 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10346 if (! peer)
10347 return CMD_WARNING;
10348
10349 return peer_adj_routes (vty, peer, AFI_IP6, SAFI_MULTICAST, 1);
paul718e3742002-12-13 20:15:29 +000010350}
paulbb46e942003-10-24 19:02:03 +000010351
10352DEFUN (show_bgp_view_neighbor_received_prefix_filter,
10353 show_bgp_view_neighbor_received_prefix_filter_cmd,
10354 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10355 SHOW_STR
10356 BGP_STR
10357 "BGP view\n"
10358 "View name\n"
10359 "Detailed information on TCP and BGP neighbor connections\n"
10360 "Neighbor to display information about\n"
10361 "Neighbor to display information about\n"
10362 "Display information received from a BGP neighbor\n"
10363 "Display the prefixlist filter\n")
10364{
10365 char name[BUFSIZ];
10366 union sockunion *su;
10367 struct peer *peer;
10368 struct bgp *bgp;
10369 int count;
10370
10371 /* BGP structure lookup. */
10372 bgp = bgp_lookup_by_name (argv[0]);
10373 if (bgp == NULL)
10374 {
10375 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10376 return CMD_WARNING;
10377 }
10378
10379 su = sockunion_str2su (argv[1]);
10380 if (su == NULL)
10381 return CMD_WARNING;
10382
10383 peer = peer_lookup (bgp, su);
10384 if (! peer)
10385 return CMD_WARNING;
10386
10387 sprintf (name, "%s.%d.%d", peer->host, AFI_IP6, SAFI_UNICAST);
10388 count = prefix_bgp_show_prefix_list (NULL, AFI_IP6, name);
10389 if (count)
10390 {
10391 vty_out (vty, "Address family: IPv6 Unicast%s", VTY_NEWLINE);
10392 prefix_bgp_show_prefix_list (vty, AFI_IP6, name);
10393 }
10394
10395 return CMD_SUCCESS;
10396}
10397
10398ALIAS (show_bgp_view_neighbor_received_prefix_filter,
10399 show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd,
10400 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) received prefix-filter",
10401 SHOW_STR
10402 BGP_STR
10403 "BGP view\n"
10404 "View name\n"
10405 "Address family\n"
10406 "Detailed information on TCP and BGP neighbor connections\n"
10407 "Neighbor to display information about\n"
10408 "Neighbor to display information about\n"
10409 "Display information received from a BGP neighbor\n"
10410 "Display the prefixlist filter\n")
paul718e3742002-12-13 20:15:29 +000010411#endif /* HAVE_IPV6 */
10412
paul94f2b392005-06-28 12:44:16 +000010413static int
paulbb46e942003-10-24 19:02:03 +000010414bgp_show_neighbor_route (struct vty *vty, struct peer *peer, afi_t afi,
paul718e3742002-12-13 20:15:29 +000010415 safi_t safi, enum bgp_show_type type)
10416{
paul718e3742002-12-13 20:15:29 +000010417 if (! peer || ! peer->afc[afi][safi])
10418 {
10419 vty_out (vty, "%% No such neighbor or address family%s", VTY_NEWLINE);
paul718e3742002-12-13 20:15:29 +000010420 return CMD_WARNING;
10421 }
10422
ajs5a646652004-11-05 01:25:55 +000010423 return bgp_show (vty, peer->bgp, afi, safi, type, &peer->su);
paul718e3742002-12-13 20:15:29 +000010424}
10425
10426DEFUN (show_ip_bgp_neighbor_routes,
10427 show_ip_bgp_neighbor_routes_cmd,
10428 "show ip bgp neighbors (A.B.C.D|X:X::X:X) routes",
10429 SHOW_STR
10430 IP_STR
10431 BGP_STR
10432 "Detailed information on TCP and BGP neighbor connections\n"
10433 "Neighbor to display information about\n"
10434 "Neighbor to display information about\n"
10435 "Display routes learned from neighbor\n")
10436{
paulbb46e942003-10-24 19:02:03 +000010437 struct peer *peer;
10438
10439 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10440 if (! peer)
10441 return CMD_WARNING;
10442
10443 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010444 bgp_show_type_neighbor);
10445}
10446
10447DEFUN (show_ip_bgp_neighbor_flap,
10448 show_ip_bgp_neighbor_flap_cmd,
10449 "show ip bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
10450 SHOW_STR
10451 IP_STR
10452 BGP_STR
10453 "Detailed information on TCP and BGP neighbor connections\n"
10454 "Neighbor to display information about\n"
10455 "Neighbor to display information about\n"
10456 "Display flap statistics of the routes learned from neighbor\n")
10457{
paulbb46e942003-10-24 19:02:03 +000010458 struct peer *peer;
10459
10460 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10461 if (! peer)
10462 return CMD_WARNING;
10463
10464 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010465 bgp_show_type_flap_neighbor);
10466}
10467
10468DEFUN (show_ip_bgp_neighbor_damp,
10469 show_ip_bgp_neighbor_damp_cmd,
10470 "show ip bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10471 SHOW_STR
10472 IP_STR
10473 BGP_STR
10474 "Detailed information on TCP and BGP neighbor connections\n"
10475 "Neighbor to display information about\n"
10476 "Neighbor to display information about\n"
10477 "Display the dampened routes received from neighbor\n")
10478{
paulbb46e942003-10-24 19:02:03 +000010479 struct peer *peer;
10480
10481 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10482 if (! peer)
10483 return CMD_WARNING;
10484
10485 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010486 bgp_show_type_damp_neighbor);
10487}
10488
10489DEFUN (show_ip_bgp_ipv4_neighbor_routes,
10490 show_ip_bgp_ipv4_neighbor_routes_cmd,
10491 "show ip bgp ipv4 (unicast|multicast) neighbors (A.B.C.D|X:X::X:X) routes",
10492 SHOW_STR
10493 IP_STR
10494 BGP_STR
10495 "Address family\n"
10496 "Address Family modifier\n"
10497 "Address Family modifier\n"
10498 "Detailed information on TCP and BGP neighbor connections\n"
10499 "Neighbor to display information about\n"
10500 "Neighbor to display information about\n"
10501 "Display routes learned from neighbor\n")
10502{
paulbb46e942003-10-24 19:02:03 +000010503 struct peer *peer;
10504
10505 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10506 if (! peer)
10507 return CMD_WARNING;
10508
paul718e3742002-12-13 20:15:29 +000010509 if (strncmp (argv[0], "m", 1) == 0)
paulbb46e942003-10-24 19:02:03 +000010510 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000010511 bgp_show_type_neighbor);
10512
paulbb46e942003-10-24 19:02:03 +000010513 return bgp_show_neighbor_route (vty, peer, AFI_IP, SAFI_UNICAST,
paul718e3742002-12-13 20:15:29 +000010514 bgp_show_type_neighbor);
10515}
paulbb46e942003-10-24 19:02:03 +000010516
paulfee0f4c2004-09-13 05:12:46 +000010517DEFUN (show_ip_bgp_view_rsclient,
10518 show_ip_bgp_view_rsclient_cmd,
10519 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
10520 SHOW_STR
10521 IP_STR
10522 BGP_STR
10523 "BGP view\n"
10524 "BGP view name\n"
10525 "Information about Route Server Client\n"
10526 NEIGHBOR_ADDR_STR)
10527{
10528 struct bgp_table *table;
10529 struct peer *peer;
10530
10531 if (argc == 2)
10532 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10533 else
10534 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10535
10536 if (! peer)
10537 return CMD_WARNING;
10538
10539 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10540 {
10541 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10542 VTY_NEWLINE);
10543 return CMD_WARNING;
10544 }
10545
10546 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10547 PEER_FLAG_RSERVER_CLIENT))
10548 {
10549 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10550 VTY_NEWLINE);
10551 return CMD_WARNING;
10552 }
10553
10554 table = peer->rib[AFI_IP][SAFI_UNICAST];
10555
ajs5a646652004-11-05 01:25:55 +000010556 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000010557}
10558
10559ALIAS (show_ip_bgp_view_rsclient,
10560 show_ip_bgp_rsclient_cmd,
10561 "show ip bgp rsclient (A.B.C.D|X:X::X:X)",
10562 SHOW_STR
10563 IP_STR
10564 BGP_STR
10565 "Information about Route Server Client\n"
10566 NEIGHBOR_ADDR_STR)
10567
Michael Lambert95cbbd22010-07-23 14:43:04 -040010568DEFUN (show_bgp_view_ipv4_safi_rsclient,
10569 show_bgp_view_ipv4_safi_rsclient_cmd,
10570 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10571 SHOW_STR
10572 BGP_STR
10573 "BGP view\n"
10574 "BGP view name\n"
10575 "Address family\n"
10576 "Address Family modifier\n"
10577 "Address Family modifier\n"
10578 "Information about Route Server Client\n"
10579 NEIGHBOR_ADDR_STR)
10580{
10581 struct bgp_table *table;
10582 struct peer *peer;
10583 safi_t safi;
10584
10585 if (argc == 3) {
10586 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10587 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10588 } else {
10589 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10590 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10591 }
10592
10593 if (! peer)
10594 return CMD_WARNING;
10595
10596 if (! peer->afc[AFI_IP][safi])
10597 {
10598 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10599 VTY_NEWLINE);
10600 return CMD_WARNING;
10601 }
10602
10603 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10604 PEER_FLAG_RSERVER_CLIENT))
10605 {
10606 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10607 VTY_NEWLINE);
10608 return CMD_WARNING;
10609 }
10610
10611 table = peer->rib[AFI_IP][safi];
10612
10613 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
10614}
10615
10616ALIAS (show_bgp_view_ipv4_safi_rsclient,
10617 show_bgp_ipv4_safi_rsclient_cmd,
10618 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
10619 SHOW_STR
10620 BGP_STR
10621 "Address family\n"
10622 "Address Family modifier\n"
10623 "Address Family modifier\n"
10624 "Information about Route Server Client\n"
10625 NEIGHBOR_ADDR_STR)
10626
paulfee0f4c2004-09-13 05:12:46 +000010627DEFUN (show_ip_bgp_view_rsclient_route,
10628 show_ip_bgp_view_rsclient_route_cmd,
Michael Lamberta8bf6f52008-09-24 17:23:11 +010010629 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
paulfee0f4c2004-09-13 05:12:46 +000010630 SHOW_STR
10631 IP_STR
10632 BGP_STR
10633 "BGP view\n"
10634 "BGP view name\n"
10635 "Information about Route Server Client\n"
10636 NEIGHBOR_ADDR_STR
10637 "Network in the BGP routing table to display\n")
10638{
10639 struct bgp *bgp;
10640 struct peer *peer;
10641
10642 /* BGP structure lookup. */
10643 if (argc == 3)
10644 {
10645 bgp = bgp_lookup_by_name (argv[0]);
10646 if (bgp == NULL)
10647 {
10648 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10649 return CMD_WARNING;
10650 }
10651 }
10652 else
10653 {
10654 bgp = bgp_get_default ();
10655 if (bgp == NULL)
10656 {
10657 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10658 return CMD_WARNING;
10659 }
10660 }
10661
10662 if (argc == 3)
10663 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10664 else
10665 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10666
10667 if (! peer)
10668 return CMD_WARNING;
10669
10670 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10671 {
10672 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10673 VTY_NEWLINE);
10674 return CMD_WARNING;
10675}
10676
10677 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10678 PEER_FLAG_RSERVER_CLIENT))
10679 {
10680 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10681 VTY_NEWLINE);
10682 return CMD_WARNING;
10683 }
10684
10685 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10686 (argc == 3) ? argv[2] : argv[1],
10687 AFI_IP, SAFI_UNICAST, NULL, 0);
10688}
10689
10690ALIAS (show_ip_bgp_view_rsclient_route,
10691 show_ip_bgp_rsclient_route_cmd,
10692 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10693 SHOW_STR
10694 IP_STR
10695 BGP_STR
10696 "Information about Route Server Client\n"
10697 NEIGHBOR_ADDR_STR
10698 "Network in the BGP routing table to display\n")
10699
Michael Lambert95cbbd22010-07-23 14:43:04 -040010700DEFUN (show_bgp_view_ipv4_safi_rsclient_route,
10701 show_bgp_view_ipv4_safi_rsclient_route_cmd,
10702 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10703 SHOW_STR
10704 BGP_STR
10705 "BGP view\n"
10706 "BGP view name\n"
10707 "Address family\n"
10708 "Address Family modifier\n"
10709 "Address Family modifier\n"
10710 "Information about Route Server Client\n"
10711 NEIGHBOR_ADDR_STR
10712 "Network in the BGP routing table to display\n")
10713{
10714 struct bgp *bgp;
10715 struct peer *peer;
10716 safi_t safi;
10717
10718 /* BGP structure lookup. */
10719 if (argc == 4)
10720 {
10721 bgp = bgp_lookup_by_name (argv[0]);
10722 if (bgp == NULL)
10723 {
10724 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10725 return CMD_WARNING;
10726 }
10727 }
10728 else
10729 {
10730 bgp = bgp_get_default ();
10731 if (bgp == NULL)
10732 {
10733 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10734 return CMD_WARNING;
10735 }
10736 }
10737
10738 if (argc == 4) {
10739 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10740 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10741 } else {
10742 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10743 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10744 }
10745
10746 if (! peer)
10747 return CMD_WARNING;
10748
10749 if (! peer->afc[AFI_IP][safi])
10750 {
10751 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10752 VTY_NEWLINE);
10753 return CMD_WARNING;
10754}
10755
10756 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10757 PEER_FLAG_RSERVER_CLIENT))
10758 {
10759 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10760 VTY_NEWLINE);
10761 return CMD_WARNING;
10762 }
10763
10764 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10765 (argc == 4) ? argv[3] : argv[2],
10766 AFI_IP, safi, NULL, 0);
10767}
10768
10769ALIAS (show_bgp_view_ipv4_safi_rsclient_route,
10770 show_bgp_ipv4_safi_rsclient_route_cmd,
10771 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D",
10772 SHOW_STR
10773 BGP_STR
10774 "Address family\n"
10775 "Address Family modifier\n"
10776 "Address Family modifier\n"
10777 "Information about Route Server Client\n"
10778 NEIGHBOR_ADDR_STR
10779 "Network in the BGP routing table to display\n")
10780
paulfee0f4c2004-09-13 05:12:46 +000010781DEFUN (show_ip_bgp_view_rsclient_prefix,
10782 show_ip_bgp_view_rsclient_prefix_cmd,
10783 "show ip bgp view WORD rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10784 SHOW_STR
10785 IP_STR
10786 BGP_STR
10787 "BGP view\n"
10788 "BGP view name\n"
10789 "Information about Route Server Client\n"
10790 NEIGHBOR_ADDR_STR
10791 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10792{
10793 struct bgp *bgp;
10794 struct peer *peer;
10795
10796 /* BGP structure lookup. */
10797 if (argc == 3)
10798 {
10799 bgp = bgp_lookup_by_name (argv[0]);
10800 if (bgp == NULL)
10801 {
10802 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10803 return CMD_WARNING;
10804 }
10805 }
10806 else
10807 {
10808 bgp = bgp_get_default ();
10809 if (bgp == NULL)
10810 {
10811 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10812 return CMD_WARNING;
10813 }
10814 }
10815
10816 if (argc == 3)
10817 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10818 else
10819 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10820
10821 if (! peer)
10822 return CMD_WARNING;
10823
10824 if (! peer->afc[AFI_IP][SAFI_UNICAST])
10825 {
10826 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10827 VTY_NEWLINE);
10828 return CMD_WARNING;
10829}
10830
10831 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][SAFI_UNICAST],
10832 PEER_FLAG_RSERVER_CLIENT))
10833{
10834 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10835 VTY_NEWLINE);
10836 return CMD_WARNING;
10837 }
10838
10839 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][SAFI_UNICAST],
10840 (argc == 3) ? argv[2] : argv[1],
10841 AFI_IP, SAFI_UNICAST, NULL, 1);
10842}
10843
10844ALIAS (show_ip_bgp_view_rsclient_prefix,
10845 show_ip_bgp_rsclient_prefix_cmd,
10846 "show ip bgp rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10847 SHOW_STR
10848 IP_STR
10849 BGP_STR
10850 "Information about Route Server Client\n"
10851 NEIGHBOR_ADDR_STR
10852 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10853
Michael Lambert95cbbd22010-07-23 14:43:04 -040010854DEFUN (show_bgp_view_ipv4_safi_rsclient_prefix,
10855 show_bgp_view_ipv4_safi_rsclient_prefix_cmd,
10856 "show bgp view WORD ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10857 SHOW_STR
10858 BGP_STR
10859 "BGP view\n"
10860 "BGP view name\n"
10861 "Address family\n"
10862 "Address Family modifier\n"
10863 "Address Family modifier\n"
10864 "Information about Route Server Client\n"
10865 NEIGHBOR_ADDR_STR
10866 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
10867{
10868 struct bgp *bgp;
10869 struct peer *peer;
10870 safi_t safi;
10871
10872 /* BGP structure lookup. */
10873 if (argc == 4)
10874 {
10875 bgp = bgp_lookup_by_name (argv[0]);
10876 if (bgp == NULL)
10877 {
10878 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
10879 return CMD_WARNING;
10880 }
10881 }
10882 else
10883 {
10884 bgp = bgp_get_default ();
10885 if (bgp == NULL)
10886 {
10887 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
10888 return CMD_WARNING;
10889 }
10890 }
10891
10892 if (argc == 4) {
10893 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
10894 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10895 } else {
10896 peer = peer_lookup_in_view (vty, NULL, argv[1]);
10897 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
10898 }
10899
10900 if (! peer)
10901 return CMD_WARNING;
10902
10903 if (! peer->afc[AFI_IP][safi])
10904 {
10905 vty_out (vty, "%% Activate the neighbor for the address family first%s",
10906 VTY_NEWLINE);
10907 return CMD_WARNING;
10908}
10909
10910 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP][safi],
10911 PEER_FLAG_RSERVER_CLIENT))
10912{
10913 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
10914 VTY_NEWLINE);
10915 return CMD_WARNING;
10916 }
10917
10918 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP][safi],
10919 (argc == 4) ? argv[3] : argv[2],
10920 AFI_IP, safi, NULL, 1);
10921}
10922
10923ALIAS (show_bgp_view_ipv4_safi_rsclient_prefix,
10924 show_bgp_ipv4_safi_rsclient_prefix_cmd,
10925 "show bgp ipv4 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) A.B.C.D/M",
10926 SHOW_STR
10927 BGP_STR
10928 "Address family\n"
10929 "Address Family modifier\n"
10930 "Address Family modifier\n"
10931 "Information about Route Server Client\n"
10932 NEIGHBOR_ADDR_STR
10933 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
paulfee0f4c2004-09-13 05:12:46 +000010934
paul718e3742002-12-13 20:15:29 +000010935#ifdef HAVE_IPV6
paulbb46e942003-10-24 19:02:03 +000010936DEFUN (show_bgp_view_neighbor_routes,
10937 show_bgp_view_neighbor_routes_cmd,
10938 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) routes",
10939 SHOW_STR
10940 BGP_STR
10941 "BGP view\n"
10942 "BGP view name\n"
10943 "Detailed information on TCP and BGP neighbor connections\n"
10944 "Neighbor to display information about\n"
10945 "Neighbor to display information about\n"
10946 "Display routes learned from neighbor\n")
10947{
10948 struct peer *peer;
10949
10950 if (argc == 2)
10951 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10952 else
10953 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10954
10955 if (! peer)
10956 return CMD_WARNING;
10957
10958 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10959 bgp_show_type_neighbor);
10960}
10961
10962ALIAS (show_bgp_view_neighbor_routes,
10963 show_bgp_view_ipv6_neighbor_routes_cmd,
10964 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
10965 SHOW_STR
10966 BGP_STR
10967 "BGP view\n"
10968 "BGP view name\n"
10969 "Address family\n"
10970 "Detailed information on TCP and BGP neighbor connections\n"
10971 "Neighbor to display information about\n"
10972 "Neighbor to display information about\n"
10973 "Display routes learned from neighbor\n")
10974
10975DEFUN (show_bgp_view_neighbor_damp,
10976 show_bgp_view_neighbor_damp_cmd,
10977 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) dampened-routes",
10978 SHOW_STR
10979 BGP_STR
10980 "BGP view\n"
10981 "BGP view name\n"
10982 "Detailed information on TCP and BGP neighbor connections\n"
10983 "Neighbor to display information about\n"
10984 "Neighbor to display information about\n"
10985 "Display the dampened routes received from neighbor\n")
10986{
10987 struct peer *peer;
10988
10989 if (argc == 2)
10990 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
10991 else
10992 peer = peer_lookup_in_view (vty, NULL, argv[0]);
10993
10994 if (! peer)
10995 return CMD_WARNING;
10996
10997 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
10998 bgp_show_type_damp_neighbor);
10999}
11000
11001ALIAS (show_bgp_view_neighbor_damp,
11002 show_bgp_view_ipv6_neighbor_damp_cmd,
11003 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11004 SHOW_STR
11005 BGP_STR
11006 "BGP view\n"
11007 "BGP view name\n"
11008 "Address family\n"
11009 "Detailed information on TCP and BGP neighbor connections\n"
11010 "Neighbor to display information about\n"
11011 "Neighbor to display information about\n"
11012 "Display the dampened routes received from neighbor\n")
11013
11014DEFUN (show_bgp_view_neighbor_flap,
11015 show_bgp_view_neighbor_flap_cmd,
11016 "show bgp view WORD neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11017 SHOW_STR
11018 BGP_STR
11019 "BGP view\n"
11020 "BGP view name\n"
11021 "Detailed information on TCP and BGP neighbor connections\n"
11022 "Neighbor to display information about\n"
11023 "Neighbor to display information about\n"
11024 "Display flap statistics of the routes learned from neighbor\n")
11025{
11026 struct peer *peer;
11027
11028 if (argc == 2)
11029 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11030 else
11031 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11032
11033 if (! peer)
11034 return CMD_WARNING;
11035
11036 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_UNICAST,
11037 bgp_show_type_flap_neighbor);
11038}
11039
11040ALIAS (show_bgp_view_neighbor_flap,
11041 show_bgp_view_ipv6_neighbor_flap_cmd,
11042 "show bgp view WORD ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11043 SHOW_STR
11044 BGP_STR
11045 "BGP view\n"
11046 "BGP view name\n"
11047 "Address family\n"
11048 "Detailed information on TCP and BGP neighbor connections\n"
11049 "Neighbor to display information about\n"
11050 "Neighbor to display information about\n"
11051 "Display flap statistics of the routes learned from neighbor\n")
11052
11053ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011054 show_bgp_neighbor_routes_cmd,
11055 "show bgp neighbors (A.B.C.D|X:X::X:X) routes",
11056 SHOW_STR
11057 BGP_STR
11058 "Detailed information on TCP and BGP neighbor connections\n"
11059 "Neighbor to display information about\n"
11060 "Neighbor to display information about\n"
11061 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011062
paulbb46e942003-10-24 19:02:03 +000011063
11064ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011065 show_bgp_ipv6_neighbor_routes_cmd,
11066 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) routes",
11067 SHOW_STR
11068 BGP_STR
11069 "Address family\n"
11070 "Detailed information on TCP and BGP neighbor connections\n"
11071 "Neighbor to display information about\n"
11072 "Neighbor to display information about\n"
11073 "Display routes learned from neighbor\n")
11074
11075/* old command */
paulbb46e942003-10-24 19:02:03 +000011076ALIAS (show_bgp_view_neighbor_routes,
paul718e3742002-12-13 20:15:29 +000011077 ipv6_bgp_neighbor_routes_cmd,
11078 "show ipv6 bgp neighbors (A.B.C.D|X:X::X:X) routes",
11079 SHOW_STR
11080 IPV6_STR
11081 BGP_STR
11082 "Detailed information on TCP and BGP neighbor connections\n"
11083 "Neighbor to display information about\n"
11084 "Neighbor to display information about\n"
11085 "Display routes learned from neighbor\n")
paul718e3742002-12-13 20:15:29 +000011086
11087/* old command */
11088DEFUN (ipv6_mbgp_neighbor_routes,
11089 ipv6_mbgp_neighbor_routes_cmd,
11090 "show ipv6 mbgp neighbors (A.B.C.D|X:X::X:X) routes",
11091 SHOW_STR
11092 IPV6_STR
11093 MBGP_STR
11094 "Detailed information on TCP and BGP neighbor connections\n"
11095 "Neighbor to display information about\n"
11096 "Neighbor to display information about\n"
11097 "Display routes learned from neighbor\n")
11098{
paulbb46e942003-10-24 19:02:03 +000011099 struct peer *peer;
11100
11101 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11102 if (! peer)
11103 return CMD_WARNING;
11104
11105 return bgp_show_neighbor_route (vty, peer, AFI_IP6, SAFI_MULTICAST,
paul718e3742002-12-13 20:15:29 +000011106 bgp_show_type_neighbor);
11107}
paulbb46e942003-10-24 19:02:03 +000011108
11109ALIAS (show_bgp_view_neighbor_flap,
11110 show_bgp_neighbor_flap_cmd,
11111 "show bgp neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11112 SHOW_STR
11113 BGP_STR
11114 "Detailed information on TCP and BGP neighbor connections\n"
11115 "Neighbor to display information about\n"
11116 "Neighbor to display information about\n"
11117 "Display flap statistics of the routes learned from neighbor\n")
11118
11119ALIAS (show_bgp_view_neighbor_flap,
11120 show_bgp_ipv6_neighbor_flap_cmd,
11121 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) flap-statistics",
11122 SHOW_STR
11123 BGP_STR
11124 "Address family\n"
11125 "Detailed information on TCP and BGP neighbor connections\n"
11126 "Neighbor to display information about\n"
11127 "Neighbor to display information about\n"
11128 "Display flap statistics of the routes learned from neighbor\n")
11129
11130ALIAS (show_bgp_view_neighbor_damp,
11131 show_bgp_neighbor_damp_cmd,
11132 "show bgp neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11133 SHOW_STR
11134 BGP_STR
11135 "Detailed information on TCP and BGP neighbor connections\n"
11136 "Neighbor to display information about\n"
11137 "Neighbor to display information about\n"
11138 "Display the dampened routes received from neighbor\n")
11139
11140ALIAS (show_bgp_view_neighbor_damp,
11141 show_bgp_ipv6_neighbor_damp_cmd,
11142 "show bgp ipv6 neighbors (A.B.C.D|X:X::X:X) dampened-routes",
11143 SHOW_STR
11144 BGP_STR
11145 "Address family\n"
11146 "Detailed information on TCP and BGP neighbor connections\n"
11147 "Neighbor to display information about\n"
11148 "Neighbor to display information about\n"
paulc001ae62003-11-03 12:37:43 +000011149 "Display the dampened routes received from neighbor\n")
paulfee0f4c2004-09-13 05:12:46 +000011150
11151DEFUN (show_bgp_view_rsclient,
11152 show_bgp_view_rsclient_cmd,
11153 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X)",
11154 SHOW_STR
11155 BGP_STR
11156 "BGP view\n"
11157 "BGP view name\n"
11158 "Information about Route Server Client\n"
11159 NEIGHBOR_ADDR_STR)
11160{
11161 struct bgp_table *table;
11162 struct peer *peer;
11163
11164 if (argc == 2)
11165 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11166 else
11167 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11168
11169 if (! peer)
11170 return CMD_WARNING;
11171
11172 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11173 {
11174 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11175 VTY_NEWLINE);
11176 return CMD_WARNING;
11177 }
11178
11179 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11180 PEER_FLAG_RSERVER_CLIENT))
11181 {
11182 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11183 VTY_NEWLINE);
11184 return CMD_WARNING;
11185 }
11186
11187 table = peer->rib[AFI_IP6][SAFI_UNICAST];
11188
ajs5a646652004-11-05 01:25:55 +000011189 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
paulfee0f4c2004-09-13 05:12:46 +000011190}
11191
11192ALIAS (show_bgp_view_rsclient,
11193 show_bgp_rsclient_cmd,
11194 "show bgp rsclient (A.B.C.D|X:X::X:X)",
11195 SHOW_STR
11196 BGP_STR
11197 "Information about Route Server Client\n"
11198 NEIGHBOR_ADDR_STR)
11199
Michael Lambert95cbbd22010-07-23 14:43:04 -040011200DEFUN (show_bgp_view_ipv6_safi_rsclient,
11201 show_bgp_view_ipv6_safi_rsclient_cmd,
11202 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11203 SHOW_STR
11204 BGP_STR
11205 "BGP view\n"
11206 "BGP view name\n"
11207 "Address family\n"
11208 "Address Family modifier\n"
11209 "Address Family modifier\n"
11210 "Information about Route Server Client\n"
11211 NEIGHBOR_ADDR_STR)
11212{
11213 struct bgp_table *table;
11214 struct peer *peer;
11215 safi_t safi;
11216
11217 if (argc == 3) {
11218 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11219 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11220 } else {
11221 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11222 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11223 }
11224
11225 if (! peer)
11226 return CMD_WARNING;
11227
11228 if (! peer->afc[AFI_IP6][safi])
11229 {
11230 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11231 VTY_NEWLINE);
11232 return CMD_WARNING;
11233 }
11234
11235 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11236 PEER_FLAG_RSERVER_CLIENT))
11237 {
11238 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11239 VTY_NEWLINE);
11240 return CMD_WARNING;
11241 }
11242
11243 table = peer->rib[AFI_IP6][safi];
11244
11245 return bgp_show_table (vty, table, &peer->remote_id, bgp_show_type_normal, NULL);
11246}
11247
11248ALIAS (show_bgp_view_ipv6_safi_rsclient,
11249 show_bgp_ipv6_safi_rsclient_cmd,
11250 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X)",
11251 SHOW_STR
11252 BGP_STR
11253 "Address family\n"
11254 "Address Family modifier\n"
11255 "Address Family modifier\n"
11256 "Information about Route Server Client\n"
11257 NEIGHBOR_ADDR_STR)
11258
paulfee0f4c2004-09-13 05:12:46 +000011259DEFUN (show_bgp_view_rsclient_route,
11260 show_bgp_view_rsclient_route_cmd,
11261 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11262 SHOW_STR
11263 BGP_STR
11264 "BGP view\n"
11265 "BGP view name\n"
11266 "Information about Route Server Client\n"
11267 NEIGHBOR_ADDR_STR
11268 "Network in the BGP routing table to display\n")
11269{
11270 struct bgp *bgp;
11271 struct peer *peer;
11272
11273 /* BGP structure lookup. */
11274 if (argc == 3)
11275 {
11276 bgp = bgp_lookup_by_name (argv[0]);
11277 if (bgp == NULL)
11278 {
11279 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11280 return CMD_WARNING;
11281 }
11282 }
11283 else
11284 {
11285 bgp = bgp_get_default ();
11286 if (bgp == NULL)
11287 {
11288 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11289 return CMD_WARNING;
11290 }
11291 }
11292
11293 if (argc == 3)
11294 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11295 else
11296 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11297
11298 if (! peer)
11299 return CMD_WARNING;
11300
11301 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11302 {
11303 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11304 VTY_NEWLINE);
11305 return CMD_WARNING;
11306 }
11307
11308 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11309 PEER_FLAG_RSERVER_CLIENT))
11310 {
11311 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11312 VTY_NEWLINE);
11313 return CMD_WARNING;
11314 }
11315
11316 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11317 (argc == 3) ? argv[2] : argv[1],
11318 AFI_IP6, SAFI_UNICAST, NULL, 0);
11319}
11320
11321ALIAS (show_bgp_view_rsclient_route,
11322 show_bgp_rsclient_route_cmd,
11323 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11324 SHOW_STR
11325 BGP_STR
11326 "Information about Route Server Client\n"
11327 NEIGHBOR_ADDR_STR
11328 "Network in the BGP routing table to display\n")
11329
Michael Lambert95cbbd22010-07-23 14:43:04 -040011330DEFUN (show_bgp_view_ipv6_safi_rsclient_route,
11331 show_bgp_view_ipv6_safi_rsclient_route_cmd,
11332 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11333 SHOW_STR
11334 BGP_STR
11335 "BGP view\n"
11336 "BGP view name\n"
11337 "Address family\n"
11338 "Address Family modifier\n"
11339 "Address Family modifier\n"
11340 "Information about Route Server Client\n"
11341 NEIGHBOR_ADDR_STR
11342 "Network in the BGP routing table to display\n")
11343{
11344 struct bgp *bgp;
11345 struct peer *peer;
11346 safi_t safi;
11347
11348 /* BGP structure lookup. */
11349 if (argc == 4)
11350 {
11351 bgp = bgp_lookup_by_name (argv[0]);
11352 if (bgp == NULL)
11353 {
11354 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11355 return CMD_WARNING;
11356 }
11357 }
11358 else
11359 {
11360 bgp = bgp_get_default ();
11361 if (bgp == NULL)
11362 {
11363 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11364 return CMD_WARNING;
11365 }
11366 }
11367
11368 if (argc == 4) {
11369 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11370 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11371 } else {
11372 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11373 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11374 }
11375
11376 if (! peer)
11377 return CMD_WARNING;
11378
11379 if (! peer->afc[AFI_IP6][safi])
11380 {
11381 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11382 VTY_NEWLINE);
11383 return CMD_WARNING;
11384}
11385
11386 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11387 PEER_FLAG_RSERVER_CLIENT))
11388 {
11389 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11390 VTY_NEWLINE);
11391 return CMD_WARNING;
11392 }
11393
11394 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11395 (argc == 4) ? argv[3] : argv[2],
11396 AFI_IP6, safi, NULL, 0);
11397}
11398
11399ALIAS (show_bgp_view_ipv6_safi_rsclient_route,
11400 show_bgp_ipv6_safi_rsclient_route_cmd,
11401 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X",
11402 SHOW_STR
11403 BGP_STR
11404 "Address family\n"
11405 "Address Family modifier\n"
11406 "Address Family modifier\n"
11407 "Information about Route Server Client\n"
11408 NEIGHBOR_ADDR_STR
11409 "Network in the BGP routing table to display\n")
11410
paulfee0f4c2004-09-13 05:12:46 +000011411DEFUN (show_bgp_view_rsclient_prefix,
11412 show_bgp_view_rsclient_prefix_cmd,
11413 "show bgp view WORD rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11414 SHOW_STR
11415 BGP_STR
11416 "BGP view\n"
11417 "BGP view name\n"
11418 "Information about Route Server Client\n"
11419 NEIGHBOR_ADDR_STR
11420 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11421{
11422 struct bgp *bgp;
11423 struct peer *peer;
11424
11425 /* BGP structure lookup. */
11426 if (argc == 3)
11427 {
11428 bgp = bgp_lookup_by_name (argv[0]);
11429 if (bgp == NULL)
11430 {
11431 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11432 return CMD_WARNING;
11433 }
11434 }
11435 else
11436 {
11437 bgp = bgp_get_default ();
11438 if (bgp == NULL)
11439 {
11440 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11441 return CMD_WARNING;
11442 }
11443 }
11444
11445 if (argc == 3)
11446 peer = peer_lookup_in_view (vty, argv[0], argv[1]);
11447 else
11448 peer = peer_lookup_in_view (vty, NULL, argv[0]);
11449
11450 if (! peer)
11451 return CMD_WARNING;
11452
11453 if (! peer->afc[AFI_IP6][SAFI_UNICAST])
11454 {
11455 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11456 VTY_NEWLINE);
11457 return CMD_WARNING;
11458 }
11459
11460 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][SAFI_UNICAST],
11461 PEER_FLAG_RSERVER_CLIENT))
11462 {
11463 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11464 VTY_NEWLINE);
11465 return CMD_WARNING;
11466 }
11467
11468 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][SAFI_UNICAST],
11469 (argc == 3) ? argv[2] : argv[1],
11470 AFI_IP6, SAFI_UNICAST, NULL, 1);
11471}
11472
11473ALIAS (show_bgp_view_rsclient_prefix,
11474 show_bgp_rsclient_prefix_cmd,
11475 "show bgp rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11476 SHOW_STR
11477 BGP_STR
11478 "Information about Route Server Client\n"
11479 NEIGHBOR_ADDR_STR
11480 "IPv6 prefix <network>/<length>, e.g., 3ffe::/16\n")
11481
Michael Lambert95cbbd22010-07-23 14:43:04 -040011482DEFUN (show_bgp_view_ipv6_safi_rsclient_prefix,
11483 show_bgp_view_ipv6_safi_rsclient_prefix_cmd,
11484 "show bgp view WORD ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11485 SHOW_STR
11486 BGP_STR
11487 "BGP view\n"
11488 "BGP view name\n"
11489 "Address family\n"
11490 "Address Family modifier\n"
11491 "Address Family modifier\n"
11492 "Information about Route Server Client\n"
11493 NEIGHBOR_ADDR_STR
11494 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11495{
11496 struct bgp *bgp;
11497 struct peer *peer;
11498 safi_t safi;
11499
11500 /* BGP structure lookup. */
11501 if (argc == 4)
11502 {
11503 bgp = bgp_lookup_by_name (argv[0]);
11504 if (bgp == NULL)
11505 {
11506 vty_out (vty, "Can't find BGP view %s%s", argv[0], VTY_NEWLINE);
11507 return CMD_WARNING;
11508 }
11509 }
11510 else
11511 {
11512 bgp = bgp_get_default ();
11513 if (bgp == NULL)
11514 {
11515 vty_out (vty, "No BGP process is configured%s", VTY_NEWLINE);
11516 return CMD_WARNING;
11517 }
11518 }
11519
11520 if (argc == 4) {
11521 peer = peer_lookup_in_view (vty, argv[0], argv[2]);
11522 safi = (strncmp (argv[1], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11523 } else {
11524 peer = peer_lookup_in_view (vty, NULL, argv[1]);
11525 safi = (strncmp (argv[0], "m", 1) == 0) ? SAFI_MULTICAST : SAFI_UNICAST;
11526 }
11527
11528 if (! peer)
11529 return CMD_WARNING;
11530
11531 if (! peer->afc[AFI_IP6][safi])
11532 {
11533 vty_out (vty, "%% Activate the neighbor for the address family first%s",
11534 VTY_NEWLINE);
11535 return CMD_WARNING;
11536}
11537
11538 if ( ! CHECK_FLAG (peer->af_flags[AFI_IP6][safi],
11539 PEER_FLAG_RSERVER_CLIENT))
11540{
11541 vty_out (vty, "%% Neighbor is not a Route-Server client%s",
11542 VTY_NEWLINE);
11543 return CMD_WARNING;
11544 }
11545
11546 return bgp_show_route_in_table (vty, bgp, peer->rib[AFI_IP6][safi],
11547 (argc == 4) ? argv[3] : argv[2],
11548 AFI_IP6, safi, NULL, 1);
11549}
11550
11551ALIAS (show_bgp_view_ipv6_safi_rsclient_prefix,
11552 show_bgp_ipv6_safi_rsclient_prefix_cmd,
11553 "show bgp ipv6 (unicast|multicast) rsclient (A.B.C.D|X:X::X:X) X:X::X:X/M",
11554 SHOW_STR
11555 BGP_STR
11556 "Address family\n"
11557 "Address Family modifier\n"
11558 "Address Family modifier\n"
11559 "Information about Route Server Client\n"
11560 NEIGHBOR_ADDR_STR
11561 "IP prefix <network>/<length>, e.g., 3ffe::/16\n")
11562
paul718e3742002-12-13 20:15:29 +000011563#endif /* HAVE_IPV6 */
11564
11565struct bgp_table *bgp_distance_table;
11566
11567struct bgp_distance
11568{
11569 /* Distance value for the IP source prefix. */
11570 u_char distance;
11571
11572 /* Name of the access-list to be matched. */
11573 char *access_list;
11574};
11575
paul94f2b392005-06-28 12:44:16 +000011576static struct bgp_distance *
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080011577bgp_distance_new (void)
paul718e3742002-12-13 20:15:29 +000011578{
Stephen Hemminger393deb92008-08-18 14:13:29 -070011579 return XCALLOC (MTYPE_BGP_DISTANCE, sizeof (struct bgp_distance));
paul718e3742002-12-13 20:15:29 +000011580}
11581
paul94f2b392005-06-28 12:44:16 +000011582static void
paul718e3742002-12-13 20:15:29 +000011583bgp_distance_free (struct bgp_distance *bdistance)
11584{
11585 XFREE (MTYPE_BGP_DISTANCE, bdistance);
11586}
11587
paul94f2b392005-06-28 12:44:16 +000011588static int
paulfd79ac92004-10-13 05:06:08 +000011589bgp_distance_set (struct vty *vty, const char *distance_str,
11590 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011591{
11592 int ret;
11593 struct prefix_ipv4 p;
11594 u_char distance;
11595 struct bgp_node *rn;
11596 struct bgp_distance *bdistance;
11597
11598 ret = str2prefix_ipv4 (ip_str, &p);
11599 if (ret == 0)
11600 {
11601 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11602 return CMD_WARNING;
11603 }
11604
11605 distance = atoi (distance_str);
11606
11607 /* Get BGP distance node. */
11608 rn = bgp_node_get (bgp_distance_table, (struct prefix *) &p);
11609 if (rn->info)
11610 {
11611 bdistance = rn->info;
11612 bgp_unlock_node (rn);
11613 }
11614 else
11615 {
11616 bdistance = bgp_distance_new ();
11617 rn->info = bdistance;
11618 }
11619
11620 /* Set distance value. */
11621 bdistance->distance = distance;
11622
11623 /* Reset access-list configuration. */
11624 if (bdistance->access_list)
11625 {
11626 free (bdistance->access_list);
11627 bdistance->access_list = NULL;
11628 }
11629 if (access_list_str)
11630 bdistance->access_list = strdup (access_list_str);
11631
11632 return CMD_SUCCESS;
11633}
11634
paul94f2b392005-06-28 12:44:16 +000011635static int
paulfd79ac92004-10-13 05:06:08 +000011636bgp_distance_unset (struct vty *vty, const char *distance_str,
11637 const char *ip_str, const char *access_list_str)
paul718e3742002-12-13 20:15:29 +000011638{
11639 int ret;
11640 struct prefix_ipv4 p;
11641 u_char distance;
11642 struct bgp_node *rn;
11643 struct bgp_distance *bdistance;
11644
11645 ret = str2prefix_ipv4 (ip_str, &p);
11646 if (ret == 0)
11647 {
11648 vty_out (vty, "Malformed prefix%s", VTY_NEWLINE);
11649 return CMD_WARNING;
11650 }
11651
11652 distance = atoi (distance_str);
11653
11654 rn = bgp_node_lookup (bgp_distance_table, (struct prefix *)&p);
11655 if (! rn)
11656 {
11657 vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE);
11658 return CMD_WARNING;
11659 }
11660
11661 bdistance = rn->info;
11662
11663 if (bdistance->access_list)
11664 free (bdistance->access_list);
11665 bgp_distance_free (bdistance);
11666
11667 rn->info = NULL;
11668 bgp_unlock_node (rn);
11669 bgp_unlock_node (rn);
11670
11671 return CMD_SUCCESS;
11672}
11673
paul718e3742002-12-13 20:15:29 +000011674/* Apply BGP information to distance method. */
11675u_char
11676bgp_distance_apply (struct prefix *p, struct bgp_info *rinfo, struct bgp *bgp)
11677{
11678 struct bgp_node *rn;
11679 struct prefix_ipv4 q;
11680 struct peer *peer;
11681 struct bgp_distance *bdistance;
11682 struct access_list *alist;
11683 struct bgp_static *bgp_static;
11684
11685 if (! bgp)
11686 return 0;
11687
11688 if (p->family != AF_INET)
11689 return 0;
11690
11691 peer = rinfo->peer;
11692
11693 if (peer->su.sa.sa_family != AF_INET)
11694 return 0;
11695
11696 memset (&q, 0, sizeof (struct prefix_ipv4));
11697 q.family = AF_INET;
11698 q.prefix = peer->su.sin.sin_addr;
11699 q.prefixlen = IPV4_MAX_BITLEN;
11700
11701 /* Check source address. */
11702 rn = bgp_node_match (bgp_distance_table, (struct prefix *) &q);
11703 if (rn)
11704 {
11705 bdistance = rn->info;
11706 bgp_unlock_node (rn);
11707
11708 if (bdistance->access_list)
11709 {
11710 alist = access_list_lookup (AFI_IP, bdistance->access_list);
11711 if (alist && access_list_apply (alist, p) == FILTER_PERMIT)
11712 return bdistance->distance;
11713 }
11714 else
11715 return bdistance->distance;
11716 }
11717
11718 /* Backdoor check. */
11719 rn = bgp_node_lookup (bgp->route[AFI_IP][SAFI_UNICAST], p);
11720 if (rn)
11721 {
11722 bgp_static = rn->info;
11723 bgp_unlock_node (rn);
11724
11725 if (bgp_static->backdoor)
11726 {
11727 if (bgp->distance_local)
11728 return bgp->distance_local;
11729 else
11730 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11731 }
11732 }
11733
11734 if (peer_sort (peer) == BGP_PEER_EBGP)
11735 {
11736 if (bgp->distance_ebgp)
11737 return bgp->distance_ebgp;
11738 return ZEBRA_EBGP_DISTANCE_DEFAULT;
11739 }
11740 else
11741 {
11742 if (bgp->distance_ibgp)
11743 return bgp->distance_ibgp;
11744 return ZEBRA_IBGP_DISTANCE_DEFAULT;
11745 }
11746}
11747
11748DEFUN (bgp_distance,
11749 bgp_distance_cmd,
11750 "distance bgp <1-255> <1-255> <1-255>",
11751 "Define an administrative distance\n"
11752 "BGP distance\n"
11753 "Distance for routes external to the AS\n"
11754 "Distance for routes internal to the AS\n"
11755 "Distance for local routes\n")
11756{
11757 struct bgp *bgp;
11758
11759 bgp = vty->index;
11760
11761 bgp->distance_ebgp = atoi (argv[0]);
11762 bgp->distance_ibgp = atoi (argv[1]);
11763 bgp->distance_local = atoi (argv[2]);
11764 return CMD_SUCCESS;
11765}
11766
11767DEFUN (no_bgp_distance,
11768 no_bgp_distance_cmd,
11769 "no distance bgp <1-255> <1-255> <1-255>",
11770 NO_STR
11771 "Define an administrative distance\n"
11772 "BGP distance\n"
11773 "Distance for routes external to the AS\n"
11774 "Distance for routes internal to the AS\n"
11775 "Distance for local routes\n")
11776{
11777 struct bgp *bgp;
11778
11779 bgp = vty->index;
11780
11781 bgp->distance_ebgp= 0;
11782 bgp->distance_ibgp = 0;
11783 bgp->distance_local = 0;
11784 return CMD_SUCCESS;
11785}
11786
11787ALIAS (no_bgp_distance,
11788 no_bgp_distance2_cmd,
11789 "no distance bgp",
11790 NO_STR
11791 "Define an administrative distance\n"
11792 "BGP distance\n")
11793
11794DEFUN (bgp_distance_source,
11795 bgp_distance_source_cmd,
11796 "distance <1-255> A.B.C.D/M",
11797 "Define an administrative distance\n"
11798 "Administrative distance\n"
11799 "IP source prefix\n")
11800{
11801 bgp_distance_set (vty, argv[0], argv[1], NULL);
11802 return CMD_SUCCESS;
11803}
11804
11805DEFUN (no_bgp_distance_source,
11806 no_bgp_distance_source_cmd,
11807 "no distance <1-255> A.B.C.D/M",
11808 NO_STR
11809 "Define an administrative distance\n"
11810 "Administrative distance\n"
11811 "IP source prefix\n")
11812{
11813 bgp_distance_unset (vty, argv[0], argv[1], NULL);
11814 return CMD_SUCCESS;
11815}
11816
11817DEFUN (bgp_distance_source_access_list,
11818 bgp_distance_source_access_list_cmd,
11819 "distance <1-255> A.B.C.D/M WORD",
11820 "Define an administrative distance\n"
11821 "Administrative distance\n"
11822 "IP source prefix\n"
11823 "Access list name\n")
11824{
11825 bgp_distance_set (vty, argv[0], argv[1], argv[2]);
11826 return CMD_SUCCESS;
11827}
11828
11829DEFUN (no_bgp_distance_source_access_list,
11830 no_bgp_distance_source_access_list_cmd,
11831 "no distance <1-255> A.B.C.D/M WORD",
11832 NO_STR
11833 "Define an administrative distance\n"
11834 "Administrative distance\n"
11835 "IP source prefix\n"
11836 "Access list name\n")
11837{
11838 bgp_distance_unset (vty, argv[0], argv[1], argv[2]);
11839 return CMD_SUCCESS;
11840}
11841
11842DEFUN (bgp_damp_set,
11843 bgp_damp_set_cmd,
11844 "bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11845 "BGP Specific commands\n"
11846 "Enable route-flap dampening\n"
11847 "Half-life time for the penalty\n"
11848 "Value to start reusing a route\n"
11849 "Value to start suppressing a route\n"
11850 "Maximum duration to suppress a stable route\n")
11851{
11852 struct bgp *bgp;
11853 int half = DEFAULT_HALF_LIFE * 60;
11854 int reuse = DEFAULT_REUSE;
11855 int suppress = DEFAULT_SUPPRESS;
11856 int max = 4 * half;
11857
11858 if (argc == 4)
11859 {
11860 half = atoi (argv[0]) * 60;
11861 reuse = atoi (argv[1]);
11862 suppress = atoi (argv[2]);
11863 max = atoi (argv[3]) * 60;
11864 }
11865 else if (argc == 1)
11866 {
11867 half = atoi (argv[0]) * 60;
11868 max = 4 * half;
11869 }
11870
11871 bgp = vty->index;
11872 return bgp_damp_enable (bgp, bgp_node_afi (vty), bgp_node_safi (vty),
11873 half, reuse, suppress, max);
11874}
11875
11876ALIAS (bgp_damp_set,
11877 bgp_damp_set2_cmd,
11878 "bgp dampening <1-45>",
11879 "BGP Specific commands\n"
11880 "Enable route-flap dampening\n"
11881 "Half-life time for the penalty\n")
11882
11883ALIAS (bgp_damp_set,
11884 bgp_damp_set3_cmd,
11885 "bgp dampening",
11886 "BGP Specific commands\n"
11887 "Enable route-flap dampening\n")
11888
11889DEFUN (bgp_damp_unset,
11890 bgp_damp_unset_cmd,
11891 "no bgp dampening",
11892 NO_STR
11893 "BGP Specific commands\n"
11894 "Enable route-flap dampening\n")
11895{
11896 struct bgp *bgp;
11897
11898 bgp = vty->index;
11899 return bgp_damp_disable (bgp, bgp_node_afi (vty), bgp_node_safi (vty));
11900}
11901
11902ALIAS (bgp_damp_unset,
11903 bgp_damp_unset2_cmd,
11904 "no bgp dampening <1-45> <1-20000> <1-20000> <1-255>",
11905 NO_STR
11906 "BGP Specific commands\n"
11907 "Enable route-flap dampening\n"
11908 "Half-life time for the penalty\n"
11909 "Value to start reusing a route\n"
11910 "Value to start suppressing a route\n"
11911 "Maximum duration to suppress a stable route\n")
11912
11913DEFUN (show_ip_bgp_dampened_paths,
11914 show_ip_bgp_dampened_paths_cmd,
11915 "show ip bgp dampened-paths",
11916 SHOW_STR
11917 IP_STR
11918 BGP_STR
11919 "Display paths suppressed due to dampening\n")
11920{
ajs5a646652004-11-05 01:25:55 +000011921 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST, bgp_show_type_dampend_paths,
11922 NULL);
paul718e3742002-12-13 20:15:29 +000011923}
11924
11925DEFUN (show_ip_bgp_flap_statistics,
11926 show_ip_bgp_flap_statistics_cmd,
11927 "show ip bgp flap-statistics",
11928 SHOW_STR
11929 IP_STR
11930 BGP_STR
11931 "Display flap statistics of routes\n")
11932{
ajs5a646652004-11-05 01:25:55 +000011933 return bgp_show (vty, NULL, AFI_IP, SAFI_UNICAST,
11934 bgp_show_type_flap_statistics, NULL);
paul718e3742002-12-13 20:15:29 +000011935}
11936
11937/* Display specified route of BGP table. */
paul94f2b392005-06-28 12:44:16 +000011938static int
paulfd79ac92004-10-13 05:06:08 +000011939bgp_clear_damp_route (struct vty *vty, const char *view_name,
11940 const char *ip_str, afi_t afi, safi_t safi,
11941 struct prefix_rd *prd, int prefix_check)
paul718e3742002-12-13 20:15:29 +000011942{
11943 int ret;
11944 struct prefix match;
11945 struct bgp_node *rn;
11946 struct bgp_node *rm;
11947 struct bgp_info *ri;
11948 struct bgp_info *ri_temp;
11949 struct bgp *bgp;
11950 struct bgp_table *table;
11951
11952 /* BGP structure lookup. */
11953 if (view_name)
11954 {
11955 bgp = bgp_lookup_by_name (view_name);
11956 if (bgp == NULL)
11957 {
11958 vty_out (vty, "%% Can't find BGP view %s%s", view_name, VTY_NEWLINE);
11959 return CMD_WARNING;
11960 }
11961 }
11962 else
11963 {
11964 bgp = bgp_get_default ();
11965 if (bgp == NULL)
11966 {
11967 vty_out (vty, "%% No BGP process is configured%s", VTY_NEWLINE);
11968 return CMD_WARNING;
11969 }
11970 }
11971
11972 /* Check IP address argument. */
11973 ret = str2prefix (ip_str, &match);
11974 if (! ret)
11975 {
11976 vty_out (vty, "%% address is malformed%s", VTY_NEWLINE);
11977 return CMD_WARNING;
11978 }
11979
11980 match.family = afi2family (afi);
11981
11982 if (safi == SAFI_MPLS_VPN)
11983 {
11984 for (rn = bgp_table_top (bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rn; rn = bgp_route_next (rn))
11985 {
11986 if (prd && memcmp (rn->p.u.val, prd->val, 8) != 0)
11987 continue;
11988
11989 if ((table = rn->info) != NULL)
11990 if ((rm = bgp_node_match (table, &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000011991 {
11992 if (! prefix_check || rm->p.prefixlen == match.prefixlen)
11993 {
11994 ri = rm->info;
11995 while (ri)
11996 {
11997 if (ri->extra && ri->extra->damp_info)
11998 {
11999 ri_temp = ri->next;
12000 bgp_damp_info_free (ri->extra->damp_info, 1);
12001 ri = ri_temp;
12002 }
12003 else
12004 ri = ri->next;
12005 }
12006 }
12007
12008 bgp_unlock_node (rm);
12009 }
paul718e3742002-12-13 20:15:29 +000012010 }
12011 }
12012 else
12013 {
12014 if ((rn = bgp_node_match (bgp->rib[afi][safi], &match)) != NULL)
Chris Caputo6c88b442010-07-27 16:28:55 +000012015 {
12016 if (! prefix_check || rn->p.prefixlen == match.prefixlen)
12017 {
12018 ri = rn->info;
12019 while (ri)
12020 {
12021 if (ri->extra && ri->extra->damp_info)
12022 {
12023 ri_temp = ri->next;
12024 bgp_damp_info_free (ri->extra->damp_info, 1);
12025 ri = ri_temp;
12026 }
12027 else
12028 ri = ri->next;
12029 }
12030 }
12031
12032 bgp_unlock_node (rn);
12033 }
paul718e3742002-12-13 20:15:29 +000012034 }
12035
12036 return CMD_SUCCESS;
12037}
12038
12039DEFUN (clear_ip_bgp_dampening,
12040 clear_ip_bgp_dampening_cmd,
12041 "clear ip bgp dampening",
12042 CLEAR_STR
12043 IP_STR
12044 BGP_STR
12045 "Clear route flap dampening information\n")
12046{
12047 bgp_damp_info_clean ();
12048 return CMD_SUCCESS;
12049}
12050
12051DEFUN (clear_ip_bgp_dampening_prefix,
12052 clear_ip_bgp_dampening_prefix_cmd,
12053 "clear ip bgp dampening A.B.C.D/M",
12054 CLEAR_STR
12055 IP_STR
12056 BGP_STR
12057 "Clear route flap dampening information\n"
12058 "IP prefix <network>/<length>, e.g., 35.0.0.0/8\n")
12059{
12060 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12061 SAFI_UNICAST, NULL, 1);
12062}
12063
12064DEFUN (clear_ip_bgp_dampening_address,
12065 clear_ip_bgp_dampening_address_cmd,
12066 "clear ip bgp dampening A.B.C.D",
12067 CLEAR_STR
12068 IP_STR
12069 BGP_STR
12070 "Clear route flap dampening information\n"
12071 "Network to clear damping information\n")
12072{
12073 return bgp_clear_damp_route (vty, NULL, argv[0], AFI_IP,
12074 SAFI_UNICAST, NULL, 0);
12075}
12076
12077DEFUN (clear_ip_bgp_dampening_address_mask,
12078 clear_ip_bgp_dampening_address_mask_cmd,
12079 "clear ip bgp dampening A.B.C.D A.B.C.D",
12080 CLEAR_STR
12081 IP_STR
12082 BGP_STR
12083 "Clear route flap dampening information\n"
12084 "Network to clear damping information\n"
12085 "Network mask\n")
12086{
12087 int ret;
12088 char prefix_str[BUFSIZ];
12089
12090 ret = netmask_str2prefix_str (argv[0], argv[1], prefix_str);
12091 if (! ret)
12092 {
12093 vty_out (vty, "%% Inconsistent address and mask%s", VTY_NEWLINE);
12094 return CMD_WARNING;
12095 }
12096
12097 return bgp_clear_damp_route (vty, NULL, prefix_str, AFI_IP,
12098 SAFI_UNICAST, NULL, 0);
12099}
12100
paul94f2b392005-06-28 12:44:16 +000012101static int
paul718e3742002-12-13 20:15:29 +000012102bgp_config_write_network_vpnv4 (struct vty *vty, struct bgp *bgp,
12103 afi_t afi, safi_t safi, int *write)
12104{
12105 struct bgp_node *prn;
12106 struct bgp_node *rn;
12107 struct bgp_table *table;
12108 struct prefix *p;
12109 struct prefix_rd *prd;
12110 struct bgp_static *bgp_static;
12111 u_int32_t label;
12112 char buf[SU_ADDRSTRLEN];
12113 char rdbuf[RD_ADDRSTRLEN];
12114
12115 /* Network configuration. */
12116 for (prn = bgp_table_top (bgp->route[afi][safi]); prn; prn = bgp_route_next (prn))
12117 if ((table = prn->info) != NULL)
12118 for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn))
12119 if ((bgp_static = rn->info) != NULL)
12120 {
12121 p = &rn->p;
12122 prd = (struct prefix_rd *) &prn->p;
12123
12124 /* "address-family" display. */
12125 bgp_config_write_family_header (vty, afi, safi, write);
12126
12127 /* "network" configuration display. */
12128 prefix_rd2str (prd, rdbuf, RD_ADDRSTRLEN);
12129 label = decode_label (bgp_static->tag);
12130
12131 vty_out (vty, " network %s/%d rd %s tag %d",
12132 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12133 p->prefixlen,
12134 rdbuf, label);
12135 vty_out (vty, "%s", VTY_NEWLINE);
12136 }
12137 return 0;
12138}
12139
12140/* Configuration of static route announcement and aggregate
12141 information. */
12142int
12143bgp_config_write_network (struct vty *vty, struct bgp *bgp,
12144 afi_t afi, safi_t safi, int *write)
12145{
12146 struct bgp_node *rn;
12147 struct prefix *p;
12148 struct bgp_static *bgp_static;
12149 struct bgp_aggregate *bgp_aggregate;
12150 char buf[SU_ADDRSTRLEN];
12151
12152 if (afi == AFI_IP && safi == SAFI_MPLS_VPN)
12153 return bgp_config_write_network_vpnv4 (vty, bgp, afi, safi, write);
12154
12155 /* Network configuration. */
12156 for (rn = bgp_table_top (bgp->route[afi][safi]); rn; rn = bgp_route_next (rn))
12157 if ((bgp_static = rn->info) != NULL)
12158 {
12159 p = &rn->p;
12160
12161 /* "address-family" display. */
12162 bgp_config_write_family_header (vty, afi, safi, write);
12163
12164 /* "network" configuration display. */
12165 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12166 {
12167 u_int32_t destination;
12168 struct in_addr netmask;
12169
12170 destination = ntohl (p->u.prefix4.s_addr);
12171 masklen2ip (p->prefixlen, &netmask);
12172 vty_out (vty, " network %s",
12173 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN));
12174
12175 if ((IN_CLASSC (destination) && p->prefixlen == 24)
12176 || (IN_CLASSB (destination) && p->prefixlen == 16)
12177 || (IN_CLASSA (destination) && p->prefixlen == 8)
12178 || p->u.prefix4.s_addr == 0)
12179 {
12180 /* Natural mask is not display. */
12181 }
12182 else
12183 vty_out (vty, " mask %s", inet_ntoa (netmask));
12184 }
12185 else
12186 {
12187 vty_out (vty, " network %s/%d",
12188 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12189 p->prefixlen);
12190 }
12191
12192 if (bgp_static->rmap.name)
12193 vty_out (vty, " route-map %s", bgp_static->rmap.name);
Paul Jakma41367172007-08-06 15:24:51 +000012194 else
12195 {
12196 if (bgp_static->backdoor)
12197 vty_out (vty, " backdoor");
Paul Jakma41367172007-08-06 15:24:51 +000012198 }
paul718e3742002-12-13 20:15:29 +000012199
12200 vty_out (vty, "%s", VTY_NEWLINE);
12201 }
12202
12203 /* Aggregate-address configuration. */
12204 for (rn = bgp_table_top (bgp->aggregate[afi][safi]); rn; rn = bgp_route_next (rn))
12205 if ((bgp_aggregate = rn->info) != NULL)
12206 {
12207 p = &rn->p;
12208
12209 /* "address-family" display. */
12210 bgp_config_write_family_header (vty, afi, safi, write);
12211
12212 if (bgp_option_check (BGP_OPT_CONFIG_CISCO) && afi == AFI_IP)
12213 {
12214 struct in_addr netmask;
12215
12216 masklen2ip (p->prefixlen, &netmask);
12217 vty_out (vty, " aggregate-address %s %s",
12218 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12219 inet_ntoa (netmask));
12220 }
12221 else
12222 {
12223 vty_out (vty, " aggregate-address %s/%d",
12224 inet_ntop (p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
12225 p->prefixlen);
12226 }
12227
12228 if (bgp_aggregate->as_set)
12229 vty_out (vty, " as-set");
12230
12231 if (bgp_aggregate->summary_only)
12232 vty_out (vty, " summary-only");
12233
12234 vty_out (vty, "%s", VTY_NEWLINE);
12235 }
12236
12237 return 0;
12238}
12239
12240int
12241bgp_config_write_distance (struct vty *vty, struct bgp *bgp)
12242{
12243 struct bgp_node *rn;
12244 struct bgp_distance *bdistance;
12245
12246 /* Distance configuration. */
12247 if (bgp->distance_ebgp
12248 && bgp->distance_ibgp
12249 && bgp->distance_local
12250 && (bgp->distance_ebgp != ZEBRA_EBGP_DISTANCE_DEFAULT
12251 || bgp->distance_ibgp != ZEBRA_IBGP_DISTANCE_DEFAULT
12252 || bgp->distance_local != ZEBRA_IBGP_DISTANCE_DEFAULT))
12253 vty_out (vty, " distance bgp %d %d %d%s",
12254 bgp->distance_ebgp, bgp->distance_ibgp, bgp->distance_local,
12255 VTY_NEWLINE);
12256
12257 for (rn = bgp_table_top (bgp_distance_table); rn; rn = bgp_route_next (rn))
12258 if ((bdistance = rn->info) != NULL)
12259 {
12260 vty_out (vty, " distance %d %s/%d %s%s", bdistance->distance,
12261 inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen,
12262 bdistance->access_list ? bdistance->access_list : "",
12263 VTY_NEWLINE);
12264 }
12265
12266 return 0;
12267}
12268
12269/* Allocate routing table structure and install commands. */
12270void
Stephen Hemminger66e5cd82009-02-09 10:14:16 -080012271bgp_route_init (void)
paul718e3742002-12-13 20:15:29 +000012272{
12273 /* Init BGP distance table. */
Paul Jakma64e580a2006-02-21 01:09:01 +000012274 bgp_distance_table = bgp_table_init (AFI_IP, SAFI_UNICAST);
paul718e3742002-12-13 20:15:29 +000012275
12276 /* IPv4 BGP commands. */
12277 install_element (BGP_NODE, &bgp_network_cmd);
12278 install_element (BGP_NODE, &bgp_network_mask_cmd);
12279 install_element (BGP_NODE, &bgp_network_mask_natural_cmd);
12280 install_element (BGP_NODE, &bgp_network_route_map_cmd);
12281 install_element (BGP_NODE, &bgp_network_mask_route_map_cmd);
12282 install_element (BGP_NODE, &bgp_network_mask_natural_route_map_cmd);
12283 install_element (BGP_NODE, &bgp_network_backdoor_cmd);
12284 install_element (BGP_NODE, &bgp_network_mask_backdoor_cmd);
12285 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_cmd);
12286 install_element (BGP_NODE, &no_bgp_network_cmd);
12287 install_element (BGP_NODE, &no_bgp_network_mask_cmd);
12288 install_element (BGP_NODE, &no_bgp_network_mask_natural_cmd);
12289 install_element (BGP_NODE, &no_bgp_network_route_map_cmd);
12290 install_element (BGP_NODE, &no_bgp_network_mask_route_map_cmd);
12291 install_element (BGP_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12292 install_element (BGP_NODE, &no_bgp_network_backdoor_cmd);
12293 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_cmd);
12294 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_cmd);
12295
12296 install_element (BGP_NODE, &aggregate_address_cmd);
12297 install_element (BGP_NODE, &aggregate_address_mask_cmd);
12298 install_element (BGP_NODE, &aggregate_address_summary_only_cmd);
12299 install_element (BGP_NODE, &aggregate_address_mask_summary_only_cmd);
12300 install_element (BGP_NODE, &aggregate_address_as_set_cmd);
12301 install_element (BGP_NODE, &aggregate_address_mask_as_set_cmd);
12302 install_element (BGP_NODE, &aggregate_address_as_set_summary_cmd);
12303 install_element (BGP_NODE, &aggregate_address_mask_as_set_summary_cmd);
12304 install_element (BGP_NODE, &aggregate_address_summary_as_set_cmd);
12305 install_element (BGP_NODE, &aggregate_address_mask_summary_as_set_cmd);
12306 install_element (BGP_NODE, &no_aggregate_address_cmd);
12307 install_element (BGP_NODE, &no_aggregate_address_summary_only_cmd);
12308 install_element (BGP_NODE, &no_aggregate_address_as_set_cmd);
12309 install_element (BGP_NODE, &no_aggregate_address_as_set_summary_cmd);
12310 install_element (BGP_NODE, &no_aggregate_address_summary_as_set_cmd);
12311 install_element (BGP_NODE, &no_aggregate_address_mask_cmd);
12312 install_element (BGP_NODE, &no_aggregate_address_mask_summary_only_cmd);
12313 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_cmd);
12314 install_element (BGP_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12315 install_element (BGP_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12316
12317 /* IPv4 unicast configuration. */
12318 install_element (BGP_IPV4_NODE, &bgp_network_cmd);
12319 install_element (BGP_IPV4_NODE, &bgp_network_mask_cmd);
12320 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_cmd);
12321 install_element (BGP_IPV4_NODE, &bgp_network_route_map_cmd);
12322 install_element (BGP_IPV4_NODE, &bgp_network_mask_route_map_cmd);
12323 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012324 install_element (BGP_IPV4_NODE, &no_bgp_network_cmd);
paul718e3742002-12-13 20:15:29 +000012325 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_cmd);
12326 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_cmd);
12327 install_element (BGP_IPV4_NODE, &no_bgp_network_route_map_cmd);
12328 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_route_map_cmd);
12329 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_route_map_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012330
paul718e3742002-12-13 20:15:29 +000012331 install_element (BGP_IPV4_NODE, &aggregate_address_cmd);
12332 install_element (BGP_IPV4_NODE, &aggregate_address_mask_cmd);
12333 install_element (BGP_IPV4_NODE, &aggregate_address_summary_only_cmd);
12334 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_only_cmd);
12335 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_cmd);
12336 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_cmd);
12337 install_element (BGP_IPV4_NODE, &aggregate_address_as_set_summary_cmd);
12338 install_element (BGP_IPV4_NODE, &aggregate_address_mask_as_set_summary_cmd);
12339 install_element (BGP_IPV4_NODE, &aggregate_address_summary_as_set_cmd);
12340 install_element (BGP_IPV4_NODE, &aggregate_address_mask_summary_as_set_cmd);
12341 install_element (BGP_IPV4_NODE, &no_aggregate_address_cmd);
12342 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_only_cmd);
12343 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_cmd);
12344 install_element (BGP_IPV4_NODE, &no_aggregate_address_as_set_summary_cmd);
12345 install_element (BGP_IPV4_NODE, &no_aggregate_address_summary_as_set_cmd);
12346 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_cmd);
12347 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_only_cmd);
12348 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_cmd);
12349 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12350 install_element (BGP_IPV4_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12351
12352 /* IPv4 multicast configuration. */
12353 install_element (BGP_IPV4M_NODE, &bgp_network_cmd);
12354 install_element (BGP_IPV4M_NODE, &bgp_network_mask_cmd);
12355 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_cmd);
12356 install_element (BGP_IPV4M_NODE, &bgp_network_route_map_cmd);
12357 install_element (BGP_IPV4M_NODE, &bgp_network_mask_route_map_cmd);
12358 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_route_map_cmd);
12359 install_element (BGP_IPV4M_NODE, &no_bgp_network_cmd);
12360 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_cmd);
12361 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_cmd);
12362 install_element (BGP_IPV4M_NODE, &no_bgp_network_route_map_cmd);
12363 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_route_map_cmd);
12364 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_route_map_cmd);
12365 install_element (BGP_IPV4M_NODE, &aggregate_address_cmd);
12366 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_cmd);
12367 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_only_cmd);
12368 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_only_cmd);
12369 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_cmd);
12370 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_cmd);
12371 install_element (BGP_IPV4M_NODE, &aggregate_address_as_set_summary_cmd);
12372 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_as_set_summary_cmd);
12373 install_element (BGP_IPV4M_NODE, &aggregate_address_summary_as_set_cmd);
12374 install_element (BGP_IPV4M_NODE, &aggregate_address_mask_summary_as_set_cmd);
12375 install_element (BGP_IPV4M_NODE, &no_aggregate_address_cmd);
12376 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_only_cmd);
12377 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_cmd);
12378 install_element (BGP_IPV4M_NODE, &no_aggregate_address_as_set_summary_cmd);
12379 install_element (BGP_IPV4M_NODE, &no_aggregate_address_summary_as_set_cmd);
12380 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_cmd);
12381 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_only_cmd);
12382 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_cmd);
12383 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_as_set_summary_cmd);
12384 install_element (BGP_IPV4M_NODE, &no_aggregate_address_mask_summary_as_set_cmd);
12385
12386 install_element (VIEW_NODE, &show_ip_bgp_cmd);
12387 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012388 install_element (VIEW_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012389 install_element (VIEW_NODE, &show_ip_bgp_route_cmd);
12390 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012391 install_element (VIEW_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012392 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12393 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12394 install_element (VIEW_NODE, &show_ip_bgp_prefix_cmd);
12395 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012396 install_element (VIEW_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012397 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12398 install_element (VIEW_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12399 install_element (VIEW_NODE, &show_ip_bgp_view_cmd);
12400 install_element (VIEW_NODE, &show_ip_bgp_view_route_cmd);
12401 install_element (VIEW_NODE, &show_ip_bgp_view_prefix_cmd);
12402 install_element (VIEW_NODE, &show_ip_bgp_regexp_cmd);
12403 install_element (VIEW_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12404 install_element (VIEW_NODE, &show_ip_bgp_prefix_list_cmd);
12405 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12406 install_element (VIEW_NODE, &show_ip_bgp_filter_list_cmd);
12407 install_element (VIEW_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12408 install_element (VIEW_NODE, &show_ip_bgp_route_map_cmd);
12409 install_element (VIEW_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12410 install_element (VIEW_NODE, &show_ip_bgp_cidr_only_cmd);
12411 install_element (VIEW_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12412 install_element (VIEW_NODE, &show_ip_bgp_community_all_cmd);
12413 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12414 install_element (VIEW_NODE, &show_ip_bgp_community_cmd);
12415 install_element (VIEW_NODE, &show_ip_bgp_community2_cmd);
12416 install_element (VIEW_NODE, &show_ip_bgp_community3_cmd);
12417 install_element (VIEW_NODE, &show_ip_bgp_community4_cmd);
12418 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_cmd);
12419 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_cmd);
12420 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_cmd);
12421 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012422 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12423 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community_cmd);
12424 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community2_cmd);
12425 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community3_cmd);
12426 install_element (VIEW_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012427 install_element (VIEW_NODE, &show_ip_bgp_community_exact_cmd);
12428 install_element (VIEW_NODE, &show_ip_bgp_community2_exact_cmd);
12429 install_element (VIEW_NODE, &show_ip_bgp_community3_exact_cmd);
12430 install_element (VIEW_NODE, &show_ip_bgp_community4_exact_cmd);
12431 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12432 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12433 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12434 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12435 install_element (VIEW_NODE, &show_ip_bgp_community_list_cmd);
12436 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12437 install_element (VIEW_NODE, &show_ip_bgp_community_list_exact_cmd);
12438 install_element (VIEW_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12439 install_element (VIEW_NODE, &show_ip_bgp_prefix_longer_cmd);
12440 install_element (VIEW_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12441 install_element (VIEW_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12442 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12443 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12444 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012445 install_element (VIEW_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012446 install_element (VIEW_NODE, &show_ip_bgp_neighbor_routes_cmd);
12447 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12448 install_element (VIEW_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12449 install_element (VIEW_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12450 install_element (VIEW_NODE, &show_ip_bgp_dampened_paths_cmd);
12451 install_element (VIEW_NODE, &show_ip_bgp_flap_statistics_cmd);
12452 install_element (VIEW_NODE, &show_ip_bgp_flap_address_cmd);
12453 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_cmd);
12454 install_element (VIEW_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12455 install_element (VIEW_NODE, &show_ip_bgp_flap_regexp_cmd);
12456 install_element (VIEW_NODE, &show_ip_bgp_flap_filter_list_cmd);
12457 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12458 install_element (VIEW_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12459 install_element (VIEW_NODE, &show_ip_bgp_flap_route_map_cmd);
12460 install_element (VIEW_NODE, &show_ip_bgp_neighbor_flap_cmd);
12461 install_element (VIEW_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012462 install_element (VIEW_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012463 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012464 install_element (VIEW_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012465 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012466 install_element (VIEW_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012467 install_element (VIEW_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012468 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12469 install_element (VIEW_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012470 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012471 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012472 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012473 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012474 install_element (VIEW_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012475 install_element (VIEW_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012476
12477 /* Restricted node: VIEW_NODE - (set of dangerous commands) */
12478 install_element (RESTRICTED_NODE, &show_ip_bgp_route_cmd);
12479 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012480 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012481 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12482 install_element (RESTRICTED_NODE, &show_ip_bgp_prefix_cmd);
12483 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012484 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012485 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12486 install_element (RESTRICTED_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12487 install_element (RESTRICTED_NODE, &show_ip_bgp_view_route_cmd);
12488 install_element (RESTRICTED_NODE, &show_ip_bgp_view_prefix_cmd);
12489 install_element (RESTRICTED_NODE, &show_ip_bgp_community_cmd);
12490 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_cmd);
12491 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_cmd);
12492 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_cmd);
12493 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_cmd);
12494 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_cmd);
12495 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_cmd);
12496 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012497 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12498 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community_cmd);
12499 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community2_cmd);
12500 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community3_cmd);
12501 install_element (RESTRICTED_NODE, &show_bgp_view_afi_safi_community4_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012502 install_element (RESTRICTED_NODE, &show_ip_bgp_community_exact_cmd);
12503 install_element (RESTRICTED_NODE, &show_ip_bgp_community2_exact_cmd);
12504 install_element (RESTRICTED_NODE, &show_ip_bgp_community3_exact_cmd);
12505 install_element (RESTRICTED_NODE, &show_ip_bgp_community4_exact_cmd);
12506 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12507 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12508 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12509 install_element (RESTRICTED_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12510 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012511 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012512 install_element (RESTRICTED_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012513 install_element (RESTRICTED_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012514 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012515 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012516 install_element (RESTRICTED_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012517 install_element (RESTRICTED_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012518
12519 install_element (ENABLE_NODE, &show_ip_bgp_cmd);
12520 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012521 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012522 install_element (ENABLE_NODE, &show_ip_bgp_route_cmd);
12523 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012524 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012525 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_route_cmd);
12526 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_route_cmd);
12527 install_element (ENABLE_NODE, &show_ip_bgp_prefix_cmd);
12528 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012529 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012530 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_all_prefix_cmd);
12531 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_rd_prefix_cmd);
12532 install_element (ENABLE_NODE, &show_ip_bgp_view_cmd);
12533 install_element (ENABLE_NODE, &show_ip_bgp_view_route_cmd);
12534 install_element (ENABLE_NODE, &show_ip_bgp_view_prefix_cmd);
12535 install_element (ENABLE_NODE, &show_ip_bgp_regexp_cmd);
12536 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_regexp_cmd);
12537 install_element (ENABLE_NODE, &show_ip_bgp_prefix_list_cmd);
12538 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_list_cmd);
12539 install_element (ENABLE_NODE, &show_ip_bgp_filter_list_cmd);
12540 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_filter_list_cmd);
12541 install_element (ENABLE_NODE, &show_ip_bgp_route_map_cmd);
12542 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_route_map_cmd);
12543 install_element (ENABLE_NODE, &show_ip_bgp_cidr_only_cmd);
12544 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_cidr_only_cmd);
12545 install_element (ENABLE_NODE, &show_ip_bgp_community_all_cmd);
12546 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_all_cmd);
12547 install_element (ENABLE_NODE, &show_ip_bgp_community_cmd);
12548 install_element (ENABLE_NODE, &show_ip_bgp_community2_cmd);
12549 install_element (ENABLE_NODE, &show_ip_bgp_community3_cmd);
12550 install_element (ENABLE_NODE, &show_ip_bgp_community4_cmd);
12551 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_cmd);
12552 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_cmd);
12553 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_cmd);
12554 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012555 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_all_cmd);
12556 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community_cmd);
12557 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community2_cmd);
12558 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community3_cmd);
12559 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_community4_cmd);
paul718e3742002-12-13 20:15:29 +000012560 install_element (ENABLE_NODE, &show_ip_bgp_community_exact_cmd);
12561 install_element (ENABLE_NODE, &show_ip_bgp_community2_exact_cmd);
12562 install_element (ENABLE_NODE, &show_ip_bgp_community3_exact_cmd);
12563 install_element (ENABLE_NODE, &show_ip_bgp_community4_exact_cmd);
12564 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_exact_cmd);
12565 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community2_exact_cmd);
12566 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community3_exact_cmd);
12567 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community4_exact_cmd);
12568 install_element (ENABLE_NODE, &show_ip_bgp_community_list_cmd);
12569 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_cmd);
12570 install_element (ENABLE_NODE, &show_ip_bgp_community_list_exact_cmd);
12571 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_community_list_exact_cmd);
12572 install_element (ENABLE_NODE, &show_ip_bgp_prefix_longer_cmd);
12573 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_prefix_longer_cmd);
12574 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_advertised_route_cmd);
12575 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_advertised_route_cmd);
12576 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_routes_cmd);
12577 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_routes_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012578 install_element (ENABLE_NODE, &show_bgp_view_afi_safi_neighbor_adv_recd_routes_cmd);
paul718e3742002-12-13 20:15:29 +000012579 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_routes_cmd);
12580 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_routes_cmd);
12581 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_received_prefix_filter_cmd);
12582 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_received_prefix_filter_cmd);
12583 install_element (ENABLE_NODE, &show_ip_bgp_dampened_paths_cmd);
12584 install_element (ENABLE_NODE, &show_ip_bgp_flap_statistics_cmd);
12585 install_element (ENABLE_NODE, &show_ip_bgp_flap_address_cmd);
12586 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_cmd);
12587 install_element (ENABLE_NODE, &show_ip_bgp_flap_cidr_only_cmd);
12588 install_element (ENABLE_NODE, &show_ip_bgp_flap_regexp_cmd);
12589 install_element (ENABLE_NODE, &show_ip_bgp_flap_filter_list_cmd);
12590 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_list_cmd);
12591 install_element (ENABLE_NODE, &show_ip_bgp_flap_prefix_longer_cmd);
12592 install_element (ENABLE_NODE, &show_ip_bgp_flap_route_map_cmd);
12593 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_flap_cmd);
12594 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012595 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012596 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012597 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012598 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012599 install_element (ENABLE_NODE, &show_ip_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012600 install_element (ENABLE_NODE, &show_bgp_ipv4_safi_rsclient_prefix_cmd);
Tomasz Pala2a71e9c2009-06-24 21:36:50 +010012601 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_advertised_route_cmd);
12602 install_element (ENABLE_NODE, &show_ip_bgp_view_neighbor_received_routes_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012603 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012604 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012605 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012606 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012607 install_element (ENABLE_NODE, &show_ip_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012608 install_element (ENABLE_NODE, &show_bgp_view_ipv4_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012609
12610 /* BGP dampening clear commands */
12611 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_cmd);
12612 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_prefix_cmd);
12613 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_cmd);
12614 install_element (ENABLE_NODE, &clear_ip_bgp_dampening_address_mask_cmd);
12615
Paul Jakmaff7924f2006-09-04 01:10:36 +000012616 /* prefix count */
12617 install_element (ENABLE_NODE, &show_ip_bgp_neighbor_prefix_counts_cmd);
12618 install_element (ENABLE_NODE, &show_ip_bgp_ipv4_neighbor_prefix_counts_cmd);
12619 install_element (ENABLE_NODE, &show_ip_bgp_vpnv4_neighbor_prefix_counts_cmd);
paul718e3742002-12-13 20:15:29 +000012620#ifdef HAVE_IPV6
Paul Jakmaff7924f2006-09-04 01:10:36 +000012621 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_prefix_counts_cmd);
12622
paul718e3742002-12-13 20:15:29 +000012623 /* New config IPv6 BGP commands. */
12624 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_cmd);
12625 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_route_map_cmd);
12626 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_cmd);
12627 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_route_map_cmd);
12628
12629 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_cmd);
12630 install_element (BGP_IPV6_NODE, &ipv6_aggregate_address_summary_only_cmd);
12631 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_cmd);
12632 install_element (BGP_IPV6_NODE, &no_ipv6_aggregate_address_summary_only_cmd);
12633
12634 /* Old config IPv6 BGP commands. */
12635 install_element (BGP_NODE, &old_ipv6_bgp_network_cmd);
12636 install_element (BGP_NODE, &old_no_ipv6_bgp_network_cmd);
12637
12638 install_element (BGP_NODE, &old_ipv6_aggregate_address_cmd);
12639 install_element (BGP_NODE, &old_ipv6_aggregate_address_summary_only_cmd);
12640 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_cmd);
12641 install_element (BGP_NODE, &old_no_ipv6_aggregate_address_summary_only_cmd);
12642
12643 install_element (VIEW_NODE, &show_bgp_cmd);
12644 install_element (VIEW_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012645 install_element (VIEW_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012646 install_element (VIEW_NODE, &show_bgp_route_cmd);
12647 install_element (VIEW_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012648 install_element (VIEW_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012649 install_element (VIEW_NODE, &show_bgp_prefix_cmd);
12650 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012651 install_element (VIEW_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012652 install_element (VIEW_NODE, &show_bgp_regexp_cmd);
12653 install_element (VIEW_NODE, &show_bgp_ipv6_regexp_cmd);
12654 install_element (VIEW_NODE, &show_bgp_prefix_list_cmd);
12655 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_list_cmd);
12656 install_element (VIEW_NODE, &show_bgp_filter_list_cmd);
12657 install_element (VIEW_NODE, &show_bgp_ipv6_filter_list_cmd);
12658 install_element (VIEW_NODE, &show_bgp_route_map_cmd);
12659 install_element (VIEW_NODE, &show_bgp_ipv6_route_map_cmd);
12660 install_element (VIEW_NODE, &show_bgp_community_all_cmd);
12661 install_element (VIEW_NODE, &show_bgp_ipv6_community_all_cmd);
12662 install_element (VIEW_NODE, &show_bgp_community_cmd);
12663 install_element (VIEW_NODE, &show_bgp_ipv6_community_cmd);
12664 install_element (VIEW_NODE, &show_bgp_community2_cmd);
12665 install_element (VIEW_NODE, &show_bgp_ipv6_community2_cmd);
12666 install_element (VIEW_NODE, &show_bgp_community3_cmd);
12667 install_element (VIEW_NODE, &show_bgp_ipv6_community3_cmd);
12668 install_element (VIEW_NODE, &show_bgp_community4_cmd);
12669 install_element (VIEW_NODE, &show_bgp_ipv6_community4_cmd);
12670 install_element (VIEW_NODE, &show_bgp_community_exact_cmd);
12671 install_element (VIEW_NODE, &show_bgp_ipv6_community_exact_cmd);
12672 install_element (VIEW_NODE, &show_bgp_community2_exact_cmd);
12673 install_element (VIEW_NODE, &show_bgp_ipv6_community2_exact_cmd);
12674 install_element (VIEW_NODE, &show_bgp_community3_exact_cmd);
12675 install_element (VIEW_NODE, &show_bgp_ipv6_community3_exact_cmd);
12676 install_element (VIEW_NODE, &show_bgp_community4_exact_cmd);
12677 install_element (VIEW_NODE, &show_bgp_ipv6_community4_exact_cmd);
12678 install_element (VIEW_NODE, &show_bgp_community_list_cmd);
12679 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_cmd);
12680 install_element (VIEW_NODE, &show_bgp_community_list_exact_cmd);
12681 install_element (VIEW_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12682 install_element (VIEW_NODE, &show_bgp_prefix_longer_cmd);
12683 install_element (VIEW_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12684 install_element (VIEW_NODE, &show_bgp_neighbor_advertised_route_cmd);
12685 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12686 install_element (VIEW_NODE, &show_bgp_neighbor_received_routes_cmd);
12687 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12688 install_element (VIEW_NODE, &show_bgp_neighbor_routes_cmd);
12689 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12690 install_element (VIEW_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12691 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012692 install_element (VIEW_NODE, &show_bgp_neighbor_flap_cmd);
12693 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12694 install_element (VIEW_NODE, &show_bgp_neighbor_damp_cmd);
12695 install_element (VIEW_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012696 install_element (VIEW_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012697 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012698 install_element (VIEW_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012699 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012700 install_element (VIEW_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012701 install_element (VIEW_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012702 install_element (VIEW_NODE, &show_bgp_view_cmd);
12703 install_element (VIEW_NODE, &show_bgp_view_ipv6_cmd);
12704 install_element (VIEW_NODE, &show_bgp_view_route_cmd);
12705 install_element (VIEW_NODE, &show_bgp_view_ipv6_route_cmd);
12706 install_element (VIEW_NODE, &show_bgp_view_prefix_cmd);
12707 install_element (VIEW_NODE, &show_bgp_view_ipv6_prefix_cmd);
12708 install_element (VIEW_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12709 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12710 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12711 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12712 install_element (VIEW_NODE, &show_bgp_view_neighbor_routes_cmd);
12713 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12714 install_element (VIEW_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12715 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12716 install_element (VIEW_NODE, &show_bgp_view_neighbor_flap_cmd);
12717 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12718 install_element (VIEW_NODE, &show_bgp_view_neighbor_damp_cmd);
12719 install_element (VIEW_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012720 install_element (VIEW_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012721 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012722 install_element (VIEW_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012723 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012724 install_element (VIEW_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012725 install_element (VIEW_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012726
12727 /* Restricted:
12728 * VIEW_NODE - (set of dangerous commands) - (commands dependent on prev)
12729 */
12730 install_element (RESTRICTED_NODE, &show_bgp_route_cmd);
12731 install_element (RESTRICTED_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012732 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012733 install_element (RESTRICTED_NODE, &show_bgp_prefix_cmd);
12734 install_element (RESTRICTED_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012735 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012736 install_element (RESTRICTED_NODE, &show_bgp_community_cmd);
12737 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_cmd);
12738 install_element (RESTRICTED_NODE, &show_bgp_community2_cmd);
12739 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_cmd);
12740 install_element (RESTRICTED_NODE, &show_bgp_community3_cmd);
12741 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_cmd);
12742 install_element (RESTRICTED_NODE, &show_bgp_community4_cmd);
12743 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_cmd);
12744 install_element (RESTRICTED_NODE, &show_bgp_community_exact_cmd);
12745 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community_exact_cmd);
12746 install_element (RESTRICTED_NODE, &show_bgp_community2_exact_cmd);
12747 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community2_exact_cmd);
12748 install_element (RESTRICTED_NODE, &show_bgp_community3_exact_cmd);
12749 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community3_exact_cmd);
12750 install_element (RESTRICTED_NODE, &show_bgp_community4_exact_cmd);
12751 install_element (RESTRICTED_NODE, &show_bgp_ipv6_community4_exact_cmd);
12752 install_element (RESTRICTED_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012753 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012754 install_element (RESTRICTED_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012755 install_element (RESTRICTED_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012756 install_element (RESTRICTED_NODE, &show_bgp_view_route_cmd);
12757 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_route_cmd);
12758 install_element (RESTRICTED_NODE, &show_bgp_view_prefix_cmd);
12759 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_prefix_cmd);
12760 install_element (RESTRICTED_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12761 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12762 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012763 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
Paul Jakma62687ff2008-08-23 14:27:06 +010012764 install_element (RESTRICTED_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012765 install_element (RESTRICTED_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012766
12767 install_element (ENABLE_NODE, &show_bgp_cmd);
12768 install_element (ENABLE_NODE, &show_bgp_ipv6_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012769 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_cmd);
paul718e3742002-12-13 20:15:29 +000012770 install_element (ENABLE_NODE, &show_bgp_route_cmd);
12771 install_element (ENABLE_NODE, &show_bgp_ipv6_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012772 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_route_cmd);
paul718e3742002-12-13 20:15:29 +000012773 install_element (ENABLE_NODE, &show_bgp_prefix_cmd);
12774 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012775 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_prefix_cmd);
paul718e3742002-12-13 20:15:29 +000012776 install_element (ENABLE_NODE, &show_bgp_regexp_cmd);
12777 install_element (ENABLE_NODE, &show_bgp_ipv6_regexp_cmd);
12778 install_element (ENABLE_NODE, &show_bgp_prefix_list_cmd);
12779 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_list_cmd);
12780 install_element (ENABLE_NODE, &show_bgp_filter_list_cmd);
12781 install_element (ENABLE_NODE, &show_bgp_ipv6_filter_list_cmd);
12782 install_element (ENABLE_NODE, &show_bgp_route_map_cmd);
12783 install_element (ENABLE_NODE, &show_bgp_ipv6_route_map_cmd);
12784 install_element (ENABLE_NODE, &show_bgp_community_all_cmd);
12785 install_element (ENABLE_NODE, &show_bgp_ipv6_community_all_cmd);
12786 install_element (ENABLE_NODE, &show_bgp_community_cmd);
12787 install_element (ENABLE_NODE, &show_bgp_ipv6_community_cmd);
12788 install_element (ENABLE_NODE, &show_bgp_community2_cmd);
12789 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_cmd);
12790 install_element (ENABLE_NODE, &show_bgp_community3_cmd);
12791 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_cmd);
12792 install_element (ENABLE_NODE, &show_bgp_community4_cmd);
12793 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_cmd);
12794 install_element (ENABLE_NODE, &show_bgp_community_exact_cmd);
12795 install_element (ENABLE_NODE, &show_bgp_ipv6_community_exact_cmd);
12796 install_element (ENABLE_NODE, &show_bgp_community2_exact_cmd);
12797 install_element (ENABLE_NODE, &show_bgp_ipv6_community2_exact_cmd);
12798 install_element (ENABLE_NODE, &show_bgp_community3_exact_cmd);
12799 install_element (ENABLE_NODE, &show_bgp_ipv6_community3_exact_cmd);
12800 install_element (ENABLE_NODE, &show_bgp_community4_exact_cmd);
12801 install_element (ENABLE_NODE, &show_bgp_ipv6_community4_exact_cmd);
12802 install_element (ENABLE_NODE, &show_bgp_community_list_cmd);
12803 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_cmd);
12804 install_element (ENABLE_NODE, &show_bgp_community_list_exact_cmd);
12805 install_element (ENABLE_NODE, &show_bgp_ipv6_community_list_exact_cmd);
12806 install_element (ENABLE_NODE, &show_bgp_prefix_longer_cmd);
12807 install_element (ENABLE_NODE, &show_bgp_ipv6_prefix_longer_cmd);
12808 install_element (ENABLE_NODE, &show_bgp_neighbor_advertised_route_cmd);
12809 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_advertised_route_cmd);
12810 install_element (ENABLE_NODE, &show_bgp_neighbor_received_routes_cmd);
12811 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_routes_cmd);
12812 install_element (ENABLE_NODE, &show_bgp_neighbor_routes_cmd);
12813 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_routes_cmd);
12814 install_element (ENABLE_NODE, &show_bgp_neighbor_received_prefix_filter_cmd);
12815 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_received_prefix_filter_cmd);
paulbb46e942003-10-24 19:02:03 +000012816 install_element (ENABLE_NODE, &show_bgp_neighbor_flap_cmd);
12817 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_flap_cmd);
12818 install_element (ENABLE_NODE, &show_bgp_neighbor_damp_cmd);
12819 install_element (ENABLE_NODE, &show_bgp_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012820 install_element (ENABLE_NODE, &show_bgp_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012821 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012822 install_element (ENABLE_NODE, &show_bgp_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012823 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012824 install_element (ENABLE_NODE, &show_bgp_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012825 install_element (ENABLE_NODE, &show_bgp_ipv6_safi_rsclient_prefix_cmd);
paulbb46e942003-10-24 19:02:03 +000012826 install_element (ENABLE_NODE, &show_bgp_view_cmd);
12827 install_element (ENABLE_NODE, &show_bgp_view_ipv6_cmd);
12828 install_element (ENABLE_NODE, &show_bgp_view_route_cmd);
12829 install_element (ENABLE_NODE, &show_bgp_view_ipv6_route_cmd);
12830 install_element (ENABLE_NODE, &show_bgp_view_prefix_cmd);
12831 install_element (ENABLE_NODE, &show_bgp_view_ipv6_prefix_cmd);
12832 install_element (ENABLE_NODE, &show_bgp_view_neighbor_advertised_route_cmd);
12833 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_advertised_route_cmd);
12834 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_routes_cmd);
12835 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_routes_cmd);
12836 install_element (ENABLE_NODE, &show_bgp_view_neighbor_routes_cmd);
12837 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_routes_cmd);
12838 install_element (ENABLE_NODE, &show_bgp_view_neighbor_received_prefix_filter_cmd);
12839 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_received_prefix_filter_cmd);
12840 install_element (ENABLE_NODE, &show_bgp_view_neighbor_flap_cmd);
12841 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_flap_cmd);
12842 install_element (ENABLE_NODE, &show_bgp_view_neighbor_damp_cmd);
12843 install_element (ENABLE_NODE, &show_bgp_view_ipv6_neighbor_damp_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012844 install_element (ENABLE_NODE, &show_bgp_view_rsclient_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012845 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012846 install_element (ENABLE_NODE, &show_bgp_view_rsclient_route_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012847 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_route_cmd);
paulfee0f4c2004-09-13 05:12:46 +000012848 install_element (ENABLE_NODE, &show_bgp_view_rsclient_prefix_cmd);
Michael Lambert95cbbd22010-07-23 14:43:04 -040012849 install_element (ENABLE_NODE, &show_bgp_view_ipv6_safi_rsclient_prefix_cmd);
Paul Jakma2815e612006-09-14 02:56:07 +000012850
12851 /* Statistics */
12852 install_element (ENABLE_NODE, &show_bgp_statistics_cmd);
12853 install_element (ENABLE_NODE, &show_bgp_statistics_vpnv4_cmd);
12854 install_element (ENABLE_NODE, &show_bgp_statistics_view_cmd);
12855 install_element (ENABLE_NODE, &show_bgp_statistics_view_vpnv4_cmd);
12856
paul718e3742002-12-13 20:15:29 +000012857 /* old command */
12858 install_element (VIEW_NODE, &show_ipv6_bgp_cmd);
12859 install_element (VIEW_NODE, &show_ipv6_bgp_route_cmd);
12860 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_cmd);
12861 install_element (VIEW_NODE, &show_ipv6_bgp_regexp_cmd);
12862 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_list_cmd);
12863 install_element (VIEW_NODE, &show_ipv6_bgp_filter_list_cmd);
12864 install_element (VIEW_NODE, &show_ipv6_bgp_community_all_cmd);
12865 install_element (VIEW_NODE, &show_ipv6_bgp_community_cmd);
12866 install_element (VIEW_NODE, &show_ipv6_bgp_community2_cmd);
12867 install_element (VIEW_NODE, &show_ipv6_bgp_community3_cmd);
12868 install_element (VIEW_NODE, &show_ipv6_bgp_community4_cmd);
12869 install_element (VIEW_NODE, &show_ipv6_bgp_community_exact_cmd);
12870 install_element (VIEW_NODE, &show_ipv6_bgp_community2_exact_cmd);
12871 install_element (VIEW_NODE, &show_ipv6_bgp_community3_exact_cmd);
12872 install_element (VIEW_NODE, &show_ipv6_bgp_community4_exact_cmd);
12873 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_cmd);
12874 install_element (VIEW_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12875 install_element (VIEW_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12876 install_element (VIEW_NODE, &show_ipv6_mbgp_cmd);
12877 install_element (VIEW_NODE, &show_ipv6_mbgp_route_cmd);
12878 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_cmd);
12879 install_element (VIEW_NODE, &show_ipv6_mbgp_regexp_cmd);
12880 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12881 install_element (VIEW_NODE, &show_ipv6_mbgp_filter_list_cmd);
12882 install_element (VIEW_NODE, &show_ipv6_mbgp_community_all_cmd);
12883 install_element (VIEW_NODE, &show_ipv6_mbgp_community_cmd);
12884 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_cmd);
12885 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_cmd);
12886 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_cmd);
12887 install_element (VIEW_NODE, &show_ipv6_mbgp_community_exact_cmd);
12888 install_element (VIEW_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12889 install_element (VIEW_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12890 install_element (VIEW_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12891 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_cmd);
12892 install_element (VIEW_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12893 install_element (VIEW_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
paulbb46e942003-10-24 19:02:03 +000012894
paul718e3742002-12-13 20:15:29 +000012895 /* old command */
12896 install_element (ENABLE_NODE, &show_ipv6_bgp_cmd);
12897 install_element (ENABLE_NODE, &show_ipv6_bgp_route_cmd);
12898 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_cmd);
12899 install_element (ENABLE_NODE, &show_ipv6_bgp_regexp_cmd);
12900 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_list_cmd);
12901 install_element (ENABLE_NODE, &show_ipv6_bgp_filter_list_cmd);
12902 install_element (ENABLE_NODE, &show_ipv6_bgp_community_all_cmd);
12903 install_element (ENABLE_NODE, &show_ipv6_bgp_community_cmd);
12904 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_cmd);
12905 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_cmd);
12906 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_cmd);
12907 install_element (ENABLE_NODE, &show_ipv6_bgp_community_exact_cmd);
12908 install_element (ENABLE_NODE, &show_ipv6_bgp_community2_exact_cmd);
12909 install_element (ENABLE_NODE, &show_ipv6_bgp_community3_exact_cmd);
12910 install_element (ENABLE_NODE, &show_ipv6_bgp_community4_exact_cmd);
12911 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_cmd);
12912 install_element (ENABLE_NODE, &show_ipv6_bgp_community_list_exact_cmd);
12913 install_element (ENABLE_NODE, &show_ipv6_bgp_prefix_longer_cmd);
12914 install_element (ENABLE_NODE, &show_ipv6_mbgp_cmd);
12915 install_element (ENABLE_NODE, &show_ipv6_mbgp_route_cmd);
12916 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_cmd);
12917 install_element (ENABLE_NODE, &show_ipv6_mbgp_regexp_cmd);
12918 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_list_cmd);
12919 install_element (ENABLE_NODE, &show_ipv6_mbgp_filter_list_cmd);
12920 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_all_cmd);
12921 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_cmd);
12922 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_cmd);
12923 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_cmd);
12924 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_cmd);
12925 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_exact_cmd);
12926 install_element (ENABLE_NODE, &show_ipv6_mbgp_community2_exact_cmd);
12927 install_element (ENABLE_NODE, &show_ipv6_mbgp_community3_exact_cmd);
12928 install_element (ENABLE_NODE, &show_ipv6_mbgp_community4_exact_cmd);
12929 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_cmd);
12930 install_element (ENABLE_NODE, &show_ipv6_mbgp_community_list_exact_cmd);
12931 install_element (ENABLE_NODE, &show_ipv6_mbgp_prefix_longer_cmd);
12932
12933 /* old command */
12934 install_element (VIEW_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12935 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_advertised_route_cmd);
12936 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12937 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_advertised_route_cmd);
12938
12939 /* old command */
12940 install_element (VIEW_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12941 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_received_routes_cmd);
12942 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12943 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_received_routes_cmd);
12944
12945 /* old command */
12946 install_element (VIEW_NODE, &ipv6_bgp_neighbor_routes_cmd);
12947 install_element (ENABLE_NODE, &ipv6_bgp_neighbor_routes_cmd);
12948 install_element (VIEW_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12949 install_element (ENABLE_NODE, &ipv6_mbgp_neighbor_routes_cmd);
12950#endif /* HAVE_IPV6 */
12951
12952 install_element (BGP_NODE, &bgp_distance_cmd);
12953 install_element (BGP_NODE, &no_bgp_distance_cmd);
12954 install_element (BGP_NODE, &no_bgp_distance2_cmd);
12955 install_element (BGP_NODE, &bgp_distance_source_cmd);
12956 install_element (BGP_NODE, &no_bgp_distance_source_cmd);
12957 install_element (BGP_NODE, &bgp_distance_source_access_list_cmd);
12958 install_element (BGP_NODE, &no_bgp_distance_source_access_list_cmd);
12959
12960 install_element (BGP_NODE, &bgp_damp_set_cmd);
12961 install_element (BGP_NODE, &bgp_damp_set2_cmd);
12962 install_element (BGP_NODE, &bgp_damp_set3_cmd);
12963 install_element (BGP_NODE, &bgp_damp_unset_cmd);
12964 install_element (BGP_NODE, &bgp_damp_unset2_cmd);
12965 install_element (BGP_IPV4_NODE, &bgp_damp_set_cmd);
12966 install_element (BGP_IPV4_NODE, &bgp_damp_set2_cmd);
12967 install_element (BGP_IPV4_NODE, &bgp_damp_set3_cmd);
12968 install_element (BGP_IPV4_NODE, &bgp_damp_unset_cmd);
12969 install_element (BGP_IPV4_NODE, &bgp_damp_unset2_cmd);
Paul Jakmac8f3fe32010-12-05 20:28:02 +000012970
12971 /* Deprecated AS-Pathlimit commands */
12972 install_element (BGP_NODE, &bgp_network_ttl_cmd);
12973 install_element (BGP_NODE, &bgp_network_mask_ttl_cmd);
12974 install_element (BGP_NODE, &bgp_network_mask_natural_ttl_cmd);
12975 install_element (BGP_NODE, &bgp_network_backdoor_ttl_cmd);
12976 install_element (BGP_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12977 install_element (BGP_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12978
12979 install_element (BGP_NODE, &no_bgp_network_ttl_cmd);
12980 install_element (BGP_NODE, &no_bgp_network_mask_ttl_cmd);
12981 install_element (BGP_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12982 install_element (BGP_NODE, &no_bgp_network_backdoor_ttl_cmd);
12983 install_element (BGP_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12984 install_element (BGP_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12985
12986 install_element (BGP_IPV4_NODE, &bgp_network_ttl_cmd);
12987 install_element (BGP_IPV4_NODE, &bgp_network_mask_ttl_cmd);
12988 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_ttl_cmd);
12989 install_element (BGP_IPV4_NODE, &bgp_network_backdoor_ttl_cmd);
12990 install_element (BGP_IPV4_NODE, &bgp_network_mask_backdoor_ttl_cmd);
12991 install_element (BGP_IPV4_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
12992
12993 install_element (BGP_IPV4_NODE, &no_bgp_network_ttl_cmd);
12994 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_ttl_cmd);
12995 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_ttl_cmd);
12996 install_element (BGP_IPV4_NODE, &no_bgp_network_backdoor_ttl_cmd);
12997 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
12998 install_element (BGP_IPV4_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
12999
13000 install_element (BGP_IPV4M_NODE, &bgp_network_ttl_cmd);
13001 install_element (BGP_IPV4M_NODE, &bgp_network_mask_ttl_cmd);
13002 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_ttl_cmd);
13003 install_element (BGP_IPV4M_NODE, &bgp_network_backdoor_ttl_cmd);
13004 install_element (BGP_IPV4M_NODE, &bgp_network_mask_backdoor_ttl_cmd);
13005 install_element (BGP_IPV4M_NODE, &bgp_network_mask_natural_backdoor_ttl_cmd);
13006
13007 install_element (BGP_IPV4M_NODE, &no_bgp_network_ttl_cmd);
13008 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_ttl_cmd);
13009 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_ttl_cmd);
13010 install_element (BGP_IPV4M_NODE, &no_bgp_network_backdoor_ttl_cmd);
13011 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_backdoor_ttl_cmd);
13012 install_element (BGP_IPV4M_NODE, &no_bgp_network_mask_natural_backdoor_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013013
13014#ifdef HAVE_IPV6
Paul Jakmac8f3fe32010-12-05 20:28:02 +000013015 install_element (BGP_IPV6_NODE, &ipv6_bgp_network_ttl_cmd);
13016 install_element (BGP_IPV6_NODE, &no_ipv6_bgp_network_ttl_cmd);
Paul Jakma3bde17f2011-03-23 10:30:30 +000013017#endif
paul718e3742002-12-13 20:15:29 +000013018}
Chris Caputo228da422009-07-18 05:44:03 +000013019
13020void
13021bgp_route_finish (void)
13022{
13023 bgp_table_unlock (bgp_distance_table);
13024 bgp_distance_table = NULL;
13025}